gpio-pcie-idio-24.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * GPIO driver for the ACCES PCIe-IDIO-24 family
  4. * Copyright (C) 2018 William Breathitt Gray
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License, version 2, as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * This driver supports the following ACCES devices: PCIe-IDIO-24,
  16. * PCIe-IDI-24, PCIe-IDO-24, and PCIe-IDIO-12.
  17. */
  18. #include <linux/bitmap.h>
  19. #include <linux/bitops.h>
  20. #include <linux/device.h>
  21. #include <linux/errno.h>
  22. #include <linux/gpio/driver.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/irqdesc.h>
  25. #include <linux/kernel.h>
  26. #include <linux/module.h>
  27. #include <linux/pci.h>
  28. #include <linux/spinlock.h>
  29. #include <linux/types.h>
  30. /*
  31. * PLX PEX8311 PCI LCS_INTCSR Interrupt Control/Status
  32. *
  33. * Bit: Description
  34. * 0: Enable Interrupt Sources (Bit 0)
  35. * 1: Enable Interrupt Sources (Bit 1)
  36. * 2: Generate Internal PCI Bus Internal SERR# Interrupt
  37. * 3: Mailbox Interrupt Enable
  38. * 4: Power Management Interrupt Enable
  39. * 5: Power Management Interrupt
  40. * 6: Slave Read Local Data Parity Check Error Enable
  41. * 7: Slave Read Local Data Parity Check Error Status
  42. * 8: Internal PCI Wire Interrupt Enable
  43. * 9: PCI Express Doorbell Interrupt Enable
  44. * 10: PCI Abort Interrupt Enable
  45. * 11: Local Interrupt Input Enable
  46. * 12: Retry Abort Enable
  47. * 13: PCI Express Doorbell Interrupt Active
  48. * 14: PCI Abort Interrupt Active
  49. * 15: Local Interrupt Input Active
  50. * 16: Local Interrupt Output Enable
  51. * 17: Local Doorbell Interrupt Enable
  52. * 18: DMA Channel 0 Interrupt Enable
  53. * 19: DMA Channel 1 Interrupt Enable
  54. * 20: Local Doorbell Interrupt Active
  55. * 21: DMA Channel 0 Interrupt Active
  56. * 22: DMA Channel 1 Interrupt Active
  57. * 23: Built-In Self-Test (BIST) Interrupt Active
  58. * 24: Direct Master was the Bus Master during a Master or Target Abort
  59. * 25: DMA Channel 0 was the Bus Master during a Master or Target Abort
  60. * 26: DMA Channel 1 was the Bus Master during a Master or Target Abort
  61. * 27: Target Abort after internal 256 consecutive Master Retrys
  62. * 28: PCI Bus wrote data to LCS_MBOX0
  63. * 29: PCI Bus wrote data to LCS_MBOX1
  64. * 30: PCI Bus wrote data to LCS_MBOX2
  65. * 31: PCI Bus wrote data to LCS_MBOX3
  66. */
  67. #define PLX_PEX8311_PCI_LCS_INTCSR 0x68
  68. #define INTCSR_INTERNAL_PCI_WIRE BIT(8)
  69. #define INTCSR_LOCAL_INPUT BIT(11)
  70. /**
  71. * struct idio_24_gpio_reg - GPIO device registers structure
  72. * @out0_7: Read: FET Outputs 0-7
  73. * Write: FET Outputs 0-7
  74. * @out8_15: Read: FET Outputs 8-15
  75. * Write: FET Outputs 8-15
  76. * @out16_23: Read: FET Outputs 16-23
  77. * Write: FET Outputs 16-23
  78. * @ttl_out0_7: Read: TTL/CMOS Outputs 0-7
  79. * Write: TTL/CMOS Outputs 0-7
  80. * @in0_7: Read: Isolated Inputs 0-7
  81. * Write: Reserved
  82. * @in8_15: Read: Isolated Inputs 8-15
  83. * Write: Reserved
  84. * @in16_23: Read: Isolated Inputs 16-23
  85. * Write: Reserved
  86. * @ttl_in0_7: Read: TTL/CMOS Inputs 0-7
  87. * Write: Reserved
  88. * @cos0_7: Read: COS Status Inputs 0-7
  89. * Write: COS Clear Inputs 0-7
  90. * @cos8_15: Read: COS Status Inputs 8-15
  91. * Write: COS Clear Inputs 8-15
  92. * @cos16_23: Read: COS Status Inputs 16-23
  93. * Write: COS Clear Inputs 16-23
  94. * @cos_ttl0_7: Read: COS Status TTL/CMOS 0-7
  95. * Write: COS Clear TTL/CMOS 0-7
  96. * @ctl: Read: Control Register
  97. * Write: Control Register
  98. * @reserved: Read: Reserved
  99. * Write: Reserved
  100. * @cos_enable: Read: COS Enable
  101. * Write: COS Enable
  102. * @soft_reset: Read: IRQ Output Pin Status
  103. * Write: Software Board Reset
  104. */
  105. struct idio_24_gpio_reg {
  106. u8 out0_7;
  107. u8 out8_15;
  108. u8 out16_23;
  109. u8 ttl_out0_7;
  110. u8 in0_7;
  111. u8 in8_15;
  112. u8 in16_23;
  113. u8 ttl_in0_7;
  114. u8 cos0_7;
  115. u8 cos8_15;
  116. u8 cos16_23;
  117. u8 cos_ttl0_7;
  118. u8 ctl;
  119. u8 reserved;
  120. u8 cos_enable;
  121. u8 soft_reset;
  122. };
  123. /**
  124. * struct idio_24_gpio - GPIO device private data structure
  125. * @chip: instance of the gpio_chip
  126. * @lock: synchronization lock to prevent I/O race conditions
  127. * @reg: I/O address offset for the GPIO device registers
  128. * @irq_mask: I/O bits affected by interrupts
  129. */
  130. struct idio_24_gpio {
  131. struct gpio_chip chip;
  132. raw_spinlock_t lock;
  133. __u8 __iomem *plx;
  134. struct idio_24_gpio_reg __iomem *reg;
  135. unsigned long irq_mask;
  136. };
  137. static int idio_24_gpio_get_direction(struct gpio_chip *chip,
  138. unsigned int offset)
  139. {
  140. struct idio_24_gpio *const idio24gpio = gpiochip_get_data(chip);
  141. const unsigned long out_mode_mask = BIT(1);
  142. /* FET Outputs */
  143. if (offset < 24)
  144. return 0;
  145. /* Isolated Inputs */
  146. if (offset < 48)
  147. return 1;
  148. /* TTL/CMOS I/O */
  149. /* OUT MODE = 1 when TTL/CMOS Output Mode is set */
  150. return !(ioread8(&idio24gpio->reg->ctl) & out_mode_mask);
  151. }
  152. static int idio_24_gpio_direction_input(struct gpio_chip *chip,
  153. unsigned int offset)
  154. {
  155. struct idio_24_gpio *const idio24gpio = gpiochip_get_data(chip);
  156. unsigned long flags;
  157. unsigned int ctl_state;
  158. const unsigned long out_mode_mask = BIT(1);
  159. /* TTL/CMOS I/O */
  160. if (offset > 47) {
  161. raw_spin_lock_irqsave(&idio24gpio->lock, flags);
  162. /* Clear TTL/CMOS Output Mode */
  163. ctl_state = ioread8(&idio24gpio->reg->ctl) & ~out_mode_mask;
  164. iowrite8(ctl_state, &idio24gpio->reg->ctl);
  165. raw_spin_unlock_irqrestore(&idio24gpio->lock, flags);
  166. }
  167. return 0;
  168. }
  169. static int idio_24_gpio_direction_output(struct gpio_chip *chip,
  170. unsigned int offset, int value)
  171. {
  172. struct idio_24_gpio *const idio24gpio = gpiochip_get_data(chip);
  173. unsigned long flags;
  174. unsigned int ctl_state;
  175. const unsigned long out_mode_mask = BIT(1);
  176. /* TTL/CMOS I/O */
  177. if (offset > 47) {
  178. raw_spin_lock_irqsave(&idio24gpio->lock, flags);
  179. /* Set TTL/CMOS Output Mode */
  180. ctl_state = ioread8(&idio24gpio->reg->ctl) | out_mode_mask;
  181. iowrite8(ctl_state, &idio24gpio->reg->ctl);
  182. raw_spin_unlock_irqrestore(&idio24gpio->lock, flags);
  183. }
  184. chip->set(chip, offset, value);
  185. return 0;
  186. }
  187. static int idio_24_gpio_get(struct gpio_chip *chip, unsigned int offset)
  188. {
  189. struct idio_24_gpio *const idio24gpio = gpiochip_get_data(chip);
  190. const unsigned long offset_mask = BIT(offset % 8);
  191. const unsigned long out_mode_mask = BIT(1);
  192. /* FET Outputs */
  193. if (offset < 8)
  194. return !!(ioread8(&idio24gpio->reg->out0_7) & offset_mask);
  195. if (offset < 16)
  196. return !!(ioread8(&idio24gpio->reg->out8_15) & offset_mask);
  197. if (offset < 24)
  198. return !!(ioread8(&idio24gpio->reg->out16_23) & offset_mask);
  199. /* Isolated Inputs */
  200. if (offset < 32)
  201. return !!(ioread8(&idio24gpio->reg->in0_7) & offset_mask);
  202. if (offset < 40)
  203. return !!(ioread8(&idio24gpio->reg->in8_15) & offset_mask);
  204. if (offset < 48)
  205. return !!(ioread8(&idio24gpio->reg->in16_23) & offset_mask);
  206. /* TTL/CMOS Outputs */
  207. if (ioread8(&idio24gpio->reg->ctl) & out_mode_mask)
  208. return !!(ioread8(&idio24gpio->reg->ttl_out0_7) & offset_mask);
  209. /* TTL/CMOS Inputs */
  210. return !!(ioread8(&idio24gpio->reg->ttl_in0_7) & offset_mask);
  211. }
  212. static int idio_24_gpio_get_multiple(struct gpio_chip *chip,
  213. unsigned long *mask, unsigned long *bits)
  214. {
  215. struct idio_24_gpio *const idio24gpio = gpiochip_get_data(chip);
  216. size_t i;
  217. const unsigned int gpio_reg_size = 8;
  218. unsigned int bits_offset;
  219. size_t word_index;
  220. unsigned int word_offset;
  221. unsigned long word_mask;
  222. const unsigned long port_mask = GENMASK(gpio_reg_size - 1, 0);
  223. unsigned long port_state;
  224. void __iomem *ports[] = {
  225. &idio24gpio->reg->out0_7, &idio24gpio->reg->out8_15,
  226. &idio24gpio->reg->out16_23, &idio24gpio->reg->in0_7,
  227. &idio24gpio->reg->in8_15, &idio24gpio->reg->in16_23,
  228. };
  229. const unsigned long out_mode_mask = BIT(1);
  230. /* clear bits array to a clean slate */
  231. bitmap_zero(bits, chip->ngpio);
  232. /* get bits are evaluated a gpio port register at a time */
  233. for (i = 0; i < ARRAY_SIZE(ports) + 1; i++) {
  234. /* gpio offset in bits array */
  235. bits_offset = i * gpio_reg_size;
  236. /* word index for bits array */
  237. word_index = BIT_WORD(bits_offset);
  238. /* gpio offset within current word of bits array */
  239. word_offset = bits_offset % BITS_PER_LONG;
  240. /* mask of get bits for current gpio within current word */
  241. word_mask = mask[word_index] & (port_mask << word_offset);
  242. if (!word_mask) {
  243. /* no get bits in this port so skip to next one */
  244. continue;
  245. }
  246. /* read bits from current gpio port (port 6 is TTL GPIO) */
  247. if (i < 6)
  248. port_state = ioread8(ports[i]);
  249. else if (ioread8(&idio24gpio->reg->ctl) & out_mode_mask)
  250. port_state = ioread8(&idio24gpio->reg->ttl_out0_7);
  251. else
  252. port_state = ioread8(&idio24gpio->reg->ttl_in0_7);
  253. /* store acquired bits at respective bits array offset */
  254. bits[word_index] |= port_state << word_offset;
  255. }
  256. return 0;
  257. }
  258. static void idio_24_gpio_set(struct gpio_chip *chip, unsigned int offset,
  259. int value)
  260. {
  261. struct idio_24_gpio *const idio24gpio = gpiochip_get_data(chip);
  262. const unsigned long out_mode_mask = BIT(1);
  263. void __iomem *base;
  264. const unsigned int mask = BIT(offset % 8);
  265. unsigned long flags;
  266. unsigned int out_state;
  267. /* Isolated Inputs */
  268. if (offset > 23 && offset < 48)
  269. return;
  270. /* TTL/CMOS Inputs */
  271. if (offset > 47 && !(ioread8(&idio24gpio->reg->ctl) & out_mode_mask))
  272. return;
  273. /* TTL/CMOS Outputs */
  274. if (offset > 47)
  275. base = &idio24gpio->reg->ttl_out0_7;
  276. /* FET Outputs */
  277. else if (offset > 15)
  278. base = &idio24gpio->reg->out16_23;
  279. else if (offset > 7)
  280. base = &idio24gpio->reg->out8_15;
  281. else
  282. base = &idio24gpio->reg->out0_7;
  283. raw_spin_lock_irqsave(&idio24gpio->lock, flags);
  284. if (value)
  285. out_state = ioread8(base) | mask;
  286. else
  287. out_state = ioread8(base) & ~mask;
  288. iowrite8(out_state, base);
  289. raw_spin_unlock_irqrestore(&idio24gpio->lock, flags);
  290. }
  291. static void idio_24_gpio_set_multiple(struct gpio_chip *chip,
  292. unsigned long *mask, unsigned long *bits)
  293. {
  294. struct idio_24_gpio *const idio24gpio = gpiochip_get_data(chip);
  295. size_t i;
  296. unsigned long bits_offset;
  297. unsigned long gpio_mask;
  298. const unsigned int gpio_reg_size = 8;
  299. const unsigned long port_mask = GENMASK(gpio_reg_size, 0);
  300. unsigned long flags;
  301. unsigned int out_state;
  302. void __iomem *ports[] = {
  303. &idio24gpio->reg->out0_7, &idio24gpio->reg->out8_15,
  304. &idio24gpio->reg->out16_23
  305. };
  306. const unsigned long out_mode_mask = BIT(1);
  307. const unsigned int ttl_offset = 48;
  308. const size_t ttl_i = BIT_WORD(ttl_offset);
  309. const unsigned int word_offset = ttl_offset % BITS_PER_LONG;
  310. const unsigned long ttl_mask = (mask[ttl_i] >> word_offset) & port_mask;
  311. const unsigned long ttl_bits = (bits[ttl_i] >> word_offset) & ttl_mask;
  312. /* set bits are processed a gpio port register at a time */
  313. for (i = 0; i < ARRAY_SIZE(ports); i++) {
  314. /* gpio offset in bits array */
  315. bits_offset = i * gpio_reg_size;
  316. /* check if any set bits for current port */
  317. gpio_mask = (*mask >> bits_offset) & port_mask;
  318. if (!gpio_mask) {
  319. /* no set bits for this port so move on to next port */
  320. continue;
  321. }
  322. raw_spin_lock_irqsave(&idio24gpio->lock, flags);
  323. /* process output lines */
  324. out_state = ioread8(ports[i]) & ~gpio_mask;
  325. out_state |= (*bits >> bits_offset) & gpio_mask;
  326. iowrite8(out_state, ports[i]);
  327. raw_spin_unlock_irqrestore(&idio24gpio->lock, flags);
  328. }
  329. /* check if setting TTL lines and if they are in output mode */
  330. if (!ttl_mask || !(ioread8(&idio24gpio->reg->ctl) & out_mode_mask))
  331. return;
  332. /* handle TTL output */
  333. raw_spin_lock_irqsave(&idio24gpio->lock, flags);
  334. /* process output lines */
  335. out_state = ioread8(&idio24gpio->reg->ttl_out0_7) & ~ttl_mask;
  336. out_state |= ttl_bits;
  337. iowrite8(out_state, &idio24gpio->reg->ttl_out0_7);
  338. raw_spin_unlock_irqrestore(&idio24gpio->lock, flags);
  339. }
  340. static void idio_24_irq_ack(struct irq_data *data)
  341. {
  342. }
  343. static void idio_24_irq_mask(struct irq_data *data)
  344. {
  345. struct gpio_chip *const chip = irq_data_get_irq_chip_data(data);
  346. struct idio_24_gpio *const idio24gpio = gpiochip_get_data(chip);
  347. unsigned long flags;
  348. const unsigned long bit_offset = irqd_to_hwirq(data) - 24;
  349. unsigned char new_irq_mask;
  350. const unsigned long bank_offset = bit_offset / 8;
  351. unsigned char cos_enable_state;
  352. raw_spin_lock_irqsave(&idio24gpio->lock, flags);
  353. idio24gpio->irq_mask &= ~BIT(bit_offset);
  354. new_irq_mask = idio24gpio->irq_mask >> bank_offset * 8;
  355. if (!new_irq_mask) {
  356. cos_enable_state = ioread8(&idio24gpio->reg->cos_enable);
  357. /* Disable Rising Edge detection */
  358. cos_enable_state &= ~BIT(bank_offset);
  359. /* Disable Falling Edge detection */
  360. cos_enable_state &= ~BIT(bank_offset + 4);
  361. iowrite8(cos_enable_state, &idio24gpio->reg->cos_enable);
  362. }
  363. raw_spin_unlock_irqrestore(&idio24gpio->lock, flags);
  364. }
  365. static void idio_24_irq_unmask(struct irq_data *data)
  366. {
  367. struct gpio_chip *const chip = irq_data_get_irq_chip_data(data);
  368. struct idio_24_gpio *const idio24gpio = gpiochip_get_data(chip);
  369. unsigned long flags;
  370. unsigned char prev_irq_mask;
  371. const unsigned long bit_offset = irqd_to_hwirq(data) - 24;
  372. const unsigned long bank_offset = bit_offset / 8;
  373. unsigned char cos_enable_state;
  374. raw_spin_lock_irqsave(&idio24gpio->lock, flags);
  375. prev_irq_mask = idio24gpio->irq_mask >> bank_offset * 8;
  376. idio24gpio->irq_mask |= BIT(bit_offset);
  377. if (!prev_irq_mask) {
  378. cos_enable_state = ioread8(&idio24gpio->reg->cos_enable);
  379. /* Enable Rising Edge detection */
  380. cos_enable_state |= BIT(bank_offset);
  381. /* Enable Falling Edge detection */
  382. cos_enable_state |= BIT(bank_offset + 4);
  383. iowrite8(cos_enable_state, &idio24gpio->reg->cos_enable);
  384. }
  385. raw_spin_unlock_irqrestore(&idio24gpio->lock, flags);
  386. }
  387. static int idio_24_irq_set_type(struct irq_data *data, unsigned int flow_type)
  388. {
  389. /* The only valid irq types are none and both-edges */
  390. if (flow_type != IRQ_TYPE_NONE &&
  391. (flow_type & IRQ_TYPE_EDGE_BOTH) != IRQ_TYPE_EDGE_BOTH)
  392. return -EINVAL;
  393. return 0;
  394. }
  395. static struct irq_chip idio_24_irqchip = {
  396. .name = "pcie-idio-24",
  397. .irq_ack = idio_24_irq_ack,
  398. .irq_mask = idio_24_irq_mask,
  399. .irq_unmask = idio_24_irq_unmask,
  400. .irq_set_type = idio_24_irq_set_type
  401. };
  402. static irqreturn_t idio_24_irq_handler(int irq, void *dev_id)
  403. {
  404. struct idio_24_gpio *const idio24gpio = dev_id;
  405. unsigned long irq_status;
  406. struct gpio_chip *const chip = &idio24gpio->chip;
  407. unsigned long irq_mask;
  408. int gpio;
  409. raw_spin_lock(&idio24gpio->lock);
  410. /* Read Change-Of-State status */
  411. irq_status = ioread32(&idio24gpio->reg->cos0_7);
  412. raw_spin_unlock(&idio24gpio->lock);
  413. /* Make sure our device generated IRQ */
  414. if (!irq_status)
  415. return IRQ_NONE;
  416. /* Handle only unmasked IRQ */
  417. irq_mask = idio24gpio->irq_mask & irq_status;
  418. for_each_set_bit(gpio, &irq_mask, chip->ngpio - 24)
  419. generic_handle_irq(irq_find_mapping(chip->irq.domain,
  420. gpio + 24));
  421. raw_spin_lock(&idio24gpio->lock);
  422. /* Clear Change-Of-State status */
  423. iowrite32(irq_status, &idio24gpio->reg->cos0_7);
  424. raw_spin_unlock(&idio24gpio->lock);
  425. return IRQ_HANDLED;
  426. }
  427. #define IDIO_24_NGPIO 56
  428. static const char *idio_24_names[IDIO_24_NGPIO] = {
  429. "OUT0", "OUT1", "OUT2", "OUT3", "OUT4", "OUT5", "OUT6", "OUT7",
  430. "OUT8", "OUT9", "OUT10", "OUT11", "OUT12", "OUT13", "OUT14", "OUT15",
  431. "OUT16", "OUT17", "OUT18", "OUT19", "OUT20", "OUT21", "OUT22", "OUT23",
  432. "IIN0", "IIN1", "IIN2", "IIN3", "IIN4", "IIN5", "IIN6", "IIN7",
  433. "IIN8", "IIN9", "IIN10", "IIN11", "IIN12", "IIN13", "IIN14", "IIN15",
  434. "IIN16", "IIN17", "IIN18", "IIN19", "IIN20", "IIN21", "IIN22", "IIN23",
  435. "TTL0", "TTL1", "TTL2", "TTL3", "TTL4", "TTL5", "TTL6", "TTL7"
  436. };
  437. static int idio_24_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  438. {
  439. struct device *const dev = &pdev->dev;
  440. struct idio_24_gpio *idio24gpio;
  441. int err;
  442. const size_t pci_plx_bar_index = 1;
  443. const size_t pci_bar_index = 2;
  444. const char *const name = pci_name(pdev);
  445. idio24gpio = devm_kzalloc(dev, sizeof(*idio24gpio), GFP_KERNEL);
  446. if (!idio24gpio)
  447. return -ENOMEM;
  448. err = pcim_enable_device(pdev);
  449. if (err) {
  450. dev_err(dev, "Failed to enable PCI device (%d)\n", err);
  451. return err;
  452. }
  453. err = pcim_iomap_regions(pdev, BIT(pci_plx_bar_index) | BIT(pci_bar_index), name);
  454. if (err) {
  455. dev_err(dev, "Unable to map PCI I/O addresses (%d)\n", err);
  456. return err;
  457. }
  458. idio24gpio->plx = pcim_iomap_table(pdev)[pci_plx_bar_index];
  459. idio24gpio->reg = pcim_iomap_table(pdev)[pci_bar_index];
  460. idio24gpio->chip.label = name;
  461. idio24gpio->chip.parent = dev;
  462. idio24gpio->chip.owner = THIS_MODULE;
  463. idio24gpio->chip.base = -1;
  464. idio24gpio->chip.ngpio = IDIO_24_NGPIO;
  465. idio24gpio->chip.names = idio_24_names;
  466. idio24gpio->chip.get_direction = idio_24_gpio_get_direction;
  467. idio24gpio->chip.direction_input = idio_24_gpio_direction_input;
  468. idio24gpio->chip.direction_output = idio_24_gpio_direction_output;
  469. idio24gpio->chip.get = idio_24_gpio_get;
  470. idio24gpio->chip.get_multiple = idio_24_gpio_get_multiple;
  471. idio24gpio->chip.set = idio_24_gpio_set;
  472. idio24gpio->chip.set_multiple = idio_24_gpio_set_multiple;
  473. raw_spin_lock_init(&idio24gpio->lock);
  474. /* Software board reset */
  475. iowrite8(0, &idio24gpio->reg->soft_reset);
  476. /*
  477. * enable PLX PEX8311 internal PCI wire interrupt and local interrupt
  478. * input
  479. */
  480. iowrite8((INTCSR_INTERNAL_PCI_WIRE | INTCSR_LOCAL_INPUT) >> 8,
  481. idio24gpio->plx + PLX_PEX8311_PCI_LCS_INTCSR + 1);
  482. err = devm_gpiochip_add_data(dev, &idio24gpio->chip, idio24gpio);
  483. if (err) {
  484. dev_err(dev, "GPIO registering failed (%d)\n", err);
  485. return err;
  486. }
  487. err = gpiochip_irqchip_add(&idio24gpio->chip, &idio_24_irqchip, 0,
  488. handle_edge_irq, IRQ_TYPE_NONE);
  489. if (err) {
  490. dev_err(dev, "Could not add irqchip (%d)\n", err);
  491. return err;
  492. }
  493. err = devm_request_irq(dev, pdev->irq, idio_24_irq_handler, IRQF_SHARED,
  494. name, idio24gpio);
  495. if (err) {
  496. dev_err(dev, "IRQ handler registering failed (%d)\n", err);
  497. return err;
  498. }
  499. return 0;
  500. }
  501. static const struct pci_device_id idio_24_pci_dev_id[] = {
  502. { PCI_DEVICE(0x494F, 0x0FD0) }, { PCI_DEVICE(0x494F, 0x0BD0) },
  503. { PCI_DEVICE(0x494F, 0x07D0) }, { PCI_DEVICE(0x494F, 0x0FC0) },
  504. { 0 }
  505. };
  506. MODULE_DEVICE_TABLE(pci, idio_24_pci_dev_id);
  507. static struct pci_driver idio_24_driver = {
  508. .name = "pcie-idio-24",
  509. .id_table = idio_24_pci_dev_id,
  510. .probe = idio_24_probe
  511. };
  512. module_pci_driver(idio_24_driver);
  513. MODULE_AUTHOR("William Breathitt Gray <vilhelm.gray@gmail.com>");
  514. MODULE_DESCRIPTION("ACCES PCIe-IDIO-24 GPIO driver");
  515. MODULE_LICENSE("GPL v2");