Platform: x86: chromeos_laptop - Add Pixel Trackpad
[linux-2.6-block.git] / drivers / platform / x86 / chromeos_laptop.c
CommitLineData
d1381f45
BL
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
8e1ad4c4
BL
28#define ATMEL_TP_I2C_ADDR 0x4b
29#define ATMEL_TP_I2C_BL_ADDR 0x25
d1381f45
BL
30#define CYAPA_TP_I2C_ADDR 0x67
31#define ISL_ALS_I2C_ADDR 0x44
aabf3f44 32#define TAOS_ALS_I2C_ADDR 0x29
d1381f45
BL
33
34static struct i2c_client *als;
35static struct i2c_client *tp;
36
37const char *i2c_adapter_names[] = {
38 "SMBus I801 adapter",
39};
40
41/* Keep this enum consistent with i2c_adapter_names */
42enum i2c_adapter_type {
43 I2C_ADAPTER_SMBUS = 0,
44};
45
46static struct i2c_board_info __initdata cyapa_device = {
47 I2C_BOARD_INFO("cyapa", CYAPA_TP_I2C_ADDR),
48 .flags = I2C_CLIENT_WAKE,
49};
50
51static struct i2c_board_info __initdata isl_als_device = {
52 I2C_BOARD_INFO("isl29018", ISL_ALS_I2C_ADDR),
53};
54
8016bcbc
BL
55static struct i2c_board_info __initdata tsl2583_als_device = {
56 I2C_BOARD_INFO("tsl2583", TAOS_ALS_I2C_ADDR),
57};
58
aabf3f44
BL
59static struct i2c_board_info __initdata tsl2563_als_device = {
60 I2C_BOARD_INFO("tsl2563", TAOS_ALS_I2C_ADDR),
61};
62
8e1ad4c4
BL
63static struct i2c_board_info __initdata atmel_224s_tp_device = {
64 I2C_BOARD_INFO("atmel_mxt_tp", ATMEL_TP_I2C_ADDR),
65 .platform_data = NULL,
66 .flags = I2C_CLIENT_WAKE,
67};
68
d1381f45
BL
69static struct i2c_client __init *__add_probed_i2c_device(
70 const char *name,
71 int bus,
72 struct i2c_board_info *info,
73 const unsigned short *addrs)
74{
75 const struct dmi_device *dmi_dev;
76 const struct dmi_dev_onboard *dev_data;
77 struct i2c_adapter *adapter;
78 struct i2c_client *client;
79
80 if (bus < 0)
81 return NULL;
82 /*
83 * If a name is specified, look for irq platform information stashed
84 * in DMI_DEV_TYPE_DEV_ONBOARD by the Chrome OS custom system firmware.
85 */
86 if (name) {
87 dmi_dev = dmi_find_device(DMI_DEV_TYPE_DEV_ONBOARD, name, NULL);
88 if (!dmi_dev) {
89 pr_err("%s failed to dmi find device %s.\n",
90 __func__,
91 name);
92 return NULL;
93 }
94 dev_data = (struct dmi_dev_onboard *)dmi_dev->device_data;
95 if (!dev_data) {
96 pr_err("%s failed to get data from dmi for %s.\n",
97 __func__, name);
98 return NULL;
99 }
100 info->irq = dev_data->instance;
101 }
102
103 adapter = i2c_get_adapter(bus);
104 if (!adapter) {
105 pr_err("%s failed to get i2c adapter %d.\n", __func__, bus);
106 return NULL;
107 }
108
109 /* add the i2c device */
110 client = i2c_new_probed_device(adapter, info, addrs, NULL);
111 if (!client)
112 pr_err("%s failed to register device %d-%02x\n",
113 __func__, bus, info->addr);
114 else
115 pr_debug("%s added i2c device %d-%02x\n",
116 __func__, bus, info->addr);
117
118 i2c_put_adapter(adapter);
119 return client;
120}
121
122static int __init __find_i2c_adap(struct device *dev, void *data)
123{
124 const char *name = data;
125 static const char *prefix = "i2c-";
126 struct i2c_adapter *adapter;
127 if (strncmp(dev_name(dev), prefix, strlen(prefix)) != 0)
128 return 0;
129 adapter = to_i2c_adapter(dev);
130 return (strncmp(adapter->name, name, strlen(name)) == 0);
131}
132
133static int __init find_i2c_adapter_num(enum i2c_adapter_type type)
134{
135 struct device *dev = NULL;
136 struct i2c_adapter *adapter;
137 const char *name = i2c_adapter_names[type];
138 /* find the adapter by name */
139 dev = bus_find_device(&i2c_bus_type, NULL, (void *)name,
140 __find_i2c_adap);
141 if (!dev) {
142 pr_err("%s: i2c adapter %s not found on system.\n", __func__,
143 name);
144 return -ENODEV;
145 }
146 adapter = to_i2c_adapter(dev);
147 return adapter->nr;
148}
149
150/*
151 * Probes for a device at a single address, the one provided by
152 * info->addr.
153 * Returns NULL if no device found.
154 */
155static struct i2c_client __init *add_smbus_device(const char *name,
156 struct i2c_board_info *info)
157{
158 const unsigned short addr_list[] = { info->addr, I2C_CLIENT_END };
159 return __add_probed_i2c_device(name,
160 find_i2c_adapter_num(I2C_ADAPTER_SMBUS),
161 info,
162 addr_list);
163}
164
6e71094d 165static int __init setup_cyapa_smbus_tp(const struct dmi_system_id *id)
d1381f45
BL
166{
167 /* add cyapa touchpad on smbus */
168 tp = add_smbus_device("trackpad", &cyapa_device);
169 return 0;
170}
171
8e1ad4c4
BL
172static int __init setup_atmel_224s_tp(const struct dmi_system_id *id)
173{
174 const unsigned short addr_list[] = { ATMEL_TP_I2C_BL_ADDR,
175 ATMEL_TP_I2C_ADDR,
176 I2C_CLIENT_END };
177
178 /* add atmel mxt touchpad on VGA DDC GMBus */
179 tp = add_probed_i2c_device("trackpad", I2C_ADAPTER_VGADDC,
180 &atmel_224s_tp_device, addr_list);
181 return 0;
182}
183
184
d1381f45
BL
185static int __init setup_isl29018_als(const struct dmi_system_id *id)
186{
187 /* add isl29018 light sensor */
188 als = add_smbus_device("lightsensor", &isl_als_device);
189 return 0;
190}
191
8016bcbc
BL
192static int __init setup_tsl2583_als(const struct dmi_system_id *id)
193{
194 /* add tsl2583 light sensor on smbus */
195 als = add_smbus_device(NULL, &tsl2583_als_device);
196 return 0;
197}
198
aabf3f44
BL
199static int __init setup_tsl2563_als(const struct dmi_system_id *id)
200{
201 /* add tsl2563 light sensor on smbus */
202 als = add_smbus_device(NULL, &tsl2563_als_device);
203 return 0;
204}
205
d1381f45
BL
206static struct dmi_system_id __initdata chromeos_laptop_dmi_table[] = {
207 {
208 .ident = "Samsung Series 5 550 - Touchpad",
209 .matches = {
210 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG"),
211 DMI_MATCH(DMI_PRODUCT_NAME, "Lumpy"),
212 },
6e71094d 213 .callback = setup_cyapa_smbus_tp,
d1381f45 214 },
8e1ad4c4
BL
215 {
216 .ident = "Chromebook Pixel - Touchpad",
217 .matches = {
218 DMI_MATCH(DMI_SYS_VENDOR, "GOOGLE"),
219 DMI_MATCH(DMI_PRODUCT_NAME, "Link"),
220 },
221 .callback = setup_atmel_224s_tp,
222 },
d1381f45
BL
223 {
224 .ident = "Samsung Series 5 550 - Light Sensor",
225 .matches = {
226 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG"),
227 DMI_MATCH(DMI_PRODUCT_NAME, "Lumpy"),
228 },
229 .callback = setup_isl29018_als,
230 },
261f171f
BL
231 {
232 .ident = "Acer C7 Chromebook - Touchpad",
233 .matches = {
234 DMI_MATCH(DMI_PRODUCT_NAME, "Parrot"),
235 },
236 .callback = setup_cyapa_smbus_tp,
e65a624b
BL
237 },
238 {
239 .ident = "HP Pavilion 14 Chromebook - Touchpad",
240 .matches = {
241 DMI_MATCH(DMI_PRODUCT_NAME, "Butterfly"),
242 },
243 .callback = setup_cyapa_smbus_tp,
261f171f 244 },
8016bcbc
BL
245 {
246 .ident = "Samsung Series 5 - Light Sensor",
247 .matches = {
248 DMI_MATCH(DMI_PRODUCT_NAME, "Alex"),
249 },
250 .callback = setup_tsl2583_als,
251 },
aabf3f44
BL
252 {
253 .ident = "Cr-48 - Light Sensor",
254 .matches = {
255 DMI_MATCH(DMI_PRODUCT_NAME, "Mario"),
256 },
257 .callback = setup_tsl2563_als,
258 },
259 {
260 .ident = "Acer AC700 - Light Sensor",
261 .matches = {
262 DMI_MATCH(DMI_PRODUCT_NAME, "ZGB"),
263 },
264 .callback = setup_tsl2563_als,
265 },
d1381f45
BL
266 { }
267};
268MODULE_DEVICE_TABLE(dmi, chromeos_laptop_dmi_table);
269
270static int __init chromeos_laptop_init(void)
271{
272 if (!dmi_check_system(chromeos_laptop_dmi_table)) {
273 pr_debug("%s unsupported system.\n", __func__);
274 return -ENODEV;
275 }
276 return 0;
277}
278
279static void __exit chromeos_laptop_exit(void)
280{
281 if (als)
282 i2c_unregister_device(als);
283 if (tp)
284 i2c_unregister_device(tp);
285}
286
287module_init(chromeos_laptop_init);
288module_exit(chromeos_laptop_exit);
289
290MODULE_DESCRIPTION("Chrome OS Laptop driver");
291MODULE_AUTHOR("Benson Leung <bleung@chromium.org>");
292MODULE_LICENSE("GPL");