3 Commits

Author SHA1 Message Date
184b877b34 spi stuff 2025-06-12 14:59:12 +01:00
17ad8044fb ls7366r started 2025-06-06 21:59:16 +01:00
31e308efe9 try to drop MODULE_DEVICE_TABLE 2025-06-04 18:09:42 +01:00
2 changed files with 113 additions and 22 deletions

View File

@ -5,32 +5,62 @@
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/of_device.h> #include <linux/of_device.h>
#include <linux/gpio/consumer.h> #include <linux/gpio/consumer.h>
#include <linux/spi/spi.h>
/* Meta Information */ /* Meta Information */
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
MODULE_AUTHOR("Wolfgang Hottgenroth"); MODULE_AUTHOR("Wolfgang Hottgenroth");
MODULE_DESCRIPTION("A simple LKM to parse the device tree for a specific device and its properties"); MODULE_DESCRIPTION("A simple LKM to parse the device tree for a specific device and its properties");
/* Declate the probe and remove functions */ static int dt_leds_probe(struct platform_device *pdev);
static int dt_probe(struct platform_device *pdev); static void dt_leds_remove(struct platform_device *pdev);
static void dt_remove(struct platform_device *pdev);
static struct of_device_id my_driver_ids[] = { static struct of_device_id leds_driver_ids[] = {
{ {
.compatible = "hottis,counter", .compatible = "hottis,leds",
}, { /* sentinel */ } }, { /* sentinel */ }
}; };
MODULE_DEVICE_TABLE(of, my_driver_ids); // MODULE_DEVICE_TABLE(of, leds_driver_ids);
static struct platform_driver my_driver = { static struct platform_driver leds_driver = {
.probe = dt_probe, .probe = dt_leds_probe,
.remove = dt_remove, .remove = dt_leds_remove,
.driver = { .driver = {
.name = "my_device_driver", .name = "leds_device_driver",
.of_match_table = my_driver_ids, .of_match_table = leds_driver_ids,
}, },
}; };
/*
static int dt_ls7366r_probe(struct spi_device *client);
static void dt_ls7366r_remove(struct spi_device *client);
static struct of_device_id ls7366r_driver_ids[] = {
{
.compatible = "hottis,ls7366r0",
}, {}
};
MODULE_DEVICE_TABLE(of, ls7366r_driver_ids);
static struct spi_device_id ls7366r[] = {
{ "ls7366r0", 0 },
{},
};
MODULE_DEVICE_TABLE(spi, ls7366r);
static struct spi_driver ls7366r_driver = {
.probe = dt_ls7366r_probe,
.remove = dt_ls7366r_remove,
.id_table = ls7366r,
.driver = {
.name = "ls7366r0",
.of_match_table = ls7366r_driver_ids,
},
};
*/
/* GPIO variable */ /* GPIO variable */
static struct gpio_desc *red_led = NULL; static struct gpio_desc *red_led = NULL;
static struct gpio_desc *blue_led = NULL; static struct gpio_desc *blue_led = NULL;
@ -39,10 +69,10 @@ static struct gpio_desc *blue_led = NULL;
/** /**
* @brief This function is called on loading the driver * @brief This function is called on loading the driver
*/ */
static int dt_probe(struct platform_device *pdev) { static int dt_leds_probe(struct platform_device *pdev) {
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
printk("counter - probing\n"); printk("counter - led probing\n");
if(!device_property_present(dev, "red-led-gpio")) { if(!device_property_present(dev, "red-led-gpio")) {
printk("counter - Error! Device property 'red-led-gpio' not found!\n"); printk("counter - Error! Device property 'red-led-gpio' not found!\n");
@ -72,22 +102,53 @@ static int dt_probe(struct platform_device *pdev) {
/** /**
* @brief This function is called on unloading the driver * @brief This function is called on unloading the driver
*/ */
static void dt_remove(struct platform_device *pdev) { static void dt_leds_remove(struct platform_device *pdev) {
printk("counter - removing\n"); printk("counter - led removing\n");
gpiod_put(red_led); gpiod_put(red_led);
gpiod_put(blue_led); gpiod_put(blue_led);
} }
/*
static int dt_ls7366r_probe(struct spi_device *client) {
printk("counter - ls7366r probing\n");
int ret = spi_setup(client);
if (ret < 0) {
printk("counter - Error! Failed to set up the SPI bus\n");
return ret;
}
return 0;
}
static void dt_ls7366r_remove(struct spi_device *client) {
printk("counter - ls7366r removing\n");
}
*/
/** /**
* @brief This function is called, when the module is loaded into the kernel * @brief This function is called, when the module is loaded into the kernel
*/ */
static int __init my_init(void) { static int __init my_init(void) {
printk("counter - Loading the driver...\n"); printk("counter - Loading the drivers...\n");
if(platform_driver_register(&my_driver)) {
printk("dt_gpio - Error! Could not load driver\n"); if (platform_driver_register(&leds_driver)) {
printk("counter - Error! Could not load leds driver\n");
return -1; return -1;
} }
/*
if (spi_register_driver(&ls7366r_driver)) {
printk("counter - Error! Could not load spi driver\n");
return -1;
}
*/
printk("counter - red led on\n"); printk("counter - red led on\n");
gpiod_set_value(red_led, 1); gpiod_set_value(red_led, 1);
@ -98,12 +159,15 @@ static int __init my_init(void) {
* @brief This function is called, when the module is removed from the kernel * @brief This function is called, when the module is removed from the kernel
*/ */
static void __exit my_exit(void) { static void __exit my_exit(void) {
printk("counter - Unload driver"); printk("counter - Unload drivers");
printk("counter - red led off\n"); printk("counter - red led off\n");
gpiod_set_value(red_led, 0); gpiod_set_value(red_led, 0);
platform_driver_unregister(&my_driver); platform_driver_unregister(&leds_driver);
/*
spi_unregister_driver(&ls7366r_driver);
*/
} }
module_init(my_init); module_init(my_init);

View File

@ -6,11 +6,38 @@
target-path = "/"; target-path = "/";
__overlay__ { __overlay__ {
status = "okay"; status = "okay";
counter { leds {
compatible = "hottis,counter"; compatible = "hottis,leds";
red-led-gpio = <&gpio 26 0>; red-led-gpio = <&gpio 26 0>;
blue-led-gpio = <&gpio 21 0>; blue-led-gpio = <&gpio 21 0>;
}; };
}; };
}; };
/*
fragment@1 {
target = <&spidev0>;
__overlay__ {
status = "disabled";
};
};
fragment@2 {
target = <&spi0>;
__overlay__ {
status = "okay";
#address-cells = <1>;
#size-cells = <0>;
ls7366r: ls7366r0@0 {
compatible = "hottis,counter";
reg = <0x0>;
spi-max-frequency = <1000000>;
spi-bits-per-word = <8>;
status = "okay";
};
};
};
*/
}; };