aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2024-05-14 17:25:12 +0200
committerlonkaars <loek@pipeframe.xyz>2024-05-14 17:25:12 +0200
commitcfcf4b94f312eeb88e462f3eec88b932d672ef3d (patch)
tree798ffcc8d334e0623b6a9c9e3fcf287829387631
parent773e13be02f1f42c8ac578031282c9455be023bb (diff)
WIP char->platform driver
-rw-r--r--driver/Makefile2
-rw-r--r--driver/config.h2
-rw-r--r--driver/main.c124
-rw-r--r--driver/platform.c12
-rw-r--r--driver/platform.h8
-rw-r--r--dts/am335x-boneblack-uboot.dts8
6 files changed, 66 insertions, 90 deletions
diff --git a/driver/Makefile b/driver/Makefile
index d968e31..7de7424 100644
--- a/driver/Makefile
+++ b/driver/Makefile
@@ -7,7 +7,7 @@ KERNEL := /lib/modules/$(RELEASE)/build
# system, see [kbuild-obj-var] and [kbuild-module-makefile] in ../readme.md
obj-m += lork.o
lork-y += main.o
-lork-y += fopdrv.o
+lork-y += platform.o
all:
$(MAKE) -C $(KERNEL) M=$(PWD) modules
diff --git a/driver/config.h b/driver/config.h
index 87eb81f..147e2f3 100644
--- a/driver/config.h
+++ b/driver/config.h
@@ -1,7 +1,5 @@
#pragma once
-#define DRV_NAME "lork"
-
#include <linux/types.h>
// values from <https://www.ti.com/lit/ug/spruh73q/spruh73q.pdf>
diff --git a/driver/main.c b/driver/main.c
index 226f158..a322616 100644
--- a/driver/main.c
+++ b/driver/main.c
@@ -1,98 +1,54 @@
-#include <linux/cdev.h>
#include <linux/init.h>
-#include <linux/module.h>
#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
-#include "fopdrv.h"
-#include "config.h"
+#include "platform.h"
-struct cdev *cdev;
-struct device *dev;
-struct class *class;
-dev_t node;
-struct file_operations fops = {
- .read = fop_read,
- .write = fop_write,
- .open = fop_open,
- .release = fop_release,
+static const struct of_device_id lork_ids[] = {
+ { .compatible = "gpio-extern" },
+ {},
};
-static int mod_init(void) {
- int err;
-
- err = alloc_chrdev_region(&node, 0, 1, DRV_NAME);
- if (err < 0) {
- printk(KERN_ERR "alloc_chrdev_region error %d\n", err);
- goto return_err;
- }
-
- class = class_create(DRV_NAME);
- if (IS_ERR_OR_NULL(class)) {
- err = PTR_ERR(class);
- printk(KERN_ERR "class_create error %d\n", err);
- goto free_class;
- }
-
- cdev = cdev_alloc();
- if (!cdev) {
- err = ENOMEM;
- goto free_cdev;
- }
-
- cdev->ops = &fops;
- cdev_init(cdev, &fops);
- err = cdev_add(cdev, node, 1);
- if (err < 0) {
- printk(KERN_ERR "cdev_add error %d\n", err);
- goto free_cdev;
- }
-
- dev = device_create(class, NULL, node, NULL, DRV_NAME);
- if (IS_ERR_OR_NULL(dev)) {
- err = PTR_ERR(dev);
- printk(KERN_ERR "device_create error %d\n", err);
- goto free_device;
+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),
}
+};
- // configure gpio mux
- uint32_t* conf_gpmc_a3 = ioremap(TI_AM335X_CM_GPMC_A3_ADDR, sizeof(ti_am335x_word_t));
- if (conf_gpmc_a3 == NULL)
- return -EINVAL;
- barrier();
- uint32_t val = ioread32(conf_gpmc_a3); rmb();
- val &= ~0x7;
- val |= 0x7;
- iowrite32(val, conf_gpmc_a3); wmb();
- iounmap(conf_gpmc_a3);
-
- // configure output pin
- ti_am335x_word_t* gpio1 = ioremap(TI_AM335X_GPIO1_ADDR, GPIO_REG_SIZE);
- barrier();
- ti_am335x_word_t oe_reg = ioread32(gpio1 + GPIO_OE); rmb();
- oe_reg &= ~(1<<PIN); // 0=output
- iowrite32(oe_reg, gpio1 + GPIO_OE); wmb();
- iounmap(gpio1);
-
- // printk("%s() -> 0 (%d:%d)\n", __PRETTY_FUNCTION__, MAJOR(node), MINOR(node));
-
- return 0;
-
-free_device:
- device_destroy(class, node);
-free_cdev:
- cdev_del(cdev);
-free_class:
- class_destroy(class);
-return_err:
- // printk("%s() -> %d\n", __PRETTY_FUNCTION__, err);
- return err;
+static int mod_init(void) {
+ printk("%s()\n", __PRETTY_FUNCTION__);
+
+ // // configure gpio mux
+ // uint32_t* conf_gpmc_a3 = ioremap(TI_AM335X_CM_GPMC_A3_ADDR, sizeof(ti_am335x_word_t));
+ // if (conf_gpmc_a3 == NULL)
+ // return -EINVAL;
+ // barrier();
+ // uint32_t val = ioread32(conf_gpmc_a3); rmb();
+ // val &= ~0x7;
+ // val |= 0x7;
+ // iowrite32(val, conf_gpmc_a3); wmb();
+ // iounmap(conf_gpmc_a3);
+
+ // // configure output pin
+ // ti_am335x_word_t* gpio1 = ioremap(TI_AM335X_GPIO1_ADDR, GPIO_REG_SIZE);
+ // barrier();
+ // ti_am335x_word_t oe_reg = ioread32(gpio1 + GPIO_OE); rmb();
+ // oe_reg &= ~(1<<PIN); // 0=output
+ // iowrite32(oe_reg, gpio1 + GPIO_OE); wmb();
+ // iounmap(gpio1);
+
+ return platform_driver_register(&lork_driver);
}
static void mod_exit(void) {
- device_destroy(class, node);
- cdev_del(cdev);
- class_destroy(class);
- // printk("%s()\n", __PRETTY_FUNCTION__);
+ printk("%s()\n", __PRETTY_FUNCTION__);
+ platform_driver_unregister(&lork_driver);
}
module_init(mod_init);
diff --git a/driver/platform.c b/driver/platform.c
new file mode 100644
index 0000000..85aefec
--- /dev/null
+++ b/driver/platform.c
@@ -0,0 +1,12 @@
+#include "platform.h"
+
+int lork_probe(struct platform_device* dev) {
+ printk("%s(%s)\n", __PRETTY_FUNCTION__, dev->name);
+ return 0;
+}
+
+int lork_remove(struct platform_device* dev) {
+ printk("%s(%s)\n", __PRETTY_FUNCTION__, dev->name);
+ return 0;
+}
+
diff --git a/driver/platform.h b/driver/platform.h
new file mode 100644
index 0000000..3faaad5
--- /dev/null
+++ b/driver/platform.h
@@ -0,0 +1,8 @@
+#pragma once
+
+#include <linux/types.h>
+#include <linux/platform_device.h>
+
+int lork_probe(struct platform_device*);
+int lork_remove(struct platform_device*);
+
diff --git a/dts/am335x-boneblack-uboot.dts b/dts/am335x-boneblack-uboot.dts
index 8d140c0..e02de51 100644
--- a/dts/am335x-boneblack-uboot.dts
+++ b/dts/am335x-boneblack-uboot.dts
@@ -1,4 +1,4 @@
-#include <dt-bindings/gpio/gpio.h>
+#include <dt-bindings/gpio/gpio.h> // GPIO_ACTIVE_HIGH
/dts-v1/;
@@ -3893,9 +3893,11 @@
vmmcsd_fixed = "/fixedregulator0";
};
- led_extern {
+ // this section is visible at runtime under
+ // /sys/firmware/devicetree/base/lork
+ lork {
compatible = "gpio-extern";
- label = "lork-gpio";
+ // label = "lork-gpio";
gpios = <&gpio1 18 GPIO_ACTIVE_HIGH>;
};
};