msi-laptop.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  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. #define MSI_DRIVER_VERSION "0.5"
  57. #define MSI_LCD_LEVEL_MAX 9
  58. #define MSI_EC_COMMAND_WIRELESS 0x10
  59. #define MSI_EC_COMMAND_LCD_LEVEL 0x11
  60. #define MSI_STANDARD_EC_COMMAND_ADDRESS 0x2e
  61. #define MSI_STANDARD_EC_BLUETOOTH_MASK (1 << 0)
  62. #define MSI_STANDARD_EC_WEBCAM_MASK (1 << 1)
  63. #define MSI_STANDARD_EC_WLAN_MASK (1 << 3)
  64. #define MSI_STANDARD_EC_3G_MASK (1 << 4)
  65. /* For set SCM load flag to disable BIOS fn key */
  66. #define MSI_STANDARD_EC_SCM_LOAD_ADDRESS 0x2d
  67. #define MSI_STANDARD_EC_SCM_LOAD_MASK (1 << 0)
  68. static int msi_laptop_resume(struct platform_device *device);
  69. #define MSI_STANDARD_EC_DEVICES_EXISTS_ADDRESS 0x2f
  70. static int force;
  71. module_param(force, bool, 0);
  72. MODULE_PARM_DESC(force, "Force driver load, ignore DMI data");
  73. static int auto_brightness;
  74. module_param(auto_brightness, int, 0);
  75. MODULE_PARM_DESC(auto_brightness, "Enable automatic brightness control (0: disabled; 1: enabled; 2: don't touch)");
  76. static bool old_ec_model;
  77. static int wlan_s, bluetooth_s, threeg_s;
  78. static int threeg_exists;
  79. /* Some MSI 3G netbook only have one fn key to control Wlan/Bluetooth/3G,
  80. * those netbook will load the SCM (windows app) to disable the original
  81. * Wlan/Bluetooth control by BIOS when user press fn key, then control
  82. * Wlan/Bluetooth/3G by SCM (software control by OS). Without SCM, user
  83. * cann't on/off 3G module on those 3G netbook.
  84. * On Linux, msi-laptop driver will do the same thing to disable the
  85. * original BIOS control, then might need use HAL or other userland
  86. * application to do the software control that simulate with SCM.
  87. * e.g. MSI N034 netbook
  88. */
  89. static bool load_scm_model;
  90. static struct rfkill *rfk_wlan, *rfk_bluetooth, *rfk_threeg;
  91. /* Hardware access */
  92. static int set_lcd_level(int level)
  93. {
  94. u8 buf[2];
  95. if (level < 0 || level >= MSI_LCD_LEVEL_MAX)
  96. return -EINVAL;
  97. buf[0] = 0x80;
  98. buf[1] = (u8) (level*31);
  99. return ec_transaction(MSI_EC_COMMAND_LCD_LEVEL, buf, sizeof(buf), NULL, 0, 1);
  100. }
  101. static int get_lcd_level(void)
  102. {
  103. u8 wdata = 0, rdata;
  104. int result;
  105. result = ec_transaction(MSI_EC_COMMAND_LCD_LEVEL, &wdata, 1, &rdata, 1, 1);
  106. if (result < 0)
  107. return result;
  108. return (int) rdata / 31;
  109. }
  110. static int get_auto_brightness(void)
  111. {
  112. u8 wdata = 4, rdata;
  113. int result;
  114. result = ec_transaction(MSI_EC_COMMAND_LCD_LEVEL, &wdata, 1, &rdata, 1, 1);
  115. if (result < 0)
  116. return result;
  117. return !!(rdata & 8);
  118. }
  119. static int set_auto_brightness(int enable)
  120. {
  121. u8 wdata[2], rdata;
  122. int result;
  123. wdata[0] = 4;
  124. result = ec_transaction(MSI_EC_COMMAND_LCD_LEVEL, wdata, 1, &rdata, 1, 1);
  125. if (result < 0)
  126. return result;
  127. wdata[0] = 0x84;
  128. wdata[1] = (rdata & 0xF7) | (enable ? 8 : 0);
  129. return ec_transaction(MSI_EC_COMMAND_LCD_LEVEL, wdata, 2, NULL, 0, 1);
  130. }
  131. static ssize_t set_device_state(const char *buf, size_t count, u8 mask)
  132. {
  133. int status;
  134. u8 wdata = 0, rdata;
  135. int result;
  136. if (sscanf(buf, "%i", &status) != 1 || (status < 0 || status > 1))
  137. return -EINVAL;
  138. /* read current device state */
  139. result = ec_read(MSI_STANDARD_EC_COMMAND_ADDRESS, &rdata);
  140. if (result < 0)
  141. return -EINVAL;
  142. if (!!(rdata & mask) != status) {
  143. /* reverse device bit */
  144. if (rdata & mask)
  145. wdata = rdata & ~mask;
  146. else
  147. wdata = rdata | mask;
  148. result = ec_write(MSI_STANDARD_EC_COMMAND_ADDRESS, wdata);
  149. if (result < 0)
  150. return -EINVAL;
  151. }
  152. return count;
  153. }
  154. static int get_wireless_state(int *wlan, int *bluetooth)
  155. {
  156. u8 wdata = 0, rdata;
  157. int result;
  158. result = ec_transaction(MSI_EC_COMMAND_WIRELESS, &wdata, 1, &rdata, 1, 1);
  159. if (result < 0)
  160. return -1;
  161. if (wlan)
  162. *wlan = !!(rdata & 8);
  163. if (bluetooth)
  164. *bluetooth = !!(rdata & 128);
  165. return 0;
  166. }
  167. static int get_wireless_state_ec_standard(void)
  168. {
  169. u8 rdata;
  170. int result;
  171. result = ec_read(MSI_STANDARD_EC_COMMAND_ADDRESS, &rdata);
  172. if (result < 0)
  173. return -1;
  174. wlan_s = !!(rdata & MSI_STANDARD_EC_WLAN_MASK);
  175. bluetooth_s = !!(rdata & MSI_STANDARD_EC_BLUETOOTH_MASK);
  176. threeg_s = !!(rdata & MSI_STANDARD_EC_3G_MASK);
  177. return 0;
  178. }
  179. static int get_threeg_exists(void)
  180. {
  181. u8 rdata;
  182. int result;
  183. result = ec_read(MSI_STANDARD_EC_DEVICES_EXISTS_ADDRESS, &rdata);
  184. if (result < 0)
  185. return -1;
  186. threeg_exists = !!(rdata & MSI_STANDARD_EC_3G_MASK);
  187. return 0;
  188. }
  189. /* Backlight device stuff */
  190. static int bl_get_brightness(struct backlight_device *b)
  191. {
  192. return get_lcd_level();
  193. }
  194. static int bl_update_status(struct backlight_device *b)
  195. {
  196. return set_lcd_level(b->props.brightness);
  197. }
  198. static struct backlight_ops msibl_ops = {
  199. .get_brightness = bl_get_brightness,
  200. .update_status = bl_update_status,
  201. };
  202. static struct backlight_device *msibl_device;
  203. /* Platform device */
  204. static ssize_t show_wlan(struct device *dev,
  205. struct device_attribute *attr, char *buf)
  206. {
  207. int ret, enabled;
  208. if (old_ec_model) {
  209. ret = get_wireless_state(&enabled, NULL);
  210. } else {
  211. ret = get_wireless_state_ec_standard();
  212. enabled = wlan_s;
  213. }
  214. if (ret < 0)
  215. return ret;
  216. return sprintf(buf, "%i\n", enabled);
  217. }
  218. static ssize_t store_wlan(struct device *dev,
  219. struct device_attribute *attr, const char *buf, size_t count)
  220. {
  221. return set_device_state(buf, count, MSI_STANDARD_EC_WLAN_MASK);
  222. }
  223. static ssize_t show_bluetooth(struct device *dev,
  224. struct device_attribute *attr, char *buf)
  225. {
  226. int ret, enabled;
  227. if (old_ec_model) {
  228. ret = get_wireless_state(NULL, &enabled);
  229. } else {
  230. ret = get_wireless_state_ec_standard();
  231. enabled = bluetooth_s;
  232. }
  233. if (ret < 0)
  234. return ret;
  235. return sprintf(buf, "%i\n", enabled);
  236. }
  237. static ssize_t store_bluetooth(struct device *dev,
  238. struct device_attribute *attr, const char *buf, size_t count)
  239. {
  240. return set_device_state(buf, count, MSI_STANDARD_EC_BLUETOOTH_MASK);
  241. }
  242. static ssize_t show_threeg(struct device *dev,
  243. struct device_attribute *attr, char *buf)
  244. {
  245. int ret;
  246. /* old msi ec not support 3G */
  247. if (old_ec_model)
  248. return -1;
  249. ret = get_wireless_state_ec_standard();
  250. if (ret < 0)
  251. return ret;
  252. return sprintf(buf, "%i\n", threeg_s);
  253. }
  254. static ssize_t store_threeg(struct device *dev,
  255. struct device_attribute *attr, const char *buf, size_t count)
  256. {
  257. return set_device_state(buf, count, MSI_STANDARD_EC_3G_MASK);
  258. }
  259. static ssize_t show_lcd_level(struct device *dev,
  260. struct device_attribute *attr, char *buf)
  261. {
  262. int ret;
  263. ret = get_lcd_level();
  264. if (ret < 0)
  265. return ret;
  266. return sprintf(buf, "%i\n", ret);
  267. }
  268. static ssize_t store_lcd_level(struct device *dev,
  269. struct device_attribute *attr, const char *buf, size_t count)
  270. {
  271. int level, ret;
  272. if (sscanf(buf, "%i", &level) != 1 || (level < 0 || level >= MSI_LCD_LEVEL_MAX))
  273. return -EINVAL;
  274. ret = set_lcd_level(level);
  275. if (ret < 0)
  276. return ret;
  277. return count;
  278. }
  279. static ssize_t show_auto_brightness(struct device *dev,
  280. struct device_attribute *attr, char *buf)
  281. {
  282. int ret;
  283. ret = get_auto_brightness();
  284. if (ret < 0)
  285. return ret;
  286. return sprintf(buf, "%i\n", ret);
  287. }
  288. static ssize_t store_auto_brightness(struct device *dev,
  289. struct device_attribute *attr, const char *buf, size_t count)
  290. {
  291. int enable, ret;
  292. if (sscanf(buf, "%i", &enable) != 1 || (enable != (enable & 1)))
  293. return -EINVAL;
  294. ret = set_auto_brightness(enable);
  295. if (ret < 0)
  296. return ret;
  297. return count;
  298. }
  299. static DEVICE_ATTR(lcd_level, 0644, show_lcd_level, store_lcd_level);
  300. static DEVICE_ATTR(auto_brightness, 0644, show_auto_brightness, store_auto_brightness);
  301. static DEVICE_ATTR(bluetooth, 0444, show_bluetooth, NULL);
  302. static DEVICE_ATTR(wlan, 0444, show_wlan, NULL);
  303. static DEVICE_ATTR(threeg, 0444, show_threeg, NULL);
  304. static struct attribute *msipf_attributes[] = {
  305. &dev_attr_lcd_level.attr,
  306. &dev_attr_auto_brightness.attr,
  307. &dev_attr_bluetooth.attr,
  308. &dev_attr_wlan.attr,
  309. NULL
  310. };
  311. static struct attribute_group msipf_attribute_group = {
  312. .attrs = msipf_attributes
  313. };
  314. static struct platform_driver msipf_driver = {
  315. .driver = {
  316. .name = "msi-laptop-pf",
  317. .owner = THIS_MODULE,
  318. },
  319. .resume = msi_laptop_resume,
  320. };
  321. static struct platform_device *msipf_device;
  322. /* Initialization */
  323. static int dmi_check_cb(const struct dmi_system_id *id)
  324. {
  325. printk("msi-laptop: Identified laptop model '%s'.\n", id->ident);
  326. return 0;
  327. }
  328. static struct dmi_system_id __initdata msi_dmi_table[] = {
  329. {
  330. .ident = "MSI S270",
  331. .matches = {
  332. DMI_MATCH(DMI_SYS_VENDOR, "MICRO-STAR INT'L CO.,LTD"),
  333. DMI_MATCH(DMI_PRODUCT_NAME, "MS-1013"),
  334. DMI_MATCH(DMI_PRODUCT_VERSION, "0131"),
  335. DMI_MATCH(DMI_CHASSIS_VENDOR, "MICRO-STAR INT'L CO.,LTD")
  336. },
  337. .callback = dmi_check_cb
  338. },
  339. {
  340. .ident = "MSI S271",
  341. .matches = {
  342. DMI_MATCH(DMI_SYS_VENDOR, "Micro-Star International"),
  343. DMI_MATCH(DMI_PRODUCT_NAME, "MS-1058"),
  344. DMI_MATCH(DMI_PRODUCT_VERSION, "0581"),
  345. DMI_MATCH(DMI_BOARD_NAME, "MS-1058")
  346. },
  347. .callback = dmi_check_cb
  348. },
  349. {
  350. .ident = "MSI S420",
  351. .matches = {
  352. DMI_MATCH(DMI_SYS_VENDOR, "Micro-Star International"),
  353. DMI_MATCH(DMI_PRODUCT_NAME, "MS-1412"),
  354. DMI_MATCH(DMI_BOARD_VENDOR, "MSI"),
  355. DMI_MATCH(DMI_BOARD_NAME, "MS-1412")
  356. },
  357. .callback = dmi_check_cb
  358. },
  359. {
  360. .ident = "Medion MD96100",
  361. .matches = {
  362. DMI_MATCH(DMI_SYS_VENDOR, "NOTEBOOK"),
  363. DMI_MATCH(DMI_PRODUCT_NAME, "SAM2000"),
  364. DMI_MATCH(DMI_PRODUCT_VERSION, "0131"),
  365. DMI_MATCH(DMI_CHASSIS_VENDOR, "MICRO-STAR INT'L CO.,LTD")
  366. },
  367. .callback = dmi_check_cb
  368. },
  369. { }
  370. };
  371. static struct dmi_system_id __initdata msi_load_scm_models_dmi_table[] = {
  372. {
  373. .ident = "MSI N034",
  374. .matches = {
  375. DMI_MATCH(DMI_SYS_VENDOR,
  376. "MICRO-STAR INTERNATIONAL CO., LTD"),
  377. DMI_MATCH(DMI_PRODUCT_NAME, "MS-N034"),
  378. DMI_MATCH(DMI_CHASSIS_VENDOR,
  379. "MICRO-STAR INTERNATIONAL CO., LTD")
  380. },
  381. .callback = dmi_check_cb
  382. },
  383. { }
  384. };
  385. static int rfkill_bluetooth_set(void *data, bool blocked)
  386. {
  387. /* Do something with blocked...*/
  388. /*
  389. * blocked == false is on
  390. * blocked == true is off
  391. */
  392. if (blocked)
  393. set_device_state("0", 0, MSI_STANDARD_EC_BLUETOOTH_MASK);
  394. else
  395. set_device_state("1", 0, MSI_STANDARD_EC_BLUETOOTH_MASK);
  396. return 0;
  397. }
  398. static int rfkill_wlan_set(void *data, bool blocked)
  399. {
  400. if (blocked)
  401. set_device_state("0", 0, MSI_STANDARD_EC_WLAN_MASK);
  402. else
  403. set_device_state("1", 0, MSI_STANDARD_EC_WLAN_MASK);
  404. return 0;
  405. }
  406. static int rfkill_threeg_set(void *data, bool blocked)
  407. {
  408. if (blocked)
  409. set_device_state("0", 0, MSI_STANDARD_EC_3G_MASK);
  410. else
  411. set_device_state("1", 0, MSI_STANDARD_EC_3G_MASK);
  412. return 0;
  413. }
  414. static struct rfkill_ops rfkill_bluetooth_ops = {
  415. .set_block = rfkill_bluetooth_set
  416. };
  417. static struct rfkill_ops rfkill_wlan_ops = {
  418. .set_block = rfkill_wlan_set
  419. };
  420. static struct rfkill_ops rfkill_threeg_ops = {
  421. .set_block = rfkill_threeg_set
  422. };
  423. static void rfkill_cleanup(void)
  424. {
  425. if (rfk_bluetooth) {
  426. rfkill_unregister(rfk_bluetooth);
  427. rfkill_destroy(rfk_bluetooth);
  428. }
  429. if (rfk_threeg) {
  430. rfkill_unregister(rfk_threeg);
  431. rfkill_destroy(rfk_threeg);
  432. }
  433. if (rfk_wlan) {
  434. rfkill_unregister(rfk_wlan);
  435. rfkill_destroy(rfk_wlan);
  436. }
  437. }
  438. static int rfkill_init(struct platform_device *sdev)
  439. {
  440. /* add rfkill */
  441. int retval;
  442. rfk_bluetooth = rfkill_alloc("msi-bluetooth", &sdev->dev,
  443. RFKILL_TYPE_BLUETOOTH,
  444. &rfkill_bluetooth_ops, NULL);
  445. if (!rfk_bluetooth) {
  446. retval = -ENOMEM;
  447. goto err_bluetooth;
  448. }
  449. retval = rfkill_register(rfk_bluetooth);
  450. if (retval)
  451. goto err_bluetooth;
  452. rfk_wlan = rfkill_alloc("msi-wlan", &sdev->dev, RFKILL_TYPE_WLAN,
  453. &rfkill_wlan_ops, NULL);
  454. if (!rfk_wlan) {
  455. retval = -ENOMEM;
  456. goto err_wlan;
  457. }
  458. retval = rfkill_register(rfk_wlan);
  459. if (retval)
  460. goto err_wlan;
  461. if (threeg_exists) {
  462. rfk_threeg = rfkill_alloc("msi-threeg", &sdev->dev,
  463. RFKILL_TYPE_WWAN, &rfkill_threeg_ops, NULL);
  464. if (!rfk_threeg) {
  465. retval = -ENOMEM;
  466. goto err_threeg;
  467. }
  468. retval = rfkill_register(rfk_threeg);
  469. if (retval)
  470. goto err_threeg;
  471. }
  472. return 0;
  473. err_threeg:
  474. rfkill_destroy(rfk_threeg);
  475. if (rfk_wlan)
  476. rfkill_unregister(rfk_wlan);
  477. err_wlan:
  478. rfkill_destroy(rfk_wlan);
  479. if (rfk_bluetooth)
  480. rfkill_unregister(rfk_bluetooth);
  481. err_bluetooth:
  482. rfkill_destroy(rfk_bluetooth);
  483. return retval;
  484. }
  485. static int msi_laptop_resume(struct platform_device *device)
  486. {
  487. u8 data;
  488. int result;
  489. if (!load_scm_model)
  490. return 0;
  491. /* set load SCM to disable hardware control by fn key */
  492. result = ec_read(MSI_STANDARD_EC_SCM_LOAD_ADDRESS, &data);
  493. if (result < 0)
  494. return result;
  495. result = ec_write(MSI_STANDARD_EC_SCM_LOAD_ADDRESS,
  496. data | MSI_STANDARD_EC_SCM_LOAD_MASK);
  497. if (result < 0)
  498. return result;
  499. return 0;
  500. }
  501. static int load_scm_model_init(struct platform_device *sdev)
  502. {
  503. u8 data;
  504. int result;
  505. /* allow userland write sysfs file */
  506. dev_attr_bluetooth.store = store_bluetooth;
  507. dev_attr_wlan.store = store_wlan;
  508. dev_attr_threeg.store = store_threeg;
  509. dev_attr_bluetooth.attr.mode |= S_IWUSR;
  510. dev_attr_wlan.attr.mode |= S_IWUSR;
  511. dev_attr_threeg.attr.mode |= S_IWUSR;
  512. /* disable hardware control by fn key */
  513. result = ec_read(MSI_STANDARD_EC_SCM_LOAD_ADDRESS, &data);
  514. if (result < 0)
  515. return result;
  516. result = ec_write(MSI_STANDARD_EC_SCM_LOAD_ADDRESS,
  517. data | MSI_STANDARD_EC_SCM_LOAD_MASK);
  518. if (result < 0)
  519. return result;
  520. /* initial rfkill */
  521. result = rfkill_init(sdev);
  522. if (result < 0)
  523. return result;
  524. return 0;
  525. }
  526. static int __init msi_init(void)
  527. {
  528. int ret;
  529. if (acpi_disabled)
  530. return -ENODEV;
  531. if (force || dmi_check_system(msi_dmi_table))
  532. old_ec_model = 1;
  533. if (!old_ec_model)
  534. get_threeg_exists();
  535. if (!old_ec_model && dmi_check_system(msi_load_scm_models_dmi_table))
  536. load_scm_model = 1;
  537. if (auto_brightness < 0 || auto_brightness > 2)
  538. return -EINVAL;
  539. /* Register backlight stuff */
  540. if (acpi_video_backlight_support()) {
  541. printk(KERN_INFO "MSI: Brightness ignored, must be controlled "
  542. "by ACPI video driver\n");
  543. } else {
  544. struct backlight_properties props;
  545. memset(&props, 0, sizeof(struct backlight_properties));
  546. props.max_brightness = MSI_LCD_LEVEL_MAX - 1;
  547. msibl_device = backlight_device_register("msi-laptop-bl", NULL,
  548. NULL, &msibl_ops,
  549. &props);
  550. if (IS_ERR(msibl_device))
  551. return PTR_ERR(msibl_device);
  552. }
  553. ret = platform_driver_register(&msipf_driver);
  554. if (ret)
  555. goto fail_backlight;
  556. /* Register platform stuff */
  557. msipf_device = platform_device_alloc("msi-laptop-pf", -1);
  558. if (!msipf_device) {
  559. ret = -ENOMEM;
  560. goto fail_platform_driver;
  561. }
  562. ret = platform_device_add(msipf_device);
  563. if (ret)
  564. goto fail_platform_device1;
  565. if (load_scm_model && (load_scm_model_init(msipf_device) < 0)) {
  566. ret = -EINVAL;
  567. goto fail_platform_device1;
  568. }
  569. ret = sysfs_create_group(&msipf_device->dev.kobj, &msipf_attribute_group);
  570. if (ret)
  571. goto fail_platform_device2;
  572. if (!old_ec_model) {
  573. if (threeg_exists)
  574. ret = device_create_file(&msipf_device->dev,
  575. &dev_attr_threeg);
  576. if (ret)
  577. goto fail_platform_device2;
  578. }
  579. /* Disable automatic brightness control by default because
  580. * this module was probably loaded to do brightness control in
  581. * software. */
  582. if (auto_brightness != 2)
  583. set_auto_brightness(auto_brightness);
  584. printk(KERN_INFO "msi-laptop: driver "MSI_DRIVER_VERSION" successfully loaded.\n");
  585. return 0;
  586. fail_platform_device2:
  587. platform_device_del(msipf_device);
  588. fail_platform_device1:
  589. platform_device_put(msipf_device);
  590. fail_platform_driver:
  591. platform_driver_unregister(&msipf_driver);
  592. fail_backlight:
  593. backlight_device_unregister(msibl_device);
  594. return ret;
  595. }
  596. static void __exit msi_cleanup(void)
  597. {
  598. sysfs_remove_group(&msipf_device->dev.kobj, &msipf_attribute_group);
  599. if (!old_ec_model && threeg_exists)
  600. device_remove_file(&msipf_device->dev, &dev_attr_threeg);
  601. platform_device_unregister(msipf_device);
  602. platform_driver_unregister(&msipf_driver);
  603. backlight_device_unregister(msibl_device);
  604. rfkill_cleanup();
  605. /* Enable automatic brightness control again */
  606. if (auto_brightness != 2)
  607. set_auto_brightness(1);
  608. printk(KERN_INFO "msi-laptop: driver unloaded.\n");
  609. }
  610. module_init(msi_init);
  611. module_exit(msi_cleanup);
  612. MODULE_AUTHOR("Lennart Poettering");
  613. MODULE_DESCRIPTION("MSI Laptop Support");
  614. MODULE_VERSION(MSI_DRIVER_VERSION);
  615. MODULE_LICENSE("GPL");
  616. MODULE_ALIAS("dmi:*:svnMICRO-STARINT'LCO.,LTD:pnMS-1013:pvr0131*:cvnMICRO-STARINT'LCO.,LTD:ct10:*");
  617. MODULE_ALIAS("dmi:*:svnMicro-StarInternational:pnMS-1058:pvr0581:rvnMSI:rnMS-1058:*:ct10:*");
  618. MODULE_ALIAS("dmi:*:svnMicro-StarInternational:pnMS-1412:*:rvnMSI:rnMS-1412:*:cvnMICRO-STARINT'LCO.,LTD:ct10:*");
  619. MODULE_ALIAS("dmi:*:svnNOTEBOOK:pnSAM2000:pvr0131*:cvnMICRO-STARINT'LCO.,LTD:ct10:*");
  620. MODULE_ALIAS("dmi:*:svnMICRO-STARINTERNATIONAL*:pnMS-N034:*");