From 98f33b124608919c27aabd7387d50cda45842baa Mon Sep 17 00:00:00 2001 From: Florian RICHER Date: Tue, 25 Feb 2025 21:31:17 +0100 Subject: [PATCH] Begin add usb driver --- .gitignore | 1 + 10_lnp_usb_driver/Makefile | 7 +++++ 10_lnp_usb_driver/bind.sh | 35 ++++++++++++++++++++++ 10_lnp_usb_driver/test_module.c | 53 +++++++++++++++++++++++++++++++++ 4 files changed, 96 insertions(+) create mode 100644 10_lnp_usb_driver/Makefile create mode 100755 10_lnp_usb_driver/bind.sh create mode 100644 10_lnp_usb_driver/test_module.c diff --git a/.gitignore b/.gitignore index 2cfd27c..4f32292 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ # Ignore other compiled files and directories *.o +*.o.d *.mod *.symvers *.order diff --git a/10_lnp_usb_driver/Makefile b/10_lnp_usb_driver/Makefile new file mode 100644 index 0000000..b909b3c --- /dev/null +++ b/10_lnp_usb_driver/Makefile @@ -0,0 +1,7 @@ +obj-m += test_module.o + +all: + make -C $(LINUX_MODULES_FOLDER)/build M=$(PWD) modules + +clean: + make -C $(LINUX_MODULES_FOLDER)/build M=$(PWD) clean diff --git a/10_lnp_usb_driver/bind.sh b/10_lnp_usb_driver/bind.sh new file mode 100755 index 0000000..dbd803c --- /dev/null +++ b/10_lnp_usb_driver/bind.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +# Définir les détails du périphérique USB et des pilotes +VENDOR_ID="1b1c" +DEVICE_ID="0c0b" +NEW_DRIVER="lightning-node-pro" + +# Vérifier les identifiants avec lsusb +echo "Vérifiez que le périphérique est listé avec les identifiants corrects :" +lsusb | grep "${VENDOR_ID}:${DEVICE_ID}" + +# Trouver le chemin du périphérique USB +USB_DEVICE_PATH=$(find /sys/bus/usb/devices/*/ -type f -name 'idVendor' -execdir sh -c 'grep -q '"$VENDOR_ID"' idVendor && grep -q '"$DEVICE_ID"' idProduct && pwd' \; | head -n 1) + +if [ -z "$USB_DEVICE_PATH" ]; then + echo "Périphérique USB non trouvé" + exit 1 +fi + +echo "Chemin du périphérique USB : $USB_DEVICE_PATH" + +# Extraire l'identifiant du périphérique (par exemple, 1-10) +DEVICE_IDENTIFIER=$(basename "$USB_DEVICE_PATH") + +echo "Identifiant du périphérique : $DEVICE_IDENTIFIER" + +# Délier le périphérique USB du pilote actuel +echo "Délier le périphérique USB du pilote actuel..." +echo -n "$DEVICE_IDENTIFIER" | sudo tee "/sys/bus/usb/devices/$DEVICE_IDENTIFIER/driver/unbind" > /dev/null + +# Lier le périphérique USB au nouveau pilote +echo "Lier le périphérique USB au nouveau pilote..." +echo -n "$DEVICE_IDENTIFIER" | sudo tee "/sys/bus/usb/drivers/${NEW_DRIVER}/bind" > /dev/null + +echo "Périphérique USB lié avec succès au nouveau pilote" diff --git a/10_lnp_usb_driver/test_module.c b/10_lnp_usb_driver/test_module.c new file mode 100644 index 0000000..03ace2d --- /dev/null +++ b/10_lnp_usb_driver/test_module.c @@ -0,0 +1,53 @@ +#include +#include +#include + +#define USB_VENDOR_ID_CORSAIR 0x1b1c +#define USB_DEVICE_ID_LIGHTNING_NODE_PRO 0x0c0b + +static int lnp_driver_probe(struct usb_interface *interface, + const struct usb_device_id *id) +{ + pr_info("Détection USB pour Lightning Node Pro\n"); + + return 0; +} + +static struct usb_device_id lnp_driver_table[] = { + { USB_DEVICE(USB_VENDOR_ID_CORSAIR, USB_DEVICE_ID_LIGHTNING_NODE_PRO) }, + {} /* Entrée de terminaison */ +}; +MODULE_DEVICE_TABLE(usb, lnp_driver_table); + +static struct usb_driver lnp_driver = { + .name = "lightning-node-pro", + .id_table = lnp_driver_table, + .probe = lnp_driver_probe, +}; + +static int __init lnp_usb_driver_init(void) +{ + int ret; + + ret = usb_register(&lnp_driver); + if (ret < 0) { + pr_err("lnp_usb_driver: Impossible d'enregistrer le pilote pour %s. Code d'erreur: %d\n", + lnp_driver.name, ret); + return -1; + } + + return 0; +} + +static void __exit lnp_usb_driver_exit(void) +{ + usb_deregister(&lnp_driver); +} + +module_init(lnp_usb_driver_init); +module_exit(lnp_usb_driver_exit); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Florian RICHER "); +MODULE_DESCRIPTION("Un module noyau pour utiliser le Lightning Node Pro LED"); +MODULE_VERSION("1.0"); \ No newline at end of file