Thomas Gleixner | 1ccea77 | 2019-05-19 15:51:43 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Bill Richardson | e7c256f | 2015-02-02 12:26:25 +0100 | [diff] [blame] | 2 | /* |
| 3 | * cros_ec_dev - expose the Chrome OS Embedded Controller to user-space |
| 4 | * |
| 5 | * Copyright (C) 2014 Google, Inc. |
Bill Richardson | e7c256f | 2015-02-02 12:26:25 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
Gwendal Grignou | a75f4d1 | 2021-05-25 20:45:00 -0700 | [diff] [blame] | 8 | #include <linux/dmi.h> |
Prashant Malani | 4602dce | 2020-01-14 15:22:20 -0800 | [diff] [blame] | 9 | #include <linux/kconfig.h> |
Enric Balletbo i Serra | 5668bfd | 2016-08-01 11:54:38 +0200 | [diff] [blame] | 10 | #include <linux/mfd/core.h> |
Bill Richardson | e7c256f | 2015-02-02 12:26:25 +0100 | [diff] [blame] | 11 | #include <linux/module.h> |
Randy Dunlap | ac31672 | 2018-06-19 22:47:28 -0700 | [diff] [blame] | 12 | #include <linux/mod_devicetable.h> |
Enric Balletbo i Serra | 0545625 | 2018-12-12 18:34:01 +0100 | [diff] [blame] | 13 | #include <linux/of_platform.h> |
Bill Richardson | e7c256f | 2015-02-02 12:26:25 +0100 | [diff] [blame] | 14 | #include <linux/platform_device.h> |
Enric Balletbo i Serra | 459aedb | 2019-09-02 11:53:03 +0200 | [diff] [blame] | 15 | #include <linux/platform_data/cros_ec_chardev.h> |
Enric Balletbo i Serra | 840d9f1 | 2019-09-02 11:53:05 +0200 | [diff] [blame] | 16 | #include <linux/platform_data/cros_ec_commands.h> |
| 17 | #include <linux/platform_data/cros_ec_proto.h> |
Javier Martinez Canillas | a841178 | 2015-06-09 13:04:42 +0200 | [diff] [blame] | 18 | #include <linux/slab.h> |
Bill Richardson | e7c256f | 2015-02-02 12:26:25 +0100 | [diff] [blame] | 19 | |
Thierry Escande | ea01a31 | 2017-11-20 17:15:25 +0100 | [diff] [blame] | 20 | #define DRV_NAME "cros-ec-dev" |
| 21 | |
Gwendal Grignou | 57b33ff | 2015-06-09 13:04:47 +0200 | [diff] [blame] | 22 | static struct class cros_class = { |
| 23 | .owner = THIS_MODULE, |
| 24 | .name = "chromeos", |
Gwendal Grignou | 57b33ff | 2015-06-09 13:04:47 +0200 | [diff] [blame] | 25 | }; |
| 26 | |
Enric Balletbo i Serra | b027dcf | 2019-09-02 11:53:07 +0200 | [diff] [blame] | 27 | /** |
Lee Jones | 5ae3d1b | 2020-06-24 13:07:45 +0100 | [diff] [blame] | 28 | * struct cros_feature_to_name - CrOS feature id to name/short description. |
Enric Balletbo i Serra | b027dcf | 2019-09-02 11:53:07 +0200 | [diff] [blame] | 29 | * @id: The feature identifier. |
| 30 | * @name: Device name associated with the feature id. |
| 31 | * @desc: Short name that will be displayed. |
| 32 | */ |
| 33 | struct cros_feature_to_name { |
| 34 | unsigned int id; |
| 35 | const char *name; |
| 36 | const char *desc; |
| 37 | }; |
| 38 | |
Enric Balletbo i Serra | 832a636 | 2019-09-02 11:53:08 +0200 | [diff] [blame] | 39 | /** |
Lee Jones | 5ae3d1b | 2020-06-24 13:07:45 +0100 | [diff] [blame] | 40 | * struct cros_feature_to_cells - CrOS feature id to mfd cells association. |
Enric Balletbo i Serra | 832a636 | 2019-09-02 11:53:08 +0200 | [diff] [blame] | 41 | * @id: The feature identifier. |
| 42 | * @mfd_cells: Pointer to the array of mfd cells that needs to be added. |
| 43 | * @num_cells: Number of mfd cells into the array. |
| 44 | */ |
| 45 | struct cros_feature_to_cells { |
| 46 | unsigned int id; |
| 47 | const struct mfd_cell *mfd_cells; |
| 48 | unsigned int num_cells; |
| 49 | }; |
| 50 | |
Enric Balletbo i Serra | b027dcf | 2019-09-02 11:53:07 +0200 | [diff] [blame] | 51 | static const struct cros_feature_to_name cros_mcu_devices[] = { |
| 52 | { |
| 53 | .id = EC_FEATURE_FINGERPRINT, |
| 54 | .name = CROS_EC_DEV_FP_NAME, |
| 55 | .desc = "Fingerprint", |
| 56 | }, |
| 57 | { |
| 58 | .id = EC_FEATURE_ISH, |
| 59 | .name = CROS_EC_DEV_ISH_NAME, |
| 60 | .desc = "Integrated Sensor Hub", |
| 61 | }, |
| 62 | { |
| 63 | .id = EC_FEATURE_SCP, |
| 64 | .name = CROS_EC_DEV_SCP_NAME, |
| 65 | .desc = "System Control Processor", |
| 66 | }, |
| 67 | { |
| 68 | .id = EC_FEATURE_TOUCHPAD, |
| 69 | .name = CROS_EC_DEV_TP_NAME, |
| 70 | .desc = "Touchpad", |
| 71 | }, |
| 72 | }; |
| 73 | |
Enric Balletbo i Serra | 832a636 | 2019-09-02 11:53:08 +0200 | [diff] [blame] | 74 | static const struct mfd_cell cros_ec_cec_cells[] = { |
| 75 | { .name = "cros-ec-cec", }, |
| 76 | }; |
| 77 | |
| 78 | static const struct mfd_cell cros_ec_rtc_cells[] = { |
| 79 | { .name = "cros-ec-rtc", }, |
| 80 | }; |
| 81 | |
Gwendal Grignou | d60ac88 | 2019-11-19 13:45:45 +0100 | [diff] [blame] | 82 | static const struct mfd_cell cros_ec_sensorhub_cells[] = { |
| 83 | { .name = "cros-ec-sensorhub", }, |
| 84 | }; |
| 85 | |
Enric Balletbo i Serra | 832a636 | 2019-09-02 11:53:08 +0200 | [diff] [blame] | 86 | static const struct mfd_cell cros_usbpd_charger_cells[] = { |
| 87 | { .name = "cros-usbpd-charger", }, |
| 88 | { .name = "cros-usbpd-logger", }, |
| 89 | }; |
| 90 | |
Prashant Malani | 4602dce | 2020-01-14 15:22:20 -0800 | [diff] [blame] | 91 | static const struct mfd_cell cros_usbpd_notify_cells[] = { |
| 92 | { .name = "cros-usbpd-notify", }, |
| 93 | }; |
| 94 | |
Enric Balletbo i Serra | 832a636 | 2019-09-02 11:53:08 +0200 | [diff] [blame] | 95 | static const struct cros_feature_to_cells cros_subdevices[] = { |
| 96 | { |
| 97 | .id = EC_FEATURE_CEC, |
| 98 | .mfd_cells = cros_ec_cec_cells, |
| 99 | .num_cells = ARRAY_SIZE(cros_ec_cec_cells), |
| 100 | }, |
| 101 | { |
| 102 | .id = EC_FEATURE_RTC, |
| 103 | .mfd_cells = cros_ec_rtc_cells, |
| 104 | .num_cells = ARRAY_SIZE(cros_ec_rtc_cells), |
| 105 | }, |
| 106 | { |
| 107 | .id = EC_FEATURE_USB_PD, |
| 108 | .mfd_cells = cros_usbpd_charger_cells, |
| 109 | .num_cells = ARRAY_SIZE(cros_usbpd_charger_cells), |
| 110 | }, |
| 111 | }; |
| 112 | |
| 113 | static const struct mfd_cell cros_ec_platform_cells[] = { |
| 114 | { .name = "cros-ec-chardev", }, |
| 115 | { .name = "cros-ec-debugfs", }, |
Enric Balletbo i Serra | 832a636 | 2019-09-02 11:53:08 +0200 | [diff] [blame] | 116 | { .name = "cros-ec-sysfs", }, |
Daisuke Nojiri | 8a14ded | 2021-06-16 11:51:25 -0700 | [diff] [blame] | 117 | { .name = "cros-ec-pchg", }, |
Enric Balletbo i Serra | 832a636 | 2019-09-02 11:53:08 +0200 | [diff] [blame] | 118 | }; |
| 119 | |
Gwendal Grignou | a75f4d1 | 2021-05-25 20:45:00 -0700 | [diff] [blame] | 120 | static const struct mfd_cell cros_ec_lightbar_cells[] = { |
| 121 | { .name = "cros-ec-lightbar", } |
| 122 | }; |
| 123 | |
Enric Balletbo i Serra | 832a636 | 2019-09-02 11:53:08 +0200 | [diff] [blame] | 124 | static const struct mfd_cell cros_ec_vbc_cells[] = { |
| 125 | { .name = "cros-ec-vbc", } |
| 126 | }; |
| 127 | |
Enric Balletbo i Serra | 48a2ca0 | 2018-12-04 16:58:43 +0100 | [diff] [blame] | 128 | static void cros_ec_class_release(struct device *dev) |
| 129 | { |
| 130 | kfree(to_cros_ec_dev(dev)); |
| 131 | } |
| 132 | |
Bill Richardson | e7c256f | 2015-02-02 12:26:25 +0100 | [diff] [blame] | 133 | static int ec_device_probe(struct platform_device *pdev) |
| 134 | { |
Gwendal Grignou | 57b33ff | 2015-06-09 13:04:47 +0200 | [diff] [blame] | 135 | int retval = -ENOMEM; |
Enric Balletbo i Serra | 0545625 | 2018-12-12 18:34:01 +0100 | [diff] [blame] | 136 | struct device_node *node; |
Gwendal Grignou | 57b33ff | 2015-06-09 13:04:47 +0200 | [diff] [blame] | 137 | struct device *dev = &pdev->dev; |
| 138 | struct cros_ec_platform *ec_platform = dev_get_platdata(dev); |
Enric Balletbo i Serra | 48a2ca0 | 2018-12-04 16:58:43 +0100 | [diff] [blame] | 139 | struct cros_ec_dev *ec = kzalloc(sizeof(*ec), GFP_KERNEL); |
Enric Balletbo i Serra | b027dcf | 2019-09-02 11:53:07 +0200 | [diff] [blame] | 140 | int i; |
Bill Richardson | e7c256f | 2015-02-02 12:26:25 +0100 | [diff] [blame] | 141 | |
Gwendal Grignou | 57b33ff | 2015-06-09 13:04:47 +0200 | [diff] [blame] | 142 | if (!ec) |
| 143 | return retval; |
| 144 | |
| 145 | dev_set_drvdata(dev, ec); |
| 146 | ec->ec_dev = dev_get_drvdata(dev->parent); |
| 147 | ec->dev = dev; |
| 148 | ec->cmd_offset = ec_platform->cmd_offset; |
Prashant Malani | 7ff2278 | 2021-10-04 10:07:09 -0700 | [diff] [blame] | 149 | ec->features.flags[0] = -1U; /* Not cached yet */ |
| 150 | ec->features.flags[1] = -1U; /* Not cached yet */ |
Gwendal Grignou | 57b33ff | 2015-06-09 13:04:47 +0200 | [diff] [blame] | 151 | device_initialize(&ec->class_dev); |
Bill Richardson | e7c256f | 2015-02-02 12:26:25 +0100 | [diff] [blame] | 152 | |
Enric Balletbo i Serra | b027dcf | 2019-09-02 11:53:07 +0200 | [diff] [blame] | 153 | for (i = 0; i < ARRAY_SIZE(cros_mcu_devices); i++) { |
Enric Balletbo i Serra | 90486af | 2019-05-08 11:19:55 +0200 | [diff] [blame] | 154 | /* |
Enric Balletbo i Serra | b027dcf | 2019-09-02 11:53:07 +0200 | [diff] [blame] | 155 | * Check whether this is actually a dedicated MCU rather |
| 156 | * than an standard EC. |
Enric Balletbo i Serra | 90486af | 2019-05-08 11:19:55 +0200 | [diff] [blame] | 157 | */ |
Enric Balletbo i Serra | b027dcf | 2019-09-02 11:53:07 +0200 | [diff] [blame] | 158 | if (cros_ec_check_features(ec, cros_mcu_devices[i].id)) { |
| 159 | dev_info(dev, "CrOS %s MCU detected\n", |
| 160 | cros_mcu_devices[i].desc); |
| 161 | /* |
| 162 | * Help userspace differentiating ECs from other MCU, |
| 163 | * regardless of the probing order. |
| 164 | */ |
| 165 | ec_platform->ec_name = cros_mcu_devices[i].name; |
| 166 | break; |
| 167 | } |
Pi-Hsun Shih | 554e937 | 2019-06-03 11:45:11 +0800 | [diff] [blame] | 168 | } |
| 169 | |
Rushikesh S Kadam | d4cee95 | 2019-03-01 13:50:54 +0530 | [diff] [blame] | 170 | /* |
Gwendal Grignou | 57b33ff | 2015-06-09 13:04:47 +0200 | [diff] [blame] | 171 | * Add the class device |
Gwendal Grignou | 57b33ff | 2015-06-09 13:04:47 +0200 | [diff] [blame] | 172 | */ |
Gwendal Grignou | 57b33ff | 2015-06-09 13:04:47 +0200 | [diff] [blame] | 173 | ec->class_dev.class = &cros_class; |
| 174 | ec->class_dev.parent = dev; |
Enric Balletbo i Serra | 48a2ca0 | 2018-12-04 16:58:43 +0100 | [diff] [blame] | 175 | ec->class_dev.release = cros_ec_class_release; |
Gwendal Grignou | 57b33ff | 2015-06-09 13:04:47 +0200 | [diff] [blame] | 176 | |
| 177 | retval = dev_set_name(&ec->class_dev, "%s", ec_platform->ec_name); |
| 178 | if (retval) { |
| 179 | dev_err(dev, "dev_set_name failed => %d\n", retval); |
Logan Gunthorpe | 1c1d152 | 2017-03-17 12:48:14 -0600 | [diff] [blame] | 180 | goto failed; |
Bill Richardson | e7c256f | 2015-02-02 12:26:25 +0100 | [diff] [blame] | 181 | } |
| 182 | |
Enric Balletbo i Serra | 459aedb | 2019-09-02 11:53:03 +0200 | [diff] [blame] | 183 | retval = device_add(&ec->class_dev); |
| 184 | if (retval) |
| 185 | goto failed; |
| 186 | |
Gwendal Grignou | c1d1e91a | 2018-03-23 18:42:47 +0100 | [diff] [blame] | 187 | /* check whether this EC is a sensor hub. */ |
Gwendal Grignou | d60ac88 | 2019-11-19 13:45:45 +0100 | [diff] [blame] | 188 | if (cros_ec_get_sensor_count(ec) > 0) { |
| 189 | retval = mfd_add_hotplug_devices(ec->dev, |
| 190 | cros_ec_sensorhub_cells, |
| 191 | ARRAY_SIZE(cros_ec_sensorhub_cells)); |
| 192 | if (retval) |
| 193 | dev_err(ec->dev, "failed to add %s subdevice: %d\n", |
| 194 | cros_ec_sensorhub_cells->name, retval); |
| 195 | } |
Gwendal Grignou | c1d1e91a | 2018-03-23 18:42:47 +0100 | [diff] [blame] | 196 | |
Enric Balletbo i Serra | 832a636 | 2019-09-02 11:53:08 +0200 | [diff] [blame] | 197 | /* |
| 198 | * The following subdevices can be detected by sending the |
| 199 | * EC_FEATURE_GET_CMD Embedded Controller device. |
| 200 | */ |
| 201 | for (i = 0; i < ARRAY_SIZE(cros_subdevices); i++) { |
| 202 | if (cros_ec_check_features(ec, cros_subdevices[i].id)) { |
| 203 | retval = mfd_add_hotplug_devices(ec->dev, |
| 204 | cros_subdevices[i].mfd_cells, |
| 205 | cros_subdevices[i].num_cells); |
| 206 | if (retval) |
| 207 | dev_err(ec->dev, |
| 208 | "failed to add %s subdevice: %d\n", |
| 209 | cros_subdevices[i].mfd_cells->name, |
| 210 | retval); |
| 211 | } |
Neil Armstrong | 03a5755 | 2018-07-04 17:08:20 +0200 | [diff] [blame] | 212 | } |
| 213 | |
Enric Balletbo i Serra | 832a636 | 2019-09-02 11:53:08 +0200 | [diff] [blame] | 214 | /* |
Gwendal Grignou | a75f4d1 | 2021-05-25 20:45:00 -0700 | [diff] [blame] | 215 | * Lightbar is a special case. Newer devices support autodetection, |
| 216 | * but older ones do not. |
| 217 | */ |
| 218 | if (cros_ec_check_features(ec, EC_FEATURE_LIGHTBAR) || |
| 219 | dmi_match(DMI_PRODUCT_NAME, "Link")) { |
| 220 | retval = mfd_add_hotplug_devices(ec->dev, |
| 221 | cros_ec_lightbar_cells, |
| 222 | ARRAY_SIZE(cros_ec_lightbar_cells)); |
| 223 | if (retval) |
| 224 | dev_warn(ec->dev, "failed to add lightbar: %d\n", |
| 225 | retval); |
| 226 | } |
| 227 | |
| 228 | /* |
Prashant Malani | 4602dce | 2020-01-14 15:22:20 -0800 | [diff] [blame] | 229 | * The PD notifier driver cell is separate since it only needs to be |
| 230 | * explicitly added on platforms that don't have the PD notifier ACPI |
| 231 | * device entry defined. |
| 232 | */ |
Prashant Malani | f8db89d | 2020-02-10 11:06:24 -0800 | [diff] [blame] | 233 | if (IS_ENABLED(CONFIG_OF) && ec->ec_dev->dev->of_node) { |
Prashant Malani | 4602dce | 2020-01-14 15:22:20 -0800 | [diff] [blame] | 234 | if (cros_ec_check_features(ec, EC_FEATURE_USB_PD)) { |
| 235 | retval = mfd_add_hotplug_devices(ec->dev, |
| 236 | cros_usbpd_notify_cells, |
| 237 | ARRAY_SIZE(cros_usbpd_notify_cells)); |
| 238 | if (retval) |
| 239 | dev_err(ec->dev, |
| 240 | "failed to add PD notify devices: %d\n", |
| 241 | retval); |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | /* |
Enric Balletbo i Serra | 832a636 | 2019-09-02 11:53:08 +0200 | [diff] [blame] | 246 | * The following subdevices cannot be detected by sending the |
| 247 | * EC_FEATURE_GET_CMD to the Embedded Controller device. |
| 248 | */ |
Enric Balletbo i Serra | 28e6fcc | 2019-09-02 11:53:09 +0200 | [diff] [blame] | 249 | retval = mfd_add_hotplug_devices(ec->dev, cros_ec_platform_cells, |
| 250 | ARRAY_SIZE(cros_ec_platform_cells)); |
Enric Balletbo i Serra | ecf8a6c | 2018-12-12 18:33:57 +0100 | [diff] [blame] | 251 | if (retval) |
| 252 | dev_warn(ec->dev, |
| 253 | "failed to add cros-ec platform devices: %d\n", |
| 254 | retval); |
| 255 | |
Enric Balletbo i Serra | 0545625 | 2018-12-12 18:34:01 +0100 | [diff] [blame] | 256 | /* Check whether this EC instance has a VBC NVRAM */ |
| 257 | node = ec->ec_dev->dev->of_node; |
| 258 | if (of_property_read_bool(node, "google,has-vbc-nvram")) { |
Enric Balletbo i Serra | 28e6fcc | 2019-09-02 11:53:09 +0200 | [diff] [blame] | 259 | retval = mfd_add_hotplug_devices(ec->dev, cros_ec_vbc_cells, |
| 260 | ARRAY_SIZE(cros_ec_vbc_cells)); |
Enric Balletbo i Serra | 0545625 | 2018-12-12 18:34:01 +0100 | [diff] [blame] | 261 | if (retval) |
| 262 | dev_warn(ec->dev, "failed to add VBC devices: %d\n", |
| 263 | retval); |
| 264 | } |
| 265 | |
Bill Richardson | e7c256f | 2015-02-02 12:26:25 +0100 | [diff] [blame] | 266 | return 0; |
Gwendal Grignou | 57b33ff | 2015-06-09 13:04:47 +0200 | [diff] [blame] | 267 | |
Logan Gunthorpe | 1c1d152 | 2017-03-17 12:48:14 -0600 | [diff] [blame] | 268 | failed: |
| 269 | put_device(&ec->class_dev); |
Gwendal Grignou | 57b33ff | 2015-06-09 13:04:47 +0200 | [diff] [blame] | 270 | return retval; |
Bill Richardson | e7c256f | 2015-02-02 12:26:25 +0100 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | static int ec_device_remove(struct platform_device *pdev) |
| 274 | { |
Gwendal Grignou | 57b33ff | 2015-06-09 13:04:47 +0200 | [diff] [blame] | 275 | struct cros_ec_dev *ec = dev_get_drvdata(&pdev->dev); |
Eric Caruso | e862645 | 2017-05-16 17:46:48 +0200 | [diff] [blame] | 276 | |
Enric Balletbo i Serra | 18e294d | 2018-12-10 19:00:02 +0100 | [diff] [blame] | 277 | mfd_remove_devices(ec->dev); |
Gwendal Grignou | 57b33ff | 2015-06-09 13:04:47 +0200 | [diff] [blame] | 278 | device_unregister(&ec->class_dev); |
Bill Richardson | e7c256f | 2015-02-02 12:26:25 +0100 | [diff] [blame] | 279 | return 0; |
| 280 | } |
| 281 | |
Javier Martinez Canillas | afbf8ec | 2015-06-22 08:27:20 +0200 | [diff] [blame] | 282 | static const struct platform_device_id cros_ec_id[] = { |
Thierry Escande | ea01a31 | 2017-11-20 17:15:25 +0100 | [diff] [blame] | 283 | { DRV_NAME, 0 }, |
Wei-Ning Huang | abeed71 | 2018-04-18 12:24:03 +0200 | [diff] [blame] | 284 | { /* sentinel */ } |
Javier Martinez Canillas | afbf8ec | 2015-06-22 08:27:20 +0200 | [diff] [blame] | 285 | }; |
| 286 | MODULE_DEVICE_TABLE(platform, cros_ec_id); |
| 287 | |
Bill Richardson | e7c256f | 2015-02-02 12:26:25 +0100 | [diff] [blame] | 288 | static struct platform_driver cros_ec_dev_driver = { |
| 289 | .driver = { |
Thierry Escande | ea01a31 | 2017-11-20 17:15:25 +0100 | [diff] [blame] | 290 | .name = DRV_NAME, |
Bill Richardson | e7c256f | 2015-02-02 12:26:25 +0100 | [diff] [blame] | 291 | }, |
Nathan Chancellor | 6eb3578 | 2018-09-26 20:33:17 -0700 | [diff] [blame] | 292 | .id_table = cros_ec_id, |
Bill Richardson | e7c256f | 2015-02-02 12:26:25 +0100 | [diff] [blame] | 293 | .probe = ec_device_probe, |
| 294 | .remove = ec_device_remove, |
| 295 | }; |
| 296 | |
| 297 | static int __init cros_ec_dev_init(void) |
| 298 | { |
| 299 | int ret; |
Bill Richardson | e7c256f | 2015-02-02 12:26:25 +0100 | [diff] [blame] | 300 | |
Gwendal Grignou | 57b33ff | 2015-06-09 13:04:47 +0200 | [diff] [blame] | 301 | ret = class_register(&cros_class); |
| 302 | if (ret) { |
Bill Richardson | e7c256f | 2015-02-02 12:26:25 +0100 | [diff] [blame] | 303 | pr_err(CROS_EC_DEV_NAME ": failed to register device class\n"); |
Gwendal Grignou | 57b33ff | 2015-06-09 13:04:47 +0200 | [diff] [blame] | 304 | return ret; |
Bill Richardson | e7c256f | 2015-02-02 12:26:25 +0100 | [diff] [blame] | 305 | } |
| 306 | |
Bill Richardson | e7c256f | 2015-02-02 12:26:25 +0100 | [diff] [blame] | 307 | /* Register the driver */ |
| 308 | ret = platform_driver_register(&cros_ec_dev_driver); |
| 309 | if (ret < 0) { |
| 310 | pr_warn(CROS_EC_DEV_NAME ": can't register driver: %d\n", ret); |
| 311 | goto failed_devreg; |
| 312 | } |
| 313 | return 0; |
| 314 | |
| 315 | failed_devreg: |
Gwendal Grignou | 57b33ff | 2015-06-09 13:04:47 +0200 | [diff] [blame] | 316 | class_unregister(&cros_class); |
Bill Richardson | e7c256f | 2015-02-02 12:26:25 +0100 | [diff] [blame] | 317 | return ret; |
| 318 | } |
| 319 | |
| 320 | static void __exit cros_ec_dev_exit(void) |
| 321 | { |
| 322 | platform_driver_unregister(&cros_ec_dev_driver); |
Gwendal Grignou | 57b33ff | 2015-06-09 13:04:47 +0200 | [diff] [blame] | 323 | class_unregister(&cros_class); |
Bill Richardson | e7c256f | 2015-02-02 12:26:25 +0100 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | module_init(cros_ec_dev_init); |
| 327 | module_exit(cros_ec_dev_exit); |
| 328 | |
Bill Richardson | e7c256f | 2015-02-02 12:26:25 +0100 | [diff] [blame] | 329 | MODULE_AUTHOR("Bill Richardson <wfrichar@chromium.org>"); |
| 330 | MODULE_DESCRIPTION("Userspace interface to the Chrome OS Embedded Controller"); |
| 331 | MODULE_VERSION("1.0"); |
| 332 | MODULE_LICENSE("GPL"); |