PageRenderTime 140ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/platform/x86/samsung-laptop.c

https://bitbucket.org/wisechild/galaxy-nexus
C | 882 lines | 686 code | 120 blank | 76 comment | 50 complexity | 5fddd31941ab9107314491ec4abaa0f1 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
  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 > sabi_config->min_brightness)
  305. user_brightness -= sabi_config->min_brightness;
  306. else
  307. user_brightness = 0;
  308. }
  309. return user_brightness;
  310. }
  311. static void set_brightness(u8 user_brightness)
  312. {
  313. u8 user_level = user_brightness + sabi_config->min_brightness;
  314. sabi_set_command(sabi_config->commands.set_brightness, user_level);
  315. }
  316. static int get_brightness(struct backlight_device *bd)
  317. {
  318. return (int)read_brightness();
  319. }
  320. static int update_status(struct backlight_device *bd)
  321. {
  322. set_brightness(bd->props.brightness);
  323. if (bd->props.power == FB_BLANK_UNBLANK)
  324. sabi_set_command(sabi_config->commands.set_backlight, 1);
  325. else
  326. sabi_set_command(sabi_config->commands.set_backlight, 0);
  327. return 0;
  328. }
  329. static const struct backlight_ops backlight_ops = {
  330. .get_brightness = get_brightness,
  331. .update_status = update_status,
  332. };
  333. static int rfkill_set(void *data, bool blocked)
  334. {
  335. /* Do something with blocked...*/
  336. /*
  337. * blocked == false is on
  338. * blocked == true is off
  339. */
  340. if (blocked)
  341. sabi_set_command(sabi_config->commands.set_wireless_button, 0);
  342. else
  343. sabi_set_command(sabi_config->commands.set_wireless_button, 1);
  344. return 0;
  345. }
  346. static struct rfkill_ops rfkill_ops = {
  347. .set_block = rfkill_set,
  348. };
  349. static int init_wireless(struct platform_device *sdev)
  350. {
  351. int retval;
  352. rfk = rfkill_alloc("samsung-wifi", &sdev->dev, RFKILL_TYPE_WLAN,
  353. &rfkill_ops, NULL);
  354. if (!rfk)
  355. return -ENOMEM;
  356. retval = rfkill_register(rfk);
  357. if (retval) {
  358. rfkill_destroy(rfk);
  359. return -ENODEV;
  360. }
  361. return 0;
  362. }
  363. static void destroy_wireless(void)
  364. {
  365. rfkill_unregister(rfk);
  366. rfkill_destroy(rfk);
  367. }
  368. static ssize_t get_performance_level(struct device *dev,
  369. struct device_attribute *attr, char *buf)
  370. {
  371. struct sabi_retval sretval;
  372. int retval;
  373. int i;
  374. /* Read the state */
  375. retval = sabi_get_command(sabi_config->commands.get_performance_level,
  376. &sretval);
  377. if (retval)
  378. return retval;
  379. /* The logic is backwards, yeah, lots of fun... */
  380. for (i = 0; sabi_config->performance_levels[i].name; ++i) {
  381. if (sretval.retval[0] == sabi_config->performance_levels[i].value)
  382. return sprintf(buf, "%s\n", sabi_config->performance_levels[i].name);
  383. }
  384. return sprintf(buf, "%s\n", "unknown");
  385. }
  386. static ssize_t set_performance_level(struct device *dev,
  387. struct device_attribute *attr, const char *buf,
  388. size_t count)
  389. {
  390. if (count >= 1) {
  391. int i;
  392. for (i = 0; sabi_config->performance_levels[i].name; ++i) {
  393. const struct sabi_performance_level *level =
  394. &sabi_config->performance_levels[i];
  395. if (!strncasecmp(level->name, buf, strlen(level->name))) {
  396. sabi_set_command(sabi_config->commands.set_performance_level,
  397. level->value);
  398. break;
  399. }
  400. }
  401. if (!sabi_config->performance_levels[i].name)
  402. return -EINVAL;
  403. }
  404. return count;
  405. }
  406. static DEVICE_ATTR(performance_level, S_IWUSR | S_IRUGO,
  407. get_performance_level, set_performance_level);
  408. static int __init dmi_check_cb(const struct dmi_system_id *id)
  409. {
  410. pr_info("found laptop model '%s'\n",
  411. id->ident);
  412. return 1;
  413. }
  414. static struct dmi_system_id __initdata samsung_dmi_table[] = {
  415. {
  416. .ident = "N128",
  417. .matches = {
  418. DMI_MATCH(DMI_SYS_VENDOR,
  419. "SAMSUNG ELECTRONICS CO., LTD."),
  420. DMI_MATCH(DMI_PRODUCT_NAME, "N128"),
  421. DMI_MATCH(DMI_BOARD_NAME, "N128"),
  422. },
  423. .callback = dmi_check_cb,
  424. },
  425. {
  426. .ident = "N130",
  427. .matches = {
  428. DMI_MATCH(DMI_SYS_VENDOR,
  429. "SAMSUNG ELECTRONICS CO., LTD."),
  430. DMI_MATCH(DMI_PRODUCT_NAME, "N130"),
  431. DMI_MATCH(DMI_BOARD_NAME, "N130"),
  432. },
  433. .callback = dmi_check_cb,
  434. },
  435. {
  436. .ident = "X125",
  437. .matches = {
  438. DMI_MATCH(DMI_SYS_VENDOR,
  439. "SAMSUNG ELECTRONICS CO., LTD."),
  440. DMI_MATCH(DMI_PRODUCT_NAME, "X125"),
  441. DMI_MATCH(DMI_BOARD_NAME, "X125"),
  442. },
  443. .callback = dmi_check_cb,
  444. },
  445. {
  446. .ident = "X120/X170",
  447. .matches = {
  448. DMI_MATCH(DMI_SYS_VENDOR,
  449. "SAMSUNG ELECTRONICS CO., LTD."),
  450. DMI_MATCH(DMI_PRODUCT_NAME, "X120/X170"),
  451. DMI_MATCH(DMI_BOARD_NAME, "X120/X170"),
  452. },
  453. .callback = dmi_check_cb,
  454. },
  455. {
  456. .ident = "NC10",
  457. .matches = {
  458. DMI_MATCH(DMI_SYS_VENDOR,
  459. "SAMSUNG ELECTRONICS CO., LTD."),
  460. DMI_MATCH(DMI_PRODUCT_NAME, "NC10"),
  461. DMI_MATCH(DMI_BOARD_NAME, "NC10"),
  462. },
  463. .callback = dmi_check_cb,
  464. },
  465. {
  466. .ident = "NP-Q45",
  467. .matches = {
  468. DMI_MATCH(DMI_SYS_VENDOR,
  469. "SAMSUNG ELECTRONICS CO., LTD."),
  470. DMI_MATCH(DMI_PRODUCT_NAME, "SQ45S70S"),
  471. DMI_MATCH(DMI_BOARD_NAME, "SQ45S70S"),
  472. },
  473. .callback = dmi_check_cb,
  474. },
  475. {
  476. .ident = "X360",
  477. .matches = {
  478. DMI_MATCH(DMI_SYS_VENDOR,
  479. "SAMSUNG ELECTRONICS CO., LTD."),
  480. DMI_MATCH(DMI_PRODUCT_NAME, "X360"),
  481. DMI_MATCH(DMI_BOARD_NAME, "X360"),
  482. },
  483. .callback = dmi_check_cb,
  484. },
  485. {
  486. .ident = "R410 Plus",
  487. .matches = {
  488. DMI_MATCH(DMI_SYS_VENDOR,
  489. "SAMSUNG ELECTRONICS CO., LTD."),
  490. DMI_MATCH(DMI_PRODUCT_NAME, "R410P"),
  491. DMI_MATCH(DMI_BOARD_NAME, "R460"),
  492. },
  493. .callback = dmi_check_cb,
  494. },
  495. {
  496. .ident = "R518",
  497. .matches = {
  498. DMI_MATCH(DMI_SYS_VENDOR,
  499. "SAMSUNG ELECTRONICS CO., LTD."),
  500. DMI_MATCH(DMI_PRODUCT_NAME, "R518"),
  501. DMI_MATCH(DMI_BOARD_NAME, "R518"),
  502. },
  503. .callback = dmi_check_cb,
  504. },
  505. {
  506. .ident = "R519/R719",
  507. .matches = {
  508. DMI_MATCH(DMI_SYS_VENDOR,
  509. "SAMSUNG ELECTRONICS CO., LTD."),
  510. DMI_MATCH(DMI_PRODUCT_NAME, "R519/R719"),
  511. DMI_MATCH(DMI_BOARD_NAME, "R519/R719"),
  512. },
  513. .callback = dmi_check_cb,
  514. },
  515. {
  516. .ident = "N150/N210/N220",
  517. .matches = {
  518. DMI_MATCH(DMI_SYS_VENDOR,
  519. "SAMSUNG ELECTRONICS CO., LTD."),
  520. DMI_MATCH(DMI_PRODUCT_NAME, "N150/N210/N220"),
  521. DMI_MATCH(DMI_BOARD_NAME, "N150/N210/N220"),
  522. },
  523. .callback = dmi_check_cb,
  524. },
  525. {
  526. .ident = "N150/N210/N220/N230",
  527. .matches = {
  528. DMI_MATCH(DMI_SYS_VENDOR,
  529. "SAMSUNG ELECTRONICS CO., LTD."),
  530. DMI_MATCH(DMI_PRODUCT_NAME, "N150/N210/N220/N230"),
  531. DMI_MATCH(DMI_BOARD_NAME, "N150/N210/N220/N230"),
  532. },
  533. .callback = dmi_check_cb,
  534. },
  535. {
  536. .ident = "N150P/N210P/N220P",
  537. .matches = {
  538. DMI_MATCH(DMI_SYS_VENDOR,
  539. "SAMSUNG ELECTRONICS CO., LTD."),
  540. DMI_MATCH(DMI_PRODUCT_NAME, "N150P/N210P/N220P"),
  541. DMI_MATCH(DMI_BOARD_NAME, "N150P/N210P/N220P"),
  542. },
  543. .callback = dmi_check_cb,
  544. },
  545. {
  546. .ident = "R700",
  547. .matches = {
  548. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
  549. DMI_MATCH(DMI_PRODUCT_NAME, "SR700"),
  550. DMI_MATCH(DMI_BOARD_NAME, "SR700"),
  551. },
  552. .callback = dmi_check_cb,
  553. },
  554. {
  555. .ident = "R530/R730",
  556. .matches = {
  557. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
  558. DMI_MATCH(DMI_PRODUCT_NAME, "R530/R730"),
  559. DMI_MATCH(DMI_BOARD_NAME, "R530/R730"),
  560. },
  561. .callback = dmi_check_cb,
  562. },
  563. {
  564. .ident = "NF110/NF210/NF310",
  565. .matches = {
  566. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
  567. DMI_MATCH(DMI_PRODUCT_NAME, "NF110/NF210/NF310"),
  568. DMI_MATCH(DMI_BOARD_NAME, "NF110/NF210/NF310"),
  569. },
  570. .callback = dmi_check_cb,
  571. },
  572. {
  573. .ident = "N145P/N250P/N260P",
  574. .matches = {
  575. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
  576. DMI_MATCH(DMI_PRODUCT_NAME, "N145P/N250P/N260P"),
  577. DMI_MATCH(DMI_BOARD_NAME, "N145P/N250P/N260P"),
  578. },
  579. .callback = dmi_check_cb,
  580. },
  581. {
  582. .ident = "R70/R71",
  583. .matches = {
  584. DMI_MATCH(DMI_SYS_VENDOR,
  585. "SAMSUNG ELECTRONICS CO., LTD."),
  586. DMI_MATCH(DMI_PRODUCT_NAME, "R70/R71"),
  587. DMI_MATCH(DMI_BOARD_NAME, "R70/R71"),
  588. },
  589. .callback = dmi_check_cb,
  590. },
  591. {
  592. .ident = "P460",
  593. .matches = {
  594. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
  595. DMI_MATCH(DMI_PRODUCT_NAME, "P460"),
  596. DMI_MATCH(DMI_BOARD_NAME, "P460"),
  597. },
  598. .callback = dmi_check_cb,
  599. },
  600. {
  601. .ident = "X520",
  602. .matches = {
  603. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
  604. DMI_MATCH(DMI_PRODUCT_NAME, "X520"),
  605. DMI_MATCH(DMI_BOARD_NAME, "X520"),
  606. },
  607. .callback = dmi_check_cb,
  608. },
  609. {
  610. .ident = "R528/R728",
  611. .matches = {
  612. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
  613. DMI_MATCH(DMI_PRODUCT_NAME, "R528/R728"),
  614. DMI_MATCH(DMI_BOARD_NAME, "R528/R728"),
  615. },
  616. .callback = dmi_check_cb,
  617. },
  618. { },
  619. };
  620. MODULE_DEVICE_TABLE(dmi, samsung_dmi_table);
  621. static int find_signature(void __iomem *memcheck, const char *testStr)
  622. {
  623. int i = 0;
  624. int loca;
  625. for (loca = 0; loca < 0xffff; loca++) {
  626. char temp = readb(memcheck + loca);
  627. if (temp == testStr[i]) {
  628. if (i == strlen(testStr)-1)
  629. break;
  630. ++i;
  631. } else {
  632. i = 0;
  633. }
  634. }
  635. return loca;
  636. }
  637. static int __init samsung_init(void)
  638. {
  639. struct backlight_properties props;
  640. struct sabi_retval sretval;
  641. unsigned int ifaceP;
  642. int i;
  643. int loca;
  644. int retval;
  645. mutex_init(&sabi_mutex);
  646. if (!force && !dmi_check_system(samsung_dmi_table))
  647. return -ENODEV;
  648. f0000_segment = ioremap_nocache(0xf0000, 0xffff);
  649. if (!f0000_segment) {
  650. pr_err("Can't map the segment at 0xf0000\n");
  651. return -EINVAL;
  652. }
  653. /* Try to find one of the signatures in memory to find the header */
  654. for (i = 0; sabi_configs[i].test_string != 0; ++i) {
  655. sabi_config = &sabi_configs[i];
  656. loca = find_signature(f0000_segment, sabi_config->test_string);
  657. if (loca != 0xffff)
  658. break;
  659. }
  660. if (loca == 0xffff) {
  661. pr_err("This computer does not support SABI\n");
  662. goto error_no_signature;
  663. }
  664. /* point to the SMI port Number */
  665. loca += 1;
  666. sabi = (f0000_segment + loca);
  667. if (debug) {
  668. printk(KERN_DEBUG "This computer supports SABI==%x\n",
  669. loca + 0xf0000 - 6);
  670. printk(KERN_DEBUG "SABI header:\n");
  671. printk(KERN_DEBUG " SMI Port Number = 0x%04x\n",
  672. readw(sabi + sabi_config->header_offsets.port));
  673. printk(KERN_DEBUG " SMI Interface Function = 0x%02x\n",
  674. readb(sabi + sabi_config->header_offsets.iface_func));
  675. printk(KERN_DEBUG " SMI enable memory buffer = 0x%02x\n",
  676. readb(sabi + sabi_config->header_offsets.en_mem));
  677. printk(KERN_DEBUG " SMI restore memory buffer = 0x%02x\n",
  678. readb(sabi + sabi_config->header_offsets.re_mem));
  679. printk(KERN_DEBUG " SABI data offset = 0x%04x\n",
  680. readw(sabi + sabi_config->header_offsets.data_offset));
  681. printk(KERN_DEBUG " SABI data segment = 0x%04x\n",
  682. readw(sabi + sabi_config->header_offsets.data_segment));
  683. }
  684. /* Get a pointer to the SABI Interface */
  685. ifaceP = (readw(sabi + sabi_config->header_offsets.data_segment) & 0x0ffff) << 4;
  686. ifaceP += readw(sabi + sabi_config->header_offsets.data_offset) & 0x0ffff;
  687. sabi_iface = ioremap_nocache(ifaceP, 16);
  688. if (!sabi_iface) {
  689. pr_err("Can't remap %x\n", ifaceP);
  690. goto error_no_signature;
  691. }
  692. if (debug) {
  693. printk(KERN_DEBUG "ifaceP = 0x%08x\n", ifaceP);
  694. printk(KERN_DEBUG "sabi_iface = %p\n", sabi_iface);
  695. test_backlight();
  696. test_wireless();
  697. retval = sabi_get_command(sabi_config->commands.get_brightness,
  698. &sretval);
  699. printk(KERN_DEBUG "brightness = 0x%02x\n", sretval.retval[0]);
  700. }
  701. /* Turn on "Linux" mode in the BIOS */
  702. if (sabi_config->commands.set_linux != 0xff) {
  703. retval = sabi_set_command(sabi_config->commands.set_linux,
  704. 0x81);
  705. if (retval) {
  706. pr_warn("Linux mode was not set!\n");
  707. goto error_no_platform;
  708. }
  709. }
  710. /* knock up a platform device to hang stuff off of */
  711. sdev = platform_device_register_simple("samsung", -1, NULL, 0);
  712. if (IS_ERR(sdev))
  713. goto error_no_platform;
  714. /* create a backlight device to talk to this one */
  715. memset(&props, 0, sizeof(struct backlight_properties));
  716. props.type = BACKLIGHT_PLATFORM;
  717. props.max_brightness = sabi_config->max_brightness -
  718. sabi_config->min_brightness;
  719. backlight_device = backlight_device_register("samsung", &sdev->dev,
  720. NULL, &backlight_ops,
  721. &props);
  722. if (IS_ERR(backlight_device))
  723. goto error_no_backlight;
  724. backlight_device->props.brightness = read_brightness();
  725. backlight_device->props.power = FB_BLANK_UNBLANK;
  726. backlight_update_status(backlight_device);
  727. retval = init_wireless(sdev);
  728. if (retval)
  729. goto error_no_rfk;
  730. retval = device_create_file(&sdev->dev, &dev_attr_performance_level);
  731. if (retval)
  732. goto error_file_create;
  733. return 0;
  734. error_file_create:
  735. destroy_wireless();
  736. error_no_rfk:
  737. backlight_device_unregister(backlight_device);
  738. error_no_backlight:
  739. platform_device_unregister(sdev);
  740. error_no_platform:
  741. iounmap(sabi_iface);
  742. error_no_signature:
  743. iounmap(f0000_segment);
  744. return -EINVAL;
  745. }
  746. static void __exit samsung_exit(void)
  747. {
  748. /* Turn off "Linux" mode in the BIOS */
  749. if (sabi_config->commands.set_linux != 0xff)
  750. sabi_set_command(sabi_config->commands.set_linux, 0x80);
  751. device_remove_file(&sdev->dev, &dev_attr_performance_level);
  752. backlight_device_unregister(backlight_device);
  753. destroy_wireless();
  754. iounmap(sabi_iface);
  755. iounmap(f0000_segment);
  756. platform_device_unregister(sdev);
  757. }
  758. module_init(samsung_init);
  759. module_exit(samsung_exit);
  760. MODULE_AUTHOR("Greg Kroah-Hartman <gregkh@suse.de>");
  761. MODULE_DESCRIPTION("Samsung Backlight driver");
  762. MODULE_LICENSE("GPL");