diff options
author | lonkaars <loek@pipeframe.xyz> | 2024-05-14 17:25:12 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2024-05-14 17:25:12 +0200 |
commit | cfcf4b94f312eeb88e462f3eec88b932d672ef3d (patch) | |
tree | 798ffcc8d334e0623b6a9c9e3fcf287829387631 /driver/main.c | |
parent | 773e13be02f1f42c8ac578031282c9455be023bb (diff) |
WIP char->platform driver
Diffstat (limited to 'driver/main.c')
-rw-r--r-- | driver/main.c | 124 |
1 files changed, 40 insertions, 84 deletions
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); |