panasonic-laptop.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  1. /*
  2. * Panasonic HotKey and LCD brightness control driver
  3. * (C) 2004 Hiroshi Miura <miura@da-cha.org>
  4. * (C) 2004 NTT DATA Intellilink Co. http://www.intellilink.co.jp/
  5. * (C) YOKOTA Hiroshi <yokota (at) netlab. is. tsukuba. ac. jp>
  6. * (C) 2004 David Bronaugh <dbronaugh>
  7. * (C) 2006-2008 Harald Welte <laforge@gnumonks.org>
  8. *
  9. * derived from toshiba_acpi.c, Copyright (C) 2002-2004 John Belmonte
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License version 2 as
  13. * publicshed by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. *
  24. *---------------------------------------------------------------------------
  25. *
  26. * ChangeLog:
  27. * Sep.23, 2008 Harald Welte <laforge@gnumonks.org>
  28. * -v0.95 rename driver from drivers/acpi/pcc_acpi.c to
  29. * drivers/misc/panasonic-laptop.c
  30. *
  31. * Jul.04, 2008 Harald Welte <laforge@gnumonks.org>
  32. * -v0.94 replace /proc interface with device attributes
  33. * support {set,get}keycode on th input device
  34. *
  35. * Jun.27, 2008 Harald Welte <laforge@gnumonks.org>
  36. * -v0.92 merge with 2.6.26-rc6 input API changes
  37. * remove broken <= 2.6.15 kernel support
  38. * resolve all compiler warnings
  39. * various coding style fixes (checkpatch.pl)
  40. * add support for backlight api
  41. * major code restructuring
  42. *
  43. * Dac.28, 2007 Harald Welte <laforge@gnumonks.org>
  44. * -v0.91 merge with 2.6.24-rc6 ACPI changes
  45. *
  46. * Nov.04, 2006 Hiroshi Miura <miura@da-cha.org>
  47. * -v0.9 remove warning about section reference.
  48. * remove acpi_os_free
  49. * add /proc/acpi/pcc/brightness interface for HAL access
  50. * merge dbronaugh's enhancement
  51. * Aug.17, 2004 David Bronaugh (dbronaugh)
  52. * - Added screen brightness setting interface
  53. * Thanks to FreeBSD crew (acpi_panasonic.c)
  54. * for the ideas I needed to accomplish it
  55. *
  56. * May.29, 2006 Hiroshi Miura <miura@da-cha.org>
  57. * -v0.8.4 follow to change keyinput structure
  58. * thanks Fabian Yamaguchi <fabs@cs.tu-berlin.de>,
  59. * Jacob Bower <jacob.bower@ic.ac.uk> and
  60. * Hiroshi Yokota for providing solutions.
  61. *
  62. * Oct.02, 2004 Hiroshi Miura <miura@da-cha.org>
  63. * -v0.8.2 merge code of YOKOTA Hiroshi
  64. * <yokota@netlab.is.tsukuba.ac.jp>.
  65. * Add sticky key mode interface.
  66. * Refactoring acpi_pcc_generate_keyinput().
  67. *
  68. * Sep.15, 2004 Hiroshi Miura <miura@da-cha.org>
  69. * -v0.8 Generate key input event on input subsystem.
  70. * This is based on yet another driver written by
  71. * Ryuta Nakanishi.
  72. *
  73. * Sep.10, 2004 Hiroshi Miura <miura@da-cha.org>
  74. * -v0.7 Change proc interface functions using seq_file
  75. * facility as same as other ACPI drivers.
  76. *
  77. * Aug.28, 2004 Hiroshi Miura <miura@da-cha.org>
  78. * -v0.6.4 Fix a silly error with status checking
  79. *
  80. * Aug.25, 2004 Hiroshi Miura <miura@da-cha.org>
  81. * -v0.6.3 replace read_acpi_int by standard function
  82. * acpi_evaluate_integer
  83. * some clean up and make smart copyright notice.
  84. * fix return value of pcc_acpi_get_key()
  85. * fix checking return value of acpi_bus_register_driver()
  86. *
  87. * Aug.22, 2004 David Bronaugh <dbronaugh@linuxboxen.org>
  88. * -v0.6.2 Add check on ACPI data (num_sifr)
  89. * Coding style cleanups, better error messages/handling
  90. * Fixed an off-by-one error in memory allocation
  91. *
  92. * Aug.21, 2004 David Bronaugh <dbronaugh@linuxboxen.org>
  93. * -v0.6.1 Fix a silly error with status checking
  94. *
  95. * Aug.20, 2004 David Bronaugh <dbronaugh@linuxboxen.org>
  96. * - v0.6 Correct brightness controls to reflect reality
  97. * based on information gleaned by Hiroshi Miura
  98. * and discussions with Hiroshi Miura
  99. *
  100. * Aug.10, 2004 Hiroshi Miura <miura@da-cha.org>
  101. * - v0.5 support LCD brightness control
  102. * based on the disclosed information by MEI.
  103. *
  104. * Jul.25, 2004 Hiroshi Miura <miura@da-cha.org>
  105. * - v0.4 first post version
  106. * add function to retrive SIFR
  107. *
  108. * Jul.24, 2004 Hiroshi Miura <miura@da-cha.org>
  109. * - v0.3 get proper status of hotkey
  110. *
  111. * Jul.22, 2004 Hiroshi Miura <miura@da-cha.org>
  112. * - v0.2 add HotKey handler
  113. *
  114. * Jul.17, 2004 Hiroshi Miura <miura@da-cha.org>
  115. * - v0.1 start from toshiba_acpi driver written by John Belmonte
  116. *
  117. */
  118. #include <linux/kernel.h>
  119. #include <linux/module.h>
  120. #include <linux/init.h>
  121. #include <linux/types.h>
  122. #include <linux/backlight.h>
  123. #include <linux/ctype.h>
  124. #include <linux/seq_file.h>
  125. #include <linux/uaccess.h>
  126. #include <linux/slab.h>
  127. #include <acpi/acpi_bus.h>
  128. #include <acpi/acpi_drivers.h>
  129. #include <linux/input.h>
  130. #ifndef ACPI_HOTKEY_COMPONENT
  131. #define ACPI_HOTKEY_COMPONENT 0x10000000
  132. #endif
  133. #define _COMPONENT ACPI_HOTKEY_COMPONENT
  134. MODULE_AUTHOR("Hiroshi Miura, David Bronaugh and Harald Welte");
  135. MODULE_DESCRIPTION("ACPI HotKey driver for Panasonic Let's Note laptops");
  136. MODULE_LICENSE("GPL");
  137. #define LOGPREFIX "pcc_acpi: "
  138. /* Define ACPI PATHs */
  139. /* Lets note hotkeys */
  140. #define METHOD_HKEY_QUERY "HINF"
  141. #define METHOD_HKEY_SQTY "SQTY"
  142. #define METHOD_HKEY_SINF "SINF"
  143. #define METHOD_HKEY_SSET "SSET"
  144. #define HKEY_NOTIFY 0x80
  145. #define ACPI_PCC_DRIVER_NAME "Panasonic Laptop Support"
  146. #define ACPI_PCC_DEVICE_NAME "Hotkey"
  147. #define ACPI_PCC_CLASS "pcc"
  148. #define ACPI_PCC_INPUT_PHYS "panasonic/hkey0"
  149. /* LCD_TYPEs: 0 = Normal, 1 = Semi-transparent
  150. ENV_STATEs: Normal temp=0x01, High temp=0x81, N/A=0x00
  151. */
  152. enum SINF_BITS { SINF_NUM_BATTERIES = 0,
  153. SINF_LCD_TYPE,
  154. SINF_AC_MAX_BRIGHT,
  155. SINF_AC_MIN_BRIGHT,
  156. SINF_AC_CUR_BRIGHT,
  157. SINF_DC_MAX_BRIGHT,
  158. SINF_DC_MIN_BRIGHT,
  159. SINF_DC_CUR_BRIGHT,
  160. SINF_MUTE,
  161. SINF_RESERVED,
  162. SINF_ENV_STATE,
  163. SINF_STICKY_KEY = 0x80,
  164. };
  165. /* R1 handles SINF_AC_CUR_BRIGHT as SINF_CUR_BRIGHT, doesn't know AC state */
  166. static int acpi_pcc_hotkey_add(struct acpi_device *device);
  167. static int acpi_pcc_hotkey_remove(struct acpi_device *device, int type);
  168. static int acpi_pcc_hotkey_resume(struct acpi_device *device);
  169. static void acpi_pcc_hotkey_notify(struct acpi_device *device, u32 event);
  170. static const struct acpi_device_id pcc_device_ids[] = {
  171. { "MAT0012", 0},
  172. { "MAT0013", 0},
  173. { "MAT0018", 0},
  174. { "MAT0019", 0},
  175. { "", 0},
  176. };
  177. MODULE_DEVICE_TABLE(acpi, pcc_device_ids);
  178. static struct acpi_driver acpi_pcc_driver = {
  179. .name = ACPI_PCC_DRIVER_NAME,
  180. .class = ACPI_PCC_CLASS,
  181. .ids = pcc_device_ids,
  182. .ops = {
  183. .add = acpi_pcc_hotkey_add,
  184. .remove = acpi_pcc_hotkey_remove,
  185. .resume = acpi_pcc_hotkey_resume,
  186. .notify = acpi_pcc_hotkey_notify,
  187. },
  188. };
  189. #define KEYMAP_SIZE 11
  190. static const unsigned int initial_keymap[KEYMAP_SIZE] = {
  191. /* 0 */ KEY_RESERVED,
  192. /* 1 */ KEY_BRIGHTNESSDOWN,
  193. /* 2 */ KEY_BRIGHTNESSUP,
  194. /* 3 */ KEY_DISPLAYTOGGLE,
  195. /* 4 */ KEY_MUTE,
  196. /* 5 */ KEY_VOLUMEDOWN,
  197. /* 6 */ KEY_VOLUMEUP,
  198. /* 7 */ KEY_SLEEP,
  199. /* 8 */ KEY_PROG1, /* Change CPU boost */
  200. /* 9 */ KEY_BATTERY,
  201. /* 10 */ KEY_SUSPEND,
  202. };
  203. struct pcc_acpi {
  204. acpi_handle handle;
  205. unsigned long num_sifr;
  206. int sticky_mode;
  207. u32 *sinf;
  208. struct acpi_device *device;
  209. struct input_dev *input_dev;
  210. struct backlight_device *backlight;
  211. unsigned int keymap[KEYMAP_SIZE];
  212. };
  213. struct pcc_keyinput {
  214. struct acpi_hotkey *hotkey;
  215. };
  216. /* method access functions */
  217. static int acpi_pcc_write_sset(struct pcc_acpi *pcc, int func, int val)
  218. {
  219. union acpi_object in_objs[] = {
  220. { .integer.type = ACPI_TYPE_INTEGER,
  221. .integer.value = func, },
  222. { .integer.type = ACPI_TYPE_INTEGER,
  223. .integer.value = val, },
  224. };
  225. struct acpi_object_list params = {
  226. .count = ARRAY_SIZE(in_objs),
  227. .pointer = in_objs,
  228. };
  229. acpi_status status = AE_OK;
  230. status = acpi_evaluate_object(pcc->handle, METHOD_HKEY_SSET,
  231. &params, NULL);
  232. return (status == AE_OK) ? 0 : -EIO;
  233. }
  234. static inline int acpi_pcc_get_sqty(struct acpi_device *device)
  235. {
  236. unsigned long long s;
  237. acpi_status status;
  238. status = acpi_evaluate_integer(device->handle, METHOD_HKEY_SQTY,
  239. NULL, &s);
  240. if (ACPI_SUCCESS(status))
  241. return s;
  242. else {
  243. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  244. "evaluation error HKEY.SQTY\n"));
  245. return -EINVAL;
  246. }
  247. }
  248. static int acpi_pcc_retrieve_biosdata(struct pcc_acpi *pcc, u32 *sinf)
  249. {
  250. acpi_status status;
  251. struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
  252. union acpi_object *hkey = NULL;
  253. int i;
  254. status = acpi_evaluate_object(pcc->handle, METHOD_HKEY_SINF, NULL,
  255. &buffer);
  256. if (ACPI_FAILURE(status)) {
  257. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  258. "evaluation error HKEY.SINF\n"));
  259. return 0;
  260. }
  261. hkey = buffer.pointer;
  262. if (!hkey || (hkey->type != ACPI_TYPE_PACKAGE)) {
  263. ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid HKEY.SINF\n"));
  264. goto end;
  265. }
  266. if (pcc->num_sifr < hkey->package.count) {
  267. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  268. "SQTY reports bad SINF length\n"));
  269. status = AE_ERROR;
  270. goto end;
  271. }
  272. for (i = 0; i < hkey->package.count; i++) {
  273. union acpi_object *element = &(hkey->package.elements[i]);
  274. if (likely(element->type == ACPI_TYPE_INTEGER)) {
  275. sinf[i] = element->integer.value;
  276. } else
  277. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  278. "Invalid HKEY.SINF data\n"));
  279. }
  280. sinf[hkey->package.count] = -1;
  281. end:
  282. kfree(buffer.pointer);
  283. return status == AE_OK;
  284. }
  285. /* backlight API interface functions */
  286. /* This driver currently treats AC and DC brightness identical,
  287. * since we don't need to invent an interface to the core ACPI
  288. * logic to receive events in case a power supply is plugged in
  289. * or removed */
  290. static int bl_get(struct backlight_device *bd)
  291. {
  292. struct pcc_acpi *pcc = bl_get_data(bd);
  293. if (!acpi_pcc_retrieve_biosdata(pcc, pcc->sinf))
  294. return -EIO;
  295. return pcc->sinf[SINF_AC_CUR_BRIGHT];
  296. }
  297. static int bl_set_status(struct backlight_device *bd)
  298. {
  299. struct pcc_acpi *pcc = bl_get_data(bd);
  300. int bright = bd->props.brightness;
  301. int rc;
  302. if (!acpi_pcc_retrieve_biosdata(pcc, pcc->sinf))
  303. return -EIO;
  304. if (bright < pcc->sinf[SINF_AC_MIN_BRIGHT])
  305. bright = pcc->sinf[SINF_AC_MIN_BRIGHT];
  306. if (bright < pcc->sinf[SINF_DC_MIN_BRIGHT])
  307. bright = pcc->sinf[SINF_DC_MIN_BRIGHT];
  308. if (bright < pcc->sinf[SINF_AC_MIN_BRIGHT] ||
  309. bright > pcc->sinf[SINF_AC_MAX_BRIGHT])
  310. return -EINVAL;
  311. rc = acpi_pcc_write_sset(pcc, SINF_AC_CUR_BRIGHT, bright);
  312. if (rc < 0)
  313. return rc;
  314. return acpi_pcc_write_sset(pcc, SINF_DC_CUR_BRIGHT, bright);
  315. }
  316. static const struct backlight_ops pcc_backlight_ops = {
  317. .get_brightness = bl_get,
  318. .update_status = bl_set_status,
  319. };
  320. /* sysfs user interface functions */
  321. static ssize_t show_numbatt(struct device *dev, struct device_attribute *attr,
  322. char *buf)
  323. {
  324. struct acpi_device *acpi = to_acpi_device(dev);
  325. struct pcc_acpi *pcc = acpi_driver_data(acpi);
  326. if (!acpi_pcc_retrieve_biosdata(pcc, pcc->sinf))
  327. return -EIO;
  328. return snprintf(buf, PAGE_SIZE, "%u\n", pcc->sinf[SINF_NUM_BATTERIES]);
  329. }
  330. static ssize_t show_lcdtype(struct device *dev, struct device_attribute *attr,
  331. char *buf)
  332. {
  333. struct acpi_device *acpi = to_acpi_device(dev);
  334. struct pcc_acpi *pcc = acpi_driver_data(acpi);
  335. if (!acpi_pcc_retrieve_biosdata(pcc, pcc->sinf))
  336. return -EIO;
  337. return snprintf(buf, PAGE_SIZE, "%u\n", pcc->sinf[SINF_LCD_TYPE]);
  338. }
  339. static ssize_t show_mute(struct device *dev, struct device_attribute *attr,
  340. char *buf)
  341. {
  342. struct acpi_device *acpi = to_acpi_device(dev);
  343. struct pcc_acpi *pcc = acpi_driver_data(acpi);
  344. if (!acpi_pcc_retrieve_biosdata(pcc, pcc->sinf))
  345. return -EIO;
  346. return snprintf(buf, PAGE_SIZE, "%u\n", pcc->sinf[SINF_MUTE]);
  347. }
  348. static ssize_t show_sticky(struct device *dev, struct device_attribute *attr,
  349. char *buf)
  350. {
  351. struct acpi_device *acpi = to_acpi_device(dev);
  352. struct pcc_acpi *pcc = acpi_driver_data(acpi);
  353. if (!acpi_pcc_retrieve_biosdata(pcc, pcc->sinf))
  354. return -EIO;
  355. return snprintf(buf, PAGE_SIZE, "%u\n", pcc->sinf[SINF_STICKY_KEY]);
  356. }
  357. static ssize_t set_sticky(struct device *dev, struct device_attribute *attr,
  358. const char *buf, size_t count)
  359. {
  360. struct acpi_device *acpi = to_acpi_device(dev);
  361. struct pcc_acpi *pcc = acpi_driver_data(acpi);
  362. int val;
  363. if (count && sscanf(buf, "%i", &val) == 1 &&
  364. (val == 0 || val == 1)) {
  365. acpi_pcc_write_sset(pcc, SINF_STICKY_KEY, val);
  366. pcc->sticky_mode = val;
  367. }
  368. return count;
  369. }
  370. static DEVICE_ATTR(numbatt, S_IRUGO, show_numbatt, NULL);
  371. static DEVICE_ATTR(lcdtype, S_IRUGO, show_lcdtype, NULL);
  372. static DEVICE_ATTR(mute, S_IRUGO, show_mute, NULL);
  373. static DEVICE_ATTR(sticky_key, S_IRUGO | S_IWUSR, show_sticky, set_sticky);
  374. static struct attribute *pcc_sysfs_entries[] = {
  375. &dev_attr_numbatt.attr,
  376. &dev_attr_lcdtype.attr,
  377. &dev_attr_mute.attr,
  378. &dev_attr_sticky_key.attr,
  379. NULL,
  380. };
  381. static struct attribute_group pcc_attr_group = {
  382. .name = NULL, /* put in device directory */
  383. .attrs = pcc_sysfs_entries,
  384. };
  385. /* hotkey input device driver */
  386. static int pcc_getkeycode(struct input_dev *dev,
  387. unsigned int scancode, unsigned int *keycode)
  388. {
  389. struct pcc_acpi *pcc = input_get_drvdata(dev);
  390. if (scancode >= ARRAY_SIZE(pcc->keymap))
  391. return -EINVAL;
  392. *keycode = pcc->keymap[scancode];
  393. return 0;
  394. }
  395. static int keymap_get_by_keycode(struct pcc_acpi *pcc, unsigned int keycode)
  396. {
  397. int i;
  398. for (i = 0; i < ARRAY_SIZE(pcc->keymap); i++) {
  399. if (pcc->keymap[i] == keycode)
  400. return i+1;
  401. }
  402. return 0;
  403. }
  404. static int pcc_setkeycode(struct input_dev *dev,
  405. unsigned int scancode, unsigned int keycode)
  406. {
  407. struct pcc_acpi *pcc = input_get_drvdata(dev);
  408. int oldkeycode;
  409. if (scancode >= ARRAY_SIZE(pcc->keymap))
  410. return -EINVAL;
  411. oldkeycode = pcc->keymap[scancode];
  412. pcc->keymap[scancode] = keycode;
  413. set_bit(keycode, dev->keybit);
  414. if (!keymap_get_by_keycode(pcc, oldkeycode))
  415. clear_bit(oldkeycode, dev->keybit);
  416. return 0;
  417. }
  418. static void acpi_pcc_generate_keyinput(struct pcc_acpi *pcc)
  419. {
  420. struct input_dev *hotk_input_dev = pcc->input_dev;
  421. int rc;
  422. int key_code, hkey_num;
  423. unsigned long long result;
  424. rc = acpi_evaluate_integer(pcc->handle, METHOD_HKEY_QUERY,
  425. NULL, &result);
  426. if (!ACPI_SUCCESS(rc)) {
  427. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  428. "error getting hotkey status\n"));
  429. return;
  430. }
  431. acpi_bus_generate_proc_event(pcc->device, HKEY_NOTIFY, result);
  432. hkey_num = result & 0xf;
  433. if (hkey_num < 0 || hkey_num >= ARRAY_SIZE(pcc->keymap)) {
  434. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  435. "hotkey number out of range: %d\n",
  436. hkey_num));
  437. return;
  438. }
  439. key_code = pcc->keymap[hkey_num];
  440. if (key_code != KEY_RESERVED) {
  441. int pushed = (result & 0x80) ? TRUE : FALSE;
  442. input_report_key(hotk_input_dev, key_code, pushed);
  443. input_sync(hotk_input_dev);
  444. }
  445. return;
  446. }
  447. static void acpi_pcc_hotkey_notify(struct acpi_device *device, u32 event)
  448. {
  449. struct pcc_acpi *pcc = acpi_driver_data(device);
  450. switch (event) {
  451. case HKEY_NOTIFY:
  452. acpi_pcc_generate_keyinput(pcc);
  453. break;
  454. default:
  455. /* nothing to do */
  456. break;
  457. }
  458. }
  459. static int acpi_pcc_init_input(struct pcc_acpi *pcc)
  460. {
  461. int i, rc;
  462. pcc->input_dev = input_allocate_device();
  463. if (!pcc->input_dev) {
  464. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  465. "Couldn't allocate input device for hotkey"));
  466. return -ENOMEM;
  467. }
  468. pcc->input_dev->evbit[0] = BIT(EV_KEY);
  469. pcc->input_dev->name = ACPI_PCC_DRIVER_NAME;
  470. pcc->input_dev->phys = ACPI_PCC_INPUT_PHYS;
  471. pcc->input_dev->id.bustype = BUS_HOST;
  472. pcc->input_dev->id.vendor = 0x0001;
  473. pcc->input_dev->id.product = 0x0001;
  474. pcc->input_dev->id.version = 0x0100;
  475. pcc->input_dev->getkeycode = pcc_getkeycode;
  476. pcc->input_dev->setkeycode = pcc_setkeycode;
  477. /* load initial keymap */
  478. memcpy(pcc->keymap, initial_keymap, sizeof(pcc->keymap));
  479. for (i = 0; i < ARRAY_SIZE(pcc->keymap); i++)
  480. __set_bit(pcc->keymap[i], pcc->input_dev->keybit);
  481. __clear_bit(KEY_RESERVED, pcc->input_dev->keybit);
  482. input_set_drvdata(pcc->input_dev, pcc);
  483. rc = input_register_device(pcc->input_dev);
  484. if (rc < 0)
  485. input_free_device(pcc->input_dev);
  486. return rc;
  487. }
  488. /* kernel module interface */
  489. static int acpi_pcc_hotkey_resume(struct acpi_device *device)
  490. {
  491. struct pcc_acpi *pcc = acpi_driver_data(device);
  492. if (device == NULL || pcc == NULL)
  493. return -EINVAL;
  494. ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Sticky mode restore: %d\n",
  495. pcc->sticky_mode));
  496. return acpi_pcc_write_sset(pcc, SINF_STICKY_KEY, pcc->sticky_mode);
  497. }
  498. static int acpi_pcc_hotkey_add(struct acpi_device *device)
  499. {
  500. struct backlight_properties props;
  501. struct pcc_acpi *pcc;
  502. int num_sifr, result;
  503. if (!device)
  504. return -EINVAL;
  505. num_sifr = acpi_pcc_get_sqty(device);
  506. if (num_sifr > 255) {
  507. ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "num_sifr too large"));
  508. return -ENODEV;
  509. }
  510. pcc = kzalloc(sizeof(struct pcc_acpi), GFP_KERNEL);
  511. if (!pcc) {
  512. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  513. "Couldn't allocate mem for pcc"));
  514. return -ENOMEM;
  515. }
  516. pcc->sinf = kzalloc(sizeof(u32) * (num_sifr + 1), GFP_KERNEL);
  517. if (!pcc->sinf) {
  518. result = -ENOMEM;
  519. goto out_hotkey;
  520. }
  521. pcc->device = device;
  522. pcc->handle = device->handle;
  523. pcc->num_sifr = num_sifr;
  524. device->driver_data = pcc;
  525. strcpy(acpi_device_name(device), ACPI_PCC_DEVICE_NAME);
  526. strcpy(acpi_device_class(device), ACPI_PCC_CLASS);
  527. result = acpi_pcc_init_input(pcc);
  528. if (result) {
  529. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  530. "Error installing keyinput handler\n"));
  531. goto out_hotkey;
  532. }
  533. if (!acpi_pcc_retrieve_biosdata(pcc, pcc->sinf)) {
  534. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  535. "Couldn't retrieve BIOS data\n"));
  536. goto out_input;
  537. }
  538. /* initialize backlight */
  539. memset(&props, 0, sizeof(struct backlight_properties));
  540. props.max_brightness = pcc->sinf[SINF_AC_MAX_BRIGHT];
  541. pcc->backlight = backlight_device_register("panasonic", NULL, pcc,
  542. &pcc_backlight_ops, &props);
  543. if (IS_ERR(pcc->backlight)) {
  544. result = PTR_ERR(pcc->backlight);
  545. goto out_sinf;
  546. }
  547. /* read the initial brightness setting from the hardware */
  548. pcc->backlight->props.brightness = pcc->sinf[SINF_AC_CUR_BRIGHT];
  549. /* read the initial sticky key mode from the hardware */
  550. pcc->sticky_mode = pcc->sinf[SINF_STICKY_KEY];
  551. /* add sysfs attributes */
  552. result = sysfs_create_group(&device->dev.kobj, &pcc_attr_group);
  553. if (result)
  554. goto out_backlight;
  555. return 0;
  556. out_backlight:
  557. backlight_device_unregister(pcc->backlight);
  558. out_sinf:
  559. kfree(pcc->sinf);
  560. out_input:
  561. input_unregister_device(pcc->input_dev);
  562. /* no need to input_free_device() since core input API refcount and
  563. * free()s the device */
  564. out_hotkey:
  565. kfree(pcc);
  566. return result;
  567. }
  568. static int __init acpi_pcc_init(void)
  569. {
  570. int result = 0;
  571. if (acpi_disabled)
  572. return -ENODEV;
  573. result = acpi_bus_register_driver(&acpi_pcc_driver);
  574. if (result < 0) {
  575. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  576. "Error registering hotkey driver\n"));
  577. return -ENODEV;
  578. }
  579. return 0;
  580. }
  581. static int acpi_pcc_hotkey_remove(struct acpi_device *device, int type)
  582. {
  583. struct pcc_acpi *pcc = acpi_driver_data(device);
  584. if (!device || !pcc)
  585. return -EINVAL;
  586. sysfs_remove_group(&device->dev.kobj, &pcc_attr_group);
  587. backlight_device_unregister(pcc->backlight);
  588. input_unregister_device(pcc->input_dev);
  589. /* no need to input_free_device() since core input API refcount and
  590. * free()s the device */
  591. kfree(pcc->sinf);
  592. kfree(pcc);
  593. return 0;
  594. }
  595. static void __exit acpi_pcc_exit(void)
  596. {
  597. acpi_bus_unregister_driver(&acpi_pcc_driver);
  598. }
  599. module_init(acpi_pcc_init);
  600. module_exit(acpi_pcc_exit);