dell-smm-hwmon.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468
  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 <[email protected]>
  6. *
  7. * Hwmon integration:
  8. * Copyright (C) 2011 Jean Delvare <[email protected]>
  9. * Copyright (C) 2013, 2014 Guenter Roeck <[email protected]>
  10. * Copyright (C) 2014, 2015 Pali Rohár <[email protected]>
  11. */
  12. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  13. #include <linux/capability.h>
  14. #include <linux/cpu.h>
  15. #include <linux/ctype.h>
  16. #include <linux/delay.h>
  17. #include <linux/dmi.h>
  18. #include <linux/err.h>
  19. #include <linux/errno.h>
  20. #include <linux/hwmon.h>
  21. #include <linux/init.h>
  22. #include <linux/kconfig.h>
  23. #include <linux/kernel.h>
  24. #include <linux/module.h>
  25. #include <linux/mutex.h>
  26. #include <linux/platform_device.h>
  27. #include <linux/proc_fs.h>
  28. #include <linux/seq_file.h>
  29. #include <linux/slab.h>
  30. #include <linux/smp.h>
  31. #include <linux/string.h>
  32. #include <linux/thermal.h>
  33. #include <linux/types.h>
  34. #include <linux/uaccess.h>
  35. #include <linux/i8k.h>
  36. #define I8K_SMM_FN_STATUS 0x0025
  37. #define I8K_SMM_POWER_STATUS 0x0069
  38. #define I8K_SMM_SET_FAN 0x01a3
  39. #define I8K_SMM_GET_FAN 0x00a3
  40. #define I8K_SMM_GET_SPEED 0x02a3
  41. #define I8K_SMM_GET_FAN_TYPE 0x03a3
  42. #define I8K_SMM_GET_NOM_SPEED 0x04a3
  43. #define I8K_SMM_GET_TEMP 0x10a3
  44. #define I8K_SMM_GET_TEMP_TYPE 0x11a3
  45. #define I8K_SMM_GET_DELL_SIG1 0xfea3
  46. #define I8K_SMM_GET_DELL_SIG2 0xffa3
  47. /* in usecs */
  48. #define DELL_SMM_MAX_DURATION 250000
  49. #define I8K_FAN_MULT 30
  50. #define I8K_FAN_RPM_THRESHOLD 1000
  51. #define I8K_MAX_TEMP 127
  52. #define I8K_FN_NONE 0x00
  53. #define I8K_FN_UP 0x01
  54. #define I8K_FN_DOWN 0x02
  55. #define I8K_FN_MUTE 0x04
  56. #define I8K_FN_MASK 0x07
  57. #define I8K_FN_SHIFT 8
  58. #define I8K_POWER_AC 0x05
  59. #define I8K_POWER_BATTERY 0x01
  60. #define DELL_SMM_NO_TEMP 10
  61. #define DELL_SMM_NO_FANS 3
  62. struct dell_smm_data {
  63. struct mutex i8k_mutex; /* lock for sensors writes */
  64. char bios_version[4];
  65. char bios_machineid[16];
  66. uint i8k_fan_mult;
  67. uint i8k_pwm_mult;
  68. uint i8k_fan_max;
  69. bool disallow_fan_type_call;
  70. bool disallow_fan_support;
  71. unsigned int manual_fan;
  72. unsigned int auto_fan;
  73. int temp_type[DELL_SMM_NO_TEMP];
  74. bool fan[DELL_SMM_NO_FANS];
  75. int fan_type[DELL_SMM_NO_FANS];
  76. int *fan_nominal_speed[DELL_SMM_NO_FANS];
  77. };
  78. struct dell_smm_cooling_data {
  79. u8 fan_num;
  80. struct dell_smm_data *data;
  81. };
  82. MODULE_AUTHOR("Massimo Dal Zotto ([email protected])");
  83. MODULE_AUTHOR("Pali Rohár <[email protected]>");
  84. MODULE_DESCRIPTION("Dell laptop SMM BIOS hwmon driver");
  85. MODULE_LICENSE("GPL");
  86. MODULE_ALIAS("i8k");
  87. static bool force;
  88. module_param_unsafe(force, bool, 0);
  89. MODULE_PARM_DESC(force, "Force loading without checking for supported models and features");
  90. static bool ignore_dmi;
  91. module_param(ignore_dmi, bool, 0);
  92. MODULE_PARM_DESC(ignore_dmi, "Continue probing hardware even if DMI data does not match");
  93. #if IS_ENABLED(CONFIG_I8K)
  94. static bool restricted = true;
  95. module_param(restricted, bool, 0);
  96. MODULE_PARM_DESC(restricted, "Restrict fan control and serial number to CAP_SYS_ADMIN (default: 1)");
  97. static bool power_status;
  98. module_param(power_status, bool, 0600);
  99. MODULE_PARM_DESC(power_status, "Report power status in /proc/i8k (default: 0)");
  100. #endif
  101. static uint fan_mult;
  102. module_param(fan_mult, uint, 0);
  103. MODULE_PARM_DESC(fan_mult, "Factor to multiply fan speed with (default: autodetect)");
  104. static uint fan_max;
  105. module_param(fan_max, uint, 0);
  106. MODULE_PARM_DESC(fan_max, "Maximum configurable fan speed (default: autodetect)");
  107. struct smm_regs {
  108. unsigned int eax;
  109. unsigned int ebx;
  110. unsigned int ecx;
  111. unsigned int edx;
  112. unsigned int esi;
  113. unsigned int edi;
  114. };
  115. static const char * const temp_labels[] = {
  116. "CPU",
  117. "GPU",
  118. "SODIMM",
  119. "Other",
  120. "Ambient",
  121. "Other",
  122. };
  123. static const char * const fan_labels[] = {
  124. "Processor Fan",
  125. "Motherboard Fan",
  126. "Video Fan",
  127. "Power Supply Fan",
  128. "Chipset Fan",
  129. "Other Fan",
  130. };
  131. static const char * const docking_labels[] = {
  132. "Docking Processor Fan",
  133. "Docking Motherboard Fan",
  134. "Docking Video Fan",
  135. "Docking Power Supply Fan",
  136. "Docking Chipset Fan",
  137. "Docking Other Fan",
  138. };
  139. static inline const char __init *i8k_get_dmi_data(int field)
  140. {
  141. const char *dmi_data = dmi_get_system_info(field);
  142. return dmi_data && *dmi_data ? dmi_data : "?";
  143. }
  144. /*
  145. * Call the System Management Mode BIOS. Code provided by Jonathan Buzzard.
  146. */
  147. static int i8k_smm_func(void *par)
  148. {
  149. ktime_t calltime = ktime_get();
  150. struct smm_regs *regs = par;
  151. int eax = regs->eax;
  152. int ebx = regs->ebx;
  153. unsigned char carry;
  154. long long duration;
  155. /* SMM requires CPU 0 */
  156. if (smp_processor_id() != 0)
  157. return -EBUSY;
  158. asm volatile("out %%al,$0xb2\n\t"
  159. "out %%al,$0x84\n\t"
  160. "setc %0\n"
  161. : "=mr" (carry),
  162. "+a" (regs->eax),
  163. "+b" (regs->ebx),
  164. "+c" (regs->ecx),
  165. "+d" (regs->edx),
  166. "+S" (regs->esi),
  167. "+D" (regs->edi));
  168. duration = ktime_us_delta(ktime_get(), calltime);
  169. pr_debug("smm(0x%.4x 0x%.4x) = 0x%.4x carry: %d (took %7lld usecs)\n",
  170. eax, ebx, regs->eax & 0xffff, carry, duration);
  171. if (duration > DELL_SMM_MAX_DURATION)
  172. pr_warn_once("SMM call took %lld usecs!\n", duration);
  173. if (carry || (regs->eax & 0xffff) == 0xffff || regs->eax == eax)
  174. return -EINVAL;
  175. return 0;
  176. }
  177. /*
  178. * Call the System Management Mode BIOS.
  179. */
  180. static int i8k_smm(struct smm_regs *regs)
  181. {
  182. int ret;
  183. cpus_read_lock();
  184. ret = smp_call_on_cpu(0, i8k_smm_func, regs, true);
  185. cpus_read_unlock();
  186. return ret;
  187. }
  188. /*
  189. * Read the fan status.
  190. */
  191. static int i8k_get_fan_status(const struct dell_smm_data *data, u8 fan)
  192. {
  193. struct smm_regs regs = {
  194. .eax = I8K_SMM_GET_FAN,
  195. .ebx = fan,
  196. };
  197. if (data->disallow_fan_support)
  198. return -EINVAL;
  199. return i8k_smm(&regs) ? : regs.eax & 0xff;
  200. }
  201. /*
  202. * Read the fan speed in RPM.
  203. */
  204. static int i8k_get_fan_speed(const struct dell_smm_data *data, u8 fan)
  205. {
  206. struct smm_regs regs = {
  207. .eax = I8K_SMM_GET_SPEED,
  208. .ebx = fan,
  209. };
  210. if (data->disallow_fan_support)
  211. return -EINVAL;
  212. return i8k_smm(&regs) ? : (regs.eax & 0xffff) * data->i8k_fan_mult;
  213. }
  214. /*
  215. * Read the fan type.
  216. */
  217. static int _i8k_get_fan_type(const struct dell_smm_data *data, u8 fan)
  218. {
  219. struct smm_regs regs = {
  220. .eax = I8K_SMM_GET_FAN_TYPE,
  221. .ebx = fan,
  222. };
  223. if (data->disallow_fan_support || data->disallow_fan_type_call)
  224. return -EINVAL;
  225. return i8k_smm(&regs) ? : regs.eax & 0xff;
  226. }
  227. static int i8k_get_fan_type(struct dell_smm_data *data, u8 fan)
  228. {
  229. /* I8K_SMM_GET_FAN_TYPE SMM call is expensive, so cache values */
  230. if (data->fan_type[fan] == INT_MIN)
  231. data->fan_type[fan] = _i8k_get_fan_type(data, fan);
  232. return data->fan_type[fan];
  233. }
  234. /*
  235. * Read the fan nominal rpm for specific fan speed.
  236. */
  237. static int __init i8k_get_fan_nominal_speed(const struct dell_smm_data *data, u8 fan, int speed)
  238. {
  239. struct smm_regs regs = {
  240. .eax = I8K_SMM_GET_NOM_SPEED,
  241. .ebx = fan | (speed << 8),
  242. };
  243. if (data->disallow_fan_support)
  244. return -EINVAL;
  245. return i8k_smm(&regs) ? : (regs.eax & 0xffff);
  246. }
  247. /*
  248. * Enable or disable automatic BIOS fan control support
  249. */
  250. static int i8k_enable_fan_auto_mode(const struct dell_smm_data *data, bool enable)
  251. {
  252. struct smm_regs regs = { };
  253. if (data->disallow_fan_support)
  254. return -EINVAL;
  255. regs.eax = enable ? data->auto_fan : data->manual_fan;
  256. return i8k_smm(&regs);
  257. }
  258. /*
  259. * Set the fan speed (off, low, high, ...).
  260. */
  261. static int i8k_set_fan(const struct dell_smm_data *data, u8 fan, int speed)
  262. {
  263. struct smm_regs regs = { .eax = I8K_SMM_SET_FAN, };
  264. if (data->disallow_fan_support)
  265. return -EINVAL;
  266. speed = (speed < 0) ? 0 : ((speed > data->i8k_fan_max) ? data->i8k_fan_max : speed);
  267. regs.ebx = fan | (speed << 8);
  268. return i8k_smm(&regs);
  269. }
  270. static int __init i8k_get_temp_type(u8 sensor)
  271. {
  272. struct smm_regs regs = {
  273. .eax = I8K_SMM_GET_TEMP_TYPE,
  274. .ebx = sensor,
  275. };
  276. return i8k_smm(&regs) ? : regs.eax & 0xff;
  277. }
  278. /*
  279. * Read the cpu temperature.
  280. */
  281. static int _i8k_get_temp(u8 sensor)
  282. {
  283. struct smm_regs regs = {
  284. .eax = I8K_SMM_GET_TEMP,
  285. .ebx = sensor,
  286. };
  287. return i8k_smm(&regs) ? : regs.eax & 0xff;
  288. }
  289. static int i8k_get_temp(u8 sensor)
  290. {
  291. int temp = _i8k_get_temp(sensor);
  292. /*
  293. * Sometimes the temperature sensor returns 0x99, which is out of range.
  294. * In this case we retry (once) before returning an error.
  295. # 1003655137 00000058 00005a4b
  296. # 1003655138 00000099 00003a80 <--- 0x99 = 153 degrees
  297. # 1003655139 00000054 00005c52
  298. */
  299. if (temp == 0x99) {
  300. msleep(100);
  301. temp = _i8k_get_temp(sensor);
  302. }
  303. /*
  304. * Return -ENODATA for all invalid temperatures.
  305. *
  306. * Known instances are the 0x99 value as seen above as well as
  307. * 0xc1 (193), which may be returned when trying to read the GPU
  308. * temperature if the system supports a GPU and it is currently
  309. * turned off.
  310. */
  311. if (temp > I8K_MAX_TEMP)
  312. return -ENODATA;
  313. return temp;
  314. }
  315. static int __init i8k_get_dell_signature(int req_fn)
  316. {
  317. struct smm_regs regs = { .eax = req_fn, };
  318. int rc;
  319. rc = i8k_smm(&regs);
  320. if (rc < 0)
  321. return rc;
  322. return regs.eax == 1145651527 && regs.edx == 1145392204 ? 0 : -1;
  323. }
  324. #if IS_ENABLED(CONFIG_I8K)
  325. /*
  326. * Read the Fn key status.
  327. */
  328. static int i8k_get_fn_status(void)
  329. {
  330. struct smm_regs regs = { .eax = I8K_SMM_FN_STATUS, };
  331. int rc;
  332. rc = i8k_smm(&regs);
  333. if (rc < 0)
  334. return rc;
  335. switch ((regs.eax >> I8K_FN_SHIFT) & I8K_FN_MASK) {
  336. case I8K_FN_UP:
  337. return I8K_VOL_UP;
  338. case I8K_FN_DOWN:
  339. return I8K_VOL_DOWN;
  340. case I8K_FN_MUTE:
  341. return I8K_VOL_MUTE;
  342. default:
  343. return 0;
  344. }
  345. }
  346. /*
  347. * Read the power status.
  348. */
  349. static int i8k_get_power_status(void)
  350. {
  351. struct smm_regs regs = { .eax = I8K_SMM_POWER_STATUS, };
  352. int rc;
  353. rc = i8k_smm(&regs);
  354. if (rc < 0)
  355. return rc;
  356. return (regs.eax & 0xff) == I8K_POWER_AC ? I8K_AC : I8K_BATTERY;
  357. }
  358. /*
  359. * Procfs interface
  360. */
  361. static long i8k_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
  362. {
  363. struct dell_smm_data *data = pde_data(file_inode(fp));
  364. int __user *argp = (int __user *)arg;
  365. int speed, err;
  366. int val = 0;
  367. if (!argp)
  368. return -EINVAL;
  369. switch (cmd) {
  370. case I8K_BIOS_VERSION:
  371. if (!isdigit(data->bios_version[0]) || !isdigit(data->bios_version[1]) ||
  372. !isdigit(data->bios_version[2]))
  373. return -EINVAL;
  374. val = (data->bios_version[0] << 16) |
  375. (data->bios_version[1] << 8) | data->bios_version[2];
  376. if (copy_to_user(argp, &val, sizeof(val)))
  377. return -EFAULT;
  378. return 0;
  379. case I8K_MACHINE_ID:
  380. if (restricted && !capable(CAP_SYS_ADMIN))
  381. return -EPERM;
  382. if (copy_to_user(argp, data->bios_machineid, sizeof(data->bios_machineid)))
  383. return -EFAULT;
  384. return 0;
  385. case I8K_FN_STATUS:
  386. val = i8k_get_fn_status();
  387. break;
  388. case I8K_POWER_STATUS:
  389. val = i8k_get_power_status();
  390. break;
  391. case I8K_GET_TEMP:
  392. val = i8k_get_temp(0);
  393. break;
  394. case I8K_GET_SPEED:
  395. if (copy_from_user(&val, argp, sizeof(int)))
  396. return -EFAULT;
  397. if (val > U8_MAX || val < 0)
  398. return -EINVAL;
  399. val = i8k_get_fan_speed(data, val);
  400. break;
  401. case I8K_GET_FAN:
  402. if (copy_from_user(&val, argp, sizeof(int)))
  403. return -EFAULT;
  404. if (val > U8_MAX || val < 0)
  405. return -EINVAL;
  406. val = i8k_get_fan_status(data, val);
  407. break;
  408. case I8K_SET_FAN:
  409. if (restricted && !capable(CAP_SYS_ADMIN))
  410. return -EPERM;
  411. if (copy_from_user(&val, argp, sizeof(int)))
  412. return -EFAULT;
  413. if (val > U8_MAX || val < 0)
  414. return -EINVAL;
  415. if (copy_from_user(&speed, argp + 1, sizeof(int)))
  416. return -EFAULT;
  417. mutex_lock(&data->i8k_mutex);
  418. err = i8k_set_fan(data, val, speed);
  419. if (err < 0)
  420. val = err;
  421. else
  422. val = i8k_get_fan_status(data, val);
  423. mutex_unlock(&data->i8k_mutex);
  424. break;
  425. default:
  426. return -ENOIOCTLCMD;
  427. }
  428. if (val < 0)
  429. return val;
  430. if (copy_to_user(argp, &val, sizeof(int)))
  431. return -EFAULT;
  432. return 0;
  433. }
  434. /*
  435. * Print the information for /proc/i8k.
  436. */
  437. static int i8k_proc_show(struct seq_file *seq, void *offset)
  438. {
  439. struct dell_smm_data *data = seq->private;
  440. int fn_key, cpu_temp, ac_power;
  441. int left_fan, right_fan, left_speed, right_speed;
  442. cpu_temp = i8k_get_temp(0); /* 11100 µs */
  443. left_fan = i8k_get_fan_status(data, I8K_FAN_LEFT); /* 580 µs */
  444. right_fan = i8k_get_fan_status(data, I8K_FAN_RIGHT); /* 580 µs */
  445. left_speed = i8k_get_fan_speed(data, I8K_FAN_LEFT); /* 580 µs */
  446. right_speed = i8k_get_fan_speed(data, I8K_FAN_RIGHT); /* 580 µs */
  447. fn_key = i8k_get_fn_status(); /* 750 µs */
  448. if (power_status)
  449. ac_power = i8k_get_power_status(); /* 14700 µs */
  450. else
  451. ac_power = -1;
  452. /*
  453. * Info:
  454. *
  455. * 1) Format version (this will change if format changes)
  456. * 2) BIOS version
  457. * 3) BIOS machine ID
  458. * 4) Cpu temperature
  459. * 5) Left fan status
  460. * 6) Right fan status
  461. * 7) Left fan speed
  462. * 8) Right fan speed
  463. * 9) AC power
  464. * 10) Fn Key status
  465. */
  466. seq_printf(seq, "%s %s %s %d %d %d %d %d %d %d\n",
  467. I8K_PROC_FMT,
  468. data->bios_version,
  469. (restricted && !capable(CAP_SYS_ADMIN)) ? "-1" : data->bios_machineid,
  470. cpu_temp,
  471. left_fan, right_fan, left_speed, right_speed,
  472. ac_power, fn_key);
  473. return 0;
  474. }
  475. static int i8k_open_fs(struct inode *inode, struct file *file)
  476. {
  477. return single_open(file, i8k_proc_show, pde_data(inode));
  478. }
  479. static const struct proc_ops i8k_proc_ops = {
  480. .proc_open = i8k_open_fs,
  481. .proc_read = seq_read,
  482. .proc_lseek = seq_lseek,
  483. .proc_release = single_release,
  484. .proc_ioctl = i8k_ioctl,
  485. };
  486. static void i8k_exit_procfs(void *param)
  487. {
  488. remove_proc_entry("i8k", NULL);
  489. }
  490. static void __init i8k_init_procfs(struct device *dev)
  491. {
  492. struct dell_smm_data *data = dev_get_drvdata(dev);
  493. /* Only register exit function if creation was successful */
  494. if (proc_create_data("i8k", 0, NULL, &i8k_proc_ops, data))
  495. devm_add_action_or_reset(dev, i8k_exit_procfs, NULL);
  496. }
  497. #else
  498. static void __init i8k_init_procfs(struct device *dev)
  499. {
  500. }
  501. #endif
  502. static int dell_smm_get_max_state(struct thermal_cooling_device *dev, unsigned long *state)
  503. {
  504. struct dell_smm_cooling_data *cdata = dev->devdata;
  505. *state = cdata->data->i8k_fan_max;
  506. return 0;
  507. }
  508. static int dell_smm_get_cur_state(struct thermal_cooling_device *dev, unsigned long *state)
  509. {
  510. struct dell_smm_cooling_data *cdata = dev->devdata;
  511. int ret;
  512. ret = i8k_get_fan_status(cdata->data, cdata->fan_num);
  513. if (ret < 0)
  514. return ret;
  515. *state = ret;
  516. return 0;
  517. }
  518. static int dell_smm_set_cur_state(struct thermal_cooling_device *dev, unsigned long state)
  519. {
  520. struct dell_smm_cooling_data *cdata = dev->devdata;
  521. struct dell_smm_data *data = cdata->data;
  522. int ret;
  523. if (state > data->i8k_fan_max)
  524. return -EINVAL;
  525. mutex_lock(&data->i8k_mutex);
  526. ret = i8k_set_fan(data, cdata->fan_num, (int)state);
  527. mutex_unlock(&data->i8k_mutex);
  528. return ret;
  529. }
  530. static const struct thermal_cooling_device_ops dell_smm_cooling_ops = {
  531. .get_max_state = dell_smm_get_max_state,
  532. .get_cur_state = dell_smm_get_cur_state,
  533. .set_cur_state = dell_smm_set_cur_state,
  534. };
  535. static umode_t dell_smm_is_visible(const void *drvdata, enum hwmon_sensor_types type, u32 attr,
  536. int channel)
  537. {
  538. const struct dell_smm_data *data = drvdata;
  539. switch (type) {
  540. case hwmon_temp:
  541. switch (attr) {
  542. case hwmon_temp_input:
  543. /* _i8k_get_temp() is fine since we do not care about the actual value */
  544. if (data->temp_type[channel] >= 0 || _i8k_get_temp(channel) >= 0)
  545. return 0444;
  546. break;
  547. case hwmon_temp_label:
  548. if (data->temp_type[channel] >= 0)
  549. return 0444;
  550. break;
  551. default:
  552. break;
  553. }
  554. break;
  555. case hwmon_fan:
  556. if (data->disallow_fan_support)
  557. break;
  558. switch (attr) {
  559. case hwmon_fan_input:
  560. if (data->fan[channel])
  561. return 0444;
  562. break;
  563. case hwmon_fan_label:
  564. if (data->fan[channel] && !data->disallow_fan_type_call)
  565. return 0444;
  566. break;
  567. case hwmon_fan_min:
  568. case hwmon_fan_max:
  569. case hwmon_fan_target:
  570. if (data->fan_nominal_speed[channel])
  571. return 0444;
  572. break;
  573. default:
  574. break;
  575. }
  576. break;
  577. case hwmon_pwm:
  578. if (data->disallow_fan_support)
  579. break;
  580. switch (attr) {
  581. case hwmon_pwm_input:
  582. if (data->fan[channel])
  583. return 0644;
  584. break;
  585. case hwmon_pwm_enable:
  586. if (data->auto_fan)
  587. /*
  588. * There is no command for retrieve the current status
  589. * from BIOS, and userspace/firmware itself can change
  590. * it.
  591. * Thus we can only provide write-only access for now.
  592. */
  593. return 0200;
  594. break;
  595. default:
  596. break;
  597. }
  598. break;
  599. default:
  600. break;
  601. }
  602. return 0;
  603. }
  604. static int dell_smm_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel,
  605. long *val)
  606. {
  607. struct dell_smm_data *data = dev_get_drvdata(dev);
  608. int mult = data->i8k_fan_mult;
  609. int ret;
  610. switch (type) {
  611. case hwmon_temp:
  612. switch (attr) {
  613. case hwmon_temp_input:
  614. ret = i8k_get_temp(channel);
  615. if (ret < 0)
  616. return ret;
  617. *val = ret * 1000;
  618. return 0;
  619. default:
  620. break;
  621. }
  622. break;
  623. case hwmon_fan:
  624. switch (attr) {
  625. case hwmon_fan_input:
  626. ret = i8k_get_fan_speed(data, channel);
  627. if (ret < 0)
  628. return ret;
  629. *val = ret;
  630. return 0;
  631. case hwmon_fan_min:
  632. *val = data->fan_nominal_speed[channel][0] * mult;
  633. return 0;
  634. case hwmon_fan_max:
  635. *val = data->fan_nominal_speed[channel][data->i8k_fan_max] * mult;
  636. return 0;
  637. case hwmon_fan_target:
  638. ret = i8k_get_fan_status(data, channel);
  639. if (ret < 0)
  640. return ret;
  641. if (ret > data->i8k_fan_max)
  642. ret = data->i8k_fan_max;
  643. *val = data->fan_nominal_speed[channel][ret] * mult;
  644. return 0;
  645. default:
  646. break;
  647. }
  648. break;
  649. case hwmon_pwm:
  650. switch (attr) {
  651. case hwmon_pwm_input:
  652. ret = i8k_get_fan_status(data, channel);
  653. if (ret < 0)
  654. return ret;
  655. *val = clamp_val(ret * data->i8k_pwm_mult, 0, 255);
  656. return 0;
  657. default:
  658. break;
  659. }
  660. break;
  661. default:
  662. break;
  663. }
  664. return -EOPNOTSUPP;
  665. }
  666. static const char *dell_smm_fan_label(struct dell_smm_data *data, int channel)
  667. {
  668. bool dock = false;
  669. int type = i8k_get_fan_type(data, channel);
  670. if (type < 0)
  671. return ERR_PTR(type);
  672. if (type & 0x10) {
  673. dock = true;
  674. type &= 0x0F;
  675. }
  676. if (type >= ARRAY_SIZE(fan_labels))
  677. type = ARRAY_SIZE(fan_labels) - 1;
  678. return dock ? docking_labels[type] : fan_labels[type];
  679. }
  680. static int dell_smm_read_string(struct device *dev, enum hwmon_sensor_types type, u32 attr,
  681. int channel, const char **str)
  682. {
  683. struct dell_smm_data *data = dev_get_drvdata(dev);
  684. switch (type) {
  685. case hwmon_temp:
  686. switch (attr) {
  687. case hwmon_temp_label:
  688. *str = temp_labels[data->temp_type[channel]];
  689. return 0;
  690. default:
  691. break;
  692. }
  693. break;
  694. case hwmon_fan:
  695. switch (attr) {
  696. case hwmon_fan_label:
  697. *str = dell_smm_fan_label(data, channel);
  698. return PTR_ERR_OR_ZERO(*str);
  699. default:
  700. break;
  701. }
  702. break;
  703. default:
  704. break;
  705. }
  706. return -EOPNOTSUPP;
  707. }
  708. static int dell_smm_write(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel,
  709. long val)
  710. {
  711. struct dell_smm_data *data = dev_get_drvdata(dev);
  712. unsigned long pwm;
  713. bool enable;
  714. int err;
  715. switch (type) {
  716. case hwmon_pwm:
  717. switch (attr) {
  718. case hwmon_pwm_input:
  719. pwm = clamp_val(DIV_ROUND_CLOSEST(val, data->i8k_pwm_mult), 0,
  720. data->i8k_fan_max);
  721. mutex_lock(&data->i8k_mutex);
  722. err = i8k_set_fan(data, channel, pwm);
  723. mutex_unlock(&data->i8k_mutex);
  724. if (err < 0)
  725. return err;
  726. return 0;
  727. case hwmon_pwm_enable:
  728. if (!val)
  729. return -EINVAL;
  730. if (val == 1)
  731. enable = false;
  732. else
  733. enable = true;
  734. mutex_lock(&data->i8k_mutex);
  735. err = i8k_enable_fan_auto_mode(data, enable);
  736. mutex_unlock(&data->i8k_mutex);
  737. if (err < 0)
  738. return err;
  739. return 0;
  740. default:
  741. break;
  742. }
  743. break;
  744. default:
  745. break;
  746. }
  747. return -EOPNOTSUPP;
  748. }
  749. static const struct hwmon_ops dell_smm_ops = {
  750. .is_visible = dell_smm_is_visible,
  751. .read = dell_smm_read,
  752. .read_string = dell_smm_read_string,
  753. .write = dell_smm_write,
  754. };
  755. static const struct hwmon_channel_info *dell_smm_info[] = {
  756. HWMON_CHANNEL_INFO(chip, HWMON_C_REGISTER_TZ),
  757. HWMON_CHANNEL_INFO(temp,
  758. HWMON_T_INPUT | HWMON_T_LABEL,
  759. HWMON_T_INPUT | HWMON_T_LABEL,
  760. HWMON_T_INPUT | HWMON_T_LABEL,
  761. HWMON_T_INPUT | HWMON_T_LABEL,
  762. HWMON_T_INPUT | HWMON_T_LABEL,
  763. HWMON_T_INPUT | HWMON_T_LABEL,
  764. HWMON_T_INPUT | HWMON_T_LABEL,
  765. HWMON_T_INPUT | HWMON_T_LABEL,
  766. HWMON_T_INPUT | HWMON_T_LABEL,
  767. HWMON_T_INPUT | HWMON_T_LABEL
  768. ),
  769. HWMON_CHANNEL_INFO(fan,
  770. HWMON_F_INPUT | HWMON_F_LABEL | HWMON_F_MIN | HWMON_F_MAX |
  771. HWMON_F_TARGET,
  772. HWMON_F_INPUT | HWMON_F_LABEL | HWMON_F_MIN | HWMON_F_MAX |
  773. HWMON_F_TARGET,
  774. HWMON_F_INPUT | HWMON_F_LABEL | HWMON_F_MIN | HWMON_F_MAX |
  775. HWMON_F_TARGET
  776. ),
  777. HWMON_CHANNEL_INFO(pwm,
  778. HWMON_PWM_INPUT | HWMON_PWM_ENABLE,
  779. HWMON_PWM_INPUT,
  780. HWMON_PWM_INPUT
  781. ),
  782. NULL
  783. };
  784. static const struct hwmon_chip_info dell_smm_chip_info = {
  785. .ops = &dell_smm_ops,
  786. .info = dell_smm_info,
  787. };
  788. static int __init dell_smm_init_cdev(struct device *dev, u8 fan_num)
  789. {
  790. struct dell_smm_data *data = dev_get_drvdata(dev);
  791. struct thermal_cooling_device *cdev;
  792. struct dell_smm_cooling_data *cdata;
  793. int ret = 0;
  794. char *name;
  795. name = kasprintf(GFP_KERNEL, "dell-smm-fan%u", fan_num + 1);
  796. if (!name)
  797. return -ENOMEM;
  798. cdata = devm_kmalloc(dev, sizeof(*cdata), GFP_KERNEL);
  799. if (cdata) {
  800. cdata->fan_num = fan_num;
  801. cdata->data = data;
  802. cdev = devm_thermal_of_cooling_device_register(dev, NULL, name, cdata,
  803. &dell_smm_cooling_ops);
  804. if (IS_ERR(cdev)) {
  805. devm_kfree(dev, cdata);
  806. ret = PTR_ERR(cdev);
  807. }
  808. } else {
  809. ret = -ENOMEM;
  810. }
  811. kfree(name);
  812. return ret;
  813. }
  814. static int __init dell_smm_init_hwmon(struct device *dev)
  815. {
  816. struct dell_smm_data *data = dev_get_drvdata(dev);
  817. struct device *dell_smm_hwmon_dev;
  818. int state, err;
  819. u8 i;
  820. for (i = 0; i < DELL_SMM_NO_TEMP; i++) {
  821. data->temp_type[i] = i8k_get_temp_type(i);
  822. if (data->temp_type[i] < 0)
  823. continue;
  824. if (data->temp_type[i] >= ARRAY_SIZE(temp_labels))
  825. data->temp_type[i] = ARRAY_SIZE(temp_labels) - 1;
  826. }
  827. for (i = 0; i < DELL_SMM_NO_FANS; i++) {
  828. data->fan_type[i] = INT_MIN;
  829. err = i8k_get_fan_status(data, i);
  830. if (err < 0)
  831. err = i8k_get_fan_type(data, i);
  832. if (err < 0)
  833. continue;
  834. data->fan[i] = true;
  835. /* the cooling device is not critical, ignore failures */
  836. if (IS_REACHABLE(CONFIG_THERMAL)) {
  837. err = dell_smm_init_cdev(dev, i);
  838. if (err < 0)
  839. dev_warn(dev, "Failed to register cooling device for fan %u\n",
  840. i + 1);
  841. }
  842. data->fan_nominal_speed[i] = devm_kmalloc_array(dev, data->i8k_fan_max + 1,
  843. sizeof(*data->fan_nominal_speed[i]),
  844. GFP_KERNEL);
  845. if (!data->fan_nominal_speed[i])
  846. continue;
  847. for (state = 0; state <= data->i8k_fan_max; state++) {
  848. err = i8k_get_fan_nominal_speed(data, i, state);
  849. if (err < 0) {
  850. /* Mark nominal speed table as invalid in case of error */
  851. devm_kfree(dev, data->fan_nominal_speed[i]);
  852. data->fan_nominal_speed[i] = NULL;
  853. break;
  854. }
  855. data->fan_nominal_speed[i][state] = err;
  856. /*
  857. * Autodetect fan multiplier based on nominal rpm if multiplier
  858. * was not specified as module param or in DMI. If fan reports
  859. * rpm value too high then set multiplier to 1.
  860. */
  861. if (!fan_mult && err > I8K_FAN_RPM_THRESHOLD)
  862. data->i8k_fan_mult = 1;
  863. }
  864. }
  865. dell_smm_hwmon_dev = devm_hwmon_device_register_with_info(dev, "dell_smm", data,
  866. &dell_smm_chip_info, NULL);
  867. return PTR_ERR_OR_ZERO(dell_smm_hwmon_dev);
  868. }
  869. struct i8k_config_data {
  870. uint fan_mult;
  871. uint fan_max;
  872. };
  873. enum i8k_configs {
  874. DELL_LATITUDE_D520,
  875. DELL_PRECISION_490,
  876. DELL_STUDIO,
  877. DELL_XPS,
  878. };
  879. /*
  880. * Only use for machines which need some special configuration
  881. * in order to work correctly (e.g. if autoconfig fails on this machines).
  882. */
  883. static const struct i8k_config_data i8k_config_data[] __initconst = {
  884. [DELL_LATITUDE_D520] = {
  885. .fan_mult = 1,
  886. .fan_max = I8K_FAN_TURBO,
  887. },
  888. [DELL_PRECISION_490] = {
  889. .fan_mult = 1,
  890. .fan_max = I8K_FAN_TURBO,
  891. },
  892. [DELL_STUDIO] = {
  893. .fan_mult = 1,
  894. .fan_max = I8K_FAN_HIGH,
  895. },
  896. [DELL_XPS] = {
  897. .fan_mult = 1,
  898. .fan_max = I8K_FAN_HIGH,
  899. },
  900. };
  901. static const struct dmi_system_id i8k_dmi_table[] __initconst = {
  902. {
  903. .ident = "Dell G5 5590",
  904. .matches = {
  905. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  906. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "G5 5590"),
  907. },
  908. },
  909. {
  910. .ident = "Dell Inspiron",
  911. .matches = {
  912. DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"),
  913. DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"),
  914. },
  915. },
  916. {
  917. .ident = "Dell Latitude",
  918. .matches = {
  919. DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer"),
  920. DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"),
  921. },
  922. },
  923. {
  924. .ident = "Dell Inspiron 2",
  925. .matches = {
  926. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  927. DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron"),
  928. },
  929. },
  930. {
  931. .ident = "Dell Latitude D520",
  932. .matches = {
  933. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  934. DMI_MATCH(DMI_PRODUCT_NAME, "Latitude D520"),
  935. },
  936. .driver_data = (void *)&i8k_config_data[DELL_LATITUDE_D520],
  937. },
  938. {
  939. .ident = "Dell Latitude 2",
  940. .matches = {
  941. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  942. DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"),
  943. },
  944. },
  945. { /* UK Inspiron 6400 */
  946. .ident = "Dell Inspiron 3",
  947. .matches = {
  948. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  949. DMI_MATCH(DMI_PRODUCT_NAME, "MM061"),
  950. },
  951. },
  952. {
  953. .ident = "Dell Inspiron 3",
  954. .matches = {
  955. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  956. DMI_MATCH(DMI_PRODUCT_NAME, "MP061"),
  957. },
  958. },
  959. {
  960. .ident = "Dell Precision 490",
  961. .matches = {
  962. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  963. DMI_MATCH(DMI_PRODUCT_NAME,
  964. "Precision WorkStation 490"),
  965. },
  966. .driver_data = (void *)&i8k_config_data[DELL_PRECISION_490],
  967. },
  968. {
  969. .ident = "Dell Precision",
  970. .matches = {
  971. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  972. DMI_MATCH(DMI_PRODUCT_NAME, "Precision"),
  973. },
  974. },
  975. {
  976. .ident = "Dell Vostro",
  977. .matches = {
  978. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  979. DMI_MATCH(DMI_PRODUCT_NAME, "Vostro"),
  980. },
  981. },
  982. {
  983. .ident = "Dell Studio",
  984. .matches = {
  985. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  986. DMI_MATCH(DMI_PRODUCT_NAME, "Studio"),
  987. },
  988. .driver_data = (void *)&i8k_config_data[DELL_STUDIO],
  989. },
  990. {
  991. .ident = "Dell XPS M140",
  992. .matches = {
  993. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  994. DMI_MATCH(DMI_PRODUCT_NAME, "MXC051"),
  995. },
  996. .driver_data = (void *)&i8k_config_data[DELL_XPS],
  997. },
  998. {
  999. .ident = "Dell XPS",
  1000. .matches = {
  1001. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  1002. DMI_MATCH(DMI_PRODUCT_NAME, "XPS"),
  1003. },
  1004. },
  1005. { }
  1006. };
  1007. MODULE_DEVICE_TABLE(dmi, i8k_dmi_table);
  1008. /*
  1009. * On some machines once I8K_SMM_GET_FAN_TYPE is issued then CPU fan speed
  1010. * randomly going up and down due to bug in Dell SMM or BIOS. Here is blacklist
  1011. * of affected Dell machines for which we disallow I8K_SMM_GET_FAN_TYPE call.
  1012. * See bug: https://bugzilla.kernel.org/show_bug.cgi?id=100121
  1013. */
  1014. static const struct dmi_system_id i8k_blacklist_fan_type_dmi_table[] __initconst = {
  1015. {
  1016. .ident = "Dell Studio XPS 8000",
  1017. .matches = {
  1018. DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  1019. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Studio XPS 8000"),
  1020. },
  1021. },
  1022. {
  1023. .ident = "Dell Studio XPS 8100",
  1024. .matches = {
  1025. DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  1026. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Studio XPS 8100"),
  1027. },
  1028. },
  1029. {
  1030. .ident = "Dell Inspiron 580",
  1031. .matches = {
  1032. DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  1033. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Inspiron 580 "),
  1034. },
  1035. },
  1036. {
  1037. .ident = "Dell Inspiron 3505",
  1038. .matches = {
  1039. DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  1040. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Inspiron 3505"),
  1041. },
  1042. },
  1043. { }
  1044. };
  1045. /*
  1046. * On some machines all fan related SMM functions implemented by Dell BIOS
  1047. * firmware freeze kernel for about 500ms. Until Dell fixes these problems fan
  1048. * support for affected blacklisted Dell machines stay disabled.
  1049. * See bug: https://bugzilla.kernel.org/show_bug.cgi?id=195751
  1050. */
  1051. static const struct dmi_system_id i8k_blacklist_fan_support_dmi_table[] __initconst = {
  1052. {
  1053. .ident = "Dell Inspiron 7720",
  1054. .matches = {
  1055. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  1056. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Inspiron 7720"),
  1057. },
  1058. },
  1059. {
  1060. .ident = "Dell Vostro 3360",
  1061. .matches = {
  1062. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  1063. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Vostro 3360"),
  1064. },
  1065. },
  1066. {
  1067. .ident = "Dell XPS13 9333",
  1068. .matches = {
  1069. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  1070. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "XPS13 9333"),
  1071. },
  1072. },
  1073. {
  1074. .ident = "Dell XPS 15 L502X",
  1075. .matches = {
  1076. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  1077. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Dell System XPS L502X"),
  1078. },
  1079. },
  1080. { }
  1081. };
  1082. struct i8k_fan_control_data {
  1083. unsigned int manual_fan;
  1084. unsigned int auto_fan;
  1085. };
  1086. enum i8k_fan_controls {
  1087. I8K_FAN_34A3_35A3,
  1088. };
  1089. static const struct i8k_fan_control_data i8k_fan_control_data[] __initconst = {
  1090. [I8K_FAN_34A3_35A3] = {
  1091. .manual_fan = 0x34a3,
  1092. .auto_fan = 0x35a3,
  1093. },
  1094. };
  1095. static const struct dmi_system_id i8k_whitelist_fan_control[] __initconst = {
  1096. {
  1097. .ident = "Dell Latitude 5480",
  1098. .matches = {
  1099. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  1100. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Latitude 5480"),
  1101. },
  1102. .driver_data = (void *)&i8k_fan_control_data[I8K_FAN_34A3_35A3],
  1103. },
  1104. {
  1105. .ident = "Dell Latitude E6440",
  1106. .matches = {
  1107. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  1108. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Latitude E6440"),
  1109. },
  1110. .driver_data = (void *)&i8k_fan_control_data[I8K_FAN_34A3_35A3],
  1111. },
  1112. {
  1113. .ident = "Dell Latitude E7440",
  1114. .matches = {
  1115. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  1116. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Latitude E7440"),
  1117. },
  1118. .driver_data = (void *)&i8k_fan_control_data[I8K_FAN_34A3_35A3],
  1119. },
  1120. {
  1121. .ident = "Dell Precision 5530",
  1122. .matches = {
  1123. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  1124. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Precision 5530"),
  1125. },
  1126. .driver_data = (void *)&i8k_fan_control_data[I8K_FAN_34A3_35A3],
  1127. },
  1128. {
  1129. .ident = "Dell Precision 7510",
  1130. .matches = {
  1131. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  1132. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Precision 7510"),
  1133. },
  1134. .driver_data = (void *)&i8k_fan_control_data[I8K_FAN_34A3_35A3],
  1135. },
  1136. {
  1137. .ident = "Dell XPS 13 7390",
  1138. .matches = {
  1139. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  1140. DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "XPS 13 7390"),
  1141. },
  1142. .driver_data = (void *)&i8k_fan_control_data[I8K_FAN_34A3_35A3],
  1143. },
  1144. { }
  1145. };
  1146. static int __init dell_smm_probe(struct platform_device *pdev)
  1147. {
  1148. struct dell_smm_data *data;
  1149. const struct dmi_system_id *id, *fan_control;
  1150. int ret;
  1151. data = devm_kzalloc(&pdev->dev, sizeof(struct dell_smm_data), GFP_KERNEL);
  1152. if (!data)
  1153. return -ENOMEM;
  1154. mutex_init(&data->i8k_mutex);
  1155. platform_set_drvdata(pdev, data);
  1156. if (dmi_check_system(i8k_blacklist_fan_support_dmi_table)) {
  1157. if (!force) {
  1158. dev_notice(&pdev->dev, "Disabling fan support due to BIOS bugs\n");
  1159. data->disallow_fan_support = true;
  1160. } else {
  1161. dev_warn(&pdev->dev, "Enabling fan support despite BIOS bugs\n");
  1162. }
  1163. }
  1164. if (dmi_check_system(i8k_blacklist_fan_type_dmi_table)) {
  1165. if (!force) {
  1166. dev_notice(&pdev->dev, "Disabling fan type call due to BIOS bugs\n");
  1167. data->disallow_fan_type_call = true;
  1168. } else {
  1169. dev_warn(&pdev->dev, "Enabling fan type call despite BIOS bugs\n");
  1170. }
  1171. }
  1172. strscpy(data->bios_version, i8k_get_dmi_data(DMI_BIOS_VERSION),
  1173. sizeof(data->bios_version));
  1174. strscpy(data->bios_machineid, i8k_get_dmi_data(DMI_PRODUCT_SERIAL),
  1175. sizeof(data->bios_machineid));
  1176. /*
  1177. * Set fan multiplier and maximal fan speed from dmi config
  1178. * Values specified in module parameters override values from dmi
  1179. */
  1180. id = dmi_first_match(i8k_dmi_table);
  1181. if (id && id->driver_data) {
  1182. const struct i8k_config_data *conf = id->driver_data;
  1183. if (!fan_mult && conf->fan_mult)
  1184. fan_mult = conf->fan_mult;
  1185. if (!fan_max && conf->fan_max)
  1186. fan_max = conf->fan_max;
  1187. }
  1188. /* All options must not be 0 */
  1189. data->i8k_fan_mult = fan_mult ? : I8K_FAN_MULT;
  1190. data->i8k_fan_max = fan_max ? : I8K_FAN_HIGH;
  1191. data->i8k_pwm_mult = DIV_ROUND_UP(255, data->i8k_fan_max);
  1192. fan_control = dmi_first_match(i8k_whitelist_fan_control);
  1193. if (fan_control && fan_control->driver_data) {
  1194. const struct i8k_fan_control_data *control = fan_control->driver_data;
  1195. data->manual_fan = control->manual_fan;
  1196. data->auto_fan = control->auto_fan;
  1197. dev_info(&pdev->dev, "enabling support for setting automatic/manual fan control\n");
  1198. }
  1199. ret = dell_smm_init_hwmon(&pdev->dev);
  1200. if (ret)
  1201. return ret;
  1202. i8k_init_procfs(&pdev->dev);
  1203. return 0;
  1204. }
  1205. static struct platform_driver dell_smm_driver = {
  1206. .driver = {
  1207. .name = KBUILD_MODNAME,
  1208. },
  1209. };
  1210. static struct platform_device *dell_smm_device;
  1211. /*
  1212. * Probe for the presence of a supported laptop.
  1213. */
  1214. static int __init i8k_init(void)
  1215. {
  1216. /*
  1217. * Get DMI information
  1218. */
  1219. if (!dmi_check_system(i8k_dmi_table)) {
  1220. if (!ignore_dmi && !force)
  1221. return -ENODEV;
  1222. pr_info("not running on a supported Dell system.\n");
  1223. pr_info("vendor=%s, model=%s, version=%s\n",
  1224. i8k_get_dmi_data(DMI_SYS_VENDOR),
  1225. i8k_get_dmi_data(DMI_PRODUCT_NAME),
  1226. i8k_get_dmi_data(DMI_BIOS_VERSION));
  1227. }
  1228. /*
  1229. * Get SMM Dell signature
  1230. */
  1231. if (i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG1) &&
  1232. i8k_get_dell_signature(I8K_SMM_GET_DELL_SIG2)) {
  1233. pr_err("unable to get SMM Dell signature\n");
  1234. if (!force)
  1235. return -ENODEV;
  1236. }
  1237. dell_smm_device = platform_create_bundle(&dell_smm_driver, dell_smm_probe, NULL, 0, NULL,
  1238. 0);
  1239. return PTR_ERR_OR_ZERO(dell_smm_device);
  1240. }
  1241. static void __exit i8k_exit(void)
  1242. {
  1243. platform_device_unregister(dell_smm_device);
  1244. platform_driver_unregister(&dell_smm_driver);
  1245. }
  1246. module_init(i8k_init);
  1247. module_exit(i8k_exit);