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/module.h>
28 #define CYAPA_TP_I2C_ADDR 0x67
29 #define ISL_ALS_I2C_ADDR 0x44
31 static struct i2c_client *als;
32 static struct i2c_client *tp;
34 const char *i2c_adapter_names[] = {
38 /* Keep this enum consistent with i2c_adapter_names */
39 enum i2c_adapter_type {
40 I2C_ADAPTER_SMBUS = 0,
43 static struct i2c_board_info __initdata cyapa_device = {
44 I2C_BOARD_INFO("cyapa", CYAPA_TP_I2C_ADDR),
45 .flags = I2C_CLIENT_WAKE,
48 static struct i2c_board_info __initdata isl_als_device = {
49 I2C_BOARD_INFO("isl29018", ISL_ALS_I2C_ADDR),
52 static struct i2c_client __init *__add_probed_i2c_device(
55 struct i2c_board_info *info,
56 const unsigned short *addrs)
58 const struct dmi_device *dmi_dev;
59 const struct dmi_dev_onboard *dev_data;
60 struct i2c_adapter *adapter;
61 struct i2c_client *client;
66 * If a name is specified, look for irq platform information stashed
67 * in DMI_DEV_TYPE_DEV_ONBOARD by the Chrome OS custom system firmware.
70 dmi_dev = dmi_find_device(DMI_DEV_TYPE_DEV_ONBOARD, name, NULL);
72 pr_err("%s failed to dmi find device %s.\n",
77 dev_data = (struct dmi_dev_onboard *)dmi_dev->device_data;
79 pr_err("%s failed to get data from dmi for %s.\n",
83 info->irq = dev_data->instance;
86 adapter = i2c_get_adapter(bus);
88 pr_err("%s failed to get i2c adapter %d.\n", __func__, bus);
92 /* add the i2c device */
93 client = i2c_new_probed_device(adapter, info, addrs, NULL);
95 pr_err("%s failed to register device %d-%02x\n",
96 __func__, bus, info->addr);
98 pr_debug("%s added i2c device %d-%02x\n",
99 __func__, bus, info->addr);
101 i2c_put_adapter(adapter);
105 static int __init __find_i2c_adap(struct device *dev, void *data)
107 const char *name = data;
108 static const char *prefix = "i2c-";
109 struct i2c_adapter *adapter;
110 if (strncmp(dev_name(dev), prefix, strlen(prefix)) != 0)
112 adapter = to_i2c_adapter(dev);
113 return (strncmp(adapter->name, name, strlen(name)) == 0);
116 static int __init find_i2c_adapter_num(enum i2c_adapter_type type)
118 struct device *dev = NULL;
119 struct i2c_adapter *adapter;
120 const char *name = i2c_adapter_names[type];
121 /* find the adapter by name */
122 dev = bus_find_device(&i2c_bus_type, NULL, (void *)name,
125 pr_err("%s: i2c adapter %s not found on system.\n", __func__,
129 adapter = to_i2c_adapter(dev);
134 * Probes for a device at a single address, the one provided by
136 * Returns NULL if no device found.
138 static struct i2c_client __init *add_smbus_device(const char *name,
139 struct i2c_board_info *info)
141 const unsigned short addr_list[] = { info->addr, I2C_CLIENT_END };
142 return __add_probed_i2c_device(name,
143 find_i2c_adapter_num(I2C_ADAPTER_SMBUS),
148 static int __init setup_cyapa_smbus_tp(const struct dmi_system_id *id)
150 /* add cyapa touchpad on smbus */
151 tp = add_smbus_device("trackpad", &cyapa_device);
155 static int __init setup_isl29018_als(const struct dmi_system_id *id)
157 /* add isl29018 light sensor */
158 als = add_smbus_device("lightsensor", &isl_als_device);
162 static struct dmi_system_id __initdata chromeos_laptop_dmi_table[] = {
164 .ident = "Samsung Series 5 550 - Touchpad",
166 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG"),
167 DMI_MATCH(DMI_PRODUCT_NAME, "Lumpy"),
169 .callback = setup_cyapa_smbus_tp,
172 .ident = "Samsung Series 5 550 - Light Sensor",
174 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG"),
175 DMI_MATCH(DMI_PRODUCT_NAME, "Lumpy"),
177 .callback = setup_isl29018_als,
181 MODULE_DEVICE_TABLE(dmi, chromeos_laptop_dmi_table);
183 static int __init chromeos_laptop_init(void)
185 if (!dmi_check_system(chromeos_laptop_dmi_table)) {
186 pr_debug("%s unsupported system.\n", __func__);
192 static void __exit chromeos_laptop_exit(void)
195 i2c_unregister_device(als);
197 i2c_unregister_device(tp);
200 module_init(chromeos_laptop_init);
201 module_exit(chromeos_laptop_exit);
203 MODULE_DESCRIPTION("Chrome OS Laptop driver");
204 MODULE_AUTHOR("Benson Leung <bleung@chromium.org>");
205 MODULE_LICENSE("GPL");