pinctrl-imx1-core.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. /*
  2. * Core driver for the imx pin controller in imx1/21/27
  3. *
  4. * Copyright (C) 2013 Pengutronix
  5. * Author: Markus Pargmann <mpa@pengutronix.de>
  6. *
  7. * Based on pinctrl-imx.c:
  8. * Author: Dong Aisheng <dong.aisheng@linaro.org>
  9. * Copyright (C) 2012 Freescale Semiconductor, Inc.
  10. * Copyright (C) 2012 Linaro Ltd.
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2 of the License, or
  15. * (at your option) any later version.
  16. */
  17. #include <linux/bitops.h>
  18. #include <linux/err.h>
  19. #include <linux/init.h>
  20. #include <linux/io.h>
  21. #include <linux/of.h>
  22. #include <linux/of_device.h>
  23. #include <linux/pinctrl/machine.h>
  24. #include <linux/pinctrl/pinconf.h>
  25. #include <linux/pinctrl/pinctrl.h>
  26. #include <linux/pinctrl/pinmux.h>
  27. #include <linux/slab.h>
  28. #include "../core.h"
  29. #include "pinctrl-imx1.h"
  30. struct imx1_pinctrl {
  31. struct device *dev;
  32. struct pinctrl_dev *pctl;
  33. void __iomem *base;
  34. const struct imx1_pinctrl_soc_info *info;
  35. };
  36. /*
  37. * MX1 register offsets
  38. */
  39. #define MX1_DDIR 0x00
  40. #define MX1_OCR 0x04
  41. #define MX1_ICONFA 0x0c
  42. #define MX1_ICONFB 0x14
  43. #define MX1_GIUS 0x20
  44. #define MX1_GPR 0x38
  45. #define MX1_PUEN 0x40
  46. #define MX1_PORT_STRIDE 0x100
  47. /*
  48. * MUX_ID format defines
  49. */
  50. #define MX1_MUX_FUNCTION(val) (BIT(0) & val)
  51. #define MX1_MUX_GPIO(val) ((BIT(1) & val) >> 1)
  52. #define MX1_MUX_DIR(val) ((BIT(2) & val) >> 2)
  53. #define MX1_MUX_OCONF(val) (((BIT(4) | BIT(5)) & val) >> 4)
  54. #define MX1_MUX_ICONFA(val) (((BIT(8) | BIT(9)) & val) >> 8)
  55. #define MX1_MUX_ICONFB(val) (((BIT(10) | BIT(11)) & val) >> 10)
  56. /*
  57. * IMX1 IOMUXC manages the pins based on ports. Each port has 32 pins. IOMUX
  58. * control register are seperated into function, output configuration, input
  59. * configuration A, input configuration B, GPIO in use and data direction.
  60. *
  61. * Those controls that are represented by 1 bit have a direct mapping between
  62. * bit position and pin id. If they are represented by 2 bit, the lower 16 pins
  63. * are in the first register and the upper 16 pins in the second (next)
  64. * register. pin_id is stored in bit (pin_id%16)*2 and the bit above.
  65. */
  66. /*
  67. * Calculates the register offset from a pin_id
  68. */
  69. static void __iomem *imx1_mem(struct imx1_pinctrl *ipctl, unsigned int pin_id)
  70. {
  71. unsigned int port = pin_id / 32;
  72. return ipctl->base + port * MX1_PORT_STRIDE;
  73. }
  74. /*
  75. * Write to a register with 2 bits per pin. The function will automatically
  76. * use the next register if the pin is managed in the second register.
  77. */
  78. static void imx1_write_2bit(struct imx1_pinctrl *ipctl, unsigned int pin_id,
  79. u32 value, u32 reg_offset)
  80. {
  81. void __iomem *reg = imx1_mem(ipctl, pin_id) + reg_offset;
  82. int offset = (pin_id % 16) * 2; /* offset, regardless of register used */
  83. int mask = ~(0x3 << offset); /* Mask for 2 bits at offset */
  84. u32 old_val;
  85. u32 new_val;
  86. /* Use the next register if the pin's port pin number is >=16 */
  87. if (pin_id % 32 >= 16)
  88. reg += 0x04;
  89. dev_dbg(ipctl->dev, "write: register 0x%p offset %d value 0x%x\n",
  90. reg, offset, value);
  91. /* Get current state of pins */
  92. old_val = readl(reg);
  93. old_val &= mask;
  94. new_val = value & 0x3; /* Make sure value is really 2 bit */
  95. new_val <<= offset;
  96. new_val |= old_val;/* Set new state for pin_id */
  97. writel(new_val, reg);
  98. }
  99. static void imx1_write_bit(struct imx1_pinctrl *ipctl, unsigned int pin_id,
  100. u32 value, u32 reg_offset)
  101. {
  102. void __iomem *reg = imx1_mem(ipctl, pin_id) + reg_offset;
  103. int offset = pin_id % 32;
  104. int mask = ~BIT_MASK(offset);
  105. u32 old_val;
  106. u32 new_val;
  107. /* Get current state of pins */
  108. old_val = readl(reg);
  109. old_val &= mask;
  110. new_val = value & 0x1; /* Make sure value is really 1 bit */
  111. new_val <<= offset;
  112. new_val |= old_val;/* Set new state for pin_id */
  113. writel(new_val, reg);
  114. }
  115. static int imx1_read_2bit(struct imx1_pinctrl *ipctl, unsigned int pin_id,
  116. u32 reg_offset)
  117. {
  118. void __iomem *reg = imx1_mem(ipctl, pin_id) + reg_offset;
  119. int offset = (pin_id % 16) * 2;
  120. /* Use the next register if the pin's port pin number is >=16 */
  121. if (pin_id % 32 >= 16)
  122. reg += 0x04;
  123. return (readl(reg) & (BIT(offset) | BIT(offset+1))) >> offset;
  124. }
  125. static int imx1_read_bit(struct imx1_pinctrl *ipctl, unsigned int pin_id,
  126. u32 reg_offset)
  127. {
  128. void __iomem *reg = imx1_mem(ipctl, pin_id) + reg_offset;
  129. int offset = pin_id % 32;
  130. return !!(readl(reg) & BIT(offset));
  131. }
  132. static inline const struct imx1_pin_group *imx1_pinctrl_find_group_by_name(
  133. const struct imx1_pinctrl_soc_info *info,
  134. const char *name)
  135. {
  136. const struct imx1_pin_group *grp = NULL;
  137. int i;
  138. for (i = 0; i < info->ngroups; i++) {
  139. if (!strcmp(info->groups[i].name, name)) {
  140. grp = &info->groups[i];
  141. break;
  142. }
  143. }
  144. return grp;
  145. }
  146. static int imx1_get_groups_count(struct pinctrl_dev *pctldev)
  147. {
  148. struct imx1_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);
  149. const struct imx1_pinctrl_soc_info *info = ipctl->info;
  150. return info->ngroups;
  151. }
  152. static const char *imx1_get_group_name(struct pinctrl_dev *pctldev,
  153. unsigned selector)
  154. {
  155. struct imx1_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);
  156. const struct imx1_pinctrl_soc_info *info = ipctl->info;
  157. return info->groups[selector].name;
  158. }
  159. static int imx1_get_group_pins(struct pinctrl_dev *pctldev, unsigned selector,
  160. const unsigned int **pins,
  161. unsigned *npins)
  162. {
  163. struct imx1_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);
  164. const struct imx1_pinctrl_soc_info *info = ipctl->info;
  165. if (selector >= info->ngroups)
  166. return -EINVAL;
  167. *pins = info->groups[selector].pin_ids;
  168. *npins = info->groups[selector].npins;
  169. return 0;
  170. }
  171. static void imx1_pin_dbg_show(struct pinctrl_dev *pctldev, struct seq_file *s,
  172. unsigned offset)
  173. {
  174. struct imx1_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);
  175. seq_printf(s, "GPIO %d, function %d, direction %d, oconf %d, iconfa %d, iconfb %d",
  176. imx1_read_bit(ipctl, offset, MX1_GIUS),
  177. imx1_read_bit(ipctl, offset, MX1_GPR),
  178. imx1_read_bit(ipctl, offset, MX1_DDIR),
  179. imx1_read_2bit(ipctl, offset, MX1_OCR),
  180. imx1_read_2bit(ipctl, offset, MX1_ICONFA),
  181. imx1_read_2bit(ipctl, offset, MX1_ICONFB));
  182. }
  183. static int imx1_dt_node_to_map(struct pinctrl_dev *pctldev,
  184. struct device_node *np,
  185. struct pinctrl_map **map, unsigned *num_maps)
  186. {
  187. struct imx1_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);
  188. const struct imx1_pinctrl_soc_info *info = ipctl->info;
  189. const struct imx1_pin_group *grp;
  190. struct pinctrl_map *new_map;
  191. struct device_node *parent;
  192. int map_num = 1;
  193. int i, j;
  194. /*
  195. * first find the group of this node and check if we need create
  196. * config maps for pins
  197. */
  198. grp = imx1_pinctrl_find_group_by_name(info, np->name);
  199. if (!grp) {
  200. dev_err(info->dev, "unable to find group for node %s\n",
  201. np->name);
  202. return -EINVAL;
  203. }
  204. for (i = 0; i < grp->npins; i++)
  205. map_num++;
  206. new_map = kmalloc(sizeof(struct pinctrl_map) * map_num, GFP_KERNEL);
  207. if (!new_map)
  208. return -ENOMEM;
  209. *map = new_map;
  210. *num_maps = map_num;
  211. /* create mux map */
  212. parent = of_get_parent(np);
  213. if (!parent) {
  214. kfree(new_map);
  215. return -EINVAL;
  216. }
  217. new_map[0].type = PIN_MAP_TYPE_MUX_GROUP;
  218. new_map[0].data.mux.function = parent->name;
  219. new_map[0].data.mux.group = np->name;
  220. of_node_put(parent);
  221. /* create config map */
  222. new_map++;
  223. for (i = j = 0; i < grp->npins; i++) {
  224. new_map[j].type = PIN_MAP_TYPE_CONFIGS_PIN;
  225. new_map[j].data.configs.group_or_pin =
  226. pin_get_name(pctldev, grp->pins[i].pin_id);
  227. new_map[j].data.configs.configs = &grp->pins[i].config;
  228. new_map[j].data.configs.num_configs = 1;
  229. j++;
  230. }
  231. dev_dbg(pctldev->dev, "maps: function %s group %s num %d\n",
  232. (*map)->data.mux.function, (*map)->data.mux.group, map_num);
  233. return 0;
  234. }
  235. static void imx1_dt_free_map(struct pinctrl_dev *pctldev,
  236. struct pinctrl_map *map, unsigned num_maps)
  237. {
  238. kfree(map);
  239. }
  240. static const struct pinctrl_ops imx1_pctrl_ops = {
  241. .get_groups_count = imx1_get_groups_count,
  242. .get_group_name = imx1_get_group_name,
  243. .get_group_pins = imx1_get_group_pins,
  244. .pin_dbg_show = imx1_pin_dbg_show,
  245. .dt_node_to_map = imx1_dt_node_to_map,
  246. .dt_free_map = imx1_dt_free_map,
  247. };
  248. static int imx1_pmx_set(struct pinctrl_dev *pctldev, unsigned selector,
  249. unsigned group)
  250. {
  251. struct imx1_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);
  252. const struct imx1_pinctrl_soc_info *info = ipctl->info;
  253. const struct imx1_pin *pins;
  254. unsigned int npins;
  255. int i;
  256. /*
  257. * Configure the mux mode for each pin in the group for a specific
  258. * function.
  259. */
  260. pins = info->groups[group].pins;
  261. npins = info->groups[group].npins;
  262. WARN_ON(!pins || !npins);
  263. dev_dbg(ipctl->dev, "enable function %s group %s\n",
  264. info->functions[selector].name, info->groups[group].name);
  265. for (i = 0; i < npins; i++) {
  266. unsigned int mux = pins[i].mux_id;
  267. unsigned int pin_id = pins[i].pin_id;
  268. unsigned int afunction = MX1_MUX_FUNCTION(mux);
  269. unsigned int gpio_in_use = MX1_MUX_GPIO(mux);
  270. unsigned int direction = MX1_MUX_DIR(mux);
  271. unsigned int gpio_oconf = MX1_MUX_OCONF(mux);
  272. unsigned int gpio_iconfa = MX1_MUX_ICONFA(mux);
  273. unsigned int gpio_iconfb = MX1_MUX_ICONFB(mux);
  274. dev_dbg(pctldev->dev, "%s, pin 0x%x, function %d, gpio %d, direction %d, oconf %d, iconfa %d, iconfb %d\n",
  275. __func__, pin_id, afunction, gpio_in_use,
  276. direction, gpio_oconf, gpio_iconfa,
  277. gpio_iconfb);
  278. imx1_write_bit(ipctl, pin_id, gpio_in_use, MX1_GIUS);
  279. imx1_write_bit(ipctl, pin_id, direction, MX1_DDIR);
  280. if (gpio_in_use) {
  281. imx1_write_2bit(ipctl, pin_id, gpio_oconf, MX1_OCR);
  282. imx1_write_2bit(ipctl, pin_id, gpio_iconfa,
  283. MX1_ICONFA);
  284. imx1_write_2bit(ipctl, pin_id, gpio_iconfb,
  285. MX1_ICONFB);
  286. } else {
  287. imx1_write_bit(ipctl, pin_id, afunction, MX1_GPR);
  288. }
  289. }
  290. return 0;
  291. }
  292. static int imx1_pmx_get_funcs_count(struct pinctrl_dev *pctldev)
  293. {
  294. struct imx1_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);
  295. const struct imx1_pinctrl_soc_info *info = ipctl->info;
  296. return info->nfunctions;
  297. }
  298. static const char *imx1_pmx_get_func_name(struct pinctrl_dev *pctldev,
  299. unsigned selector)
  300. {
  301. struct imx1_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);
  302. const struct imx1_pinctrl_soc_info *info = ipctl->info;
  303. return info->functions[selector].name;
  304. }
  305. static int imx1_pmx_get_groups(struct pinctrl_dev *pctldev, unsigned selector,
  306. const char * const **groups,
  307. unsigned * const num_groups)
  308. {
  309. struct imx1_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);
  310. const struct imx1_pinctrl_soc_info *info = ipctl->info;
  311. *groups = info->functions[selector].groups;
  312. *num_groups = info->functions[selector].num_groups;
  313. return 0;
  314. }
  315. static const struct pinmux_ops imx1_pmx_ops = {
  316. .get_functions_count = imx1_pmx_get_funcs_count,
  317. .get_function_name = imx1_pmx_get_func_name,
  318. .get_function_groups = imx1_pmx_get_groups,
  319. .set_mux = imx1_pmx_set,
  320. };
  321. static int imx1_pinconf_get(struct pinctrl_dev *pctldev,
  322. unsigned pin_id, unsigned long *config)
  323. {
  324. struct imx1_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);
  325. *config = imx1_read_bit(ipctl, pin_id, MX1_PUEN);
  326. return 0;
  327. }
  328. static int imx1_pinconf_set(struct pinctrl_dev *pctldev,
  329. unsigned pin_id, unsigned long *configs,
  330. unsigned num_configs)
  331. {
  332. struct imx1_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);
  333. int i;
  334. for (i = 0; i != num_configs; ++i) {
  335. imx1_write_bit(ipctl, pin_id, configs[i] & 0x01, MX1_PUEN);
  336. dev_dbg(ipctl->dev, "pinconf set pullup pin %s\n",
  337. pin_desc_get(pctldev, pin_id)->name);
  338. }
  339. return 0;
  340. }
  341. static void imx1_pinconf_dbg_show(struct pinctrl_dev *pctldev,
  342. struct seq_file *s, unsigned pin_id)
  343. {
  344. unsigned long config;
  345. imx1_pinconf_get(pctldev, pin_id, &config);
  346. seq_printf(s, "0x%lx", config);
  347. }
  348. static void imx1_pinconf_group_dbg_show(struct pinctrl_dev *pctldev,
  349. struct seq_file *s, unsigned group)
  350. {
  351. struct imx1_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);
  352. const struct imx1_pinctrl_soc_info *info = ipctl->info;
  353. struct imx1_pin_group *grp;
  354. unsigned long config;
  355. const char *name;
  356. int i, ret;
  357. if (group > info->ngroups)
  358. return;
  359. seq_puts(s, "\n");
  360. grp = &info->groups[group];
  361. for (i = 0; i < grp->npins; i++) {
  362. name = pin_get_name(pctldev, grp->pins[i].pin_id);
  363. ret = imx1_pinconf_get(pctldev, grp->pins[i].pin_id, &config);
  364. if (ret)
  365. return;
  366. seq_printf(s, "%s: 0x%lx", name, config);
  367. }
  368. }
  369. static const struct pinconf_ops imx1_pinconf_ops = {
  370. .pin_config_get = imx1_pinconf_get,
  371. .pin_config_set = imx1_pinconf_set,
  372. .pin_config_dbg_show = imx1_pinconf_dbg_show,
  373. .pin_config_group_dbg_show = imx1_pinconf_group_dbg_show,
  374. };
  375. static struct pinctrl_desc imx1_pinctrl_desc = {
  376. .pctlops = &imx1_pctrl_ops,
  377. .pmxops = &imx1_pmx_ops,
  378. .confops = &imx1_pinconf_ops,
  379. .owner = THIS_MODULE,
  380. };
  381. static int imx1_pinctrl_parse_groups(struct device_node *np,
  382. struct imx1_pin_group *grp,
  383. struct imx1_pinctrl_soc_info *info,
  384. u32 index)
  385. {
  386. int size;
  387. const __be32 *list;
  388. int i;
  389. dev_dbg(info->dev, "group(%d): %s\n", index, np->name);
  390. /* Initialise group */
  391. grp->name = np->name;
  392. /*
  393. * the binding format is fsl,pins = <PIN MUX_ID CONFIG>
  394. */
  395. list = of_get_property(np, "fsl,pins", &size);
  396. /* we do not check return since it's safe node passed down */
  397. if (!size || size % 12) {
  398. dev_notice(info->dev, "Not a valid fsl,pins property (%s)\n",
  399. np->name);
  400. return -EINVAL;
  401. }
  402. grp->npins = size / 12;
  403. grp->pins = devm_kzalloc(info->dev,
  404. grp->npins * sizeof(struct imx1_pin), GFP_KERNEL);
  405. grp->pin_ids = devm_kzalloc(info->dev,
  406. grp->npins * sizeof(unsigned int), GFP_KERNEL);
  407. if (!grp->pins || !grp->pin_ids)
  408. return -ENOMEM;
  409. for (i = 0; i < grp->npins; i++) {
  410. grp->pins[i].pin_id = be32_to_cpu(*list++);
  411. grp->pins[i].mux_id = be32_to_cpu(*list++);
  412. grp->pins[i].config = be32_to_cpu(*list++);
  413. grp->pin_ids[i] = grp->pins[i].pin_id;
  414. }
  415. return 0;
  416. }
  417. static int imx1_pinctrl_parse_functions(struct device_node *np,
  418. struct imx1_pinctrl_soc_info *info,
  419. u32 index)
  420. {
  421. struct device_node *child;
  422. struct imx1_pmx_func *func;
  423. struct imx1_pin_group *grp;
  424. int ret;
  425. static u32 grp_index;
  426. u32 i = 0;
  427. dev_dbg(info->dev, "parse function(%d): %s\n", index, np->name);
  428. func = &info->functions[index];
  429. /* Initialise function */
  430. func->name = np->name;
  431. func->num_groups = of_get_child_count(np);
  432. if (func->num_groups == 0)
  433. return -EINVAL;
  434. func->groups = devm_kzalloc(info->dev,
  435. func->num_groups * sizeof(char *), GFP_KERNEL);
  436. if (!func->groups)
  437. return -ENOMEM;
  438. for_each_child_of_node(np, child) {
  439. func->groups[i] = child->name;
  440. grp = &info->groups[grp_index++];
  441. ret = imx1_pinctrl_parse_groups(child, grp, info, i++);
  442. if (ret == -ENOMEM) {
  443. of_node_put(child);
  444. return ret;
  445. }
  446. }
  447. return 0;
  448. }
  449. static int imx1_pinctrl_parse_dt(struct platform_device *pdev,
  450. struct imx1_pinctrl *pctl, struct imx1_pinctrl_soc_info *info)
  451. {
  452. struct device_node *np = pdev->dev.of_node;
  453. struct device_node *child;
  454. int ret;
  455. u32 nfuncs = 0;
  456. u32 ngroups = 0;
  457. u32 ifunc = 0;
  458. if (!np)
  459. return -ENODEV;
  460. for_each_child_of_node(np, child) {
  461. ++nfuncs;
  462. ngroups += of_get_child_count(child);
  463. }
  464. if (!nfuncs) {
  465. dev_err(&pdev->dev, "No pin functions defined\n");
  466. return -EINVAL;
  467. }
  468. info->nfunctions = nfuncs;
  469. info->functions = devm_kzalloc(&pdev->dev,
  470. nfuncs * sizeof(struct imx1_pmx_func), GFP_KERNEL);
  471. info->ngroups = ngroups;
  472. info->groups = devm_kzalloc(&pdev->dev,
  473. ngroups * sizeof(struct imx1_pin_group), GFP_KERNEL);
  474. if (!info->functions || !info->groups)
  475. return -ENOMEM;
  476. for_each_child_of_node(np, child) {
  477. ret = imx1_pinctrl_parse_functions(child, info, ifunc++);
  478. if (ret == -ENOMEM) {
  479. of_node_put(child);
  480. return -ENOMEM;
  481. }
  482. }
  483. return 0;
  484. }
  485. int imx1_pinctrl_core_probe(struct platform_device *pdev,
  486. struct imx1_pinctrl_soc_info *info)
  487. {
  488. struct imx1_pinctrl *ipctl;
  489. struct resource *res;
  490. struct pinctrl_desc *pctl_desc;
  491. int ret;
  492. if (!info || !info->pins || !info->npins) {
  493. dev_err(&pdev->dev, "wrong pinctrl info\n");
  494. return -EINVAL;
  495. }
  496. info->dev = &pdev->dev;
  497. /* Create state holders etc for this driver */
  498. ipctl = devm_kzalloc(&pdev->dev, sizeof(*ipctl), GFP_KERNEL);
  499. if (!ipctl)
  500. return -ENOMEM;
  501. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  502. if (!res)
  503. return -ENOENT;
  504. ipctl->base = devm_ioremap_nocache(&pdev->dev, res->start,
  505. resource_size(res));
  506. if (!ipctl->base)
  507. return -ENOMEM;
  508. pctl_desc = &imx1_pinctrl_desc;
  509. pctl_desc->name = dev_name(&pdev->dev);
  510. pctl_desc->pins = info->pins;
  511. pctl_desc->npins = info->npins;
  512. ret = imx1_pinctrl_parse_dt(pdev, ipctl, info);
  513. if (ret) {
  514. dev_err(&pdev->dev, "fail to probe dt properties\n");
  515. return ret;
  516. }
  517. ipctl->info = info;
  518. ipctl->dev = info->dev;
  519. platform_set_drvdata(pdev, ipctl);
  520. ipctl->pctl = devm_pinctrl_register(&pdev->dev, pctl_desc, ipctl);
  521. if (IS_ERR(ipctl->pctl)) {
  522. dev_err(&pdev->dev, "could not register IMX pinctrl driver\n");
  523. return PTR_ERR(ipctl->pctl);
  524. }
  525. ret = of_platform_populate(pdev->dev.of_node, NULL, NULL, &pdev->dev);
  526. if (ret) {
  527. pinctrl_unregister(ipctl->pctl);
  528. dev_err(&pdev->dev, "Failed to populate subdevices\n");
  529. return ret;
  530. }
  531. dev_info(&pdev->dev, "initialized IMX pinctrl driver\n");
  532. return 0;
  533. }