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 static struct i2c_board_info __initdata cyapa_device = {
57 I2C_BOARD_INFO("cyapa", CYAPA_TP_I2C_ADDR),
58 .flags = I2C_CLIENT_WAKE,
61 static struct i2c_board_info __initdata isl_als_device = {
62 I2C_BOARD_INFO("isl29018", ISL_ALS_I2C_ADDR),
65 static struct i2c_board_info __initdata tsl2583_als_device = {
66 I2C_BOARD_INFO("tsl2583", TAOS_ALS_I2C_ADDR),
69 static struct i2c_board_info __initdata tsl2563_als_device = {
70 I2C_BOARD_INFO("tsl2563", TAOS_ALS_I2C_ADDR),
73 static struct mxt_platform_data atmel_224s_tp_platform_data = {
78 .blen = 0x80, /* Gain setting is in upper 4 bits */
80 .voltage = 0, /* 3.3V */
81 .orient = MXT_VERTICAL_FLIP,
82 .irqflags = IRQF_TRIGGER_FALLING,
84 .key_map = { KEY_RESERVED,
92 static struct i2c_board_info __initdata atmel_224s_tp_device = {
93 I2C_BOARD_INFO("atmel_mxt_tp", ATMEL_TP_I2C_ADDR),
94 .platform_data = &atmel_224s_tp_platform_data,
95 .flags = I2C_CLIENT_WAKE,
98 static struct mxt_platform_data atmel_1664s_platform_data = {
103 .blen = 0x89, /* Gain setting is in upper 4 bits */
105 .voltage = 0, /* 3.3V */
106 .orient = MXT_ROTATED_90_COUNTER,
107 .irqflags = IRQF_TRIGGER_FALLING,
113 static struct i2c_board_info __initdata atmel_1664s_device = {
114 I2C_BOARD_INFO("atmel_mxt_ts", ATMEL_TS_I2C_ADDR),
115 .platform_data = &atmel_1664s_platform_data,
116 .flags = I2C_CLIENT_WAKE,
119 static struct i2c_client __init *__add_probed_i2c_device(
122 struct i2c_board_info *info,
123 const unsigned short *addrs)
125 const struct dmi_device *dmi_dev;
126 const struct dmi_dev_onboard *dev_data;
127 struct i2c_adapter *adapter;
128 struct i2c_client *client;
133 * If a name is specified, look for irq platform information stashed
134 * in DMI_DEV_TYPE_DEV_ONBOARD by the Chrome OS custom system firmware.
137 dmi_dev = dmi_find_device(DMI_DEV_TYPE_DEV_ONBOARD, name, NULL);
139 pr_err("%s failed to dmi find device %s.\n",
144 dev_data = (struct dmi_dev_onboard *)dmi_dev->device_data;
146 pr_err("%s failed to get data from dmi for %s.\n",
150 info->irq = dev_data->instance;
153 adapter = i2c_get_adapter(bus);
155 pr_err("%s failed to get i2c adapter %d.\n", __func__, bus);
159 /* add the i2c device */
160 client = i2c_new_probed_device(adapter, info, addrs, NULL);
162 pr_err("%s failed to register device %d-%02x\n",
163 __func__, bus, info->addr);
165 pr_debug("%s added i2c device %d-%02x\n",
166 __func__, bus, info->addr);
168 i2c_put_adapter(adapter);
172 static int __init __find_i2c_adap(struct device *dev, void *data)
174 const char *name = data;
175 static const char *prefix = "i2c-";
176 struct i2c_adapter *adapter;
177 if (strncmp(dev_name(dev), prefix, strlen(prefix)) != 0)
179 adapter = to_i2c_adapter(dev);
180 return (strncmp(adapter->name, name, strlen(name)) == 0);
183 static int __init find_i2c_adapter_num(enum i2c_adapter_type type)
185 struct device *dev = NULL;
186 struct i2c_adapter *adapter;
187 const char *name = i2c_adapter_names[type];
188 /* find the adapter by name */
189 dev = bus_find_device(&i2c_bus_type, NULL, (void *)name,
192 pr_err("%s: i2c adapter %s not found on system.\n", __func__,
196 adapter = to_i2c_adapter(dev);
201 * Takes a list of addresses in addrs as such :
202 * { addr1, ... , addrn, I2C_CLIENT_END };
203 * add_probed_i2c_device will use i2c_new_probed_device
204 * and probe for devices at all of the addresses listed.
205 * Returns NULL if no devices found.
206 * See Documentation/i2c/instantiating-devices for more information.
208 static __init struct i2c_client *add_probed_i2c_device(
210 enum i2c_adapter_type type,
211 struct i2c_board_info *info,
212 const unsigned short *addrs)
214 return __add_probed_i2c_device(name,
215 find_i2c_adapter_num(type),
221 * Probes for a device at a single address, the one provided by
223 * Returns NULL if no device found.
225 static __init struct i2c_client *add_i2c_device(const char *name,
226 enum i2c_adapter_type type,
227 struct i2c_board_info *info)
229 const unsigned short addr_list[] = { info->addr, I2C_CLIENT_END };
230 return __add_probed_i2c_device(name,
231 find_i2c_adapter_num(type),
237 static struct i2c_client __init *add_smbus_device(const char *name,
238 struct i2c_board_info *info)
240 return add_i2c_device(name, I2C_ADAPTER_SMBUS, info);
243 static int __init setup_cyapa_smbus_tp(const struct dmi_system_id *id)
245 /* add cyapa touchpad on smbus */
246 tp = add_smbus_device("trackpad", &cyapa_device);
250 static int __init setup_atmel_224s_tp(const struct dmi_system_id *id)
252 const unsigned short addr_list[] = { ATMEL_TP_I2C_BL_ADDR,
256 /* add atmel mxt touchpad on VGA DDC GMBus */
257 tp = add_probed_i2c_device("trackpad", I2C_ADAPTER_VGADDC,
258 &atmel_224s_tp_device, addr_list);
262 static int __init setup_atmel_1664s_ts(const struct dmi_system_id *id)
264 const unsigned short addr_list[] = { ATMEL_TS_I2C_BL_ADDR,
268 /* add atmel mxt touch device on PANEL GMBus */
269 ts = add_probed_i2c_device("touchscreen", I2C_ADAPTER_PANEL,
270 &atmel_1664s_device, addr_list);
275 static int __init setup_isl29018_als(const struct dmi_system_id *id)
277 /* add isl29018 light sensor */
278 als = add_smbus_device("lightsensor", &isl_als_device);
282 static int __init setup_isl29023_als(const struct dmi_system_id *id)
284 /* add isl29023 light sensor on Panel GMBus */
285 als = add_i2c_device("lightsensor", I2C_ADAPTER_PANEL,
290 static int __init setup_tsl2583_als(const struct dmi_system_id *id)
292 /* add tsl2583 light sensor on smbus */
293 als = add_smbus_device(NULL, &tsl2583_als_device);
297 static int __init setup_tsl2563_als(const struct dmi_system_id *id)
299 /* add tsl2563 light sensor on smbus */
300 als = add_smbus_device(NULL, &tsl2563_als_device);
304 static struct dmi_system_id __initdata chromeos_laptop_dmi_table[] = {
306 .ident = "Samsung Series 5 550 - Touchpad",
308 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG"),
309 DMI_MATCH(DMI_PRODUCT_NAME, "Lumpy"),
311 .callback = setup_cyapa_smbus_tp,
314 .ident = "Chromebook Pixel - Touchscreen",
316 DMI_MATCH(DMI_SYS_VENDOR, "GOOGLE"),
317 DMI_MATCH(DMI_PRODUCT_NAME, "Link"),
319 .callback = setup_atmel_1664s_ts,
322 .ident = "Chromebook Pixel - Touchpad",
324 DMI_MATCH(DMI_SYS_VENDOR, "GOOGLE"),
325 DMI_MATCH(DMI_PRODUCT_NAME, "Link"),
327 .callback = setup_atmel_224s_tp,
330 .ident = "Samsung Series 5 550 - Light Sensor",
332 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG"),
333 DMI_MATCH(DMI_PRODUCT_NAME, "Lumpy"),
335 .callback = setup_isl29018_als,
338 .ident = "Chromebook Pixel - Light Sensor",
340 DMI_MATCH(DMI_SYS_VENDOR, "GOOGLE"),
341 DMI_MATCH(DMI_PRODUCT_NAME, "Link"),
343 .callback = setup_isl29023_als,
346 .ident = "Acer C7 Chromebook - Touchpad",
348 DMI_MATCH(DMI_PRODUCT_NAME, "Parrot"),
350 .callback = setup_cyapa_smbus_tp,
353 .ident = "HP Pavilion 14 Chromebook - Touchpad",
355 DMI_MATCH(DMI_PRODUCT_NAME, "Butterfly"),
357 .callback = setup_cyapa_smbus_tp,
360 .ident = "Samsung Series 5 - Light Sensor",
362 DMI_MATCH(DMI_PRODUCT_NAME, "Alex"),
364 .callback = setup_tsl2583_als,
367 .ident = "Cr-48 - Light Sensor",
369 DMI_MATCH(DMI_PRODUCT_NAME, "Mario"),
371 .callback = setup_tsl2563_als,
374 .ident = "Acer AC700 - Light Sensor",
376 DMI_MATCH(DMI_PRODUCT_NAME, "ZGB"),
378 .callback = setup_tsl2563_als,
382 MODULE_DEVICE_TABLE(dmi, chromeos_laptop_dmi_table);
384 static int __init chromeos_laptop_init(void)
386 if (!dmi_check_system(chromeos_laptop_dmi_table)) {
387 pr_debug("%s unsupported system.\n", __func__);
393 static void __exit chromeos_laptop_exit(void)
396 i2c_unregister_device(als);
398 i2c_unregister_device(tp);
400 i2c_unregister_device(ts);
403 module_init(chromeos_laptop_init);
404 module_exit(chromeos_laptop_exit);
406 MODULE_DESCRIPTION("Chrome OS Laptop driver");
407 MODULE_AUTHOR("Benson Leung <bleung@chromium.org>");
408 MODULE_LICENSE("GPL");