fujitsu-laptop.c 35 KB

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