samsung-laptop.c 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696
  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/leds.h>
  20. #include <linux/fb.h>
  21. #include <linux/dmi.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/rfkill.h>
  24. #include <linux/acpi.h>
  25. #include <linux/seq_file.h>
  26. #include <linux/debugfs.h>
  27. /*
  28. * This driver is needed because a number of Samsung laptops do not hook
  29. * their control settings through ACPI. So we have to poke around in the
  30. * BIOS to do things like brightness values, and "special" key controls.
  31. */
  32. /*
  33. * We have 0 - 8 as valid brightness levels. The specs say that level 0 should
  34. * be reserved by the BIOS (which really doesn't make much sense), we tell
  35. * userspace that the value is 0 - 7 and then just tell the hardware 1 - 8
  36. */
  37. #define MAX_BRIGHT 0x07
  38. #define SABI_IFACE_MAIN 0x00
  39. #define SABI_IFACE_SUB 0x02
  40. #define SABI_IFACE_COMPLETE 0x04
  41. #define SABI_IFACE_DATA 0x05
  42. #define WL_STATUS_WLAN 0x0
  43. #define WL_STATUS_BT 0x2
  44. /* Structure get/set data using sabi */
  45. struct sabi_data {
  46. union {
  47. struct {
  48. u32 d0;
  49. u32 d1;
  50. u16 d2;
  51. u8 d3;
  52. };
  53. u8 data[11];
  54. };
  55. };
  56. struct sabi_header_offsets {
  57. u8 port;
  58. u8 re_mem;
  59. u8 iface_func;
  60. u8 en_mem;
  61. u8 data_offset;
  62. u8 data_segment;
  63. };
  64. struct sabi_commands {
  65. /*
  66. * Brightness is 0 - 8, as described above.
  67. * Value 0 is for the BIOS to use
  68. */
  69. u16 get_brightness;
  70. u16 set_brightness;
  71. /*
  72. * first byte:
  73. * 0x00 - wireless is off
  74. * 0x01 - wireless is on
  75. * second byte:
  76. * 0x02 - 3G is off
  77. * 0x03 - 3G is on
  78. * TODO, verify 3G is correct, that doesn't seem right...
  79. */
  80. u16 get_wireless_button;
  81. u16 set_wireless_button;
  82. /* 0 is off, 1 is on */
  83. u16 get_backlight;
  84. u16 set_backlight;
  85. /*
  86. * 0x80 or 0x00 - no action
  87. * 0x81 - recovery key pressed
  88. */
  89. u16 get_recovery_mode;
  90. u16 set_recovery_mode;
  91. /*
  92. * on seclinux: 0 is low, 1 is high,
  93. * on swsmi: 0 is normal, 1 is silent, 2 is turbo
  94. */
  95. u16 get_performance_level;
  96. u16 set_performance_level;
  97. /* 0x80 is off, 0x81 is on */
  98. u16 get_battery_life_extender;
  99. u16 set_battery_life_extender;
  100. /* 0x80 is off, 0x81 is on */
  101. u16 get_usb_charge;
  102. u16 set_usb_charge;
  103. /* the first byte is for bluetooth and the third one is for wlan */
  104. u16 get_wireless_status;
  105. u16 set_wireless_status;
  106. /* 0x81 to read, (0x82 | level << 8) to set, 0xaabb to enable */
  107. u16 kbd_backlight;
  108. /*
  109. * Tell the BIOS that Linux is running on this machine.
  110. * 81 is on, 80 is off
  111. */
  112. u16 set_linux;
  113. };
  114. struct sabi_performance_level {
  115. const char *name;
  116. u16 value;
  117. };
  118. struct sabi_config {
  119. int sabi_version;
  120. const char *test_string;
  121. u16 main_function;
  122. const struct sabi_header_offsets header_offsets;
  123. const struct sabi_commands commands;
  124. const struct sabi_performance_level performance_levels[4];
  125. u8 min_brightness;
  126. u8 max_brightness;
  127. };
  128. static const struct sabi_config sabi_configs[] = {
  129. {
  130. /* I don't know if it is really 2, but it it is
  131. * less than 3 anyway */
  132. .sabi_version = 2,
  133. .test_string = "SECLINUX",
  134. .main_function = 0x4c49,
  135. .header_offsets = {
  136. .port = 0x00,
  137. .re_mem = 0x02,
  138. .iface_func = 0x03,
  139. .en_mem = 0x04,
  140. .data_offset = 0x05,
  141. .data_segment = 0x07,
  142. },
  143. .commands = {
  144. .get_brightness = 0x00,
  145. .set_brightness = 0x01,
  146. .get_wireless_button = 0x02,
  147. .set_wireless_button = 0x03,
  148. .get_backlight = 0x04,
  149. .set_backlight = 0x05,
  150. .get_recovery_mode = 0x06,
  151. .set_recovery_mode = 0x07,
  152. .get_performance_level = 0x08,
  153. .set_performance_level = 0x09,
  154. .get_battery_life_extender = 0xFFFF,
  155. .set_battery_life_extender = 0xFFFF,
  156. .get_usb_charge = 0xFFFF,
  157. .set_usb_charge = 0xFFFF,
  158. .get_wireless_status = 0xFFFF,
  159. .set_wireless_status = 0xFFFF,
  160. .kbd_backlight = 0xFFFF,
  161. .set_linux = 0x0a,
  162. },
  163. .performance_levels = {
  164. {
  165. .name = "silent",
  166. .value = 0,
  167. },
  168. {
  169. .name = "normal",
  170. .value = 1,
  171. },
  172. { },
  173. },
  174. .min_brightness = 1,
  175. .max_brightness = 8,
  176. },
  177. {
  178. .sabi_version = 3,
  179. .test_string = "SwSmi@",
  180. .main_function = 0x5843,
  181. .header_offsets = {
  182. .port = 0x00,
  183. .re_mem = 0x04,
  184. .iface_func = 0x02,
  185. .en_mem = 0x03,
  186. .data_offset = 0x05,
  187. .data_segment = 0x07,
  188. },
  189. .commands = {
  190. .get_brightness = 0x10,
  191. .set_brightness = 0x11,
  192. .get_wireless_button = 0x12,
  193. .set_wireless_button = 0x13,
  194. .get_backlight = 0x2d,
  195. .set_backlight = 0x2e,
  196. .get_recovery_mode = 0xff,
  197. .set_recovery_mode = 0xff,
  198. .get_performance_level = 0x31,
  199. .set_performance_level = 0x32,
  200. .get_battery_life_extender = 0x65,
  201. .set_battery_life_extender = 0x66,
  202. .get_usb_charge = 0x67,
  203. .set_usb_charge = 0x68,
  204. .get_wireless_status = 0x69,
  205. .set_wireless_status = 0x6a,
  206. .kbd_backlight = 0x78,
  207. .set_linux = 0xff,
  208. },
  209. .performance_levels = {
  210. {
  211. .name = "normal",
  212. .value = 0,
  213. },
  214. {
  215. .name = "silent",
  216. .value = 1,
  217. },
  218. {
  219. .name = "overclock",
  220. .value = 2,
  221. },
  222. { },
  223. },
  224. .min_brightness = 0,
  225. .max_brightness = 8,
  226. },
  227. { },
  228. };
  229. /*
  230. * samsung-laptop/ - debugfs root directory
  231. * f0000_segment - dump f0000 segment
  232. * command - current command
  233. * data - current data
  234. * d0, d1, d2, d3 - data fields
  235. * call - call SABI using command and data
  236. *
  237. * This allow to call arbitrary sabi commands wihout
  238. * modifying the driver at all.
  239. * For example, setting the keyboard backlight brightness to 5
  240. *
  241. * echo 0x78 > command
  242. * echo 0x0582 > d0
  243. * echo 0 > d1
  244. * echo 0 > d2
  245. * echo 0 > d3
  246. * cat call
  247. */
  248. struct samsung_laptop_debug {
  249. struct dentry *root;
  250. struct sabi_data data;
  251. u16 command;
  252. struct debugfs_blob_wrapper f0000_wrapper;
  253. struct debugfs_blob_wrapper data_wrapper;
  254. };
  255. struct samsung_laptop;
  256. struct samsung_rfkill {
  257. struct samsung_laptop *samsung;
  258. struct rfkill *rfkill;
  259. enum rfkill_type type;
  260. };
  261. struct samsung_laptop {
  262. const struct sabi_config *config;
  263. void __iomem *sabi;
  264. void __iomem *sabi_iface;
  265. void __iomem *f0000_segment;
  266. struct mutex sabi_mutex;
  267. struct platform_device *platform_device;
  268. struct backlight_device *backlight_device;
  269. struct samsung_rfkill wlan;
  270. struct samsung_rfkill bluetooth;
  271. struct led_classdev kbd_led;
  272. int kbd_led_wk;
  273. struct workqueue_struct *led_workqueue;
  274. struct work_struct kbd_led_work;
  275. struct samsung_laptop_debug debug;
  276. bool handle_backlight;
  277. bool has_stepping_quirk;
  278. };
  279. static bool force;
  280. module_param(force, bool, 0);
  281. MODULE_PARM_DESC(force,
  282. "Disable the DMI check and forces the driver to be loaded");
  283. static bool debug;
  284. module_param(debug, bool, S_IRUGO | S_IWUSR);
  285. MODULE_PARM_DESC(debug, "Debug enabled or not");
  286. static int sabi_command(struct samsung_laptop *samsung, u16 command,
  287. struct sabi_data *in,
  288. struct sabi_data *out)
  289. {
  290. const struct sabi_config *config = samsung->config;
  291. int ret = 0;
  292. u16 port = readw(samsung->sabi + config->header_offsets.port);
  293. u8 complete, iface_data;
  294. mutex_lock(&samsung->sabi_mutex);
  295. if (debug) {
  296. if (in)
  297. pr_info("SABI 0x%04x {0x%08x, 0x%08x, 0x%04x, 0x%02x}",
  298. command, in->d0, in->d1, in->d2, in->d3);
  299. else
  300. pr_info("SABI 0x%04x", command);
  301. }
  302. /* enable memory to be able to write to it */
  303. outb(readb(samsung->sabi + config->header_offsets.en_mem), port);
  304. /* write out the command */
  305. writew(config->main_function, samsung->sabi_iface + SABI_IFACE_MAIN);
  306. writew(command, samsung->sabi_iface + SABI_IFACE_SUB);
  307. writeb(0, samsung->sabi_iface + SABI_IFACE_COMPLETE);
  308. if (in) {
  309. writel(in->d0, samsung->sabi_iface + SABI_IFACE_DATA);
  310. writel(in->d1, samsung->sabi_iface + SABI_IFACE_DATA + 4);
  311. writew(in->d2, samsung->sabi_iface + SABI_IFACE_DATA + 8);
  312. writeb(in->d3, samsung->sabi_iface + SABI_IFACE_DATA + 10);
  313. }
  314. outb(readb(samsung->sabi + config->header_offsets.iface_func), port);
  315. /* write protect memory to make it safe */
  316. outb(readb(samsung->sabi + config->header_offsets.re_mem), port);
  317. /* see if the command actually succeeded */
  318. complete = readb(samsung->sabi_iface + SABI_IFACE_COMPLETE);
  319. iface_data = readb(samsung->sabi_iface + SABI_IFACE_DATA);
  320. if (complete != 0xaa || iface_data == 0xff) {
  321. pr_warn("SABI command 0x%04x failed with"
  322. " completion flag 0x%02x and interface data 0x%02x",
  323. command, complete, iface_data);
  324. ret = -EINVAL;
  325. goto exit;
  326. }
  327. if (out) {
  328. out->d0 = readl(samsung->sabi_iface + SABI_IFACE_DATA);
  329. out->d1 = readl(samsung->sabi_iface + SABI_IFACE_DATA + 4);
  330. out->d2 = readw(samsung->sabi_iface + SABI_IFACE_DATA + 2);
  331. out->d3 = readb(samsung->sabi_iface + SABI_IFACE_DATA + 1);
  332. }
  333. if (debug && out) {
  334. pr_info("SABI {0x%08x, 0x%08x, 0x%04x, 0x%02x}",
  335. out->d0, out->d1, out->d2, out->d3);
  336. }
  337. exit:
  338. mutex_unlock(&samsung->sabi_mutex);
  339. return ret;
  340. }
  341. /* simple wrappers usable with most commands */
  342. static int sabi_set_commandb(struct samsung_laptop *samsung,
  343. u16 command, u8 data)
  344. {
  345. struct sabi_data in = { .d0 = 0, .d1 = 0, .d2 = 0, .d3 = 0 };
  346. in.data[0] = data;
  347. return sabi_command(samsung, command, &in, NULL);
  348. }
  349. static int read_brightness(struct samsung_laptop *samsung)
  350. {
  351. const struct sabi_config *config = samsung->config;
  352. const struct sabi_commands *commands = &samsung->config->commands;
  353. struct sabi_data sretval;
  354. int user_brightness = 0;
  355. int retval;
  356. retval = sabi_command(samsung, commands->get_brightness,
  357. NULL, &sretval);
  358. if (retval)
  359. return retval;
  360. user_brightness = sretval.data[0];
  361. if (user_brightness > config->min_brightness)
  362. user_brightness -= config->min_brightness;
  363. else
  364. user_brightness = 0;
  365. return user_brightness;
  366. }
  367. static void set_brightness(struct samsung_laptop *samsung, u8 user_brightness)
  368. {
  369. const struct sabi_config *config = samsung->config;
  370. const struct sabi_commands *commands = &samsung->config->commands;
  371. u8 user_level = user_brightness + config->min_brightness;
  372. if (samsung->has_stepping_quirk && user_level != 0) {
  373. /*
  374. * short circuit if the specified level is what's already set
  375. * to prevent the screen from flickering needlessly
  376. */
  377. if (user_brightness == read_brightness(samsung))
  378. return;
  379. sabi_set_commandb(samsung, commands->set_brightness, 0);
  380. }
  381. sabi_set_commandb(samsung, commands->set_brightness, user_level);
  382. }
  383. static int get_brightness(struct backlight_device *bd)
  384. {
  385. struct samsung_laptop *samsung = bl_get_data(bd);
  386. return read_brightness(samsung);
  387. }
  388. static void check_for_stepping_quirk(struct samsung_laptop *samsung)
  389. {
  390. int initial_level;
  391. int check_level;
  392. int orig_level = read_brightness(samsung);
  393. /*
  394. * Some laptops exhibit the strange behaviour of stepping toward
  395. * (rather than setting) the brightness except when changing to/from
  396. * brightness level 0. This behaviour is checked for here and worked
  397. * around in set_brightness.
  398. */
  399. if (orig_level == 0)
  400. set_brightness(samsung, 1);
  401. initial_level = read_brightness(samsung);
  402. if (initial_level <= 2)
  403. check_level = initial_level + 2;
  404. else
  405. check_level = initial_level - 2;
  406. samsung->has_stepping_quirk = false;
  407. set_brightness(samsung, check_level);
  408. if (read_brightness(samsung) != check_level) {
  409. samsung->has_stepping_quirk = true;
  410. pr_info("enabled workaround for brightness stepping quirk\n");
  411. }
  412. set_brightness(samsung, orig_level);
  413. }
  414. static int update_status(struct backlight_device *bd)
  415. {
  416. struct samsung_laptop *samsung = bl_get_data(bd);
  417. const struct sabi_commands *commands = &samsung->config->commands;
  418. set_brightness(samsung, bd->props.brightness);
  419. if (bd->props.power == FB_BLANK_UNBLANK)
  420. sabi_set_commandb(samsung, commands->set_backlight, 1);
  421. else
  422. sabi_set_commandb(samsung, commands->set_backlight, 0);
  423. return 0;
  424. }
  425. static const struct backlight_ops backlight_ops = {
  426. .get_brightness = get_brightness,
  427. .update_status = update_status,
  428. };
  429. static int seclinux_rfkill_set(void *data, bool blocked)
  430. {
  431. struct samsung_laptop *samsung = data;
  432. const struct sabi_commands *commands = &samsung->config->commands;
  433. return sabi_set_commandb(samsung, commands->set_wireless_button,
  434. !blocked);
  435. }
  436. static struct rfkill_ops seclinux_rfkill_ops = {
  437. .set_block = seclinux_rfkill_set,
  438. };
  439. static int swsmi_wireless_status(struct samsung_laptop *samsung,
  440. struct sabi_data *data)
  441. {
  442. const struct sabi_commands *commands = &samsung->config->commands;
  443. return sabi_command(samsung, commands->get_wireless_status,
  444. NULL, data);
  445. }
  446. static int swsmi_rfkill_set(void *priv, bool blocked)
  447. {
  448. struct samsung_rfkill *srfkill = priv;
  449. struct samsung_laptop *samsung = srfkill->samsung;
  450. const struct sabi_commands *commands = &samsung->config->commands;
  451. struct sabi_data data;
  452. int ret, i;
  453. ret = swsmi_wireless_status(samsung, &data);
  454. if (ret)
  455. return ret;
  456. /* Don't set the state for non-present devices */
  457. for (i = 0; i < 4; i++)
  458. if (data.data[i] == 0x02)
  459. data.data[1] = 0;
  460. if (srfkill->type == RFKILL_TYPE_WLAN)
  461. data.data[WL_STATUS_WLAN] = !blocked;
  462. else if (srfkill->type == RFKILL_TYPE_BLUETOOTH)
  463. data.data[WL_STATUS_BT] = !blocked;
  464. return sabi_command(samsung, commands->set_wireless_status,
  465. &data, &data);
  466. }
  467. static void swsmi_rfkill_query(struct rfkill *rfkill, void *priv)
  468. {
  469. struct samsung_rfkill *srfkill = priv;
  470. struct samsung_laptop *samsung = srfkill->samsung;
  471. struct sabi_data data;
  472. int ret;
  473. ret = swsmi_wireless_status(samsung, &data);
  474. if (ret)
  475. return ;
  476. if (srfkill->type == RFKILL_TYPE_WLAN)
  477. ret = data.data[WL_STATUS_WLAN];
  478. else if (srfkill->type == RFKILL_TYPE_BLUETOOTH)
  479. ret = data.data[WL_STATUS_BT];
  480. else
  481. return ;
  482. rfkill_set_sw_state(rfkill, !ret);
  483. }
  484. static struct rfkill_ops swsmi_rfkill_ops = {
  485. .set_block = swsmi_rfkill_set,
  486. .query = swsmi_rfkill_query,
  487. };
  488. static ssize_t get_performance_level(struct device *dev,
  489. struct device_attribute *attr, char *buf)
  490. {
  491. struct samsung_laptop *samsung = dev_get_drvdata(dev);
  492. const struct sabi_config *config = samsung->config;
  493. const struct sabi_commands *commands = &config->commands;
  494. struct sabi_data sretval;
  495. int retval;
  496. int i;
  497. /* Read the state */
  498. retval = sabi_command(samsung, commands->get_performance_level,
  499. NULL, &sretval);
  500. if (retval)
  501. return retval;
  502. /* The logic is backwards, yeah, lots of fun... */
  503. for (i = 0; config->performance_levels[i].name; ++i) {
  504. if (sretval.data[0] == config->performance_levels[i].value)
  505. return sprintf(buf, "%s\n", config->performance_levels[i].name);
  506. }
  507. return sprintf(buf, "%s\n", "unknown");
  508. }
  509. static ssize_t set_performance_level(struct device *dev,
  510. struct device_attribute *attr, const char *buf,
  511. size_t count)
  512. {
  513. struct samsung_laptop *samsung = dev_get_drvdata(dev);
  514. const struct sabi_config *config = samsung->config;
  515. const struct sabi_commands *commands = &config->commands;
  516. int i;
  517. if (count < 1)
  518. return count;
  519. for (i = 0; config->performance_levels[i].name; ++i) {
  520. const struct sabi_performance_level *level =
  521. &config->performance_levels[i];
  522. if (!strncasecmp(level->name, buf, strlen(level->name))) {
  523. sabi_set_commandb(samsung,
  524. commands->set_performance_level,
  525. level->value);
  526. break;
  527. }
  528. }
  529. if (!config->performance_levels[i].name)
  530. return -EINVAL;
  531. return count;
  532. }
  533. static DEVICE_ATTR(performance_level, S_IWUSR | S_IRUGO,
  534. get_performance_level, set_performance_level);
  535. static int read_battery_life_extender(struct samsung_laptop *samsung)
  536. {
  537. const struct sabi_commands *commands = &samsung->config->commands;
  538. struct sabi_data data;
  539. int retval;
  540. if (commands->get_battery_life_extender == 0xFFFF)
  541. return -ENODEV;
  542. memset(&data, 0, sizeof(data));
  543. data.data[0] = 0x80;
  544. retval = sabi_command(samsung, commands->get_battery_life_extender,
  545. &data, &data);
  546. if (retval)
  547. return retval;
  548. if (data.data[0] != 0 && data.data[0] != 1)
  549. return -ENODEV;
  550. return data.data[0];
  551. }
  552. static int write_battery_life_extender(struct samsung_laptop *samsung,
  553. int enabled)
  554. {
  555. const struct sabi_commands *commands = &samsung->config->commands;
  556. struct sabi_data data;
  557. memset(&data, 0, sizeof(data));
  558. data.data[0] = 0x80 | enabled;
  559. return sabi_command(samsung, commands->set_battery_life_extender,
  560. &data, NULL);
  561. }
  562. static ssize_t get_battery_life_extender(struct device *dev,
  563. struct device_attribute *attr,
  564. char *buf)
  565. {
  566. struct samsung_laptop *samsung = dev_get_drvdata(dev);
  567. int ret;
  568. ret = read_battery_life_extender(samsung);
  569. if (ret < 0)
  570. return ret;
  571. return sprintf(buf, "%d\n", ret);
  572. }
  573. static ssize_t set_battery_life_extender(struct device *dev,
  574. struct device_attribute *attr,
  575. const char *buf, size_t count)
  576. {
  577. struct samsung_laptop *samsung = dev_get_drvdata(dev);
  578. int ret, value;
  579. if (!count || sscanf(buf, "%i", &value) != 1)
  580. return -EINVAL;
  581. ret = write_battery_life_extender(samsung, !!value);
  582. if (ret < 0)
  583. return ret;
  584. return count;
  585. }
  586. static DEVICE_ATTR(battery_life_extender, S_IWUSR | S_IRUGO,
  587. get_battery_life_extender, set_battery_life_extender);
  588. static int read_usb_charge(struct samsung_laptop *samsung)
  589. {
  590. const struct sabi_commands *commands = &samsung->config->commands;
  591. struct sabi_data data;
  592. int retval;
  593. if (commands->get_usb_charge == 0xFFFF)
  594. return -ENODEV;
  595. memset(&data, 0, sizeof(data));
  596. data.data[0] = 0x80;
  597. retval = sabi_command(samsung, commands->get_usb_charge,
  598. &data, &data);
  599. if (retval)
  600. return retval;
  601. if (data.data[0] != 0 && data.data[0] != 1)
  602. return -ENODEV;
  603. return data.data[0];
  604. }
  605. static int write_usb_charge(struct samsung_laptop *samsung,
  606. int enabled)
  607. {
  608. const struct sabi_commands *commands = &samsung->config->commands;
  609. struct sabi_data data;
  610. memset(&data, 0, sizeof(data));
  611. data.data[0] = 0x80 | enabled;
  612. return sabi_command(samsung, commands->set_usb_charge,
  613. &data, NULL);
  614. }
  615. static ssize_t get_usb_charge(struct device *dev,
  616. struct device_attribute *attr,
  617. char *buf)
  618. {
  619. struct samsung_laptop *samsung = dev_get_drvdata(dev);
  620. int ret;
  621. ret = read_usb_charge(samsung);
  622. if (ret < 0)
  623. return ret;
  624. return sprintf(buf, "%d\n", ret);
  625. }
  626. static ssize_t set_usb_charge(struct device *dev,
  627. struct device_attribute *attr,
  628. const char *buf, size_t count)
  629. {
  630. struct samsung_laptop *samsung = dev_get_drvdata(dev);
  631. int ret, value;
  632. if (!count || sscanf(buf, "%i", &value) != 1)
  633. return -EINVAL;
  634. ret = write_usb_charge(samsung, !!value);
  635. if (ret < 0)
  636. return ret;
  637. return count;
  638. }
  639. static DEVICE_ATTR(usb_charge, S_IWUSR | S_IRUGO,
  640. get_usb_charge, set_usb_charge);
  641. static struct attribute *platform_attributes[] = {
  642. &dev_attr_performance_level.attr,
  643. &dev_attr_battery_life_extender.attr,
  644. &dev_attr_usb_charge.attr,
  645. NULL
  646. };
  647. static int find_signature(void __iomem *memcheck, const char *testStr)
  648. {
  649. int i = 0;
  650. int loca;
  651. for (loca = 0; loca < 0xffff; loca++) {
  652. char temp = readb(memcheck + loca);
  653. if (temp == testStr[i]) {
  654. if (i == strlen(testStr)-1)
  655. break;
  656. ++i;
  657. } else {
  658. i = 0;
  659. }
  660. }
  661. return loca;
  662. }
  663. static void samsung_rfkill_exit(struct samsung_laptop *samsung)
  664. {
  665. if (samsung->wlan.rfkill) {
  666. rfkill_unregister(samsung->wlan.rfkill);
  667. rfkill_destroy(samsung->wlan.rfkill);
  668. samsung->wlan.rfkill = NULL;
  669. }
  670. if (samsung->bluetooth.rfkill) {
  671. rfkill_unregister(samsung->bluetooth.rfkill);
  672. rfkill_destroy(samsung->bluetooth.rfkill);
  673. samsung->bluetooth.rfkill = NULL;
  674. }
  675. }
  676. static int samsung_new_rfkill(struct samsung_laptop *samsung,
  677. struct samsung_rfkill *arfkill,
  678. const char *name, enum rfkill_type type,
  679. const struct rfkill_ops *ops,
  680. int blocked)
  681. {
  682. struct rfkill **rfkill = &arfkill->rfkill;
  683. int ret;
  684. arfkill->type = type;
  685. arfkill->samsung = samsung;
  686. *rfkill = rfkill_alloc(name, &samsung->platform_device->dev,
  687. type, ops, arfkill);
  688. if (!*rfkill)
  689. return -EINVAL;
  690. if (blocked != -1)
  691. rfkill_init_sw_state(*rfkill, blocked);
  692. ret = rfkill_register(*rfkill);
  693. if (ret) {
  694. rfkill_destroy(*rfkill);
  695. *rfkill = NULL;
  696. return ret;
  697. }
  698. return 0;
  699. }
  700. static int __init samsung_rfkill_init_seclinux(struct samsung_laptop *samsung)
  701. {
  702. return samsung_new_rfkill(samsung, &samsung->wlan, "samsung-wlan",
  703. RFKILL_TYPE_WLAN, &seclinux_rfkill_ops, -1);
  704. }
  705. static int __init samsung_rfkill_init_swsmi(struct samsung_laptop *samsung)
  706. {
  707. struct sabi_data data;
  708. int ret;
  709. ret = swsmi_wireless_status(samsung, &data);
  710. if (ret)
  711. return ret;
  712. /* 0x02 seems to mean that the device is no present/available */
  713. if (data.data[WL_STATUS_WLAN] != 0x02)
  714. ret = samsung_new_rfkill(samsung, &samsung->wlan,
  715. "samsung-wlan",
  716. RFKILL_TYPE_WLAN,
  717. &swsmi_rfkill_ops,
  718. !data.data[WL_STATUS_WLAN]);
  719. if (ret)
  720. goto exit;
  721. if (data.data[WL_STATUS_BT] != 0x02)
  722. ret = samsung_new_rfkill(samsung, &samsung->bluetooth,
  723. "samsung-bluetooth",
  724. RFKILL_TYPE_BLUETOOTH,
  725. &swsmi_rfkill_ops,
  726. !data.data[WL_STATUS_BT]);
  727. if (ret)
  728. goto exit;
  729. exit:
  730. if (ret)
  731. samsung_rfkill_exit(samsung);
  732. return ret;
  733. }
  734. static int __init samsung_rfkill_init(struct samsung_laptop *samsung)
  735. {
  736. if (samsung->config->sabi_version == 2)
  737. return samsung_rfkill_init_seclinux(samsung);
  738. if (samsung->config->sabi_version == 3)
  739. return samsung_rfkill_init_swsmi(samsung);
  740. return 0;
  741. }
  742. static int kbd_backlight_enable(struct samsung_laptop *samsung)
  743. {
  744. const struct sabi_commands *commands = &samsung->config->commands;
  745. struct sabi_data data;
  746. int retval;
  747. if (commands->kbd_backlight == 0xFFFF)
  748. return -ENODEV;
  749. memset(&data, 0, sizeof(data));
  750. data.d0 = 0xaabb;
  751. retval = sabi_command(samsung, commands->kbd_backlight,
  752. &data, &data);
  753. if (retval)
  754. return retval;
  755. if (data.d0 != 0xccdd)
  756. return -ENODEV;
  757. return 0;
  758. }
  759. static int kbd_backlight_read(struct samsung_laptop *samsung)
  760. {
  761. const struct sabi_commands *commands = &samsung->config->commands;
  762. struct sabi_data data;
  763. int retval;
  764. memset(&data, 0, sizeof(data));
  765. data.data[0] = 0x81;
  766. retval = sabi_command(samsung, commands->kbd_backlight,
  767. &data, &data);
  768. if (retval)
  769. return retval;
  770. return data.data[0];
  771. }
  772. static int kbd_backlight_write(struct samsung_laptop *samsung, int brightness)
  773. {
  774. const struct sabi_commands *commands = &samsung->config->commands;
  775. struct sabi_data data;
  776. memset(&data, 0, sizeof(data));
  777. data.d0 = 0x82 | ((brightness & 0xFF) << 8);
  778. return sabi_command(samsung, commands->kbd_backlight,
  779. &data, NULL);
  780. }
  781. static void kbd_led_update(struct work_struct *work)
  782. {
  783. struct samsung_laptop *samsung;
  784. samsung = container_of(work, struct samsung_laptop, kbd_led_work);
  785. kbd_backlight_write(samsung, samsung->kbd_led_wk);
  786. }
  787. static void kbd_led_set(struct led_classdev *led_cdev,
  788. enum led_brightness value)
  789. {
  790. struct samsung_laptop *samsung;
  791. samsung = container_of(led_cdev, struct samsung_laptop, kbd_led);
  792. if (value > samsung->kbd_led.max_brightness)
  793. value = samsung->kbd_led.max_brightness;
  794. else if (value < 0)
  795. value = 0;
  796. samsung->kbd_led_wk = value;
  797. queue_work(samsung->led_workqueue, &samsung->kbd_led_work);
  798. }
  799. static enum led_brightness kbd_led_get(struct led_classdev *led_cdev)
  800. {
  801. struct samsung_laptop *samsung;
  802. samsung = container_of(led_cdev, struct samsung_laptop, kbd_led);
  803. return kbd_backlight_read(samsung);
  804. }
  805. static void samsung_leds_exit(struct samsung_laptop *samsung)
  806. {
  807. if (!IS_ERR_OR_NULL(samsung->kbd_led.dev))
  808. led_classdev_unregister(&samsung->kbd_led);
  809. if (samsung->led_workqueue)
  810. destroy_workqueue(samsung->led_workqueue);
  811. }
  812. static int __init samsung_leds_init(struct samsung_laptop *samsung)
  813. {
  814. int ret = 0;
  815. samsung->led_workqueue = create_singlethread_workqueue("led_workqueue");
  816. if (!samsung->led_workqueue)
  817. return -ENOMEM;
  818. if (kbd_backlight_enable(samsung) >= 0) {
  819. INIT_WORK(&samsung->kbd_led_work, kbd_led_update);
  820. samsung->kbd_led.name = "samsung::kbd_backlight";
  821. samsung->kbd_led.brightness_set = kbd_led_set;
  822. samsung->kbd_led.brightness_get = kbd_led_get;
  823. samsung->kbd_led.max_brightness = 8;
  824. ret = led_classdev_register(&samsung->platform_device->dev,
  825. &samsung->kbd_led);
  826. }
  827. if (ret)
  828. samsung_leds_exit(samsung);
  829. return ret;
  830. }
  831. static void samsung_backlight_exit(struct samsung_laptop *samsung)
  832. {
  833. if (samsung->backlight_device) {
  834. backlight_device_unregister(samsung->backlight_device);
  835. samsung->backlight_device = NULL;
  836. }
  837. }
  838. static int __init samsung_backlight_init(struct samsung_laptop *samsung)
  839. {
  840. struct backlight_device *bd;
  841. struct backlight_properties props;
  842. if (!samsung->handle_backlight)
  843. return 0;
  844. memset(&props, 0, sizeof(struct backlight_properties));
  845. props.type = BACKLIGHT_PLATFORM;
  846. props.max_brightness = samsung->config->max_brightness -
  847. samsung->config->min_brightness;
  848. bd = backlight_device_register("samsung",
  849. &samsung->platform_device->dev,
  850. samsung, &backlight_ops,
  851. &props);
  852. if (IS_ERR(bd))
  853. return PTR_ERR(bd);
  854. samsung->backlight_device = bd;
  855. samsung->backlight_device->props.brightness = read_brightness(samsung);
  856. samsung->backlight_device->props.power = FB_BLANK_UNBLANK;
  857. backlight_update_status(samsung->backlight_device);
  858. return 0;
  859. }
  860. static mode_t samsung_sysfs_is_visible(struct kobject *kobj,
  861. struct attribute *attr, int idx)
  862. {
  863. struct device *dev = container_of(kobj, struct device, kobj);
  864. struct platform_device *pdev = to_platform_device(dev);
  865. struct samsung_laptop *samsung = platform_get_drvdata(pdev);
  866. bool ok = true;
  867. if (attr == &dev_attr_performance_level.attr)
  868. ok = !!samsung->config->performance_levels[0].name;
  869. if (attr == &dev_attr_battery_life_extender.attr)
  870. ok = !!(read_battery_life_extender(samsung) >= 0);
  871. if (attr == &dev_attr_usb_charge.attr)
  872. ok = !!(read_usb_charge(samsung) >= 0);
  873. return ok ? attr->mode : 0;
  874. }
  875. static struct attribute_group platform_attribute_group = {
  876. .is_visible = samsung_sysfs_is_visible,
  877. .attrs = platform_attributes
  878. };
  879. static void samsung_sysfs_exit(struct samsung_laptop *samsung)
  880. {
  881. struct platform_device *device = samsung->platform_device;
  882. sysfs_remove_group(&device->dev.kobj, &platform_attribute_group);
  883. }
  884. static int __init samsung_sysfs_init(struct samsung_laptop *samsung)
  885. {
  886. struct platform_device *device = samsung->platform_device;
  887. return sysfs_create_group(&device->dev.kobj, &platform_attribute_group);
  888. }
  889. static int show_call(struct seq_file *m, void *data)
  890. {
  891. struct samsung_laptop *samsung = m->private;
  892. struct sabi_data *sdata = &samsung->debug.data;
  893. int ret;
  894. seq_printf(m, "SABI 0x%04x {0x%08x, 0x%08x, 0x%04x, 0x%02x}\n",
  895. samsung->debug.command,
  896. sdata->d0, sdata->d1, sdata->d2, sdata->d3);
  897. ret = sabi_command(samsung, samsung->debug.command, sdata, sdata);
  898. if (ret) {
  899. seq_printf(m, "SABI command 0x%04x failed\n",
  900. samsung->debug.command);
  901. return ret;
  902. }
  903. seq_printf(m, "SABI {0x%08x, 0x%08x, 0x%04x, 0x%02x}\n",
  904. sdata->d0, sdata->d1, sdata->d2, sdata->d3);
  905. return 0;
  906. }
  907. static int samsung_debugfs_open(struct inode *inode, struct file *file)
  908. {
  909. return single_open(file, show_call, inode->i_private);
  910. }
  911. static const struct file_operations samsung_laptop_call_io_ops = {
  912. .owner = THIS_MODULE,
  913. .open = samsung_debugfs_open,
  914. .read = seq_read,
  915. .llseek = seq_lseek,
  916. .release = single_release,
  917. };
  918. static void samsung_debugfs_exit(struct samsung_laptop *samsung)
  919. {
  920. debugfs_remove_recursive(samsung->debug.root);
  921. }
  922. static int samsung_debugfs_init(struct samsung_laptop *samsung)
  923. {
  924. struct dentry *dent;
  925. samsung->debug.root = debugfs_create_dir("samsung-laptop", NULL);
  926. if (!samsung->debug.root) {
  927. pr_err("failed to create debugfs directory");
  928. goto error_debugfs;
  929. }
  930. samsung->debug.f0000_wrapper.data = samsung->f0000_segment;
  931. samsung->debug.f0000_wrapper.size = 0xffff;
  932. samsung->debug.data_wrapper.data = &samsung->debug.data;
  933. samsung->debug.data_wrapper.size = sizeof(samsung->debug.data);
  934. dent = debugfs_create_u16("command", S_IRUGO | S_IWUSR,
  935. samsung->debug.root, &samsung->debug.command);
  936. if (!dent)
  937. goto error_debugfs;
  938. dent = debugfs_create_u32("d0", S_IRUGO | S_IWUSR, samsung->debug.root,
  939. &samsung->debug.data.d0);
  940. if (!dent)
  941. goto error_debugfs;
  942. dent = debugfs_create_u32("d1", S_IRUGO | S_IWUSR, samsung->debug.root,
  943. &samsung->debug.data.d1);
  944. if (!dent)
  945. goto error_debugfs;
  946. dent = debugfs_create_u16("d2", S_IRUGO | S_IWUSR, samsung->debug.root,
  947. &samsung->debug.data.d2);
  948. if (!dent)
  949. goto error_debugfs;
  950. dent = debugfs_create_u8("d3", S_IRUGO | S_IWUSR, samsung->debug.root,
  951. &samsung->debug.data.d3);
  952. if (!dent)
  953. goto error_debugfs;
  954. dent = debugfs_create_blob("data", S_IRUGO | S_IWUSR,
  955. samsung->debug.root,
  956. &samsung->debug.data_wrapper);
  957. if (!dent)
  958. goto error_debugfs;
  959. dent = debugfs_create_blob("f0000_segment", S_IRUSR | S_IWUSR,
  960. samsung->debug.root,
  961. &samsung->debug.f0000_wrapper);
  962. if (!dent)
  963. goto error_debugfs;
  964. dent = debugfs_create_file("call", S_IFREG | S_IRUGO,
  965. samsung->debug.root, samsung,
  966. &samsung_laptop_call_io_ops);
  967. if (!dent)
  968. goto error_debugfs;
  969. return 0;
  970. error_debugfs:
  971. samsung_debugfs_exit(samsung);
  972. return -ENOMEM;
  973. }
  974. static void samsung_sabi_exit(struct samsung_laptop *samsung)
  975. {
  976. const struct sabi_config *config = samsung->config;
  977. /* Turn off "Linux" mode in the BIOS */
  978. if (config && config->commands.set_linux != 0xff)
  979. sabi_set_commandb(samsung, config->commands.set_linux, 0x80);
  980. if (samsung->sabi_iface) {
  981. iounmap(samsung->sabi_iface);
  982. samsung->sabi_iface = NULL;
  983. }
  984. if (samsung->f0000_segment) {
  985. iounmap(samsung->f0000_segment);
  986. samsung->f0000_segment = NULL;
  987. }
  988. samsung->config = NULL;
  989. }
  990. static __init void samsung_sabi_infos(struct samsung_laptop *samsung, int loca,
  991. unsigned int ifaceP)
  992. {
  993. const struct sabi_config *config = samsung->config;
  994. printk(KERN_DEBUG "This computer supports SABI==%x\n",
  995. loca + 0xf0000 - 6);
  996. printk(KERN_DEBUG "SABI header:\n");
  997. printk(KERN_DEBUG " SMI Port Number = 0x%04x\n",
  998. readw(samsung->sabi + config->header_offsets.port));
  999. printk(KERN_DEBUG " SMI Interface Function = 0x%02x\n",
  1000. readb(samsung->sabi + config->header_offsets.iface_func));
  1001. printk(KERN_DEBUG " SMI enable memory buffer = 0x%02x\n",
  1002. readb(samsung->sabi + config->header_offsets.en_mem));
  1003. printk(KERN_DEBUG " SMI restore memory buffer = 0x%02x\n",
  1004. readb(samsung->sabi + config->header_offsets.re_mem));
  1005. printk(KERN_DEBUG " SABI data offset = 0x%04x\n",
  1006. readw(samsung->sabi + config->header_offsets.data_offset));
  1007. printk(KERN_DEBUG " SABI data segment = 0x%04x\n",
  1008. readw(samsung->sabi + config->header_offsets.data_segment));
  1009. printk(KERN_DEBUG " SABI pointer = 0x%08x\n", ifaceP);
  1010. }
  1011. static int __init samsung_sabi_init(struct samsung_laptop *samsung)
  1012. {
  1013. const struct sabi_config *config = NULL;
  1014. const struct sabi_commands *commands;
  1015. unsigned int ifaceP;
  1016. int ret = 0;
  1017. int i;
  1018. int loca;
  1019. samsung->f0000_segment = ioremap_nocache(0xf0000, 0xffff);
  1020. if (!samsung->f0000_segment) {
  1021. pr_err("Can't map the segment at 0xf0000\n");
  1022. ret = -EINVAL;
  1023. goto exit;
  1024. }
  1025. /* Try to find one of the signatures in memory to find the header */
  1026. for (i = 0; sabi_configs[i].test_string != 0; ++i) {
  1027. samsung->config = &sabi_configs[i];
  1028. loca = find_signature(samsung->f0000_segment,
  1029. samsung->config->test_string);
  1030. if (loca != 0xffff)
  1031. break;
  1032. }
  1033. if (loca == 0xffff) {
  1034. pr_err("This computer does not support SABI\n");
  1035. ret = -ENODEV;
  1036. goto exit;
  1037. }
  1038. config = samsung->config;
  1039. commands = &config->commands;
  1040. /* point to the SMI port Number */
  1041. loca += 1;
  1042. samsung->sabi = (samsung->f0000_segment + loca);
  1043. /* Get a pointer to the SABI Interface */
  1044. ifaceP = (readw(samsung->sabi + config->header_offsets.data_segment) & 0x0ffff) << 4;
  1045. ifaceP += readw(samsung->sabi + config->header_offsets.data_offset) & 0x0ffff;
  1046. if (debug)
  1047. samsung_sabi_infos(samsung, loca, ifaceP);
  1048. samsung->sabi_iface = ioremap_nocache(ifaceP, 16);
  1049. if (!samsung->sabi_iface) {
  1050. pr_err("Can't remap %x\n", ifaceP);
  1051. ret = -EINVAL;
  1052. goto exit;
  1053. }
  1054. /* Turn on "Linux" mode in the BIOS */
  1055. if (commands->set_linux != 0xff) {
  1056. int retval = sabi_set_commandb(samsung,
  1057. commands->set_linux, 0x81);
  1058. if (retval) {
  1059. pr_warn("Linux mode was not set!\n");
  1060. ret = -ENODEV;
  1061. goto exit;
  1062. }
  1063. }
  1064. /* Check for stepping quirk */
  1065. if (samsung->handle_backlight)
  1066. check_for_stepping_quirk(samsung);
  1067. exit:
  1068. if (ret)
  1069. samsung_sabi_exit(samsung);
  1070. return ret;
  1071. }
  1072. static void samsung_platform_exit(struct samsung_laptop *samsung)
  1073. {
  1074. if (samsung->platform_device) {
  1075. platform_device_unregister(samsung->platform_device);
  1076. samsung->platform_device = NULL;
  1077. }
  1078. }
  1079. static int __init samsung_platform_init(struct samsung_laptop *samsung)
  1080. {
  1081. struct platform_device *pdev;
  1082. pdev = platform_device_register_simple("samsung", -1, NULL, 0);
  1083. if (IS_ERR(pdev))
  1084. return PTR_ERR(pdev);
  1085. samsung->platform_device = pdev;
  1086. platform_set_drvdata(samsung->platform_device, samsung);
  1087. return 0;
  1088. }
  1089. static int __init dmi_check_cb(const struct dmi_system_id *id)
  1090. {
  1091. pr_info("found laptop model '%s'\n", id->ident);
  1092. return 1;
  1093. }
  1094. static struct dmi_system_id __initdata samsung_dmi_table[] = {
  1095. {
  1096. .ident = "N128",
  1097. .matches = {
  1098. DMI_MATCH(DMI_SYS_VENDOR,
  1099. "SAMSUNG ELECTRONICS CO., LTD."),
  1100. DMI_MATCH(DMI_PRODUCT_NAME, "N128"),
  1101. DMI_MATCH(DMI_BOARD_NAME, "N128"),
  1102. },
  1103. .callback = dmi_check_cb,
  1104. },
  1105. {
  1106. .ident = "N130",
  1107. .matches = {
  1108. DMI_MATCH(DMI_SYS_VENDOR,
  1109. "SAMSUNG ELECTRONICS CO., LTD."),
  1110. DMI_MATCH(DMI_PRODUCT_NAME, "N130"),
  1111. DMI_MATCH(DMI_BOARD_NAME, "N130"),
  1112. },
  1113. .callback = dmi_check_cb,
  1114. },
  1115. {
  1116. .ident = "N510",
  1117. .matches = {
  1118. DMI_MATCH(DMI_SYS_VENDOR,
  1119. "SAMSUNG ELECTRONICS CO., LTD."),
  1120. DMI_MATCH(DMI_PRODUCT_NAME, "N510"),
  1121. DMI_MATCH(DMI_BOARD_NAME, "N510"),
  1122. },
  1123. .callback = dmi_check_cb,
  1124. },
  1125. {
  1126. .ident = "X125",
  1127. .matches = {
  1128. DMI_MATCH(DMI_SYS_VENDOR,
  1129. "SAMSUNG ELECTRONICS CO., LTD."),
  1130. DMI_MATCH(DMI_PRODUCT_NAME, "X125"),
  1131. DMI_MATCH(DMI_BOARD_NAME, "X125"),
  1132. },
  1133. .callback = dmi_check_cb,
  1134. },
  1135. {
  1136. .ident = "X120/X170",
  1137. .matches = {
  1138. DMI_MATCH(DMI_SYS_VENDOR,
  1139. "SAMSUNG ELECTRONICS CO., LTD."),
  1140. DMI_MATCH(DMI_PRODUCT_NAME, "X120/X170"),
  1141. DMI_MATCH(DMI_BOARD_NAME, "X120/X170"),
  1142. },
  1143. .callback = dmi_check_cb,
  1144. },
  1145. {
  1146. .ident = "NC10",
  1147. .matches = {
  1148. DMI_MATCH(DMI_SYS_VENDOR,
  1149. "SAMSUNG ELECTRONICS CO., LTD."),
  1150. DMI_MATCH(DMI_PRODUCT_NAME, "NC10"),
  1151. DMI_MATCH(DMI_BOARD_NAME, "NC10"),
  1152. },
  1153. .callback = dmi_check_cb,
  1154. },
  1155. {
  1156. .ident = "NP-Q45",
  1157. .matches = {
  1158. DMI_MATCH(DMI_SYS_VENDOR,
  1159. "SAMSUNG ELECTRONICS CO., LTD."),
  1160. DMI_MATCH(DMI_PRODUCT_NAME, "SQ45S70S"),
  1161. DMI_MATCH(DMI_BOARD_NAME, "SQ45S70S"),
  1162. },
  1163. .callback = dmi_check_cb,
  1164. },
  1165. {
  1166. .ident = "X360",
  1167. .matches = {
  1168. DMI_MATCH(DMI_SYS_VENDOR,
  1169. "SAMSUNG ELECTRONICS CO., LTD."),
  1170. DMI_MATCH(DMI_PRODUCT_NAME, "X360"),
  1171. DMI_MATCH(DMI_BOARD_NAME, "X360"),
  1172. },
  1173. .callback = dmi_check_cb,
  1174. },
  1175. {
  1176. .ident = "R410 Plus",
  1177. .matches = {
  1178. DMI_MATCH(DMI_SYS_VENDOR,
  1179. "SAMSUNG ELECTRONICS CO., LTD."),
  1180. DMI_MATCH(DMI_PRODUCT_NAME, "R410P"),
  1181. DMI_MATCH(DMI_BOARD_NAME, "R460"),
  1182. },
  1183. .callback = dmi_check_cb,
  1184. },
  1185. {
  1186. .ident = "R518",
  1187. .matches = {
  1188. DMI_MATCH(DMI_SYS_VENDOR,
  1189. "SAMSUNG ELECTRONICS CO., LTD."),
  1190. DMI_MATCH(DMI_PRODUCT_NAME, "R518"),
  1191. DMI_MATCH(DMI_BOARD_NAME, "R518"),
  1192. },
  1193. .callback = dmi_check_cb,
  1194. },
  1195. {
  1196. .ident = "R519/R719",
  1197. .matches = {
  1198. DMI_MATCH(DMI_SYS_VENDOR,
  1199. "SAMSUNG ELECTRONICS CO., LTD."),
  1200. DMI_MATCH(DMI_PRODUCT_NAME, "R519/R719"),
  1201. DMI_MATCH(DMI_BOARD_NAME, "R519/R719"),
  1202. },
  1203. .callback = dmi_check_cb,
  1204. },
  1205. {
  1206. .ident = "N150/N210/N220",
  1207. .matches = {
  1208. DMI_MATCH(DMI_SYS_VENDOR,
  1209. "SAMSUNG ELECTRONICS CO., LTD."),
  1210. DMI_MATCH(DMI_PRODUCT_NAME, "N150/N210/N220"),
  1211. DMI_MATCH(DMI_BOARD_NAME, "N150/N210/N220"),
  1212. },
  1213. .callback = dmi_check_cb,
  1214. },
  1215. {
  1216. .ident = "N220",
  1217. .matches = {
  1218. DMI_MATCH(DMI_SYS_VENDOR,
  1219. "SAMSUNG ELECTRONICS CO., LTD."),
  1220. DMI_MATCH(DMI_PRODUCT_NAME, "N220"),
  1221. DMI_MATCH(DMI_BOARD_NAME, "N220"),
  1222. },
  1223. .callback = dmi_check_cb,
  1224. },
  1225. {
  1226. .ident = "N150/N210/N220/N230",
  1227. .matches = {
  1228. DMI_MATCH(DMI_SYS_VENDOR,
  1229. "SAMSUNG ELECTRONICS CO., LTD."),
  1230. DMI_MATCH(DMI_PRODUCT_NAME, "N150/N210/N220/N230"),
  1231. DMI_MATCH(DMI_BOARD_NAME, "N150/N210/N220/N230"),
  1232. },
  1233. .callback = dmi_check_cb,
  1234. },
  1235. {
  1236. .ident = "N150P/N210P/N220P",
  1237. .matches = {
  1238. DMI_MATCH(DMI_SYS_VENDOR,
  1239. "SAMSUNG ELECTRONICS CO., LTD."),
  1240. DMI_MATCH(DMI_PRODUCT_NAME, "N150P/N210P/N220P"),
  1241. DMI_MATCH(DMI_BOARD_NAME, "N150P/N210P/N220P"),
  1242. },
  1243. .callback = dmi_check_cb,
  1244. },
  1245. {
  1246. .ident = "R700",
  1247. .matches = {
  1248. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
  1249. DMI_MATCH(DMI_PRODUCT_NAME, "SR700"),
  1250. DMI_MATCH(DMI_BOARD_NAME, "SR700"),
  1251. },
  1252. .callback = dmi_check_cb,
  1253. },
  1254. {
  1255. .ident = "R530/R730",
  1256. .matches = {
  1257. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
  1258. DMI_MATCH(DMI_PRODUCT_NAME, "R530/R730"),
  1259. DMI_MATCH(DMI_BOARD_NAME, "R530/R730"),
  1260. },
  1261. .callback = dmi_check_cb,
  1262. },
  1263. {
  1264. .ident = "NF110/NF210/NF310",
  1265. .matches = {
  1266. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
  1267. DMI_MATCH(DMI_PRODUCT_NAME, "NF110/NF210/NF310"),
  1268. DMI_MATCH(DMI_BOARD_NAME, "NF110/NF210/NF310"),
  1269. },
  1270. .callback = dmi_check_cb,
  1271. },
  1272. {
  1273. .ident = "N145P/N250P/N260P",
  1274. .matches = {
  1275. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
  1276. DMI_MATCH(DMI_PRODUCT_NAME, "N145P/N250P/N260P"),
  1277. DMI_MATCH(DMI_BOARD_NAME, "N145P/N250P/N260P"),
  1278. },
  1279. .callback = dmi_check_cb,
  1280. },
  1281. {
  1282. .ident = "R70/R71",
  1283. .matches = {
  1284. DMI_MATCH(DMI_SYS_VENDOR,
  1285. "SAMSUNG ELECTRONICS CO., LTD."),
  1286. DMI_MATCH(DMI_PRODUCT_NAME, "R70/R71"),
  1287. DMI_MATCH(DMI_BOARD_NAME, "R70/R71"),
  1288. },
  1289. .callback = dmi_check_cb,
  1290. },
  1291. {
  1292. .ident = "P460",
  1293. .matches = {
  1294. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
  1295. DMI_MATCH(DMI_PRODUCT_NAME, "P460"),
  1296. DMI_MATCH(DMI_BOARD_NAME, "P460"),
  1297. },
  1298. .callback = dmi_check_cb,
  1299. },
  1300. {
  1301. .ident = "R528/R728",
  1302. .matches = {
  1303. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
  1304. DMI_MATCH(DMI_PRODUCT_NAME, "R528/R728"),
  1305. DMI_MATCH(DMI_BOARD_NAME, "R528/R728"),
  1306. },
  1307. .callback = dmi_check_cb,
  1308. },
  1309. {
  1310. .ident = "NC210/NC110",
  1311. .matches = {
  1312. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
  1313. DMI_MATCH(DMI_PRODUCT_NAME, "NC210/NC110"),
  1314. DMI_MATCH(DMI_BOARD_NAME, "NC210/NC110"),
  1315. },
  1316. .callback = dmi_check_cb,
  1317. },
  1318. {
  1319. .ident = "X520",
  1320. .matches = {
  1321. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
  1322. DMI_MATCH(DMI_PRODUCT_NAME, "X520"),
  1323. DMI_MATCH(DMI_BOARD_NAME, "X520"),
  1324. },
  1325. .callback = dmi_check_cb,
  1326. },
  1327. { },
  1328. };
  1329. MODULE_DEVICE_TABLE(dmi, samsung_dmi_table);
  1330. static struct platform_device *samsung_platform_device;
  1331. static int __init samsung_init(void)
  1332. {
  1333. struct samsung_laptop *samsung;
  1334. int ret;
  1335. if (!force && !dmi_check_system(samsung_dmi_table))
  1336. return -ENODEV;
  1337. samsung = kzalloc(sizeof(*samsung), GFP_KERNEL);
  1338. if (!samsung)
  1339. return -ENOMEM;
  1340. mutex_init(&samsung->sabi_mutex);
  1341. samsung->handle_backlight = true;
  1342. #ifdef CONFIG_ACPI
  1343. /* Don't handle backlight here if the acpi video already handle it */
  1344. if (acpi_video_backlight_support()) {
  1345. pr_info("Backlight controlled by ACPI video driver\n");
  1346. samsung->handle_backlight = false;
  1347. }
  1348. #endif
  1349. ret = samsung_platform_init(samsung);
  1350. if (ret)
  1351. goto error_platform;
  1352. ret = samsung_sabi_init(samsung);
  1353. if (ret)
  1354. goto error_sabi;
  1355. ret = samsung_sysfs_init(samsung);
  1356. if (ret)
  1357. goto error_sysfs;
  1358. ret = samsung_backlight_init(samsung);
  1359. if (ret)
  1360. goto error_backlight;
  1361. ret = samsung_rfkill_init(samsung);
  1362. if (ret)
  1363. goto error_rfkill;
  1364. ret = samsung_leds_init(samsung);
  1365. if (ret)
  1366. goto error_leds;
  1367. ret = samsung_debugfs_init(samsung);
  1368. if (ret)
  1369. goto error_debugfs;
  1370. samsung_platform_device = samsung->platform_device;
  1371. return ret;
  1372. error_debugfs:
  1373. samsung_leds_exit(samsung);
  1374. error_leds:
  1375. samsung_rfkill_exit(samsung);
  1376. error_rfkill:
  1377. samsung_backlight_exit(samsung);
  1378. error_backlight:
  1379. samsung_sysfs_exit(samsung);
  1380. error_sysfs:
  1381. samsung_sabi_exit(samsung);
  1382. error_sabi:
  1383. samsung_platform_exit(samsung);
  1384. error_platform:
  1385. kfree(samsung);
  1386. return ret;
  1387. }
  1388. static void __exit samsung_exit(void)
  1389. {
  1390. struct samsung_laptop *samsung;
  1391. samsung = platform_get_drvdata(samsung_platform_device);
  1392. samsung_debugfs_exit(samsung);
  1393. samsung_leds_exit(samsung);
  1394. samsung_rfkill_exit(samsung);
  1395. samsung_backlight_exit(samsung);
  1396. samsung_sysfs_exit(samsung);
  1397. samsung_sabi_exit(samsung);
  1398. samsung_platform_exit(samsung);
  1399. kfree(samsung);
  1400. samsung_platform_device = NULL;
  1401. }
  1402. module_init(samsung_init);
  1403. module_exit(samsung_exit);
  1404. MODULE_AUTHOR("Greg Kroah-Hartman <gregkh@suse.de>");
  1405. MODULE_DESCRIPTION("Samsung Backlight driver");
  1406. MODULE_LICENSE("GPL");