samsung-laptop.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874
  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 = "N510",
  437. .matches = {
  438. DMI_MATCH(DMI_SYS_VENDOR,
  439. "SAMSUNG ELECTRONICS CO., LTD."),
  440. DMI_MATCH(DMI_PRODUCT_NAME, "N510"),
  441. DMI_MATCH(DMI_BOARD_NAME, "N510"),
  442. },
  443. .callback = dmi_check_cb,
  444. },
  445. {
  446. .ident = "X125",
  447. .matches = {
  448. DMI_MATCH(DMI_SYS_VENDOR,
  449. "SAMSUNG ELECTRONICS CO., LTD."),
  450. DMI_MATCH(DMI_PRODUCT_NAME, "X125"),
  451. DMI_MATCH(DMI_BOARD_NAME, "X125"),
  452. },
  453. .callback = dmi_check_cb,
  454. },
  455. {
  456. .ident = "X120/X170",
  457. .matches = {
  458. DMI_MATCH(DMI_SYS_VENDOR,
  459. "SAMSUNG ELECTRONICS CO., LTD."),
  460. DMI_MATCH(DMI_PRODUCT_NAME, "X120/X170"),
  461. DMI_MATCH(DMI_BOARD_NAME, "X120/X170"),
  462. },
  463. .callback = dmi_check_cb,
  464. },
  465. {
  466. .ident = "NC10",
  467. .matches = {
  468. DMI_MATCH(DMI_SYS_VENDOR,
  469. "SAMSUNG ELECTRONICS CO., LTD."),
  470. DMI_MATCH(DMI_PRODUCT_NAME, "NC10"),
  471. DMI_MATCH(DMI_BOARD_NAME, "NC10"),
  472. },
  473. .callback = dmi_check_cb,
  474. },
  475. {
  476. .ident = "NP-Q45",
  477. .matches = {
  478. DMI_MATCH(DMI_SYS_VENDOR,
  479. "SAMSUNG ELECTRONICS CO., LTD."),
  480. DMI_MATCH(DMI_PRODUCT_NAME, "SQ45S70S"),
  481. DMI_MATCH(DMI_BOARD_NAME, "SQ45S70S"),
  482. },
  483. .callback = dmi_check_cb,
  484. },
  485. {
  486. .ident = "X360",
  487. .matches = {
  488. DMI_MATCH(DMI_SYS_VENDOR,
  489. "SAMSUNG ELECTRONICS CO., LTD."),
  490. DMI_MATCH(DMI_PRODUCT_NAME, "X360"),
  491. DMI_MATCH(DMI_BOARD_NAME, "X360"),
  492. },
  493. .callback = dmi_check_cb,
  494. },
  495. {
  496. .ident = "R410 Plus",
  497. .matches = {
  498. DMI_MATCH(DMI_SYS_VENDOR,
  499. "SAMSUNG ELECTRONICS CO., LTD."),
  500. DMI_MATCH(DMI_PRODUCT_NAME, "R410P"),
  501. DMI_MATCH(DMI_BOARD_NAME, "R460"),
  502. },
  503. .callback = dmi_check_cb,
  504. },
  505. {
  506. .ident = "R518",
  507. .matches = {
  508. DMI_MATCH(DMI_SYS_VENDOR,
  509. "SAMSUNG ELECTRONICS CO., LTD."),
  510. DMI_MATCH(DMI_PRODUCT_NAME, "R518"),
  511. DMI_MATCH(DMI_BOARD_NAME, "R518"),
  512. },
  513. .callback = dmi_check_cb,
  514. },
  515. {
  516. .ident = "R519/R719",
  517. .matches = {
  518. DMI_MATCH(DMI_SYS_VENDOR,
  519. "SAMSUNG ELECTRONICS CO., LTD."),
  520. DMI_MATCH(DMI_PRODUCT_NAME, "R519/R719"),
  521. DMI_MATCH(DMI_BOARD_NAME, "R519/R719"),
  522. },
  523. .callback = dmi_check_cb,
  524. },
  525. {
  526. .ident = "N150/N210/N220",
  527. .matches = {
  528. DMI_MATCH(DMI_SYS_VENDOR,
  529. "SAMSUNG ELECTRONICS CO., LTD."),
  530. DMI_MATCH(DMI_PRODUCT_NAME, "N150/N210/N220"),
  531. DMI_MATCH(DMI_BOARD_NAME, "N150/N210/N220"),
  532. },
  533. .callback = dmi_check_cb,
  534. },
  535. {
  536. .ident = "N150/N210/N220/N230",
  537. .matches = {
  538. DMI_MATCH(DMI_SYS_VENDOR,
  539. "SAMSUNG ELECTRONICS CO., LTD."),
  540. DMI_MATCH(DMI_PRODUCT_NAME, "N150/N210/N220/N230"),
  541. DMI_MATCH(DMI_BOARD_NAME, "N150/N210/N220/N230"),
  542. },
  543. .callback = dmi_check_cb,
  544. },
  545. {
  546. .ident = "N150P/N210P/N220P",
  547. .matches = {
  548. DMI_MATCH(DMI_SYS_VENDOR,
  549. "SAMSUNG ELECTRONICS CO., LTD."),
  550. DMI_MATCH(DMI_PRODUCT_NAME, "N150P/N210P/N220P"),
  551. DMI_MATCH(DMI_BOARD_NAME, "N150P/N210P/N220P"),
  552. },
  553. .callback = dmi_check_cb,
  554. },
  555. {
  556. .ident = "R530/R730",
  557. .matches = {
  558. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
  559. DMI_MATCH(DMI_PRODUCT_NAME, "R530/R730"),
  560. DMI_MATCH(DMI_BOARD_NAME, "R530/R730"),
  561. },
  562. .callback = dmi_check_cb,
  563. },
  564. {
  565. .ident = "NF110/NF210/NF310",
  566. .matches = {
  567. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
  568. DMI_MATCH(DMI_PRODUCT_NAME, "NF110/NF210/NF310"),
  569. DMI_MATCH(DMI_BOARD_NAME, "NF110/NF210/NF310"),
  570. },
  571. .callback = dmi_check_cb,
  572. },
  573. {
  574. .ident = "N145P/N250P/N260P",
  575. .matches = {
  576. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
  577. DMI_MATCH(DMI_PRODUCT_NAME, "N145P/N250P/N260P"),
  578. DMI_MATCH(DMI_BOARD_NAME, "N145P/N250P/N260P"),
  579. },
  580. .callback = dmi_check_cb,
  581. },
  582. {
  583. .ident = "R70/R71",
  584. .matches = {
  585. DMI_MATCH(DMI_SYS_VENDOR,
  586. "SAMSUNG ELECTRONICS CO., LTD."),
  587. DMI_MATCH(DMI_PRODUCT_NAME, "R70/R71"),
  588. DMI_MATCH(DMI_BOARD_NAME, "R70/R71"),
  589. },
  590. .callback = dmi_check_cb,
  591. },
  592. {
  593. .ident = "P460",
  594. .matches = {
  595. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
  596. DMI_MATCH(DMI_PRODUCT_NAME, "P460"),
  597. DMI_MATCH(DMI_BOARD_NAME, "P460"),
  598. },
  599. .callback = dmi_check_cb,
  600. },
  601. {
  602. .ident = "R528/R728",
  603. .matches = {
  604. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
  605. DMI_MATCH(DMI_PRODUCT_NAME, "R528/R728"),
  606. DMI_MATCH(DMI_BOARD_NAME, "R528/R728"),
  607. },
  608. .callback = dmi_check_cb,
  609. },
  610. { },
  611. };
  612. MODULE_DEVICE_TABLE(dmi, samsung_dmi_table);
  613. static int find_signature(void __iomem *memcheck, const char *testStr)
  614. {
  615. int i = 0;
  616. int loca;
  617. for (loca = 0; loca < 0xffff; loca++) {
  618. char temp = readb(memcheck + loca);
  619. if (temp == testStr[i]) {
  620. if (i == strlen(testStr)-1)
  621. break;
  622. ++i;
  623. } else {
  624. i = 0;
  625. }
  626. }
  627. return loca;
  628. }
  629. static int __init samsung_init(void)
  630. {
  631. struct backlight_properties props;
  632. struct sabi_retval sretval;
  633. unsigned int ifaceP;
  634. int i;
  635. int loca;
  636. int retval;
  637. mutex_init(&sabi_mutex);
  638. if (!force && !dmi_check_system(samsung_dmi_table))
  639. return -ENODEV;
  640. f0000_segment = ioremap_nocache(0xf0000, 0xffff);
  641. if (!f0000_segment) {
  642. pr_err("Can't map the segment at 0xf0000\n");
  643. return -EINVAL;
  644. }
  645. /* Try to find one of the signatures in memory to find the header */
  646. for (i = 0; sabi_configs[i].test_string != 0; ++i) {
  647. sabi_config = &sabi_configs[i];
  648. loca = find_signature(f0000_segment, sabi_config->test_string);
  649. if (loca != 0xffff)
  650. break;
  651. }
  652. if (loca == 0xffff) {
  653. pr_err("This computer does not support SABI\n");
  654. goto error_no_signature;
  655. }
  656. /* point to the SMI port Number */
  657. loca += 1;
  658. sabi = (f0000_segment + loca);
  659. if (debug) {
  660. printk(KERN_DEBUG "This computer supports SABI==%x\n",
  661. loca + 0xf0000 - 6);
  662. printk(KERN_DEBUG "SABI header:\n");
  663. printk(KERN_DEBUG " SMI Port Number = 0x%04x\n",
  664. readw(sabi + sabi_config->header_offsets.port));
  665. printk(KERN_DEBUG " SMI Interface Function = 0x%02x\n",
  666. readb(sabi + sabi_config->header_offsets.iface_func));
  667. printk(KERN_DEBUG " SMI enable memory buffer = 0x%02x\n",
  668. readb(sabi + sabi_config->header_offsets.en_mem));
  669. printk(KERN_DEBUG " SMI restore memory buffer = 0x%02x\n",
  670. readb(sabi + sabi_config->header_offsets.re_mem));
  671. printk(KERN_DEBUG " SABI data offset = 0x%04x\n",
  672. readw(sabi + sabi_config->header_offsets.data_offset));
  673. printk(KERN_DEBUG " SABI data segment = 0x%04x\n",
  674. readw(sabi + sabi_config->header_offsets.data_segment));
  675. }
  676. /* Get a pointer to the SABI Interface */
  677. ifaceP = (readw(sabi + sabi_config->header_offsets.data_segment) & 0x0ffff) << 4;
  678. ifaceP += readw(sabi + sabi_config->header_offsets.data_offset) & 0x0ffff;
  679. sabi_iface = ioremap_nocache(ifaceP, 16);
  680. if (!sabi_iface) {
  681. pr_err("Can't remap %x\n", ifaceP);
  682. goto error_no_signature;
  683. }
  684. if (debug) {
  685. printk(KERN_DEBUG "ifaceP = 0x%08x\n", ifaceP);
  686. printk(KERN_DEBUG "sabi_iface = %p\n", sabi_iface);
  687. test_backlight();
  688. test_wireless();
  689. retval = sabi_get_command(sabi_config->commands.get_brightness,
  690. &sretval);
  691. printk(KERN_DEBUG "brightness = 0x%02x\n", sretval.retval[0]);
  692. }
  693. /* Turn on "Linux" mode in the BIOS */
  694. if (sabi_config->commands.set_linux != 0xff) {
  695. retval = sabi_set_command(sabi_config->commands.set_linux,
  696. 0x81);
  697. if (retval) {
  698. pr_warn("Linux mode was not set!\n");
  699. goto error_no_platform;
  700. }
  701. }
  702. /* knock up a platform device to hang stuff off of */
  703. sdev = platform_device_register_simple("samsung", -1, NULL, 0);
  704. if (IS_ERR(sdev))
  705. goto error_no_platform;
  706. /* create a backlight device to talk to this one */
  707. memset(&props, 0, sizeof(struct backlight_properties));
  708. props.type = BACKLIGHT_PLATFORM;
  709. props.max_brightness = sabi_config->max_brightness -
  710. sabi_config->min_brightness;
  711. backlight_device = backlight_device_register("samsung", &sdev->dev,
  712. NULL, &backlight_ops,
  713. &props);
  714. if (IS_ERR(backlight_device))
  715. goto error_no_backlight;
  716. backlight_device->props.brightness = read_brightness();
  717. backlight_device->props.power = FB_BLANK_UNBLANK;
  718. backlight_update_status(backlight_device);
  719. retval = init_wireless(sdev);
  720. if (retval)
  721. goto error_no_rfk;
  722. retval = device_create_file(&sdev->dev, &dev_attr_performance_level);
  723. if (retval)
  724. goto error_file_create;
  725. return 0;
  726. error_file_create:
  727. destroy_wireless();
  728. error_no_rfk:
  729. backlight_device_unregister(backlight_device);
  730. error_no_backlight:
  731. platform_device_unregister(sdev);
  732. error_no_platform:
  733. iounmap(sabi_iface);
  734. error_no_signature:
  735. iounmap(f0000_segment);
  736. return -EINVAL;
  737. }
  738. static void __exit samsung_exit(void)
  739. {
  740. /* Turn off "Linux" mode in the BIOS */
  741. if (sabi_config->commands.set_linux != 0xff)
  742. sabi_set_command(sabi_config->commands.set_linux, 0x80);
  743. device_remove_file(&sdev->dev, &dev_attr_performance_level);
  744. backlight_device_unregister(backlight_device);
  745. destroy_wireless();
  746. iounmap(sabi_iface);
  747. iounmap(f0000_segment);
  748. platform_device_unregister(sdev);
  749. }
  750. module_init(samsung_init);
  751. module_exit(samsung_exit);
  752. MODULE_AUTHOR("Greg Kroah-Hartman <gregkh@suse.de>");
  753. MODULE_DESCRIPTION("Samsung Backlight driver");
  754. MODULE_LICENSE("GPL");