greybus: gpb: Create a "GP Bridge" kernel module
authorGreg Kroah-Hartman <greg@kroah.com>
Wed, 24 Dec 2014 21:01:43 +0000 (13:01 -0800)
committerGreg Kroah-Hartman <greg@kroah.com>
Fri, 2 Jan 2015 21:05:42 +0000 (13:05 -0800)
This bundles together the existing GP Bridged PHY protocols that were
part of the Greybus core: USB, UART, SDIO, PWM, and GPIO.  This is now a
stand-alone kernel module.  More logic will be moving here in the future
to handle bridged devices.

Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
Reviewed-by: Alex Elder <elder@linaro.org>
drivers/staging/greybus/Makefile
drivers/staging/greybus/core.c
drivers/staging/greybus/gpb.c [new file with mode: 0644]
drivers/staging/greybus/protocol.c
drivers/staging/greybus/protocol.h

index 79cb193..5d73aed 100644 (file)
@@ -7,14 +7,17 @@ greybus-y :=  core.o          \
                bundle.o        \
                connection.o    \
                protocol.o      \
-               operation.o     \
-               gpio-gb.o       \
-               pwm-gb.o        \
+               operation.o
+
+gpbridge-y :=  gpb.o           \
                sdio-gb.o       \
                uart-gb.o       \
+               pwm-gb.o        \
+               gpio-gb.o       \
                usb-gb.o
 
 obj-m += greybus.o
+obj-m += gpbridge.o
 obj-m += i2c-gb.o
 obj-m += vibrator-gb.o
 obj-m += battery-gb.o
index f6ca89a..ee8bba5 100644 (file)
@@ -233,17 +233,8 @@ static int __init gb_init(void)
                goto error_operation;
        }
 
-       if (!gb_protocol_init()) {
-               /* This only fails for duplicate protocol registration */
-               retval = -EEXIST;
-               pr_err("gb_protocol_init failed\n");
-               goto error_protocol;
-       }
-
        return 0;       /* Success */
 
-error_protocol:
-       gb_operation_exit();
 error_operation:
        gb_ap_exit();
 error_ap:
@@ -256,7 +247,6 @@ error_bus:
 
 static void __exit gb_exit(void)
 {
-       gb_protocol_exit();
        gb_operation_exit();
        gb_ap_exit();
        bus_unregister(&greybus_bus_type);
diff --git a/drivers/staging/greybus/gpb.c b/drivers/staging/greybus/gpb.c
new file mode 100644 (file)
index 0000000..0c4f46c
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Greybus GP Bridge driver
+ *
+ * Copyright 2014 Google Inc.
+ * Copyright 2014 Linaro Ltd.
+ *
+ * Released under the GPLv2 only.
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <linux/types.h>
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/kernel.h>
+#include <linux/slab.h>
+#include <linux/device.h>
+
+#include "greybus.h"
+
+
+static int __init gpbridge_init(void)
+{
+       if (gb_gpio_protocol_init()) {
+               pr_err("error initializing gpio protocol\n");
+               goto error_gpio;
+       }
+       if (gb_pwm_protocol_init()) {
+               pr_err("error initializing pwm protocol\n");
+               goto error_pwm;
+       }
+       if (gb_uart_protocol_init()) {
+               pr_err("error initializing uart protocol\n");
+               goto error_uart;
+       }
+       if (gb_sdio_protocol_init()) {
+               pr_err("error initializing sdio protocol\n");
+               goto error_sdio;
+       }
+       if (gb_usb_protocol_init()) {
+               pr_err("error initializing usb protocol\n");
+               goto error_usb;
+       }
+       return 0;
+
+error_usb:
+       gb_sdio_protocol_exit();
+error_sdio:
+       gb_uart_protocol_exit();
+error_uart:
+       gb_pwm_protocol_exit();
+error_pwm:
+       gb_gpio_protocol_exit();
+error_gpio:
+       return -EPROTO;
+}
+
+static void __exit gpbridge_exit(void)
+{
+       gb_usb_protocol_exit();
+       gb_sdio_protocol_exit();
+       gb_uart_protocol_exit();
+       gb_pwm_protocol_exit();
+       gb_gpio_protocol_exit();
+}
+
+module_init(gpbridge_init);
+module_exit(gpbridge_exit);
+
+MODULE_LICENSE("GPL");
index e32f4ac..654adbc 100644 (file)
@@ -178,38 +178,3 @@ void gb_protocol_put(struct gb_protocol *protocol)
                pr_err("protocol id %hhu version %hhu.%hhu not found\n",
                        protocol->id, major, minor);
 }
-
-bool gb_protocol_init(void)
-{
-       bool ret = true;
-
-       if (gb_gpio_protocol_init()) {
-               pr_err("error initializing gpio protocol\n");
-               ret = false;
-       }
-       if (gb_pwm_protocol_init()) {
-               pr_err("error initializing pwm protocol\n");
-               ret = false;
-       }
-       if (gb_uart_protocol_init()) {
-               pr_err("error initializing uart protocol\n");
-               ret = false;
-       }
-       if (gb_sdio_protocol_init()) {
-               pr_err("error initializing sdio protocol\n");
-               ret = false;
-       }
-       if (gb_usb_protocol_init()) {
-               pr_err("error initializing usb protocol\n");
-               ret = false;
-       }
-       return ret;
-}
-
-void gb_protocol_exit(void)
-{
-       gb_usb_protocol_exit();
-       gb_sdio_protocol_exit();
-       gb_uart_protocol_exit();
-       gb_gpio_protocol_exit();
-}
index 1acc615..1f6fd74 100644 (file)
@@ -66,9 +66,6 @@ extern void gb_sdio_protocol_exit(void);
 extern int gb_usb_protocol_init(void);
 extern void gb_usb_protocol_exit(void);
 
-bool gb_protocol_init(void);
-void gb_protocol_exit(void);
-
 #define gb_protocol_driver(__protocol)                 \
 static int __init protocol_init(void)                  \
 {                                                      \