dell-smm-hwmon.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * dell-smm-hwmon.c -- Linux driver for accessing the SMM BIOS on Dell laptops.
  4. *
  5. * Copyright (C) 2001 Massimo Dal Zotto <dz@debian.org>
  6. *
  7. * Hwmon integration:
  8. * Copyright (C) 2011 Jean Delvare <jdelvare@suse.de>
  9. * Copyright (C) 2013, 2014 Guenter Roeck <linux@roeck-us.net>
  10. * Copyright (C) 2014, 2015 Pali Rohár <pali@kernel.org>
  11. */
  12. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  13. #include <linux/cpu.h>
  14. #include <linux/delay.h>
  15. #include <linux/module.h>
  16. #include <linux/types.h>
  17. #include <linux/init.h>
  18. #include <linux/proc_fs.h>
  19. #include <linux/seq_file.h>
  20. #include <linux/dmi.h>
  21. #include <linux/capability.h>
  22. #include <linux/mutex.h>
  23. #include <linux/hwmon.h>
  24. #include <linux/hwmon-sysfs.h>
  25. #include <linux/uaccess.h>
  26. #include <linux/io.h>
  27. #include <linux/sched.h>
  28. #include <linux/ctype.h>
  29. #include <linux/smp.h>
  30. #include <linux/i8k.h>
  31. #define I8K_SMM_FN_STATUS 0x0025
  32. #define I8K_SMM_POWER_STATUS 0x0069
  33. #define I8K_SMM_SET_FAN 0x01a3
  34. #define I8K_SMM_GET_FAN 0x00a3
  35. #define I8K_SMM_GET_SPEED 0x02a3
  36. #define I8K_SMM_GET_FAN_TYPE 0x03a3
  37. #define I8K_SMM_GET_NOM_SPEED 0x04a3
  38. #define I8K_SMM_GET_TEMP 0x10a3
  39. #define I8K_SMM_GET_TEMP_TYPE 0x11a3
  40. #define I8K_SMM_GET_DELL_SIG1 0xfea3
  41. #define I8K_SMM_GET_DELL_SIG2 0xffa3
  42. #define I8K_FAN_MULT 30
  43. #define I8K_FAN_MAX_RPM 30000
  44. #define I8K_MAX_TEMP 127
  45. #define I8K_FN_NONE 0x00
  46. #define I8K_FN_UP 0x01
  47. #define I8K_FN_DOWN 0x02
  48. #define I8K_FN_MUTE 0x04
  49. #define I8K_FN_MASK 0x07
  50. #define I8K_FN_SHIFT 8
  51. #define I8K_POWER_AC 0x05
  52. #define I8K_POWER_BATTERY 0x01
  53. static DEFINE_MUTEX(i8k_mutex);
  54. static char bios_version[4];
  55. static char bios_machineid[16];
  56. static struct device *i8k_hwmon_dev;
  57. static u32 i8k_hwmon_flags;
  58. static uint i8k_fan_mult = I8K_FAN_MULT;
  59. static uint i8k_pwm_mult;
  60. static uint i8k_fan_max = I8K_FAN_HIGH;
  61. static bool disallow_fan_type_call;
  62. static bool disallow_fan_support;
  63. static unsigned int manual_fan;
  64. static unsigned int auto_fan;
  65. #define I8K_HWMON_HAVE_TEMP1 (1 << 0)
  66. #define I8K_HWMON_HAVE_TEMP2 (1 << 1)
  67. #define I8K_HWMON_HAVE_TEMP3 (1 << 2)
  68. #define I8K_HWMON_HAVE_TEMP4 (1 << 3)
  69. #define I8K_HWMON_HAVE_TEMP5 (1 << 4)
  70. #define I8K_HWMON_HAVE_TEMP6 (1 << 5)
  71. #define I8K_HWMON_HAVE_TEMP7 (1 << 6)
  72. #define I8K_HWMON_HAVE_TEMP8 (1 << 7)
  73. #define I8K_HWMON_HAVE_TEMP9 (1 << 8)
  74. #define I8K_HWMON_HAVE_TEMP10 (1 << 9)
  75. #define I8K_HWMON_HAVE_FAN1 (1 << 10)
  76. #define I8K_HWMON_HAVE_FAN2 (1 << 11)
  77. #define I8K_HWMON_HAVE_FAN3 (1 << 12)
  78. MODULE_AUTHOR("Massimo Dal Zotto (dz@debian.org)");
  79. MODULE_AUTHOR("Pali Rohár <pali@kernel.org>");
  80. MODULE_DESCRIPTION("Dell laptop SMM BIOS hwmon driver");
  81. MODULE_LICENSE("GPL");
  82. MODULE_ALIAS("i8k");
  83. static bool force;
  84. module_param(force, bool, 0);
  85. MODULE_PARM_DESC(force, "Force loading without checking for supported models");
  86. static bool ignore_dmi;
  87. module_param(ignore_dmi, bool, 0);
  88. MODULE_PARM_DESC(ignore_dmi, "Continue probing hardware even if DMI data does not match");
  89. #if IS_ENABLED(CONFIG_I8K)
  90. static bool restricted = true;
  91. module_param(restricted, bool, 0);
  92. MODULE_PARM_DESC(restricted, "Restrict fan control and serial number to CAP_SYS_ADMIN (default: 1)");
  93. static bool power_status;
  94. module_param(power_status, bool, 0600);
  95. MODULE_PARM_DESC(power_status, "Report power status in /proc/i8k (default: 0)");
  96. #endif
  97. static uint fan_mult;
  98. module_param(fan_mult, uint, 0);
  99. MODULE_PARM_DESC(fan_mult, "Factor to multiply fan speed with (default: autodetect)");
  100. static uint fan_max;
  101. module_param(fan_max, uint, 0);
  102. MODULE_PARM_DESC(fan_max, "Maximum configurable fan speed (default: autodetect)");
  103. struct smm_regs {
  104. unsigned int eax;
  105. unsigned int ebx __packed;
  106. unsigned int ecx __packed;
  107. unsigned int edx __packed;
  108. unsigned int esi __packed;
  109. unsigned int edi __packed;
  110. };
  111. static inline const char *i8k_get_dmi_data(int field)
  112. {
  113. const char *dmi_data = dmi_get_system_info(field);
  114. return dmi_data && *dmi_data ? dmi_data : "?";
  115. }
  116. /*
  117. * Call the System Management Mode BIOS. Code provided by Jonathan Buzzard.
  118. */
  119. static int i8k_smm_func(void *par)
  120. {
  121. int rc;
  122. struct smm_regs *regs = par;
  123. int eax = regs->eax;
  124. #ifdef DEBUG
  125. int ebx = regs->ebx;
  126. unsigned long duration;
  127. ktime_t calltime, delta, rettime;
  128. calltime = ktime_get();
  129. #endif
  130. /* SMM requires CPU 0 */
  131. if (smp_processor_id() != 0)
  132. return -EBUSY;
  133. #if defined(CONFIG_X86_64)
  134. asm volatile("pushq %%rax\n\t"
  135. "movl 0(%%rax),%%edx\n\t"
  136. "pushq %%rdx\n\t"
  137. "movl 4(%%rax),%%ebx\n\t"
  138. "movl 8(%%rax),%%ecx\n\t"
  139. "movl 12(%%rax),%%edx\n\t"
  140. "movl 16(%%rax),%%esi\n\t"
  141. "movl 20(%%rax),%%edi\n\t"
  142. "popq %%rax\n\t"
  143. "out %%al,$0xb2\n\t"
  144. "out %%al,$0x84\n\t"
  145. "xchgq %%rax,(%%rsp)\n\t"
  146. "movl %%ebx,4(%%rax)\n\t"
  147. "movl %%ecx,8(%%rax)\n\t"
  148. "movl %%edx,12(%%rax)\n\t"
  149. "movl %%esi,16(%%rax)\n\t"
  150. "movl %%edi,20(%%rax)\n\t"
  151. "popq %%rdx\n\t"
  152. "movl %%edx,0(%%rax)\n\t"
  153. "pushfq\n\t"
  154. "popq %%rax\n\t"
  155. "andl $1,%%eax\n"
  156. : "=a"(rc)
  157. : "a"(regs)
  158. : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
  159. #else
  160. asm volatile("pushl %%eax\n\t"
  161. "movl 0(%%eax),%%edx\n\t"
  162. "push %%edx\n\t"
  163. "movl 4(%%eax),%%ebx\n\t"
  164. "movl 8(%%eax),%%ecx\n\t"
  165. "movl 12(%%eax),%%edx\n\t"
  166. "movl 16(%%eax),%%esi\n\t"
  167. "movl 20(%%eax),%%edi\n\t"
  168. "popl %%eax\n\t"
  169. "out %%al,$0xb2\n\t"
  170. "out %%al,$0x84\n\t"
  171. "xchgl %%eax,(%%esp)\n\t"
  172. "movl %%ebx,4(%%eax)\n\t"
  173. "movl %%ecx,8(%%eax)\n\t"
  174. "movl %%edx,12(%%eax)\n\t"
  175. "movl %%esi,16(%%eax)\n\t"
  176. "movl %%edi,20(%%eax)\n\t"
  177. "popl %%edx\n\t"
  178. "movl %%edx,0(%%eax)\n\t"
  179. "lahf\n\t"
  180. "shrl $8,%%eax\n\t"
  181. "andl $1,%%eax\n"
  182. : "=a"(rc)
  183. : "a"(regs)
  184. : "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
  185. #endif
  186. if (rc != 0 || (regs->eax & 0xffff) == 0xffff || regs->eax == eax)
  187. rc = -EINVAL;
  188. #ifdef DEBUG
  189. rettime = ktime_get();
  190. delta = ktime_sub(rettime, calltime);
  191. duration = ktime_to_ns(delta) >> 10;
  192. pr_debug("smm(0x%.4x 0x%.4x) = 0x%.4x (took %7lu usecs)\n", eax, ebx,
  193. (rc ? 0xffff : regs->eax & 0xffff), duration);
  194. #endif
  195. return rc;
  196. }
  197. /*
  198. * Call the System Management Mode BIOS.
  199. */
  200. static int i8k_smm(struct smm_regs *regs)
  201. {
  202. int ret;
  203. get_online_cpus();
  204. ret = smp_call_on_cpu(0, i8k_smm_func, regs, true);
  205. put_online_cpus();
  206. return ret;
  207. }
  208. /*
  209. * Read the fan status.
  210. */
  211. static int i8k_get_fan_status(int fan)
  212. {
  213. struct smm_regs regs = { .eax = I8K_SMM_GET_FAN, };
  214. if (disallow_fan_support)
  215. return -EINVAL;
  216. regs.ebx = fan & 0xff;
  217. return i8k_smm(&regs) ? : regs.eax & 0xff;
  218. }
  219. /*
  220. * Read the fan speed in RPM.
  221. */
  222. static int i8k_get_fan_speed(int fan)
  223. {
  224. struct smm_regs regs = { .eax = I8K_SMM_GET_SPEED, };
  225. if (disallow_fan_support)
  226. return -EINVAL;
  227. regs.ebx = fan & 0xff;
  228. return i8k_smm(&regs) ? : (regs.eax & 0xffff) * i8k_fan_mult;
  229. }
  230. /*
  231. * Read the fan type.
  232. */
  233. static int _i8k_get_fan_type(int fan)
  234. {
  235. struct smm_regs regs = { .eax = I8K_SMM_GET_FAN_TYPE, };
  236. if (disallow_fan_support || disallow_fan_type_call)
  237. return -EINVAL;
  238. regs.ebx = fan & 0xff;
  239. return i8k_smm(&regs) ? : regs.eax & 0xff;
  240. }
  241. static int i8k_get_fan_type(int fan)
  242. {
  243. /* I8K_SMM_GET_FAN_TYPE SMM call is expensive, so cache values */
  244. static int types[3] = { INT_MIN, INT_MIN, INT_MIN };
  245. if (types[fan] == INT_MIN)
  246. types[fan] = _i8k_get_fan_type(fan);
  247. return types[fan];
  248. }
  249. /*
  250. * Read the fan nominal rpm for specific fan speed.
  251. */
  252. static int i8k_get_fan_nominal_speed(int fan, int speed)
  253. {
  254. struct smm_regs regs = { .eax = I8K_SMM_GET_NOM_SPEED, };
  255. if (disallow_fan_support)
  256. return -EINVAL;
  257. regs.ebx = (fan & 0xff) | (speed << 8);
  258. return i8k_smm(&regs) ? : (regs.eax & 0xffff) * i8k_fan_mult;
  259. }
  260. /*
  261. * Enable or disable automatic BIOS fan control support
  262. */
  263. static int i8k_enable_fan_auto_mode(bool enable)
  264. {
  265. struct smm_regs regs = { };
  266. if (disallow_fan_support)
  267. return -EINVAL;
  268. regs.eax = enable ? auto_fan : manual_fan;
  269. return i8k_smm(&regs);
  270. }
  271. /*
  272. * Set the fan speed (off, low, high, ...).
  273. */
  274. static int i8k_set_fan(int fan, int speed)
  275. {
  276. struct smm_regs regs = { .eax = I8K_SMM_SET_FAN, };
  277. if (disallow_fan_support)
  278. return -EINVAL;
  279. speed = (speed < 0) ? 0 : ((speed > i8k_fan_max) ? i8k_fan_max : speed);
  280. regs.ebx = (fan & 0xff) | (speed << 8);
  281. return i8k_smm(&regs);
  282. }
  283. static int i8k_get_temp_type(int sensor)
  284. {
  285. struct smm_regs regs = { .eax = I8K_SMM_GET_TEMP_TYPE, };
  286. regs.ebx = sensor & 0xff;
  287. return i8k_smm(&regs) ? : regs.eax & 0xff;
  288. }
  289. /*
  290. * Read the cpu temperature.
  291. */
  292. static int _i8k_get_temp(int sensor)
  293. {
  294. struct smm_regs regs = {
  295. .eax = I8K_SMM_GET_TEMP,
  296. .ebx = sensor & 0xff,
  297. };
  298. return i8k_smm(&regs) ? : regs.eax & 0xff;
  299. }
  300. static int i8k_get_temp(int sensor)
  301. {
  302. int temp = _i8k_get_temp(sensor);
  303. /*
  304. * Sometimes the temperature sensor returns 0x99, which is out of range.
  305. * In this case we retry (once) before returning an error.
  306. # 1003655137 00000058 00005a4b
  307. # 1003655138 00000099 00003a80 <--- 0x99 = 153 degrees
  308. # 1003655139 00000054 00005c52
  309. */
  310. if (temp == 0x99) {
  311. msleep(100);
  312. temp = _i8k_get_temp(sensor);
  313. }
  314. /*
  315. * Return -ENODATA for all invalid temperatures.
  316. *
  317. * Known instances are the 0x99 value as seen above as well as
  318. * 0xc1 (193), which may be returned when trying to read the GPU
  319. * temperature if the system supports a GPU and it is currently
  320. * turned off.
  321. */
  322. if (temp > I8K_MAX_TEMP)
  323. return -ENODATA;
  324. return temp;
  325. }
  326. static int i8k_get_dell_signature(int req_fn)
  327. {
  328. struct smm_regs regs = { .eax = req_fn, };
  329. int rc;
  330. rc = i8k_smm(&regs);
  331. if (rc < 0)
  332. return rc;
  333. return regs.eax == 1145651527 && regs.edx == 1145392204 ? 0 : -1;
  334. }
  335. #if IS_ENABLED(CONFIG_I8K)
  336. /*
  337. * Read the Fn key status.
  338. */
  339. static int i8k_get_fn_status(void)
  340. {
  341. struct smm_regs regs = { .eax = I8K_SMM_FN_STATUS, };
  342. int rc;
  343. rc = i8k_smm(&regs);
  344. if (rc < 0)
  345. return rc;
  346. switch ((regs.eax >> I8K_FN_SHIFT) & I8K_FN_MASK) {
  347. case I8K_FN_UP:
  348. return I8K_VOL_UP;
  349. case I8K_FN_DOWN:
  350. return I8K_VOL_DOWN;
  351. case I8K_FN_MUTE:
  352. return I8K_VOL_MUTE;
  353. default:
  354. return 0;
  355. }
  356. }
  357. /*
  358. * Read the power status.
  359. */
  360. static int i8k_get_power_status(void)
  361. {
  362. struct smm_regs regs = { .eax = I8K_SMM_POWER_STATUS, };
  363. int rc;
  364. rc = i8k_smm(&regs);
  365. if (rc < 0)
  366. return rc;
  367. return (regs.eax & 0xff) == I8K_POWER_AC ? I8K_AC : I8K_BATTERY;
  368. }
  369. /*
  370. * Procfs interface
  371. */
  372. static int
  373. i8k_ioctl_unlocked(struct file *fp, unsigned int cmd, unsigned long arg)
  374. {
  375. int val = 0;
  376. int speed, err;
  377. unsigned char buff[16];
  378. int __user *argp = (int __user *)arg;
  379. if (!argp)
  380. return -EINVAL;
  381. switch (cmd) {
  382. case I8K_BIOS_VERSION:
  383. if (!isdigit(bios_version[0]) || !isdigit(bios_version[1]) ||
  384. !isdigit(bios_version[2]))
  385. return -EINVAL;
  386. val = (bios_version[0] << 16) |
  387. (bios_version[1] << 8) | bios_version[2];
  388. break;
  389. case I8K_MACHINE_ID:
  390. if (restricted && !capable(CAP_SYS_ADMIN))
  391. return -EPERM;
  392. memset(buff, 0, sizeof(buff));
  393. strlcpy(buff, bios_machineid, sizeof(buff));
  394. break;
  395. case I8K_FN_STATUS:
  396. val = i8k_get_fn_status();
  397. break;
  398. case I8K_POWER_STATUS:
  399. val = i8k_get_power_status();
  400. break;
  401. case I8K_GET_TEMP:
  402. val = i8k_get_temp(0);
  403. break;
  404. case I8K_GET_SPEED:
  405. if (copy_from_user(&val, argp, sizeof(int)))
  406. return -EFAULT;
  407. val = i8k_get_fan_speed(val);
  408. break;
  409. case I8K_GET_FAN:
  410. if (copy_from_user(&val, argp, sizeof(int)))
  411. return -EFAULT;
  412. val = i8k_get_fan_status(val);
  413. break;
  414. case I8K_SET_FAN:
  415. if (restricted && !capable(CAP_SYS_ADMIN))
  416. return -EPERM;
  417. if (copy_from_user(&val, argp, sizeof(int)))
  418. return -EFAULT;
  419. if (copy_from_user(&speed, argp + 1, sizeof(int)))
  420. return -EFAULT;
  421. err = i8k_set_fan(val, speed);
  422. if (err < 0)
  423. return err;
  424. val = i8k_get_fan_status(val);
  425. break;
  426. default:
  427. return -EINVAL;
  428. }
  429. if (val < 0)
  430. return val;
  431. switch (cmd) {
  432. case I8K_BIOS_VERSION:
  433. if (copy_to_user(argp, &val, 4))
  434. return -EFAULT;
  435. break;
  436. case I8K_MACHINE_ID:
  437. if (copy_to_user(argp, buff, 16))
  438. return -EFAULT;
  439. break;
  440. default:
  441. if (copy_to_user(argp, &val, sizeof(int)))
  442. return -EFAULT;
  443. break;
  444. }
  445. return 0;
  446. }
  447. static long i8k_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
  448. {
  449. long ret;
  450. mutex_lock(&i8k_mutex);
  451. ret = i8k_ioctl_unlocked(fp, cmd, arg);
  452. mutex_unlock(&i8k_mutex);
  453. return ret;
  454. }
  455. /*
  456. * Print the information for /proc/i8k.
  457. */
  458. static int i8k_proc_show(struct seq_file *seq, void *offset)
  459. {
  460. int fn_key, cpu_temp, ac_power;
  461. int left_fan, right_fan, left_speed, right_speed;
  462. cpu_temp = i8k_get_temp(0); /* 11100 µs */
  463. left_fan = i8k_get_fan_status(I8K_FAN_LEFT); /* 580 µs */
  464. right_fan = i8k_get_fan_status(I8K_FAN_RIGHT); /* 580 µs */
  465. left_speed = i8k_get_fan_speed(I8K_FAN_LEFT); /* 580 µs */
  466. right_speed = i8k_get_fan_speed(I8K_FAN_RIGHT); /* 580 µs */
  467. fn_key = i8k_get_fn_status(); /* 750 µs */
  468. if (power_status)
  469. ac_power = i8k_get_power_status(); /* 14700 µs */
  470. else
  471. ac_power = -1;
  472. /*
  473. * Info:
  474. *
  475. * 1) Format version (this will change if format changes)
  476. * 2) BIOS version
  477. * 3) BIOS machine ID
  478. * 4) Cpu temperature
  479. * 5) Left fan status
  480. * 6) Right fan status
  481. * 7) Left fan speed
  482. * 8) Right fan speed
  483. * 9) AC power
  484. * 10) Fn Key status
  485. */
  486. seq_printf(seq, "%s %s %s %d %d %d %d %d %d %d\n",
  487. I8K_PROC_FMT,
  488. bios_version,
  489. (restricted && !capable(CAP_SYS_ADMIN)) ? "-1" : bios_machineid,
  490. cpu_temp,
  491. left_fan, right_fan, left_speed, right_speed,
  492. ac_power, fn_key);
  493. return 0;
  494. }
  495. static int i8k_open_fs(struct inode *inode, struct file *file)
  496. {
  497. return single_open(file, i8k_proc_show, NULL);
  498. }
  499. static const struct proc_ops i8k_proc_ops = {
  500. .proc_open = i8k_open_fs,
  501. .proc_read = seq_read,
  502. .proc_lseek = seq_lseek,
  503. .proc_release = single_release,
  504. .proc_ioctl = i8k_ioctl,
  505. };
  506. static struct proc_dir_entry *entry;
  507. static void __init i8k_init_procfs(void)
  508. {
  509. /* Register the proc entry */
  510. entry = proc_create("i8k", 0, NULL, &i8k_proc_ops);
  511. }
  512. static void __exit i8k_exit_procfs(void)
  513. {
  514. if (entry)
  515. remove_proc_entry("i8k", NULL);
  516. }
  517. #else
  518. static inline void __init i8k_init_procfs(void)
  519. {
  520. }
  521. static inline void __exit i8k_exit_procfs(void)
  522. {
  523. }
  524. #endif
  525. /*
  526. * Hwmon interface
  527. */
  528. static ssize_t i8k_hwmon_temp_label_show(struct device *dev,
  529. struct device_attribute *devattr,
  530. char *buf)
  531. {
  532. static const char * const labels[] = {
  533. "CPU",
  534. "GPU",
  535. "SODIMM",
  536. "Other",
  537. "Ambient",
  538. "Other",
  539. };
  540. int index = to_sensor_dev_attr(devattr)->index;
  541. int type;
  542. type = i8k_get_temp_type(index);
  543. if (type < 0)
  544. return type;
  545. if (type >= ARRAY_SIZE(labels))
  546. type = ARRAY_SIZE(labels) - 1;
  547. return sprintf(buf, "%s\n", labels[type]);
  548. }
  549. static ssize_t i8k_hwmon_temp_show(struct device *dev,
  550. struct device_attribute *devattr,
  551. char *buf)
  552. {
  553. int index = to_sensor_dev_attr(devattr)->index;
  554. int temp;
  555. temp = i8k_get_temp(index);
  556. if (temp < 0)
  557. return temp;
  558. return sprintf(buf, "%d\n", temp * 1000);
  559. }
  560. static ssize_t i8k_hwmon_fan_label_show(struct device *dev,
  561. struct device_attribute *devattr,
  562. char *buf)
  563. {
  564. static const char * const labels[] = {
  565. "Processor Fan",
  566. "Motherboard Fan",
  567. "Video Fan",
  568. "Power Supply Fan",
  569. "Chipset Fan",
  570. "Other Fan",
  571. };
  572. int index = to_sensor_dev_attr(devattr)->index;
  573. bool dock = false;
  574. int type;
  575. type = i8k_get_fan_type(index);
  576. if (type < 0)
  577. return type;
  578. if (type & 0x10) {
  579. dock = true;
  580. type &= 0x0F;
  581. }
  582. if (type >= ARRAY_SIZE(labels))
  583. type = (ARRAY_SIZE(labels) - 1);
  584. return sprintf(buf, "%s%s\n", (dock ? "Docking " : ""), labels[type]);
  585. }
  586. static ssize_t i8k_hwmon_fan_show(struct device *dev,
  587. struct device_attribute *devattr, char *buf)
  588. {
  589. int index = to_sensor_dev_attr(devattr)->index;
  590. int fan_speed;
  591. fan_speed = i8k_get_fan_speed(index);
  592. if (fan_speed < 0)
  593. return fan_speed;
  594. return sprintf(buf, "%d\n", fan_speed);
  595. }
  596. static ssize_t i8k_hwmon_pwm_show(struct device *dev,
  597. struct device_attribute *devattr, char *buf)
  598. {
  599. int index = to_sensor_dev_attr(devattr)->index;
  600. int status;
  601. status = i8k_get_fan_status(index);
  602. if (status < 0)
  603. return -EIO;
  604. return sprintf(buf, "%d\n", clamp_val(status * i8k_pwm_mult, 0, 255));
  605. }
  606. static ssize_t i8k_hwmon_pwm_store(struct device *dev,
  607. struct device_attribute *attr,
  608. const char *buf, size_t count)
  609. {
  610. int index = to_sensor_dev_attr(attr)->index;
  611. unsigned long val;
  612. int err;
  613. err = kstrtoul(buf, 10, &val);
  614. if (err)
  615. return err;
  616. val = clamp_val(DIV_ROUND_CLOSEST(val, i8k_pwm_mult), 0, i8k_fan_max);
  617. mutex_lock(&i8k_mutex);
  618. err = i8k_set_fan(index, val);
  619. mutex_unlock(&i8k_mutex);
  620. return err < 0 ? -EIO : count;
  621. }
  622. static ssize_t i8k_hwmon_pwm_enable_store(struct device *dev,
  623. struct device_attribute *attr,
  624. const char *buf, size_t count)
  625. {
  626. int err;
  627. bool enable;
  628. unsigned long val;
  629. if (!auto_fan)
  630. return -ENODEV;
  631. err = kstrtoul(buf, 10, &val);
  632. if (err)
  633. return err;
  634. if (val == 1)
  635. enable = false;
  636. else if (val == 2)
  637. enable = true;
  638. else
  639. return -EINVAL;
  640. mutex_lock(&i8k_mutex);
  641. err = i8k_enable_fan_auto_mode(enable);
  642. mutex_unlock(&i8k_mutex);
  643. return err ? err : count;
  644. }
  645. static SENSOR_DEVICE_ATTR_RO(temp1_input, i8k_hwmon_temp, 0);
  646. static SENSOR_DEVICE_ATTR_RO(temp1_label, i8k_hwmon_temp_label, 0);
  647. static SENSOR_DEVICE_ATTR_RO(temp2_input, i8k_hwmon_temp, 1);
  648. static SENSOR_DEVICE_ATTR_RO(temp2_label, i8k_hwmon_temp_label, 1);
  649. static SENSOR_DEVICE_ATTR_RO(temp3_input, i8k_hwmon_temp, 2);
  650. static SENSOR_DEVICE_ATTR_RO(temp3_label, i8k_hwmon_temp_label, 2);
  651. static SENSOR_DEVICE_ATTR_RO(temp4_input, i8k_hwmon_temp, 3);
  652. static SENSOR_DEVICE_ATTR_RO(temp4_label, i8k_hwmon_temp_label, 3);
  653. static SENSOR_DEVICE_ATTR_RO(temp5_input, i8k_hwmon_temp, 4);
  654. static SENSOR_DEVICE_ATTR_RO(temp5_label, i8k_hwmon_temp_label, 4);
  655. static SENSOR_DEVICE_ATTR_RO(temp6_input, i8k_hwmon_temp, 5);
  656. static SENSOR_DEVICE_ATTR_RO(temp6_label, i8k_hwmon_temp_label, 5);
  657. static SENSOR_DEVICE_ATTR_RO(temp7_input, i8k_hwmon_temp, 6);
  658. static SENSOR_DEVICE_ATTR_RO(temp7_label, i8k_hwmon_temp_label, 6);
  659. static SENSOR_DEVICE_ATTR_RO(temp8_input, i8k_hwmon_temp, 7);
  660. static SENSOR_DEVICE_ATTR_RO(temp8_label, i8k_hwmon_temp_label, 7);
  661. static SENSOR_DEVICE_ATTR_RO(temp9_input, i8k_hwmon_temp, 8);
  662. static SENSOR_DEVICE_ATTR_RO(temp9_label, i8k_hwmon_temp_label, 8);
  663. static SENSOR_DEVICE_ATTR_RO(temp10_input, i8k_hwmon_temp, 9);
  664. static SENSOR_DEVICE_ATTR_RO(temp10_label, i8k_hwmon_temp_label, 9);
  665. static SENSOR_DEVICE_ATTR_RO(fan1_input, i8k_hwmon_fan, 0);
  666. static SENSOR_DEVICE_ATTR_RO(fan1_label, i8k_hwmon_fan_label, 0);
  667. static SENSOR_DEVICE_ATTR_RW(pwm1, i8k_hwmon_pwm, 0);
  668. static SENSOR_DEVICE_ATTR_WO(pwm1_enable, i8k_hwmon_pwm_enable, 0);
  669. static SENSOR_DEVICE_ATTR_RO(fan2_input, i8k_hwmon_fan, 1);
  670. static SENSOR_DEVICE_ATTR_RO(fan2_label, i8k_hwmon_fan_label, 1);
  671. static SENSOR_DEVICE_ATTR_RW(pwm2, i8k_hwmon_pwm, 1);
  672. static SENSOR_DEVICE_ATTR_RO(fan3_input, i8k_hwmon_fan, 2);
  673. static SENSOR_DEVICE_ATTR_RO(fan3_label, i8k_hwmon_fan_label, 2);
  674. static SENSOR_DEVICE_ATTR_RW(pwm3, i8k_hwmon_pwm, 2);
  675. static struct attribute *i8k_attrs[] = {
  676. &sensor_dev_attr_temp1_input.dev_attr.attr, /* 0 */
  677. &sensor_dev_attr_temp1_label.dev_attr.attr, /* 1 */
  678. &sensor_dev_attr_temp2_input.dev_attr.attr, /* 2 */
  679. &sensor_dev_attr_temp2_label.dev_attr.attr, /* 3 */
  680. &sensor_dev_attr_temp3_input.dev_attr.attr, /* 4 */
  681. &sensor_dev_attr_temp3_label.dev_attr.attr, /* 5 */
  682. &sensor_dev_attr_temp4_input.dev_attr.attr, /* 6 */
  683. &sensor_dev_attr_temp4_label.dev_attr.attr, /* 7 */
  684. &sensor_dev_attr_temp5_input.dev_attr.attr, /* 8 */
  685. &sensor_dev_attr_temp5_label.dev_attr.attr, /* 9 */
  686. &sensor_dev_attr_temp6_input.dev_attr.attr, /* 10 */
  687. &sensor_dev_attr_temp6_label.dev_attr.attr, /* 11 */
  688. &sensor_dev_attr_temp7_input.dev_attr.attr, /* 12 */
  689. &sensor_dev_attr_temp7_label.dev_attr.attr, /* 13 */
  690. &sensor_dev_attr_temp8_input.dev_attr.attr, /* 14 */
  691. &sensor_dev_attr_temp8_label.dev_attr.attr, /* 15 */
  692. &sensor_dev_attr_temp9_input.dev_attr.attr, /* 16 */
  693. &sensor_dev_attr_temp9_label.dev_attr.attr, /* 17 */
  694. &sensor_dev_attr_temp10_input.dev_attr.attr, /* 18 */
  695. &sensor_dev_attr_temp10_label.dev_attr.attr, /* 19 */
  696. &sensor_dev_attr_fan1_input.dev_attr.attr, /* 20 */
  697. &sensor_dev_attr_fan1_label.dev_attr.attr, /* 21 */
  698. &sensor_dev_attr_pwm1.dev_attr.attr, /* 22 */
  699. &sensor_dev_attr_pwm1_enable.dev_attr.attr, /* 23 */
  700. &sensor_dev_attr_fan2_input.dev_attr.attr, /* 24 */
  701. &sensor_dev_attr_fan2_label.dev_attr.attr, /* 25 */
  702. &sensor_dev_attr_pwm2.dev_attr.attr, /* 26 */
  703. &sensor_dev_attr_fan3_input.dev_attr.attr, /* 27 */
  704. &sensor_dev_attr_fan3_label.dev_attr.attr, /* 28 */
  705. &sensor_dev_attr_pwm3.dev_attr.attr, /* 29 */
  706. NULL
  707. };
  708. static umode_t i8k_is_visible(struct kobject *kobj, struct attribute *attr,
  709. int index)
  710. {
  711. if (disallow_fan_support && index >= 20)
  712. return 0;
  713. if (disallow_fan_type_call &&
  714. (index == 21 || index == 25 || index == 28))
  715. return 0;
  716. if (index >= 0 && index <= 1 &&
  717. !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP1))
  718. return 0;
  719. if (index >= 2 && index <= 3 &&
  720. !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP2))
  721. return 0;
  722. if (index >= 4 && index <= 5 &&
  723. !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP3))
  724. return 0;
  725. if (index >= 6 && index <= 7 &&
  726. !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP4))
  727. return 0;
  728. if (index >= 8 && index <= 9 &&
  729. !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP5))
  730. return 0;
  731. if (index >= 10 && index <= 11 &&
  732. !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP6))
  733. return 0;
  734. if (index >= 12 && index <= 13 &&
  735. !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP7))
  736. return 0;
  737. if (index >= 14 && index <= 15 &&
  738. !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP8))
  739. return 0;
  740. if (index >= 16 && index <= 17 &&
  741. !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP9))
  742. return 0;
  743. if (index >= 18 && index <= 19 &&
  744. !(i8k_hwmon_flags & I8K_HWMON_HAVE_TEMP10))
  745. return 0;
  746. if (index >= 20 && index <= 23 &&
  747. !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN1))
  748. return 0;
  749. if (index >= 24 && index <= 26 &&
  750. !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN2))
  751. return 0;
  752. if (index >= 27 && index <= 29 &&
  753. !(i8k_hwmon_flags & I8K_HWMON_HAVE_FAN3))
  754. return 0;
  755. if (index == 23 && !auto_fan)
  756. return 0;
  757. return attr->mode;
  758. }
  759. static const struct attribute_group i8k_group = {
  760. .attrs = i8k_attrs,
  761. .is_visible = i8k_is_visible,
  762. };
  763. __ATTRIBUTE_GROUPS(i8k);
  764. static int __init i8k_init_hwmon(void)
  765. {
  766. int err;
  767. i8k_hwmon_flags = 0;
  768. /* CPU temperature attributes, if temperature type is OK */
  769. err = i8k_get_temp_type(0);
  770. if (err >= 0)
  771. i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP1;
  772. /* check for additional temperature sensors */
  773. err = i8k_get_temp_type(1);
  774. if (err >= 0)
  775. i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP2;
  776. err = i8k_get_temp_type(2);
  777. if (err >= 0)
  778. i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP3;
  779. err = i8k_get_temp_type(3);
  780. if (err >= 0)
  781. i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP4;
  782. err = i8k_get_temp_type(4);
  783. if (err >= 0)
  784. i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP5;
  785. err = i8k_get_temp_type(5);
  786. if (err >= 0)
  787. i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP6;
  788. err = i8k_get_temp_type(6);
  789. if (err >= 0)
  790. i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP7;
  791. err = i8k_get_temp_type(7);
  792. if (err >= 0)
  793. i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP8;
  794. err = i8k_get_temp_type(8);
  795. if (err >= 0)
  796. i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP9;
  797. err = i8k_get_temp_type(9);
  798. if (err >= 0)
  799. i8k_hwmon_flags |= I8K_HWMON_HAVE_TEMP10;
  800. /* First fan attributes, if fan status or type is OK */
  801. err = i8k_get_fan_status(0);
  802. if (err < 0)
  803. err = i8k_get_fan_type(0);
  804. if (err >= 0)
  805. i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN1;
  806. /* Second fan attributes, if fan status or type is OK */
  807. err = i8k_get_fan_status(1);
  808. if (err < 0)
  809. err = i8k_get_fan_type(1);
  810. if (err >= 0)
  811. i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN2;
  812. /* Third fan attributes, if fan status or type is OK */
  813. err = i8k_get_fan_status(2);
  814. if (err < 0)
  815. err = i8k_get_fan_type(2);
  816. if (err >= 0)
  817. i8k_hwmon_flags |= I8K_HWMON_HAVE_FAN3;
  818. i8k_hwmon_dev = hwmon_device_register_with_groups(NULL, "dell_smm",
  819. NULL, i8k_groups);
  820. if (IS_ERR(i8k_hwmon_dev)) {
  821. err = PTR_ERR(i8k_hwmon_dev);
  822. i8k_hwmon_dev = NULL;
  823. pr_err("hwmon registration failed (%d)\n", err);
  824. return err;
  825. }
  826. return 0;
  827. }
  828. struct i8k_config_data {
  829. uint fan_mult;
  830. uint fan_max;
  831. };
  832. enum i8k_configs {
  833. DELL_LATITUDE_D520,
  834. DELL_PRECISION_490,
  835. DELL_STUDIO,
  836. DELL_XPS,
  837. };
  838. static const struct i8k_config_data i8k_config_data[] = {
  839. [DELL_LATITUDE_D520] = {
  840. .fan_mult = 1,
  841. .fan_max = I8K_FAN_TURBO,
  842. },
  843. [DELL_PRECISION_490] = {
  844. .fan_mult = 1,
  845. .fan_max = I8K_FAN_TURBO,
  846. },
  847. [DELL_STUDIO] = {
  848. .fan_mult = 1,
  849. .fan_max = I8K_FAN_HIGH,
  850. },
  851. [DELL_XPS] = {
  852. .fan_mult = 1,
  853. .fan_max = I8K_FAN_HIGH,
  854. },
  855. };
  856. static const struct dmi_system_id i8k_dmi_table[] __initconst = {
  857. {
  858. .ident = "Dell Inspiron",
  859. .matches = {
  860. DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"),
  861. DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"),
  862. },
  863. },
  864. {
  865. .ident = "Dell Latitude",
  866. .matches = {
  867. DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"),
  868. DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"),
  869. },
  870. },
  871. {
  872. .ident = "Dell Inspiron 2",
  873. .matches = {
  874. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  875. DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"),
  876. },
  877. },
  878. {
  879. .ident = "Dell Latitude D520",
  880. .matches = {
  881. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  882. DMI_MATCH(DMI_PRODUCT_NAME, "Latitude D520"),
  883. },
  884. .driver_data = (void *)&i8k_config_data[DELL_LATITUDE_D520],
  885. },
  886. {
  887. .ident = "Dell Latitude 2",
  888. .matches = {
  889. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  890. DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"),
  891. },
  892. },
  893. { /* UK Inspiron 6400 */
  894. .ident = "Dell Inspiron 3",
  895. .matches = {
  896. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  897. DMI_MATCH(DMI_PRODUCT_NAME, "MM061"),
  898. },
  899. },
  900. {
  901. .ident = "Dell Inspiron 3",
  902. .matches = {
  903. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  904. DMI_MATCH(DMI_PRODUCT_NAME, "MP061"),
  905. },
  906. },
  907. {
  908. .ident = "Dell Precision 490",
  909. .matches = {
  910. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  911. DMI_MATCH(DMI_PRODUCT_NAME,
  912. "Precision WorkStation 490"),
  913. },
  914. .driver_data = (void *)&i8k_config_data[DELL_PRECISION_490],
  915. },
  916. {
  917. .ident = "Dell Precision",
  918. .matches = {
  919. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  920. DMI_MATCH(DMI_PRODUCT_NAME, "Precision"),
  921. },
  922. },
  923. {
  924. .ident = "Dell Vostro",
  925. .matches = {
  926. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  927. DMI_MATCH(DMI_PRODUCT_NAME, "Vostro"),
  928. },
  929. },
  930. {
  931. .ident = "Dell Studio",
  932. .matches = {
  933. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  934. DMI_MATCH(DMI_PRODUCT_NAME, "Studio"),
  935. },
  936. .driver_data = (void *)&i8k_config_data[DELL_STUDIO],
  937. },
  938. {
  939. .ident = "Dell XPS M140",
  940. .matches = {
  941. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  942. DMI_MATCH(DMI_PRODUCT_NAME, "MXC051"),
  943. },
  944. .driver_data = (void *)&i8k_config_data[DELL_XPS],
  945. },
  946. {
  947. .ident = "Dell XPS",
  948. .matches = {
  949. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  950. DMI_MATCH(DMI_PRODUCT_NAME, "XPS"),
  951. },
  952. },
  953. { }
  954. };
  955. MODULE_DEVICE_TABLE(dmi, i8k_dmi_table);
  956. /*
  957. * On some machines once I8K_SMM_GET_FAN_TYPE is issued then CPU fan speed
  958. * randomly going up and down due to bug in Dell SMM or BIOS. Here is blacklist
  959. * of affected Dell machines for which we disallow I8K_SMM_GET_FAN_TYPE call.
  960. * See bug: https://bugzilla.kernel.org/show_bug.cgi?id=100121
  961. */
  962. static const struct dmi_system_id i8k_blacklist_fan_type_dmi_table[] __initconst = {
  963. {
  964. .ident = "Dell Studio XPS 8000",
  965. .matches = {
  966. DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  967. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Studio XPS 8000"),
  968. },
  969. },
  970. {
  971. .ident = "Dell Studio XPS 8100",
  972. .matches = {
  973. DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  974. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Studio XPS 8100"),
  975. },
  976. },
  977. {
  978. .ident = "Dell Inspiron 580",
  979. .matches = {
  980. DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  981. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Inspiron 580 "),
  982. },
  983. },
  984. { }
  985. };
  986. /*
  987. * On some machines all fan related SMM functions implemented by Dell BIOS
  988. * firmware freeze kernel for about 500ms. Until Dell fixes these problems fan
  989. * support for affected blacklisted Dell machines stay disabled.
  990. * See bug: https://bugzilla.kernel.org/show_bug.cgi?id=195751
  991. */
  992. static struct dmi_system_id i8k_blacklist_fan_support_dmi_table[] __initdata = {
  993. {
  994. .ident = "Dell Inspiron 7720",
  995. .matches = {
  996. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  997. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Inspiron 7720"),
  998. },
  999. },
  1000. {
  1001. .ident = "Dell Vostro 3360",
  1002. .matches = {
  1003. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  1004. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Vostro 3360"),
  1005. },
  1006. },
  1007. {
  1008. .ident = "Dell XPS13 9333",
  1009. .matches = {
  1010. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  1011. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "XPS13 9333"),
  1012. },
  1013. },
  1014. {
  1015. .ident = "Dell XPS 15 L502X",
  1016. .matches = {
  1017. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  1018. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Dell System XPS L502X"),
  1019. },
  1020. },
  1021. { }
  1022. };
  1023. struct i8k_fan_control_data {
  1024. unsigned int manual_fan;
  1025. unsigned int auto_fan;
  1026. };
  1027. enum i8k_fan_controls {
  1028. I8K_FAN_34A3_35A3,
  1029. };
  1030. static const struct i8k_fan_control_data i8k_fan_control_data[] = {
  1031. [I8K_FAN_34A3_35A3] = {
  1032. .manual_fan = 0x34a3,
  1033. .auto_fan = 0x35a3,
  1034. },
  1035. };
  1036. static struct dmi_system_id i8k_whitelist_fan_control[] __initdata = {
  1037. {
  1038. .ident = "Dell Precision 5530",
  1039. .matches = {
  1040. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  1041. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Precision 5530"),
  1042. },
  1043. .driver_data = (void *)&i8k_fan_control_data[I8K_FAN_34A3_35A3],
  1044. },
  1045. {
  1046. .ident = "Dell Latitude 5480",
  1047. .matches = {
  1048. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  1049. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Latitude 5480"),
  1050. },
  1051. .driver_data = (void *)&i8k_fan_control_data[I8K_FAN_34A3_35A3],
  1052. },
  1053. {
  1054. .ident = "Dell Latitude E6440",
  1055. .matches = {
  1056. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  1057. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Latitude E6440"),
  1058. },
  1059. .driver_data = (void *)&i8k_fan_control_data[I8K_FAN_34A3_35A3],
  1060. },
  1061. { }
  1062. };
  1063. /*
  1064. * Probe for the presence of a supported laptop.
  1065. */
  1066. static int __init i8k_probe(void)
  1067. {
  1068. const struct dmi_system_id *id, *fan_control;
  1069. int fan, ret;
  1070. /*
  1071. * Get DMI information
  1072. */
  1073. if (!dmi_check_system(i8k_dmi_table)) {
  1074. if (!ignore_dmi && !force)
  1075. return -ENODEV;
  1076. pr_info("not running on a supported Dell system.\n");
  1077. pr_info("vendor=%s, model=%s, version=%s\n",
  1078. i8k_get_dmi_data(DMI_SYS_VENDOR),
  1079. i8k_get_dmi_data(DMI_PRODUCT_NAME),
  1080. i8k_get_dmi_data(DMI_BIOS_VERSION));
  1081. }
  1082. if (dmi_check_system(i8k_blacklist_fan_support_dmi_table)) {
  1083. pr_warn("broken Dell BIOS detected, disallow fan support\n");
  1084. if (!force)
  1085. disallow_fan_support = true;
  1086. }
  1087. if (dmi_check_system(i8k_blacklist_fan_type_dmi_table)) {
  1088. pr_warn("broken Dell BIOS detected, disallow fan type call\n");
  1089. if (!force)
  1090. disallow_fan_type_call = true;
  1091. }
  1092. strlcpy(bios_version, i8k_get_dmi_data(DMI_BIOS_VERSION),
  1093. sizeof(bios_version));
  1094. strlcpy(bios_machineid, i8k_get_dmi_data(DMI_PRODUCT_SERIAL),
  1095. sizeof(bios_machineid));
  1096. /*
  1097. * Get SMM Dell signature
  1098. */
  1099. if (i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG1) &&
  1100. i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG2)) {
  1101. pr_err("unable to get SMM Dell signature\n");
  1102. if (!force)
  1103. return -ENODEV;
  1104. }
  1105. /*
  1106. * Set fan multiplier and maximal fan speed from dmi config
  1107. * Values specified in module parameters override values from dmi
  1108. */
  1109. id = dmi_first_match(i8k_dmi_table);
  1110. if (id && id->driver_data) {
  1111. const struct i8k_config_data *conf = id->driver_data;
  1112. if (!fan_mult && conf->fan_mult)
  1113. fan_mult = conf->fan_mult;
  1114. if (!fan_max && conf->fan_max)
  1115. fan_max = conf->fan_max;
  1116. }
  1117. i8k_fan_max = fan_max ? : I8K_FAN_HIGH; /* Must not be 0 */
  1118. i8k_pwm_mult = DIV_ROUND_UP(255, i8k_fan_max);
  1119. fan_control = dmi_first_match(i8k_whitelist_fan_control);
  1120. if (fan_control && fan_control->driver_data) {
  1121. const struct i8k_fan_control_data *data = fan_control->driver_data;
  1122. manual_fan = data->manual_fan;
  1123. auto_fan = data->auto_fan;
  1124. pr_info("enabling support for setting automatic/manual fan control\n");
  1125. }
  1126. if (!fan_mult) {
  1127. /*
  1128. * Autodetect fan multiplier based on nominal rpm
  1129. * If fan reports rpm value too high then set multiplier to 1
  1130. */
  1131. for (fan = 0; fan < 2; ++fan) {
  1132. ret = i8k_get_fan_nominal_speed(fan, i8k_fan_max);
  1133. if (ret < 0)
  1134. continue;
  1135. if (ret > I8K_FAN_MAX_RPM)
  1136. i8k_fan_mult = 1;
  1137. break;
  1138. }
  1139. } else {
  1140. /* Fan multiplier was specified in module param or in dmi */
  1141. i8k_fan_mult = fan_mult;
  1142. }
  1143. return 0;
  1144. }
  1145. static int __init i8k_init(void)
  1146. {
  1147. int err;
  1148. /* Are we running on an supported laptop? */
  1149. if (i8k_probe())
  1150. return -ENODEV;
  1151. err = i8k_init_hwmon();
  1152. if (err)
  1153. return err;
  1154. i8k_init_procfs();
  1155. return 0;
  1156. }
  1157. static void __exit i8k_exit(void)
  1158. {
  1159. hwmon_device_unregister(i8k_hwmon_dev);
  1160. i8k_exit_procfs();
  1161. }
  1162. module_init(i8k_init);
  1163. module_exit(i8k_exit);