blob: 93d66809355a203e97b0e4229f5dc2ac932d2e54 [file] [log] [blame]
Benson Leungd1381f42012-10-25 14:21:21 -07001/*
2 * chromeos_laptop.c - Driver to instantiate Chromebook i2c/smbus devices.
3 *
4 * Author : Benson Leung <bleung@chromium.org>
5 *
6 * Copyright (C) 2012 Google, Inc.
7 *
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.
12 *
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.
17 *
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
21 *
22 */
23
24#include <linux/dmi.h>
25#include <linux/i2c.h>
26#include <linux/module.h>
27
Benson Leung8e1ad4c2013-02-21 12:14:59 -080028#define ATMEL_TP_I2C_ADDR 0x4b
29#define ATMEL_TP_I2C_BL_ADDR 0x25
Yufeng Shen33a84f82013-02-21 12:15:00 -080030#define ATMEL_TS_I2C_ADDR 0x4a
31#define ATMEL_TS_I2C_BL_ADDR 0x26
Benson Leungd1381f42012-10-25 14:21:21 -070032#define CYAPA_TP_I2C_ADDR 0x67
33#define ISL_ALS_I2C_ADDR 0x44
Benson Leungaabf3f42013-02-01 14:34:45 -080034#define TAOS_ALS_I2C_ADDR 0x29
Benson Leungd1381f42012-10-25 14:21:21 -070035
36static struct i2c_client *als;
37static struct i2c_client *tp;
Yufeng Shen33a84f82013-02-21 12:15:00 -080038static struct i2c_client *ts;
Benson Leungd1381f42012-10-25 14:21:21 -070039
40const char *i2c_adapter_names[] = {
41 "SMBus I801 adapter",
Benson Leung741bf0c2013-02-21 12:14:55 -080042 "i915 gmbus vga",
43 "i915 gmbus panel",
Benson Leungd1381f42012-10-25 14:21:21 -070044};
45
46/* Keep this enum consistent with i2c_adapter_names */
47enum i2c_adapter_type {
48 I2C_ADAPTER_SMBUS = 0,
Benson Leung741bf0c2013-02-21 12:14:55 -080049 I2C_ADAPTER_VGADDC,
50 I2C_ADAPTER_PANEL,
Benson Leungd1381f42012-10-25 14:21:21 -070051};
52
53static struct i2c_board_info __initdata cyapa_device = {
54 I2C_BOARD_INFO("cyapa", CYAPA_TP_I2C_ADDR),
55 .flags = I2C_CLIENT_WAKE,
56};
57
58static struct i2c_board_info __initdata isl_als_device = {
59 I2C_BOARD_INFO("isl29018", ISL_ALS_I2C_ADDR),
60};
61
Benson Leung8016bcb2013-02-01 14:34:46 -080062static struct i2c_board_info __initdata tsl2583_als_device = {
63 I2C_BOARD_INFO("tsl2583", TAOS_ALS_I2C_ADDR),
64};
65
Benson Leungaabf3f42013-02-01 14:34:45 -080066static struct i2c_board_info __initdata tsl2563_als_device = {
67 I2C_BOARD_INFO("tsl2563", TAOS_ALS_I2C_ADDR),
68};
69
Benson Leung8e1ad4c2013-02-21 12:14:59 -080070static 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,
74};
75
Yufeng Shen33a84f82013-02-21 12:15:00 -080076static 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,
80};
81
Benson Leungd1381f42012-10-25 14:21:21 -070082static struct i2c_client __init *__add_probed_i2c_device(
83 const char *name,
84 int bus,
85 struct i2c_board_info *info,
86 const unsigned short *addrs)
87{
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;
92
93 if (bus < 0)
94 return NULL;
95 /*
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.
98 */
99 if (name) {
100 dmi_dev = dmi_find_device(DMI_DEV_TYPE_DEV_ONBOARD, name, NULL);
101 if (!dmi_dev) {
102 pr_err("%s failed to dmi find device %s.\n",
103 __func__,
104 name);
105 return NULL;
106 }
107 dev_data = (struct dmi_dev_onboard *)dmi_dev->device_data;
108 if (!dev_data) {
109 pr_err("%s failed to get data from dmi for %s.\n",
110 __func__, name);
111 return NULL;
112 }
113 info->irq = dev_data->instance;
114 }
115
116 adapter = i2c_get_adapter(bus);
117 if (!adapter) {
118 pr_err("%s failed to get i2c adapter %d.\n", __func__, bus);
119 return NULL;
120 }
121
122 /* add the i2c device */
123 client = i2c_new_probed_device(adapter, info, addrs, NULL);
124 if (!client)
125 pr_err("%s failed to register device %d-%02x\n",
126 __func__, bus, info->addr);
127 else
128 pr_debug("%s added i2c device %d-%02x\n",
129 __func__, bus, info->addr);
130
131 i2c_put_adapter(adapter);
132 return client;
133}
134
135static int __init __find_i2c_adap(struct device *dev, void *data)
136{
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)
141 return 0;
142 adapter = to_i2c_adapter(dev);
143 return (strncmp(adapter->name, name, strlen(name)) == 0);
144}
145
146static int __init find_i2c_adapter_num(enum i2c_adapter_type type)
147{
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,
153 __find_i2c_adap);
154 if (!dev) {
155 pr_err("%s: i2c adapter %s not found on system.\n", __func__,
156 name);
157 return -ENODEV;
158 }
159 adapter = to_i2c_adapter(dev);
160 return adapter->nr;
161}
162
163/*
Benson Leungbcaf0892013-02-21 12:14:58 -0800164 * 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.
170 */
171static __init struct i2c_client *add_probed_i2c_device(
172 const char *name,
173 enum i2c_adapter_type type,
174 struct i2c_board_info *info,
175 const unsigned short *addrs)
176{
177 return __add_probed_i2c_device(name,
178 find_i2c_adapter_num(type),
179 info,
180 addrs);
181}
182
183/*
Benson Leungd1381f42012-10-25 14:21:21 -0700184 * Probes for a device at a single address, the one provided by
185 * info->addr.
186 * Returns NULL if no device found.
187 */
Benson Leunge7b28842013-02-21 12:14:56 -0800188static __init struct i2c_client *add_i2c_device(const char *name,
189 enum i2c_adapter_type type,
190 struct i2c_board_info *info)
Benson Leungd1381f42012-10-25 14:21:21 -0700191{
192 const unsigned short addr_list[] = { info->addr, I2C_CLIENT_END };
193 return __add_probed_i2c_device(name,
Benson Leunge7b28842013-02-21 12:14:56 -0800194 find_i2c_adapter_num(type),
Benson Leungd1381f42012-10-25 14:21:21 -0700195 info,
196 addr_list);
197}
198
Benson Leunge7b28842013-02-21 12:14:56 -0800199
200static struct i2c_client __init *add_smbus_device(const char *name,
201 struct i2c_board_info *info)
202{
203 return add_i2c_device(name, I2C_ADAPTER_SMBUS, info);
204}
205
Benson Leung6e710942013-02-01 14:34:43 -0800206static int __init setup_cyapa_smbus_tp(const struct dmi_system_id *id)
Benson Leungd1381f42012-10-25 14:21:21 -0700207{
208 /* add cyapa touchpad on smbus */
209 tp = add_smbus_device("trackpad", &cyapa_device);
210 return 0;
211}
212
Benson Leung8e1ad4c2013-02-21 12:14:59 -0800213static int __init setup_atmel_224s_tp(const struct dmi_system_id *id)
214{
215 const unsigned short addr_list[] = { ATMEL_TP_I2C_BL_ADDR,
216 ATMEL_TP_I2C_ADDR,
217 I2C_CLIENT_END };
218
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);
222 return 0;
223}
224
Yufeng Shen33a84f82013-02-21 12:15:00 -0800225static int __init setup_atmel_1664s_ts(const struct dmi_system_id *id)
226{
227 const unsigned short addr_list[] = { ATMEL_TS_I2C_BL_ADDR,
228 ATMEL_TS_I2C_ADDR,
229 I2C_CLIENT_END };
230
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);
234 return 0;
235}
236
Benson Leung8e1ad4c2013-02-21 12:14:59 -0800237
Benson Leungd1381f42012-10-25 14:21:21 -0700238static int __init setup_isl29018_als(const struct dmi_system_id *id)
239{
240 /* add isl29018 light sensor */
241 als = add_smbus_device("lightsensor", &isl_als_device);
242 return 0;
243}
244
Benson Leungcc5c3982013-02-21 12:14:57 -0800245static int __init setup_isl29023_als(const struct dmi_system_id *id)
246{
247 /* add isl29023 light sensor on Panel GMBus */
248 als = add_i2c_device("lightsensor", I2C_ADAPTER_PANEL,
249 &isl_als_device);
250 return 0;
251}
252
Benson Leung8016bcb2013-02-01 14:34:46 -0800253static int __init setup_tsl2583_als(const struct dmi_system_id *id)
254{
255 /* add tsl2583 light sensor on smbus */
256 als = add_smbus_device(NULL, &tsl2583_als_device);
257 return 0;
258}
259
Benson Leungaabf3f42013-02-01 14:34:45 -0800260static int __init setup_tsl2563_als(const struct dmi_system_id *id)
261{
262 /* add tsl2563 light sensor on smbus */
263 als = add_smbus_device(NULL, &tsl2563_als_device);
264 return 0;
265}
266
Benson Leungd1381f42012-10-25 14:21:21 -0700267static struct dmi_system_id __initdata chromeos_laptop_dmi_table[] = {
268 {
269 .ident = "Samsung Series 5 550 - Touchpad",
270 .matches = {
271 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG"),
272 DMI_MATCH(DMI_PRODUCT_NAME, "Lumpy"),
273 },
Benson Leung6e710942013-02-01 14:34:43 -0800274 .callback = setup_cyapa_smbus_tp,
Benson Leungd1381f42012-10-25 14:21:21 -0700275 },
276 {
Yufeng Shen33a84f82013-02-21 12:15:00 -0800277 .ident = "Chromebook Pixel - Touchscreen",
278 .matches = {
279 DMI_MATCH(DMI_SYS_VENDOR, "GOOGLE"),
280 DMI_MATCH(DMI_PRODUCT_NAME, "Link"),
281 },
282 .callback = setup_atmel_1664s_ts,
283 },
284 {
Benson Leung8e1ad4c2013-02-21 12:14:59 -0800285 .ident = "Chromebook Pixel - Touchpad",
286 .matches = {
287 DMI_MATCH(DMI_SYS_VENDOR, "GOOGLE"),
288 DMI_MATCH(DMI_PRODUCT_NAME, "Link"),
289 },
290 .callback = setup_atmel_224s_tp,
291 },
292 {
Benson Leungd1381f42012-10-25 14:21:21 -0700293 .ident = "Samsung Series 5 550 - Light Sensor",
294 .matches = {
295 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG"),
296 DMI_MATCH(DMI_PRODUCT_NAME, "Lumpy"),
297 },
298 .callback = setup_isl29018_als,
299 },
Benson Leung261f1712013-02-01 14:34:44 -0800300 {
Benson Leungcc5c3982013-02-21 12:14:57 -0800301 .ident = "Chromebook Pixel - Light Sensor",
302 .matches = {
303 DMI_MATCH(DMI_SYS_VENDOR, "GOOGLE"),
304 DMI_MATCH(DMI_PRODUCT_NAME, "Link"),
305 },
306 .callback = setup_isl29023_als,
307 },
308 {
Benson Leung261f1712013-02-01 14:34:44 -0800309 .ident = "Acer C7 Chromebook - Touchpad",
310 .matches = {
311 DMI_MATCH(DMI_PRODUCT_NAME, "Parrot"),
312 },
313 .callback = setup_cyapa_smbus_tp,
314 },
Benson Leungaabf3f42013-02-01 14:34:45 -0800315 {
Benson Leunge65a6242013-02-10 16:20:17 -0800316 .ident = "HP Pavilion 14 Chromebook - Touchpad",
317 .matches = {
318 DMI_MATCH(DMI_PRODUCT_NAME, "Butterfly"),
319 },
320 .callback = setup_cyapa_smbus_tp,
321 },
322 {
Benson Leung8016bcb2013-02-01 14:34:46 -0800323 .ident = "Samsung Series 5 - Light Sensor",
324 .matches = {
325 DMI_MATCH(DMI_PRODUCT_NAME, "Alex"),
326 },
327 .callback = setup_tsl2583_als,
328 },
329 {
Benson Leungaabf3f42013-02-01 14:34:45 -0800330 .ident = "Cr-48 - Light Sensor",
331 .matches = {
332 DMI_MATCH(DMI_PRODUCT_NAME, "Mario"),
333 },
334 .callback = setup_tsl2563_als,
335 },
336 {
337 .ident = "Acer AC700 - Light Sensor",
338 .matches = {
339 DMI_MATCH(DMI_PRODUCT_NAME, "ZGB"),
340 },
341 .callback = setup_tsl2563_als,
342 },
Benson Leungd1381f42012-10-25 14:21:21 -0700343 { }
344};
345MODULE_DEVICE_TABLE(dmi, chromeos_laptop_dmi_table);
346
347static int __init chromeos_laptop_init(void)
348{
349 if (!dmi_check_system(chromeos_laptop_dmi_table)) {
350 pr_debug("%s unsupported system.\n", __func__);
351 return -ENODEV;
352 }
353 return 0;
354}
355
356static void __exit chromeos_laptop_exit(void)
357{
358 if (als)
359 i2c_unregister_device(als);
360 if (tp)
361 i2c_unregister_device(tp);
Yufeng Shen33a84f82013-02-21 12:15:00 -0800362 if (ts)
363 i2c_unregister_device(ts);
Benson Leungd1381f42012-10-25 14:21:21 -0700364}
365
366module_init(chromeos_laptop_init);
367module_exit(chromeos_laptop_exit);
368
369MODULE_DESCRIPTION("Chrome OS Laptop driver");
370MODULE_AUTHOR("Benson Leung <bleung@chromium.org>");
371MODULE_LICENSE("GPL");