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> |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 14 | #include <linux/module.h> |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 15 | #include <linux/platform_device.h> |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 16 | |
Benson Leung | 8e1ad4c | 2013-02-21 12:14:59 -0800 | [diff] [blame] | 17 | #define ATMEL_TP_I2C_ADDR 0x4b |
| 18 | #define ATMEL_TP_I2C_BL_ADDR 0x25 |
Yufeng Shen | 33a84f8 | 2013-02-21 12:15:00 -0800 | [diff] [blame] | 19 | #define ATMEL_TS_I2C_ADDR 0x4a |
| 20 | #define ATMEL_TS_I2C_BL_ADDR 0x26 |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 21 | #define CYAPA_TP_I2C_ADDR 0x67 |
Benson Leung | 9bd9a90 | 2016-05-02 08:57:16 +0800 | [diff] [blame] | 22 | #define ELAN_TP_I2C_ADDR 0x15 |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 23 | #define ISL_ALS_I2C_ADDR 0x44 |
Benson Leung | aabf3f4 | 2013-02-01 14:34:45 -0800 | [diff] [blame] | 24 | #define TAOS_ALS_I2C_ADDR 0x29 |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 25 | |
Benson Leung | 5502486 | 2014-07-15 17:43:11 -0700 | [diff] [blame] | 26 | #define MAX_I2C_DEVICE_DEFERRALS 5 |
| 27 | |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 28 | static struct i2c_client *als; |
| 29 | static struct i2c_client *tp; |
Yufeng Shen | 33a84f8 | 2013-02-21 12:15:00 -0800 | [diff] [blame] | 30 | static struct i2c_client *ts; |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 31 | |
Olof Johansson | 6d3c1af | 2013-11-25 13:10:25 -0800 | [diff] [blame] | 32 | static const char *i2c_adapter_names[] = { |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 33 | "SMBus I801 adapter", |
Benson Leung | 741bf0c | 2013-02-21 12:14:55 -0800 | [diff] [blame] | 34 | "i915 gmbus vga", |
| 35 | "i915 gmbus panel", |
Jarkko Nikula | ebaf31c | 2015-11-03 13:09:00 +0200 | [diff] [blame] | 36 | "Synopsys DesignWare I2C adapter", |
| 37 | "Synopsys DesignWare I2C adapter", |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 38 | }; |
| 39 | |
| 40 | /* Keep this enum consistent with i2c_adapter_names */ |
| 41 | enum i2c_adapter_type { |
| 42 | I2C_ADAPTER_SMBUS = 0, |
Benson Leung | 741bf0c | 2013-02-21 12:14:55 -0800 | [diff] [blame] | 43 | I2C_ADAPTER_VGADDC, |
| 44 | I2C_ADAPTER_PANEL, |
Mika Westerberg | da3b0ab | 2014-06-17 14:02:00 -0700 | [diff] [blame] | 45 | I2C_ADAPTER_DESIGNWARE_0, |
| 46 | I2C_ADAPTER_DESIGNWARE_1, |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 47 | }; |
| 48 | |
Benson Leung | 5502486 | 2014-07-15 17:43:11 -0700 | [diff] [blame] | 49 | enum i2c_peripheral_state { |
| 50 | UNPROBED = 0, |
| 51 | PROBED, |
| 52 | TIMEDOUT, |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 53 | }; |
| 54 | |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 55 | struct i2c_peripheral { |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 56 | int (*add)(enum i2c_adapter_type type); |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 57 | enum i2c_adapter_type type; |
Benson Leung | 5502486 | 2014-07-15 17:43:11 -0700 | [diff] [blame] | 58 | enum i2c_peripheral_state state; |
| 59 | int tries; |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 60 | }; |
| 61 | |
Benson Leung | 9bd9a90 | 2016-05-02 08:57:16 +0800 | [diff] [blame] | 62 | #define MAX_I2C_PERIPHERALS 4 |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 63 | |
| 64 | struct chromeos_laptop { |
| 65 | struct i2c_peripheral i2c_peripherals[MAX_I2C_PERIPHERALS]; |
| 66 | }; |
| 67 | |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 68 | static struct chromeos_laptop *cros_laptop; |
| 69 | |
| 70 | static struct i2c_board_info cyapa_device = { |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 71 | I2C_BOARD_INFO("cyapa", CYAPA_TP_I2C_ADDR), |
| 72 | .flags = I2C_CLIENT_WAKE, |
| 73 | }; |
| 74 | |
Benson Leung | 9bd9a90 | 2016-05-02 08:57:16 +0800 | [diff] [blame] | 75 | static struct i2c_board_info elantech_device = { |
| 76 | I2C_BOARD_INFO("elan_i2c", ELAN_TP_I2C_ADDR), |
| 77 | .flags = I2C_CLIENT_WAKE, |
| 78 | }; |
| 79 | |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 80 | static struct i2c_board_info isl_als_device = { |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 81 | I2C_BOARD_INFO("isl29018", ISL_ALS_I2C_ADDR), |
| 82 | }; |
| 83 | |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 84 | static struct i2c_board_info tsl2583_als_device = { |
Benson Leung | 8016bcb | 2013-02-01 14:34:46 -0800 | [diff] [blame] | 85 | I2C_BOARD_INFO("tsl2583", TAOS_ALS_I2C_ADDR), |
| 86 | }; |
| 87 | |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 88 | static struct i2c_board_info tsl2563_als_device = { |
Benson Leung | aabf3f4 | 2013-02-01 14:34:45 -0800 | [diff] [blame] | 89 | I2C_BOARD_INFO("tsl2563", TAOS_ALS_I2C_ADDR), |
| 90 | }; |
| 91 | |
Nick Dyer | fb5e4c3e | 2014-05-18 23:00:15 -0700 | [diff] [blame] | 92 | static int mxt_t19_keys[] = { |
| 93 | KEY_RESERVED, |
| 94 | KEY_RESERVED, |
| 95 | KEY_RESERVED, |
| 96 | KEY_RESERVED, |
| 97 | KEY_RESERVED, |
| 98 | BTN_LEFT |
| 99 | }; |
| 100 | |
Benson Leung | 2ef3920 | 2013-03-07 19:43:34 -0800 | [diff] [blame] | 101 | static struct mxt_platform_data atmel_224s_tp_platform_data = { |
Benson Leung | 2ef3920 | 2013-03-07 19:43:34 -0800 | [diff] [blame] | 102 | .irqflags = IRQF_TRIGGER_FALLING, |
Nick Dyer | fb5e4c3e | 2014-05-18 23:00:15 -0700 | [diff] [blame] | 103 | .t19_num_keys = ARRAY_SIZE(mxt_t19_keys), |
| 104 | .t19_keymap = mxt_t19_keys, |
Benson Leung | 2ef3920 | 2013-03-07 19:43:34 -0800 | [diff] [blame] | 105 | }; |
| 106 | |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 107 | static struct i2c_board_info atmel_224s_tp_device = { |
Benson Leung | 8e1ad4c | 2013-02-21 12:14:59 -0800 | [diff] [blame] | 108 | I2C_BOARD_INFO("atmel_mxt_tp", ATMEL_TP_I2C_ADDR), |
Benson Leung | 2ef3920 | 2013-03-07 19:43:34 -0800 | [diff] [blame] | 109 | .platform_data = &atmel_224s_tp_platform_data, |
Benson Leung | 8e1ad4c | 2013-02-21 12:14:59 -0800 | [diff] [blame] | 110 | .flags = I2C_CLIENT_WAKE, |
| 111 | }; |
| 112 | |
Benson Leung | 2ef3920 | 2013-03-07 19:43:34 -0800 | [diff] [blame] | 113 | static struct mxt_platform_data atmel_1664s_platform_data = { |
Benson Leung | 2ef3920 | 2013-03-07 19:43:34 -0800 | [diff] [blame] | 114 | .irqflags = IRQF_TRIGGER_FALLING, |
Benson Leung | 2ef3920 | 2013-03-07 19:43:34 -0800 | [diff] [blame] | 115 | }; |
| 116 | |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 117 | static struct i2c_board_info atmel_1664s_device = { |
Yufeng Shen | 33a84f8 | 2013-02-21 12:15:00 -0800 | [diff] [blame] | 118 | I2C_BOARD_INFO("atmel_mxt_ts", ATMEL_TS_I2C_ADDR), |
Benson Leung | 2ef3920 | 2013-03-07 19:43:34 -0800 | [diff] [blame] | 119 | .platform_data = &atmel_1664s_platform_data, |
Yufeng Shen | 33a84f8 | 2013-02-21 12:15:00 -0800 | [diff] [blame] | 120 | .flags = I2C_CLIENT_WAKE, |
| 121 | }; |
| 122 | |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 123 | static struct i2c_client *__add_probed_i2c_device( |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 124 | const char *name, |
| 125 | int bus, |
| 126 | struct i2c_board_info *info, |
Dmitry Torokhov | 96cba9b | 2015-04-14 13:50:09 -0700 | [diff] [blame] | 127 | const unsigned short *alt_addr_list) |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 128 | { |
| 129 | const struct dmi_device *dmi_dev; |
| 130 | const struct dmi_dev_onboard *dev_data; |
| 131 | struct i2c_adapter *adapter; |
Dmitry Torokhov | 96cba9b | 2015-04-14 13:50:09 -0700 | [diff] [blame] | 132 | struct i2c_client *client = NULL; |
| 133 | const unsigned short addr_list[] = { info->addr, I2C_CLIENT_END }; |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 134 | |
| 135 | if (bus < 0) |
| 136 | return NULL; |
| 137 | /* |
| 138 | * If a name is specified, look for irq platform information stashed |
| 139 | * in DMI_DEV_TYPE_DEV_ONBOARD by the Chrome OS custom system firmware. |
| 140 | */ |
| 141 | if (name) { |
| 142 | dmi_dev = dmi_find_device(DMI_DEV_TYPE_DEV_ONBOARD, name, NULL); |
| 143 | if (!dmi_dev) { |
Dmitry Torokhov | 4f27f67 | 2018-03-20 15:31:30 -0700 | [diff] [blame^] | 144 | pr_err("failed to dmi find device %s\n", name); |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 145 | return NULL; |
| 146 | } |
| 147 | dev_data = (struct dmi_dev_onboard *)dmi_dev->device_data; |
| 148 | if (!dev_data) { |
Dmitry Torokhov | 4f27f67 | 2018-03-20 15:31:30 -0700 | [diff] [blame^] | 149 | pr_err("failed to get data from dmi for %s\n", name); |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 150 | return NULL; |
| 151 | } |
| 152 | info->irq = dev_data->instance; |
| 153 | } |
| 154 | |
| 155 | adapter = i2c_get_adapter(bus); |
| 156 | if (!adapter) { |
Dmitry Torokhov | 4f27f67 | 2018-03-20 15:31:30 -0700 | [diff] [blame^] | 157 | pr_err("failed to get i2c adapter %d\n", bus); |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 158 | return NULL; |
| 159 | } |
| 160 | |
Dmitry Torokhov | 96cba9b | 2015-04-14 13:50:09 -0700 | [diff] [blame] | 161 | /* |
| 162 | * Add the i2c device. If we can't detect it at the primary |
| 163 | * address we scan secondary addresses. In any case the client |
| 164 | * structure gets assigned primary address. |
| 165 | */ |
| 166 | client = i2c_new_probed_device(adapter, info, addr_list, NULL); |
| 167 | if (!client && alt_addr_list) { |
| 168 | struct i2c_board_info dummy_info = { |
| 169 | I2C_BOARD_INFO("dummy", info->addr), |
| 170 | }; |
| 171 | struct i2c_client *dummy; |
| 172 | |
| 173 | dummy = i2c_new_probed_device(adapter, &dummy_info, |
| 174 | alt_addr_list, NULL); |
| 175 | if (dummy) { |
Dmitry Torokhov | 4f27f67 | 2018-03-20 15:31:30 -0700 | [diff] [blame^] | 176 | pr_debug("%d-%02x is probed at %02x\n", |
| 177 | bus, info->addr, dummy->addr); |
Dmitry Torokhov | 96cba9b | 2015-04-14 13:50:09 -0700 | [diff] [blame] | 178 | i2c_unregister_device(dummy); |
| 179 | client = i2c_new_device(adapter, info); |
| 180 | } |
| 181 | } |
| 182 | |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 183 | if (!client) |
Dmitry Torokhov | 4f27f67 | 2018-03-20 15:31:30 -0700 | [diff] [blame^] | 184 | pr_notice("failed to register device %d-%02x\n", |
| 185 | bus, info->addr); |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 186 | else |
Dmitry Torokhov | 4f27f67 | 2018-03-20 15:31:30 -0700 | [diff] [blame^] | 187 | pr_debug("added i2c device %d-%02x\n", bus, info->addr); |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 188 | |
| 189 | i2c_put_adapter(adapter); |
| 190 | return client; |
| 191 | } |
| 192 | |
Mika Westerberg | da3b0ab | 2014-06-17 14:02:00 -0700 | [diff] [blame] | 193 | struct i2c_lookup { |
| 194 | const char *name; |
| 195 | int instance; |
| 196 | int n; |
| 197 | }; |
| 198 | |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 199 | static int __find_i2c_adap(struct device *dev, void *data) |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 200 | { |
Mika Westerberg | da3b0ab | 2014-06-17 14:02:00 -0700 | [diff] [blame] | 201 | struct i2c_lookup *lookup = data; |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 202 | static const char *prefix = "i2c-"; |
| 203 | struct i2c_adapter *adapter; |
Robin Schroer | 49c68a2 | 2014-05-29 20:45:07 +0200 | [diff] [blame] | 204 | |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 205 | if (strncmp(dev_name(dev), prefix, strlen(prefix)) != 0) |
| 206 | return 0; |
| 207 | adapter = to_i2c_adapter(dev); |
Mika Westerberg | da3b0ab | 2014-06-17 14:02:00 -0700 | [diff] [blame] | 208 | if (strncmp(adapter->name, lookup->name, strlen(lookup->name)) == 0 && |
| 209 | lookup->n++ == lookup->instance) |
| 210 | return 1; |
| 211 | return 0; |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 212 | } |
| 213 | |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 214 | static int find_i2c_adapter_num(enum i2c_adapter_type type) |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 215 | { |
| 216 | struct device *dev = NULL; |
| 217 | struct i2c_adapter *adapter; |
Mika Westerberg | da3b0ab | 2014-06-17 14:02:00 -0700 | [diff] [blame] | 218 | struct i2c_lookup lookup; |
| 219 | |
| 220 | memset(&lookup, 0, sizeof(lookup)); |
| 221 | lookup.name = i2c_adapter_names[type]; |
| 222 | lookup.instance = (type == I2C_ADAPTER_DESIGNWARE_1) ? 1 : 0; |
| 223 | |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 224 | /* find the adapter by name */ |
Mika Westerberg | da3b0ab | 2014-06-17 14:02:00 -0700 | [diff] [blame] | 225 | dev = bus_find_device(&i2c_bus_type, NULL, &lookup, __find_i2c_adap); |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 226 | if (!dev) { |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 227 | /* Adapters may appear later. Deferred probing will retry */ |
Dmitry Torokhov | 4f27f67 | 2018-03-20 15:31:30 -0700 | [diff] [blame^] | 228 | pr_notice("i2c adapter %s not found on system.\n", |
Mika Westerberg | da3b0ab | 2014-06-17 14:02:00 -0700 | [diff] [blame] | 229 | lookup.name); |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 230 | return -ENODEV; |
| 231 | } |
| 232 | adapter = to_i2c_adapter(dev); |
| 233 | return adapter->nr; |
| 234 | } |
| 235 | |
| 236 | /* |
Benson Leung | bcaf089 | 2013-02-21 12:14:58 -0800 | [diff] [blame] | 237 | * Takes a list of addresses in addrs as such : |
| 238 | * { addr1, ... , addrn, I2C_CLIENT_END }; |
| 239 | * add_probed_i2c_device will use i2c_new_probed_device |
| 240 | * and probe for devices at all of the addresses listed. |
| 241 | * Returns NULL if no devices found. |
| 242 | * See Documentation/i2c/instantiating-devices for more information. |
| 243 | */ |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 244 | static struct i2c_client *add_probed_i2c_device( |
Benson Leung | bcaf089 | 2013-02-21 12:14:58 -0800 | [diff] [blame] | 245 | const char *name, |
| 246 | enum i2c_adapter_type type, |
| 247 | struct i2c_board_info *info, |
| 248 | const unsigned short *addrs) |
| 249 | { |
| 250 | return __add_probed_i2c_device(name, |
| 251 | find_i2c_adapter_num(type), |
| 252 | info, |
| 253 | addrs); |
| 254 | } |
| 255 | |
| 256 | /* |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 257 | * Probes for a device at a single address, the one provided by |
| 258 | * info->addr. |
| 259 | * Returns NULL if no device found. |
| 260 | */ |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 261 | static struct i2c_client *add_i2c_device(const char *name, |
Benson Leung | e7b2884 | 2013-02-21 12:14:56 -0800 | [diff] [blame] | 262 | enum i2c_adapter_type type, |
| 263 | struct i2c_board_info *info) |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 264 | { |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 265 | return __add_probed_i2c_device(name, |
Benson Leung | e7b2884 | 2013-02-21 12:14:56 -0800 | [diff] [blame] | 266 | find_i2c_adapter_num(type), |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 267 | info, |
Dmitry Torokhov | 96cba9b | 2015-04-14 13:50:09 -0700 | [diff] [blame] | 268 | NULL); |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 269 | } |
| 270 | |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 271 | static int setup_cyapa_tp(enum i2c_adapter_type type) |
Benson Leung | e7b2884 | 2013-02-21 12:14:56 -0800 | [diff] [blame] | 272 | { |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 273 | if (tp) |
| 274 | return 0; |
| 275 | |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 276 | /* add cyapa touchpad */ |
| 277 | tp = add_i2c_device("trackpad", type, &cyapa_device); |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 278 | return (!tp) ? -EAGAIN : 0; |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 279 | } |
| 280 | |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 281 | static int setup_atmel_224s_tp(enum i2c_adapter_type type) |
Benson Leung | 8e1ad4c | 2013-02-21 12:14:59 -0800 | [diff] [blame] | 282 | { |
| 283 | const unsigned short addr_list[] = { ATMEL_TP_I2C_BL_ADDR, |
Benson Leung | 8e1ad4c | 2013-02-21 12:14:59 -0800 | [diff] [blame] | 284 | I2C_CLIENT_END }; |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 285 | if (tp) |
| 286 | return 0; |
Benson Leung | 8e1ad4c | 2013-02-21 12:14:59 -0800 | [diff] [blame] | 287 | |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 288 | /* add atmel mxt touchpad */ |
| 289 | tp = add_probed_i2c_device("trackpad", type, |
Benson Leung | 8e1ad4c | 2013-02-21 12:14:59 -0800 | [diff] [blame] | 290 | &atmel_224s_tp_device, addr_list); |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 291 | return (!tp) ? -EAGAIN : 0; |
Benson Leung | 8e1ad4c | 2013-02-21 12:14:59 -0800 | [diff] [blame] | 292 | } |
| 293 | |
Benson Leung | 9bd9a90 | 2016-05-02 08:57:16 +0800 | [diff] [blame] | 294 | static int setup_elantech_tp(enum i2c_adapter_type type) |
| 295 | { |
| 296 | if (tp) |
| 297 | return 0; |
| 298 | |
| 299 | /* add elantech touchpad */ |
| 300 | tp = add_i2c_device("trackpad", type, &elantech_device); |
| 301 | return (!tp) ? -EAGAIN : 0; |
| 302 | } |
| 303 | |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 304 | static int setup_atmel_1664s_ts(enum i2c_adapter_type type) |
Yufeng Shen | 33a84f8 | 2013-02-21 12:15:00 -0800 | [diff] [blame] | 305 | { |
| 306 | const unsigned short addr_list[] = { ATMEL_TS_I2C_BL_ADDR, |
Yufeng Shen | 33a84f8 | 2013-02-21 12:15:00 -0800 | [diff] [blame] | 307 | I2C_CLIENT_END }; |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 308 | if (ts) |
| 309 | return 0; |
Yufeng Shen | 33a84f8 | 2013-02-21 12:15:00 -0800 | [diff] [blame] | 310 | |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 311 | /* add atmel mxt touch device */ |
| 312 | ts = add_probed_i2c_device("touchscreen", type, |
Yufeng Shen | 33a84f8 | 2013-02-21 12:15:00 -0800 | [diff] [blame] | 313 | &atmel_1664s_device, addr_list); |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 314 | return (!ts) ? -EAGAIN : 0; |
Yufeng Shen | 33a84f8 | 2013-02-21 12:15:00 -0800 | [diff] [blame] | 315 | } |
| 316 | |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 317 | static int setup_isl29018_als(enum i2c_adapter_type type) |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 318 | { |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 319 | if (als) |
| 320 | return 0; |
| 321 | |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 322 | /* add isl29018 light sensor */ |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 323 | als = add_i2c_device("lightsensor", type, &isl_als_device); |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 324 | return (!als) ? -EAGAIN : 0; |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 325 | } |
| 326 | |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 327 | static int setup_tsl2583_als(enum i2c_adapter_type type) |
Benson Leung | cc5c398 | 2013-02-21 12:14:57 -0800 | [diff] [blame] | 328 | { |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 329 | if (als) |
| 330 | return 0; |
| 331 | |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 332 | /* add tsl2583 light sensor */ |
| 333 | als = add_i2c_device(NULL, type, &tsl2583_als_device); |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 334 | return (!als) ? -EAGAIN : 0; |
Benson Leung | cc5c398 | 2013-02-21 12:14:57 -0800 | [diff] [blame] | 335 | } |
| 336 | |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 337 | static int setup_tsl2563_als(enum i2c_adapter_type type) |
Benson Leung | 8016bcb | 2013-02-01 14:34:46 -0800 | [diff] [blame] | 338 | { |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 339 | if (als) |
| 340 | return 0; |
| 341 | |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 342 | /* add tsl2563 light sensor */ |
| 343 | als = add_i2c_device(NULL, type, &tsl2563_als_device); |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 344 | return (!als) ? -EAGAIN : 0; |
Benson Leung | 8016bcb | 2013-02-01 14:34:46 -0800 | [diff] [blame] | 345 | } |
| 346 | |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 347 | static int __init chromeos_laptop_dmi_matched(const struct dmi_system_id *id) |
| 348 | { |
| 349 | cros_laptop = (void *)id->driver_data; |
Dmitry Torokhov | 4f27f67 | 2018-03-20 15:31:30 -0700 | [diff] [blame^] | 350 | pr_debug("DMI Matched %s\n", id->ident); |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 351 | |
| 352 | /* Indicate to dmi_scan that processing is done. */ |
| 353 | return 1; |
| 354 | } |
| 355 | |
| 356 | static int chromeos_laptop_probe(struct platform_device *pdev) |
Benson Leung | aabf3f4 | 2013-02-01 14:34:45 -0800 | [diff] [blame] | 357 | { |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 358 | int i; |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 359 | int ret = 0; |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 360 | |
| 361 | for (i = 0; i < MAX_I2C_PERIPHERALS; i++) { |
| 362 | struct i2c_peripheral *i2c_dev; |
| 363 | |
| 364 | i2c_dev = &cros_laptop->i2c_peripherals[i]; |
| 365 | |
| 366 | /* No more peripherals. */ |
| 367 | if (i2c_dev->add == NULL) |
| 368 | break; |
| 369 | |
Benson Leung | 5502486 | 2014-07-15 17:43:11 -0700 | [diff] [blame] | 370 | if (i2c_dev->state == TIMEDOUT || i2c_dev->state == PROBED) |
| 371 | continue; |
| 372 | |
| 373 | /* |
| 374 | * Check that the i2c adapter is present. |
| 375 | * -EPROBE_DEFER if missing as the adapter may appear much |
| 376 | * later. |
| 377 | */ |
| 378 | if (find_i2c_adapter_num(i2c_dev->type) == -ENODEV) { |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 379 | ret = -EPROBE_DEFER; |
Benson Leung | 5502486 | 2014-07-15 17:43:11 -0700 | [diff] [blame] | 380 | continue; |
| 381 | } |
| 382 | |
| 383 | /* Add the device. */ |
| 384 | if (i2c_dev->add(i2c_dev->type) == -EAGAIN) { |
| 385 | /* |
| 386 | * Set -EPROBE_DEFER a limited num of times |
| 387 | * if device is not successfully added. |
| 388 | */ |
| 389 | if (++i2c_dev->tries < MAX_I2C_DEVICE_DEFERRALS) { |
| 390 | ret = -EPROBE_DEFER; |
| 391 | } else { |
| 392 | /* Ran out of tries. */ |
Dmitry Torokhov | 4f27f67 | 2018-03-20 15:31:30 -0700 | [diff] [blame^] | 393 | pr_notice("ran out of tries for device.\n"); |
Benson Leung | 5502486 | 2014-07-15 17:43:11 -0700 | [diff] [blame] | 394 | i2c_dev->state = TIMEDOUT; |
| 395 | } |
| 396 | } else { |
| 397 | i2c_dev->state = PROBED; |
| 398 | } |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 399 | } |
| 400 | |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 401 | return ret; |
Benson Leung | aabf3f4 | 2013-02-01 14:34:45 -0800 | [diff] [blame] | 402 | } |
| 403 | |
Dmitry Torokhov | fc88bbd | 2018-03-06 10:59:15 -0800 | [diff] [blame] | 404 | static struct chromeos_laptop samsung_series_5_550 = { |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 405 | .i2c_peripherals = { |
| 406 | /* Touchpad. */ |
| 407 | { .add = setup_cyapa_tp, I2C_ADAPTER_SMBUS }, |
| 408 | /* Light Sensor. */ |
| 409 | { .add = setup_isl29018_als, I2C_ADAPTER_SMBUS }, |
| 410 | }, |
| 411 | }; |
| 412 | |
Dmitry Torokhov | fc88bbd | 2018-03-06 10:59:15 -0800 | [diff] [blame] | 413 | static struct chromeos_laptop samsung_series_5 = { |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 414 | .i2c_peripherals = { |
| 415 | /* Light Sensor. */ |
| 416 | { .add = setup_tsl2583_als, I2C_ADAPTER_SMBUS }, |
| 417 | }, |
| 418 | }; |
| 419 | |
Dmitry Torokhov | fc88bbd | 2018-03-06 10:59:15 -0800 | [diff] [blame] | 420 | static struct chromeos_laptop chromebook_pixel = { |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 421 | .i2c_peripherals = { |
| 422 | /* Touch Screen. */ |
| 423 | { .add = setup_atmel_1664s_ts, I2C_ADAPTER_PANEL }, |
| 424 | /* Touchpad. */ |
| 425 | { .add = setup_atmel_224s_tp, I2C_ADAPTER_VGADDC }, |
| 426 | /* Light Sensor. */ |
| 427 | { .add = setup_isl29018_als, I2C_ADAPTER_PANEL }, |
| 428 | }, |
| 429 | }; |
| 430 | |
Dmitry Torokhov | fc88bbd | 2018-03-06 10:59:15 -0800 | [diff] [blame] | 431 | static struct chromeos_laptop hp_chromebook_14 = { |
Benson Leung | 5ea9567 | 2014-06-17 14:02:01 -0700 | [diff] [blame] | 432 | .i2c_peripherals = { |
| 433 | /* Touchpad. */ |
| 434 | { .add = setup_cyapa_tp, I2C_ADAPTER_DESIGNWARE_0 }, |
| 435 | }, |
| 436 | }; |
| 437 | |
Dmitry Torokhov | fc88bbd | 2018-03-06 10:59:15 -0800 | [diff] [blame] | 438 | static struct chromeos_laptop dell_chromebook_11 = { |
Mohammed Habibulla | 0e1e5e5 | 2014-06-17 14:02:02 -0700 | [diff] [blame] | 439 | .i2c_peripherals = { |
| 440 | /* Touchpad. */ |
| 441 | { .add = setup_cyapa_tp, I2C_ADAPTER_DESIGNWARE_0 }, |
Charlie Mooney | 9e96aa7 | 2016-05-02 08:57:17 +0800 | [diff] [blame] | 442 | /* Elan Touchpad option. */ |
| 443 | { .add = setup_elantech_tp, I2C_ADAPTER_DESIGNWARE_0 }, |
Mohammed Habibulla | 0e1e5e5 | 2014-06-17 14:02:02 -0700 | [diff] [blame] | 444 | }, |
| 445 | }; |
| 446 | |
Dmitry Torokhov | fc88bbd | 2018-03-06 10:59:15 -0800 | [diff] [blame] | 447 | static struct chromeos_laptop toshiba_cb35 = { |
Gene Chen | 963cb6f | 2014-06-17 14:02:03 -0700 | [diff] [blame] | 448 | .i2c_peripherals = { |
| 449 | /* Touchpad. */ |
| 450 | { .add = setup_cyapa_tp, I2C_ADAPTER_DESIGNWARE_0 }, |
| 451 | }, |
| 452 | }; |
| 453 | |
Dmitry Torokhov | fc88bbd | 2018-03-06 10:59:15 -0800 | [diff] [blame] | 454 | static struct chromeos_laptop acer_c7_chromebook = { |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 455 | .i2c_peripherals = { |
| 456 | /* Touchpad. */ |
| 457 | { .add = setup_cyapa_tp, I2C_ADAPTER_SMBUS }, |
| 458 | }, |
| 459 | }; |
| 460 | |
Dmitry Torokhov | fc88bbd | 2018-03-06 10:59:15 -0800 | [diff] [blame] | 461 | static struct chromeos_laptop acer_ac700 = { |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 462 | .i2c_peripherals = { |
| 463 | /* Light Sensor. */ |
| 464 | { .add = setup_tsl2563_als, I2C_ADAPTER_SMBUS }, |
| 465 | }, |
| 466 | }; |
| 467 | |
Dmitry Torokhov | fc88bbd | 2018-03-06 10:59:15 -0800 | [diff] [blame] | 468 | static struct chromeos_laptop acer_c720 = { |
Mika Westerberg | da3b0ab | 2014-06-17 14:02:00 -0700 | [diff] [blame] | 469 | .i2c_peripherals = { |
Michael Mullin | b90b3c4 | 2014-07-15 20:00:54 -0400 | [diff] [blame] | 470 | /* Touchscreen. */ |
| 471 | { .add = setup_atmel_1664s_ts, I2C_ADAPTER_DESIGNWARE_1 }, |
Mika Westerberg | da3b0ab | 2014-06-17 14:02:00 -0700 | [diff] [blame] | 472 | /* Touchpad. */ |
| 473 | { .add = setup_cyapa_tp, I2C_ADAPTER_DESIGNWARE_0 }, |
Benson Leung | 9bd9a90 | 2016-05-02 08:57:16 +0800 | [diff] [blame] | 474 | /* Elan Touchpad option. */ |
| 475 | { .add = setup_elantech_tp, I2C_ADAPTER_DESIGNWARE_0 }, |
Mika Westerberg | da3b0ab | 2014-06-17 14:02:00 -0700 | [diff] [blame] | 476 | /* Light Sensor. */ |
| 477 | { .add = setup_isl29018_als, I2C_ADAPTER_DESIGNWARE_1 }, |
| 478 | }, |
| 479 | }; |
| 480 | |
Dmitry Torokhov | fc88bbd | 2018-03-06 10:59:15 -0800 | [diff] [blame] | 481 | static struct chromeos_laptop hp_pavilion_14_chromebook = { |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 482 | .i2c_peripherals = { |
| 483 | /* Touchpad. */ |
| 484 | { .add = setup_cyapa_tp, I2C_ADAPTER_SMBUS }, |
| 485 | }, |
| 486 | }; |
| 487 | |
Dmitry Torokhov | fc88bbd | 2018-03-06 10:59:15 -0800 | [diff] [blame] | 488 | static struct chromeos_laptop cr48 = { |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 489 | .i2c_peripherals = { |
| 490 | /* Light Sensor. */ |
| 491 | { .add = setup_tsl2563_als, I2C_ADAPTER_SMBUS }, |
| 492 | }, |
| 493 | }; |
| 494 | |
| 495 | #define _CBDD(board_) \ |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 496 | .callback = chromeos_laptop_dmi_matched, \ |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 497 | .driver_data = (void *)&board_ |
| 498 | |
Christoph Hellwig | 6faadbb | 2017-09-14 11:59:30 +0200 | [diff] [blame] | 499 | static const struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = { |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 500 | { |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 501 | .ident = "Samsung Series 5 550", |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 502 | .matches = { |
| 503 | DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG"), |
| 504 | DMI_MATCH(DMI_PRODUCT_NAME, "Lumpy"), |
| 505 | }, |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 506 | _CBDD(samsung_series_5_550), |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 507 | }, |
| 508 | { |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 509 | .ident = "Samsung Series 5", |
Benson Leung | 8016bcb | 2013-02-01 14:34:46 -0800 | [diff] [blame] | 510 | .matches = { |
| 511 | DMI_MATCH(DMI_PRODUCT_NAME, "Alex"), |
| 512 | }, |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 513 | _CBDD(samsung_series_5), |
Benson Leung | 8016bcb | 2013-02-01 14:34:46 -0800 | [diff] [blame] | 514 | }, |
| 515 | { |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 516 | .ident = "Chromebook Pixel", |
Benson Leung | aabf3f4 | 2013-02-01 14:34:45 -0800 | [diff] [blame] | 517 | .matches = { |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 518 | DMI_MATCH(DMI_SYS_VENDOR, "GOOGLE"), |
| 519 | DMI_MATCH(DMI_PRODUCT_NAME, "Link"), |
Benson Leung | aabf3f4 | 2013-02-01 14:34:45 -0800 | [diff] [blame] | 520 | }, |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 521 | _CBDD(chromebook_pixel), |
Benson Leung | aabf3f4 | 2013-02-01 14:34:45 -0800 | [diff] [blame] | 522 | }, |
| 523 | { |
Mohammed Habibulla | 0e1e5e5 | 2014-06-17 14:02:02 -0700 | [diff] [blame] | 524 | .ident = "Wolf", |
| 525 | .matches = { |
| 526 | DMI_MATCH(DMI_BIOS_VENDOR, "coreboot"), |
| 527 | DMI_MATCH(DMI_PRODUCT_NAME, "Wolf"), |
| 528 | }, |
| 529 | _CBDD(dell_chromebook_11), |
| 530 | }, |
| 531 | { |
Benson Leung | 5ea9567 | 2014-06-17 14:02:01 -0700 | [diff] [blame] | 532 | .ident = "HP Chromebook 14", |
| 533 | .matches = { |
| 534 | DMI_MATCH(DMI_BIOS_VENDOR, "coreboot"), |
| 535 | DMI_MATCH(DMI_PRODUCT_NAME, "Falco"), |
| 536 | }, |
| 537 | _CBDD(hp_chromebook_14), |
| 538 | }, |
| 539 | { |
Gene Chen | 963cb6f | 2014-06-17 14:02:03 -0700 | [diff] [blame] | 540 | .ident = "Toshiba CB35", |
| 541 | .matches = { |
| 542 | DMI_MATCH(DMI_BIOS_VENDOR, "coreboot"), |
| 543 | DMI_MATCH(DMI_PRODUCT_NAME, "Leon"), |
| 544 | }, |
| 545 | _CBDD(toshiba_cb35), |
| 546 | }, |
| 547 | { |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 548 | .ident = "Acer C7 Chromebook", |
| 549 | .matches = { |
| 550 | DMI_MATCH(DMI_PRODUCT_NAME, "Parrot"), |
| 551 | }, |
| 552 | _CBDD(acer_c7_chromebook), |
| 553 | }, |
| 554 | { |
| 555 | .ident = "Acer AC700", |
Benson Leung | aabf3f4 | 2013-02-01 14:34:45 -0800 | [diff] [blame] | 556 | .matches = { |
| 557 | DMI_MATCH(DMI_PRODUCT_NAME, "ZGB"), |
| 558 | }, |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 559 | _CBDD(acer_ac700), |
| 560 | }, |
| 561 | { |
Mika Westerberg | da3b0ab | 2014-06-17 14:02:00 -0700 | [diff] [blame] | 562 | .ident = "Acer C720", |
| 563 | .matches = { |
| 564 | DMI_MATCH(DMI_PRODUCT_NAME, "Peppy"), |
| 565 | }, |
| 566 | _CBDD(acer_c720), |
| 567 | }, |
| 568 | { |
Aaron Durbin | ec199dd | 2013-10-20 20:58:24 -0700 | [diff] [blame] | 569 | .ident = "HP Pavilion 14 Chromebook", |
| 570 | .matches = { |
| 571 | DMI_MATCH(DMI_PRODUCT_NAME, "Butterfly"), |
| 572 | }, |
| 573 | _CBDD(hp_pavilion_14_chromebook), |
| 574 | }, |
| 575 | { |
| 576 | .ident = "Cr-48", |
| 577 | .matches = { |
| 578 | DMI_MATCH(DMI_PRODUCT_NAME, "Mario"), |
| 579 | }, |
| 580 | _CBDD(cr48), |
Benson Leung | aabf3f4 | 2013-02-01 14:34:45 -0800 | [diff] [blame] | 581 | }, |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 582 | { } |
| 583 | }; |
| 584 | MODULE_DEVICE_TABLE(dmi, chromeos_laptop_dmi_table); |
| 585 | |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 586 | static struct platform_device *cros_platform_device; |
| 587 | |
| 588 | static struct platform_driver cros_platform_driver = { |
| 589 | .driver = { |
| 590 | .name = "chromeos_laptop", |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 591 | }, |
| 592 | .probe = chromeos_laptop_probe, |
| 593 | }; |
| 594 | |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 595 | static int __init chromeos_laptop_init(void) |
| 596 | { |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 597 | int ret; |
Robin Schroer | 49c68a2 | 2014-05-29 20:45:07 +0200 | [diff] [blame] | 598 | |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 599 | if (!dmi_check_system(chromeos_laptop_dmi_table)) { |
Dmitry Torokhov | 4f27f67 | 2018-03-20 15:31:30 -0700 | [diff] [blame^] | 600 | pr_debug("unsupported system\n"); |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 601 | return -ENODEV; |
| 602 | } |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 603 | |
| 604 | ret = platform_driver_register(&cros_platform_driver); |
| 605 | if (ret) |
| 606 | return ret; |
| 607 | |
| 608 | cros_platform_device = platform_device_alloc("chromeos_laptop", -1); |
| 609 | if (!cros_platform_device) { |
| 610 | ret = -ENOMEM; |
| 611 | goto fail_platform_device1; |
| 612 | } |
| 613 | |
| 614 | ret = platform_device_add(cros_platform_device); |
| 615 | if (ret) |
| 616 | goto fail_platform_device2; |
| 617 | |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 618 | return 0; |
Benson Leung | 9ad3692 | 2013-10-20 20:58:25 -0700 | [diff] [blame] | 619 | |
| 620 | fail_platform_device2: |
| 621 | platform_device_put(cros_platform_device); |
| 622 | fail_platform_device1: |
| 623 | platform_driver_unregister(&cros_platform_driver); |
| 624 | return ret; |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | static void __exit chromeos_laptop_exit(void) |
| 628 | { |
| 629 | if (als) |
| 630 | i2c_unregister_device(als); |
| 631 | if (tp) |
| 632 | i2c_unregister_device(tp); |
Yufeng Shen | 33a84f8 | 2013-02-21 12:15:00 -0800 | [diff] [blame] | 633 | if (ts) |
| 634 | i2c_unregister_device(ts); |
Wei Yongjun | 2b8454a | 2013-11-27 11:34:58 +0800 | [diff] [blame] | 635 | |
| 636 | platform_device_unregister(cros_platform_device); |
| 637 | platform_driver_unregister(&cros_platform_driver); |
Benson Leung | d1381f4 | 2012-10-25 14:21:21 -0700 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | module_init(chromeos_laptop_init); |
| 641 | module_exit(chromeos_laptop_exit); |
| 642 | |
| 643 | MODULE_DESCRIPTION("Chrome OS Laptop driver"); |
| 644 | MODULE_AUTHOR("Benson Leung <bleung@chromium.org>"); |
| 645 | MODULE_LICENSE("GPL"); |