samsung-laptop.c 23 KB

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