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/i2c/atmel_mxt_ts.h>
27 #include <linux/input.h>
28 #include <linux/interrupt.h>
29 #include <linux/module.h>
30 #include <linux/platform_device.h>
32 #define ATMEL_TP_I2C_ADDR 0x4b
33 #define ATMEL_TP_I2C_BL_ADDR 0x25
34 #define ATMEL_TS_I2C_ADDR 0x4a
35 #define ATMEL_TS_I2C_BL_ADDR 0x26
36 #define CYAPA_TP_I2C_ADDR 0x67
37 #define ISL_ALS_I2C_ADDR 0x44
38 #define TAOS_ALS_I2C_ADDR 0x29
40 static struct i2c_client
*als
;
41 static struct i2c_client
*tp
;
42 static struct i2c_client
*ts
;
44 static const char *i2c_adapter_names
[] = {
50 /* Keep this enum consistent with i2c_adapter_names */
51 enum i2c_adapter_type
{
52 I2C_ADAPTER_SMBUS
= 0,
57 struct i2c_peripheral
{
58 int (*add
)(enum i2c_adapter_type type
);
59 enum i2c_adapter_type type
;
62 #define MAX_I2C_PERIPHERALS 3
64 struct chromeos_laptop
{
65 struct i2c_peripheral i2c_peripherals
[MAX_I2C_PERIPHERALS
];
68 static struct chromeos_laptop
*cros_laptop
;
70 static struct i2c_board_info cyapa_device
= {
71 I2C_BOARD_INFO("cyapa", CYAPA_TP_I2C_ADDR
),
72 .flags
= I2C_CLIENT_WAKE
,
75 static struct i2c_board_info isl_als_device
= {
76 I2C_BOARD_INFO("isl29018", ISL_ALS_I2C_ADDR
),
79 static struct i2c_board_info tsl2583_als_device
= {
80 I2C_BOARD_INFO("tsl2583", TAOS_ALS_I2C_ADDR
),
83 static struct i2c_board_info tsl2563_als_device
= {
84 I2C_BOARD_INFO("tsl2563", TAOS_ALS_I2C_ADDR
),
87 static int mxt_t19_keys
[] = {
96 static struct mxt_platform_data atmel_224s_tp_platform_data
= {
99 .orient
= MXT_VERTICAL_FLIP
,
100 .irqflags
= IRQF_TRIGGER_FALLING
,
101 .t19_num_keys
= ARRAY_SIZE(mxt_t19_keys
),
102 .t19_keymap
= mxt_t19_keys
,
107 static struct i2c_board_info atmel_224s_tp_device
= {
108 I2C_BOARD_INFO("atmel_mxt_tp", ATMEL_TP_I2C_ADDR
),
109 .platform_data
= &atmel_224s_tp_platform_data
,
110 .flags
= I2C_CLIENT_WAKE
,
113 static struct mxt_platform_data atmel_1664s_platform_data
= {
116 .orient
= MXT_ROTATED_90_COUNTER
,
117 .irqflags
= IRQF_TRIGGER_FALLING
,
122 static struct i2c_board_info atmel_1664s_device
= {
123 I2C_BOARD_INFO("atmel_mxt_ts", ATMEL_TS_I2C_ADDR
),
124 .platform_data
= &atmel_1664s_platform_data
,
125 .flags
= I2C_CLIENT_WAKE
,
128 static struct i2c_client
*__add_probed_i2c_device(
131 struct i2c_board_info
*info
,
132 const unsigned short *addrs
)
134 const struct dmi_device
*dmi_dev
;
135 const struct dmi_dev_onboard
*dev_data
;
136 struct i2c_adapter
*adapter
;
137 struct i2c_client
*client
;
142 * If a name is specified, look for irq platform information stashed
143 * in DMI_DEV_TYPE_DEV_ONBOARD by the Chrome OS custom system firmware.
146 dmi_dev
= dmi_find_device(DMI_DEV_TYPE_DEV_ONBOARD
, name
, NULL
);
148 pr_err("%s failed to dmi find device %s.\n",
153 dev_data
= (struct dmi_dev_onboard
*)dmi_dev
->device_data
;
155 pr_err("%s failed to get data from dmi for %s.\n",
159 info
->irq
= dev_data
->instance
;
162 adapter
= i2c_get_adapter(bus
);
164 pr_err("%s failed to get i2c adapter %d.\n", __func__
, bus
);
168 /* add the i2c device */
169 client
= i2c_new_probed_device(adapter
, info
, addrs
, NULL
);
171 pr_err("%s failed to register device %d-%02x\n",
172 __func__
, bus
, info
->addr
);
174 pr_debug("%s added i2c device %d-%02x\n",
175 __func__
, bus
, info
->addr
);
177 i2c_put_adapter(adapter
);
181 static int __find_i2c_adap(struct device
*dev
, void *data
)
183 const char *name
= data
;
184 static const char *prefix
= "i2c-";
185 struct i2c_adapter
*adapter
;
186 if (strncmp(dev_name(dev
), prefix
, strlen(prefix
)) != 0)
188 adapter
= to_i2c_adapter(dev
);
189 return (strncmp(adapter
->name
, name
, strlen(name
)) == 0);
192 static int find_i2c_adapter_num(enum i2c_adapter_type type
)
194 struct device
*dev
= NULL
;
195 struct i2c_adapter
*adapter
;
196 const char *name
= i2c_adapter_names
[type
];
197 /* find the adapter by name */
198 dev
= bus_find_device(&i2c_bus_type
, NULL
, (void *)name
,
201 /* Adapters may appear later. Deferred probing will retry */
202 pr_notice("%s: i2c adapter %s not found on system.\n", __func__
,
206 adapter
= to_i2c_adapter(dev
);
211 * Takes a list of addresses in addrs as such :
212 * { addr1, ... , addrn, I2C_CLIENT_END };
213 * add_probed_i2c_device will use i2c_new_probed_device
214 * and probe for devices at all of the addresses listed.
215 * Returns NULL if no devices found.
216 * See Documentation/i2c/instantiating-devices for more information.
218 static struct i2c_client
*add_probed_i2c_device(
220 enum i2c_adapter_type type
,
221 struct i2c_board_info
*info
,
222 const unsigned short *addrs
)
224 return __add_probed_i2c_device(name
,
225 find_i2c_adapter_num(type
),
231 * Probes for a device at a single address, the one provided by
233 * Returns NULL if no device found.
235 static struct i2c_client
*add_i2c_device(const char *name
,
236 enum i2c_adapter_type type
,
237 struct i2c_board_info
*info
)
239 const unsigned short addr_list
[] = { info
->addr
, I2C_CLIENT_END
};
240 return __add_probed_i2c_device(name
,
241 find_i2c_adapter_num(type
),
246 static int setup_cyapa_tp(enum i2c_adapter_type type
)
251 /* add cyapa touchpad */
252 tp
= add_i2c_device("trackpad", type
, &cyapa_device
);
253 return (!tp
) ? -EAGAIN
: 0;
256 static int setup_atmel_224s_tp(enum i2c_adapter_type type
)
258 const unsigned short addr_list
[] = { ATMEL_TP_I2C_BL_ADDR
,
264 /* add atmel mxt touchpad */
265 tp
= add_probed_i2c_device("trackpad", type
,
266 &atmel_224s_tp_device
, addr_list
);
267 return (!tp
) ? -EAGAIN
: 0;
270 static int setup_atmel_1664s_ts(enum i2c_adapter_type type
)
272 const unsigned short addr_list
[] = { ATMEL_TS_I2C_BL_ADDR
,
278 /* add atmel mxt touch device */
279 ts
= add_probed_i2c_device("touchscreen", type
,
280 &atmel_1664s_device
, addr_list
);
281 return (!ts
) ? -EAGAIN
: 0;
284 static int setup_isl29018_als(enum i2c_adapter_type type
)
289 /* add isl29018 light sensor */
290 als
= add_i2c_device("lightsensor", type
, &isl_als_device
);
291 return (!als
) ? -EAGAIN
: 0;
294 static int setup_tsl2583_als(enum i2c_adapter_type type
)
299 /* add tsl2583 light sensor */
300 als
= add_i2c_device(NULL
, type
, &tsl2583_als_device
);
301 return (!als
) ? -EAGAIN
: 0;
304 static int setup_tsl2563_als(enum i2c_adapter_type type
)
309 /* add tsl2563 light sensor */
310 als
= add_i2c_device(NULL
, type
, &tsl2563_als_device
);
311 return (!als
) ? -EAGAIN
: 0;
314 static int __init
chromeos_laptop_dmi_matched(const struct dmi_system_id
*id
)
316 cros_laptop
= (void *)id
->driver_data
;
317 pr_debug("DMI Matched %s.\n", id
->ident
);
319 /* Indicate to dmi_scan that processing is done. */
323 static int chromeos_laptop_probe(struct platform_device
*pdev
)
328 for (i
= 0; i
< MAX_I2C_PERIPHERALS
; i
++) {
329 struct i2c_peripheral
*i2c_dev
;
331 i2c_dev
= &cros_laptop
->i2c_peripherals
[i
];
333 /* No more peripherals. */
334 if (i2c_dev
->add
== NULL
)
337 /* Add the device. Set -EPROBE_DEFER on any failure */
338 if (i2c_dev
->add(i2c_dev
->type
))
345 static struct chromeos_laptop samsung_series_5_550
= {
348 { .add
= setup_cyapa_tp
, I2C_ADAPTER_SMBUS
},
350 { .add
= setup_isl29018_als
, I2C_ADAPTER_SMBUS
},
354 static struct chromeos_laptop samsung_series_5
= {
357 { .add
= setup_tsl2583_als
, I2C_ADAPTER_SMBUS
},
361 static struct chromeos_laptop chromebook_pixel
= {
364 { .add
= setup_atmel_1664s_ts
, I2C_ADAPTER_PANEL
},
366 { .add
= setup_atmel_224s_tp
, I2C_ADAPTER_VGADDC
},
368 { .add
= setup_isl29018_als
, I2C_ADAPTER_PANEL
},
372 static struct chromeos_laptop acer_c7_chromebook
= {
375 { .add
= setup_cyapa_tp
, I2C_ADAPTER_SMBUS
},
379 static struct chromeos_laptop acer_ac700
= {
382 { .add
= setup_tsl2563_als
, I2C_ADAPTER_SMBUS
},
386 static struct chromeos_laptop hp_pavilion_14_chromebook
= {
389 { .add
= setup_cyapa_tp
, I2C_ADAPTER_SMBUS
},
393 static struct chromeos_laptop cr48
= {
396 { .add
= setup_tsl2563_als
, I2C_ADAPTER_SMBUS
},
400 #define _CBDD(board_) \
401 .callback = chromeos_laptop_dmi_matched, \
402 .driver_data = (void *)&board_
404 static struct dmi_system_id chromeos_laptop_dmi_table
[] __initdata
= {
406 .ident
= "Samsung Series 5 550",
408 DMI_MATCH(DMI_SYS_VENDOR
, "SAMSUNG"),
409 DMI_MATCH(DMI_PRODUCT_NAME
, "Lumpy"),
411 _CBDD(samsung_series_5_550
),
414 .ident
= "Samsung Series 5",
416 DMI_MATCH(DMI_PRODUCT_NAME
, "Alex"),
418 _CBDD(samsung_series_5
),
421 .ident
= "Chromebook Pixel",
423 DMI_MATCH(DMI_SYS_VENDOR
, "GOOGLE"),
424 DMI_MATCH(DMI_PRODUCT_NAME
, "Link"),
426 _CBDD(chromebook_pixel
),
429 .ident
= "Acer C7 Chromebook",
431 DMI_MATCH(DMI_PRODUCT_NAME
, "Parrot"),
433 _CBDD(acer_c7_chromebook
),
436 .ident
= "Acer AC700",
438 DMI_MATCH(DMI_PRODUCT_NAME
, "ZGB"),
443 .ident
= "HP Pavilion 14 Chromebook",
445 DMI_MATCH(DMI_PRODUCT_NAME
, "Butterfly"),
447 _CBDD(hp_pavilion_14_chromebook
),
452 DMI_MATCH(DMI_PRODUCT_NAME
, "Mario"),
458 MODULE_DEVICE_TABLE(dmi
, chromeos_laptop_dmi_table
);
460 static struct platform_device
*cros_platform_device
;
462 static struct platform_driver cros_platform_driver
= {
464 .name
= "chromeos_laptop",
465 .owner
= THIS_MODULE
,
467 .probe
= chromeos_laptop_probe
,
470 static int __init
chromeos_laptop_init(void)
473 if (!dmi_check_system(chromeos_laptop_dmi_table
)) {
474 pr_debug("%s unsupported system.\n", __func__
);
478 ret
= platform_driver_register(&cros_platform_driver
);
482 cros_platform_device
= platform_device_alloc("chromeos_laptop", -1);
483 if (!cros_platform_device
) {
485 goto fail_platform_device1
;
488 ret
= platform_device_add(cros_platform_device
);
490 goto fail_platform_device2
;
494 fail_platform_device2
:
495 platform_device_put(cros_platform_device
);
496 fail_platform_device1
:
497 platform_driver_unregister(&cros_platform_driver
);
501 static void __exit
chromeos_laptop_exit(void)
504 i2c_unregister_device(als
);
506 i2c_unregister_device(tp
);
508 i2c_unregister_device(ts
);
510 platform_device_unregister(cros_platform_device
);
511 platform_driver_unregister(&cros_platform_driver
);
514 module_init(chromeos_laptop_init
);
515 module_exit(chromeos_laptop_exit
);
517 MODULE_DESCRIPTION("Chrome OS Laptop driver");
518 MODULE_AUTHOR("Benson Leung <bleung@chromium.org>");
519 MODULE_LICENSE("GPL");