platform/chrome: chromeos_laptop - Add Dell Chromebook 11 touch
[deliverable/linux.git] / drivers / platform / chrome / chromeos_laptop.c
CommitLineData
d1381f45
BL
1/*
2 * chromeos_laptop.c - Driver to instantiate Chromebook i2c/smbus devices.
3 *
4 * Author : Benson Leung <bleung@chromium.org>
5 *
6 * Copyright (C) 2012 Google, Inc.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 */
23
24#include <linux/dmi.h>
25#include <linux/i2c.h>
2ef39204
BL
26#include <linux/i2c/atmel_mxt_ts.h>
27#include <linux/input.h>
28#include <linux/interrupt.h>
d1381f45 29#include <linux/module.h>
9ad36924 30#include <linux/platform_device.h>
d1381f45 31
8e1ad4c4
BL
32#define ATMEL_TP_I2C_ADDR 0x4b
33#define ATMEL_TP_I2C_BL_ADDR 0x25
33a84f8a
YS
34#define ATMEL_TS_I2C_ADDR 0x4a
35#define ATMEL_TS_I2C_BL_ADDR 0x26
d1381f45
BL
36#define CYAPA_TP_I2C_ADDR 0x67
37#define ISL_ALS_I2C_ADDR 0x44
aabf3f44 38#define TAOS_ALS_I2C_ADDR 0x29
d1381f45
BL
39
40static struct i2c_client *als;
41static struct i2c_client *tp;
33a84f8a 42static struct i2c_client *ts;
d1381f45 43
6d3c1afe 44static const char *i2c_adapter_names[] = {
d1381f45 45 "SMBus I801 adapter",
741bf0c7
BL
46 "i915 gmbus vga",
47 "i915 gmbus panel",
da3b0ab7
MW
48 "i2c-designware-pci",
49 "i2c-designware-pci",
d1381f45
BL
50};
51
52/* Keep this enum consistent with i2c_adapter_names */
53enum i2c_adapter_type {
54 I2C_ADAPTER_SMBUS = 0,
741bf0c7
BL
55 I2C_ADAPTER_VGADDC,
56 I2C_ADAPTER_PANEL,
da3b0ab7
MW
57 I2C_ADAPTER_DESIGNWARE_0,
58 I2C_ADAPTER_DESIGNWARE_1,
d1381f45
BL
59};
60
ec199dd5 61struct i2c_peripheral {
9ad36924 62 int (*add)(enum i2c_adapter_type type);
ec199dd5
AD
63 enum i2c_adapter_type type;
64};
65
66#define MAX_I2C_PERIPHERALS 3
67
68struct chromeos_laptop {
69 struct i2c_peripheral i2c_peripherals[MAX_I2C_PERIPHERALS];
70};
71
9ad36924
BL
72static struct chromeos_laptop *cros_laptop;
73
74static struct i2c_board_info cyapa_device = {
d1381f45
BL
75 I2C_BOARD_INFO("cyapa", CYAPA_TP_I2C_ADDR),
76 .flags = I2C_CLIENT_WAKE,
77};
78
9ad36924 79static struct i2c_board_info isl_als_device = {
d1381f45
BL
80 I2C_BOARD_INFO("isl29018", ISL_ALS_I2C_ADDR),
81};
82
9ad36924 83static struct i2c_board_info tsl2583_als_device = {
8016bcbc
BL
84 I2C_BOARD_INFO("tsl2583", TAOS_ALS_I2C_ADDR),
85};
86
9ad36924 87static struct i2c_board_info tsl2563_als_device = {
aabf3f44
BL
88 I2C_BOARD_INFO("tsl2563", TAOS_ALS_I2C_ADDR),
89};
90
fb5e4c3e
ND
91static int mxt_t19_keys[] = {
92 KEY_RESERVED,
93 KEY_RESERVED,
94 KEY_RESERVED,
95 KEY_RESERVED,
96 KEY_RESERVED,
97 BTN_LEFT
98};
99
2ef39204 100static struct mxt_platform_data atmel_224s_tp_platform_data = {
2ef39204 101 .irqflags = IRQF_TRIGGER_FALLING,
fb5e4c3e
ND
102 .t19_num_keys = ARRAY_SIZE(mxt_t19_keys),
103 .t19_keymap = mxt_t19_keys,
2ef39204
BL
104 .config = NULL,
105 .config_length = 0,
106};
107
9ad36924 108static struct i2c_board_info atmel_224s_tp_device = {
8e1ad4c4 109 I2C_BOARD_INFO("atmel_mxt_tp", ATMEL_TP_I2C_ADDR),
2ef39204 110 .platform_data = &atmel_224s_tp_platform_data,
8e1ad4c4
BL
111 .flags = I2C_CLIENT_WAKE,
112};
113
2ef39204 114static struct mxt_platform_data atmel_1664s_platform_data = {
2ef39204 115 .irqflags = IRQF_TRIGGER_FALLING,
2ef39204
BL
116 .config = NULL,
117 .config_length = 0,
118};
119
9ad36924 120static struct i2c_board_info atmel_1664s_device = {
33a84f8a 121 I2C_BOARD_INFO("atmel_mxt_ts", ATMEL_TS_I2C_ADDR),
2ef39204 122 .platform_data = &atmel_1664s_platform_data,
33a84f8a
YS
123 .flags = I2C_CLIENT_WAKE,
124};
125
9ad36924 126static struct i2c_client *__add_probed_i2c_device(
d1381f45
BL
127 const char *name,
128 int bus,
129 struct i2c_board_info *info,
130 const unsigned short *addrs)
131{
132 const struct dmi_device *dmi_dev;
133 const struct dmi_dev_onboard *dev_data;
134 struct i2c_adapter *adapter;
135 struct i2c_client *client;
136
137 if (bus < 0)
138 return NULL;
139 /*
140 * If a name is specified, look for irq platform information stashed
141 * in DMI_DEV_TYPE_DEV_ONBOARD by the Chrome OS custom system firmware.
142 */
143 if (name) {
144 dmi_dev = dmi_find_device(DMI_DEV_TYPE_DEV_ONBOARD, name, NULL);
145 if (!dmi_dev) {
146 pr_err("%s failed to dmi find device %s.\n",
147 __func__,
148 name);
149 return NULL;
150 }
151 dev_data = (struct dmi_dev_onboard *)dmi_dev->device_data;
152 if (!dev_data) {
153 pr_err("%s failed to get data from dmi for %s.\n",
154 __func__, name);
155 return NULL;
156 }
157 info->irq = dev_data->instance;
158 }
159
160 adapter = i2c_get_adapter(bus);
161 if (!adapter) {
162 pr_err("%s failed to get i2c adapter %d.\n", __func__, bus);
163 return NULL;
164 }
165
166 /* add the i2c device */
167 client = i2c_new_probed_device(adapter, info, addrs, NULL);
168 if (!client)
169 pr_err("%s failed to register device %d-%02x\n",
170 __func__, bus, info->addr);
171 else
172 pr_debug("%s added i2c device %d-%02x\n",
173 __func__, bus, info->addr);
174
175 i2c_put_adapter(adapter);
176 return client;
177}
178
da3b0ab7
MW
179struct i2c_lookup {
180 const char *name;
181 int instance;
182 int n;
183};
184
9ad36924 185static int __find_i2c_adap(struct device *dev, void *data)
d1381f45 186{
da3b0ab7 187 struct i2c_lookup *lookup = data;
d1381f45
BL
188 static const char *prefix = "i2c-";
189 struct i2c_adapter *adapter;
190 if (strncmp(dev_name(dev), prefix, strlen(prefix)) != 0)
191 return 0;
192 adapter = to_i2c_adapter(dev);
da3b0ab7
MW
193 if (strncmp(adapter->name, lookup->name, strlen(lookup->name)) == 0 &&
194 lookup->n++ == lookup->instance)
195 return 1;
196 return 0;
d1381f45
BL
197}
198
9ad36924 199static int find_i2c_adapter_num(enum i2c_adapter_type type)
d1381f45
BL
200{
201 struct device *dev = NULL;
202 struct i2c_adapter *adapter;
da3b0ab7
MW
203 struct i2c_lookup lookup;
204
205 memset(&lookup, 0, sizeof(lookup));
206 lookup.name = i2c_adapter_names[type];
207 lookup.instance = (type == I2C_ADAPTER_DESIGNWARE_1) ? 1 : 0;
208
d1381f45 209 /* find the adapter by name */
da3b0ab7 210 dev = bus_find_device(&i2c_bus_type, NULL, &lookup, __find_i2c_adap);
d1381f45 211 if (!dev) {
9ad36924
BL
212 /* Adapters may appear later. Deferred probing will retry */
213 pr_notice("%s: i2c adapter %s not found on system.\n", __func__,
da3b0ab7 214 lookup.name);
d1381f45
BL
215 return -ENODEV;
216 }
217 adapter = to_i2c_adapter(dev);
218 return adapter->nr;
219}
220
bcaf089c
BL
221/*
222 * Takes a list of addresses in addrs as such :
223 * { addr1, ... , addrn, I2C_CLIENT_END };
224 * add_probed_i2c_device will use i2c_new_probed_device
225 * and probe for devices at all of the addresses listed.
226 * Returns NULL if no devices found.
227 * See Documentation/i2c/instantiating-devices for more information.
228 */
9ad36924 229static struct i2c_client *add_probed_i2c_device(
bcaf089c
BL
230 const char *name,
231 enum i2c_adapter_type type,
232 struct i2c_board_info *info,
233 const unsigned short *addrs)
234{
235 return __add_probed_i2c_device(name,
236 find_i2c_adapter_num(type),
237 info,
238 addrs);
239}
240
d1381f45
BL
241/*
242 * Probes for a device at a single address, the one provided by
243 * info->addr.
244 * Returns NULL if no device found.
245 */
9ad36924 246static struct i2c_client *add_i2c_device(const char *name,
e7b28845
BL
247 enum i2c_adapter_type type,
248 struct i2c_board_info *info)
d1381f45
BL
249{
250 const unsigned short addr_list[] = { info->addr, I2C_CLIENT_END };
251 return __add_probed_i2c_device(name,
e7b28845 252 find_i2c_adapter_num(type),
d1381f45
BL
253 info,
254 addr_list);
255}
256
9ad36924 257static int setup_cyapa_tp(enum i2c_adapter_type type)
d1381f45 258{
9ad36924
BL
259 if (tp)
260 return 0;
261
ec199dd5
AD
262 /* add cyapa touchpad */
263 tp = add_i2c_device("trackpad", type, &cyapa_device);
9ad36924 264 return (!tp) ? -EAGAIN : 0;
d1381f45
BL
265}
266
9ad36924 267static int setup_atmel_224s_tp(enum i2c_adapter_type type)
8e1ad4c4
BL
268{
269 const unsigned short addr_list[] = { ATMEL_TP_I2C_BL_ADDR,
270 ATMEL_TP_I2C_ADDR,
271 I2C_CLIENT_END };
9ad36924
BL
272 if (tp)
273 return 0;
8e1ad4c4 274
ec199dd5
AD
275 /* add atmel mxt touchpad */
276 tp = add_probed_i2c_device("trackpad", type,
8e1ad4c4 277 &atmel_224s_tp_device, addr_list);
9ad36924 278 return (!tp) ? -EAGAIN : 0;
8e1ad4c4
BL
279}
280
9ad36924 281static int setup_atmel_1664s_ts(enum i2c_adapter_type type)
33a84f8a
YS
282{
283 const unsigned short addr_list[] = { ATMEL_TS_I2C_BL_ADDR,
284 ATMEL_TS_I2C_ADDR,
285 I2C_CLIENT_END };
9ad36924
BL
286 if (ts)
287 return 0;
33a84f8a 288
ec199dd5
AD
289 /* add atmel mxt touch device */
290 ts = add_probed_i2c_device("touchscreen", type,
33a84f8a 291 &atmel_1664s_device, addr_list);
9ad36924 292 return (!ts) ? -EAGAIN : 0;
33a84f8a
YS
293}
294
9ad36924 295static int setup_isl29018_als(enum i2c_adapter_type type)
d1381f45 296{
9ad36924
BL
297 if (als)
298 return 0;
299
d1381f45 300 /* add isl29018 light sensor */
ec199dd5 301 als = add_i2c_device("lightsensor", type, &isl_als_device);
9ad36924 302 return (!als) ? -EAGAIN : 0;
d1381f45
BL
303}
304
9ad36924 305static int setup_tsl2583_als(enum i2c_adapter_type type)
cc5c3985 306{
9ad36924
BL
307 if (als)
308 return 0;
309
ec199dd5
AD
310 /* add tsl2583 light sensor */
311 als = add_i2c_device(NULL, type, &tsl2583_als_device);
9ad36924 312 return (!als) ? -EAGAIN : 0;
cc5c3985
BL
313}
314
9ad36924 315static int setup_tsl2563_als(enum i2c_adapter_type type)
8016bcbc 316{
9ad36924
BL
317 if (als)
318 return 0;
319
ec199dd5
AD
320 /* add tsl2563 light sensor */
321 als = add_i2c_device(NULL, type, &tsl2563_als_device);
9ad36924 322 return (!als) ? -EAGAIN : 0;
8016bcbc
BL
323}
324
9ad36924 325static int __init chromeos_laptop_dmi_matched(const struct dmi_system_id *id)
aabf3f44 326{
9ad36924
BL
327 cros_laptop = (void *)id->driver_data;
328 pr_debug("DMI Matched %s.\n", id->ident);
ec199dd5 329
9ad36924
BL
330 /* Indicate to dmi_scan that processing is done. */
331 return 1;
332}
333
334static int chromeos_laptop_probe(struct platform_device *pdev)
335{
336 int i;
337 int ret = 0;
ec199dd5
AD
338
339 for (i = 0; i < MAX_I2C_PERIPHERALS; i++) {
340 struct i2c_peripheral *i2c_dev;
341
342 i2c_dev = &cros_laptop->i2c_peripherals[i];
343
344 /* No more peripherals. */
345 if (i2c_dev->add == NULL)
346 break;
347
9ad36924
BL
348 /* Add the device. Set -EPROBE_DEFER on any failure */
349 if (i2c_dev->add(i2c_dev->type))
350 ret = -EPROBE_DEFER;
ec199dd5
AD
351 }
352
9ad36924 353 return ret;
aabf3f44
BL
354}
355
9ad36924 356static struct chromeos_laptop samsung_series_5_550 = {
ec199dd5
AD
357 .i2c_peripherals = {
358 /* Touchpad. */
359 { .add = setup_cyapa_tp, I2C_ADAPTER_SMBUS },
360 /* Light Sensor. */
361 { .add = setup_isl29018_als, I2C_ADAPTER_SMBUS },
362 },
363};
364
9ad36924 365static struct chromeos_laptop samsung_series_5 = {
ec199dd5
AD
366 .i2c_peripherals = {
367 /* Light Sensor. */
368 { .add = setup_tsl2583_als, I2C_ADAPTER_SMBUS },
369 },
370};
371
9ad36924 372static struct chromeos_laptop chromebook_pixel = {
ec199dd5
AD
373 .i2c_peripherals = {
374 /* Touch Screen. */
375 { .add = setup_atmel_1664s_ts, I2C_ADAPTER_PANEL },
376 /* Touchpad. */
377 { .add = setup_atmel_224s_tp, I2C_ADAPTER_VGADDC },
378 /* Light Sensor. */
379 { .add = setup_isl29018_als, I2C_ADAPTER_PANEL },
380 },
381};
382
5ea9567f
BL
383static struct chromeos_laptop hp_chromebook_14 = {
384 .i2c_peripherals = {
385 /* Touchpad. */
386 { .add = setup_cyapa_tp, I2C_ADAPTER_DESIGNWARE_0 },
387 },
388};
389
0e1e5e59
MH
390static struct chromeos_laptop dell_chromebook_11 = {
391 .i2c_peripherals = {
392 /* Touchpad. */
393 { .add = setup_cyapa_tp, I2C_ADAPTER_DESIGNWARE_0 },
394 },
395};
396
9ad36924 397static struct chromeos_laptop acer_c7_chromebook = {
ec199dd5
AD
398 .i2c_peripherals = {
399 /* Touchpad. */
400 { .add = setup_cyapa_tp, I2C_ADAPTER_SMBUS },
401 },
402};
403
9ad36924 404static struct chromeos_laptop acer_ac700 = {
ec199dd5
AD
405 .i2c_peripherals = {
406 /* Light Sensor. */
407 { .add = setup_tsl2563_als, I2C_ADAPTER_SMBUS },
408 },
409};
410
da3b0ab7
MW
411static struct chromeos_laptop acer_c720 = {
412 .i2c_peripherals = {
413 /* Touchpad. */
414 { .add = setup_cyapa_tp, I2C_ADAPTER_DESIGNWARE_0 },
415 /* Light Sensor. */
416 { .add = setup_isl29018_als, I2C_ADAPTER_DESIGNWARE_1 },
417 },
418};
419
9ad36924 420static struct chromeos_laptop hp_pavilion_14_chromebook = {
ec199dd5
AD
421 .i2c_peripherals = {
422 /* Touchpad. */
423 { .add = setup_cyapa_tp, I2C_ADAPTER_SMBUS },
424 },
425};
426
9ad36924 427static struct chromeos_laptop cr48 = {
ec199dd5
AD
428 .i2c_peripherals = {
429 /* Light Sensor. */
430 { .add = setup_tsl2563_als, I2C_ADAPTER_SMBUS },
431 },
432};
433
434#define _CBDD(board_) \
9ad36924 435 .callback = chromeos_laptop_dmi_matched, \
ec199dd5
AD
436 .driver_data = (void *)&board_
437
cdddd23f 438static struct dmi_system_id chromeos_laptop_dmi_table[] __initdata = {
d1381f45 439 {
ec199dd5 440 .ident = "Samsung Series 5 550",
d1381f45
BL
441 .matches = {
442 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG"),
443 DMI_MATCH(DMI_PRODUCT_NAME, "Lumpy"),
444 },
ec199dd5 445 _CBDD(samsung_series_5_550),
8e1ad4c4 446 },
d1381f45 447 {
ec199dd5 448 .ident = "Samsung Series 5",
d1381f45 449 .matches = {
ec199dd5 450 DMI_MATCH(DMI_PRODUCT_NAME, "Alex"),
d1381f45 451 },
ec199dd5 452 _CBDD(samsung_series_5),
d1381f45 453 },
cc5c3985 454 {
ec199dd5 455 .ident = "Chromebook Pixel",
cc5c3985
BL
456 .matches = {
457 DMI_MATCH(DMI_SYS_VENDOR, "GOOGLE"),
458 DMI_MATCH(DMI_PRODUCT_NAME, "Link"),
459 },
ec199dd5 460 _CBDD(chromebook_pixel),
cc5c3985 461 },
0e1e5e59
MH
462 {
463 .ident = "Wolf",
464 .matches = {
465 DMI_MATCH(DMI_BIOS_VENDOR, "coreboot"),
466 DMI_MATCH(DMI_PRODUCT_NAME, "Wolf"),
467 },
468 _CBDD(dell_chromebook_11),
469 },
5ea9567f
BL
470 {
471 .ident = "HP Chromebook 14",
472 .matches = {
473 DMI_MATCH(DMI_BIOS_VENDOR, "coreboot"),
474 DMI_MATCH(DMI_PRODUCT_NAME, "Falco"),
475 },
476 _CBDD(hp_chromebook_14),
477 },
261f171f 478 {
ec199dd5 479 .ident = "Acer C7 Chromebook",
261f171f
BL
480 .matches = {
481 DMI_MATCH(DMI_PRODUCT_NAME, "Parrot"),
482 },
ec199dd5 483 _CBDD(acer_c7_chromebook),
e65a624b
BL
484 },
485 {
ec199dd5 486 .ident = "Acer AC700",
e65a624b 487 .matches = {
ec199dd5 488 DMI_MATCH(DMI_PRODUCT_NAME, "ZGB"),
e65a624b 489 },
ec199dd5 490 _CBDD(acer_ac700),
261f171f 491 },
da3b0ab7
MW
492 {
493 .ident = "Acer C720",
494 .matches = {
495 DMI_MATCH(DMI_PRODUCT_NAME, "Peppy"),
496 },
497 _CBDD(acer_c720),
498 },
8016bcbc 499 {
ec199dd5 500 .ident = "HP Pavilion 14 Chromebook",
8016bcbc 501 .matches = {
ec199dd5 502 DMI_MATCH(DMI_PRODUCT_NAME, "Butterfly"),
8016bcbc 503 },
ec199dd5 504 _CBDD(hp_pavilion_14_chromebook),
8016bcbc 505 },
aabf3f44 506 {
ec199dd5 507 .ident = "Cr-48",
aabf3f44
BL
508 .matches = {
509 DMI_MATCH(DMI_PRODUCT_NAME, "Mario"),
510 },
ec199dd5 511 _CBDD(cr48),
aabf3f44 512 },
d1381f45
BL
513 { }
514};
515MODULE_DEVICE_TABLE(dmi, chromeos_laptop_dmi_table);
516
9ad36924
BL
517static struct platform_device *cros_platform_device;
518
519static struct platform_driver cros_platform_driver = {
520 .driver = {
521 .name = "chromeos_laptop",
522 .owner = THIS_MODULE,
523 },
524 .probe = chromeos_laptop_probe,
525};
526
d1381f45
BL
527static int __init chromeos_laptop_init(void)
528{
9ad36924 529 int ret;
d1381f45
BL
530 if (!dmi_check_system(chromeos_laptop_dmi_table)) {
531 pr_debug("%s unsupported system.\n", __func__);
532 return -ENODEV;
533 }
9ad36924
BL
534
535 ret = platform_driver_register(&cros_platform_driver);
536 if (ret)
537 return ret;
538
539 cros_platform_device = platform_device_alloc("chromeos_laptop", -1);
540 if (!cros_platform_device) {
541 ret = -ENOMEM;
542 goto fail_platform_device1;
543 }
544
545 ret = platform_device_add(cros_platform_device);
546 if (ret)
547 goto fail_platform_device2;
548
d1381f45 549 return 0;
9ad36924
BL
550
551fail_platform_device2:
552 platform_device_put(cros_platform_device);
553fail_platform_device1:
554 platform_driver_unregister(&cros_platform_driver);
555 return ret;
d1381f45
BL
556}
557
558static void __exit chromeos_laptop_exit(void)
559{
560 if (als)
561 i2c_unregister_device(als);
562 if (tp)
563 i2c_unregister_device(tp);
33a84f8a
YS
564 if (ts)
565 i2c_unregister_device(ts);
2b8454a7
WY
566
567 platform_device_unregister(cros_platform_device);
568 platform_driver_unregister(&cros_platform_driver);
d1381f45
BL
569}
570
571module_init(chromeos_laptop_init);
572module_exit(chromeos_laptop_exit);
573
574MODULE_DESCRIPTION("Chrome OS Laptop driver");
575MODULE_AUTHOR("Benson Leung <bleung@chromium.org>");
576MODULE_LICENSE("GPL");
This page took 0.110321 seconds and 5 git commands to generate.