pinctrl-meson.c 18 KB

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