samsung-laptop.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832
  1. /*
  2. * Samsung Laptop driver
  3. *
  4. * Copyright (C) 2009,2011 Greg Kroah-Hartman (gregkh@suse.de)
  5. * Copyright (C) 2009,2011 Novell Inc.
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2 as published by
  9. * the Free Software Foundation.
  10. *
  11. */
  12. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  13. #include <linux/kernel.h>
  14. #include <linux/init.h>
  15. #include <linux/module.h>
  16. #include <linux/delay.h>
  17. #include <linux/pci.h>
  18. #include <linux/backlight.h>
  19. #include <linux/fb.h>
  20. #include <linux/dmi.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/rfkill.h>
  23. /*
  24. * This driver is needed because a number of Samsung laptops do not hook
  25. * their control settings through ACPI. So we have to poke around in the
  26. * BIOS to do things like brightness values, and "special" key controls.
  27. */
  28. /*
  29. * We have 0 - 8 as valid brightness levels. The specs say that level 0 should
  30. * be reserved by the BIOS (which really doesn't make much sense), we tell
  31. * userspace that the value is 0 - 7 and then just tell the hardware 1 - 8
  32. */
  33. #define MAX_BRIGHT 0x07
  34. #define SABI_IFACE_MAIN 0x00
  35. #define SABI_IFACE_SUB 0x02
  36. #define SABI_IFACE_COMPLETE 0x04
  37. #define SABI_IFACE_DATA 0x05
  38. /* Structure to get data back to the calling function */
  39. struct sabi_retval {
  40. u8 retval[20];
  41. };
  42. struct sabi_header_offsets {
  43. u8 port;
  44. u8 re_mem;
  45. u8 iface_func;
  46. u8 en_mem;
  47. u8 data_offset;
  48. u8 data_segment;
  49. };
  50. struct sabi_commands {
  51. /*
  52. * Brightness is 0 - 8, as described above.
  53. * Value 0 is for the BIOS to use
  54. */
  55. u8 get_brightness;
  56. u8 set_brightness;
  57. /*
  58. * first byte:
  59. * 0x00 - wireless is off
  60. * 0x01 - wireless is on
  61. * second byte:
  62. * 0x02 - 3G is off
  63. * 0x03 - 3G is on
  64. * TODO, verify 3G is correct, that doesn't seem right...
  65. */
  66. u8 get_wireless_button;
  67. u8 set_wireless_button;
  68. /* 0 is off, 1 is on */
  69. u8 get_backlight;
  70. u8 set_backlight;
  71. /*
  72. * 0x80 or 0x00 - no action
  73. * 0x81 - recovery key pressed
  74. */
  75. u8 get_recovery_mode;
  76. u8 set_recovery_mode;
  77. /*
  78. * on seclinux: 0 is low, 1 is high,
  79. * on swsmi: 0 is normal, 1 is silent, 2 is turbo
  80. */
  81. u8 get_performance_level;
  82. u8 set_performance_level;
  83. /*
  84. * Tell the BIOS that Linux is running on this machine.
  85. * 81 is on, 80 is off
  86. */
  87. u8 set_linux;
  88. };
  89. struct sabi_performance_level {
  90. const char *name;
  91. u8 value;
  92. };
  93. struct sabi_config {
  94. const char *test_string;
  95. u16 main_function;
  96. const struct sabi_header_offsets header_offsets;
  97. const struct sabi_commands commands;
  98. const struct sabi_performance_level performance_levels[4];
  99. u8 min_brightness;
  100. u8 max_brightness;
  101. };
  102. static const struct sabi_config sabi_configs[] = {
  103. {
  104. .test_string = "SECLINUX",
  105. .main_function = 0x4c49,
  106. .header_offsets = {
  107. .port = 0x00,
  108. .re_mem = 0x02,
  109. .iface_func = 0x03,
  110. .en_mem = 0x04,
  111. .data_offset = 0x05,
  112. .data_segment = 0x07,
  113. },
  114. .commands = {
  115. .get_brightness = 0x00,
  116. .set_brightness = 0x01,
  117. .get_wireless_button = 0x02,
  118. .set_wireless_button = 0x03,
  119. .get_backlight = 0x04,
  120. .set_backlight = 0x05,
  121. .get_recovery_mode = 0x06,
  122. .set_recovery_mode = 0x07,
  123. .get_performance_level = 0x08,
  124. .set_performance_level = 0x09,
  125. .set_linux = 0x0a,
  126. },
  127. .performance_levels = {
  128. {
  129. .name = "silent",
  130. .value = 0,
  131. },
  132. {
  133. .name = "normal",
  134. .value = 1,
  135. },
  136. { },
  137. },
  138. .min_brightness = 1,
  139. .max_brightness = 8,
  140. },
  141. {
  142. .test_string = "SwSmi@",
  143. .main_function = 0x5843,
  144. .header_offsets = {
  145. .port = 0x00,
  146. .re_mem = 0x04,
  147. .iface_func = 0x02,
  148. .en_mem = 0x03,
  149. .data_offset = 0x05,
  150. .data_segment = 0x07,
  151. },
  152. .commands = {
  153. .get_brightness = 0x10,
  154. .set_brightness = 0x11,
  155. .get_wireless_button = 0x12,
  156. .set_wireless_button = 0x13,
  157. .get_backlight = 0x2d,
  158. .set_backlight = 0x2e,
  159. .get_recovery_mode = 0xff,
  160. .set_recovery_mode = 0xff,
  161. .get_performance_level = 0x31,
  162. .set_performance_level = 0x32,
  163. .set_linux = 0xff,
  164. },
  165. .performance_levels = {
  166. {
  167. .name = "normal",
  168. .value = 0,
  169. },
  170. {
  171. .name = "silent",
  172. .value = 1,
  173. },
  174. {
  175. .name = "overclock",
  176. .value = 2,
  177. },
  178. { },
  179. },
  180. .min_brightness = 0,
  181. .max_brightness = 8,
  182. },
  183. { },
  184. };
  185. static const struct sabi_config *sabi_config;
  186. static void __iomem *sabi;
  187. static void __iomem *sabi_iface;
  188. static void __iomem *f0000_segment;
  189. static struct backlight_device *backlight_device;
  190. static struct mutex sabi_mutex;
  191. static struct platform_device *sdev;
  192. static struct rfkill *rfk;
  193. static int force;
  194. module_param(force, bool, 0);
  195. MODULE_PARM_DESC(force,
  196. "Disable the DMI check and forces the driver to be loaded");
  197. static int debug;
  198. module_param(debug, bool, S_IRUGO | S_IWUSR);
  199. MODULE_PARM_DESC(debug, "Debug enabled or not");
  200. static int sabi_get_command(u8 command, struct sabi_retval *sretval)
  201. {
  202. int retval = 0;
  203. u16 port = readw(sabi + sabi_config->header_offsets.port);
  204. u8 complete, iface_data;
  205. mutex_lock(&sabi_mutex);
  206. /* enable memory to be able to write to it */
  207. outb(readb(sabi + sabi_config->header_offsets.en_mem), port);
  208. /* write out the command */
  209. writew(sabi_config->main_function, sabi_iface + SABI_IFACE_MAIN);
  210. writew(command, sabi_iface + SABI_IFACE_SUB);
  211. writeb(0, sabi_iface + SABI_IFACE_COMPLETE);
  212. outb(readb(sabi + sabi_config->header_offsets.iface_func), port);
  213. /* write protect memory to make it safe */
  214. outb(readb(sabi + sabi_config->header_offsets.re_mem), port);
  215. /* see if the command actually succeeded */
  216. complete = readb(sabi_iface + SABI_IFACE_COMPLETE);
  217. iface_data = readb(sabi_iface + SABI_IFACE_DATA);
  218. if (complete != 0xaa || iface_data == 0xff) {
  219. pr_warn("SABI get command 0x%02x failed with completion flag 0x%02x and data 0x%02x\n",
  220. command, complete, iface_data);
  221. retval = -EINVAL;
  222. goto exit;
  223. }
  224. /*
  225. * Save off the data into a structure so the caller use it.
  226. * Right now we only want the first 4 bytes,
  227. * There are commands that need more, but not for the ones we
  228. * currently care about.
  229. */
  230. sretval->retval[0] = readb(sabi_iface + SABI_IFACE_DATA);
  231. sretval->retval[1] = readb(sabi_iface + SABI_IFACE_DATA + 1);
  232. sretval->retval[2] = readb(sabi_iface + SABI_IFACE_DATA + 2);
  233. sretval->retval[3] = readb(sabi_iface + SABI_IFACE_DATA + 3);
  234. exit:
  235. mutex_unlock(&sabi_mutex);
  236. return retval;
  237. }
  238. static int sabi_set_command(u8 command, u8 data)
  239. {
  240. int retval = 0;
  241. u16 port = readw(sabi + sabi_config->header_offsets.port);
  242. u8 complete, iface_data;
  243. mutex_lock(&sabi_mutex);
  244. /* enable memory to be able to write to it */
  245. outb(readb(sabi + sabi_config->header_offsets.en_mem), port);
  246. /* write out the command */
  247. writew(sabi_config->main_function, sabi_iface + SABI_IFACE_MAIN);
  248. writew(command, sabi_iface + SABI_IFACE_SUB);
  249. writeb(0, sabi_iface + SABI_IFACE_COMPLETE);
  250. writeb(data, sabi_iface + SABI_IFACE_DATA);
  251. outb(readb(sabi + sabi_config->header_offsets.iface_func), port);
  252. /* write protect memory to make it safe */
  253. outb(readb(sabi + sabi_config->header_offsets.re_mem), port);
  254. /* see if the command actually succeeded */
  255. complete = readb(sabi_iface + SABI_IFACE_COMPLETE);
  256. iface_data = readb(sabi_iface + SABI_IFACE_DATA);
  257. if (complete != 0xaa || iface_data == 0xff) {
  258. pr_warn("SABI set command 0x%02x failed with completion flag 0x%02x and data 0x%02x\n",
  259. command, complete, iface_data);
  260. retval = -EINVAL;
  261. }
  262. mutex_unlock(&sabi_mutex);
  263. return retval;
  264. }
  265. static void test_backlight(void)
  266. {
  267. struct sabi_retval sretval;
  268. sabi_get_command(sabi_config->commands.get_backlight, &sretval);
  269. printk(KERN_DEBUG "backlight = 0x%02x\n", sretval.retval[0]);
  270. sabi_set_command(sabi_config->commands.set_backlight, 0);
  271. printk(KERN_DEBUG "backlight should be off\n");
  272. sabi_get_command(sabi_config->commands.get_backlight, &sretval);
  273. printk(KERN_DEBUG "backlight = 0x%02x\n", sretval.retval[0]);
  274. msleep(1000);
  275. sabi_set_command(sabi_config->commands.set_backlight, 1);
  276. printk(KERN_DEBUG "backlight should be on\n");
  277. sabi_get_command(sabi_config->commands.get_backlight, &sretval);
  278. printk(KERN_DEBUG "backlight = 0x%02x\n", sretval.retval[0]);
  279. }
  280. static void test_wireless(void)
  281. {
  282. struct sabi_retval sretval;
  283. sabi_get_command(sabi_config->commands.get_wireless_button, &sretval);
  284. printk(KERN_DEBUG "wireless led = 0x%02x\n", sretval.retval[0]);
  285. sabi_set_command(sabi_config->commands.set_wireless_button, 0);
  286. printk(KERN_DEBUG "wireless led should be off\n");
  287. sabi_get_command(sabi_config->commands.get_wireless_button, &sretval);
  288. printk(KERN_DEBUG "wireless led = 0x%02x\n", sretval.retval[0]);
  289. msleep(1000);
  290. sabi_set_command(sabi_config->commands.set_wireless_button, 1);
  291. printk(KERN_DEBUG "wireless led should be on\n");
  292. sabi_get_command(sabi_config->commands.get_wireless_button, &sretval);
  293. printk(KERN_DEBUG "wireless led = 0x%02x\n", sretval.retval[0]);
  294. }
  295. static u8 read_brightness(void)
  296. {
  297. struct sabi_retval sretval;
  298. int user_brightness = 0;
  299. int retval;
  300. retval = sabi_get_command(sabi_config->commands.get_brightness,
  301. &sretval);
  302. if (!retval) {
  303. user_brightness = sretval.retval[0];
  304. if (user_brightness != 0)
  305. user_brightness -= sabi_config->min_brightness;
  306. }
  307. return user_brightness;
  308. }
  309. static void set_brightness(u8 user_brightness)
  310. {
  311. u8 user_level = user_brightness - sabi_config->min_brightness;
  312. sabi_set_command(sabi_config->commands.set_brightness, user_level);
  313. }
  314. static int get_brightness(struct backlight_device *bd)
  315. {
  316. return (int)read_brightness();
  317. }
  318. static int update_status(struct backlight_device *bd)
  319. {
  320. set_brightness(bd->props.brightness);
  321. if (bd->props.power == FB_BLANK_UNBLANK)
  322. sabi_set_command(sabi_config->commands.set_backlight, 1);
  323. else
  324. sabi_set_command(sabi_config->commands.set_backlight, 0);
  325. return 0;
  326. }
  327. static const struct backlight_ops backlight_ops = {
  328. .get_brightness = get_brightness,
  329. .update_status = update_status,
  330. };
  331. static int rfkill_set(void *data, bool blocked)
  332. {
  333. /* Do something with blocked...*/
  334. /*
  335. * blocked == false is on
  336. * blocked == true is off
  337. */
  338. if (blocked)
  339. sabi_set_command(sabi_config->commands.set_wireless_button, 0);
  340. else
  341. sabi_set_command(sabi_config->commands.set_wireless_button, 1);
  342. return 0;
  343. }
  344. static struct rfkill_ops rfkill_ops = {
  345. .set_block = rfkill_set,
  346. };
  347. static int init_wireless(struct platform_device *sdev)
  348. {
  349. int retval;
  350. rfk = rfkill_alloc("samsung-wifi", &sdev->dev, RFKILL_TYPE_WLAN,
  351. &rfkill_ops, NULL);
  352. if (!rfk)
  353. return -ENOMEM;
  354. retval = rfkill_register(rfk);
  355. if (retval) {
  356. rfkill_destroy(rfk);
  357. return -ENODEV;
  358. }
  359. return 0;
  360. }
  361. static void destroy_wireless(void)
  362. {
  363. rfkill_unregister(rfk);
  364. rfkill_destroy(rfk);
  365. }
  366. static ssize_t get_performance_level(struct device *dev,
  367. struct device_attribute *attr, char *buf)
  368. {
  369. struct sabi_retval sretval;
  370. int retval;
  371. int i;
  372. /* Read the state */
  373. retval = sabi_get_command(sabi_config->commands.get_performance_level,
  374. &sretval);
  375. if (retval)
  376. return retval;
  377. /* The logic is backwards, yeah, lots of fun... */
  378. for (i = 0; sabi_config->performance_levels[i].name; ++i) {
  379. if (sretval.retval[0] == sabi_config->performance_levels[i].value)
  380. return sprintf(buf, "%s\n", sabi_config->performance_levels[i].name);
  381. }
  382. return sprintf(buf, "%s\n", "unknown");
  383. }
  384. static ssize_t set_performance_level(struct device *dev,
  385. struct device_attribute *attr, const char *buf,
  386. size_t count)
  387. {
  388. if (count >= 1) {
  389. int i;
  390. for (i = 0; sabi_config->performance_levels[i].name; ++i) {
  391. const struct sabi_performance_level *level =
  392. &sabi_config->performance_levels[i];
  393. if (!strncasecmp(level->name, buf, strlen(level->name))) {
  394. sabi_set_command(sabi_config->commands.set_performance_level,
  395. level->value);
  396. break;
  397. }
  398. }
  399. if (!sabi_config->performance_levels[i].name)
  400. return -EINVAL;
  401. }
  402. return count;
  403. }
  404. static DEVICE_ATTR(performance_level, S_IWUSR | S_IRUGO,
  405. get_performance_level, set_performance_level);
  406. static int __init dmi_check_cb(const struct dmi_system_id *id)
  407. {
  408. pr_info("found laptop model '%s'\n",
  409. id->ident);
  410. return 1;
  411. }
  412. static struct dmi_system_id __initdata samsung_dmi_table[] = {
  413. {
  414. .ident = "N128",
  415. .matches = {
  416. DMI_MATCH(DMI_SYS_VENDOR,
  417. "SAMSUNG ELECTRONICS CO., LTD."),
  418. DMI_MATCH(DMI_PRODUCT_NAME, "N128"),
  419. DMI_MATCH(DMI_BOARD_NAME, "N128"),
  420. },
  421. .callback = dmi_check_cb,
  422. },
  423. {
  424. .ident = "N130",
  425. .matches = {
  426. DMI_MATCH(DMI_SYS_VENDOR,
  427. "SAMSUNG ELECTRONICS CO., LTD."),
  428. DMI_MATCH(DMI_PRODUCT_NAME, "N130"),
  429. DMI_MATCH(DMI_BOARD_NAME, "N130"),
  430. },
  431. .callback = dmi_check_cb,
  432. },
  433. {
  434. .ident = "X125",
  435. .matches = {
  436. DMI_MATCH(DMI_SYS_VENDOR,
  437. "SAMSUNG ELECTRONICS CO., LTD."),
  438. DMI_MATCH(DMI_PRODUCT_NAME, "X125"),
  439. DMI_MATCH(DMI_BOARD_NAME, "X125"),
  440. },
  441. .callback = dmi_check_cb,
  442. },
  443. {
  444. .ident = "X120/X170",
  445. .matches = {
  446. DMI_MATCH(DMI_SYS_VENDOR,
  447. "SAMSUNG ELECTRONICS CO., LTD."),
  448. DMI_MATCH(DMI_PRODUCT_NAME, "X120/X170"),
  449. DMI_MATCH(DMI_BOARD_NAME, "X120/X170"),
  450. },
  451. .callback = dmi_check_cb,
  452. },
  453. {
  454. .ident = "NC10",
  455. .matches = {
  456. DMI_MATCH(DMI_SYS_VENDOR,
  457. "SAMSUNG ELECTRONICS CO., LTD."),
  458. DMI_MATCH(DMI_PRODUCT_NAME, "NC10"),
  459. DMI_MATCH(DMI_BOARD_NAME, "NC10"),
  460. },
  461. .callback = dmi_check_cb,
  462. },
  463. {
  464. .ident = "NP-Q45",
  465. .matches = {
  466. DMI_MATCH(DMI_SYS_VENDOR,
  467. "SAMSUNG ELECTRONICS CO., LTD."),
  468. DMI_MATCH(DMI_PRODUCT_NAME, "SQ45S70S"),
  469. DMI_MATCH(DMI_BOARD_NAME, "SQ45S70S"),
  470. },
  471. .callback = dmi_check_cb,
  472. },
  473. {
  474. .ident = "X360",
  475. .matches = {
  476. DMI_MATCH(DMI_SYS_VENDOR,
  477. "SAMSUNG ELECTRONICS CO., LTD."),
  478. DMI_MATCH(DMI_PRODUCT_NAME, "X360"),
  479. DMI_MATCH(DMI_BOARD_NAME, "X360"),
  480. },
  481. .callback = dmi_check_cb,
  482. },
  483. {
  484. .ident = "R518",
  485. .matches = {
  486. DMI_MATCH(DMI_SYS_VENDOR,
  487. "SAMSUNG ELECTRONICS CO., LTD."),
  488. DMI_MATCH(DMI_PRODUCT_NAME, "R518"),
  489. DMI_MATCH(DMI_BOARD_NAME, "R518"),
  490. },
  491. .callback = dmi_check_cb,
  492. },
  493. {
  494. .ident = "R519/R719",
  495. .matches = {
  496. DMI_MATCH(DMI_SYS_VENDOR,
  497. "SAMSUNG ELECTRONICS CO., LTD."),
  498. DMI_MATCH(DMI_PRODUCT_NAME, "R519/R719"),
  499. DMI_MATCH(DMI_BOARD_NAME, "R519/R719"),
  500. },
  501. .callback = dmi_check_cb,
  502. },
  503. {
  504. .ident = "N150/N210/N220",
  505. .matches = {
  506. DMI_MATCH(DMI_SYS_VENDOR,
  507. "SAMSUNG ELECTRONICS CO., LTD."),
  508. DMI_MATCH(DMI_PRODUCT_NAME, "N150/N210/N220"),
  509. DMI_MATCH(DMI_BOARD_NAME, "N150/N210/N220"),
  510. },
  511. .callback = dmi_check_cb,
  512. },
  513. {
  514. .ident = "N150P/N210P/N220P",
  515. .matches = {
  516. DMI_MATCH(DMI_SYS_VENDOR,
  517. "SAMSUNG ELECTRONICS CO., LTD."),
  518. DMI_MATCH(DMI_PRODUCT_NAME, "N150P/N210P/N220P"),
  519. DMI_MATCH(DMI_BOARD_NAME, "N150P/N210P/N220P"),
  520. },
  521. .callback = dmi_check_cb,
  522. },
  523. {
  524. .ident = "R530/R730",
  525. .matches = {
  526. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
  527. DMI_MATCH(DMI_PRODUCT_NAME, "R530/R730"),
  528. DMI_MATCH(DMI_BOARD_NAME, "R530/R730"),
  529. },
  530. .callback = dmi_check_cb,
  531. },
  532. {
  533. .ident = "NF110/NF210/NF310",
  534. .matches = {
  535. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
  536. DMI_MATCH(DMI_PRODUCT_NAME, "NF110/NF210/NF310"),
  537. DMI_MATCH(DMI_BOARD_NAME, "NF110/NF210/NF310"),
  538. },
  539. .callback = dmi_check_cb,
  540. },
  541. {
  542. .ident = "N145P/N250P/N260P",
  543. .matches = {
  544. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
  545. DMI_MATCH(DMI_PRODUCT_NAME, "N145P/N250P/N260P"),
  546. DMI_MATCH(DMI_BOARD_NAME, "N145P/N250P/N260P"),
  547. },
  548. .callback = dmi_check_cb,
  549. },
  550. {
  551. .ident = "R70/R71",
  552. .matches = {
  553. DMI_MATCH(DMI_SYS_VENDOR,
  554. "SAMSUNG ELECTRONICS CO., LTD."),
  555. DMI_MATCH(DMI_PRODUCT_NAME, "R70/R71"),
  556. DMI_MATCH(DMI_BOARD_NAME, "R70/R71"),
  557. },
  558. .callback = dmi_check_cb,
  559. },
  560. {
  561. .ident = "P460",
  562. .matches = {
  563. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
  564. DMI_MATCH(DMI_PRODUCT_NAME, "P460"),
  565. DMI_MATCH(DMI_BOARD_NAME, "P460"),
  566. },
  567. .callback = dmi_check_cb,
  568. },
  569. { },
  570. };
  571. MODULE_DEVICE_TABLE(dmi, samsung_dmi_table);
  572. static int find_signature(void __iomem *memcheck, const char *testStr)
  573. {
  574. int i = 0;
  575. int loca;
  576. for (loca = 0; loca < 0xffff; loca++) {
  577. char temp = readb(memcheck + loca);
  578. if (temp == testStr[i]) {
  579. if (i == strlen(testStr)-1)
  580. break;
  581. ++i;
  582. } else {
  583. i = 0;
  584. }
  585. }
  586. return loca;
  587. }
  588. static int __init samsung_init(void)
  589. {
  590. struct backlight_properties props;
  591. struct sabi_retval sretval;
  592. unsigned int ifaceP;
  593. int i;
  594. int loca;
  595. int retval;
  596. mutex_init(&sabi_mutex);
  597. if (!force && !dmi_check_system(samsung_dmi_table))
  598. return -ENODEV;
  599. f0000_segment = ioremap_nocache(0xf0000, 0xffff);
  600. if (!f0000_segment) {
  601. pr_err("Can't map the segment at 0xf0000\n");
  602. return -EINVAL;
  603. }
  604. /* Try to find one of the signatures in memory to find the header */
  605. for (i = 0; sabi_configs[i].test_string != 0; ++i) {
  606. sabi_config = &sabi_configs[i];
  607. loca = find_signature(f0000_segment, sabi_config->test_string);
  608. if (loca != 0xffff)
  609. break;
  610. }
  611. if (loca == 0xffff) {
  612. pr_err("This computer does not support SABI\n");
  613. goto error_no_signature;
  614. }
  615. /* point to the SMI port Number */
  616. loca += 1;
  617. sabi = (f0000_segment + loca);
  618. if (debug) {
  619. printk(KERN_DEBUG "This computer supports SABI==%x\n",
  620. loca + 0xf0000 - 6);
  621. printk(KERN_DEBUG "SABI header:\n");
  622. printk(KERN_DEBUG " SMI Port Number = 0x%04x\n",
  623. readw(sabi + sabi_config->header_offsets.port));
  624. printk(KERN_DEBUG " SMI Interface Function = 0x%02x\n",
  625. readb(sabi + sabi_config->header_offsets.iface_func));
  626. printk(KERN_DEBUG " SMI enable memory buffer = 0x%02x\n",
  627. readb(sabi + sabi_config->header_offsets.en_mem));
  628. printk(KERN_DEBUG " SMI restore memory buffer = 0x%02x\n",
  629. readb(sabi + sabi_config->header_offsets.re_mem));
  630. printk(KERN_DEBUG " SABI data offset = 0x%04x\n",
  631. readw(sabi + sabi_config->header_offsets.data_offset));
  632. printk(KERN_DEBUG " SABI data segment = 0x%04x\n",
  633. readw(sabi + sabi_config->header_offsets.data_segment));
  634. }
  635. /* Get a pointer to the SABI Interface */
  636. ifaceP = (readw(sabi + sabi_config->header_offsets.data_segment) & 0x0ffff) << 4;
  637. ifaceP += readw(sabi + sabi_config->header_offsets.data_offset) & 0x0ffff;
  638. sabi_iface = ioremap_nocache(ifaceP, 16);
  639. if (!sabi_iface) {
  640. pr_err("Can't remap %x\n", ifaceP);
  641. goto exit;
  642. }
  643. if (debug) {
  644. printk(KERN_DEBUG "ifaceP = 0x%08x\n", ifaceP);
  645. printk(KERN_DEBUG "sabi_iface = %p\n", sabi_iface);
  646. test_backlight();
  647. test_wireless();
  648. retval = sabi_get_command(sabi_config->commands.get_brightness,
  649. &sretval);
  650. printk(KERN_DEBUG "brightness = 0x%02x\n", sretval.retval[0]);
  651. }
  652. /* Turn on "Linux" mode in the BIOS */
  653. if (sabi_config->commands.set_linux != 0xff) {
  654. retval = sabi_set_command(sabi_config->commands.set_linux,
  655. 0x81);
  656. if (retval) {
  657. pr_warn("Linux mode was not set!\n");
  658. goto error_no_platform;
  659. }
  660. }
  661. /* knock up a platform device to hang stuff off of */
  662. sdev = platform_device_register_simple("samsung", -1, NULL, 0);
  663. if (IS_ERR(sdev))
  664. goto error_no_platform;
  665. /* create a backlight device to talk to this one */
  666. memset(&props, 0, sizeof(struct backlight_properties));
  667. props.max_brightness = sabi_config->max_brightness;
  668. backlight_device = backlight_device_register("samsung", &sdev->dev,
  669. NULL, &backlight_ops,
  670. &props);
  671. if (IS_ERR(backlight_device))
  672. goto error_no_backlight;
  673. backlight_device->props.brightness = read_brightness();
  674. backlight_device->props.power = FB_BLANK_UNBLANK;
  675. backlight_update_status(backlight_device);
  676. retval = init_wireless(sdev);
  677. if (retval)
  678. goto error_no_rfk;
  679. retval = device_create_file(&sdev->dev, &dev_attr_performance_level);
  680. if (retval)
  681. goto error_file_create;
  682. exit:
  683. return 0;
  684. error_file_create:
  685. destroy_wireless();
  686. error_no_rfk:
  687. backlight_device_unregister(backlight_device);
  688. error_no_backlight:
  689. platform_device_unregister(sdev);
  690. error_no_platform:
  691. iounmap(sabi_iface);
  692. error_no_signature:
  693. iounmap(f0000_segment);
  694. return -EINVAL;
  695. }
  696. static void __exit samsung_exit(void)
  697. {
  698. /* Turn off "Linux" mode in the BIOS */
  699. if (sabi_config->commands.set_linux != 0xff)
  700. sabi_set_command(sabi_config->commands.set_linux, 0x80);
  701. device_remove_file(&sdev->dev, &dev_attr_performance_level);
  702. backlight_device_unregister(backlight_device);
  703. destroy_wireless();
  704. iounmap(sabi_iface);
  705. iounmap(f0000_segment);
  706. platform_device_unregister(sdev);
  707. }
  708. module_init(samsung_init);
  709. module_exit(samsung_exit);
  710. MODULE_AUTHOR("Greg Kroah-Hartman <gregkh@suse.de>");
  711. MODULE_DESCRIPTION("Samsung Backlight driver");
  712. MODULE_LICENSE("GPL");