Greg Kroah-Hartman | c8a797a | 2014-08-11 15:30:45 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Greybus "Core" |
| 3 | * |
Alex Elder | 4441f47 | 2015-05-22 12:59:16 -0500 | [diff] [blame] | 4 | * Copyright 2014-2015 Google Inc. |
| 5 | * Copyright 2014-2015 Linaro Ltd. |
Greg Kroah-Hartman | c8a797a | 2014-08-11 15:30:45 +0800 | [diff] [blame] | 6 | * |
| 7 | * Released under the GPLv2 only. |
| 8 | */ |
| 9 | |
| 10 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 11 | |
Greg Kroah-Hartman | c8a797a | 2014-08-11 15:30:45 +0800 | [diff] [blame] | 12 | #include "greybus.h" |
| 13 | |
| 14 | /* Allow greybus to be disabled at boot if needed */ |
| 15 | static bool nogreybus; |
| 16 | #ifdef MODULE |
| 17 | module_param(nogreybus, bool, 0444); |
| 18 | #else |
Viresh Kumar | 8597e6b | 2014-10-20 16:45:50 +0530 | [diff] [blame] | 19 | core_param(nogreybus, nogreybus, bool, 0444); |
Greg Kroah-Hartman | c8a797a | 2014-08-11 15:30:45 +0800 | [diff] [blame] | 20 | #endif |
| 21 | int greybus_disabled(void) |
| 22 | { |
| 23 | return nogreybus; |
| 24 | } |
| 25 | EXPORT_SYMBOL_GPL(greybus_disabled); |
| 26 | |
Alex Elder | 778c69c | 2014-09-22 19:19:03 -0500 | [diff] [blame] | 27 | static int greybus_module_match(struct device *dev, struct device_driver *drv) |
Greg Kroah-Hartman | c8a797a | 2014-08-11 15:30:45 +0800 | [diff] [blame] | 28 | { |
Viresh Kumar | 95bd99d | 2014-11-14 17:24:59 +0530 | [diff] [blame] | 29 | struct greybus_driver *driver = to_greybus_driver(drv); |
Viresh Kumar | 9f5f30e712 | 2015-04-01 20:32:04 +0530 | [diff] [blame] | 30 | struct gb_bundle *bundle = to_gb_bundle(dev); |
| 31 | const struct greybus_bundle_id *id; |
Greg Kroah-Hartman | c8a797a | 2014-08-11 15:30:45 +0800 | [diff] [blame] | 32 | |
Viresh Kumar | 9f5f30e712 | 2015-04-01 20:32:04 +0530 | [diff] [blame] | 33 | id = gb_bundle_match_id(bundle, driver->id_table); |
Greg Kroah-Hartman | c8a797a | 2014-08-11 15:30:45 +0800 | [diff] [blame] | 34 | if (id) |
| 35 | return 1; |
Viresh Kumar | 696e0cc | 2014-11-21 11:26:30 +0530 | [diff] [blame] | 36 | /* FIXME - Dynamic ids? */ |
Greg Kroah-Hartman | c8a797a | 2014-08-11 15:30:45 +0800 | [diff] [blame] | 37 | return 0; |
| 38 | } |
| 39 | |
| 40 | static int greybus_uevent(struct device *dev, struct kobj_uevent_env *env) |
| 41 | { |
Greg Kroah-Hartman | df67155 | 2014-12-21 14:10:26 -0800 | [diff] [blame] | 42 | struct gb_module *module = NULL; |
Greg Kroah-Hartman | 4ab9b3c | 2014-12-19 14:56:31 -0800 | [diff] [blame] | 43 | struct gb_interface *intf = NULL; |
Greg Kroah-Hartman | 1db0a5f | 2014-12-12 17:10:17 -0500 | [diff] [blame] | 44 | struct gb_bundle *bundle = NULL; |
Greg Kroah-Hartman | 0ac5a83 | 2014-11-15 12:12:16 -0800 | [diff] [blame] | 45 | struct gb_connection *connection = NULL; |
Greg Kroah-Hartman | c8a797a | 2014-08-11 15:30:45 +0800 | [diff] [blame] | 46 | |
Greg Kroah-Hartman | 0f035ac | 2015-04-07 20:26:53 +0200 | [diff] [blame] | 47 | if (is_gb_endo(dev)) { |
| 48 | /* |
| 49 | * Not much to do for an endo, just fall through, as the |
| 50 | * "default" attributes are good enough for us. |
| 51 | */ |
| 52 | return 0; |
| 53 | } |
| 54 | |
Greg Kroah-Hartman | df67155 | 2014-12-21 14:10:26 -0800 | [diff] [blame] | 55 | if (is_gb_module(dev)) { |
| 56 | module = to_gb_module(dev); |
| 57 | } else if (is_gb_interface(dev)) { |
Greg Kroah-Hartman | 4ab9b3c | 2014-12-19 14:56:31 -0800 | [diff] [blame] | 58 | intf = to_gb_interface(dev); |
Greg Kroah-Hartman | 1db0a5f | 2014-12-12 17:10:17 -0500 | [diff] [blame] | 59 | } else if (is_gb_bundle(dev)) { |
| 60 | bundle = to_gb_bundle(dev); |
Greg Kroah-Hartman | 4ab9b3c | 2014-12-19 14:56:31 -0800 | [diff] [blame] | 61 | intf = bundle->intf; |
Greg Kroah-Hartman | 0ac5a83 | 2014-11-15 12:12:16 -0800 | [diff] [blame] | 62 | } else if (is_gb_connection(dev)) { |
| 63 | connection = to_gb_connection(dev); |
Greg Kroah-Hartman | 1db0a5f | 2014-12-12 17:10:17 -0500 | [diff] [blame] | 64 | bundle = connection->bundle; |
Greg Kroah-Hartman | 4ab9b3c | 2014-12-19 14:56:31 -0800 | [diff] [blame] | 65 | intf = bundle->intf; |
Greg Kroah-Hartman | 0ac5a83 | 2014-11-15 12:12:16 -0800 | [diff] [blame] | 66 | } else { |
| 67 | dev_WARN(dev, "uevent for unknown greybus device \"type\"!\n"); |
| 68 | return -EINVAL; |
| 69 | } |
Greg Kroah-Hartman | f0f61b9 | 2014-10-24 17:34:46 +0800 | [diff] [blame] | 70 | |
Greg Kroah-Hartman | 0ac5a83 | 2014-11-15 12:12:16 -0800 | [diff] [blame] | 71 | if (connection) { |
| 72 | // FIXME |
| 73 | // add a uevent that can "load" a connection type |
| 74 | return 0; |
| 75 | } |
Greg Kroah-Hartman | f0f61b9 | 2014-10-24 17:34:46 +0800 | [diff] [blame] | 76 | |
Greg Kroah-Hartman | 1db0a5f | 2014-12-12 17:10:17 -0500 | [diff] [blame] | 77 | if (bundle) { |
Greg Kroah-Hartman | 0ac5a83 | 2014-11-15 12:12:16 -0800 | [diff] [blame] | 78 | // FIXME |
Greg Kroah-Hartman | 1db0a5f | 2014-12-12 17:10:17 -0500 | [diff] [blame] | 79 | // add a uevent that can "load" a bundle type |
Greg Kroah-Hartman | 0ac5a83 | 2014-11-15 12:12:16 -0800 | [diff] [blame] | 80 | // This is what we need to bind a driver to so use the info |
| 81 | // in gmod here as well |
| 82 | return 0; |
| 83 | } |
| 84 | |
| 85 | // FIXME |
| 86 | // "just" a module, be vague here, nothing binds to a module except |
| 87 | // the greybus core, so there's not much, if anything, we need to |
| 88 | // advertise. |
Greg Kroah-Hartman | c8a797a | 2014-08-11 15:30:45 +0800 | [diff] [blame] | 89 | return 0; |
| 90 | } |
| 91 | |
Greg Kroah-Hartman | f0f61b9 | 2014-10-24 17:34:46 +0800 | [diff] [blame] | 92 | struct bus_type greybus_bus_type = { |
Greg Kroah-Hartman | c8a797a | 2014-08-11 15:30:45 +0800 | [diff] [blame] | 93 | .name = "greybus", |
Alex Elder | 778c69c | 2014-09-22 19:19:03 -0500 | [diff] [blame] | 94 | .match = greybus_module_match, |
Greg Kroah-Hartman | c8a797a | 2014-08-11 15:30:45 +0800 | [diff] [blame] | 95 | .uevent = greybus_uevent, |
| 96 | }; |
| 97 | |
| 98 | static int greybus_probe(struct device *dev) |
| 99 | { |
| 100 | struct greybus_driver *driver = to_greybus_driver(dev->driver); |
Viresh Kumar | 9f5f30e712 | 2015-04-01 20:32:04 +0530 | [diff] [blame] | 101 | struct gb_bundle *bundle = to_gb_bundle(dev); |
| 102 | const struct greybus_bundle_id *id; |
Greg Kroah-Hartman | c8a797a | 2014-08-11 15:30:45 +0800 | [diff] [blame] | 103 | int retval; |
| 104 | |
| 105 | /* match id */ |
Viresh Kumar | 9f5f30e712 | 2015-04-01 20:32:04 +0530 | [diff] [blame] | 106 | id = gb_bundle_match_id(bundle, driver->id_table); |
Greg Kroah-Hartman | c8a797a | 2014-08-11 15:30:45 +0800 | [diff] [blame] | 107 | if (!id) |
| 108 | return -ENODEV; |
| 109 | |
Viresh Kumar | 9f5f30e712 | 2015-04-01 20:32:04 +0530 | [diff] [blame] | 110 | retval = driver->probe(bundle, id); |
Greg Kroah-Hartman | c8a797a | 2014-08-11 15:30:45 +0800 | [diff] [blame] | 111 | if (retval) |
| 112 | return retval; |
| 113 | |
| 114 | return 0; |
| 115 | } |
| 116 | |
| 117 | static int greybus_remove(struct device *dev) |
| 118 | { |
| 119 | struct greybus_driver *driver = to_greybus_driver(dev->driver); |
Viresh Kumar | 9f5f30e712 | 2015-04-01 20:32:04 +0530 | [diff] [blame] | 120 | struct gb_bundle *bundle = to_gb_bundle(dev); |
Greg Kroah-Hartman | c8a797a | 2014-08-11 15:30:45 +0800 | [diff] [blame] | 121 | |
Viresh Kumar | 9f5f30e712 | 2015-04-01 20:32:04 +0530 | [diff] [blame] | 122 | driver->disconnect(bundle); |
Greg Kroah-Hartman | c8a797a | 2014-08-11 15:30:45 +0800 | [diff] [blame] | 123 | return 0; |
| 124 | } |
| 125 | |
| 126 | int greybus_register_driver(struct greybus_driver *driver, struct module *owner, |
| 127 | const char *mod_name) |
| 128 | { |
| 129 | int retval; |
| 130 | |
| 131 | if (greybus_disabled()) |
| 132 | return -ENODEV; |
| 133 | |
| 134 | driver->driver.name = driver->name; |
| 135 | driver->driver.probe = greybus_probe; |
| 136 | driver->driver.remove = greybus_remove; |
| 137 | driver->driver.owner = owner; |
| 138 | driver->driver.mod_name = mod_name; |
| 139 | |
| 140 | retval = driver_register(&driver->driver); |
| 141 | if (retval) |
| 142 | return retval; |
| 143 | |
| 144 | pr_info("registered new driver %s\n", driver->name); |
| 145 | return 0; |
| 146 | } |
| 147 | EXPORT_SYMBOL_GPL(greybus_register_driver); |
| 148 | |
Alex Elder | fd1c2e5 | 2015-06-08 12:05:13 -0500 | [diff] [blame] | 149 | void greybus_deregister_driver(struct greybus_driver *driver) |
Greg Kroah-Hartman | c8a797a | 2014-08-11 15:30:45 +0800 | [diff] [blame] | 150 | { |
| 151 | driver_unregister(&driver->driver); |
| 152 | } |
Alex Elder | fd1c2e5 | 2015-06-08 12:05:13 -0500 | [diff] [blame] | 153 | EXPORT_SYMBOL_GPL(greybus_deregister_driver); |
Greg Kroah-Hartman | c8a797a | 2014-08-11 15:30:45 +0800 | [diff] [blame] | 154 | |
Greg Kroah-Hartman | 199d68d | 2014-08-30 16:20:22 -0700 | [diff] [blame] | 155 | |
Greg Kroah-Hartman | 68f1fc4 | 2014-09-07 13:12:11 -0700 | [diff] [blame] | 156 | static DEFINE_MUTEX(hd_mutex); |
| 157 | |
| 158 | static void free_hd(struct kref *kref) |
| 159 | { |
| 160 | struct greybus_host_device *hd; |
| 161 | |
| 162 | hd = container_of(kref, struct greybus_host_device, kref); |
| 163 | |
Greg Kroah-Hartman | fe166c6 | 2015-07-27 14:23:44 -0700 | [diff] [blame] | 164 | ida_destroy(&hd->cport_id_map); |
Greg Kroah-Hartman | 68f1fc4 | 2014-09-07 13:12:11 -0700 | [diff] [blame] | 165 | kfree(hd); |
Alex Elder | a06df4b | 2014-10-16 06:35:26 -0500 | [diff] [blame] | 166 | mutex_unlock(&hd_mutex); |
Greg Kroah-Hartman | 68f1fc4 | 2014-09-07 13:12:11 -0700 | [diff] [blame] | 167 | } |
| 168 | |
Greg Kroah-Hartman | a39879f | 2014-09-06 16:57:36 -0700 | [diff] [blame] | 169 | struct greybus_host_device *greybus_create_hd(struct greybus_host_driver *driver, |
Johan Hovold | d933667 | 2015-05-19 11:22:43 +0200 | [diff] [blame] | 170 | struct device *parent, |
Fabien Parent | 144670c | 2015-09-02 15:50:35 +0200 | [diff] [blame] | 171 | size_t buffer_size_max, |
| 172 | size_t num_cports) |
Greg Kroah-Hartman | a39879f | 2014-09-06 16:57:36 -0700 | [diff] [blame] | 173 | { |
| 174 | struct greybus_host_device *hd; |
| 175 | |
Greg Kroah-Hartman | 724b619 | 2014-10-27 13:32:27 +0800 | [diff] [blame] | 176 | /* |
| 177 | * Validate that the driver implements all of the callbacks |
| 178 | * so that we don't have to every time we make them. |
| 179 | */ |
Greg Kroah-Hartman | 260998e | 2015-07-24 17:19:21 -0700 | [diff] [blame] | 180 | if ((!driver->message_send) || (!driver->message_cancel)) { |
Greg Kroah-Hartman | 724b619 | 2014-10-27 13:32:27 +0800 | [diff] [blame] | 181 | pr_err("Must implement all greybus_host_driver callbacks!\n"); |
Alex Elder | 8ea70fe | 2015-05-22 09:52:45 -0500 | [diff] [blame] | 182 | return ERR_PTR(-EINVAL); |
Greg Kroah-Hartman | 724b619 | 2014-10-27 13:32:27 +0800 | [diff] [blame] | 183 | } |
| 184 | |
Johan Hovold | 8e929a8 | 2015-05-19 11:22:45 +0200 | [diff] [blame] | 185 | if (buffer_size_max < GB_OPERATION_MESSAGE_SIZE_MIN) { |
| 186 | dev_err(parent, "greybus host-device buffers too small\n"); |
Johan Hovold | 1a58a3b | 2015-09-02 17:37:38 +0200 | [diff] [blame] | 187 | return ERR_PTR(-EINVAL); |
Johan Hovold | 8e929a8 | 2015-05-19 11:22:45 +0200 | [diff] [blame] | 188 | } |
| 189 | |
Fabien Parent | 144670c | 2015-09-02 15:50:35 +0200 | [diff] [blame] | 190 | if (num_cports == 0 || num_cports > CPORT_ID_MAX) { |
| 191 | dev_err(parent, "Invalid number of CPorts: %zu\n", num_cports); |
| 192 | return ERR_PTR(-EINVAL); |
| 193 | } |
| 194 | |
Johan Hovold | d933667 | 2015-05-19 11:22:43 +0200 | [diff] [blame] | 195 | /* |
| 196 | * Make sure to never allocate messages larger than what the Greybus |
| 197 | * protocol supports. |
| 198 | */ |
| 199 | if (buffer_size_max > GB_OPERATION_MESSAGE_SIZE_MAX) { |
| 200 | dev_warn(parent, "limiting buffer size to %u\n", |
| 201 | GB_OPERATION_MESSAGE_SIZE_MAX); |
| 202 | buffer_size_max = GB_OPERATION_MESSAGE_SIZE_MAX; |
| 203 | } |
| 204 | |
Greg Kroah-Hartman | a39879f | 2014-09-06 16:57:36 -0700 | [diff] [blame] | 205 | hd = kzalloc(sizeof(*hd) + driver->hd_priv_size, GFP_KERNEL); |
| 206 | if (!hd) |
Alex Elder | 8ea70fe | 2015-05-22 09:52:45 -0500 | [diff] [blame] | 207 | return ERR_PTR(-ENOMEM); |
Greg Kroah-Hartman | a39879f | 2014-09-06 16:57:36 -0700 | [diff] [blame] | 208 | |
| 209 | kref_init(&hd->kref); |
Greg Kroah-Hartman | 772149b | 2014-09-14 12:27:28 -0700 | [diff] [blame] | 210 | hd->parent = parent; |
| 211 | hd->driver = driver; |
Greg Kroah-Hartman | 1cd56a8 | 2014-12-19 14:56:36 -0800 | [diff] [blame] | 212 | INIT_LIST_HEAD(&hd->interfaces); |
Alex Elder | 2c43ce4 | 2014-11-17 08:08:44 -0600 | [diff] [blame] | 213 | INIT_LIST_HEAD(&hd->connections); |
Greg Kroah-Hartman | fd7b435 | 2015-06-16 19:43:05 -0700 | [diff] [blame] | 214 | ida_init(&hd->cport_id_map); |
Johan Hovold | d933667 | 2015-05-19 11:22:43 +0200 | [diff] [blame] | 215 | hd->buffer_size_max = buffer_size_max; |
Fabien Parent | 144670c | 2015-09-02 15:50:35 +0200 | [diff] [blame] | 216 | hd->num_cports = num_cports; |
Alex Elder | 1bb3c72 | 2014-10-02 12:30:03 -0500 | [diff] [blame] | 217 | |
Viresh Kumar | e75b82b | 2015-07-28 07:28:42 +0530 | [diff] [blame] | 218 | /* |
| 219 | * Initialize AP's SVC protocol connection: |
| 220 | * |
| 221 | * This is required as part of early initialization of the host device |
| 222 | * as we need this connection in order to start any kind of message |
| 223 | * exchange between the AP and the SVC. SVC will start with a |
| 224 | * 'get-version' request followed by a 'svc-hello' message and at that |
| 225 | * time we will create a fully initialized svc-connection, as we need |
| 226 | * endo-id and AP's interface id for that. |
| 227 | */ |
| 228 | if (!gb_ap_svc_connection_create(hd)) { |
| 229 | kref_put_mutex(&hd->kref, free_hd, &hd_mutex); |
| 230 | return ERR_PTR(-ENOMEM); |
| 231 | } |
| 232 | |
Greg Kroah-Hartman | a39879f | 2014-09-06 16:57:36 -0700 | [diff] [blame] | 233 | return hd; |
| 234 | } |
| 235 | EXPORT_SYMBOL_GPL(greybus_create_hd); |
| 236 | |
Alex Elder | eb765e4 | 2015-05-22 12:56:49 -0500 | [diff] [blame] | 237 | int greybus_endo_setup(struct greybus_host_device *hd, u16 endo_id, |
| 238 | u8 ap_intf_id) |
| 239 | { |
| 240 | struct gb_endo *endo; |
| 241 | |
| 242 | endo = gb_endo_create(hd, endo_id, ap_intf_id); |
| 243 | if (IS_ERR(endo)) |
| 244 | return PTR_ERR(endo); |
| 245 | hd->endo = endo; |
| 246 | |
| 247 | return 0; |
| 248 | } |
| 249 | EXPORT_SYMBOL_GPL(greybus_endo_setup); |
| 250 | |
Greg Kroah-Hartman | 68f1fc4 | 2014-09-07 13:12:11 -0700 | [diff] [blame] | 251 | void greybus_remove_hd(struct greybus_host_device *hd) |
| 252 | { |
Greg Kroah-Hartman | a4d9150 | 2015-04-07 20:27:15 +0200 | [diff] [blame] | 253 | /* |
| 254 | * Tear down all interfaces, modules, and the endo that is associated |
| 255 | * with this host controller before freeing the memory associated with |
| 256 | * the host controller. |
| 257 | */ |
Viresh Kumar | 51b5d8d | 2015-05-20 17:33:51 +0530 | [diff] [blame] | 258 | gb_interfaces_remove(hd); |
Greg Kroah-Hartman | a4d9150 | 2015-04-07 20:27:15 +0200 | [diff] [blame] | 259 | gb_endo_remove(hd->endo); |
Viresh Kumar | e99f305 | 2015-07-09 10:56:30 +0530 | [diff] [blame] | 260 | |
Viresh Kumar | dcd0500 | 2015-07-24 15:32:20 +0530 | [diff] [blame] | 261 | /* Is the SVC still using the partially uninitialized connection ? */ |
Viresh Kumar | fda2381 | 2015-08-31 17:21:13 +0530 | [diff] [blame^] | 262 | if (hd->initial_svc_connection) |
Viresh Kumar | dcd0500 | 2015-07-24 15:32:20 +0530 | [diff] [blame] | 263 | gb_connection_destroy(hd->initial_svc_connection); |
Viresh Kumar | dcd0500 | 2015-07-24 15:32:20 +0530 | [diff] [blame] | 264 | |
Viresh Kumar | e99f305 | 2015-07-09 10:56:30 +0530 | [diff] [blame] | 265 | /* |
| 266 | * Make sure there are no leftovers that can potentially corrupt sysfs. |
| 267 | */ |
| 268 | if (WARN_ON(!list_empty(&hd->connections))) |
| 269 | gb_hd_connections_exit(hd); |
| 270 | |
Greg Kroah-Hartman | 68f1fc4 | 2014-09-07 13:12:11 -0700 | [diff] [blame] | 271 | kref_put_mutex(&hd->kref, free_hd, &hd_mutex); |
| 272 | } |
| 273 | EXPORT_SYMBOL_GPL(greybus_remove_hd); |
| 274 | |
Greg Kroah-Hartman | 503c1cd | 2014-08-30 16:21:03 -0700 | [diff] [blame] | 275 | static int __init gb_init(void) |
Greg Kroah-Hartman | 199d68d | 2014-08-30 16:20:22 -0700 | [diff] [blame] | 276 | { |
Greg Kroah-Hartman | db6e1fd | 2014-08-30 16:47:26 -0700 | [diff] [blame] | 277 | int retval; |
| 278 | |
Viresh Kumar | 337b068 | 2015-03-20 20:29:13 +0530 | [diff] [blame] | 279 | if (greybus_disabled()) |
| 280 | return -ENODEV; |
| 281 | |
Alex Elder | fb690ca | 2015-06-13 11:02:09 -0500 | [diff] [blame] | 282 | BUILD_BUG_ON(CPORT_ID_MAX >= (long)CPORT_ID_BAD); |
Alex Elder | 1bb3c72 | 2014-10-02 12:30:03 -0500 | [diff] [blame] | 283 | |
Greg Kroah-Hartman | 48f7047 | 2015-03-27 11:38:06 +0100 | [diff] [blame] | 284 | gb_debugfs_init(); |
Greg Kroah-Hartman | db6e1fd | 2014-08-30 16:47:26 -0700 | [diff] [blame] | 285 | |
Greg Kroah-Hartman | 27fb831 | 2014-08-31 13:54:59 -0700 | [diff] [blame] | 286 | retval = bus_register(&greybus_bus_type); |
Greg Kroah-Hartman | 168db1c | 2014-09-13 16:15:52 -0700 | [diff] [blame] | 287 | if (retval) { |
Alex Elder | f35ab90 | 2015-06-09 17:42:51 -0500 | [diff] [blame] | 288 | pr_err("bus_register failed (%d)\n", retval); |
Greg Kroah-Hartman | 27fb831 | 2014-08-31 13:54:59 -0700 | [diff] [blame] | 289 | goto error_bus; |
Greg Kroah-Hartman | 168db1c | 2014-09-13 16:15:52 -0700 | [diff] [blame] | 290 | } |
Greg Kroah-Hartman | 27fb831 | 2014-08-31 13:54:59 -0700 | [diff] [blame] | 291 | |
Alex Elder | 2eb585f | 2014-10-16 06:35:34 -0500 | [diff] [blame] | 292 | retval = gb_operation_init(); |
| 293 | if (retval) { |
Alex Elder | f35ab90 | 2015-06-09 17:42:51 -0500 | [diff] [blame] | 294 | pr_err("gb_operation_init failed (%d)\n", retval); |
Alex Elder | 2eb585f | 2014-10-16 06:35:34 -0500 | [diff] [blame] | 295 | goto error_operation; |
| 296 | } |
| 297 | |
Alex Elder | f35ab90 | 2015-06-09 17:42:51 -0500 | [diff] [blame] | 298 | retval = gb_endo_init(); |
| 299 | if (retval) { |
| 300 | pr_err("gb_endo_init failed (%d)\n", retval); |
| 301 | goto error_endo; |
| 302 | } |
| 303 | |
Viresh Kumar | cdee4f7 | 2015-06-22 16:42:26 +0530 | [diff] [blame] | 304 | retval = gb_control_protocol_init(); |
| 305 | if (retval) { |
| 306 | pr_err("gb_control_protocol_init failed\n"); |
| 307 | goto error_control; |
| 308 | } |
| 309 | |
Viresh Kumar | ab69c4c | 2015-07-03 17:00:29 +0530 | [diff] [blame] | 310 | retval = gb_svc_protocol_init(); |
| 311 | if (retval) { |
| 312 | pr_err("gb_svc_protocol_init failed\n"); |
| 313 | goto error_svc; |
| 314 | } |
| 315 | |
Viresh Kumar | 90f1b61 | 2015-08-12 09:19:33 +0530 | [diff] [blame] | 316 | retval = gb_firmware_protocol_init(); |
| 317 | if (retval) { |
| 318 | pr_err("gb_firmware_protocol_init failed\n"); |
| 319 | goto error_firmware; |
| 320 | } |
| 321 | |
Alex Elder | 19d03de | 2014-11-05 16:12:53 -0600 | [diff] [blame] | 322 | return 0; /* Success */ |
| 323 | |
Viresh Kumar | 90f1b61 | 2015-08-12 09:19:33 +0530 | [diff] [blame] | 324 | error_firmware: |
| 325 | gb_svc_protocol_exit(); |
Viresh Kumar | ab69c4c | 2015-07-03 17:00:29 +0530 | [diff] [blame] | 326 | error_svc: |
| 327 | gb_control_protocol_exit(); |
Viresh Kumar | cdee4f7 | 2015-06-22 16:42:26 +0530 | [diff] [blame] | 328 | error_control: |
| 329 | gb_endo_exit(); |
Alex Elder | f35ab90 | 2015-06-09 17:42:51 -0500 | [diff] [blame] | 330 | error_endo: |
| 331 | gb_operation_exit(); |
Alex Elder | 2eb585f | 2014-10-16 06:35:34 -0500 | [diff] [blame] | 332 | error_operation: |
Greg Kroah-Hartman | 27fb831 | 2014-08-31 13:54:59 -0700 | [diff] [blame] | 333 | bus_unregister(&greybus_bus_type); |
Greg Kroah-Hartman | 27fb831 | 2014-08-31 13:54:59 -0700 | [diff] [blame] | 334 | error_bus: |
Greg Kroah-Hartman | de536e3 | 2014-08-31 16:17:04 -0700 | [diff] [blame] | 335 | gb_debugfs_cleanup(); |
Greg Kroah-Hartman | 27fb831 | 2014-08-31 13:54:59 -0700 | [diff] [blame] | 336 | |
| 337 | return retval; |
Greg Kroah-Hartman | 199d68d | 2014-08-30 16:20:22 -0700 | [diff] [blame] | 338 | } |
Viresh Kumar | d71aaf2 | 2015-03-19 17:02:49 +0530 | [diff] [blame] | 339 | module_init(gb_init); |
Greg Kroah-Hartman | 199d68d | 2014-08-30 16:20:22 -0700 | [diff] [blame] | 340 | |
Greg Kroah-Hartman | 503c1cd | 2014-08-30 16:21:03 -0700 | [diff] [blame] | 341 | static void __exit gb_exit(void) |
Greg Kroah-Hartman | 199d68d | 2014-08-30 16:20:22 -0700 | [diff] [blame] | 342 | { |
Viresh Kumar | 90f1b61 | 2015-08-12 09:19:33 +0530 | [diff] [blame] | 343 | gb_firmware_protocol_exit(); |
Viresh Kumar | ab69c4c | 2015-07-03 17:00:29 +0530 | [diff] [blame] | 344 | gb_svc_protocol_exit(); |
Viresh Kumar | cdee4f7 | 2015-06-22 16:42:26 +0530 | [diff] [blame] | 345 | gb_control_protocol_exit(); |
Alex Elder | f35ab90 | 2015-06-09 17:42:51 -0500 | [diff] [blame] | 346 | gb_endo_exit(); |
Alex Elder | 2eb585f | 2014-10-16 06:35:34 -0500 | [diff] [blame] | 347 | gb_operation_exit(); |
Greg Kroah-Hartman | 27fb831 | 2014-08-31 13:54:59 -0700 | [diff] [blame] | 348 | bus_unregister(&greybus_bus_type); |
Greg Kroah-Hartman | de536e3 | 2014-08-31 16:17:04 -0700 | [diff] [blame] | 349 | gb_debugfs_cleanup(); |
Greg Kroah-Hartman | 199d68d | 2014-08-30 16:20:22 -0700 | [diff] [blame] | 350 | } |
Greg Kroah-Hartman | 199d68d | 2014-08-30 16:20:22 -0700 | [diff] [blame] | 351 | module_exit(gb_exit); |
Greg Kroah-Hartman | 6cf42a4 | 2015-04-13 19:51:33 +0200 | [diff] [blame] | 352 | MODULE_LICENSE("GPL v2"); |
Greg Kroah-Hartman | c8a797a | 2014-08-11 15:30:45 +0800 | [diff] [blame] | 353 | MODULE_AUTHOR("Greg Kroah-Hartman <gregkh@linuxfoundation.org>"); |