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/module.h>
28 #define ATMEL_TP_I2C_ADDR 0x4b
29 #define ATMEL_TP_I2C_BL_ADDR 0x25
30 #define ATMEL_TS_I2C_ADDR 0x4a
31 #define ATMEL_TS_I2C_BL_ADDR 0x26
32 #define CYAPA_TP_I2C_ADDR 0x67
33 #define ISL_ALS_I2C_ADDR 0x44
34 #define TAOS_ALS_I2C_ADDR 0x29
36 static struct i2c_client *als;
37 static struct i2c_client *tp;
38 static struct i2c_client *ts;
40 const char *i2c_adapter_names[] = {
44 /* Keep this enum consistent with i2c_adapter_names */
45 enum i2c_adapter_type {
46 I2C_ADAPTER_SMBUS = 0,
49 static struct i2c_board_info __initdata cyapa_device = {
50 I2C_BOARD_INFO("cyapa", CYAPA_TP_I2C_ADDR),
51 .flags = I2C_CLIENT_WAKE,
54 static struct i2c_board_info __initdata isl_als_device = {
55 I2C_BOARD_INFO("isl29018", ISL_ALS_I2C_ADDR),
58 static struct i2c_board_info __initdata tsl2583_als_device = {
59 I2C_BOARD_INFO("tsl2583", TAOS_ALS_I2C_ADDR),
62 static struct i2c_board_info __initdata tsl2563_als_device = {
63 I2C_BOARD_INFO("tsl2563", TAOS_ALS_I2C_ADDR),
66 static struct i2c_board_info __initdata atmel_224s_tp_device = {
67 I2C_BOARD_INFO("atmel_mxt_tp", ATMEL_TP_I2C_ADDR),
68 .platform_data = NULL,
69 .flags = I2C_CLIENT_WAKE,
72 static struct i2c_board_info __initdata atmel_1664s_device = {
73 I2C_BOARD_INFO("atmel_mxt_ts", ATMEL_TS_I2C_ADDR),
74 .platform_data = NULL,
75 .flags = I2C_CLIENT_WAKE,
78 static struct i2c_client __init *__add_probed_i2c_device(
81 struct i2c_board_info *info,
82 const unsigned short *addrs)
84 const struct dmi_device *dmi_dev;
85 const struct dmi_dev_onboard *dev_data;
86 struct i2c_adapter *adapter;
87 struct i2c_client *client;
92 * If a name is specified, look for irq platform information stashed
93 * in DMI_DEV_TYPE_DEV_ONBOARD by the Chrome OS custom system firmware.
96 dmi_dev = dmi_find_device(DMI_DEV_TYPE_DEV_ONBOARD, name, NULL);
98 pr_err("%s failed to dmi find device %s.\n",
103 dev_data = (struct dmi_dev_onboard *)dmi_dev->device_data;
105 pr_err("%s failed to get data from dmi for %s.\n",
109 info->irq = dev_data->instance;
112 adapter = i2c_get_adapter(bus);
114 pr_err("%s failed to get i2c adapter %d.\n", __func__, bus);
118 /* add the i2c device */
119 client = i2c_new_probed_device(adapter, info, addrs, NULL);
121 pr_err("%s failed to register device %d-%02x\n",
122 __func__, bus, info->addr);
124 pr_debug("%s added i2c device %d-%02x\n",
125 __func__, bus, info->addr);
127 i2c_put_adapter(adapter);
131 static int __init __find_i2c_adap(struct device *dev, void *data)
133 const char *name = data;
134 static const char *prefix = "i2c-";
135 struct i2c_adapter *adapter;
136 if (strncmp(dev_name(dev), prefix, strlen(prefix)) != 0)
138 adapter = to_i2c_adapter(dev);
139 return (strncmp(adapter->name, name, strlen(name)) == 0);
142 static int __init find_i2c_adapter_num(enum i2c_adapter_type type)
144 struct device *dev = NULL;
145 struct i2c_adapter *adapter;
146 const char *name = i2c_adapter_names[type];
147 /* find the adapter by name */
148 dev = bus_find_device(&i2c_bus_type, NULL, (void *)name,
151 pr_err("%s: i2c adapter %s not found on system.\n", __func__,
155 adapter = to_i2c_adapter(dev);
160 * Takes a list of addresses in addrs as such :
161 * { addr1, ... , addrn, I2C_CLIENT_END };
162 * add_probed_i2c_device will use i2c_new_probed_device
163 * and probe for devices at all of the addresses listed.
164 * Returns NULL if no devices found.
165 * See Documentation/i2c/instantiating-devices for more information.
167 static __init struct i2c_client *add_probed_i2c_device(
169 enum i2c_adapter_type type,
170 struct i2c_board_info *info,
171 const unsigned short *addrs)
173 return __add_probed_i2c_device(name,
174 find_i2c_adapter_num(type),
180 * Probes for a device at a single address, the one provided by
182 * Returns NULL if no device found.
184 static __init struct i2c_client *add_i2c_device(const char *name,
185 enum i2c_adapter_type type,
186 struct i2c_board_info *info)
188 const unsigned short addr_list[] = { info->addr, I2C_CLIENT_END };
189 return __add_probed_i2c_device(name,
190 find_i2c_adapter_num(type),
196 static struct i2c_client __init *add_smbus_device(const char *name,
197 struct i2c_board_info *info)
199 return add_i2c_device(name, I2C_ADAPTER_SMBUS, info);
202 static int __init setup_cyapa_smbus_tp(const struct dmi_system_id *id)
204 /* add cyapa touchpad on smbus */
205 tp = add_smbus_device("trackpad", &cyapa_device);
209 static int __init setup_atmel_224s_tp(const struct dmi_system_id *id)
211 const unsigned short addr_list[] = { ATMEL_TP_I2C_BL_ADDR,
215 /* add atmel mxt touchpad on VGA DDC GMBus */
216 tp = add_probed_i2c_device("trackpad", I2C_ADAPTER_VGADDC,
217 &atmel_224s_tp_device, addr_list);
221 static int __init setup_atmel_1664s_ts(const struct dmi_system_id *id)
223 const unsigned short addr_list[] = { ATMEL_TS_I2C_BL_ADDR,
227 /* add atmel mxt touch device on PANEL GMBus */
228 ts = add_probed_i2c_device("touchscreen", I2C_ADAPTER_PANEL,
229 &atmel_1664s_device, addr_list);
234 static int __init setup_isl29018_als(const struct dmi_system_id *id)
236 /* add isl29018 light sensor */
237 als = add_smbus_device("lightsensor", &isl_als_device);
241 static int __init setup_isl29023_als(const struct dmi_system_id *id)
243 /* add isl29023 light sensor on Panel GMBus */
244 als = add_i2c_device("lightsensor", I2C_ADAPTER_PANEL,
249 static int __init setup_tsl2583_als(const struct dmi_system_id *id)
251 /* add tsl2583 light sensor on smbus */
252 als = add_smbus_device(NULL, &tsl2583_als_device);
256 static int __init setup_tsl2563_als(const struct dmi_system_id *id)
258 /* add tsl2563 light sensor on smbus */
259 als = add_smbus_device(NULL, &tsl2563_als_device);
263 static struct dmi_system_id __initdata chromeos_laptop_dmi_table[] = {
265 .ident = "Samsung Series 5 550 - Touchpad",
267 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG"),
268 DMI_MATCH(DMI_PRODUCT_NAME, "Lumpy"),
270 .callback = setup_cyapa_smbus_tp,
273 .ident = "Chromebook Pixel - Touchscreen",
275 DMI_MATCH(DMI_SYS_VENDOR, "GOOGLE"),
276 DMI_MATCH(DMI_PRODUCT_NAME, "Link"),
278 .callback = setup_atmel_1664s_ts,
281 .ident = "Chromebook Pixel - Touchpad",
283 DMI_MATCH(DMI_SYS_VENDOR, "GOOGLE"),
284 DMI_MATCH(DMI_PRODUCT_NAME, "Link"),
286 .callback = setup_atmel_224s_tp,
289 .ident = "Samsung Series 5 550 - Light Sensor",
291 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG"),
292 DMI_MATCH(DMI_PRODUCT_NAME, "Lumpy"),
294 .callback = setup_isl29018_als,
297 .ident = "Chromebook Pixel - Light Sensor",
299 DMI_MATCH(DMI_SYS_VENDOR, "GOOGLE"),
300 DMI_MATCH(DMI_PRODUCT_NAME, "Link"),
302 .callback = setup_isl29023_als,
305 .ident = "Acer C7 Chromebook - Touchpad",
307 DMI_MATCH(DMI_PRODUCT_NAME, "Parrot"),
309 .callback = setup_cyapa_smbus_tp,
312 .ident = "HP Pavilion 14 Chromebook - Touchpad",
314 DMI_MATCH(DMI_PRODUCT_NAME, "Butterfly"),
316 .callback = setup_cyapa_smbus_tp,
319 .ident = "Samsung Series 5 - Light Sensor",
321 DMI_MATCH(DMI_PRODUCT_NAME, "Alex"),
323 .callback = setup_tsl2583_als,
326 .ident = "Cr-48 - Light Sensor",
328 DMI_MATCH(DMI_PRODUCT_NAME, "Mario"),
330 .callback = setup_tsl2563_als,
333 .ident = "Acer AC700 - Light Sensor",
335 DMI_MATCH(DMI_PRODUCT_NAME, "ZGB"),
337 .callback = setup_tsl2563_als,
341 MODULE_DEVICE_TABLE(dmi, chromeos_laptop_dmi_table);
343 static int __init chromeos_laptop_init(void)
345 if (!dmi_check_system(chromeos_laptop_dmi_table)) {
346 pr_debug("%s unsupported system.\n", __func__);
352 static void __exit chromeos_laptop_exit(void)
355 i2c_unregister_device(als);
357 i2c_unregister_device(tp);
359 i2c_unregister_device(ts);
362 module_init(chromeos_laptop_init);
363 module_exit(chromeos_laptop_exit);
365 MODULE_DESCRIPTION("Chrome OS Laptop driver");
366 MODULE_AUTHOR("Benson Leung <bleung@chromium.org>");
367 MODULE_LICENSE("GPL");