panasonic-laptop.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  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. #include <linux/input/sparse-keymap.h>
  131. #ifndef ACPI_HOTKEY_COMPONENT
  132. #define ACPI_HOTKEY_COMPONENT 0x10000000
  133. #endif
  134. #define _COMPONENT ACPI_HOTKEY_COMPONENT
  135. MODULE_AUTHOR("Hiroshi Miura, David Bronaugh and Harald Welte");
  136. MODULE_DESCRIPTION("ACPI HotKey driver for Panasonic Let's Note laptops");
  137. MODULE_LICENSE("GPL");
  138. #define LOGPREFIX "pcc_acpi: "
  139. /* Define ACPI PATHs */
  140. /* Lets note hotkeys */
  141. #define METHOD_HKEY_QUERY "HINF"
  142. #define METHOD_HKEY_SQTY "SQTY"
  143. #define METHOD_HKEY_SINF "SINF"
  144. #define METHOD_HKEY_SSET "SSET"
  145. #define HKEY_NOTIFY 0x80
  146. #define ACPI_PCC_DRIVER_NAME "Panasonic Laptop Support"
  147. #define ACPI_PCC_DEVICE_NAME "Hotkey"
  148. #define ACPI_PCC_CLASS "pcc"
  149. #define ACPI_PCC_INPUT_PHYS "panasonic/hkey0"
  150. /* LCD_TYPEs: 0 = Normal, 1 = Semi-transparent
  151. ENV_STATEs: Normal temp=0x01, High temp=0x81, N/A=0x00
  152. */
  153. enum SINF_BITS { SINF_NUM_BATTERIES = 0,
  154. SINF_LCD_TYPE,
  155. SINF_AC_MAX_BRIGHT,
  156. SINF_AC_MIN_BRIGHT,
  157. SINF_AC_CUR_BRIGHT,
  158. SINF_DC_MAX_BRIGHT,
  159. SINF_DC_MIN_BRIGHT,
  160. SINF_DC_CUR_BRIGHT,
  161. SINF_MUTE,
  162. SINF_RESERVED,
  163. SINF_ENV_STATE,
  164. SINF_STICKY_KEY = 0x80,
  165. };
  166. /* R1 handles SINF_AC_CUR_BRIGHT as SINF_CUR_BRIGHT, doesn't know AC state */
  167. static int acpi_pcc_hotkey_add(struct acpi_device *device);
  168. static int acpi_pcc_hotkey_remove(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. #ifdef CONFIG_PM_SLEEP
  179. static int acpi_pcc_hotkey_resume(struct device *dev);
  180. #endif
  181. static SIMPLE_DEV_PM_OPS(acpi_pcc_hotkey_pm, NULL, acpi_pcc_hotkey_resume);
  182. static struct acpi_driver acpi_pcc_driver = {
  183. .name = ACPI_PCC_DRIVER_NAME,
  184. .class = ACPI_PCC_CLASS,
  185. .ids = pcc_device_ids,
  186. .ops = {
  187. .add = acpi_pcc_hotkey_add,
  188. .remove = acpi_pcc_hotkey_remove,
  189. .notify = acpi_pcc_hotkey_notify,
  190. },
  191. .drv.pm = &acpi_pcc_hotkey_pm,
  192. };
  193. static const struct key_entry panasonic_keymap[] = {
  194. { KE_KEY, 0, { KEY_RESERVED } },
  195. { KE_KEY, 1, { KEY_BRIGHTNESSDOWN } },
  196. { KE_KEY, 2, { KEY_BRIGHTNESSUP } },
  197. { KE_KEY, 3, { KEY_DISPLAYTOGGLE } },
  198. { KE_KEY, 4, { KEY_MUTE } },
  199. { KE_KEY, 5, { KEY_VOLUMEDOWN } },
  200. { KE_KEY, 6, { KEY_VOLUMEUP } },
  201. { KE_KEY, 7, { KEY_SLEEP } },
  202. { KE_KEY, 8, { KEY_PROG1 } }, /* Change CPU boost */
  203. { KE_KEY, 9, { KEY_BATTERY } },
  204. { KE_KEY, 10, { KEY_SUSPEND } },
  205. { KE_END, 0 }
  206. };
  207. struct pcc_acpi {
  208. acpi_handle handle;
  209. unsigned long num_sifr;
  210. int sticky_mode;
  211. u32 *sinf;
  212. struct acpi_device *device;
  213. struct input_dev *input_dev;
  214. struct backlight_device *backlight;
  215. };
  216. struct pcc_keyinput {
  217. struct acpi_hotkey *hotkey;
  218. };
  219. /* method access functions */
  220. static int acpi_pcc_write_sset(struct pcc_acpi *pcc, int func, int val)
  221. {
  222. union acpi_object in_objs[] = {
  223. { .integer.type = ACPI_TYPE_INTEGER,
  224. .integer.value = func, },
  225. { .integer.type = ACPI_TYPE_INTEGER,
  226. .integer.value = val, },
  227. };
  228. struct acpi_object_list params = {
  229. .count = ARRAY_SIZE(in_objs),
  230. .pointer = in_objs,
  231. };
  232. acpi_status status = AE_OK;
  233. status = acpi_evaluate_object(pcc->handle, METHOD_HKEY_SSET,
  234. &params, NULL);
  235. return (status == AE_OK) ? 0 : -EIO;
  236. }
  237. static inline int acpi_pcc_get_sqty(struct acpi_device *device)
  238. {
  239. unsigned long long s;
  240. acpi_status status;
  241. status = acpi_evaluate_integer(device->handle, METHOD_HKEY_SQTY,
  242. NULL, &s);
  243. if (ACPI_SUCCESS(status))
  244. return s;
  245. else {
  246. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  247. "evaluation error HKEY.SQTY\n"));
  248. return -EINVAL;
  249. }
  250. }
  251. static int acpi_pcc_retrieve_biosdata(struct pcc_acpi *pcc)
  252. {
  253. acpi_status status;
  254. struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
  255. union acpi_object *hkey = NULL;
  256. int i;
  257. status = acpi_evaluate_object(pcc->handle, METHOD_HKEY_SINF, NULL,
  258. &buffer);
  259. if (ACPI_FAILURE(status)) {
  260. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  261. "evaluation error HKEY.SINF\n"));
  262. return 0;
  263. }
  264. hkey = buffer.pointer;
  265. if (!hkey || (hkey->type != ACPI_TYPE_PACKAGE)) {
  266. ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid HKEY.SINF\n"));
  267. status = AE_ERROR;
  268. goto end;
  269. }
  270. if (pcc->num_sifr < hkey->package.count) {
  271. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  272. "SQTY reports bad SINF length\n"));
  273. status = AE_ERROR;
  274. goto end;
  275. }
  276. for (i = 0; i < hkey->package.count; i++) {
  277. union acpi_object *element = &(hkey->package.elements[i]);
  278. if (likely(element->type == ACPI_TYPE_INTEGER)) {
  279. pcc->sinf[i] = element->integer.value;
  280. } else
  281. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  282. "Invalid HKEY.SINF data\n"));
  283. }
  284. pcc->sinf[hkey->package.count] = -1;
  285. end:
  286. kfree(buffer.pointer);
  287. return status == AE_OK;
  288. }
  289. /* backlight API interface functions */
  290. /* This driver currently treats AC and DC brightness identical,
  291. * since we don't need to invent an interface to the core ACPI
  292. * logic to receive events in case a power supply is plugged in
  293. * or removed */
  294. static int bl_get(struct backlight_device *bd)
  295. {
  296. struct pcc_acpi *pcc = bl_get_data(bd);
  297. if (!acpi_pcc_retrieve_biosdata(pcc))
  298. return -EIO;
  299. return pcc->sinf[SINF_AC_CUR_BRIGHT];
  300. }
  301. static int bl_set_status(struct backlight_device *bd)
  302. {
  303. struct pcc_acpi *pcc = bl_get_data(bd);
  304. int bright = bd->props.brightness;
  305. int rc;
  306. if (!acpi_pcc_retrieve_biosdata(pcc))
  307. return -EIO;
  308. if (bright < pcc->sinf[SINF_AC_MIN_BRIGHT])
  309. bright = pcc->sinf[SINF_AC_MIN_BRIGHT];
  310. if (bright < pcc->sinf[SINF_DC_MIN_BRIGHT])
  311. bright = pcc->sinf[SINF_DC_MIN_BRIGHT];
  312. if (bright < pcc->sinf[SINF_AC_MIN_BRIGHT] ||
  313. bright > pcc->sinf[SINF_AC_MAX_BRIGHT])
  314. return -EINVAL;
  315. rc = acpi_pcc_write_sset(pcc, SINF_AC_CUR_BRIGHT, bright);
  316. if (rc < 0)
  317. return rc;
  318. return acpi_pcc_write_sset(pcc, SINF_DC_CUR_BRIGHT, bright);
  319. }
  320. static const struct backlight_ops pcc_backlight_ops = {
  321. .get_brightness = bl_get,
  322. .update_status = bl_set_status,
  323. };
  324. /* sysfs user interface functions */
  325. static ssize_t show_numbatt(struct device *dev, struct device_attribute *attr,
  326. char *buf)
  327. {
  328. struct acpi_device *acpi = to_acpi_device(dev);
  329. struct pcc_acpi *pcc = acpi_driver_data(acpi);
  330. if (!acpi_pcc_retrieve_biosdata(pcc))
  331. return -EIO;
  332. return snprintf(buf, PAGE_SIZE, "%u\n", pcc->sinf[SINF_NUM_BATTERIES]);
  333. }
  334. static ssize_t show_lcdtype(struct device *dev, struct device_attribute *attr,
  335. char *buf)
  336. {
  337. struct acpi_device *acpi = to_acpi_device(dev);
  338. struct pcc_acpi *pcc = acpi_driver_data(acpi);
  339. if (!acpi_pcc_retrieve_biosdata(pcc))
  340. return -EIO;
  341. return snprintf(buf, PAGE_SIZE, "%u\n", pcc->sinf[SINF_LCD_TYPE]);
  342. }
  343. static ssize_t show_mute(struct device *dev, struct device_attribute *attr,
  344. char *buf)
  345. {
  346. struct acpi_device *acpi = to_acpi_device(dev);
  347. struct pcc_acpi *pcc = acpi_driver_data(acpi);
  348. if (!acpi_pcc_retrieve_biosdata(pcc))
  349. return -EIO;
  350. return snprintf(buf, PAGE_SIZE, "%u\n", pcc->sinf[SINF_MUTE]);
  351. }
  352. static ssize_t show_sticky(struct device *dev, struct device_attribute *attr,
  353. char *buf)
  354. {
  355. struct acpi_device *acpi = to_acpi_device(dev);
  356. struct pcc_acpi *pcc = acpi_driver_data(acpi);
  357. if (!acpi_pcc_retrieve_biosdata(pcc))
  358. return -EIO;
  359. return snprintf(buf, PAGE_SIZE, "%u\n", pcc->sinf[SINF_STICKY_KEY]);
  360. }
  361. static ssize_t set_sticky(struct device *dev, struct device_attribute *attr,
  362. const char *buf, size_t count)
  363. {
  364. struct acpi_device *acpi = to_acpi_device(dev);
  365. struct pcc_acpi *pcc = acpi_driver_data(acpi);
  366. int val;
  367. if (count && sscanf(buf, "%i", &val) == 1 &&
  368. (val == 0 || val == 1)) {
  369. acpi_pcc_write_sset(pcc, SINF_STICKY_KEY, val);
  370. pcc->sticky_mode = val;
  371. }
  372. return count;
  373. }
  374. static DEVICE_ATTR(numbatt, S_IRUGO, show_numbatt, NULL);
  375. static DEVICE_ATTR(lcdtype, S_IRUGO, show_lcdtype, NULL);
  376. static DEVICE_ATTR(mute, S_IRUGO, show_mute, NULL);
  377. static DEVICE_ATTR(sticky_key, S_IRUGO | S_IWUSR, show_sticky, set_sticky);
  378. static struct attribute *pcc_sysfs_entries[] = {
  379. &dev_attr_numbatt.attr,
  380. &dev_attr_lcdtype.attr,
  381. &dev_attr_mute.attr,
  382. &dev_attr_sticky_key.attr,
  383. NULL,
  384. };
  385. static struct attribute_group pcc_attr_group = {
  386. .name = NULL, /* put in device directory */
  387. .attrs = pcc_sysfs_entries,
  388. };
  389. /* hotkey input device driver */
  390. static void acpi_pcc_generate_keyinput(struct pcc_acpi *pcc)
  391. {
  392. struct input_dev *hotk_input_dev = pcc->input_dev;
  393. int rc;
  394. unsigned long long result;
  395. rc = acpi_evaluate_integer(pcc->handle, METHOD_HKEY_QUERY,
  396. NULL, &result);
  397. if (!ACPI_SUCCESS(rc)) {
  398. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  399. "error getting hotkey status\n"));
  400. return;
  401. }
  402. acpi_bus_generate_proc_event(pcc->device, HKEY_NOTIFY, result);
  403. if (!sparse_keymap_report_event(hotk_input_dev,
  404. result & 0xf, result & 0x80, false))
  405. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  406. "Unknown hotkey event: %d\n", result));
  407. }
  408. static void acpi_pcc_hotkey_notify(struct acpi_device *device, u32 event)
  409. {
  410. struct pcc_acpi *pcc = acpi_driver_data(device);
  411. switch (event) {
  412. case HKEY_NOTIFY:
  413. acpi_pcc_generate_keyinput(pcc);
  414. break;
  415. default:
  416. /* nothing to do */
  417. break;
  418. }
  419. }
  420. static int acpi_pcc_init_input(struct pcc_acpi *pcc)
  421. {
  422. struct input_dev *input_dev;
  423. int error;
  424. input_dev = input_allocate_device();
  425. if (!input_dev) {
  426. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  427. "Couldn't allocate input device for hotkey"));
  428. return -ENOMEM;
  429. }
  430. input_dev->name = ACPI_PCC_DRIVER_NAME;
  431. input_dev->phys = ACPI_PCC_INPUT_PHYS;
  432. input_dev->id.bustype = BUS_HOST;
  433. input_dev->id.vendor = 0x0001;
  434. input_dev->id.product = 0x0001;
  435. input_dev->id.version = 0x0100;
  436. error = sparse_keymap_setup(input_dev, panasonic_keymap, NULL);
  437. if (error) {
  438. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  439. "Unable to setup input device keymap\n"));
  440. goto err_free_dev;
  441. }
  442. error = input_register_device(input_dev);
  443. if (error) {
  444. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  445. "Unable to register input device\n"));
  446. goto err_free_keymap;
  447. }
  448. pcc->input_dev = input_dev;
  449. return 0;
  450. err_free_keymap:
  451. sparse_keymap_free(input_dev);
  452. err_free_dev:
  453. input_free_device(input_dev);
  454. return error;
  455. }
  456. static void acpi_pcc_destroy_input(struct pcc_acpi *pcc)
  457. {
  458. sparse_keymap_free(pcc->input_dev);
  459. input_unregister_device(pcc->input_dev);
  460. /*
  461. * No need to input_free_device() since core input API refcounts
  462. * and free()s the device.
  463. */
  464. }
  465. /* kernel module interface */
  466. #ifdef CONFIG_PM_SLEEP
  467. static int acpi_pcc_hotkey_resume(struct device *dev)
  468. {
  469. struct pcc_acpi *pcc;
  470. if (!dev)
  471. return -EINVAL;
  472. pcc = acpi_driver_data(to_acpi_device(dev));
  473. if (!pcc)
  474. return -EINVAL;
  475. ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Sticky mode restore: %d\n",
  476. pcc->sticky_mode));
  477. return acpi_pcc_write_sset(pcc, SINF_STICKY_KEY, pcc->sticky_mode);
  478. }
  479. #endif
  480. static int acpi_pcc_hotkey_add(struct acpi_device *device)
  481. {
  482. struct backlight_properties props;
  483. struct pcc_acpi *pcc;
  484. int num_sifr, result;
  485. if (!device)
  486. return -EINVAL;
  487. num_sifr = acpi_pcc_get_sqty(device);
  488. if (num_sifr < 0 || num_sifr > 255) {
  489. ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "num_sifr out of range"));
  490. return -ENODEV;
  491. }
  492. pcc = kzalloc(sizeof(struct pcc_acpi), GFP_KERNEL);
  493. if (!pcc) {
  494. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  495. "Couldn't allocate mem for pcc"));
  496. return -ENOMEM;
  497. }
  498. pcc->sinf = kzalloc(sizeof(u32) * (num_sifr + 1), GFP_KERNEL);
  499. if (!pcc->sinf) {
  500. result = -ENOMEM;
  501. goto out_hotkey;
  502. }
  503. pcc->device = device;
  504. pcc->handle = device->handle;
  505. pcc->num_sifr = num_sifr;
  506. device->driver_data = pcc;
  507. strcpy(acpi_device_name(device), ACPI_PCC_DEVICE_NAME);
  508. strcpy(acpi_device_class(device), ACPI_PCC_CLASS);
  509. result = acpi_pcc_init_input(pcc);
  510. if (result) {
  511. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  512. "Error installing keyinput handler\n"));
  513. goto out_sinf;
  514. }
  515. if (!acpi_pcc_retrieve_biosdata(pcc)) {
  516. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  517. "Couldn't retrieve BIOS data\n"));
  518. result = -EIO;
  519. goto out_input;
  520. }
  521. /* initialize backlight */
  522. memset(&props, 0, sizeof(struct backlight_properties));
  523. props.type = BACKLIGHT_PLATFORM;
  524. props.max_brightness = pcc->sinf[SINF_AC_MAX_BRIGHT];
  525. pcc->backlight = backlight_device_register("panasonic", NULL, pcc,
  526. &pcc_backlight_ops, &props);
  527. if (IS_ERR(pcc->backlight)) {
  528. result = PTR_ERR(pcc->backlight);
  529. goto out_input;
  530. }
  531. /* read the initial brightness setting from the hardware */
  532. pcc->backlight->props.brightness = pcc->sinf[SINF_AC_CUR_BRIGHT];
  533. /* read the initial sticky key mode from the hardware */
  534. pcc->sticky_mode = pcc->sinf[SINF_STICKY_KEY];
  535. /* add sysfs attributes */
  536. result = sysfs_create_group(&device->dev.kobj, &pcc_attr_group);
  537. if (result)
  538. goto out_backlight;
  539. return 0;
  540. out_backlight:
  541. backlight_device_unregister(pcc->backlight);
  542. out_input:
  543. acpi_pcc_destroy_input(pcc);
  544. out_sinf:
  545. kfree(pcc->sinf);
  546. out_hotkey:
  547. kfree(pcc);
  548. return result;
  549. }
  550. static int __init acpi_pcc_init(void)
  551. {
  552. int result = 0;
  553. if (acpi_disabled)
  554. return -ENODEV;
  555. result = acpi_bus_register_driver(&acpi_pcc_driver);
  556. if (result < 0) {
  557. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  558. "Error registering hotkey driver\n"));
  559. return -ENODEV;
  560. }
  561. return 0;
  562. }
  563. static int acpi_pcc_hotkey_remove(struct acpi_device *device)
  564. {
  565. struct pcc_acpi *pcc = acpi_driver_data(device);
  566. if (!device || !pcc)
  567. return -EINVAL;
  568. sysfs_remove_group(&device->dev.kobj, &pcc_attr_group);
  569. backlight_device_unregister(pcc->backlight);
  570. acpi_pcc_destroy_input(pcc);
  571. kfree(pcc->sinf);
  572. kfree(pcc);
  573. return 0;
  574. }
  575. static void __exit acpi_pcc_exit(void)
  576. {
  577. acpi_bus_unregister_driver(&acpi_pcc_driver);
  578. }
  579. module_init(acpi_pcc_init);
  580. module_exit(acpi_pcc_exit);