pinctrl-meson.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. /*
  2. * Pin controller and GPIO driver for Amlogic Meson SoCs
  3. *
  4. * Copyright (C) 2014 Beniamino Galvani <b.galvani@gmail.com>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * version 2 as published by the Free Software Foundation.
  9. *
  10. * You should have received a copy of the GNU General Public License
  11. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  12. */
  13. /*
  14. * The available pins are organized in banks (A,B,C,D,E,X,Y,Z,AO,
  15. * BOOT,CARD for meson6, X,Y,DV,H,Z,AO,BOOT,CARD for meson8 and
  16. * X,Y,DV,H,AO,BOOT,CARD,DIF for meson8b) and each bank has a
  17. * variable number of pins.
  18. *
  19. * The AO bank is special because it belongs to the Always-On power
  20. * domain which can't be powered off; the bank also uses a set of
  21. * registers different from the other banks.
  22. *
  23. * For each pin controller there are 4 different register ranges that
  24. * control the following properties of the pins:
  25. * 1) pin muxing
  26. * 2) pull enable/disable
  27. * 3) pull up/down
  28. * 4) GPIO direction, output value, input value
  29. *
  30. * In some cases the register ranges for pull enable and pull
  31. * direction are the same and thus there are only 3 register ranges.
  32. *
  33. * Every pinmux group can be enabled by a specific bit in the first
  34. * register range; when all groups for a given pin are disabled the
  35. * pin acts as a GPIO.
  36. *
  37. * For the pull and GPIO configuration every bank uses a contiguous
  38. * set of bits in the register sets described above; the same register
  39. * can be shared by more banks with different offsets.
  40. *
  41. * In addition to this there are some registers shared between all
  42. * banks that control the IRQ functionality. This feature is not
  43. * supported at the moment by the driver.
  44. */
  45. #include <linux/device.h>
  46. #include <linux/gpio.h>
  47. #include <linux/init.h>
  48. #include <linux/io.h>
  49. #include <linux/of.h>
  50. #include <linux/of_address.h>
  51. #include <linux/pinctrl/pinconf-generic.h>
  52. #include <linux/pinctrl/pinconf.h>
  53. #include <linux/pinctrl/pinctrl.h>
  54. #include <linux/pinctrl/pinmux.h>
  55. #include <linux/platform_device.h>
  56. #include <linux/regmap.h>
  57. #include <linux/seq_file.h>
  58. #include "../core.h"
  59. #include "../pinctrl-utils.h"
  60. #include "pinctrl-meson.h"
  61. /**
  62. * meson_get_bank() - find the bank containing a given pin
  63. *
  64. * @pc: the pinctrl instance
  65. * @pin: the pin number
  66. * @bank: the found bank
  67. *
  68. * Return: 0 on success, a negative value on error
  69. */
  70. static int meson_get_bank(struct meson_pinctrl *pc, unsigned int pin,
  71. struct meson_bank **bank)
  72. {
  73. int i;
  74. for (i = 0; i < pc->data->num_banks; i++) {
  75. if (pin >= pc->data->banks[i].first &&
  76. pin <= pc->data->banks[i].last) {
  77. *bank = &pc->data->banks[i];
  78. return 0;
  79. }
  80. }
  81. return -EINVAL;
  82. }
  83. /**
  84. * meson_calc_reg_and_bit() - calculate register and bit for a pin
  85. *
  86. * @bank: the bank containing the pin
  87. * @pin: the pin number
  88. * @reg_type: the type of register needed (pull-enable, pull, etc...)
  89. * @reg: the computed register offset
  90. * @bit: the computed bit
  91. */
  92. static void meson_calc_reg_and_bit(struct meson_bank *bank, unsigned int pin,
  93. enum meson_reg_type reg_type,
  94. unsigned int *reg, unsigned int *bit)
  95. {
  96. struct meson_reg_desc *desc = &bank->regs[reg_type];
  97. *reg = desc->reg * 4;
  98. *bit = desc->bit + pin - bank->first;
  99. }
  100. static int meson_get_groups_count(struct pinctrl_dev *pcdev)
  101. {
  102. struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev);
  103. return pc->data->num_groups;
  104. }
  105. static const char *meson_get_group_name(struct pinctrl_dev *pcdev,
  106. unsigned selector)
  107. {
  108. struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev);
  109. return pc->data->groups[selector].name;
  110. }
  111. static int meson_get_group_pins(struct pinctrl_dev *pcdev, unsigned selector,
  112. const unsigned **pins, unsigned *num_pins)
  113. {
  114. struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev);
  115. *pins = pc->data->groups[selector].pins;
  116. *num_pins = pc->data->groups[selector].num_pins;
  117. return 0;
  118. }
  119. static void meson_pin_dbg_show(struct pinctrl_dev *pcdev, struct seq_file *s,
  120. unsigned offset)
  121. {
  122. seq_printf(s, " %s", dev_name(pcdev->dev));
  123. }
  124. static const struct pinctrl_ops meson_pctrl_ops = {
  125. .get_groups_count = meson_get_groups_count,
  126. .get_group_name = meson_get_group_name,
  127. .get_group_pins = meson_get_group_pins,
  128. .dt_node_to_map = pinconf_generic_dt_node_to_map_all,
  129. .dt_free_map = pinctrl_utils_free_map,
  130. .pin_dbg_show = meson_pin_dbg_show,
  131. };
  132. /**
  133. * meson_pmx_disable_other_groups() - disable other groups using a given pin
  134. *
  135. * @pc: meson pin controller device
  136. * @pin: number of the pin
  137. * @sel_group: index of the selected group, or -1 if none
  138. *
  139. * The function disables all pinmux groups using a pin except the
  140. * selected one. If @sel_group is -1 all groups are disabled, leaving
  141. * the pin in GPIO mode.
  142. */
  143. static void meson_pmx_disable_other_groups(struct meson_pinctrl *pc,
  144. unsigned int pin, int sel_group)
  145. {
  146. struct meson_pmx_group *group;
  147. int i, j;
  148. for (i = 0; i < pc->data->num_groups; i++) {
  149. group = &pc->data->groups[i];
  150. if (group->is_gpio || i == sel_group)
  151. continue;
  152. for (j = 0; j < group->num_pins; j++) {
  153. if (group->pins[j] == pin) {
  154. /* We have found a group using the pin */
  155. regmap_update_bits(pc->reg_mux,
  156. group->reg * 4,
  157. BIT(group->bit), 0);
  158. }
  159. }
  160. }
  161. }
  162. static int meson_pmx_set_mux(struct pinctrl_dev *pcdev, unsigned func_num,
  163. unsigned group_num)
  164. {
  165. struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev);
  166. struct meson_pmx_func *func = &pc->data->funcs[func_num];
  167. struct meson_pmx_group *group = &pc->data->groups[group_num];
  168. int i, ret = 0;
  169. dev_dbg(pc->dev, "enable function %s, group %s\n", func->name,
  170. group->name);
  171. /*
  172. * Disable groups using the same pin.
  173. * The selected group is not disabled to avoid glitches.
  174. */
  175. for (i = 0; i < group->num_pins; i++)
  176. meson_pmx_disable_other_groups(pc, group->pins[i], group_num);
  177. /* Function 0 (GPIO) doesn't need any additional setting */
  178. if (func_num)
  179. ret = regmap_update_bits(pc->reg_mux, group->reg * 4,
  180. BIT(group->bit), BIT(group->bit));
  181. return ret;
  182. }
  183. static int meson_pmx_request_gpio(struct pinctrl_dev *pcdev,
  184. struct pinctrl_gpio_range *range,
  185. unsigned offset)
  186. {
  187. struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev);
  188. meson_pmx_disable_other_groups(pc, offset, -1);
  189. return 0;
  190. }
  191. static int meson_pmx_get_funcs_count(struct pinctrl_dev *pcdev)
  192. {
  193. struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev);
  194. return pc->data->num_funcs;
  195. }
  196. static const char *meson_pmx_get_func_name(struct pinctrl_dev *pcdev,
  197. unsigned selector)
  198. {
  199. struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev);
  200. return pc->data->funcs[selector].name;
  201. }
  202. static int meson_pmx_get_groups(struct pinctrl_dev *pcdev, unsigned selector,
  203. const char * const **groups,
  204. unsigned * const num_groups)
  205. {
  206. struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev);
  207. *groups = pc->data->funcs[selector].groups;
  208. *num_groups = pc->data->funcs[selector].num_groups;
  209. return 0;
  210. }
  211. static const struct pinmux_ops meson_pmx_ops = {
  212. .set_mux = meson_pmx_set_mux,
  213. .get_functions_count = meson_pmx_get_funcs_count,
  214. .get_function_name = meson_pmx_get_func_name,
  215. .get_function_groups = meson_pmx_get_groups,
  216. .gpio_request_enable = meson_pmx_request_gpio,
  217. };
  218. static int meson_pinconf_set(struct pinctrl_dev *pcdev, unsigned int pin,
  219. unsigned long *configs, unsigned num_configs)
  220. {
  221. struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev);
  222. struct meson_bank *bank;
  223. enum pin_config_param param;
  224. unsigned int reg, bit;
  225. int i, ret;
  226. ret = meson_get_bank(pc, pin, &bank);
  227. if (ret)
  228. return ret;
  229. for (i = 0; i < num_configs; i++) {
  230. param = pinconf_to_config_param(configs[i]);
  231. switch (param) {
  232. case PIN_CONFIG_BIAS_DISABLE:
  233. dev_dbg(pc->dev, "pin %u: disable bias\n", pin);
  234. meson_calc_reg_and_bit(bank, pin, REG_PULL, &reg, &bit);
  235. ret = regmap_update_bits(pc->reg_pull, reg,
  236. BIT(bit), 0);
  237. if (ret)
  238. return ret;
  239. break;
  240. case PIN_CONFIG_BIAS_PULL_UP:
  241. dev_dbg(pc->dev, "pin %u: enable pull-up\n", pin);
  242. meson_calc_reg_and_bit(bank, pin, REG_PULLEN,
  243. &reg, &bit);
  244. ret = regmap_update_bits(pc->reg_pullen, reg,
  245. BIT(bit), BIT(bit));
  246. if (ret)
  247. return ret;
  248. meson_calc_reg_and_bit(bank, pin, REG_PULL, &reg, &bit);
  249. ret = regmap_update_bits(pc->reg_pull, reg,
  250. BIT(bit), BIT(bit));
  251. if (ret)
  252. return ret;
  253. break;
  254. case PIN_CONFIG_BIAS_PULL_DOWN:
  255. dev_dbg(pc->dev, "pin %u: enable pull-down\n", pin);
  256. meson_calc_reg_and_bit(bank, pin, REG_PULLEN,
  257. &reg, &bit);
  258. ret = regmap_update_bits(pc->reg_pullen, reg,
  259. BIT(bit), BIT(bit));
  260. if (ret)
  261. return ret;
  262. meson_calc_reg_and_bit(bank, pin, REG_PULL, &reg, &bit);
  263. ret = regmap_update_bits(pc->reg_pull, reg,
  264. BIT(bit), 0);
  265. if (ret)
  266. return ret;
  267. break;
  268. default:
  269. return -ENOTSUPP;
  270. }
  271. }
  272. return 0;
  273. }
  274. static int meson_pinconf_get_pull(struct meson_pinctrl *pc, unsigned int pin)
  275. {
  276. struct meson_bank *bank;
  277. unsigned int reg, bit, val;
  278. int ret, conf;
  279. ret = meson_get_bank(pc, pin, &bank);
  280. if (ret)
  281. return ret;
  282. meson_calc_reg_and_bit(bank, pin, REG_PULLEN, &reg, &bit);
  283. ret = regmap_read(pc->reg_pullen, reg, &val);
  284. if (ret)
  285. return ret;
  286. if (!(val & BIT(bit))) {
  287. conf = PIN_CONFIG_BIAS_DISABLE;
  288. } else {
  289. meson_calc_reg_and_bit(bank, pin, REG_PULL, &reg, &bit);
  290. ret = regmap_read(pc->reg_pull, reg, &val);
  291. if (ret)
  292. return ret;
  293. if (val & BIT(bit))
  294. conf = PIN_CONFIG_BIAS_PULL_UP;
  295. else
  296. conf = PIN_CONFIG_BIAS_PULL_DOWN;
  297. }
  298. return conf;
  299. }
  300. static int meson_pinconf_get(struct pinctrl_dev *pcdev, unsigned int pin,
  301. unsigned long *config)
  302. {
  303. struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev);
  304. enum pin_config_param param = pinconf_to_config_param(*config);
  305. u16 arg;
  306. switch (param) {
  307. case PIN_CONFIG_BIAS_DISABLE:
  308. case PIN_CONFIG_BIAS_PULL_DOWN:
  309. case PIN_CONFIG_BIAS_PULL_UP:
  310. if (meson_pinconf_get_pull(pc, pin) == param)
  311. arg = 1;
  312. else
  313. return -EINVAL;
  314. break;
  315. default:
  316. return -ENOTSUPP;
  317. }
  318. *config = pinconf_to_config_packed(param, arg);
  319. dev_dbg(pc->dev, "pinconf for pin %u is %lu\n", pin, *config);
  320. return 0;
  321. }
  322. static int meson_pinconf_group_set(struct pinctrl_dev *pcdev,
  323. unsigned int num_group,
  324. unsigned long *configs, unsigned num_configs)
  325. {
  326. struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev);
  327. struct meson_pmx_group *group = &pc->data->groups[num_group];
  328. int i;
  329. dev_dbg(pc->dev, "set pinconf for group %s\n", group->name);
  330. for (i = 0; i < group->num_pins; i++) {
  331. meson_pinconf_set(pcdev, group->pins[i], configs,
  332. num_configs);
  333. }
  334. return 0;
  335. }
  336. static int meson_pinconf_group_get(struct pinctrl_dev *pcdev,
  337. unsigned int group, unsigned long *config)
  338. {
  339. return -ENOSYS;
  340. }
  341. static const struct pinconf_ops meson_pinconf_ops = {
  342. .pin_config_get = meson_pinconf_get,
  343. .pin_config_set = meson_pinconf_set,
  344. .pin_config_group_get = meson_pinconf_group_get,
  345. .pin_config_group_set = meson_pinconf_group_set,
  346. .is_generic = true,
  347. };
  348. static int meson_gpio_request(struct gpio_chip *chip, unsigned gpio)
  349. {
  350. return pinctrl_request_gpio(chip->base + gpio);
  351. }
  352. static void meson_gpio_free(struct gpio_chip *chip, unsigned gpio)
  353. {
  354. struct meson_pinctrl *pc = gpiochip_get_data(chip);
  355. pinctrl_free_gpio(pc->data->pin_base + gpio);
  356. }
  357. static int meson_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
  358. {
  359. struct meson_pinctrl *pc = gpiochip_get_data(chip);
  360. unsigned int reg, bit, pin;
  361. struct meson_bank *bank;
  362. int ret;
  363. pin = pc->data->pin_base + gpio;
  364. ret = meson_get_bank(pc, pin, &bank);
  365. if (ret)
  366. return ret;
  367. meson_calc_reg_and_bit(bank, pin, REG_DIR, &reg, &bit);
  368. return regmap_update_bits(pc->reg_gpio, reg, BIT(bit), BIT(bit));
  369. }
  370. static int meson_gpio_direction_output(struct gpio_chip *chip, unsigned gpio,
  371. int value)
  372. {
  373. struct meson_pinctrl *pc = gpiochip_get_data(chip);
  374. unsigned int reg, bit, pin;
  375. struct meson_bank *bank;
  376. int ret;
  377. pin = pc->data->pin_base + gpio;
  378. ret = meson_get_bank(pc, pin, &bank);
  379. if (ret)
  380. return ret;
  381. meson_calc_reg_and_bit(bank, pin, REG_DIR, &reg, &bit);
  382. ret = regmap_update_bits(pc->reg_gpio, reg, BIT(bit), 0);
  383. if (ret)
  384. return ret;
  385. meson_calc_reg_and_bit(bank, pin, REG_OUT, &reg, &bit);
  386. return regmap_update_bits(pc->reg_gpio, reg, BIT(bit),
  387. value ? BIT(bit) : 0);
  388. }
  389. static void meson_gpio_set(struct gpio_chip *chip, unsigned gpio, int value)
  390. {
  391. struct meson_pinctrl *pc = gpiochip_get_data(chip);
  392. unsigned int reg, bit, pin;
  393. struct meson_bank *bank;
  394. int ret;
  395. pin = pc->data->pin_base + gpio;
  396. ret = meson_get_bank(pc, pin, &bank);
  397. if (ret)
  398. return;
  399. meson_calc_reg_and_bit(bank, pin, REG_OUT, &reg, &bit);
  400. regmap_update_bits(pc->reg_gpio, reg, BIT(bit),
  401. value ? BIT(bit) : 0);
  402. }
  403. static int meson_gpio_get(struct gpio_chip *chip, unsigned gpio)
  404. {
  405. struct meson_pinctrl *pc = gpiochip_get_data(chip);
  406. unsigned int reg, bit, val, pin;
  407. struct meson_bank *bank;
  408. int ret;
  409. pin = pc->data->pin_base + gpio;
  410. ret = meson_get_bank(pc, pin, &bank);
  411. if (ret)
  412. return ret;
  413. meson_calc_reg_and_bit(bank, pin, REG_IN, &reg, &bit);
  414. regmap_read(pc->reg_gpio, reg, &val);
  415. return !!(val & BIT(bit));
  416. }
  417. static const struct of_device_id meson_pinctrl_dt_match[] = {
  418. {
  419. .compatible = "amlogic,meson8-cbus-pinctrl",
  420. .data = &meson8_cbus_pinctrl_data,
  421. },
  422. {
  423. .compatible = "amlogic,meson8b-cbus-pinctrl",
  424. .data = &meson8b_cbus_pinctrl_data,
  425. },
  426. {
  427. .compatible = "amlogic,meson8-aobus-pinctrl",
  428. .data = &meson8_aobus_pinctrl_data,
  429. },
  430. {
  431. .compatible = "amlogic,meson8b-aobus-pinctrl",
  432. .data = &meson8b_aobus_pinctrl_data,
  433. },
  434. {
  435. .compatible = "amlogic,meson-gxbb-periphs-pinctrl",
  436. .data = &meson_gxbb_periphs_pinctrl_data,
  437. },
  438. {
  439. .compatible = "amlogic,meson-gxbb-aobus-pinctrl",
  440. .data = &meson_gxbb_aobus_pinctrl_data,
  441. },
  442. {
  443. .compatible = "amlogic,meson-gxl-periphs-pinctrl",
  444. .data = &meson_gxl_periphs_pinctrl_data,
  445. },
  446. {
  447. .compatible = "amlogic,meson-gxl-aobus-pinctrl",
  448. .data = &meson_gxl_aobus_pinctrl_data,
  449. },
  450. { },
  451. };
  452. static int meson_gpiolib_register(struct meson_pinctrl *pc)
  453. {
  454. int ret;
  455. pc->chip.label = pc->data->name;
  456. pc->chip.parent = pc->dev;
  457. pc->chip.request = meson_gpio_request;
  458. pc->chip.free = meson_gpio_free;
  459. pc->chip.direction_input = meson_gpio_direction_input;
  460. pc->chip.direction_output = meson_gpio_direction_output;
  461. pc->chip.get = meson_gpio_get;
  462. pc->chip.set = meson_gpio_set;
  463. pc->chip.base = pc->data->pin_base;
  464. pc->chip.ngpio = pc->data->num_pins;
  465. pc->chip.can_sleep = false;
  466. pc->chip.of_node = pc->of_node;
  467. pc->chip.of_gpio_n_cells = 2;
  468. ret = gpiochip_add_data(&pc->chip, pc);
  469. if (ret) {
  470. dev_err(pc->dev, "can't add gpio chip %s\n",
  471. pc->data->name);
  472. return ret;
  473. }
  474. return 0;
  475. }
  476. static struct regmap_config meson_regmap_config = {
  477. .reg_bits = 32,
  478. .val_bits = 32,
  479. .reg_stride = 4,
  480. };
  481. static struct regmap *meson_map_resource(struct meson_pinctrl *pc,
  482. struct device_node *node, char *name)
  483. {
  484. struct resource res;
  485. void __iomem *base;
  486. int i;
  487. i = of_property_match_string(node, "reg-names", name);
  488. if (of_address_to_resource(node, i, &res))
  489. return ERR_PTR(-ENOENT);
  490. base = devm_ioremap_resource(pc->dev, &res);
  491. if (IS_ERR(base))
  492. return ERR_CAST(base);
  493. meson_regmap_config.max_register = resource_size(&res) - 4;
  494. meson_regmap_config.name = devm_kasprintf(pc->dev, GFP_KERNEL,
  495. "%s-%s", node->name,
  496. name);
  497. if (!meson_regmap_config.name)
  498. return ERR_PTR(-ENOMEM);
  499. return devm_regmap_init_mmio(pc->dev, base, &meson_regmap_config);
  500. }
  501. static int meson_pinctrl_parse_dt(struct meson_pinctrl *pc,
  502. struct device_node *node)
  503. {
  504. struct device_node *np, *gpio_np = NULL;
  505. for_each_child_of_node(node, np) {
  506. if (!of_find_property(np, "gpio-controller", NULL))
  507. continue;
  508. if (gpio_np) {
  509. dev_err(pc->dev, "multiple gpio nodes\n");
  510. return -EINVAL;
  511. }
  512. gpio_np = np;
  513. }
  514. if (!gpio_np) {
  515. dev_err(pc->dev, "no gpio node found\n");
  516. return -EINVAL;
  517. }
  518. pc->of_node = gpio_np;
  519. pc->reg_mux = meson_map_resource(pc, gpio_np, "mux");
  520. if (IS_ERR(pc->reg_mux)) {
  521. dev_err(pc->dev, "mux registers not found\n");
  522. return PTR_ERR(pc->reg_mux);
  523. }
  524. pc->reg_pull = meson_map_resource(pc, gpio_np, "pull");
  525. if (IS_ERR(pc->reg_pull)) {
  526. dev_err(pc->dev, "pull registers not found\n");
  527. return PTR_ERR(pc->reg_pull);
  528. }
  529. pc->reg_pullen = meson_map_resource(pc, gpio_np, "pull-enable");
  530. /* Use pull region if pull-enable one is not present */
  531. if (IS_ERR(pc->reg_pullen))
  532. pc->reg_pullen = pc->reg_pull;
  533. pc->reg_gpio = meson_map_resource(pc, gpio_np, "gpio");
  534. if (IS_ERR(pc->reg_gpio)) {
  535. dev_err(pc->dev, "gpio registers not found\n");
  536. return PTR_ERR(pc->reg_gpio);
  537. }
  538. return 0;
  539. }
  540. static int meson_pinctrl_probe(struct platform_device *pdev)
  541. {
  542. const struct of_device_id *match;
  543. struct device *dev = &pdev->dev;
  544. struct meson_pinctrl *pc;
  545. int ret;
  546. pc = devm_kzalloc(dev, sizeof(struct meson_pinctrl), GFP_KERNEL);
  547. if (!pc)
  548. return -ENOMEM;
  549. pc->dev = dev;
  550. match = of_match_node(meson_pinctrl_dt_match, pdev->dev.of_node);
  551. pc->data = (struct meson_pinctrl_data *) match->data;
  552. ret = meson_pinctrl_parse_dt(pc, pdev->dev.of_node);
  553. if (ret)
  554. return ret;
  555. pc->desc.name = "pinctrl-meson";
  556. pc->desc.owner = THIS_MODULE;
  557. pc->desc.pctlops = &meson_pctrl_ops;
  558. pc->desc.pmxops = &meson_pmx_ops;
  559. pc->desc.confops = &meson_pinconf_ops;
  560. pc->desc.pins = pc->data->pins;
  561. pc->desc.npins = pc->data->num_pins;
  562. pc->pcdev = devm_pinctrl_register(pc->dev, &pc->desc, pc);
  563. if (IS_ERR(pc->pcdev)) {
  564. dev_err(pc->dev, "can't register pinctrl device");
  565. return PTR_ERR(pc->pcdev);
  566. }
  567. return meson_gpiolib_register(pc);
  568. }
  569. static struct platform_driver meson_pinctrl_driver = {
  570. .probe = meson_pinctrl_probe,
  571. .driver = {
  572. .name = "meson-pinctrl",
  573. .of_match_table = meson_pinctrl_dt_match,
  574. },
  575. };
  576. builtin_platform_driver(meson_pinctrl_driver);