pinctrl-imx1-core.c 17 KB

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