pinctrl-tegra.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. /*
  2. * Driver for the NVIDIA Tegra pinmux
  3. *
  4. * Copyright (c) 2011-2012, NVIDIA CORPORATION. All rights reserved.
  5. *
  6. * Derived from code:
  7. * Copyright (C) 2010 Google, Inc.
  8. * Copyright (C) 2010 NVIDIA Corporation
  9. * Copyright (C) 2009-2011 ST-Ericsson AB
  10. *
  11. * This program is free software; you can redistribute it and/or modify it
  12. * under the terms and conditions of the GNU General Public License,
  13. * version 2, as published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope it will be useful, but WITHOUT
  16. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  17. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  18. * more details.
  19. */
  20. #include <linux/err.h>
  21. #include <linux/init.h>
  22. #include <linux/io.h>
  23. #include <linux/module.h>
  24. #include <linux/of.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/pinctrl/machine.h>
  27. #include <linux/pinctrl/pinctrl.h>
  28. #include <linux/pinctrl/pinmux.h>
  29. #include <linux/pinctrl/pinconf.h>
  30. #include <linux/slab.h>
  31. #include "core.h"
  32. #include "pinctrl-tegra.h"
  33. #include "pinctrl-utils.h"
  34. struct tegra_pmx {
  35. struct device *dev;
  36. struct pinctrl_dev *pctl;
  37. const struct tegra_pinctrl_soc_data *soc;
  38. int nbanks;
  39. void __iomem **regs;
  40. };
  41. static inline u32 pmx_readl(struct tegra_pmx *pmx, u32 bank, u32 reg)
  42. {
  43. return readl(pmx->regs[bank] + reg);
  44. }
  45. static inline void pmx_writel(struct tegra_pmx *pmx, u32 val, u32 bank, u32 reg)
  46. {
  47. writel(val, pmx->regs[bank] + reg);
  48. }
  49. static int tegra_pinctrl_get_groups_count(struct pinctrl_dev *pctldev)
  50. {
  51. struct tegra_pmx *pmx = pinctrl_dev_get_drvdata(pctldev);
  52. return pmx->soc->ngroups;
  53. }
  54. static const char *tegra_pinctrl_get_group_name(struct pinctrl_dev *pctldev,
  55. unsigned group)
  56. {
  57. struct tegra_pmx *pmx = pinctrl_dev_get_drvdata(pctldev);
  58. return pmx->soc->groups[group].name;
  59. }
  60. static int tegra_pinctrl_get_group_pins(struct pinctrl_dev *pctldev,
  61. unsigned group,
  62. const unsigned **pins,
  63. unsigned *num_pins)
  64. {
  65. struct tegra_pmx *pmx = pinctrl_dev_get_drvdata(pctldev);
  66. *pins = pmx->soc->groups[group].pins;
  67. *num_pins = pmx->soc->groups[group].npins;
  68. return 0;
  69. }
  70. #ifdef CONFIG_DEBUG_FS
  71. static void tegra_pinctrl_pin_dbg_show(struct pinctrl_dev *pctldev,
  72. struct seq_file *s,
  73. unsigned offset)
  74. {
  75. seq_printf(s, " %s", dev_name(pctldev->dev));
  76. }
  77. #endif
  78. static const struct cfg_param {
  79. const char *property;
  80. enum tegra_pinconf_param param;
  81. } cfg_params[] = {
  82. {"nvidia,pull", TEGRA_PINCONF_PARAM_PULL},
  83. {"nvidia,tristate", TEGRA_PINCONF_PARAM_TRISTATE},
  84. {"nvidia,enable-input", TEGRA_PINCONF_PARAM_ENABLE_INPUT},
  85. {"nvidia,open-drain", TEGRA_PINCONF_PARAM_OPEN_DRAIN},
  86. {"nvidia,lock", TEGRA_PINCONF_PARAM_LOCK},
  87. {"nvidia,io-reset", TEGRA_PINCONF_PARAM_IORESET},
  88. {"nvidia,rcv-sel", TEGRA_PINCONF_PARAM_RCV_SEL},
  89. {"nvidia,high-speed-mode", TEGRA_PINCONF_PARAM_HIGH_SPEED_MODE},
  90. {"nvidia,schmitt", TEGRA_PINCONF_PARAM_SCHMITT},
  91. {"nvidia,low-power-mode", TEGRA_PINCONF_PARAM_LOW_POWER_MODE},
  92. {"nvidia,pull-down-strength", TEGRA_PINCONF_PARAM_DRIVE_DOWN_STRENGTH},
  93. {"nvidia,pull-up-strength", TEGRA_PINCONF_PARAM_DRIVE_UP_STRENGTH},
  94. {"nvidia,slew-rate-falling", TEGRA_PINCONF_PARAM_SLEW_RATE_FALLING},
  95. {"nvidia,slew-rate-rising", TEGRA_PINCONF_PARAM_SLEW_RATE_RISING},
  96. {"nvidia,drive-type", TEGRA_PINCONF_PARAM_DRIVE_TYPE},
  97. };
  98. static int tegra_pinctrl_dt_subnode_to_map(struct pinctrl_dev *pctldev,
  99. struct device_node *np,
  100. struct pinctrl_map **map,
  101. unsigned *reserved_maps,
  102. unsigned *num_maps)
  103. {
  104. struct device *dev = pctldev->dev;
  105. int ret, i;
  106. const char *function;
  107. u32 val;
  108. unsigned long config;
  109. unsigned long *configs = NULL;
  110. unsigned num_configs = 0;
  111. unsigned reserve;
  112. struct property *prop;
  113. const char *group;
  114. ret = of_property_read_string(np, "nvidia,function", &function);
  115. if (ret < 0) {
  116. /* EINVAL=missing, which is fine since it's optional */
  117. if (ret != -EINVAL)
  118. dev_err(dev,
  119. "could not parse property nvidia,function\n");
  120. function = NULL;
  121. }
  122. for (i = 0; i < ARRAY_SIZE(cfg_params); i++) {
  123. ret = of_property_read_u32(np, cfg_params[i].property, &val);
  124. if (!ret) {
  125. config = TEGRA_PINCONF_PACK(cfg_params[i].param, val);
  126. ret = pinctrl_utils_add_config(pctldev, &configs,
  127. &num_configs, config);
  128. if (ret < 0)
  129. goto exit;
  130. /* EINVAL=missing, which is fine since it's optional */
  131. } else if (ret != -EINVAL) {
  132. dev_err(dev, "could not parse property %s\n",
  133. cfg_params[i].property);
  134. }
  135. }
  136. reserve = 0;
  137. if (function != NULL)
  138. reserve++;
  139. if (num_configs)
  140. reserve++;
  141. ret = of_property_count_strings(np, "nvidia,pins");
  142. if (ret < 0) {
  143. dev_err(dev, "could not parse property nvidia,pins\n");
  144. goto exit;
  145. }
  146. reserve *= ret;
  147. ret = pinctrl_utils_reserve_map(pctldev, map, reserved_maps,
  148. num_maps, reserve);
  149. if (ret < 0)
  150. goto exit;
  151. of_property_for_each_string(np, "nvidia,pins", prop, group) {
  152. if (function) {
  153. ret = pinctrl_utils_add_map_mux(pctldev, map,
  154. reserved_maps, num_maps, group,
  155. function);
  156. if (ret < 0)
  157. goto exit;
  158. }
  159. if (num_configs) {
  160. ret = pinctrl_utils_add_map_configs(pctldev, map,
  161. reserved_maps, num_maps, group,
  162. configs, num_configs,
  163. PIN_MAP_TYPE_CONFIGS_GROUP);
  164. if (ret < 0)
  165. goto exit;
  166. }
  167. }
  168. ret = 0;
  169. exit:
  170. kfree(configs);
  171. return ret;
  172. }
  173. static int tegra_pinctrl_dt_node_to_map(struct pinctrl_dev *pctldev,
  174. struct device_node *np_config,
  175. struct pinctrl_map **map,
  176. unsigned *num_maps)
  177. {
  178. unsigned reserved_maps;
  179. struct device_node *np;
  180. int ret;
  181. reserved_maps = 0;
  182. *map = NULL;
  183. *num_maps = 0;
  184. for_each_child_of_node(np_config, np) {
  185. ret = tegra_pinctrl_dt_subnode_to_map(pctldev, np, map,
  186. &reserved_maps, num_maps);
  187. if (ret < 0) {
  188. pinctrl_utils_dt_free_map(pctldev, *map,
  189. *num_maps);
  190. return ret;
  191. }
  192. }
  193. return 0;
  194. }
  195. static const struct pinctrl_ops tegra_pinctrl_ops = {
  196. .get_groups_count = tegra_pinctrl_get_groups_count,
  197. .get_group_name = tegra_pinctrl_get_group_name,
  198. .get_group_pins = tegra_pinctrl_get_group_pins,
  199. #ifdef CONFIG_DEBUG_FS
  200. .pin_dbg_show = tegra_pinctrl_pin_dbg_show,
  201. #endif
  202. .dt_node_to_map = tegra_pinctrl_dt_node_to_map,
  203. .dt_free_map = pinctrl_utils_dt_free_map,
  204. };
  205. static int tegra_pinctrl_get_funcs_count(struct pinctrl_dev *pctldev)
  206. {
  207. struct tegra_pmx *pmx = pinctrl_dev_get_drvdata(pctldev);
  208. return pmx->soc->nfunctions;
  209. }
  210. static const char *tegra_pinctrl_get_func_name(struct pinctrl_dev *pctldev,
  211. unsigned function)
  212. {
  213. struct tegra_pmx *pmx = pinctrl_dev_get_drvdata(pctldev);
  214. return pmx->soc->functions[function].name;
  215. }
  216. static int tegra_pinctrl_get_func_groups(struct pinctrl_dev *pctldev,
  217. unsigned function,
  218. const char * const **groups,
  219. unsigned * const num_groups)
  220. {
  221. struct tegra_pmx *pmx = pinctrl_dev_get_drvdata(pctldev);
  222. *groups = pmx->soc->functions[function].groups;
  223. *num_groups = pmx->soc->functions[function].ngroups;
  224. return 0;
  225. }
  226. static int tegra_pinctrl_enable(struct pinctrl_dev *pctldev, unsigned function,
  227. unsigned group)
  228. {
  229. struct tegra_pmx *pmx = pinctrl_dev_get_drvdata(pctldev);
  230. const struct tegra_pingroup *g;
  231. int i;
  232. u32 val;
  233. g = &pmx->soc->groups[group];
  234. if (WARN_ON(g->mux_reg < 0))
  235. return -EINVAL;
  236. for (i = 0; i < ARRAY_SIZE(g->funcs); i++) {
  237. if (g->funcs[i] == function)
  238. break;
  239. }
  240. if (WARN_ON(i == ARRAY_SIZE(g->funcs)))
  241. return -EINVAL;
  242. val = pmx_readl(pmx, g->mux_bank, g->mux_reg);
  243. val &= ~(0x3 << g->mux_bit);
  244. val |= i << g->mux_bit;
  245. pmx_writel(pmx, val, g->mux_bank, g->mux_reg);
  246. return 0;
  247. }
  248. static void tegra_pinctrl_disable(struct pinctrl_dev *pctldev,
  249. unsigned function, unsigned group)
  250. {
  251. struct tegra_pmx *pmx = pinctrl_dev_get_drvdata(pctldev);
  252. const struct tegra_pingroup *g;
  253. u32 val;
  254. g = &pmx->soc->groups[group];
  255. if (WARN_ON(g->mux_reg < 0))
  256. return;
  257. val = pmx_readl(pmx, g->mux_bank, g->mux_reg);
  258. val &= ~(0x3 << g->mux_bit);
  259. val |= g->func_safe << g->mux_bit;
  260. pmx_writel(pmx, val, g->mux_bank, g->mux_reg);
  261. }
  262. static const struct pinmux_ops tegra_pinmux_ops = {
  263. .get_functions_count = tegra_pinctrl_get_funcs_count,
  264. .get_function_name = tegra_pinctrl_get_func_name,
  265. .get_function_groups = tegra_pinctrl_get_func_groups,
  266. .enable = tegra_pinctrl_enable,
  267. .disable = tegra_pinctrl_disable,
  268. };
  269. static int tegra_pinconf_reg(struct tegra_pmx *pmx,
  270. const struct tegra_pingroup *g,
  271. enum tegra_pinconf_param param,
  272. bool report_err,
  273. s8 *bank, s16 *reg, s8 *bit, s8 *width)
  274. {
  275. switch (param) {
  276. case TEGRA_PINCONF_PARAM_PULL:
  277. *bank = g->pupd_bank;
  278. *reg = g->pupd_reg;
  279. *bit = g->pupd_bit;
  280. *width = 2;
  281. break;
  282. case TEGRA_PINCONF_PARAM_TRISTATE:
  283. *bank = g->tri_bank;
  284. *reg = g->tri_reg;
  285. *bit = g->tri_bit;
  286. *width = 1;
  287. break;
  288. case TEGRA_PINCONF_PARAM_ENABLE_INPUT:
  289. *bank = g->einput_bank;
  290. *reg = g->einput_reg;
  291. *bit = g->einput_bit;
  292. *width = 1;
  293. break;
  294. case TEGRA_PINCONF_PARAM_OPEN_DRAIN:
  295. *bank = g->odrain_bank;
  296. *reg = g->odrain_reg;
  297. *bit = g->odrain_bit;
  298. *width = 1;
  299. break;
  300. case TEGRA_PINCONF_PARAM_LOCK:
  301. *bank = g->lock_bank;
  302. *reg = g->lock_reg;
  303. *bit = g->lock_bit;
  304. *width = 1;
  305. break;
  306. case TEGRA_PINCONF_PARAM_IORESET:
  307. *bank = g->ioreset_bank;
  308. *reg = g->ioreset_reg;
  309. *bit = g->ioreset_bit;
  310. *width = 1;
  311. break;
  312. case TEGRA_PINCONF_PARAM_RCV_SEL:
  313. *bank = g->rcv_sel_bank;
  314. *reg = g->rcv_sel_reg;
  315. *bit = g->rcv_sel_bit;
  316. *width = 1;
  317. break;
  318. case TEGRA_PINCONF_PARAM_HIGH_SPEED_MODE:
  319. *bank = g->drv_bank;
  320. *reg = g->drv_reg;
  321. *bit = g->hsm_bit;
  322. *width = 1;
  323. break;
  324. case TEGRA_PINCONF_PARAM_SCHMITT:
  325. *bank = g->drv_bank;
  326. *reg = g->drv_reg;
  327. *bit = g->schmitt_bit;
  328. *width = 1;
  329. break;
  330. case TEGRA_PINCONF_PARAM_LOW_POWER_MODE:
  331. *bank = g->drv_bank;
  332. *reg = g->drv_reg;
  333. *bit = g->lpmd_bit;
  334. *width = 2;
  335. break;
  336. case TEGRA_PINCONF_PARAM_DRIVE_DOWN_STRENGTH:
  337. *bank = g->drv_bank;
  338. *reg = g->drv_reg;
  339. *bit = g->drvdn_bit;
  340. *width = g->drvdn_width;
  341. break;
  342. case TEGRA_PINCONF_PARAM_DRIVE_UP_STRENGTH:
  343. *bank = g->drv_bank;
  344. *reg = g->drv_reg;
  345. *bit = g->drvup_bit;
  346. *width = g->drvup_width;
  347. break;
  348. case TEGRA_PINCONF_PARAM_SLEW_RATE_FALLING:
  349. *bank = g->drv_bank;
  350. *reg = g->drv_reg;
  351. *bit = g->slwf_bit;
  352. *width = g->slwf_width;
  353. break;
  354. case TEGRA_PINCONF_PARAM_SLEW_RATE_RISING:
  355. *bank = g->drv_bank;
  356. *reg = g->drv_reg;
  357. *bit = g->slwr_bit;
  358. *width = g->slwr_width;
  359. break;
  360. case TEGRA_PINCONF_PARAM_DRIVE_TYPE:
  361. *bank = g->drvtype_bank;
  362. *reg = g->drvtype_reg;
  363. *bit = g->drvtype_bit;
  364. *width = 2;
  365. break;
  366. default:
  367. dev_err(pmx->dev, "Invalid config param %04x\n", param);
  368. return -ENOTSUPP;
  369. }
  370. if (*reg < 0) {
  371. if (report_err)
  372. dev_err(pmx->dev,
  373. "Config param %04x not supported on group %s\n",
  374. param, g->name);
  375. return -ENOTSUPP;
  376. }
  377. return 0;
  378. }
  379. static int tegra_pinconf_get(struct pinctrl_dev *pctldev,
  380. unsigned pin, unsigned long *config)
  381. {
  382. dev_err(pctldev->dev, "pin_config_get op not supported\n");
  383. return -ENOTSUPP;
  384. }
  385. static int tegra_pinconf_set(struct pinctrl_dev *pctldev,
  386. unsigned pin, unsigned long *configs,
  387. unsigned num_configs)
  388. {
  389. dev_err(pctldev->dev, "pin_config_set op not supported\n");
  390. return -ENOTSUPP;
  391. }
  392. static int tegra_pinconf_group_get(struct pinctrl_dev *pctldev,
  393. unsigned group, unsigned long *config)
  394. {
  395. struct tegra_pmx *pmx = pinctrl_dev_get_drvdata(pctldev);
  396. enum tegra_pinconf_param param = TEGRA_PINCONF_UNPACK_PARAM(*config);
  397. u16 arg;
  398. const struct tegra_pingroup *g;
  399. int ret;
  400. s8 bank, bit, width;
  401. s16 reg;
  402. u32 val, mask;
  403. g = &pmx->soc->groups[group];
  404. ret = tegra_pinconf_reg(pmx, g, param, true, &bank, &reg, &bit,
  405. &width);
  406. if (ret < 0)
  407. return ret;
  408. val = pmx_readl(pmx, bank, reg);
  409. mask = (1 << width) - 1;
  410. arg = (val >> bit) & mask;
  411. *config = TEGRA_PINCONF_PACK(param, arg);
  412. return 0;
  413. }
  414. static int tegra_pinconf_group_set(struct pinctrl_dev *pctldev,
  415. unsigned group, unsigned long *configs,
  416. unsigned num_configs)
  417. {
  418. struct tegra_pmx *pmx = pinctrl_dev_get_drvdata(pctldev);
  419. enum tegra_pinconf_param param;
  420. u16 arg;
  421. const struct tegra_pingroup *g;
  422. int ret, i;
  423. s8 bank, bit, width;
  424. s16 reg;
  425. u32 val, mask;
  426. g = &pmx->soc->groups[group];
  427. for (i = 0; i < num_configs; i++) {
  428. param = TEGRA_PINCONF_UNPACK_PARAM(configs[i]);
  429. arg = TEGRA_PINCONF_UNPACK_ARG(configs[i]);
  430. ret = tegra_pinconf_reg(pmx, g, param, true, &bank, &reg, &bit,
  431. &width);
  432. if (ret < 0)
  433. return ret;
  434. val = pmx_readl(pmx, bank, reg);
  435. /* LOCK can't be cleared */
  436. if (param == TEGRA_PINCONF_PARAM_LOCK) {
  437. if ((val & BIT(bit)) && !arg) {
  438. dev_err(pctldev->dev, "LOCK bit cannot be cleared\n");
  439. return -EINVAL;
  440. }
  441. }
  442. /* Special-case Boolean values; allow any non-zero as true */
  443. if (width == 1)
  444. arg = !!arg;
  445. /* Range-check user-supplied value */
  446. mask = (1 << width) - 1;
  447. if (arg & ~mask) {
  448. dev_err(pctldev->dev,
  449. "config %lx: %x too big for %d bit register\n",
  450. configs[i], arg, width);
  451. return -EINVAL;
  452. }
  453. /* Update register */
  454. val &= ~(mask << bit);
  455. val |= arg << bit;
  456. pmx_writel(pmx, val, bank, reg);
  457. } /* for each config */
  458. return 0;
  459. }
  460. #ifdef CONFIG_DEBUG_FS
  461. static void tegra_pinconf_dbg_show(struct pinctrl_dev *pctldev,
  462. struct seq_file *s, unsigned offset)
  463. {
  464. }
  465. static const char *strip_prefix(const char *s)
  466. {
  467. const char *comma = strchr(s, ',');
  468. if (!comma)
  469. return s;
  470. return comma + 1;
  471. }
  472. static void tegra_pinconf_group_dbg_show(struct pinctrl_dev *pctldev,
  473. struct seq_file *s, unsigned group)
  474. {
  475. struct tegra_pmx *pmx = pinctrl_dev_get_drvdata(pctldev);
  476. const struct tegra_pingroup *g;
  477. int i, ret;
  478. s8 bank, bit, width;
  479. s16 reg;
  480. u32 val;
  481. g = &pmx->soc->groups[group];
  482. for (i = 0; i < ARRAY_SIZE(cfg_params); i++) {
  483. ret = tegra_pinconf_reg(pmx, g, cfg_params[i].param, false,
  484. &bank, &reg, &bit, &width);
  485. if (ret < 0)
  486. continue;
  487. val = pmx_readl(pmx, bank, reg);
  488. val >>= bit;
  489. val &= (1 << width) - 1;
  490. seq_printf(s, "\n\t%s=%u",
  491. strip_prefix(cfg_params[i].property), val);
  492. }
  493. }
  494. static void tegra_pinconf_config_dbg_show(struct pinctrl_dev *pctldev,
  495. struct seq_file *s,
  496. unsigned long config)
  497. {
  498. enum tegra_pinconf_param param = TEGRA_PINCONF_UNPACK_PARAM(config);
  499. u16 arg = TEGRA_PINCONF_UNPACK_ARG(config);
  500. const char *pname = "unknown";
  501. int i;
  502. for (i = 0; i < ARRAY_SIZE(cfg_params); i++) {
  503. if (cfg_params[i].param == param) {
  504. pname = cfg_params[i].property;
  505. break;
  506. }
  507. }
  508. seq_printf(s, "%s=%d", strip_prefix(pname), arg);
  509. }
  510. #endif
  511. static const struct pinconf_ops tegra_pinconf_ops = {
  512. .pin_config_get = tegra_pinconf_get,
  513. .pin_config_set = tegra_pinconf_set,
  514. .pin_config_group_get = tegra_pinconf_group_get,
  515. .pin_config_group_set = tegra_pinconf_group_set,
  516. #ifdef CONFIG_DEBUG_FS
  517. .pin_config_dbg_show = tegra_pinconf_dbg_show,
  518. .pin_config_group_dbg_show = tegra_pinconf_group_dbg_show,
  519. .pin_config_config_dbg_show = tegra_pinconf_config_dbg_show,
  520. #endif
  521. };
  522. static struct pinctrl_gpio_range tegra_pinctrl_gpio_range = {
  523. .name = "Tegra GPIOs",
  524. .id = 0,
  525. .base = 0,
  526. };
  527. static struct pinctrl_desc tegra_pinctrl_desc = {
  528. .pctlops = &tegra_pinctrl_ops,
  529. .pmxops = &tegra_pinmux_ops,
  530. .confops = &tegra_pinconf_ops,
  531. .owner = THIS_MODULE,
  532. };
  533. int tegra_pinctrl_probe(struct platform_device *pdev,
  534. const struct tegra_pinctrl_soc_data *soc_data)
  535. {
  536. struct tegra_pmx *pmx;
  537. struct resource *res;
  538. int i;
  539. pmx = devm_kzalloc(&pdev->dev, sizeof(*pmx), GFP_KERNEL);
  540. if (!pmx) {
  541. dev_err(&pdev->dev, "Can't alloc tegra_pmx\n");
  542. return -ENOMEM;
  543. }
  544. pmx->dev = &pdev->dev;
  545. pmx->soc = soc_data;
  546. tegra_pinctrl_gpio_range.npins = pmx->soc->ngpios;
  547. tegra_pinctrl_desc.name = dev_name(&pdev->dev);
  548. tegra_pinctrl_desc.pins = pmx->soc->pins;
  549. tegra_pinctrl_desc.npins = pmx->soc->npins;
  550. for (i = 0; ; i++) {
  551. res = platform_get_resource(pdev, IORESOURCE_MEM, i);
  552. if (!res)
  553. break;
  554. }
  555. pmx->nbanks = i;
  556. pmx->regs = devm_kzalloc(&pdev->dev, pmx->nbanks * sizeof(*pmx->regs),
  557. GFP_KERNEL);
  558. if (!pmx->regs) {
  559. dev_err(&pdev->dev, "Can't alloc regs pointer\n");
  560. return -ENODEV;
  561. }
  562. for (i = 0; i < pmx->nbanks; i++) {
  563. res = platform_get_resource(pdev, IORESOURCE_MEM, i);
  564. pmx->regs[i] = devm_ioremap_resource(&pdev->dev, res);
  565. if (IS_ERR(pmx->regs[i]))
  566. return PTR_ERR(pmx->regs[i]);
  567. }
  568. pmx->pctl = pinctrl_register(&tegra_pinctrl_desc, &pdev->dev, pmx);
  569. if (!pmx->pctl) {
  570. dev_err(&pdev->dev, "Couldn't register pinctrl driver\n");
  571. return -ENODEV;
  572. }
  573. pinctrl_add_gpio_range(pmx->pctl, &tegra_pinctrl_gpio_range);
  574. platform_set_drvdata(pdev, pmx);
  575. dev_dbg(&pdev->dev, "Probed Tegra pinctrl driver\n");
  576. return 0;
  577. }
  578. EXPORT_SYMBOL_GPL(tegra_pinctrl_probe);
  579. int tegra_pinctrl_remove(struct platform_device *pdev)
  580. {
  581. struct tegra_pmx *pmx = platform_get_drvdata(pdev);
  582. pinctrl_unregister(pmx->pctl);
  583. return 0;
  584. }
  585. EXPORT_SYMBOL_GPL(tegra_pinctrl_remove);