]> git.feebdaed.xyz Git - linuxyz.git/commitdiff
gpio
authorseantywork <seantywork@gmail.com>
Mon, 17 Nov 2025 06:37:51 +0000 (15:37 +0900)
committerseantywork <seantywork@gmail.com>
Mon, 17 Nov 2025 06:37:51 +0000 (15:37 +0900)
kdev-gpio-dt/.gitignore [new file with mode: 0644]
kdev-gpio-dt/Makefile [new file with mode: 0644]
kdev-gpio-dt/dt.sh [new file with mode: 0644]
kdev-gpio-dt/gpiodt.dts [new file with mode: 0644]
kdev-gpio-dt/kdev_gpio.c [new file with mode: 0644]

diff --git a/kdev-gpio-dt/.gitignore b/kdev-gpio-dt/.gitignore
new file mode 100644 (file)
index 0000000..413e225
--- /dev/null
@@ -0,0 +1 @@
+*.dtbo
\ No newline at end of file
diff --git a/kdev-gpio-dt/Makefile b/kdev-gpio-dt/Makefile
new file mode 100644 (file)
index 0000000..ccc97aa
--- /dev/null
@@ -0,0 +1,6 @@
+obj-m := kdev_gpio.o
+
+all:
+       make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) modules
+clean:
+       make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) clean
\ No newline at end of file
diff --git a/kdev-gpio-dt/dt.sh b/kdev-gpio-dt/dt.sh
new file mode 100644 (file)
index 0000000..1ea4b03
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+dtc -@ -I dts -O dtb -o gpiodt.dtbo gpiodt.dts
\ No newline at end of file
diff --git a/kdev-gpio-dt/gpiodt.dts b/kdev-gpio-dt/gpiodt.dts
new file mode 100644 (file)
index 0000000..4c8493f
--- /dev/null
@@ -0,0 +1,19 @@
+/dts-v1/;
+/plugin/;
+
+/ {
+    compatible = "brcm,bcm2711";
+
+    fragment@0 {
+        target = <&gpio>;
+        __overlay__ {
+            pinctrl-names = "default";
+            pinctrl-0 = <&gpiosk_pins_in>;
+
+            gpiosk_pins_in: gpiosk_pins_in {
+                brcm,pins = <17>;     /* GPIO17 */
+                brcm,function = <1>; /* Output */
+            };
+        };
+    };
+};
diff --git a/kdev-gpio-dt/kdev_gpio.c b/kdev-gpio-dt/kdev_gpio.c
new file mode 100644 (file)
index 0000000..1b1fce3
--- /dev/null
@@ -0,0 +1,49 @@
+#include <linux/kernel.h>
+#include <linux/init.h> 
+#include <linux/module.h>
+#include <linux/gpio.h>
+
+#include <linux/slab.h> 
+#include <linux/errno.h>  
+#include <linux/types.h> 
+#include <linux/interrupt.h> 
+
+#include <linux/in.h>
+#include <linux/string.h>
+#include <linux/version.h> 
+
+#include <linux/gpio/driver.h>
+#include <linux/gpio/consumer.h>
+
+#define TARGET_LABEL "pinctrl-bcm2711"
+#define TARGET_PIN_NAME        "GPIO17"
+
+
+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);
+        }
+    } else {
+        printk("kdev_gpio: label: not available\n");
+    }
+
+    return 0;
+}
+static int __init kdev_gpio_init(void){
+    gpio_device_find(NULL, _gc_match);
+
+    return 0;
+}
+
+static void __exit kdev_gpio_exit(void){
+    printk("kdev_gpio: bye\n");
+}
+
+module_init(kdev_gpio_init);
+module_exit(kdev_gpio_exit);
+
+MODULE_LICENSE("GPL");
\ No newline at end of file