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[] = {
46 /* Keep this enum consistent with i2c_adapter_names */
47 enum i2c_adapter_type {
48 I2C_ADAPTER_SMBUS = 0,
53 static struct i2c_board_info __initdata cyapa_device = {
54 I2C_BOARD_INFO("cyapa", CYAPA_TP_I2C_ADDR),
55 .flags = I2C_CLIENT_WAKE,
58 static struct i2c_board_info __initdata isl_als_device = {
59 I2C_BOARD_INFO("isl29018", ISL_ALS_I2C_ADDR),
62 static struct i2c_board_info __initdata tsl2583_als_device = {
63 I2C_BOARD_INFO("tsl2583", TAOS_ALS_I2C_ADDR),
66 static struct i2c_board_info __initdata tsl2563_als_device = {
67 I2C_BOARD_INFO("tsl2563", TAOS_ALS_I2C_ADDR),
70 static struct i2c_board_info __initdata atmel_224s_tp_device = {
71 I2C_BOARD_INFO("atmel_mxt_tp", ATMEL_TP_I2C_ADDR),
72 .platform_data = NULL,
73 .flags = I2C_CLIENT_WAKE,
76 static struct i2c_board_info __initdata atmel_1664s_device = {
77 I2C_BOARD_INFO("atmel_mxt_ts", ATMEL_TS_I2C_ADDR),
78 .platform_data = NULL,
79 .flags = I2C_CLIENT_WAKE,
82 static struct i2c_client __init *__add_probed_i2c_device(
85 struct i2c_board_info *info,
86 const unsigned short *addrs)
88 const struct dmi_device *dmi_dev;
89 const struct dmi_dev_onboard *dev_data;
90 struct i2c_adapter *adapter;
91 struct i2c_client *client;
96 * If a name is specified, look for irq platform information stashed
97 * in DMI_DEV_TYPE_DEV_ONBOARD by the Chrome OS custom system firmware.
100 dmi_dev = dmi_find_device(DMI_DEV_TYPE_DEV_ONBOARD, name, NULL);
102 pr_err("%s failed to dmi find device %s.\n",
107 dev_data = (struct dmi_dev_onboard *)dmi_dev->device_data;
109 pr_err("%s failed to get data from dmi for %s.\n",
113 info->irq = dev_data->instance;
116 adapter = i2c_get_adapter(bus);
118 pr_err("%s failed to get i2c adapter %d.\n", __func__, bus);
122 /* add the i2c device */
123 client = i2c_new_probed_device(adapter, info, addrs, NULL);
125 pr_err("%s failed to register device %d-%02x\n",
126 __func__, bus, info->addr);
128 pr_debug("%s added i2c device %d-%02x\n",
129 __func__, bus, info->addr);
131 i2c_put_adapter(adapter);
135 static int __init __find_i2c_adap(struct device *dev, void *data)
137 const char *name = data;
138 static const char *prefix = "i2c-";
139 struct i2c_adapter *adapter;
140 if (strncmp(dev_name(dev), prefix, strlen(prefix)) != 0)
142 adapter = to_i2c_adapter(dev);
143 return (strncmp(adapter->name, name, strlen(name)) == 0);
146 static int __init find_i2c_adapter_num(enum i2c_adapter_type type)
148 struct device *dev = NULL;
149 struct i2c_adapter *adapter;
150 const char *name = i2c_adapter_names[type];
151 /* find the adapter by name */
152 dev = bus_find_device(&i2c_bus_type, NULL, (void *)name,
155 pr_err("%s: i2c adapter %s not found on system.\n", __func__,
159 adapter = to_i2c_adapter(dev);
164 * Takes a list of addresses in addrs as such :
165 * { addr1, ... , addrn, I2C_CLIENT_END };
166 * add_probed_i2c_device will use i2c_new_probed_device
167 * and probe for devices at all of the addresses listed.
168 * Returns NULL if no devices found.
169 * See Documentation/i2c/instantiating-devices for more information.
171 static __init struct i2c_client *add_probed_i2c_device(
173 enum i2c_adapter_type type,
174 struct i2c_board_info *info,
175 const unsigned short *addrs)
177 return __add_probed_i2c_device(name,
178 find_i2c_adapter_num(type),
184 * Probes for a device at a single address, the one provided by
186 * Returns NULL if no device found.
188 static __init struct i2c_client *add_i2c_device(const char *name,
189 enum i2c_adapter_type type,
190 struct i2c_board_info *info)
192 const unsigned short addr_list[] = { info->addr, I2C_CLIENT_END };
193 return __add_probed_i2c_device(name,
194 find_i2c_adapter_num(type),
200 static struct i2c_client __init *add_smbus_device(const char *name,
201 struct i2c_board_info *info)
203 return add_i2c_device(name, I2C_ADAPTER_SMBUS, info);
206 static int __init setup_cyapa_smbus_tp(const struct dmi_system_id *id)
208 /* add cyapa touchpad on smbus */
209 tp = add_smbus_device("trackpad", &cyapa_device);
213 static int __init setup_atmel_224s_tp(const struct dmi_system_id *id)
215 const unsigned short addr_list[] = { ATMEL_TP_I2C_BL_ADDR,
219 /* add atmel mxt touchpad on VGA DDC GMBus */
220 tp = add_probed_i2c_device("trackpad", I2C_ADAPTER_VGADDC,
221 &atmel_224s_tp_device, addr_list);
225 static int __init setup_atmel_1664s_ts(const struct dmi_system_id *id)
227 const unsigned short addr_list[] = { ATMEL_TS_I2C_BL_ADDR,
231 /* add atmel mxt touch device on PANEL GMBus */
232 ts = add_probed_i2c_device("touchscreen", I2C_ADAPTER_PANEL,
233 &atmel_1664s_device, addr_list);
238 static int __init setup_isl29018_als(const struct dmi_system_id *id)
240 /* add isl29018 light sensor */
241 als = add_smbus_device("lightsensor", &isl_als_device);
245 static int __init setup_isl29023_als(const struct dmi_system_id *id)
247 /* add isl29023 light sensor on Panel GMBus */
248 als = add_i2c_device("lightsensor", I2C_ADAPTER_PANEL,
253 static int __init setup_tsl2583_als(const struct dmi_system_id *id)
255 /* add tsl2583 light sensor on smbus */
256 als = add_smbus_device(NULL, &tsl2583_als_device);
260 static int __init setup_tsl2563_als(const struct dmi_system_id *id)
262 /* add tsl2563 light sensor on smbus */
263 als = add_smbus_device(NULL, &tsl2563_als_device);
267 static struct dmi_system_id __initdata chromeos_laptop_dmi_table[] = {
269 .ident = "Samsung Series 5 550 - Touchpad",
271 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG"),
272 DMI_MATCH(DMI_PRODUCT_NAME, "Lumpy"),
274 .callback = setup_cyapa_smbus_tp,
277 .ident = "Chromebook Pixel - Touchscreen",
279 DMI_MATCH(DMI_SYS_VENDOR, "GOOGLE"),
280 DMI_MATCH(DMI_PRODUCT_NAME, "Link"),
282 .callback = setup_atmel_1664s_ts,
285 .ident = "Chromebook Pixel - Touchpad",
287 DMI_MATCH(DMI_SYS_VENDOR, "GOOGLE"),
288 DMI_MATCH(DMI_PRODUCT_NAME, "Link"),
290 .callback = setup_atmel_224s_tp,
293 .ident = "Samsung Series 5 550 - Light Sensor",
295 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG"),
296 DMI_MATCH(DMI_PRODUCT_NAME, "Lumpy"),
298 .callback = setup_isl29018_als,
301 .ident = "Chromebook Pixel - Light Sensor",
303 DMI_MATCH(DMI_SYS_VENDOR, "GOOGLE"),
304 DMI_MATCH(DMI_PRODUCT_NAME, "Link"),
306 .callback = setup_isl29023_als,
309 .ident = "Acer C7 Chromebook - Touchpad",
311 DMI_MATCH(DMI_PRODUCT_NAME, "Parrot"),
313 .callback = setup_cyapa_smbus_tp,
316 .ident = "HP Pavilion 14 Chromebook - Touchpad",
318 DMI_MATCH(DMI_PRODUCT_NAME, "Butterfly"),
320 .callback = setup_cyapa_smbus_tp,
323 .ident = "Samsung Series 5 - Light Sensor",
325 DMI_MATCH(DMI_PRODUCT_NAME, "Alex"),
327 .callback = setup_tsl2583_als,
330 .ident = "Cr-48 - Light Sensor",
332 DMI_MATCH(DMI_PRODUCT_NAME, "Mario"),
334 .callback = setup_tsl2563_als,
337 .ident = "Acer AC700 - Light Sensor",
339 DMI_MATCH(DMI_PRODUCT_NAME, "ZGB"),
341 .callback = setup_tsl2563_als,
345 MODULE_DEVICE_TABLE(dmi, chromeos_laptop_dmi_table);
347 static int __init chromeos_laptop_init(void)
349 if (!dmi_check_system(chromeos_laptop_dmi_table)) {
350 pr_debug("%s unsupported system.\n", __func__);
356 static void __exit chromeos_laptop_exit(void)
359 i2c_unregister_device(als);
361 i2c_unregister_device(tp);
363 i2c_unregister_device(ts);
366 module_init(chromeos_laptop_init);
367 module_exit(chromeos_laptop_exit);
369 MODULE_DESCRIPTION("Chrome OS Laptop driver");
370 MODULE_AUTHOR("Benson Leung <bleung@chromium.org>");
371 MODULE_LICENSE("GPL");