core.c 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958
  1. /*
  2. * Core driver for the pin control subsystem
  3. *
  4. * Copyright (C) 2011-2012 ST-Ericsson SA
  5. * Written on behalf of Linaro for ST-Ericsson
  6. * Based on bits of regulator core, gpio core and clk core
  7. *
  8. * Author: Linus Walleij <linus.walleij@linaro.org>
  9. *
  10. * Copyright (C) 2012 NVIDIA CORPORATION. All rights reserved.
  11. *
  12. * License terms: GNU General Public License (GPL) version 2
  13. */
  14. #define pr_fmt(fmt) "pinctrl core: " fmt
  15. #include <linux/kernel.h>
  16. #include <linux/kref.h>
  17. #include <linux/export.h>
  18. #include <linux/init.h>
  19. #include <linux/device.h>
  20. #include <linux/slab.h>
  21. #include <linux/err.h>
  22. #include <linux/list.h>
  23. #include <linux/sysfs.h>
  24. #include <linux/debugfs.h>
  25. #include <linux/seq_file.h>
  26. #include <linux/pinctrl/consumer.h>
  27. #include <linux/pinctrl/pinctrl.h>
  28. #include <linux/pinctrl/machine.h>
  29. #ifdef CONFIG_GPIOLIB
  30. #include <asm-generic/gpio.h>
  31. #endif
  32. #include "core.h"
  33. #include "devicetree.h"
  34. #include "pinmux.h"
  35. #include "pinconf.h"
  36. static bool pinctrl_dummy_state;
  37. /* Mutex taken to protect pinctrl_list */
  38. static DEFINE_MUTEX(pinctrl_list_mutex);
  39. /* Mutex taken to protect pinctrl_maps */
  40. DEFINE_MUTEX(pinctrl_maps_mutex);
  41. /* Mutex taken to protect pinctrldev_list */
  42. static DEFINE_MUTEX(pinctrldev_list_mutex);
  43. /* Global list of pin control devices (struct pinctrl_dev) */
  44. static LIST_HEAD(pinctrldev_list);
  45. /* List of pin controller handles (struct pinctrl) */
  46. static LIST_HEAD(pinctrl_list);
  47. /* List of pinctrl maps (struct pinctrl_maps) */
  48. LIST_HEAD(pinctrl_maps);
  49. /**
  50. * pinctrl_provide_dummies() - indicate if pinctrl provides dummy state support
  51. *
  52. * Usually this function is called by platforms without pinctrl driver support
  53. * but run with some shared drivers using pinctrl APIs.
  54. * After calling this function, the pinctrl core will return successfully
  55. * with creating a dummy state for the driver to keep going smoothly.
  56. */
  57. void pinctrl_provide_dummies(void)
  58. {
  59. pinctrl_dummy_state = true;
  60. }
  61. const char *pinctrl_dev_get_name(struct pinctrl_dev *pctldev)
  62. {
  63. /* We're not allowed to register devices without name */
  64. return pctldev->desc->name;
  65. }
  66. EXPORT_SYMBOL_GPL(pinctrl_dev_get_name);
  67. const char *pinctrl_dev_get_devname(struct pinctrl_dev *pctldev)
  68. {
  69. return dev_name(pctldev->dev);
  70. }
  71. EXPORT_SYMBOL_GPL(pinctrl_dev_get_devname);
  72. void *pinctrl_dev_get_drvdata(struct pinctrl_dev *pctldev)
  73. {
  74. return pctldev->driver_data;
  75. }
  76. EXPORT_SYMBOL_GPL(pinctrl_dev_get_drvdata);
  77. /**
  78. * get_pinctrl_dev_from_devname() - look up pin controller device
  79. * @devname: the name of a device instance, as returned by dev_name()
  80. *
  81. * Looks up a pin control device matching a certain device name or pure device
  82. * pointer, the pure device pointer will take precedence.
  83. */
  84. struct pinctrl_dev *get_pinctrl_dev_from_devname(const char *devname)
  85. {
  86. struct pinctrl_dev *pctldev = NULL;
  87. if (!devname)
  88. return NULL;
  89. mutex_lock(&pinctrldev_list_mutex);
  90. list_for_each_entry(pctldev, &pinctrldev_list, node) {
  91. if (!strcmp(dev_name(pctldev->dev), devname)) {
  92. /* Matched on device name */
  93. mutex_unlock(&pinctrldev_list_mutex);
  94. return pctldev;
  95. }
  96. }
  97. mutex_unlock(&pinctrldev_list_mutex);
  98. return NULL;
  99. }
  100. struct pinctrl_dev *get_pinctrl_dev_from_of_node(struct device_node *np)
  101. {
  102. struct pinctrl_dev *pctldev;
  103. mutex_lock(&pinctrldev_list_mutex);
  104. list_for_each_entry(pctldev, &pinctrldev_list, node)
  105. if (pctldev->dev->of_node == np) {
  106. mutex_unlock(&pinctrldev_list_mutex);
  107. return pctldev;
  108. }
  109. mutex_unlock(&pinctrldev_list_mutex);
  110. return NULL;
  111. }
  112. /**
  113. * pin_get_from_name() - look up a pin number from a name
  114. * @pctldev: the pin control device to lookup the pin on
  115. * @name: the name of the pin to look up
  116. */
  117. int pin_get_from_name(struct pinctrl_dev *pctldev, const char *name)
  118. {
  119. unsigned i, pin;
  120. /* The pin number can be retrived from the pin controller descriptor */
  121. for (i = 0; i < pctldev->desc->npins; i++) {
  122. struct pin_desc *desc;
  123. pin = pctldev->desc->pins[i].number;
  124. desc = pin_desc_get(pctldev, pin);
  125. /* Pin space may be sparse */
  126. if (desc && !strcmp(name, desc->name))
  127. return pin;
  128. }
  129. return -EINVAL;
  130. }
  131. /**
  132. * pin_get_name_from_id() - look up a pin name from a pin id
  133. * @pctldev: the pin control device to lookup the pin on
  134. * @name: the name of the pin to look up
  135. */
  136. const char *pin_get_name(struct pinctrl_dev *pctldev, const unsigned pin)
  137. {
  138. const struct pin_desc *desc;
  139. desc = pin_desc_get(pctldev, pin);
  140. if (desc == NULL) {
  141. dev_err(pctldev->dev, "failed to get pin(%d) name\n",
  142. pin);
  143. return NULL;
  144. }
  145. return desc->name;
  146. }
  147. /**
  148. * pin_is_valid() - check if pin exists on controller
  149. * @pctldev: the pin control device to check the pin on
  150. * @pin: pin to check, use the local pin controller index number
  151. *
  152. * This tells us whether a certain pin exist on a certain pin controller or
  153. * not. Pin lists may be sparse, so some pins may not exist.
  154. */
  155. bool pin_is_valid(struct pinctrl_dev *pctldev, int pin)
  156. {
  157. struct pin_desc *pindesc;
  158. if (pin < 0)
  159. return false;
  160. mutex_lock(&pctldev->mutex);
  161. pindesc = pin_desc_get(pctldev, pin);
  162. mutex_unlock(&pctldev->mutex);
  163. return pindesc != NULL;
  164. }
  165. EXPORT_SYMBOL_GPL(pin_is_valid);
  166. /* Deletes a range of pin descriptors */
  167. static void pinctrl_free_pindescs(struct pinctrl_dev *pctldev,
  168. const struct pinctrl_pin_desc *pins,
  169. unsigned num_pins)
  170. {
  171. int i;
  172. for (i = 0; i < num_pins; i++) {
  173. struct pin_desc *pindesc;
  174. pindesc = radix_tree_lookup(&pctldev->pin_desc_tree,
  175. pins[i].number);
  176. if (pindesc != NULL) {
  177. radix_tree_delete(&pctldev->pin_desc_tree,
  178. pins[i].number);
  179. if (pindesc->dynamic_name)
  180. kfree(pindesc->name);
  181. }
  182. kfree(pindesc);
  183. }
  184. }
  185. static int pinctrl_register_one_pin(struct pinctrl_dev *pctldev,
  186. const struct pinctrl_pin_desc *pin)
  187. {
  188. struct pin_desc *pindesc;
  189. pindesc = pin_desc_get(pctldev, pin->number);
  190. if (pindesc != NULL) {
  191. dev_err(pctldev->dev, "pin %d already registered\n",
  192. pin->number);
  193. return -EINVAL;
  194. }
  195. pindesc = kzalloc(sizeof(*pindesc), GFP_KERNEL);
  196. if (pindesc == NULL) {
  197. dev_err(pctldev->dev, "failed to alloc struct pin_desc\n");
  198. return -ENOMEM;
  199. }
  200. /* Set owner */
  201. pindesc->pctldev = pctldev;
  202. /* Copy basic pin info */
  203. if (pin->name) {
  204. pindesc->name = pin->name;
  205. } else {
  206. pindesc->name = kasprintf(GFP_KERNEL, "PIN%u", pin->number);
  207. if (pindesc->name == NULL) {
  208. kfree(pindesc);
  209. return -ENOMEM;
  210. }
  211. pindesc->dynamic_name = true;
  212. }
  213. pindesc->drv_data = pin->drv_data;
  214. radix_tree_insert(&pctldev->pin_desc_tree, pin->number, pindesc);
  215. pr_debug("registered pin %d (%s) on %s\n",
  216. pin->number, pindesc->name, pctldev->desc->name);
  217. return 0;
  218. }
  219. static int pinctrl_register_pins(struct pinctrl_dev *pctldev,
  220. struct pinctrl_pin_desc const *pins,
  221. unsigned num_descs)
  222. {
  223. unsigned i;
  224. int ret = 0;
  225. for (i = 0; i < num_descs; i++) {
  226. ret = pinctrl_register_one_pin(pctldev, &pins[i]);
  227. if (ret)
  228. return ret;
  229. }
  230. return 0;
  231. }
  232. /**
  233. * gpio_to_pin() - GPIO range GPIO number to pin number translation
  234. * @range: GPIO range used for the translation
  235. * @gpio: gpio pin to translate to a pin number
  236. *
  237. * Finds the pin number for a given GPIO using the specified GPIO range
  238. * as a base for translation. The distinction between linear GPIO ranges
  239. * and pin list based GPIO ranges is managed correctly by this function.
  240. *
  241. * This function assumes the gpio is part of the specified GPIO range, use
  242. * only after making sure this is the case (e.g. by calling it on the
  243. * result of successful pinctrl_get_device_gpio_range calls)!
  244. */
  245. static inline int gpio_to_pin(struct pinctrl_gpio_range *range,
  246. unsigned int gpio)
  247. {
  248. unsigned int offset = gpio - range->base;
  249. if (range->pins)
  250. return range->pins[offset];
  251. else
  252. return range->pin_base + offset;
  253. }
  254. /**
  255. * pinctrl_match_gpio_range() - check if a certain GPIO pin is in range
  256. * @pctldev: pin controller device to check
  257. * @gpio: gpio pin to check taken from the global GPIO pin space
  258. *
  259. * Tries to match a GPIO pin number to the ranges handled by a certain pin
  260. * controller, return the range or NULL
  261. */
  262. static struct pinctrl_gpio_range *
  263. pinctrl_match_gpio_range(struct pinctrl_dev *pctldev, unsigned gpio)
  264. {
  265. struct pinctrl_gpio_range *range = NULL;
  266. mutex_lock(&pctldev->mutex);
  267. /* Loop over the ranges */
  268. list_for_each_entry(range, &pctldev->gpio_ranges, node) {
  269. /* Check if we're in the valid range */
  270. if (gpio >= range->base &&
  271. gpio < range->base + range->npins) {
  272. mutex_unlock(&pctldev->mutex);
  273. return range;
  274. }
  275. }
  276. mutex_unlock(&pctldev->mutex);
  277. return NULL;
  278. }
  279. /**
  280. * pinctrl_ready_for_gpio_range() - check if other GPIO pins of
  281. * the same GPIO chip are in range
  282. * @gpio: gpio pin to check taken from the global GPIO pin space
  283. *
  284. * This function is complement of pinctrl_match_gpio_range(). If the return
  285. * value of pinctrl_match_gpio_range() is NULL, this function could be used
  286. * to check whether pinctrl device is ready or not. Maybe some GPIO pins
  287. * of the same GPIO chip don't have back-end pinctrl interface.
  288. * If the return value is true, it means that pinctrl device is ready & the
  289. * certain GPIO pin doesn't have back-end pinctrl device. If the return value
  290. * is false, it means that pinctrl device may not be ready.
  291. */
  292. #ifdef CONFIG_GPIOLIB
  293. static bool pinctrl_ready_for_gpio_range(unsigned gpio)
  294. {
  295. struct pinctrl_dev *pctldev;
  296. struct pinctrl_gpio_range *range = NULL;
  297. struct gpio_chip *chip = gpio_to_chip(gpio);
  298. if (WARN(!chip, "no gpio_chip for gpio%i?", gpio))
  299. return false;
  300. mutex_lock(&pinctrldev_list_mutex);
  301. /* Loop over the pin controllers */
  302. list_for_each_entry(pctldev, &pinctrldev_list, node) {
  303. /* Loop over the ranges */
  304. mutex_lock(&pctldev->mutex);
  305. list_for_each_entry(range, &pctldev->gpio_ranges, node) {
  306. /* Check if any gpio range overlapped with gpio chip */
  307. if (range->base + range->npins - 1 < chip->base ||
  308. range->base > chip->base + chip->ngpio - 1)
  309. continue;
  310. mutex_unlock(&pctldev->mutex);
  311. mutex_unlock(&pinctrldev_list_mutex);
  312. return true;
  313. }
  314. mutex_unlock(&pctldev->mutex);
  315. }
  316. mutex_unlock(&pinctrldev_list_mutex);
  317. return false;
  318. }
  319. #else
  320. static bool pinctrl_ready_for_gpio_range(unsigned gpio) { return true; }
  321. #endif
  322. /**
  323. * pinctrl_get_device_gpio_range() - find device for GPIO range
  324. * @gpio: the pin to locate the pin controller for
  325. * @outdev: the pin control device if found
  326. * @outrange: the GPIO range if found
  327. *
  328. * Find the pin controller handling a certain GPIO pin from the pinspace of
  329. * the GPIO subsystem, return the device and the matching GPIO range. Returns
  330. * -EPROBE_DEFER if the GPIO range could not be found in any device since it
  331. * may still have not been registered.
  332. */
  333. static int pinctrl_get_device_gpio_range(unsigned gpio,
  334. struct pinctrl_dev **outdev,
  335. struct pinctrl_gpio_range **outrange)
  336. {
  337. struct pinctrl_dev *pctldev = NULL;
  338. mutex_lock(&pinctrldev_list_mutex);
  339. /* Loop over the pin controllers */
  340. list_for_each_entry(pctldev, &pinctrldev_list, node) {
  341. struct pinctrl_gpio_range *range;
  342. range = pinctrl_match_gpio_range(pctldev, gpio);
  343. if (range != NULL) {
  344. *outdev = pctldev;
  345. *outrange = range;
  346. mutex_unlock(&pinctrldev_list_mutex);
  347. return 0;
  348. }
  349. }
  350. mutex_unlock(&pinctrldev_list_mutex);
  351. return -EPROBE_DEFER;
  352. }
  353. /**
  354. * pinctrl_add_gpio_range() - register a GPIO range for a controller
  355. * @pctldev: pin controller device to add the range to
  356. * @range: the GPIO range to add
  357. *
  358. * This adds a range of GPIOs to be handled by a certain pin controller. Call
  359. * this to register handled ranges after registering your pin controller.
  360. */
  361. void pinctrl_add_gpio_range(struct pinctrl_dev *pctldev,
  362. struct pinctrl_gpio_range *range)
  363. {
  364. mutex_lock(&pctldev->mutex);
  365. list_add_tail(&range->node, &pctldev->gpio_ranges);
  366. mutex_unlock(&pctldev->mutex);
  367. }
  368. EXPORT_SYMBOL_GPL(pinctrl_add_gpio_range);
  369. void pinctrl_add_gpio_ranges(struct pinctrl_dev *pctldev,
  370. struct pinctrl_gpio_range *ranges,
  371. unsigned nranges)
  372. {
  373. int i;
  374. for (i = 0; i < nranges; i++)
  375. pinctrl_add_gpio_range(pctldev, &ranges[i]);
  376. }
  377. EXPORT_SYMBOL_GPL(pinctrl_add_gpio_ranges);
  378. struct pinctrl_dev *pinctrl_find_and_add_gpio_range(const char *devname,
  379. struct pinctrl_gpio_range *range)
  380. {
  381. struct pinctrl_dev *pctldev;
  382. pctldev = get_pinctrl_dev_from_devname(devname);
  383. /*
  384. * If we can't find this device, let's assume that is because
  385. * it has not probed yet, so the driver trying to register this
  386. * range need to defer probing.
  387. */
  388. if (!pctldev) {
  389. return ERR_PTR(-EPROBE_DEFER);
  390. }
  391. pinctrl_add_gpio_range(pctldev, range);
  392. return pctldev;
  393. }
  394. EXPORT_SYMBOL_GPL(pinctrl_find_and_add_gpio_range);
  395. int pinctrl_get_group_pins(struct pinctrl_dev *pctldev, const char *pin_group,
  396. const unsigned **pins, unsigned *num_pins)
  397. {
  398. const struct pinctrl_ops *pctlops = pctldev->desc->pctlops;
  399. int gs;
  400. if (!pctlops->get_group_pins)
  401. return -EINVAL;
  402. gs = pinctrl_get_group_selector(pctldev, pin_group);
  403. if (gs < 0)
  404. return gs;
  405. return pctlops->get_group_pins(pctldev, gs, pins, num_pins);
  406. }
  407. EXPORT_SYMBOL_GPL(pinctrl_get_group_pins);
  408. struct pinctrl_gpio_range *
  409. pinctrl_find_gpio_range_from_pin_nolock(struct pinctrl_dev *pctldev,
  410. unsigned int pin)
  411. {
  412. struct pinctrl_gpio_range *range;
  413. /* Loop over the ranges */
  414. list_for_each_entry(range, &pctldev->gpio_ranges, node) {
  415. /* Check if we're in the valid range */
  416. if (range->pins) {
  417. int a;
  418. for (a = 0; a < range->npins; a++) {
  419. if (range->pins[a] == pin)
  420. return range;
  421. }
  422. } else if (pin >= range->pin_base &&
  423. pin < range->pin_base + range->npins)
  424. return range;
  425. }
  426. return NULL;
  427. }
  428. EXPORT_SYMBOL_GPL(pinctrl_find_gpio_range_from_pin_nolock);
  429. /**
  430. * pinctrl_find_gpio_range_from_pin() - locate the GPIO range for a pin
  431. * @pctldev: the pin controller device to look in
  432. * @pin: a controller-local number to find the range for
  433. */
  434. struct pinctrl_gpio_range *
  435. pinctrl_find_gpio_range_from_pin(struct pinctrl_dev *pctldev,
  436. unsigned int pin)
  437. {
  438. struct pinctrl_gpio_range *range;
  439. mutex_lock(&pctldev->mutex);
  440. range = pinctrl_find_gpio_range_from_pin_nolock(pctldev, pin);
  441. mutex_unlock(&pctldev->mutex);
  442. return range;
  443. }
  444. EXPORT_SYMBOL_GPL(pinctrl_find_gpio_range_from_pin);
  445. /**
  446. * pinctrl_remove_gpio_range() - remove a range of GPIOs fro a pin controller
  447. * @pctldev: pin controller device to remove the range from
  448. * @range: the GPIO range to remove
  449. */
  450. void pinctrl_remove_gpio_range(struct pinctrl_dev *pctldev,
  451. struct pinctrl_gpio_range *range)
  452. {
  453. mutex_lock(&pctldev->mutex);
  454. list_del(&range->node);
  455. mutex_unlock(&pctldev->mutex);
  456. }
  457. EXPORT_SYMBOL_GPL(pinctrl_remove_gpio_range);
  458. /**
  459. * pinctrl_get_group_selector() - returns the group selector for a group
  460. * @pctldev: the pin controller handling the group
  461. * @pin_group: the pin group to look up
  462. */
  463. int pinctrl_get_group_selector(struct pinctrl_dev *pctldev,
  464. const char *pin_group)
  465. {
  466. const struct pinctrl_ops *pctlops = pctldev->desc->pctlops;
  467. unsigned ngroups = pctlops->get_groups_count(pctldev);
  468. unsigned group_selector = 0;
  469. while (group_selector < ngroups) {
  470. const char *gname = pctlops->get_group_name(pctldev,
  471. group_selector);
  472. if (!strcmp(gname, pin_group)) {
  473. dev_dbg(pctldev->dev,
  474. "found group selector %u for %s\n",
  475. group_selector,
  476. pin_group);
  477. return group_selector;
  478. }
  479. group_selector++;
  480. }
  481. dev_err(pctldev->dev, "does not have pin group %s\n",
  482. pin_group);
  483. return -EINVAL;
  484. }
  485. /**
  486. * pinctrl_request_gpio() - request a single pin to be used as GPIO
  487. * @gpio: the GPIO pin number from the GPIO subsystem number space
  488. *
  489. * This function should *ONLY* be used from gpiolib-based GPIO drivers,
  490. * as part of their gpio_request() semantics, platforms and individual drivers
  491. * shall *NOT* request GPIO pins to be muxed in.
  492. */
  493. int pinctrl_request_gpio(unsigned gpio)
  494. {
  495. struct pinctrl_dev *pctldev;
  496. struct pinctrl_gpio_range *range;
  497. int ret;
  498. int pin;
  499. ret = pinctrl_get_device_gpio_range(gpio, &pctldev, &range);
  500. if (ret) {
  501. if (pinctrl_ready_for_gpio_range(gpio))
  502. ret = 0;
  503. return ret;
  504. }
  505. mutex_lock(&pctldev->mutex);
  506. /* Convert to the pin controllers number space */
  507. pin = gpio_to_pin(range, gpio);
  508. ret = pinmux_request_gpio(pctldev, range, pin, gpio);
  509. mutex_unlock(&pctldev->mutex);
  510. return ret;
  511. }
  512. EXPORT_SYMBOL_GPL(pinctrl_request_gpio);
  513. /**
  514. * pinctrl_free_gpio() - free control on a single pin, currently used as GPIO
  515. * @gpio: the GPIO pin number from the GPIO subsystem number space
  516. *
  517. * This function should *ONLY* be used from gpiolib-based GPIO drivers,
  518. * as part of their gpio_free() semantics, platforms and individual drivers
  519. * shall *NOT* request GPIO pins to be muxed out.
  520. */
  521. void pinctrl_free_gpio(unsigned gpio)
  522. {
  523. struct pinctrl_dev *pctldev;
  524. struct pinctrl_gpio_range *range;
  525. int ret;
  526. int pin;
  527. ret = pinctrl_get_device_gpio_range(gpio, &pctldev, &range);
  528. if (ret) {
  529. return;
  530. }
  531. mutex_lock(&pctldev->mutex);
  532. /* Convert to the pin controllers number space */
  533. pin = gpio_to_pin(range, gpio);
  534. pinmux_free_gpio(pctldev, pin, range);
  535. mutex_unlock(&pctldev->mutex);
  536. }
  537. EXPORT_SYMBOL_GPL(pinctrl_free_gpio);
  538. static int pinctrl_gpio_direction(unsigned gpio, bool input)
  539. {
  540. struct pinctrl_dev *pctldev;
  541. struct pinctrl_gpio_range *range;
  542. int ret;
  543. int pin;
  544. ret = pinctrl_get_device_gpio_range(gpio, &pctldev, &range);
  545. if (ret) {
  546. return ret;
  547. }
  548. mutex_lock(&pctldev->mutex);
  549. /* Convert to the pin controllers number space */
  550. pin = gpio_to_pin(range, gpio);
  551. ret = pinmux_gpio_direction(pctldev, range, pin, input);
  552. mutex_unlock(&pctldev->mutex);
  553. return ret;
  554. }
  555. /**
  556. * pinctrl_gpio_direction_input() - request a GPIO pin to go into input mode
  557. * @gpio: the GPIO pin number from the GPIO subsystem number space
  558. *
  559. * This function should *ONLY* be used from gpiolib-based GPIO drivers,
  560. * as part of their gpio_direction_input() semantics, platforms and individual
  561. * drivers shall *NOT* touch pin control GPIO calls.
  562. */
  563. int pinctrl_gpio_direction_input(unsigned gpio)
  564. {
  565. return pinctrl_gpio_direction(gpio, true);
  566. }
  567. EXPORT_SYMBOL_GPL(pinctrl_gpio_direction_input);
  568. /**
  569. * pinctrl_gpio_direction_output() - request a GPIO pin to go into output mode
  570. * @gpio: the GPIO pin number from the GPIO subsystem number space
  571. *
  572. * This function should *ONLY* be used from gpiolib-based GPIO drivers,
  573. * as part of their gpio_direction_output() semantics, platforms and individual
  574. * drivers shall *NOT* touch pin control GPIO calls.
  575. */
  576. int pinctrl_gpio_direction_output(unsigned gpio)
  577. {
  578. return pinctrl_gpio_direction(gpio, false);
  579. }
  580. EXPORT_SYMBOL_GPL(pinctrl_gpio_direction_output);
  581. static struct pinctrl_state *find_state(struct pinctrl *p,
  582. const char *name)
  583. {
  584. struct pinctrl_state *state;
  585. list_for_each_entry(state, &p->states, node)
  586. if (!strcmp(state->name, name))
  587. return state;
  588. return NULL;
  589. }
  590. static struct pinctrl_state *create_state(struct pinctrl *p,
  591. const char *name)
  592. {
  593. struct pinctrl_state *state;
  594. state = kzalloc(sizeof(*state), GFP_KERNEL);
  595. if (state == NULL) {
  596. dev_err(p->dev,
  597. "failed to alloc struct pinctrl_state\n");
  598. return ERR_PTR(-ENOMEM);
  599. }
  600. state->name = name;
  601. INIT_LIST_HEAD(&state->settings);
  602. list_add_tail(&state->node, &p->states);
  603. return state;
  604. }
  605. static int add_setting(struct pinctrl *p, struct pinctrl_map const *map)
  606. {
  607. struct pinctrl_state *state;
  608. struct pinctrl_setting *setting;
  609. int ret;
  610. state = find_state(p, map->name);
  611. if (!state)
  612. state = create_state(p, map->name);
  613. if (IS_ERR(state))
  614. return PTR_ERR(state);
  615. if (map->type == PIN_MAP_TYPE_DUMMY_STATE)
  616. return 0;
  617. setting = kzalloc(sizeof(*setting), GFP_KERNEL);
  618. if (setting == NULL) {
  619. dev_err(p->dev,
  620. "failed to alloc struct pinctrl_setting\n");
  621. return -ENOMEM;
  622. }
  623. setting->type = map->type;
  624. setting->pctldev = get_pinctrl_dev_from_devname(map->ctrl_dev_name);
  625. if (setting->pctldev == NULL) {
  626. kfree(setting);
  627. /* Do not defer probing of hogs (circular loop) */
  628. if (!strcmp(map->ctrl_dev_name, map->dev_name))
  629. return -ENODEV;
  630. /*
  631. * OK let us guess that the driver is not there yet, and
  632. * let's defer obtaining this pinctrl handle to later...
  633. */
  634. dev_info(p->dev, "unknown pinctrl device %s in map entry, deferring probe",
  635. map->ctrl_dev_name);
  636. return -EPROBE_DEFER;
  637. }
  638. setting->dev_name = map->dev_name;
  639. switch (map->type) {
  640. case PIN_MAP_TYPE_MUX_GROUP:
  641. ret = pinmux_map_to_setting(map, setting);
  642. break;
  643. case PIN_MAP_TYPE_CONFIGS_PIN:
  644. case PIN_MAP_TYPE_CONFIGS_GROUP:
  645. ret = pinconf_map_to_setting(map, setting);
  646. break;
  647. default:
  648. ret = -EINVAL;
  649. break;
  650. }
  651. if (ret < 0) {
  652. kfree(setting);
  653. return ret;
  654. }
  655. list_add_tail(&setting->node, &state->settings);
  656. return 0;
  657. }
  658. static struct pinctrl *find_pinctrl(struct device *dev)
  659. {
  660. struct pinctrl *p;
  661. mutex_lock(&pinctrl_list_mutex);
  662. list_for_each_entry(p, &pinctrl_list, node)
  663. if (p->dev == dev) {
  664. mutex_unlock(&pinctrl_list_mutex);
  665. return p;
  666. }
  667. mutex_unlock(&pinctrl_list_mutex);
  668. return NULL;
  669. }
  670. static void pinctrl_free(struct pinctrl *p, bool inlist);
  671. static struct pinctrl *create_pinctrl(struct device *dev)
  672. {
  673. struct pinctrl *p;
  674. const char *devname;
  675. struct pinctrl_maps *maps_node;
  676. int i;
  677. struct pinctrl_map const *map;
  678. int ret;
  679. /*
  680. * create the state cookie holder struct pinctrl for each
  681. * mapping, this is what consumers will get when requesting
  682. * a pin control handle with pinctrl_get()
  683. */
  684. p = kzalloc(sizeof(*p), GFP_KERNEL);
  685. if (p == NULL) {
  686. dev_err(dev, "failed to alloc struct pinctrl\n");
  687. return ERR_PTR(-ENOMEM);
  688. }
  689. p->dev = dev;
  690. INIT_LIST_HEAD(&p->states);
  691. INIT_LIST_HEAD(&p->dt_maps);
  692. ret = pinctrl_dt_to_map(p);
  693. if (ret < 0) {
  694. kfree(p);
  695. return ERR_PTR(ret);
  696. }
  697. devname = dev_name(dev);
  698. mutex_lock(&pinctrl_maps_mutex);
  699. /* Iterate over the pin control maps to locate the right ones */
  700. for_each_maps(maps_node, i, map) {
  701. /* Map must be for this device */
  702. if (strcmp(map->dev_name, devname))
  703. continue;
  704. ret = add_setting(p, map);
  705. /*
  706. * At this point the adding of a setting may:
  707. *
  708. * - Defer, if the pinctrl device is not yet available
  709. * - Fail, if the pinctrl device is not yet available,
  710. * AND the setting is a hog. We cannot defer that, since
  711. * the hog will kick in immediately after the device
  712. * is registered.
  713. *
  714. * If the error returned was not -EPROBE_DEFER then we
  715. * accumulate the errors to see if we end up with
  716. * an -EPROBE_DEFER later, as that is the worst case.
  717. */
  718. if (ret == -EPROBE_DEFER) {
  719. pinctrl_free(p, false);
  720. mutex_unlock(&pinctrl_maps_mutex);
  721. return ERR_PTR(ret);
  722. }
  723. }
  724. mutex_unlock(&pinctrl_maps_mutex);
  725. if (ret < 0) {
  726. /* If some other error than deferral occured, return here */
  727. pinctrl_free(p, false);
  728. return ERR_PTR(ret);
  729. }
  730. kref_init(&p->users);
  731. /* Add the pinctrl handle to the global list */
  732. mutex_lock(&pinctrl_list_mutex);
  733. list_add_tail(&p->node, &pinctrl_list);
  734. mutex_unlock(&pinctrl_list_mutex);
  735. return p;
  736. }
  737. /**
  738. * pinctrl_get() - retrieves the pinctrl handle for a device
  739. * @dev: the device to obtain the handle for
  740. */
  741. struct pinctrl *pinctrl_get(struct device *dev)
  742. {
  743. struct pinctrl *p;
  744. if (WARN_ON(!dev))
  745. return ERR_PTR(-EINVAL);
  746. /*
  747. * See if somebody else (such as the device core) has already
  748. * obtained a handle to the pinctrl for this device. In that case,
  749. * return another pointer to it.
  750. */
  751. p = find_pinctrl(dev);
  752. if (p != NULL) {
  753. dev_dbg(dev, "obtain a copy of previously claimed pinctrl\n");
  754. kref_get(&p->users);
  755. return p;
  756. }
  757. return create_pinctrl(dev);
  758. }
  759. EXPORT_SYMBOL_GPL(pinctrl_get);
  760. static void pinctrl_free_setting(bool disable_setting,
  761. struct pinctrl_setting *setting)
  762. {
  763. switch (setting->type) {
  764. case PIN_MAP_TYPE_MUX_GROUP:
  765. if (disable_setting)
  766. pinmux_disable_setting(setting);
  767. pinmux_free_setting(setting);
  768. break;
  769. case PIN_MAP_TYPE_CONFIGS_PIN:
  770. case PIN_MAP_TYPE_CONFIGS_GROUP:
  771. pinconf_free_setting(setting);
  772. break;
  773. default:
  774. break;
  775. }
  776. }
  777. static void pinctrl_free(struct pinctrl *p, bool inlist)
  778. {
  779. struct pinctrl_state *state, *n1;
  780. struct pinctrl_setting *setting, *n2;
  781. mutex_lock(&pinctrl_list_mutex);
  782. list_for_each_entry_safe(state, n1, &p->states, node) {
  783. list_for_each_entry_safe(setting, n2, &state->settings, node) {
  784. pinctrl_free_setting(state == p->state, setting);
  785. list_del(&setting->node);
  786. kfree(setting);
  787. }
  788. list_del(&state->node);
  789. kfree(state);
  790. }
  791. pinctrl_dt_free_maps(p);
  792. if (inlist)
  793. list_del(&p->node);
  794. kfree(p);
  795. mutex_unlock(&pinctrl_list_mutex);
  796. }
  797. /**
  798. * pinctrl_release() - release the pinctrl handle
  799. * @kref: the kref in the pinctrl being released
  800. */
  801. static void pinctrl_release(struct kref *kref)
  802. {
  803. struct pinctrl *p = container_of(kref, struct pinctrl, users);
  804. pinctrl_free(p, true);
  805. }
  806. /**
  807. * pinctrl_put() - decrease use count on a previously claimed pinctrl handle
  808. * @p: the pinctrl handle to release
  809. */
  810. void pinctrl_put(struct pinctrl *p)
  811. {
  812. kref_put(&p->users, pinctrl_release);
  813. }
  814. EXPORT_SYMBOL_GPL(pinctrl_put);
  815. /**
  816. * pinctrl_lookup_state() - retrieves a state handle from a pinctrl handle
  817. * @p: the pinctrl handle to retrieve the state from
  818. * @name: the state name to retrieve
  819. */
  820. struct pinctrl_state *pinctrl_lookup_state(struct pinctrl *p,
  821. const char *name)
  822. {
  823. struct pinctrl_state *state;
  824. state = find_state(p, name);
  825. if (!state) {
  826. if (pinctrl_dummy_state) {
  827. /* create dummy state */
  828. dev_dbg(p->dev, "using pinctrl dummy state (%s)\n",
  829. name);
  830. state = create_state(p, name);
  831. } else
  832. state = ERR_PTR(-ENODEV);
  833. }
  834. return state;
  835. }
  836. EXPORT_SYMBOL_GPL(pinctrl_lookup_state);
  837. /**
  838. * pinctrl_commit_state() - select/activate/program a pinctrl state to HW
  839. * @p: the pinctrl handle for the device that requests configuration
  840. * @state: the state handle to select/activate/program
  841. */
  842. static int pinctrl_commit_state(struct pinctrl *p, struct pinctrl_state *state)
  843. {
  844. struct pinctrl_setting *setting, *setting2;
  845. struct pinctrl_state *old_state = p->state;
  846. int ret;
  847. if (p->state) {
  848. /*
  849. * For each pinmux setting in the old state, forget SW's record
  850. * of mux owner for that pingroup. Any pingroups which are
  851. * still owned by the new state will be re-acquired by the call
  852. * to pinmux_enable_setting() in the loop below.
  853. */
  854. list_for_each_entry(setting, &p->state->settings, node) {
  855. if (setting->type != PIN_MAP_TYPE_MUX_GROUP)
  856. continue;
  857. pinmux_disable_setting(setting);
  858. }
  859. }
  860. p->state = NULL;
  861. /* Apply all the settings for the new state */
  862. list_for_each_entry(setting, &state->settings, node) {
  863. switch (setting->type) {
  864. case PIN_MAP_TYPE_MUX_GROUP:
  865. ret = pinmux_enable_setting(setting);
  866. break;
  867. case PIN_MAP_TYPE_CONFIGS_PIN:
  868. case PIN_MAP_TYPE_CONFIGS_GROUP:
  869. ret = pinconf_apply_setting(setting);
  870. break;
  871. default:
  872. ret = -EINVAL;
  873. break;
  874. }
  875. if (ret < 0) {
  876. goto unapply_new_state;
  877. }
  878. }
  879. p->state = state;
  880. return 0;
  881. unapply_new_state:
  882. dev_err(p->dev, "Error applying setting, reverse things back\n");
  883. list_for_each_entry(setting2, &state->settings, node) {
  884. if (&setting2->node == &setting->node)
  885. break;
  886. /*
  887. * All we can do here is pinmux_disable_setting.
  888. * That means that some pins are muxed differently now
  889. * than they were before applying the setting (We can't
  890. * "unmux a pin"!), but it's not a big deal since the pins
  891. * are free to be muxed by another apply_setting.
  892. */
  893. if (setting2->type == PIN_MAP_TYPE_MUX_GROUP)
  894. pinmux_disable_setting(setting2);
  895. }
  896. /* There's no infinite recursive loop here because p->state is NULL */
  897. if (old_state)
  898. pinctrl_select_state(p, old_state);
  899. return ret;
  900. }
  901. /**
  902. * pinctrl_select_state() - select/activate/program a pinctrl state to HW
  903. * @p: the pinctrl handle for the device that requests configuration
  904. * @state: the state handle to select/activate/program
  905. */
  906. int pinctrl_select_state(struct pinctrl *p, struct pinctrl_state *state)
  907. {
  908. if (p->state == state)
  909. return 0;
  910. return pinctrl_commit_state(p, state);
  911. }
  912. EXPORT_SYMBOL_GPL(pinctrl_select_state);
  913. static void devm_pinctrl_release(struct device *dev, void *res)
  914. {
  915. pinctrl_put(*(struct pinctrl **)res);
  916. }
  917. /**
  918. * struct devm_pinctrl_get() - Resource managed pinctrl_get()
  919. * @dev: the device to obtain the handle for
  920. *
  921. * If there is a need to explicitly destroy the returned struct pinctrl,
  922. * devm_pinctrl_put() should be used, rather than plain pinctrl_put().
  923. */
  924. struct pinctrl *devm_pinctrl_get(struct device *dev)
  925. {
  926. struct pinctrl **ptr, *p;
  927. ptr = devres_alloc(devm_pinctrl_release, sizeof(*ptr), GFP_KERNEL);
  928. if (!ptr)
  929. return ERR_PTR(-ENOMEM);
  930. p = pinctrl_get(dev);
  931. if (!IS_ERR(p)) {
  932. *ptr = p;
  933. devres_add(dev, ptr);
  934. } else {
  935. devres_free(ptr);
  936. }
  937. return p;
  938. }
  939. EXPORT_SYMBOL_GPL(devm_pinctrl_get);
  940. static int devm_pinctrl_match(struct device *dev, void *res, void *data)
  941. {
  942. struct pinctrl **p = res;
  943. return *p == data;
  944. }
  945. /**
  946. * devm_pinctrl_put() - Resource managed pinctrl_put()
  947. * @p: the pinctrl handle to release
  948. *
  949. * Deallocate a struct pinctrl obtained via devm_pinctrl_get(). Normally
  950. * this function will not need to be called and the resource management
  951. * code will ensure that the resource is freed.
  952. */
  953. void devm_pinctrl_put(struct pinctrl *p)
  954. {
  955. WARN_ON(devres_release(p->dev, devm_pinctrl_release,
  956. devm_pinctrl_match, p));
  957. }
  958. EXPORT_SYMBOL_GPL(devm_pinctrl_put);
  959. int pinctrl_register_map(struct pinctrl_map const *maps, unsigned num_maps,
  960. bool dup)
  961. {
  962. int i, ret;
  963. struct pinctrl_maps *maps_node;
  964. pr_debug("add %u pinctrl maps\n", num_maps);
  965. /* First sanity check the new mapping */
  966. for (i = 0; i < num_maps; i++) {
  967. if (!maps[i].dev_name) {
  968. pr_err("failed to register map %s (%d): no device given\n",
  969. maps[i].name, i);
  970. return -EINVAL;
  971. }
  972. if (!maps[i].name) {
  973. pr_err("failed to register map %d: no map name given\n",
  974. i);
  975. return -EINVAL;
  976. }
  977. if (maps[i].type != PIN_MAP_TYPE_DUMMY_STATE &&
  978. !maps[i].ctrl_dev_name) {
  979. pr_err("failed to register map %s (%d): no pin control device given\n",
  980. maps[i].name, i);
  981. return -EINVAL;
  982. }
  983. switch (maps[i].type) {
  984. case PIN_MAP_TYPE_DUMMY_STATE:
  985. break;
  986. case PIN_MAP_TYPE_MUX_GROUP:
  987. ret = pinmux_validate_map(&maps[i], i);
  988. if (ret < 0)
  989. return ret;
  990. break;
  991. case PIN_MAP_TYPE_CONFIGS_PIN:
  992. case PIN_MAP_TYPE_CONFIGS_GROUP:
  993. ret = pinconf_validate_map(&maps[i], i);
  994. if (ret < 0)
  995. return ret;
  996. break;
  997. default:
  998. pr_err("failed to register map %s (%d): invalid type given\n",
  999. maps[i].name, i);
  1000. return -EINVAL;
  1001. }
  1002. }
  1003. maps_node = kzalloc(sizeof(*maps_node), GFP_KERNEL);
  1004. if (!maps_node) {
  1005. pr_err("failed to alloc struct pinctrl_maps\n");
  1006. return -ENOMEM;
  1007. }
  1008. maps_node->num_maps = num_maps;
  1009. if (dup) {
  1010. maps_node->maps = kmemdup(maps, sizeof(*maps) * num_maps,
  1011. GFP_KERNEL);
  1012. if (!maps_node->maps) {
  1013. pr_err("failed to duplicate mapping table\n");
  1014. kfree(maps_node);
  1015. return -ENOMEM;
  1016. }
  1017. } else {
  1018. maps_node->maps = maps;
  1019. }
  1020. mutex_lock(&pinctrl_maps_mutex);
  1021. list_add_tail(&maps_node->node, &pinctrl_maps);
  1022. mutex_unlock(&pinctrl_maps_mutex);
  1023. return 0;
  1024. }
  1025. /**
  1026. * pinctrl_register_mappings() - register a set of pin controller mappings
  1027. * @maps: the pincontrol mappings table to register. This should probably be
  1028. * marked with __initdata so it can be discarded after boot. This
  1029. * function will perform a shallow copy for the mapping entries.
  1030. * @num_maps: the number of maps in the mapping table
  1031. */
  1032. int pinctrl_register_mappings(struct pinctrl_map const *maps,
  1033. unsigned num_maps)
  1034. {
  1035. return pinctrl_register_map(maps, num_maps, true);
  1036. }
  1037. void pinctrl_unregister_map(struct pinctrl_map const *map)
  1038. {
  1039. struct pinctrl_maps *maps_node;
  1040. mutex_lock(&pinctrl_maps_mutex);
  1041. list_for_each_entry(maps_node, &pinctrl_maps, node) {
  1042. if (maps_node->maps == map) {
  1043. list_del(&maps_node->node);
  1044. kfree(maps_node);
  1045. mutex_unlock(&pinctrl_maps_mutex);
  1046. return;
  1047. }
  1048. }
  1049. mutex_unlock(&pinctrl_maps_mutex);
  1050. }
  1051. /**
  1052. * pinctrl_force_sleep() - turn a given controller device into sleep state
  1053. * @pctldev: pin controller device
  1054. */
  1055. int pinctrl_force_sleep(struct pinctrl_dev *pctldev)
  1056. {
  1057. if (!IS_ERR(pctldev->p) && !IS_ERR(pctldev->hog_sleep))
  1058. return pinctrl_commit_state(pctldev->p, pctldev->hog_sleep);
  1059. return 0;
  1060. }
  1061. EXPORT_SYMBOL_GPL(pinctrl_force_sleep);
  1062. /**
  1063. * pinctrl_force_default() - turn a given controller device into default state
  1064. * @pctldev: pin controller device
  1065. */
  1066. int pinctrl_force_default(struct pinctrl_dev *pctldev)
  1067. {
  1068. if (!IS_ERR(pctldev->p) && !IS_ERR(pctldev->hog_default))
  1069. return pinctrl_commit_state(pctldev->p, pctldev->hog_default);
  1070. return 0;
  1071. }
  1072. EXPORT_SYMBOL_GPL(pinctrl_force_default);
  1073. /**
  1074. * pinctrl_init_done() - tell pinctrl probe is done
  1075. *
  1076. * We'll use this time to switch the pins from "init" to "default" unless the
  1077. * driver selected some other state.
  1078. *
  1079. * @dev: device to that's done probing
  1080. */
  1081. int pinctrl_init_done(struct device *dev)
  1082. {
  1083. struct dev_pin_info *pins = dev->pins;
  1084. int ret;
  1085. if (!pins)
  1086. return 0;
  1087. if (IS_ERR(pins->init_state))
  1088. return 0; /* No such state */
  1089. if (pins->p->state != pins->init_state)
  1090. return 0; /* Not at init anyway */
  1091. if (IS_ERR(pins->default_state))
  1092. return 0; /* No default state */
  1093. ret = pinctrl_select_state(pins->p, pins->default_state);
  1094. if (ret)
  1095. dev_err(dev, "failed to activate default pinctrl state\n");
  1096. return ret;
  1097. }
  1098. #ifdef CONFIG_PM
  1099. /**
  1100. * pinctrl_pm_select_state() - select pinctrl state for PM
  1101. * @dev: device to select default state for
  1102. * @state: state to set
  1103. */
  1104. static int pinctrl_pm_select_state(struct device *dev,
  1105. struct pinctrl_state *state)
  1106. {
  1107. struct dev_pin_info *pins = dev->pins;
  1108. int ret;
  1109. if (IS_ERR(state))
  1110. return 0; /* No such state */
  1111. ret = pinctrl_select_state(pins->p, state);
  1112. if (ret)
  1113. dev_err(dev, "failed to activate pinctrl state %s\n",
  1114. state->name);
  1115. return ret;
  1116. }
  1117. /**
  1118. * pinctrl_pm_select_default_state() - select default pinctrl state for PM
  1119. * @dev: device to select default state for
  1120. */
  1121. int pinctrl_pm_select_default_state(struct device *dev)
  1122. {
  1123. if (!dev->pins)
  1124. return 0;
  1125. return pinctrl_pm_select_state(dev, dev->pins->default_state);
  1126. }
  1127. EXPORT_SYMBOL_GPL(pinctrl_pm_select_default_state);
  1128. /**
  1129. * pinctrl_pm_select_sleep_state() - select sleep pinctrl state for PM
  1130. * @dev: device to select sleep state for
  1131. */
  1132. int pinctrl_pm_select_sleep_state(struct device *dev)
  1133. {
  1134. if (!dev->pins)
  1135. return 0;
  1136. return pinctrl_pm_select_state(dev, dev->pins->sleep_state);
  1137. }
  1138. EXPORT_SYMBOL_GPL(pinctrl_pm_select_sleep_state);
  1139. /**
  1140. * pinctrl_pm_select_idle_state() - select idle pinctrl state for PM
  1141. * @dev: device to select idle state for
  1142. */
  1143. int pinctrl_pm_select_idle_state(struct device *dev)
  1144. {
  1145. if (!dev->pins)
  1146. return 0;
  1147. return pinctrl_pm_select_state(dev, dev->pins->idle_state);
  1148. }
  1149. EXPORT_SYMBOL_GPL(pinctrl_pm_select_idle_state);
  1150. #endif
  1151. #ifdef CONFIG_DEBUG_FS
  1152. static int pinctrl_pins_show(struct seq_file *s, void *what)
  1153. {
  1154. struct pinctrl_dev *pctldev = s->private;
  1155. const struct pinctrl_ops *ops = pctldev->desc->pctlops;
  1156. unsigned i, pin;
  1157. seq_printf(s, "registered pins: %d\n", pctldev->desc->npins);
  1158. mutex_lock(&pctldev->mutex);
  1159. /* The pin number can be retrived from the pin controller descriptor */
  1160. for (i = 0; i < pctldev->desc->npins; i++) {
  1161. struct pin_desc *desc;
  1162. pin = pctldev->desc->pins[i].number;
  1163. desc = pin_desc_get(pctldev, pin);
  1164. /* Pin space may be sparse */
  1165. if (desc == NULL)
  1166. continue;
  1167. seq_printf(s, "pin %d (%s) ", pin, desc->name);
  1168. /* Driver-specific info per pin */
  1169. if (ops->pin_dbg_show)
  1170. ops->pin_dbg_show(pctldev, s, pin);
  1171. seq_puts(s, "\n");
  1172. }
  1173. mutex_unlock(&pctldev->mutex);
  1174. return 0;
  1175. }
  1176. static int pinctrl_groups_show(struct seq_file *s, void *what)
  1177. {
  1178. struct pinctrl_dev *pctldev = s->private;
  1179. const struct pinctrl_ops *ops = pctldev->desc->pctlops;
  1180. unsigned ngroups, selector = 0;
  1181. mutex_lock(&pctldev->mutex);
  1182. ngroups = ops->get_groups_count(pctldev);
  1183. seq_puts(s, "registered pin groups:\n");
  1184. while (selector < ngroups) {
  1185. const unsigned *pins = NULL;
  1186. unsigned num_pins = 0;
  1187. const char *gname = ops->get_group_name(pctldev, selector);
  1188. const char *pname;
  1189. int ret = 0;
  1190. int i;
  1191. if (ops->get_group_pins)
  1192. ret = ops->get_group_pins(pctldev, selector,
  1193. &pins, &num_pins);
  1194. if (ret)
  1195. seq_printf(s, "%s [ERROR GETTING PINS]\n",
  1196. gname);
  1197. else {
  1198. seq_printf(s, "group: %s\n", gname);
  1199. for (i = 0; i < num_pins; i++) {
  1200. pname = pin_get_name(pctldev, pins[i]);
  1201. if (WARN_ON(!pname)) {
  1202. mutex_unlock(&pctldev->mutex);
  1203. return -EINVAL;
  1204. }
  1205. seq_printf(s, "pin %d (%s)\n", pins[i], pname);
  1206. }
  1207. seq_puts(s, "\n");
  1208. }
  1209. selector++;
  1210. }
  1211. mutex_unlock(&pctldev->mutex);
  1212. return 0;
  1213. }
  1214. static int pinctrl_gpioranges_show(struct seq_file *s, void *what)
  1215. {
  1216. struct pinctrl_dev *pctldev = s->private;
  1217. struct pinctrl_gpio_range *range = NULL;
  1218. seq_puts(s, "GPIO ranges handled:\n");
  1219. mutex_lock(&pctldev->mutex);
  1220. /* Loop over the ranges */
  1221. list_for_each_entry(range, &pctldev->gpio_ranges, node) {
  1222. if (range->pins) {
  1223. int a;
  1224. seq_printf(s, "%u: %s GPIOS [%u - %u] PINS {",
  1225. range->id, range->name,
  1226. range->base, (range->base + range->npins - 1));
  1227. for (a = 0; a < range->npins - 1; a++)
  1228. seq_printf(s, "%u, ", range->pins[a]);
  1229. seq_printf(s, "%u}\n", range->pins[a]);
  1230. }
  1231. else
  1232. seq_printf(s, "%u: %s GPIOS [%u - %u] PINS [%u - %u]\n",
  1233. range->id, range->name,
  1234. range->base, (range->base + range->npins - 1),
  1235. range->pin_base,
  1236. (range->pin_base + range->npins - 1));
  1237. }
  1238. mutex_unlock(&pctldev->mutex);
  1239. return 0;
  1240. }
  1241. static int pinctrl_devices_show(struct seq_file *s, void *what)
  1242. {
  1243. struct pinctrl_dev *pctldev;
  1244. seq_puts(s, "name [pinmux] [pinconf]\n");
  1245. mutex_lock(&pinctrldev_list_mutex);
  1246. list_for_each_entry(pctldev, &pinctrldev_list, node) {
  1247. seq_printf(s, "%s ", pctldev->desc->name);
  1248. if (pctldev->desc->pmxops)
  1249. seq_puts(s, "yes ");
  1250. else
  1251. seq_puts(s, "no ");
  1252. if (pctldev->desc->confops)
  1253. seq_puts(s, "yes");
  1254. else
  1255. seq_puts(s, "no");
  1256. seq_puts(s, "\n");
  1257. }
  1258. mutex_unlock(&pinctrldev_list_mutex);
  1259. return 0;
  1260. }
  1261. static inline const char *map_type(enum pinctrl_map_type type)
  1262. {
  1263. static const char * const names[] = {
  1264. "INVALID",
  1265. "DUMMY_STATE",
  1266. "MUX_GROUP",
  1267. "CONFIGS_PIN",
  1268. "CONFIGS_GROUP",
  1269. };
  1270. if (type >= ARRAY_SIZE(names))
  1271. return "UNKNOWN";
  1272. return names[type];
  1273. }
  1274. static int pinctrl_maps_show(struct seq_file *s, void *what)
  1275. {
  1276. struct pinctrl_maps *maps_node;
  1277. int i;
  1278. struct pinctrl_map const *map;
  1279. seq_puts(s, "Pinctrl maps:\n");
  1280. mutex_lock(&pinctrl_maps_mutex);
  1281. for_each_maps(maps_node, i, map) {
  1282. seq_printf(s, "device %s\nstate %s\ntype %s (%d)\n",
  1283. map->dev_name, map->name, map_type(map->type),
  1284. map->type);
  1285. if (map->type != PIN_MAP_TYPE_DUMMY_STATE)
  1286. seq_printf(s, "controlling device %s\n",
  1287. map->ctrl_dev_name);
  1288. switch (map->type) {
  1289. case PIN_MAP_TYPE_MUX_GROUP:
  1290. pinmux_show_map(s, map);
  1291. break;
  1292. case PIN_MAP_TYPE_CONFIGS_PIN:
  1293. case PIN_MAP_TYPE_CONFIGS_GROUP:
  1294. pinconf_show_map(s, map);
  1295. break;
  1296. default:
  1297. break;
  1298. }
  1299. seq_printf(s, "\n");
  1300. }
  1301. mutex_unlock(&pinctrl_maps_mutex);
  1302. return 0;
  1303. }
  1304. static int pinctrl_show(struct seq_file *s, void *what)
  1305. {
  1306. struct pinctrl *p;
  1307. struct pinctrl_state *state;
  1308. struct pinctrl_setting *setting;
  1309. seq_puts(s, "Requested pin control handlers their pinmux maps:\n");
  1310. mutex_lock(&pinctrl_list_mutex);
  1311. list_for_each_entry(p, &pinctrl_list, node) {
  1312. seq_printf(s, "device: %s current state: %s\n",
  1313. dev_name(p->dev),
  1314. p->state ? p->state->name : "none");
  1315. list_for_each_entry(state, &p->states, node) {
  1316. seq_printf(s, " state: %s\n", state->name);
  1317. list_for_each_entry(setting, &state->settings, node) {
  1318. struct pinctrl_dev *pctldev = setting->pctldev;
  1319. seq_printf(s, " type: %s controller %s ",
  1320. map_type(setting->type),
  1321. pinctrl_dev_get_name(pctldev));
  1322. switch (setting->type) {
  1323. case PIN_MAP_TYPE_MUX_GROUP:
  1324. pinmux_show_setting(s, setting);
  1325. break;
  1326. case PIN_MAP_TYPE_CONFIGS_PIN:
  1327. case PIN_MAP_TYPE_CONFIGS_GROUP:
  1328. pinconf_show_setting(s, setting);
  1329. break;
  1330. default:
  1331. break;
  1332. }
  1333. }
  1334. }
  1335. }
  1336. mutex_unlock(&pinctrl_list_mutex);
  1337. return 0;
  1338. }
  1339. static int pinctrl_pins_open(struct inode *inode, struct file *file)
  1340. {
  1341. return single_open(file, pinctrl_pins_show, inode->i_private);
  1342. }
  1343. static int pinctrl_groups_open(struct inode *inode, struct file *file)
  1344. {
  1345. return single_open(file, pinctrl_groups_show, inode->i_private);
  1346. }
  1347. static int pinctrl_gpioranges_open(struct inode *inode, struct file *file)
  1348. {
  1349. return single_open(file, pinctrl_gpioranges_show, inode->i_private);
  1350. }
  1351. static int pinctrl_devices_open(struct inode *inode, struct file *file)
  1352. {
  1353. return single_open(file, pinctrl_devices_show, NULL);
  1354. }
  1355. static int pinctrl_maps_open(struct inode *inode, struct file *file)
  1356. {
  1357. return single_open(file, pinctrl_maps_show, NULL);
  1358. }
  1359. static int pinctrl_open(struct inode *inode, struct file *file)
  1360. {
  1361. return single_open(file, pinctrl_show, NULL);
  1362. }
  1363. static const struct file_operations pinctrl_pins_ops = {
  1364. .open = pinctrl_pins_open,
  1365. .read = seq_read,
  1366. .llseek = seq_lseek,
  1367. .release = single_release,
  1368. };
  1369. static const struct file_operations pinctrl_groups_ops = {
  1370. .open = pinctrl_groups_open,
  1371. .read = seq_read,
  1372. .llseek = seq_lseek,
  1373. .release = single_release,
  1374. };
  1375. static const struct file_operations pinctrl_gpioranges_ops = {
  1376. .open = pinctrl_gpioranges_open,
  1377. .read = seq_read,
  1378. .llseek = seq_lseek,
  1379. .release = single_release,
  1380. };
  1381. static const struct file_operations pinctrl_devices_ops = {
  1382. .open = pinctrl_devices_open,
  1383. .read = seq_read,
  1384. .llseek = seq_lseek,
  1385. .release = single_release,
  1386. };
  1387. static const struct file_operations pinctrl_maps_ops = {
  1388. .open = pinctrl_maps_open,
  1389. .read = seq_read,
  1390. .llseek = seq_lseek,
  1391. .release = single_release,
  1392. };
  1393. static const struct file_operations pinctrl_ops = {
  1394. .open = pinctrl_open,
  1395. .read = seq_read,
  1396. .llseek = seq_lseek,
  1397. .release = single_release,
  1398. };
  1399. static struct dentry *debugfs_root;
  1400. static void pinctrl_init_device_debugfs(struct pinctrl_dev *pctldev)
  1401. {
  1402. struct dentry *device_root;
  1403. device_root = debugfs_create_dir(dev_name(pctldev->dev),
  1404. debugfs_root);
  1405. pctldev->device_root = device_root;
  1406. if (IS_ERR(device_root) || !device_root) {
  1407. pr_warn("failed to create debugfs directory for %s\n",
  1408. dev_name(pctldev->dev));
  1409. return;
  1410. }
  1411. debugfs_create_file("pins", S_IFREG | S_IRUGO,
  1412. device_root, pctldev, &pinctrl_pins_ops);
  1413. debugfs_create_file("pingroups", S_IFREG | S_IRUGO,
  1414. device_root, pctldev, &pinctrl_groups_ops);
  1415. debugfs_create_file("gpio-ranges", S_IFREG | S_IRUGO,
  1416. device_root, pctldev, &pinctrl_gpioranges_ops);
  1417. if (pctldev->desc->pmxops)
  1418. pinmux_init_device_debugfs(device_root, pctldev);
  1419. if (pctldev->desc->confops)
  1420. pinconf_init_device_debugfs(device_root, pctldev);
  1421. }
  1422. static void pinctrl_remove_device_debugfs(struct pinctrl_dev *pctldev)
  1423. {
  1424. debugfs_remove_recursive(pctldev->device_root);
  1425. }
  1426. static void pinctrl_init_debugfs(void)
  1427. {
  1428. debugfs_root = debugfs_create_dir("pinctrl", NULL);
  1429. if (IS_ERR(debugfs_root) || !debugfs_root) {
  1430. pr_warn("failed to create debugfs directory\n");
  1431. debugfs_root = NULL;
  1432. return;
  1433. }
  1434. debugfs_create_file("pinctrl-devices", S_IFREG | S_IRUGO,
  1435. debugfs_root, NULL, &pinctrl_devices_ops);
  1436. debugfs_create_file("pinctrl-maps", S_IFREG | S_IRUGO,
  1437. debugfs_root, NULL, &pinctrl_maps_ops);
  1438. debugfs_create_file("pinctrl-handles", S_IFREG | S_IRUGO,
  1439. debugfs_root, NULL, &pinctrl_ops);
  1440. }
  1441. #else /* CONFIG_DEBUG_FS */
  1442. static void pinctrl_init_device_debugfs(struct pinctrl_dev *pctldev)
  1443. {
  1444. }
  1445. static void pinctrl_init_debugfs(void)
  1446. {
  1447. }
  1448. static void pinctrl_remove_device_debugfs(struct pinctrl_dev *pctldev)
  1449. {
  1450. }
  1451. #endif
  1452. static int pinctrl_check_ops(struct pinctrl_dev *pctldev)
  1453. {
  1454. const struct pinctrl_ops *ops = pctldev->desc->pctlops;
  1455. if (!ops ||
  1456. !ops->get_groups_count ||
  1457. !ops->get_group_name)
  1458. return -EINVAL;
  1459. if (ops->dt_node_to_map && !ops->dt_free_map)
  1460. return -EINVAL;
  1461. return 0;
  1462. }
  1463. /**
  1464. * pinctrl_register() - register a pin controller device
  1465. * @pctldesc: descriptor for this pin controller
  1466. * @dev: parent device for this pin controller
  1467. * @driver_data: private pin controller data for this pin controller
  1468. */
  1469. struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc,
  1470. struct device *dev, void *driver_data)
  1471. {
  1472. struct pinctrl_dev *pctldev;
  1473. int ret;
  1474. if (!pctldesc)
  1475. return ERR_PTR(-EINVAL);
  1476. if (!pctldesc->name)
  1477. return ERR_PTR(-EINVAL);
  1478. pctldev = kzalloc(sizeof(*pctldev), GFP_KERNEL);
  1479. if (pctldev == NULL) {
  1480. dev_err(dev, "failed to alloc struct pinctrl_dev\n");
  1481. return ERR_PTR(-ENOMEM);
  1482. }
  1483. /* Initialize pin control device struct */
  1484. pctldev->owner = pctldesc->owner;
  1485. pctldev->desc = pctldesc;
  1486. pctldev->driver_data = driver_data;
  1487. INIT_RADIX_TREE(&pctldev->pin_desc_tree, GFP_KERNEL);
  1488. INIT_LIST_HEAD(&pctldev->gpio_ranges);
  1489. pctldev->dev = dev;
  1490. mutex_init(&pctldev->mutex);
  1491. /* check core ops for sanity */
  1492. ret = pinctrl_check_ops(pctldev);
  1493. if (ret) {
  1494. dev_err(dev, "pinctrl ops lacks necessary functions\n");
  1495. goto out_err;
  1496. }
  1497. /* If we're implementing pinmuxing, check the ops for sanity */
  1498. if (pctldesc->pmxops) {
  1499. ret = pinmux_check_ops(pctldev);
  1500. if (ret)
  1501. goto out_err;
  1502. }
  1503. /* If we're implementing pinconfig, check the ops for sanity */
  1504. if (pctldesc->confops) {
  1505. ret = pinconf_check_ops(pctldev);
  1506. if (ret)
  1507. goto out_err;
  1508. }
  1509. /* Register all the pins */
  1510. dev_dbg(dev, "try to register %d pins ...\n", pctldesc->npins);
  1511. ret = pinctrl_register_pins(pctldev, pctldesc->pins, pctldesc->npins);
  1512. if (ret) {
  1513. dev_err(dev, "error during pin registration\n");
  1514. pinctrl_free_pindescs(pctldev, pctldesc->pins,
  1515. pctldesc->npins);
  1516. goto out_err;
  1517. }
  1518. mutex_lock(&pinctrldev_list_mutex);
  1519. list_add_tail(&pctldev->node, &pinctrldev_list);
  1520. mutex_unlock(&pinctrldev_list_mutex);
  1521. pctldev->p = pinctrl_get(pctldev->dev);
  1522. if (!IS_ERR(pctldev->p)) {
  1523. pctldev->hog_default =
  1524. pinctrl_lookup_state(pctldev->p, PINCTRL_STATE_DEFAULT);
  1525. if (IS_ERR(pctldev->hog_default)) {
  1526. dev_dbg(dev, "failed to lookup the default state\n");
  1527. } else {
  1528. if (pinctrl_select_state(pctldev->p,
  1529. pctldev->hog_default))
  1530. dev_err(dev,
  1531. "failed to select default state\n");
  1532. }
  1533. pctldev->hog_sleep =
  1534. pinctrl_lookup_state(pctldev->p,
  1535. PINCTRL_STATE_SLEEP);
  1536. if (IS_ERR(pctldev->hog_sleep))
  1537. dev_dbg(dev, "failed to lookup the sleep state\n");
  1538. }
  1539. pinctrl_init_device_debugfs(pctldev);
  1540. return pctldev;
  1541. out_err:
  1542. mutex_destroy(&pctldev->mutex);
  1543. kfree(pctldev);
  1544. return ERR_PTR(ret);
  1545. }
  1546. EXPORT_SYMBOL_GPL(pinctrl_register);
  1547. /**
  1548. * pinctrl_unregister() - unregister pinmux
  1549. * @pctldev: pin controller to unregister
  1550. *
  1551. * Called by pinmux drivers to unregister a pinmux.
  1552. */
  1553. void pinctrl_unregister(struct pinctrl_dev *pctldev)
  1554. {
  1555. struct pinctrl_gpio_range *range, *n;
  1556. if (pctldev == NULL)
  1557. return;
  1558. mutex_lock(&pctldev->mutex);
  1559. pinctrl_remove_device_debugfs(pctldev);
  1560. mutex_unlock(&pctldev->mutex);
  1561. if (!IS_ERR(pctldev->p))
  1562. pinctrl_put(pctldev->p);
  1563. mutex_lock(&pinctrldev_list_mutex);
  1564. mutex_lock(&pctldev->mutex);
  1565. /* TODO: check that no pinmuxes are still active? */
  1566. list_del(&pctldev->node);
  1567. /* Destroy descriptor tree */
  1568. pinctrl_free_pindescs(pctldev, pctldev->desc->pins,
  1569. pctldev->desc->npins);
  1570. /* remove gpio ranges map */
  1571. list_for_each_entry_safe(range, n, &pctldev->gpio_ranges, node)
  1572. list_del(&range->node);
  1573. mutex_unlock(&pctldev->mutex);
  1574. mutex_destroy(&pctldev->mutex);
  1575. kfree(pctldev);
  1576. mutex_unlock(&pinctrldev_list_mutex);
  1577. }
  1578. EXPORT_SYMBOL_GPL(pinctrl_unregister);
  1579. static void devm_pinctrl_dev_release(struct device *dev, void *res)
  1580. {
  1581. struct pinctrl_dev *pctldev = *(struct pinctrl_dev **)res;
  1582. pinctrl_unregister(pctldev);
  1583. }
  1584. static int devm_pinctrl_dev_match(struct device *dev, void *res, void *data)
  1585. {
  1586. struct pctldev **r = res;
  1587. if (WARN_ON(!r || !*r))
  1588. return 0;
  1589. return *r == data;
  1590. }
  1591. /**
  1592. * devm_pinctrl_register() - Resource managed version of pinctrl_register().
  1593. * @dev: parent device for this pin controller
  1594. * @pctldesc: descriptor for this pin controller
  1595. * @driver_data: private pin controller data for this pin controller
  1596. *
  1597. * Returns an error pointer if pincontrol register failed. Otherwise
  1598. * it returns valid pinctrl handle.
  1599. *
  1600. * The pinctrl device will be automatically released when the device is unbound.
  1601. */
  1602. struct pinctrl_dev *devm_pinctrl_register(struct device *dev,
  1603. struct pinctrl_desc *pctldesc,
  1604. void *driver_data)
  1605. {
  1606. struct pinctrl_dev **ptr, *pctldev;
  1607. ptr = devres_alloc(devm_pinctrl_dev_release, sizeof(*ptr), GFP_KERNEL);
  1608. if (!ptr)
  1609. return ERR_PTR(-ENOMEM);
  1610. pctldev = pinctrl_register(pctldesc, dev, driver_data);
  1611. if (IS_ERR(pctldev)) {
  1612. devres_free(ptr);
  1613. return pctldev;
  1614. }
  1615. *ptr = pctldev;
  1616. devres_add(dev, ptr);
  1617. return pctldev;
  1618. }
  1619. EXPORT_SYMBOL_GPL(devm_pinctrl_register);
  1620. /**
  1621. * devm_pinctrl_unregister() - Resource managed version of pinctrl_unregister().
  1622. * @dev: device for which which resource was allocated
  1623. * @pctldev: the pinctrl device to unregister.
  1624. */
  1625. void devm_pinctrl_unregister(struct device *dev, struct pinctrl_dev *pctldev)
  1626. {
  1627. WARN_ON(devres_release(dev, devm_pinctrl_dev_release,
  1628. devm_pinctrl_dev_match, pctldev));
  1629. }
  1630. EXPORT_SYMBOL_GPL(devm_pinctrl_unregister);
  1631. static int __init pinctrl_init(void)
  1632. {
  1633. pr_info("initialized pinctrl subsystem\n");
  1634. pinctrl_init_debugfs();
  1635. return 0;
  1636. }
  1637. /* init early since many drivers really need to initialized pinmux early */
  1638. core_initcall(pinctrl_init);