samsung-laptop.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917
  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 bool has_stepping_quirk;
  194. static int force;
  195. module_param(force, bool, 0);
  196. MODULE_PARM_DESC(force,
  197. "Disable the DMI check and forces the driver to be loaded");
  198. static int debug;
  199. module_param(debug, bool, S_IRUGO | S_IWUSR);
  200. MODULE_PARM_DESC(debug, "Debug enabled or not");
  201. static int sabi_get_command(u8 command, struct sabi_retval *sretval)
  202. {
  203. int retval = 0;
  204. u16 port = readw(sabi + sabi_config->header_offsets.port);
  205. u8 complete, iface_data;
  206. mutex_lock(&sabi_mutex);
  207. /* enable memory to be able to write to it */
  208. outb(readb(sabi + sabi_config->header_offsets.en_mem), port);
  209. /* write out the command */
  210. writew(sabi_config->main_function, sabi_iface + SABI_IFACE_MAIN);
  211. writew(command, sabi_iface + SABI_IFACE_SUB);
  212. writeb(0, sabi_iface + SABI_IFACE_COMPLETE);
  213. outb(readb(sabi + sabi_config->header_offsets.iface_func), port);
  214. /* write protect memory to make it safe */
  215. outb(readb(sabi + sabi_config->header_offsets.re_mem), port);
  216. /* see if the command actually succeeded */
  217. complete = readb(sabi_iface + SABI_IFACE_COMPLETE);
  218. iface_data = readb(sabi_iface + SABI_IFACE_DATA);
  219. if (complete != 0xaa || iface_data == 0xff) {
  220. pr_warn("SABI get command 0x%02x failed with completion flag 0x%02x and data 0x%02x\n",
  221. command, complete, iface_data);
  222. retval = -EINVAL;
  223. goto exit;
  224. }
  225. /*
  226. * Save off the data into a structure so the caller use it.
  227. * Right now we only want the first 4 bytes,
  228. * There are commands that need more, but not for the ones we
  229. * currently care about.
  230. */
  231. sretval->retval[0] = readb(sabi_iface + SABI_IFACE_DATA);
  232. sretval->retval[1] = readb(sabi_iface + SABI_IFACE_DATA + 1);
  233. sretval->retval[2] = readb(sabi_iface + SABI_IFACE_DATA + 2);
  234. sretval->retval[3] = readb(sabi_iface + SABI_IFACE_DATA + 3);
  235. exit:
  236. mutex_unlock(&sabi_mutex);
  237. return retval;
  238. }
  239. static int sabi_set_command(u8 command, u8 data)
  240. {
  241. int retval = 0;
  242. u16 port = readw(sabi + sabi_config->header_offsets.port);
  243. u8 complete, iface_data;
  244. mutex_lock(&sabi_mutex);
  245. /* enable memory to be able to write to it */
  246. outb(readb(sabi + sabi_config->header_offsets.en_mem), port);
  247. /* write out the command */
  248. writew(sabi_config->main_function, sabi_iface + SABI_IFACE_MAIN);
  249. writew(command, sabi_iface + SABI_IFACE_SUB);
  250. writeb(0, sabi_iface + SABI_IFACE_COMPLETE);
  251. writeb(data, sabi_iface + SABI_IFACE_DATA);
  252. outb(readb(sabi + sabi_config->header_offsets.iface_func), port);
  253. /* write protect memory to make it safe */
  254. outb(readb(sabi + sabi_config->header_offsets.re_mem), port);
  255. /* see if the command actually succeeded */
  256. complete = readb(sabi_iface + SABI_IFACE_COMPLETE);
  257. iface_data = readb(sabi_iface + SABI_IFACE_DATA);
  258. if (complete != 0xaa || iface_data == 0xff) {
  259. pr_warn("SABI set command 0x%02x failed with completion flag 0x%02x and data 0x%02x\n",
  260. command, complete, iface_data);
  261. retval = -EINVAL;
  262. }
  263. mutex_unlock(&sabi_mutex);
  264. return retval;
  265. }
  266. static void test_backlight(void)
  267. {
  268. struct sabi_retval sretval;
  269. sabi_get_command(sabi_config->commands.get_backlight, &sretval);
  270. printk(KERN_DEBUG "backlight = 0x%02x\n", sretval.retval[0]);
  271. sabi_set_command(sabi_config->commands.set_backlight, 0);
  272. printk(KERN_DEBUG "backlight should be off\n");
  273. sabi_get_command(sabi_config->commands.get_backlight, &sretval);
  274. printk(KERN_DEBUG "backlight = 0x%02x\n", sretval.retval[0]);
  275. msleep(1000);
  276. sabi_set_command(sabi_config->commands.set_backlight, 1);
  277. printk(KERN_DEBUG "backlight should be on\n");
  278. sabi_get_command(sabi_config->commands.get_backlight, &sretval);
  279. printk(KERN_DEBUG "backlight = 0x%02x\n", sretval.retval[0]);
  280. }
  281. static void test_wireless(void)
  282. {
  283. struct sabi_retval sretval;
  284. sabi_get_command(sabi_config->commands.get_wireless_button, &sretval);
  285. printk(KERN_DEBUG "wireless led = 0x%02x\n", sretval.retval[0]);
  286. sabi_set_command(sabi_config->commands.set_wireless_button, 0);
  287. printk(KERN_DEBUG "wireless led should be off\n");
  288. sabi_get_command(sabi_config->commands.get_wireless_button, &sretval);
  289. printk(KERN_DEBUG "wireless led = 0x%02x\n", sretval.retval[0]);
  290. msleep(1000);
  291. sabi_set_command(sabi_config->commands.set_wireless_button, 1);
  292. printk(KERN_DEBUG "wireless led should be on\n");
  293. sabi_get_command(sabi_config->commands.get_wireless_button, &sretval);
  294. printk(KERN_DEBUG "wireless led = 0x%02x\n", sretval.retval[0]);
  295. }
  296. static u8 read_brightness(void)
  297. {
  298. struct sabi_retval sretval;
  299. int user_brightness = 0;
  300. int retval;
  301. retval = sabi_get_command(sabi_config->commands.get_brightness,
  302. &sretval);
  303. if (!retval) {
  304. user_brightness = sretval.retval[0];
  305. if (user_brightness > sabi_config->min_brightness)
  306. user_brightness -= sabi_config->min_brightness;
  307. else
  308. user_brightness = 0;
  309. }
  310. return user_brightness;
  311. }
  312. static void set_brightness(u8 user_brightness)
  313. {
  314. u8 user_level = user_brightness + sabi_config->min_brightness;
  315. if (has_stepping_quirk && user_level != 0) {
  316. /*
  317. * short circuit if the specified level is what's already set
  318. * to prevent the screen from flickering needlessly
  319. */
  320. if (user_brightness == read_brightness())
  321. return;
  322. sabi_set_command(sabi_config->commands.set_brightness, 0);
  323. }
  324. sabi_set_command(sabi_config->commands.set_brightness, user_level);
  325. }
  326. static int get_brightness(struct backlight_device *bd)
  327. {
  328. return (int)read_brightness();
  329. }
  330. static void check_for_stepping_quirk(void)
  331. {
  332. u8 initial_level = read_brightness();
  333. u8 check_level;
  334. /*
  335. * Some laptops exhibit the strange behaviour of stepping toward
  336. * (rather than setting) the brightness except when changing to/from
  337. * brightness level 0. This behaviour is checked for here and worked
  338. * around in set_brightness.
  339. */
  340. if (initial_level <= 2)
  341. check_level = initial_level + 2;
  342. else
  343. check_level = initial_level - 2;
  344. has_stepping_quirk = false;
  345. set_brightness(check_level);
  346. if (read_brightness() != check_level) {
  347. has_stepping_quirk = true;
  348. pr_info("enabled workaround for brightness stepping quirk\n");
  349. }
  350. set_brightness(initial_level);
  351. }
  352. static int update_status(struct backlight_device *bd)
  353. {
  354. set_brightness(bd->props.brightness);
  355. if (bd->props.power == FB_BLANK_UNBLANK)
  356. sabi_set_command(sabi_config->commands.set_backlight, 1);
  357. else
  358. sabi_set_command(sabi_config->commands.set_backlight, 0);
  359. return 0;
  360. }
  361. static const struct backlight_ops backlight_ops = {
  362. .get_brightness = get_brightness,
  363. .update_status = update_status,
  364. };
  365. static int rfkill_set(void *data, bool blocked)
  366. {
  367. /* Do something with blocked...*/
  368. /*
  369. * blocked == false is on
  370. * blocked == true is off
  371. */
  372. if (blocked)
  373. sabi_set_command(sabi_config->commands.set_wireless_button, 0);
  374. else
  375. sabi_set_command(sabi_config->commands.set_wireless_button, 1);
  376. return 0;
  377. }
  378. static struct rfkill_ops rfkill_ops = {
  379. .set_block = rfkill_set,
  380. };
  381. static int init_wireless(struct platform_device *sdev)
  382. {
  383. int retval;
  384. rfk = rfkill_alloc("samsung-wifi", &sdev->dev, RFKILL_TYPE_WLAN,
  385. &rfkill_ops, NULL);
  386. if (!rfk)
  387. return -ENOMEM;
  388. retval = rfkill_register(rfk);
  389. if (retval) {
  390. rfkill_destroy(rfk);
  391. return -ENODEV;
  392. }
  393. return 0;
  394. }
  395. static void destroy_wireless(void)
  396. {
  397. rfkill_unregister(rfk);
  398. rfkill_destroy(rfk);
  399. }
  400. static ssize_t get_performance_level(struct device *dev,
  401. struct device_attribute *attr, char *buf)
  402. {
  403. struct sabi_retval sretval;
  404. int retval;
  405. int i;
  406. /* Read the state */
  407. retval = sabi_get_command(sabi_config->commands.get_performance_level,
  408. &sretval);
  409. if (retval)
  410. return retval;
  411. /* The logic is backwards, yeah, lots of fun... */
  412. for (i = 0; sabi_config->performance_levels[i].name; ++i) {
  413. if (sretval.retval[0] == sabi_config->performance_levels[i].value)
  414. return sprintf(buf, "%s\n", sabi_config->performance_levels[i].name);
  415. }
  416. return sprintf(buf, "%s\n", "unknown");
  417. }
  418. static ssize_t set_performance_level(struct device *dev,
  419. struct device_attribute *attr, const char *buf,
  420. size_t count)
  421. {
  422. if (count >= 1) {
  423. int i;
  424. for (i = 0; sabi_config->performance_levels[i].name; ++i) {
  425. const struct sabi_performance_level *level =
  426. &sabi_config->performance_levels[i];
  427. if (!strncasecmp(level->name, buf, strlen(level->name))) {
  428. sabi_set_command(sabi_config->commands.set_performance_level,
  429. level->value);
  430. break;
  431. }
  432. }
  433. if (!sabi_config->performance_levels[i].name)
  434. return -EINVAL;
  435. }
  436. return count;
  437. }
  438. static DEVICE_ATTR(performance_level, S_IWUSR | S_IRUGO,
  439. get_performance_level, set_performance_level);
  440. static int __init dmi_check_cb(const struct dmi_system_id *id)
  441. {
  442. pr_info("found laptop model '%s'\n",
  443. id->ident);
  444. return 1;
  445. }
  446. static struct dmi_system_id __initdata samsung_dmi_table[] = {
  447. {
  448. .ident = "N128",
  449. .matches = {
  450. DMI_MATCH(DMI_SYS_VENDOR,
  451. "SAMSUNG ELECTRONICS CO., LTD."),
  452. DMI_MATCH(DMI_PRODUCT_NAME, "N128"),
  453. DMI_MATCH(DMI_BOARD_NAME, "N128"),
  454. },
  455. .callback = dmi_check_cb,
  456. },
  457. {
  458. .ident = "N130",
  459. .matches = {
  460. DMI_MATCH(DMI_SYS_VENDOR,
  461. "SAMSUNG ELECTRONICS CO., LTD."),
  462. DMI_MATCH(DMI_PRODUCT_NAME, "N130"),
  463. DMI_MATCH(DMI_BOARD_NAME, "N130"),
  464. },
  465. .callback = dmi_check_cb,
  466. },
  467. {
  468. .ident = "N510",
  469. .matches = {
  470. DMI_MATCH(DMI_SYS_VENDOR,
  471. "SAMSUNG ELECTRONICS CO., LTD."),
  472. DMI_MATCH(DMI_PRODUCT_NAME, "N510"),
  473. DMI_MATCH(DMI_BOARD_NAME, "N510"),
  474. },
  475. .callback = dmi_check_cb,
  476. },
  477. {
  478. .ident = "X125",
  479. .matches = {
  480. DMI_MATCH(DMI_SYS_VENDOR,
  481. "SAMSUNG ELECTRONICS CO., LTD."),
  482. DMI_MATCH(DMI_PRODUCT_NAME, "X125"),
  483. DMI_MATCH(DMI_BOARD_NAME, "X125"),
  484. },
  485. .callback = dmi_check_cb,
  486. },
  487. {
  488. .ident = "X120/X170",
  489. .matches = {
  490. DMI_MATCH(DMI_SYS_VENDOR,
  491. "SAMSUNG ELECTRONICS CO., LTD."),
  492. DMI_MATCH(DMI_PRODUCT_NAME, "X120/X170"),
  493. DMI_MATCH(DMI_BOARD_NAME, "X120/X170"),
  494. },
  495. .callback = dmi_check_cb,
  496. },
  497. {
  498. .ident = "NC10",
  499. .matches = {
  500. DMI_MATCH(DMI_SYS_VENDOR,
  501. "SAMSUNG ELECTRONICS CO., LTD."),
  502. DMI_MATCH(DMI_PRODUCT_NAME, "NC10"),
  503. DMI_MATCH(DMI_BOARD_NAME, "NC10"),
  504. },
  505. .callback = dmi_check_cb,
  506. },
  507. {
  508. .ident = "NP-Q45",
  509. .matches = {
  510. DMI_MATCH(DMI_SYS_VENDOR,
  511. "SAMSUNG ELECTRONICS CO., LTD."),
  512. DMI_MATCH(DMI_PRODUCT_NAME, "SQ45S70S"),
  513. DMI_MATCH(DMI_BOARD_NAME, "SQ45S70S"),
  514. },
  515. .callback = dmi_check_cb,
  516. },
  517. {
  518. .ident = "X360",
  519. .matches = {
  520. DMI_MATCH(DMI_SYS_VENDOR,
  521. "SAMSUNG ELECTRONICS CO., LTD."),
  522. DMI_MATCH(DMI_PRODUCT_NAME, "X360"),
  523. DMI_MATCH(DMI_BOARD_NAME, "X360"),
  524. },
  525. .callback = dmi_check_cb,
  526. },
  527. {
  528. .ident = "R410 Plus",
  529. .matches = {
  530. DMI_MATCH(DMI_SYS_VENDOR,
  531. "SAMSUNG ELECTRONICS CO., LTD."),
  532. DMI_MATCH(DMI_PRODUCT_NAME, "R410P"),
  533. DMI_MATCH(DMI_BOARD_NAME, "R460"),
  534. },
  535. .callback = dmi_check_cb,
  536. },
  537. {
  538. .ident = "R518",
  539. .matches = {
  540. DMI_MATCH(DMI_SYS_VENDOR,
  541. "SAMSUNG ELECTRONICS CO., LTD."),
  542. DMI_MATCH(DMI_PRODUCT_NAME, "R518"),
  543. DMI_MATCH(DMI_BOARD_NAME, "R518"),
  544. },
  545. .callback = dmi_check_cb,
  546. },
  547. {
  548. .ident = "R519/R719",
  549. .matches = {
  550. DMI_MATCH(DMI_SYS_VENDOR,
  551. "SAMSUNG ELECTRONICS CO., LTD."),
  552. DMI_MATCH(DMI_PRODUCT_NAME, "R519/R719"),
  553. DMI_MATCH(DMI_BOARD_NAME, "R519/R719"),
  554. },
  555. .callback = dmi_check_cb,
  556. },
  557. {
  558. .ident = "N150/N210/N220",
  559. .matches = {
  560. DMI_MATCH(DMI_SYS_VENDOR,
  561. "SAMSUNG ELECTRONICS CO., LTD."),
  562. DMI_MATCH(DMI_PRODUCT_NAME, "N150/N210/N220"),
  563. DMI_MATCH(DMI_BOARD_NAME, "N150/N210/N220"),
  564. },
  565. .callback = dmi_check_cb,
  566. },
  567. {
  568. .ident = "N150/N210/N220/N230",
  569. .matches = {
  570. DMI_MATCH(DMI_SYS_VENDOR,
  571. "SAMSUNG ELECTRONICS CO., LTD."),
  572. DMI_MATCH(DMI_PRODUCT_NAME, "N150/N210/N220/N230"),
  573. DMI_MATCH(DMI_BOARD_NAME, "N150/N210/N220/N230"),
  574. },
  575. .callback = dmi_check_cb,
  576. },
  577. {
  578. .ident = "N150P/N210P/N220P",
  579. .matches = {
  580. DMI_MATCH(DMI_SYS_VENDOR,
  581. "SAMSUNG ELECTRONICS CO., LTD."),
  582. DMI_MATCH(DMI_PRODUCT_NAME, "N150P/N210P/N220P"),
  583. DMI_MATCH(DMI_BOARD_NAME, "N150P/N210P/N220P"),
  584. },
  585. .callback = dmi_check_cb,
  586. },
  587. {
  588. .ident = "R530/R730",
  589. .matches = {
  590. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
  591. DMI_MATCH(DMI_PRODUCT_NAME, "R530/R730"),
  592. DMI_MATCH(DMI_BOARD_NAME, "R530/R730"),
  593. },
  594. .callback = dmi_check_cb,
  595. },
  596. {
  597. .ident = "NF110/NF210/NF310",
  598. .matches = {
  599. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
  600. DMI_MATCH(DMI_PRODUCT_NAME, "NF110/NF210/NF310"),
  601. DMI_MATCH(DMI_BOARD_NAME, "NF110/NF210/NF310"),
  602. },
  603. .callback = dmi_check_cb,
  604. },
  605. {
  606. .ident = "N145P/N250P/N260P",
  607. .matches = {
  608. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
  609. DMI_MATCH(DMI_PRODUCT_NAME, "N145P/N250P/N260P"),
  610. DMI_MATCH(DMI_BOARD_NAME, "N145P/N250P/N260P"),
  611. },
  612. .callback = dmi_check_cb,
  613. },
  614. {
  615. .ident = "R70/R71",
  616. .matches = {
  617. DMI_MATCH(DMI_SYS_VENDOR,
  618. "SAMSUNG ELECTRONICS CO., LTD."),
  619. DMI_MATCH(DMI_PRODUCT_NAME, "R70/R71"),
  620. DMI_MATCH(DMI_BOARD_NAME, "R70/R71"),
  621. },
  622. .callback = dmi_check_cb,
  623. },
  624. {
  625. .ident = "P460",
  626. .matches = {
  627. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
  628. DMI_MATCH(DMI_PRODUCT_NAME, "P460"),
  629. DMI_MATCH(DMI_BOARD_NAME, "P460"),
  630. },
  631. .callback = dmi_check_cb,
  632. },
  633. {
  634. .ident = "R528/R728",
  635. .matches = {
  636. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
  637. DMI_MATCH(DMI_PRODUCT_NAME, "R528/R728"),
  638. DMI_MATCH(DMI_BOARD_NAME, "R528/R728"),
  639. },
  640. .callback = dmi_check_cb,
  641. },
  642. { },
  643. };
  644. MODULE_DEVICE_TABLE(dmi, samsung_dmi_table);
  645. static int find_signature(void __iomem *memcheck, const char *testStr)
  646. {
  647. int i = 0;
  648. int loca;
  649. for (loca = 0; loca < 0xffff; loca++) {
  650. char temp = readb(memcheck + loca);
  651. if (temp == testStr[i]) {
  652. if (i == strlen(testStr)-1)
  653. break;
  654. ++i;
  655. } else {
  656. i = 0;
  657. }
  658. }
  659. return loca;
  660. }
  661. static int __init samsung_init(void)
  662. {
  663. struct backlight_properties props;
  664. struct sabi_retval sretval;
  665. unsigned int ifaceP;
  666. int i;
  667. int loca;
  668. int retval;
  669. mutex_init(&sabi_mutex);
  670. if (!force && !dmi_check_system(samsung_dmi_table))
  671. return -ENODEV;
  672. f0000_segment = ioremap_nocache(0xf0000, 0xffff);
  673. if (!f0000_segment) {
  674. pr_err("Can't map the segment at 0xf0000\n");
  675. return -EINVAL;
  676. }
  677. /* Try to find one of the signatures in memory to find the header */
  678. for (i = 0; sabi_configs[i].test_string != 0; ++i) {
  679. sabi_config = &sabi_configs[i];
  680. loca = find_signature(f0000_segment, sabi_config->test_string);
  681. if (loca != 0xffff)
  682. break;
  683. }
  684. if (loca == 0xffff) {
  685. pr_err("This computer does not support SABI\n");
  686. goto error_no_signature;
  687. }
  688. /* point to the SMI port Number */
  689. loca += 1;
  690. sabi = (f0000_segment + loca);
  691. if (debug) {
  692. printk(KERN_DEBUG "This computer supports SABI==%x\n",
  693. loca + 0xf0000 - 6);
  694. printk(KERN_DEBUG "SABI header:\n");
  695. printk(KERN_DEBUG " SMI Port Number = 0x%04x\n",
  696. readw(sabi + sabi_config->header_offsets.port));
  697. printk(KERN_DEBUG " SMI Interface Function = 0x%02x\n",
  698. readb(sabi + sabi_config->header_offsets.iface_func));
  699. printk(KERN_DEBUG " SMI enable memory buffer = 0x%02x\n",
  700. readb(sabi + sabi_config->header_offsets.en_mem));
  701. printk(KERN_DEBUG " SMI restore memory buffer = 0x%02x\n",
  702. readb(sabi + sabi_config->header_offsets.re_mem));
  703. printk(KERN_DEBUG " SABI data offset = 0x%04x\n",
  704. readw(sabi + sabi_config->header_offsets.data_offset));
  705. printk(KERN_DEBUG " SABI data segment = 0x%04x\n",
  706. readw(sabi + sabi_config->header_offsets.data_segment));
  707. }
  708. /* Get a pointer to the SABI Interface */
  709. ifaceP = (readw(sabi + sabi_config->header_offsets.data_segment) & 0x0ffff) << 4;
  710. ifaceP += readw(sabi + sabi_config->header_offsets.data_offset) & 0x0ffff;
  711. sabi_iface = ioremap_nocache(ifaceP, 16);
  712. if (!sabi_iface) {
  713. pr_err("Can't remap %x\n", ifaceP);
  714. goto error_no_signature;
  715. }
  716. if (debug) {
  717. printk(KERN_DEBUG "ifaceP = 0x%08x\n", ifaceP);
  718. printk(KERN_DEBUG "sabi_iface = %p\n", sabi_iface);
  719. test_backlight();
  720. test_wireless();
  721. retval = sabi_get_command(sabi_config->commands.get_brightness,
  722. &sretval);
  723. printk(KERN_DEBUG "brightness = 0x%02x\n", sretval.retval[0]);
  724. }
  725. /* Turn on "Linux" mode in the BIOS */
  726. if (sabi_config->commands.set_linux != 0xff) {
  727. retval = sabi_set_command(sabi_config->commands.set_linux,
  728. 0x81);
  729. if (retval) {
  730. pr_warn("Linux mode was not set!\n");
  731. goto error_no_platform;
  732. }
  733. }
  734. /* Check for stepping quirk */
  735. check_for_stepping_quirk();
  736. /* knock up a platform device to hang stuff off of */
  737. sdev = platform_device_register_simple("samsung", -1, NULL, 0);
  738. if (IS_ERR(sdev))
  739. goto error_no_platform;
  740. /* create a backlight device to talk to this one */
  741. memset(&props, 0, sizeof(struct backlight_properties));
  742. props.type = BACKLIGHT_PLATFORM;
  743. props.max_brightness = sabi_config->max_brightness -
  744. sabi_config->min_brightness;
  745. backlight_device = backlight_device_register("samsung", &sdev->dev,
  746. NULL, &backlight_ops,
  747. &props);
  748. if (IS_ERR(backlight_device))
  749. goto error_no_backlight;
  750. backlight_device->props.brightness = read_brightness();
  751. backlight_device->props.power = FB_BLANK_UNBLANK;
  752. backlight_update_status(backlight_device);
  753. retval = init_wireless(sdev);
  754. if (retval)
  755. goto error_no_rfk;
  756. retval = device_create_file(&sdev->dev, &dev_attr_performance_level);
  757. if (retval)
  758. goto error_file_create;
  759. return 0;
  760. error_file_create:
  761. destroy_wireless();
  762. error_no_rfk:
  763. backlight_device_unregister(backlight_device);
  764. error_no_backlight:
  765. platform_device_unregister(sdev);
  766. error_no_platform:
  767. iounmap(sabi_iface);
  768. error_no_signature:
  769. iounmap(f0000_segment);
  770. return -EINVAL;
  771. }
  772. static void __exit samsung_exit(void)
  773. {
  774. /* Turn off "Linux" mode in the BIOS */
  775. if (sabi_config->commands.set_linux != 0xff)
  776. sabi_set_command(sabi_config->commands.set_linux, 0x80);
  777. device_remove_file(&sdev->dev, &dev_attr_performance_level);
  778. backlight_device_unregister(backlight_device);
  779. destroy_wireless();
  780. iounmap(sabi_iface);
  781. iounmap(f0000_segment);
  782. platform_device_unregister(sdev);
  783. }
  784. module_init(samsung_init);
  785. module_exit(samsung_exit);
  786. MODULE_AUTHOR("Greg Kroah-Hartman <gregkh@suse.de>");
  787. MODULE_DESCRIPTION("Samsung Backlight driver");
  788. MODULE_LICENSE("GPL");