From: Alex Elder Date: Wed, 5 Nov 2014 22:12:54 +0000 (-0600) Subject: greybus: move methods into protocol X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=5d9fd7e1ba801ff83bb657ad364581947400898c;p=GitHub%2Fmoto-9609%2Fandroid_kernel_motorola_exynos9610.git greybus: move methods into protocol Get rid of the connection handler structure, and instead put the methods that were there into the protocol structure. Eliminate the big switch statement in connection_init() and just call the connection's protocol's init function there directly. Signed-off-by: Alex Elder Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/greybus/battery-gb.c b/drivers/staging/greybus/battery-gb.c index 457daf700543..a4015673bf4c 100644 --- a/drivers/staging/greybus/battery-gb.c +++ b/drivers/staging/greybus/battery-gb.c @@ -400,15 +400,12 @@ static void gb_battery_connection_exit(struct gb_connection *connection) kfree(gb); } -struct gb_connection_handler gb_battery_connection_handler = { - .connection_init = gb_battery_connection_init, - .connection_exit = gb_battery_connection_exit, -}; - static struct gb_protocol battery_protocol = { .id = GREYBUS_PROTOCOL_BATTERY, .major = 0, .minor = 1, + .connection_init = gb_battery_connection_init, + .connection_exit = gb_battery_connection_exit, }; bool gb_battery_protocol_init(void) diff --git a/drivers/staging/greybus/connection.c b/drivers/staging/greybus/connection.c index e3000f7eb799..586457f027de 100644 --- a/drivers/staging/greybus/connection.c +++ b/drivers/staging/greybus/connection.c @@ -267,45 +267,18 @@ void gb_connection_err(struct gb_connection *connection, const char *fmt, ...) va_end(args); } -/* - * XXX Protocols should have a set of function pointers: - * ->init (called here, to initialize the device) - * ->input_handler - * ->exit (reverse of init) - */ int gb_connection_init(struct gb_connection *connection) { int ret; - /* Need to enable the connection to initialize it */ - connection->state = GB_CONNECTION_STATE_ENABLED; - switch (connection->protocol->id) { - case GREYBUS_PROTOCOL_I2C: - connection->handler = &gb_i2c_connection_handler; - break; - case GREYBUS_PROTOCOL_GPIO: - connection->handler = &gb_gpio_connection_handler; - break; - case GREYBUS_PROTOCOL_BATTERY: - connection->handler = &gb_battery_connection_handler; - break; - case GREYBUS_PROTOCOL_UART: - connection->handler = &gb_uart_connection_handler; - break; - case GREYBUS_PROTOCOL_CONTROL: - case GREYBUS_PROTOCOL_AP: - case GREYBUS_PROTOCOL_HID: - case GREYBUS_PROTOCOL_LED: - case GREYBUS_PROTOCOL_VENDOR: - default: - gb_connection_err(connection, "unimplemented protocol %hhu", - connection->protocol->id); - ret = -ENXIO; - break; + if (!connection->protocol) { + gb_connection_err(connection, "uninitialized connection"); + return -EIO; } - ret = connection->handler->connection_init(connection); - + /* Need to enable the connection to initialize it */ + connection->state = GB_CONNECTION_STATE_ENABLED; + ret = connection->protocol->connection_init(connection); if (ret) connection->state = GB_CONNECTION_STATE_ERROR; @@ -314,10 +287,10 @@ int gb_connection_init(struct gb_connection *connection) void gb_connection_exit(struct gb_connection *connection) { - if (!connection->handler) { + if (!connection->protocol) { gb_connection_err(connection, "uninitialized connection"); return; } connection->state = GB_CONNECTION_STATE_DESTROYING; - connection->handler->connection_exit(connection); + connection->protocol->connection_exit(connection); } diff --git a/drivers/staging/greybus/connection.h b/drivers/staging/greybus/connection.h index ea54334238bd..893c02af3710 100644 --- a/drivers/staging/greybus/connection.h +++ b/drivers/staging/greybus/connection.h @@ -21,15 +21,6 @@ enum gb_connection_state { GB_CONNECTION_STATE_DESTROYING = 4, }; -struct gb_connection; -typedef int (*gb_connection_init_t)(struct gb_connection *); -typedef void (*gb_connection_exit_t)(struct gb_connection *); - -struct gb_connection_handler { - gb_connection_init_t connection_init; - gb_connection_exit_t connection_exit; -}; - struct gb_connection { struct greybus_host_device *hd; struct gb_interface *interface; @@ -48,8 +39,6 @@ struct gb_connection { struct rb_root pending; /* awaiting reponse */ atomic_t op_cycle; - struct gb_connection_handler *handler; - void *private; }; #define to_gb_connection(d) container_of(d, struct gb_connection, dev) diff --git a/drivers/staging/greybus/gpio-gb.c b/drivers/staging/greybus/gpio-gb.c index 242b91a99d22..a4ee35671434 100644 --- a/drivers/staging/greybus/gpio-gb.c +++ b/drivers/staging/greybus/gpio-gb.c @@ -792,15 +792,12 @@ static void gb_gpio_connection_exit(struct gb_connection *connection) kfree(gb_gpio_controller); } -struct gb_connection_handler gb_gpio_connection_handler = { - .connection_init = gb_gpio_connection_init, - .connection_exit = gb_gpio_connection_exit, -}; - static struct gb_protocol gpio_protocol = { .id = GREYBUS_PROTOCOL_GPIO, .major = 0, .minor = 1, + .connection_init = gb_gpio_connection_init, + .connection_exit = gb_gpio_connection_exit, }; bool gb_gpio_protocol_init(void) diff --git a/drivers/staging/greybus/i2c-gb.c b/drivers/staging/greybus/i2c-gb.c index c8fae17d4b77..60db15ee364d 100644 --- a/drivers/staging/greybus/i2c-gb.c +++ b/drivers/staging/greybus/i2c-gb.c @@ -518,15 +518,12 @@ static void gb_i2c_connection_exit(struct gb_connection *connection) kfree(gb_i2c_dev); } -struct gb_connection_handler gb_i2c_connection_handler = { - .connection_init = gb_i2c_connection_init, - .connection_exit = gb_i2c_connection_exit, -}; - static struct gb_protocol i2c_protocol = { .id = GREYBUS_PROTOCOL_I2C, .major = 0, .minor = 1, + .connection_init = gb_i2c_connection_init, + .connection_exit = gb_i2c_connection_exit, }; bool gb_i2c_protocol_init(void) diff --git a/drivers/staging/greybus/protocol.h b/drivers/staging/greybus/protocol.h index c2adfdca8bf7..32178f1f2671 100644 --- a/drivers/staging/greybus/protocol.h +++ b/drivers/staging/greybus/protocol.h @@ -11,6 +11,9 @@ #include "greybus.h" +typedef int (*gb_connection_init_t)(struct gb_connection *); +typedef void (*gb_connection_exit_t)(struct gb_connection *); + /* * Protocols having the same id but different major and/or minor * version numbers are treated as distinct protocols. If it makes @@ -23,6 +26,9 @@ struct gb_protocol { u8 count; struct list_head links; /* global list */ + + gb_connection_init_t connection_init; + gb_connection_exit_t connection_exit; }; bool gb_protocol_register(struct gb_protocol *protocol); diff --git a/drivers/staging/greybus/sdio-gb.c b/drivers/staging/greybus/sdio-gb.c index 8fbfbca37c48..9e5fb8f26425 100644 --- a/drivers/staging/greybus/sdio-gb.c +++ b/drivers/staging/greybus/sdio-gb.c @@ -77,15 +77,12 @@ static void gb_sdio_connection_exit(struct gb_connection *connection) connection->private = NULL; } -struct gb_connection_handler gb_sdio_connection_handler = { - .connection_init = gb_sdio_connection_init, - .connection_exit = gb_sdio_connection_exit, -}; - static struct gb_protocol sdio_protocol = { .id = GREYBUS_PROTOCOL_SDIO, .major = 0, .minor = 1, + .connection_init = gb_sdio_connection_init, + .connection_exit = gb_sdio_connection_exit, }; bool gb_sdio_protocol_init(void) diff --git a/drivers/staging/greybus/uart-gb.c b/drivers/staging/greybus/uart-gb.c index 5596644e952b..56db8911d800 100644 --- a/drivers/staging/greybus/uart-gb.c +++ b/drivers/staging/greybus/uart-gb.c @@ -520,15 +520,12 @@ static void gb_tty_exit(void) unregister_chrdev_region(MKDEV(major, minor), GB_NUM_MINORS); } -struct gb_connection_handler gb_uart_connection_handler = { - .connection_init = gb_uart_connection_init, - .connection_exit = gb_uart_connection_exit, -}; - static struct gb_protocol uart_protocol = { .id = GREYBUS_PROTOCOL_UART, .major = 0, .minor = 1, + .connection_init = gb_uart_connection_init, + .connection_exit = gb_uart_connection_exit, }; bool gb_uart_protocol_init(void)