blob: da20028e7c468bc66a870179e464d5a80fc979e1 [file] [log] [blame]
Greg Kroah-Hartmanc16854c2014-08-12 12:00:16 +08001/*
2 * GPIO Greybus driver.
3 *
4 * Copyright 2014 Google Inc.
5 *
6 * Released under the GPLv2 only.
7 */
8
9#include <linux/kernel.h>
10#include <linux/module.h>
11#include <linux/slab.h>
12#include <linux/gpio.h>
13#include "greybus.h"
14
Greg Kroah-Hartman199d68d2014-08-30 16:20:22 -070015struct gb_gpio_device {
Greg Kroah-Hartmanc16854c2014-08-12 12:00:16 +080016 struct gpio_chip chip;
Alex Eldere1e9dbd2014-10-01 21:54:11 -050017 struct gb_module *gmod;
Greg Kroah-Hartmane9023d22014-08-12 14:41:49 +080018 struct gpio_chip *gpio;
Greg Kroah-Hartmanc16854c2014-08-12 12:00:16 +080019 // FIXME - some lock?
20};
21
Greg Kroah-Hartman6584c8a2014-09-01 13:31:31 -070022static const struct greybus_module_id id_table[] = {
Greg Kroah-Hartmanc16854c2014-08-12 12:00:16 +080023 { GREYBUS_DEVICE(0x44, 0x44) }, /* make shit up */
24 { }, /* terminating NULL entry */
25};
26
27static int direction_input(struct gpio_chip *gpio, unsigned nr)
28{
Greg Kroah-Hartman199d68d2014-08-30 16:20:22 -070029 //struct gb_gpio_device *gb_gpio_dev = container_of(gpio, struct gb_gpio_device, chip);
Greg Kroah-Hartmanc16854c2014-08-12 12:00:16 +080030
31 // FIXME - do something there
32 return 0;
33}
34
35static int direction_output(struct gpio_chip *gpio, unsigned nr, int val)
36{
37 // FIXME - do something there
38 return 0;
39}
40
41static int gpio_get(struct gpio_chip *gpio, unsigned nr)
42{
43 // FIXME - do something there
44 return 0;
45}
46
Greg Kroah-Hartmane9023d22014-08-12 14:41:49 +080047static void gpio_set(struct gpio_chip *gpio, unsigned nr, int val)
Greg Kroah-Hartmanc16854c2014-08-12 12:00:16 +080048{
49 // FIXME - do something there
Greg Kroah-Hartmanc16854c2014-08-12 12:00:16 +080050}
51
Alex Eldere1e9dbd2014-10-01 21:54:11 -050052int gb_gpio_probe(struct gb_module *gmod,
Greg Kroah-Hartman6584c8a2014-09-01 13:31:31 -070053 const struct greybus_module_id *id)
Greg Kroah-Hartmanc16854c2014-08-12 12:00:16 +080054{
Greg Kroah-Hartman199d68d2014-08-30 16:20:22 -070055 struct gb_gpio_device *gb_gpio;
Greg Kroah-Hartmanc16854c2014-08-12 12:00:16 +080056 struct gpio_chip *gpio;
Alex Elder778c69c2014-09-22 19:19:03 -050057 struct device *dev = &gmod->dev;
Greg Kroah-Hartmane9023d22014-08-12 14:41:49 +080058 int retval;
Greg Kroah-Hartmanc16854c2014-08-12 12:00:16 +080059
Greg Kroah-Hartman8bf23e82014-08-30 17:18:04 -070060 gb_gpio = kzalloc(sizeof(*gb_gpio), GFP_KERNEL);
Greg Kroah-Hartmane9023d22014-08-12 14:41:49 +080061 if (!gb_gpio)
Greg Kroah-Hartmanc16854c2014-08-12 12:00:16 +080062 return -ENOMEM;
Alex Elder778c69c2014-09-22 19:19:03 -050063 gb_gpio->gmod = gmod;
Greg Kroah-Hartmanc16854c2014-08-12 12:00:16 +080064
Greg Kroah-Hartmane9023d22014-08-12 14:41:49 +080065 gpio = &gb_gpio->chip;
Greg Kroah-Hartmanc16854c2014-08-12 12:00:16 +080066
67 gpio->label = "greybus_gpio";
68 gpio->owner = THIS_MODULE;
69 gpio->direction_input = direction_input;
70 gpio->direction_output = direction_output;
71 gpio->get = gpio_get;
72 gpio->set = gpio_set;
73 gpio->dbg_show = NULL;
74 gpio->base = 0; // FIXME!!!
75 gpio->ngpio = 42; // FIXME!!!
76 gpio->can_sleep = false; // FIXME!!!
77
Alex Elder778c69c2014-09-22 19:19:03 -050078 gmod->gb_gpio_dev = gb_gpio;
Greg Kroah-Hartmanc16854c2014-08-12 12:00:16 +080079
Greg Kroah-Hartmane9023d22014-08-12 14:41:49 +080080 retval = gpiochip_add(gpio);
Greg Kroah-Hartmanc16854c2014-08-12 12:00:16 +080081 if (retval) {
82 dev_err(dev, "Failed to register GPIO\n");
83 return retval;
84 }
85
86 return 0;
87}
88
Alex Eldere1e9dbd2014-10-01 21:54:11 -050089void gb_gpio_disconnect(struct gb_module *gmod)
Greg Kroah-Hartmanc16854c2014-08-12 12:00:16 +080090{
Greg Kroah-Hartman199d68d2014-08-30 16:20:22 -070091 struct gb_gpio_device *gb_gpio_dev;
Greg Kroah-Hartmanf91121b2014-09-11 08:22:06 -070092 int retval;
Greg Kroah-Hartmanc16854c2014-08-12 12:00:16 +080093
Alex Elder778c69c2014-09-22 19:19:03 -050094 gb_gpio_dev = gmod->gb_gpio_dev;
Alex Elder051fb042014-10-16 06:35:24 -050095 if (!gb_gpio_dev)
96 return;
Greg Kroah-Hartmanc16854c2014-08-12 12:00:16 +080097
Greg Kroah-Hartmanf91121b2014-09-11 08:22:06 -070098 retval = gpiochip_remove(&gb_gpio_dev->chip);
Greg Kroah-Hartmane5f167f2014-08-30 17:11:41 -070099 kfree(gb_gpio_dev);
Greg Kroah-Hartmanc16854c2014-08-12 12:00:16 +0800100}
101
Greg Kroah-Hartmandb6e1fd2014-08-30 16:47:26 -0700102#if 0
Greg Kroah-Hartmanc16854c2014-08-12 12:00:16 +0800103static struct greybus_driver gpio_gb_driver = {
Greg Kroah-Hartmandb6e1fd2014-08-30 16:47:26 -0700104 .probe = gb_gpio_probe,
105 .disconnect = gb_gpio_disconnect,
Greg Kroah-Hartmanc16854c2014-08-12 12:00:16 +0800106 .id_table = id_table,
107};
108
109module_greybus_driver(gpio_gb_driver);
110MODULE_LICENSE("GPL");
111MODULE_DESCRIPTION("Greybus GPIO driver");
112MODULE_AUTHOR("Greg Kroah-Hartman <gregkh@linuxfoundation.org>");
Greg Kroah-Hartmandb6e1fd2014-08-30 16:47:26 -0700113#endif