fujitsu-laptop.c 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109
  1. /*-*-linux-c-*-*/
  2. /*
  3. Copyright (C) 2007,2008 Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
  4. Copyright (C) 2008 Peter Gruber <nokos@gmx.net>
  5. Based on earlier work:
  6. Copyright (C) 2003 Shane Spencer <shane@bogomip.com>
  7. Adrian Yee <brewt-fujitsu@brewt.org>
  8. Templated from msi-laptop.c and thinkpad_acpi.c which is copyright
  9. by its respective authors.
  10. This program is free software; you can redistribute it and/or modify
  11. it under the terms of the GNU General Public License as published by
  12. the Free Software Foundation; either version 2 of the License, or
  13. (at your option) any later version.
  14. This program is distributed in the hope that it will be useful, but
  15. WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. 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., 51 Franklin Street, Fifth Floor, Boston, MA
  21. 02110-1301, USA.
  22. */
  23. /*
  24. * fujitsu-laptop.c - Fujitsu laptop support, providing access to additional
  25. * features made available on a range of Fujitsu laptops including the
  26. * P2xxx/P5xxx/S6xxx/S7xxx series.
  27. *
  28. * This driver exports a few files in /sys/devices/platform/fujitsu-laptop/;
  29. * others may be added at a later date.
  30. *
  31. * lcd_level - Screen brightness: contains a single integer in the
  32. * range 0..7. (rw)
  33. *
  34. * In addition to these platform device attributes the driver
  35. * registers itself in the Linux backlight control subsystem and is
  36. * available to userspace under /sys/class/backlight/fujitsu-laptop/.
  37. *
  38. * Hotkeys present on certain Fujitsu laptops (eg: the S6xxx series) are
  39. * also supported by this driver.
  40. *
  41. * This driver has been tested on a Fujitsu Lifebook S6410, S7020 and
  42. * P8010. It should work on most P-series and S-series Lifebooks, but
  43. * YMMV.
  44. *
  45. * The module parameter use_alt_lcd_levels switches between different ACPI
  46. * brightness controls which are used by different Fujitsu laptops. In most
  47. * cases the correct method is automatically detected. "use_alt_lcd_levels=1"
  48. * is applicable for a Fujitsu Lifebook S6410 if autodetection fails.
  49. *
  50. */
  51. #include <linux/module.h>
  52. #include <linux/kernel.h>
  53. #include <linux/init.h>
  54. #include <linux/acpi.h>
  55. #include <linux/dmi.h>
  56. #include <linux/backlight.h>
  57. #include <linux/input.h>
  58. #include <linux/kfifo.h>
  59. #include <linux/video_output.h>
  60. #include <linux/platform_device.h>
  61. #define FUJITSU_DRIVER_VERSION "0.4.3"
  62. #define FUJITSU_LCD_N_LEVELS 8
  63. #define ACPI_FUJITSU_CLASS "fujitsu"
  64. #define ACPI_FUJITSU_HID "FUJ02B1"
  65. #define ACPI_FUJITSU_DRIVER_NAME "Fujitsu laptop FUJ02B1 ACPI brightness driver"
  66. #define ACPI_FUJITSU_DEVICE_NAME "Fujitsu FUJ02B1"
  67. #define ACPI_FUJITSU_HOTKEY_HID "FUJ02E3"
  68. #define ACPI_FUJITSU_HOTKEY_DRIVER_NAME "Fujitsu laptop FUJ02E3 ACPI hotkeys driver"
  69. #define ACPI_FUJITSU_HOTKEY_DEVICE_NAME "Fujitsu FUJ02E3"
  70. #define ACPI_FUJITSU_NOTIFY_CODE1 0x80
  71. #define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x86
  72. #define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x87
  73. /* Hotkey details */
  74. #define KEY1_CODE 0x410 /* codes for the keys in the GIRB register */
  75. #define KEY2_CODE 0x411
  76. #define KEY3_CODE 0x412
  77. #define KEY4_CODE 0x413
  78. #define MAX_HOTKEY_RINGBUFFER_SIZE 100
  79. #define RINGBUFFERSIZE 40
  80. /* Debugging */
  81. #define FUJLAPTOP_LOG ACPI_FUJITSU_HID ": "
  82. #define FUJLAPTOP_ERR KERN_ERR FUJLAPTOP_LOG
  83. #define FUJLAPTOP_NOTICE KERN_NOTICE FUJLAPTOP_LOG
  84. #define FUJLAPTOP_INFO KERN_INFO FUJLAPTOP_LOG
  85. #define FUJLAPTOP_DEBUG KERN_DEBUG FUJLAPTOP_LOG
  86. #define FUJLAPTOP_DBG_ALL 0xffff
  87. #define FUJLAPTOP_DBG_ERROR 0x0001
  88. #define FUJLAPTOP_DBG_WARN 0x0002
  89. #define FUJLAPTOP_DBG_INFO 0x0004
  90. #define FUJLAPTOP_DBG_TRACE 0x0008
  91. #define dbg_printk(a_dbg_level, format, arg...) \
  92. do { if (dbg_level & a_dbg_level) \
  93. printk(FUJLAPTOP_DEBUG "%s: " format, __func__ , ## arg); \
  94. } while (0)
  95. #ifdef CONFIG_FUJITSU_LAPTOP_DEBUG
  96. #define vdbg_printk(a_dbg_level, format, arg...) \
  97. dbg_printk(a_dbg_level, format, ## arg)
  98. #else
  99. #define vdbg_printk(a_dbg_level, format, arg...)
  100. #endif
  101. /* Device controlling the backlight and associated keys */
  102. struct fujitsu_t {
  103. acpi_handle acpi_handle;
  104. struct acpi_device *dev;
  105. struct input_dev *input;
  106. char phys[32];
  107. struct backlight_device *bl_device;
  108. struct platform_device *pf_device;
  109. int keycode1, keycode2, keycode3, keycode4;
  110. unsigned int max_brightness;
  111. unsigned int brightness_changed;
  112. unsigned int brightness_level;
  113. };
  114. static struct fujitsu_t *fujitsu;
  115. static int use_alt_lcd_levels = -1;
  116. static int disable_brightness_keys = -1;
  117. static int disable_brightness_adjust = -1;
  118. /* Device used to access other hotkeys on the laptop */
  119. struct fujitsu_hotkey_t {
  120. acpi_handle acpi_handle;
  121. struct acpi_device *dev;
  122. struct input_dev *input;
  123. char phys[32];
  124. struct platform_device *pf_device;
  125. struct kfifo *fifo;
  126. spinlock_t fifo_lock;
  127. unsigned int irb; /* info about the pressed buttons */
  128. };
  129. static struct fujitsu_hotkey_t *fujitsu_hotkey;
  130. static void acpi_fujitsu_hotkey_notify(acpi_handle handle, u32 event,
  131. void *data);
  132. #ifdef CONFIG_FUJITSU_LAPTOP_DEBUG
  133. static u32 dbg_level = 0x03;
  134. #endif
  135. static void acpi_fujitsu_notify(acpi_handle handle, u32 event, void *data);
  136. /* Hardware access for LCD brightness control */
  137. static int set_lcd_level(int level)
  138. {
  139. acpi_status status = AE_OK;
  140. union acpi_object arg0 = { ACPI_TYPE_INTEGER };
  141. struct acpi_object_list arg_list = { 1, &arg0 };
  142. acpi_handle handle = NULL;
  143. vdbg_printk(FUJLAPTOP_DBG_TRACE, "set lcd level via SBLL [%d]\n",
  144. level);
  145. if (level < 0 || level >= fujitsu->max_brightness)
  146. return -EINVAL;
  147. if (!fujitsu)
  148. return -EINVAL;
  149. status = acpi_get_handle(fujitsu->acpi_handle, "SBLL", &handle);
  150. if (ACPI_FAILURE(status)) {
  151. vdbg_printk(FUJLAPTOP_DBG_ERROR, "SBLL not present\n");
  152. return -ENODEV;
  153. }
  154. arg0.integer.value = level;
  155. status = acpi_evaluate_object(handle, NULL, &arg_list, NULL);
  156. if (ACPI_FAILURE(status))
  157. return -ENODEV;
  158. return 0;
  159. }
  160. static int set_lcd_level_alt(int level)
  161. {
  162. acpi_status status = AE_OK;
  163. union acpi_object arg0 = { ACPI_TYPE_INTEGER };
  164. struct acpi_object_list arg_list = { 1, &arg0 };
  165. acpi_handle handle = NULL;
  166. vdbg_printk(FUJLAPTOP_DBG_TRACE, "set lcd level via SBL2 [%d]\n",
  167. level);
  168. if (level < 0 || level >= fujitsu->max_brightness)
  169. return -EINVAL;
  170. if (!fujitsu)
  171. return -EINVAL;
  172. status = acpi_get_handle(fujitsu->acpi_handle, "SBL2", &handle);
  173. if (ACPI_FAILURE(status)) {
  174. vdbg_printk(FUJLAPTOP_DBG_ERROR, "SBL2 not present\n");
  175. return -ENODEV;
  176. }
  177. arg0.integer.value = level;
  178. status = acpi_evaluate_object(handle, NULL, &arg_list, NULL);
  179. if (ACPI_FAILURE(status))
  180. return -ENODEV;
  181. return 0;
  182. }
  183. static int get_lcd_level(void)
  184. {
  185. unsigned long state = 0;
  186. acpi_status status = AE_OK;
  187. vdbg_printk(FUJLAPTOP_DBG_TRACE, "get lcd level via GBLL\n");
  188. status =
  189. acpi_evaluate_integer(fujitsu->acpi_handle, "GBLL", NULL, &state);
  190. if (status < 0)
  191. return status;
  192. fujitsu->brightness_level = state & 0x0fffffff;
  193. if (state & 0x80000000)
  194. fujitsu->brightness_changed = 1;
  195. else
  196. fujitsu->brightness_changed = 0;
  197. return fujitsu->brightness_level;
  198. }
  199. static int get_max_brightness(void)
  200. {
  201. unsigned long state = 0;
  202. acpi_status status = AE_OK;
  203. vdbg_printk(FUJLAPTOP_DBG_TRACE, "get max lcd level via RBLL\n");
  204. status =
  205. acpi_evaluate_integer(fujitsu->acpi_handle, "RBLL", NULL, &state);
  206. if (status < 0)
  207. return status;
  208. fujitsu->max_brightness = state;
  209. return fujitsu->max_brightness;
  210. }
  211. static int get_lcd_level_alt(void)
  212. {
  213. unsigned long state = 0;
  214. acpi_status status = AE_OK;
  215. vdbg_printk(FUJLAPTOP_DBG_TRACE, "get lcd level via GBLS\n");
  216. status =
  217. acpi_evaluate_integer(fujitsu->acpi_handle, "GBLS", NULL, &state);
  218. if (status < 0)
  219. return status;
  220. fujitsu->brightness_level = state & 0x0fffffff;
  221. if (state & 0x80000000)
  222. fujitsu->brightness_changed = 1;
  223. else
  224. fujitsu->brightness_changed = 0;
  225. return fujitsu->brightness_level;
  226. }
  227. /* Backlight device stuff */
  228. static int bl_get_brightness(struct backlight_device *b)
  229. {
  230. if (use_alt_lcd_levels)
  231. return get_lcd_level_alt();
  232. else
  233. return get_lcd_level();
  234. }
  235. static int bl_update_status(struct backlight_device *b)
  236. {
  237. if (use_alt_lcd_levels)
  238. return set_lcd_level_alt(b->props.brightness);
  239. else
  240. return set_lcd_level(b->props.brightness);
  241. }
  242. static struct backlight_ops fujitsubl_ops = {
  243. .get_brightness = bl_get_brightness,
  244. .update_status = bl_update_status,
  245. };
  246. /* Platform LCD brightness device */
  247. static ssize_t
  248. show_max_brightness(struct device *dev,
  249. struct device_attribute *attr, char *buf)
  250. {
  251. int ret;
  252. ret = get_max_brightness();
  253. if (ret < 0)
  254. return ret;
  255. return sprintf(buf, "%i\n", ret);
  256. }
  257. static ssize_t
  258. show_brightness_changed(struct device *dev,
  259. struct device_attribute *attr, char *buf)
  260. {
  261. int ret;
  262. ret = fujitsu->brightness_changed;
  263. if (ret < 0)
  264. return ret;
  265. return sprintf(buf, "%i\n", ret);
  266. }
  267. static ssize_t show_lcd_level(struct device *dev,
  268. struct device_attribute *attr, char *buf)
  269. {
  270. int ret;
  271. if (use_alt_lcd_levels)
  272. ret = get_lcd_level_alt();
  273. else
  274. ret = get_lcd_level();
  275. if (ret < 0)
  276. return ret;
  277. return sprintf(buf, "%i\n", ret);
  278. }
  279. static ssize_t store_lcd_level(struct device *dev,
  280. struct device_attribute *attr, const char *buf,
  281. size_t count)
  282. {
  283. int level, ret;
  284. if (sscanf(buf, "%i", &level) != 1
  285. || (level < 0 || level >= fujitsu->max_brightness))
  286. return -EINVAL;
  287. if (use_alt_lcd_levels)
  288. ret = set_lcd_level_alt(level);
  289. else
  290. ret = set_lcd_level(level);
  291. if (ret < 0)
  292. return ret;
  293. if (use_alt_lcd_levels)
  294. ret = get_lcd_level_alt();
  295. else
  296. ret = get_lcd_level();
  297. if (ret < 0)
  298. return ret;
  299. return count;
  300. }
  301. /* Hardware access for hotkey device */
  302. static int get_irb(void)
  303. {
  304. unsigned long state = 0;
  305. acpi_status status = AE_OK;
  306. vdbg_printk(FUJLAPTOP_DBG_TRACE, "Get irb\n");
  307. status =
  308. acpi_evaluate_integer(fujitsu_hotkey->acpi_handle, "GIRB", NULL,
  309. &state);
  310. if (status < 0)
  311. return status;
  312. fujitsu_hotkey->irb = state;
  313. return fujitsu_hotkey->irb;
  314. }
  315. static ssize_t
  316. ignore_store(struct device *dev,
  317. struct device_attribute *attr, const char *buf, size_t count)
  318. {
  319. return count;
  320. }
  321. static DEVICE_ATTR(max_brightness, 0444, show_max_brightness, ignore_store);
  322. static DEVICE_ATTR(brightness_changed, 0444, show_brightness_changed,
  323. ignore_store);
  324. static DEVICE_ATTR(lcd_level, 0644, show_lcd_level, store_lcd_level);
  325. static struct attribute *fujitsupf_attributes[] = {
  326. &dev_attr_brightness_changed.attr,
  327. &dev_attr_max_brightness.attr,
  328. &dev_attr_lcd_level.attr,
  329. NULL
  330. };
  331. static struct attribute_group fujitsupf_attribute_group = {
  332. .attrs = fujitsupf_attributes
  333. };
  334. static struct platform_driver fujitsupf_driver = {
  335. .driver = {
  336. .name = "fujitsu-laptop",
  337. .owner = THIS_MODULE,
  338. }
  339. };
  340. static void dmi_check_cb_common(const struct dmi_system_id *id)
  341. {
  342. acpi_handle handle;
  343. int have_blnf;
  344. printk(KERN_INFO "fujitsu-laptop: Identified laptop model '%s'.\n",
  345. id->ident);
  346. have_blnf = ACPI_SUCCESS
  347. (acpi_get_handle(NULL, "\\_SB.PCI0.GFX0.LCD.BLNF", &handle));
  348. if (use_alt_lcd_levels == -1) {
  349. vdbg_printk(FUJLAPTOP_DBG_TRACE, "auto-detecting usealt\n");
  350. use_alt_lcd_levels = 1;
  351. }
  352. if (disable_brightness_keys == -1) {
  353. vdbg_printk(FUJLAPTOP_DBG_TRACE,
  354. "auto-detecting disable_keys\n");
  355. disable_brightness_keys = have_blnf ? 1 : 0;
  356. }
  357. if (disable_brightness_adjust == -1) {
  358. vdbg_printk(FUJLAPTOP_DBG_TRACE,
  359. "auto-detecting disable_adjust\n");
  360. disable_brightness_adjust = have_blnf ? 0 : 1;
  361. }
  362. }
  363. static int dmi_check_cb_s6410(const struct dmi_system_id *id)
  364. {
  365. dmi_check_cb_common(id);
  366. fujitsu->keycode1 = KEY_SCREENLOCK; /* "Lock" */
  367. fujitsu->keycode2 = KEY_HELP; /* "Mobility Center" */
  368. return 0;
  369. }
  370. static int dmi_check_cb_p8010(const struct dmi_system_id *id)
  371. {
  372. dmi_check_cb_common(id);
  373. fujitsu->keycode1 = KEY_HELP; /* "Support" */
  374. fujitsu->keycode3 = KEY_SWITCHVIDEOMODE; /* "Presentation" */
  375. fujitsu->keycode4 = KEY_WWW; /* "Internet" */
  376. return 0;
  377. }
  378. static struct dmi_system_id __initdata fujitsu_dmi_table[] = {
  379. {
  380. .ident = "Fujitsu Siemens S6410",
  381. .matches = {
  382. DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
  383. DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK S6410"),
  384. },
  385. .callback = dmi_check_cb_s6410},
  386. {
  387. .ident = "Fujitsu LifeBook P8010",
  388. .matches = {
  389. DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
  390. DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook P8010"),
  391. },
  392. .callback = dmi_check_cb_p8010},
  393. {}
  394. };
  395. /* ACPI device for LCD brightness control */
  396. static int acpi_fujitsu_add(struct acpi_device *device)
  397. {
  398. acpi_status status;
  399. acpi_handle handle;
  400. int result = 0;
  401. int state = 0;
  402. struct input_dev *input;
  403. int error;
  404. if (!device)
  405. return -EINVAL;
  406. fujitsu->acpi_handle = device->handle;
  407. sprintf(acpi_device_name(device), "%s", ACPI_FUJITSU_DEVICE_NAME);
  408. sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS);
  409. acpi_driver_data(device) = fujitsu;
  410. status = acpi_install_notify_handler(device->handle,
  411. ACPI_DEVICE_NOTIFY,
  412. acpi_fujitsu_notify, fujitsu);
  413. if (ACPI_FAILURE(status)) {
  414. printk(KERN_ERR "Error installing notify handler\n");
  415. error = -ENODEV;
  416. goto err_stop;
  417. }
  418. fujitsu->input = input = input_allocate_device();
  419. if (!input) {
  420. error = -ENOMEM;
  421. goto err_uninstall_notify;
  422. }
  423. snprintf(fujitsu->phys, sizeof(fujitsu->phys),
  424. "%s/video/input0", acpi_device_hid(device));
  425. input->name = acpi_device_name(device);
  426. input->phys = fujitsu->phys;
  427. input->id.bustype = BUS_HOST;
  428. input->id.product = 0x06;
  429. input->dev.parent = &device->dev;
  430. input->evbit[0] = BIT(EV_KEY);
  431. set_bit(KEY_BRIGHTNESSUP, input->keybit);
  432. set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
  433. set_bit(KEY_UNKNOWN, input->keybit);
  434. error = input_register_device(input);
  435. if (error)
  436. goto err_free_input_dev;
  437. result = acpi_bus_get_power(fujitsu->acpi_handle, &state);
  438. if (result) {
  439. printk(KERN_ERR "Error reading power state\n");
  440. goto end;
  441. }
  442. printk(KERN_INFO PREFIX "%s [%s] (%s)\n",
  443. acpi_device_name(device), acpi_device_bid(device),
  444. !device->power.state ? "on" : "off");
  445. fujitsu->dev = device;
  446. if (ACPI_SUCCESS
  447. (acpi_get_handle(device->handle, METHOD_NAME__INI, &handle))) {
  448. vdbg_printk(FUJLAPTOP_DBG_INFO, "Invoking _INI\n");
  449. if (ACPI_FAILURE
  450. (acpi_evaluate_object
  451. (device->handle, METHOD_NAME__INI, NULL, NULL)))
  452. printk(KERN_ERR "_INI Method failed\n");
  453. }
  454. /* do config (detect defaults) */
  455. use_alt_lcd_levels = use_alt_lcd_levels == 1 ? 1 : 0;
  456. disable_brightness_keys = disable_brightness_keys == 1 ? 1 : 0;
  457. disable_brightness_adjust = disable_brightness_adjust == 1 ? 1 : 0;
  458. vdbg_printk(FUJLAPTOP_DBG_INFO,
  459. "config: [alt interface: %d], [key disable: %d], [adjust disable: %d]\n",
  460. use_alt_lcd_levels, disable_brightness_keys,
  461. disable_brightness_adjust);
  462. if (get_max_brightness() <= 0)
  463. fujitsu->max_brightness = FUJITSU_LCD_N_LEVELS;
  464. if (use_alt_lcd_levels)
  465. get_lcd_level_alt();
  466. else
  467. get_lcd_level();
  468. return result;
  469. end:
  470. err_free_input_dev:
  471. input_free_device(input);
  472. err_uninstall_notify:
  473. acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
  474. acpi_fujitsu_notify);
  475. err_stop:
  476. return result;
  477. }
  478. static int acpi_fujitsu_remove(struct acpi_device *device, int type)
  479. {
  480. acpi_status status;
  481. struct fujitsu_t *fujitsu = NULL;
  482. if (!device || !acpi_driver_data(device))
  483. return -EINVAL;
  484. fujitsu = acpi_driver_data(device);
  485. status = acpi_remove_notify_handler(fujitsu->acpi_handle,
  486. ACPI_DEVICE_NOTIFY,
  487. acpi_fujitsu_notify);
  488. if (!device || !acpi_driver_data(device))
  489. return -EINVAL;
  490. fujitsu->acpi_handle = NULL;
  491. return 0;
  492. }
  493. /* Brightness notify */
  494. static void acpi_fujitsu_notify(acpi_handle handle, u32 event, void *data)
  495. {
  496. struct input_dev *input;
  497. int keycode;
  498. int oldb, newb;
  499. input = fujitsu->input;
  500. switch (event) {
  501. case ACPI_FUJITSU_NOTIFY_CODE1:
  502. keycode = 0;
  503. oldb = fujitsu->brightness_level;
  504. get_lcd_level(); /* the alt version always yields changed */
  505. newb = fujitsu->brightness_level;
  506. vdbg_printk(FUJLAPTOP_DBG_TRACE,
  507. "brightness button event [%i -> %i (%i)]\n",
  508. oldb, newb, fujitsu->brightness_changed);
  509. if (oldb == newb && fujitsu->brightness_changed) {
  510. keycode = 0;
  511. if (disable_brightness_keys != 1) {
  512. if (oldb == 0) {
  513. acpi_bus_generate_proc_event
  514. (fujitsu->dev,
  515. ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS,
  516. 0);
  517. keycode = KEY_BRIGHTNESSDOWN;
  518. } else if (oldb ==
  519. (fujitsu->max_brightness) - 1) {
  520. acpi_bus_generate_proc_event
  521. (fujitsu->dev,
  522. ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS,
  523. 0);
  524. keycode = KEY_BRIGHTNESSUP;
  525. }
  526. }
  527. } else if (oldb < newb) {
  528. if (disable_brightness_adjust != 1) {
  529. if (use_alt_lcd_levels)
  530. set_lcd_level_alt(newb);
  531. else
  532. set_lcd_level(newb);
  533. }
  534. if (disable_brightness_keys != 1) {
  535. acpi_bus_generate_proc_event(fujitsu->dev,
  536. ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS, 0);
  537. keycode = KEY_BRIGHTNESSUP;
  538. }
  539. } else if (oldb > newb) {
  540. if (disable_brightness_adjust != 1) {
  541. if (use_alt_lcd_levels)
  542. set_lcd_level_alt(newb);
  543. else
  544. set_lcd_level(newb);
  545. }
  546. if (disable_brightness_keys != 1) {
  547. acpi_bus_generate_proc_event(fujitsu->dev,
  548. ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS, 0);
  549. keycode = KEY_BRIGHTNESSDOWN;
  550. }
  551. } else {
  552. keycode = KEY_UNKNOWN;
  553. }
  554. break;
  555. default:
  556. keycode = KEY_UNKNOWN;
  557. vdbg_printk(FUJLAPTOP_DBG_WARN,
  558. "unsupported event [0x%x]\n", event);
  559. break;
  560. }
  561. if (keycode != 0) {
  562. input_report_key(input, keycode, 1);
  563. input_sync(input);
  564. input_report_key(input, keycode, 0);
  565. input_sync(input);
  566. }
  567. return;
  568. }
  569. /* ACPI device for hotkey handling */
  570. static int acpi_fujitsu_hotkey_add(struct acpi_device *device)
  571. {
  572. acpi_status status;
  573. acpi_handle handle;
  574. int result = 0;
  575. int state = 0;
  576. struct input_dev *input;
  577. int error;
  578. int i;
  579. if (!device)
  580. return -EINVAL;
  581. fujitsu_hotkey->acpi_handle = device->handle;
  582. sprintf(acpi_device_name(device), "%s",
  583. ACPI_FUJITSU_HOTKEY_DEVICE_NAME);
  584. sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS);
  585. acpi_driver_data(device) = fujitsu_hotkey;
  586. status = acpi_install_notify_handler(device->handle,
  587. ACPI_DEVICE_NOTIFY,
  588. acpi_fujitsu_hotkey_notify,
  589. fujitsu_hotkey);
  590. if (ACPI_FAILURE(status)) {
  591. printk(KERN_ERR "Error installing notify handler\n");
  592. error = -ENODEV;
  593. goto err_stop;
  594. }
  595. /* kfifo */
  596. spin_lock_init(&fujitsu_hotkey->fifo_lock);
  597. fujitsu_hotkey->fifo =
  598. kfifo_alloc(RINGBUFFERSIZE * sizeof(int), GFP_KERNEL,
  599. &fujitsu_hotkey->fifo_lock);
  600. if (IS_ERR(fujitsu_hotkey->fifo)) {
  601. printk(KERN_ERR "kfifo_alloc failed\n");
  602. error = PTR_ERR(fujitsu_hotkey->fifo);
  603. goto err_stop;
  604. }
  605. fujitsu_hotkey->input = input = input_allocate_device();
  606. if (!input) {
  607. error = -ENOMEM;
  608. goto err_uninstall_notify;
  609. }
  610. snprintf(fujitsu_hotkey->phys, sizeof(fujitsu_hotkey->phys),
  611. "%s/video/input0", acpi_device_hid(device));
  612. input->name = acpi_device_name(device);
  613. input->phys = fujitsu_hotkey->phys;
  614. input->id.bustype = BUS_HOST;
  615. input->id.product = 0x06;
  616. input->dev.parent = &device->dev;
  617. input->evbit[0] = BIT(EV_KEY);
  618. set_bit(fujitsu->keycode1, input->keybit);
  619. set_bit(fujitsu->keycode2, input->keybit);
  620. set_bit(fujitsu->keycode3, input->keybit);
  621. set_bit(fujitsu->keycode4, input->keybit);
  622. set_bit(KEY_UNKNOWN, input->keybit);
  623. error = input_register_device(input);
  624. if (error)
  625. goto err_free_input_dev;
  626. result = acpi_bus_get_power(fujitsu_hotkey->acpi_handle, &state);
  627. if (result) {
  628. printk(KERN_ERR "Error reading power state\n");
  629. goto end;
  630. }
  631. printk(KERN_INFO PREFIX "%s [%s] (%s)\n",
  632. acpi_device_name(device), acpi_device_bid(device),
  633. !device->power.state ? "on" : "off");
  634. fujitsu_hotkey->dev = device;
  635. if (ACPI_SUCCESS
  636. (acpi_get_handle(device->handle, METHOD_NAME__INI, &handle))) {
  637. vdbg_printk(FUJLAPTOP_DBG_INFO, "Invoking _INI\n");
  638. if (ACPI_FAILURE
  639. (acpi_evaluate_object
  640. (device->handle, METHOD_NAME__INI, NULL, NULL)))
  641. printk(KERN_ERR "_INI Method failed\n");
  642. }
  643. i = 0; /* Discard hotkey ringbuffer */
  644. while (get_irb() != 0 && (i++) < MAX_HOTKEY_RINGBUFFER_SIZE) ;
  645. vdbg_printk(FUJLAPTOP_DBG_INFO, "Discarded %i ringbuffer entries\n", i);
  646. return result;
  647. end:
  648. err_free_input_dev:
  649. input_free_device(input);
  650. err_uninstall_notify:
  651. acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
  652. acpi_fujitsu_hotkey_notify);
  653. kfifo_free(fujitsu_hotkey->fifo);
  654. err_stop:
  655. return result;
  656. }
  657. static int acpi_fujitsu_hotkey_remove(struct acpi_device *device, int type)
  658. {
  659. acpi_status status;
  660. struct fujitsu_hotkey_t *fujitsu_hotkey = NULL;
  661. if (!device || !acpi_driver_data(device))
  662. return -EINVAL;
  663. fujitsu_hotkey = acpi_driver_data(device);
  664. status = acpi_remove_notify_handler(fujitsu_hotkey->acpi_handle,
  665. ACPI_DEVICE_NOTIFY,
  666. acpi_fujitsu_hotkey_notify);
  667. fujitsu_hotkey->acpi_handle = NULL;
  668. kfifo_free(fujitsu_hotkey->fifo);
  669. return 0;
  670. }
  671. static void acpi_fujitsu_hotkey_notify(acpi_handle handle, u32 event,
  672. void *data)
  673. {
  674. struct input_dev *input;
  675. int keycode, keycode_r;
  676. unsigned int irb = 1;
  677. int i, status;
  678. input = fujitsu_hotkey->input;
  679. vdbg_printk(FUJLAPTOP_DBG_TRACE, "Hotkey event\n");
  680. switch (event) {
  681. case ACPI_FUJITSU_NOTIFY_CODE1:
  682. i = 0;
  683. while ((irb = get_irb()) != 0
  684. && (i++) < MAX_HOTKEY_RINGBUFFER_SIZE) {
  685. vdbg_printk(FUJLAPTOP_DBG_TRACE, "GIRB result [%x]\n",
  686. irb);
  687. switch (irb & 0x4ff) {
  688. case KEY1_CODE:
  689. keycode = fujitsu->keycode1;
  690. break;
  691. case KEY2_CODE:
  692. keycode = fujitsu->keycode2;
  693. break;
  694. case KEY3_CODE:
  695. keycode = fujitsu->keycode3;
  696. break;
  697. case KEY4_CODE:
  698. keycode = fujitsu->keycode4;
  699. break;
  700. case 0:
  701. keycode = 0;
  702. break;
  703. default:
  704. vdbg_printk(FUJLAPTOP_DBG_WARN,
  705. "Unknown GIRB result [%x]\n", irb);
  706. keycode = -1;
  707. break;
  708. }
  709. if (keycode > 0) {
  710. vdbg_printk(FUJLAPTOP_DBG_TRACE,
  711. "Push keycode into ringbuffer [%d]\n",
  712. keycode);
  713. status = kfifo_put(fujitsu_hotkey->fifo,
  714. (unsigned char *)&keycode,
  715. sizeof(keycode));
  716. if (status != sizeof(keycode)) {
  717. vdbg_printk(FUJLAPTOP_DBG_WARN,
  718. "Could not push keycode [0x%x]\n",
  719. keycode);
  720. } else {
  721. input_report_key(input, keycode, 1);
  722. input_sync(input);
  723. }
  724. } else if (keycode == 0) {
  725. while ((status =
  726. kfifo_get
  727. (fujitsu_hotkey->fifo, (unsigned char *)
  728. &keycode_r,
  729. sizeof
  730. (keycode_r))) == sizeof(keycode_r)) {
  731. input_report_key(input, keycode_r, 0);
  732. input_sync(input);
  733. vdbg_printk(FUJLAPTOP_DBG_TRACE,
  734. "Pop keycode from ringbuffer [%d]\n",
  735. keycode_r);
  736. }
  737. }
  738. }
  739. break;
  740. default:
  741. keycode = KEY_UNKNOWN;
  742. vdbg_printk(FUJLAPTOP_DBG_WARN,
  743. "Unsupported event [0x%x]\n", event);
  744. input_report_key(input, keycode, 1);
  745. input_sync(input);
  746. input_report_key(input, keycode, 0);
  747. input_sync(input);
  748. break;
  749. }
  750. return;
  751. }
  752. /* Initialization */
  753. static const struct acpi_device_id fujitsu_device_ids[] = {
  754. {ACPI_FUJITSU_HID, 0},
  755. {"", 0},
  756. };
  757. static struct acpi_driver acpi_fujitsu_driver = {
  758. .name = ACPI_FUJITSU_DRIVER_NAME,
  759. .class = ACPI_FUJITSU_CLASS,
  760. .ids = fujitsu_device_ids,
  761. .ops = {
  762. .add = acpi_fujitsu_add,
  763. .remove = acpi_fujitsu_remove,
  764. },
  765. };
  766. static const struct acpi_device_id fujitsu_hotkey_device_ids[] = {
  767. {ACPI_FUJITSU_HOTKEY_HID, 0},
  768. {"", 0},
  769. };
  770. static struct acpi_driver acpi_fujitsu_hotkey_driver = {
  771. .name = ACPI_FUJITSU_HOTKEY_DRIVER_NAME,
  772. .class = ACPI_FUJITSU_CLASS,
  773. .ids = fujitsu_hotkey_device_ids,
  774. .ops = {
  775. .add = acpi_fujitsu_hotkey_add,
  776. .remove = acpi_fujitsu_hotkey_remove,
  777. },
  778. };
  779. static int __init fujitsu_init(void)
  780. {
  781. int ret, result, max_brightness;
  782. if (acpi_disabled)
  783. return -ENODEV;
  784. fujitsu = kmalloc(sizeof(struct fujitsu_t), GFP_KERNEL);
  785. if (!fujitsu)
  786. return -ENOMEM;
  787. memset(fujitsu, 0, sizeof(struct fujitsu_t));
  788. fujitsu->keycode1 = KEY_PROG1;
  789. fujitsu->keycode2 = KEY_PROG2;
  790. fujitsu->keycode3 = KEY_PROG3;
  791. fujitsu->keycode4 = KEY_PROG4;
  792. dmi_check_system(fujitsu_dmi_table);
  793. result = acpi_bus_register_driver(&acpi_fujitsu_driver);
  794. if (result < 0) {
  795. ret = -ENODEV;
  796. goto fail_acpi;
  797. }
  798. /* Register platform stuff */
  799. fujitsu->pf_device = platform_device_alloc("fujitsu-laptop", -1);
  800. if (!fujitsu->pf_device) {
  801. ret = -ENOMEM;
  802. goto fail_platform_driver;
  803. }
  804. ret = platform_device_add(fujitsu->pf_device);
  805. if (ret)
  806. goto fail_platform_device1;
  807. ret =
  808. sysfs_create_group(&fujitsu->pf_device->dev.kobj,
  809. &fujitsupf_attribute_group);
  810. if (ret)
  811. goto fail_platform_device2;
  812. /* Register backlight stuff */
  813. fujitsu->bl_device =
  814. backlight_device_register("fujitsu-laptop", NULL, NULL,
  815. &fujitsubl_ops);
  816. if (IS_ERR(fujitsu->bl_device))
  817. return PTR_ERR(fujitsu->bl_device);
  818. max_brightness = fujitsu->max_brightness;
  819. fujitsu->bl_device->props.max_brightness = max_brightness - 1;
  820. fujitsu->bl_device->props.brightness = fujitsu->brightness_level;
  821. ret = platform_driver_register(&fujitsupf_driver);
  822. if (ret)
  823. goto fail_backlight;
  824. /* Register hotkey driver */
  825. fujitsu_hotkey = kmalloc(sizeof(struct fujitsu_hotkey_t), GFP_KERNEL);
  826. if (!fujitsu_hotkey) {
  827. ret = -ENOMEM;
  828. goto fail_hotkey;
  829. }
  830. memset(fujitsu_hotkey, 0, sizeof(struct fujitsu_hotkey_t));
  831. result = acpi_bus_register_driver(&acpi_fujitsu_hotkey_driver);
  832. if (result < 0) {
  833. ret = -ENODEV;
  834. goto fail_hotkey1;
  835. }
  836. printk(KERN_INFO "fujitsu-laptop: driver " FUJITSU_DRIVER_VERSION
  837. " successfully loaded.\n");
  838. return 0;
  839. fail_hotkey1:
  840. kfree(fujitsu_hotkey);
  841. fail_hotkey:
  842. platform_driver_unregister(&fujitsupf_driver);
  843. fail_backlight:
  844. backlight_device_unregister(fujitsu->bl_device);
  845. fail_platform_device2:
  846. platform_device_del(fujitsu->pf_device);
  847. fail_platform_device1:
  848. platform_device_put(fujitsu->pf_device);
  849. fail_platform_driver:
  850. acpi_bus_unregister_driver(&acpi_fujitsu_driver);
  851. fail_acpi:
  852. kfree(fujitsu);
  853. return ret;
  854. }
  855. static void __exit fujitsu_cleanup(void)
  856. {
  857. sysfs_remove_group(&fujitsu->pf_device->dev.kobj,
  858. &fujitsupf_attribute_group);
  859. platform_device_unregister(fujitsu->pf_device);
  860. platform_driver_unregister(&fujitsupf_driver);
  861. backlight_device_unregister(fujitsu->bl_device);
  862. acpi_bus_unregister_driver(&acpi_fujitsu_driver);
  863. kfree(fujitsu);
  864. acpi_bus_unregister_driver(&acpi_fujitsu_hotkey_driver);
  865. kfree(fujitsu_hotkey);
  866. printk(KERN_INFO "fujitsu-laptop: driver unloaded.\n");
  867. }
  868. module_init(fujitsu_init);
  869. module_exit(fujitsu_cleanup);
  870. module_param(use_alt_lcd_levels, uint, 0644);
  871. MODULE_PARM_DESC(use_alt_lcd_levels,
  872. "Use alternative interface for lcd_levels (needed for Lifebook s6410).");
  873. module_param(disable_brightness_keys, uint, 0644);
  874. MODULE_PARM_DESC(disable_brightness_keys,
  875. "Disable brightness keys (eg. if they are already handled by the generic ACPI_VIDEO device).");
  876. module_param(disable_brightness_adjust, uint, 0644);
  877. MODULE_PARM_DESC(disable_brightness_adjust, "Disable brightness adjustment .");
  878. #ifdef CONFIG_FUJITSU_LAPTOP_DEBUG
  879. module_param_named(debug, dbg_level, uint, 0644);
  880. MODULE_PARM_DESC(debug, "Sets debug level bit-mask");
  881. #endif
  882. MODULE_AUTHOR("Jonathan Woithe, Peter Gruber");
  883. MODULE_DESCRIPTION("Fujitsu laptop extras support");
  884. MODULE_VERSION(FUJITSU_DRIVER_VERSION);
  885. MODULE_LICENSE("GPL");
  886. MODULE_ALIAS("dmi:*:svnFUJITSUSIEMENS:*:pvr:rvnFUJITSU:rnFJNB1D3:*:cvrS6410:*");
  887. MODULE_ALIAS("dmi:*:svnFUJITSU:*:pvr:rvnFUJITSU:rnFJNB19C:*:cvrS7020:*");
  888. static struct pnp_device_id pnp_ids[] = {
  889. {.id = "FUJ02bf"},
  890. {.id = "FUJ02B1"},
  891. {.id = "FUJ02E3"},
  892. {.id = ""}
  893. };
  894. MODULE_DEVICE_TABLE(pnp, pnp_ids);