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 struct i2c_client __init
*add_smbus_device(const char *name
,
185 struct i2c_board_info
*info
)
187 const unsigned short addr_list
[] = { info
->addr
, I2C_CLIENT_END
};
188 return __add_probed_i2c_device(name
,
189 find_i2c_adapter_num(I2C_ADAPTER_SMBUS
),
194 static int __init
setup_cyapa_smbus_tp(const struct dmi_system_id
*id
)
196 /* add cyapa touchpad on smbus */
197 tp
= add_smbus_device("trackpad", &cyapa_device
);
201 static int __init
setup_atmel_224s_tp(const struct dmi_system_id
*id
)
203 const unsigned short addr_list
[] = { ATMEL_TP_I2C_BL_ADDR
,
207 /* add atmel mxt touchpad on VGA DDC GMBus */
208 tp
= add_probed_i2c_device("trackpad", I2C_ADAPTER_VGADDC
,
209 &atmel_224s_tp_device
, addr_list
);
213 static int __init
setup_atmel_1664s_ts(const struct dmi_system_id
*id
)
215 const unsigned short addr_list
[] = { ATMEL_TS_I2C_BL_ADDR
,
219 /* add atmel mxt touch device on PANEL GMBus */
220 ts
= add_probed_i2c_device("touchscreen", I2C_ADAPTER_PANEL
,
221 &atmel_1664s_device
, addr_list
);
226 static int __init
setup_isl29018_als(const struct dmi_system_id
*id
)
228 /* add isl29018 light sensor */
229 als
= add_smbus_device("lightsensor", &isl_als_device
);
233 static int __init
setup_tsl2583_als(const struct dmi_system_id
*id
)
235 /* add tsl2583 light sensor on smbus */
236 als
= add_smbus_device(NULL
, &tsl2583_als_device
);
240 static int __init
setup_tsl2563_als(const struct dmi_system_id
*id
)
242 /* add tsl2563 light sensor on smbus */
243 als
= add_smbus_device(NULL
, &tsl2563_als_device
);
247 static struct dmi_system_id __initdata chromeos_laptop_dmi_table
[] = {
249 .ident
= "Samsung Series 5 550 - Touchpad",
251 DMI_MATCH(DMI_SYS_VENDOR
, "SAMSUNG"),
252 DMI_MATCH(DMI_PRODUCT_NAME
, "Lumpy"),
254 .callback
= setup_cyapa_smbus_tp
,
257 .ident
= "Chromebook Pixel - Touchscreen",
259 DMI_MATCH(DMI_SYS_VENDOR
, "GOOGLE"),
260 DMI_MATCH(DMI_PRODUCT_NAME
, "Link"),
262 .callback
= setup_atmel_1664s_ts
,
265 .ident
= "Chromebook Pixel - Touchpad",
267 DMI_MATCH(DMI_SYS_VENDOR
, "GOOGLE"),
268 DMI_MATCH(DMI_PRODUCT_NAME
, "Link"),
270 .callback
= setup_atmel_224s_tp
,
273 .ident
= "Samsung Series 5 550 - Light Sensor",
275 DMI_MATCH(DMI_SYS_VENDOR
, "SAMSUNG"),
276 DMI_MATCH(DMI_PRODUCT_NAME
, "Lumpy"),
278 .callback
= setup_isl29018_als
,
281 .ident
= "Acer C7 Chromebook - Touchpad",
283 DMI_MATCH(DMI_PRODUCT_NAME
, "Parrot"),
285 .callback
= setup_cyapa_smbus_tp
,
288 .ident
= "HP Pavilion 14 Chromebook - Touchpad",
290 DMI_MATCH(DMI_PRODUCT_NAME
, "Butterfly"),
292 .callback
= setup_cyapa_smbus_tp
,
295 .ident
= "Samsung Series 5 - Light Sensor",
297 DMI_MATCH(DMI_PRODUCT_NAME
, "Alex"),
299 .callback
= setup_tsl2583_als
,
302 .ident
= "Cr-48 - Light Sensor",
304 DMI_MATCH(DMI_PRODUCT_NAME
, "Mario"),
306 .callback
= setup_tsl2563_als
,
309 .ident
= "Acer AC700 - Light Sensor",
311 DMI_MATCH(DMI_PRODUCT_NAME
, "ZGB"),
313 .callback
= setup_tsl2563_als
,
317 MODULE_DEVICE_TABLE(dmi
, chromeos_laptop_dmi_table
);
319 static int __init
chromeos_laptop_init(void)
321 if (!dmi_check_system(chromeos_laptop_dmi_table
)) {
322 pr_debug("%s unsupported system.\n", __func__
);
328 static void __exit
chromeos_laptop_exit(void)
331 i2c_unregister_device(als
);
333 i2c_unregister_device(tp
);
335 i2c_unregister_device(ts
);
338 module_init(chromeos_laptop_init
);
339 module_exit(chromeos_laptop_exit
);
341 MODULE_DESCRIPTION("Chrome OS Laptop driver");
342 MODULE_AUTHOR("Benson Leung <bleung@chromium.org>");
343 MODULE_LICENSE("GPL");