From 7da2db660f734e84e9da22f08cff9cf70ddde510 Mon Sep 17 00:00:00 2001 From: seantywork Date: Mon, 17 Nov 2025 15:37:51 +0900 Subject: [PATCH] gpio --- kdev-gpio-dt/.gitignore | 1 + kdev-gpio-dt/Makefile | 6 +++++ kdev-gpio-dt/dt.sh | 3 +++ kdev-gpio-dt/gpiodt.dts | 19 ++++++++++++++++ kdev-gpio-dt/kdev_gpio.c | 49 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 78 insertions(+) create mode 100644 kdev-gpio-dt/.gitignore create mode 100644 kdev-gpio-dt/Makefile create mode 100644 kdev-gpio-dt/dt.sh create mode 100644 kdev-gpio-dt/gpiodt.dts create mode 100644 kdev-gpio-dt/kdev_gpio.c diff --git a/kdev-gpio-dt/.gitignore b/kdev-gpio-dt/.gitignore new file mode 100644 index 0000000..413e225 --- /dev/null +++ b/kdev-gpio-dt/.gitignore @@ -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 index 0000000..ccc97aa --- /dev/null +++ b/kdev-gpio-dt/Makefile @@ -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 index 0000000..1ea4b03 --- /dev/null +++ b/kdev-gpio-dt/dt.sh @@ -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 index 0000000..4c8493f --- /dev/null +++ b/kdev-gpio-dt/gpiodt.dts @@ -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 index 0000000..1b1fce3 --- /dev/null +++ b/kdev-gpio-dt/kdev_gpio.c @@ -0,0 +1,49 @@ +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + +#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 -- 2.43.0