msi-laptop.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903
  1. /*-*-linux-c-*-*/
  2. /*
  3. Copyright (C) 2006 Lennart Poettering <mzxreary (at) 0pointer (dot) de>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  15. 02110-1301, USA.
  16. */
  17. /*
  18. * msi-laptop.c - MSI S270 laptop support. This laptop is sold under
  19. * various brands, including "Cytron/TCM/Medion/Tchibo MD96100".
  20. *
  21. * Driver also supports S271, S420 models.
  22. *
  23. * This driver exports a few files in /sys/devices/platform/msi-laptop-pf/:
  24. *
  25. * lcd_level - Screen brightness: contains a single integer in the
  26. * range 0..8. (rw)
  27. *
  28. * auto_brightness - Enable automatic brightness control: contains
  29. * either 0 or 1. If set to 1 the hardware adjusts the screen
  30. * brightness automatically when the power cord is
  31. * plugged/unplugged. (rw)
  32. *
  33. * wlan - WLAN subsystem enabled: contains either 0 or 1. (ro)
  34. *
  35. * bluetooth - Bluetooth subsystem enabled: contains either 0 or 1
  36. * Please note that this file is constantly 0 if no Bluetooth
  37. * hardware is available. (ro)
  38. *
  39. * In addition to these platform device attributes the driver
  40. * registers itself in the Linux backlight control subsystem and is
  41. * available to userspace under /sys/class/backlight/msi-laptop-bl/.
  42. *
  43. * This driver might work on other laptops produced by MSI. If you
  44. * want to try it you can pass force=1 as argument to the module which
  45. * will force it to load even when the DMI data doesn't identify the
  46. * laptop as MSI S270. YMMV.
  47. */
  48. #include <linux/module.h>
  49. #include <linux/kernel.h>
  50. #include <linux/init.h>
  51. #include <linux/acpi.h>
  52. #include <linux/dmi.h>
  53. #include <linux/backlight.h>
  54. #include <linux/platform_device.h>
  55. #include <linux/rfkill.h>
  56. #include <linux/i8042.h>
  57. #define MSI_DRIVER_VERSION "0.5"
  58. #define MSI_LCD_LEVEL_MAX 9
  59. #define MSI_EC_COMMAND_WIRELESS 0x10
  60. #define MSI_EC_COMMAND_LCD_LEVEL 0x11
  61. #define MSI_STANDARD_EC_COMMAND_ADDRESS 0x2e
  62. #define MSI_STANDARD_EC_BLUETOOTH_MASK (1 << 0)
  63. #define MSI_STANDARD_EC_WEBCAM_MASK (1 << 1)
  64. #define MSI_STANDARD_EC_WLAN_MASK (1 << 3)
  65. #define MSI_STANDARD_EC_3G_MASK (1 << 4)
  66. /* For set SCM load flag to disable BIOS fn key */
  67. #define MSI_STANDARD_EC_SCM_LOAD_ADDRESS 0x2d
  68. #define MSI_STANDARD_EC_SCM_LOAD_MASK (1 << 0)
  69. static int msi_laptop_resume(struct platform_device *device);
  70. #define MSI_STANDARD_EC_DEVICES_EXISTS_ADDRESS 0x2f
  71. static int force;
  72. module_param(force, bool, 0);
  73. MODULE_PARM_DESC(force, "Force driver load, ignore DMI data");
  74. static int auto_brightness;
  75. module_param(auto_brightness, int, 0);
  76. MODULE_PARM_DESC(auto_brightness, "Enable automatic brightness control (0: disabled; 1: enabled; 2: don't touch)");
  77. static bool old_ec_model;
  78. static int wlan_s, bluetooth_s, threeg_s;
  79. static int threeg_exists;
  80. /* Some MSI 3G netbook only have one fn key to control Wlan/Bluetooth/3G,
  81. * those netbook will load the SCM (windows app) to disable the original
  82. * Wlan/Bluetooth control by BIOS when user press fn key, then control
  83. * Wlan/Bluetooth/3G by SCM (software control by OS). Without SCM, user
  84. * cann't on/off 3G module on those 3G netbook.
  85. * On Linux, msi-laptop driver will do the same thing to disable the
  86. * original BIOS control, then might need use HAL or other userland
  87. * application to do the software control that simulate with SCM.
  88. * e.g. MSI N034 netbook
  89. */
  90. static bool load_scm_model;
  91. static struct rfkill *rfk_wlan, *rfk_bluetooth, *rfk_threeg;
  92. /* Hardware access */
  93. static int set_lcd_level(int level)
  94. {
  95. u8 buf[2];
  96. if (level < 0 || level >= MSI_LCD_LEVEL_MAX)
  97. return -EINVAL;
  98. buf[0] = 0x80;
  99. buf[1] = (u8) (level*31);
  100. return ec_transaction(MSI_EC_COMMAND_LCD_LEVEL, buf, sizeof(buf), NULL, 0, 1);
  101. }
  102. static int get_lcd_level(void)
  103. {
  104. u8 wdata = 0, rdata;
  105. int result;
  106. result = ec_transaction(MSI_EC_COMMAND_LCD_LEVEL, &wdata, 1, &rdata, 1, 1);
  107. if (result < 0)
  108. return result;
  109. return (int) rdata / 31;
  110. }
  111. static int get_auto_brightness(void)
  112. {
  113. u8 wdata = 4, rdata;
  114. int result;
  115. result = ec_transaction(MSI_EC_COMMAND_LCD_LEVEL, &wdata, 1, &rdata, 1, 1);
  116. if (result < 0)
  117. return result;
  118. return !!(rdata & 8);
  119. }
  120. static int set_auto_brightness(int enable)
  121. {
  122. u8 wdata[2], rdata;
  123. int result;
  124. wdata[0] = 4;
  125. result = ec_transaction(MSI_EC_COMMAND_LCD_LEVEL, wdata, 1, &rdata, 1, 1);
  126. if (result < 0)
  127. return result;
  128. wdata[0] = 0x84;
  129. wdata[1] = (rdata & 0xF7) | (enable ? 8 : 0);
  130. return ec_transaction(MSI_EC_COMMAND_LCD_LEVEL, wdata, 2, NULL, 0, 1);
  131. }
  132. static ssize_t set_device_state(const char *buf, size_t count, u8 mask)
  133. {
  134. int status;
  135. u8 wdata = 0, rdata;
  136. int result;
  137. if (sscanf(buf, "%i", &status) != 1 || (status < 0 || status > 1))
  138. return -EINVAL;
  139. /* read current device state */
  140. result = ec_read(MSI_STANDARD_EC_COMMAND_ADDRESS, &rdata);
  141. if (result < 0)
  142. return -EINVAL;
  143. if (!!(rdata & mask) != status) {
  144. /* reverse device bit */
  145. if (rdata & mask)
  146. wdata = rdata & ~mask;
  147. else
  148. wdata = rdata | mask;
  149. result = ec_write(MSI_STANDARD_EC_COMMAND_ADDRESS, wdata);
  150. if (result < 0)
  151. return -EINVAL;
  152. }
  153. return count;
  154. }
  155. static int get_wireless_state(int *wlan, int *bluetooth)
  156. {
  157. u8 wdata = 0, rdata;
  158. int result;
  159. result = ec_transaction(MSI_EC_COMMAND_WIRELESS, &wdata, 1, &rdata, 1, 1);
  160. if (result < 0)
  161. return -1;
  162. if (wlan)
  163. *wlan = !!(rdata & 8);
  164. if (bluetooth)
  165. *bluetooth = !!(rdata & 128);
  166. return 0;
  167. }
  168. static int get_wireless_state_ec_standard(void)
  169. {
  170. u8 rdata;
  171. int result;
  172. result = ec_read(MSI_STANDARD_EC_COMMAND_ADDRESS, &rdata);
  173. if (result < 0)
  174. return -1;
  175. wlan_s = !!(rdata & MSI_STANDARD_EC_WLAN_MASK);
  176. bluetooth_s = !!(rdata & MSI_STANDARD_EC_BLUETOOTH_MASK);
  177. threeg_s = !!(rdata & MSI_STANDARD_EC_3G_MASK);
  178. return 0;
  179. }
  180. static int get_threeg_exists(void)
  181. {
  182. u8 rdata;
  183. int result;
  184. result = ec_read(MSI_STANDARD_EC_DEVICES_EXISTS_ADDRESS, &rdata);
  185. if (result < 0)
  186. return -1;
  187. threeg_exists = !!(rdata & MSI_STANDARD_EC_3G_MASK);
  188. return 0;
  189. }
  190. /* Backlight device stuff */
  191. static int bl_get_brightness(struct backlight_device *b)
  192. {
  193. return get_lcd_level();
  194. }
  195. static int bl_update_status(struct backlight_device *b)
  196. {
  197. return set_lcd_level(b->props.brightness);
  198. }
  199. static struct backlight_ops msibl_ops = {
  200. .get_brightness = bl_get_brightness,
  201. .update_status = bl_update_status,
  202. };
  203. static struct backlight_device *msibl_device;
  204. /* Platform device */
  205. static ssize_t show_wlan(struct device *dev,
  206. struct device_attribute *attr, char *buf)
  207. {
  208. int ret, enabled;
  209. if (old_ec_model) {
  210. ret = get_wireless_state(&enabled, NULL);
  211. } else {
  212. ret = get_wireless_state_ec_standard();
  213. enabled = wlan_s;
  214. }
  215. if (ret < 0)
  216. return ret;
  217. return sprintf(buf, "%i\n", enabled);
  218. }
  219. static ssize_t store_wlan(struct device *dev,
  220. struct device_attribute *attr, const char *buf, size_t count)
  221. {
  222. return set_device_state(buf, count, MSI_STANDARD_EC_WLAN_MASK);
  223. }
  224. static ssize_t show_bluetooth(struct device *dev,
  225. struct device_attribute *attr, char *buf)
  226. {
  227. int ret, enabled;
  228. if (old_ec_model) {
  229. ret = get_wireless_state(NULL, &enabled);
  230. } else {
  231. ret = get_wireless_state_ec_standard();
  232. enabled = bluetooth_s;
  233. }
  234. if (ret < 0)
  235. return ret;
  236. return sprintf(buf, "%i\n", enabled);
  237. }
  238. static ssize_t store_bluetooth(struct device *dev,
  239. struct device_attribute *attr, const char *buf, size_t count)
  240. {
  241. return set_device_state(buf, count, MSI_STANDARD_EC_BLUETOOTH_MASK);
  242. }
  243. static ssize_t show_threeg(struct device *dev,
  244. struct device_attribute *attr, char *buf)
  245. {
  246. int ret;
  247. /* old msi ec not support 3G */
  248. if (old_ec_model)
  249. return -1;
  250. ret = get_wireless_state_ec_standard();
  251. if (ret < 0)
  252. return ret;
  253. return sprintf(buf, "%i\n", threeg_s);
  254. }
  255. static ssize_t store_threeg(struct device *dev,
  256. struct device_attribute *attr, const char *buf, size_t count)
  257. {
  258. return set_device_state(buf, count, MSI_STANDARD_EC_3G_MASK);
  259. }
  260. static ssize_t show_lcd_level(struct device *dev,
  261. struct device_attribute *attr, char *buf)
  262. {
  263. int ret;
  264. ret = get_lcd_level();
  265. if (ret < 0)
  266. return ret;
  267. return sprintf(buf, "%i\n", ret);
  268. }
  269. static ssize_t store_lcd_level(struct device *dev,
  270. struct device_attribute *attr, const char *buf, size_t count)
  271. {
  272. int level, ret;
  273. if (sscanf(buf, "%i", &level) != 1 || (level < 0 || level >= MSI_LCD_LEVEL_MAX))
  274. return -EINVAL;
  275. ret = set_lcd_level(level);
  276. if (ret < 0)
  277. return ret;
  278. return count;
  279. }
  280. static ssize_t show_auto_brightness(struct device *dev,
  281. struct device_attribute *attr, char *buf)
  282. {
  283. int ret;
  284. ret = get_auto_brightness();
  285. if (ret < 0)
  286. return ret;
  287. return sprintf(buf, "%i\n", ret);
  288. }
  289. static ssize_t store_auto_brightness(struct device *dev,
  290. struct device_attribute *attr, const char *buf, size_t count)
  291. {
  292. int enable, ret;
  293. if (sscanf(buf, "%i", &enable) != 1 || (enable != (enable & 1)))
  294. return -EINVAL;
  295. ret = set_auto_brightness(enable);
  296. if (ret < 0)
  297. return ret;
  298. return count;
  299. }
  300. static DEVICE_ATTR(lcd_level, 0644, show_lcd_level, store_lcd_level);
  301. static DEVICE_ATTR(auto_brightness, 0644, show_auto_brightness, store_auto_brightness);
  302. static DEVICE_ATTR(bluetooth, 0444, show_bluetooth, NULL);
  303. static DEVICE_ATTR(wlan, 0444, show_wlan, NULL);
  304. static DEVICE_ATTR(threeg, 0444, show_threeg, NULL);
  305. static struct attribute *msipf_attributes[] = {
  306. &dev_attr_lcd_level.attr,
  307. &dev_attr_auto_brightness.attr,
  308. &dev_attr_bluetooth.attr,
  309. &dev_attr_wlan.attr,
  310. NULL
  311. };
  312. static struct attribute_group msipf_attribute_group = {
  313. .attrs = msipf_attributes
  314. };
  315. static struct platform_driver msipf_driver = {
  316. .driver = {
  317. .name = "msi-laptop-pf",
  318. .owner = THIS_MODULE,
  319. },
  320. .resume = msi_laptop_resume,
  321. };
  322. static struct platform_device *msipf_device;
  323. /* Initialization */
  324. static int dmi_check_cb(const struct dmi_system_id *id)
  325. {
  326. printk("msi-laptop: Identified laptop model '%s'.\n", id->ident);
  327. return 0;
  328. }
  329. static struct dmi_system_id __initdata msi_dmi_table[] = {
  330. {
  331. .ident = "MSI S270",
  332. .matches = {
  333. DMI_MATCH(DMI_SYS_VENDOR, "MICRO-STAR INT'L CO.,LTD"),
  334. DMI_MATCH(DMI_PRODUCT_NAME, "MS-1013"),
  335. DMI_MATCH(DMI_PRODUCT_VERSION, "0131"),
  336. DMI_MATCH(DMI_CHASSIS_VENDOR, "MICRO-STAR INT'L CO.,LTD")
  337. },
  338. .callback = dmi_check_cb
  339. },
  340. {
  341. .ident = "MSI S271",
  342. .matches = {
  343. DMI_MATCH(DMI_SYS_VENDOR, "Micro-Star International"),
  344. DMI_MATCH(DMI_PRODUCT_NAME, "MS-1058"),
  345. DMI_MATCH(DMI_PRODUCT_VERSION, "0581"),
  346. DMI_MATCH(DMI_BOARD_NAME, "MS-1058")
  347. },
  348. .callback = dmi_check_cb
  349. },
  350. {
  351. .ident = "MSI S420",
  352. .matches = {
  353. DMI_MATCH(DMI_SYS_VENDOR, "Micro-Star International"),
  354. DMI_MATCH(DMI_PRODUCT_NAME, "MS-1412"),
  355. DMI_MATCH(DMI_BOARD_VENDOR, "MSI"),
  356. DMI_MATCH(DMI_BOARD_NAME, "MS-1412")
  357. },
  358. .callback = dmi_check_cb
  359. },
  360. {
  361. .ident = "Medion MD96100",
  362. .matches = {
  363. DMI_MATCH(DMI_SYS_VENDOR, "NOTEBOOK"),
  364. DMI_MATCH(DMI_PRODUCT_NAME, "SAM2000"),
  365. DMI_MATCH(DMI_PRODUCT_VERSION, "0131"),
  366. DMI_MATCH(DMI_CHASSIS_VENDOR, "MICRO-STAR INT'L CO.,LTD")
  367. },
  368. .callback = dmi_check_cb
  369. },
  370. {
  371. .ident = "MSI N051",
  372. .matches = {
  373. DMI_MATCH(DMI_SYS_VENDOR,
  374. "MICRO-STAR INTERNATIONAL CO., LTD"),
  375. DMI_MATCH(DMI_PRODUCT_NAME, "MS-N051"),
  376. DMI_MATCH(DMI_CHASSIS_VENDOR,
  377. "MICRO-STAR INTERNATIONAL CO., LTD")
  378. },
  379. .callback = dmi_check_cb
  380. },
  381. {
  382. .ident = "MSI N014",
  383. .matches = {
  384. DMI_MATCH(DMI_SYS_VENDOR,
  385. "MICRO-STAR INTERNATIONAL CO., LTD"),
  386. DMI_MATCH(DMI_PRODUCT_NAME, "MS-N014"),
  387. },
  388. .callback = dmi_check_cb
  389. },
  390. {
  391. .ident = "MSI CR620",
  392. .matches = {
  393. DMI_MATCH(DMI_SYS_VENDOR,
  394. "Micro-Star International"),
  395. DMI_MATCH(DMI_PRODUCT_NAME, "CR620"),
  396. },
  397. .callback = dmi_check_cb
  398. },
  399. { }
  400. };
  401. static struct dmi_system_id __initdata msi_load_scm_models_dmi_table[] = {
  402. {
  403. .ident = "MSI N034",
  404. .matches = {
  405. DMI_MATCH(DMI_SYS_VENDOR,
  406. "MICRO-STAR INTERNATIONAL CO., LTD"),
  407. DMI_MATCH(DMI_PRODUCT_NAME, "MS-N034"),
  408. DMI_MATCH(DMI_CHASSIS_VENDOR,
  409. "MICRO-STAR INTERNATIONAL CO., LTD")
  410. },
  411. .callback = dmi_check_cb
  412. },
  413. { }
  414. };
  415. static int rfkill_bluetooth_set(void *data, bool blocked)
  416. {
  417. /* Do something with blocked...*/
  418. /*
  419. * blocked == false is on
  420. * blocked == true is off
  421. */
  422. if (blocked)
  423. set_device_state("0", 0, MSI_STANDARD_EC_BLUETOOTH_MASK);
  424. else
  425. set_device_state("1", 0, MSI_STANDARD_EC_BLUETOOTH_MASK);
  426. return 0;
  427. }
  428. static int rfkill_wlan_set(void *data, bool blocked)
  429. {
  430. if (blocked)
  431. set_device_state("0", 0, MSI_STANDARD_EC_WLAN_MASK);
  432. else
  433. set_device_state("1", 0, MSI_STANDARD_EC_WLAN_MASK);
  434. return 0;
  435. }
  436. static int rfkill_threeg_set(void *data, bool blocked)
  437. {
  438. if (blocked)
  439. set_device_state("0", 0, MSI_STANDARD_EC_3G_MASK);
  440. else
  441. set_device_state("1", 0, MSI_STANDARD_EC_3G_MASK);
  442. return 0;
  443. }
  444. static struct rfkill_ops rfkill_bluetooth_ops = {
  445. .set_block = rfkill_bluetooth_set
  446. };
  447. static struct rfkill_ops rfkill_wlan_ops = {
  448. .set_block = rfkill_wlan_set
  449. };
  450. static struct rfkill_ops rfkill_threeg_ops = {
  451. .set_block = rfkill_threeg_set
  452. };
  453. static void rfkill_cleanup(void)
  454. {
  455. if (rfk_bluetooth) {
  456. rfkill_unregister(rfk_bluetooth);
  457. rfkill_destroy(rfk_bluetooth);
  458. }
  459. if (rfk_threeg) {
  460. rfkill_unregister(rfk_threeg);
  461. rfkill_destroy(rfk_threeg);
  462. }
  463. if (rfk_wlan) {
  464. rfkill_unregister(rfk_wlan);
  465. rfkill_destroy(rfk_wlan);
  466. }
  467. }
  468. static void msi_update_rfkill(struct work_struct *ignored)
  469. {
  470. get_wireless_state_ec_standard();
  471. if (rfk_wlan)
  472. rfkill_set_sw_state(rfk_wlan, !wlan_s);
  473. if (rfk_bluetooth)
  474. rfkill_set_sw_state(rfk_bluetooth, !bluetooth_s);
  475. if (rfk_threeg)
  476. rfkill_set_sw_state(rfk_threeg, !threeg_s);
  477. }
  478. static DECLARE_DELAYED_WORK(msi_rfkill_work, msi_update_rfkill);
  479. static bool msi_laptop_i8042_filter(unsigned char data, unsigned char str,
  480. struct serio *port)
  481. {
  482. static bool extended;
  483. if (str & 0x20)
  484. return false;
  485. /* 0x54 wwan, 0x62 bluetooth, 0x76 wlan*/
  486. if (unlikely(data == 0xe0)) {
  487. extended = true;
  488. return false;
  489. } else if (unlikely(extended)) {
  490. switch (data) {
  491. case 0x54:
  492. case 0x62:
  493. case 0x76:
  494. schedule_delayed_work(&msi_rfkill_work,
  495. round_jiffies_relative(0.5 * HZ));
  496. break;
  497. }
  498. extended = false;
  499. }
  500. return false;
  501. }
  502. static void msi_init_rfkill(struct work_struct *ignored)
  503. {
  504. if (rfk_wlan) {
  505. rfkill_set_sw_state(rfk_wlan, !wlan_s);
  506. rfkill_wlan_set(NULL, !wlan_s);
  507. }
  508. if (rfk_bluetooth) {
  509. rfkill_set_sw_state(rfk_bluetooth, !bluetooth_s);
  510. rfkill_bluetooth_set(NULL, !bluetooth_s);
  511. }
  512. if (rfk_threeg) {
  513. rfkill_set_sw_state(rfk_threeg, !threeg_s);
  514. rfkill_threeg_set(NULL, !threeg_s);
  515. }
  516. }
  517. static DECLARE_DELAYED_WORK(msi_rfkill_init, msi_init_rfkill);
  518. static int rfkill_init(struct platform_device *sdev)
  519. {
  520. /* add rfkill */
  521. int retval;
  522. /* keep the hardware wireless state */
  523. get_wireless_state_ec_standard();
  524. rfk_bluetooth = rfkill_alloc("msi-bluetooth", &sdev->dev,
  525. RFKILL_TYPE_BLUETOOTH,
  526. &rfkill_bluetooth_ops, NULL);
  527. if (!rfk_bluetooth) {
  528. retval = -ENOMEM;
  529. goto err_bluetooth;
  530. }
  531. retval = rfkill_register(rfk_bluetooth);
  532. if (retval)
  533. goto err_bluetooth;
  534. rfk_wlan = rfkill_alloc("msi-wlan", &sdev->dev, RFKILL_TYPE_WLAN,
  535. &rfkill_wlan_ops, NULL);
  536. if (!rfk_wlan) {
  537. retval = -ENOMEM;
  538. goto err_wlan;
  539. }
  540. retval = rfkill_register(rfk_wlan);
  541. if (retval)
  542. goto err_wlan;
  543. if (threeg_exists) {
  544. rfk_threeg = rfkill_alloc("msi-threeg", &sdev->dev,
  545. RFKILL_TYPE_WWAN, &rfkill_threeg_ops, NULL);
  546. if (!rfk_threeg) {
  547. retval = -ENOMEM;
  548. goto err_threeg;
  549. }
  550. retval = rfkill_register(rfk_threeg);
  551. if (retval)
  552. goto err_threeg;
  553. }
  554. /* schedule to run rfkill state initial */
  555. schedule_delayed_work(&msi_rfkill_init,
  556. round_jiffies_relative(1 * HZ));
  557. return 0;
  558. err_threeg:
  559. rfkill_destroy(rfk_threeg);
  560. if (rfk_wlan)
  561. rfkill_unregister(rfk_wlan);
  562. err_wlan:
  563. rfkill_destroy(rfk_wlan);
  564. if (rfk_bluetooth)
  565. rfkill_unregister(rfk_bluetooth);
  566. err_bluetooth:
  567. rfkill_destroy(rfk_bluetooth);
  568. return retval;
  569. }
  570. static int msi_laptop_resume(struct platform_device *device)
  571. {
  572. u8 data;
  573. int result;
  574. if (!load_scm_model)
  575. return 0;
  576. /* set load SCM to disable hardware control by fn key */
  577. result = ec_read(MSI_STANDARD_EC_SCM_LOAD_ADDRESS, &data);
  578. if (result < 0)
  579. return result;
  580. result = ec_write(MSI_STANDARD_EC_SCM_LOAD_ADDRESS,
  581. data | MSI_STANDARD_EC_SCM_LOAD_MASK);
  582. if (result < 0)
  583. return result;
  584. return 0;
  585. }
  586. static int load_scm_model_init(struct platform_device *sdev)
  587. {
  588. u8 data;
  589. int result;
  590. /* allow userland write sysfs file */
  591. dev_attr_bluetooth.store = store_bluetooth;
  592. dev_attr_wlan.store = store_wlan;
  593. dev_attr_threeg.store = store_threeg;
  594. dev_attr_bluetooth.attr.mode |= S_IWUSR;
  595. dev_attr_wlan.attr.mode |= S_IWUSR;
  596. dev_attr_threeg.attr.mode |= S_IWUSR;
  597. /* disable hardware control by fn key */
  598. result = ec_read(MSI_STANDARD_EC_SCM_LOAD_ADDRESS, &data);
  599. if (result < 0)
  600. return result;
  601. result = ec_write(MSI_STANDARD_EC_SCM_LOAD_ADDRESS,
  602. data | MSI_STANDARD_EC_SCM_LOAD_MASK);
  603. if (result < 0)
  604. return result;
  605. /* initial rfkill */
  606. result = rfkill_init(sdev);
  607. if (result < 0)
  608. goto fail_rfkill;
  609. result = i8042_install_filter(msi_laptop_i8042_filter);
  610. if (result) {
  611. printk(KERN_ERR
  612. "msi-laptop: Unable to install key filter\n");
  613. goto fail_filter;
  614. }
  615. return 0;
  616. fail_filter:
  617. rfkill_cleanup();
  618. fail_rfkill:
  619. return result;
  620. }
  621. static int __init msi_init(void)
  622. {
  623. int ret;
  624. if (acpi_disabled)
  625. return -ENODEV;
  626. if (force || dmi_check_system(msi_dmi_table))
  627. old_ec_model = 1;
  628. if (!old_ec_model)
  629. get_threeg_exists();
  630. if (!old_ec_model && dmi_check_system(msi_load_scm_models_dmi_table))
  631. load_scm_model = 1;
  632. if (auto_brightness < 0 || auto_brightness > 2)
  633. return -EINVAL;
  634. /* Register backlight stuff */
  635. if (acpi_video_backlight_support()) {
  636. printk(KERN_INFO "MSI: Brightness ignored, must be controlled "
  637. "by ACPI video driver\n");
  638. } else {
  639. struct backlight_properties props;
  640. memset(&props, 0, sizeof(struct backlight_properties));
  641. props.max_brightness = MSI_LCD_LEVEL_MAX - 1;
  642. msibl_device = backlight_device_register("msi-laptop-bl", NULL,
  643. NULL, &msibl_ops,
  644. &props);
  645. if (IS_ERR(msibl_device))
  646. return PTR_ERR(msibl_device);
  647. }
  648. ret = platform_driver_register(&msipf_driver);
  649. if (ret)
  650. goto fail_backlight;
  651. /* Register platform stuff */
  652. msipf_device = platform_device_alloc("msi-laptop-pf", -1);
  653. if (!msipf_device) {
  654. ret = -ENOMEM;
  655. goto fail_platform_driver;
  656. }
  657. ret = platform_device_add(msipf_device);
  658. if (ret)
  659. goto fail_platform_device1;
  660. if (load_scm_model && (load_scm_model_init(msipf_device) < 0)) {
  661. ret = -EINVAL;
  662. goto fail_platform_device1;
  663. }
  664. ret = sysfs_create_group(&msipf_device->dev.kobj, &msipf_attribute_group);
  665. if (ret)
  666. goto fail_platform_device2;
  667. if (!old_ec_model) {
  668. if (threeg_exists)
  669. ret = device_create_file(&msipf_device->dev,
  670. &dev_attr_threeg);
  671. if (ret)
  672. goto fail_platform_device2;
  673. }
  674. /* Disable automatic brightness control by default because
  675. * this module was probably loaded to do brightness control in
  676. * software. */
  677. if (auto_brightness != 2)
  678. set_auto_brightness(auto_brightness);
  679. printk(KERN_INFO "msi-laptop: driver "MSI_DRIVER_VERSION" successfully loaded.\n");
  680. return 0;
  681. fail_platform_device2:
  682. platform_device_del(msipf_device);
  683. fail_platform_device1:
  684. platform_device_put(msipf_device);
  685. fail_platform_driver:
  686. platform_driver_unregister(&msipf_driver);
  687. fail_backlight:
  688. backlight_device_unregister(msibl_device);
  689. return ret;
  690. }
  691. static void __exit msi_cleanup(void)
  692. {
  693. sysfs_remove_group(&msipf_device->dev.kobj, &msipf_attribute_group);
  694. if (!old_ec_model && threeg_exists)
  695. device_remove_file(&msipf_device->dev, &dev_attr_threeg);
  696. platform_device_unregister(msipf_device);
  697. platform_driver_unregister(&msipf_driver);
  698. backlight_device_unregister(msibl_device);
  699. i8042_remove_filter(msi_laptop_i8042_filter);
  700. rfkill_cleanup();
  701. /* Enable automatic brightness control again */
  702. if (auto_brightness != 2)
  703. set_auto_brightness(1);
  704. printk(KERN_INFO "msi-laptop: driver unloaded.\n");
  705. }
  706. module_init(msi_init);
  707. module_exit(msi_cleanup);
  708. MODULE_AUTHOR("Lennart Poettering");
  709. MODULE_DESCRIPTION("MSI Laptop Support");
  710. MODULE_VERSION(MSI_DRIVER_VERSION);
  711. MODULE_LICENSE("GPL");
  712. MODULE_ALIAS("dmi:*:svnMICRO-STARINT'LCO.,LTD:pnMS-1013:pvr0131*:cvnMICRO-STARINT'LCO.,LTD:ct10:*");
  713. MODULE_ALIAS("dmi:*:svnMicro-StarInternational:pnMS-1058:pvr0581:rvnMSI:rnMS-1058:*:ct10:*");
  714. MODULE_ALIAS("dmi:*:svnMicro-StarInternational:pnMS-1412:*:rvnMSI:rnMS-1412:*:cvnMICRO-STARINT'LCO.,LTD:ct10:*");
  715. MODULE_ALIAS("dmi:*:svnNOTEBOOK:pnSAM2000:pvr0131*:cvnMICRO-STARINT'LCO.,LTD:ct10:*");
  716. MODULE_ALIAS("dmi:*:svnMICRO-STARINTERNATIONAL*:pnMS-N034:*");
  717. MODULE_ALIAS("dmi:*:svnMICRO-STARINTERNATIONAL*:pnMS-N051:*");
  718. MODULE_ALIAS("dmi:*:svnMICRO-STARINTERNATIONAL*:pnMS-N014:*");
  719. MODULE_ALIAS("dmi:*:svnMicro-StarInternational*:pnCR620:*");