greybus: start moving the function types into the greybus core
authorGreg Kroah-Hartman <greg@kroah.com>
Sat, 30 Aug 2014 23:20:22 +0000 (16:20 -0700)
committerGreg Kroah-Hartman <greg@kroah.com>
Sat, 30 Aug 2014 23:20:22 +0000 (16:20 -0700)
drivers/staging/greybus/Makefile
drivers/staging/greybus/core.c
drivers/staging/greybus/gpio-gb.c
drivers/staging/greybus/greybus.h
drivers/staging/greybus/i2c-gb.c
drivers/staging/greybus/sdio-gb.c
drivers/staging/greybus/uart-gb.c

index b84ff76..2e3212b 100644 (file)
@@ -1,7 +1,6 @@
-greybus-y := core.o gbuf.o
+greybus-y := core.o gbuf.o i2c-gb.o
 
 obj-m += greybus.o
-obj-m += i2c-gb.o
 obj-m += sdio-gb.o
 obj-m += gpio-gb.o
 obj-m += uart-gb.o
index 87148cd..ccc4e35 100644 (file)
@@ -149,5 +149,29 @@ void greybus_deregister(struct greybus_driver *driver)
 }
 EXPORT_SYMBOL_GPL(greybus_deregister);
 
+
+static int new_device(struct greybus_device *gdev,
+                     const struct greybus_device_id *id)
+{
+       int retval;
+
+       /* Allocate all of the different "sub device types" for this device */
+       retval = gb_i2c_probe(gdev, id);
+       return 0;
+}
+
+
+int __init gb_init(void)
+{
+       return 0;
+}
+
+void __exit gb_exit(void)
+{
+}
+
+module_init(gb_init);
+module_exit(gb_exit);
+
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Greg Kroah-Hartman <gregkh@linuxfoundation.org>");
index 0cbabb5..990a74d 100644 (file)
@@ -13,7 +13,7 @@
 #include <linux/gpio/driver.h>
 #include "greybus.h"
 
-struct gb_gpio {
+struct gb_gpio_device {
        struct gpio_chip chip;
        struct greybus_device *gdev;
        struct gpio_chip *gpio;
@@ -27,7 +27,7 @@ static const struct greybus_device_id id_table[] = {
 
 static int direction_input(struct gpio_chip *gpio, unsigned nr)
 {
-//     struct gb_gpio *gb_gpio = container_of(gpio, struct gb_gpio, chip);
+       //struct gb_gpio_device *gb_gpio_dev = container_of(gpio, struct gb_gpio_device, chip);
 
        // FIXME - do something there
        return 0;
@@ -53,7 +53,7 @@ static void gpio_set(struct gpio_chip *gpio, unsigned nr, int val)
 
 static int gpio_gb_probe(struct greybus_device *gdev, const struct greybus_device_id *id)
 {
-       struct gb_gpio *gb_gpio;
+       struct gb_gpio_device *gb_gpio;
        struct gpio_chip *gpio;
        struct device *dev = &gdev->dev;
        int retval;
@@ -89,11 +89,11 @@ static int gpio_gb_probe(struct greybus_device *gdev, const struct greybus_devic
 
 static void gpio_gb_disconnect(struct greybus_device *gdev)
 {
-       struct gb_gpio *gb_gpio;
+       struct gb_gpio_device *gb_gpio_dev;
 
-       gb_gpio = greybus_get_drvdata(gdev);
+       gb_gpio_dev = greybus_get_drvdata(gdev);
 
-       gpiochip_remove(&gb_gpio->chip);
+       gpiochip_remove(&gb_gpio_dev->chip);
 }
 
 static struct greybus_driver gpio_gb_driver = {
index 51b9f5b..3137668 100644 (file)
@@ -72,15 +72,44 @@ struct gbuf {
  */
 #define GBUF_FREE_BUFFER       BIT(0)  /* Free the transfer buffer with the gbuf */
 
+/* For SP1 hardware, we are going to "hardcode" each device to have all logical
+ * blocks in order to be able to address them as one unified "unit".  Then
+ * higher up layers will then be able to talk to them as one logical block and
+ * properly know how they are hooked together (i.e. which i2c port is on the
+ * same module as the gpio pins, etc.)
+ *
+ * So, put the "private" data structures here in greybus.h and link to them off
+ * of the "main" greybus_device structure.
+ */
+
+struct gb_i2c_device;
+struct gb_gpio_device;
+struct gb_sdio_host;
+struct gb_tty;
+struct gb_usb_device;
 
 struct greybus_device {
        struct device dev;
        struct greybus_descriptor descriptor;
        int num_cport;
        struct cport cport[0];
+
+       struct gb_i2c_device *gb_i2c_dev;
+       struct gb_gpio_device *gb_gpio_dev;
+       struct gb_sdio_host *gb_sdio_host;
+       struct gb_tty *gb_tty;
+       struct gb_usb_device *gb_usb_dev;
 };
 #define to_greybus_device(d) container_of(d, struct greybus_device, dev)
 
+/*
+ * Because we are allocating a data structure per "type" in the greybus device,
+ * we have static functions for this, not "dynamic" drivers like we really
+ * should in the end.
+ */
+int gb_i2c_probe(struct greybus_device *gdev, const struct greybus_device_id *id);
+void gb_i2c_disconnect(struct greybus_device *gdev);
+
 
 struct gbuf *greybus_alloc_gbuf(struct greybus_device *gdev,
                                struct cport *cport,
index 7fcbcef..929243e 100644 (file)
@@ -12,7 +12,7 @@
 #include <linux/i2c.h>
 #include "greybus.h"
 
-struct i2c_gb_data {
+struct gb_i2c_device {
        struct i2c_adapter *adapter;
        struct greybus_device *gdev;
 };
@@ -32,11 +32,11 @@ static s32 i2c_gb_access(struct i2c_adapter *adap, u16 addr,
                         unsigned short flags, char read_write, u8 command,
                         int size, union i2c_smbus_data *data)
 {
-       struct i2c_gb_data *i2c_gb_data;
+       struct gb_i2c_device *i2c_gb_dev;
        struct greybus_device *gdev;
 
-       i2c_gb_data = i2c_get_adapdata(adap);
-       gdev = i2c_gb_data->gdev;
+       i2c_gb_dev = i2c_get_adapdata(adap);
+       gdev = i2c_gb_dev->gdev;
 
        // FIXME - do the actual work of sending a i2c message here...
        switch (size) {
@@ -75,22 +75,23 @@ static const struct i2c_algorithm smbus_algorithm = {
        .functionality  = i2c_gb_func,
 };
 
-static int i2c_gb_probe(struct greybus_device *gdev, const struct greybus_device_id *id)
+int gb_i2c_probe(struct greybus_device *gdev,
+                const struct greybus_device_id *id)
 {
-       struct i2c_gb_data *i2c_gb_data;
+       struct gb_i2c_device *i2c_gb_dev;
        struct i2c_adapter *adapter;
        int retval;
 
-       i2c_gb_data = kzalloc(sizeof(*i2c_gb_data), GFP_KERNEL);
-       if (!i2c_gb_data)
+       i2c_gb_dev = kzalloc(sizeof(*i2c_gb_dev), GFP_KERNEL);
+       if (!i2c_gb_dev)
                return -ENOMEM;
        adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
        if (!adapter) {
-               kfree(i2c_gb_data);
+               kfree(i2c_gb_dev);
                return -ENOMEM;
        }
 
-       i2c_set_adapdata(adapter, i2c_gb_data);
+       i2c_set_adapdata(adapter, i2c_gb_dev);
        adapter->owner = THIS_MODULE;
        adapter->class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
        adapter->algo = &smbus_algorithm;
@@ -103,33 +104,35 @@ static int i2c_gb_probe(struct greybus_device *gdev, const struct greybus_device
                goto error;
        }
 
-       i2c_gb_data->gdev = gdev;
-       i2c_gb_data->adapter = adapter;
+       i2c_gb_dev->gdev = gdev;
+       i2c_gb_dev->adapter = adapter;
 
-       greybus_set_drvdata(gdev, i2c_gb_data);
+       greybus_set_drvdata(gdev, i2c_gb_dev);
        return 0;
 error:
        kfree(adapter);
-       kfree(i2c_gb_data);
+       kfree(i2c_gb_dev);
        return retval;
 }
 
-static void i2c_gb_disconnect(struct greybus_device *gdev)
+void gb_i2c_disconnect(struct greybus_device *gdev)
 {
-       struct i2c_gb_data *i2c_gb_data;
+       struct gb_i2c_device *i2c_gb_dev;
 
-       i2c_gb_data = greybus_get_drvdata(gdev);
-       i2c_del_adapter(i2c_gb_data->adapter);
-       kfree(i2c_gb_data->adapter);
-       kfree(i2c_gb_data);
+       i2c_gb_dev = greybus_get_drvdata(gdev);
+       i2c_del_adapter(i2c_gb_dev->adapter);
+       kfree(i2c_gb_dev->adapter);
+       kfree(i2c_gb_dev);
 }
 
+#if 0
 static struct greybus_driver i2c_gb_driver = {
-       .probe =        i2c_gb_probe,
-       .disconnect =   i2c_gb_disconnect,
+       .probe =        gb_i2c_probe,
+       .disconnect =   gb_i2c_disconnect,
        .id_table =     id_table,
 };
 
 module_greybus_driver(i2c_gb_driver);
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Greg Kroah-Hartman <gregkh@linuxfoundation.org>");
+#endif
index f92ab1b..8521b06 100644 (file)
@@ -12,7 +12,7 @@
 #include <linux/mmc/host.h>
 #include "greybus.h"
 
-struct sd_gb_host {
+struct gb_sdio_host {
        struct mmc_host *mmc;
        struct mmc_request *mrq;
        // FIXME - some lock?
@@ -48,9 +48,9 @@ static const struct mmc_host_ops gb_sd_ops = {
 static int sd_gb_probe(struct greybus_device *gdev, const struct greybus_device_id *id)
 {
        struct mmc_host *mmc;
-       struct sd_gb_host *host;
+       struct gb_sdio_host *host;
 
-       mmc = mmc_alloc_host(sizeof(struct sd_gb_host), &gdev->dev);
+       mmc = mmc_alloc_host(sizeof(struct gb_sdio_host), &gdev->dev);
        if (!mmc)
                return -ENOMEM;
 
@@ -67,7 +67,7 @@ static int sd_gb_probe(struct greybus_device *gdev, const struct greybus_device_
 static void sd_gb_disconnect(struct greybus_device *gdev)
 {
        struct mmc_host *mmc;
-       struct sd_gb_host *host;
+       struct gb_sdio_host *host;
 
        host = greybus_get_drvdata(gdev);
        mmc = host->mmc;
index 4a54e9e..839ea2d 100644 (file)
@@ -344,27 +344,22 @@ static int gb_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
                        unsigned long arg)
 {
        struct gb_tty *gb_tty = tty->driver_data;
-       int retval = -ENOIOCTLCMD;
 
        switch (cmd) {
        case TIOCGSERIAL:
-               retval = get_serial_info(gb_tty,
-                                        (struct serial_struct __user *)arg);
-               break;
+               return get_serial_info(gb_tty,
+                                      (struct serial_struct __user *)arg);
        case TIOCSSERIAL:
-               retval = set_serial_info(gb_tty,
-                                        (struct serial_struct __user *)arg);
-               break;
+               return set_serial_info(gb_tty,
+                                      (struct serial_struct __user *)arg);
        case TIOCMIWAIT:
-               retval = wait_serial_change(gb_tty, arg);
-               break;
+               return wait_serial_change(gb_tty, arg);
        case TIOCGICOUNT:
-               retval = get_serial_usage(gb_tty,
-                                         (struct serial_icounter_struct __user *)arg);
-               break;
+               return get_serial_usage(gb_tty,
+                                       (struct serial_icounter_struct __user *)arg);
        }
 
-       return retval;
+       return -ENOIOCTLCMD;
 }