]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/platform/x86/chromeos_laptop.c
Merge remote-tracking branch 'asoc/fix/wm8350' into tmp
[karo-tx-linux.git] / drivers / platform / x86 / chromeos_laptop.c
1 /*
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
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
35
36 static struct i2c_client *als;
37 static struct i2c_client *tp;
38 static struct i2c_client *ts;
39
40 const char *i2c_adapter_names[] = {
41         "SMBus I801 adapter",
42         "i915 gmbus vga",
43         "i915 gmbus panel",
44 };
45
46 /* Keep this enum consistent with i2c_adapter_names */
47 enum i2c_adapter_type {
48         I2C_ADAPTER_SMBUS = 0,
49         I2C_ADAPTER_VGADDC,
50         I2C_ADAPTER_PANEL,
51 };
52
53 static struct i2c_board_info __initdata cyapa_device = {
54         I2C_BOARD_INFO("cyapa", CYAPA_TP_I2C_ADDR),
55         .flags          = I2C_CLIENT_WAKE,
56 };
57
58 static struct i2c_board_info __initdata isl_als_device = {
59         I2C_BOARD_INFO("isl29018", ISL_ALS_I2C_ADDR),
60 };
61
62 static struct i2c_board_info __initdata tsl2583_als_device = {
63         I2C_BOARD_INFO("tsl2583", TAOS_ALS_I2C_ADDR),
64 };
65
66 static struct i2c_board_info __initdata tsl2563_als_device = {
67         I2C_BOARD_INFO("tsl2563", TAOS_ALS_I2C_ADDR),
68 };
69
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,
74 };
75
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,
80 };
81
82 static 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
135 static 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
146 static 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 /*
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.
170  */
171 static __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 /*
184  * Probes for a device at a single address, the one provided by
185  * info->addr.
186  * Returns NULL if no device found.
187  */
188 static __init struct i2c_client *add_i2c_device(const char *name,
189                                                 enum i2c_adapter_type type,
190                                                 struct i2c_board_info *info)
191 {
192         const unsigned short addr_list[] = { info->addr, I2C_CLIENT_END };
193         return __add_probed_i2c_device(name,
194                                        find_i2c_adapter_num(type),
195                                        info,
196                                        addr_list);
197 }
198
199
200 static 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
206 static int __init setup_cyapa_smbus_tp(const struct dmi_system_id *id)
207 {
208         /* add cyapa touchpad on smbus */
209         tp = add_smbus_device("trackpad", &cyapa_device);
210         return 0;
211 }
212
213 static 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
225 static 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
237
238 static 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
245 static 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
253 static 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
260 static 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
267 static 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                 },
274                 .callback = setup_cyapa_smbus_tp,
275         },
276         {
277                 .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         {
285                 .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         {
293                 .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         },
300         {
301                 .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         {
309                 .ident = "Acer C7 Chromebook - Touchpad",
310                 .matches = {
311                         DMI_MATCH(DMI_PRODUCT_NAME, "Parrot"),
312                 },
313                 .callback = setup_cyapa_smbus_tp,
314         },
315         {
316                 .ident = "HP Pavilion 14 Chromebook - Touchpad",
317                 .matches = {
318                         DMI_MATCH(DMI_PRODUCT_NAME, "Butterfly"),
319                 },
320                 .callback = setup_cyapa_smbus_tp,
321         },
322         {
323                 .ident = "Samsung Series 5 - Light Sensor",
324                 .matches = {
325                         DMI_MATCH(DMI_PRODUCT_NAME, "Alex"),
326                 },
327                 .callback = setup_tsl2583_als,
328         },
329         {
330                 .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         },
343         { }
344 };
345 MODULE_DEVICE_TABLE(dmi, chromeos_laptop_dmi_table);
346
347 static 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
356 static void __exit chromeos_laptop_exit(void)
357 {
358         if (als)
359                 i2c_unregister_device(als);
360         if (tp)
361                 i2c_unregister_device(tp);
362         if (ts)
363                 i2c_unregister_device(ts);
364 }
365
366 module_init(chromeos_laptop_init);
367 module_exit(chromeos_laptop_exit);
368
369 MODULE_DESCRIPTION("Chrome OS Laptop driver");
370 MODULE_AUTHOR("Benson Leung <bleung@chromium.org>");
371 MODULE_LICENSE("GPL");