blob: a241e5fa6c8383303b0a7751b759746bd5f17d74 [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>
Benson Leung2ef39202013-03-07 19:43:34 -080026#include <linux/i2c/atmel_mxt_ts.h>
27#include <linux/input.h>
28#include <linux/interrupt.h>
Benson Leungd1381f42012-10-25 14:21:21 -070029#include <linux/module.h>
Benson Leung9ad36922013-10-20 20:58:25 -070030#include <linux/platform_device.h>
Benson Leungd1381f42012-10-25 14:21:21 -070031
Benson Leung8e1ad4c2013-02-21 12:14:59 -080032#define ATMEL_TP_I2C_ADDR 0x4b
33#define ATMEL_TP_I2C_BL_ADDR 0x25
Yufeng Shen33a84f82013-02-21 12:15:00 -080034#define ATMEL_TS_I2C_ADDR 0x4a
35#define ATMEL_TS_I2C_BL_ADDR 0x26
Benson Leungd1381f42012-10-25 14:21:21 -070036#define CYAPA_TP_I2C_ADDR 0x67
37#define ISL_ALS_I2C_ADDR 0x44
Benson Leungaabf3f42013-02-01 14:34:45 -080038#define TAOS_ALS_I2C_ADDR 0x29
Benson Leungd1381f42012-10-25 14:21:21 -070039
40static struct i2c_client *als;
41static struct i2c_client *tp;
Yufeng Shen33a84f82013-02-21 12:15:00 -080042static struct i2c_client *ts;
Benson Leungd1381f42012-10-25 14:21:21 -070043
Olof Johansson6d3c1af2013-11-25 13:10:25 -080044static const char *i2c_adapter_names[] = {
Benson Leungd1381f42012-10-25 14:21:21 -070045 "SMBus I801 adapter",
Benson Leung741bf0c2013-02-21 12:14:55 -080046 "i915 gmbus vga",
47 "i915 gmbus panel",
Mika Westerbergda3b0ab2014-06-17 14:02:00 -070048 "i2c-designware-pci",
49 "i2c-designware-pci",
Benson Leungd1381f42012-10-25 14:21:21 -070050};
51
52/* Keep this enum consistent with i2c_adapter_names */
53enum i2c_adapter_type {
54 I2C_ADAPTER_SMBUS = 0,
Benson Leung741bf0c2013-02-21 12:14:55 -080055 I2C_ADAPTER_VGADDC,
56 I2C_ADAPTER_PANEL,
Mika Westerbergda3b0ab2014-06-17 14:02:00 -070057 I2C_ADAPTER_DESIGNWARE_0,
58 I2C_ADAPTER_DESIGNWARE_1,
Benson Leungd1381f42012-10-25 14:21:21 -070059};
60
Aaron Durbinec199dd2013-10-20 20:58:24 -070061struct i2c_peripheral {
Benson Leung9ad36922013-10-20 20:58:25 -070062 int (*add)(enum i2c_adapter_type type);
Aaron Durbinec199dd2013-10-20 20:58:24 -070063 enum i2c_adapter_type type;
64};
65
66#define MAX_I2C_PERIPHERALS 3
67
68struct chromeos_laptop {
69 struct i2c_peripheral i2c_peripherals[MAX_I2C_PERIPHERALS];
70};
71
Benson Leung9ad36922013-10-20 20:58:25 -070072static struct chromeos_laptop *cros_laptop;
73
74static struct i2c_board_info cyapa_device = {
Benson Leungd1381f42012-10-25 14:21:21 -070075 I2C_BOARD_INFO("cyapa", CYAPA_TP_I2C_ADDR),
76 .flags = I2C_CLIENT_WAKE,
77};
78
Benson Leung9ad36922013-10-20 20:58:25 -070079static struct i2c_board_info isl_als_device = {
Benson Leungd1381f42012-10-25 14:21:21 -070080 I2C_BOARD_INFO("isl29018", ISL_ALS_I2C_ADDR),
81};
82
Benson Leung9ad36922013-10-20 20:58:25 -070083static struct i2c_board_info tsl2583_als_device = {
Benson Leung8016bcb2013-02-01 14:34:46 -080084 I2C_BOARD_INFO("tsl2583", TAOS_ALS_I2C_ADDR),
85};
86
Benson Leung9ad36922013-10-20 20:58:25 -070087static struct i2c_board_info tsl2563_als_device = {
Benson Leungaabf3f42013-02-01 14:34:45 -080088 I2C_BOARD_INFO("tsl2563", TAOS_ALS_I2C_ADDR),
89};
90
Nick Dyerfb5e4c3e2014-05-18 23:00:15 -070091static int mxt_t19_keys[] = {
92 KEY_RESERVED,
93 KEY_RESERVED,
94 KEY_RESERVED,
95 KEY_RESERVED,
96 KEY_RESERVED,
97 BTN_LEFT
98};
99
Benson Leung2ef39202013-03-07 19:43:34 -0800100static struct mxt_platform_data atmel_224s_tp_platform_data = {
Benson Leung2ef39202013-03-07 19:43:34 -0800101 .irqflags = IRQF_TRIGGER_FALLING,
Nick Dyerfb5e4c3e2014-05-18 23:00:15 -0700102 .t19_num_keys = ARRAY_SIZE(mxt_t19_keys),
103 .t19_keymap = mxt_t19_keys,
Benson Leung2ef39202013-03-07 19:43:34 -0800104 .config = NULL,
105 .config_length = 0,
106};
107
Benson Leung9ad36922013-10-20 20:58:25 -0700108static struct i2c_board_info atmel_224s_tp_device = {
Benson Leung8e1ad4c2013-02-21 12:14:59 -0800109 I2C_BOARD_INFO("atmel_mxt_tp", ATMEL_TP_I2C_ADDR),
Benson Leung2ef39202013-03-07 19:43:34 -0800110 .platform_data = &atmel_224s_tp_platform_data,
Benson Leung8e1ad4c2013-02-21 12:14:59 -0800111 .flags = I2C_CLIENT_WAKE,
112};
113
Benson Leung2ef39202013-03-07 19:43:34 -0800114static struct mxt_platform_data atmel_1664s_platform_data = {
Benson Leung2ef39202013-03-07 19:43:34 -0800115 .irqflags = IRQF_TRIGGER_FALLING,
Benson Leung2ef39202013-03-07 19:43:34 -0800116 .config = NULL,
117 .config_length = 0,
118};
119
Benson Leung9ad36922013-10-20 20:58:25 -0700120static struct i2c_board_info atmel_1664s_device = {
Yufeng Shen33a84f82013-02-21 12:15:00 -0800121 I2C_BOARD_INFO("atmel_mxt_ts", ATMEL_TS_I2C_ADDR),
Benson Leung2ef39202013-03-07 19:43:34 -0800122 .platform_data = &atmel_1664s_platform_data,
Yufeng Shen33a84f82013-02-21 12:15:00 -0800123 .flags = I2C_CLIENT_WAKE,
124};
125
Benson Leung9ad36922013-10-20 20:58:25 -0700126static struct i2c_client *__add_probed_i2c_device(
Benson Leungd1381f42012-10-25 14:21:21 -0700127 const char *name,
128 int bus,
129 struct i2c_board_info *info,
130 const unsigned short *addrs)
131{
132 const struct dmi_device *dmi_dev;
133 const struct dmi_dev_onboard *dev_data;
134 struct i2c_adapter *adapter;
135 struct i2c_client *client;
136
137 if (bus < 0)
138 return NULL;
139 /*
140 * If a name is specified, look for irq platform information stashed
141 * in DMI_DEV_TYPE_DEV_ONBOARD by the Chrome OS custom system firmware.
142 */
143 if (name) {
144 dmi_dev = dmi_find_device(DMI_DEV_TYPE_DEV_ONBOARD, name, NULL);
145 if (!dmi_dev) {
146 pr_err("%s failed to dmi find device %s.\n",
147 __func__,
148 name);
149 return NULL;
150 }
151 dev_data = (struct dmi_dev_onboard *)dmi_dev->device_data;
152 if (!dev_data) {
153 pr_err("%s failed to get data from dmi for %s.\n",
154 __func__, name);
155 return NULL;
156 }
157 info->irq = dev_data->instance;
158 }
159
160 adapter = i2c_get_adapter(bus);
161 if (!adapter) {
162 pr_err("%s failed to get i2c adapter %d.\n", __func__, bus);
163 return NULL;
164 }
165
166 /* add the i2c device */
167 client = i2c_new_probed_device(adapter, info, addrs, NULL);
168 if (!client)
169 pr_err("%s failed to register device %d-%02x\n",
170 __func__, bus, info->addr);
171 else
172 pr_debug("%s added i2c device %d-%02x\n",
173 __func__, bus, info->addr);
174
175 i2c_put_adapter(adapter);
176 return client;
177}
178
Mika Westerbergda3b0ab2014-06-17 14:02:00 -0700179struct i2c_lookup {
180 const char *name;
181 int instance;
182 int n;
183};
184
Benson Leung9ad36922013-10-20 20:58:25 -0700185static int __find_i2c_adap(struct device *dev, void *data)
Benson Leungd1381f42012-10-25 14:21:21 -0700186{
Mika Westerbergda3b0ab2014-06-17 14:02:00 -0700187 struct i2c_lookup *lookup = data;
Benson Leungd1381f42012-10-25 14:21:21 -0700188 static const char *prefix = "i2c-";
189 struct i2c_adapter *adapter;
190 if (strncmp(dev_name(dev), prefix, strlen(prefix)) != 0)
191 return 0;
192 adapter = to_i2c_adapter(dev);
Mika Westerbergda3b0ab2014-06-17 14:02:00 -0700193 if (strncmp(adapter->name, lookup->name, strlen(lookup->name)) == 0 &&
194 lookup->n++ == lookup->instance)
195 return 1;
196 return 0;
Benson Leungd1381f42012-10-25 14:21:21 -0700197}
198
Benson Leung9ad36922013-10-20 20:58:25 -0700199static int find_i2c_adapter_num(enum i2c_adapter_type type)
Benson Leungd1381f42012-10-25 14:21:21 -0700200{
201 struct device *dev = NULL;
202 struct i2c_adapter *adapter;
Mika Westerbergda3b0ab2014-06-17 14:02:00 -0700203 struct i2c_lookup lookup;
204
205 memset(&lookup, 0, sizeof(lookup));
206 lookup.name = i2c_adapter_names[type];
207 lookup.instance = (type == I2C_ADAPTER_DESIGNWARE_1) ? 1 : 0;
208
Benson Leungd1381f42012-10-25 14:21:21 -0700209 /* find the adapter by name */
Mika Westerbergda3b0ab2014-06-17 14:02:00 -0700210 dev = bus_find_device(&i2c_bus_type, NULL, &lookup, __find_i2c_adap);
Benson Leungd1381f42012-10-25 14:21:21 -0700211 if (!dev) {
Benson Leung9ad36922013-10-20 20:58:25 -0700212 /* Adapters may appear later. Deferred probing will retry */
213 pr_notice("%s: i2c adapter %s not found on system.\n", __func__,
Mika Westerbergda3b0ab2014-06-17 14:02:00 -0700214 lookup.name);
Benson Leungd1381f42012-10-25 14:21:21 -0700215 return -ENODEV;
216 }
217 adapter = to_i2c_adapter(dev);
218 return adapter->nr;
219}
220
221/*
Benson Leungbcaf0892013-02-21 12:14:58 -0800222 * Takes a list of addresses in addrs as such :
223 * { addr1, ... , addrn, I2C_CLIENT_END };
224 * add_probed_i2c_device will use i2c_new_probed_device
225 * and probe for devices at all of the addresses listed.
226 * Returns NULL if no devices found.
227 * See Documentation/i2c/instantiating-devices for more information.
228 */
Benson Leung9ad36922013-10-20 20:58:25 -0700229static struct i2c_client *add_probed_i2c_device(
Benson Leungbcaf0892013-02-21 12:14:58 -0800230 const char *name,
231 enum i2c_adapter_type type,
232 struct i2c_board_info *info,
233 const unsigned short *addrs)
234{
235 return __add_probed_i2c_device(name,
236 find_i2c_adapter_num(type),
237 info,
238 addrs);
239}
240
241/*
Benson Leungd1381f42012-10-25 14:21:21 -0700242 * Probes for a device at a single address, the one provided by
243 * info->addr.
244 * Returns NULL if no device found.
245 */
Benson Leung9ad36922013-10-20 20:58:25 -0700246static struct i2c_client *add_i2c_device(const char *name,
Benson Leunge7b28842013-02-21 12:14:56 -0800247 enum i2c_adapter_type type,
248 struct i2c_board_info *info)
Benson Leungd1381f42012-10-25 14:21:21 -0700249{
250 const unsigned short addr_list[] = { info->addr, I2C_CLIENT_END };
251 return __add_probed_i2c_device(name,
Benson Leunge7b28842013-02-21 12:14:56 -0800252 find_i2c_adapter_num(type),
Benson Leungd1381f42012-10-25 14:21:21 -0700253 info,
254 addr_list);
255}
256
Benson Leung9ad36922013-10-20 20:58:25 -0700257static int setup_cyapa_tp(enum i2c_adapter_type type)
Benson Leunge7b28842013-02-21 12:14:56 -0800258{
Benson Leung9ad36922013-10-20 20:58:25 -0700259 if (tp)
260 return 0;
261
Aaron Durbinec199dd2013-10-20 20:58:24 -0700262 /* add cyapa touchpad */
263 tp = add_i2c_device("trackpad", type, &cyapa_device);
Benson Leung9ad36922013-10-20 20:58:25 -0700264 return (!tp) ? -EAGAIN : 0;
Benson Leungd1381f42012-10-25 14:21:21 -0700265}
266
Benson Leung9ad36922013-10-20 20:58:25 -0700267static int setup_atmel_224s_tp(enum i2c_adapter_type type)
Benson Leung8e1ad4c2013-02-21 12:14:59 -0800268{
269 const unsigned short addr_list[] = { ATMEL_TP_I2C_BL_ADDR,
270 ATMEL_TP_I2C_ADDR,
271 I2C_CLIENT_END };
Benson Leung9ad36922013-10-20 20:58:25 -0700272 if (tp)
273 return 0;
Benson Leung8e1ad4c2013-02-21 12:14:59 -0800274
Aaron Durbinec199dd2013-10-20 20:58:24 -0700275 /* add atmel mxt touchpad */
276 tp = add_probed_i2c_device("trackpad", type,
Benson Leung8e1ad4c2013-02-21 12:14:59 -0800277 &atmel_224s_tp_device, addr_list);
Benson Leung9ad36922013-10-20 20:58:25 -0700278 return (!tp) ? -EAGAIN : 0;
Benson Leung8e1ad4c2013-02-21 12:14:59 -0800279}
280
Benson Leung9ad36922013-10-20 20:58:25 -0700281static int setup_atmel_1664s_ts(enum i2c_adapter_type type)
Yufeng Shen33a84f82013-02-21 12:15:00 -0800282{
283 const unsigned short addr_list[] = { ATMEL_TS_I2C_BL_ADDR,
284 ATMEL_TS_I2C_ADDR,
285 I2C_CLIENT_END };
Benson Leung9ad36922013-10-20 20:58:25 -0700286 if (ts)
287 return 0;
Yufeng Shen33a84f82013-02-21 12:15:00 -0800288
Aaron Durbinec199dd2013-10-20 20:58:24 -0700289 /* add atmel mxt touch device */
290 ts = add_probed_i2c_device("touchscreen", type,
Yufeng Shen33a84f82013-02-21 12:15:00 -0800291 &atmel_1664s_device, addr_list);
Benson Leung9ad36922013-10-20 20:58:25 -0700292 return (!ts) ? -EAGAIN : 0;
Yufeng Shen33a84f82013-02-21 12:15:00 -0800293}
294
Benson Leung9ad36922013-10-20 20:58:25 -0700295static int setup_isl29018_als(enum i2c_adapter_type type)
Benson Leungd1381f42012-10-25 14:21:21 -0700296{
Benson Leung9ad36922013-10-20 20:58:25 -0700297 if (als)
298 return 0;
299
Benson Leungd1381f42012-10-25 14:21:21 -0700300 /* add isl29018 light sensor */
Aaron Durbinec199dd2013-10-20 20:58:24 -0700301 als = add_i2c_device("lightsensor", type, &isl_als_device);
Benson Leung9ad36922013-10-20 20:58:25 -0700302 return (!als) ? -EAGAIN : 0;
Benson Leungd1381f42012-10-25 14:21:21 -0700303}
304
Benson Leung9ad36922013-10-20 20:58:25 -0700305static int setup_tsl2583_als(enum i2c_adapter_type type)
Benson Leungcc5c3982013-02-21 12:14:57 -0800306{
Benson Leung9ad36922013-10-20 20:58:25 -0700307 if (als)
308 return 0;
309
Aaron Durbinec199dd2013-10-20 20:58:24 -0700310 /* add tsl2583 light sensor */
311 als = add_i2c_device(NULL, type, &tsl2583_als_device);
Benson Leung9ad36922013-10-20 20:58:25 -0700312 return (!als) ? -EAGAIN : 0;
Benson Leungcc5c3982013-02-21 12:14:57 -0800313}
314
Benson Leung9ad36922013-10-20 20:58:25 -0700315static int setup_tsl2563_als(enum i2c_adapter_type type)
Benson Leung8016bcb2013-02-01 14:34:46 -0800316{
Benson Leung9ad36922013-10-20 20:58:25 -0700317 if (als)
318 return 0;
319
Aaron Durbinec199dd2013-10-20 20:58:24 -0700320 /* add tsl2563 light sensor */
321 als = add_i2c_device(NULL, type, &tsl2563_als_device);
Benson Leung9ad36922013-10-20 20:58:25 -0700322 return (!als) ? -EAGAIN : 0;
Benson Leung8016bcb2013-02-01 14:34:46 -0800323}
324
Benson Leung9ad36922013-10-20 20:58:25 -0700325static int __init chromeos_laptop_dmi_matched(const struct dmi_system_id *id)
326{
327 cros_laptop = (void *)id->driver_data;
328 pr_debug("DMI Matched %s.\n", id->ident);
329
330 /* Indicate to dmi_scan that processing is done. */
331 return 1;
332}
333
334static int chromeos_laptop_probe(struct platform_device *pdev)
Benson Leungaabf3f42013-02-01 14:34:45 -0800335{
Aaron Durbinec199dd2013-10-20 20:58:24 -0700336 int i;
Benson Leung9ad36922013-10-20 20:58:25 -0700337 int ret = 0;
Aaron Durbinec199dd2013-10-20 20:58:24 -0700338
339 for (i = 0; i < MAX_I2C_PERIPHERALS; i++) {
340 struct i2c_peripheral *i2c_dev;
341
342 i2c_dev = &cros_laptop->i2c_peripherals[i];
343
344 /* No more peripherals. */
345 if (i2c_dev->add == NULL)
346 break;
347
Benson Leung9ad36922013-10-20 20:58:25 -0700348 /* Add the device. Set -EPROBE_DEFER on any failure */
349 if (i2c_dev->add(i2c_dev->type))
350 ret = -EPROBE_DEFER;
Aaron Durbinec199dd2013-10-20 20:58:24 -0700351 }
352
Benson Leung9ad36922013-10-20 20:58:25 -0700353 return ret;
Benson Leungaabf3f42013-02-01 14:34:45 -0800354}
355
Benson Leung9ad36922013-10-20 20:58:25 -0700356static struct chromeos_laptop samsung_series_5_550 = {
Aaron Durbinec199dd2013-10-20 20:58:24 -0700357 .i2c_peripherals = {
358 /* Touchpad. */
359 { .add = setup_cyapa_tp, I2C_ADAPTER_SMBUS },
360 /* Light Sensor. */
361 { .add = setup_isl29018_als, I2C_ADAPTER_SMBUS },
362 },
363};
364
Benson Leung9ad36922013-10-20 20:58:25 -0700365static struct chromeos_laptop samsung_series_5 = {
Aaron Durbinec199dd2013-10-20 20:58:24 -0700366 .i2c_peripherals = {
367 /* Light Sensor. */
368 { .add = setup_tsl2583_als, I2C_ADAPTER_SMBUS },
369 },
370};
371
Benson Leung9ad36922013-10-20 20:58:25 -0700372static struct chromeos_laptop chromebook_pixel = {
Aaron Durbinec199dd2013-10-20 20:58:24 -0700373 .i2c_peripherals = {
374 /* Touch Screen. */
375 { .add = setup_atmel_1664s_ts, I2C_ADAPTER_PANEL },
376 /* Touchpad. */
377 { .add = setup_atmel_224s_tp, I2C_ADAPTER_VGADDC },
378 /* Light Sensor. */
379 { .add = setup_isl29018_als, I2C_ADAPTER_PANEL },
380 },
381};
382
Benson Leung9ad36922013-10-20 20:58:25 -0700383static struct chromeos_laptop acer_c7_chromebook = {
Aaron Durbinec199dd2013-10-20 20:58:24 -0700384 .i2c_peripherals = {
385 /* Touchpad. */
386 { .add = setup_cyapa_tp, I2C_ADAPTER_SMBUS },
387 },
388};
389
Benson Leung9ad36922013-10-20 20:58:25 -0700390static struct chromeos_laptop acer_ac700 = {
Aaron Durbinec199dd2013-10-20 20:58:24 -0700391 .i2c_peripherals = {
392 /* Light Sensor. */
393 { .add = setup_tsl2563_als, I2C_ADAPTER_SMBUS },
394 },
395};
396
Mika Westerbergda3b0ab2014-06-17 14:02:00 -0700397static struct chromeos_laptop acer_c720 = {
398 .i2c_peripherals = {
399 /* Touchpad. */
400 { .add = setup_cyapa_tp, I2C_ADAPTER_DESIGNWARE_0 },
401 /* Light Sensor. */
402 { .add = setup_isl29018_als, I2C_ADAPTER_DESIGNWARE_1 },
403 },
404};
405
Benson Leung9ad36922013-10-20 20:58:25 -0700406static struct chromeos_laptop hp_pavilion_14_chromebook = {
Aaron Durbinec199dd2013-10-20 20:58:24 -0700407 .i2c_peripherals = {
408 /* Touchpad. */
409 { .add = setup_cyapa_tp, I2C_ADAPTER_SMBUS },
410 },
411};
412
Benson Leung9ad36922013-10-20 20:58:25 -0700413static struct chromeos_laptop cr48 = {
Aaron Durbinec199dd2013-10-20 20:58:24 -0700414 .i2c_peripherals = {
415 /* Light Sensor. */
416 { .add = setup_tsl2563_als, I2C_ADAPTER_SMBUS },
417 },
418};
419
420#define _CBDD(board_) \
Benson Leung9ad36922013-10-20 20:58:25 -0700421 .callback = chromeos_laptop_dmi_matched, \
Aaron Durbinec199dd2013-10-20 20:58:24 -0700422 .driver_data = (void *)&board_
423
Benson Leungcdddd232013-10-20 20:58:26 -0700424static struct dmi_system_id chromeos_laptop_dmi_table[] __initdata = {
Benson Leungd1381f42012-10-25 14:21:21 -0700425 {
Aaron Durbinec199dd2013-10-20 20:58:24 -0700426 .ident = "Samsung Series 5 550",
Benson Leungd1381f42012-10-25 14:21:21 -0700427 .matches = {
428 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG"),
429 DMI_MATCH(DMI_PRODUCT_NAME, "Lumpy"),
430 },
Aaron Durbinec199dd2013-10-20 20:58:24 -0700431 _CBDD(samsung_series_5_550),
Benson Leungd1381f42012-10-25 14:21:21 -0700432 },
433 {
Aaron Durbinec199dd2013-10-20 20:58:24 -0700434 .ident = "Samsung Series 5",
Benson Leung8016bcb2013-02-01 14:34:46 -0800435 .matches = {
436 DMI_MATCH(DMI_PRODUCT_NAME, "Alex"),
437 },
Aaron Durbinec199dd2013-10-20 20:58:24 -0700438 _CBDD(samsung_series_5),
Benson Leung8016bcb2013-02-01 14:34:46 -0800439 },
440 {
Aaron Durbinec199dd2013-10-20 20:58:24 -0700441 .ident = "Chromebook Pixel",
Benson Leungaabf3f42013-02-01 14:34:45 -0800442 .matches = {
Aaron Durbinec199dd2013-10-20 20:58:24 -0700443 DMI_MATCH(DMI_SYS_VENDOR, "GOOGLE"),
444 DMI_MATCH(DMI_PRODUCT_NAME, "Link"),
Benson Leungaabf3f42013-02-01 14:34:45 -0800445 },
Aaron Durbinec199dd2013-10-20 20:58:24 -0700446 _CBDD(chromebook_pixel),
Benson Leungaabf3f42013-02-01 14:34:45 -0800447 },
448 {
Aaron Durbinec199dd2013-10-20 20:58:24 -0700449 .ident = "Acer C7 Chromebook",
450 .matches = {
451 DMI_MATCH(DMI_PRODUCT_NAME, "Parrot"),
452 },
453 _CBDD(acer_c7_chromebook),
454 },
455 {
456 .ident = "Acer AC700",
Benson Leungaabf3f42013-02-01 14:34:45 -0800457 .matches = {
458 DMI_MATCH(DMI_PRODUCT_NAME, "ZGB"),
459 },
Aaron Durbinec199dd2013-10-20 20:58:24 -0700460 _CBDD(acer_ac700),
461 },
462 {
Mika Westerbergda3b0ab2014-06-17 14:02:00 -0700463 .ident = "Acer C720",
464 .matches = {
465 DMI_MATCH(DMI_PRODUCT_NAME, "Peppy"),
466 },
467 _CBDD(acer_c720),
468 },
469 {
Aaron Durbinec199dd2013-10-20 20:58:24 -0700470 .ident = "HP Pavilion 14 Chromebook",
471 .matches = {
472 DMI_MATCH(DMI_PRODUCT_NAME, "Butterfly"),
473 },
474 _CBDD(hp_pavilion_14_chromebook),
475 },
476 {
477 .ident = "Cr-48",
478 .matches = {
479 DMI_MATCH(DMI_PRODUCT_NAME, "Mario"),
480 },
481 _CBDD(cr48),
Benson Leungaabf3f42013-02-01 14:34:45 -0800482 },
Benson Leungd1381f42012-10-25 14:21:21 -0700483 { }
484};
485MODULE_DEVICE_TABLE(dmi, chromeos_laptop_dmi_table);
486
Benson Leung9ad36922013-10-20 20:58:25 -0700487static struct platform_device *cros_platform_device;
488
489static struct platform_driver cros_platform_driver = {
490 .driver = {
491 .name = "chromeos_laptop",
492 .owner = THIS_MODULE,
493 },
494 .probe = chromeos_laptop_probe,
495};
496
Benson Leungd1381f42012-10-25 14:21:21 -0700497static int __init chromeos_laptop_init(void)
498{
Benson Leung9ad36922013-10-20 20:58:25 -0700499 int ret;
Benson Leungd1381f42012-10-25 14:21:21 -0700500 if (!dmi_check_system(chromeos_laptop_dmi_table)) {
501 pr_debug("%s unsupported system.\n", __func__);
502 return -ENODEV;
503 }
Benson Leung9ad36922013-10-20 20:58:25 -0700504
505 ret = platform_driver_register(&cros_platform_driver);
506 if (ret)
507 return ret;
508
509 cros_platform_device = platform_device_alloc("chromeos_laptop", -1);
510 if (!cros_platform_device) {
511 ret = -ENOMEM;
512 goto fail_platform_device1;
513 }
514
515 ret = platform_device_add(cros_platform_device);
516 if (ret)
517 goto fail_platform_device2;
518
Benson Leungd1381f42012-10-25 14:21:21 -0700519 return 0;
Benson Leung9ad36922013-10-20 20:58:25 -0700520
521fail_platform_device2:
522 platform_device_put(cros_platform_device);
523fail_platform_device1:
524 platform_driver_unregister(&cros_platform_driver);
525 return ret;
Benson Leungd1381f42012-10-25 14:21:21 -0700526}
527
528static void __exit chromeos_laptop_exit(void)
529{
530 if (als)
531 i2c_unregister_device(als);
532 if (tp)
533 i2c_unregister_device(tp);
Yufeng Shen33a84f82013-02-21 12:15:00 -0800534 if (ts)
535 i2c_unregister_device(ts);
Wei Yongjun2b8454a2013-11-27 11:34:58 +0800536
537 platform_device_unregister(cros_platform_device);
538 platform_driver_unregister(&cros_platform_driver);
Benson Leungd1381f42012-10-25 14:21:21 -0700539}
540
541module_init(chromeos_laptop_init);
542module_exit(chromeos_laptop_exit);
543
544MODULE_DESCRIPTION("Chrome OS Laptop driver");
545MODULE_AUTHOR("Benson Leung <bleung@chromium.org>");
546MODULE_LICENSE("GPL");