Dmitry Torokhov | 203e0ba | 2018-03-20 15:31:28 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | // Driver to instantiate Chromebook i2c/smbus devices. |
| 3 | // |
| 4 | // Copyright (C) 2012 Google, Inc. |
| 5 | // Author: Benson Leung <bleung@chromium.org> |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 6 | |
Dmitry Torokhov | 4f27f67 | 2018-03-20 15:31:30 -0700 | [diff] [blame] | 7 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 8 | |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 9 | #include <linux/dmi.h> |
| 10 | #include <linux/i2c.h> |
Nick Dyer | 7f3884f7 | 2015-08-04 16:36:29 -0700 | [diff] [blame] | 11 | #include <linux/platform_data/atmel_mxt_ts.h> |
Benson Leung | 2ef3920 | 2013-03-07 19:43:34 -0800 | [diff] [blame] | 12 | #include <linux/input.h> |
| 13 | #include <linux/interrupt.h> |
Dmitry Torokhov | e6215eea | 2018-03-20 15:31:35 -0700 | [diff] [blame^] | 14 | #include <linux/ioport.h> |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 15 | #include <linux/module.h> |
Dmitry Torokhov | 8d88cb0 | 2018-03-20 15:31:34 -0700 | [diff] [blame] | 16 | #include <linux/pci.h> |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 17 | #include <linux/platform_device.h> |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 18 | |
Benson Leung | 8e1ad4c | 2013-02-21 12:14:59 -0800 | [diff] [blame] | 19 | #define ATMEL_TP_I2C_ADDR 0x4b |
| 20 | #define ATMEL_TP_I2C_BL_ADDR 0x25 |
Yufeng Shen | 33a84f8 | 2013-02-21 12:15:00 -0800 | [diff] [blame] | 21 | #define ATMEL_TS_I2C_ADDR 0x4a |
| 22 | #define ATMEL_TS_I2C_BL_ADDR 0x26 |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 23 | #define CYAPA_TP_I2C_ADDR 0x67 |
Benson Leung | 9bd9a90 | 2016-05-02 08:57:16 +0800 | [diff] [blame] | 24 | #define ELAN_TP_I2C_ADDR 0x15 |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 25 | #define ISL_ALS_I2C_ADDR 0x44 |
Benson Leung | aabf3f4 | 2013-02-01 14:34:45 -0800 | [diff] [blame] | 26 | #define TAOS_ALS_I2C_ADDR 0x29 |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 27 | |
Olof Johansson | 6d3c1af | 2013-11-25 13:10:25 -0800 | [diff] [blame] | 28 | static const char *i2c_adapter_names[] = { |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 29 | "SMBus I801 adapter", |
Benson Leung | 741bf0c | 2013-02-21 12:14:55 -0800 | [diff] [blame] | 30 | "i915 gmbus vga", |
| 31 | "i915 gmbus panel", |
Jarkko Nikula | ebaf31c | 2015-11-03 13:09:00 +0200 | [diff] [blame] | 32 | "Synopsys DesignWare I2C adapter", |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 33 | }; |
| 34 | |
| 35 | /* Keep this enum consistent with i2c_adapter_names */ |
| 36 | enum i2c_adapter_type { |
| 37 | I2C_ADAPTER_SMBUS = 0, |
Benson Leung | 741bf0c | 2013-02-21 12:14:55 -0800 | [diff] [blame] | 38 | I2C_ADAPTER_VGADDC, |
| 39 | I2C_ADAPTER_PANEL, |
Dmitry Torokhov | 8d88cb0 | 2018-03-20 15:31:34 -0700 | [diff] [blame] | 40 | I2C_ADAPTER_DESIGNWARE, |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 41 | }; |
| 42 | |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 43 | struct i2c_peripheral { |
Dmitry Torokhov | 28cd38f | 2018-03-20 15:31:32 -0700 | [diff] [blame] | 44 | struct i2c_board_info board_info; |
| 45 | unsigned short alt_addr; |
Dmitry Torokhov | e6215eea | 2018-03-20 15:31:35 -0700 | [diff] [blame^] | 46 | |
Dmitry Torokhov | 28cd38f | 2018-03-20 15:31:32 -0700 | [diff] [blame] | 47 | const char *dmi_name; |
Dmitry Torokhov | e6215eea | 2018-03-20 15:31:35 -0700 | [diff] [blame^] | 48 | unsigned long irqflags; |
| 49 | struct resource irq_resource; |
| 50 | |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 51 | enum i2c_adapter_type type; |
Dmitry Torokhov | 8d88cb0 | 2018-03-20 15:31:34 -0700 | [diff] [blame] | 52 | u32 pci_devid; |
Dmitry Torokhov | 28cd38f | 2018-03-20 15:31:32 -0700 | [diff] [blame] | 53 | |
Dmitry Torokhov | 28cd38f | 2018-03-20 15:31:32 -0700 | [diff] [blame] | 54 | struct i2c_client *client; |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 55 | }; |
| 56 | |
Benson Leung | 9bd9a90 | 2016-05-02 08:57:16 +0800 | [diff] [blame] | 57 | #define MAX_I2C_PERIPHERALS 4 |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 58 | |
| 59 | struct chromeos_laptop { |
| 60 | struct i2c_peripheral i2c_peripherals[MAX_I2C_PERIPHERALS]; |
| 61 | }; |
| 62 | |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 63 | static struct chromeos_laptop *cros_laptop; |
| 64 | |
Dmitry Torokhov | 28cd38f | 2018-03-20 15:31:32 -0700 | [diff] [blame] | 65 | static struct i2c_client * |
Dmitry Torokhov | 8d88cb0 | 2018-03-20 15:31:34 -0700 | [diff] [blame] | 66 | chromes_laptop_instantiate_i2c_device(struct i2c_adapter *adapter, |
Dmitry Torokhov | 28cd38f | 2018-03-20 15:31:32 -0700 | [diff] [blame] | 67 | struct i2c_board_info *info, |
| 68 | unsigned short alt_addr) |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 69 | { |
Dmitry Torokhov | 96cba9b | 2015-04-14 13:50:09 -0700 | [diff] [blame] | 70 | const unsigned short addr_list[] = { info->addr, I2C_CLIENT_END }; |
Dmitry Torokhov | 8d88cb0 | 2018-03-20 15:31:34 -0700 | [diff] [blame] | 71 | struct i2c_client *client; |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 72 | |
Dmitry Torokhov | 96cba9b | 2015-04-14 13:50:09 -0700 | [diff] [blame] | 73 | /* |
| 74 | * Add the i2c device. If we can't detect it at the primary |
| 75 | * address we scan secondary addresses. In any case the client |
| 76 | * structure gets assigned primary address. |
| 77 | */ |
| 78 | client = i2c_new_probed_device(adapter, info, addr_list, NULL); |
Dmitry Torokhov | 28cd38f | 2018-03-20 15:31:32 -0700 | [diff] [blame] | 79 | if (!client && alt_addr) { |
Dmitry Torokhov | 96cba9b | 2015-04-14 13:50:09 -0700 | [diff] [blame] | 80 | struct i2c_board_info dummy_info = { |
| 81 | I2C_BOARD_INFO("dummy", info->addr), |
| 82 | }; |
Dmitry Torokhov | 28cd38f | 2018-03-20 15:31:32 -0700 | [diff] [blame] | 83 | const unsigned short alt_addr_list[] = { |
| 84 | alt_addr, I2C_CLIENT_END |
| 85 | }; |
Dmitry Torokhov | 96cba9b | 2015-04-14 13:50:09 -0700 | [diff] [blame] | 86 | struct i2c_client *dummy; |
| 87 | |
| 88 | dummy = i2c_new_probed_device(adapter, &dummy_info, |
| 89 | alt_addr_list, NULL); |
| 90 | if (dummy) { |
Dmitry Torokhov | 4f27f67 | 2018-03-20 15:31:30 -0700 | [diff] [blame] | 91 | pr_debug("%d-%02x is probed at %02x\n", |
Dmitry Torokhov | 8d88cb0 | 2018-03-20 15:31:34 -0700 | [diff] [blame] | 92 | adapter->nr, info->addr, dummy->addr); |
Dmitry Torokhov | 96cba9b | 2015-04-14 13:50:09 -0700 | [diff] [blame] | 93 | i2c_unregister_device(dummy); |
| 94 | client = i2c_new_device(adapter, info); |
| 95 | } |
| 96 | } |
| 97 | |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 98 | if (!client) |
Dmitry Torokhov | 8d88cb0 | 2018-03-20 15:31:34 -0700 | [diff] [blame] | 99 | pr_debug("failed to register device %d-%02x\n", |
| 100 | adapter->nr, info->addr); |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 101 | else |
Dmitry Torokhov | 8d88cb0 | 2018-03-20 15:31:34 -0700 | [diff] [blame] | 102 | pr_debug("added i2c device %d-%02x\n", |
| 103 | adapter->nr, info->addr); |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 104 | |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 105 | return client; |
| 106 | } |
| 107 | |
Dmitry Torokhov | 8d88cb0 | 2018-03-20 15:31:34 -0700 | [diff] [blame] | 108 | static bool chromeos_laptop_match_adapter_devid(struct device *dev, u32 devid) |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 109 | { |
Dmitry Torokhov | 8d88cb0 | 2018-03-20 15:31:34 -0700 | [diff] [blame] | 110 | struct pci_dev *pdev; |
Robin Schroer | 49c68a2 | 2014-05-29 20:45:07 +0200 | [diff] [blame] | 111 | |
Dmitry Torokhov | 8d88cb0 | 2018-03-20 15:31:34 -0700 | [diff] [blame] | 112 | if (!dev_is_pci(dev)) |
| 113 | return false; |
| 114 | |
| 115 | pdev = to_pci_dev(dev); |
| 116 | return devid == PCI_DEVID(pdev->bus->number, pdev->devfn); |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Dmitry Torokhov | 8d88cb0 | 2018-03-20 15:31:34 -0700 | [diff] [blame] | 119 | static void chromeos_laptop_check_adapter(struct i2c_adapter *adapter) |
Benson Leung | aabf3f4 | 2013-02-01 14:34:45 -0800 | [diff] [blame] | 120 | { |
Dmitry Torokhov | 28cd38f | 2018-03-20 15:31:32 -0700 | [diff] [blame] | 121 | struct i2c_peripheral *i2c_dev; |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 122 | int i; |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 123 | |
| 124 | for (i = 0; i < MAX_I2C_PERIPHERALS; i++) { |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 125 | i2c_dev = &cros_laptop->i2c_peripherals[i]; |
| 126 | |
Dmitry Torokhov | 8d88cb0 | 2018-03-20 15:31:34 -0700 | [diff] [blame] | 127 | /* No more peripherals */ |
Dmitry Torokhov | 28cd38f | 2018-03-20 15:31:32 -0700 | [diff] [blame] | 128 | if (!i2c_dev->board_info.addr) |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 129 | break; |
| 130 | |
Dmitry Torokhov | 8d88cb0 | 2018-03-20 15:31:34 -0700 | [diff] [blame] | 131 | /* Skip devices already created */ |
| 132 | if (i2c_dev->client) |
Benson Leung | 5502486 | 2014-07-15 17:43:11 -0700 | [diff] [blame] | 133 | continue; |
| 134 | |
Dmitry Torokhov | 8d88cb0 | 2018-03-20 15:31:34 -0700 | [diff] [blame] | 135 | if (strncmp(adapter->name, i2c_adapter_names[i2c_dev->type], |
| 136 | strlen(i2c_adapter_names[i2c_dev->type]))) |
| 137 | continue; |
| 138 | |
| 139 | if (i2c_dev->pci_devid && |
| 140 | !chromeos_laptop_match_adapter_devid(adapter->dev.parent, |
| 141 | i2c_dev->pci_devid)) { |
| 142 | continue; |
| 143 | } |
| 144 | |
| 145 | i2c_dev->client = |
| 146 | chromes_laptop_instantiate_i2c_device(adapter, |
| 147 | &i2c_dev->board_info, |
| 148 | i2c_dev->alt_addr); |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | static void chromeos_laptop_detach_i2c_client(struct i2c_client *client) |
| 153 | { |
| 154 | struct i2c_peripheral *i2c_dev; |
| 155 | int i; |
| 156 | |
| 157 | for (i = 0; i < MAX_I2C_PERIPHERALS; i++) { |
| 158 | i2c_dev = &cros_laptop->i2c_peripherals[i]; |
| 159 | |
| 160 | if (i2c_dev->client == client) |
| 161 | i2c_dev->client = NULL; |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | static int chromeos_laptop_i2c_notifier_call(struct notifier_block *nb, |
| 166 | unsigned long action, void *data) |
| 167 | { |
| 168 | struct device *dev = data; |
| 169 | |
| 170 | switch (action) { |
| 171 | case BUS_NOTIFY_ADD_DEVICE: |
| 172 | if (dev->type == &i2c_adapter_type) |
| 173 | chromeos_laptop_check_adapter(to_i2c_adapter(dev)); |
| 174 | break; |
| 175 | |
| 176 | case BUS_NOTIFY_REMOVED_DEVICE: |
| 177 | if (dev->type == &i2c_client_type) |
| 178 | chromeos_laptop_detach_i2c_client(to_i2c_client(dev)); |
| 179 | break; |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 180 | } |
| 181 | |
Dmitry Torokhov | 8d88cb0 | 2018-03-20 15:31:34 -0700 | [diff] [blame] | 182 | return 0; |
Benson Leung | aabf3f4 | 2013-02-01 14:34:45 -0800 | [diff] [blame] | 183 | } |
| 184 | |
Dmitry Torokhov | 8d88cb0 | 2018-03-20 15:31:34 -0700 | [diff] [blame] | 185 | static struct notifier_block chromeos_laptop_i2c_notifier = { |
| 186 | .notifier_call = chromeos_laptop_i2c_notifier_call, |
| 187 | }; |
| 188 | |
Dmitry Torokhov | fc88bbd | 2018-03-06 10:59:15 -0800 | [diff] [blame] | 189 | static struct chromeos_laptop samsung_series_5_550 = { |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 190 | .i2c_peripherals = { |
| 191 | /* Touchpad. */ |
Dmitry Torokhov | 28cd38f | 2018-03-20 15:31:32 -0700 | [diff] [blame] | 192 | { |
| 193 | .board_info = { |
| 194 | I2C_BOARD_INFO("cyapa", CYAPA_TP_I2C_ADDR), |
| 195 | .flags = I2C_CLIENT_WAKE, |
| 196 | }, |
| 197 | .dmi_name = "trackpad", |
| 198 | .type = I2C_ADAPTER_SMBUS, |
| 199 | }, |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 200 | /* Light Sensor. */ |
Dmitry Torokhov | 28cd38f | 2018-03-20 15:31:32 -0700 | [diff] [blame] | 201 | { |
| 202 | .board_info = { |
| 203 | I2C_BOARD_INFO("isl29018", ISL_ALS_I2C_ADDR), |
| 204 | }, |
| 205 | .dmi_name = "lightsensor", |
| 206 | .type = I2C_ADAPTER_SMBUS, |
| 207 | }, |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 208 | }, |
| 209 | }; |
| 210 | |
Dmitry Torokhov | fc88bbd | 2018-03-06 10:59:15 -0800 | [diff] [blame] | 211 | static struct chromeos_laptop samsung_series_5 = { |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 212 | .i2c_peripherals = { |
| 213 | /* Light Sensor. */ |
Dmitry Torokhov | 28cd38f | 2018-03-20 15:31:32 -0700 | [diff] [blame] | 214 | { |
| 215 | .board_info = { |
| 216 | I2C_BOARD_INFO("tsl2583", TAOS_ALS_I2C_ADDR), |
| 217 | }, |
| 218 | .type = I2C_ADAPTER_SMBUS, |
| 219 | }, |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 220 | }, |
| 221 | }; |
| 222 | |
Dmitry Torokhov | 28cd38f | 2018-03-20 15:31:32 -0700 | [diff] [blame] | 223 | static int chromebook_pixel_tp_keys[] = { |
| 224 | KEY_RESERVED, |
| 225 | KEY_RESERVED, |
| 226 | KEY_RESERVED, |
| 227 | KEY_RESERVED, |
| 228 | KEY_RESERVED, |
| 229 | BTN_LEFT |
| 230 | }; |
| 231 | |
| 232 | static struct mxt_platform_data chromebook_pixel_tp_platform_data = { |
Dmitry Torokhov | 28cd38f | 2018-03-20 15:31:32 -0700 | [diff] [blame] | 233 | .t19_num_keys = ARRAY_SIZE(chromebook_pixel_tp_keys), |
| 234 | .t19_keymap = chromebook_pixel_tp_keys, |
| 235 | }; |
| 236 | |
Dmitry Torokhov | fc88bbd | 2018-03-06 10:59:15 -0800 | [diff] [blame] | 237 | static struct chromeos_laptop chromebook_pixel = { |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 238 | .i2c_peripherals = { |
| 239 | /* Touch Screen. */ |
Dmitry Torokhov | 28cd38f | 2018-03-20 15:31:32 -0700 | [diff] [blame] | 240 | { |
| 241 | .board_info = { |
| 242 | I2C_BOARD_INFO("atmel_mxt_ts", |
| 243 | ATMEL_TS_I2C_ADDR), |
Dmitry Torokhov | 28cd38f | 2018-03-20 15:31:32 -0700 | [diff] [blame] | 244 | .flags = I2C_CLIENT_WAKE, |
| 245 | }, |
| 246 | .dmi_name = "touchscreen", |
Dmitry Torokhov | e6215eea | 2018-03-20 15:31:35 -0700 | [diff] [blame^] | 247 | .irqflags = IRQF_TRIGGER_FALLING, |
Dmitry Torokhov | 28cd38f | 2018-03-20 15:31:32 -0700 | [diff] [blame] | 248 | .type = I2C_ADAPTER_PANEL, |
| 249 | .alt_addr = ATMEL_TS_I2C_BL_ADDR, |
| 250 | }, |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 251 | /* Touchpad. */ |
Dmitry Torokhov | 28cd38f | 2018-03-20 15:31:32 -0700 | [diff] [blame] | 252 | { |
| 253 | .board_info = { |
| 254 | I2C_BOARD_INFO("atmel_mxt_tp", |
| 255 | ATMEL_TP_I2C_ADDR), |
| 256 | .platform_data = |
| 257 | &chromebook_pixel_tp_platform_data, |
| 258 | .flags = I2C_CLIENT_WAKE, |
| 259 | }, |
| 260 | .dmi_name = "trackpad", |
Dmitry Torokhov | e6215eea | 2018-03-20 15:31:35 -0700 | [diff] [blame^] | 261 | .irqflags = IRQF_TRIGGER_FALLING, |
Dmitry Torokhov | 28cd38f | 2018-03-20 15:31:32 -0700 | [diff] [blame] | 262 | .type = I2C_ADAPTER_VGADDC, |
| 263 | .alt_addr = ATMEL_TP_I2C_BL_ADDR, |
| 264 | }, |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 265 | /* Light Sensor. */ |
Dmitry Torokhov | 28cd38f | 2018-03-20 15:31:32 -0700 | [diff] [blame] | 266 | { |
| 267 | .board_info = { |
| 268 | I2C_BOARD_INFO("isl29018", ISL_ALS_I2C_ADDR), |
| 269 | }, |
| 270 | .dmi_name = "lightsensor", |
| 271 | .type = I2C_ADAPTER_PANEL, |
| 272 | }, |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 273 | }, |
| 274 | }; |
| 275 | |
Dmitry Torokhov | fc88bbd | 2018-03-06 10:59:15 -0800 | [diff] [blame] | 276 | static struct chromeos_laptop hp_chromebook_14 = { |
Benson Leung | 5ea9567 | 2014-06-17 14:02:01 -0700 | [diff] [blame] | 277 | .i2c_peripherals = { |
| 278 | /* Touchpad. */ |
Dmitry Torokhov | 28cd38f | 2018-03-20 15:31:32 -0700 | [diff] [blame] | 279 | { |
| 280 | .board_info = { |
| 281 | I2C_BOARD_INFO("cyapa", CYAPA_TP_I2C_ADDR), |
| 282 | .flags = I2C_CLIENT_WAKE, |
| 283 | }, |
| 284 | .dmi_name = "trackpad", |
Dmitry Torokhov | 8d88cb0 | 2018-03-20 15:31:34 -0700 | [diff] [blame] | 285 | .type = I2C_ADAPTER_DESIGNWARE, |
Dmitry Torokhov | 28cd38f | 2018-03-20 15:31:32 -0700 | [diff] [blame] | 286 | }, |
Benson Leung | 5ea9567 | 2014-06-17 14:02:01 -0700 | [diff] [blame] | 287 | }, |
| 288 | }; |
| 289 | |
Dmitry Torokhov | fc88bbd | 2018-03-06 10:59:15 -0800 | [diff] [blame] | 290 | static struct chromeos_laptop dell_chromebook_11 = { |
Mohammed Habibulla | 0e1e5e5 | 2014-06-17 14:02:02 -0700 | [diff] [blame] | 291 | .i2c_peripherals = { |
| 292 | /* Touchpad. */ |
Dmitry Torokhov | 28cd38f | 2018-03-20 15:31:32 -0700 | [diff] [blame] | 293 | { |
| 294 | .board_info = { |
| 295 | I2C_BOARD_INFO("cyapa", CYAPA_TP_I2C_ADDR), |
| 296 | .flags = I2C_CLIENT_WAKE, |
| 297 | }, |
| 298 | .dmi_name = "trackpad", |
Dmitry Torokhov | 8d88cb0 | 2018-03-20 15:31:34 -0700 | [diff] [blame] | 299 | .type = I2C_ADAPTER_DESIGNWARE, |
Dmitry Torokhov | 28cd38f | 2018-03-20 15:31:32 -0700 | [diff] [blame] | 300 | }, |
Charlie Mooney | 9e96aa7 | 2016-05-02 08:57:17 +0800 | [diff] [blame] | 301 | /* Elan Touchpad option. */ |
Dmitry Torokhov | 28cd38f | 2018-03-20 15:31:32 -0700 | [diff] [blame] | 302 | { |
| 303 | .board_info = { |
| 304 | I2C_BOARD_INFO("elan_i2c", ELAN_TP_I2C_ADDR), |
| 305 | .flags = I2C_CLIENT_WAKE, |
| 306 | }, |
| 307 | .dmi_name = "trackpad", |
Dmitry Torokhov | 8d88cb0 | 2018-03-20 15:31:34 -0700 | [diff] [blame] | 308 | .type = I2C_ADAPTER_DESIGNWARE, |
Dmitry Torokhov | 28cd38f | 2018-03-20 15:31:32 -0700 | [diff] [blame] | 309 | }, |
Mohammed Habibulla | 0e1e5e5 | 2014-06-17 14:02:02 -0700 | [diff] [blame] | 310 | }, |
| 311 | }; |
| 312 | |
Dmitry Torokhov | fc88bbd | 2018-03-06 10:59:15 -0800 | [diff] [blame] | 313 | static struct chromeos_laptop toshiba_cb35 = { |
Gene Chen | 963cb6f | 2014-06-17 14:02:03 -0700 | [diff] [blame] | 314 | .i2c_peripherals = { |
| 315 | /* Touchpad. */ |
Dmitry Torokhov | 28cd38f | 2018-03-20 15:31:32 -0700 | [diff] [blame] | 316 | { |
| 317 | .board_info = { |
| 318 | I2C_BOARD_INFO("cyapa", CYAPA_TP_I2C_ADDR), |
| 319 | .flags = I2C_CLIENT_WAKE, |
| 320 | }, |
| 321 | .dmi_name = "trackpad", |
Dmitry Torokhov | 8d88cb0 | 2018-03-20 15:31:34 -0700 | [diff] [blame] | 322 | .type = I2C_ADAPTER_DESIGNWARE, |
Dmitry Torokhov | 28cd38f | 2018-03-20 15:31:32 -0700 | [diff] [blame] | 323 | }, |
Gene Chen | 963cb6f | 2014-06-17 14:02:03 -0700 | [diff] [blame] | 324 | }, |
| 325 | }; |
| 326 | |
Dmitry Torokhov | fc88bbd | 2018-03-06 10:59:15 -0800 | [diff] [blame] | 327 | static struct chromeos_laptop acer_c7_chromebook = { |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 328 | .i2c_peripherals = { |
| 329 | /* Touchpad. */ |
Dmitry Torokhov | 28cd38f | 2018-03-20 15:31:32 -0700 | [diff] [blame] | 330 | { |
| 331 | .board_info = { |
| 332 | I2C_BOARD_INFO("cyapa", CYAPA_TP_I2C_ADDR), |
| 333 | .flags = I2C_CLIENT_WAKE, |
| 334 | }, |
| 335 | .dmi_name = "trackpad", |
| 336 | .type = I2C_ADAPTER_SMBUS, |
| 337 | }, |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 338 | }, |
| 339 | }; |
| 340 | |
Dmitry Torokhov | fc88bbd | 2018-03-06 10:59:15 -0800 | [diff] [blame] | 341 | static struct chromeos_laptop acer_ac700 = { |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 342 | .i2c_peripherals = { |
| 343 | /* Light Sensor. */ |
Dmitry Torokhov | 28cd38f | 2018-03-20 15:31:32 -0700 | [diff] [blame] | 344 | { |
| 345 | .board_info = { |
| 346 | I2C_BOARD_INFO("tsl2583", TAOS_ALS_I2C_ADDR), |
| 347 | }, |
| 348 | .type = I2C_ADAPTER_SMBUS, |
| 349 | }, |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 350 | }, |
| 351 | }; |
| 352 | |
Dmitry Torokhov | fc88bbd | 2018-03-06 10:59:15 -0800 | [diff] [blame] | 353 | static struct chromeos_laptop acer_c720 = { |
Mika Westerberg | da3b0ab | 2014-06-17 14:02:00 -0700 | [diff] [blame] | 354 | .i2c_peripherals = { |
Michael Mullin | b90b3c4 | 2014-07-15 20:00:54 -0400 | [diff] [blame] | 355 | /* Touchscreen. */ |
Dmitry Torokhov | 28cd38f | 2018-03-20 15:31:32 -0700 | [diff] [blame] | 356 | { |
| 357 | .board_info = { |
| 358 | I2C_BOARD_INFO("atmel_mxt_ts", |
| 359 | ATMEL_TS_I2C_ADDR), |
Dmitry Torokhov | 28cd38f | 2018-03-20 15:31:32 -0700 | [diff] [blame] | 360 | .flags = I2C_CLIENT_WAKE, |
| 361 | }, |
| 362 | .dmi_name = "touchscreen", |
Dmitry Torokhov | e6215eea | 2018-03-20 15:31:35 -0700 | [diff] [blame^] | 363 | .irqflags = IRQF_TRIGGER_FALLING, |
Dmitry Torokhov | 8d88cb0 | 2018-03-20 15:31:34 -0700 | [diff] [blame] | 364 | .type = I2C_ADAPTER_DESIGNWARE, |
| 365 | .pci_devid = PCI_DEVID(0, PCI_DEVFN(0x15, 0x2)), |
Dmitry Torokhov | 28cd38f | 2018-03-20 15:31:32 -0700 | [diff] [blame] | 366 | .alt_addr = ATMEL_TS_I2C_BL_ADDR, |
| 367 | }, |
Mika Westerberg | da3b0ab | 2014-06-17 14:02:00 -0700 | [diff] [blame] | 368 | /* Touchpad. */ |
Dmitry Torokhov | 28cd38f | 2018-03-20 15:31:32 -0700 | [diff] [blame] | 369 | { |
| 370 | .board_info = { |
| 371 | I2C_BOARD_INFO("cyapa", CYAPA_TP_I2C_ADDR), |
| 372 | .flags = I2C_CLIENT_WAKE, |
| 373 | }, |
| 374 | .dmi_name = "trackpad", |
Dmitry Torokhov | 8d88cb0 | 2018-03-20 15:31:34 -0700 | [diff] [blame] | 375 | .type = I2C_ADAPTER_DESIGNWARE, |
| 376 | .pci_devid = PCI_DEVID(0, PCI_DEVFN(0x15, 0x1)), |
Dmitry Torokhov | 28cd38f | 2018-03-20 15:31:32 -0700 | [diff] [blame] | 377 | }, |
Benson Leung | 9bd9a90 | 2016-05-02 08:57:16 +0800 | [diff] [blame] | 378 | /* Elan Touchpad option. */ |
Dmitry Torokhov | 28cd38f | 2018-03-20 15:31:32 -0700 | [diff] [blame] | 379 | { |
| 380 | .board_info = { |
| 381 | I2C_BOARD_INFO("elan_i2c", ELAN_TP_I2C_ADDR), |
| 382 | .flags = I2C_CLIENT_WAKE, |
| 383 | }, |
| 384 | .dmi_name = "trackpad", |
Dmitry Torokhov | 8d88cb0 | 2018-03-20 15:31:34 -0700 | [diff] [blame] | 385 | .type = I2C_ADAPTER_DESIGNWARE, |
| 386 | .pci_devid = PCI_DEVID(0, PCI_DEVFN(0x15, 0x1)), |
Dmitry Torokhov | 28cd38f | 2018-03-20 15:31:32 -0700 | [diff] [blame] | 387 | }, |
Mika Westerberg | da3b0ab | 2014-06-17 14:02:00 -0700 | [diff] [blame] | 388 | /* Light Sensor. */ |
Dmitry Torokhov | 28cd38f | 2018-03-20 15:31:32 -0700 | [diff] [blame] | 389 | { |
| 390 | .board_info = { |
| 391 | I2C_BOARD_INFO("isl29018", ISL_ALS_I2C_ADDR), |
| 392 | }, |
| 393 | .dmi_name = "lightsensor", |
Dmitry Torokhov | 8d88cb0 | 2018-03-20 15:31:34 -0700 | [diff] [blame] | 394 | .type = I2C_ADAPTER_DESIGNWARE, |
| 395 | .pci_devid = PCI_DEVID(0, PCI_DEVFN(0x15, 0x2)), |
Dmitry Torokhov | 28cd38f | 2018-03-20 15:31:32 -0700 | [diff] [blame] | 396 | }, |
Mika Westerberg | da3b0ab | 2014-06-17 14:02:00 -0700 | [diff] [blame] | 397 | }, |
| 398 | }; |
| 399 | |
Dmitry Torokhov | fc88bbd | 2018-03-06 10:59:15 -0800 | [diff] [blame] | 400 | static struct chromeos_laptop hp_pavilion_14_chromebook = { |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 401 | .i2c_peripherals = { |
| 402 | /* Touchpad. */ |
Dmitry Torokhov | 28cd38f | 2018-03-20 15:31:32 -0700 | [diff] [blame] | 403 | { |
| 404 | .board_info = { |
| 405 | I2C_BOARD_INFO("cyapa", CYAPA_TP_I2C_ADDR), |
| 406 | .flags = I2C_CLIENT_WAKE, |
| 407 | }, |
| 408 | .dmi_name = "trackpad", |
| 409 | .type = I2C_ADAPTER_SMBUS, |
| 410 | }, |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 411 | }, |
| 412 | }; |
| 413 | |
Dmitry Torokhov | fc88bbd | 2018-03-06 10:59:15 -0800 | [diff] [blame] | 414 | static struct chromeos_laptop cr48 = { |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 415 | .i2c_peripherals = { |
| 416 | /* Light Sensor. */ |
Dmitry Torokhov | 28cd38f | 2018-03-20 15:31:32 -0700 | [diff] [blame] | 417 | { |
| 418 | .board_info = { |
| 419 | I2C_BOARD_INFO("tsl2563", TAOS_ALS_I2C_ADDR), |
| 420 | }, |
| 421 | .type = I2C_ADAPTER_SMBUS, |
| 422 | }, |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 423 | }, |
| 424 | }; |
| 425 | |
Christoph Hellwig | 6faadbb | 2017-09-14 11:59:30 +0200 | [diff] [blame] | 426 | static const struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = { |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 427 | { |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 428 | .ident = "Samsung Series 5 550", |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 429 | .matches = { |
| 430 | DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG"), |
| 431 | DMI_MATCH(DMI_PRODUCT_NAME, "Lumpy"), |
| 432 | }, |
Dmitry Torokhov | 6558292 | 2018-03-20 15:31:33 -0700 | [diff] [blame] | 433 | .driver_data = (void *)&samsung_series_5_550, |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 434 | }, |
| 435 | { |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 436 | .ident = "Samsung Series 5", |
Benson Leung | 8016bcb | 2013-02-01 14:34:46 -0800 | [diff] [blame] | 437 | .matches = { |
| 438 | DMI_MATCH(DMI_PRODUCT_NAME, "Alex"), |
| 439 | }, |
Dmitry Torokhov | 6558292 | 2018-03-20 15:31:33 -0700 | [diff] [blame] | 440 | .driver_data = (void *)&samsung_series_5, |
Benson Leung | 8016bcb | 2013-02-01 14:34:46 -0800 | [diff] [blame] | 441 | }, |
| 442 | { |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 443 | .ident = "Chromebook Pixel", |
Benson Leung | aabf3f4 | 2013-02-01 14:34:45 -0800 | [diff] [blame] | 444 | .matches = { |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 445 | DMI_MATCH(DMI_SYS_VENDOR, "GOOGLE"), |
| 446 | DMI_MATCH(DMI_PRODUCT_NAME, "Link"), |
Benson Leung | aabf3f4 | 2013-02-01 14:34:45 -0800 | [diff] [blame] | 447 | }, |
Dmitry Torokhov | 6558292 | 2018-03-20 15:31:33 -0700 | [diff] [blame] | 448 | .driver_data = (void *)&chromebook_pixel, |
Benson Leung | aabf3f4 | 2013-02-01 14:34:45 -0800 | [diff] [blame] | 449 | }, |
| 450 | { |
Mohammed Habibulla | 0e1e5e5 | 2014-06-17 14:02:02 -0700 | [diff] [blame] | 451 | .ident = "Wolf", |
| 452 | .matches = { |
| 453 | DMI_MATCH(DMI_BIOS_VENDOR, "coreboot"), |
| 454 | DMI_MATCH(DMI_PRODUCT_NAME, "Wolf"), |
| 455 | }, |
Dmitry Torokhov | 6558292 | 2018-03-20 15:31:33 -0700 | [diff] [blame] | 456 | .driver_data = (void *)&dell_chromebook_11, |
Mohammed Habibulla | 0e1e5e5 | 2014-06-17 14:02:02 -0700 | [diff] [blame] | 457 | }, |
| 458 | { |
Benson Leung | 5ea9567 | 2014-06-17 14:02:01 -0700 | [diff] [blame] | 459 | .ident = "HP Chromebook 14", |
| 460 | .matches = { |
| 461 | DMI_MATCH(DMI_BIOS_VENDOR, "coreboot"), |
| 462 | DMI_MATCH(DMI_PRODUCT_NAME, "Falco"), |
| 463 | }, |
Dmitry Torokhov | 6558292 | 2018-03-20 15:31:33 -0700 | [diff] [blame] | 464 | .driver_data = (void *)&hp_chromebook_14, |
Benson Leung | 5ea9567 | 2014-06-17 14:02:01 -0700 | [diff] [blame] | 465 | }, |
| 466 | { |
Gene Chen | 963cb6f | 2014-06-17 14:02:03 -0700 | [diff] [blame] | 467 | .ident = "Toshiba CB35", |
| 468 | .matches = { |
| 469 | DMI_MATCH(DMI_BIOS_VENDOR, "coreboot"), |
| 470 | DMI_MATCH(DMI_PRODUCT_NAME, "Leon"), |
| 471 | }, |
Dmitry Torokhov | 6558292 | 2018-03-20 15:31:33 -0700 | [diff] [blame] | 472 | .driver_data = (void *)&toshiba_cb35, |
Gene Chen | 963cb6f | 2014-06-17 14:02:03 -0700 | [diff] [blame] | 473 | }, |
| 474 | { |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 475 | .ident = "Acer C7 Chromebook", |
| 476 | .matches = { |
| 477 | DMI_MATCH(DMI_PRODUCT_NAME, "Parrot"), |
| 478 | }, |
Dmitry Torokhov | 6558292 | 2018-03-20 15:31:33 -0700 | [diff] [blame] | 479 | .driver_data = (void *)&acer_c7_chromebook, |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 480 | }, |
| 481 | { |
| 482 | .ident = "Acer AC700", |
Benson Leung | aabf3f4 | 2013-02-01 14:34:45 -0800 | [diff] [blame] | 483 | .matches = { |
| 484 | DMI_MATCH(DMI_PRODUCT_NAME, "ZGB"), |
| 485 | }, |
Dmitry Torokhov | 6558292 | 2018-03-20 15:31:33 -0700 | [diff] [blame] | 486 | .driver_data = (void *)&acer_ac700, |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 487 | }, |
| 488 | { |
Mika Westerberg | da3b0ab | 2014-06-17 14:02:00 -0700 | [diff] [blame] | 489 | .ident = "Acer C720", |
| 490 | .matches = { |
| 491 | DMI_MATCH(DMI_PRODUCT_NAME, "Peppy"), |
| 492 | }, |
Dmitry Torokhov | 6558292 | 2018-03-20 15:31:33 -0700 | [diff] [blame] | 493 | .driver_data = (void *)&acer_c720, |
Mika Westerberg | da3b0ab | 2014-06-17 14:02:00 -0700 | [diff] [blame] | 494 | }, |
| 495 | { |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 496 | .ident = "HP Pavilion 14 Chromebook", |
| 497 | .matches = { |
| 498 | DMI_MATCH(DMI_PRODUCT_NAME, "Butterfly"), |
| 499 | }, |
Dmitry Torokhov | 6558292 | 2018-03-20 15:31:33 -0700 | [diff] [blame] | 500 | .driver_data = (void *)&hp_pavilion_14_chromebook, |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 501 | }, |
| 502 | { |
| 503 | .ident = "Cr-48", |
| 504 | .matches = { |
| 505 | DMI_MATCH(DMI_PRODUCT_NAME, "Mario"), |
| 506 | }, |
Dmitry Torokhov | 6558292 | 2018-03-20 15:31:33 -0700 | [diff] [blame] | 507 | .driver_data = (void *)&cr48, |
Benson Leung | aabf3f4 | 2013-02-01 14:34:45 -0800 | [diff] [blame] | 508 | }, |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 509 | { } |
| 510 | }; |
| 511 | MODULE_DEVICE_TABLE(dmi, chromeos_laptop_dmi_table); |
| 512 | |
Dmitry Torokhov | 8d88cb0 | 2018-03-20 15:31:34 -0700 | [diff] [blame] | 513 | static int __init chromeos_laptop_scan_adapter(struct device *dev, void *data) |
| 514 | { |
| 515 | struct i2c_adapter *adapter; |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 516 | |
Dmitry Torokhov | 8d88cb0 | 2018-03-20 15:31:34 -0700 | [diff] [blame] | 517 | adapter = i2c_verify_adapter(dev); |
| 518 | if (adapter) |
| 519 | chromeos_laptop_check_adapter(adapter); |
| 520 | |
| 521 | return 0; |
| 522 | } |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 523 | |
Dmitry Torokhov | 6558292 | 2018-03-20 15:31:33 -0700 | [diff] [blame] | 524 | static int __init chromeos_laptop_get_irq_from_dmi(const char *dmi_name) |
| 525 | { |
| 526 | const struct dmi_device *dmi_dev; |
| 527 | const struct dmi_dev_onboard *dev_data; |
| 528 | |
| 529 | dmi_dev = dmi_find_device(DMI_DEV_TYPE_DEV_ONBOARD, dmi_name, NULL); |
| 530 | if (!dmi_dev) { |
| 531 | pr_err("failed to find DMI device '%s'\n", dmi_name); |
| 532 | return -ENOENT; |
| 533 | } |
| 534 | |
| 535 | dev_data = dmi_dev->device_data; |
| 536 | if (!dev_data) { |
| 537 | pr_err("failed to get data from DMI for '%s'\n", dmi_name); |
| 538 | return -EINVAL; |
| 539 | } |
| 540 | |
| 541 | return dev_data->instance; |
| 542 | } |
| 543 | |
| 544 | static struct chromeos_laptop * __init |
| 545 | chromeos_laptop_prepare(const struct dmi_system_id *id) |
| 546 | { |
| 547 | struct i2c_peripheral *i2c_dev; |
| 548 | int irq; |
| 549 | int i; |
| 550 | |
| 551 | cros_laptop = (void *)id->driver_data; |
| 552 | |
| 553 | for (i = 0; i < MAX_I2C_PERIPHERALS; i++) { |
| 554 | i2c_dev = &cros_laptop->i2c_peripherals[i]; |
| 555 | |
| 556 | if (!i2c_dev->dmi_name) |
| 557 | continue; |
| 558 | |
| 559 | irq = chromeos_laptop_get_irq_from_dmi(i2c_dev->dmi_name); |
| 560 | if (irq < 0) |
| 561 | return ERR_PTR(irq); |
Dmitry Torokhov | e6215eea | 2018-03-20 15:31:35 -0700 | [diff] [blame^] | 562 | |
| 563 | i2c_dev->irq_resource = (struct resource) |
| 564 | DEFINE_RES_NAMED(irq, 1, NULL, |
| 565 | IORESOURCE_IRQ | i2c_dev->irqflags); |
| 566 | i2c_dev->board_info.resources = &i2c_dev->irq_resource; |
| 567 | i2c_dev->board_info.num_resources = 1; |
Dmitry Torokhov | 6558292 | 2018-03-20 15:31:33 -0700 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | return cros_laptop; |
| 571 | } |
| 572 | |
| 573 | |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 574 | static int __init chromeos_laptop_init(void) |
| 575 | { |
Dmitry Torokhov | 6558292 | 2018-03-20 15:31:33 -0700 | [diff] [blame] | 576 | const struct dmi_system_id *dmi_id; |
Dmitry Torokhov | 8d88cb0 | 2018-03-20 15:31:34 -0700 | [diff] [blame] | 577 | int error; |
Robin Schroer | 49c68a2 | 2014-05-29 20:45:07 +0200 | [diff] [blame] | 578 | |
Dmitry Torokhov | 6558292 | 2018-03-20 15:31:33 -0700 | [diff] [blame] | 579 | dmi_id = dmi_first_match(chromeos_laptop_dmi_table); |
| 580 | if (!dmi_id) { |
Dmitry Torokhov | 4f27f67 | 2018-03-20 15:31:30 -0700 | [diff] [blame] | 581 | pr_debug("unsupported system\n"); |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 582 | return -ENODEV; |
| 583 | } |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 584 | |
Dmitry Torokhov | 6558292 | 2018-03-20 15:31:33 -0700 | [diff] [blame] | 585 | pr_debug("DMI Matched %s\n", dmi_id->ident); |
| 586 | |
| 587 | cros_laptop = chromeos_laptop_prepare(dmi_id->driver_data); |
| 588 | if (IS_ERR(cros_laptop)) |
| 589 | return PTR_ERR(cros_laptop); |
| 590 | |
Dmitry Torokhov | 8d88cb0 | 2018-03-20 15:31:34 -0700 | [diff] [blame] | 591 | error = bus_register_notifier(&i2c_bus_type, |
| 592 | &chromeos_laptop_i2c_notifier); |
| 593 | if (error) { |
| 594 | pr_err("failed to register i2c bus notifier: %d\n", error); |
| 595 | return error; |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 596 | } |
| 597 | |
Dmitry Torokhov | 8d88cb0 | 2018-03-20 15:31:34 -0700 | [diff] [blame] | 598 | /* |
| 599 | * Scan adapters that have been registered before we installed |
| 600 | * the notifier to make sure we do not miss any devices. |
| 601 | */ |
| 602 | i2c_for_each_dev(NULL, chromeos_laptop_scan_adapter); |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 603 | |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 604 | return 0; |
| 605 | } |
| 606 | |
| 607 | static void __exit chromeos_laptop_exit(void) |
| 608 | { |
Dmitry Torokhov | 28cd38f | 2018-03-20 15:31:32 -0700 | [diff] [blame] | 609 | struct i2c_peripheral *i2c_dev; |
| 610 | int i; |
Wei Yongjun | 2b8454a | 2013-11-27 11:34:58 +0800 | [diff] [blame] | 611 | |
Dmitry Torokhov | 8d88cb0 | 2018-03-20 15:31:34 -0700 | [diff] [blame] | 612 | bus_unregister_notifier(&i2c_bus_type, &chromeos_laptop_i2c_notifier); |
Dmitry Torokhov | 28cd38f | 2018-03-20 15:31:32 -0700 | [diff] [blame] | 613 | |
| 614 | for (i = 0; i < MAX_I2C_PERIPHERALS; i++) { |
| 615 | i2c_dev = &cros_laptop->i2c_peripherals[i]; |
| 616 | |
| 617 | /* No more peripherals */ |
| 618 | if (!i2c_dev->board_info.type) |
| 619 | break; |
| 620 | |
Dmitry Torokhov | 8d88cb0 | 2018-03-20 15:31:34 -0700 | [diff] [blame] | 621 | if (i2c_dev->client) |
Dmitry Torokhov | 28cd38f | 2018-03-20 15:31:32 -0700 | [diff] [blame] | 622 | i2c_unregister_device(i2c_dev->client); |
| 623 | } |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | module_init(chromeos_laptop_init); |
| 627 | module_exit(chromeos_laptop_exit); |
| 628 | |
| 629 | MODULE_DESCRIPTION("Chrome OS Laptop driver"); |
| 630 | MODULE_AUTHOR("Benson Leung <bleung@chromium.org>"); |
| 631 | MODULE_LICENSE("GPL"); |