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 int mxt_t19_keys[] = {
96 static struct mxt_platform_data atmel_224s_tp_platform_data = {
97 .irqflags = IRQF_TRIGGER_FALLING,
98 .t19_num_keys = ARRAY_SIZE(mxt_t19_keys),
99 .t19_keymap = mxt_t19_keys,
104 static struct i2c_board_info atmel_224s_tp_device = {
105 I2C_BOARD_INFO("atmel_mxt_tp", ATMEL_TP_I2C_ADDR),
106 .platform_data = &atmel_224s_tp_platform_data,
107 .flags = I2C_CLIENT_WAKE,
110 static struct mxt_platform_data atmel_1664s_platform_data = {
111 .irqflags = IRQF_TRIGGER_FALLING,
116 static struct i2c_board_info atmel_1664s_device = {
117 I2C_BOARD_INFO("atmel_mxt_ts", ATMEL_TS_I2C_ADDR),
118 .platform_data = &atmel_1664s_platform_data,
119 .flags = I2C_CLIENT_WAKE,
122 static struct i2c_client *__add_probed_i2c_device(
125 struct i2c_board_info *info,
126 const unsigned short *addrs)
128 const struct dmi_device *dmi_dev;
129 const struct dmi_dev_onboard *dev_data;
130 struct i2c_adapter *adapter;
131 struct i2c_client *client;
136 * If a name is specified, look for irq platform information stashed
137 * in DMI_DEV_TYPE_DEV_ONBOARD by the Chrome OS custom system firmware.
140 dmi_dev = dmi_find_device(DMI_DEV_TYPE_DEV_ONBOARD, name, NULL);
142 pr_err("%s failed to dmi find device %s.\n",
147 dev_data = (struct dmi_dev_onboard *)dmi_dev->device_data;
149 pr_err("%s failed to get data from dmi for %s.\n",
153 info->irq = dev_data->instance;
156 adapter = i2c_get_adapter(bus);
158 pr_err("%s failed to get i2c adapter %d.\n", __func__, bus);
162 /* add the i2c device */
163 client = i2c_new_probed_device(adapter, info, addrs, NULL);
165 pr_err("%s failed to register device %d-%02x\n",
166 __func__, bus, info->addr);
168 pr_debug("%s added i2c device %d-%02x\n",
169 __func__, bus, info->addr);
171 i2c_put_adapter(adapter);
175 static int __find_i2c_adap(struct device *dev, void *data)
177 const char *name = data;
178 static const char *prefix = "i2c-";
179 struct i2c_adapter *adapter;
180 if (strncmp(dev_name(dev), prefix, strlen(prefix)) != 0)
182 adapter = to_i2c_adapter(dev);
183 return (strncmp(adapter->name, name, strlen(name)) == 0);
186 static int find_i2c_adapter_num(enum i2c_adapter_type type)
188 struct device *dev = NULL;
189 struct i2c_adapter *adapter;
190 const char *name = i2c_adapter_names[type];
191 /* find the adapter by name */
192 dev = bus_find_device(&i2c_bus_type, NULL, (void *)name,
195 /* Adapters may appear later. Deferred probing will retry */
196 pr_notice("%s: i2c adapter %s not found on system.\n", __func__,
200 adapter = to_i2c_adapter(dev);
205 * Takes a list of addresses in addrs as such :
206 * { addr1, ... , addrn, I2C_CLIENT_END };
207 * add_probed_i2c_device will use i2c_new_probed_device
208 * and probe for devices at all of the addresses listed.
209 * Returns NULL if no devices found.
210 * See Documentation/i2c/instantiating-devices for more information.
212 static struct i2c_client *add_probed_i2c_device(
214 enum i2c_adapter_type type,
215 struct i2c_board_info *info,
216 const unsigned short *addrs)
218 return __add_probed_i2c_device(name,
219 find_i2c_adapter_num(type),
225 * Probes for a device at a single address, the one provided by
227 * Returns NULL if no device found.
229 static struct i2c_client *add_i2c_device(const char *name,
230 enum i2c_adapter_type type,
231 struct i2c_board_info *info)
233 const unsigned short addr_list[] = { info->addr, I2C_CLIENT_END };
234 return __add_probed_i2c_device(name,
235 find_i2c_adapter_num(type),
240 static int setup_cyapa_tp(enum i2c_adapter_type type)
245 /* add cyapa touchpad */
246 tp = add_i2c_device("trackpad", type, &cyapa_device);
247 return (!tp) ? -EAGAIN : 0;
250 static int setup_atmel_224s_tp(enum i2c_adapter_type type)
252 const unsigned short addr_list[] = { ATMEL_TP_I2C_BL_ADDR,
258 /* add atmel mxt touchpad */
259 tp = add_probed_i2c_device("trackpad", type,
260 &atmel_224s_tp_device, addr_list);
261 return (!tp) ? -EAGAIN : 0;
264 static int setup_atmel_1664s_ts(enum i2c_adapter_type type)
266 const unsigned short addr_list[] = { ATMEL_TS_I2C_BL_ADDR,
272 /* add atmel mxt touch device */
273 ts = add_probed_i2c_device("touchscreen", type,
274 &atmel_1664s_device, addr_list);
275 return (!ts) ? -EAGAIN : 0;
278 static int setup_isl29018_als(enum i2c_adapter_type type)
283 /* add isl29018 light sensor */
284 als = add_i2c_device("lightsensor", type, &isl_als_device);
285 return (!als) ? -EAGAIN : 0;
288 static int setup_tsl2583_als(enum i2c_adapter_type type)
293 /* add tsl2583 light sensor */
294 als = add_i2c_device(NULL, type, &tsl2583_als_device);
295 return (!als) ? -EAGAIN : 0;
298 static int setup_tsl2563_als(enum i2c_adapter_type type)
303 /* add tsl2563 light sensor */
304 als = add_i2c_device(NULL, type, &tsl2563_als_device);
305 return (!als) ? -EAGAIN : 0;
308 static int __init chromeos_laptop_dmi_matched(const struct dmi_system_id *id)
310 cros_laptop = (void *)id->driver_data;
311 pr_debug("DMI Matched %s.\n", id->ident);
313 /* Indicate to dmi_scan that processing is done. */
317 static int chromeos_laptop_probe(struct platform_device *pdev)
322 for (i = 0; i < MAX_I2C_PERIPHERALS; i++) {
323 struct i2c_peripheral *i2c_dev;
325 i2c_dev = &cros_laptop->i2c_peripherals[i];
327 /* No more peripherals. */
328 if (i2c_dev->add == NULL)
331 /* Add the device. Set -EPROBE_DEFER on any failure */
332 if (i2c_dev->add(i2c_dev->type))
339 static struct chromeos_laptop samsung_series_5_550 = {
342 { .add = setup_cyapa_tp, I2C_ADAPTER_SMBUS },
344 { .add = setup_isl29018_als, I2C_ADAPTER_SMBUS },
348 static struct chromeos_laptop samsung_series_5 = {
351 { .add = setup_tsl2583_als, I2C_ADAPTER_SMBUS },
355 static struct chromeos_laptop chromebook_pixel = {
358 { .add = setup_atmel_1664s_ts, I2C_ADAPTER_PANEL },
360 { .add = setup_atmel_224s_tp, I2C_ADAPTER_VGADDC },
362 { .add = setup_isl29018_als, I2C_ADAPTER_PANEL },
366 static struct chromeos_laptop acer_c7_chromebook = {
369 { .add = setup_cyapa_tp, I2C_ADAPTER_SMBUS },
373 static struct chromeos_laptop acer_ac700 = {
376 { .add = setup_tsl2563_als, I2C_ADAPTER_SMBUS },
380 static struct chromeos_laptop hp_pavilion_14_chromebook = {
383 { .add = setup_cyapa_tp, I2C_ADAPTER_SMBUS },
387 static struct chromeos_laptop cr48 = {
390 { .add = setup_tsl2563_als, I2C_ADAPTER_SMBUS },
394 #define _CBDD(board_) \
395 .callback = chromeos_laptop_dmi_matched, \
396 .driver_data = (void *)&board_
398 static struct dmi_system_id chromeos_laptop_dmi_table[] __initdata = {
400 .ident = "Samsung Series 5 550",
402 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG"),
403 DMI_MATCH(DMI_PRODUCT_NAME, "Lumpy"),
405 _CBDD(samsung_series_5_550),
408 .ident = "Samsung Series 5",
410 DMI_MATCH(DMI_PRODUCT_NAME, "Alex"),
412 _CBDD(samsung_series_5),
415 .ident = "Chromebook Pixel",
417 DMI_MATCH(DMI_SYS_VENDOR, "GOOGLE"),
418 DMI_MATCH(DMI_PRODUCT_NAME, "Link"),
420 _CBDD(chromebook_pixel),
423 .ident = "Acer C7 Chromebook",
425 DMI_MATCH(DMI_PRODUCT_NAME, "Parrot"),
427 _CBDD(acer_c7_chromebook),
430 .ident = "Acer AC700",
432 DMI_MATCH(DMI_PRODUCT_NAME, "ZGB"),
437 .ident = "HP Pavilion 14 Chromebook",
439 DMI_MATCH(DMI_PRODUCT_NAME, "Butterfly"),
441 _CBDD(hp_pavilion_14_chromebook),
446 DMI_MATCH(DMI_PRODUCT_NAME, "Mario"),
452 MODULE_DEVICE_TABLE(dmi, chromeos_laptop_dmi_table);
454 static struct platform_device *cros_platform_device;
456 static struct platform_driver cros_platform_driver = {
458 .name = "chromeos_laptop",
459 .owner = THIS_MODULE,
461 .probe = chromeos_laptop_probe,
464 static int __init chromeos_laptop_init(void)
467 if (!dmi_check_system(chromeos_laptop_dmi_table)) {
468 pr_debug("%s unsupported system.\n", __func__);
472 ret = platform_driver_register(&cros_platform_driver);
476 cros_platform_device = platform_device_alloc("chromeos_laptop", -1);
477 if (!cros_platform_device) {
479 goto fail_platform_device1;
482 ret = platform_device_add(cros_platform_device);
484 goto fail_platform_device2;
488 fail_platform_device2:
489 platform_device_put(cros_platform_device);
490 fail_platform_device1:
491 platform_driver_unregister(&cros_platform_driver);
495 static void __exit chromeos_laptop_exit(void)
498 i2c_unregister_device(als);
500 i2c_unregister_device(tp);
502 i2c_unregister_device(ts);
504 platform_device_unregister(cros_platform_device);
505 platform_driver_unregister(&cros_platform_driver);
508 module_init(chromeos_laptop_init);
509 module_exit(chromeos_laptop_exit);
511 MODULE_DESCRIPTION("Chrome OS Laptop driver");
512 MODULE_AUTHOR("Benson Leung <bleung@chromium.org>");
513 MODULE_LICENSE("GPL");