chromeos_laptop.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  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. #include <linux/dmi.h>
  24. #include <linux/i2c.h>
  25. #include <linux/i2c/atmel_mxt_ts.h>
  26. #include <linux/input.h>
  27. #include <linux/interrupt.h>
  28. #include <linux/module.h>
  29. #define ATMEL_TP_I2C_ADDR 0x4b
  30. #define ATMEL_TP_I2C_BL_ADDR 0x25
  31. #define ATMEL_TS_I2C_ADDR 0x4a
  32. #define ATMEL_TS_I2C_BL_ADDR 0x26
  33. #define CYAPA_TP_I2C_ADDR 0x67
  34. #define ISL_ALS_I2C_ADDR 0x44
  35. #define TAOS_ALS_I2C_ADDR 0x29
  36. static struct i2c_client *als;
  37. static struct i2c_client *tp;
  38. static struct i2c_client *ts;
  39. const char *i2c_adapter_names[] = {
  40. "SMBus I801 adapter",
  41. "i915 gmbus vga",
  42. "i915 gmbus panel",
  43. };
  44. /* Keep this enum consistent with i2c_adapter_names */
  45. enum i2c_adapter_type {
  46. I2C_ADAPTER_SMBUS = 0,
  47. I2C_ADAPTER_VGADDC,
  48. I2C_ADAPTER_PANEL,
  49. };
  50. static struct i2c_board_info __initdata cyapa_device = {
  51. I2C_BOARD_INFO("cyapa", CYAPA_TP_I2C_ADDR),
  52. .flags = I2C_CLIENT_WAKE,
  53. };
  54. static struct i2c_board_info __initdata isl_als_device = {
  55. I2C_BOARD_INFO("isl29018", ISL_ALS_I2C_ADDR),
  56. };
  57. static struct i2c_board_info __initdata tsl2583_als_device = {
  58. I2C_BOARD_INFO("tsl2583", TAOS_ALS_I2C_ADDR),
  59. };
  60. static struct i2c_board_info __initdata tsl2563_als_device = {
  61. I2C_BOARD_INFO("tsl2563", TAOS_ALS_I2C_ADDR),
  62. };
  63. static struct mxt_platform_data atmel_224s_tp_platform_data = {
  64. .x_line = 18,
  65. .y_line = 12,
  66. .x_size = 102*20,
  67. .y_size = 68*20,
  68. .blen = 0x80, /* Gain setting is in upper 4 bits */
  69. .threshold = 0x32,
  70. .voltage = 0, /* 3.3V */
  71. .orient = MXT_VERTICAL_FLIP,
  72. .irqflags = IRQF_TRIGGER_FALLING,
  73. .is_tp = true,
  74. .key_map = { KEY_RESERVED,
  75. KEY_RESERVED,
  76. KEY_RESERVED,
  77. BTN_LEFT },
  78. .config = NULL,
  79. .config_length = 0,
  80. };
  81. static struct i2c_board_info __initdata atmel_224s_tp_device = {
  82. I2C_BOARD_INFO("atmel_mxt_tp", ATMEL_TP_I2C_ADDR),
  83. .platform_data = &atmel_224s_tp_platform_data,
  84. .flags = I2C_CLIENT_WAKE,
  85. };
  86. static struct mxt_platform_data atmel_1664s_platform_data = {
  87. .x_line = 32,
  88. .y_line = 50,
  89. .x_size = 1700,
  90. .y_size = 2560,
  91. .blen = 0x89, /* Gain setting is in upper 4 bits */
  92. .threshold = 0x28,
  93. .voltage = 0, /* 3.3V */
  94. .orient = MXT_ROTATED_90_COUNTER,
  95. .irqflags = IRQF_TRIGGER_FALLING,
  96. .is_tp = false,
  97. .config = NULL,
  98. .config_length = 0,
  99. };
  100. static struct i2c_board_info __initdata atmel_1664s_device = {
  101. I2C_BOARD_INFO("atmel_mxt_ts", ATMEL_TS_I2C_ADDR),
  102. .platform_data = &atmel_1664s_platform_data,
  103. .flags = I2C_CLIENT_WAKE,
  104. };
  105. static struct i2c_client __init *__add_probed_i2c_device(
  106. const char *name,
  107. int bus,
  108. struct i2c_board_info *info,
  109. const unsigned short *addrs)
  110. {
  111. const struct dmi_device *dmi_dev;
  112. const struct dmi_dev_onboard *dev_data;
  113. struct i2c_adapter *adapter;
  114. struct i2c_client *client;
  115. if (bus < 0)
  116. return NULL;
  117. /*
  118. * If a name is specified, look for irq platform information stashed
  119. * in DMI_DEV_TYPE_DEV_ONBOARD by the Chrome OS custom system firmware.
  120. */
  121. if (name) {
  122. dmi_dev = dmi_find_device(DMI_DEV_TYPE_DEV_ONBOARD, name, NULL);
  123. if (!dmi_dev) {
  124. pr_err("%s failed to dmi find device %s.\n",
  125. __func__,
  126. name);
  127. return NULL;
  128. }
  129. dev_data = (struct dmi_dev_onboard *)dmi_dev->device_data;
  130. if (!dev_data) {
  131. pr_err("%s failed to get data from dmi for %s.\n",
  132. __func__, name);
  133. return NULL;
  134. }
  135. info->irq = dev_data->instance;
  136. }
  137. adapter = i2c_get_adapter(bus);
  138. if (!adapter) {
  139. pr_err("%s failed to get i2c adapter %d.\n", __func__, bus);
  140. return NULL;
  141. }
  142. /* add the i2c device */
  143. client = i2c_new_probed_device(adapter, info, addrs, NULL);
  144. if (!client)
  145. pr_err("%s failed to register device %d-%02x\n",
  146. __func__, bus, info->addr);
  147. else
  148. pr_debug("%s added i2c device %d-%02x\n",
  149. __func__, bus, info->addr);
  150. i2c_put_adapter(adapter);
  151. return client;
  152. }
  153. static int __init __find_i2c_adap(struct device *dev, void *data)
  154. {
  155. const char *name = data;
  156. static const char *prefix = "i2c-";
  157. struct i2c_adapter *adapter;
  158. if (strncmp(dev_name(dev), prefix, strlen(prefix)) != 0)
  159. return 0;
  160. adapter = to_i2c_adapter(dev);
  161. return (strncmp(adapter->name, name, strlen(name)) == 0);
  162. }
  163. static int __init find_i2c_adapter_num(enum i2c_adapter_type type)
  164. {
  165. struct device *dev = NULL;
  166. struct i2c_adapter *adapter;
  167. const char *name = i2c_adapter_names[type];
  168. /* find the adapter by name */
  169. dev = bus_find_device(&i2c_bus_type, NULL, (void *)name,
  170. __find_i2c_adap);
  171. if (!dev) {
  172. pr_err("%s: i2c adapter %s not found on system.\n", __func__,
  173. name);
  174. return -ENODEV;
  175. }
  176. adapter = to_i2c_adapter(dev);
  177. return adapter->nr;
  178. }
  179. /*
  180. * Takes a list of addresses in addrs as such :
  181. * { addr1, ... , addrn, I2C_CLIENT_END };
  182. * add_probed_i2c_device will use i2c_new_probed_device
  183. * and probe for devices at all of the addresses listed.
  184. * Returns NULL if no devices found.
  185. * See Documentation/i2c/instantiating-devices for more information.
  186. */
  187. static __init struct i2c_client *add_probed_i2c_device(
  188. const char *name,
  189. enum i2c_adapter_type type,
  190. struct i2c_board_info *info,
  191. const unsigned short *addrs)
  192. {
  193. return __add_probed_i2c_device(name,
  194. find_i2c_adapter_num(type),
  195. info,
  196. addrs);
  197. }
  198. /*
  199. * Probes for a device at a single address, the one provided by
  200. * info->addr.
  201. * Returns NULL if no device found.
  202. */
  203. static __init struct i2c_client *add_i2c_device(const char *name,
  204. enum i2c_adapter_type type,
  205. struct i2c_board_info *info)
  206. {
  207. const unsigned short addr_list[] = { info->addr, I2C_CLIENT_END };
  208. return __add_probed_i2c_device(name,
  209. find_i2c_adapter_num(type),
  210. info,
  211. addr_list);
  212. }
  213. static struct i2c_client __init *add_smbus_device(const char *name,
  214. struct i2c_board_info *info)
  215. {
  216. return add_i2c_device(name, I2C_ADAPTER_SMBUS, info);
  217. }
  218. static int __init setup_cyapa_smbus_tp(const struct dmi_system_id *id)
  219. {
  220. /* add cyapa touchpad on smbus */
  221. tp = add_smbus_device("trackpad", &cyapa_device);
  222. return 0;
  223. }
  224. static int __init setup_atmel_224s_tp(const struct dmi_system_id *id)
  225. {
  226. const unsigned short addr_list[] = { ATMEL_TP_I2C_BL_ADDR,
  227. ATMEL_TP_I2C_ADDR,
  228. I2C_CLIENT_END };
  229. /* add atmel mxt touchpad on VGA DDC GMBus */
  230. tp = add_probed_i2c_device("trackpad", I2C_ADAPTER_VGADDC,
  231. &atmel_224s_tp_device, addr_list);
  232. return 0;
  233. }
  234. static int __init setup_atmel_1664s_ts(const struct dmi_system_id *id)
  235. {
  236. const unsigned short addr_list[] = { ATMEL_TS_I2C_BL_ADDR,
  237. ATMEL_TS_I2C_ADDR,
  238. I2C_CLIENT_END };
  239. /* add atmel mxt touch device on PANEL GMBus */
  240. ts = add_probed_i2c_device("touchscreen", I2C_ADAPTER_PANEL,
  241. &atmel_1664s_device, addr_list);
  242. return 0;
  243. }
  244. static int __init setup_isl29018_als(const struct dmi_system_id *id)
  245. {
  246. /* add isl29018 light sensor */
  247. als = add_smbus_device("lightsensor", &isl_als_device);
  248. return 0;
  249. }
  250. static int __init setup_isl29023_als(const struct dmi_system_id *id)
  251. {
  252. /* add isl29023 light sensor on Panel GMBus */
  253. als = add_i2c_device("lightsensor", I2C_ADAPTER_PANEL,
  254. &isl_als_device);
  255. return 0;
  256. }
  257. static int __init setup_tsl2583_als(const struct dmi_system_id *id)
  258. {
  259. /* add tsl2583 light sensor on smbus */
  260. als = add_smbus_device(NULL, &tsl2583_als_device);
  261. return 0;
  262. }
  263. static int __init setup_tsl2563_als(const struct dmi_system_id *id)
  264. {
  265. /* add tsl2563 light sensor on smbus */
  266. als = add_smbus_device(NULL, &tsl2563_als_device);
  267. return 0;
  268. }
  269. static struct dmi_system_id __initdata chromeos_laptop_dmi_table[] = {
  270. {
  271. .ident = "Samsung Series 5 550 - Touchpad",
  272. .matches = {
  273. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG"),
  274. DMI_MATCH(DMI_PRODUCT_NAME, "Lumpy"),
  275. },
  276. .callback = setup_cyapa_smbus_tp,
  277. },
  278. {
  279. .ident = "Chromebook Pixel - Touchscreen",
  280. .matches = {
  281. DMI_MATCH(DMI_SYS_VENDOR, "GOOGLE"),
  282. DMI_MATCH(DMI_PRODUCT_NAME, "Link"),
  283. },
  284. .callback = setup_atmel_1664s_ts,
  285. },
  286. {
  287. .ident = "Chromebook Pixel - Touchpad",
  288. .matches = {
  289. DMI_MATCH(DMI_SYS_VENDOR, "GOOGLE"),
  290. DMI_MATCH(DMI_PRODUCT_NAME, "Link"),
  291. },
  292. .callback = setup_atmel_224s_tp,
  293. },
  294. {
  295. .ident = "Samsung Series 5 550 - Light Sensor",
  296. .matches = {
  297. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG"),
  298. DMI_MATCH(DMI_PRODUCT_NAME, "Lumpy"),
  299. },
  300. .callback = setup_isl29018_als,
  301. },
  302. {
  303. .ident = "Chromebook Pixel - Light Sensor",
  304. .matches = {
  305. DMI_MATCH(DMI_SYS_VENDOR, "GOOGLE"),
  306. DMI_MATCH(DMI_PRODUCT_NAME, "Link"),
  307. },
  308. .callback = setup_isl29023_als,
  309. },
  310. {
  311. .ident = "Acer C7 Chromebook - Touchpad",
  312. .matches = {
  313. DMI_MATCH(DMI_PRODUCT_NAME, "Parrot"),
  314. },
  315. .callback = setup_cyapa_smbus_tp,
  316. },
  317. {
  318. .ident = "HP Pavilion 14 Chromebook - Touchpad",
  319. .matches = {
  320. DMI_MATCH(DMI_PRODUCT_NAME, "Butterfly"),
  321. },
  322. .callback = setup_cyapa_smbus_tp,
  323. },
  324. {
  325. .ident = "Samsung Series 5 - Light Sensor",
  326. .matches = {
  327. DMI_MATCH(DMI_PRODUCT_NAME, "Alex"),
  328. },
  329. .callback = setup_tsl2583_als,
  330. },
  331. {
  332. .ident = "Cr-48 - Light Sensor",
  333. .matches = {
  334. DMI_MATCH(DMI_PRODUCT_NAME, "Mario"),
  335. },
  336. .callback = setup_tsl2563_als,
  337. },
  338. {
  339. .ident = "Acer AC700 - Light Sensor",
  340. .matches = {
  341. DMI_MATCH(DMI_PRODUCT_NAME, "ZGB"),
  342. },
  343. .callback = setup_tsl2563_als,
  344. },
  345. { }
  346. };
  347. MODULE_DEVICE_TABLE(dmi, chromeos_laptop_dmi_table);
  348. static int __init chromeos_laptop_init(void)
  349. {
  350. if (!dmi_check_system(chromeos_laptop_dmi_table)) {
  351. pr_debug("%s unsupported system.\n", __func__);
  352. return -ENODEV;
  353. }
  354. return 0;
  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. module_init(chromeos_laptop_init);
  366. module_exit(chromeos_laptop_exit);
  367. MODULE_DESCRIPTION("Chrome OS Laptop driver");
  368. MODULE_AUTHOR("Benson Leung <bleung@chromium.org>");
  369. MODULE_LICENSE("GPL");