]> git.feebdaed.xyz Git - linuxyz.git/commitdiff
dt
authorseantywork <seantywork@gmail.com>
Mon, 17 Nov 2025 08:36:02 +0000 (08:36 +0000)
committerseantywork <seantywork@gmail.com>
Mon, 17 Nov 2025 08:36:02 +0000 (08:36 +0000)
kdev-gpio-dt/dt.sh [changed mode: 0644->0755]
kdev-gpio-dt/gpiodt.dts
kdev-gpio-dt/kdev_gpio.c

old mode 100644 (file)
new mode 100755 (executable)
index 4c8493f165ef8b3b7ccf2679e99ed754b26f478e..6b00150d978933b1832c2514787155f20f202c01 100644 (file)
@@ -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
index 1b1fce3eceefa4449dfeef828936d2d7472a36ea..bf94806c0da78d4b394f9dad4baaa52c39ff22e6 100644 (file)
 #include <linux/string.h>
 #include <linux/version.h> 
 
+#include <linux/device.h>
+#include <linux/of.h>
+#include <linux/of_gpio.h>
 #include <linux/gpio/driver.h>
 #include <linux/gpio/consumer.h>
 
-#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");
 }