f71808e_wdt.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /***************************************************************************
  3. * Copyright (C) 2006 by Hans Edgington <[email protected]> *
  4. * Copyright (C) 2007-2009 Hans de Goede <[email protected]> *
  5. * Copyright (C) 2010 Giel van Schijndel <[email protected]> *
  6. * *
  7. ***************************************************************************/
  8. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  9. #include <linux/err.h>
  10. #include <linux/init.h>
  11. #include <linux/io.h>
  12. #include <linux/ioport.h>
  13. #include <linux/module.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/watchdog.h>
  16. #define DRVNAME "f71808e_wdt"
  17. #define SIO_F71808FG_LD_WDT 0x07 /* Watchdog timer logical device */
  18. #define SIO_UNLOCK_KEY 0x87 /* Key to enable Super-I/O */
  19. #define SIO_LOCK_KEY 0xAA /* Key to disable Super-I/O */
  20. #define SIO_REG_LDSEL 0x07 /* Logical device select */
  21. #define SIO_REG_DEVID 0x20 /* Device ID (2 bytes) */
  22. #define SIO_REG_DEVREV 0x22 /* Device revision */
  23. #define SIO_REG_MANID 0x23 /* Fintek ID (2 bytes) */
  24. #define SIO_REG_CLOCK_SEL 0x26 /* Clock select */
  25. #define SIO_REG_ROM_ADDR_SEL 0x27 /* ROM address select */
  26. #define SIO_F81866_REG_PORT_SEL 0x27 /* F81866 Multi-Function Register */
  27. #define SIO_REG_TSI_LEVEL_SEL 0x28 /* TSI Level select */
  28. #define SIO_REG_MFUNCT1 0x29 /* Multi function select 1 */
  29. #define SIO_REG_MFUNCT2 0x2a /* Multi function select 2 */
  30. #define SIO_REG_MFUNCT3 0x2b /* Multi function select 3 */
  31. #define SIO_F81866_REG_GPIO1 0x2c /* F81866 GPIO1 Enable Register */
  32. #define SIO_REG_ENABLE 0x30 /* Logical device enable */
  33. #define SIO_REG_ADDR 0x60 /* Logical device address (2 bytes) */
  34. #define SIO_FINTEK_ID 0x1934 /* Manufacturers ID */
  35. #define SIO_F71808_ID 0x0901 /* Chipset ID */
  36. #define SIO_F71858_ID 0x0507 /* Chipset ID */
  37. #define SIO_F71862_ID 0x0601 /* Chipset ID */
  38. #define SIO_F71868_ID 0x1106 /* Chipset ID */
  39. #define SIO_F71869_ID 0x0814 /* Chipset ID */
  40. #define SIO_F71869A_ID 0x1007 /* Chipset ID */
  41. #define SIO_F71882_ID 0x0541 /* Chipset ID */
  42. #define SIO_F71889_ID 0x0723 /* Chipset ID */
  43. #define SIO_F81803_ID 0x1210 /* Chipset ID */
  44. #define SIO_F81865_ID 0x0704 /* Chipset ID */
  45. #define SIO_F81866_ID 0x1010 /* Chipset ID */
  46. #define SIO_F81966_ID 0x1502 /* F81804 chipset ID, same for f81966 */
  47. #define F71808FG_REG_WDO_CONF 0xf0
  48. #define F71808FG_REG_WDT_CONF 0xf5
  49. #define F71808FG_REG_WD_TIME 0xf6
  50. #define F71808FG_FLAG_WDOUT_EN 7
  51. #define F71808FG_FLAG_WDTMOUT_STS 6
  52. #define F71808FG_FLAG_WD_EN 5
  53. #define F71808FG_FLAG_WD_PULSE 4
  54. #define F71808FG_FLAG_WD_UNIT 3
  55. #define F81865_REG_WDO_CONF 0xfa
  56. #define F81865_FLAG_WDOUT_EN 0
  57. /* Default values */
  58. #define WATCHDOG_TIMEOUT 60 /* 1 minute default timeout */
  59. #define WATCHDOG_MAX_TIMEOUT (60 * 255)
  60. #define WATCHDOG_PULSE_WIDTH 125 /* 125 ms, default pulse width for
  61. watchdog signal */
  62. #define WATCHDOG_F71862FG_PIN 63 /* default watchdog reset output
  63. pin number 63 */
  64. static unsigned short force_id;
  65. module_param(force_id, ushort, 0);
  66. MODULE_PARM_DESC(force_id, "Override the detected device ID");
  67. static int timeout = WATCHDOG_TIMEOUT; /* default timeout in seconds */
  68. module_param(timeout, int, 0);
  69. MODULE_PARM_DESC(timeout,
  70. "Watchdog timeout in seconds. 1<= timeout <="
  71. __MODULE_STRING(WATCHDOG_MAX_TIMEOUT) " (default="
  72. __MODULE_STRING(WATCHDOG_TIMEOUT) ")");
  73. static unsigned int pulse_width = WATCHDOG_PULSE_WIDTH;
  74. module_param(pulse_width, uint, 0);
  75. MODULE_PARM_DESC(pulse_width,
  76. "Watchdog signal pulse width. 0(=level), 1, 25, 30, 125, 150, 5000 or 6000 ms"
  77. " (default=" __MODULE_STRING(WATCHDOG_PULSE_WIDTH) ")");
  78. static unsigned int f71862fg_pin = WATCHDOG_F71862FG_PIN;
  79. module_param(f71862fg_pin, uint, 0);
  80. MODULE_PARM_DESC(f71862fg_pin,
  81. "Watchdog f71862fg reset output pin configuration. Choose pin 56 or 63"
  82. " (default=" __MODULE_STRING(WATCHDOG_F71862FG_PIN)")");
  83. static bool nowayout = WATCHDOG_NOWAYOUT;
  84. module_param(nowayout, bool, 0444);
  85. MODULE_PARM_DESC(nowayout, "Disable watchdog shutdown on close");
  86. static unsigned int start_withtimeout;
  87. module_param(start_withtimeout, uint, 0);
  88. MODULE_PARM_DESC(start_withtimeout, "Start watchdog timer on module load with"
  89. " given initial timeout. Zero (default) disables this feature.");
  90. enum chips { f71808fg, f71858fg, f71862fg, f71868, f71869, f71882fg, f71889fg,
  91. f81803, f81865, f81866, f81966};
  92. static const char * const fintek_wdt_names[] = {
  93. "f71808fg",
  94. "f71858fg",
  95. "f71862fg",
  96. "f71868",
  97. "f71869",
  98. "f71882fg",
  99. "f71889fg",
  100. "f81803",
  101. "f81865",
  102. "f81866",
  103. "f81966"
  104. };
  105. /* Super-I/O Function prototypes */
  106. static inline int superio_inb(int base, int reg);
  107. static inline int superio_inw(int base, int reg);
  108. static inline void superio_outb(int base, int reg, u8 val);
  109. static inline void superio_set_bit(int base, int reg, int bit);
  110. static inline void superio_clear_bit(int base, int reg, int bit);
  111. static inline int superio_enter(int base);
  112. static inline void superio_select(int base, int ld);
  113. static inline void superio_exit(int base);
  114. struct fintek_wdt {
  115. struct watchdog_device wdd;
  116. unsigned short sioaddr;
  117. enum chips type;
  118. struct watchdog_info ident;
  119. u8 timer_val; /* content for the wd_time register */
  120. char minutes_mode;
  121. u8 pulse_val; /* pulse width flag */
  122. char pulse_mode; /* enable pulse output mode? */
  123. };
  124. struct fintek_wdt_pdata {
  125. enum chips type;
  126. };
  127. /* Super I/O functions */
  128. static inline int superio_inb(int base, int reg)
  129. {
  130. outb(reg, base);
  131. return inb(base + 1);
  132. }
  133. static int superio_inw(int base, int reg)
  134. {
  135. int val;
  136. val = superio_inb(base, reg) << 8;
  137. val |= superio_inb(base, reg + 1);
  138. return val;
  139. }
  140. static inline void superio_outb(int base, int reg, u8 val)
  141. {
  142. outb(reg, base);
  143. outb(val, base + 1);
  144. }
  145. static inline void superio_set_bit(int base, int reg, int bit)
  146. {
  147. unsigned long val = superio_inb(base, reg);
  148. __set_bit(bit, &val);
  149. superio_outb(base, reg, val);
  150. }
  151. static inline void superio_clear_bit(int base, int reg, int bit)
  152. {
  153. unsigned long val = superio_inb(base, reg);
  154. __clear_bit(bit, &val);
  155. superio_outb(base, reg, val);
  156. }
  157. static inline int superio_enter(int base)
  158. {
  159. /* Don't step on other drivers' I/O space by accident */
  160. if (!request_muxed_region(base, 2, DRVNAME)) {
  161. pr_err("I/O address 0x%04x already in use\n", (int)base);
  162. return -EBUSY;
  163. }
  164. /* according to the datasheet the key must be sent twice! */
  165. outb(SIO_UNLOCK_KEY, base);
  166. outb(SIO_UNLOCK_KEY, base);
  167. return 0;
  168. }
  169. static inline void superio_select(int base, int ld)
  170. {
  171. outb(SIO_REG_LDSEL, base);
  172. outb(ld, base + 1);
  173. }
  174. static inline void superio_exit(int base)
  175. {
  176. outb(SIO_LOCK_KEY, base);
  177. release_region(base, 2);
  178. }
  179. static int fintek_wdt_set_timeout(struct watchdog_device *wdd, unsigned int timeout)
  180. {
  181. struct fintek_wdt *wd = watchdog_get_drvdata(wdd);
  182. if (timeout > 0xff) {
  183. wd->timer_val = DIV_ROUND_UP(timeout, 60);
  184. wd->minutes_mode = true;
  185. timeout = wd->timer_val * 60;
  186. } else {
  187. wd->timer_val = timeout;
  188. wd->minutes_mode = false;
  189. }
  190. wdd->timeout = timeout;
  191. return 0;
  192. }
  193. static int fintek_wdt_set_pulse_width(struct fintek_wdt *wd, unsigned int pw)
  194. {
  195. unsigned int t1 = 25, t2 = 125, t3 = 5000;
  196. if (wd->type == f71868) {
  197. t1 = 30;
  198. t2 = 150;
  199. t3 = 6000;
  200. }
  201. if (pw <= 1) {
  202. wd->pulse_val = 0;
  203. } else if (pw <= t1) {
  204. wd->pulse_val = 1;
  205. } else if (pw <= t2) {
  206. wd->pulse_val = 2;
  207. } else if (pw <= t3) {
  208. wd->pulse_val = 3;
  209. } else {
  210. pr_err("pulse width out of range\n");
  211. return -EINVAL;
  212. }
  213. wd->pulse_mode = pw;
  214. return 0;
  215. }
  216. static int fintek_wdt_keepalive(struct watchdog_device *wdd)
  217. {
  218. struct fintek_wdt *wd = watchdog_get_drvdata(wdd);
  219. int err;
  220. err = superio_enter(wd->sioaddr);
  221. if (err)
  222. return err;
  223. superio_select(wd->sioaddr, SIO_F71808FG_LD_WDT);
  224. if (wd->minutes_mode)
  225. /* select minutes for timer units */
  226. superio_set_bit(wd->sioaddr, F71808FG_REG_WDT_CONF,
  227. F71808FG_FLAG_WD_UNIT);
  228. else
  229. /* select seconds for timer units */
  230. superio_clear_bit(wd->sioaddr, F71808FG_REG_WDT_CONF,
  231. F71808FG_FLAG_WD_UNIT);
  232. /* Set timer value */
  233. superio_outb(wd->sioaddr, F71808FG_REG_WD_TIME,
  234. wd->timer_val);
  235. superio_exit(wd->sioaddr);
  236. return 0;
  237. }
  238. static int fintek_wdt_start(struct watchdog_device *wdd)
  239. {
  240. struct fintek_wdt *wd = watchdog_get_drvdata(wdd);
  241. int err;
  242. u8 tmp;
  243. /* Make sure we don't die as soon as the watchdog is enabled below */
  244. err = fintek_wdt_keepalive(wdd);
  245. if (err)
  246. return err;
  247. err = superio_enter(wd->sioaddr);
  248. if (err)
  249. return err;
  250. superio_select(wd->sioaddr, SIO_F71808FG_LD_WDT);
  251. /* Watchdog pin configuration */
  252. switch (wd->type) {
  253. case f71808fg:
  254. /* Set pin 21 to GPIO23/WDTRST#, then to WDTRST# */
  255. superio_clear_bit(wd->sioaddr, SIO_REG_MFUNCT2, 3);
  256. superio_clear_bit(wd->sioaddr, SIO_REG_MFUNCT3, 3);
  257. break;
  258. case f71862fg:
  259. if (f71862fg_pin == 63) {
  260. /* SPI must be disabled first to use this pin! */
  261. superio_clear_bit(wd->sioaddr, SIO_REG_ROM_ADDR_SEL, 6);
  262. superio_set_bit(wd->sioaddr, SIO_REG_MFUNCT3, 4);
  263. } else if (f71862fg_pin == 56) {
  264. superio_set_bit(wd->sioaddr, SIO_REG_MFUNCT1, 1);
  265. }
  266. break;
  267. case f71868:
  268. case f71869:
  269. /* GPIO14 --> WDTRST# */
  270. superio_clear_bit(wd->sioaddr, SIO_REG_MFUNCT1, 4);
  271. break;
  272. case f71882fg:
  273. /* Set pin 56 to WDTRST# */
  274. superio_set_bit(wd->sioaddr, SIO_REG_MFUNCT1, 1);
  275. break;
  276. case f71889fg:
  277. /* set pin 40 to WDTRST# */
  278. superio_outb(wd->sioaddr, SIO_REG_MFUNCT3,
  279. superio_inb(wd->sioaddr, SIO_REG_MFUNCT3) & 0xcf);
  280. break;
  281. case f81803:
  282. /* Enable TSI Level register bank */
  283. superio_clear_bit(wd->sioaddr, SIO_REG_CLOCK_SEL, 3);
  284. /* Set pin 27 to WDTRST# */
  285. superio_outb(wd->sioaddr, SIO_REG_TSI_LEVEL_SEL, 0x5f &
  286. superio_inb(wd->sioaddr, SIO_REG_TSI_LEVEL_SEL));
  287. break;
  288. case f81865:
  289. /* Set pin 70 to WDTRST# */
  290. superio_clear_bit(wd->sioaddr, SIO_REG_MFUNCT3, 5);
  291. break;
  292. case f81866:
  293. case f81966:
  294. /*
  295. * GPIO1 Control Register when 27h BIT3:2 = 01 & BIT0 = 0.
  296. * The PIN 70(GPIO15/WDTRST) is controlled by 2Ch:
  297. * BIT5: 0 -> WDTRST#
  298. * 1 -> GPIO15
  299. */
  300. tmp = superio_inb(wd->sioaddr, SIO_F81866_REG_PORT_SEL);
  301. tmp &= ~(BIT(3) | BIT(0));
  302. tmp |= BIT(2);
  303. superio_outb(wd->sioaddr, SIO_F81866_REG_PORT_SEL, tmp);
  304. superio_clear_bit(wd->sioaddr, SIO_F81866_REG_GPIO1, 5);
  305. break;
  306. default:
  307. /*
  308. * 'default' label to shut up the compiler and catch
  309. * programmer errors
  310. */
  311. err = -ENODEV;
  312. goto exit_superio;
  313. }
  314. superio_select(wd->sioaddr, SIO_F71808FG_LD_WDT);
  315. superio_set_bit(wd->sioaddr, SIO_REG_ENABLE, 0);
  316. if (wd->type == f81865 || wd->type == f81866 || wd->type == f81966)
  317. superio_set_bit(wd->sioaddr, F81865_REG_WDO_CONF,
  318. F81865_FLAG_WDOUT_EN);
  319. else
  320. superio_set_bit(wd->sioaddr, F71808FG_REG_WDO_CONF,
  321. F71808FG_FLAG_WDOUT_EN);
  322. superio_set_bit(wd->sioaddr, F71808FG_REG_WDT_CONF,
  323. F71808FG_FLAG_WD_EN);
  324. if (wd->pulse_mode) {
  325. /* Select "pulse" output mode with given duration */
  326. u8 wdt_conf = superio_inb(wd->sioaddr,
  327. F71808FG_REG_WDT_CONF);
  328. /* Set WD_PSWIDTH bits (1:0) */
  329. wdt_conf = (wdt_conf & 0xfc) | (wd->pulse_val & 0x03);
  330. /* Set WD_PULSE to "pulse" mode */
  331. wdt_conf |= BIT(F71808FG_FLAG_WD_PULSE);
  332. superio_outb(wd->sioaddr, F71808FG_REG_WDT_CONF,
  333. wdt_conf);
  334. } else {
  335. /* Select "level" output mode */
  336. superio_clear_bit(wd->sioaddr, F71808FG_REG_WDT_CONF,
  337. F71808FG_FLAG_WD_PULSE);
  338. }
  339. exit_superio:
  340. superio_exit(wd->sioaddr);
  341. return err;
  342. }
  343. static int fintek_wdt_stop(struct watchdog_device *wdd)
  344. {
  345. struct fintek_wdt *wd = watchdog_get_drvdata(wdd);
  346. int err;
  347. err = superio_enter(wd->sioaddr);
  348. if (err)
  349. return err;
  350. superio_select(wd->sioaddr, SIO_F71808FG_LD_WDT);
  351. superio_clear_bit(wd->sioaddr, F71808FG_REG_WDT_CONF,
  352. F71808FG_FLAG_WD_EN);
  353. superio_exit(wd->sioaddr);
  354. return 0;
  355. }
  356. static bool fintek_wdt_is_running(struct fintek_wdt *wd, u8 wdt_conf)
  357. {
  358. return (superio_inb(wd->sioaddr, SIO_REG_ENABLE) & BIT(0))
  359. && (wdt_conf & BIT(F71808FG_FLAG_WD_EN));
  360. }
  361. static const struct watchdog_ops fintek_wdt_ops = {
  362. .owner = THIS_MODULE,
  363. .start = fintek_wdt_start,
  364. .stop = fintek_wdt_stop,
  365. .ping = fintek_wdt_keepalive,
  366. .set_timeout = fintek_wdt_set_timeout,
  367. };
  368. static int fintek_wdt_probe(struct platform_device *pdev)
  369. {
  370. struct device *dev = &pdev->dev;
  371. struct fintek_wdt_pdata *pdata;
  372. struct watchdog_device *wdd;
  373. struct fintek_wdt *wd;
  374. int wdt_conf, err = 0;
  375. struct resource *res;
  376. int sioaddr;
  377. res = platform_get_resource(pdev, IORESOURCE_IO, 0);
  378. if (!res)
  379. return -ENXIO;
  380. sioaddr = res->start;
  381. wd = devm_kzalloc(dev, sizeof(*wd), GFP_KERNEL);
  382. if (!wd)
  383. return -ENOMEM;
  384. pdata = dev->platform_data;
  385. wd->type = pdata->type;
  386. wd->sioaddr = sioaddr;
  387. wd->ident.options = WDIOF_SETTIMEOUT
  388. | WDIOF_MAGICCLOSE
  389. | WDIOF_KEEPALIVEPING
  390. | WDIOF_CARDRESET;
  391. snprintf(wd->ident.identity,
  392. sizeof(wd->ident.identity), "%s watchdog",
  393. fintek_wdt_names[wd->type]);
  394. err = superio_enter(sioaddr);
  395. if (err)
  396. return err;
  397. superio_select(wd->sioaddr, SIO_F71808FG_LD_WDT);
  398. wdt_conf = superio_inb(sioaddr, F71808FG_REG_WDT_CONF);
  399. /*
  400. * We don't want WDTMOUT_STS to stick around till regular reboot.
  401. * Write 1 to the bit to clear it to zero.
  402. */
  403. superio_outb(sioaddr, F71808FG_REG_WDT_CONF,
  404. wdt_conf | BIT(F71808FG_FLAG_WDTMOUT_STS));
  405. wdd = &wd->wdd;
  406. if (fintek_wdt_is_running(wd, wdt_conf))
  407. set_bit(WDOG_HW_RUNNING, &wdd->status);
  408. superio_exit(sioaddr);
  409. wdd->parent = dev;
  410. wdd->info = &wd->ident;
  411. wdd->ops = &fintek_wdt_ops;
  412. wdd->min_timeout = 1;
  413. wdd->max_timeout = WATCHDOG_MAX_TIMEOUT;
  414. watchdog_set_drvdata(wdd, wd);
  415. watchdog_set_nowayout(wdd, nowayout);
  416. watchdog_stop_on_unregister(wdd);
  417. watchdog_stop_on_reboot(wdd);
  418. watchdog_init_timeout(wdd, start_withtimeout ?: timeout, NULL);
  419. if (wdt_conf & BIT(F71808FG_FLAG_WDTMOUT_STS))
  420. wdd->bootstatus = WDIOF_CARDRESET;
  421. /*
  422. * WATCHDOG_HANDLE_BOOT_ENABLED can result in keepalive being directly
  423. * called without a set_timeout before, so it needs to be done here
  424. * unconditionally.
  425. */
  426. fintek_wdt_set_timeout(wdd, wdd->timeout);
  427. fintek_wdt_set_pulse_width(wd, pulse_width);
  428. if (start_withtimeout) {
  429. err = fintek_wdt_start(wdd);
  430. if (err) {
  431. dev_err(dev, "cannot start watchdog timer\n");
  432. return err;
  433. }
  434. set_bit(WDOG_HW_RUNNING, &wdd->status);
  435. dev_info(dev, "watchdog started with initial timeout of %u sec\n",
  436. start_withtimeout);
  437. }
  438. return devm_watchdog_register_device(dev, wdd);
  439. }
  440. static int __init fintek_wdt_find(int sioaddr)
  441. {
  442. enum chips type;
  443. u16 devid;
  444. int err = superio_enter(sioaddr);
  445. if (err)
  446. return err;
  447. devid = superio_inw(sioaddr, SIO_REG_MANID);
  448. if (devid != SIO_FINTEK_ID) {
  449. pr_debug("Not a Fintek device\n");
  450. err = -ENODEV;
  451. goto exit;
  452. }
  453. devid = force_id ? force_id : superio_inw(sioaddr, SIO_REG_DEVID);
  454. switch (devid) {
  455. case SIO_F71808_ID:
  456. type = f71808fg;
  457. break;
  458. case SIO_F71862_ID:
  459. type = f71862fg;
  460. break;
  461. case SIO_F71868_ID:
  462. type = f71868;
  463. break;
  464. case SIO_F71869_ID:
  465. case SIO_F71869A_ID:
  466. type = f71869;
  467. break;
  468. case SIO_F71882_ID:
  469. type = f71882fg;
  470. break;
  471. case SIO_F71889_ID:
  472. type = f71889fg;
  473. break;
  474. case SIO_F71858_ID:
  475. /* Confirmed (by datasheet) not to have a watchdog. */
  476. err = -ENODEV;
  477. goto exit;
  478. case SIO_F81803_ID:
  479. type = f81803;
  480. break;
  481. case SIO_F81865_ID:
  482. type = f81865;
  483. break;
  484. case SIO_F81866_ID:
  485. type = f81866;
  486. break;
  487. case SIO_F81966_ID:
  488. type = f81966;
  489. break;
  490. default:
  491. pr_info("Unrecognized Fintek device: %04x\n",
  492. (unsigned int)devid);
  493. err = -ENODEV;
  494. goto exit;
  495. }
  496. pr_info("Found %s watchdog chip, revision %d\n",
  497. fintek_wdt_names[type],
  498. (int)superio_inb(sioaddr, SIO_REG_DEVREV));
  499. exit:
  500. superio_exit(sioaddr);
  501. return err ? err : type;
  502. }
  503. static struct platform_driver fintek_wdt_driver = {
  504. .probe = fintek_wdt_probe,
  505. .driver = {
  506. .name = DRVNAME,
  507. },
  508. };
  509. static struct platform_device *fintek_wdt_pdev;
  510. static int __init fintek_wdt_init(void)
  511. {
  512. static const unsigned short addrs[] = { 0x2e, 0x4e };
  513. struct fintek_wdt_pdata pdata;
  514. struct resource wdt_res = {};
  515. int ret;
  516. int i;
  517. if (f71862fg_pin != 63 && f71862fg_pin != 56) {
  518. pr_err("Invalid argument f71862fg_pin=%d\n", f71862fg_pin);
  519. return -EINVAL;
  520. }
  521. for (i = 0; i < ARRAY_SIZE(addrs); i++) {
  522. ret = fintek_wdt_find(addrs[i]);
  523. if (ret >= 0)
  524. break;
  525. }
  526. if (i == ARRAY_SIZE(addrs))
  527. return ret;
  528. pdata.type = ret;
  529. ret = platform_driver_register(&fintek_wdt_driver);
  530. if (ret)
  531. return ret;
  532. wdt_res.name = "superio port";
  533. wdt_res.flags = IORESOURCE_IO;
  534. wdt_res.start = addrs[i];
  535. wdt_res.end = addrs[i] + 1;
  536. fintek_wdt_pdev = platform_device_register_resndata(NULL, DRVNAME, -1,
  537. &wdt_res, 1,
  538. &pdata, sizeof(pdata));
  539. if (IS_ERR(fintek_wdt_pdev)) {
  540. platform_driver_unregister(&fintek_wdt_driver);
  541. return PTR_ERR(fintek_wdt_pdev);
  542. }
  543. return 0;
  544. }
  545. static void __exit fintek_wdt_exit(void)
  546. {
  547. platform_device_unregister(fintek_wdt_pdev);
  548. platform_driver_unregister(&fintek_wdt_driver);
  549. }
  550. MODULE_DESCRIPTION("F71808E Watchdog Driver");
  551. MODULE_AUTHOR("Giel van Schijndel <[email protected]>");
  552. MODULE_LICENSE("GPL");
  553. module_init(fintek_wdt_init);
  554. module_exit(fintek_wdt_exit);