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)
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;
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);
}
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;
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)
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)
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)
#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
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);
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)
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)