pinctrl-at91-pio4.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107
  1. /*
  2. * Driver for the Atmel PIO4 controller
  3. *
  4. * Copyright (C) 2015 Atmel,
  5. * 2015 Ludovic Desroches <ludovic.desroches@atmel.com>
  6. *
  7. * This software is licensed under the terms of the GNU General Public
  8. * License version 2, as published by the Free Software Foundation, and
  9. * may be copied, distributed, and modified under those terms.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. */
  16. #include <linux/clk.h>
  17. #include <linux/gpio/driver.h>
  18. /* FIXME: needed for gpio_to_irq(), get rid of this */
  19. #include <linux/gpio.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/io.h>
  22. #include <linux/init.h>
  23. #include <linux/of.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/pinctrl/pinconf.h>
  26. #include <linux/pinctrl/pinconf-generic.h>
  27. #include <linux/pinctrl/pinctrl.h>
  28. #include <linux/pinctrl/pinmux.h>
  29. #include <linux/slab.h>
  30. #include "core.h"
  31. #include "pinconf.h"
  32. #include "pinctrl-utils.h"
  33. /*
  34. * Warning:
  35. * In order to not introduce confusion between Atmel PIO groups and pinctrl
  36. * framework groups, Atmel PIO groups will be called banks, line is kept to
  37. * designed the pin id into this bank.
  38. */
  39. #define ATMEL_PIO_MSKR 0x0000
  40. #define ATMEL_PIO_CFGR 0x0004
  41. #define ATMEL_PIO_CFGR_FUNC_MASK GENMASK(2, 0)
  42. #define ATMEL_PIO_DIR_MASK BIT(8)
  43. #define ATMEL_PIO_PUEN_MASK BIT(9)
  44. #define ATMEL_PIO_PDEN_MASK BIT(10)
  45. #define ATMEL_PIO_IFEN_MASK BIT(12)
  46. #define ATMEL_PIO_IFSCEN_MASK BIT(13)
  47. #define ATMEL_PIO_OPD_MASK BIT(14)
  48. #define ATMEL_PIO_SCHMITT_MASK BIT(15)
  49. #define ATMEL_PIO_CFGR_EVTSEL_MASK GENMASK(26, 24)
  50. #define ATMEL_PIO_CFGR_EVTSEL_FALLING (0 << 24)
  51. #define ATMEL_PIO_CFGR_EVTSEL_RISING (1 << 24)
  52. #define ATMEL_PIO_CFGR_EVTSEL_BOTH (2 << 24)
  53. #define ATMEL_PIO_CFGR_EVTSEL_LOW (3 << 24)
  54. #define ATMEL_PIO_CFGR_EVTSEL_HIGH (4 << 24)
  55. #define ATMEL_PIO_PDSR 0x0008
  56. #define ATMEL_PIO_LOCKSR 0x000C
  57. #define ATMEL_PIO_SODR 0x0010
  58. #define ATMEL_PIO_CODR 0x0014
  59. #define ATMEL_PIO_ODSR 0x0018
  60. #define ATMEL_PIO_IER 0x0020
  61. #define ATMEL_PIO_IDR 0x0024
  62. #define ATMEL_PIO_IMR 0x0028
  63. #define ATMEL_PIO_ISR 0x002C
  64. #define ATMEL_PIO_IOFR 0x003C
  65. #define ATMEL_PIO_NPINS_PER_BANK 32
  66. #define ATMEL_PIO_BANK(pin_id) (pin_id / ATMEL_PIO_NPINS_PER_BANK)
  67. #define ATMEL_PIO_LINE(pin_id) (pin_id % ATMEL_PIO_NPINS_PER_BANK)
  68. #define ATMEL_PIO_BANK_OFFSET 0x40
  69. #define ATMEL_GET_PIN_NO(pinfunc) ((pinfunc) & 0xff)
  70. #define ATMEL_GET_PIN_FUNC(pinfunc) ((pinfunc >> 16) & 0xf)
  71. #define ATMEL_GET_PIN_IOSET(pinfunc) ((pinfunc >> 20) & 0xf)
  72. struct atmel_pioctrl_data {
  73. unsigned nbanks;
  74. };
  75. struct atmel_group {
  76. const char *name;
  77. u32 pin;
  78. };
  79. struct atmel_pin {
  80. unsigned pin_id;
  81. unsigned mux;
  82. unsigned ioset;
  83. unsigned bank;
  84. unsigned line;
  85. const char *device;
  86. };
  87. /**
  88. * struct atmel_pioctrl - Atmel PIO controller (pinmux + gpio)
  89. * @reg_base: base address of the controller.
  90. * @clk: clock of the controller.
  91. * @nbanks: number of PIO groups, it can vary depending on the SoC.
  92. * @pinctrl_dev: pinctrl device registered.
  93. * @groups: groups table to provide group name and pin in the group to pinctrl.
  94. * @group_names: group names table to provide all the group/pin names to
  95. * pinctrl or gpio.
  96. * @pins: pins table used for both pinctrl and gpio. pin_id, bank and line
  97. * fields are set at probe time. Other ones are set when parsing dt
  98. * pinctrl.
  99. * @npins: number of pins.
  100. * @gpio_chip: gpio chip registered.
  101. * @irq_domain: irq domain for the gpio controller.
  102. * @irqs: table containing the hw irq number of the bank. The index of the
  103. * table is the bank id.
  104. * @dev: device entry for the Atmel PIO controller.
  105. * @node: node of the Atmel PIO controller.
  106. */
  107. struct atmel_pioctrl {
  108. void __iomem *reg_base;
  109. struct clk *clk;
  110. unsigned nbanks;
  111. struct pinctrl_dev *pinctrl_dev;
  112. struct atmel_group *groups;
  113. const char * const *group_names;
  114. struct atmel_pin **pins;
  115. unsigned npins;
  116. struct gpio_chip *gpio_chip;
  117. struct irq_domain *irq_domain;
  118. int *irqs;
  119. unsigned *pm_wakeup_sources;
  120. struct {
  121. u32 imr;
  122. u32 odsr;
  123. u32 cfgr[ATMEL_PIO_NPINS_PER_BANK];
  124. } *pm_suspend_backup;
  125. struct device *dev;
  126. struct device_node *node;
  127. };
  128. static const char * const atmel_functions[] = {
  129. "GPIO", "A", "B", "C", "D", "E", "F", "G"
  130. };
  131. /* --- GPIO --- */
  132. static unsigned int atmel_gpio_read(struct atmel_pioctrl *atmel_pioctrl,
  133. unsigned int bank, unsigned int reg)
  134. {
  135. return readl_relaxed(atmel_pioctrl->reg_base
  136. + ATMEL_PIO_BANK_OFFSET * bank + reg);
  137. }
  138. static void atmel_gpio_write(struct atmel_pioctrl *atmel_pioctrl,
  139. unsigned int bank, unsigned int reg,
  140. unsigned int val)
  141. {
  142. writel_relaxed(val, atmel_pioctrl->reg_base
  143. + ATMEL_PIO_BANK_OFFSET * bank + reg);
  144. }
  145. static void atmel_gpio_irq_ack(struct irq_data *d)
  146. {
  147. /*
  148. * Nothing to do, interrupt is cleared when reading the status
  149. * register.
  150. */
  151. }
  152. static int atmel_gpio_irq_set_type(struct irq_data *d, unsigned type)
  153. {
  154. struct atmel_pioctrl *atmel_pioctrl = irq_data_get_irq_chip_data(d);
  155. struct atmel_pin *pin = atmel_pioctrl->pins[d->hwirq];
  156. unsigned reg;
  157. atmel_gpio_write(atmel_pioctrl, pin->bank, ATMEL_PIO_MSKR,
  158. BIT(pin->line));
  159. reg = atmel_gpio_read(atmel_pioctrl, pin->bank, ATMEL_PIO_CFGR);
  160. reg &= (~ATMEL_PIO_CFGR_EVTSEL_MASK);
  161. switch (type) {
  162. case IRQ_TYPE_EDGE_RISING:
  163. irq_set_handler_locked(d, handle_edge_irq);
  164. reg |= ATMEL_PIO_CFGR_EVTSEL_RISING;
  165. break;
  166. case IRQ_TYPE_EDGE_FALLING:
  167. irq_set_handler_locked(d, handle_edge_irq);
  168. reg |= ATMEL_PIO_CFGR_EVTSEL_FALLING;
  169. break;
  170. case IRQ_TYPE_EDGE_BOTH:
  171. irq_set_handler_locked(d, handle_edge_irq);
  172. reg |= ATMEL_PIO_CFGR_EVTSEL_BOTH;
  173. break;
  174. case IRQ_TYPE_LEVEL_LOW:
  175. irq_set_handler_locked(d, handle_level_irq);
  176. reg |= ATMEL_PIO_CFGR_EVTSEL_LOW;
  177. break;
  178. case IRQ_TYPE_LEVEL_HIGH:
  179. irq_set_handler_locked(d, handle_level_irq);
  180. reg |= ATMEL_PIO_CFGR_EVTSEL_HIGH;
  181. break;
  182. case IRQ_TYPE_NONE:
  183. default:
  184. return -EINVAL;
  185. }
  186. atmel_gpio_write(atmel_pioctrl, pin->bank, ATMEL_PIO_CFGR, reg);
  187. return 0;
  188. }
  189. static void atmel_gpio_irq_mask(struct irq_data *d)
  190. {
  191. struct atmel_pioctrl *atmel_pioctrl = irq_data_get_irq_chip_data(d);
  192. struct atmel_pin *pin = atmel_pioctrl->pins[d->hwirq];
  193. atmel_gpio_write(atmel_pioctrl, pin->bank, ATMEL_PIO_IDR,
  194. BIT(pin->line));
  195. }
  196. static void atmel_gpio_irq_unmask(struct irq_data *d)
  197. {
  198. struct atmel_pioctrl *atmel_pioctrl = irq_data_get_irq_chip_data(d);
  199. struct atmel_pin *pin = atmel_pioctrl->pins[d->hwirq];
  200. atmel_gpio_write(atmel_pioctrl, pin->bank, ATMEL_PIO_IER,
  201. BIT(pin->line));
  202. }
  203. #ifdef CONFIG_PM_SLEEP
  204. static int atmel_gpio_irq_set_wake(struct irq_data *d, unsigned int on)
  205. {
  206. struct atmel_pioctrl *atmel_pioctrl = irq_data_get_irq_chip_data(d);
  207. int bank = ATMEL_PIO_BANK(d->hwirq);
  208. int line = ATMEL_PIO_LINE(d->hwirq);
  209. /* The gpio controller has one interrupt line per bank. */
  210. irq_set_irq_wake(atmel_pioctrl->irqs[bank], on);
  211. if (on)
  212. atmel_pioctrl->pm_wakeup_sources[bank] |= BIT(line);
  213. else
  214. atmel_pioctrl->pm_wakeup_sources[bank] &= ~(BIT(line));
  215. return 0;
  216. }
  217. #else
  218. #define atmel_gpio_irq_set_wake NULL
  219. #endif /* CONFIG_PM_SLEEP */
  220. static struct irq_chip atmel_gpio_irq_chip = {
  221. .name = "GPIO",
  222. .irq_ack = atmel_gpio_irq_ack,
  223. .irq_mask = atmel_gpio_irq_mask,
  224. .irq_unmask = atmel_gpio_irq_unmask,
  225. .irq_set_type = atmel_gpio_irq_set_type,
  226. .irq_set_wake = atmel_gpio_irq_set_wake,
  227. };
  228. static void atmel_gpio_irq_handler(struct irq_desc *desc)
  229. {
  230. unsigned int irq = irq_desc_get_irq(desc);
  231. struct atmel_pioctrl *atmel_pioctrl = irq_desc_get_handler_data(desc);
  232. struct irq_chip *chip = irq_desc_get_chip(desc);
  233. unsigned long isr;
  234. int n, bank = -1;
  235. /* Find from which bank is the irq received. */
  236. for (n = 0; n < atmel_pioctrl->nbanks; n++) {
  237. if (atmel_pioctrl->irqs[n] == irq) {
  238. bank = n;
  239. break;
  240. }
  241. }
  242. if (bank < 0) {
  243. dev_err(atmel_pioctrl->dev,
  244. "no bank associated to irq %u\n", irq);
  245. return;
  246. }
  247. chained_irq_enter(chip, desc);
  248. for (;;) {
  249. isr = (unsigned long)atmel_gpio_read(atmel_pioctrl, bank,
  250. ATMEL_PIO_ISR);
  251. isr &= (unsigned long)atmel_gpio_read(atmel_pioctrl, bank,
  252. ATMEL_PIO_IMR);
  253. if (!isr)
  254. break;
  255. for_each_set_bit(n, &isr, BITS_PER_LONG)
  256. generic_handle_irq(gpio_to_irq(bank *
  257. ATMEL_PIO_NPINS_PER_BANK + n));
  258. }
  259. chained_irq_exit(chip, desc);
  260. }
  261. static int atmel_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
  262. {
  263. struct atmel_pioctrl *atmel_pioctrl = gpiochip_get_data(chip);
  264. struct atmel_pin *pin = atmel_pioctrl->pins[offset];
  265. unsigned reg;
  266. atmel_gpio_write(atmel_pioctrl, pin->bank, ATMEL_PIO_MSKR,
  267. BIT(pin->line));
  268. reg = atmel_gpio_read(atmel_pioctrl, pin->bank, ATMEL_PIO_CFGR);
  269. reg &= ~ATMEL_PIO_DIR_MASK;
  270. atmel_gpio_write(atmel_pioctrl, pin->bank, ATMEL_PIO_CFGR, reg);
  271. return 0;
  272. }
  273. static int atmel_gpio_get(struct gpio_chip *chip, unsigned offset)
  274. {
  275. struct atmel_pioctrl *atmel_pioctrl = gpiochip_get_data(chip);
  276. struct atmel_pin *pin = atmel_pioctrl->pins[offset];
  277. unsigned reg;
  278. reg = atmel_gpio_read(atmel_pioctrl, pin->bank, ATMEL_PIO_PDSR);
  279. return !!(reg & BIT(pin->line));
  280. }
  281. static int atmel_gpio_direction_output(struct gpio_chip *chip, unsigned offset,
  282. int value)
  283. {
  284. struct atmel_pioctrl *atmel_pioctrl = gpiochip_get_data(chip);
  285. struct atmel_pin *pin = atmel_pioctrl->pins[offset];
  286. unsigned reg;
  287. atmel_gpio_write(atmel_pioctrl, pin->bank,
  288. value ? ATMEL_PIO_SODR : ATMEL_PIO_CODR,
  289. BIT(pin->line));
  290. atmel_gpio_write(atmel_pioctrl, pin->bank, ATMEL_PIO_MSKR,
  291. BIT(pin->line));
  292. reg = atmel_gpio_read(atmel_pioctrl, pin->bank, ATMEL_PIO_CFGR);
  293. reg |= ATMEL_PIO_DIR_MASK;
  294. atmel_gpio_write(atmel_pioctrl, pin->bank, ATMEL_PIO_CFGR, reg);
  295. return 0;
  296. }
  297. static void atmel_gpio_set(struct gpio_chip *chip, unsigned offset, int val)
  298. {
  299. struct atmel_pioctrl *atmel_pioctrl = gpiochip_get_data(chip);
  300. struct atmel_pin *pin = atmel_pioctrl->pins[offset];
  301. atmel_gpio_write(atmel_pioctrl, pin->bank,
  302. val ? ATMEL_PIO_SODR : ATMEL_PIO_CODR,
  303. BIT(pin->line));
  304. }
  305. static int atmel_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
  306. {
  307. struct atmel_pioctrl *atmel_pioctrl = gpiochip_get_data(chip);
  308. return irq_find_mapping(atmel_pioctrl->irq_domain, offset);
  309. }
  310. static struct gpio_chip atmel_gpio_chip = {
  311. .direction_input = atmel_gpio_direction_input,
  312. .get = atmel_gpio_get,
  313. .direction_output = atmel_gpio_direction_output,
  314. .set = atmel_gpio_set,
  315. .to_irq = atmel_gpio_to_irq,
  316. .base = 0,
  317. };
  318. /* --- PINCTRL --- */
  319. static unsigned int atmel_pin_config_read(struct pinctrl_dev *pctldev,
  320. unsigned pin_id)
  321. {
  322. struct atmel_pioctrl *atmel_pioctrl = pinctrl_dev_get_drvdata(pctldev);
  323. unsigned bank = atmel_pioctrl->pins[pin_id]->bank;
  324. unsigned line = atmel_pioctrl->pins[pin_id]->line;
  325. void __iomem *addr = atmel_pioctrl->reg_base
  326. + bank * ATMEL_PIO_BANK_OFFSET;
  327. writel_relaxed(BIT(line), addr + ATMEL_PIO_MSKR);
  328. /* Have to set MSKR first, to access the right pin CFGR. */
  329. wmb();
  330. return readl_relaxed(addr + ATMEL_PIO_CFGR);
  331. }
  332. static void atmel_pin_config_write(struct pinctrl_dev *pctldev,
  333. unsigned pin_id, u32 conf)
  334. {
  335. struct atmel_pioctrl *atmel_pioctrl = pinctrl_dev_get_drvdata(pctldev);
  336. unsigned bank = atmel_pioctrl->pins[pin_id]->bank;
  337. unsigned line = atmel_pioctrl->pins[pin_id]->line;
  338. void __iomem *addr = atmel_pioctrl->reg_base
  339. + bank * ATMEL_PIO_BANK_OFFSET;
  340. writel_relaxed(BIT(line), addr + ATMEL_PIO_MSKR);
  341. /* Have to set MSKR first, to access the right pin CFGR. */
  342. wmb();
  343. writel_relaxed(conf, addr + ATMEL_PIO_CFGR);
  344. }
  345. static int atmel_pctl_get_groups_count(struct pinctrl_dev *pctldev)
  346. {
  347. struct atmel_pioctrl *atmel_pioctrl = pinctrl_dev_get_drvdata(pctldev);
  348. return atmel_pioctrl->npins;
  349. }
  350. static const char *atmel_pctl_get_group_name(struct pinctrl_dev *pctldev,
  351. unsigned selector)
  352. {
  353. struct atmel_pioctrl *atmel_pioctrl = pinctrl_dev_get_drvdata(pctldev);
  354. return atmel_pioctrl->groups[selector].name;
  355. }
  356. static int atmel_pctl_get_group_pins(struct pinctrl_dev *pctldev,
  357. unsigned selector, const unsigned **pins,
  358. unsigned *num_pins)
  359. {
  360. struct atmel_pioctrl *atmel_pioctrl = pinctrl_dev_get_drvdata(pctldev);
  361. *pins = (unsigned *)&atmel_pioctrl->groups[selector].pin;
  362. *num_pins = 1;
  363. return 0;
  364. }
  365. static struct atmel_group *
  366. atmel_pctl_find_group_by_pin(struct pinctrl_dev *pctldev, unsigned pin)
  367. {
  368. struct atmel_pioctrl *atmel_pioctrl = pinctrl_dev_get_drvdata(pctldev);
  369. int i;
  370. for (i = 0; i < atmel_pioctrl->npins; i++) {
  371. struct atmel_group *grp = atmel_pioctrl->groups + i;
  372. if (grp->pin == pin)
  373. return grp;
  374. }
  375. return NULL;
  376. }
  377. static int atmel_pctl_xlate_pinfunc(struct pinctrl_dev *pctldev,
  378. struct device_node *np,
  379. u32 pinfunc, const char **grp_name,
  380. const char **func_name)
  381. {
  382. struct atmel_pioctrl *atmel_pioctrl = pinctrl_dev_get_drvdata(pctldev);
  383. unsigned pin_id, func_id;
  384. struct atmel_group *grp;
  385. pin_id = ATMEL_GET_PIN_NO(pinfunc);
  386. func_id = ATMEL_GET_PIN_FUNC(pinfunc);
  387. if (func_id >= ARRAY_SIZE(atmel_functions))
  388. return -EINVAL;
  389. *func_name = atmel_functions[func_id];
  390. grp = atmel_pctl_find_group_by_pin(pctldev, pin_id);
  391. if (!grp)
  392. return -EINVAL;
  393. *grp_name = grp->name;
  394. atmel_pioctrl->pins[pin_id]->mux = func_id;
  395. atmel_pioctrl->pins[pin_id]->ioset = ATMEL_GET_PIN_IOSET(pinfunc);
  396. /* Want the device name not the group one. */
  397. if (np->parent == atmel_pioctrl->node)
  398. atmel_pioctrl->pins[pin_id]->device = np->name;
  399. else
  400. atmel_pioctrl->pins[pin_id]->device = np->parent->name;
  401. return 0;
  402. }
  403. static int atmel_pctl_dt_subnode_to_map(struct pinctrl_dev *pctldev,
  404. struct device_node *np,
  405. struct pinctrl_map **map,
  406. unsigned *reserved_maps,
  407. unsigned *num_maps)
  408. {
  409. unsigned num_pins, num_configs, reserve;
  410. unsigned long *configs;
  411. struct property *pins;
  412. bool has_config;
  413. u32 pinfunc;
  414. int ret, i;
  415. pins = of_find_property(np, "pinmux", NULL);
  416. if (!pins)
  417. return -EINVAL;
  418. ret = pinconf_generic_parse_dt_config(np, pctldev, &configs,
  419. &num_configs);
  420. if (ret < 0) {
  421. dev_err(pctldev->dev, "%s: could not parse node property\n",
  422. of_node_full_name(np));
  423. return ret;
  424. }
  425. if (num_configs)
  426. has_config = true;
  427. num_pins = pins->length / sizeof(u32);
  428. if (!num_pins) {
  429. dev_err(pctldev->dev, "no pins found in node %s\n",
  430. of_node_full_name(np));
  431. ret = -EINVAL;
  432. goto exit;
  433. }
  434. /*
  435. * Reserve maps, at least there is a mux map and an optional conf
  436. * map for each pin.
  437. */
  438. reserve = 1;
  439. if (has_config && num_pins >= 1)
  440. reserve++;
  441. reserve *= num_pins;
  442. ret = pinctrl_utils_reserve_map(pctldev, map, reserved_maps, num_maps,
  443. reserve);
  444. if (ret < 0)
  445. goto exit;
  446. for (i = 0; i < num_pins; i++) {
  447. const char *group, *func;
  448. ret = of_property_read_u32_index(np, "pinmux", i, &pinfunc);
  449. if (ret)
  450. goto exit;
  451. ret = atmel_pctl_xlate_pinfunc(pctldev, np, pinfunc, &group,
  452. &func);
  453. if (ret)
  454. goto exit;
  455. pinctrl_utils_add_map_mux(pctldev, map, reserved_maps, num_maps,
  456. group, func);
  457. if (has_config) {
  458. ret = pinctrl_utils_add_map_configs(pctldev, map,
  459. reserved_maps, num_maps, group,
  460. configs, num_configs,
  461. PIN_MAP_TYPE_CONFIGS_GROUP);
  462. if (ret < 0)
  463. goto exit;
  464. }
  465. }
  466. exit:
  467. kfree(configs);
  468. return ret;
  469. }
  470. static int atmel_pctl_dt_node_to_map(struct pinctrl_dev *pctldev,
  471. struct device_node *np_config,
  472. struct pinctrl_map **map,
  473. unsigned *num_maps)
  474. {
  475. struct device_node *np;
  476. unsigned reserved_maps;
  477. int ret;
  478. *map = NULL;
  479. *num_maps = 0;
  480. reserved_maps = 0;
  481. /*
  482. * If all the pins of a device have the same configuration (or no one),
  483. * it is useless to add a subnode, so directly parse node referenced by
  484. * phandle.
  485. */
  486. ret = atmel_pctl_dt_subnode_to_map(pctldev, np_config, map,
  487. &reserved_maps, num_maps);
  488. if (ret) {
  489. for_each_child_of_node(np_config, np) {
  490. ret = atmel_pctl_dt_subnode_to_map(pctldev, np, map,
  491. &reserved_maps, num_maps);
  492. if (ret < 0)
  493. break;
  494. }
  495. }
  496. if (ret < 0) {
  497. pinctrl_utils_free_map(pctldev, *map, *num_maps);
  498. dev_err(pctldev->dev, "can't create maps for node %s\n",
  499. np_config->full_name);
  500. }
  501. return ret;
  502. }
  503. static const struct pinctrl_ops atmel_pctlops = {
  504. .get_groups_count = atmel_pctl_get_groups_count,
  505. .get_group_name = atmel_pctl_get_group_name,
  506. .get_group_pins = atmel_pctl_get_group_pins,
  507. .dt_node_to_map = atmel_pctl_dt_node_to_map,
  508. .dt_free_map = pinctrl_utils_free_map,
  509. };
  510. static int atmel_pmx_get_functions_count(struct pinctrl_dev *pctldev)
  511. {
  512. return ARRAY_SIZE(atmel_functions);
  513. }
  514. static const char *atmel_pmx_get_function_name(struct pinctrl_dev *pctldev,
  515. unsigned selector)
  516. {
  517. return atmel_functions[selector];
  518. }
  519. static int atmel_pmx_get_function_groups(struct pinctrl_dev *pctldev,
  520. unsigned selector,
  521. const char * const **groups,
  522. unsigned * const num_groups)
  523. {
  524. struct atmel_pioctrl *atmel_pioctrl = pinctrl_dev_get_drvdata(pctldev);
  525. *groups = atmel_pioctrl->group_names;
  526. *num_groups = atmel_pioctrl->npins;
  527. return 0;
  528. }
  529. static int atmel_pmx_set_mux(struct pinctrl_dev *pctldev,
  530. unsigned function,
  531. unsigned group)
  532. {
  533. struct atmel_pioctrl *atmel_pioctrl = pinctrl_dev_get_drvdata(pctldev);
  534. unsigned pin;
  535. u32 conf;
  536. dev_dbg(pctldev->dev, "enable function %s group %s\n",
  537. atmel_functions[function], atmel_pioctrl->groups[group].name);
  538. pin = atmel_pioctrl->groups[group].pin;
  539. conf = atmel_pin_config_read(pctldev, pin);
  540. conf &= (~ATMEL_PIO_CFGR_FUNC_MASK);
  541. conf |= (function & ATMEL_PIO_CFGR_FUNC_MASK);
  542. dev_dbg(pctldev->dev, "pin: %u, conf: 0x%08x\n", pin, conf);
  543. atmel_pin_config_write(pctldev, pin, conf);
  544. return 0;
  545. }
  546. static const struct pinmux_ops atmel_pmxops = {
  547. .get_functions_count = atmel_pmx_get_functions_count,
  548. .get_function_name = atmel_pmx_get_function_name,
  549. .get_function_groups = atmel_pmx_get_function_groups,
  550. .set_mux = atmel_pmx_set_mux,
  551. };
  552. static int atmel_conf_pin_config_group_get(struct pinctrl_dev *pctldev,
  553. unsigned group,
  554. unsigned long *config)
  555. {
  556. struct atmel_pioctrl *atmel_pioctrl = pinctrl_dev_get_drvdata(pctldev);
  557. unsigned param = pinconf_to_config_param(*config), arg = 0;
  558. struct atmel_group *grp = atmel_pioctrl->groups + group;
  559. unsigned pin_id = grp->pin;
  560. u32 res;
  561. res = atmel_pin_config_read(pctldev, pin_id);
  562. switch (param) {
  563. case PIN_CONFIG_BIAS_PULL_UP:
  564. if (!(res & ATMEL_PIO_PUEN_MASK))
  565. return -EINVAL;
  566. arg = 1;
  567. break;
  568. case PIN_CONFIG_BIAS_PULL_DOWN:
  569. if ((res & ATMEL_PIO_PUEN_MASK) ||
  570. (!(res & ATMEL_PIO_PDEN_MASK)))
  571. return -EINVAL;
  572. arg = 1;
  573. break;
  574. case PIN_CONFIG_BIAS_DISABLE:
  575. if ((res & ATMEL_PIO_PUEN_MASK) ||
  576. ((res & ATMEL_PIO_PDEN_MASK)))
  577. return -EINVAL;
  578. arg = 1;
  579. break;
  580. case PIN_CONFIG_DRIVE_OPEN_DRAIN:
  581. if (!(res & ATMEL_PIO_OPD_MASK))
  582. return -EINVAL;
  583. arg = 1;
  584. break;
  585. case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
  586. if (!(res & ATMEL_PIO_SCHMITT_MASK))
  587. return -EINVAL;
  588. arg = 1;
  589. break;
  590. default:
  591. return -ENOTSUPP;
  592. }
  593. *config = pinconf_to_config_packed(param, arg);
  594. return 0;
  595. }
  596. static int atmel_conf_pin_config_group_set(struct pinctrl_dev *pctldev,
  597. unsigned group,
  598. unsigned long *configs,
  599. unsigned num_configs)
  600. {
  601. struct atmel_pioctrl *atmel_pioctrl = pinctrl_dev_get_drvdata(pctldev);
  602. struct atmel_group *grp = atmel_pioctrl->groups + group;
  603. unsigned bank, pin, pin_id = grp->pin;
  604. u32 mask, conf = 0;
  605. int i;
  606. conf = atmel_pin_config_read(pctldev, pin_id);
  607. for (i = 0; i < num_configs; i++) {
  608. unsigned param = pinconf_to_config_param(configs[i]);
  609. unsigned arg = pinconf_to_config_argument(configs[i]);
  610. dev_dbg(pctldev->dev, "%s: pin=%u, config=0x%lx\n",
  611. __func__, pin_id, configs[i]);
  612. switch (param) {
  613. case PIN_CONFIG_BIAS_DISABLE:
  614. conf &= (~ATMEL_PIO_PUEN_MASK);
  615. conf &= (~ATMEL_PIO_PDEN_MASK);
  616. break;
  617. case PIN_CONFIG_BIAS_PULL_UP:
  618. conf |= ATMEL_PIO_PUEN_MASK;
  619. conf &= (~ATMEL_PIO_PDEN_MASK);
  620. break;
  621. case PIN_CONFIG_BIAS_PULL_DOWN:
  622. conf |= ATMEL_PIO_PDEN_MASK;
  623. conf &= (~ATMEL_PIO_PUEN_MASK);
  624. break;
  625. case PIN_CONFIG_DRIVE_OPEN_DRAIN:
  626. if (arg == 0)
  627. conf &= (~ATMEL_PIO_OPD_MASK);
  628. else
  629. conf |= ATMEL_PIO_OPD_MASK;
  630. break;
  631. case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
  632. if (arg == 0)
  633. conf |= ATMEL_PIO_SCHMITT_MASK;
  634. else
  635. conf &= (~ATMEL_PIO_SCHMITT_MASK);
  636. break;
  637. case PIN_CONFIG_INPUT_DEBOUNCE:
  638. if (arg == 0) {
  639. conf &= (~ATMEL_PIO_IFEN_MASK);
  640. conf &= (~ATMEL_PIO_IFSCEN_MASK);
  641. } else {
  642. /*
  643. * We don't care about the debounce value for several reasons:
  644. * - can't have different debounce periods inside a same group,
  645. * - the register to configure this period is a secure register.
  646. * The debouncing filter can filter a pulse with a duration of less
  647. * than 1/2 slow clock period.
  648. */
  649. conf |= ATMEL_PIO_IFEN_MASK;
  650. conf |= ATMEL_PIO_IFSCEN_MASK;
  651. }
  652. break;
  653. case PIN_CONFIG_OUTPUT:
  654. conf |= ATMEL_PIO_DIR_MASK;
  655. bank = ATMEL_PIO_BANK(pin_id);
  656. pin = ATMEL_PIO_LINE(pin_id);
  657. mask = 1 << pin;
  658. if (arg == 0) {
  659. writel_relaxed(mask, atmel_pioctrl->reg_base +
  660. bank * ATMEL_PIO_BANK_OFFSET +
  661. ATMEL_PIO_CODR);
  662. } else {
  663. writel_relaxed(mask, atmel_pioctrl->reg_base +
  664. bank * ATMEL_PIO_BANK_OFFSET +
  665. ATMEL_PIO_SODR);
  666. }
  667. break;
  668. default:
  669. dev_warn(pctldev->dev,
  670. "unsupported configuration parameter: %u\n",
  671. param);
  672. continue;
  673. }
  674. }
  675. dev_dbg(pctldev->dev, "%s: reg=0x%08x\n", __func__, conf);
  676. atmel_pin_config_write(pctldev, pin_id, conf);
  677. return 0;
  678. }
  679. static void atmel_conf_pin_config_dbg_show(struct pinctrl_dev *pctldev,
  680. struct seq_file *s, unsigned pin_id)
  681. {
  682. struct atmel_pioctrl *atmel_pioctrl = pinctrl_dev_get_drvdata(pctldev);
  683. u32 conf;
  684. if (!atmel_pioctrl->pins[pin_id]->device)
  685. return;
  686. if (atmel_pioctrl->pins[pin_id])
  687. seq_printf(s, " (%s, ioset %u) ",
  688. atmel_pioctrl->pins[pin_id]->device,
  689. atmel_pioctrl->pins[pin_id]->ioset);
  690. conf = atmel_pin_config_read(pctldev, pin_id);
  691. if (conf & ATMEL_PIO_PUEN_MASK)
  692. seq_printf(s, "%s ", "pull-up");
  693. if (conf & ATMEL_PIO_PDEN_MASK)
  694. seq_printf(s, "%s ", "pull-down");
  695. if (conf & ATMEL_PIO_IFEN_MASK)
  696. seq_printf(s, "%s ", "debounce");
  697. if (conf & ATMEL_PIO_OPD_MASK)
  698. seq_printf(s, "%s ", "open-drain");
  699. if (conf & ATMEL_PIO_SCHMITT_MASK)
  700. seq_printf(s, "%s ", "schmitt");
  701. }
  702. static const struct pinconf_ops atmel_confops = {
  703. .pin_config_group_get = atmel_conf_pin_config_group_get,
  704. .pin_config_group_set = atmel_conf_pin_config_group_set,
  705. .pin_config_dbg_show = atmel_conf_pin_config_dbg_show,
  706. };
  707. static struct pinctrl_desc atmel_pinctrl_desc = {
  708. .name = "atmel_pinctrl",
  709. .confops = &atmel_confops,
  710. .pctlops = &atmel_pctlops,
  711. .pmxops = &atmel_pmxops,
  712. };
  713. static int __maybe_unused atmel_pctrl_suspend(struct device *dev)
  714. {
  715. struct platform_device *pdev = to_platform_device(dev);
  716. struct atmel_pioctrl *atmel_pioctrl = platform_get_drvdata(pdev);
  717. int i, j;
  718. /*
  719. * For each bank, save IMR to restore it later and disable all GPIO
  720. * interrupts excepting the ones marked as wakeup sources.
  721. */
  722. for (i = 0; i < atmel_pioctrl->nbanks; i++) {
  723. atmel_pioctrl->pm_suspend_backup[i].imr =
  724. atmel_gpio_read(atmel_pioctrl, i, ATMEL_PIO_IMR);
  725. atmel_gpio_write(atmel_pioctrl, i, ATMEL_PIO_IDR,
  726. ~atmel_pioctrl->pm_wakeup_sources[i]);
  727. atmel_pioctrl->pm_suspend_backup[i].odsr =
  728. atmel_gpio_read(atmel_pioctrl, i, ATMEL_PIO_ODSR);
  729. for (j = 0; j < ATMEL_PIO_NPINS_PER_BANK; j++) {
  730. atmel_gpio_write(atmel_pioctrl, i,
  731. ATMEL_PIO_MSKR, BIT(j));
  732. atmel_pioctrl->pm_suspend_backup[i].cfgr[j] =
  733. atmel_gpio_read(atmel_pioctrl, i,
  734. ATMEL_PIO_CFGR);
  735. }
  736. }
  737. return 0;
  738. }
  739. static int __maybe_unused atmel_pctrl_resume(struct device *dev)
  740. {
  741. struct platform_device *pdev = to_platform_device(dev);
  742. struct atmel_pioctrl *atmel_pioctrl = platform_get_drvdata(pdev);
  743. int i, j;
  744. for (i = 0; i < atmel_pioctrl->nbanks; i++) {
  745. atmel_gpio_write(atmel_pioctrl, i, ATMEL_PIO_IER,
  746. atmel_pioctrl->pm_suspend_backup[i].imr);
  747. atmel_gpio_write(atmel_pioctrl, i, ATMEL_PIO_SODR,
  748. atmel_pioctrl->pm_suspend_backup[i].odsr);
  749. for (j = 0; j < ATMEL_PIO_NPINS_PER_BANK; j++) {
  750. atmel_gpio_write(atmel_pioctrl, i,
  751. ATMEL_PIO_MSKR, BIT(j));
  752. atmel_gpio_write(atmel_pioctrl, i, ATMEL_PIO_CFGR,
  753. atmel_pioctrl->pm_suspend_backup[i].cfgr[j]);
  754. }
  755. }
  756. return 0;
  757. }
  758. static const struct dev_pm_ops atmel_pctrl_pm_ops = {
  759. SET_SYSTEM_SLEEP_PM_OPS(atmel_pctrl_suspend, atmel_pctrl_resume)
  760. };
  761. /*
  762. * The number of banks can be different from a SoC to another one.
  763. * We can have up to 16 banks.
  764. */
  765. static const struct atmel_pioctrl_data atmel_sama5d2_pioctrl_data = {
  766. .nbanks = 4,
  767. };
  768. static const struct of_device_id atmel_pctrl_of_match[] = {
  769. {
  770. .compatible = "atmel,sama5d2-pinctrl",
  771. .data = &atmel_sama5d2_pioctrl_data,
  772. }, {
  773. /* sentinel */
  774. }
  775. };
  776. static int atmel_pinctrl_probe(struct platform_device *pdev)
  777. {
  778. struct device *dev = &pdev->dev;
  779. struct pinctrl_pin_desc *pin_desc;
  780. const char **group_names;
  781. const struct of_device_id *match;
  782. int i, ret;
  783. struct resource *res;
  784. struct atmel_pioctrl *atmel_pioctrl;
  785. struct atmel_pioctrl_data *atmel_pioctrl_data;
  786. atmel_pioctrl = devm_kzalloc(dev, sizeof(*atmel_pioctrl), GFP_KERNEL);
  787. if (!atmel_pioctrl)
  788. return -ENOMEM;
  789. atmel_pioctrl->dev = dev;
  790. atmel_pioctrl->node = dev->of_node;
  791. platform_set_drvdata(pdev, atmel_pioctrl);
  792. match = of_match_node(atmel_pctrl_of_match, dev->of_node);
  793. if (!match) {
  794. dev_err(dev, "unknown compatible string\n");
  795. return -ENODEV;
  796. }
  797. atmel_pioctrl_data = (struct atmel_pioctrl_data *)match->data;
  798. atmel_pioctrl->nbanks = atmel_pioctrl_data->nbanks;
  799. atmel_pioctrl->npins = atmel_pioctrl->nbanks * ATMEL_PIO_NPINS_PER_BANK;
  800. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  801. if (!res) {
  802. dev_err(dev, "unable to get atmel pinctrl resource\n");
  803. return -EINVAL;
  804. }
  805. atmel_pioctrl->reg_base = devm_ioremap_resource(dev, res);
  806. if (IS_ERR(atmel_pioctrl->reg_base))
  807. return -EINVAL;
  808. atmel_pioctrl->clk = devm_clk_get(dev, NULL);
  809. if (IS_ERR(atmel_pioctrl->clk)) {
  810. dev_err(dev, "failed to get clock\n");
  811. return PTR_ERR(atmel_pioctrl->clk);
  812. }
  813. atmel_pioctrl->pins = devm_kzalloc(dev, sizeof(*atmel_pioctrl->pins)
  814. * atmel_pioctrl->npins, GFP_KERNEL);
  815. if (!atmel_pioctrl->pins)
  816. return -ENOMEM;
  817. pin_desc = devm_kzalloc(dev, sizeof(*pin_desc)
  818. * atmel_pioctrl->npins, GFP_KERNEL);
  819. if (!pin_desc)
  820. return -ENOMEM;
  821. atmel_pinctrl_desc.pins = pin_desc;
  822. atmel_pinctrl_desc.npins = atmel_pioctrl->npins;
  823. /* One pin is one group since a pin can achieve all functions. */
  824. group_names = devm_kzalloc(dev, sizeof(*group_names)
  825. * atmel_pioctrl->npins, GFP_KERNEL);
  826. if (!group_names)
  827. return -ENOMEM;
  828. atmel_pioctrl->group_names = group_names;
  829. atmel_pioctrl->groups = devm_kzalloc(&pdev->dev,
  830. sizeof(*atmel_pioctrl->groups) * atmel_pioctrl->npins,
  831. GFP_KERNEL);
  832. if (!atmel_pioctrl->groups)
  833. return -ENOMEM;
  834. for (i = 0 ; i < atmel_pioctrl->npins; i++) {
  835. struct atmel_group *group = atmel_pioctrl->groups + i;
  836. unsigned bank = ATMEL_PIO_BANK(i);
  837. unsigned line = ATMEL_PIO_LINE(i);
  838. atmel_pioctrl->pins[i] = devm_kzalloc(dev,
  839. sizeof(**atmel_pioctrl->pins), GFP_KERNEL);
  840. if (!atmel_pioctrl->pins[i])
  841. return -ENOMEM;
  842. atmel_pioctrl->pins[i]->pin_id = i;
  843. atmel_pioctrl->pins[i]->bank = bank;
  844. atmel_pioctrl->pins[i]->line = line;
  845. pin_desc[i].number = i;
  846. /* Pin naming convention: P(bank_name)(bank_pin_number). */
  847. pin_desc[i].name = kasprintf(GFP_KERNEL, "P%c%d",
  848. bank + 'A', line);
  849. group->name = group_names[i] = pin_desc[i].name;
  850. group->pin = pin_desc[i].number;
  851. dev_dbg(dev, "pin_id=%u, bank=%u, line=%u", i, bank, line);
  852. }
  853. atmel_pioctrl->gpio_chip = &atmel_gpio_chip;
  854. atmel_pioctrl->gpio_chip->of_node = dev->of_node;
  855. atmel_pioctrl->gpio_chip->ngpio = atmel_pioctrl->npins;
  856. atmel_pioctrl->gpio_chip->label = dev_name(dev);
  857. atmel_pioctrl->gpio_chip->parent = dev;
  858. atmel_pioctrl->gpio_chip->names = atmel_pioctrl->group_names;
  859. atmel_pioctrl->pm_wakeup_sources = devm_kzalloc(dev,
  860. sizeof(*atmel_pioctrl->pm_wakeup_sources)
  861. * atmel_pioctrl->nbanks, GFP_KERNEL);
  862. if (!atmel_pioctrl->pm_wakeup_sources)
  863. return -ENOMEM;
  864. atmel_pioctrl->pm_suspend_backup = devm_kzalloc(dev,
  865. sizeof(*atmel_pioctrl->pm_suspend_backup)
  866. * atmel_pioctrl->nbanks, GFP_KERNEL);
  867. if (!atmel_pioctrl->pm_suspend_backup)
  868. return -ENOMEM;
  869. atmel_pioctrl->irqs = devm_kzalloc(dev, sizeof(*atmel_pioctrl->irqs)
  870. * atmel_pioctrl->nbanks, GFP_KERNEL);
  871. if (!atmel_pioctrl->irqs)
  872. return -ENOMEM;
  873. /* There is one controller but each bank has its own irq line. */
  874. for (i = 0; i < atmel_pioctrl->nbanks; i++) {
  875. res = platform_get_resource(pdev, IORESOURCE_IRQ, i);
  876. if (!res) {
  877. dev_err(dev, "missing irq resource for group %c\n",
  878. 'A' + i);
  879. return -EINVAL;
  880. }
  881. atmel_pioctrl->irqs[i] = res->start;
  882. irq_set_chained_handler(res->start, atmel_gpio_irq_handler);
  883. irq_set_handler_data(res->start, atmel_pioctrl);
  884. dev_dbg(dev, "bank %i: irq=%pr\n", i, res);
  885. }
  886. atmel_pioctrl->irq_domain = irq_domain_add_linear(dev->of_node,
  887. atmel_pioctrl->gpio_chip->ngpio,
  888. &irq_domain_simple_ops, NULL);
  889. if (!atmel_pioctrl->irq_domain) {
  890. dev_err(dev, "can't add the irq domain\n");
  891. return -ENODEV;
  892. }
  893. atmel_pioctrl->irq_domain->name = "atmel gpio";
  894. for (i = 0; i < atmel_pioctrl->npins; i++) {
  895. int irq = irq_create_mapping(atmel_pioctrl->irq_domain, i);
  896. irq_set_chip_and_handler(irq, &atmel_gpio_irq_chip,
  897. handle_simple_irq);
  898. irq_set_chip_data(irq, atmel_pioctrl);
  899. dev_dbg(dev,
  900. "atmel gpio irq domain: hwirq: %d, linux irq: %d\n",
  901. i, irq);
  902. }
  903. ret = clk_prepare_enable(atmel_pioctrl->clk);
  904. if (ret) {
  905. dev_err(dev, "failed to prepare and enable clock\n");
  906. goto clk_prepare_enable_error;
  907. }
  908. atmel_pioctrl->pinctrl_dev = devm_pinctrl_register(&pdev->dev,
  909. &atmel_pinctrl_desc,
  910. atmel_pioctrl);
  911. if (IS_ERR(atmel_pioctrl->pinctrl_dev)) {
  912. ret = PTR_ERR(atmel_pioctrl->pinctrl_dev);
  913. dev_err(dev, "pinctrl registration failed\n");
  914. goto clk_unprep;
  915. }
  916. ret = gpiochip_add_data(atmel_pioctrl->gpio_chip, atmel_pioctrl);
  917. if (ret) {
  918. dev_err(dev, "failed to add gpiochip\n");
  919. goto clk_unprep;
  920. }
  921. ret = gpiochip_add_pin_range(atmel_pioctrl->gpio_chip, dev_name(dev),
  922. 0, 0, atmel_pioctrl->gpio_chip->ngpio);
  923. if (ret) {
  924. dev_err(dev, "failed to add gpio pin range\n");
  925. goto gpiochip_add_pin_range_error;
  926. }
  927. dev_info(&pdev->dev, "atmel pinctrl initialized\n");
  928. return 0;
  929. gpiochip_add_pin_range_error:
  930. gpiochip_remove(atmel_pioctrl->gpio_chip);
  931. clk_unprep:
  932. clk_disable_unprepare(atmel_pioctrl->clk);
  933. clk_prepare_enable_error:
  934. irq_domain_remove(atmel_pioctrl->irq_domain);
  935. return ret;
  936. }
  937. static struct platform_driver atmel_pinctrl_driver = {
  938. .driver = {
  939. .name = "pinctrl-at91-pio4",
  940. .of_match_table = atmel_pctrl_of_match,
  941. .pm = &atmel_pctrl_pm_ops,
  942. .suppress_bind_attrs = true,
  943. },
  944. .probe = atmel_pinctrl_probe,
  945. };
  946. builtin_platform_driver(atmel_pinctrl_driver);