gpio-mvebu.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145
  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(0, 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. spin_lock_init(&mvpwm->lock);
  658. return pwmchip_add(&mvpwm->chip);
  659. }
  660. #ifdef CONFIG_DEBUG_FS
  661. #include <linux/seq_file.h>
  662. static void mvebu_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
  663. {
  664. struct mvebu_gpio_chip *mvchip = gpiochip_get_data(chip);
  665. u32 out, io_conf, blink, in_pol, data_in, cause, edg_msk, lvl_msk;
  666. int i;
  667. out = readl_relaxed(mvebu_gpioreg_out(mvchip));
  668. io_conf = readl_relaxed(mvebu_gpioreg_io_conf(mvchip));
  669. blink = readl_relaxed(mvebu_gpioreg_blink(mvchip));
  670. in_pol = readl_relaxed(mvebu_gpioreg_in_pol(mvchip));
  671. data_in = readl_relaxed(mvebu_gpioreg_data_in(mvchip));
  672. cause = readl_relaxed(mvebu_gpioreg_edge_cause(mvchip));
  673. edg_msk = readl_relaxed(mvebu_gpioreg_edge_mask(mvchip));
  674. lvl_msk = readl_relaxed(mvebu_gpioreg_level_mask(mvchip));
  675. for (i = 0; i < chip->ngpio; i++) {
  676. const char *label;
  677. u32 msk;
  678. bool is_out;
  679. label = gpiochip_is_requested(chip, i);
  680. if (!label)
  681. continue;
  682. msk = BIT(i);
  683. is_out = !(io_conf & msk);
  684. seq_printf(s, " gpio-%-3d (%-20.20s)", chip->base + i, label);
  685. if (is_out) {
  686. seq_printf(s, " out %s %s\n",
  687. out & msk ? "hi" : "lo",
  688. blink & msk ? "(blink )" : "");
  689. continue;
  690. }
  691. seq_printf(s, " in %s (act %s) - IRQ",
  692. (data_in ^ in_pol) & msk ? "hi" : "lo",
  693. in_pol & msk ? "lo" : "hi");
  694. if (!((edg_msk | lvl_msk) & msk)) {
  695. seq_puts(s, " disabled\n");
  696. continue;
  697. }
  698. if (edg_msk & msk)
  699. seq_puts(s, " edge ");
  700. if (lvl_msk & msk)
  701. seq_puts(s, " level");
  702. seq_printf(s, " (%s)\n", cause & msk ? "pending" : "clear ");
  703. }
  704. }
  705. #else
  706. #define mvebu_gpio_dbg_show NULL
  707. #endif
  708. static const struct of_device_id mvebu_gpio_of_match[] = {
  709. {
  710. .compatible = "marvell,orion-gpio",
  711. .data = (void *) MVEBU_GPIO_SOC_VARIANT_ORION,
  712. },
  713. {
  714. .compatible = "marvell,mv78200-gpio",
  715. .data = (void *) MVEBU_GPIO_SOC_VARIANT_MV78200,
  716. },
  717. {
  718. .compatible = "marvell,armadaxp-gpio",
  719. .data = (void *) MVEBU_GPIO_SOC_VARIANT_ARMADAXP,
  720. },
  721. {
  722. .compatible = "marvell,armada-370-xp-gpio",
  723. .data = (void *) MVEBU_GPIO_SOC_VARIANT_ORION,
  724. },
  725. {
  726. /* sentinel */
  727. },
  728. };
  729. static int mvebu_gpio_suspend(struct platform_device *pdev, pm_message_t state)
  730. {
  731. struct mvebu_gpio_chip *mvchip = platform_get_drvdata(pdev);
  732. int i;
  733. mvchip->out_reg = readl(mvebu_gpioreg_out(mvchip));
  734. mvchip->io_conf_reg = readl(mvebu_gpioreg_io_conf(mvchip));
  735. mvchip->blink_en_reg = readl(mvebu_gpioreg_blink(mvchip));
  736. mvchip->in_pol_reg = readl(mvebu_gpioreg_in_pol(mvchip));
  737. switch (mvchip->soc_variant) {
  738. case MVEBU_GPIO_SOC_VARIANT_ORION:
  739. mvchip->edge_mask_regs[0] =
  740. readl(mvchip->membase + GPIO_EDGE_MASK_OFF);
  741. mvchip->level_mask_regs[0] =
  742. readl(mvchip->membase + GPIO_LEVEL_MASK_OFF);
  743. break;
  744. case MVEBU_GPIO_SOC_VARIANT_MV78200:
  745. for (i = 0; i < 2; i++) {
  746. mvchip->edge_mask_regs[i] =
  747. readl(mvchip->membase +
  748. GPIO_EDGE_MASK_MV78200_OFF(i));
  749. mvchip->level_mask_regs[i] =
  750. readl(mvchip->membase +
  751. GPIO_LEVEL_MASK_MV78200_OFF(i));
  752. }
  753. break;
  754. case MVEBU_GPIO_SOC_VARIANT_ARMADAXP:
  755. for (i = 0; i < 4; i++) {
  756. mvchip->edge_mask_regs[i] =
  757. readl(mvchip->membase +
  758. GPIO_EDGE_MASK_ARMADAXP_OFF(i));
  759. mvchip->level_mask_regs[i] =
  760. readl(mvchip->membase +
  761. GPIO_LEVEL_MASK_ARMADAXP_OFF(i));
  762. }
  763. break;
  764. default:
  765. BUG();
  766. }
  767. if (IS_ENABLED(CONFIG_PWM))
  768. mvebu_pwm_suspend(mvchip);
  769. return 0;
  770. }
  771. static int mvebu_gpio_resume(struct platform_device *pdev)
  772. {
  773. struct mvebu_gpio_chip *mvchip = platform_get_drvdata(pdev);
  774. int i;
  775. writel(mvchip->out_reg, mvebu_gpioreg_out(mvchip));
  776. writel(mvchip->io_conf_reg, mvebu_gpioreg_io_conf(mvchip));
  777. writel(mvchip->blink_en_reg, mvebu_gpioreg_blink(mvchip));
  778. writel(mvchip->in_pol_reg, mvebu_gpioreg_in_pol(mvchip));
  779. switch (mvchip->soc_variant) {
  780. case MVEBU_GPIO_SOC_VARIANT_ORION:
  781. writel(mvchip->edge_mask_regs[0],
  782. mvchip->membase + GPIO_EDGE_MASK_OFF);
  783. writel(mvchip->level_mask_regs[0],
  784. mvchip->membase + GPIO_LEVEL_MASK_OFF);
  785. break;
  786. case MVEBU_GPIO_SOC_VARIANT_MV78200:
  787. for (i = 0; i < 2; i++) {
  788. writel(mvchip->edge_mask_regs[i],
  789. mvchip->membase + GPIO_EDGE_MASK_MV78200_OFF(i));
  790. writel(mvchip->level_mask_regs[i],
  791. mvchip->membase +
  792. GPIO_LEVEL_MASK_MV78200_OFF(i));
  793. }
  794. break;
  795. case MVEBU_GPIO_SOC_VARIANT_ARMADAXP:
  796. for (i = 0; i < 4; i++) {
  797. writel(mvchip->edge_mask_regs[i],
  798. mvchip->membase +
  799. GPIO_EDGE_MASK_ARMADAXP_OFF(i));
  800. writel(mvchip->level_mask_regs[i],
  801. mvchip->membase +
  802. GPIO_LEVEL_MASK_ARMADAXP_OFF(i));
  803. }
  804. break;
  805. default:
  806. BUG();
  807. }
  808. if (IS_ENABLED(CONFIG_PWM))
  809. mvebu_pwm_resume(mvchip);
  810. return 0;
  811. }
  812. static int mvebu_gpio_probe(struct platform_device *pdev)
  813. {
  814. struct mvebu_gpio_chip *mvchip;
  815. const struct of_device_id *match;
  816. struct device_node *np = pdev->dev.of_node;
  817. struct resource *res;
  818. struct irq_chip_generic *gc;
  819. struct irq_chip_type *ct;
  820. unsigned int ngpios;
  821. bool have_irqs;
  822. int soc_variant;
  823. int i, cpu, id;
  824. int err;
  825. match = of_match_device(mvebu_gpio_of_match, &pdev->dev);
  826. if (match)
  827. soc_variant = (unsigned long) match->data;
  828. else
  829. soc_variant = MVEBU_GPIO_SOC_VARIANT_ORION;
  830. /* Some gpio controllers do not provide irq support */
  831. have_irqs = of_irq_count(np) != 0;
  832. mvchip = devm_kzalloc(&pdev->dev, sizeof(struct mvebu_gpio_chip),
  833. GFP_KERNEL);
  834. if (!mvchip)
  835. return -ENOMEM;
  836. platform_set_drvdata(pdev, mvchip);
  837. if (of_property_read_u32(pdev->dev.of_node, "ngpios", &ngpios)) {
  838. dev_err(&pdev->dev, "Missing ngpios OF property\n");
  839. return -ENODEV;
  840. }
  841. id = of_alias_get_id(pdev->dev.of_node, "gpio");
  842. if (id < 0) {
  843. dev_err(&pdev->dev, "Couldn't get OF id\n");
  844. return id;
  845. }
  846. mvchip->clk = devm_clk_get(&pdev->dev, NULL);
  847. /* Not all SoCs require a clock.*/
  848. if (!IS_ERR(mvchip->clk))
  849. clk_prepare_enable(mvchip->clk);
  850. mvchip->soc_variant = soc_variant;
  851. mvchip->chip.label = dev_name(&pdev->dev);
  852. mvchip->chip.parent = &pdev->dev;
  853. mvchip->chip.request = gpiochip_generic_request;
  854. mvchip->chip.free = gpiochip_generic_free;
  855. mvchip->chip.direction_input = mvebu_gpio_direction_input;
  856. mvchip->chip.get = mvebu_gpio_get;
  857. mvchip->chip.direction_output = mvebu_gpio_direction_output;
  858. mvchip->chip.set = mvebu_gpio_set;
  859. if (have_irqs)
  860. mvchip->chip.to_irq = mvebu_gpio_to_irq;
  861. mvchip->chip.base = id * MVEBU_MAX_GPIO_PER_BANK;
  862. mvchip->chip.ngpio = ngpios;
  863. mvchip->chip.can_sleep = false;
  864. mvchip->chip.of_node = np;
  865. mvchip->chip.dbg_show = mvebu_gpio_dbg_show;
  866. spin_lock_init(&mvchip->lock);
  867. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  868. mvchip->membase = devm_ioremap_resource(&pdev->dev, res);
  869. if (IS_ERR(mvchip->membase))
  870. return PTR_ERR(mvchip->membase);
  871. /*
  872. * The Armada XP has a second range of registers for the
  873. * per-CPU registers
  874. */
  875. if (soc_variant == MVEBU_GPIO_SOC_VARIANT_ARMADAXP) {
  876. res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  877. mvchip->percpu_membase = devm_ioremap_resource(&pdev->dev,
  878. res);
  879. if (IS_ERR(mvchip->percpu_membase))
  880. return PTR_ERR(mvchip->percpu_membase);
  881. }
  882. /*
  883. * Mask and clear GPIO interrupts.
  884. */
  885. switch (soc_variant) {
  886. case MVEBU_GPIO_SOC_VARIANT_ORION:
  887. writel_relaxed(0, mvchip->membase + GPIO_EDGE_CAUSE_OFF);
  888. writel_relaxed(0, mvchip->membase + GPIO_EDGE_MASK_OFF);
  889. writel_relaxed(0, mvchip->membase + GPIO_LEVEL_MASK_OFF);
  890. break;
  891. case MVEBU_GPIO_SOC_VARIANT_MV78200:
  892. writel_relaxed(0, mvchip->membase + GPIO_EDGE_CAUSE_OFF);
  893. for (cpu = 0; cpu < 2; cpu++) {
  894. writel_relaxed(0, mvchip->membase +
  895. GPIO_EDGE_MASK_MV78200_OFF(cpu));
  896. writel_relaxed(0, mvchip->membase +
  897. GPIO_LEVEL_MASK_MV78200_OFF(cpu));
  898. }
  899. break;
  900. case MVEBU_GPIO_SOC_VARIANT_ARMADAXP:
  901. writel_relaxed(0, mvchip->membase + GPIO_EDGE_CAUSE_OFF);
  902. writel_relaxed(0, mvchip->membase + GPIO_EDGE_MASK_OFF);
  903. writel_relaxed(0, mvchip->membase + GPIO_LEVEL_MASK_OFF);
  904. for (cpu = 0; cpu < 4; cpu++) {
  905. writel_relaxed(0, mvchip->percpu_membase +
  906. GPIO_EDGE_CAUSE_ARMADAXP_OFF(cpu));
  907. writel_relaxed(0, mvchip->percpu_membase +
  908. GPIO_EDGE_MASK_ARMADAXP_OFF(cpu));
  909. writel_relaxed(0, mvchip->percpu_membase +
  910. GPIO_LEVEL_MASK_ARMADAXP_OFF(cpu));
  911. }
  912. break;
  913. default:
  914. BUG();
  915. }
  916. devm_gpiochip_add_data(&pdev->dev, &mvchip->chip, mvchip);
  917. /* Some gpio controllers do not provide irq support */
  918. if (!have_irqs)
  919. return 0;
  920. mvchip->domain =
  921. irq_domain_add_linear(np, ngpios, &irq_generic_chip_ops, NULL);
  922. if (!mvchip->domain) {
  923. dev_err(&pdev->dev, "couldn't allocate irq domain %s (DT).\n",
  924. mvchip->chip.label);
  925. return -ENODEV;
  926. }
  927. err = irq_alloc_domain_generic_chips(
  928. mvchip->domain, ngpios, 2, np->name, handle_level_irq,
  929. IRQ_NOREQUEST | IRQ_NOPROBE | IRQ_LEVEL, 0, 0);
  930. if (err) {
  931. dev_err(&pdev->dev, "couldn't allocate irq chips %s (DT).\n",
  932. mvchip->chip.label);
  933. goto err_domain;
  934. }
  935. /*
  936. * NOTE: The common accessors cannot be used because of the percpu
  937. * access to the mask registers
  938. */
  939. gc = irq_get_domain_generic_chip(mvchip->domain, 0);
  940. gc->private = mvchip;
  941. ct = &gc->chip_types[0];
  942. ct->type = IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW;
  943. ct->chip.irq_mask = mvebu_gpio_level_irq_mask;
  944. ct->chip.irq_unmask = mvebu_gpio_level_irq_unmask;
  945. ct->chip.irq_set_type = mvebu_gpio_irq_set_type;
  946. ct->chip.name = mvchip->chip.label;
  947. ct = &gc->chip_types[1];
  948. ct->type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
  949. ct->chip.irq_ack = mvebu_gpio_irq_ack;
  950. ct->chip.irq_mask = mvebu_gpio_edge_irq_mask;
  951. ct->chip.irq_unmask = mvebu_gpio_edge_irq_unmask;
  952. ct->chip.irq_set_type = mvebu_gpio_irq_set_type;
  953. ct->handler = handle_edge_irq;
  954. ct->chip.name = mvchip->chip.label;
  955. /*
  956. * Setup the interrupt handlers. Each chip can have up to 4
  957. * interrupt handlers, with each handler dealing with 8 GPIO
  958. * pins.
  959. */
  960. for (i = 0; i < 4; i++) {
  961. int irq = platform_get_irq(pdev, i);
  962. if (irq < 0)
  963. continue;
  964. irq_set_chained_handler_and_data(irq, mvebu_gpio_irq_handler,
  965. mvchip);
  966. }
  967. /* Armada 370/XP has simple PWM support for GPIO lines */
  968. if (IS_ENABLED(CONFIG_PWM))
  969. return mvebu_pwm_probe(pdev, mvchip, id);
  970. return 0;
  971. err_domain:
  972. irq_domain_remove(mvchip->domain);
  973. return err;
  974. }
  975. static struct platform_driver mvebu_gpio_driver = {
  976. .driver = {
  977. .name = "mvebu-gpio",
  978. .of_match_table = mvebu_gpio_of_match,
  979. },
  980. .probe = mvebu_gpio_probe,
  981. .suspend = mvebu_gpio_suspend,
  982. .resume = mvebu_gpio_resume,
  983. };
  984. builtin_platform_driver(mvebu_gpio_driver);