diff --git a/README.md b/README.md index 02e3ee9..149ba2e 100644 --- a/README.md +++ b/README.md @@ -64,13 +64,13 @@ sudo dkms build -m cc1101 -v 1.4.0 sudo dkms install -m cc1101 -v 1.4.0 # Enable SPI -sudo sed -i "s/^#dtparam=spi=on$/dtparam=spi=on/" /boot/config.txt +sudo sed -i "s/^#dtparam=spi=on$/dtparam=spi=on/" /boot/firmware/config.txt # Compile Device Tree overlay sudo dtc -@ -I dts -O dtb -o /boot/overlays/cc1101.dtbo cc1101.dts # Enable Device Tree overlay -echo "dtoverlay=cc1101" | sudo tee -a /boot/config.txt +echo "dtoverlay=cc1101" | sudo tee -a /boot/firmware/config.txt # Enable module loading at boot echo "cc1101" | sudo tee -a /etc/modules @@ -109,7 +109,7 @@ To apply the device tree overlay, compile the dts file and move the compiled fil # Ubuntu mv cc1101.dtbo /boot/firmware/overlays -The following should then be added to /boot/config.txt (Raspberry Pi OS) or /boot/firmware/syscfg.txt (Ubuntu): +The following should then be added to /boot/firmware/config.txt (Raspberry Pi OS) or /boot/firmware/syscfg.txt (Ubuntu): dtoverlay=cc1101 diff --git a/cc1101_chrdev.c b/cc1101_chrdev.c index 489c569..f361343 100644 --- a/cc1101_chrdev.c +++ b/cc1101_chrdev.c @@ -365,30 +365,37 @@ static ssize_t chrdev_write(struct file *file, const char __user *buf, size_t le /* * Add a character device for a cc1101 */ -int cc1101_chrdev_add_device(cc1101_t * cc1101) { +int cc1101_chrdev_add_device(cc1101_t *cc1101) +{ int ret; int device_index; - + mutex_lock(&device_list_lock); - // Search for a free minor number - for(device_index = 0; device_index < N_SPI_MINOR_NUMBERS; device_index++){ - if(device_list[device_index] == NULL){ - // Allocate the minor number + for (device_index = 0; device_index < N_SPI_MINOR_NUMBERS; device_index++) { + if (device_list[device_index] == NULL) { + const char *spi_id; + cc1101->devt = MKDEV(SPI_MAJOR_NUMBER, device_index); - // Create a /dev/cc1101.x.x character device - if(IS_ERR(device_create(dev_class, &cc1101->spi->dev, cc1101->devt, cc1101, "cc1101.%d.%d", cc1101->spi->master->bus_num, cc1101->spi->chip_select))) { + spi_id = dev_name(&cc1101->spi->dev); + + if (IS_ERR(device_create(dev_class, + &cc1101->spi->dev, + cc1101->devt, + cc1101, + "cc1101.%s", + spi_id))) { ret = -ENODEV; goto done; } - // Insert the device in the device list device_list[device_index] = cc1101; ret = 0; goto done; } } + ret = -ENODEV; done: @@ -432,7 +439,7 @@ int cc1101_chrdev_setup(struct spi_driver* cc1101_driver) goto err_register; } - dev_class = class_create(THIS_MODULE, "cc1101"); + dev_class = class_create("cc1101"); if (IS_ERR(dev_class)) { ret = PTR_ERR(dev_class); goto err_class_create; @@ -462,4 +469,4 @@ void cc1101_chrdev_teardown(struct spi_driver* cc1101_driver) spi_unregister_driver(cc1101_driver); class_destroy(dev_class); unregister_chrdev(SPI_MAJOR_NUMBER, cc1101_driver->driver.name); -} \ No newline at end of file +} diff --git a/cc1101_internal.h b/cc1101_internal.h index ebaa64c..773722d 100644 --- a/cc1101_internal.h +++ b/cc1101_internal.h @@ -9,6 +9,9 @@ #include #include "cc1101.h" +#include +#include +#include #define DRIVER_VERSION 4 diff --git a/cc1101_main.c b/cc1101_main.c index a684adf..5e35aed 100755 --- a/cc1101_main.c +++ b/cc1101_main.c @@ -117,7 +117,7 @@ static int cc1101_spi_probe(struct spi_device *spi) /* * Function called on module removal for each CC1101 entry in device tree */ -static int cc1101_spi_remove(struct spi_device *spi) +static void cc1101_spi_remove(struct spi_device *spi) { cc1101_t* cc1101; cc1101 = spi_get_drvdata(spi); @@ -131,7 +131,6 @@ static int cc1101_spi_remove(struct spi_device *spi) // Remove /dev/cc1101.x.x cc1101_chrdev_remove_device(cc1101); CC1101_INFO(cc1101, "Removed"); - return 0; } /*