gpio-mvebu.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152
  1. /*
  2. * GPIO driver for Marvell SoCs
  3. *
  4. * Copyright (C) 2012 Marvell
  5. *
  6. * Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
  7. * Andrew Lunn <andrew@lunn.ch>
  8. * Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
  9. *
  10. * This file is licensed under the terms of the GNU General Public
  11. * License version 2. This program is licensed "as is" without any
  12. * warranty of any kind, whether express or implied.
  13. *
  14. * This driver is a fairly straightforward GPIO driver for the
  15. * complete family of Marvell EBU SoC platforms (Orion, Dove,
  16. * Kirkwood, Discovery, Armada 370/XP). The only complexity of this
  17. * driver is the different register layout that exists between the
  18. * non-SMP platforms (Orion, Dove, Kirkwood, Armada 370) and the SMP
  19. * platforms (MV78200 from the Discovery family and the Armada
  20. * XP). Therefore, this driver handles three variants of the GPIO
  21. * block:
  22. * - the basic variant, called "orion-gpio", with the simplest
  23. * register set. Used on Orion, Dove, Kirkwoord, Armada 370 and
  24. * non-SMP Discovery systems
  25. * - the mv78200 variant for MV78200 Discovery systems. This variant
  26. * turns the edge mask and level mask registers into CPU0 edge
  27. * mask/level mask registers, and adds CPU1 edge mask/level mask
  28. * registers.
  29. * - the armadaxp variant for Armada XP systems. This variant keeps
  30. * the normal cause/edge mask/level mask registers when the global
  31. * interrupts are used, but adds per-CPU cause/edge mask/level mask
  32. * registers n a separate memory area for the per-CPU GPIO
  33. * interrupts.
  34. */
  35. #include <linux/err.h>
  36. #include <linux/init.h>
  37. #include <linux/gpio.h>
  38. #include <linux/irq.h>
  39. #include <linux/slab.h>
  40. #include <linux/irqdomain.h>
  41. #include <linux/io.h>
  42. #include <linux/of_irq.h>
  43. #include <linux/of_device.h>
  44. #include <linux/pwm.h>
  45. #include <linux/clk.h>
  46. #include <linux/pinctrl/consumer.h>
  47. #include <linux/irqchip/chained_irq.h>
  48. #include <linux/platform_device.h>
  49. #include <linux/bitops.h>
  50. #include "gpiolib.h"
  51. /*
  52. * GPIO unit register offsets.
  53. */
  54. #define GPIO_OUT_OFF 0x0000
  55. #define GPIO_IO_CONF_OFF 0x0004
  56. #define GPIO_BLINK_EN_OFF 0x0008
  57. #define GPIO_IN_POL_OFF 0x000c
  58. #define GPIO_DATA_IN_OFF 0x0010
  59. #define GPIO_EDGE_CAUSE_OFF 0x0014
  60. #define GPIO_EDGE_MASK_OFF 0x0018
  61. #define GPIO_LEVEL_MASK_OFF 0x001c
  62. #define GPIO_BLINK_CNT_SELECT_OFF 0x0020
  63. /*
  64. * PWM register offsets.
  65. */
  66. #define PWM_BLINK_ON_DURATION_OFF 0x0
  67. #define PWM_BLINK_OFF_DURATION_OFF 0x4
  68. /* The MV78200 has per-CPU registers for edge mask and level mask */
  69. #define GPIO_EDGE_MASK_MV78200_OFF(cpu) ((cpu) ? 0x30 : 0x18)
  70. #define GPIO_LEVEL_MASK_MV78200_OFF(cpu) ((cpu) ? 0x34 : 0x1C)
  71. /*
  72. * The Armada XP has per-CPU registers for interrupt cause, interrupt
  73. * mask and interrupt level mask. Those are relative to the
  74. * percpu_membase.
  75. */
  76. #define GPIO_EDGE_CAUSE_ARMADAXP_OFF(cpu) ((cpu) * 0x4)
  77. #define GPIO_EDGE_MASK_ARMADAXP_OFF(cpu) (0x10 + (cpu) * 0x4)
  78. #define GPIO_LEVEL_MASK_ARMADAXP_OFF(cpu) (0x20 + (cpu) * 0x4)
  79. #define MVEBU_GPIO_SOC_VARIANT_ORION 0x1
  80. #define MVEBU_GPIO_SOC_VARIANT_MV78200 0x2
  81. #define MVEBU_GPIO_SOC_VARIANT_ARMADAXP 0x3
  82. #define MVEBU_MAX_GPIO_PER_BANK 32
  83. struct mvebu_pwm {
  84. void __iomem *membase;
  85. unsigned long clk_rate;
  86. struct gpio_desc *gpiod;
  87. struct pwm_chip chip;
  88. spinlock_t lock;
  89. struct mvebu_gpio_chip *mvchip;
  90. /* Used to preserve GPIO/PWM registers across suspend/resume */
  91. u32 blink_select;
  92. u32 blink_on_duration;
  93. u32 blink_off_duration;
  94. };
  95. struct mvebu_gpio_chip {
  96. struct gpio_chip chip;
  97. spinlock_t lock;
  98. void __iomem *membase;
  99. void __iomem *percpu_membase;
  100. int irqbase;
  101. struct irq_domain *domain;
  102. int soc_variant;
  103. /* Used for PWM support */
  104. struct clk *clk;
  105. struct mvebu_pwm *mvpwm;
  106. /* Used to preserve GPIO registers across suspend/resume */
  107. u32 out_reg;
  108. u32 io_conf_reg;
  109. u32 blink_en_reg;
  110. u32 in_pol_reg;
  111. u32 edge_mask_regs[4];
  112. u32 level_mask_regs[4];
  113. };
  114. /*
  115. * Functions returning addresses of individual registers for a given
  116. * GPIO controller.
  117. */
  118. static void __iomem *mvebu_gpioreg_out(struct mvebu_gpio_chip *mvchip)
  119. {
  120. return mvchip->membase + GPIO_OUT_OFF;
  121. }
  122. static void __iomem *mvebu_gpioreg_blink(struct mvebu_gpio_chip *mvchip)
  123. {
  124. return mvchip->membase + GPIO_BLINK_EN_OFF;
  125. }
  126. static void __iomem *mvebu_gpioreg_blink_counter_select(struct mvebu_gpio_chip
  127. *mvchip)
  128. {
  129. return mvchip->membase + GPIO_BLINK_CNT_SELECT_OFF;
  130. }
  131. static void __iomem *mvebu_gpioreg_io_conf(struct mvebu_gpio_chip *mvchip)
  132. {
  133. return mvchip->membase + GPIO_IO_CONF_OFF;
  134. }
  135. static void __iomem *mvebu_gpioreg_in_pol(struct mvebu_gpio_chip *mvchip)
  136. {
  137. return mvchip->membase + GPIO_IN_POL_OFF;
  138. }
  139. static void __iomem *mvebu_gpioreg_data_in(struct mvebu_gpio_chip *mvchip)
  140. {
  141. return mvchip->membase + GPIO_DATA_IN_OFF;
  142. }
  143. static void __iomem *mvebu_gpioreg_edge_cause(struct mvebu_gpio_chip *mvchip)
  144. {
  145. int cpu;
  146. switch (mvchip->soc_variant) {
  147. case MVEBU_GPIO_SOC_VARIANT_ORION:
  148. case MVEBU_GPIO_SOC_VARIANT_MV78200:
  149. return mvchip->membase + GPIO_EDGE_CAUSE_OFF;
  150. case MVEBU_GPIO_SOC_VARIANT_ARMADAXP:
  151. cpu = smp_processor_id();
  152. return mvchip->percpu_membase +
  153. GPIO_EDGE_CAUSE_ARMADAXP_OFF(cpu);
  154. default:
  155. BUG();
  156. }
  157. }
  158. static void __iomem *mvebu_gpioreg_edge_mask(struct mvebu_gpio_chip *mvchip)
  159. {
  160. int cpu;
  161. switch (mvchip->soc_variant) {
  162. case MVEBU_GPIO_SOC_VARIANT_ORION:
  163. return mvchip->membase + GPIO_EDGE_MASK_OFF;
  164. case MVEBU_GPIO_SOC_VARIANT_MV78200:
  165. cpu = smp_processor_id();
  166. return mvchip->membase + GPIO_EDGE_MASK_MV78200_OFF(cpu);
  167. case MVEBU_GPIO_SOC_VARIANT_ARMADAXP:
  168. cpu = smp_processor_id();
  169. return mvchip->percpu_membase +
  170. GPIO_EDGE_MASK_ARMADAXP_OFF(cpu);
  171. default:
  172. BUG();
  173. }
  174. }
  175. static void __iomem *mvebu_gpioreg_level_mask(struct mvebu_gpio_chip *mvchip)
  176. {
  177. int cpu;
  178. switch (mvchip->soc_variant) {
  179. case MVEBU_GPIO_SOC_VARIANT_ORION:
  180. return mvchip->membase + GPIO_LEVEL_MASK_OFF;
  181. case MVEBU_GPIO_SOC_VARIANT_MV78200:
  182. cpu = smp_processor_id();
  183. return mvchip->membase + GPIO_LEVEL_MASK_MV78200_OFF(cpu);
  184. case MVEBU_GPIO_SOC_VARIANT_ARMADAXP:
  185. cpu = smp_processor_id();
  186. return mvchip->percpu_membase +
  187. GPIO_LEVEL_MASK_ARMADAXP_OFF(cpu);
  188. default:
  189. BUG();
  190. }
  191. }
  192. /*
  193. * Functions returning addresses of individual registers for a given
  194. * PWM controller.
  195. */
  196. static void __iomem *mvebu_pwmreg_blink_on_duration(struct mvebu_pwm *mvpwm)
  197. {
  198. return mvpwm->membase + PWM_BLINK_ON_DURATION_OFF;
  199. }
  200. static void __iomem *mvebu_pwmreg_blink_off_duration(struct mvebu_pwm *mvpwm)
  201. {
  202. return mvpwm->membase + PWM_BLINK_OFF_DURATION_OFF;
  203. }
  204. /*
  205. * Functions implementing the gpio_chip methods
  206. */
  207. static void mvebu_gpio_set(struct gpio_chip *chip, unsigned int pin, int value)
  208. {
  209. struct mvebu_gpio_chip *mvchip = gpiochip_get_data(chip);
  210. unsigned long flags;
  211. u32 u;
  212. spin_lock_irqsave(&mvchip->lock, flags);
  213. u = readl_relaxed(mvebu_gpioreg_out(mvchip));
  214. if (value)
  215. u |= BIT(pin);
  216. else
  217. u &= ~BIT(pin);
  218. writel_relaxed(u, mvebu_gpioreg_out(mvchip));
  219. spin_unlock_irqrestore(&mvchip->lock, flags);
  220. }
  221. static int mvebu_gpio_get(struct gpio_chip *chip, unsigned int pin)
  222. {
  223. struct mvebu_gpio_chip *mvchip = gpiochip_get_data(chip);
  224. u32 u;
  225. if (readl_relaxed(mvebu_gpioreg_io_conf(mvchip)) & BIT(pin)) {
  226. u = readl_relaxed(mvebu_gpioreg_data_in(mvchip)) ^
  227. readl_relaxed(mvebu_gpioreg_in_pol(mvchip));
  228. } else {
  229. u = readl_relaxed(mvebu_gpioreg_out(mvchip));
  230. }
  231. return (u >> pin) & 1;
  232. }
  233. static void mvebu_gpio_blink(struct gpio_chip *chip, unsigned int pin,
  234. int value)
  235. {
  236. struct mvebu_gpio_chip *mvchip = gpiochip_get_data(chip);
  237. unsigned long flags;
  238. u32 u;
  239. spin_lock_irqsave(&mvchip->lock, flags);
  240. u = readl_relaxed(mvebu_gpioreg_blink(mvchip));
  241. if (value)
  242. u |= BIT(pin);
  243. else
  244. u &= ~BIT(pin);
  245. writel_relaxed(u, mvebu_gpioreg_blink(mvchip));
  246. spin_unlock_irqrestore(&mvchip->lock, flags);
  247. }
  248. static int mvebu_gpio_direction_input(struct gpio_chip *chip, unsigned int pin)
  249. {
  250. struct mvebu_gpio_chip *mvchip = gpiochip_get_data(chip);
  251. unsigned long flags;
  252. int ret;
  253. u32 u;
  254. /*
  255. * Check with the pinctrl driver whether this pin is usable as
  256. * an input GPIO
  257. */
  258. ret = pinctrl_gpio_direction_input(chip->base + pin);
  259. if (ret)
  260. return ret;
  261. spin_lock_irqsave(&mvchip->lock, flags);
  262. u = readl_relaxed(mvebu_gpioreg_io_conf(mvchip));
  263. u |= BIT(pin);
  264. writel_relaxed(u, mvebu_gpioreg_io_conf(mvchip));
  265. spin_unlock_irqrestore(&mvchip->lock, flags);
  266. return 0;
  267. }
  268. static int mvebu_gpio_direction_output(struct gpio_chip *chip, unsigned int pin,
  269. int value)
  270. {
  271. struct mvebu_gpio_chip *mvchip = gpiochip_get_data(chip);
  272. unsigned long flags;
  273. int ret;
  274. u32 u;
  275. /*
  276. * Check with the pinctrl driver whether this pin is usable as
  277. * an output GPIO
  278. */
  279. ret = pinctrl_gpio_direction_output(chip->base + pin);
  280. if (ret)
  281. return ret;
  282. mvebu_gpio_blink(chip, pin, 0);
  283. mvebu_gpio_set(chip, pin, value);
  284. spin_lock_irqsave(&mvchip->lock, flags);
  285. u = readl_relaxed(mvebu_gpioreg_io_conf(mvchip));
  286. u &= ~BIT(pin);
  287. writel_relaxed(u, mvebu_gpioreg_io_conf(mvchip));
  288. spin_unlock_irqrestore(&mvchip->lock, flags);
  289. return 0;
  290. }
  291. static int mvebu_gpio_to_irq(struct gpio_chip *chip, unsigned int pin)
  292. {
  293. struct mvebu_gpio_chip *mvchip = gpiochip_get_data(chip);
  294. return irq_create_mapping(mvchip->domain, pin);
  295. }
  296. /*
  297. * Functions implementing the irq_chip methods
  298. */
  299. static void mvebu_gpio_irq_ack(struct irq_data *d)
  300. {
  301. struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
  302. struct mvebu_gpio_chip *mvchip = gc->private;
  303. u32 mask = d->mask;
  304. irq_gc_lock(gc);
  305. writel_relaxed(~mask, mvebu_gpioreg_edge_cause(mvchip));
  306. irq_gc_unlock(gc);
  307. }
  308. static void mvebu_gpio_edge_irq_mask(struct irq_data *d)
  309. {
  310. struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
  311. struct mvebu_gpio_chip *mvchip = gc->private;
  312. struct irq_chip_type *ct = irq_data_get_chip_type(d);
  313. u32 mask = d->mask;
  314. irq_gc_lock(gc);
  315. ct->mask_cache_priv &= ~mask;
  316. writel_relaxed(ct->mask_cache_priv, mvebu_gpioreg_edge_mask(mvchip));
  317. irq_gc_unlock(gc);
  318. }
  319. static void mvebu_gpio_edge_irq_unmask(struct irq_data *d)
  320. {
  321. struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
  322. struct mvebu_gpio_chip *mvchip = gc->private;
  323. struct irq_chip_type *ct = irq_data_get_chip_type(d);
  324. u32 mask = d->mask;
  325. irq_gc_lock(gc);
  326. ct->mask_cache_priv |= mask;
  327. writel_relaxed(ct->mask_cache_priv, mvebu_gpioreg_edge_mask(mvchip));
  328. irq_gc_unlock(gc);
  329. }
  330. static void mvebu_gpio_level_irq_mask(struct irq_data *d)
  331. {
  332. struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
  333. struct mvebu_gpio_chip *mvchip = gc->private;
  334. struct irq_chip_type *ct = irq_data_get_chip_type(d);
  335. u32 mask = d->mask;
  336. irq_gc_lock(gc);
  337. ct->mask_cache_priv &= ~mask;
  338. writel_relaxed(ct->mask_cache_priv, mvebu_gpioreg_level_mask(mvchip));
  339. irq_gc_unlock(gc);
  340. }
  341. static void mvebu_gpio_level_irq_unmask(struct irq_data *d)
  342. {
  343. struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
  344. struct mvebu_gpio_chip *mvchip = gc->private;
  345. struct irq_chip_type *ct = irq_data_get_chip_type(d);
  346. u32 mask = d->mask;
  347. irq_gc_lock(gc);
  348. ct->mask_cache_priv |= mask;
  349. writel_relaxed(ct->mask_cache_priv, mvebu_gpioreg_level_mask(mvchip));
  350. irq_gc_unlock(gc);
  351. }
  352. /*****************************************************************************
  353. * MVEBU GPIO IRQ
  354. *
  355. * GPIO_IN_POL register controls whether GPIO_DATA_IN will hold the same
  356. * value of the line or the opposite value.
  357. *
  358. * Level IRQ handlers: DATA_IN is used directly as cause register.
  359. * Interrupt are masked by LEVEL_MASK registers.
  360. * Edge IRQ handlers: Change in DATA_IN are latched in EDGE_CAUSE.
  361. * Interrupt are masked by EDGE_MASK registers.
  362. * Both-edge handlers: Similar to regular Edge handlers, but also swaps
  363. * the polarity to catch the next line transaction.
  364. * This is a race condition that might not perfectly
  365. * work on some use cases.
  366. *
  367. * Every eight GPIO lines are grouped (OR'ed) before going up to main
  368. * cause register.
  369. *
  370. * EDGE cause mask
  371. * data-in /--------| |-----| |----\
  372. * -----| |----- ---- to main cause reg
  373. * X \----------------| |----/
  374. * polarity LEVEL mask
  375. *
  376. ****************************************************************************/
  377. static int mvebu_gpio_irq_set_type(struct irq_data *d, unsigned int type)
  378. {
  379. struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
  380. struct irq_chip_type *ct = irq_data_get_chip_type(d);
  381. struct mvebu_gpio_chip *mvchip = gc->private;
  382. int pin;
  383. u32 u;
  384. pin = d->hwirq;
  385. u = readl_relaxed(mvebu_gpioreg_io_conf(mvchip)) & BIT(pin);
  386. if (!u)
  387. return -EINVAL;
  388. type &= IRQ_TYPE_SENSE_MASK;
  389. if (type == IRQ_TYPE_NONE)
  390. return -EINVAL;
  391. /* Check if we need to change chip and handler */
  392. if (!(ct->type & type))
  393. if (irq_setup_alt_chip(d, type))
  394. return -EINVAL;
  395. /*
  396. * Configure interrupt polarity.
  397. */
  398. switch (type) {
  399. case IRQ_TYPE_EDGE_RISING:
  400. case IRQ_TYPE_LEVEL_HIGH:
  401. u = readl_relaxed(mvebu_gpioreg_in_pol(mvchip));
  402. u &= ~BIT(pin);
  403. writel_relaxed(u, mvebu_gpioreg_in_pol(mvchip));
  404. break;
  405. case IRQ_TYPE_EDGE_FALLING:
  406. case IRQ_TYPE_LEVEL_LOW:
  407. u = readl_relaxed(mvebu_gpioreg_in_pol(mvchip));
  408. u |= BIT(pin);
  409. writel_relaxed(u, mvebu_gpioreg_in_pol(mvchip));
  410. break;
  411. case IRQ_TYPE_EDGE_BOTH: {
  412. u32 v;
  413. v = readl_relaxed(mvebu_gpioreg_in_pol(mvchip)) ^
  414. readl_relaxed(mvebu_gpioreg_data_in(mvchip));
  415. /*
  416. * set initial polarity based on current input level
  417. */
  418. u = readl_relaxed(mvebu_gpioreg_in_pol(mvchip));
  419. if (v & BIT(pin))
  420. u |= BIT(pin); /* falling */
  421. else
  422. u &= ~BIT(pin); /* rising */
  423. writel_relaxed(u, mvebu_gpioreg_in_pol(mvchip));
  424. break;
  425. }
  426. }
  427. return 0;
  428. }
  429. static void mvebu_gpio_irq_handler(struct irq_desc *desc)
  430. {
  431. struct mvebu_gpio_chip *mvchip = irq_desc_get_handler_data(desc);
  432. struct irq_chip *chip = irq_desc_get_chip(desc);
  433. u32 cause, type;
  434. int i;
  435. if (mvchip == NULL)
  436. return;
  437. chained_irq_enter(chip, desc);
  438. cause = readl_relaxed(mvebu_gpioreg_data_in(mvchip)) &
  439. readl_relaxed(mvebu_gpioreg_level_mask(mvchip));
  440. cause |= readl_relaxed(mvebu_gpioreg_edge_cause(mvchip)) &
  441. readl_relaxed(mvebu_gpioreg_edge_mask(mvchip));
  442. for (i = 0; i < mvchip->chip.ngpio; i++) {
  443. int irq;
  444. irq = irq_find_mapping(mvchip->domain, i);
  445. if (!(cause & BIT(i)))
  446. continue;
  447. type = irq_get_trigger_type(irq);
  448. if ((type & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH) {
  449. /* Swap polarity (race with GPIO line) */
  450. u32 polarity;
  451. polarity = readl_relaxed(mvebu_gpioreg_in_pol(mvchip));
  452. polarity ^= BIT(i);
  453. writel_relaxed(polarity, mvebu_gpioreg_in_pol(mvchip));
  454. }
  455. generic_handle_irq(irq);
  456. }
  457. chained_irq_exit(chip, desc);
  458. }
  459. /*
  460. * Functions implementing the pwm_chip methods
  461. */
  462. static struct mvebu_pwm *to_mvebu_pwm(struct pwm_chip *chip)
  463. {
  464. return container_of(chip, struct mvebu_pwm, chip);
  465. }
  466. static int mvebu_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)
  467. {
  468. struct mvebu_pwm *mvpwm = to_mvebu_pwm(chip);
  469. struct mvebu_gpio_chip *mvchip = mvpwm->mvchip;
  470. struct gpio_desc *desc;
  471. unsigned long flags;
  472. int ret = 0;
  473. spin_lock_irqsave(&mvpwm->lock, flags);
  474. if (mvpwm->gpiod) {
  475. ret = -EBUSY;
  476. } else {
  477. desc = gpio_to_desc(mvchip->chip.base + pwm->hwpwm);
  478. if (!desc) {
  479. ret = -ENODEV;
  480. goto out;
  481. }
  482. ret = gpiod_request(desc, "mvebu-pwm");
  483. if (ret)
  484. goto out;
  485. ret = gpiod_direction_output(desc, 0);
  486. if (ret) {
  487. gpiod_free(desc);
  488. goto out;
  489. }
  490. mvpwm->gpiod = desc;
  491. }
  492. out:
  493. spin_unlock_irqrestore(&mvpwm->lock, flags);
  494. return ret;
  495. }
  496. static void mvebu_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)
  497. {
  498. struct mvebu_pwm *mvpwm = to_mvebu_pwm(chip);
  499. unsigned long flags;
  500. spin_lock_irqsave(&mvpwm->lock, flags);
  501. gpiod_free(mvpwm->gpiod);
  502. mvpwm->gpiod = NULL;
  503. spin_unlock_irqrestore(&mvpwm->lock, flags);
  504. }
  505. static void mvebu_pwm_get_state(struct pwm_chip *chip,
  506. struct pwm_device *pwm,
  507. struct pwm_state *state) {
  508. struct mvebu_pwm *mvpwm = to_mvebu_pwm(chip);
  509. struct mvebu_gpio_chip *mvchip = mvpwm->mvchip;
  510. unsigned long long val;
  511. unsigned long flags;
  512. u32 u;
  513. spin_lock_irqsave(&mvpwm->lock, flags);
  514. val = (unsigned long long)
  515. readl_relaxed(mvebu_pwmreg_blink_on_duration(mvpwm));
  516. val *= NSEC_PER_SEC;
  517. do_div(val, mvpwm->clk_rate);
  518. if (val > UINT_MAX)
  519. state->duty_cycle = UINT_MAX;
  520. else if (val)
  521. state->duty_cycle = val;
  522. else
  523. state->duty_cycle = 1;
  524. val = (unsigned long long)
  525. readl_relaxed(mvebu_pwmreg_blink_off_duration(mvpwm));
  526. val *= NSEC_PER_SEC;
  527. do_div(val, mvpwm->clk_rate);
  528. if (val < state->duty_cycle) {
  529. state->period = 1;
  530. } else {
  531. val -= state->duty_cycle;
  532. if (val > UINT_MAX)
  533. state->period = UINT_MAX;
  534. else if (val)
  535. state->period = val;
  536. else
  537. state->period = 1;
  538. }
  539. u = readl_relaxed(mvebu_gpioreg_blink(mvchip));
  540. if (u)
  541. state->enabled = true;
  542. else
  543. state->enabled = false;
  544. spin_unlock_irqrestore(&mvpwm->lock, flags);
  545. }
  546. static int mvebu_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
  547. struct pwm_state *state)
  548. {
  549. struct mvebu_pwm *mvpwm = to_mvebu_pwm(chip);
  550. struct mvebu_gpio_chip *mvchip = mvpwm->mvchip;
  551. unsigned long long val;
  552. unsigned long flags;
  553. unsigned int on, off;
  554. val = (unsigned long long) mvpwm->clk_rate * state->duty_cycle;
  555. do_div(val, NSEC_PER_SEC);
  556. if (val > UINT_MAX)
  557. return -EINVAL;
  558. if (val)
  559. on = val;
  560. else
  561. on = 1;
  562. val = (unsigned long long) mvpwm->clk_rate *
  563. (state->period - state->duty_cycle);
  564. do_div(val, NSEC_PER_SEC);
  565. if (val > UINT_MAX)
  566. return -EINVAL;
  567. if (val)
  568. off = val;
  569. else
  570. off = 1;
  571. spin_lock_irqsave(&mvpwm->lock, flags);
  572. writel_relaxed(on, mvebu_pwmreg_blink_on_duration(mvpwm));
  573. writel_relaxed(off, mvebu_pwmreg_blink_off_duration(mvpwm));
  574. if (state->enabled)
  575. mvebu_gpio_blink(&mvchip->chip, pwm->hwpwm, 1);
  576. else
  577. mvebu_gpio_blink(&mvchip->chip, pwm->hwpwm, 0);
  578. spin_unlock_irqrestore(&mvpwm->lock, flags);
  579. return 0;
  580. }
  581. static const struct pwm_ops mvebu_pwm_ops = {
  582. .request = mvebu_pwm_request,
  583. .free = mvebu_pwm_free,
  584. .get_state = mvebu_pwm_get_state,
  585. .apply = mvebu_pwm_apply,
  586. .owner = THIS_MODULE,
  587. };
  588. static void __maybe_unused mvebu_pwm_suspend(struct mvebu_gpio_chip *mvchip)
  589. {
  590. struct mvebu_pwm *mvpwm = mvchip->mvpwm;
  591. mvpwm->blink_select =
  592. readl_relaxed(mvebu_gpioreg_blink_counter_select(mvchip));
  593. mvpwm->blink_on_duration =
  594. readl_relaxed(mvebu_pwmreg_blink_on_duration(mvpwm));
  595. mvpwm->blink_off_duration =
  596. readl_relaxed(mvebu_pwmreg_blink_off_duration(mvpwm));
  597. }
  598. static void __maybe_unused mvebu_pwm_resume(struct mvebu_gpio_chip *mvchip)
  599. {
  600. struct mvebu_pwm *mvpwm = mvchip->mvpwm;
  601. writel_relaxed(mvpwm->blink_select,
  602. mvebu_gpioreg_blink_counter_select(mvchip));
  603. writel_relaxed(mvpwm->blink_on_duration,
  604. mvebu_pwmreg_blink_on_duration(mvpwm));
  605. writel_relaxed(mvpwm->blink_off_duration,
  606. mvebu_pwmreg_blink_off_duration(mvpwm));
  607. }
  608. static int mvebu_pwm_probe(struct platform_device *pdev,
  609. struct mvebu_gpio_chip *mvchip,
  610. int id)
  611. {
  612. struct device *dev = &pdev->dev;
  613. struct mvebu_pwm *mvpwm;
  614. struct resource *res;
  615. u32 set;
  616. if (!of_device_is_compatible(mvchip->chip.of_node,
  617. "marvell,armada-370-xp-gpio"))
  618. return 0;
  619. if (IS_ERR(mvchip->clk))
  620. return PTR_ERR(mvchip->clk);
  621. /*
  622. * There are only two sets of PWM configuration registers for
  623. * all the GPIO lines on those SoCs which this driver reserves
  624. * for the first two GPIO chips. So if the resource is missing
  625. * we can't treat it as an error.
  626. */
  627. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pwm");
  628. if (!res)
  629. return 0;
  630. /*
  631. * Use set A for lines of GPIO chip with id 0, B for GPIO chip
  632. * with id 1. Don't allow further GPIO chips to be used for PWM.
  633. */
  634. if (id == 0)
  635. set = 0;
  636. else if (id == 1)
  637. set = U32_MAX;
  638. else
  639. return -EINVAL;
  640. writel_relaxed(set, mvebu_gpioreg_blink_counter_select(mvchip));
  641. mvpwm = devm_kzalloc(dev, sizeof(struct mvebu_pwm), GFP_KERNEL);
  642. if (!mvpwm)
  643. return -ENOMEM;
  644. mvchip->mvpwm = mvpwm;
  645. mvpwm->mvchip = mvchip;
  646. mvpwm->membase = devm_ioremap_resource(dev, res);
  647. if (IS_ERR(mvpwm->membase))
  648. return PTR_ERR(mvpwm->membase);
  649. mvpwm->clk_rate = clk_get_rate(mvchip->clk);
  650. if (!mvpwm->clk_rate) {
  651. dev_err(dev, "failed to get clock rate\n");
  652. return -EINVAL;
  653. }
  654. mvpwm->chip.dev = dev;
  655. mvpwm->chip.ops = &mvebu_pwm_ops;
  656. mvpwm->chip.npwm = mvchip->chip.ngpio;
  657. /*
  658. * There may already be some PWM allocated, so we can't force
  659. * mvpwm->chip.base to a fixed point like mvchip->chip.base.
  660. * So, we let pwmchip_add() do the numbering and take the next free
  661. * region.
  662. */
  663. mvpwm->chip.base = -1;
  664. spin_lock_init(&mvpwm->lock);
  665. return pwmchip_add(&mvpwm->chip);
  666. }
  667. #ifdef CONFIG_DEBUG_FS
  668. #include <linux/seq_file.h>
  669. static void mvebu_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
  670. {
  671. struct mvebu_gpio_chip *mvchip = gpiochip_get_data(chip);
  672. u32 out, io_conf, blink, in_pol, data_in, cause, edg_msk, lvl_msk;
  673. int i;
  674. out = readl_relaxed(mvebu_gpioreg_out(mvchip));
  675. io_conf = readl_relaxed(mvebu_gpioreg_io_conf(mvchip));
  676. blink = readl_relaxed(mvebu_gpioreg_blink(mvchip));
  677. in_pol = readl_relaxed(mvebu_gpioreg_in_pol(mvchip));
  678. data_in = readl_relaxed(mvebu_gpioreg_data_in(mvchip));
  679. cause = readl_relaxed(mvebu_gpioreg_edge_cause(mvchip));
  680. edg_msk = readl_relaxed(mvebu_gpioreg_edge_mask(mvchip));
  681. lvl_msk = readl_relaxed(mvebu_gpioreg_level_mask(mvchip));
  682. for (i = 0; i < chip->ngpio; i++) {
  683. const char *label;
  684. u32 msk;
  685. bool is_out;
  686. label = gpiochip_is_requested(chip, i);
  687. if (!label)
  688. continue;
  689. msk = BIT(i);
  690. is_out = !(io_conf & msk);
  691. seq_printf(s, " gpio-%-3d (%-20.20s)", chip->base + i, label);
  692. if (is_out) {
  693. seq_printf(s, " out %s %s\n",
  694. out & msk ? "hi" : "lo",
  695. blink & msk ? "(blink )" : "");
  696. continue;
  697. }
  698. seq_printf(s, " in %s (act %s) - IRQ",
  699. (data_in ^ in_pol) & msk ? "hi" : "lo",
  700. in_pol & msk ? "lo" : "hi");
  701. if (!((edg_msk | lvl_msk) & msk)) {
  702. seq_puts(s, " disabled\n");
  703. continue;
  704. }
  705. if (edg_msk & msk)
  706. seq_puts(s, " edge ");
  707. if (lvl_msk & msk)
  708. seq_puts(s, " level");
  709. seq_printf(s, " (%s)\n", cause & msk ? "pending" : "clear ");
  710. }
  711. }
  712. #else
  713. #define mvebu_gpio_dbg_show NULL
  714. #endif
  715. static const struct of_device_id mvebu_gpio_of_match[] = {
  716. {
  717. .compatible = "marvell,orion-gpio",
  718. .data = (void *) MVEBU_GPIO_SOC_VARIANT_ORION,
  719. },
  720. {
  721. .compatible = "marvell,mv78200-gpio",
  722. .data = (void *) MVEBU_GPIO_SOC_VARIANT_MV78200,
  723. },
  724. {
  725. .compatible = "marvell,armadaxp-gpio",
  726. .data = (void *) MVEBU_GPIO_SOC_VARIANT_ARMADAXP,
  727. },
  728. {
  729. .compatible = "marvell,armada-370-xp-gpio",
  730. .data = (void *) MVEBU_GPIO_SOC_VARIANT_ORION,
  731. },
  732. {
  733. /* sentinel */
  734. },
  735. };
  736. static int mvebu_gpio_suspend(struct platform_device *pdev, pm_message_t state)
  737. {
  738. struct mvebu_gpio_chip *mvchip = platform_get_drvdata(pdev);
  739. int i;
  740. mvchip->out_reg = readl(mvebu_gpioreg_out(mvchip));
  741. mvchip->io_conf_reg = readl(mvebu_gpioreg_io_conf(mvchip));
  742. mvchip->blink_en_reg = readl(mvebu_gpioreg_blink(mvchip));
  743. mvchip->in_pol_reg = readl(mvebu_gpioreg_in_pol(mvchip));
  744. switch (mvchip->soc_variant) {
  745. case MVEBU_GPIO_SOC_VARIANT_ORION:
  746. mvchip->edge_mask_regs[0] =
  747. readl(mvchip->membase + GPIO_EDGE_MASK_OFF);
  748. mvchip->level_mask_regs[0] =
  749. readl(mvchip->membase + GPIO_LEVEL_MASK_OFF);
  750. break;
  751. case MVEBU_GPIO_SOC_VARIANT_MV78200:
  752. for (i = 0; i < 2; i++) {
  753. mvchip->edge_mask_regs[i] =
  754. readl(mvchip->membase +
  755. GPIO_EDGE_MASK_MV78200_OFF(i));
  756. mvchip->level_mask_regs[i] =
  757. readl(mvchip->membase +
  758. GPIO_LEVEL_MASK_MV78200_OFF(i));
  759. }
  760. break;
  761. case MVEBU_GPIO_SOC_VARIANT_ARMADAXP:
  762. for (i = 0; i < 4; i++) {
  763. mvchip->edge_mask_regs[i] =
  764. readl(mvchip->membase +
  765. GPIO_EDGE_MASK_ARMADAXP_OFF(i));
  766. mvchip->level_mask_regs[i] =
  767. readl(mvchip->membase +
  768. GPIO_LEVEL_MASK_ARMADAXP_OFF(i));
  769. }
  770. break;
  771. default:
  772. BUG();
  773. }
  774. if (IS_ENABLED(CONFIG_PWM))
  775. mvebu_pwm_suspend(mvchip);
  776. return 0;
  777. }
  778. static int mvebu_gpio_resume(struct platform_device *pdev)
  779. {
  780. struct mvebu_gpio_chip *mvchip = platform_get_drvdata(pdev);
  781. int i;
  782. writel(mvchip->out_reg, mvebu_gpioreg_out(mvchip));
  783. writel(mvchip->io_conf_reg, mvebu_gpioreg_io_conf(mvchip));
  784. writel(mvchip->blink_en_reg, mvebu_gpioreg_blink(mvchip));
  785. writel(mvchip->in_pol_reg, mvebu_gpioreg_in_pol(mvchip));
  786. switch (mvchip->soc_variant) {
  787. case MVEBU_GPIO_SOC_VARIANT_ORION:
  788. writel(mvchip->edge_mask_regs[0],
  789. mvchip->membase + GPIO_EDGE_MASK_OFF);
  790. writel(mvchip->level_mask_regs[0],
  791. mvchip->membase + GPIO_LEVEL_MASK_OFF);
  792. break;
  793. case MVEBU_GPIO_SOC_VARIANT_MV78200:
  794. for (i = 0; i < 2; i++) {
  795. writel(mvchip->edge_mask_regs[i],
  796. mvchip->membase + GPIO_EDGE_MASK_MV78200_OFF(i));
  797. writel(mvchip->level_mask_regs[i],
  798. mvchip->membase +
  799. GPIO_LEVEL_MASK_MV78200_OFF(i));
  800. }
  801. break;
  802. case MVEBU_GPIO_SOC_VARIANT_ARMADAXP:
  803. for (i = 0; i < 4; i++) {
  804. writel(mvchip->edge_mask_regs[i],
  805. mvchip->membase +
  806. GPIO_EDGE_MASK_ARMADAXP_OFF(i));
  807. writel(mvchip->level_mask_regs[i],
  808. mvchip->membase +
  809. GPIO_LEVEL_MASK_ARMADAXP_OFF(i));
  810. }
  811. break;
  812. default:
  813. BUG();
  814. }
  815. if (IS_ENABLED(CONFIG_PWM))
  816. mvebu_pwm_resume(mvchip);
  817. return 0;
  818. }
  819. static int mvebu_gpio_probe(struct platform_device *pdev)
  820. {
  821. struct mvebu_gpio_chip *mvchip;
  822. const struct of_device_id *match;
  823. struct device_node *np = pdev->dev.of_node;
  824. struct resource *res;
  825. struct irq_chip_generic *gc;
  826. struct irq_chip_type *ct;
  827. unsigned int ngpios;
  828. bool have_irqs;
  829. int soc_variant;
  830. int i, cpu, id;
  831. int err;
  832. match = of_match_device(mvebu_gpio_of_match, &pdev->dev);
  833. if (match)
  834. soc_variant = (unsigned long) match->data;
  835. else
  836. soc_variant = MVEBU_GPIO_SOC_VARIANT_ORION;
  837. /* Some gpio controllers do not provide irq support */
  838. have_irqs = of_irq_count(np) != 0;
  839. mvchip = devm_kzalloc(&pdev->dev, sizeof(struct mvebu_gpio_chip),
  840. GFP_KERNEL);
  841. if (!mvchip)
  842. return -ENOMEM;
  843. platform_set_drvdata(pdev, mvchip);
  844. if (of_property_read_u32(pdev->dev.of_node, "ngpios", &ngpios)) {
  845. dev_err(&pdev->dev, "Missing ngpios OF property\n");
  846. return -ENODEV;
  847. }
  848. id = of_alias_get_id(pdev->dev.of_node, "gpio");
  849. if (id < 0) {
  850. dev_err(&pdev->dev, "Couldn't get OF id\n");
  851. return id;
  852. }
  853. mvchip->clk = devm_clk_get(&pdev->dev, NULL);
  854. /* Not all SoCs require a clock.*/
  855. if (!IS_ERR(mvchip->clk))
  856. clk_prepare_enable(mvchip->clk);
  857. mvchip->soc_variant = soc_variant;
  858. mvchip->chip.label = dev_name(&pdev->dev);
  859. mvchip->chip.parent = &pdev->dev;
  860. mvchip->chip.request = gpiochip_generic_request;
  861. mvchip->chip.free = gpiochip_generic_free;
  862. mvchip->chip.direction_input = mvebu_gpio_direction_input;
  863. mvchip->chip.get = mvebu_gpio_get;
  864. mvchip->chip.direction_output = mvebu_gpio_direction_output;
  865. mvchip->chip.set = mvebu_gpio_set;
  866. if (have_irqs)
  867. mvchip->chip.to_irq = mvebu_gpio_to_irq;
  868. mvchip->chip.base = id * MVEBU_MAX_GPIO_PER_BANK;
  869. mvchip->chip.ngpio = ngpios;
  870. mvchip->chip.can_sleep = false;
  871. mvchip->chip.of_node = np;
  872. mvchip->chip.dbg_show = mvebu_gpio_dbg_show;
  873. spin_lock_init(&mvchip->lock);
  874. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  875. mvchip->membase = devm_ioremap_resource(&pdev->dev, res);
  876. if (IS_ERR(mvchip->membase))
  877. return PTR_ERR(mvchip->membase);
  878. /*
  879. * The Armada XP has a second range of registers for the
  880. * per-CPU registers
  881. */
  882. if (soc_variant == MVEBU_GPIO_SOC_VARIANT_ARMADAXP) {
  883. res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  884. mvchip->percpu_membase = devm_ioremap_resource(&pdev->dev,
  885. res);
  886. if (IS_ERR(mvchip->percpu_membase))
  887. return PTR_ERR(mvchip->percpu_membase);
  888. }
  889. /*
  890. * Mask and clear GPIO interrupts.
  891. */
  892. switch (soc_variant) {
  893. case MVEBU_GPIO_SOC_VARIANT_ORION:
  894. writel_relaxed(0, mvchip->membase + GPIO_EDGE_CAUSE_OFF);
  895. writel_relaxed(0, mvchip->membase + GPIO_EDGE_MASK_OFF);
  896. writel_relaxed(0, mvchip->membase + GPIO_LEVEL_MASK_OFF);
  897. break;
  898. case MVEBU_GPIO_SOC_VARIANT_MV78200:
  899. writel_relaxed(0, mvchip->membase + GPIO_EDGE_CAUSE_OFF);
  900. for (cpu = 0; cpu < 2; cpu++) {
  901. writel_relaxed(0, mvchip->membase +
  902. GPIO_EDGE_MASK_MV78200_OFF(cpu));
  903. writel_relaxed(0, mvchip->membase +
  904. GPIO_LEVEL_MASK_MV78200_OFF(cpu));
  905. }
  906. break;
  907. case MVEBU_GPIO_SOC_VARIANT_ARMADAXP:
  908. writel_relaxed(0, mvchip->membase + GPIO_EDGE_CAUSE_OFF);
  909. writel_relaxed(0, mvchip->membase + GPIO_EDGE_MASK_OFF);
  910. writel_relaxed(0, mvchip->membase + GPIO_LEVEL_MASK_OFF);
  911. for (cpu = 0; cpu < 4; cpu++) {
  912. writel_relaxed(0, mvchip->percpu_membase +
  913. GPIO_EDGE_CAUSE_ARMADAXP_OFF(cpu));
  914. writel_relaxed(0, mvchip->percpu_membase +
  915. GPIO_EDGE_MASK_ARMADAXP_OFF(cpu));
  916. writel_relaxed(0, mvchip->percpu_membase +
  917. GPIO_LEVEL_MASK_ARMADAXP_OFF(cpu));
  918. }
  919. break;
  920. default:
  921. BUG();
  922. }
  923. devm_gpiochip_add_data(&pdev->dev, &mvchip->chip, mvchip);
  924. /* Some gpio controllers do not provide irq support */
  925. if (!have_irqs)
  926. return 0;
  927. mvchip->domain =
  928. irq_domain_add_linear(np, ngpios, &irq_generic_chip_ops, NULL);
  929. if (!mvchip->domain) {
  930. dev_err(&pdev->dev, "couldn't allocate irq domain %s (DT).\n",
  931. mvchip->chip.label);
  932. return -ENODEV;
  933. }
  934. err = irq_alloc_domain_generic_chips(
  935. mvchip->domain, ngpios, 2, np->name, handle_level_irq,
  936. IRQ_NOREQUEST | IRQ_NOPROBE | IRQ_LEVEL, 0, 0);
  937. if (err) {
  938. dev_err(&pdev->dev, "couldn't allocate irq chips %s (DT).\n",
  939. mvchip->chip.label);
  940. goto err_domain;
  941. }
  942. /*
  943. * NOTE: The common accessors cannot be used because of the percpu
  944. * access to the mask registers
  945. */
  946. gc = irq_get_domain_generic_chip(mvchip->domain, 0);
  947. gc->private = mvchip;
  948. ct = &gc->chip_types[0];
  949. ct->type = IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW;
  950. ct->chip.irq_mask = mvebu_gpio_level_irq_mask;
  951. ct->chip.irq_unmask = mvebu_gpio_level_irq_unmask;
  952. ct->chip.irq_set_type = mvebu_gpio_irq_set_type;
  953. ct->chip.name = mvchip->chip.label;
  954. ct = &gc->chip_types[1];
  955. ct->type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
  956. ct->chip.irq_ack = mvebu_gpio_irq_ack;
  957. ct->chip.irq_mask = mvebu_gpio_edge_irq_mask;
  958. ct->chip.irq_unmask = mvebu_gpio_edge_irq_unmask;
  959. ct->chip.irq_set_type = mvebu_gpio_irq_set_type;
  960. ct->handler = handle_edge_irq;
  961. ct->chip.name = mvchip->chip.label;
  962. /*
  963. * Setup the interrupt handlers. Each chip can have up to 4
  964. * interrupt handlers, with each handler dealing with 8 GPIO
  965. * pins.
  966. */
  967. for (i = 0; i < 4; i++) {
  968. int irq = platform_get_irq(pdev, i);
  969. if (irq < 0)
  970. continue;
  971. irq_set_chained_handler_and_data(irq, mvebu_gpio_irq_handler,
  972. mvchip);
  973. }
  974. /* Armada 370/XP has simple PWM support for GPIO lines */
  975. if (IS_ENABLED(CONFIG_PWM))
  976. return mvebu_pwm_probe(pdev, mvchip, id);
  977. return 0;
  978. err_domain:
  979. irq_domain_remove(mvchip->domain);
  980. return err;
  981. }
  982. static struct platform_driver mvebu_gpio_driver = {
  983. .driver = {
  984. .name = "mvebu-gpio",
  985. .of_match_table = mvebu_gpio_of_match,
  986. },
  987. .probe = mvebu_gpio_probe,
  988. .suspend = mvebu_gpio_suspend,
  989. .resume = mvebu_gpio_resume,
  990. };
  991. builtin_platform_driver(mvebu_gpio_driver);