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>
31 #define ATMEL_TP_I2C_ADDR 0x4b
32 #define ATMEL_TP_I2C_BL_ADDR 0x25
33 #define ATMEL_TS_I2C_ADDR 0x4a
34 #define ATMEL_TS_I2C_BL_ADDR 0x26
35 #define CYAPA_TP_I2C_ADDR 0x67
36 #define ISL_ALS_I2C_ADDR 0x44
37 #define TAOS_ALS_I2C_ADDR 0x29
39 static struct i2c_client *als;
40 static struct i2c_client *tp;
41 static struct i2c_client *ts;
43 const char *i2c_adapter_names[] = {
49 /* Keep this enum consistent with i2c_adapter_names */
50 enum i2c_adapter_type {
51 I2C_ADAPTER_SMBUS = 0,
56 struct i2c_peripheral {
57 void (*add)(enum i2c_adapter_type type);
58 enum i2c_adapter_type type;
61 #define MAX_I2C_PERIPHERALS 3
63 struct chromeos_laptop {
64 struct i2c_peripheral i2c_peripherals[MAX_I2C_PERIPHERALS];
67 static struct i2c_board_info __initdata cyapa_device = {
68 I2C_BOARD_INFO("cyapa", CYAPA_TP_I2C_ADDR),
69 .flags = I2C_CLIENT_WAKE,
72 static struct i2c_board_info __initdata isl_als_device = {
73 I2C_BOARD_INFO("isl29018", ISL_ALS_I2C_ADDR),
76 static struct i2c_board_info __initdata tsl2583_als_device = {
77 I2C_BOARD_INFO("tsl2583", TAOS_ALS_I2C_ADDR),
80 static struct i2c_board_info __initdata tsl2563_als_device = {
81 I2C_BOARD_INFO("tsl2563", TAOS_ALS_I2C_ADDR),
84 static struct mxt_platform_data atmel_224s_tp_platform_data = {
89 .blen = 0x80, /* Gain setting is in upper 4 bits */
91 .voltage = 0, /* 3.3V */
92 .orient = MXT_VERTICAL_FLIP,
93 .irqflags = IRQF_TRIGGER_FALLING,
95 .key_map = { KEY_RESERVED,
103 static struct i2c_board_info __initdata atmel_224s_tp_device = {
104 I2C_BOARD_INFO("atmel_mxt_tp", ATMEL_TP_I2C_ADDR),
105 .platform_data = &atmel_224s_tp_platform_data,
106 .flags = I2C_CLIENT_WAKE,
109 static struct mxt_platform_data atmel_1664s_platform_data = {
114 .blen = 0x89, /* Gain setting is in upper 4 bits */
116 .voltage = 0, /* 3.3V */
117 .orient = MXT_ROTATED_90_COUNTER,
118 .irqflags = IRQF_TRIGGER_FALLING,
124 static struct i2c_board_info __initdata atmel_1664s_device = {
125 I2C_BOARD_INFO("atmel_mxt_ts", ATMEL_TS_I2C_ADDR),
126 .platform_data = &atmel_1664s_platform_data,
127 .flags = I2C_CLIENT_WAKE,
130 static struct i2c_client __init *__add_probed_i2c_device(
133 struct i2c_board_info *info,
134 const unsigned short *addrs)
136 const struct dmi_device *dmi_dev;
137 const struct dmi_dev_onboard *dev_data;
138 struct i2c_adapter *adapter;
139 struct i2c_client *client;
144 * If a name is specified, look for irq platform information stashed
145 * in DMI_DEV_TYPE_DEV_ONBOARD by the Chrome OS custom system firmware.
148 dmi_dev = dmi_find_device(DMI_DEV_TYPE_DEV_ONBOARD, name, NULL);
150 pr_err("%s failed to dmi find device %s.\n",
155 dev_data = (struct dmi_dev_onboard *)dmi_dev->device_data;
157 pr_err("%s failed to get data from dmi for %s.\n",
161 info->irq = dev_data->instance;
164 adapter = i2c_get_adapter(bus);
166 pr_err("%s failed to get i2c adapter %d.\n", __func__, bus);
170 /* add the i2c device */
171 client = i2c_new_probed_device(adapter, info, addrs, NULL);
173 pr_err("%s failed to register device %d-%02x\n",
174 __func__, bus, info->addr);
176 pr_debug("%s added i2c device %d-%02x\n",
177 __func__, bus, info->addr);
179 i2c_put_adapter(adapter);
183 static int __init __find_i2c_adap(struct device *dev, void *data)
185 const char *name = data;
186 static const char *prefix = "i2c-";
187 struct i2c_adapter *adapter;
188 if (strncmp(dev_name(dev), prefix, strlen(prefix)) != 0)
190 adapter = to_i2c_adapter(dev);
191 return (strncmp(adapter->name, name, strlen(name)) == 0);
194 static int __init find_i2c_adapter_num(enum i2c_adapter_type type)
196 struct device *dev = NULL;
197 struct i2c_adapter *adapter;
198 const char *name = i2c_adapter_names[type];
199 /* find the adapter by name */
200 dev = bus_find_device(&i2c_bus_type, NULL, (void *)name,
203 pr_err("%s: i2c adapter %s not found on system.\n", __func__,
207 adapter = to_i2c_adapter(dev);
212 * Takes a list of addresses in addrs as such :
213 * { addr1, ... , addrn, I2C_CLIENT_END };
214 * add_probed_i2c_device will use i2c_new_probed_device
215 * and probe for devices at all of the addresses listed.
216 * Returns NULL if no devices found.
217 * See Documentation/i2c/instantiating-devices for more information.
219 static __init struct i2c_client *add_probed_i2c_device(
221 enum i2c_adapter_type type,
222 struct i2c_board_info *info,
223 const unsigned short *addrs)
225 return __add_probed_i2c_device(name,
226 find_i2c_adapter_num(type),
232 * Probes for a device at a single address, the one provided by
234 * Returns NULL if no device found.
236 static __init struct i2c_client *add_i2c_device(const char *name,
237 enum i2c_adapter_type type,
238 struct i2c_board_info *info)
240 const unsigned short addr_list[] = { info->addr, I2C_CLIENT_END };
241 return __add_probed_i2c_device(name,
242 find_i2c_adapter_num(type),
247 static int __init setup_cyapa_tp(enum i2c_adapter_type type)
249 /* add cyapa touchpad */
250 tp = add_i2c_device("trackpad", type, &cyapa_device);
254 static int __init setup_atmel_224s_tp(enum i2c_adapter_type type)
256 const unsigned short addr_list[] = { ATMEL_TP_I2C_BL_ADDR,
260 /* add atmel mxt touchpad */
261 tp = add_probed_i2c_device("trackpad", type,
262 &atmel_224s_tp_device, addr_list);
266 static int __init setup_atmel_1664s_ts(enum i2c_adapter_type type)
268 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);
278 static int __init setup_isl29018_als(enum i2c_adapter_type type)
280 /* add isl29018 light sensor */
281 als = add_i2c_device("lightsensor", type, &isl_als_device);
285 static int __init setup_tsl2583_als(enum i2c_adapter_type type)
287 /* add tsl2583 light sensor */
288 als = add_i2c_device(NULL, type, &tsl2583_als_device);
292 static int __init setup_tsl2563_als(enum i2c_adapter_type type)
294 /* add tsl2563 light sensor */
295 als = add_i2c_device(NULL, type, &tsl2563_als_device);
300 chromeos_laptop_add_peripherals(const struct dmi_system_id *id)
303 struct chromeos_laptop *cros_laptop = (void *)id->driver_data;
305 pr_debug("Adding peripherals for %s.\n", id->ident);
307 for (i = 0; i < MAX_I2C_PERIPHERALS; i++) {
308 struct i2c_peripheral *i2c_dev;
310 i2c_dev = &cros_laptop->i2c_peripherals[i];
312 /* No more peripherals. */
313 if (i2c_dev->add == NULL)
316 /* Add the device. */
317 i2c_dev->add(i2c_dev->type);
320 /* Indicate to dmi_scan that processing is done. */
324 static struct chromeos_laptop samsung_series_5_550 __initdata = {
327 { .add = setup_cyapa_tp, I2C_ADAPTER_SMBUS },
329 { .add = setup_isl29018_als, I2C_ADAPTER_SMBUS },
333 static struct chromeos_laptop samsung_series_5 __initdata = {
336 { .add = setup_tsl2583_als, I2C_ADAPTER_SMBUS },
340 static struct chromeos_laptop chromebook_pixel __initdata = {
343 { .add = setup_atmel_1664s_ts, I2C_ADAPTER_PANEL },
345 { .add = setup_atmel_224s_tp, I2C_ADAPTER_VGADDC },
347 { .add = setup_isl29018_als, I2C_ADAPTER_PANEL },
351 static struct chromeos_laptop acer_c7_chromebook __initdata = {
354 { .add = setup_cyapa_tp, I2C_ADAPTER_SMBUS },
358 static struct chromeos_laptop acer_ac700 __initdata = {
361 { .add = setup_tsl2563_als, I2C_ADAPTER_SMBUS },
365 static struct chromeos_laptop hp_pavilion_14_chromebook __initdata = {
368 { .add = setup_cyapa_tp, I2C_ADAPTER_SMBUS },
372 static struct chromeos_laptop cr48 __initdata = {
375 { .add = setup_tsl2563_als, I2C_ADAPTER_SMBUS },
379 #define _CBDD(board_) \
380 .callback = &chromeos_laptop_add_peripherals, \
381 .driver_data = (void *)&board_
383 static struct dmi_system_id __initdata chromeos_laptop_dmi_table[] = {
385 .ident = "Samsung Series 5 550",
387 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG"),
388 DMI_MATCH(DMI_PRODUCT_NAME, "Lumpy"),
390 _CBDD(samsung_series_5_550),
393 .ident = "Samsung Series 5",
395 DMI_MATCH(DMI_PRODUCT_NAME, "Alex"),
397 _CBDD(samsung_series_5),
400 .ident = "Chromebook Pixel",
402 DMI_MATCH(DMI_SYS_VENDOR, "GOOGLE"),
403 DMI_MATCH(DMI_PRODUCT_NAME, "Link"),
405 _CBDD(chromebook_pixel),
408 .ident = "Acer C7 Chromebook",
410 DMI_MATCH(DMI_PRODUCT_NAME, "Parrot"),
412 _CBDD(acer_c7_chromebook),
415 .ident = "Acer AC700",
417 DMI_MATCH(DMI_PRODUCT_NAME, "ZGB"),
422 .ident = "HP Pavilion 14 Chromebook",
424 DMI_MATCH(DMI_PRODUCT_NAME, "Butterfly"),
426 _CBDD(hp_pavilion_14_chromebook),
431 DMI_MATCH(DMI_PRODUCT_NAME, "Mario"),
437 MODULE_DEVICE_TABLE(dmi, chromeos_laptop_dmi_table);
439 static int __init chromeos_laptop_init(void)
441 if (!dmi_check_system(chromeos_laptop_dmi_table)) {
442 pr_debug("%s unsupported system.\n", __func__);
448 static void __exit chromeos_laptop_exit(void)
451 i2c_unregister_device(als);
453 i2c_unregister_device(tp);
455 i2c_unregister_device(ts);
458 module_init(chromeos_laptop_init);
459 module_exit(chromeos_laptop_exit);
461 MODULE_DESCRIPTION("Chrome OS Laptop driver");
462 MODULE_AUTHOR("Benson Leung <bleung@chromium.org>");
463 MODULE_LICENSE("GPL");