samsung-laptop.c 25 KB

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