pinctrl.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. /*
  2. * SuperH Pin Function Controller pinmux support.
  3. *
  4. * Copyright (C) 2012 Paul Mundt
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file "COPYING" in the main directory of this archive
  8. * for more details.
  9. */
  10. #define DRV_NAME "sh-pfc"
  11. #include <linux/device.h>
  12. #include <linux/err.h>
  13. #include <linux/init.h>
  14. #include <linux/module.h>
  15. #include <linux/of.h>
  16. #include <linux/pinctrl/consumer.h>
  17. #include <linux/pinctrl/machine.h>
  18. #include <linux/pinctrl/pinconf.h>
  19. #include <linux/pinctrl/pinconf-generic.h>
  20. #include <linux/pinctrl/pinctrl.h>
  21. #include <linux/pinctrl/pinmux.h>
  22. #include <linux/slab.h>
  23. #include <linux/spinlock.h>
  24. #include "core.h"
  25. #include "../core.h"
  26. #include "../pinconf.h"
  27. struct sh_pfc_pin_config {
  28. u32 type;
  29. };
  30. struct sh_pfc_pinctrl {
  31. struct pinctrl_dev *pctl;
  32. struct pinctrl_desc pctl_desc;
  33. struct sh_pfc *pfc;
  34. struct pinctrl_pin_desc *pins;
  35. struct sh_pfc_pin_config *configs;
  36. };
  37. static int sh_pfc_get_groups_count(struct pinctrl_dev *pctldev)
  38. {
  39. struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
  40. return pmx->pfc->info->nr_groups;
  41. }
  42. static const char *sh_pfc_get_group_name(struct pinctrl_dev *pctldev,
  43. unsigned selector)
  44. {
  45. struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
  46. return pmx->pfc->info->groups[selector].name;
  47. }
  48. static int sh_pfc_get_group_pins(struct pinctrl_dev *pctldev, unsigned selector,
  49. const unsigned **pins, unsigned *num_pins)
  50. {
  51. struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
  52. *pins = pmx->pfc->info->groups[selector].pins;
  53. *num_pins = pmx->pfc->info->groups[selector].nr_pins;
  54. return 0;
  55. }
  56. static void sh_pfc_pin_dbg_show(struct pinctrl_dev *pctldev, struct seq_file *s,
  57. unsigned offset)
  58. {
  59. seq_printf(s, "%s", DRV_NAME);
  60. }
  61. #ifdef CONFIG_OF
  62. static int sh_pfc_map_add_config(struct pinctrl_map *map,
  63. const char *group_or_pin,
  64. enum pinctrl_map_type type,
  65. unsigned long *configs,
  66. unsigned int num_configs)
  67. {
  68. unsigned long *cfgs;
  69. cfgs = kmemdup(configs, num_configs * sizeof(*cfgs),
  70. GFP_KERNEL);
  71. if (cfgs == NULL)
  72. return -ENOMEM;
  73. map->type = type;
  74. map->data.configs.group_or_pin = group_or_pin;
  75. map->data.configs.configs = cfgs;
  76. map->data.configs.num_configs = num_configs;
  77. return 0;
  78. }
  79. static int sh_pfc_dt_subnode_to_map(struct device *dev, struct device_node *np,
  80. struct pinctrl_map **map,
  81. unsigned int *num_maps, unsigned int *index)
  82. {
  83. struct pinctrl_map *maps = *map;
  84. unsigned int nmaps = *num_maps;
  85. unsigned int idx = *index;
  86. unsigned int num_configs;
  87. const char *function = NULL;
  88. unsigned long *configs;
  89. struct property *prop;
  90. unsigned int num_groups;
  91. unsigned int num_pins;
  92. const char *group;
  93. const char *pin;
  94. int ret;
  95. /* Parse the function and configuration properties. At least a function
  96. * or one configuration must be specified.
  97. */
  98. ret = of_property_read_string(np, "renesas,function", &function);
  99. if (ret < 0 && ret != -EINVAL) {
  100. dev_err(dev, "Invalid function in DT\n");
  101. return ret;
  102. }
  103. ret = pinconf_generic_parse_dt_config(np, &configs, &num_configs);
  104. if (ret < 0)
  105. return ret;
  106. if (!function && num_configs == 0) {
  107. dev_err(dev,
  108. "DT node must contain at least a function or config\n");
  109. goto done;
  110. }
  111. /* Count the number of pins and groups and reallocate mappings. */
  112. ret = of_property_count_strings(np, "renesas,pins");
  113. if (ret == -EINVAL) {
  114. num_pins = 0;
  115. } else if (ret < 0) {
  116. dev_err(dev, "Invalid pins list in DT\n");
  117. goto done;
  118. } else {
  119. num_pins = ret;
  120. }
  121. ret = of_property_count_strings(np, "renesas,groups");
  122. if (ret == -EINVAL) {
  123. num_groups = 0;
  124. } else if (ret < 0) {
  125. dev_err(dev, "Invalid pin groups list in DT\n");
  126. goto done;
  127. } else {
  128. num_groups = ret;
  129. }
  130. if (!num_pins && !num_groups) {
  131. dev_err(dev, "No pin or group provided in DT node\n");
  132. ret = -ENODEV;
  133. goto done;
  134. }
  135. if (function)
  136. nmaps += num_groups;
  137. if (configs)
  138. nmaps += num_pins + num_groups;
  139. maps = krealloc(maps, sizeof(*maps) * nmaps, GFP_KERNEL);
  140. if (maps == NULL) {
  141. ret = -ENOMEM;
  142. goto done;
  143. }
  144. *map = maps;
  145. *num_maps = nmaps;
  146. /* Iterate over pins and groups and create the mappings. */
  147. of_property_for_each_string(np, "renesas,groups", prop, group) {
  148. if (function) {
  149. maps[idx].type = PIN_MAP_TYPE_MUX_GROUP;
  150. maps[idx].data.mux.group = group;
  151. maps[idx].data.mux.function = function;
  152. idx++;
  153. }
  154. if (configs) {
  155. ret = sh_pfc_map_add_config(&maps[idx], group,
  156. PIN_MAP_TYPE_CONFIGS_GROUP,
  157. configs, num_configs);
  158. if (ret < 0)
  159. goto done;
  160. idx++;
  161. }
  162. }
  163. if (!configs) {
  164. ret = 0;
  165. goto done;
  166. }
  167. of_property_for_each_string(np, "renesas,pins", prop, pin) {
  168. ret = sh_pfc_map_add_config(&maps[idx], pin,
  169. PIN_MAP_TYPE_CONFIGS_PIN,
  170. configs, num_configs);
  171. if (ret < 0)
  172. goto done;
  173. idx++;
  174. }
  175. done:
  176. *index = idx;
  177. kfree(configs);
  178. return ret;
  179. }
  180. static void sh_pfc_dt_free_map(struct pinctrl_dev *pctldev,
  181. struct pinctrl_map *map, unsigned num_maps)
  182. {
  183. unsigned int i;
  184. if (map == NULL)
  185. return;
  186. for (i = 0; i < num_maps; ++i) {
  187. if (map[i].type == PIN_MAP_TYPE_CONFIGS_GROUP ||
  188. map[i].type == PIN_MAP_TYPE_CONFIGS_PIN)
  189. kfree(map[i].data.configs.configs);
  190. }
  191. kfree(map);
  192. }
  193. static int sh_pfc_dt_node_to_map(struct pinctrl_dev *pctldev,
  194. struct device_node *np,
  195. struct pinctrl_map **map, unsigned *num_maps)
  196. {
  197. struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
  198. struct device *dev = pmx->pfc->dev;
  199. struct device_node *child;
  200. unsigned int index;
  201. int ret;
  202. *map = NULL;
  203. *num_maps = 0;
  204. index = 0;
  205. for_each_child_of_node(np, child) {
  206. ret = sh_pfc_dt_subnode_to_map(dev, child, map, num_maps,
  207. &index);
  208. if (ret < 0)
  209. goto done;
  210. }
  211. /* If no mapping has been found in child nodes try the config node. */
  212. if (*num_maps == 0) {
  213. ret = sh_pfc_dt_subnode_to_map(dev, np, map, num_maps, &index);
  214. if (ret < 0)
  215. goto done;
  216. }
  217. if (*num_maps)
  218. return 0;
  219. dev_err(dev, "no mapping found in node %s\n", np->full_name);
  220. ret = -EINVAL;
  221. done:
  222. if (ret < 0)
  223. sh_pfc_dt_free_map(pctldev, *map, *num_maps);
  224. return ret;
  225. }
  226. #endif /* CONFIG_OF */
  227. static const struct pinctrl_ops sh_pfc_pinctrl_ops = {
  228. .get_groups_count = sh_pfc_get_groups_count,
  229. .get_group_name = sh_pfc_get_group_name,
  230. .get_group_pins = sh_pfc_get_group_pins,
  231. .pin_dbg_show = sh_pfc_pin_dbg_show,
  232. #ifdef CONFIG_OF
  233. .dt_node_to_map = sh_pfc_dt_node_to_map,
  234. .dt_free_map = sh_pfc_dt_free_map,
  235. #endif
  236. };
  237. static int sh_pfc_get_functions_count(struct pinctrl_dev *pctldev)
  238. {
  239. struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
  240. return pmx->pfc->info->nr_functions;
  241. }
  242. static const char *sh_pfc_get_function_name(struct pinctrl_dev *pctldev,
  243. unsigned selector)
  244. {
  245. struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
  246. return pmx->pfc->info->functions[selector].name;
  247. }
  248. static int sh_pfc_get_function_groups(struct pinctrl_dev *pctldev,
  249. unsigned selector,
  250. const char * const **groups,
  251. unsigned * const num_groups)
  252. {
  253. struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
  254. *groups = pmx->pfc->info->functions[selector].groups;
  255. *num_groups = pmx->pfc->info->functions[selector].nr_groups;
  256. return 0;
  257. }
  258. static int sh_pfc_func_enable(struct pinctrl_dev *pctldev, unsigned selector,
  259. unsigned group)
  260. {
  261. struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
  262. struct sh_pfc *pfc = pmx->pfc;
  263. const struct sh_pfc_pin_group *grp = &pfc->info->groups[group];
  264. unsigned long flags;
  265. unsigned int i;
  266. int ret = 0;
  267. spin_lock_irqsave(&pfc->lock, flags);
  268. for (i = 0; i < grp->nr_pins; ++i) {
  269. int idx = sh_pfc_get_pin_index(pfc, grp->pins[i]);
  270. struct sh_pfc_pin_config *cfg = &pmx->configs[idx];
  271. if (cfg->type != PINMUX_TYPE_NONE) {
  272. ret = -EBUSY;
  273. goto done;
  274. }
  275. }
  276. for (i = 0; i < grp->nr_pins; ++i) {
  277. ret = sh_pfc_config_mux(pfc, grp->mux[i], PINMUX_TYPE_FUNCTION);
  278. if (ret < 0)
  279. break;
  280. }
  281. done:
  282. spin_unlock_irqrestore(&pfc->lock, flags);
  283. return ret;
  284. }
  285. static void sh_pfc_func_disable(struct pinctrl_dev *pctldev, unsigned selector,
  286. unsigned group)
  287. {
  288. struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
  289. struct sh_pfc *pfc = pmx->pfc;
  290. const struct sh_pfc_pin_group *grp = &pfc->info->groups[group];
  291. unsigned long flags;
  292. unsigned int i;
  293. spin_lock_irqsave(&pfc->lock, flags);
  294. for (i = 0; i < grp->nr_pins; ++i) {
  295. int idx = sh_pfc_get_pin_index(pfc, grp->pins[i]);
  296. struct sh_pfc_pin_config *cfg = &pmx->configs[idx];
  297. cfg->type = PINMUX_TYPE_NONE;
  298. }
  299. spin_unlock_irqrestore(&pfc->lock, flags);
  300. }
  301. static int sh_pfc_gpio_request_enable(struct pinctrl_dev *pctldev,
  302. struct pinctrl_gpio_range *range,
  303. unsigned offset)
  304. {
  305. struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
  306. struct sh_pfc *pfc = pmx->pfc;
  307. int idx = sh_pfc_get_pin_index(pfc, offset);
  308. struct sh_pfc_pin_config *cfg = &pmx->configs[idx];
  309. unsigned long flags;
  310. int ret;
  311. spin_lock_irqsave(&pfc->lock, flags);
  312. if (cfg->type != PINMUX_TYPE_NONE) {
  313. dev_err(pfc->dev,
  314. "Pin %u is busy, can't configure it as GPIO.\n",
  315. offset);
  316. ret = -EBUSY;
  317. goto done;
  318. }
  319. if (!pfc->gpio) {
  320. /* If GPIOs are handled externally the pin mux type need to be
  321. * set to GPIO here.
  322. */
  323. const struct sh_pfc_pin *pin = &pfc->info->pins[idx];
  324. ret = sh_pfc_config_mux(pfc, pin->enum_id, PINMUX_TYPE_GPIO);
  325. if (ret < 0)
  326. goto done;
  327. }
  328. cfg->type = PINMUX_TYPE_GPIO;
  329. ret = 0;
  330. done:
  331. spin_unlock_irqrestore(&pfc->lock, flags);
  332. return ret;
  333. }
  334. static void sh_pfc_gpio_disable_free(struct pinctrl_dev *pctldev,
  335. struct pinctrl_gpio_range *range,
  336. unsigned offset)
  337. {
  338. struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
  339. struct sh_pfc *pfc = pmx->pfc;
  340. int idx = sh_pfc_get_pin_index(pfc, offset);
  341. struct sh_pfc_pin_config *cfg = &pmx->configs[idx];
  342. unsigned long flags;
  343. spin_lock_irqsave(&pfc->lock, flags);
  344. cfg->type = PINMUX_TYPE_NONE;
  345. spin_unlock_irqrestore(&pfc->lock, flags);
  346. }
  347. static int sh_pfc_gpio_set_direction(struct pinctrl_dev *pctldev,
  348. struct pinctrl_gpio_range *range,
  349. unsigned offset, bool input)
  350. {
  351. struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
  352. struct sh_pfc *pfc = pmx->pfc;
  353. int new_type = input ? PINMUX_TYPE_INPUT : PINMUX_TYPE_OUTPUT;
  354. int idx = sh_pfc_get_pin_index(pfc, offset);
  355. const struct sh_pfc_pin *pin = &pfc->info->pins[idx];
  356. struct sh_pfc_pin_config *cfg = &pmx->configs[idx];
  357. unsigned long flags;
  358. unsigned int dir;
  359. int ret;
  360. /* Check if the requested direction is supported by the pin. Not all SoC
  361. * provide pin config data, so perform the check conditionally.
  362. */
  363. if (pin->configs) {
  364. dir = input ? SH_PFC_PIN_CFG_INPUT : SH_PFC_PIN_CFG_OUTPUT;
  365. if (!(pin->configs & dir))
  366. return -EINVAL;
  367. }
  368. spin_lock_irqsave(&pfc->lock, flags);
  369. ret = sh_pfc_config_mux(pfc, pin->enum_id, new_type);
  370. if (ret < 0)
  371. goto done;
  372. cfg->type = new_type;
  373. done:
  374. spin_unlock_irqrestore(&pfc->lock, flags);
  375. return ret;
  376. }
  377. static const struct pinmux_ops sh_pfc_pinmux_ops = {
  378. .get_functions_count = sh_pfc_get_functions_count,
  379. .get_function_name = sh_pfc_get_function_name,
  380. .get_function_groups = sh_pfc_get_function_groups,
  381. .enable = sh_pfc_func_enable,
  382. .disable = sh_pfc_func_disable,
  383. .gpio_request_enable = sh_pfc_gpio_request_enable,
  384. .gpio_disable_free = sh_pfc_gpio_disable_free,
  385. .gpio_set_direction = sh_pfc_gpio_set_direction,
  386. };
  387. /* Check whether the requested parameter is supported for a pin. */
  388. static bool sh_pfc_pinconf_validate(struct sh_pfc *pfc, unsigned int _pin,
  389. enum pin_config_param param)
  390. {
  391. int idx = sh_pfc_get_pin_index(pfc, _pin);
  392. const struct sh_pfc_pin *pin = &pfc->info->pins[idx];
  393. switch (param) {
  394. case PIN_CONFIG_BIAS_DISABLE:
  395. return true;
  396. case PIN_CONFIG_BIAS_PULL_UP:
  397. return pin->configs & SH_PFC_PIN_CFG_PULL_UP;
  398. case PIN_CONFIG_BIAS_PULL_DOWN:
  399. return pin->configs & SH_PFC_PIN_CFG_PULL_DOWN;
  400. default:
  401. return false;
  402. }
  403. }
  404. static int sh_pfc_pinconf_get(struct pinctrl_dev *pctldev, unsigned _pin,
  405. unsigned long *config)
  406. {
  407. struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
  408. struct sh_pfc *pfc = pmx->pfc;
  409. enum pin_config_param param = pinconf_to_config_param(*config);
  410. unsigned long flags;
  411. unsigned int bias;
  412. if (!sh_pfc_pinconf_validate(pfc, _pin, param))
  413. return -ENOTSUPP;
  414. switch (param) {
  415. case PIN_CONFIG_BIAS_DISABLE:
  416. case PIN_CONFIG_BIAS_PULL_UP:
  417. case PIN_CONFIG_BIAS_PULL_DOWN:
  418. if (!pfc->info->ops || !pfc->info->ops->get_bias)
  419. return -ENOTSUPP;
  420. spin_lock_irqsave(&pfc->lock, flags);
  421. bias = pfc->info->ops->get_bias(pfc, _pin);
  422. spin_unlock_irqrestore(&pfc->lock, flags);
  423. if (bias != param)
  424. return -EINVAL;
  425. *config = 0;
  426. break;
  427. default:
  428. return -ENOTSUPP;
  429. }
  430. return 0;
  431. }
  432. static int sh_pfc_pinconf_set(struct pinctrl_dev *pctldev, unsigned _pin,
  433. unsigned long *configs, unsigned num_configs)
  434. {
  435. struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
  436. struct sh_pfc *pfc = pmx->pfc;
  437. enum pin_config_param param;
  438. unsigned long flags;
  439. unsigned int i;
  440. for (i = 0; i < num_configs; i++) {
  441. param = pinconf_to_config_param(configs[i]);
  442. if (!sh_pfc_pinconf_validate(pfc, _pin, param))
  443. return -ENOTSUPP;
  444. switch (param) {
  445. case PIN_CONFIG_BIAS_PULL_UP:
  446. case PIN_CONFIG_BIAS_PULL_DOWN:
  447. case PIN_CONFIG_BIAS_DISABLE:
  448. if (!pfc->info->ops || !pfc->info->ops->set_bias)
  449. return -ENOTSUPP;
  450. spin_lock_irqsave(&pfc->lock, flags);
  451. pfc->info->ops->set_bias(pfc, _pin, param);
  452. spin_unlock_irqrestore(&pfc->lock, flags);
  453. break;
  454. default:
  455. return -ENOTSUPP;
  456. }
  457. } /* for each config */
  458. return 0;
  459. }
  460. static int sh_pfc_pinconf_group_set(struct pinctrl_dev *pctldev, unsigned group,
  461. unsigned long *configs,
  462. unsigned num_configs)
  463. {
  464. struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
  465. const unsigned int *pins;
  466. unsigned int num_pins;
  467. unsigned int i;
  468. pins = pmx->pfc->info->groups[group].pins;
  469. num_pins = pmx->pfc->info->groups[group].nr_pins;
  470. for (i = 0; i < num_pins; ++i)
  471. sh_pfc_pinconf_set(pctldev, pins[i], configs, num_configs);
  472. return 0;
  473. }
  474. static const struct pinconf_ops sh_pfc_pinconf_ops = {
  475. .is_generic = true,
  476. .pin_config_get = sh_pfc_pinconf_get,
  477. .pin_config_set = sh_pfc_pinconf_set,
  478. .pin_config_group_set = sh_pfc_pinconf_group_set,
  479. .pin_config_config_dbg_show = pinconf_generic_dump_config,
  480. };
  481. /* PFC ranges -> pinctrl pin descs */
  482. static int sh_pfc_map_pins(struct sh_pfc *pfc, struct sh_pfc_pinctrl *pmx)
  483. {
  484. unsigned int i;
  485. /* Allocate and initialize the pins and configs arrays. */
  486. pmx->pins = devm_kzalloc(pfc->dev,
  487. sizeof(*pmx->pins) * pfc->info->nr_pins,
  488. GFP_KERNEL);
  489. if (unlikely(!pmx->pins))
  490. return -ENOMEM;
  491. pmx->configs = devm_kzalloc(pfc->dev,
  492. sizeof(*pmx->configs) * pfc->info->nr_pins,
  493. GFP_KERNEL);
  494. if (unlikely(!pmx->configs))
  495. return -ENOMEM;
  496. for (i = 0; i < pfc->info->nr_pins; ++i) {
  497. const struct sh_pfc_pin *info = &pfc->info->pins[i];
  498. struct sh_pfc_pin_config *cfg = &pmx->configs[i];
  499. struct pinctrl_pin_desc *pin = &pmx->pins[i];
  500. /* If the pin number is equal to -1 all pins are considered */
  501. pin->number = info->pin != (u16)-1 ? info->pin : i;
  502. pin->name = info->name;
  503. cfg->type = PINMUX_TYPE_NONE;
  504. }
  505. return 0;
  506. }
  507. int sh_pfc_register_pinctrl(struct sh_pfc *pfc)
  508. {
  509. struct sh_pfc_pinctrl *pmx;
  510. int ret;
  511. pmx = devm_kzalloc(pfc->dev, sizeof(*pmx), GFP_KERNEL);
  512. if (unlikely(!pmx))
  513. return -ENOMEM;
  514. pmx->pfc = pfc;
  515. pfc->pinctrl = pmx;
  516. ret = sh_pfc_map_pins(pfc, pmx);
  517. if (ret < 0)
  518. return ret;
  519. pmx->pctl_desc.name = DRV_NAME;
  520. pmx->pctl_desc.owner = THIS_MODULE;
  521. pmx->pctl_desc.pctlops = &sh_pfc_pinctrl_ops;
  522. pmx->pctl_desc.pmxops = &sh_pfc_pinmux_ops;
  523. pmx->pctl_desc.confops = &sh_pfc_pinconf_ops;
  524. pmx->pctl_desc.pins = pmx->pins;
  525. pmx->pctl_desc.npins = pfc->info->nr_pins;
  526. pmx->pctl = pinctrl_register(&pmx->pctl_desc, pfc->dev, pmx);
  527. if (pmx->pctl == NULL)
  528. return -EINVAL;
  529. return 0;
  530. }
  531. int sh_pfc_unregister_pinctrl(struct sh_pfc *pfc)
  532. {
  533. struct sh_pfc_pinctrl *pmx = pfc->pinctrl;
  534. pinctrl_unregister(pmx->pctl);
  535. pfc->pinctrl = NULL;
  536. return 0;
  537. }