blob: 54a13c70e1d8fc43e8603694889be7f3bcbc8b8f [file] [log] [blame]
Dmitry Torokhov203e0ba2018-03-20 15:31:28 -07001// 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 Leungd1381f42012-10-25 14:21:21 -07006
7#include <linux/dmi.h>
8#include <linux/i2c.h>
Nick Dyer7f3884f72015-08-04 16:36:29 -07009#include <linux/platform_data/atmel_mxt_ts.h>
Benson Leung2ef39202013-03-07 19:43:34 -080010#include <linux/input.h>
11#include <linux/interrupt.h>
Benson Leungd1381f42012-10-25 14:21:21 -070012#include <linux/module.h>
Benson Leung9ad36922013-10-20 20:58:25 -070013#include <linux/platform_device.h>
Benson Leungd1381f42012-10-25 14:21:21 -070014
Benson Leung8e1ad4c2013-02-21 12:14:59 -080015#define ATMEL_TP_I2C_ADDR 0x4b
16#define ATMEL_TP_I2C_BL_ADDR 0x25
Yufeng Shen33a84f82013-02-21 12:15:00 -080017#define ATMEL_TS_I2C_ADDR 0x4a
18#define ATMEL_TS_I2C_BL_ADDR 0x26
Benson Leungd1381f42012-10-25 14:21:21 -070019#define CYAPA_TP_I2C_ADDR 0x67
Benson Leung9bd9a902016-05-02 08:57:16 +080020#define ELAN_TP_I2C_ADDR 0x15
Benson Leungd1381f42012-10-25 14:21:21 -070021#define ISL_ALS_I2C_ADDR 0x44
Benson Leungaabf3f42013-02-01 14:34:45 -080022#define TAOS_ALS_I2C_ADDR 0x29
Benson Leungd1381f42012-10-25 14:21:21 -070023
Benson Leung55024862014-07-15 17:43:11 -070024#define MAX_I2C_DEVICE_DEFERRALS 5
25
Benson Leungd1381f42012-10-25 14:21:21 -070026static struct i2c_client *als;
27static struct i2c_client *tp;
Yufeng Shen33a84f82013-02-21 12:15:00 -080028static struct i2c_client *ts;
Benson Leungd1381f42012-10-25 14:21:21 -070029
Olof Johansson6d3c1af2013-11-25 13:10:25 -080030static const char *i2c_adapter_names[] = {
Benson Leungd1381f42012-10-25 14:21:21 -070031 "SMBus I801 adapter",
Benson Leung741bf0c2013-02-21 12:14:55 -080032 "i915 gmbus vga",
33 "i915 gmbus panel",
Jarkko Nikulaebaf31c2015-11-03 13:09:00 +020034 "Synopsys DesignWare I2C adapter",
35 "Synopsys DesignWare I2C adapter",
Benson Leungd1381f42012-10-25 14:21:21 -070036};
37
38/* Keep this enum consistent with i2c_adapter_names */
39enum i2c_adapter_type {
40 I2C_ADAPTER_SMBUS = 0,
Benson Leung741bf0c2013-02-21 12:14:55 -080041 I2C_ADAPTER_VGADDC,
42 I2C_ADAPTER_PANEL,
Mika Westerbergda3b0ab2014-06-17 14:02:00 -070043 I2C_ADAPTER_DESIGNWARE_0,
44 I2C_ADAPTER_DESIGNWARE_1,
Benson Leungd1381f42012-10-25 14:21:21 -070045};
46
Benson Leung55024862014-07-15 17:43:11 -070047enum i2c_peripheral_state {
48 UNPROBED = 0,
49 PROBED,
50 TIMEDOUT,
Benson Leungd1381f42012-10-25 14:21:21 -070051};
52
Aaron Durbinec199dd2013-10-20 20:58:24 -070053struct i2c_peripheral {
Benson Leung9ad36922013-10-20 20:58:25 -070054 int (*add)(enum i2c_adapter_type type);
Aaron Durbinec199dd2013-10-20 20:58:24 -070055 enum i2c_adapter_type type;
Benson Leung55024862014-07-15 17:43:11 -070056 enum i2c_peripheral_state state;
57 int tries;
Aaron Durbinec199dd2013-10-20 20:58:24 -070058};
59
Benson Leung9bd9a902016-05-02 08:57:16 +080060#define MAX_I2C_PERIPHERALS 4
Aaron Durbinec199dd2013-10-20 20:58:24 -070061
62struct chromeos_laptop {
63 struct i2c_peripheral i2c_peripherals[MAX_I2C_PERIPHERALS];
64};
65
Benson Leung9ad36922013-10-20 20:58:25 -070066static struct chromeos_laptop *cros_laptop;
67
68static struct i2c_board_info cyapa_device = {
Benson Leungd1381f42012-10-25 14:21:21 -070069 I2C_BOARD_INFO("cyapa", CYAPA_TP_I2C_ADDR),
70 .flags = I2C_CLIENT_WAKE,
71};
72
Benson Leung9bd9a902016-05-02 08:57:16 +080073static struct i2c_board_info elantech_device = {
74 I2C_BOARD_INFO("elan_i2c", ELAN_TP_I2C_ADDR),
75 .flags = I2C_CLIENT_WAKE,
76};
77
Benson Leung9ad36922013-10-20 20:58:25 -070078static struct i2c_board_info isl_als_device = {
Benson Leungd1381f42012-10-25 14:21:21 -070079 I2C_BOARD_INFO("isl29018", ISL_ALS_I2C_ADDR),
80};
81
Benson Leung9ad36922013-10-20 20:58:25 -070082static struct i2c_board_info tsl2583_als_device = {
Benson Leung8016bcb2013-02-01 14:34:46 -080083 I2C_BOARD_INFO("tsl2583", TAOS_ALS_I2C_ADDR),
84};
85
Benson Leung9ad36922013-10-20 20:58:25 -070086static struct i2c_board_info tsl2563_als_device = {
Benson Leungaabf3f42013-02-01 14:34:45 -080087 I2C_BOARD_INFO("tsl2563", TAOS_ALS_I2C_ADDR),
88};
89
Nick Dyerfb5e4c3e2014-05-18 23:00:15 -070090static int mxt_t19_keys[] = {
91 KEY_RESERVED,
92 KEY_RESERVED,
93 KEY_RESERVED,
94 KEY_RESERVED,
95 KEY_RESERVED,
96 BTN_LEFT
97};
98
Benson Leung2ef39202013-03-07 19:43:34 -080099static struct mxt_platform_data atmel_224s_tp_platform_data = {
Benson Leung2ef39202013-03-07 19:43:34 -0800100 .irqflags = IRQF_TRIGGER_FALLING,
Nick Dyerfb5e4c3e2014-05-18 23:00:15 -0700101 .t19_num_keys = ARRAY_SIZE(mxt_t19_keys),
102 .t19_keymap = mxt_t19_keys,
Nick Dyer7f3884f72015-08-04 16:36:29 -0700103 .suspend_mode = MXT_SUSPEND_T9_CTRL,
Benson Leung2ef39202013-03-07 19:43:34 -0800104};
105
Benson Leung9ad36922013-10-20 20:58:25 -0700106static struct i2c_board_info atmel_224s_tp_device = {
Benson Leung8e1ad4c2013-02-21 12:14:59 -0800107 I2C_BOARD_INFO("atmel_mxt_tp", ATMEL_TP_I2C_ADDR),
Benson Leung2ef39202013-03-07 19:43:34 -0800108 .platform_data = &atmel_224s_tp_platform_data,
Benson Leung8e1ad4c2013-02-21 12:14:59 -0800109 .flags = I2C_CLIENT_WAKE,
110};
111
Benson Leung2ef39202013-03-07 19:43:34 -0800112static struct mxt_platform_data atmel_1664s_platform_data = {
Benson Leung2ef39202013-03-07 19:43:34 -0800113 .irqflags = IRQF_TRIGGER_FALLING,
Nick Dyer7f3884f72015-08-04 16:36:29 -0700114 .suspend_mode = MXT_SUSPEND_T9_CTRL,
Benson Leung2ef39202013-03-07 19:43:34 -0800115};
116
Benson Leung9ad36922013-10-20 20:58:25 -0700117static struct i2c_board_info atmel_1664s_device = {
Yufeng Shen33a84f82013-02-21 12:15:00 -0800118 I2C_BOARD_INFO("atmel_mxt_ts", ATMEL_TS_I2C_ADDR),
Benson Leung2ef39202013-03-07 19:43:34 -0800119 .platform_data = &atmel_1664s_platform_data,
Yufeng Shen33a84f82013-02-21 12:15:00 -0800120 .flags = I2C_CLIENT_WAKE,
121};
122
Benson Leung9ad36922013-10-20 20:58:25 -0700123static struct i2c_client *__add_probed_i2c_device(
Benson Leungd1381f42012-10-25 14:21:21 -0700124 const char *name,
125 int bus,
126 struct i2c_board_info *info,
Dmitry Torokhov96cba9b2015-04-14 13:50:09 -0700127 const unsigned short *alt_addr_list)
Benson Leungd1381f42012-10-25 14:21:21 -0700128{
129 const struct dmi_device *dmi_dev;
130 const struct dmi_dev_onboard *dev_data;
131 struct i2c_adapter *adapter;
Dmitry Torokhov96cba9b2015-04-14 13:50:09 -0700132 struct i2c_client *client = NULL;
133 const unsigned short addr_list[] = { info->addr, I2C_CLIENT_END };
Benson Leungd1381f42012-10-25 14:21:21 -0700134
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) {
144 pr_err("%s failed to dmi find device %s.\n",
145 __func__,
146 name);
147 return NULL;
148 }
149 dev_data = (struct dmi_dev_onboard *)dmi_dev->device_data;
150 if (!dev_data) {
151 pr_err("%s failed to get data from dmi for %s.\n",
152 __func__, name);
153 return NULL;
154 }
155 info->irq = dev_data->instance;
156 }
157
158 adapter = i2c_get_adapter(bus);
159 if (!adapter) {
160 pr_err("%s failed to get i2c adapter %d.\n", __func__, bus);
161 return NULL;
162 }
163
Dmitry Torokhov96cba9b2015-04-14 13:50:09 -0700164 /*
165 * Add the i2c device. If we can't detect it at the primary
166 * address we scan secondary addresses. In any case the client
167 * structure gets assigned primary address.
168 */
169 client = i2c_new_probed_device(adapter, info, addr_list, NULL);
170 if (!client && alt_addr_list) {
171 struct i2c_board_info dummy_info = {
172 I2C_BOARD_INFO("dummy", info->addr),
173 };
174 struct i2c_client *dummy;
175
176 dummy = i2c_new_probed_device(adapter, &dummy_info,
177 alt_addr_list, NULL);
178 if (dummy) {
179 pr_debug("%s %d-%02x is probed at %02x\n",
180 __func__, bus, info->addr, dummy->addr);
181 i2c_unregister_device(dummy);
182 client = i2c_new_device(adapter, info);
183 }
184 }
185
Benson Leungd1381f42012-10-25 14:21:21 -0700186 if (!client)
Benson Leung55024862014-07-15 17:43:11 -0700187 pr_notice("%s failed to register device %d-%02x\n",
188 __func__, bus, info->addr);
Benson Leungd1381f42012-10-25 14:21:21 -0700189 else
190 pr_debug("%s added i2c device %d-%02x\n",
191 __func__, bus, info->addr);
192
193 i2c_put_adapter(adapter);
194 return client;
195}
196
Mika Westerbergda3b0ab2014-06-17 14:02:00 -0700197struct i2c_lookup {
198 const char *name;
199 int instance;
200 int n;
201};
202
Benson Leung9ad36922013-10-20 20:58:25 -0700203static int __find_i2c_adap(struct device *dev, void *data)
Benson Leungd1381f42012-10-25 14:21:21 -0700204{
Mika Westerbergda3b0ab2014-06-17 14:02:00 -0700205 struct i2c_lookup *lookup = data;
Benson Leungd1381f42012-10-25 14:21:21 -0700206 static const char *prefix = "i2c-";
207 struct i2c_adapter *adapter;
Robin Schroer49c68a22014-05-29 20:45:07 +0200208
Benson Leungd1381f42012-10-25 14:21:21 -0700209 if (strncmp(dev_name(dev), prefix, strlen(prefix)) != 0)
210 return 0;
211 adapter = to_i2c_adapter(dev);
Mika Westerbergda3b0ab2014-06-17 14:02:00 -0700212 if (strncmp(adapter->name, lookup->name, strlen(lookup->name)) == 0 &&
213 lookup->n++ == lookup->instance)
214 return 1;
215 return 0;
Benson Leungd1381f42012-10-25 14:21:21 -0700216}
217
Benson Leung9ad36922013-10-20 20:58:25 -0700218static int find_i2c_adapter_num(enum i2c_adapter_type type)
Benson Leungd1381f42012-10-25 14:21:21 -0700219{
220 struct device *dev = NULL;
221 struct i2c_adapter *adapter;
Mika Westerbergda3b0ab2014-06-17 14:02:00 -0700222 struct i2c_lookup lookup;
223
224 memset(&lookup, 0, sizeof(lookup));
225 lookup.name = i2c_adapter_names[type];
226 lookup.instance = (type == I2C_ADAPTER_DESIGNWARE_1) ? 1 : 0;
227
Benson Leungd1381f42012-10-25 14:21:21 -0700228 /* find the adapter by name */
Mika Westerbergda3b0ab2014-06-17 14:02:00 -0700229 dev = bus_find_device(&i2c_bus_type, NULL, &lookup, __find_i2c_adap);
Benson Leungd1381f42012-10-25 14:21:21 -0700230 if (!dev) {
Benson Leung9ad36922013-10-20 20:58:25 -0700231 /* Adapters may appear later. Deferred probing will retry */
232 pr_notice("%s: i2c adapter %s not found on system.\n", __func__,
Mika Westerbergda3b0ab2014-06-17 14:02:00 -0700233 lookup.name);
Benson Leungd1381f42012-10-25 14:21:21 -0700234 return -ENODEV;
235 }
236 adapter = to_i2c_adapter(dev);
237 return adapter->nr;
238}
239
240/*
Benson Leungbcaf0892013-02-21 12:14:58 -0800241 * Takes a list of addresses in addrs as such :
242 * { addr1, ... , addrn, I2C_CLIENT_END };
243 * add_probed_i2c_device will use i2c_new_probed_device
244 * and probe for devices at all of the addresses listed.
245 * Returns NULL if no devices found.
246 * See Documentation/i2c/instantiating-devices for more information.
247 */
Benson Leung9ad36922013-10-20 20:58:25 -0700248static struct i2c_client *add_probed_i2c_device(
Benson Leungbcaf0892013-02-21 12:14:58 -0800249 const char *name,
250 enum i2c_adapter_type type,
251 struct i2c_board_info *info,
252 const unsigned short *addrs)
253{
254 return __add_probed_i2c_device(name,
255 find_i2c_adapter_num(type),
256 info,
257 addrs);
258}
259
260/*
Benson Leungd1381f42012-10-25 14:21:21 -0700261 * Probes for a device at a single address, the one provided by
262 * info->addr.
263 * Returns NULL if no device found.
264 */
Benson Leung9ad36922013-10-20 20:58:25 -0700265static struct i2c_client *add_i2c_device(const char *name,
Benson Leunge7b28842013-02-21 12:14:56 -0800266 enum i2c_adapter_type type,
267 struct i2c_board_info *info)
Benson Leungd1381f42012-10-25 14:21:21 -0700268{
Benson Leungd1381f42012-10-25 14:21:21 -0700269 return __add_probed_i2c_device(name,
Benson Leunge7b28842013-02-21 12:14:56 -0800270 find_i2c_adapter_num(type),
Benson Leungd1381f42012-10-25 14:21:21 -0700271 info,
Dmitry Torokhov96cba9b2015-04-14 13:50:09 -0700272 NULL);
Benson Leungd1381f42012-10-25 14:21:21 -0700273}
274
Benson Leung9ad36922013-10-20 20:58:25 -0700275static int setup_cyapa_tp(enum i2c_adapter_type type)
Benson Leunge7b28842013-02-21 12:14:56 -0800276{
Benson Leung9ad36922013-10-20 20:58:25 -0700277 if (tp)
278 return 0;
279
Aaron Durbinec199dd2013-10-20 20:58:24 -0700280 /* add cyapa touchpad */
281 tp = add_i2c_device("trackpad", type, &cyapa_device);
Benson Leung9ad36922013-10-20 20:58:25 -0700282 return (!tp) ? -EAGAIN : 0;
Benson Leungd1381f42012-10-25 14:21:21 -0700283}
284
Benson Leung9ad36922013-10-20 20:58:25 -0700285static int setup_atmel_224s_tp(enum i2c_adapter_type type)
Benson Leung8e1ad4c2013-02-21 12:14:59 -0800286{
287 const unsigned short addr_list[] = { ATMEL_TP_I2C_BL_ADDR,
Benson Leung8e1ad4c2013-02-21 12:14:59 -0800288 I2C_CLIENT_END };
Benson Leung9ad36922013-10-20 20:58:25 -0700289 if (tp)
290 return 0;
Benson Leung8e1ad4c2013-02-21 12:14:59 -0800291
Aaron Durbinec199dd2013-10-20 20:58:24 -0700292 /* add atmel mxt touchpad */
293 tp = add_probed_i2c_device("trackpad", type,
Benson Leung8e1ad4c2013-02-21 12:14:59 -0800294 &atmel_224s_tp_device, addr_list);
Benson Leung9ad36922013-10-20 20:58:25 -0700295 return (!tp) ? -EAGAIN : 0;
Benson Leung8e1ad4c2013-02-21 12:14:59 -0800296}
297
Benson Leung9bd9a902016-05-02 08:57:16 +0800298static int setup_elantech_tp(enum i2c_adapter_type type)
299{
300 if (tp)
301 return 0;
302
303 /* add elantech touchpad */
304 tp = add_i2c_device("trackpad", type, &elantech_device);
305 return (!tp) ? -EAGAIN : 0;
306}
307
Benson Leung9ad36922013-10-20 20:58:25 -0700308static int setup_atmel_1664s_ts(enum i2c_adapter_type type)
Yufeng Shen33a84f82013-02-21 12:15:00 -0800309{
310 const unsigned short addr_list[] = { ATMEL_TS_I2C_BL_ADDR,
Yufeng Shen33a84f82013-02-21 12:15:00 -0800311 I2C_CLIENT_END };
Benson Leung9ad36922013-10-20 20:58:25 -0700312 if (ts)
313 return 0;
Yufeng Shen33a84f82013-02-21 12:15:00 -0800314
Aaron Durbinec199dd2013-10-20 20:58:24 -0700315 /* add atmel mxt touch device */
316 ts = add_probed_i2c_device("touchscreen", type,
Yufeng Shen33a84f82013-02-21 12:15:00 -0800317 &atmel_1664s_device, addr_list);
Benson Leung9ad36922013-10-20 20:58:25 -0700318 return (!ts) ? -EAGAIN : 0;
Yufeng Shen33a84f82013-02-21 12:15:00 -0800319}
320
Benson Leung9ad36922013-10-20 20:58:25 -0700321static int setup_isl29018_als(enum i2c_adapter_type type)
Benson Leungd1381f42012-10-25 14:21:21 -0700322{
Benson Leung9ad36922013-10-20 20:58:25 -0700323 if (als)
324 return 0;
325
Benson Leungd1381f42012-10-25 14:21:21 -0700326 /* add isl29018 light sensor */
Aaron Durbinec199dd2013-10-20 20:58:24 -0700327 als = add_i2c_device("lightsensor", type, &isl_als_device);
Benson Leung9ad36922013-10-20 20:58:25 -0700328 return (!als) ? -EAGAIN : 0;
Benson Leungd1381f42012-10-25 14:21:21 -0700329}
330
Benson Leung9ad36922013-10-20 20:58:25 -0700331static int setup_tsl2583_als(enum i2c_adapter_type type)
Benson Leungcc5c3982013-02-21 12:14:57 -0800332{
Benson Leung9ad36922013-10-20 20:58:25 -0700333 if (als)
334 return 0;
335
Aaron Durbinec199dd2013-10-20 20:58:24 -0700336 /* add tsl2583 light sensor */
337 als = add_i2c_device(NULL, type, &tsl2583_als_device);
Benson Leung9ad36922013-10-20 20:58:25 -0700338 return (!als) ? -EAGAIN : 0;
Benson Leungcc5c3982013-02-21 12:14:57 -0800339}
340
Benson Leung9ad36922013-10-20 20:58:25 -0700341static int setup_tsl2563_als(enum i2c_adapter_type type)
Benson Leung8016bcb2013-02-01 14:34:46 -0800342{
Benson Leung9ad36922013-10-20 20:58:25 -0700343 if (als)
344 return 0;
345
Aaron Durbinec199dd2013-10-20 20:58:24 -0700346 /* add tsl2563 light sensor */
347 als = add_i2c_device(NULL, type, &tsl2563_als_device);
Benson Leung9ad36922013-10-20 20:58:25 -0700348 return (!als) ? -EAGAIN : 0;
Benson Leung8016bcb2013-02-01 14:34:46 -0800349}
350
Benson Leung9ad36922013-10-20 20:58:25 -0700351static int __init chromeos_laptop_dmi_matched(const struct dmi_system_id *id)
352{
353 cros_laptop = (void *)id->driver_data;
354 pr_debug("DMI Matched %s.\n", id->ident);
355
356 /* Indicate to dmi_scan that processing is done. */
357 return 1;
358}
359
360static int chromeos_laptop_probe(struct platform_device *pdev)
Benson Leungaabf3f42013-02-01 14:34:45 -0800361{
Aaron Durbinec199dd2013-10-20 20:58:24 -0700362 int i;
Benson Leung9ad36922013-10-20 20:58:25 -0700363 int ret = 0;
Aaron Durbinec199dd2013-10-20 20:58:24 -0700364
365 for (i = 0; i < MAX_I2C_PERIPHERALS; i++) {
366 struct i2c_peripheral *i2c_dev;
367
368 i2c_dev = &cros_laptop->i2c_peripherals[i];
369
370 /* No more peripherals. */
371 if (i2c_dev->add == NULL)
372 break;
373
Benson Leung55024862014-07-15 17:43:11 -0700374 if (i2c_dev->state == TIMEDOUT || i2c_dev->state == PROBED)
375 continue;
376
377 /*
378 * Check that the i2c adapter is present.
379 * -EPROBE_DEFER if missing as the adapter may appear much
380 * later.
381 */
382 if (find_i2c_adapter_num(i2c_dev->type) == -ENODEV) {
Benson Leung9ad36922013-10-20 20:58:25 -0700383 ret = -EPROBE_DEFER;
Benson Leung55024862014-07-15 17:43:11 -0700384 continue;
385 }
386
387 /* Add the device. */
388 if (i2c_dev->add(i2c_dev->type) == -EAGAIN) {
389 /*
390 * Set -EPROBE_DEFER a limited num of times
391 * if device is not successfully added.
392 */
393 if (++i2c_dev->tries < MAX_I2C_DEVICE_DEFERRALS) {
394 ret = -EPROBE_DEFER;
395 } else {
396 /* Ran out of tries. */
397 pr_notice("%s: Ran out of tries for device.\n",
398 __func__);
399 i2c_dev->state = TIMEDOUT;
400 }
401 } else {
402 i2c_dev->state = PROBED;
403 }
Aaron Durbinec199dd2013-10-20 20:58:24 -0700404 }
405
Benson Leung9ad36922013-10-20 20:58:25 -0700406 return ret;
Benson Leungaabf3f42013-02-01 14:34:45 -0800407}
408
Dmitry Torokhovfc88bbd2018-03-06 10:59:15 -0800409static struct chromeos_laptop samsung_series_5_550 = {
Aaron Durbinec199dd2013-10-20 20:58:24 -0700410 .i2c_peripherals = {
411 /* Touchpad. */
412 { .add = setup_cyapa_tp, I2C_ADAPTER_SMBUS },
413 /* Light Sensor. */
414 { .add = setup_isl29018_als, I2C_ADAPTER_SMBUS },
415 },
416};
417
Dmitry Torokhovfc88bbd2018-03-06 10:59:15 -0800418static struct chromeos_laptop samsung_series_5 = {
Aaron Durbinec199dd2013-10-20 20:58:24 -0700419 .i2c_peripherals = {
420 /* Light Sensor. */
421 { .add = setup_tsl2583_als, I2C_ADAPTER_SMBUS },
422 },
423};
424
Dmitry Torokhovfc88bbd2018-03-06 10:59:15 -0800425static struct chromeos_laptop chromebook_pixel = {
Aaron Durbinec199dd2013-10-20 20:58:24 -0700426 .i2c_peripherals = {
427 /* Touch Screen. */
428 { .add = setup_atmel_1664s_ts, I2C_ADAPTER_PANEL },
429 /* Touchpad. */
430 { .add = setup_atmel_224s_tp, I2C_ADAPTER_VGADDC },
431 /* Light Sensor. */
432 { .add = setup_isl29018_als, I2C_ADAPTER_PANEL },
433 },
434};
435
Dmitry Torokhovfc88bbd2018-03-06 10:59:15 -0800436static struct chromeos_laptop hp_chromebook_14 = {
Benson Leung5ea95672014-06-17 14:02:01 -0700437 .i2c_peripherals = {
438 /* Touchpad. */
439 { .add = setup_cyapa_tp, I2C_ADAPTER_DESIGNWARE_0 },
440 },
441};
442
Dmitry Torokhovfc88bbd2018-03-06 10:59:15 -0800443static struct chromeos_laptop dell_chromebook_11 = {
Mohammed Habibulla0e1e5e52014-06-17 14:02:02 -0700444 .i2c_peripherals = {
445 /* Touchpad. */
446 { .add = setup_cyapa_tp, I2C_ADAPTER_DESIGNWARE_0 },
Charlie Mooney9e96aa72016-05-02 08:57:17 +0800447 /* Elan Touchpad option. */
448 { .add = setup_elantech_tp, I2C_ADAPTER_DESIGNWARE_0 },
Mohammed Habibulla0e1e5e52014-06-17 14:02:02 -0700449 },
450};
451
Dmitry Torokhovfc88bbd2018-03-06 10:59:15 -0800452static struct chromeos_laptop toshiba_cb35 = {
Gene Chen963cb6f2014-06-17 14:02:03 -0700453 .i2c_peripherals = {
454 /* Touchpad. */
455 { .add = setup_cyapa_tp, I2C_ADAPTER_DESIGNWARE_0 },
456 },
457};
458
Dmitry Torokhovfc88bbd2018-03-06 10:59:15 -0800459static struct chromeos_laptop acer_c7_chromebook = {
Aaron Durbinec199dd2013-10-20 20:58:24 -0700460 .i2c_peripherals = {
461 /* Touchpad. */
462 { .add = setup_cyapa_tp, I2C_ADAPTER_SMBUS },
463 },
464};
465
Dmitry Torokhovfc88bbd2018-03-06 10:59:15 -0800466static struct chromeos_laptop acer_ac700 = {
Aaron Durbinec199dd2013-10-20 20:58:24 -0700467 .i2c_peripherals = {
468 /* Light Sensor. */
469 { .add = setup_tsl2563_als, I2C_ADAPTER_SMBUS },
470 },
471};
472
Dmitry Torokhovfc88bbd2018-03-06 10:59:15 -0800473static struct chromeos_laptop acer_c720 = {
Mika Westerbergda3b0ab2014-06-17 14:02:00 -0700474 .i2c_peripherals = {
Michael Mullinb90b3c42014-07-15 20:00:54 -0400475 /* Touchscreen. */
476 { .add = setup_atmel_1664s_ts, I2C_ADAPTER_DESIGNWARE_1 },
Mika Westerbergda3b0ab2014-06-17 14:02:00 -0700477 /* Touchpad. */
478 { .add = setup_cyapa_tp, I2C_ADAPTER_DESIGNWARE_0 },
Benson Leung9bd9a902016-05-02 08:57:16 +0800479 /* Elan Touchpad option. */
480 { .add = setup_elantech_tp, I2C_ADAPTER_DESIGNWARE_0 },
Mika Westerbergda3b0ab2014-06-17 14:02:00 -0700481 /* Light Sensor. */
482 { .add = setup_isl29018_als, I2C_ADAPTER_DESIGNWARE_1 },
483 },
484};
485
Dmitry Torokhovfc88bbd2018-03-06 10:59:15 -0800486static struct chromeos_laptop hp_pavilion_14_chromebook = {
Aaron Durbinec199dd2013-10-20 20:58:24 -0700487 .i2c_peripherals = {
488 /* Touchpad. */
489 { .add = setup_cyapa_tp, I2C_ADAPTER_SMBUS },
490 },
491};
492
Dmitry Torokhovfc88bbd2018-03-06 10:59:15 -0800493static struct chromeos_laptop cr48 = {
Aaron Durbinec199dd2013-10-20 20:58:24 -0700494 .i2c_peripherals = {
495 /* Light Sensor. */
496 { .add = setup_tsl2563_als, I2C_ADAPTER_SMBUS },
497 },
498};
499
500#define _CBDD(board_) \
Benson Leung9ad36922013-10-20 20:58:25 -0700501 .callback = chromeos_laptop_dmi_matched, \
Aaron Durbinec199dd2013-10-20 20:58:24 -0700502 .driver_data = (void *)&board_
503
Christoph Hellwig6faadbb2017-09-14 11:59:30 +0200504static const struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
Benson Leungd1381f42012-10-25 14:21:21 -0700505 {
Aaron Durbinec199dd2013-10-20 20:58:24 -0700506 .ident = "Samsung Series 5 550",
Benson Leungd1381f42012-10-25 14:21:21 -0700507 .matches = {
508 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG"),
509 DMI_MATCH(DMI_PRODUCT_NAME, "Lumpy"),
510 },
Aaron Durbinec199dd2013-10-20 20:58:24 -0700511 _CBDD(samsung_series_5_550),
Benson Leungd1381f42012-10-25 14:21:21 -0700512 },
513 {
Aaron Durbinec199dd2013-10-20 20:58:24 -0700514 .ident = "Samsung Series 5",
Benson Leung8016bcb2013-02-01 14:34:46 -0800515 .matches = {
516 DMI_MATCH(DMI_PRODUCT_NAME, "Alex"),
517 },
Aaron Durbinec199dd2013-10-20 20:58:24 -0700518 _CBDD(samsung_series_5),
Benson Leung8016bcb2013-02-01 14:34:46 -0800519 },
520 {
Aaron Durbinec199dd2013-10-20 20:58:24 -0700521 .ident = "Chromebook Pixel",
Benson Leungaabf3f42013-02-01 14:34:45 -0800522 .matches = {
Aaron Durbinec199dd2013-10-20 20:58:24 -0700523 DMI_MATCH(DMI_SYS_VENDOR, "GOOGLE"),
524 DMI_MATCH(DMI_PRODUCT_NAME, "Link"),
Benson Leungaabf3f42013-02-01 14:34:45 -0800525 },
Aaron Durbinec199dd2013-10-20 20:58:24 -0700526 _CBDD(chromebook_pixel),
Benson Leungaabf3f42013-02-01 14:34:45 -0800527 },
528 {
Mohammed Habibulla0e1e5e52014-06-17 14:02:02 -0700529 .ident = "Wolf",
530 .matches = {
531 DMI_MATCH(DMI_BIOS_VENDOR, "coreboot"),
532 DMI_MATCH(DMI_PRODUCT_NAME, "Wolf"),
533 },
534 _CBDD(dell_chromebook_11),
535 },
536 {
Benson Leung5ea95672014-06-17 14:02:01 -0700537 .ident = "HP Chromebook 14",
538 .matches = {
539 DMI_MATCH(DMI_BIOS_VENDOR, "coreboot"),
540 DMI_MATCH(DMI_PRODUCT_NAME, "Falco"),
541 },
542 _CBDD(hp_chromebook_14),
543 },
544 {
Gene Chen963cb6f2014-06-17 14:02:03 -0700545 .ident = "Toshiba CB35",
546 .matches = {
547 DMI_MATCH(DMI_BIOS_VENDOR, "coreboot"),
548 DMI_MATCH(DMI_PRODUCT_NAME, "Leon"),
549 },
550 _CBDD(toshiba_cb35),
551 },
552 {
Aaron Durbinec199dd2013-10-20 20:58:24 -0700553 .ident = "Acer C7 Chromebook",
554 .matches = {
555 DMI_MATCH(DMI_PRODUCT_NAME, "Parrot"),
556 },
557 _CBDD(acer_c7_chromebook),
558 },
559 {
560 .ident = "Acer AC700",
Benson Leungaabf3f42013-02-01 14:34:45 -0800561 .matches = {
562 DMI_MATCH(DMI_PRODUCT_NAME, "ZGB"),
563 },
Aaron Durbinec199dd2013-10-20 20:58:24 -0700564 _CBDD(acer_ac700),
565 },
566 {
Mika Westerbergda3b0ab2014-06-17 14:02:00 -0700567 .ident = "Acer C720",
568 .matches = {
569 DMI_MATCH(DMI_PRODUCT_NAME, "Peppy"),
570 },
571 _CBDD(acer_c720),
572 },
573 {
Aaron Durbinec199dd2013-10-20 20:58:24 -0700574 .ident = "HP Pavilion 14 Chromebook",
575 .matches = {
576 DMI_MATCH(DMI_PRODUCT_NAME, "Butterfly"),
577 },
578 _CBDD(hp_pavilion_14_chromebook),
579 },
580 {
581 .ident = "Cr-48",
582 .matches = {
583 DMI_MATCH(DMI_PRODUCT_NAME, "Mario"),
584 },
585 _CBDD(cr48),
Benson Leungaabf3f42013-02-01 14:34:45 -0800586 },
Benson Leungd1381f42012-10-25 14:21:21 -0700587 { }
588};
589MODULE_DEVICE_TABLE(dmi, chromeos_laptop_dmi_table);
590
Benson Leung9ad36922013-10-20 20:58:25 -0700591static struct platform_device *cros_platform_device;
592
593static struct platform_driver cros_platform_driver = {
594 .driver = {
595 .name = "chromeos_laptop",
Benson Leung9ad36922013-10-20 20:58:25 -0700596 },
597 .probe = chromeos_laptop_probe,
598};
599
Benson Leungd1381f42012-10-25 14:21:21 -0700600static int __init chromeos_laptop_init(void)
601{
Benson Leung9ad36922013-10-20 20:58:25 -0700602 int ret;
Robin Schroer49c68a22014-05-29 20:45:07 +0200603
Benson Leungd1381f42012-10-25 14:21:21 -0700604 if (!dmi_check_system(chromeos_laptop_dmi_table)) {
605 pr_debug("%s unsupported system.\n", __func__);
606 return -ENODEV;
607 }
Benson Leung9ad36922013-10-20 20:58:25 -0700608
609 ret = platform_driver_register(&cros_platform_driver);
610 if (ret)
611 return ret;
612
613 cros_platform_device = platform_device_alloc("chromeos_laptop", -1);
614 if (!cros_platform_device) {
615 ret = -ENOMEM;
616 goto fail_platform_device1;
617 }
618
619 ret = platform_device_add(cros_platform_device);
620 if (ret)
621 goto fail_platform_device2;
622
Benson Leungd1381f42012-10-25 14:21:21 -0700623 return 0;
Benson Leung9ad36922013-10-20 20:58:25 -0700624
625fail_platform_device2:
626 platform_device_put(cros_platform_device);
627fail_platform_device1:
628 platform_driver_unregister(&cros_platform_driver);
629 return ret;
Benson Leungd1381f42012-10-25 14:21:21 -0700630}
631
632static void __exit chromeos_laptop_exit(void)
633{
634 if (als)
635 i2c_unregister_device(als);
636 if (tp)
637 i2c_unregister_device(tp);
Yufeng Shen33a84f82013-02-21 12:15:00 -0800638 if (ts)
639 i2c_unregister_device(ts);
Wei Yongjun2b8454a2013-11-27 11:34:58 +0800640
641 platform_device_unregister(cros_platform_device);
642 platform_driver_unregister(&cros_platform_driver);
Benson Leungd1381f42012-10-25 14:21:21 -0700643}
644
645module_init(chromeos_laptop_init);
646module_exit(chromeos_laptop_exit);
647
648MODULE_DESCRIPTION("Chrome OS Laptop driver");
649MODULE_AUTHOR("Benson Leung <bleung@chromium.org>");
650MODULE_LICENSE("GPL");