pinctrl-meson.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  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_PULLEN, &reg,
  235. &bit);
  236. ret = regmap_update_bits(pc->reg_pullen, reg,
  237. BIT(bit), 0);
  238. if (ret)
  239. return ret;
  240. break;
  241. case PIN_CONFIG_BIAS_PULL_UP:
  242. dev_dbg(pc->dev, "pin %u: enable pull-up\n", pin);
  243. meson_calc_reg_and_bit(bank, pin, REG_PULLEN,
  244. &reg, &bit);
  245. ret = regmap_update_bits(pc->reg_pullen, reg,
  246. BIT(bit), BIT(bit));
  247. if (ret)
  248. return ret;
  249. meson_calc_reg_and_bit(bank, pin, REG_PULL, &reg, &bit);
  250. ret = regmap_update_bits(pc->reg_pull, reg,
  251. BIT(bit), BIT(bit));
  252. if (ret)
  253. return ret;
  254. break;
  255. case PIN_CONFIG_BIAS_PULL_DOWN:
  256. dev_dbg(pc->dev, "pin %u: enable pull-down\n", pin);
  257. meson_calc_reg_and_bit(bank, pin, REG_PULLEN,
  258. &reg, &bit);
  259. ret = regmap_update_bits(pc->reg_pullen, reg,
  260. BIT(bit), BIT(bit));
  261. if (ret)
  262. return ret;
  263. meson_calc_reg_and_bit(bank, pin, REG_PULL, &reg, &bit);
  264. ret = regmap_update_bits(pc->reg_pull, reg,
  265. BIT(bit), 0);
  266. if (ret)
  267. return ret;
  268. break;
  269. default:
  270. return -ENOTSUPP;
  271. }
  272. }
  273. return 0;
  274. }
  275. static int meson_pinconf_get_pull(struct meson_pinctrl *pc, unsigned int pin)
  276. {
  277. struct meson_bank *bank;
  278. unsigned int reg, bit, val;
  279. int ret, conf;
  280. ret = meson_get_bank(pc, pin, &bank);
  281. if (ret)
  282. return ret;
  283. meson_calc_reg_and_bit(bank, pin, REG_PULLEN, &reg, &bit);
  284. ret = regmap_read(pc->reg_pullen, reg, &val);
  285. if (ret)
  286. return ret;
  287. if (!(val & BIT(bit))) {
  288. conf = PIN_CONFIG_BIAS_DISABLE;
  289. } else {
  290. meson_calc_reg_and_bit(bank, pin, REG_PULL, &reg, &bit);
  291. ret = regmap_read(pc->reg_pull, reg, &val);
  292. if (ret)
  293. return ret;
  294. if (val & BIT(bit))
  295. conf = PIN_CONFIG_BIAS_PULL_UP;
  296. else
  297. conf = PIN_CONFIG_BIAS_PULL_DOWN;
  298. }
  299. return conf;
  300. }
  301. static int meson_pinconf_get(struct pinctrl_dev *pcdev, unsigned int pin,
  302. unsigned long *config)
  303. {
  304. struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev);
  305. enum pin_config_param param = pinconf_to_config_param(*config);
  306. u16 arg;
  307. switch (param) {
  308. case PIN_CONFIG_BIAS_DISABLE:
  309. case PIN_CONFIG_BIAS_PULL_DOWN:
  310. case PIN_CONFIG_BIAS_PULL_UP:
  311. if (meson_pinconf_get_pull(pc, pin) == param)
  312. arg = 1;
  313. else
  314. return -EINVAL;
  315. break;
  316. default:
  317. return -ENOTSUPP;
  318. }
  319. *config = pinconf_to_config_packed(param, arg);
  320. dev_dbg(pc->dev, "pinconf for pin %u is %lu\n", pin, *config);
  321. return 0;
  322. }
  323. static int meson_pinconf_group_set(struct pinctrl_dev *pcdev,
  324. unsigned int num_group,
  325. unsigned long *configs, unsigned num_configs)
  326. {
  327. struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev);
  328. struct meson_pmx_group *group = &pc->data->groups[num_group];
  329. int i;
  330. dev_dbg(pc->dev, "set pinconf for group %s\n", group->name);
  331. for (i = 0; i < group->num_pins; i++) {
  332. meson_pinconf_set(pcdev, group->pins[i], configs,
  333. num_configs);
  334. }
  335. return 0;
  336. }
  337. static int meson_pinconf_group_get(struct pinctrl_dev *pcdev,
  338. unsigned int group, unsigned long *config)
  339. {
  340. return -ENOSYS;
  341. }
  342. static const struct pinconf_ops meson_pinconf_ops = {
  343. .pin_config_get = meson_pinconf_get,
  344. .pin_config_set = meson_pinconf_set,
  345. .pin_config_group_get = meson_pinconf_group_get,
  346. .pin_config_group_set = meson_pinconf_group_set,
  347. .is_generic = true,
  348. };
  349. static int meson_gpio_request(struct gpio_chip *chip, unsigned gpio)
  350. {
  351. return pinctrl_request_gpio(chip->base + gpio);
  352. }
  353. static void meson_gpio_free(struct gpio_chip *chip, unsigned gpio)
  354. {
  355. struct meson_pinctrl *pc = gpiochip_get_data(chip);
  356. pinctrl_free_gpio(pc->data->pin_base + gpio);
  357. }
  358. static int meson_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
  359. {
  360. struct meson_pinctrl *pc = gpiochip_get_data(chip);
  361. unsigned int reg, bit, pin;
  362. struct meson_bank *bank;
  363. int ret;
  364. pin = pc->data->pin_base + gpio;
  365. ret = meson_get_bank(pc, pin, &bank);
  366. if (ret)
  367. return ret;
  368. meson_calc_reg_and_bit(bank, pin, REG_DIR, &reg, &bit);
  369. return regmap_update_bits(pc->reg_gpio, reg, BIT(bit), BIT(bit));
  370. }
  371. static int meson_gpio_direction_output(struct gpio_chip *chip, unsigned gpio,
  372. int value)
  373. {
  374. struct meson_pinctrl *pc = gpiochip_get_data(chip);
  375. unsigned int reg, bit, pin;
  376. struct meson_bank *bank;
  377. int ret;
  378. pin = pc->data->pin_base + gpio;
  379. ret = meson_get_bank(pc, pin, &bank);
  380. if (ret)
  381. return ret;
  382. meson_calc_reg_and_bit(bank, pin, REG_DIR, &reg, &bit);
  383. ret = regmap_update_bits(pc->reg_gpio, reg, BIT(bit), 0);
  384. if (ret)
  385. return ret;
  386. meson_calc_reg_and_bit(bank, pin, REG_OUT, &reg, &bit);
  387. return regmap_update_bits(pc->reg_gpio, reg, BIT(bit),
  388. value ? BIT(bit) : 0);
  389. }
  390. static void meson_gpio_set(struct gpio_chip *chip, unsigned gpio, int value)
  391. {
  392. struct meson_pinctrl *pc = gpiochip_get_data(chip);
  393. unsigned int reg, bit, pin;
  394. struct meson_bank *bank;
  395. int ret;
  396. pin = pc->data->pin_base + gpio;
  397. ret = meson_get_bank(pc, pin, &bank);
  398. if (ret)
  399. return;
  400. meson_calc_reg_and_bit(bank, pin, REG_OUT, &reg, &bit);
  401. regmap_update_bits(pc->reg_gpio, reg, BIT(bit),
  402. value ? BIT(bit) : 0);
  403. }
  404. static int meson_gpio_get(struct gpio_chip *chip, unsigned gpio)
  405. {
  406. struct meson_pinctrl *pc = gpiochip_get_data(chip);
  407. unsigned int reg, bit, val, pin;
  408. struct meson_bank *bank;
  409. int ret;
  410. pin = pc->data->pin_base + gpio;
  411. ret = meson_get_bank(pc, pin, &bank);
  412. if (ret)
  413. return ret;
  414. meson_calc_reg_and_bit(bank, pin, REG_IN, &reg, &bit);
  415. regmap_read(pc->reg_gpio, reg, &val);
  416. return !!(val & BIT(bit));
  417. }
  418. static const struct of_device_id meson_pinctrl_dt_match[] = {
  419. {
  420. .compatible = "amlogic,meson8-cbus-pinctrl",
  421. .data = &meson8_cbus_pinctrl_data,
  422. },
  423. {
  424. .compatible = "amlogic,meson8b-cbus-pinctrl",
  425. .data = &meson8b_cbus_pinctrl_data,
  426. },
  427. {
  428. .compatible = "amlogic,meson8-aobus-pinctrl",
  429. .data = &meson8_aobus_pinctrl_data,
  430. },
  431. {
  432. .compatible = "amlogic,meson8b-aobus-pinctrl",
  433. .data = &meson8b_aobus_pinctrl_data,
  434. },
  435. {
  436. .compatible = "amlogic,meson-gxbb-periphs-pinctrl",
  437. .data = &meson_gxbb_periphs_pinctrl_data,
  438. },
  439. {
  440. .compatible = "amlogic,meson-gxbb-aobus-pinctrl",
  441. .data = &meson_gxbb_aobus_pinctrl_data,
  442. },
  443. {
  444. .compatible = "amlogic,meson-gxl-periphs-pinctrl",
  445. .data = &meson_gxl_periphs_pinctrl_data,
  446. },
  447. {
  448. .compatible = "amlogic,meson-gxl-aobus-pinctrl",
  449. .data = &meson_gxl_aobus_pinctrl_data,
  450. },
  451. { },
  452. };
  453. static int meson_gpiolib_register(struct meson_pinctrl *pc)
  454. {
  455. int ret;
  456. pc->chip.label = pc->data->name;
  457. pc->chip.parent = pc->dev;
  458. pc->chip.request = meson_gpio_request;
  459. pc->chip.free = meson_gpio_free;
  460. pc->chip.direction_input = meson_gpio_direction_input;
  461. pc->chip.direction_output = meson_gpio_direction_output;
  462. pc->chip.get = meson_gpio_get;
  463. pc->chip.set = meson_gpio_set;
  464. pc->chip.base = pc->data->pin_base;
  465. pc->chip.ngpio = pc->data->num_pins;
  466. pc->chip.can_sleep = false;
  467. pc->chip.of_node = pc->of_node;
  468. pc->chip.of_gpio_n_cells = 2;
  469. ret = gpiochip_add_data(&pc->chip, pc);
  470. if (ret) {
  471. dev_err(pc->dev, "can't add gpio chip %s\n",
  472. pc->data->name);
  473. return ret;
  474. }
  475. return 0;
  476. }
  477. static struct regmap_config meson_regmap_config = {
  478. .reg_bits = 32,
  479. .val_bits = 32,
  480. .reg_stride = 4,
  481. };
  482. static struct regmap *meson_map_resource(struct meson_pinctrl *pc,
  483. struct device_node *node, char *name)
  484. {
  485. struct resource res;
  486. void __iomem *base;
  487. int i;
  488. i = of_property_match_string(node, "reg-names", name);
  489. if (of_address_to_resource(node, i, &res))
  490. return ERR_PTR(-ENOENT);
  491. base = devm_ioremap_resource(pc->dev, &res);
  492. if (IS_ERR(base))
  493. return ERR_CAST(base);
  494. meson_regmap_config.max_register = resource_size(&res) - 4;
  495. meson_regmap_config.name = devm_kasprintf(pc->dev, GFP_KERNEL,
  496. "%s-%s", node->name,
  497. name);
  498. if (!meson_regmap_config.name)
  499. return ERR_PTR(-ENOMEM);
  500. return devm_regmap_init_mmio(pc->dev, base, &meson_regmap_config);
  501. }
  502. static int meson_pinctrl_parse_dt(struct meson_pinctrl *pc,
  503. struct device_node *node)
  504. {
  505. struct device_node *np, *gpio_np = NULL;
  506. for_each_child_of_node(node, np) {
  507. if (!of_find_property(np, "gpio-controller", NULL))
  508. continue;
  509. if (gpio_np) {
  510. dev_err(pc->dev, "multiple gpio nodes\n");
  511. return -EINVAL;
  512. }
  513. gpio_np = np;
  514. }
  515. if (!gpio_np) {
  516. dev_err(pc->dev, "no gpio node found\n");
  517. return -EINVAL;
  518. }
  519. pc->of_node = gpio_np;
  520. pc->reg_mux = meson_map_resource(pc, gpio_np, "mux");
  521. if (IS_ERR(pc->reg_mux)) {
  522. dev_err(pc->dev, "mux registers not found\n");
  523. return PTR_ERR(pc->reg_mux);
  524. }
  525. pc->reg_pull = meson_map_resource(pc, gpio_np, "pull");
  526. if (IS_ERR(pc->reg_pull)) {
  527. dev_err(pc->dev, "pull registers not found\n");
  528. return PTR_ERR(pc->reg_pull);
  529. }
  530. pc->reg_pullen = meson_map_resource(pc, gpio_np, "pull-enable");
  531. /* Use pull region if pull-enable one is not present */
  532. if (IS_ERR(pc->reg_pullen))
  533. pc->reg_pullen = pc->reg_pull;
  534. pc->reg_gpio = meson_map_resource(pc, gpio_np, "gpio");
  535. if (IS_ERR(pc->reg_gpio)) {
  536. dev_err(pc->dev, "gpio registers not found\n");
  537. return PTR_ERR(pc->reg_gpio);
  538. }
  539. return 0;
  540. }
  541. static int meson_pinctrl_probe(struct platform_device *pdev)
  542. {
  543. const struct of_device_id *match;
  544. struct device *dev = &pdev->dev;
  545. struct meson_pinctrl *pc;
  546. int ret;
  547. pc = devm_kzalloc(dev, sizeof(struct meson_pinctrl), GFP_KERNEL);
  548. if (!pc)
  549. return -ENOMEM;
  550. pc->dev = dev;
  551. match = of_match_node(meson_pinctrl_dt_match, pdev->dev.of_node);
  552. pc->data = (struct meson_pinctrl_data *) match->data;
  553. ret = meson_pinctrl_parse_dt(pc, pdev->dev.of_node);
  554. if (ret)
  555. return ret;
  556. pc->desc.name = "pinctrl-meson";
  557. pc->desc.owner = THIS_MODULE;
  558. pc->desc.pctlops = &meson_pctrl_ops;
  559. pc->desc.pmxops = &meson_pmx_ops;
  560. pc->desc.confops = &meson_pinconf_ops;
  561. pc->desc.pins = pc->data->pins;
  562. pc->desc.npins = pc->data->num_pins;
  563. pc->pcdev = devm_pinctrl_register(pc->dev, &pc->desc, pc);
  564. if (IS_ERR(pc->pcdev)) {
  565. dev_err(pc->dev, "can't register pinctrl device");
  566. return PTR_ERR(pc->pcdev);
  567. }
  568. return meson_gpiolib_register(pc);
  569. }
  570. static struct platform_driver meson_pinctrl_driver = {
  571. .probe = meson_pinctrl_probe,
  572. .driver = {
  573. .name = "meson-pinctrl",
  574. .of_match_table = meson_pinctrl_dt_match,
  575. },
  576. };
  577. builtin_platform_driver(meson_pinctrl_driver);