gpio-thunderx.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2016, 2017 Cavium Inc.
  7. */
  8. #include <linux/bitops.h>
  9. #include <linux/gpio/driver.h>
  10. #include <linux/interrupt.h>
  11. #include <linux/io.h>
  12. #include <linux/irq.h>
  13. #include <linux/kernel.h>
  14. #include <linux/module.h>
  15. #include <linux/pci.h>
  16. #include <linux/spinlock.h>
  17. #define GPIO_RX_DAT 0x0
  18. #define GPIO_TX_SET 0x8
  19. #define GPIO_TX_CLR 0x10
  20. #define GPIO_CONST 0x90
  21. #define GPIO_CONST_GPIOS_MASK 0xff
  22. #define GPIO_BIT_CFG 0x400
  23. #define GPIO_BIT_CFG_TX_OE BIT(0)
  24. #define GPIO_BIT_CFG_PIN_XOR BIT(1)
  25. #define GPIO_BIT_CFG_INT_EN BIT(2)
  26. #define GPIO_BIT_CFG_INT_TYPE BIT(3)
  27. #define GPIO_BIT_CFG_FIL_MASK GENMASK(11, 4)
  28. #define GPIO_BIT_CFG_FIL_CNT_SHIFT 4
  29. #define GPIO_BIT_CFG_FIL_SEL_SHIFT 8
  30. #define GPIO_BIT_CFG_TX_OD BIT(12)
  31. #define GPIO_BIT_CFG_PIN_SEL_MASK GENMASK(25, 16)
  32. #define GPIO_INTR 0x800
  33. #define GPIO_INTR_INTR BIT(0)
  34. #define GPIO_INTR_INTR_W1S BIT(1)
  35. #define GPIO_INTR_ENA_W1C BIT(2)
  36. #define GPIO_INTR_ENA_W1S BIT(3)
  37. #define GPIO_2ND_BANK 0x1400
  38. #define GLITCH_FILTER_400NS ((4u << GPIO_BIT_CFG_FIL_SEL_SHIFT) | \
  39. (9u << GPIO_BIT_CFG_FIL_CNT_SHIFT))
  40. struct thunderx_gpio;
  41. struct thunderx_line {
  42. struct thunderx_gpio *txgpio;
  43. unsigned int line;
  44. unsigned int fil_bits;
  45. };
  46. struct thunderx_gpio {
  47. struct gpio_chip chip;
  48. u8 __iomem *register_base;
  49. struct irq_domain *irqd;
  50. struct msix_entry *msix_entries; /* per line MSI-X */
  51. struct thunderx_line *line_entries; /* per line irq info */
  52. raw_spinlock_t lock;
  53. unsigned long invert_mask[2];
  54. unsigned long od_mask[2];
  55. int base_msi;
  56. };
  57. static unsigned int bit_cfg_reg(unsigned int line)
  58. {
  59. return 8 * line + GPIO_BIT_CFG;
  60. }
  61. static unsigned int intr_reg(unsigned int line)
  62. {
  63. return 8 * line + GPIO_INTR;
  64. }
  65. static bool thunderx_gpio_is_gpio_nowarn(struct thunderx_gpio *txgpio,
  66. unsigned int line)
  67. {
  68. u64 bit_cfg = readq(txgpio->register_base + bit_cfg_reg(line));
  69. return (bit_cfg & GPIO_BIT_CFG_PIN_SEL_MASK) == 0;
  70. }
  71. /*
  72. * Check (and WARN) that the pin is available for GPIO. We will not
  73. * allow modification of the state of non-GPIO pins from this driver.
  74. */
  75. static bool thunderx_gpio_is_gpio(struct thunderx_gpio *txgpio,
  76. unsigned int line)
  77. {
  78. bool rv = thunderx_gpio_is_gpio_nowarn(txgpio, line);
  79. WARN_RATELIMIT(!rv, "Pin %d not available for GPIO\n", line);
  80. return rv;
  81. }
  82. static int thunderx_gpio_request(struct gpio_chip *chip, unsigned int line)
  83. {
  84. struct thunderx_gpio *txgpio = gpiochip_get_data(chip);
  85. return thunderx_gpio_is_gpio(txgpio, line) ? 0 : -EIO;
  86. }
  87. static int thunderx_gpio_dir_in(struct gpio_chip *chip, unsigned int line)
  88. {
  89. struct thunderx_gpio *txgpio = gpiochip_get_data(chip);
  90. if (!thunderx_gpio_is_gpio(txgpio, line))
  91. return -EIO;
  92. raw_spin_lock(&txgpio->lock);
  93. clear_bit(line, txgpio->invert_mask);
  94. clear_bit(line, txgpio->od_mask);
  95. writeq(txgpio->line_entries[line].fil_bits,
  96. txgpio->register_base + bit_cfg_reg(line));
  97. raw_spin_unlock(&txgpio->lock);
  98. return 0;
  99. }
  100. static void thunderx_gpio_set(struct gpio_chip *chip, unsigned int line,
  101. int value)
  102. {
  103. struct thunderx_gpio *txgpio = gpiochip_get_data(chip);
  104. int bank = line / 64;
  105. int bank_bit = line % 64;
  106. void __iomem *reg = txgpio->register_base +
  107. (bank * GPIO_2ND_BANK) + (value ? GPIO_TX_SET : GPIO_TX_CLR);
  108. writeq(BIT_ULL(bank_bit), reg);
  109. }
  110. static int thunderx_gpio_dir_out(struct gpio_chip *chip, unsigned int line,
  111. int value)
  112. {
  113. struct thunderx_gpio *txgpio = gpiochip_get_data(chip);
  114. u64 bit_cfg = txgpio->line_entries[line].fil_bits | GPIO_BIT_CFG_TX_OE;
  115. if (!thunderx_gpio_is_gpio(txgpio, line))
  116. return -EIO;
  117. raw_spin_lock(&txgpio->lock);
  118. thunderx_gpio_set(chip, line, value);
  119. if (test_bit(line, txgpio->invert_mask))
  120. bit_cfg |= GPIO_BIT_CFG_PIN_XOR;
  121. if (test_bit(line, txgpio->od_mask))
  122. bit_cfg |= GPIO_BIT_CFG_TX_OD;
  123. writeq(bit_cfg, txgpio->register_base + bit_cfg_reg(line));
  124. raw_spin_unlock(&txgpio->lock);
  125. return 0;
  126. }
  127. static int thunderx_gpio_get_direction(struct gpio_chip *chip, unsigned int line)
  128. {
  129. struct thunderx_gpio *txgpio = gpiochip_get_data(chip);
  130. u64 bit_cfg;
  131. if (!thunderx_gpio_is_gpio_nowarn(txgpio, line))
  132. /*
  133. * Say it is input for now to avoid WARNing on
  134. * gpiochip_add_data(). We will WARN if someone
  135. * requests it or tries to use it.
  136. */
  137. return 1;
  138. bit_cfg = readq(txgpio->register_base + bit_cfg_reg(line));
  139. return !(bit_cfg & GPIO_BIT_CFG_TX_OE);
  140. }
  141. static int thunderx_gpio_set_config(struct gpio_chip *chip,
  142. unsigned int line,
  143. unsigned long cfg)
  144. {
  145. bool orig_invert, orig_od, orig_dat, new_invert, new_od;
  146. u32 arg, sel;
  147. u64 bit_cfg;
  148. int bank = line / 64;
  149. int bank_bit = line % 64;
  150. int ret = -ENOTSUPP;
  151. struct thunderx_gpio *txgpio = gpiochip_get_data(chip);
  152. void __iomem *reg = txgpio->register_base + (bank * GPIO_2ND_BANK) + GPIO_TX_SET;
  153. if (!thunderx_gpio_is_gpio(txgpio, line))
  154. return -EIO;
  155. raw_spin_lock(&txgpio->lock);
  156. orig_invert = test_bit(line, txgpio->invert_mask);
  157. new_invert = orig_invert;
  158. orig_od = test_bit(line, txgpio->od_mask);
  159. new_od = orig_od;
  160. orig_dat = ((readq(reg) >> bank_bit) & 1) ^ orig_invert;
  161. bit_cfg = readq(txgpio->register_base + bit_cfg_reg(line));
  162. switch (pinconf_to_config_param(cfg)) {
  163. case PIN_CONFIG_DRIVE_OPEN_DRAIN:
  164. /*
  165. * Weird, setting open-drain mode causes signal
  166. * inversion. Note this so we can compensate in the
  167. * dir_out function.
  168. */
  169. set_bit(line, txgpio->invert_mask);
  170. new_invert = true;
  171. set_bit(line, txgpio->od_mask);
  172. new_od = true;
  173. ret = 0;
  174. break;
  175. case PIN_CONFIG_DRIVE_PUSH_PULL:
  176. clear_bit(line, txgpio->invert_mask);
  177. new_invert = false;
  178. clear_bit(line, txgpio->od_mask);
  179. new_od = false;
  180. ret = 0;
  181. break;
  182. case PIN_CONFIG_INPUT_DEBOUNCE:
  183. arg = pinconf_to_config_argument(cfg);
  184. if (arg > 1228) { /* 15 * 2^15 * 2.5nS maximum */
  185. ret = -EINVAL;
  186. break;
  187. }
  188. arg *= 400; /* scale to 2.5nS clocks. */
  189. sel = 0;
  190. while (arg > 15) {
  191. sel++;
  192. arg++; /* always round up */
  193. arg >>= 1;
  194. }
  195. txgpio->line_entries[line].fil_bits =
  196. (sel << GPIO_BIT_CFG_FIL_SEL_SHIFT) |
  197. (arg << GPIO_BIT_CFG_FIL_CNT_SHIFT);
  198. bit_cfg &= ~GPIO_BIT_CFG_FIL_MASK;
  199. bit_cfg |= txgpio->line_entries[line].fil_bits;
  200. writeq(bit_cfg, txgpio->register_base + bit_cfg_reg(line));
  201. ret = 0;
  202. break;
  203. default:
  204. break;
  205. }
  206. raw_spin_unlock(&txgpio->lock);
  207. /*
  208. * If currently output and OPEN_DRAIN changed, install the new
  209. * settings
  210. */
  211. if ((new_invert != orig_invert || new_od != orig_od) &&
  212. (bit_cfg & GPIO_BIT_CFG_TX_OE))
  213. ret = thunderx_gpio_dir_out(chip, line, orig_dat ^ new_invert);
  214. return ret;
  215. }
  216. static int thunderx_gpio_get(struct gpio_chip *chip, unsigned int line)
  217. {
  218. struct thunderx_gpio *txgpio = gpiochip_get_data(chip);
  219. int bank = line / 64;
  220. int bank_bit = line % 64;
  221. u64 read_bits = readq(txgpio->register_base + (bank * GPIO_2ND_BANK) + GPIO_RX_DAT);
  222. u64 masked_bits = read_bits & BIT_ULL(bank_bit);
  223. if (test_bit(line, txgpio->invert_mask))
  224. return masked_bits == 0;
  225. else
  226. return masked_bits != 0;
  227. }
  228. static void thunderx_gpio_set_multiple(struct gpio_chip *chip,
  229. unsigned long *mask,
  230. unsigned long *bits)
  231. {
  232. int bank;
  233. u64 set_bits, clear_bits;
  234. struct thunderx_gpio *txgpio = gpiochip_get_data(chip);
  235. for (bank = 0; bank <= chip->ngpio / 64; bank++) {
  236. set_bits = bits[bank] & mask[bank];
  237. clear_bits = ~bits[bank] & mask[bank];
  238. writeq(set_bits, txgpio->register_base + (bank * GPIO_2ND_BANK) + GPIO_TX_SET);
  239. writeq(clear_bits, txgpio->register_base + (bank * GPIO_2ND_BANK) + GPIO_TX_CLR);
  240. }
  241. }
  242. static void thunderx_gpio_irq_ack(struct irq_data *data)
  243. {
  244. struct thunderx_line *txline = irq_data_get_irq_chip_data(data);
  245. writeq(GPIO_INTR_INTR,
  246. txline->txgpio->register_base + intr_reg(txline->line));
  247. }
  248. static void thunderx_gpio_irq_mask(struct irq_data *data)
  249. {
  250. struct thunderx_line *txline = irq_data_get_irq_chip_data(data);
  251. writeq(GPIO_INTR_ENA_W1C,
  252. txline->txgpio->register_base + intr_reg(txline->line));
  253. }
  254. static void thunderx_gpio_irq_mask_ack(struct irq_data *data)
  255. {
  256. struct thunderx_line *txline = irq_data_get_irq_chip_data(data);
  257. writeq(GPIO_INTR_ENA_W1C | GPIO_INTR_INTR,
  258. txline->txgpio->register_base + intr_reg(txline->line));
  259. }
  260. static void thunderx_gpio_irq_unmask(struct irq_data *data)
  261. {
  262. struct thunderx_line *txline = irq_data_get_irq_chip_data(data);
  263. writeq(GPIO_INTR_ENA_W1S,
  264. txline->txgpio->register_base + intr_reg(txline->line));
  265. }
  266. static int thunderx_gpio_irq_set_type(struct irq_data *data,
  267. unsigned int flow_type)
  268. {
  269. struct thunderx_line *txline = irq_data_get_irq_chip_data(data);
  270. struct thunderx_gpio *txgpio = txline->txgpio;
  271. u64 bit_cfg;
  272. irqd_set_trigger_type(data, flow_type);
  273. bit_cfg = txline->fil_bits | GPIO_BIT_CFG_INT_EN;
  274. if (flow_type & IRQ_TYPE_EDGE_BOTH) {
  275. irq_set_handler_locked(data, handle_fasteoi_ack_irq);
  276. bit_cfg |= GPIO_BIT_CFG_INT_TYPE;
  277. } else {
  278. irq_set_handler_locked(data, handle_fasteoi_mask_irq);
  279. }
  280. raw_spin_lock(&txgpio->lock);
  281. if (flow_type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)) {
  282. bit_cfg |= GPIO_BIT_CFG_PIN_XOR;
  283. set_bit(txline->line, txgpio->invert_mask);
  284. } else {
  285. clear_bit(txline->line, txgpio->invert_mask);
  286. }
  287. clear_bit(txline->line, txgpio->od_mask);
  288. writeq(bit_cfg, txgpio->register_base + bit_cfg_reg(txline->line));
  289. raw_spin_unlock(&txgpio->lock);
  290. return IRQ_SET_MASK_OK;
  291. }
  292. static void thunderx_gpio_irq_enable(struct irq_data *data)
  293. {
  294. irq_chip_enable_parent(data);
  295. thunderx_gpio_irq_unmask(data);
  296. }
  297. static void thunderx_gpio_irq_disable(struct irq_data *data)
  298. {
  299. thunderx_gpio_irq_mask(data);
  300. irq_chip_disable_parent(data);
  301. }
  302. static int thunderx_gpio_irq_request_resources(struct irq_data *data)
  303. {
  304. struct thunderx_line *txline = irq_data_get_irq_chip_data(data);
  305. struct thunderx_gpio *txgpio = txline->txgpio;
  306. struct irq_data *parent_data = data->parent_data;
  307. int r;
  308. r = gpiochip_lock_as_irq(&txgpio->chip, txline->line);
  309. if (r)
  310. return r;
  311. if (parent_data && parent_data->chip->irq_request_resources) {
  312. r = parent_data->chip->irq_request_resources(parent_data);
  313. if (r)
  314. goto error;
  315. }
  316. return 0;
  317. error:
  318. gpiochip_unlock_as_irq(&txgpio->chip, txline->line);
  319. return r;
  320. }
  321. static void thunderx_gpio_irq_release_resources(struct irq_data *data)
  322. {
  323. struct thunderx_line *txline = irq_data_get_irq_chip_data(data);
  324. struct thunderx_gpio *txgpio = txline->txgpio;
  325. struct irq_data *parent_data = data->parent_data;
  326. if (parent_data && parent_data->chip->irq_release_resources)
  327. parent_data->chip->irq_release_resources(parent_data);
  328. gpiochip_unlock_as_irq(&txgpio->chip, txline->line);
  329. }
  330. /*
  331. * Interrupts are chained from underlying MSI-X vectors. We have
  332. * these irq_chip functions to be able to handle level triggering
  333. * semantics and other acknowledgment tasks associated with the GPIO
  334. * mechanism.
  335. */
  336. static struct irq_chip thunderx_gpio_irq_chip = {
  337. .name = "GPIO",
  338. .irq_enable = thunderx_gpio_irq_enable,
  339. .irq_disable = thunderx_gpio_irq_disable,
  340. .irq_ack = thunderx_gpio_irq_ack,
  341. .irq_mask = thunderx_gpio_irq_mask,
  342. .irq_mask_ack = thunderx_gpio_irq_mask_ack,
  343. .irq_unmask = thunderx_gpio_irq_unmask,
  344. .irq_eoi = irq_chip_eoi_parent,
  345. .irq_set_affinity = irq_chip_set_affinity_parent,
  346. .irq_request_resources = thunderx_gpio_irq_request_resources,
  347. .irq_release_resources = thunderx_gpio_irq_release_resources,
  348. .irq_set_type = thunderx_gpio_irq_set_type,
  349. .flags = IRQCHIP_SET_TYPE_MASKED
  350. };
  351. static int thunderx_gpio_irq_translate(struct irq_domain *d,
  352. struct irq_fwspec *fwspec,
  353. irq_hw_number_t *hwirq,
  354. unsigned int *type)
  355. {
  356. struct thunderx_gpio *txgpio = d->host_data;
  357. if (WARN_ON(fwspec->param_count < 2))
  358. return -EINVAL;
  359. if (fwspec->param[0] >= txgpio->chip.ngpio)
  360. return -EINVAL;
  361. *hwirq = fwspec->param[0];
  362. *type = fwspec->param[1] & IRQ_TYPE_SENSE_MASK;
  363. return 0;
  364. }
  365. static int thunderx_gpio_irq_alloc(struct irq_domain *d, unsigned int virq,
  366. unsigned int nr_irqs, void *arg)
  367. {
  368. struct thunderx_line *txline = arg;
  369. return irq_domain_set_hwirq_and_chip(d, virq, txline->line,
  370. &thunderx_gpio_irq_chip, txline);
  371. }
  372. static const struct irq_domain_ops thunderx_gpio_irqd_ops = {
  373. .alloc = thunderx_gpio_irq_alloc,
  374. .translate = thunderx_gpio_irq_translate
  375. };
  376. static int thunderx_gpio_to_irq(struct gpio_chip *chip, unsigned int offset)
  377. {
  378. struct thunderx_gpio *txgpio = gpiochip_get_data(chip);
  379. return irq_find_mapping(txgpio->irqd, offset);
  380. }
  381. static int thunderx_gpio_probe(struct pci_dev *pdev,
  382. const struct pci_device_id *id)
  383. {
  384. void __iomem * const *tbl;
  385. struct device *dev = &pdev->dev;
  386. struct thunderx_gpio *txgpio;
  387. struct gpio_chip *chip;
  388. int ngpio, i;
  389. int err = 0;
  390. txgpio = devm_kzalloc(dev, sizeof(*txgpio), GFP_KERNEL);
  391. if (!txgpio)
  392. return -ENOMEM;
  393. raw_spin_lock_init(&txgpio->lock);
  394. chip = &txgpio->chip;
  395. pci_set_drvdata(pdev, txgpio);
  396. err = pcim_enable_device(pdev);
  397. if (err) {
  398. dev_err(dev, "Failed to enable PCI device: err %d\n", err);
  399. goto out;
  400. }
  401. err = pcim_iomap_regions(pdev, 1 << 0, KBUILD_MODNAME);
  402. if (err) {
  403. dev_err(dev, "Failed to iomap PCI device: err %d\n", err);
  404. goto out;
  405. }
  406. tbl = pcim_iomap_table(pdev);
  407. txgpio->register_base = tbl[0];
  408. if (!txgpio->register_base) {
  409. dev_err(dev, "Cannot map PCI resource\n");
  410. err = -ENOMEM;
  411. goto out;
  412. }
  413. if (pdev->subsystem_device == 0xa10a) {
  414. /* CN88XX has no GPIO_CONST register*/
  415. ngpio = 50;
  416. txgpio->base_msi = 48;
  417. } else {
  418. u64 c = readq(txgpio->register_base + GPIO_CONST);
  419. ngpio = c & GPIO_CONST_GPIOS_MASK;
  420. txgpio->base_msi = (c >> 8) & 0xff;
  421. }
  422. txgpio->msix_entries = devm_kcalloc(dev,
  423. ngpio, sizeof(struct msix_entry),
  424. GFP_KERNEL);
  425. if (!txgpio->msix_entries) {
  426. err = -ENOMEM;
  427. goto out;
  428. }
  429. txgpio->line_entries = devm_kcalloc(dev,
  430. ngpio,
  431. sizeof(struct thunderx_line),
  432. GFP_KERNEL);
  433. if (!txgpio->line_entries) {
  434. err = -ENOMEM;
  435. goto out;
  436. }
  437. for (i = 0; i < ngpio; i++) {
  438. u64 bit_cfg = readq(txgpio->register_base + bit_cfg_reg(i));
  439. txgpio->msix_entries[i].entry = txgpio->base_msi + (2 * i);
  440. txgpio->line_entries[i].line = i;
  441. txgpio->line_entries[i].txgpio = txgpio;
  442. /*
  443. * If something has already programmed the pin, use
  444. * the existing glitch filter settings, otherwise go
  445. * to 400nS.
  446. */
  447. txgpio->line_entries[i].fil_bits = bit_cfg ?
  448. (bit_cfg & GPIO_BIT_CFG_FIL_MASK) : GLITCH_FILTER_400NS;
  449. if ((bit_cfg & GPIO_BIT_CFG_TX_OE) && (bit_cfg & GPIO_BIT_CFG_TX_OD))
  450. set_bit(i, txgpio->od_mask);
  451. if (bit_cfg & GPIO_BIT_CFG_PIN_XOR)
  452. set_bit(i, txgpio->invert_mask);
  453. }
  454. /* Enable all MSI-X for interrupts on all possible lines. */
  455. err = pci_enable_msix_range(pdev, txgpio->msix_entries, ngpio, ngpio);
  456. if (err < 0)
  457. goto out;
  458. /*
  459. * Push GPIO specific irqdomain on hierarchy created as a side
  460. * effect of the pci_enable_msix()
  461. */
  462. txgpio->irqd = irq_domain_create_hierarchy(irq_get_irq_data(txgpio->msix_entries[0].vector)->domain,
  463. 0, 0, of_node_to_fwnode(dev->of_node),
  464. &thunderx_gpio_irqd_ops, txgpio);
  465. if (!txgpio->irqd) {
  466. err = -ENOMEM;
  467. goto out;
  468. }
  469. /* Push on irq_data and the domain for each line. */
  470. for (i = 0; i < ngpio; i++) {
  471. err = irq_domain_push_irq(txgpio->irqd,
  472. txgpio->msix_entries[i].vector,
  473. &txgpio->line_entries[i]);
  474. if (err < 0)
  475. dev_err(dev, "irq_domain_push_irq: %d\n", err);
  476. }
  477. chip->label = KBUILD_MODNAME;
  478. chip->parent = dev;
  479. chip->owner = THIS_MODULE;
  480. chip->request = thunderx_gpio_request;
  481. chip->base = -1; /* System allocated */
  482. chip->can_sleep = false;
  483. chip->ngpio = ngpio;
  484. chip->get_direction = thunderx_gpio_get_direction;
  485. chip->direction_input = thunderx_gpio_dir_in;
  486. chip->get = thunderx_gpio_get;
  487. chip->direction_output = thunderx_gpio_dir_out;
  488. chip->set = thunderx_gpio_set;
  489. chip->set_multiple = thunderx_gpio_set_multiple;
  490. chip->set_config = thunderx_gpio_set_config;
  491. chip->to_irq = thunderx_gpio_to_irq;
  492. err = devm_gpiochip_add_data(dev, chip, txgpio);
  493. if (err)
  494. goto out;
  495. dev_info(dev, "ThunderX GPIO: %d lines with base %d.\n",
  496. ngpio, chip->base);
  497. return 0;
  498. out:
  499. pci_set_drvdata(pdev, NULL);
  500. return err;
  501. }
  502. static void thunderx_gpio_remove(struct pci_dev *pdev)
  503. {
  504. int i;
  505. struct thunderx_gpio *txgpio = pci_get_drvdata(pdev);
  506. for (i = 0; i < txgpio->chip.ngpio; i++)
  507. irq_domain_pop_irq(txgpio->irqd,
  508. txgpio->msix_entries[i].vector);
  509. irq_domain_remove(txgpio->irqd);
  510. pci_set_drvdata(pdev, NULL);
  511. }
  512. static const struct pci_device_id thunderx_gpio_id_table[] = {
  513. { PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, 0xA00A) },
  514. { 0, } /* end of table */
  515. };
  516. MODULE_DEVICE_TABLE(pci, thunderx_gpio_id_table);
  517. static struct pci_driver thunderx_gpio_driver = {
  518. .name = KBUILD_MODNAME,
  519. .id_table = thunderx_gpio_id_table,
  520. .probe = thunderx_gpio_probe,
  521. .remove = thunderx_gpio_remove,
  522. };
  523. module_pci_driver(thunderx_gpio_driver);
  524. MODULE_DESCRIPTION("Cavium Inc. ThunderX/OCTEON-TX GPIO Driver");
  525. MODULE_LICENSE("GPL");