2 * chromeos_laptop.c - Driver to instantiate Chromebook i2c/smbus devices.
4 * Author : Benson Leung <bleung@chromium.org>
6 * Copyright (C) 2012 Google, Inc.
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.
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.
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
24 #include <linux/dmi.h>
25 #include <linux/i2c.h>
26 #include <linux/i2c/atmel_mxt_ts.h>
27 #include <linux/input.h>
28 #include <linux/interrupt.h>
29 #include <linux/module.h>
30 #include <linux/platform_device.h>
32 #define ATMEL_TP_I2C_ADDR 0x4b
33 #define ATMEL_TP_I2C_BL_ADDR 0x25
34 #define ATMEL_TS_I2C_ADDR 0x4a
35 #define ATMEL_TS_I2C_BL_ADDR 0x26
36 #define CYAPA_TP_I2C_ADDR 0x67
37 #define ISL_ALS_I2C_ADDR 0x44
38 #define TAOS_ALS_I2C_ADDR 0x29
40 static struct i2c_client *als;
41 static struct i2c_client *tp;
42 static struct i2c_client *ts;
44 static const char *i2c_adapter_names[] = {
50 /* Keep this enum consistent with i2c_adapter_names */
51 enum i2c_adapter_type {
52 I2C_ADAPTER_SMBUS = 0,
57 struct i2c_peripheral {
58 int (*add)(enum i2c_adapter_type type);
59 enum i2c_adapter_type type;
62 #define MAX_I2C_PERIPHERALS 3
64 struct chromeos_laptop {
65 struct i2c_peripheral i2c_peripherals[MAX_I2C_PERIPHERALS];
68 static struct chromeos_laptop *cros_laptop;
70 static struct i2c_board_info cyapa_device = {
71 I2C_BOARD_INFO("cyapa", CYAPA_TP_I2C_ADDR),
72 .flags = I2C_CLIENT_WAKE,
75 static struct i2c_board_info isl_als_device = {
76 I2C_BOARD_INFO("isl29018", ISL_ALS_I2C_ADDR),
79 static struct i2c_board_info tsl2583_als_device = {
80 I2C_BOARD_INFO("tsl2583", TAOS_ALS_I2C_ADDR),
83 static struct i2c_board_info tsl2563_als_device = {
84 I2C_BOARD_INFO("tsl2563", TAOS_ALS_I2C_ADDR),
87 static struct mxt_platform_data atmel_224s_tp_platform_data = {
92 .blen = 0x80, /* Gain setting is in upper 4 bits */
94 .voltage = 0, /* 3.3V */
95 .orient = MXT_VERTICAL_FLIP,
96 .irqflags = IRQF_TRIGGER_FALLING,
98 .key_map = { KEY_RESERVED,
106 static struct i2c_board_info atmel_224s_tp_device = {
107 I2C_BOARD_INFO("atmel_mxt_tp", ATMEL_TP_I2C_ADDR),
108 .platform_data = &atmel_224s_tp_platform_data,
109 .flags = I2C_CLIENT_WAKE,
112 static struct mxt_platform_data atmel_1664s_platform_data = {
117 .blen = 0x89, /* Gain setting is in upper 4 bits */
119 .voltage = 0, /* 3.3V */
120 .orient = MXT_ROTATED_90_COUNTER,
121 .irqflags = IRQF_TRIGGER_FALLING,
127 static struct i2c_board_info atmel_1664s_device = {
128 I2C_BOARD_INFO("atmel_mxt_ts", ATMEL_TS_I2C_ADDR),
129 .platform_data = &atmel_1664s_platform_data,
130 .flags = I2C_CLIENT_WAKE,
133 static struct i2c_client *__add_probed_i2c_device(
136 struct i2c_board_info *info,
137 const unsigned short *addrs)
139 const struct dmi_device *dmi_dev;
140 const struct dmi_dev_onboard *dev_data;
141 struct i2c_adapter *adapter;
142 struct i2c_client *client;
147 * If a name is specified, look for irq platform information stashed
148 * in DMI_DEV_TYPE_DEV_ONBOARD by the Chrome OS custom system firmware.
151 dmi_dev = dmi_find_device(DMI_DEV_TYPE_DEV_ONBOARD, name, NULL);
153 pr_err("%s failed to dmi find device %s.\n",
158 dev_data = (struct dmi_dev_onboard *)dmi_dev->device_data;
160 pr_err("%s failed to get data from dmi for %s.\n",
164 info->irq = dev_data->instance;
167 adapter = i2c_get_adapter(bus);
169 pr_err("%s failed to get i2c adapter %d.\n", __func__, bus);
173 /* add the i2c device */
174 client = i2c_new_probed_device(adapter, info, addrs, NULL);
176 pr_err("%s failed to register device %d-%02x\n",
177 __func__, bus, info->addr);
179 pr_debug("%s added i2c device %d-%02x\n",
180 __func__, bus, info->addr);
182 i2c_put_adapter(adapter);
186 static int __find_i2c_adap(struct device *dev, void *data)
188 const char *name = data;
189 static const char *prefix = "i2c-";
190 struct i2c_adapter *adapter;
191 if (strncmp(dev_name(dev), prefix, strlen(prefix)) != 0)
193 adapter = to_i2c_adapter(dev);
194 return (strncmp(adapter->name, name, strlen(name)) == 0);
197 static int find_i2c_adapter_num(enum i2c_adapter_type type)
199 struct device *dev = NULL;
200 struct i2c_adapter *adapter;
201 const char *name = i2c_adapter_names[type];
202 /* find the adapter by name */
203 dev = bus_find_device(&i2c_bus_type, NULL, (void *)name,
206 /* Adapters may appear later. Deferred probing will retry */
207 pr_notice("%s: i2c adapter %s not found on system.\n", __func__,
211 adapter = to_i2c_adapter(dev);
216 * Takes a list of addresses in addrs as such :
217 * { addr1, ... , addrn, I2C_CLIENT_END };
218 * add_probed_i2c_device will use i2c_new_probed_device
219 * and probe for devices at all of the addresses listed.
220 * Returns NULL if no devices found.
221 * See Documentation/i2c/instantiating-devices for more information.
223 static struct i2c_client *add_probed_i2c_device(
225 enum i2c_adapter_type type,
226 struct i2c_board_info *info,
227 const unsigned short *addrs)
229 return __add_probed_i2c_device(name,
230 find_i2c_adapter_num(type),
236 * Probes for a device at a single address, the one provided by
238 * Returns NULL if no device found.
240 static struct i2c_client *add_i2c_device(const char *name,
241 enum i2c_adapter_type type,
242 struct i2c_board_info *info)
244 const unsigned short addr_list[] = { info->addr, I2C_CLIENT_END };
245 return __add_probed_i2c_device(name,
246 find_i2c_adapter_num(type),
251 static int setup_cyapa_tp(enum i2c_adapter_type type)
256 /* add cyapa touchpad */
257 tp = add_i2c_device("trackpad", type, &cyapa_device);
258 return (!tp) ? -EAGAIN : 0;
261 static int setup_atmel_224s_tp(enum i2c_adapter_type type)
263 const unsigned short addr_list[] = { ATMEL_TP_I2C_BL_ADDR,
269 /* add atmel mxt touchpad */
270 tp = add_probed_i2c_device("trackpad", type,
271 &atmel_224s_tp_device, addr_list);
272 return (!tp) ? -EAGAIN : 0;
275 static int setup_atmel_1664s_ts(enum i2c_adapter_type type)
277 const unsigned short addr_list[] = { ATMEL_TS_I2C_BL_ADDR,
283 /* add atmel mxt touch device */
284 ts = add_probed_i2c_device("touchscreen", type,
285 &atmel_1664s_device, addr_list);
286 return (!ts) ? -EAGAIN : 0;
289 static int setup_isl29018_als(enum i2c_adapter_type type)
294 /* add isl29018 light sensor */
295 als = add_i2c_device("lightsensor", type, &isl_als_device);
296 return (!als) ? -EAGAIN : 0;
299 static int setup_tsl2583_als(enum i2c_adapter_type type)
304 /* add tsl2583 light sensor */
305 als = add_i2c_device(NULL, type, &tsl2583_als_device);
306 return (!als) ? -EAGAIN : 0;
309 static int setup_tsl2563_als(enum i2c_adapter_type type)
314 /* add tsl2563 light sensor */
315 als = add_i2c_device(NULL, type, &tsl2563_als_device);
316 return (!als) ? -EAGAIN : 0;
319 static int __init chromeos_laptop_dmi_matched(const struct dmi_system_id *id)
321 cros_laptop = (void *)id->driver_data;
322 pr_debug("DMI Matched %s.\n", id->ident);
324 /* Indicate to dmi_scan that processing is done. */
328 static int chromeos_laptop_probe(struct platform_device *pdev)
333 for (i = 0; i < MAX_I2C_PERIPHERALS; i++) {
334 struct i2c_peripheral *i2c_dev;
336 i2c_dev = &cros_laptop->i2c_peripherals[i];
338 /* No more peripherals. */
339 if (i2c_dev->add == NULL)
342 /* Add the device. Set -EPROBE_DEFER on any failure */
343 if (i2c_dev->add(i2c_dev->type))
350 static struct chromeos_laptop samsung_series_5_550 = {
353 { .add = setup_cyapa_tp, I2C_ADAPTER_SMBUS },
355 { .add = setup_isl29018_als, I2C_ADAPTER_SMBUS },
359 static struct chromeos_laptop samsung_series_5 = {
362 { .add = setup_tsl2583_als, I2C_ADAPTER_SMBUS },
366 static struct chromeos_laptop chromebook_pixel = {
369 { .add = setup_atmel_1664s_ts, I2C_ADAPTER_PANEL },
371 { .add = setup_atmel_224s_tp, I2C_ADAPTER_VGADDC },
373 { .add = setup_isl29018_als, I2C_ADAPTER_PANEL },
377 static struct chromeos_laptop acer_c7_chromebook = {
380 { .add = setup_cyapa_tp, I2C_ADAPTER_SMBUS },
384 static struct chromeos_laptop acer_ac700 = {
387 { .add = setup_tsl2563_als, I2C_ADAPTER_SMBUS },
391 static struct chromeos_laptop hp_pavilion_14_chromebook = {
394 { .add = setup_cyapa_tp, I2C_ADAPTER_SMBUS },
398 static struct chromeos_laptop cr48 = {
401 { .add = setup_tsl2563_als, I2C_ADAPTER_SMBUS },
405 #define _CBDD(board_) \
406 .callback = chromeos_laptop_dmi_matched, \
407 .driver_data = (void *)&board_
409 static struct dmi_system_id chromeos_laptop_dmi_table[] __initdata = {
411 .ident = "Samsung Series 5 550",
413 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG"),
414 DMI_MATCH(DMI_PRODUCT_NAME, "Lumpy"),
416 _CBDD(samsung_series_5_550),
419 .ident = "Samsung Series 5",
421 DMI_MATCH(DMI_PRODUCT_NAME, "Alex"),
423 _CBDD(samsung_series_5),
426 .ident = "Chromebook Pixel",
428 DMI_MATCH(DMI_SYS_VENDOR, "GOOGLE"),
429 DMI_MATCH(DMI_PRODUCT_NAME, "Link"),
431 _CBDD(chromebook_pixel),
434 .ident = "Acer C7 Chromebook",
436 DMI_MATCH(DMI_PRODUCT_NAME, "Parrot"),
438 _CBDD(acer_c7_chromebook),
441 .ident = "Acer AC700",
443 DMI_MATCH(DMI_PRODUCT_NAME, "ZGB"),
448 .ident = "HP Pavilion 14 Chromebook",
450 DMI_MATCH(DMI_PRODUCT_NAME, "Butterfly"),
452 _CBDD(hp_pavilion_14_chromebook),
457 DMI_MATCH(DMI_PRODUCT_NAME, "Mario"),
463 MODULE_DEVICE_TABLE(dmi, chromeos_laptop_dmi_table);
465 static struct platform_device *cros_platform_device;
467 static struct platform_driver cros_platform_driver = {
469 .name = "chromeos_laptop",
470 .owner = THIS_MODULE,
472 .probe = chromeos_laptop_probe,
475 static int __init chromeos_laptop_init(void)
478 if (!dmi_check_system(chromeos_laptop_dmi_table)) {
479 pr_debug("%s unsupported system.\n", __func__);
483 ret = platform_driver_register(&cros_platform_driver);
487 cros_platform_device = platform_device_alloc("chromeos_laptop", -1);
488 if (!cros_platform_device) {
490 goto fail_platform_device1;
493 ret = platform_device_add(cros_platform_device);
495 goto fail_platform_device2;
499 fail_platform_device2:
500 platform_device_put(cros_platform_device);
501 fail_platform_device1:
502 platform_driver_unregister(&cros_platform_driver);
506 static void __exit chromeos_laptop_exit(void)
509 i2c_unregister_device(als);
511 i2c_unregister_device(tp);
513 i2c_unregister_device(ts);
515 platform_device_unregister(cros_platform_device);
516 platform_driver_unregister(&cros_platform_driver);
519 module_init(chromeos_laptop_init);
520 module_exit(chromeos_laptop_exit);
522 MODULE_DESCRIPTION("Chrome OS Laptop driver");
523 MODULE_AUTHOR("Benson Leung <bleung@chromium.org>");
524 MODULE_LICENSE("GPL");