pinctrl-single.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907
  1. /*
  2. * Generic device tree based pinctrl driver for one register per pin
  3. * type pinmux controllers
  4. *
  5. * Copyright (C) 2012 Texas Instruments, Inc.
  6. *
  7. * This file is licensed under the terms of the GNU General Public
  8. * License version 2. This program is licensed "as is" without any
  9. * warranty of any kind, whether express or implied.
  10. */
  11. #include <linux/init.h>
  12. #include <linux/module.h>
  13. #include <linux/io.h>
  14. #include <linux/slab.h>
  15. #include <linux/err.h>
  16. #include <linux/list.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/irqchip/chained_irq.h>
  19. #include <linux/of.h>
  20. #include <linux/of_device.h>
  21. #include <linux/of_address.h>
  22. #include <linux/of_irq.h>
  23. #include <linux/pinctrl/pinctrl.h>
  24. #include <linux/pinctrl/pinmux.h>
  25. #include <linux/pinctrl/pinconf-generic.h>
  26. #include <linux/platform_data/pinctrl-single.h>
  27. #include "core.h"
  28. #include "devicetree.h"
  29. #include "pinconf.h"
  30. #include "pinmux.h"
  31. #define DRIVER_NAME "pinctrl-single"
  32. #define PCS_OFF_DISABLED ~0U
  33. /**
  34. * struct pcs_func_vals - mux function register offset and value pair
  35. * @reg: register virtual address
  36. * @val: register value
  37. */
  38. struct pcs_func_vals {
  39. void __iomem *reg;
  40. unsigned val;
  41. unsigned mask;
  42. };
  43. /**
  44. * struct pcs_conf_vals - pinconf parameter, pinconf register offset
  45. * and value, enable, disable, mask
  46. * @param: config parameter
  47. * @val: user input bits in the pinconf register
  48. * @enable: enable bits in the pinconf register
  49. * @disable: disable bits in the pinconf register
  50. * @mask: mask bits in the register value
  51. */
  52. struct pcs_conf_vals {
  53. enum pin_config_param param;
  54. unsigned val;
  55. unsigned enable;
  56. unsigned disable;
  57. unsigned mask;
  58. };
  59. /**
  60. * struct pcs_conf_type - pinconf property name, pinconf param pair
  61. * @name: property name in DTS file
  62. * @param: config parameter
  63. */
  64. struct pcs_conf_type {
  65. const char *name;
  66. enum pin_config_param param;
  67. };
  68. /**
  69. * struct pcs_function - pinctrl function
  70. * @name: pinctrl function name
  71. * @vals: register and vals array
  72. * @nvals: number of entries in vals array
  73. * @pgnames: array of pingroup names the function uses
  74. * @npgnames: number of pingroup names the function uses
  75. * @node: list node
  76. */
  77. struct pcs_function {
  78. const char *name;
  79. struct pcs_func_vals *vals;
  80. unsigned nvals;
  81. const char **pgnames;
  82. int npgnames;
  83. struct pcs_conf_vals *conf;
  84. int nconfs;
  85. struct list_head node;
  86. };
  87. /**
  88. * struct pcs_gpiofunc_range - pin ranges with same mux value of gpio function
  89. * @offset: offset base of pins
  90. * @npins: number pins with the same mux value of gpio function
  91. * @gpiofunc: mux value of gpio function
  92. * @node: list node
  93. */
  94. struct pcs_gpiofunc_range {
  95. unsigned offset;
  96. unsigned npins;
  97. unsigned gpiofunc;
  98. struct list_head node;
  99. };
  100. /**
  101. * struct pcs_data - wrapper for data needed by pinctrl framework
  102. * @pa: pindesc array
  103. * @cur: index to current element
  104. *
  105. * REVISIT: We should be able to drop this eventually by adding
  106. * support for registering pins individually in the pinctrl
  107. * framework for those drivers that don't need a static array.
  108. */
  109. struct pcs_data {
  110. struct pinctrl_pin_desc *pa;
  111. int cur;
  112. };
  113. /**
  114. * struct pcs_soc_data - SoC specific settings
  115. * @flags: initial SoC specific PCS_FEAT_xxx values
  116. * @irq: optional interrupt for the controller
  117. * @irq_enable_mask: optional SoC specific interrupt enable mask
  118. * @irq_status_mask: optional SoC specific interrupt status mask
  119. * @rearm: optional SoC specific wake-up rearm function
  120. */
  121. struct pcs_soc_data {
  122. unsigned flags;
  123. int irq;
  124. unsigned irq_enable_mask;
  125. unsigned irq_status_mask;
  126. void (*rearm)(void);
  127. };
  128. /**
  129. * struct pcs_device - pinctrl device instance
  130. * @res: resources
  131. * @base: virtual address of the controller
  132. * @saved_vals: saved values for the controller
  133. * @size: size of the ioremapped area
  134. * @dev: device entry
  135. * @np: device tree node
  136. * @pctl: pin controller device
  137. * @flags: mask of PCS_FEAT_xxx values
  138. * @missing_nr_pinctrl_cells: for legacy binding, may go away
  139. * @socdata: soc specific data
  140. * @lock: spinlock for register access
  141. * @mutex: mutex protecting the lists
  142. * @width: bits per mux register
  143. * @fmask: function register mask
  144. * @fshift: function register shift
  145. * @foff: value to turn mux off
  146. * @fmax: max number of functions in fmask
  147. * @bits_per_mux: number of bits per mux
  148. * @bits_per_pin: number of bits per pin
  149. * @pins: physical pins on the SoC
  150. * @gpiofuncs: list of gpio functions
  151. * @irqs: list of interrupt registers
  152. * @chip: chip container for this instance
  153. * @domain: IRQ domain for this instance
  154. * @desc: pin controller descriptor
  155. * @read: register read function to use
  156. * @write: register write function to use
  157. */
  158. struct pcs_device {
  159. struct resource *res;
  160. void __iomem *base;
  161. void *saved_vals;
  162. unsigned size;
  163. struct device *dev;
  164. struct device_node *np;
  165. struct pinctrl_dev *pctl;
  166. unsigned flags;
  167. #define PCS_QUIRK_SHARED_IRQ (1 << 2)
  168. #define PCS_FEAT_IRQ (1 << 1)
  169. #define PCS_FEAT_PINCONF (1 << 0)
  170. struct property *missing_nr_pinctrl_cells;
  171. struct pcs_soc_data socdata;
  172. raw_spinlock_t lock;
  173. struct mutex mutex;
  174. unsigned width;
  175. unsigned fmask;
  176. unsigned fshift;
  177. unsigned foff;
  178. unsigned fmax;
  179. bool bits_per_mux;
  180. unsigned bits_per_pin;
  181. struct pcs_data pins;
  182. struct list_head gpiofuncs;
  183. struct list_head irqs;
  184. struct irq_chip chip;
  185. struct irq_domain *domain;
  186. struct pinctrl_desc desc;
  187. unsigned (*read)(void __iomem *reg);
  188. void (*write)(unsigned val, void __iomem *reg);
  189. };
  190. #define PCS_QUIRK_HAS_SHARED_IRQ (pcs->flags & PCS_QUIRK_SHARED_IRQ)
  191. #define PCS_HAS_IRQ (pcs->flags & PCS_FEAT_IRQ)
  192. #define PCS_HAS_PINCONF (pcs->flags & PCS_FEAT_PINCONF)
  193. static int pcs_pinconf_get(struct pinctrl_dev *pctldev, unsigned pin,
  194. unsigned long *config);
  195. static int pcs_pinconf_set(struct pinctrl_dev *pctldev, unsigned pin,
  196. unsigned long *configs, unsigned num_configs);
  197. static enum pin_config_param pcs_bias[] = {
  198. PIN_CONFIG_BIAS_PULL_DOWN,
  199. PIN_CONFIG_BIAS_PULL_UP,
  200. };
  201. /*
  202. * This lock class tells lockdep that irqchip core that this single
  203. * pinctrl can be in a different category than its parents, so it won't
  204. * report false recursion.
  205. */
  206. static struct lock_class_key pcs_lock_class;
  207. /*
  208. * REVISIT: Reads and writes could eventually use regmap or something
  209. * generic. But at least on omaps, some mux registers are performance
  210. * critical as they may need to be remuxed every time before and after
  211. * idle. Adding tests for register access width for every read and
  212. * write like regmap is doing is not desired, and caching the registers
  213. * does not help in this case.
  214. */
  215. static unsigned __maybe_unused pcs_readb(void __iomem *reg)
  216. {
  217. return readb(reg);
  218. }
  219. static unsigned __maybe_unused pcs_readw(void __iomem *reg)
  220. {
  221. return readw(reg);
  222. }
  223. static unsigned __maybe_unused pcs_readl(void __iomem *reg)
  224. {
  225. return readl(reg);
  226. }
  227. static void __maybe_unused pcs_writeb(unsigned val, void __iomem *reg)
  228. {
  229. writeb(val, reg);
  230. }
  231. static void __maybe_unused pcs_writew(unsigned val, void __iomem *reg)
  232. {
  233. writew(val, reg);
  234. }
  235. static void __maybe_unused pcs_writel(unsigned val, void __iomem *reg)
  236. {
  237. writel(val, reg);
  238. }
  239. static void pcs_pin_dbg_show(struct pinctrl_dev *pctldev,
  240. struct seq_file *s,
  241. unsigned pin)
  242. {
  243. struct pcs_device *pcs;
  244. unsigned val, mux_bytes;
  245. unsigned long offset;
  246. size_t pa;
  247. pcs = pinctrl_dev_get_drvdata(pctldev);
  248. mux_bytes = pcs->width / BITS_PER_BYTE;
  249. offset = pin * mux_bytes;
  250. val = pcs->read(pcs->base + offset);
  251. pa = pcs->res->start + offset;
  252. seq_printf(s, "%zx %08x %s ", pa, val, DRIVER_NAME);
  253. }
  254. static void pcs_dt_free_map(struct pinctrl_dev *pctldev,
  255. struct pinctrl_map *map, unsigned num_maps)
  256. {
  257. struct pcs_device *pcs;
  258. pcs = pinctrl_dev_get_drvdata(pctldev);
  259. devm_kfree(pcs->dev, map);
  260. }
  261. static int pcs_dt_node_to_map(struct pinctrl_dev *pctldev,
  262. struct device_node *np_config,
  263. struct pinctrl_map **map, unsigned *num_maps);
  264. static const struct pinctrl_ops pcs_pinctrl_ops = {
  265. .get_groups_count = pinctrl_generic_get_group_count,
  266. .get_group_name = pinctrl_generic_get_group_name,
  267. .get_group_pins = pinctrl_generic_get_group_pins,
  268. .pin_dbg_show = pcs_pin_dbg_show,
  269. .dt_node_to_map = pcs_dt_node_to_map,
  270. .dt_free_map = pcs_dt_free_map,
  271. };
  272. static int pcs_get_function(struct pinctrl_dev *pctldev, unsigned pin,
  273. struct pcs_function **func)
  274. {
  275. struct pcs_device *pcs = pinctrl_dev_get_drvdata(pctldev);
  276. struct pin_desc *pdesc = pin_desc_get(pctldev, pin);
  277. const struct pinctrl_setting_mux *setting;
  278. struct function_desc *function;
  279. unsigned fselector;
  280. /* If pin is not described in DTS & enabled, mux_setting is NULL. */
  281. setting = pdesc->mux_setting;
  282. if (!setting)
  283. return -ENOTSUPP;
  284. fselector = setting->func;
  285. function = pinmux_generic_get_function(pctldev, fselector);
  286. *func = function->data;
  287. if (!(*func)) {
  288. dev_err(pcs->dev, "%s could not find function%i\n",
  289. __func__, fselector);
  290. return -ENOTSUPP;
  291. }
  292. return 0;
  293. }
  294. static int pcs_set_mux(struct pinctrl_dev *pctldev, unsigned fselector,
  295. unsigned group)
  296. {
  297. struct pcs_device *pcs;
  298. struct function_desc *function;
  299. struct pcs_function *func;
  300. int i;
  301. pcs = pinctrl_dev_get_drvdata(pctldev);
  302. /* If function mask is null, needn't enable it. */
  303. if (!pcs->fmask)
  304. return 0;
  305. function = pinmux_generic_get_function(pctldev, fselector);
  306. func = function->data;
  307. if (!func)
  308. return -EINVAL;
  309. dev_dbg(pcs->dev, "enabling %s function%i\n",
  310. func->name, fselector);
  311. for (i = 0; i < func->nvals; i++) {
  312. struct pcs_func_vals *vals;
  313. unsigned long flags;
  314. unsigned val, mask;
  315. vals = &func->vals[i];
  316. raw_spin_lock_irqsave(&pcs->lock, flags);
  317. val = pcs->read(vals->reg);
  318. if (pcs->bits_per_mux)
  319. mask = vals->mask;
  320. else
  321. mask = pcs->fmask;
  322. val &= ~mask;
  323. val |= (vals->val & mask);
  324. pcs->write(val, vals->reg);
  325. raw_spin_unlock_irqrestore(&pcs->lock, flags);
  326. }
  327. return 0;
  328. }
  329. static int pcs_save_context(struct pinctrl_dev *pctldev)
  330. {
  331. struct pcs_device *pcs;
  332. int i;
  333. pcs = pinctrl_dev_get_drvdata(pctldev);
  334. if (!pcs->saved_vals)
  335. pcs->saved_vals = devm_kzalloc(pcs->dev, pcs->size, GFP_ATOMIC);
  336. switch (pcs->width) {
  337. case 32:
  338. for (i = 0; i < pcs->size; i += 4)
  339. *(u32 *)(pcs->saved_vals + i) =
  340. pcs->read(pcs->base + i);
  341. break;
  342. case 16:
  343. for (i = 0; i < pcs->size; i += 2)
  344. *(u16 *)(pcs->saved_vals + i) =
  345. pcs->read(pcs->base + i);
  346. break;
  347. }
  348. return 0;
  349. }
  350. static void pcs_restore_context(struct pinctrl_dev *pctldev)
  351. {
  352. struct pcs_device *pcs;
  353. int i;
  354. pcs = pinctrl_dev_get_drvdata(pctldev);
  355. switch (pcs->width) {
  356. case 32:
  357. for (i = 0; i < pcs->size; i += 4)
  358. pcs->write(*(u32 *)(pcs->saved_vals + i),
  359. pcs->base + i);
  360. break;
  361. case 16:
  362. for (i = 0; i < pcs->size; i += 2)
  363. pcs->write(*(u16 *)(pcs->saved_vals + i),
  364. pcs->base + i);
  365. break;
  366. }
  367. }
  368. static int pcs_request_gpio(struct pinctrl_dev *pctldev,
  369. struct pinctrl_gpio_range *range, unsigned pin)
  370. {
  371. struct pcs_device *pcs = pinctrl_dev_get_drvdata(pctldev);
  372. struct pcs_gpiofunc_range *frange = NULL;
  373. struct list_head *pos, *tmp;
  374. int mux_bytes = 0;
  375. unsigned data;
  376. /* If function mask is null, return directly. */
  377. if (!pcs->fmask)
  378. return -ENOTSUPP;
  379. list_for_each_safe(pos, tmp, &pcs->gpiofuncs) {
  380. frange = list_entry(pos, struct pcs_gpiofunc_range, node);
  381. if (pin >= frange->offset + frange->npins
  382. || pin < frange->offset)
  383. continue;
  384. mux_bytes = pcs->width / BITS_PER_BYTE;
  385. data = pcs->read(pcs->base + pin * mux_bytes) & ~pcs->fmask;
  386. data |= frange->gpiofunc;
  387. pcs->write(data, pcs->base + pin * mux_bytes);
  388. break;
  389. }
  390. return 0;
  391. }
  392. static const struct pinmux_ops pcs_pinmux_ops = {
  393. .get_functions_count = pinmux_generic_get_function_count,
  394. .get_function_name = pinmux_generic_get_function_name,
  395. .get_function_groups = pinmux_generic_get_function_groups,
  396. .set_mux = pcs_set_mux,
  397. .save_context = pcs_save_context,
  398. .restore_context = pcs_restore_context,
  399. .gpio_request_enable = pcs_request_gpio,
  400. };
  401. /* Clear BIAS value */
  402. static void pcs_pinconf_clear_bias(struct pinctrl_dev *pctldev, unsigned pin)
  403. {
  404. unsigned long config;
  405. int i;
  406. for (i = 0; i < ARRAY_SIZE(pcs_bias); i++) {
  407. config = pinconf_to_config_packed(pcs_bias[i], 0);
  408. pcs_pinconf_set(pctldev, pin, &config, 1);
  409. }
  410. }
  411. /*
  412. * Check whether PIN_CONFIG_BIAS_DISABLE is valid.
  413. * It's depend on that PULL_DOWN & PULL_UP configs are all invalid.
  414. */
  415. static bool pcs_pinconf_bias_disable(struct pinctrl_dev *pctldev, unsigned pin)
  416. {
  417. unsigned long config;
  418. int i;
  419. for (i = 0; i < ARRAY_SIZE(pcs_bias); i++) {
  420. config = pinconf_to_config_packed(pcs_bias[i], 0);
  421. if (!pcs_pinconf_get(pctldev, pin, &config))
  422. goto out;
  423. }
  424. return true;
  425. out:
  426. return false;
  427. }
  428. static int pcs_pinconf_get(struct pinctrl_dev *pctldev,
  429. unsigned pin, unsigned long *config)
  430. {
  431. struct pcs_device *pcs = pinctrl_dev_get_drvdata(pctldev);
  432. struct pcs_function *func;
  433. enum pin_config_param param;
  434. unsigned offset = 0, data = 0, i, j, ret;
  435. ret = pcs_get_function(pctldev, pin, &func);
  436. if (ret)
  437. return ret;
  438. for (i = 0; i < func->nconfs; i++) {
  439. param = pinconf_to_config_param(*config);
  440. if (param == PIN_CONFIG_BIAS_DISABLE) {
  441. if (pcs_pinconf_bias_disable(pctldev, pin)) {
  442. *config = 0;
  443. return 0;
  444. } else {
  445. return -ENOTSUPP;
  446. }
  447. } else if (param != func->conf[i].param) {
  448. continue;
  449. }
  450. offset = pin * (pcs->width / BITS_PER_BYTE);
  451. data = pcs->read(pcs->base + offset) & func->conf[i].mask;
  452. switch (func->conf[i].param) {
  453. /* 4 parameters */
  454. case PIN_CONFIG_BIAS_PULL_DOWN:
  455. case PIN_CONFIG_BIAS_PULL_UP:
  456. case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
  457. if ((data != func->conf[i].enable) ||
  458. (data == func->conf[i].disable))
  459. return -ENOTSUPP;
  460. *config = 0;
  461. break;
  462. /* 2 parameters */
  463. case PIN_CONFIG_INPUT_SCHMITT:
  464. for (j = 0; j < func->nconfs; j++) {
  465. switch (func->conf[j].param) {
  466. case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
  467. if (data != func->conf[j].enable)
  468. return -ENOTSUPP;
  469. break;
  470. default:
  471. break;
  472. }
  473. }
  474. *config = data;
  475. break;
  476. case PIN_CONFIG_DRIVE_STRENGTH:
  477. case PIN_CONFIG_SLEW_RATE:
  478. case PIN_CONFIG_LOW_POWER_MODE:
  479. default:
  480. *config = data;
  481. break;
  482. }
  483. return 0;
  484. }
  485. return -ENOTSUPP;
  486. }
  487. static int pcs_pinconf_set(struct pinctrl_dev *pctldev,
  488. unsigned pin, unsigned long *configs,
  489. unsigned num_configs)
  490. {
  491. struct pcs_device *pcs = pinctrl_dev_get_drvdata(pctldev);
  492. struct pcs_function *func;
  493. unsigned offset = 0, shift = 0, i, data, ret;
  494. u16 arg;
  495. int j;
  496. ret = pcs_get_function(pctldev, pin, &func);
  497. if (ret)
  498. return ret;
  499. for (j = 0; j < num_configs; j++) {
  500. for (i = 0; i < func->nconfs; i++) {
  501. if (pinconf_to_config_param(configs[j])
  502. != func->conf[i].param)
  503. continue;
  504. offset = pin * (pcs->width / BITS_PER_BYTE);
  505. data = pcs->read(pcs->base + offset);
  506. arg = pinconf_to_config_argument(configs[j]);
  507. switch (func->conf[i].param) {
  508. /* 2 parameters */
  509. case PIN_CONFIG_INPUT_SCHMITT:
  510. case PIN_CONFIG_DRIVE_STRENGTH:
  511. case PIN_CONFIG_SLEW_RATE:
  512. case PIN_CONFIG_LOW_POWER_MODE:
  513. shift = ffs(func->conf[i].mask) - 1;
  514. data &= ~func->conf[i].mask;
  515. data |= (arg << shift) & func->conf[i].mask;
  516. break;
  517. /* 4 parameters */
  518. case PIN_CONFIG_BIAS_DISABLE:
  519. pcs_pinconf_clear_bias(pctldev, pin);
  520. break;
  521. case PIN_CONFIG_BIAS_PULL_DOWN:
  522. case PIN_CONFIG_BIAS_PULL_UP:
  523. if (arg)
  524. pcs_pinconf_clear_bias(pctldev, pin);
  525. /* fall through */
  526. case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
  527. data &= ~func->conf[i].mask;
  528. if (arg)
  529. data |= func->conf[i].enable;
  530. else
  531. data |= func->conf[i].disable;
  532. break;
  533. default:
  534. return -ENOTSUPP;
  535. }
  536. pcs->write(data, pcs->base + offset);
  537. break;
  538. }
  539. if (i >= func->nconfs)
  540. return -ENOTSUPP;
  541. } /* for each config */
  542. return 0;
  543. }
  544. static int pcs_pinconf_group_get(struct pinctrl_dev *pctldev,
  545. unsigned group, unsigned long *config)
  546. {
  547. const unsigned *pins;
  548. unsigned npins, old = 0;
  549. int i, ret;
  550. ret = pinctrl_generic_get_group_pins(pctldev, group, &pins, &npins);
  551. if (ret)
  552. return ret;
  553. for (i = 0; i < npins; i++) {
  554. if (pcs_pinconf_get(pctldev, pins[i], config))
  555. return -ENOTSUPP;
  556. /* configs do not match between two pins */
  557. if (i && (old != *config))
  558. return -ENOTSUPP;
  559. old = *config;
  560. }
  561. return 0;
  562. }
  563. static int pcs_pinconf_group_set(struct pinctrl_dev *pctldev,
  564. unsigned group, unsigned long *configs,
  565. unsigned num_configs)
  566. {
  567. const unsigned *pins;
  568. unsigned npins;
  569. int i, ret;
  570. ret = pinctrl_generic_get_group_pins(pctldev, group, &pins, &npins);
  571. if (ret)
  572. return ret;
  573. for (i = 0; i < npins; i++) {
  574. if (pcs_pinconf_set(pctldev, pins[i], configs, num_configs))
  575. return -ENOTSUPP;
  576. }
  577. return 0;
  578. }
  579. static void pcs_pinconf_dbg_show(struct pinctrl_dev *pctldev,
  580. struct seq_file *s, unsigned pin)
  581. {
  582. }
  583. static void pcs_pinconf_group_dbg_show(struct pinctrl_dev *pctldev,
  584. struct seq_file *s, unsigned selector)
  585. {
  586. }
  587. static void pcs_pinconf_config_dbg_show(struct pinctrl_dev *pctldev,
  588. struct seq_file *s,
  589. unsigned long config)
  590. {
  591. pinconf_generic_dump_config(pctldev, s, config);
  592. }
  593. static const struct pinconf_ops pcs_pinconf_ops = {
  594. .pin_config_get = pcs_pinconf_get,
  595. .pin_config_set = pcs_pinconf_set,
  596. .pin_config_group_get = pcs_pinconf_group_get,
  597. .pin_config_group_set = pcs_pinconf_group_set,
  598. .pin_config_dbg_show = pcs_pinconf_dbg_show,
  599. .pin_config_group_dbg_show = pcs_pinconf_group_dbg_show,
  600. .pin_config_config_dbg_show = pcs_pinconf_config_dbg_show,
  601. .is_generic = true,
  602. };
  603. /**
  604. * pcs_add_pin() - add a pin to the static per controller pin array
  605. * @pcs: pcs driver instance
  606. * @offset: register offset from base
  607. */
  608. static int pcs_add_pin(struct pcs_device *pcs, unsigned offset,
  609. unsigned pin_pos)
  610. {
  611. struct pcs_soc_data *pcs_soc = &pcs->socdata;
  612. struct pinctrl_pin_desc *pin;
  613. int i;
  614. i = pcs->pins.cur;
  615. if (i >= pcs->desc.npins) {
  616. dev_err(pcs->dev, "too many pins, max %i\n",
  617. pcs->desc.npins);
  618. return -ENOMEM;
  619. }
  620. if (pcs_soc->irq_enable_mask) {
  621. unsigned val;
  622. val = pcs->read(pcs->base + offset);
  623. if (val & pcs_soc->irq_enable_mask) {
  624. dev_dbg(pcs->dev, "irq enabled at boot for pin at %lx (%x), clearing\n",
  625. (unsigned long)pcs->res->start + offset, val);
  626. val &= ~pcs_soc->irq_enable_mask;
  627. pcs->write(val, pcs->base + offset);
  628. }
  629. }
  630. pin = &pcs->pins.pa[i];
  631. pin->number = i;
  632. pcs->pins.cur++;
  633. return i;
  634. }
  635. /**
  636. * pcs_allocate_pin_table() - adds all the pins for the pinctrl driver
  637. * @pcs: pcs driver instance
  638. *
  639. * In case of errors, resources are freed in pcs_free_resources.
  640. *
  641. * If your hardware needs holes in the address space, then just set
  642. * up multiple driver instances.
  643. */
  644. static int pcs_allocate_pin_table(struct pcs_device *pcs)
  645. {
  646. int mux_bytes, nr_pins, i;
  647. int num_pins_in_register = 0;
  648. mux_bytes = pcs->width / BITS_PER_BYTE;
  649. if (pcs->bits_per_mux) {
  650. pcs->bits_per_pin = fls(pcs->fmask);
  651. nr_pins = (pcs->size * BITS_PER_BYTE) / pcs->bits_per_pin;
  652. num_pins_in_register = pcs->width / pcs->bits_per_pin;
  653. } else {
  654. nr_pins = pcs->size / mux_bytes;
  655. }
  656. dev_dbg(pcs->dev, "allocating %i pins\n", nr_pins);
  657. pcs->pins.pa = devm_kzalloc(pcs->dev,
  658. sizeof(*pcs->pins.pa) * nr_pins,
  659. GFP_KERNEL);
  660. if (!pcs->pins.pa)
  661. return -ENOMEM;
  662. pcs->desc.pins = pcs->pins.pa;
  663. pcs->desc.npins = nr_pins;
  664. for (i = 0; i < pcs->desc.npins; i++) {
  665. unsigned offset;
  666. int res;
  667. int byte_num;
  668. int pin_pos = 0;
  669. if (pcs->bits_per_mux) {
  670. byte_num = (pcs->bits_per_pin * i) / BITS_PER_BYTE;
  671. offset = (byte_num / mux_bytes) * mux_bytes;
  672. pin_pos = i % num_pins_in_register;
  673. } else {
  674. offset = i * mux_bytes;
  675. }
  676. res = pcs_add_pin(pcs, offset, pin_pos);
  677. if (res < 0) {
  678. dev_err(pcs->dev, "error adding pins: %i\n", res);
  679. return res;
  680. }
  681. }
  682. return 0;
  683. }
  684. /**
  685. * pcs_add_function() - adds a new function to the function list
  686. * @pcs: pcs driver instance
  687. * @np: device node of the mux entry
  688. * @name: name of the function
  689. * @vals: array of mux register value pairs used by the function
  690. * @nvals: number of mux register value pairs
  691. * @pgnames: array of pingroup names for the function
  692. * @npgnames: number of pingroup names
  693. */
  694. static struct pcs_function *pcs_add_function(struct pcs_device *pcs,
  695. struct device_node *np,
  696. const char *name,
  697. struct pcs_func_vals *vals,
  698. unsigned nvals,
  699. const char **pgnames,
  700. unsigned npgnames)
  701. {
  702. struct pcs_function *function;
  703. int res;
  704. function = devm_kzalloc(pcs->dev, sizeof(*function), GFP_KERNEL);
  705. if (!function)
  706. return NULL;
  707. function->vals = vals;
  708. function->nvals = nvals;
  709. res = pinmux_generic_add_function(pcs->pctl, name,
  710. pgnames, npgnames,
  711. function);
  712. if (res)
  713. return NULL;
  714. return function;
  715. }
  716. /**
  717. * pcs_get_pin_by_offset() - get a pin index based on the register offset
  718. * @pcs: pcs driver instance
  719. * @offset: register offset from the base
  720. *
  721. * Note that this is OK as long as the pins are in a static array.
  722. */
  723. static int pcs_get_pin_by_offset(struct pcs_device *pcs, unsigned offset)
  724. {
  725. unsigned index;
  726. if (offset >= pcs->size) {
  727. dev_err(pcs->dev, "mux offset out of range: 0x%x (0x%x)\n",
  728. offset, pcs->size);
  729. return -EINVAL;
  730. }
  731. if (pcs->bits_per_mux)
  732. index = (offset * BITS_PER_BYTE) / pcs->bits_per_pin;
  733. else
  734. index = offset / (pcs->width / BITS_PER_BYTE);
  735. return index;
  736. }
  737. /*
  738. * check whether data matches enable bits or disable bits
  739. * Return value: 1 for matching enable bits, 0 for matching disable bits,
  740. * and negative value for matching failure.
  741. */
  742. static int pcs_config_match(unsigned data, unsigned enable, unsigned disable)
  743. {
  744. int ret = -EINVAL;
  745. if (data == enable)
  746. ret = 1;
  747. else if (data == disable)
  748. ret = 0;
  749. return ret;
  750. }
  751. static void add_config(struct pcs_conf_vals **conf, enum pin_config_param param,
  752. unsigned value, unsigned enable, unsigned disable,
  753. unsigned mask)
  754. {
  755. (*conf)->param = param;
  756. (*conf)->val = value;
  757. (*conf)->enable = enable;
  758. (*conf)->disable = disable;
  759. (*conf)->mask = mask;
  760. (*conf)++;
  761. }
  762. static void add_setting(unsigned long **setting, enum pin_config_param param,
  763. unsigned arg)
  764. {
  765. **setting = pinconf_to_config_packed(param, arg);
  766. (*setting)++;
  767. }
  768. /* add pinconf setting with 2 parameters */
  769. static void pcs_add_conf2(struct pcs_device *pcs, struct device_node *np,
  770. const char *name, enum pin_config_param param,
  771. struct pcs_conf_vals **conf, unsigned long **settings)
  772. {
  773. unsigned value[2], shift;
  774. int ret;
  775. ret = of_property_read_u32_array(np, name, value, 2);
  776. if (ret)
  777. return;
  778. /* set value & mask */
  779. value[0] &= value[1];
  780. shift = ffs(value[1]) - 1;
  781. /* skip enable & disable */
  782. add_config(conf, param, value[0], 0, 0, value[1]);
  783. add_setting(settings, param, value[0] >> shift);
  784. }
  785. /* add pinconf setting with 4 parameters */
  786. static void pcs_add_conf4(struct pcs_device *pcs, struct device_node *np,
  787. const char *name, enum pin_config_param param,
  788. struct pcs_conf_vals **conf, unsigned long **settings)
  789. {
  790. unsigned value[4];
  791. int ret;
  792. /* value to set, enable, disable, mask */
  793. ret = of_property_read_u32_array(np, name, value, 4);
  794. if (ret)
  795. return;
  796. if (!value[3]) {
  797. dev_err(pcs->dev, "mask field of the property can't be 0\n");
  798. return;
  799. }
  800. value[0] &= value[3];
  801. value[1] &= value[3];
  802. value[2] &= value[3];
  803. ret = pcs_config_match(value[0], value[1], value[2]);
  804. if (ret < 0)
  805. dev_dbg(pcs->dev, "failed to match enable or disable bits\n");
  806. add_config(conf, param, value[0], value[1], value[2], value[3]);
  807. add_setting(settings, param, ret);
  808. }
  809. static int pcs_parse_pinconf(struct pcs_device *pcs, struct device_node *np,
  810. struct pcs_function *func,
  811. struct pinctrl_map **map)
  812. {
  813. struct pinctrl_map *m = *map;
  814. int i = 0, nconfs = 0;
  815. unsigned long *settings = NULL, *s = NULL;
  816. struct pcs_conf_vals *conf = NULL;
  817. struct pcs_conf_type prop2[] = {
  818. { "pinctrl-single,drive-strength", PIN_CONFIG_DRIVE_STRENGTH, },
  819. { "pinctrl-single,slew-rate", PIN_CONFIG_SLEW_RATE, },
  820. { "pinctrl-single,input-schmitt", PIN_CONFIG_INPUT_SCHMITT, },
  821. { "pinctrl-single,low-power-mode", PIN_CONFIG_LOW_POWER_MODE, },
  822. };
  823. struct pcs_conf_type prop4[] = {
  824. { "pinctrl-single,bias-pullup", PIN_CONFIG_BIAS_PULL_UP, },
  825. { "pinctrl-single,bias-pulldown", PIN_CONFIG_BIAS_PULL_DOWN, },
  826. { "pinctrl-single,input-schmitt-enable",
  827. PIN_CONFIG_INPUT_SCHMITT_ENABLE, },
  828. };
  829. /* If pinconf isn't supported, don't parse properties in below. */
  830. if (!PCS_HAS_PINCONF)
  831. return 0;
  832. /* cacluate how much properties are supported in current node */
  833. for (i = 0; i < ARRAY_SIZE(prop2); i++) {
  834. if (of_find_property(np, prop2[i].name, NULL))
  835. nconfs++;
  836. }
  837. for (i = 0; i < ARRAY_SIZE(prop4); i++) {
  838. if (of_find_property(np, prop4[i].name, NULL))
  839. nconfs++;
  840. }
  841. if (!nconfs)
  842. return 0;
  843. func->conf = devm_kzalloc(pcs->dev,
  844. sizeof(struct pcs_conf_vals) * nconfs,
  845. GFP_KERNEL);
  846. if (!func->conf)
  847. return -ENOMEM;
  848. func->nconfs = nconfs;
  849. conf = &(func->conf[0]);
  850. m++;
  851. settings = devm_kzalloc(pcs->dev, sizeof(unsigned long) * nconfs,
  852. GFP_KERNEL);
  853. if (!settings)
  854. return -ENOMEM;
  855. s = &settings[0];
  856. for (i = 0; i < ARRAY_SIZE(prop2); i++)
  857. pcs_add_conf2(pcs, np, prop2[i].name, prop2[i].param,
  858. &conf, &s);
  859. for (i = 0; i < ARRAY_SIZE(prop4); i++)
  860. pcs_add_conf4(pcs, np, prop4[i].name, prop4[i].param,
  861. &conf, &s);
  862. m->type = PIN_MAP_TYPE_CONFIGS_GROUP;
  863. m->data.configs.group_or_pin = np->name;
  864. m->data.configs.configs = settings;
  865. m->data.configs.num_configs = nconfs;
  866. return 0;
  867. }
  868. /**
  869. * smux_parse_one_pinctrl_entry() - parses a device tree mux entry
  870. * @pctldev: pin controller device
  871. * @pcs: pinctrl driver instance
  872. * @np: device node of the mux entry
  873. * @map: map entry
  874. * @num_maps: number of map
  875. * @pgnames: pingroup names
  876. *
  877. * Note that this binding currently supports only sets of one register + value.
  878. *
  879. * Also note that this driver tries to avoid understanding pin and function
  880. * names because of the extra bloat they would cause especially in the case of
  881. * a large number of pins. This driver just sets what is specified for the board
  882. * in the .dts file. Further user space debugging tools can be developed to
  883. * decipher the pin and function names using debugfs.
  884. *
  885. * If you are concerned about the boot time, set up the static pins in
  886. * the bootloader, and only set up selected pins as device tree entries.
  887. */
  888. static int pcs_parse_one_pinctrl_entry(struct pcs_device *pcs,
  889. struct device_node *np,
  890. struct pinctrl_map **map,
  891. unsigned *num_maps,
  892. const char **pgnames)
  893. {
  894. const char *name = "pinctrl-single,pins";
  895. struct pcs_func_vals *vals;
  896. int rows, *pins, found = 0, res = -ENOMEM, i;
  897. struct pcs_function *function;
  898. rows = pinctrl_count_index_with_args(np, name);
  899. if (rows <= 0) {
  900. dev_err(pcs->dev, "Invalid number of rows: %d\n", rows);
  901. return -EINVAL;
  902. }
  903. vals = devm_kzalloc(pcs->dev, sizeof(*vals) * rows, GFP_KERNEL);
  904. if (!vals)
  905. return -ENOMEM;
  906. pins = devm_kzalloc(pcs->dev, sizeof(*pins) * rows, GFP_KERNEL);
  907. if (!pins)
  908. goto free_vals;
  909. for (i = 0; i < rows; i++) {
  910. struct of_phandle_args pinctrl_spec;
  911. unsigned int offset;
  912. int pin;
  913. res = pinctrl_parse_index_with_args(np, name, i, &pinctrl_spec);
  914. if (res)
  915. return res;
  916. if (pinctrl_spec.args_count < 2) {
  917. dev_err(pcs->dev, "invalid args_count for spec: %i\n",
  918. pinctrl_spec.args_count);
  919. break;
  920. }
  921. /* Index plus one value cell */
  922. offset = pinctrl_spec.args[0];
  923. vals[found].reg = pcs->base + offset;
  924. vals[found].val = pinctrl_spec.args[1];
  925. dev_dbg(pcs->dev, "%s index: 0x%x value: 0x%x\n",
  926. pinctrl_spec.np->name, offset, pinctrl_spec.args[1]);
  927. pin = pcs_get_pin_by_offset(pcs, offset);
  928. if (pin < 0) {
  929. dev_err(pcs->dev,
  930. "could not add functions for %s %ux\n",
  931. np->name, offset);
  932. break;
  933. }
  934. pins[found++] = pin;
  935. }
  936. pgnames[0] = np->name;
  937. function = pcs_add_function(pcs, np, np->name, vals, found, pgnames, 1);
  938. if (!function) {
  939. res = -ENOMEM;
  940. goto free_pins;
  941. }
  942. res = pinctrl_generic_add_group(pcs->pctl, np->name, pins, found, pcs);
  943. if (res < 0)
  944. goto free_function;
  945. (*map)->type = PIN_MAP_TYPE_MUX_GROUP;
  946. (*map)->data.mux.group = np->name;
  947. (*map)->data.mux.function = np->name;
  948. if (PCS_HAS_PINCONF) {
  949. res = pcs_parse_pinconf(pcs, np, function, map);
  950. if (res)
  951. goto free_pingroups;
  952. *num_maps = 2;
  953. } else {
  954. *num_maps = 1;
  955. }
  956. return 0;
  957. free_pingroups:
  958. pinctrl_generic_remove_last_group(pcs->pctl);
  959. *num_maps = 1;
  960. free_function:
  961. pinmux_generic_remove_last_function(pcs->pctl);
  962. free_pins:
  963. devm_kfree(pcs->dev, pins);
  964. free_vals:
  965. devm_kfree(pcs->dev, vals);
  966. return res;
  967. }
  968. static int pcs_parse_bits_in_pinctrl_entry(struct pcs_device *pcs,
  969. struct device_node *np,
  970. struct pinctrl_map **map,
  971. unsigned *num_maps,
  972. const char **pgnames)
  973. {
  974. const char *name = "pinctrl-single,bits";
  975. struct pcs_func_vals *vals;
  976. int rows, *pins, found = 0, res = -ENOMEM, i;
  977. int npins_in_row;
  978. struct pcs_function *function;
  979. rows = pinctrl_count_index_with_args(np, name);
  980. if (rows <= 0) {
  981. dev_err(pcs->dev, "Invalid number of rows: %d\n", rows);
  982. return -EINVAL;
  983. }
  984. npins_in_row = pcs->width / pcs->bits_per_pin;
  985. vals = devm_kzalloc(pcs->dev, sizeof(*vals) * rows * npins_in_row,
  986. GFP_KERNEL);
  987. if (!vals)
  988. return -ENOMEM;
  989. pins = devm_kzalloc(pcs->dev, sizeof(*pins) * rows * npins_in_row,
  990. GFP_KERNEL);
  991. if (!pins)
  992. goto free_vals;
  993. for (i = 0; i < rows; i++) {
  994. struct of_phandle_args pinctrl_spec;
  995. unsigned offset, val;
  996. unsigned mask, bit_pos, val_pos, mask_pos, submask;
  997. unsigned pin_num_from_lsb;
  998. int pin;
  999. res = pinctrl_parse_index_with_args(np, name, i, &pinctrl_spec);
  1000. if (res)
  1001. return res;
  1002. if (pinctrl_spec.args_count < 3) {
  1003. dev_err(pcs->dev, "invalid args_count for spec: %i\n",
  1004. pinctrl_spec.args_count);
  1005. break;
  1006. }
  1007. /* Index plus two value cells */
  1008. offset = pinctrl_spec.args[0];
  1009. val = pinctrl_spec.args[1];
  1010. mask = pinctrl_spec.args[2];
  1011. dev_dbg(pcs->dev, "%s index: 0x%x value: 0x%x mask: 0x%x\n",
  1012. pinctrl_spec.np->name, offset, val, mask);
  1013. /* Parse pins in each row from LSB */
  1014. while (mask) {
  1015. bit_pos = __ffs(mask);
  1016. pin_num_from_lsb = bit_pos / pcs->bits_per_pin;
  1017. mask_pos = ((pcs->fmask) << bit_pos);
  1018. val_pos = val & mask_pos;
  1019. submask = mask & mask_pos;
  1020. if ((mask & mask_pos) == 0) {
  1021. dev_err(pcs->dev,
  1022. "Invalid mask for %s at 0x%x\n",
  1023. np->name, offset);
  1024. break;
  1025. }
  1026. mask &= ~mask_pos;
  1027. if (submask != mask_pos) {
  1028. dev_warn(pcs->dev,
  1029. "Invalid submask 0x%x for %s at 0x%x\n",
  1030. submask, np->name, offset);
  1031. continue;
  1032. }
  1033. vals[found].mask = submask;
  1034. vals[found].reg = pcs->base + offset;
  1035. vals[found].val = val_pos;
  1036. pin = pcs_get_pin_by_offset(pcs, offset);
  1037. if (pin < 0) {
  1038. dev_err(pcs->dev,
  1039. "could not add functions for %s %ux\n",
  1040. np->name, offset);
  1041. break;
  1042. }
  1043. pins[found++] = pin + pin_num_from_lsb;
  1044. }
  1045. }
  1046. pgnames[0] = np->name;
  1047. function = pcs_add_function(pcs, np, np->name, vals, found, pgnames, 1);
  1048. if (!function) {
  1049. res = -ENOMEM;
  1050. goto free_pins;
  1051. }
  1052. res = pinctrl_generic_add_group(pcs->pctl, np->name, pins, found, pcs);
  1053. if (res < 0)
  1054. goto free_function;
  1055. (*map)->type = PIN_MAP_TYPE_MUX_GROUP;
  1056. (*map)->data.mux.group = np->name;
  1057. (*map)->data.mux.function = np->name;
  1058. if (PCS_HAS_PINCONF) {
  1059. dev_err(pcs->dev, "pinconf not supported\n");
  1060. goto free_pingroups;
  1061. }
  1062. *num_maps = 1;
  1063. return 0;
  1064. free_pingroups:
  1065. pinctrl_generic_remove_last_group(pcs->pctl);
  1066. *num_maps = 1;
  1067. free_function:
  1068. pinmux_generic_remove_last_function(pcs->pctl);
  1069. free_pins:
  1070. devm_kfree(pcs->dev, pins);
  1071. free_vals:
  1072. devm_kfree(pcs->dev, vals);
  1073. return res;
  1074. }
  1075. /**
  1076. * pcs_dt_node_to_map() - allocates and parses pinctrl maps
  1077. * @pctldev: pinctrl instance
  1078. * @np_config: device tree pinmux entry
  1079. * @map: array of map entries
  1080. * @num_maps: number of maps
  1081. */
  1082. static int pcs_dt_node_to_map(struct pinctrl_dev *pctldev,
  1083. struct device_node *np_config,
  1084. struct pinctrl_map **map, unsigned *num_maps)
  1085. {
  1086. struct pcs_device *pcs;
  1087. const char **pgnames;
  1088. int ret;
  1089. pcs = pinctrl_dev_get_drvdata(pctldev);
  1090. /* create 2 maps. One is for pinmux, and the other is for pinconf. */
  1091. *map = devm_kzalloc(pcs->dev, sizeof(**map) * 2, GFP_KERNEL);
  1092. if (!*map)
  1093. return -ENOMEM;
  1094. *num_maps = 0;
  1095. pgnames = devm_kzalloc(pcs->dev, sizeof(*pgnames), GFP_KERNEL);
  1096. if (!pgnames) {
  1097. ret = -ENOMEM;
  1098. goto free_map;
  1099. }
  1100. if (pcs->bits_per_mux) {
  1101. ret = pcs_parse_bits_in_pinctrl_entry(pcs, np_config, map,
  1102. num_maps, pgnames);
  1103. if (ret < 0) {
  1104. dev_err(pcs->dev, "no pins entries for %s\n",
  1105. np_config->name);
  1106. goto free_pgnames;
  1107. }
  1108. } else {
  1109. ret = pcs_parse_one_pinctrl_entry(pcs, np_config, map,
  1110. num_maps, pgnames);
  1111. if (ret < 0) {
  1112. dev_err(pcs->dev, "no pins entries for %s\n",
  1113. np_config->name);
  1114. goto free_pgnames;
  1115. }
  1116. }
  1117. return 0;
  1118. free_pgnames:
  1119. devm_kfree(pcs->dev, pgnames);
  1120. free_map:
  1121. devm_kfree(pcs->dev, *map);
  1122. return ret;
  1123. }
  1124. /**
  1125. * pcs_irq_free() - free interrupt
  1126. * @pcs: pcs driver instance
  1127. */
  1128. static void pcs_irq_free(struct pcs_device *pcs)
  1129. {
  1130. struct pcs_soc_data *pcs_soc = &pcs->socdata;
  1131. if (pcs_soc->irq < 0)
  1132. return;
  1133. if (pcs->domain)
  1134. irq_domain_remove(pcs->domain);
  1135. if (PCS_QUIRK_HAS_SHARED_IRQ)
  1136. free_irq(pcs_soc->irq, pcs_soc);
  1137. else
  1138. irq_set_chained_handler(pcs_soc->irq, NULL);
  1139. }
  1140. /**
  1141. * pcs_free_resources() - free memory used by this driver
  1142. * @pcs: pcs driver instance
  1143. */
  1144. static void pcs_free_resources(struct pcs_device *pcs)
  1145. {
  1146. pcs_irq_free(pcs);
  1147. pinctrl_unregister(pcs->pctl);
  1148. #if IS_BUILTIN(CONFIG_PINCTRL_SINGLE)
  1149. if (pcs->missing_nr_pinctrl_cells)
  1150. of_remove_property(pcs->np, pcs->missing_nr_pinctrl_cells);
  1151. #endif
  1152. }
  1153. static const struct of_device_id pcs_of_match[];
  1154. static int pcs_add_gpio_func(struct device_node *node, struct pcs_device *pcs)
  1155. {
  1156. const char *propname = "pinctrl-single,gpio-range";
  1157. const char *cellname = "#pinctrl-single,gpio-range-cells";
  1158. struct of_phandle_args gpiospec;
  1159. struct pcs_gpiofunc_range *range;
  1160. int ret, i;
  1161. for (i = 0; ; i++) {
  1162. ret = of_parse_phandle_with_args(node, propname, cellname,
  1163. i, &gpiospec);
  1164. /* Do not treat it as error. Only treat it as end condition. */
  1165. if (ret) {
  1166. ret = 0;
  1167. break;
  1168. }
  1169. range = devm_kzalloc(pcs->dev, sizeof(*range), GFP_KERNEL);
  1170. if (!range) {
  1171. ret = -ENOMEM;
  1172. break;
  1173. }
  1174. range->offset = gpiospec.args[0];
  1175. range->npins = gpiospec.args[1];
  1176. range->gpiofunc = gpiospec.args[2];
  1177. mutex_lock(&pcs->mutex);
  1178. list_add_tail(&range->node, &pcs->gpiofuncs);
  1179. mutex_unlock(&pcs->mutex);
  1180. }
  1181. return ret;
  1182. }
  1183. /**
  1184. * @reg: virtual address of interrupt register
  1185. * @hwirq: hardware irq number
  1186. * @irq: virtual irq number
  1187. * @node: list node
  1188. */
  1189. struct pcs_interrupt {
  1190. void __iomem *reg;
  1191. irq_hw_number_t hwirq;
  1192. unsigned int irq;
  1193. struct list_head node;
  1194. };
  1195. /**
  1196. * pcs_irq_set() - enables or disables an interrupt
  1197. *
  1198. * Note that this currently assumes one interrupt per pinctrl
  1199. * register that is typically used for wake-up events.
  1200. */
  1201. static inline void pcs_irq_set(struct pcs_soc_data *pcs_soc,
  1202. int irq, const bool enable)
  1203. {
  1204. struct pcs_device *pcs;
  1205. struct list_head *pos;
  1206. unsigned mask;
  1207. pcs = container_of(pcs_soc, struct pcs_device, socdata);
  1208. list_for_each(pos, &pcs->irqs) {
  1209. struct pcs_interrupt *pcswi;
  1210. unsigned soc_mask;
  1211. pcswi = list_entry(pos, struct pcs_interrupt, node);
  1212. if (irq != pcswi->irq)
  1213. continue;
  1214. soc_mask = pcs_soc->irq_enable_mask;
  1215. raw_spin_lock(&pcs->lock);
  1216. mask = pcs->read(pcswi->reg);
  1217. if (enable)
  1218. mask |= soc_mask;
  1219. else
  1220. mask &= ~soc_mask;
  1221. pcs->write(mask, pcswi->reg);
  1222. /* flush posted write */
  1223. mask = pcs->read(pcswi->reg);
  1224. raw_spin_unlock(&pcs->lock);
  1225. }
  1226. if (pcs_soc->rearm)
  1227. pcs_soc->rearm();
  1228. }
  1229. /**
  1230. * pcs_irq_mask() - mask pinctrl interrupt
  1231. * @d: interrupt data
  1232. */
  1233. static void pcs_irq_mask(struct irq_data *d)
  1234. {
  1235. struct pcs_soc_data *pcs_soc = irq_data_get_irq_chip_data(d);
  1236. pcs_irq_set(pcs_soc, d->irq, false);
  1237. }
  1238. /**
  1239. * pcs_irq_unmask() - unmask pinctrl interrupt
  1240. * @d: interrupt data
  1241. */
  1242. static void pcs_irq_unmask(struct irq_data *d)
  1243. {
  1244. struct pcs_soc_data *pcs_soc = irq_data_get_irq_chip_data(d);
  1245. pcs_irq_set(pcs_soc, d->irq, true);
  1246. }
  1247. /**
  1248. * pcs_irq_set_wake() - toggle the suspend and resume wake up
  1249. * @d: interrupt data
  1250. * @state: wake-up state
  1251. *
  1252. * Note that this should be called only for suspend and resume.
  1253. * For runtime PM, the wake-up events should be enabled by default.
  1254. */
  1255. static int pcs_irq_set_wake(struct irq_data *d, unsigned int state)
  1256. {
  1257. if (state)
  1258. pcs_irq_unmask(d);
  1259. else
  1260. pcs_irq_mask(d);
  1261. return 0;
  1262. }
  1263. /**
  1264. * pcs_irq_handle() - common interrupt handler
  1265. * @pcs_irq: interrupt data
  1266. *
  1267. * Note that this currently assumes we have one interrupt bit per
  1268. * mux register. This interrupt is typically used for wake-up events.
  1269. * For more complex interrupts different handlers can be specified.
  1270. */
  1271. static int pcs_irq_handle(struct pcs_soc_data *pcs_soc)
  1272. {
  1273. struct pcs_device *pcs;
  1274. struct list_head *pos;
  1275. int count = 0;
  1276. pcs = container_of(pcs_soc, struct pcs_device, socdata);
  1277. list_for_each(pos, &pcs->irqs) {
  1278. struct pcs_interrupt *pcswi;
  1279. unsigned mask;
  1280. pcswi = list_entry(pos, struct pcs_interrupt, node);
  1281. raw_spin_lock(&pcs->lock);
  1282. mask = pcs->read(pcswi->reg);
  1283. raw_spin_unlock(&pcs->lock);
  1284. if (mask & pcs_soc->irq_status_mask) {
  1285. generic_handle_irq(irq_find_mapping(pcs->domain,
  1286. pcswi->hwirq));
  1287. count++;
  1288. }
  1289. }
  1290. return count;
  1291. }
  1292. /**
  1293. * pcs_irq_handler() - handler for the shared interrupt case
  1294. * @irq: interrupt
  1295. * @d: data
  1296. *
  1297. * Use this for cases where multiple instances of
  1298. * pinctrl-single share a single interrupt like on omaps.
  1299. */
  1300. static irqreturn_t pcs_irq_handler(int irq, void *d)
  1301. {
  1302. struct pcs_soc_data *pcs_soc = d;
  1303. return pcs_irq_handle(pcs_soc) ? IRQ_HANDLED : IRQ_NONE;
  1304. }
  1305. /**
  1306. * pcs_irq_handle() - handler for the dedicated chained interrupt case
  1307. * @irq: interrupt
  1308. * @desc: interrupt descriptor
  1309. *
  1310. * Use this if you have a separate interrupt for each
  1311. * pinctrl-single instance.
  1312. */
  1313. static void pcs_irq_chain_handler(struct irq_desc *desc)
  1314. {
  1315. struct pcs_soc_data *pcs_soc = irq_desc_get_handler_data(desc);
  1316. struct irq_chip *chip;
  1317. chip = irq_desc_get_chip(desc);
  1318. chained_irq_enter(chip, desc);
  1319. pcs_irq_handle(pcs_soc);
  1320. /* REVISIT: export and add handle_bad_irq(irq, desc)? */
  1321. chained_irq_exit(chip, desc);
  1322. return;
  1323. }
  1324. static int pcs_irqdomain_map(struct irq_domain *d, unsigned int irq,
  1325. irq_hw_number_t hwirq)
  1326. {
  1327. struct pcs_soc_data *pcs_soc = d->host_data;
  1328. struct pcs_device *pcs;
  1329. struct pcs_interrupt *pcswi;
  1330. pcs = container_of(pcs_soc, struct pcs_device, socdata);
  1331. pcswi = devm_kzalloc(pcs->dev, sizeof(*pcswi), GFP_KERNEL);
  1332. if (!pcswi)
  1333. return -ENOMEM;
  1334. pcswi->reg = pcs->base + hwirq;
  1335. pcswi->hwirq = hwirq;
  1336. pcswi->irq = irq;
  1337. mutex_lock(&pcs->mutex);
  1338. list_add_tail(&pcswi->node, &pcs->irqs);
  1339. mutex_unlock(&pcs->mutex);
  1340. irq_set_chip_data(irq, pcs_soc);
  1341. irq_set_chip_and_handler(irq, &pcs->chip,
  1342. handle_level_irq);
  1343. irq_set_lockdep_class(irq, &pcs_lock_class);
  1344. irq_set_noprobe(irq);
  1345. return 0;
  1346. }
  1347. static const struct irq_domain_ops pcs_irqdomain_ops = {
  1348. .map = pcs_irqdomain_map,
  1349. .xlate = irq_domain_xlate_onecell,
  1350. };
  1351. /**
  1352. * pcs_irq_init_chained_handler() - set up a chained interrupt handler
  1353. * @pcs: pcs driver instance
  1354. * @np: device node pointer
  1355. */
  1356. static int pcs_irq_init_chained_handler(struct pcs_device *pcs,
  1357. struct device_node *np)
  1358. {
  1359. struct pcs_soc_data *pcs_soc = &pcs->socdata;
  1360. const char *name = "pinctrl";
  1361. int num_irqs;
  1362. if (!pcs_soc->irq_enable_mask ||
  1363. !pcs_soc->irq_status_mask) {
  1364. pcs_soc->irq = -1;
  1365. return -EINVAL;
  1366. }
  1367. INIT_LIST_HEAD(&pcs->irqs);
  1368. pcs->chip.name = name;
  1369. pcs->chip.irq_ack = pcs_irq_mask;
  1370. pcs->chip.irq_mask = pcs_irq_mask;
  1371. pcs->chip.irq_unmask = pcs_irq_unmask;
  1372. pcs->chip.irq_set_wake = pcs_irq_set_wake;
  1373. if (PCS_QUIRK_HAS_SHARED_IRQ) {
  1374. int res;
  1375. res = request_irq(pcs_soc->irq, pcs_irq_handler,
  1376. IRQF_SHARED | IRQF_NO_SUSPEND |
  1377. IRQF_NO_THREAD,
  1378. name, pcs_soc);
  1379. if (res) {
  1380. pcs_soc->irq = -1;
  1381. return res;
  1382. }
  1383. } else {
  1384. irq_set_chained_handler_and_data(pcs_soc->irq,
  1385. pcs_irq_chain_handler,
  1386. pcs_soc);
  1387. }
  1388. /*
  1389. * We can use the register offset as the hardirq
  1390. * number as irq_domain_add_simple maps them lazily.
  1391. * This way we can easily support more than one
  1392. * interrupt per function if needed.
  1393. */
  1394. num_irqs = pcs->size;
  1395. pcs->domain = irq_domain_add_simple(np, num_irqs, 0,
  1396. &pcs_irqdomain_ops,
  1397. pcs_soc);
  1398. if (!pcs->domain) {
  1399. irq_set_chained_handler(pcs_soc->irq, NULL);
  1400. return -EINVAL;
  1401. }
  1402. return 0;
  1403. }
  1404. #ifdef CONFIG_PM
  1405. static int pinctrl_single_suspend(struct platform_device *pdev,
  1406. pm_message_t state)
  1407. {
  1408. struct pcs_device *pcs;
  1409. pcs = platform_get_drvdata(pdev);
  1410. if (!pcs)
  1411. return -EINVAL;
  1412. return pinctrl_force_sleep(pcs->pctl);
  1413. }
  1414. static int pinctrl_single_resume(struct platform_device *pdev)
  1415. {
  1416. struct pcs_device *pcs;
  1417. pcs = platform_get_drvdata(pdev);
  1418. if (!pcs)
  1419. return -EINVAL;
  1420. return pinctrl_force_default(pcs->pctl);
  1421. }
  1422. #endif
  1423. /**
  1424. * pcs_quirk_missing_pinctrl_cells - handle legacy binding
  1425. * @pcs: pinctrl driver instance
  1426. * @np: device tree node
  1427. * @cells: number of cells
  1428. *
  1429. * Handle legacy binding with no #pinctrl-cells. This should be
  1430. * always two pinctrl-single,bit-per-mux and one for others.
  1431. * At some point we may want to consider removing this.
  1432. */
  1433. static int pcs_quirk_missing_pinctrl_cells(struct pcs_device *pcs,
  1434. struct device_node *np,
  1435. int cells)
  1436. {
  1437. struct property *p;
  1438. const char *name = "#pinctrl-cells";
  1439. int error;
  1440. u32 val;
  1441. error = of_property_read_u32(np, name, &val);
  1442. if (!error)
  1443. return 0;
  1444. dev_warn(pcs->dev, "please update dts to use %s = <%i>\n",
  1445. name, cells);
  1446. p = devm_kzalloc(pcs->dev, sizeof(*p), GFP_KERNEL);
  1447. if (!p)
  1448. return -ENOMEM;
  1449. p->length = sizeof(__be32);
  1450. p->value = devm_kzalloc(pcs->dev, sizeof(__be32), GFP_KERNEL);
  1451. if (!p->value)
  1452. return -ENOMEM;
  1453. *(__be32 *)p->value = cpu_to_be32(cells);
  1454. p->name = devm_kstrdup(pcs->dev, name, GFP_KERNEL);
  1455. if (!p->name)
  1456. return -ENOMEM;
  1457. pcs->missing_nr_pinctrl_cells = p;
  1458. #if IS_BUILTIN(CONFIG_PINCTRL_SINGLE)
  1459. error = of_add_property(np, pcs->missing_nr_pinctrl_cells);
  1460. #endif
  1461. return error;
  1462. }
  1463. static int pcs_probe(struct platform_device *pdev)
  1464. {
  1465. struct device_node *np = pdev->dev.of_node;
  1466. const struct of_device_id *match;
  1467. struct pcs_pdata *pdata;
  1468. struct resource *res;
  1469. struct pcs_device *pcs;
  1470. const struct pcs_soc_data *soc;
  1471. int ret;
  1472. match = of_match_device(pcs_of_match, &pdev->dev);
  1473. if (!match)
  1474. return -EINVAL;
  1475. pcs = devm_kzalloc(&pdev->dev, sizeof(*pcs), GFP_KERNEL);
  1476. if (!pcs) {
  1477. dev_err(&pdev->dev, "could not allocate\n");
  1478. return -ENOMEM;
  1479. }
  1480. pcs->dev = &pdev->dev;
  1481. pcs->np = np;
  1482. raw_spin_lock_init(&pcs->lock);
  1483. mutex_init(&pcs->mutex);
  1484. INIT_LIST_HEAD(&pcs->gpiofuncs);
  1485. soc = match->data;
  1486. pcs->flags = soc->flags;
  1487. memcpy(&pcs->socdata, soc, sizeof(*soc));
  1488. ret = of_property_read_u32(np, "pinctrl-single,register-width",
  1489. &pcs->width);
  1490. if (ret) {
  1491. dev_err(pcs->dev, "register width not specified\n");
  1492. return ret;
  1493. }
  1494. ret = of_property_read_u32(np, "pinctrl-single,function-mask",
  1495. &pcs->fmask);
  1496. if (!ret) {
  1497. pcs->fshift = __ffs(pcs->fmask);
  1498. pcs->fmax = pcs->fmask >> pcs->fshift;
  1499. } else {
  1500. /* If mask property doesn't exist, function mux is invalid. */
  1501. pcs->fmask = 0;
  1502. pcs->fshift = 0;
  1503. pcs->fmax = 0;
  1504. }
  1505. ret = of_property_read_u32(np, "pinctrl-single,function-off",
  1506. &pcs->foff);
  1507. if (ret)
  1508. pcs->foff = PCS_OFF_DISABLED;
  1509. pcs->bits_per_mux = of_property_read_bool(np,
  1510. "pinctrl-single,bit-per-mux");
  1511. ret = pcs_quirk_missing_pinctrl_cells(pcs, np,
  1512. pcs->bits_per_mux ? 2 : 1);
  1513. if (ret) {
  1514. dev_err(&pdev->dev, "unable to patch #pinctrl-cells\n");
  1515. return ret;
  1516. }
  1517. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1518. if (!res) {
  1519. dev_err(pcs->dev, "could not get resource\n");
  1520. return -ENODEV;
  1521. }
  1522. pcs->res = devm_request_mem_region(pcs->dev, res->start,
  1523. resource_size(res), DRIVER_NAME);
  1524. if (!pcs->res) {
  1525. dev_err(pcs->dev, "could not get mem_region\n");
  1526. return -EBUSY;
  1527. }
  1528. pcs->size = resource_size(pcs->res);
  1529. pcs->base = devm_ioremap(pcs->dev, pcs->res->start, pcs->size);
  1530. if (!pcs->base) {
  1531. dev_err(pcs->dev, "could not ioremap\n");
  1532. return -ENODEV;
  1533. }
  1534. platform_set_drvdata(pdev, pcs);
  1535. switch (pcs->width) {
  1536. case 8:
  1537. pcs->read = pcs_readb;
  1538. pcs->write = pcs_writeb;
  1539. break;
  1540. case 16:
  1541. pcs->read = pcs_readw;
  1542. pcs->write = pcs_writew;
  1543. break;
  1544. case 32:
  1545. pcs->read = pcs_readl;
  1546. pcs->write = pcs_writel;
  1547. break;
  1548. default:
  1549. break;
  1550. }
  1551. pcs->desc.name = DRIVER_NAME;
  1552. pcs->desc.pctlops = &pcs_pinctrl_ops;
  1553. pcs->desc.pmxops = &pcs_pinmux_ops;
  1554. if (PCS_HAS_PINCONF)
  1555. pcs->desc.confops = &pcs_pinconf_ops;
  1556. pcs->desc.owner = THIS_MODULE;
  1557. ret = pcs_allocate_pin_table(pcs);
  1558. if (ret < 0)
  1559. goto free;
  1560. ret = pinctrl_register_and_init(&pcs->desc, pcs->dev, pcs, &pcs->pctl);
  1561. if (ret) {
  1562. dev_err(pcs->dev, "could not register single pinctrl driver\n");
  1563. goto free;
  1564. }
  1565. ret = pcs_add_gpio_func(np, pcs);
  1566. if (ret < 0)
  1567. goto free;
  1568. pcs->socdata.irq = irq_of_parse_and_map(np, 0);
  1569. if (pcs->socdata.irq)
  1570. pcs->flags |= PCS_FEAT_IRQ;
  1571. /* We still need auxdata for some omaps for PRM interrupts */
  1572. pdata = dev_get_platdata(&pdev->dev);
  1573. if (pdata) {
  1574. if (pdata->rearm)
  1575. pcs->socdata.rearm = pdata->rearm;
  1576. if (pdata->irq) {
  1577. pcs->socdata.irq = pdata->irq;
  1578. pcs->flags |= PCS_FEAT_IRQ;
  1579. }
  1580. }
  1581. if (PCS_HAS_IRQ) {
  1582. ret = pcs_irq_init_chained_handler(pcs, np);
  1583. if (ret < 0)
  1584. dev_warn(pcs->dev, "initialized with no interrupts\n");
  1585. }
  1586. dev_info(pcs->dev, "%i pins at pa %p size %u\n",
  1587. pcs->desc.npins, pcs->base, pcs->size);
  1588. return 0;
  1589. free:
  1590. pcs_free_resources(pcs);
  1591. return ret;
  1592. }
  1593. static int pcs_remove(struct platform_device *pdev)
  1594. {
  1595. struct pcs_device *pcs = platform_get_drvdata(pdev);
  1596. if (!pcs)
  1597. return 0;
  1598. pcs_free_resources(pcs);
  1599. return 0;
  1600. }
  1601. static const struct pcs_soc_data pinctrl_single_omap_wkup = {
  1602. .flags = PCS_QUIRK_SHARED_IRQ,
  1603. .irq_enable_mask = (1 << 14), /* OMAP_WAKEUP_EN */
  1604. .irq_status_mask = (1 << 15), /* OMAP_WAKEUP_EVENT */
  1605. };
  1606. static const struct pcs_soc_data pinctrl_single_dra7 = {
  1607. .irq_enable_mask = (1 << 24), /* WAKEUPENABLE */
  1608. .irq_status_mask = (1 << 25), /* WAKEUPEVENT */
  1609. };
  1610. static const struct pcs_soc_data pinctrl_single_am437x = {
  1611. .flags = PCS_QUIRK_SHARED_IRQ,
  1612. .irq_enable_mask = (1 << 29), /* OMAP_WAKEUP_EN */
  1613. .irq_status_mask = (1 << 30), /* OMAP_WAKEUP_EVENT */
  1614. };
  1615. static const struct pcs_soc_data pinctrl_single = {
  1616. };
  1617. static const struct pcs_soc_data pinconf_single = {
  1618. .flags = PCS_FEAT_PINCONF,
  1619. };
  1620. static const struct of_device_id pcs_of_match[] = {
  1621. { .compatible = "ti,omap3-padconf", .data = &pinctrl_single_omap_wkup },
  1622. { .compatible = "ti,omap4-padconf", .data = &pinctrl_single_omap_wkup },
  1623. { .compatible = "ti,omap5-padconf", .data = &pinctrl_single_omap_wkup },
  1624. { .compatible = "ti,dra7-padconf", .data = &pinctrl_single_dra7 },
  1625. { .compatible = "ti,am437-padconf", .data = &pinctrl_single_am437x },
  1626. { .compatible = "pinctrl-single", .data = &pinctrl_single },
  1627. { .compatible = "pinconf-single", .data = &pinconf_single },
  1628. { },
  1629. };
  1630. MODULE_DEVICE_TABLE(of, pcs_of_match);
  1631. static struct platform_driver pcs_driver = {
  1632. .probe = pcs_probe,
  1633. .remove = pcs_remove,
  1634. .driver = {
  1635. .name = DRIVER_NAME,
  1636. .of_match_table = pcs_of_match,
  1637. },
  1638. #ifdef CONFIG_PM
  1639. .suspend = pinctrl_single_suspend,
  1640. .resume = pinctrl_single_resume,
  1641. #endif
  1642. };
  1643. module_platform_driver(pcs_driver);
  1644. MODULE_AUTHOR("Tony Lindgren <tony@atomide.com>");
  1645. MODULE_DESCRIPTION("One-register-per-pin type device tree based pinctrl driver");
  1646. MODULE_LICENSE("GPL v2");