diff options
author | lonkaars <loek@pipeframe.xyz> | 2024-05-14 20:56:43 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2024-05-14 20:56:43 +0200 |
commit | a8bab1509e795f367db2e374fe600ecacf66e26b (patch) | |
tree | 97ccd68f1142da7cd372830ba5cab08c25495b6a | |
parent | 44a5c2b2d47dde5215171966eeef0acdadcaded3 (diff) |
add attribute (9.4)
-rw-r--r-- | driver/main.c | 24 | ||||
-rw-r--r-- | driver/main.h | 22 | ||||
-rw-r--r-- | driver/platform.c | 44 | ||||
-rw-r--r-- | driver/platform.h | 12 |
4 files changed, 70 insertions, 32 deletions
diff --git a/driver/main.c b/driver/main.c index 8775727..2676c9a 100644 --- a/driver/main.c +++ b/driver/main.c @@ -1,26 +1,11 @@ #include <linux/init.h> #include <linux/io.h> #include <linux/module.h> -#include <linux/of.h> #include <linux/platform_device.h> +#include "main.h" #include "platform.h" -static const struct of_device_id lork_ids[] = { - { .compatible = "gpio-extern" }, - {}, -}; - -struct platform_driver lork_driver = { - .probe = lork_probe, - .remove = lork_remove, - .driver = { - .name = "gpio-extern", - .owner = THIS_MODULE, - .of_match_table = of_match_ptr(lork_ids), - } -}; - struct class* class; static int mod_init(void) { @@ -38,17 +23,22 @@ static int mod_init(void) { err = platform_driver_register(&lork_driver); if (err) goto return_err; + // create attribute under /sys/bus/platform/drivers/gpio-extern + err = driver_create_file(&lork_driver.driver, &attr); + if (err) goto return_err; + printk("%s() OK\n", __PRETTY_FUNCTION__); return 0; +return_err: free_class: class_destroy(class); -return_err: printk("%s() -> %d\n", __PRETTY_FUNCTION__, err); return err; } static void mod_exit(void) { + driver_remove_file(&lork_driver.driver, &attr); platform_driver_unregister(&lork_driver); class_destroy(class); printk("%s()\n", __PRETTY_FUNCTION__); diff --git a/driver/main.h b/driver/main.h new file mode 100644 index 0000000..a0ef924 --- /dev/null +++ b/driver/main.h @@ -0,0 +1,22 @@ +#pragma once + +#include <linux/of.h> +#include <linux/platform_device.h> + +#include "platform.h" + +static const struct of_device_id lork_ids[] = { + { .compatible = "gpio-extern" }, + {}, +}; + +struct platform_driver lork_driver = { + .probe = lork_probe, + .remove = lork_remove, + .driver = { + .name = "gpio-extern", + .owner = THIS_MODULE, + .of_match_table = of_match_ptr(lork_ids), + } +}; + diff --git a/driver/platform.c b/driver/platform.c index da84064..c41d47b 100644 --- a/driver/platform.c +++ b/driver/platform.c @@ -2,6 +2,11 @@ #include <linux/types.h> #include <linux/of.h> +#include <linux/of_address.h> + +// TODO: shouldn't these be used?? +// #include <linux/pinctrl/pinctrl.h> +// #include <linux/gpio/driver.h> #include <dt-bindings/gpio/gpio.h> @@ -19,23 +24,23 @@ int lork_probe(struct platform_device* dev) { printk("lork: configure pin %u w/ mode 0x%02x\n", pin, gpio_mode); // find the multiplexer that controls pin - size_t len = of_property_count_u32_elems(gpio1, "gpio-ranges"); - struct device_node* am33xx_pinmux = NULL; - for (size_t i = 0; i < len; i += 4) { - uint32_t phandle, pin_start, pin_offset, pin_size; - of_property_read_u32_index(gpio1, "gpio-ranges", i+0, &phandle); - of_property_read_u32_index(gpio1, "gpio-ranges", i+1, &pin_start); - of_property_read_u32_index(gpio1, "gpio-ranges", i+2, &pin_offset); - of_property_read_u32_index(gpio1, "gpio-ranges", i+3, &pin_size); + // size_t len = of_property_count_u32_elems(gpio1, "gpio-ranges"); + // struct device_node* am33xx_pinmux = NULL; + // for (size_t i = 0; i < len; i += 4) { + // uint32_t phandle, pin_start, pin_offset, pin_size; + // of_property_read_u32_index(gpio1, "gpio-ranges", i+0, &phandle); + // of_property_read_u32_index(gpio1, "gpio-ranges", i+1, &pin_start); + // of_property_read_u32_index(gpio1, "gpio-ranges", i+2, &pin_offset); + // of_property_read_u32_index(gpio1, "gpio-ranges", i+3, &pin_size); - // get phandle for multiplexer corresponding to configured pin number - if (pin_start > pin || pin >= pin_start + pin_size) continue; + // // get phandle for multiplexer corresponding to configured pin number + // if (pin_start > pin || pin >= pin_start + pin_size) continue; - am33xx_pinmux = of_find_node_by_phandle(phandle); - printk("0x%02x, %u -> %u + %u\n", phandle, pin_start, pin_offset, pin_size); - break; - } - if (am33xx_pinmux == NULL) return EINVAL; + // am33xx_pinmux = of_find_node_by_phandle(phandle); + // printk("0x%02x, %u -> %u + %u\n", phandle, pin_start, pin_offset, pin_size); + // break; + // } + // if (am33xx_pinmux == NULL) return EINVAL; // TODO: ??? @@ -67,3 +72,12 @@ int lork_remove(struct platform_device* dev) { return 0; } +unsigned int val = 0; +ssize_t attr_show(struct device_driver* drv, char* buf) { + return sprintf(buf, "%u\n", val); +} +ssize_t attr_store(struct device_driver* drv, const char* buf, size_t count) { + sscanf(buf, "%u", &val); + return count; +} + diff --git a/driver/platform.h b/driver/platform.h index 3faaad5..cee82a7 100644 --- a/driver/platform.h +++ b/driver/platform.h @@ -3,6 +3,18 @@ #include <linux/types.h> #include <linux/platform_device.h> +ssize_t attr_show(struct device_driver*, char*); +ssize_t attr_store(struct device_driver*, const char*, size_t); + +static struct driver_attribute attr = { + .attr = { + .name = "attr", + .mode = 0644, + }, + .show = attr_show, + .store = attr_store, +}; + int lork_probe(struct platform_device*); int lork_remove(struct platform_device*); |