i8k.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  1. /*
  2. * i8k.c -- Linux driver for accessing the SMM BIOS on Dell laptops.
  3. * See http://www.debian.org/~dz/i8k/ for more information
  4. * and for latest version of this driver.
  5. *
  6. * Copyright (C) 2001 Massimo Dal Zotto <dz@debian.org>
  7. *
  8. * Hwmon integration:
  9. * Copyright (C) 2011 Jean Delvare <khali@linux-fr.org>
  10. *
  11. * This program is free software; you can redistribute it and/or modify it
  12. * under the terms of the GNU General Public License as published by the
  13. * Free Software Foundation; either version 2, or (at your option) any
  14. * later version.
  15. *
  16. * This program is distributed in the hope that it will be useful, but
  17. * WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * General Public License for more details.
  20. */
  21. #include <linux/module.h>
  22. #include <linux/types.h>
  23. #include <linux/init.h>
  24. #include <linux/proc_fs.h>
  25. #include <linux/seq_file.h>
  26. #include <linux/dmi.h>
  27. #include <linux/capability.h>
  28. #include <linux/mutex.h>
  29. #include <linux/hwmon.h>
  30. #include <linux/hwmon-sysfs.h>
  31. #include <asm/uaccess.h>
  32. #include <asm/io.h>
  33. #include <linux/i8k.h>
  34. #define I8K_VERSION "1.14 21/02/2005"
  35. #define I8K_SMM_FN_STATUS 0x0025
  36. #define I8K_SMM_POWER_STATUS 0x0069
  37. #define I8K_SMM_SET_FAN 0x01a3
  38. #define I8K_SMM_GET_FAN 0x00a3
  39. #define I8K_SMM_GET_SPEED 0x02a3
  40. #define I8K_SMM_GET_TEMP 0x10a3
  41. #define I8K_SMM_GET_DELL_SIG1 0xfea3
  42. #define I8K_SMM_GET_DELL_SIG2 0xffa3
  43. #define I8K_SMM_BIOS_VERSION 0x00a6
  44. #define I8K_FAN_MULT 30
  45. #define I8K_MAX_TEMP 127
  46. #define I8K_FN_NONE 0x00
  47. #define I8K_FN_UP 0x01
  48. #define I8K_FN_DOWN 0x02
  49. #define I8K_FN_MUTE 0x04
  50. #define I8K_FN_MASK 0x07
  51. #define I8K_FN_SHIFT 8
  52. #define I8K_POWER_AC 0x05
  53. #define I8K_POWER_BATTERY 0x01
  54. #define I8K_TEMPERATURE_BUG 1
  55. static DEFINE_MUTEX(i8k_mutex);
  56. static char bios_version[4];
  57. static struct device *i8k_hwmon_dev;
  58. MODULE_AUTHOR("Massimo Dal Zotto (dz@debian.org)");
  59. MODULE_DESCRIPTION("Driver for accessing SMM BIOS on Dell laptops");
  60. MODULE_LICENSE("GPL");
  61. static int force;
  62. module_param(force, bool, 0);
  63. MODULE_PARM_DESC(force, "Force loading without checking for supported models");
  64. static int ignore_dmi;
  65. module_param(ignore_dmi, bool, 0);
  66. MODULE_PARM_DESC(ignore_dmi, "Continue probing hardware even if DMI data does not match");
  67. static int restricted;
  68. module_param(restricted, bool, 0);
  69. MODULE_PARM_DESC(restricted, "Allow fan control if SYS_ADMIN capability set");
  70. static int power_status;
  71. module_param(power_status, bool, 0600);
  72. MODULE_PARM_DESC(power_status, "Report power status in /proc/i8k");
  73. static int fan_mult = I8K_FAN_MULT;
  74. module_param(fan_mult, int, 0);
  75. MODULE_PARM_DESC(fan_mult, "Factor to multiply fan speed with");
  76. static int i8k_open_fs(struct inode *inode, struct file *file);
  77. static long i8k_ioctl(struct file *, unsigned int, unsigned long);
  78. static const struct file_operations i8k_fops = {
  79. .owner = THIS_MODULE,
  80. .open = i8k_open_fs,
  81. .read = seq_read,
  82. .llseek = seq_lseek,
  83. .release = single_release,
  84. .unlocked_ioctl = i8k_ioctl,
  85. };
  86. struct smm_regs {
  87. unsigned int eax;
  88. unsigned int ebx __attribute__ ((packed));
  89. unsigned int ecx __attribute__ ((packed));
  90. unsigned int edx __attribute__ ((packed));
  91. unsigned int esi __attribute__ ((packed));
  92. unsigned int edi __attribute__ ((packed));
  93. };
  94. static inline const char *i8k_get_dmi_data(int field)
  95. {
  96. const char *dmi_data = dmi_get_system_info(field);
  97. return dmi_data && *dmi_data ? dmi_data : "?";
  98. }
  99. /*
  100. * Call the System Management Mode BIOS. Code provided by Jonathan Buzzard.
  101. */
  102. static int i8k_smm(struct smm_regs *regs)
  103. {
  104. int rc;
  105. int eax = regs->eax;
  106. #if defined(CONFIG_X86_64)
  107. asm volatile("pushq %%rax\n\t"
  108. "movl 0(%%rax),%%edx\n\t"
  109. "pushq %%rdx\n\t"
  110. "movl 4(%%rax),%%ebx\n\t"
  111. "movl 8(%%rax),%%ecx\n\t"
  112. "movl 12(%%rax),%%edx\n\t"
  113. "movl 16(%%rax),%%esi\n\t"
  114. "movl 20(%%rax),%%edi\n\t"
  115. "popq %%rax\n\t"
  116. "out %%al,$0xb2\n\t"
  117. "out %%al,$0x84\n\t"
  118. "xchgq %%rax,(%%rsp)\n\t"
  119. "movl %%ebx,4(%%rax)\n\t"
  120. "movl %%ecx,8(%%rax)\n\t"
  121. "movl %%edx,12(%%rax)\n\t"
  122. "movl %%esi,16(%%rax)\n\t"
  123. "movl %%edi,20(%%rax)\n\t"
  124. "popq %%rdx\n\t"
  125. "movl %%edx,0(%%rax)\n\t"
  126. "pushfq\n\t"
  127. "popq %%rax\n\t"
  128. "andl $1,%%eax\n"
  129. :"=a"(rc)
  130. : "a"(regs)
  131. : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
  132. #else
  133. asm volatile("pushl %%eax\n\t"
  134. "movl 0(%%eax),%%edx\n\t"
  135. "push %%edx\n\t"
  136. "movl 4(%%eax),%%ebx\n\t"
  137. "movl 8(%%eax),%%ecx\n\t"
  138. "movl 12(%%eax),%%edx\n\t"
  139. "movl 16(%%eax),%%esi\n\t"
  140. "movl 20(%%eax),%%edi\n\t"
  141. "popl %%eax\n\t"
  142. "out %%al,$0xb2\n\t"
  143. "out %%al,$0x84\n\t"
  144. "xchgl %%eax,(%%esp)\n\t"
  145. "movl %%ebx,4(%%eax)\n\t"
  146. "movl %%ecx,8(%%eax)\n\t"
  147. "movl %%edx,12(%%eax)\n\t"
  148. "movl %%esi,16(%%eax)\n\t"
  149. "movl %%edi,20(%%eax)\n\t"
  150. "popl %%edx\n\t"
  151. "movl %%edx,0(%%eax)\n\t"
  152. "lahf\n\t"
  153. "shrl $8,%%eax\n\t"
  154. "andl $1,%%eax\n"
  155. :"=a"(rc)
  156. : "a"(regs)
  157. : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
  158. #endif
  159. if (rc != 0 || (regs->eax & 0xffff) == 0xffff || regs->eax == eax)
  160. return -EINVAL;
  161. return 0;
  162. }
  163. /*
  164. * Read the bios version. Return the version as an integer corresponding
  165. * to the ascii value, for example "A17" is returned as 0x00413137.
  166. */
  167. static int i8k_get_bios_version(void)
  168. {
  169. struct smm_regs regs = { .eax = I8K_SMM_BIOS_VERSION, };
  170. return i8k_smm(&regs) ? : regs.eax;
  171. }
  172. /*
  173. * Read the Fn key status.
  174. */
  175. static int i8k_get_fn_status(void)
  176. {
  177. struct smm_regs regs = { .eax = I8K_SMM_FN_STATUS, };
  178. int rc;
  179. if ((rc = i8k_smm(&regs)) < 0)
  180. return rc;
  181. switch ((regs.eax >> I8K_FN_SHIFT) & I8K_FN_MASK) {
  182. case I8K_FN_UP:
  183. return I8K_VOL_UP;
  184. case I8K_FN_DOWN:
  185. return I8K_VOL_DOWN;
  186. case I8K_FN_MUTE:
  187. return I8K_VOL_MUTE;
  188. default:
  189. return 0;
  190. }
  191. }
  192. /*
  193. * Read the power status.
  194. */
  195. static int i8k_get_power_status(void)
  196. {
  197. struct smm_regs regs = { .eax = I8K_SMM_POWER_STATUS, };
  198. int rc;
  199. if ((rc = i8k_smm(&regs)) < 0)
  200. return rc;
  201. return (regs.eax & 0xff) == I8K_POWER_AC ? I8K_AC : I8K_BATTERY;
  202. }
  203. /*
  204. * Read the fan status.
  205. */
  206. static int i8k_get_fan_status(int fan)
  207. {
  208. struct smm_regs regs = { .eax = I8K_SMM_GET_FAN, };
  209. regs.ebx = fan & 0xff;
  210. return i8k_smm(&regs) ? : regs.eax & 0xff;
  211. }
  212. /*
  213. * Read the fan speed in RPM.
  214. */
  215. static int i8k_get_fan_speed(int fan)
  216. {
  217. struct smm_regs regs = { .eax = I8K_SMM_GET_SPEED, };
  218. regs.ebx = fan & 0xff;
  219. return i8k_smm(&regs) ? : (regs.eax & 0xffff) * fan_mult;
  220. }
  221. /*
  222. * Set the fan speed (off, low, high). Returns the new fan status.
  223. */
  224. static int i8k_set_fan(int fan, int speed)
  225. {
  226. struct smm_regs regs = { .eax = I8K_SMM_SET_FAN, };
  227. speed = (speed < 0) ? 0 : ((speed > I8K_FAN_MAX) ? I8K_FAN_MAX : speed);
  228. regs.ebx = (fan & 0xff) | (speed << 8);
  229. return i8k_smm(&regs) ? : i8k_get_fan_status(fan);
  230. }
  231. /*
  232. * Read the cpu temperature.
  233. */
  234. static int i8k_get_temp(int sensor)
  235. {
  236. struct smm_regs regs = { .eax = I8K_SMM_GET_TEMP, };
  237. int rc;
  238. int temp;
  239. #ifdef I8K_TEMPERATURE_BUG
  240. static int prev;
  241. #endif
  242. regs.ebx = sensor & 0xff;
  243. if ((rc = i8k_smm(&regs)) < 0)
  244. return rc;
  245. temp = regs.eax & 0xff;
  246. #ifdef I8K_TEMPERATURE_BUG
  247. /*
  248. * Sometimes the temperature sensor returns 0x99, which is out of range.
  249. * In this case we return (once) the previous cached value. For example:
  250. # 1003655137 00000058 00005a4b
  251. # 1003655138 00000099 00003a80 <--- 0x99 = 153 degrees
  252. # 1003655139 00000054 00005c52
  253. */
  254. if (temp > I8K_MAX_TEMP) {
  255. temp = prev;
  256. prev = I8K_MAX_TEMP;
  257. } else {
  258. prev = temp;
  259. }
  260. #endif
  261. return temp;
  262. }
  263. static int i8k_get_dell_signature(int req_fn)
  264. {
  265. struct smm_regs regs = { .eax = req_fn, };
  266. int rc;
  267. if ((rc = i8k_smm(&regs)) < 0)
  268. return rc;
  269. return regs.eax == 1145651527 && regs.edx == 1145392204 ? 0 : -1;
  270. }
  271. static int
  272. i8k_ioctl_unlocked(struct file *fp, unsigned int cmd, unsigned long arg)
  273. {
  274. int val = 0;
  275. int speed;
  276. unsigned char buff[16];
  277. int __user *argp = (int __user *)arg;
  278. if (!argp)
  279. return -EINVAL;
  280. switch (cmd) {
  281. case I8K_BIOS_VERSION:
  282. val = i8k_get_bios_version();
  283. break;
  284. case I8K_MACHINE_ID:
  285. memset(buff, 0, 16);
  286. strlcpy(buff, i8k_get_dmi_data(DMI_PRODUCT_SERIAL), sizeof(buff));
  287. break;
  288. case I8K_FN_STATUS:
  289. val = i8k_get_fn_status();
  290. break;
  291. case I8K_POWER_STATUS:
  292. val = i8k_get_power_status();
  293. break;
  294. case I8K_GET_TEMP:
  295. val = i8k_get_temp(0);
  296. break;
  297. case I8K_GET_SPEED:
  298. if (copy_from_user(&val, argp, sizeof(int)))
  299. return -EFAULT;
  300. val = i8k_get_fan_speed(val);
  301. break;
  302. case I8K_GET_FAN:
  303. if (copy_from_user(&val, argp, sizeof(int)))
  304. return -EFAULT;
  305. val = i8k_get_fan_status(val);
  306. break;
  307. case I8K_SET_FAN:
  308. if (restricted && !capable(CAP_SYS_ADMIN))
  309. return -EPERM;
  310. if (copy_from_user(&val, argp, sizeof(int)))
  311. return -EFAULT;
  312. if (copy_from_user(&speed, argp + 1, sizeof(int)))
  313. return -EFAULT;
  314. val = i8k_set_fan(val, speed);
  315. break;
  316. default:
  317. return -EINVAL;
  318. }
  319. if (val < 0)
  320. return val;
  321. switch (cmd) {
  322. case I8K_BIOS_VERSION:
  323. if (copy_to_user(argp, &val, 4))
  324. return -EFAULT;
  325. break;
  326. case I8K_MACHINE_ID:
  327. if (copy_to_user(argp, buff, 16))
  328. return -EFAULT;
  329. break;
  330. default:
  331. if (copy_to_user(argp, &val, sizeof(int)))
  332. return -EFAULT;
  333. break;
  334. }
  335. return 0;
  336. }
  337. static long i8k_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
  338. {
  339. long ret;
  340. mutex_lock(&i8k_mutex);
  341. ret = i8k_ioctl_unlocked(fp, cmd, arg);
  342. mutex_unlock(&i8k_mutex);
  343. return ret;
  344. }
  345. /*
  346. * Print the information for /proc/i8k.
  347. */
  348. static int i8k_proc_show(struct seq_file *seq, void *offset)
  349. {
  350. int fn_key, cpu_temp, ac_power;
  351. int left_fan, right_fan, left_speed, right_speed;
  352. cpu_temp = i8k_get_temp(0); /* 11100 µs */
  353. left_fan = i8k_get_fan_status(I8K_FAN_LEFT); /* 580 µs */
  354. right_fan = i8k_get_fan_status(I8K_FAN_RIGHT); /* 580 µs */
  355. left_speed = i8k_get_fan_speed(I8K_FAN_LEFT); /* 580 µs */
  356. right_speed = i8k_get_fan_speed(I8K_FAN_RIGHT); /* 580 µs */
  357. fn_key = i8k_get_fn_status(); /* 750 µs */
  358. if (power_status)
  359. ac_power = i8k_get_power_status(); /* 14700 µs */
  360. else
  361. ac_power = -1;
  362. /*
  363. * Info:
  364. *
  365. * 1) Format version (this will change if format changes)
  366. * 2) BIOS version
  367. * 3) BIOS machine ID
  368. * 4) Cpu temperature
  369. * 5) Left fan status
  370. * 6) Right fan status
  371. * 7) Left fan speed
  372. * 8) Right fan speed
  373. * 9) AC power
  374. * 10) Fn Key status
  375. */
  376. return seq_printf(seq, "%s %s %s %d %d %d %d %d %d %d\n",
  377. I8K_PROC_FMT,
  378. bios_version,
  379. i8k_get_dmi_data(DMI_PRODUCT_SERIAL),
  380. cpu_temp,
  381. left_fan, right_fan, left_speed, right_speed,
  382. ac_power, fn_key);
  383. }
  384. static int i8k_open_fs(struct inode *inode, struct file *file)
  385. {
  386. return single_open(file, i8k_proc_show, NULL);
  387. }
  388. /*
  389. * Hwmon interface
  390. */
  391. static ssize_t i8k_hwmon_show_temp(struct device *dev,
  392. struct device_attribute *devattr,
  393. char *buf)
  394. {
  395. int cpu_temp;
  396. cpu_temp = i8k_get_temp(0);
  397. if (cpu_temp < 0)
  398. return cpu_temp;
  399. return sprintf(buf, "%d\n", cpu_temp * 1000);
  400. }
  401. static ssize_t i8k_hwmon_show_fan(struct device *dev,
  402. struct device_attribute *devattr,
  403. char *buf)
  404. {
  405. int index = to_sensor_dev_attr(devattr)->index;
  406. int fan_speed;
  407. fan_speed = i8k_get_fan_speed(index);
  408. if (fan_speed < 0)
  409. return fan_speed;
  410. return sprintf(buf, "%d\n", fan_speed);
  411. }
  412. static ssize_t i8k_hwmon_show_label(struct device *dev,
  413. struct device_attribute *devattr,
  414. char *buf)
  415. {
  416. static const char *labels[4] = {
  417. "i8k",
  418. "CPU",
  419. "Left Fan",
  420. "Right Fan",
  421. };
  422. int index = to_sensor_dev_attr(devattr)->index;
  423. return sprintf(buf, "%s\n", labels[index]);
  424. }
  425. static DEVICE_ATTR(temp1_input, S_IRUGO, i8k_hwmon_show_temp, NULL);
  426. static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, i8k_hwmon_show_fan, NULL,
  427. I8K_FAN_LEFT);
  428. static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, i8k_hwmon_show_fan, NULL,
  429. I8K_FAN_RIGHT);
  430. static SENSOR_DEVICE_ATTR(name, S_IRUGO, i8k_hwmon_show_label, NULL, 0);
  431. static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO, i8k_hwmon_show_label, NULL, 1);
  432. static SENSOR_DEVICE_ATTR(fan1_label, S_IRUGO, i8k_hwmon_show_label, NULL, 2);
  433. static SENSOR_DEVICE_ATTR(fan2_label, S_IRUGO, i8k_hwmon_show_label, NULL, 3);
  434. static void i8k_hwmon_remove_files(struct device *dev)
  435. {
  436. device_remove_file(dev, &dev_attr_temp1_input);
  437. device_remove_file(dev, &sensor_dev_attr_fan1_input.dev_attr);
  438. device_remove_file(dev, &sensor_dev_attr_fan2_input.dev_attr);
  439. device_remove_file(dev, &sensor_dev_attr_temp1_label.dev_attr);
  440. device_remove_file(dev, &sensor_dev_attr_fan1_label.dev_attr);
  441. device_remove_file(dev, &sensor_dev_attr_fan2_label.dev_attr);
  442. device_remove_file(dev, &sensor_dev_attr_name.dev_attr);
  443. }
  444. static int __init i8k_init_hwmon(void)
  445. {
  446. int err;
  447. i8k_hwmon_dev = hwmon_device_register(NULL);
  448. if (IS_ERR(i8k_hwmon_dev)) {
  449. err = PTR_ERR(i8k_hwmon_dev);
  450. i8k_hwmon_dev = NULL;
  451. printk(KERN_ERR "i8k: hwmon registration failed (%d)\n", err);
  452. return err;
  453. }
  454. /* Required name attribute */
  455. err = device_create_file(i8k_hwmon_dev,
  456. &sensor_dev_attr_name.dev_attr);
  457. if (err)
  458. goto exit_unregister;
  459. /* CPU temperature attributes, if temperature reading is OK */
  460. err = i8k_get_temp(0);
  461. if (err < 0) {
  462. dev_dbg(i8k_hwmon_dev,
  463. "Not creating temperature attributes (%d)\n", err);
  464. } else {
  465. err = device_create_file(i8k_hwmon_dev, &dev_attr_temp1_input);
  466. if (err)
  467. goto exit_remove_files;
  468. err = device_create_file(i8k_hwmon_dev,
  469. &sensor_dev_attr_temp1_label.dev_attr);
  470. if (err)
  471. goto exit_remove_files;
  472. }
  473. /* Left fan attributes, if left fan is present */
  474. err = i8k_get_fan_status(I8K_FAN_LEFT);
  475. if (err < 0) {
  476. dev_dbg(i8k_hwmon_dev,
  477. "Not creating %s fan attributes (%d)\n", "left", err);
  478. } else {
  479. err = device_create_file(i8k_hwmon_dev,
  480. &sensor_dev_attr_fan1_input.dev_attr);
  481. if (err)
  482. goto exit_remove_files;
  483. err = device_create_file(i8k_hwmon_dev,
  484. &sensor_dev_attr_fan1_label.dev_attr);
  485. if (err)
  486. goto exit_remove_files;
  487. }
  488. /* Right fan attributes, if right fan is present */
  489. err = i8k_get_fan_status(I8K_FAN_RIGHT);
  490. if (err < 0) {
  491. dev_dbg(i8k_hwmon_dev,
  492. "Not creating %s fan attributes (%d)\n", "right", err);
  493. } else {
  494. err = device_create_file(i8k_hwmon_dev,
  495. &sensor_dev_attr_fan2_input.dev_attr);
  496. if (err)
  497. goto exit_remove_files;
  498. err = device_create_file(i8k_hwmon_dev,
  499. &sensor_dev_attr_fan2_label.dev_attr);
  500. if (err)
  501. goto exit_remove_files;
  502. }
  503. return 0;
  504. exit_remove_files:
  505. i8k_hwmon_remove_files(i8k_hwmon_dev);
  506. exit_unregister:
  507. hwmon_device_unregister(i8k_hwmon_dev);
  508. return err;
  509. }
  510. static void __exit i8k_exit_hwmon(void)
  511. {
  512. i8k_hwmon_remove_files(i8k_hwmon_dev);
  513. hwmon_device_unregister(i8k_hwmon_dev);
  514. }
  515. static struct dmi_system_id __initdata i8k_dmi_table[] = {
  516. {
  517. .ident = "Dell Inspiron",
  518. .matches = {
  519. DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"),
  520. DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"),
  521. },
  522. },
  523. {
  524. .ident = "Dell Latitude",
  525. .matches = {
  526. DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"),
  527. DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"),
  528. },
  529. },
  530. {
  531. .ident = "Dell Inspiron 2",
  532. .matches = {
  533. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  534. DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"),
  535. },
  536. },
  537. {
  538. .ident = "Dell Latitude 2",
  539. .matches = {
  540. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  541. DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"),
  542. },
  543. },
  544. { /* UK Inspiron 6400 */
  545. .ident = "Dell Inspiron 3",
  546. .matches = {
  547. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  548. DMI_MATCH(DMI_PRODUCT_NAME, "MM061"),
  549. },
  550. },
  551. {
  552. .ident = "Dell Inspiron 3",
  553. .matches = {
  554. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  555. DMI_MATCH(DMI_PRODUCT_NAME, "MP061"),
  556. },
  557. },
  558. {
  559. .ident = "Dell Precision",
  560. .matches = {
  561. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  562. DMI_MATCH(DMI_PRODUCT_NAME, "Precision"),
  563. },
  564. },
  565. {
  566. .ident = "Dell Vostro",
  567. .matches = {
  568. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  569. DMI_MATCH(DMI_PRODUCT_NAME, "Vostro"),
  570. },
  571. },
  572. { }
  573. };
  574. /*
  575. * Probe for the presence of a supported laptop.
  576. */
  577. static int __init i8k_probe(void)
  578. {
  579. char buff[4];
  580. int version;
  581. /*
  582. * Get DMI information
  583. */
  584. if (!dmi_check_system(i8k_dmi_table)) {
  585. if (!ignore_dmi && !force)
  586. return -ENODEV;
  587. printk(KERN_INFO "i8k: not running on a supported Dell system.\n");
  588. printk(KERN_INFO "i8k: vendor=%s, model=%s, version=%s\n",
  589. i8k_get_dmi_data(DMI_SYS_VENDOR),
  590. i8k_get_dmi_data(DMI_PRODUCT_NAME),
  591. i8k_get_dmi_data(DMI_BIOS_VERSION));
  592. }
  593. strlcpy(bios_version, i8k_get_dmi_data(DMI_BIOS_VERSION), sizeof(bios_version));
  594. /*
  595. * Get SMM Dell signature
  596. */
  597. if (i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG1) &&
  598. i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG2)) {
  599. printk(KERN_ERR "i8k: unable to get SMM Dell signature\n");
  600. if (!force)
  601. return -ENODEV;
  602. }
  603. /*
  604. * Get SMM BIOS version.
  605. */
  606. version = i8k_get_bios_version();
  607. if (version <= 0) {
  608. printk(KERN_WARNING "i8k: unable to get SMM BIOS version\n");
  609. } else {
  610. buff[0] = (version >> 16) & 0xff;
  611. buff[1] = (version >> 8) & 0xff;
  612. buff[2] = (version) & 0xff;
  613. buff[3] = '\0';
  614. /*
  615. * If DMI BIOS version is unknown use SMM BIOS version.
  616. */
  617. if (!dmi_get_system_info(DMI_BIOS_VERSION))
  618. strlcpy(bios_version, buff, sizeof(bios_version));
  619. /*
  620. * Check if the two versions match.
  621. */
  622. if (strncmp(buff, bios_version, sizeof(bios_version)) != 0)
  623. printk(KERN_WARNING "i8k: BIOS version mismatch: %s != %s\n",
  624. buff, bios_version);
  625. }
  626. return 0;
  627. }
  628. static int __init i8k_init(void)
  629. {
  630. struct proc_dir_entry *proc_i8k;
  631. int err;
  632. /* Are we running on an supported laptop? */
  633. if (i8k_probe())
  634. return -ENODEV;
  635. /* Register the proc entry */
  636. proc_i8k = proc_create("i8k", 0, NULL, &i8k_fops);
  637. if (!proc_i8k)
  638. return -ENOENT;
  639. err = i8k_init_hwmon();
  640. if (err)
  641. goto exit_remove_proc;
  642. printk(KERN_INFO
  643. "Dell laptop SMM driver v%s Massimo Dal Zotto (dz@debian.org)\n",
  644. I8K_VERSION);
  645. return 0;
  646. exit_remove_proc:
  647. remove_proc_entry("i8k", NULL);
  648. return err;
  649. }
  650. static void __exit i8k_exit(void)
  651. {
  652. i8k_exit_hwmon();
  653. remove_proc_entry("i8k", NULL);
  654. }
  655. module_init(i8k_init);
  656. module_exit(i8k_exit);