gpio-f7188x.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * GPIO driver for Fintek and Nuvoton Super-I/O chips
  4. *
  5. * Copyright (C) 2010-2013 LaCie
  6. *
  7. * Author: Simon Guinot <[email protected]>
  8. */
  9. #define DRVNAME "gpio-f7188x"
  10. #define pr_fmt(fmt) DRVNAME ": " fmt
  11. #include <linux/module.h>
  12. #include <linux/init.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/io.h>
  15. #include <linux/gpio/driver.h>
  16. #include <linux/bitops.h>
  17. /*
  18. * Super-I/O registers
  19. */
  20. #define SIO_LDSEL 0x07 /* Logical device select */
  21. #define SIO_DEVID 0x20 /* Device ID (2 bytes) */
  22. #define SIO_UNLOCK_KEY 0x87 /* Key to enable Super-I/O */
  23. #define SIO_LOCK_KEY 0xAA /* Key to disable Super-I/O */
  24. /*
  25. * Fintek devices.
  26. */
  27. #define SIO_FINTEK_DEVREV 0x22 /* Fintek Device revision */
  28. #define SIO_FINTEK_MANID 0x23 /* Fintek ID (2 bytes) */
  29. #define SIO_FINTEK_ID 0x1934 /* Manufacturer ID */
  30. #define SIO_F71869_ID 0x0814 /* F71869 chipset ID */
  31. #define SIO_F71869A_ID 0x1007 /* F71869A chipset ID */
  32. #define SIO_F71882_ID 0x0541 /* F71882 chipset ID */
  33. #define SIO_F71889_ID 0x0909 /* F71889 chipset ID */
  34. #define SIO_F71889A_ID 0x1005 /* F71889A chipset ID */
  35. #define SIO_F81866_ID 0x1010 /* F81866 chipset ID */
  36. #define SIO_F81804_ID 0x1502 /* F81804 chipset ID, same for F81966 */
  37. #define SIO_F81865_ID 0x0704 /* F81865 chipset ID */
  38. #define SIO_LD_GPIO_FINTEK 0x06 /* GPIO logical device */
  39. /*
  40. * Nuvoton devices.
  41. */
  42. #define SIO_NCT6126D_ID 0xD283 /* NCT6126D chipset ID */
  43. #define SIO_LD_GPIO_NUVOTON 0x07 /* GPIO logical device */
  44. enum chips {
  45. f71869,
  46. f71869a,
  47. f71882fg,
  48. f71889a,
  49. f71889f,
  50. f81866,
  51. f81804,
  52. f81865,
  53. nct6126d,
  54. };
  55. static const char * const f7188x_names[] = {
  56. "f71869",
  57. "f71869a",
  58. "f71882fg",
  59. "f71889a",
  60. "f71889f",
  61. "f81866",
  62. "f81804",
  63. "f81865",
  64. "nct6126d",
  65. };
  66. struct f7188x_sio {
  67. int addr;
  68. int device;
  69. enum chips type;
  70. };
  71. struct f7188x_gpio_bank {
  72. struct gpio_chip chip;
  73. unsigned int regbase;
  74. struct f7188x_gpio_data *data;
  75. };
  76. struct f7188x_gpio_data {
  77. struct f7188x_sio *sio;
  78. int nr_bank;
  79. struct f7188x_gpio_bank *bank;
  80. };
  81. /*
  82. * Super-I/O functions.
  83. */
  84. static inline int superio_inb(int base, int reg)
  85. {
  86. outb(reg, base);
  87. return inb(base + 1);
  88. }
  89. static int superio_inw(int base, int reg)
  90. {
  91. int val;
  92. outb(reg++, base);
  93. val = inb(base + 1) << 8;
  94. outb(reg, base);
  95. val |= inb(base + 1);
  96. return val;
  97. }
  98. static inline void superio_outb(int base, int reg, int val)
  99. {
  100. outb(reg, base);
  101. outb(val, base + 1);
  102. }
  103. static inline int superio_enter(int base)
  104. {
  105. /* Don't step on other drivers' I/O space by accident. */
  106. if (!request_muxed_region(base, 2, DRVNAME)) {
  107. pr_err("I/O address 0x%04x already in use\n", base);
  108. return -EBUSY;
  109. }
  110. /* According to the datasheet the key must be send twice. */
  111. outb(SIO_UNLOCK_KEY, base);
  112. outb(SIO_UNLOCK_KEY, base);
  113. return 0;
  114. }
  115. static inline void superio_select(int base, int ld)
  116. {
  117. outb(SIO_LDSEL, base);
  118. outb(ld, base + 1);
  119. }
  120. static inline void superio_exit(int base)
  121. {
  122. outb(SIO_LOCK_KEY, base);
  123. release_region(base, 2);
  124. }
  125. /*
  126. * GPIO chip.
  127. */
  128. static int f7188x_gpio_get_direction(struct gpio_chip *chip, unsigned offset);
  129. static int f7188x_gpio_direction_in(struct gpio_chip *chip, unsigned offset);
  130. static int f7188x_gpio_get(struct gpio_chip *chip, unsigned offset);
  131. static int f7188x_gpio_direction_out(struct gpio_chip *chip,
  132. unsigned offset, int value);
  133. static void f7188x_gpio_set(struct gpio_chip *chip, unsigned offset, int value);
  134. static int f7188x_gpio_set_config(struct gpio_chip *chip, unsigned offset,
  135. unsigned long config);
  136. #define F7188X_GPIO_BANK(_base, _ngpio, _regbase, _label) \
  137. { \
  138. .chip = { \
  139. .label = _label, \
  140. .owner = THIS_MODULE, \
  141. .get_direction = f7188x_gpio_get_direction, \
  142. .direction_input = f7188x_gpio_direction_in, \
  143. .get = f7188x_gpio_get, \
  144. .direction_output = f7188x_gpio_direction_out, \
  145. .set = f7188x_gpio_set, \
  146. .set_config = f7188x_gpio_set_config, \
  147. .base = _base, \
  148. .ngpio = _ngpio, \
  149. .can_sleep = true, \
  150. }, \
  151. .regbase = _regbase, \
  152. }
  153. #define f7188x_gpio_dir(base) ((base) + 0)
  154. #define f7188x_gpio_data_out(base) ((base) + 1)
  155. #define f7188x_gpio_data_in(base) ((base) + 2)
  156. /* Output mode register (0:open drain 1:push-pull). */
  157. #define f7188x_gpio_out_mode(base) ((base) + 3)
  158. #define f7188x_gpio_dir_invert(type) ((type) == nct6126d)
  159. #define f7188x_gpio_data_single(type) ((type) == nct6126d)
  160. static struct f7188x_gpio_bank f71869_gpio_bank[] = {
  161. F7188X_GPIO_BANK(0, 6, 0xF0, DRVNAME "-0"),
  162. F7188X_GPIO_BANK(10, 8, 0xE0, DRVNAME "-1"),
  163. F7188X_GPIO_BANK(20, 8, 0xD0, DRVNAME "-2"),
  164. F7188X_GPIO_BANK(30, 8, 0xC0, DRVNAME "-3"),
  165. F7188X_GPIO_BANK(40, 8, 0xB0, DRVNAME "-4"),
  166. F7188X_GPIO_BANK(50, 5, 0xA0, DRVNAME "-5"),
  167. F7188X_GPIO_BANK(60, 6, 0x90, DRVNAME "-6"),
  168. };
  169. static struct f7188x_gpio_bank f71869a_gpio_bank[] = {
  170. F7188X_GPIO_BANK(0, 6, 0xF0, DRVNAME "-0"),
  171. F7188X_GPIO_BANK(10, 8, 0xE0, DRVNAME "-1"),
  172. F7188X_GPIO_BANK(20, 8, 0xD0, DRVNAME "-2"),
  173. F7188X_GPIO_BANK(30, 8, 0xC0, DRVNAME "-3"),
  174. F7188X_GPIO_BANK(40, 8, 0xB0, DRVNAME "-4"),
  175. F7188X_GPIO_BANK(50, 5, 0xA0, DRVNAME "-5"),
  176. F7188X_GPIO_BANK(60, 8, 0x90, DRVNAME "-6"),
  177. F7188X_GPIO_BANK(70, 8, 0x80, DRVNAME "-7"),
  178. };
  179. static struct f7188x_gpio_bank f71882_gpio_bank[] = {
  180. F7188X_GPIO_BANK(0, 8, 0xF0, DRVNAME "-0"),
  181. F7188X_GPIO_BANK(10, 8, 0xE0, DRVNAME "-1"),
  182. F7188X_GPIO_BANK(20, 8, 0xD0, DRVNAME "-2"),
  183. F7188X_GPIO_BANK(30, 4, 0xC0, DRVNAME "-3"),
  184. F7188X_GPIO_BANK(40, 4, 0xB0, DRVNAME "-4"),
  185. };
  186. static struct f7188x_gpio_bank f71889a_gpio_bank[] = {
  187. F7188X_GPIO_BANK(0, 7, 0xF0, DRVNAME "-0"),
  188. F7188X_GPIO_BANK(10, 7, 0xE0, DRVNAME "-1"),
  189. F7188X_GPIO_BANK(20, 8, 0xD0, DRVNAME "-2"),
  190. F7188X_GPIO_BANK(30, 8, 0xC0, DRVNAME "-3"),
  191. F7188X_GPIO_BANK(40, 8, 0xB0, DRVNAME "-4"),
  192. F7188X_GPIO_BANK(50, 5, 0xA0, DRVNAME "-5"),
  193. F7188X_GPIO_BANK(60, 8, 0x90, DRVNAME "-6"),
  194. F7188X_GPIO_BANK(70, 8, 0x80, DRVNAME "-7"),
  195. };
  196. static struct f7188x_gpio_bank f71889_gpio_bank[] = {
  197. F7188X_GPIO_BANK(0, 7, 0xF0, DRVNAME "-0"),
  198. F7188X_GPIO_BANK(10, 7, 0xE0, DRVNAME "-1"),
  199. F7188X_GPIO_BANK(20, 8, 0xD0, DRVNAME "-2"),
  200. F7188X_GPIO_BANK(30, 8, 0xC0, DRVNAME "-3"),
  201. F7188X_GPIO_BANK(40, 8, 0xB0, DRVNAME "-4"),
  202. F7188X_GPIO_BANK(50, 5, 0xA0, DRVNAME "-5"),
  203. F7188X_GPIO_BANK(60, 8, 0x90, DRVNAME "-6"),
  204. F7188X_GPIO_BANK(70, 8, 0x80, DRVNAME "-7"),
  205. };
  206. static struct f7188x_gpio_bank f81866_gpio_bank[] = {
  207. F7188X_GPIO_BANK(0, 8, 0xF0, DRVNAME "-0"),
  208. F7188X_GPIO_BANK(10, 8, 0xE0, DRVNAME "-1"),
  209. F7188X_GPIO_BANK(20, 8, 0xD0, DRVNAME "-2"),
  210. F7188X_GPIO_BANK(30, 8, 0xC0, DRVNAME "-3"),
  211. F7188X_GPIO_BANK(40, 8, 0xB0, DRVNAME "-4"),
  212. F7188X_GPIO_BANK(50, 8, 0xA0, DRVNAME "-5"),
  213. F7188X_GPIO_BANK(60, 8, 0x90, DRVNAME "-6"),
  214. F7188X_GPIO_BANK(70, 8, 0x80, DRVNAME "-7"),
  215. F7188X_GPIO_BANK(80, 8, 0x88, DRVNAME "-8"),
  216. };
  217. static struct f7188x_gpio_bank f81804_gpio_bank[] = {
  218. F7188X_GPIO_BANK(0, 8, 0xF0, DRVNAME "-0"),
  219. F7188X_GPIO_BANK(10, 8, 0xE0, DRVNAME "-1"),
  220. F7188X_GPIO_BANK(20, 8, 0xD0, DRVNAME "-2"),
  221. F7188X_GPIO_BANK(50, 8, 0xA0, DRVNAME "-3"),
  222. F7188X_GPIO_BANK(60, 8, 0x90, DRVNAME "-4"),
  223. F7188X_GPIO_BANK(70, 8, 0x80, DRVNAME "-5"),
  224. F7188X_GPIO_BANK(90, 8, 0x98, DRVNAME "-6"),
  225. };
  226. static struct f7188x_gpio_bank f81865_gpio_bank[] = {
  227. F7188X_GPIO_BANK(0, 8, 0xF0, DRVNAME "-0"),
  228. F7188X_GPIO_BANK(10, 8, 0xE0, DRVNAME "-1"),
  229. F7188X_GPIO_BANK(20, 8, 0xD0, DRVNAME "-2"),
  230. F7188X_GPIO_BANK(30, 8, 0xC0, DRVNAME "-3"),
  231. F7188X_GPIO_BANK(40, 8, 0xB0, DRVNAME "-4"),
  232. F7188X_GPIO_BANK(50, 8, 0xA0, DRVNAME "-5"),
  233. F7188X_GPIO_BANK(60, 5, 0x90, DRVNAME "-6"),
  234. };
  235. static struct f7188x_gpio_bank nct6126d_gpio_bank[] = {
  236. F7188X_GPIO_BANK(0, 8, 0xE0, DRVNAME "-0"),
  237. F7188X_GPIO_BANK(10, 8, 0xE4, DRVNAME "-1"),
  238. F7188X_GPIO_BANK(20, 8, 0xE8, DRVNAME "-2"),
  239. F7188X_GPIO_BANK(30, 8, 0xEC, DRVNAME "-3"),
  240. F7188X_GPIO_BANK(40, 8, 0xF0, DRVNAME "-4"),
  241. F7188X_GPIO_BANK(50, 8, 0xF4, DRVNAME "-5"),
  242. F7188X_GPIO_BANK(60, 8, 0xF8, DRVNAME "-6"),
  243. F7188X_GPIO_BANK(70, 8, 0xFC, DRVNAME "-7"),
  244. };
  245. static int f7188x_gpio_get_direction(struct gpio_chip *chip, unsigned offset)
  246. {
  247. int err;
  248. struct f7188x_gpio_bank *bank = gpiochip_get_data(chip);
  249. struct f7188x_sio *sio = bank->data->sio;
  250. u8 dir;
  251. err = superio_enter(sio->addr);
  252. if (err)
  253. return err;
  254. superio_select(sio->addr, sio->device);
  255. dir = superio_inb(sio->addr, f7188x_gpio_dir(bank->regbase));
  256. superio_exit(sio->addr);
  257. if (f7188x_gpio_dir_invert(sio->type))
  258. dir = ~dir;
  259. if (dir & BIT(offset))
  260. return GPIO_LINE_DIRECTION_OUT;
  261. return GPIO_LINE_DIRECTION_IN;
  262. }
  263. static int f7188x_gpio_direction_in(struct gpio_chip *chip, unsigned offset)
  264. {
  265. int err;
  266. struct f7188x_gpio_bank *bank = gpiochip_get_data(chip);
  267. struct f7188x_sio *sio = bank->data->sio;
  268. u8 dir;
  269. err = superio_enter(sio->addr);
  270. if (err)
  271. return err;
  272. superio_select(sio->addr, sio->device);
  273. dir = superio_inb(sio->addr, f7188x_gpio_dir(bank->regbase));
  274. if (f7188x_gpio_dir_invert(sio->type))
  275. dir |= BIT(offset);
  276. else
  277. dir &= ~BIT(offset);
  278. superio_outb(sio->addr, f7188x_gpio_dir(bank->regbase), dir);
  279. superio_exit(sio->addr);
  280. return 0;
  281. }
  282. static int f7188x_gpio_get(struct gpio_chip *chip, unsigned offset)
  283. {
  284. int err;
  285. struct f7188x_gpio_bank *bank = gpiochip_get_data(chip);
  286. struct f7188x_sio *sio = bank->data->sio;
  287. u8 dir, data;
  288. err = superio_enter(sio->addr);
  289. if (err)
  290. return err;
  291. superio_select(sio->addr, sio->device);
  292. dir = superio_inb(sio->addr, f7188x_gpio_dir(bank->regbase));
  293. dir = !!(dir & BIT(offset));
  294. if (f7188x_gpio_data_single(sio->type) || dir)
  295. data = superio_inb(sio->addr, f7188x_gpio_data_out(bank->regbase));
  296. else
  297. data = superio_inb(sio->addr, f7188x_gpio_data_in(bank->regbase));
  298. superio_exit(sio->addr);
  299. return !!(data & BIT(offset));
  300. }
  301. static int f7188x_gpio_direction_out(struct gpio_chip *chip,
  302. unsigned offset, int value)
  303. {
  304. int err;
  305. struct f7188x_gpio_bank *bank = gpiochip_get_data(chip);
  306. struct f7188x_sio *sio = bank->data->sio;
  307. u8 dir, data_out;
  308. err = superio_enter(sio->addr);
  309. if (err)
  310. return err;
  311. superio_select(sio->addr, sio->device);
  312. data_out = superio_inb(sio->addr, f7188x_gpio_data_out(bank->regbase));
  313. if (value)
  314. data_out |= BIT(offset);
  315. else
  316. data_out &= ~BIT(offset);
  317. superio_outb(sio->addr, f7188x_gpio_data_out(bank->regbase), data_out);
  318. dir = superio_inb(sio->addr, f7188x_gpio_dir(bank->regbase));
  319. if (f7188x_gpio_dir_invert(sio->type))
  320. dir &= ~BIT(offset);
  321. else
  322. dir |= BIT(offset);
  323. superio_outb(sio->addr, f7188x_gpio_dir(bank->regbase), dir);
  324. superio_exit(sio->addr);
  325. return 0;
  326. }
  327. static void f7188x_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
  328. {
  329. int err;
  330. struct f7188x_gpio_bank *bank = gpiochip_get_data(chip);
  331. struct f7188x_sio *sio = bank->data->sio;
  332. u8 data_out;
  333. err = superio_enter(sio->addr);
  334. if (err)
  335. return;
  336. superio_select(sio->addr, sio->device);
  337. data_out = superio_inb(sio->addr, f7188x_gpio_data_out(bank->regbase));
  338. if (value)
  339. data_out |= BIT(offset);
  340. else
  341. data_out &= ~BIT(offset);
  342. superio_outb(sio->addr, f7188x_gpio_data_out(bank->regbase), data_out);
  343. superio_exit(sio->addr);
  344. }
  345. static int f7188x_gpio_set_config(struct gpio_chip *chip, unsigned offset,
  346. unsigned long config)
  347. {
  348. int err;
  349. enum pin_config_param param = pinconf_to_config_param(config);
  350. struct f7188x_gpio_bank *bank = gpiochip_get_data(chip);
  351. struct f7188x_sio *sio = bank->data->sio;
  352. u8 data;
  353. if (param != PIN_CONFIG_DRIVE_OPEN_DRAIN &&
  354. param != PIN_CONFIG_DRIVE_PUSH_PULL)
  355. return -ENOTSUPP;
  356. err = superio_enter(sio->addr);
  357. if (err)
  358. return err;
  359. superio_select(sio->addr, sio->device);
  360. data = superio_inb(sio->addr, f7188x_gpio_out_mode(bank->regbase));
  361. if (param == PIN_CONFIG_DRIVE_OPEN_DRAIN)
  362. data &= ~BIT(offset);
  363. else
  364. data |= BIT(offset);
  365. superio_outb(sio->addr, f7188x_gpio_out_mode(bank->regbase), data);
  366. superio_exit(sio->addr);
  367. return 0;
  368. }
  369. /*
  370. * Platform device and driver.
  371. */
  372. static int f7188x_gpio_probe(struct platform_device *pdev)
  373. {
  374. int err;
  375. int i;
  376. struct f7188x_sio *sio = dev_get_platdata(&pdev->dev);
  377. struct f7188x_gpio_data *data;
  378. data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
  379. if (!data)
  380. return -ENOMEM;
  381. switch (sio->type) {
  382. case f71869:
  383. data->nr_bank = ARRAY_SIZE(f71869_gpio_bank);
  384. data->bank = f71869_gpio_bank;
  385. break;
  386. case f71869a:
  387. data->nr_bank = ARRAY_SIZE(f71869a_gpio_bank);
  388. data->bank = f71869a_gpio_bank;
  389. break;
  390. case f71882fg:
  391. data->nr_bank = ARRAY_SIZE(f71882_gpio_bank);
  392. data->bank = f71882_gpio_bank;
  393. break;
  394. case f71889a:
  395. data->nr_bank = ARRAY_SIZE(f71889a_gpio_bank);
  396. data->bank = f71889a_gpio_bank;
  397. break;
  398. case f71889f:
  399. data->nr_bank = ARRAY_SIZE(f71889_gpio_bank);
  400. data->bank = f71889_gpio_bank;
  401. break;
  402. case f81866:
  403. data->nr_bank = ARRAY_SIZE(f81866_gpio_bank);
  404. data->bank = f81866_gpio_bank;
  405. break;
  406. case f81804:
  407. data->nr_bank = ARRAY_SIZE(f81804_gpio_bank);
  408. data->bank = f81804_gpio_bank;
  409. break;
  410. case f81865:
  411. data->nr_bank = ARRAY_SIZE(f81865_gpio_bank);
  412. data->bank = f81865_gpio_bank;
  413. break;
  414. case nct6126d:
  415. data->nr_bank = ARRAY_SIZE(nct6126d_gpio_bank);
  416. data->bank = nct6126d_gpio_bank;
  417. break;
  418. default:
  419. return -ENODEV;
  420. }
  421. data->sio = sio;
  422. platform_set_drvdata(pdev, data);
  423. /* For each GPIO bank, register a GPIO chip. */
  424. for (i = 0; i < data->nr_bank; i++) {
  425. struct f7188x_gpio_bank *bank = &data->bank[i];
  426. bank->chip.parent = &pdev->dev;
  427. bank->data = data;
  428. err = devm_gpiochip_add_data(&pdev->dev, &bank->chip, bank);
  429. if (err) {
  430. dev_err(&pdev->dev,
  431. "Failed to register gpiochip %d: %d\n",
  432. i, err);
  433. return err;
  434. }
  435. }
  436. return 0;
  437. }
  438. static int __init f7188x_find(int addr, struct f7188x_sio *sio)
  439. {
  440. int err;
  441. u16 devid;
  442. u16 manid;
  443. err = superio_enter(addr);
  444. if (err)
  445. return err;
  446. err = -ENODEV;
  447. sio->device = SIO_LD_GPIO_FINTEK;
  448. devid = superio_inw(addr, SIO_DEVID);
  449. switch (devid) {
  450. case SIO_F71869_ID:
  451. sio->type = f71869;
  452. break;
  453. case SIO_F71869A_ID:
  454. sio->type = f71869a;
  455. break;
  456. case SIO_F71882_ID:
  457. sio->type = f71882fg;
  458. break;
  459. case SIO_F71889A_ID:
  460. sio->type = f71889a;
  461. break;
  462. case SIO_F71889_ID:
  463. sio->type = f71889f;
  464. break;
  465. case SIO_F81866_ID:
  466. sio->type = f81866;
  467. break;
  468. case SIO_F81804_ID:
  469. sio->type = f81804;
  470. break;
  471. case SIO_F81865_ID:
  472. sio->type = f81865;
  473. break;
  474. case SIO_NCT6126D_ID:
  475. sio->device = SIO_LD_GPIO_NUVOTON;
  476. sio->type = nct6126d;
  477. break;
  478. default:
  479. pr_info("Unsupported Fintek device 0x%04x\n", devid);
  480. goto err;
  481. }
  482. /* double check manufacturer where possible */
  483. if (sio->type != nct6126d) {
  484. manid = superio_inw(addr, SIO_FINTEK_MANID);
  485. if (manid != SIO_FINTEK_ID) {
  486. pr_debug("Not a Fintek device at 0x%08x\n", addr);
  487. goto err;
  488. }
  489. }
  490. sio->addr = addr;
  491. err = 0;
  492. pr_info("Found %s at %#x\n", f7188x_names[sio->type], (unsigned int)addr);
  493. if (sio->type != nct6126d)
  494. pr_info(" revision %d\n", superio_inb(addr, SIO_FINTEK_DEVREV));
  495. err:
  496. superio_exit(addr);
  497. return err;
  498. }
  499. static struct platform_device *f7188x_gpio_pdev;
  500. static int __init
  501. f7188x_gpio_device_add(const struct f7188x_sio *sio)
  502. {
  503. int err;
  504. f7188x_gpio_pdev = platform_device_alloc(DRVNAME, -1);
  505. if (!f7188x_gpio_pdev)
  506. return -ENOMEM;
  507. err = platform_device_add_data(f7188x_gpio_pdev,
  508. sio, sizeof(*sio));
  509. if (err) {
  510. pr_err("Platform data allocation failed\n");
  511. goto err;
  512. }
  513. err = platform_device_add(f7188x_gpio_pdev);
  514. if (err) {
  515. pr_err("Device addition failed\n");
  516. goto err;
  517. }
  518. return 0;
  519. err:
  520. platform_device_put(f7188x_gpio_pdev);
  521. return err;
  522. }
  523. /*
  524. * Try to match a supported Fintek device by reading the (hard-wired)
  525. * configuration I/O ports. If available, then register both the platform
  526. * device and driver to support the GPIOs.
  527. */
  528. static struct platform_driver f7188x_gpio_driver = {
  529. .driver = {
  530. .name = DRVNAME,
  531. },
  532. .probe = f7188x_gpio_probe,
  533. };
  534. static int __init f7188x_gpio_init(void)
  535. {
  536. int err;
  537. struct f7188x_sio sio;
  538. if (f7188x_find(0x2e, &sio) &&
  539. f7188x_find(0x4e, &sio))
  540. return -ENODEV;
  541. err = platform_driver_register(&f7188x_gpio_driver);
  542. if (!err) {
  543. err = f7188x_gpio_device_add(&sio);
  544. if (err)
  545. platform_driver_unregister(&f7188x_gpio_driver);
  546. }
  547. return err;
  548. }
  549. subsys_initcall(f7188x_gpio_init);
  550. static void __exit f7188x_gpio_exit(void)
  551. {
  552. platform_device_unregister(f7188x_gpio_pdev);
  553. platform_driver_unregister(&f7188x_gpio_driver);
  554. }
  555. module_exit(f7188x_gpio_exit);
  556. MODULE_DESCRIPTION("GPIO driver for Super-I/O chips F71869, F71869A, F71882FG, F71889A, F71889F and F81866");
  557. MODULE_AUTHOR("Simon Guinot <[email protected]>");
  558. MODULE_LICENSE("GPL");