Greg Kroah-Hartman | eb50fd3 | 2017-11-07 14:58:41 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Greg Kroah-Hartman | c8a797a | 2014-08-11 15:30:45 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Greybus "Core" |
| 4 | * |
Alex Elder | 4441f47 | 2015-05-22 12:59:16 -0500 | [diff] [blame] | 5 | * Copyright 2014-2015 Google Inc. |
| 6 | * Copyright 2014-2015 Linaro Ltd. |
Greg Kroah-Hartman | c8a797a | 2014-08-11 15:30:45 +0800 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 10 | |
Bryan O'Donoghue | 5c8ad59 | 2015-09-18 16:38:45 +0100 | [diff] [blame] | 11 | #define CREATE_TRACE_POINTS |
Greg Kroah-Hartman | ec0ad86 | 2019-08-25 07:54:27 +0200 | [diff] [blame] | 12 | #include <linux/greybus.h> |
Bryan O'Donoghue | 5c8ad59 | 2015-09-18 16:38:45 +0100 | [diff] [blame] | 13 | #include "greybus_trace.h" |
Greg Kroah-Hartman | c8a797a | 2014-08-11 15:30:45 +0800 | [diff] [blame] | 14 | |
David Lin | 61e13db | 2016-07-14 15:13:00 -0500 | [diff] [blame] | 15 | #define GB_BUNDLE_AUTOSUSPEND_MS 3000 |
| 16 | |
Greg Kroah-Hartman | c8a797a | 2014-08-11 15:30:45 +0800 | [diff] [blame] | 17 | /* Allow greybus to be disabled at boot if needed */ |
| 18 | static bool nogreybus; |
| 19 | #ifdef MODULE |
| 20 | module_param(nogreybus, bool, 0444); |
| 21 | #else |
Viresh Kumar | 8597e6b | 2014-10-20 16:45:50 +0530 | [diff] [blame] | 22 | core_param(nogreybus, nogreybus, bool, 0444); |
Greg Kroah-Hartman | c8a797a | 2014-08-11 15:30:45 +0800 | [diff] [blame] | 23 | #endif |
| 24 | int greybus_disabled(void) |
| 25 | { |
| 26 | return nogreybus; |
| 27 | } |
| 28 | EXPORT_SYMBOL_GPL(greybus_disabled); |
| 29 | |
Viresh Kumar | 129a6fb | 2016-06-09 16:34:36 +0530 | [diff] [blame] | 30 | static bool greybus_match_one_id(struct gb_bundle *bundle, |
Ioannis Valasakis | f17f542 | 2018-11-09 13:53:31 +0000 | [diff] [blame] | 31 | const struct greybus_bundle_id *id) |
Johan Hovold | 700001a | 2015-11-21 10:52:03 +0100 | [diff] [blame] | 32 | { |
| 33 | if ((id->match_flags & GREYBUS_ID_MATCH_VENDOR) && |
Johan Hovold | 9f59263 | 2015-11-25 15:58:56 +0100 | [diff] [blame] | 34 | (id->vendor != bundle->intf->vendor_id)) |
Viresh Kumar | 129a6fb | 2016-06-09 16:34:36 +0530 | [diff] [blame] | 35 | return false; |
Johan Hovold | 700001a | 2015-11-21 10:52:03 +0100 | [diff] [blame] | 36 | |
| 37 | if ((id->match_flags & GREYBUS_ID_MATCH_PRODUCT) && |
Johan Hovold | 9f59263 | 2015-11-25 15:58:56 +0100 | [diff] [blame] | 38 | (id->product != bundle->intf->product_id)) |
Viresh Kumar | 129a6fb | 2016-06-09 16:34:36 +0530 | [diff] [blame] | 39 | return false; |
Johan Hovold | 700001a | 2015-11-21 10:52:03 +0100 | [diff] [blame] | 40 | |
| 41 | if ((id->match_flags & GREYBUS_ID_MATCH_CLASS) && |
| 42 | (id->class != bundle->class)) |
Viresh Kumar | 129a6fb | 2016-06-09 16:34:36 +0530 | [diff] [blame] | 43 | return false; |
Johan Hovold | 700001a | 2015-11-21 10:52:03 +0100 | [diff] [blame] | 44 | |
Viresh Kumar | 129a6fb | 2016-06-09 16:34:36 +0530 | [diff] [blame] | 45 | return true; |
Johan Hovold | 700001a | 2015-11-21 10:52:03 +0100 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | static const struct greybus_bundle_id * |
| 49 | greybus_match_id(struct gb_bundle *bundle, const struct greybus_bundle_id *id) |
| 50 | { |
Ioannis Valasakis | 9b76530 | 2018-11-09 13:53:24 +0000 | [diff] [blame] | 51 | if (!id) |
Johan Hovold | 700001a | 2015-11-21 10:52:03 +0100 | [diff] [blame] | 52 | return NULL; |
| 53 | |
| 54 | for (; id->vendor || id->product || id->class || id->driver_info; |
| 55 | id++) { |
| 56 | if (greybus_match_one_id(bundle, id)) |
| 57 | return id; |
| 58 | } |
| 59 | |
| 60 | return NULL; |
| 61 | } |
| 62 | |
Viresh Kumar | e4e5536 | 2016-05-12 11:34:05 +0530 | [diff] [blame] | 63 | static int greybus_match_device(struct device *dev, struct device_driver *drv) |
Greg Kroah-Hartman | c8a797a | 2014-08-11 15:30:45 +0800 | [diff] [blame] | 64 | { |
Viresh Kumar | 95bd99d | 2014-11-14 17:24:59 +0530 | [diff] [blame] | 65 | struct greybus_driver *driver = to_greybus_driver(drv); |
Johan Hovold | b77f932 | 2016-01-08 20:13:41 +0100 | [diff] [blame] | 66 | struct gb_bundle *bundle; |
Viresh Kumar | 9f5f30e712 | 2015-04-01 20:32:04 +0530 | [diff] [blame] | 67 | const struct greybus_bundle_id *id; |
Greg Kroah-Hartman | c8a797a | 2014-08-11 15:30:45 +0800 | [diff] [blame] | 68 | |
Johan Hovold | b77f932 | 2016-01-08 20:13:41 +0100 | [diff] [blame] | 69 | if (!is_gb_bundle(dev)) |
| 70 | return 0; |
| 71 | |
| 72 | bundle = to_gb_bundle(dev); |
| 73 | |
Johan Hovold | 700001a | 2015-11-21 10:52:03 +0100 | [diff] [blame] | 74 | id = greybus_match_id(bundle, driver->id_table); |
Greg Kroah-Hartman | c8a797a | 2014-08-11 15:30:45 +0800 | [diff] [blame] | 75 | if (id) |
| 76 | return 1; |
Viresh Kumar | 696e0cc | 2014-11-21 11:26:30 +0530 | [diff] [blame] | 77 | /* FIXME - Dynamic ids? */ |
Greg Kroah-Hartman | c8a797a | 2014-08-11 15:30:45 +0800 | [diff] [blame] | 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | static int greybus_uevent(struct device *dev, struct kobj_uevent_env *env) |
| 82 | { |
Johan Hovold | f0960d0 | 2015-12-03 19:18:02 +0100 | [diff] [blame] | 83 | struct gb_host_device *hd; |
Johan Hovold | b15d97d | 2016-04-23 18:47:24 +0200 | [diff] [blame] | 84 | struct gb_module *module = NULL; |
Greg Kroah-Hartman | 4ab9b3c | 2014-12-19 14:56:31 -0800 | [diff] [blame] | 85 | struct gb_interface *intf = NULL; |
Johan Hovold | a6e5b01 | 2016-04-13 19:19:02 +0200 | [diff] [blame] | 86 | struct gb_control *control = NULL; |
Greg Kroah-Hartman | 1db0a5f | 2014-12-12 17:10:17 -0500 | [diff] [blame] | 87 | struct gb_bundle *bundle = NULL; |
Johan Hovold | 88f7b96 | 2015-11-25 15:59:08 +0100 | [diff] [blame] | 88 | struct gb_svc *svc = NULL; |
Greg Kroah-Hartman | c8a797a | 2014-08-11 15:30:45 +0800 | [diff] [blame] | 89 | |
Johan Hovold | 2adaefb | 2015-11-25 15:59:02 +0100 | [diff] [blame] | 90 | if (is_gb_host_device(dev)) { |
| 91 | hd = to_gb_host_device(dev); |
Johan Hovold | b15d97d | 2016-04-23 18:47:24 +0200 | [diff] [blame] | 92 | } else if (is_gb_module(dev)) { |
| 93 | module = to_gb_module(dev); |
| 94 | hd = module->hd; |
Greg Kroah-Hartman | df67155 | 2014-12-21 14:10:26 -0800 | [diff] [blame] | 95 | } else if (is_gb_interface(dev)) { |
Greg Kroah-Hartman | 4ab9b3c | 2014-12-19 14:56:31 -0800 | [diff] [blame] | 96 | intf = to_gb_interface(dev); |
Johan Hovold | b15d97d | 2016-04-23 18:47:24 +0200 | [diff] [blame] | 97 | module = intf->module; |
Johan Hovold | f0960d0 | 2015-12-03 19:18:02 +0100 | [diff] [blame] | 98 | hd = intf->hd; |
Johan Hovold | a6e5b01 | 2016-04-13 19:19:02 +0200 | [diff] [blame] | 99 | } else if (is_gb_control(dev)) { |
| 100 | control = to_gb_control(dev); |
| 101 | intf = control->intf; |
Sandeep Patil | 3e29bcf | 2016-05-04 16:21:29 -0700 | [diff] [blame] | 102 | module = intf->module; |
Johan Hovold | a6e5b01 | 2016-04-13 19:19:02 +0200 | [diff] [blame] | 103 | hd = intf->hd; |
Greg Kroah-Hartman | 1db0a5f | 2014-12-12 17:10:17 -0500 | [diff] [blame] | 104 | } else if (is_gb_bundle(dev)) { |
| 105 | bundle = to_gb_bundle(dev); |
Greg Kroah-Hartman | 4ab9b3c | 2014-12-19 14:56:31 -0800 | [diff] [blame] | 106 | intf = bundle->intf; |
Johan Hovold | b15d97d | 2016-04-23 18:47:24 +0200 | [diff] [blame] | 107 | module = intf->module; |
Johan Hovold | f0960d0 | 2015-12-03 19:18:02 +0100 | [diff] [blame] | 108 | hd = intf->hd; |
Johan Hovold | 88f7b96 | 2015-11-25 15:59:08 +0100 | [diff] [blame] | 109 | } else if (is_gb_svc(dev)) { |
| 110 | svc = to_gb_svc(dev); |
Johan Hovold | f0960d0 | 2015-12-03 19:18:02 +0100 | [diff] [blame] | 111 | hd = svc->hd; |
Greg Kroah-Hartman | 0ac5a83 | 2014-11-15 12:12:16 -0800 | [diff] [blame] | 112 | } else { |
| 113 | dev_WARN(dev, "uevent for unknown greybus device \"type\"!\n"); |
| 114 | return -EINVAL; |
| 115 | } |
Greg Kroah-Hartman | f0f61b9 | 2014-10-24 17:34:46 +0800 | [diff] [blame] | 116 | |
Johan Hovold | f0960d0 | 2015-12-03 19:18:02 +0100 | [diff] [blame] | 117 | if (add_uevent_var(env, "BUS=%u", hd->bus_id)) |
| 118 | return -ENOMEM; |
| 119 | |
Johan Hovold | b15d97d | 2016-04-23 18:47:24 +0200 | [diff] [blame] | 120 | if (module) { |
| 121 | if (add_uevent_var(env, "MODULE=%u", module->module_id)) |
| 122 | return -ENOMEM; |
| 123 | } |
| 124 | |
Johan Hovold | c5e6b05 | 2015-12-03 19:18:04 +0100 | [diff] [blame] | 125 | if (intf) { |
| 126 | if (add_uevent_var(env, "INTERFACE=%u", intf->interface_id)) |
| 127 | return -ENOMEM; |
Greg Kroah-Hartman | 611924d | 2016-02-26 21:54:38 -0800 | [diff] [blame] | 128 | if (add_uevent_var(env, "GREYBUS_ID=%08x/%08x", |
| 129 | intf->vendor_id, intf->product_id)) |
Greg Kroah-Hartman | de14131 | 2016-01-11 19:24:54 -0800 | [diff] [blame] | 130 | return -ENOMEM; |
Johan Hovold | c5e6b05 | 2015-12-03 19:18:04 +0100 | [diff] [blame] | 131 | } |
| 132 | |
Greg Kroah-Hartman | 1db0a5f | 2014-12-12 17:10:17 -0500 | [diff] [blame] | 133 | if (bundle) { |
Greg Kroah-Hartman | 0ac5a83 | 2014-11-15 12:12:16 -0800 | [diff] [blame] | 134 | // FIXME |
Greg Kroah-Hartman | 1db0a5f | 2014-12-12 17:10:17 -0500 | [diff] [blame] | 135 | // add a uevent that can "load" a bundle type |
Greg Kroah-Hartman | 0ac5a83 | 2014-11-15 12:12:16 -0800 | [diff] [blame] | 136 | // This is what we need to bind a driver to so use the info |
| 137 | // in gmod here as well |
Johan Hovold | c29c016 | 2015-12-04 10:44:24 +0100 | [diff] [blame] | 138 | |
| 139 | if (add_uevent_var(env, "BUNDLE=%u", bundle->id)) |
| 140 | return -ENOMEM; |
Greg Kroah-Hartman | 6ce4cc2 | 2016-01-21 18:13:41 -0800 | [diff] [blame] | 141 | if (add_uevent_var(env, "BUNDLE_CLASS=%02x", bundle->class)) |
| 142 | return -ENOMEM; |
Greg Kroah-Hartman | 0ac5a83 | 2014-11-15 12:12:16 -0800 | [diff] [blame] | 143 | } |
| 144 | |
Greg Kroah-Hartman | c8a797a | 2014-08-11 15:30:45 +0800 | [diff] [blame] | 145 | return 0; |
| 146 | } |
| 147 | |
David Lin | 1f77b36 | 2016-07-12 17:41:21 -0700 | [diff] [blame] | 148 | static void greybus_shutdown(struct device *dev) |
| 149 | { |
| 150 | if (is_gb_host_device(dev)) { |
| 151 | struct gb_host_device *hd; |
| 152 | |
| 153 | hd = to_gb_host_device(dev); |
| 154 | gb_hd_shutdown(hd); |
| 155 | } |
| 156 | } |
| 157 | |
Greg Kroah-Hartman | f0f61b9 | 2014-10-24 17:34:46 +0800 | [diff] [blame] | 158 | struct bus_type greybus_bus_type = { |
Greg Kroah-Hartman | c8a797a | 2014-08-11 15:30:45 +0800 | [diff] [blame] | 159 | .name = "greybus", |
Viresh Kumar | e4e5536 | 2016-05-12 11:34:05 +0530 | [diff] [blame] | 160 | .match = greybus_match_device, |
Greg Kroah-Hartman | c8a797a | 2014-08-11 15:30:45 +0800 | [diff] [blame] | 161 | .uevent = greybus_uevent, |
David Lin | 1f77b36 | 2016-07-12 17:41:21 -0700 | [diff] [blame] | 162 | .shutdown = greybus_shutdown, |
Greg Kroah-Hartman | c8a797a | 2014-08-11 15:30:45 +0800 | [diff] [blame] | 163 | }; |
| 164 | |
| 165 | static int greybus_probe(struct device *dev) |
| 166 | { |
| 167 | struct greybus_driver *driver = to_greybus_driver(dev->driver); |
Viresh Kumar | 9f5f30e712 | 2015-04-01 20:32:04 +0530 | [diff] [blame] | 168 | struct gb_bundle *bundle = to_gb_bundle(dev); |
| 169 | const struct greybus_bundle_id *id; |
Greg Kroah-Hartman | c8a797a | 2014-08-11 15:30:45 +0800 | [diff] [blame] | 170 | int retval; |
| 171 | |
| 172 | /* match id */ |
Johan Hovold | 700001a | 2015-11-21 10:52:03 +0100 | [diff] [blame] | 173 | id = greybus_match_id(bundle, driver->id_table); |
Greg Kroah-Hartman | c8a797a | 2014-08-11 15:30:45 +0800 | [diff] [blame] | 174 | if (!id) |
| 175 | return -ENODEV; |
| 176 | |
David Lin | 61e13db | 2016-07-14 15:13:00 -0500 | [diff] [blame] | 177 | retval = pm_runtime_get_sync(&bundle->intf->dev); |
| 178 | if (retval < 0) { |
| 179 | pm_runtime_put_noidle(&bundle->intf->dev); |
| 180 | return retval; |
| 181 | } |
| 182 | |
Bartosz Golaszewski | f5c93de | 2016-07-21 18:09:34 +0200 | [diff] [blame] | 183 | retval = gb_control_bundle_activate(bundle->intf->control, bundle->id); |
| 184 | if (retval) { |
| 185 | pm_runtime_put(&bundle->intf->dev); |
| 186 | return retval; |
| 187 | } |
David Lin | 2d48b5b | 2016-07-14 15:13:00 -0500 | [diff] [blame] | 188 | |
David Lin | 61e13db | 2016-07-14 15:13:00 -0500 | [diff] [blame] | 189 | /* |
| 190 | * Unbound bundle devices are always deactivated. During probe, the |
| 191 | * Runtime PM is set to enabled and active and the usage count is |
| 192 | * incremented. If the driver supports runtime PM, it should call |
| 193 | * pm_runtime_put() in its probe routine and pm_runtime_get_sync() |
| 194 | * in remove routine. |
| 195 | */ |
| 196 | pm_runtime_set_autosuspend_delay(dev, GB_BUNDLE_AUTOSUSPEND_MS); |
| 197 | pm_runtime_use_autosuspend(dev); |
| 198 | pm_runtime_get_noresume(dev); |
| 199 | pm_runtime_set_active(dev); |
| 200 | pm_runtime_enable(dev); |
| 201 | |
Viresh Kumar | 9f5f30e712 | 2015-04-01 20:32:04 +0530 | [diff] [blame] | 202 | retval = driver->probe(bundle, id); |
Johan Hovold | 98fdf5a | 2016-01-21 17:34:09 +0100 | [diff] [blame] | 203 | if (retval) { |
| 204 | /* |
| 205 | * Catch buggy drivers that fail to destroy their connections. |
| 206 | */ |
| 207 | WARN_ON(!list_empty(&bundle->connections)); |
| 208 | |
David Lin | 2d48b5b | 2016-07-14 15:13:00 -0500 | [diff] [blame] | 209 | gb_control_bundle_deactivate(bundle->intf->control, bundle->id); |
| 210 | |
David Lin | 61e13db | 2016-07-14 15:13:00 -0500 | [diff] [blame] | 211 | pm_runtime_disable(dev); |
| 212 | pm_runtime_set_suspended(dev); |
| 213 | pm_runtime_put_noidle(dev); |
| 214 | pm_runtime_dont_use_autosuspend(dev); |
| 215 | pm_runtime_put(&bundle->intf->dev); |
| 216 | |
Greg Kroah-Hartman | c8a797a | 2014-08-11 15:30:45 +0800 | [diff] [blame] | 217 | return retval; |
Johan Hovold | 98fdf5a | 2016-01-21 17:34:09 +0100 | [diff] [blame] | 218 | } |
Greg Kroah-Hartman | c8a797a | 2014-08-11 15:30:45 +0800 | [diff] [blame] | 219 | |
David Lin | 61e13db | 2016-07-14 15:13:00 -0500 | [diff] [blame] | 220 | pm_runtime_put(&bundle->intf->dev); |
| 221 | |
Greg Kroah-Hartman | c8a797a | 2014-08-11 15:30:45 +0800 | [diff] [blame] | 222 | return 0; |
| 223 | } |
| 224 | |
| 225 | static int greybus_remove(struct device *dev) |
| 226 | { |
| 227 | struct greybus_driver *driver = to_greybus_driver(dev->driver); |
Viresh Kumar | 9f5f30e712 | 2015-04-01 20:32:04 +0530 | [diff] [blame] | 228 | struct gb_bundle *bundle = to_gb_bundle(dev); |
Johan Hovold | fa8369c | 2016-01-19 12:51:09 +0100 | [diff] [blame] | 229 | struct gb_connection *connection; |
David Lin | 61e13db | 2016-07-14 15:13:00 -0500 | [diff] [blame] | 230 | int retval; |
| 231 | |
| 232 | retval = pm_runtime_get_sync(dev); |
| 233 | if (retval < 0) |
| 234 | dev_err(dev, "failed to resume bundle: %d\n", retval); |
Johan Hovold | fa8369c | 2016-01-19 12:51:09 +0100 | [diff] [blame] | 235 | |
Johan Hovold | 82278bf | 2016-06-09 18:42:19 +0200 | [diff] [blame] | 236 | /* |
| 237 | * Disable (non-offloaded) connections early in case the interface is |
| 238 | * already gone to avoid unceccessary operation timeouts during |
| 239 | * driver disconnect. Otherwise, only disable incoming requests. |
| 240 | */ |
Johan Hovold | 47a2e67 | 2016-01-19 12:51:18 +0100 | [diff] [blame] | 241 | list_for_each_entry(connection, &bundle->connections, bundle_links) { |
Johan Hovold | 82278bf | 2016-06-09 18:42:19 +0200 | [diff] [blame] | 242 | if (gb_connection_is_offloaded(connection)) |
| 243 | continue; |
| 244 | |
Johan Hovold | 47a2e67 | 2016-01-19 12:51:18 +0100 | [diff] [blame] | 245 | if (bundle->intf->disconnected) |
Johan Hovold | 7aefe79 | 2016-05-27 17:26:22 +0200 | [diff] [blame] | 246 | gb_connection_disable_forced(connection); |
Johan Hovold | 47a2e67 | 2016-01-19 12:51:18 +0100 | [diff] [blame] | 247 | else |
| 248 | gb_connection_disable_rx(connection); |
| 249 | } |
Greg Kroah-Hartman | c8a797a | 2014-08-11 15:30:45 +0800 | [diff] [blame] | 250 | |
Viresh Kumar | 9f5f30e712 | 2015-04-01 20:32:04 +0530 | [diff] [blame] | 251 | driver->disconnect(bundle); |
Johan Hovold | 02a54dd | 2016-01-19 12:51:10 +0100 | [diff] [blame] | 252 | |
Johan Hovold | 98fdf5a | 2016-01-21 17:34:09 +0100 | [diff] [blame] | 253 | /* Catch buggy drivers that fail to destroy their connections. */ |
| 254 | WARN_ON(!list_empty(&bundle->connections)); |
Johan Hovold | 02a54dd | 2016-01-19 12:51:10 +0100 | [diff] [blame] | 255 | |
David Lin | 2d48b5b | 2016-07-14 15:13:00 -0500 | [diff] [blame] | 256 | if (!bundle->intf->disconnected) |
| 257 | gb_control_bundle_deactivate(bundle->intf->control, bundle->id); |
| 258 | |
David Lin | 61e13db | 2016-07-14 15:13:00 -0500 | [diff] [blame] | 259 | pm_runtime_put_noidle(dev); |
| 260 | pm_runtime_disable(dev); |
| 261 | pm_runtime_set_suspended(dev); |
| 262 | pm_runtime_dont_use_autosuspend(dev); |
| 263 | pm_runtime_put_noidle(dev); |
| 264 | |
Greg Kroah-Hartman | c8a797a | 2014-08-11 15:30:45 +0800 | [diff] [blame] | 265 | return 0; |
| 266 | } |
| 267 | |
| 268 | int greybus_register_driver(struct greybus_driver *driver, struct module *owner, |
Bhanusree Pola | b7417e3 | 2019-02-26 06:02:44 +0530 | [diff] [blame] | 269 | const char *mod_name) |
Greg Kroah-Hartman | c8a797a | 2014-08-11 15:30:45 +0800 | [diff] [blame] | 270 | { |
| 271 | int retval; |
| 272 | |
| 273 | if (greybus_disabled()) |
| 274 | return -ENODEV; |
| 275 | |
Johan Hovold | 3c48d1b | 2016-01-08 20:13:42 +0100 | [diff] [blame] | 276 | driver->driver.bus = &greybus_bus_type; |
Greg Kroah-Hartman | c8a797a | 2014-08-11 15:30:45 +0800 | [diff] [blame] | 277 | driver->driver.name = driver->name; |
| 278 | driver->driver.probe = greybus_probe; |
| 279 | driver->driver.remove = greybus_remove; |
| 280 | driver->driver.owner = owner; |
| 281 | driver->driver.mod_name = mod_name; |
| 282 | |
| 283 | retval = driver_register(&driver->driver); |
| 284 | if (retval) |
| 285 | return retval; |
| 286 | |
| 287 | pr_info("registered new driver %s\n", driver->name); |
| 288 | return 0; |
| 289 | } |
| 290 | EXPORT_SYMBOL_GPL(greybus_register_driver); |
| 291 | |
Alex Elder | fd1c2e5 | 2015-06-08 12:05:13 -0500 | [diff] [blame] | 292 | void greybus_deregister_driver(struct greybus_driver *driver) |
Greg Kroah-Hartman | c8a797a | 2014-08-11 15:30:45 +0800 | [diff] [blame] | 293 | { |
| 294 | driver_unregister(&driver->driver); |
| 295 | } |
Alex Elder | fd1c2e5 | 2015-06-08 12:05:13 -0500 | [diff] [blame] | 296 | EXPORT_SYMBOL_GPL(greybus_deregister_driver); |
Greg Kroah-Hartman | c8a797a | 2014-08-11 15:30:45 +0800 | [diff] [blame] | 297 | |
Greg Kroah-Hartman | 503c1cd | 2014-08-30 16:21:03 -0700 | [diff] [blame] | 298 | static int __init gb_init(void) |
Greg Kroah-Hartman | 199d68d | 2014-08-30 16:20:22 -0700 | [diff] [blame] | 299 | { |
Greg Kroah-Hartman | db6e1fd | 2014-08-30 16:47:26 -0700 | [diff] [blame] | 300 | int retval; |
| 301 | |
Viresh Kumar | 337b068 | 2015-03-20 20:29:13 +0530 | [diff] [blame] | 302 | if (greybus_disabled()) |
| 303 | return -ENODEV; |
| 304 | |
Alex Elder | fb690ca | 2015-06-13 11:02:09 -0500 | [diff] [blame] | 305 | BUILD_BUG_ON(CPORT_ID_MAX >= (long)CPORT_ID_BAD); |
Alex Elder | 1bb3c72 | 2014-10-02 12:30:03 -0500 | [diff] [blame] | 306 | |
Greg Kroah-Hartman | 48f7047 | 2015-03-27 11:38:06 +0100 | [diff] [blame] | 307 | gb_debugfs_init(); |
Greg Kroah-Hartman | db6e1fd | 2014-08-30 16:47:26 -0700 | [diff] [blame] | 308 | |
Greg Kroah-Hartman | 27fb831 | 2014-08-31 13:54:59 -0700 | [diff] [blame] | 309 | retval = bus_register(&greybus_bus_type); |
Greg Kroah-Hartman | 168db1c | 2014-09-13 16:15:52 -0700 | [diff] [blame] | 310 | if (retval) { |
Alex Elder | f35ab90 | 2015-06-09 17:42:51 -0500 | [diff] [blame] | 311 | pr_err("bus_register failed (%d)\n", retval); |
Greg Kroah-Hartman | 27fb831 | 2014-08-31 13:54:59 -0700 | [diff] [blame] | 312 | goto error_bus; |
Greg Kroah-Hartman | 168db1c | 2014-09-13 16:15:52 -0700 | [diff] [blame] | 313 | } |
Greg Kroah-Hartman | 27fb831 | 2014-08-31 13:54:59 -0700 | [diff] [blame] | 314 | |
Johan Hovold | 2adaefb | 2015-11-25 15:59:02 +0100 | [diff] [blame] | 315 | retval = gb_hd_init(); |
| 316 | if (retval) { |
| 317 | pr_err("gb_hd_init failed (%d)\n", retval); |
| 318 | goto error_hd; |
| 319 | } |
| 320 | |
Alex Elder | 2eb585f | 2014-10-16 06:35:34 -0500 | [diff] [blame] | 321 | retval = gb_operation_init(); |
| 322 | if (retval) { |
Alex Elder | f35ab90 | 2015-06-09 17:42:51 -0500 | [diff] [blame] | 323 | pr_err("gb_operation_init failed (%d)\n", retval); |
Alex Elder | 2eb585f | 2014-10-16 06:35:34 -0500 | [diff] [blame] | 324 | goto error_operation; |
| 325 | } |
Alex Elder | 19d03de | 2014-11-05 16:12:53 -0600 | [diff] [blame] | 326 | return 0; /* Success */ |
| 327 | |
Alex Elder | 2eb585f | 2014-10-16 06:35:34 -0500 | [diff] [blame] | 328 | error_operation: |
Johan Hovold | 2adaefb | 2015-11-25 15:59:02 +0100 | [diff] [blame] | 329 | gb_hd_exit(); |
| 330 | error_hd: |
Greg Kroah-Hartman | 27fb831 | 2014-08-31 13:54:59 -0700 | [diff] [blame] | 331 | bus_unregister(&greybus_bus_type); |
Greg Kroah-Hartman | 27fb831 | 2014-08-31 13:54:59 -0700 | [diff] [blame] | 332 | error_bus: |
Greg Kroah-Hartman | de536e3 | 2014-08-31 16:17:04 -0700 | [diff] [blame] | 333 | gb_debugfs_cleanup(); |
Greg Kroah-Hartman | 27fb831 | 2014-08-31 13:54:59 -0700 | [diff] [blame] | 334 | |
| 335 | return retval; |
Greg Kroah-Hartman | 199d68d | 2014-08-30 16:20:22 -0700 | [diff] [blame] | 336 | } |
Viresh Kumar | d71aaf2 | 2015-03-19 17:02:49 +0530 | [diff] [blame] | 337 | module_init(gb_init); |
Greg Kroah-Hartman | 199d68d | 2014-08-30 16:20:22 -0700 | [diff] [blame] | 338 | |
Greg Kroah-Hartman | 503c1cd | 2014-08-30 16:21:03 -0700 | [diff] [blame] | 339 | static void __exit gb_exit(void) |
Greg Kroah-Hartman | 199d68d | 2014-08-30 16:20:22 -0700 | [diff] [blame] | 340 | { |
Alex Elder | 2eb585f | 2014-10-16 06:35:34 -0500 | [diff] [blame] | 341 | gb_operation_exit(); |
Johan Hovold | 2adaefb | 2015-11-25 15:59:02 +0100 | [diff] [blame] | 342 | gb_hd_exit(); |
Greg Kroah-Hartman | 27fb831 | 2014-08-31 13:54:59 -0700 | [diff] [blame] | 343 | bus_unregister(&greybus_bus_type); |
Greg Kroah-Hartman | de536e3 | 2014-08-31 16:17:04 -0700 | [diff] [blame] | 344 | gb_debugfs_cleanup(); |
Bryan O'Donoghue | 5c8ad59 | 2015-09-18 16:38:45 +0100 | [diff] [blame] | 345 | tracepoint_synchronize_unregister(); |
Greg Kroah-Hartman | 199d68d | 2014-08-30 16:20:22 -0700 | [diff] [blame] | 346 | } |
Greg Kroah-Hartman | 199d68d | 2014-08-30 16:20:22 -0700 | [diff] [blame] | 347 | module_exit(gb_exit); |
Greg Kroah-Hartman | 6cf42a4 | 2015-04-13 19:51:33 +0200 | [diff] [blame] | 348 | MODULE_LICENSE("GPL v2"); |
Greg Kroah-Hartman | c8a797a | 2014-08-11 15:30:45 +0800 | [diff] [blame] | 349 | MODULE_AUTHOR("Greg Kroah-Hartman <gregkh@linuxfoundation.org>"); |