panasonic-laptop.c 17 KB

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