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 = {
90 .orient = MXT_VERTICAL_FLIP,
91 .irqflags = IRQF_TRIGGER_FALLING,
93 .key_map = { KEY_RESERVED,
101 static struct i2c_board_info atmel_224s_tp_device = {
102 I2C_BOARD_INFO("atmel_mxt_tp", ATMEL_TP_I2C_ADDR),
103 .platform_data = &atmel_224s_tp_platform_data,
104 .flags = I2C_CLIENT_WAKE,
107 static struct mxt_platform_data atmel_1664s_platform_data = {
110 .orient = MXT_ROTATED_90_COUNTER,
111 .irqflags = IRQF_TRIGGER_FALLING,
117 static struct i2c_board_info atmel_1664s_device = {
118 I2C_BOARD_INFO("atmel_mxt_ts", ATMEL_TS_I2C_ADDR),
119 .platform_data = &atmel_1664s_platform_data,
120 .flags = I2C_CLIENT_WAKE,
123 static struct i2c_client *__add_probed_i2c_device(
126 struct i2c_board_info *info,
127 const unsigned short *addrs)
129 const struct dmi_device *dmi_dev;
130 const struct dmi_dev_onboard *dev_data;
131 struct i2c_adapter *adapter;
132 struct i2c_client *client;
137 * If a name is specified, look for irq platform information stashed
138 * in DMI_DEV_TYPE_DEV_ONBOARD by the Chrome OS custom system firmware.
141 dmi_dev = dmi_find_device(DMI_DEV_TYPE_DEV_ONBOARD, name, NULL);
143 pr_err("%s failed to dmi find device %s.\n",
148 dev_data = (struct dmi_dev_onboard *)dmi_dev->device_data;
150 pr_err("%s failed to get data from dmi for %s.\n",
154 info->irq = dev_data->instance;
157 adapter = i2c_get_adapter(bus);
159 pr_err("%s failed to get i2c adapter %d.\n", __func__, bus);
163 /* add the i2c device */
164 client = i2c_new_probed_device(adapter, info, addrs, NULL);
166 pr_err("%s failed to register device %d-%02x\n",
167 __func__, bus, info->addr);
169 pr_debug("%s added i2c device %d-%02x\n",
170 __func__, bus, info->addr);
172 i2c_put_adapter(adapter);
176 static int __find_i2c_adap(struct device *dev, void *data)
178 const char *name = data;
179 static const char *prefix = "i2c-";
180 struct i2c_adapter *adapter;
181 if (strncmp(dev_name(dev), prefix, strlen(prefix)) != 0)
183 adapter = to_i2c_adapter(dev);
184 return (strncmp(adapter->name, name, strlen(name)) == 0);
187 static int find_i2c_adapter_num(enum i2c_adapter_type type)
189 struct device *dev = NULL;
190 struct i2c_adapter *adapter;
191 const char *name = i2c_adapter_names[type];
192 /* find the adapter by name */
193 dev = bus_find_device(&i2c_bus_type, NULL, (void *)name,
196 /* Adapters may appear later. Deferred probing will retry */
197 pr_notice("%s: i2c adapter %s not found on system.\n", __func__,
201 adapter = to_i2c_adapter(dev);
206 * Takes a list of addresses in addrs as such :
207 * { addr1, ... , addrn, I2C_CLIENT_END };
208 * add_probed_i2c_device will use i2c_new_probed_device
209 * and probe for devices at all of the addresses listed.
210 * Returns NULL if no devices found.
211 * See Documentation/i2c/instantiating-devices for more information.
213 static struct i2c_client *add_probed_i2c_device(
215 enum i2c_adapter_type type,
216 struct i2c_board_info *info,
217 const unsigned short *addrs)
219 return __add_probed_i2c_device(name,
220 find_i2c_adapter_num(type),
226 * Probes for a device at a single address, the one provided by
228 * Returns NULL if no device found.
230 static struct i2c_client *add_i2c_device(const char *name,
231 enum i2c_adapter_type type,
232 struct i2c_board_info *info)
234 const unsigned short addr_list[] = { info->addr, I2C_CLIENT_END };
235 return __add_probed_i2c_device(name,
236 find_i2c_adapter_num(type),
241 static int setup_cyapa_tp(enum i2c_adapter_type type)
246 /* add cyapa touchpad */
247 tp = add_i2c_device("trackpad", type, &cyapa_device);
248 return (!tp) ? -EAGAIN : 0;
251 static int setup_atmel_224s_tp(enum i2c_adapter_type type)
253 const unsigned short addr_list[] = { ATMEL_TP_I2C_BL_ADDR,
259 /* add atmel mxt touchpad */
260 tp = add_probed_i2c_device("trackpad", type,
261 &atmel_224s_tp_device, addr_list);
262 return (!tp) ? -EAGAIN : 0;
265 static int setup_atmel_1664s_ts(enum i2c_adapter_type type)
267 const unsigned short addr_list[] = { ATMEL_TS_I2C_BL_ADDR,
273 /* add atmel mxt touch device */
274 ts = add_probed_i2c_device("touchscreen", type,
275 &atmel_1664s_device, addr_list);
276 return (!ts) ? -EAGAIN : 0;
279 static int setup_isl29018_als(enum i2c_adapter_type type)
284 /* add isl29018 light sensor */
285 als = add_i2c_device("lightsensor", type, &isl_als_device);
286 return (!als) ? -EAGAIN : 0;
289 static int setup_tsl2583_als(enum i2c_adapter_type type)
294 /* add tsl2583 light sensor */
295 als = add_i2c_device(NULL, type, &tsl2583_als_device);
296 return (!als) ? -EAGAIN : 0;
299 static int setup_tsl2563_als(enum i2c_adapter_type type)
304 /* add tsl2563 light sensor */
305 als = add_i2c_device(NULL, type, &tsl2563_als_device);
306 return (!als) ? -EAGAIN : 0;
309 static int __init chromeos_laptop_dmi_matched(const struct dmi_system_id *id)
311 cros_laptop = (void *)id->driver_data;
312 pr_debug("DMI Matched %s.\n", id->ident);
314 /* Indicate to dmi_scan that processing is done. */
318 static int chromeos_laptop_probe(struct platform_device *pdev)
323 for (i = 0; i < MAX_I2C_PERIPHERALS; i++) {
324 struct i2c_peripheral *i2c_dev;
326 i2c_dev = &cros_laptop->i2c_peripherals[i];
328 /* No more peripherals. */
329 if (i2c_dev->add == NULL)
332 /* Add the device. Set -EPROBE_DEFER on any failure */
333 if (i2c_dev->add(i2c_dev->type))
340 static struct chromeos_laptop samsung_series_5_550 = {
343 { .add = setup_cyapa_tp, I2C_ADAPTER_SMBUS },
345 { .add = setup_isl29018_als, I2C_ADAPTER_SMBUS },
349 static struct chromeos_laptop samsung_series_5 = {
352 { .add = setup_tsl2583_als, I2C_ADAPTER_SMBUS },
356 static struct chromeos_laptop chromebook_pixel = {
359 { .add = setup_atmel_1664s_ts, I2C_ADAPTER_PANEL },
361 { .add = setup_atmel_224s_tp, I2C_ADAPTER_VGADDC },
363 { .add = setup_isl29018_als, I2C_ADAPTER_PANEL },
367 static struct chromeos_laptop acer_c7_chromebook = {
370 { .add = setup_cyapa_tp, I2C_ADAPTER_SMBUS },
374 static struct chromeos_laptop acer_ac700 = {
377 { .add = setup_tsl2563_als, I2C_ADAPTER_SMBUS },
381 static struct chromeos_laptop hp_pavilion_14_chromebook = {
384 { .add = setup_cyapa_tp, I2C_ADAPTER_SMBUS },
388 static struct chromeos_laptop cr48 = {
391 { .add = setup_tsl2563_als, I2C_ADAPTER_SMBUS },
395 #define _CBDD(board_) \
396 .callback = chromeos_laptop_dmi_matched, \
397 .driver_data = (void *)&board_
399 static struct dmi_system_id chromeos_laptop_dmi_table[] __initdata = {
401 .ident = "Samsung Series 5 550",
403 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG"),
404 DMI_MATCH(DMI_PRODUCT_NAME, "Lumpy"),
406 _CBDD(samsung_series_5_550),
409 .ident = "Samsung Series 5",
411 DMI_MATCH(DMI_PRODUCT_NAME, "Alex"),
413 _CBDD(samsung_series_5),
416 .ident = "Chromebook Pixel",
418 DMI_MATCH(DMI_SYS_VENDOR, "GOOGLE"),
419 DMI_MATCH(DMI_PRODUCT_NAME, "Link"),
421 _CBDD(chromebook_pixel),
424 .ident = "Acer C7 Chromebook",
426 DMI_MATCH(DMI_PRODUCT_NAME, "Parrot"),
428 _CBDD(acer_c7_chromebook),
431 .ident = "Acer AC700",
433 DMI_MATCH(DMI_PRODUCT_NAME, "ZGB"),
438 .ident = "HP Pavilion 14 Chromebook",
440 DMI_MATCH(DMI_PRODUCT_NAME, "Butterfly"),
442 _CBDD(hp_pavilion_14_chromebook),
447 DMI_MATCH(DMI_PRODUCT_NAME, "Mario"),
453 MODULE_DEVICE_TABLE(dmi, chromeos_laptop_dmi_table);
455 static struct platform_device *cros_platform_device;
457 static struct platform_driver cros_platform_driver = {
459 .name = "chromeos_laptop",
460 .owner = THIS_MODULE,
462 .probe = chromeos_laptop_probe,
465 static int __init chromeos_laptop_init(void)
468 if (!dmi_check_system(chromeos_laptop_dmi_table)) {
469 pr_debug("%s unsupported system.\n", __func__);
473 ret = platform_driver_register(&cros_platform_driver);
477 cros_platform_device = platform_device_alloc("chromeos_laptop", -1);
478 if (!cros_platform_device) {
480 goto fail_platform_device1;
483 ret = platform_device_add(cros_platform_device);
485 goto fail_platform_device2;
489 fail_platform_device2:
490 platform_device_put(cros_platform_device);
491 fail_platform_device1:
492 platform_driver_unregister(&cros_platform_driver);
496 static void __exit chromeos_laptop_exit(void)
499 i2c_unregister_device(als);
501 i2c_unregister_device(tp);
503 i2c_unregister_device(ts);
505 platform_device_unregister(cros_platform_device);
506 platform_driver_unregister(&cros_platform_driver);
509 module_init(chromeos_laptop_init);
510 module_exit(chromeos_laptop_exit);
512 MODULE_DESCRIPTION("Chrome OS Laptop driver");
513 MODULE_AUTHOR("Benson Leung <bleung@chromium.org>");
514 MODULE_LICENSE("GPL");