From cfcf4b94f312eeb88e462f3eec88b932d672ef3d Mon Sep 17 00:00:00 2001 From: lonkaars Date: Tue, 14 May 2024 17:25:12 +0200 Subject: WIP char->platform driver --- driver/Makefile | 2 +- driver/config.h | 2 - driver/main.c | 124 ++++++++++++++++++------------------------------------ driver/platform.c | 12 ++++++ driver/platform.h | 8 ++++ 5 files changed, 61 insertions(+), 87 deletions(-) create mode 100644 driver/platform.c create mode 100644 driver/platform.h (limited to 'driver') 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 // values from 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 #include -#include #include +#include +#include +#include -#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< 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<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 +#include + +int lork_probe(struct platform_device*); +int lork_remove(struct platform_device*); + -- cgit v1.2.3