Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
29 changes: 18 additions & 11 deletions cc1101_chrdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
3 changes: 3 additions & 0 deletions cc1101_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#include <linux/kfifo.h>

#include "cc1101.h"
#include <linux/mutex.h>
#include <linux/timer.h>
#include <linux/workqueue.h>

#define DRIVER_VERSION 4

Expand Down
3 changes: 1 addition & 2 deletions cc1101_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}

/*
Expand Down