From: seantywork Date: Mon, 17 Nov 2025 08:36:02 +0000 (+0000) Subject: dt X-Git-Url: https://git.feebdaed.xyz/?a=commitdiff_plain;h=6fcec97fbf4998d1423416bf1fd8fe5888d58073;p=linuxyz.git dt --- diff --git a/kdev-gpio-dt/dt.sh b/kdev-gpio-dt/dt.sh old mode 100644 new mode 100755 diff --git a/kdev-gpio-dt/gpiodt.dts b/kdev-gpio-dt/gpiodt.dts index 4c8493f..6b00150 100644 --- a/kdev-gpio-dt/gpiodt.dts +++ b/kdev-gpio-dt/gpiodt.dts @@ -8,12 +8,12 @@ target = <&gpio>; __overlay__ { pinctrl-names = "default"; - pinctrl-0 = <&gpiosk_pins_in>; + pinctrl-0 = <&gpiodt_pin_17>; - gpiosk_pins_in: gpiosk_pins_in { + gpiodt_pin_17: gpiodt_pin_17 { brcm,pins = <17>; /* GPIO17 */ brcm,function = <1>; /* Output */ }; }; }; -}; +}; \ No newline at end of file diff --git a/kdev-gpio-dt/kdev_gpio.c b/kdev-gpio-dt/kdev_gpio.c index 1b1fce3..bf94806 100644 --- a/kdev-gpio-dt/kdev_gpio.c +++ b/kdev-gpio-dt/kdev_gpio.c @@ -12,34 +12,61 @@ #include #include +#include +#include +#include #include #include -#define TARGET_LABEL "pinctrl-bcm2711" -#define TARGET_PIN_NAME "GPIO17" +#define TARGET_NODE_NAME "gpiodt_pin_17" +struct device_node* dn = NULL; -static int _gc_match(struct gpio_chip *gc, const void *data){ - int n = 0; - if(gc->label != NULL){ - printk("kdev_gpio: label: %s\n", gc->label); - if(strcmp(gc->label, TARGET_LABEL) == 0){ - printk("base: %d\n", gc->base); - printk("ngpio: %d\n", gc->ngpio); +static int __init kdev_gpio_init(void){ + dn = of_find_node_by_name(NULL, TARGET_NODE_NAME); + if(dn == NULL){ + printk("failed to get node by name\n"); + return -1; + } + printk("kdev_gpio: got node by name\n"); + if(dn->properties != NULL){ + struct property* p = dn->properties; + while(1){ + if(p->name != NULL){ + printk("p name: %s\n", p->name); + } + p = p->next; + if(p == NULL){ + break; + } + } + } + struct device* d = container_of(&dn,struct device, of_node); + if(d == NULL){ + of_node_put(dn); + printk("failed to get device\n"); + return -1; + } + if(d->init_name != NULL){ + printk("device init name: %s\n", d->init_name); + } + struct gpio_chip* gc = container_of(&d,struct gpio_chip, parent); + if(gc != NULL){ + printk("got gc\n"); + if(gc->label != NULL){ + printk("gc label: %d\n", gc->base); } - } else { - printk("kdev_gpio: label: not available\n"); } - return 0; -} -static int __init kdev_gpio_init(void){ - gpio_device_find(NULL, _gc_match); - + printk("kdev_gpio: init\n"); return 0; } static void __exit kdev_gpio_exit(void){ + if(dn != NULL){ + of_node_put(dn); + } + printk("kdev_gpio: bye\n"); }