fujitsu-laptop.c 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126
  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 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 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 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 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_s6420(const struct dmi_system_id *id)
  371. {
  372. dmi_check_cb_common(id);
  373. fujitsu->keycode1 = KEY_SCREENLOCK; /* "Lock" */
  374. fujitsu->keycode2 = KEY_HELP; /* "Mobility Center" */
  375. return 0;
  376. }
  377. static int dmi_check_cb_p8010(const struct dmi_system_id *id)
  378. {
  379. dmi_check_cb_common(id);
  380. fujitsu->keycode1 = KEY_HELP; /* "Support" */
  381. fujitsu->keycode3 = KEY_SWITCHVIDEOMODE; /* "Presentation" */
  382. fujitsu->keycode4 = KEY_WWW; /* "Internet" */
  383. return 0;
  384. }
  385. static struct dmi_system_id fujitsu_dmi_table[] = {
  386. {
  387. .ident = "Fujitsu Siemens S6410",
  388. .matches = {
  389. DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
  390. DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK S6410"),
  391. },
  392. .callback = dmi_check_cb_s6410},
  393. {
  394. .ident = "Fujitsu Siemens S6420",
  395. .matches = {
  396. DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
  397. DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK S6420"),
  398. },
  399. .callback = dmi_check_cb_s6420},
  400. {
  401. .ident = "Fujitsu LifeBook P8010",
  402. .matches = {
  403. DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
  404. DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook P8010"),
  405. },
  406. .callback = dmi_check_cb_p8010},
  407. {}
  408. };
  409. /* ACPI device for LCD brightness control */
  410. static int acpi_fujitsu_add(struct acpi_device *device)
  411. {
  412. acpi_status status;
  413. acpi_handle handle;
  414. int result = 0;
  415. int state = 0;
  416. struct input_dev *input;
  417. int error;
  418. if (!device)
  419. return -EINVAL;
  420. fujitsu->acpi_handle = device->handle;
  421. sprintf(acpi_device_name(device), "%s", ACPI_FUJITSU_DEVICE_NAME);
  422. sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS);
  423. device->driver_data = fujitsu;
  424. status = acpi_install_notify_handler(device->handle,
  425. ACPI_DEVICE_NOTIFY,
  426. acpi_fujitsu_notify, fujitsu);
  427. if (ACPI_FAILURE(status)) {
  428. printk(KERN_ERR "Error installing notify handler\n");
  429. error = -ENODEV;
  430. goto err_stop;
  431. }
  432. fujitsu->input = input = input_allocate_device();
  433. if (!input) {
  434. error = -ENOMEM;
  435. goto err_uninstall_notify;
  436. }
  437. snprintf(fujitsu->phys, sizeof(fujitsu->phys),
  438. "%s/video/input0", acpi_device_hid(device));
  439. input->name = acpi_device_name(device);
  440. input->phys = fujitsu->phys;
  441. input->id.bustype = BUS_HOST;
  442. input->id.product = 0x06;
  443. input->dev.parent = &device->dev;
  444. input->evbit[0] = BIT(EV_KEY);
  445. set_bit(KEY_BRIGHTNESSUP, input->keybit);
  446. set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
  447. set_bit(KEY_UNKNOWN, input->keybit);
  448. error = input_register_device(input);
  449. if (error)
  450. goto err_free_input_dev;
  451. result = acpi_bus_get_power(fujitsu->acpi_handle, &state);
  452. if (result) {
  453. printk(KERN_ERR "Error reading power state\n");
  454. goto end;
  455. }
  456. printk(KERN_INFO PREFIX "%s [%s] (%s)\n",
  457. acpi_device_name(device), acpi_device_bid(device),
  458. !device->power.state ? "on" : "off");
  459. fujitsu->dev = device;
  460. if (ACPI_SUCCESS
  461. (acpi_get_handle(device->handle, METHOD_NAME__INI, &handle))) {
  462. vdbg_printk(FUJLAPTOP_DBG_INFO, "Invoking _INI\n");
  463. if (ACPI_FAILURE
  464. (acpi_evaluate_object
  465. (device->handle, METHOD_NAME__INI, NULL, NULL)))
  466. printk(KERN_ERR "_INI Method failed\n");
  467. }
  468. /* do config (detect defaults) */
  469. use_alt_lcd_levels = use_alt_lcd_levels == 1 ? 1 : 0;
  470. disable_brightness_keys = disable_brightness_keys == 1 ? 1 : 0;
  471. disable_brightness_adjust = disable_brightness_adjust == 1 ? 1 : 0;
  472. vdbg_printk(FUJLAPTOP_DBG_INFO,
  473. "config: [alt interface: %d], [key disable: %d], [adjust disable: %d]\n",
  474. use_alt_lcd_levels, disable_brightness_keys,
  475. disable_brightness_adjust);
  476. if (get_max_brightness() <= 0)
  477. fujitsu->max_brightness = FUJITSU_LCD_N_LEVELS;
  478. if (use_alt_lcd_levels)
  479. get_lcd_level_alt();
  480. else
  481. get_lcd_level();
  482. return result;
  483. end:
  484. err_free_input_dev:
  485. input_free_device(input);
  486. err_uninstall_notify:
  487. acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
  488. acpi_fujitsu_notify);
  489. err_stop:
  490. return result;
  491. }
  492. static int acpi_fujitsu_remove(struct acpi_device *device, int type)
  493. {
  494. acpi_status status;
  495. struct fujitsu_t *fujitsu = NULL;
  496. if (!device || !acpi_driver_data(device))
  497. return -EINVAL;
  498. fujitsu = acpi_driver_data(device);
  499. status = acpi_remove_notify_handler(fujitsu->acpi_handle,
  500. ACPI_DEVICE_NOTIFY,
  501. acpi_fujitsu_notify);
  502. if (!device || !acpi_driver_data(device))
  503. return -EINVAL;
  504. fujitsu->acpi_handle = NULL;
  505. return 0;
  506. }
  507. /* Brightness notify */
  508. static void acpi_fujitsu_notify(acpi_handle handle, u32 event, void *data)
  509. {
  510. struct input_dev *input;
  511. int keycode;
  512. int oldb, newb;
  513. input = fujitsu->input;
  514. switch (event) {
  515. case ACPI_FUJITSU_NOTIFY_CODE1:
  516. keycode = 0;
  517. oldb = fujitsu->brightness_level;
  518. get_lcd_level(); /* the alt version always yields changed */
  519. newb = fujitsu->brightness_level;
  520. vdbg_printk(FUJLAPTOP_DBG_TRACE,
  521. "brightness button event [%i -> %i (%i)]\n",
  522. oldb, newb, fujitsu->brightness_changed);
  523. if (oldb == newb && fujitsu->brightness_changed) {
  524. keycode = 0;
  525. if (disable_brightness_keys != 1) {
  526. if (oldb == 0) {
  527. acpi_bus_generate_proc_event
  528. (fujitsu->dev,
  529. ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS,
  530. 0);
  531. keycode = KEY_BRIGHTNESSDOWN;
  532. } else if (oldb ==
  533. (fujitsu->max_brightness) - 1) {
  534. acpi_bus_generate_proc_event
  535. (fujitsu->dev,
  536. ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS,
  537. 0);
  538. keycode = KEY_BRIGHTNESSUP;
  539. }
  540. }
  541. } else if (oldb < newb) {
  542. if (disable_brightness_adjust != 1) {
  543. if (use_alt_lcd_levels)
  544. set_lcd_level_alt(newb);
  545. else
  546. set_lcd_level(newb);
  547. }
  548. if (disable_brightness_keys != 1) {
  549. acpi_bus_generate_proc_event(fujitsu->dev,
  550. ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS, 0);
  551. keycode = KEY_BRIGHTNESSUP;
  552. }
  553. } else if (oldb > newb) {
  554. if (disable_brightness_adjust != 1) {
  555. if (use_alt_lcd_levels)
  556. set_lcd_level_alt(newb);
  557. else
  558. set_lcd_level(newb);
  559. }
  560. if (disable_brightness_keys != 1) {
  561. acpi_bus_generate_proc_event(fujitsu->dev,
  562. ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS, 0);
  563. keycode = KEY_BRIGHTNESSDOWN;
  564. }
  565. } else {
  566. keycode = KEY_UNKNOWN;
  567. }
  568. break;
  569. default:
  570. keycode = KEY_UNKNOWN;
  571. vdbg_printk(FUJLAPTOP_DBG_WARN,
  572. "unsupported event [0x%x]\n", event);
  573. break;
  574. }
  575. if (keycode != 0) {
  576. input_report_key(input, keycode, 1);
  577. input_sync(input);
  578. input_report_key(input, keycode, 0);
  579. input_sync(input);
  580. }
  581. return;
  582. }
  583. /* ACPI device for hotkey handling */
  584. static int acpi_fujitsu_hotkey_add(struct acpi_device *device)
  585. {
  586. acpi_status status;
  587. acpi_handle handle;
  588. int result = 0;
  589. int state = 0;
  590. struct input_dev *input;
  591. int error;
  592. int i;
  593. if (!device)
  594. return -EINVAL;
  595. fujitsu_hotkey->acpi_handle = device->handle;
  596. sprintf(acpi_device_name(device), "%s",
  597. ACPI_FUJITSU_HOTKEY_DEVICE_NAME);
  598. sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS);
  599. device->driver_data = fujitsu_hotkey;
  600. status = acpi_install_notify_handler(device->handle,
  601. ACPI_DEVICE_NOTIFY,
  602. acpi_fujitsu_hotkey_notify,
  603. fujitsu_hotkey);
  604. if (ACPI_FAILURE(status)) {
  605. printk(KERN_ERR "Error installing notify handler\n");
  606. error = -ENODEV;
  607. goto err_stop;
  608. }
  609. /* kfifo */
  610. spin_lock_init(&fujitsu_hotkey->fifo_lock);
  611. fujitsu_hotkey->fifo =
  612. kfifo_alloc(RINGBUFFERSIZE * sizeof(int), GFP_KERNEL,
  613. &fujitsu_hotkey->fifo_lock);
  614. if (IS_ERR(fujitsu_hotkey->fifo)) {
  615. printk(KERN_ERR "kfifo_alloc failed\n");
  616. error = PTR_ERR(fujitsu_hotkey->fifo);
  617. goto err_stop;
  618. }
  619. fujitsu_hotkey->input = input = input_allocate_device();
  620. if (!input) {
  621. error = -ENOMEM;
  622. goto err_uninstall_notify;
  623. }
  624. snprintf(fujitsu_hotkey->phys, sizeof(fujitsu_hotkey->phys),
  625. "%s/video/input0", acpi_device_hid(device));
  626. input->name = acpi_device_name(device);
  627. input->phys = fujitsu_hotkey->phys;
  628. input->id.bustype = BUS_HOST;
  629. input->id.product = 0x06;
  630. input->dev.parent = &device->dev;
  631. input->evbit[0] = BIT(EV_KEY);
  632. set_bit(fujitsu->keycode1, input->keybit);
  633. set_bit(fujitsu->keycode2, input->keybit);
  634. set_bit(fujitsu->keycode3, input->keybit);
  635. set_bit(fujitsu->keycode4, input->keybit);
  636. set_bit(KEY_UNKNOWN, input->keybit);
  637. error = input_register_device(input);
  638. if (error)
  639. goto err_free_input_dev;
  640. result = acpi_bus_get_power(fujitsu_hotkey->acpi_handle, &state);
  641. if (result) {
  642. printk(KERN_ERR "Error reading power state\n");
  643. goto end;
  644. }
  645. printk(KERN_INFO PREFIX "%s [%s] (%s)\n",
  646. acpi_device_name(device), acpi_device_bid(device),
  647. !device->power.state ? "on" : "off");
  648. fujitsu_hotkey->dev = device;
  649. if (ACPI_SUCCESS
  650. (acpi_get_handle(device->handle, METHOD_NAME__INI, &handle))) {
  651. vdbg_printk(FUJLAPTOP_DBG_INFO, "Invoking _INI\n");
  652. if (ACPI_FAILURE
  653. (acpi_evaluate_object
  654. (device->handle, METHOD_NAME__INI, NULL, NULL)))
  655. printk(KERN_ERR "_INI Method failed\n");
  656. }
  657. i = 0; /* Discard hotkey ringbuffer */
  658. while (get_irb() != 0 && (i++) < MAX_HOTKEY_RINGBUFFER_SIZE) ;
  659. vdbg_printk(FUJLAPTOP_DBG_INFO, "Discarded %i ringbuffer entries\n", i);
  660. return result;
  661. end:
  662. err_free_input_dev:
  663. input_free_device(input);
  664. err_uninstall_notify:
  665. acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
  666. acpi_fujitsu_hotkey_notify);
  667. kfifo_free(fujitsu_hotkey->fifo);
  668. err_stop:
  669. return result;
  670. }
  671. static int acpi_fujitsu_hotkey_remove(struct acpi_device *device, int type)
  672. {
  673. acpi_status status;
  674. struct fujitsu_hotkey_t *fujitsu_hotkey = NULL;
  675. if (!device || !acpi_driver_data(device))
  676. return -EINVAL;
  677. fujitsu_hotkey = acpi_driver_data(device);
  678. status = acpi_remove_notify_handler(fujitsu_hotkey->acpi_handle,
  679. ACPI_DEVICE_NOTIFY,
  680. acpi_fujitsu_hotkey_notify);
  681. fujitsu_hotkey->acpi_handle = NULL;
  682. kfifo_free(fujitsu_hotkey->fifo);
  683. return 0;
  684. }
  685. static void acpi_fujitsu_hotkey_notify(acpi_handle handle, u32 event,
  686. void *data)
  687. {
  688. struct input_dev *input;
  689. int keycode, keycode_r;
  690. unsigned int irb = 1;
  691. int i, status;
  692. input = fujitsu_hotkey->input;
  693. vdbg_printk(FUJLAPTOP_DBG_TRACE, "Hotkey event\n");
  694. switch (event) {
  695. case ACPI_FUJITSU_NOTIFY_CODE1:
  696. i = 0;
  697. while ((irb = get_irb()) != 0
  698. && (i++) < MAX_HOTKEY_RINGBUFFER_SIZE) {
  699. vdbg_printk(FUJLAPTOP_DBG_TRACE, "GIRB result [%x]\n",
  700. irb);
  701. switch (irb & 0x4ff) {
  702. case KEY1_CODE:
  703. keycode = fujitsu->keycode1;
  704. break;
  705. case KEY2_CODE:
  706. keycode = fujitsu->keycode2;
  707. break;
  708. case KEY3_CODE:
  709. keycode = fujitsu->keycode3;
  710. break;
  711. case KEY4_CODE:
  712. keycode = fujitsu->keycode4;
  713. break;
  714. case 0:
  715. keycode = 0;
  716. break;
  717. default:
  718. vdbg_printk(FUJLAPTOP_DBG_WARN,
  719. "Unknown GIRB result [%x]\n", irb);
  720. keycode = -1;
  721. break;
  722. }
  723. if (keycode > 0) {
  724. vdbg_printk(FUJLAPTOP_DBG_TRACE,
  725. "Push keycode into ringbuffer [%d]\n",
  726. keycode);
  727. status = kfifo_put(fujitsu_hotkey->fifo,
  728. (unsigned char *)&keycode,
  729. sizeof(keycode));
  730. if (status != sizeof(keycode)) {
  731. vdbg_printk(FUJLAPTOP_DBG_WARN,
  732. "Could not push keycode [0x%x]\n",
  733. keycode);
  734. } else {
  735. input_report_key(input, keycode, 1);
  736. input_sync(input);
  737. }
  738. } else if (keycode == 0) {
  739. while ((status =
  740. kfifo_get
  741. (fujitsu_hotkey->fifo, (unsigned char *)
  742. &keycode_r,
  743. sizeof
  744. (keycode_r))) == sizeof(keycode_r)) {
  745. input_report_key(input, keycode_r, 0);
  746. input_sync(input);
  747. vdbg_printk(FUJLAPTOP_DBG_TRACE,
  748. "Pop keycode from ringbuffer [%d]\n",
  749. keycode_r);
  750. }
  751. }
  752. }
  753. break;
  754. default:
  755. keycode = KEY_UNKNOWN;
  756. vdbg_printk(FUJLAPTOP_DBG_WARN,
  757. "Unsupported event [0x%x]\n", event);
  758. input_report_key(input, keycode, 1);
  759. input_sync(input);
  760. input_report_key(input, keycode, 0);
  761. input_sync(input);
  762. break;
  763. }
  764. return;
  765. }
  766. /* Initialization */
  767. static const struct acpi_device_id fujitsu_device_ids[] = {
  768. {ACPI_FUJITSU_HID, 0},
  769. {"", 0},
  770. };
  771. static struct acpi_driver acpi_fujitsu_driver = {
  772. .name = ACPI_FUJITSU_DRIVER_NAME,
  773. .class = ACPI_FUJITSU_CLASS,
  774. .ids = fujitsu_device_ids,
  775. .ops = {
  776. .add = acpi_fujitsu_add,
  777. .remove = acpi_fujitsu_remove,
  778. },
  779. };
  780. static const struct acpi_device_id fujitsu_hotkey_device_ids[] = {
  781. {ACPI_FUJITSU_HOTKEY_HID, 0},
  782. {"", 0},
  783. };
  784. static struct acpi_driver acpi_fujitsu_hotkey_driver = {
  785. .name = ACPI_FUJITSU_HOTKEY_DRIVER_NAME,
  786. .class = ACPI_FUJITSU_CLASS,
  787. .ids = fujitsu_hotkey_device_ids,
  788. .ops = {
  789. .add = acpi_fujitsu_hotkey_add,
  790. .remove = acpi_fujitsu_hotkey_remove,
  791. },
  792. };
  793. static int __init fujitsu_init(void)
  794. {
  795. int ret, result, max_brightness;
  796. if (acpi_disabled)
  797. return -ENODEV;
  798. fujitsu = kmalloc(sizeof(struct fujitsu_t), GFP_KERNEL);
  799. if (!fujitsu)
  800. return -ENOMEM;
  801. memset(fujitsu, 0, sizeof(struct fujitsu_t));
  802. fujitsu->keycode1 = KEY_PROG1;
  803. fujitsu->keycode2 = KEY_PROG2;
  804. fujitsu->keycode3 = KEY_PROG3;
  805. fujitsu->keycode4 = KEY_PROG4;
  806. dmi_check_system(fujitsu_dmi_table);
  807. result = acpi_bus_register_driver(&acpi_fujitsu_driver);
  808. if (result < 0) {
  809. ret = -ENODEV;
  810. goto fail_acpi;
  811. }
  812. /* Register platform stuff */
  813. fujitsu->pf_device = platform_device_alloc("fujitsu-laptop", -1);
  814. if (!fujitsu->pf_device) {
  815. ret = -ENOMEM;
  816. goto fail_platform_driver;
  817. }
  818. ret = platform_device_add(fujitsu->pf_device);
  819. if (ret)
  820. goto fail_platform_device1;
  821. ret =
  822. sysfs_create_group(&fujitsu->pf_device->dev.kobj,
  823. &fujitsupf_attribute_group);
  824. if (ret)
  825. goto fail_platform_device2;
  826. /* Register backlight stuff */
  827. if (!acpi_video_backlight_support()) {
  828. fujitsu->bl_device =
  829. backlight_device_register("fujitsu-laptop", NULL, NULL,
  830. &fujitsubl_ops);
  831. if (IS_ERR(fujitsu->bl_device))
  832. return PTR_ERR(fujitsu->bl_device);
  833. max_brightness = fujitsu->max_brightness;
  834. fujitsu->bl_device->props.max_brightness = max_brightness - 1;
  835. fujitsu->bl_device->props.brightness = fujitsu->brightness_level;
  836. }
  837. ret = platform_driver_register(&fujitsupf_driver);
  838. if (ret)
  839. goto fail_backlight;
  840. /* Register hotkey driver */
  841. fujitsu_hotkey = kmalloc(sizeof(struct fujitsu_hotkey_t), GFP_KERNEL);
  842. if (!fujitsu_hotkey) {
  843. ret = -ENOMEM;
  844. goto fail_hotkey;
  845. }
  846. memset(fujitsu_hotkey, 0, sizeof(struct fujitsu_hotkey_t));
  847. result = acpi_bus_register_driver(&acpi_fujitsu_hotkey_driver);
  848. if (result < 0) {
  849. ret = -ENODEV;
  850. goto fail_hotkey1;
  851. }
  852. printk(KERN_INFO "fujitsu-laptop: driver " FUJITSU_DRIVER_VERSION
  853. " successfully loaded.\n");
  854. return 0;
  855. fail_hotkey1:
  856. kfree(fujitsu_hotkey);
  857. fail_hotkey:
  858. platform_driver_unregister(&fujitsupf_driver);
  859. fail_backlight:
  860. if (fujitsu->bl_device)
  861. backlight_device_unregister(fujitsu->bl_device);
  862. fail_platform_device2:
  863. platform_device_del(fujitsu->pf_device);
  864. fail_platform_device1:
  865. platform_device_put(fujitsu->pf_device);
  866. fail_platform_driver:
  867. acpi_bus_unregister_driver(&acpi_fujitsu_driver);
  868. fail_acpi:
  869. kfree(fujitsu);
  870. return ret;
  871. }
  872. static void __exit fujitsu_cleanup(void)
  873. {
  874. sysfs_remove_group(&fujitsu->pf_device->dev.kobj,
  875. &fujitsupf_attribute_group);
  876. platform_device_unregister(fujitsu->pf_device);
  877. platform_driver_unregister(&fujitsupf_driver);
  878. if (fujitsu->bl_device)
  879. backlight_device_unregister(fujitsu->bl_device);
  880. acpi_bus_unregister_driver(&acpi_fujitsu_driver);
  881. kfree(fujitsu);
  882. acpi_bus_unregister_driver(&acpi_fujitsu_hotkey_driver);
  883. kfree(fujitsu_hotkey);
  884. printk(KERN_INFO "fujitsu-laptop: driver unloaded.\n");
  885. }
  886. module_init(fujitsu_init);
  887. module_exit(fujitsu_cleanup);
  888. module_param(use_alt_lcd_levels, uint, 0644);
  889. MODULE_PARM_DESC(use_alt_lcd_levels,
  890. "Use alternative interface for lcd_levels (needed for Lifebook s6410).");
  891. module_param(disable_brightness_keys, uint, 0644);
  892. MODULE_PARM_DESC(disable_brightness_keys,
  893. "Disable brightness keys (eg. if they are already handled by the generic ACPI_VIDEO device).");
  894. module_param(disable_brightness_adjust, uint, 0644);
  895. MODULE_PARM_DESC(disable_brightness_adjust, "Disable brightness adjustment .");
  896. #ifdef CONFIG_FUJITSU_LAPTOP_DEBUG
  897. module_param_named(debug, dbg_level, uint, 0644);
  898. MODULE_PARM_DESC(debug, "Sets debug level bit-mask");
  899. #endif
  900. MODULE_AUTHOR("Jonathan Woithe, Peter Gruber");
  901. MODULE_DESCRIPTION("Fujitsu laptop extras support");
  902. MODULE_VERSION(FUJITSU_DRIVER_VERSION);
  903. MODULE_LICENSE("GPL");
  904. MODULE_ALIAS("dmi:*:svnFUJITSUSIEMENS:*:pvr:rvnFUJITSU:rnFJNB1D3:*:cvrS6410:*");
  905. MODULE_ALIAS("dmi:*:svnFUJITSU:*:pvr:rvnFUJITSU:rnFJNB19C:*:cvrS7020:*");
  906. static struct pnp_device_id pnp_ids[] = {
  907. {.id = "FUJ02bf"},
  908. {.id = "FUJ02B1"},
  909. {.id = "FUJ02E3"},
  910. {.id = ""}
  911. };
  912. MODULE_DEVICE_TABLE(pnp, pnp_ids);