16ac73095SBeniamino Galvani /* 26ac73095SBeniamino Galvani * Pin controller and GPIO driver for Amlogic Meson SoCs 36ac73095SBeniamino Galvani * 46ac73095SBeniamino Galvani * Copyright (C) 2014 Beniamino Galvani <b.galvani@gmail.com> 56ac73095SBeniamino Galvani * 66ac73095SBeniamino Galvani * This program is free software; you can redistribute it and/or 76ac73095SBeniamino Galvani * modify it under the terms of the GNU General Public License 86ac73095SBeniamino Galvani * version 2 as published by the Free Software Foundation. 96ac73095SBeniamino Galvani * 106ac73095SBeniamino Galvani * You should have received a copy of the GNU General Public License 116ac73095SBeniamino Galvani * along with this program. If not, see <http://www.gnu.org/licenses/>. 126ac73095SBeniamino Galvani */ 136ac73095SBeniamino Galvani 146ac73095SBeniamino Galvani /* 156ac73095SBeniamino Galvani * The available pins are organized in banks (A,B,C,D,E,X,Y,Z,AO, 16*faa246deSCarlo Caione * BOOT,CARD for meson6, X,Y,DV,H,Z,AO,BOOT,CARD for meson8 and 17*faa246deSCarlo Caione * X,Y,DV,H,AO,BOOT,CARD,DIF for meson8b) and each bank has a 18*faa246deSCarlo Caione * variable number of pins. 196ac73095SBeniamino Galvani * 206ac73095SBeniamino Galvani * The AO bank is special because it belongs to the Always-On power 216ac73095SBeniamino Galvani * domain which can't be powered off; the bank also uses a set of 226ac73095SBeniamino Galvani * registers different from the other banks. 236ac73095SBeniamino Galvani * 246ac73095SBeniamino Galvani * For each of the two power domains (regular and always-on) there are 256ac73095SBeniamino Galvani * 4 different register ranges that control the following properties 266ac73095SBeniamino Galvani * of the pins: 276ac73095SBeniamino Galvani * 1) pin muxing 286ac73095SBeniamino Galvani * 2) pull enable/disable 296ac73095SBeniamino Galvani * 3) pull up/down 306ac73095SBeniamino Galvani * 4) GPIO direction, output value, input value 316ac73095SBeniamino Galvani * 326ac73095SBeniamino Galvani * In some cases the register ranges for pull enable and pull 336ac73095SBeniamino Galvani * direction are the same and thus there are only 3 register ranges. 346ac73095SBeniamino Galvani * 356ac73095SBeniamino Galvani * Every pinmux group can be enabled by a specific bit in the first 366ac73095SBeniamino Galvani * register range of the domain; when all groups for a given pin are 376ac73095SBeniamino Galvani * disabled the pin acts as a GPIO. 386ac73095SBeniamino Galvani * 396ac73095SBeniamino Galvani * For the pull and GPIO configuration every bank uses a contiguous 406ac73095SBeniamino Galvani * set of bits in the register sets described above; the same register 416ac73095SBeniamino Galvani * can be shared by more banks with different offsets. 426ac73095SBeniamino Galvani * 436ac73095SBeniamino Galvani * In addition to this there are some registers shared between all 446ac73095SBeniamino Galvani * banks that control the IRQ functionality. This feature is not 456ac73095SBeniamino Galvani * supported at the moment by the driver. 466ac73095SBeniamino Galvani */ 476ac73095SBeniamino Galvani 486ac73095SBeniamino Galvani #include <linux/device.h> 496ac73095SBeniamino Galvani #include <linux/gpio.h> 506ac73095SBeniamino Galvani #include <linux/init.h> 516ac73095SBeniamino Galvani #include <linux/io.h> 526ac73095SBeniamino Galvani #include <linux/module.h> 536ac73095SBeniamino Galvani #include <linux/of.h> 546ac73095SBeniamino Galvani #include <linux/of_address.h> 556ac73095SBeniamino Galvani #include <linux/pinctrl/pinconf-generic.h> 566ac73095SBeniamino Galvani #include <linux/pinctrl/pinconf.h> 576ac73095SBeniamino Galvani #include <linux/pinctrl/pinctrl.h> 586ac73095SBeniamino Galvani #include <linux/pinctrl/pinmux.h> 596ac73095SBeniamino Galvani #include <linux/platform_device.h> 606ac73095SBeniamino Galvani #include <linux/regmap.h> 616ac73095SBeniamino Galvani #include <linux/seq_file.h> 626ac73095SBeniamino Galvani 636ac73095SBeniamino Galvani #include "../core.h" 646ac73095SBeniamino Galvani #include "../pinctrl-utils.h" 656ac73095SBeniamino Galvani #include "pinctrl-meson.h" 666ac73095SBeniamino Galvani 676ac73095SBeniamino Galvani /** 686ac73095SBeniamino Galvani * meson_get_bank() - find the bank containing a given pin 696ac73095SBeniamino Galvani * 706ac73095SBeniamino Galvani * @domain: the domain containing the pin 716ac73095SBeniamino Galvani * @pin: the pin number 726ac73095SBeniamino Galvani * @bank: the found bank 736ac73095SBeniamino Galvani * 746ac73095SBeniamino Galvani * Return: 0 on success, a negative value on error 756ac73095SBeniamino Galvani */ 766ac73095SBeniamino Galvani static int meson_get_bank(struct meson_domain *domain, unsigned int pin, 776ac73095SBeniamino Galvani struct meson_bank **bank) 786ac73095SBeniamino Galvani { 796ac73095SBeniamino Galvani int i; 806ac73095SBeniamino Galvani 816ac73095SBeniamino Galvani for (i = 0; i < domain->data->num_banks; i++) { 826ac73095SBeniamino Galvani if (pin >= domain->data->banks[i].first && 836ac73095SBeniamino Galvani pin <= domain->data->banks[i].last) { 846ac73095SBeniamino Galvani *bank = &domain->data->banks[i]; 856ac73095SBeniamino Galvani return 0; 866ac73095SBeniamino Galvani } 876ac73095SBeniamino Galvani } 886ac73095SBeniamino Galvani 896ac73095SBeniamino Galvani return -EINVAL; 906ac73095SBeniamino Galvani } 916ac73095SBeniamino Galvani 926ac73095SBeniamino Galvani /** 936ac73095SBeniamino Galvani * meson_get_domain_and_bank() - find domain and bank containing a given pin 946ac73095SBeniamino Galvani * 956ac73095SBeniamino Galvani * @pc: Meson pin controller device 966ac73095SBeniamino Galvani * @pin: the pin number 976ac73095SBeniamino Galvani * @domain: the found domain 986ac73095SBeniamino Galvani * @bank: the found bank 996ac73095SBeniamino Galvani * 1006ac73095SBeniamino Galvani * Return: 0 on success, a negative value on error 1016ac73095SBeniamino Galvani */ 1026ac73095SBeniamino Galvani static int meson_get_domain_and_bank(struct meson_pinctrl *pc, unsigned int pin, 1036ac73095SBeniamino Galvani struct meson_domain **domain, 1046ac73095SBeniamino Galvani struct meson_bank **bank) 1056ac73095SBeniamino Galvani { 1066ac73095SBeniamino Galvani struct meson_domain *d; 1076ac73095SBeniamino Galvani int i; 1086ac73095SBeniamino Galvani 1096ac73095SBeniamino Galvani for (i = 0; i < pc->data->num_domains; i++) { 1106ac73095SBeniamino Galvani d = &pc->domains[i]; 1116ac73095SBeniamino Galvani if (pin >= d->data->pin_base && 1126ac73095SBeniamino Galvani pin < d->data->pin_base + d->data->num_pins) { 1136ac73095SBeniamino Galvani *domain = d; 1146ac73095SBeniamino Galvani return meson_get_bank(d, pin, bank); 1156ac73095SBeniamino Galvani } 1166ac73095SBeniamino Galvani } 1176ac73095SBeniamino Galvani 1186ac73095SBeniamino Galvani return -EINVAL; 1196ac73095SBeniamino Galvani } 1206ac73095SBeniamino Galvani 1216ac73095SBeniamino Galvani /** 1226ac73095SBeniamino Galvani * meson_calc_reg_and_bit() - calculate register and bit for a pin 1236ac73095SBeniamino Galvani * 1246ac73095SBeniamino Galvani * @bank: the bank containing the pin 1256ac73095SBeniamino Galvani * @pin: the pin number 1266ac73095SBeniamino Galvani * @reg_type: the type of register needed (pull-enable, pull, etc...) 1276ac73095SBeniamino Galvani * @reg: the computed register offset 1286ac73095SBeniamino Galvani * @bit: the computed bit 1296ac73095SBeniamino Galvani */ 1306ac73095SBeniamino Galvani static void meson_calc_reg_and_bit(struct meson_bank *bank, unsigned int pin, 1316ac73095SBeniamino Galvani enum meson_reg_type reg_type, 1326ac73095SBeniamino Galvani unsigned int *reg, unsigned int *bit) 1336ac73095SBeniamino Galvani { 1346ac73095SBeniamino Galvani struct meson_reg_desc *desc = &bank->regs[reg_type]; 1356ac73095SBeniamino Galvani 1366ac73095SBeniamino Galvani *reg = desc->reg * 4; 1376ac73095SBeniamino Galvani *bit = desc->bit + pin - bank->first; 1386ac73095SBeniamino Galvani } 1396ac73095SBeniamino Galvani 1406ac73095SBeniamino Galvani static int meson_get_groups_count(struct pinctrl_dev *pcdev) 1416ac73095SBeniamino Galvani { 1426ac73095SBeniamino Galvani struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); 1436ac73095SBeniamino Galvani 1446ac73095SBeniamino Galvani return pc->data->num_groups; 1456ac73095SBeniamino Galvani } 1466ac73095SBeniamino Galvani 1476ac73095SBeniamino Galvani static const char *meson_get_group_name(struct pinctrl_dev *pcdev, 1486ac73095SBeniamino Galvani unsigned selector) 1496ac73095SBeniamino Galvani { 1506ac73095SBeniamino Galvani struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); 1516ac73095SBeniamino Galvani 1526ac73095SBeniamino Galvani return pc->data->groups[selector].name; 1536ac73095SBeniamino Galvani } 1546ac73095SBeniamino Galvani 1556ac73095SBeniamino Galvani static int meson_get_group_pins(struct pinctrl_dev *pcdev, unsigned selector, 1566ac73095SBeniamino Galvani const unsigned **pins, unsigned *num_pins) 1576ac73095SBeniamino Galvani { 1586ac73095SBeniamino Galvani struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); 1596ac73095SBeniamino Galvani 1606ac73095SBeniamino Galvani *pins = pc->data->groups[selector].pins; 1616ac73095SBeniamino Galvani *num_pins = pc->data->groups[selector].num_pins; 1626ac73095SBeniamino Galvani 1636ac73095SBeniamino Galvani return 0; 1646ac73095SBeniamino Galvani } 1656ac73095SBeniamino Galvani 1666ac73095SBeniamino Galvani static void meson_pin_dbg_show(struct pinctrl_dev *pcdev, struct seq_file *s, 1676ac73095SBeniamino Galvani unsigned offset) 1686ac73095SBeniamino Galvani { 1696ac73095SBeniamino Galvani seq_printf(s, " %s", dev_name(pcdev->dev)); 1706ac73095SBeniamino Galvani } 1716ac73095SBeniamino Galvani 1726ac73095SBeniamino Galvani static const struct pinctrl_ops meson_pctrl_ops = { 1736ac73095SBeniamino Galvani .get_groups_count = meson_get_groups_count, 1746ac73095SBeniamino Galvani .get_group_name = meson_get_group_name, 1756ac73095SBeniamino Galvani .get_group_pins = meson_get_group_pins, 1766ac73095SBeniamino Galvani .dt_node_to_map = pinconf_generic_dt_node_to_map_all, 1776ac73095SBeniamino Galvani .dt_free_map = pinctrl_utils_dt_free_map, 1786ac73095SBeniamino Galvani .pin_dbg_show = meson_pin_dbg_show, 1796ac73095SBeniamino Galvani }; 1806ac73095SBeniamino Galvani 1816ac73095SBeniamino Galvani /** 1826ac73095SBeniamino Galvani * meson_pmx_disable_other_groups() - disable other groups using a given pin 1836ac73095SBeniamino Galvani * 1846ac73095SBeniamino Galvani * @pc: meson pin controller device 1856ac73095SBeniamino Galvani * @pin: number of the pin 1866ac73095SBeniamino Galvani * @sel_group: index of the selected group, or -1 if none 1876ac73095SBeniamino Galvani * 1886ac73095SBeniamino Galvani * The function disables all pinmux groups using a pin except the 1896ac73095SBeniamino Galvani * selected one. If @sel_group is -1 all groups are disabled, leaving 1906ac73095SBeniamino Galvani * the pin in GPIO mode. 1916ac73095SBeniamino Galvani */ 1926ac73095SBeniamino Galvani static void meson_pmx_disable_other_groups(struct meson_pinctrl *pc, 1936ac73095SBeniamino Galvani unsigned int pin, int sel_group) 1946ac73095SBeniamino Galvani { 1956ac73095SBeniamino Galvani struct meson_pmx_group *group; 1966ac73095SBeniamino Galvani struct meson_domain *domain; 1976ac73095SBeniamino Galvani int i, j; 1986ac73095SBeniamino Galvani 1996ac73095SBeniamino Galvani for (i = 0; i < pc->data->num_groups; i++) { 2006ac73095SBeniamino Galvani group = &pc->data->groups[i]; 2016ac73095SBeniamino Galvani if (group->is_gpio || i == sel_group) 2026ac73095SBeniamino Galvani continue; 2036ac73095SBeniamino Galvani 2046ac73095SBeniamino Galvani for (j = 0; j < group->num_pins; j++) { 2056ac73095SBeniamino Galvani if (group->pins[j] == pin) { 2066ac73095SBeniamino Galvani /* We have found a group using the pin */ 2076ac73095SBeniamino Galvani domain = &pc->domains[group->domain]; 2086ac73095SBeniamino Galvani regmap_update_bits(domain->reg_mux, 2096ac73095SBeniamino Galvani group->reg * 4, 2106ac73095SBeniamino Galvani BIT(group->bit), 0); 2116ac73095SBeniamino Galvani } 2126ac73095SBeniamino Galvani } 2136ac73095SBeniamino Galvani } 2146ac73095SBeniamino Galvani } 2156ac73095SBeniamino Galvani 2166ac73095SBeniamino Galvani static int meson_pmx_set_mux(struct pinctrl_dev *pcdev, unsigned func_num, 2176ac73095SBeniamino Galvani unsigned group_num) 2186ac73095SBeniamino Galvani { 2196ac73095SBeniamino Galvani struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); 2206ac73095SBeniamino Galvani struct meson_pmx_func *func = &pc->data->funcs[func_num]; 2216ac73095SBeniamino Galvani struct meson_pmx_group *group = &pc->data->groups[group_num]; 2226ac73095SBeniamino Galvani struct meson_domain *domain = &pc->domains[group->domain]; 2236ac73095SBeniamino Galvani int i, ret = 0; 2246ac73095SBeniamino Galvani 2256ac73095SBeniamino Galvani dev_dbg(pc->dev, "enable function %s, group %s\n", func->name, 2266ac73095SBeniamino Galvani group->name); 2276ac73095SBeniamino Galvani 2286ac73095SBeniamino Galvani /* 2296ac73095SBeniamino Galvani * Disable groups using the same pin. 2306ac73095SBeniamino Galvani * The selected group is not disabled to avoid glitches. 2316ac73095SBeniamino Galvani */ 2326ac73095SBeniamino Galvani for (i = 0; i < group->num_pins; i++) 2336ac73095SBeniamino Galvani meson_pmx_disable_other_groups(pc, group->pins[i], group_num); 2346ac73095SBeniamino Galvani 2356ac73095SBeniamino Galvani /* Function 0 (GPIO) doesn't need any additional setting */ 2366ac73095SBeniamino Galvani if (func_num) 2376ac73095SBeniamino Galvani ret = regmap_update_bits(domain->reg_mux, group->reg * 4, 2386ac73095SBeniamino Galvani BIT(group->bit), BIT(group->bit)); 2396ac73095SBeniamino Galvani 2406ac73095SBeniamino Galvani return ret; 2416ac73095SBeniamino Galvani } 2426ac73095SBeniamino Galvani 2436ac73095SBeniamino Galvani static int meson_pmx_request_gpio(struct pinctrl_dev *pcdev, 2446ac73095SBeniamino Galvani struct pinctrl_gpio_range *range, 2456ac73095SBeniamino Galvani unsigned offset) 2466ac73095SBeniamino Galvani { 2476ac73095SBeniamino Galvani struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); 2486ac73095SBeniamino Galvani 2496ac73095SBeniamino Galvani meson_pmx_disable_other_groups(pc, range->pin_base + offset, -1); 2506ac73095SBeniamino Galvani 2516ac73095SBeniamino Galvani return 0; 2526ac73095SBeniamino Galvani } 2536ac73095SBeniamino Galvani 2546ac73095SBeniamino Galvani static int meson_pmx_get_funcs_count(struct pinctrl_dev *pcdev) 2556ac73095SBeniamino Galvani { 2566ac73095SBeniamino Galvani struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); 2576ac73095SBeniamino Galvani 2586ac73095SBeniamino Galvani return pc->data->num_funcs; 2596ac73095SBeniamino Galvani } 2606ac73095SBeniamino Galvani 2616ac73095SBeniamino Galvani static const char *meson_pmx_get_func_name(struct pinctrl_dev *pcdev, 2626ac73095SBeniamino Galvani unsigned selector) 2636ac73095SBeniamino Galvani { 2646ac73095SBeniamino Galvani struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); 2656ac73095SBeniamino Galvani 2666ac73095SBeniamino Galvani return pc->data->funcs[selector].name; 2676ac73095SBeniamino Galvani } 2686ac73095SBeniamino Galvani 2696ac73095SBeniamino Galvani static int meson_pmx_get_groups(struct pinctrl_dev *pcdev, unsigned selector, 2706ac73095SBeniamino Galvani const char * const **groups, 2716ac73095SBeniamino Galvani unsigned * const num_groups) 2726ac73095SBeniamino Galvani { 2736ac73095SBeniamino Galvani struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); 2746ac73095SBeniamino Galvani 2756ac73095SBeniamino Galvani *groups = pc->data->funcs[selector].groups; 2766ac73095SBeniamino Galvani *num_groups = pc->data->funcs[selector].num_groups; 2776ac73095SBeniamino Galvani 2786ac73095SBeniamino Galvani return 0; 2796ac73095SBeniamino Galvani } 2806ac73095SBeniamino Galvani 2816ac73095SBeniamino Galvani static const struct pinmux_ops meson_pmx_ops = { 2826ac73095SBeniamino Galvani .set_mux = meson_pmx_set_mux, 2836ac73095SBeniamino Galvani .get_functions_count = meson_pmx_get_funcs_count, 2846ac73095SBeniamino Galvani .get_function_name = meson_pmx_get_func_name, 2856ac73095SBeniamino Galvani .get_function_groups = meson_pmx_get_groups, 2866ac73095SBeniamino Galvani .gpio_request_enable = meson_pmx_request_gpio, 2876ac73095SBeniamino Galvani }; 2886ac73095SBeniamino Galvani 2896ac73095SBeniamino Galvani static int meson_pinconf_set(struct pinctrl_dev *pcdev, unsigned int pin, 2906ac73095SBeniamino Galvani unsigned long *configs, unsigned num_configs) 2916ac73095SBeniamino Galvani { 2926ac73095SBeniamino Galvani struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); 2936ac73095SBeniamino Galvani struct meson_domain *domain; 2946ac73095SBeniamino Galvani struct meson_bank *bank; 2956ac73095SBeniamino Galvani enum pin_config_param param; 2966ac73095SBeniamino Galvani unsigned int reg, bit; 2976ac73095SBeniamino Galvani int i, ret; 2986ac73095SBeniamino Galvani u16 arg; 2996ac73095SBeniamino Galvani 3006ac73095SBeniamino Galvani ret = meson_get_domain_and_bank(pc, pin, &domain, &bank); 3016ac73095SBeniamino Galvani if (ret) 3026ac73095SBeniamino Galvani return ret; 3036ac73095SBeniamino Galvani 3046ac73095SBeniamino Galvani for (i = 0; i < num_configs; i++) { 3056ac73095SBeniamino Galvani param = pinconf_to_config_param(configs[i]); 3066ac73095SBeniamino Galvani arg = pinconf_to_config_argument(configs[i]); 3076ac73095SBeniamino Galvani 3086ac73095SBeniamino Galvani switch (param) { 3096ac73095SBeniamino Galvani case PIN_CONFIG_BIAS_DISABLE: 3106ac73095SBeniamino Galvani dev_dbg(pc->dev, "pin %u: disable bias\n", pin); 3116ac73095SBeniamino Galvani 3126ac73095SBeniamino Galvani meson_calc_reg_and_bit(bank, pin, REG_PULL, ®, &bit); 3136ac73095SBeniamino Galvani ret = regmap_update_bits(domain->reg_pull, reg, 3146ac73095SBeniamino Galvani BIT(bit), 0); 3156ac73095SBeniamino Galvani if (ret) 3166ac73095SBeniamino Galvani return ret; 3176ac73095SBeniamino Galvani break; 3186ac73095SBeniamino Galvani case PIN_CONFIG_BIAS_PULL_UP: 3196ac73095SBeniamino Galvani dev_dbg(pc->dev, "pin %u: enable pull-up\n", pin); 3206ac73095SBeniamino Galvani 3216ac73095SBeniamino Galvani meson_calc_reg_and_bit(bank, pin, REG_PULLEN, 3226ac73095SBeniamino Galvani ®, &bit); 3236ac73095SBeniamino Galvani ret = regmap_update_bits(domain->reg_pullen, reg, 3246ac73095SBeniamino Galvani BIT(bit), BIT(bit)); 3256ac73095SBeniamino Galvani if (ret) 3266ac73095SBeniamino Galvani return ret; 3276ac73095SBeniamino Galvani 3286ac73095SBeniamino Galvani meson_calc_reg_and_bit(bank, pin, REG_PULL, ®, &bit); 3296ac73095SBeniamino Galvani ret = regmap_update_bits(domain->reg_pull, reg, 3306ac73095SBeniamino Galvani BIT(bit), BIT(bit)); 3316ac73095SBeniamino Galvani if (ret) 3326ac73095SBeniamino Galvani return ret; 3336ac73095SBeniamino Galvani break; 3346ac73095SBeniamino Galvani case PIN_CONFIG_BIAS_PULL_DOWN: 3356ac73095SBeniamino Galvani dev_dbg(pc->dev, "pin %u: enable pull-down\n", pin); 3366ac73095SBeniamino Galvani 3376ac73095SBeniamino Galvani meson_calc_reg_and_bit(bank, pin, REG_PULLEN, 3386ac73095SBeniamino Galvani ®, &bit); 3396ac73095SBeniamino Galvani ret = regmap_update_bits(domain->reg_pullen, reg, 3406ac73095SBeniamino Galvani BIT(bit), BIT(bit)); 3416ac73095SBeniamino Galvani if (ret) 3426ac73095SBeniamino Galvani return ret; 3436ac73095SBeniamino Galvani 3446ac73095SBeniamino Galvani meson_calc_reg_and_bit(bank, pin, REG_PULL, ®, &bit); 3456ac73095SBeniamino Galvani ret = regmap_update_bits(domain->reg_pull, reg, 3466ac73095SBeniamino Galvani BIT(bit), 0); 3476ac73095SBeniamino Galvani if (ret) 3486ac73095SBeniamino Galvani return ret; 3496ac73095SBeniamino Galvani break; 3506ac73095SBeniamino Galvani default: 3516ac73095SBeniamino Galvani return -ENOTSUPP; 3526ac73095SBeniamino Galvani } 3536ac73095SBeniamino Galvani } 3546ac73095SBeniamino Galvani 3556ac73095SBeniamino Galvani return 0; 3566ac73095SBeniamino Galvani } 3576ac73095SBeniamino Galvani 3586ac73095SBeniamino Galvani static int meson_pinconf_get_pull(struct meson_pinctrl *pc, unsigned int pin) 3596ac73095SBeniamino Galvani { 3606ac73095SBeniamino Galvani struct meson_domain *domain; 3616ac73095SBeniamino Galvani struct meson_bank *bank; 3626ac73095SBeniamino Galvani unsigned int reg, bit, val; 3636ac73095SBeniamino Galvani int ret, conf; 3646ac73095SBeniamino Galvani 3656ac73095SBeniamino Galvani ret = meson_get_domain_and_bank(pc, pin, &domain, &bank); 3666ac73095SBeniamino Galvani if (ret) 3676ac73095SBeniamino Galvani return ret; 3686ac73095SBeniamino Galvani 3696ac73095SBeniamino Galvani meson_calc_reg_and_bit(bank, pin, REG_PULLEN, ®, &bit); 3706ac73095SBeniamino Galvani 3716ac73095SBeniamino Galvani ret = regmap_read(domain->reg_pullen, reg, &val); 3726ac73095SBeniamino Galvani if (ret) 3736ac73095SBeniamino Galvani return ret; 3746ac73095SBeniamino Galvani 3756ac73095SBeniamino Galvani if (!(val & BIT(bit))) { 3766ac73095SBeniamino Galvani conf = PIN_CONFIG_BIAS_DISABLE; 3776ac73095SBeniamino Galvani } else { 3786ac73095SBeniamino Galvani meson_calc_reg_and_bit(bank, pin, REG_PULL, ®, &bit); 3796ac73095SBeniamino Galvani 3806ac73095SBeniamino Galvani ret = regmap_read(domain->reg_pull, reg, &val); 3816ac73095SBeniamino Galvani if (ret) 3826ac73095SBeniamino Galvani return ret; 3836ac73095SBeniamino Galvani 3846ac73095SBeniamino Galvani if (val & BIT(bit)) 3856ac73095SBeniamino Galvani conf = PIN_CONFIG_BIAS_PULL_UP; 3866ac73095SBeniamino Galvani else 3876ac73095SBeniamino Galvani conf = PIN_CONFIG_BIAS_PULL_DOWN; 3886ac73095SBeniamino Galvani } 3896ac73095SBeniamino Galvani 3906ac73095SBeniamino Galvani return conf; 3916ac73095SBeniamino Galvani } 3926ac73095SBeniamino Galvani 3936ac73095SBeniamino Galvani static int meson_pinconf_get(struct pinctrl_dev *pcdev, unsigned int pin, 3946ac73095SBeniamino Galvani unsigned long *config) 3956ac73095SBeniamino Galvani { 3966ac73095SBeniamino Galvani struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); 3976ac73095SBeniamino Galvani enum pin_config_param param = pinconf_to_config_param(*config); 3986ac73095SBeniamino Galvani u16 arg; 3996ac73095SBeniamino Galvani 4006ac73095SBeniamino Galvani switch (param) { 4016ac73095SBeniamino Galvani case PIN_CONFIG_BIAS_DISABLE: 4026ac73095SBeniamino Galvani case PIN_CONFIG_BIAS_PULL_DOWN: 4036ac73095SBeniamino Galvani case PIN_CONFIG_BIAS_PULL_UP: 4046ac73095SBeniamino Galvani if (meson_pinconf_get_pull(pc, pin) == param) 4056ac73095SBeniamino Galvani arg = 1; 4066ac73095SBeniamino Galvani else 4076ac73095SBeniamino Galvani return -EINVAL; 4086ac73095SBeniamino Galvani break; 4096ac73095SBeniamino Galvani default: 4106ac73095SBeniamino Galvani return -ENOTSUPP; 4116ac73095SBeniamino Galvani } 4126ac73095SBeniamino Galvani 4136ac73095SBeniamino Galvani *config = pinconf_to_config_packed(param, arg); 4146ac73095SBeniamino Galvani dev_dbg(pc->dev, "pinconf for pin %u is %lu\n", pin, *config); 4156ac73095SBeniamino Galvani 4166ac73095SBeniamino Galvani return 0; 4176ac73095SBeniamino Galvani } 4186ac73095SBeniamino Galvani 4196ac73095SBeniamino Galvani static int meson_pinconf_group_set(struct pinctrl_dev *pcdev, 4206ac73095SBeniamino Galvani unsigned int num_group, 4216ac73095SBeniamino Galvani unsigned long *configs, unsigned num_configs) 4226ac73095SBeniamino Galvani { 4236ac73095SBeniamino Galvani struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); 4246ac73095SBeniamino Galvani struct meson_pmx_group *group = &pc->data->groups[num_group]; 4256ac73095SBeniamino Galvani int i; 4266ac73095SBeniamino Galvani 4276ac73095SBeniamino Galvani dev_dbg(pc->dev, "set pinconf for group %s\n", group->name); 4286ac73095SBeniamino Galvani 4296ac73095SBeniamino Galvani for (i = 0; i < group->num_pins; i++) { 4306ac73095SBeniamino Galvani meson_pinconf_set(pcdev, group->pins[i], configs, 4316ac73095SBeniamino Galvani num_configs); 4326ac73095SBeniamino Galvani } 4336ac73095SBeniamino Galvani 4346ac73095SBeniamino Galvani return 0; 4356ac73095SBeniamino Galvani } 4366ac73095SBeniamino Galvani 4376ac73095SBeniamino Galvani static int meson_pinconf_group_get(struct pinctrl_dev *pcdev, 4386ac73095SBeniamino Galvani unsigned int group, unsigned long *config) 4396ac73095SBeniamino Galvani { 4406ac73095SBeniamino Galvani return -ENOSYS; 4416ac73095SBeniamino Galvani } 4426ac73095SBeniamino Galvani 4436ac73095SBeniamino Galvani static const struct pinconf_ops meson_pinconf_ops = { 4446ac73095SBeniamino Galvani .pin_config_get = meson_pinconf_get, 4456ac73095SBeniamino Galvani .pin_config_set = meson_pinconf_set, 4466ac73095SBeniamino Galvani .pin_config_group_get = meson_pinconf_group_get, 4476ac73095SBeniamino Galvani .pin_config_group_set = meson_pinconf_group_set, 4486ac73095SBeniamino Galvani .is_generic = true, 4496ac73095SBeniamino Galvani }; 4506ac73095SBeniamino Galvani 4516ac73095SBeniamino Galvani static inline struct meson_domain *to_meson_domain(struct gpio_chip *chip) 4526ac73095SBeniamino Galvani { 4536ac73095SBeniamino Galvani return container_of(chip, struct meson_domain, chip); 4546ac73095SBeniamino Galvani } 4556ac73095SBeniamino Galvani 4566ac73095SBeniamino Galvani static int meson_gpio_request(struct gpio_chip *chip, unsigned gpio) 4576ac73095SBeniamino Galvani { 4586ac73095SBeniamino Galvani return pinctrl_request_gpio(chip->base + gpio); 4596ac73095SBeniamino Galvani } 4606ac73095SBeniamino Galvani 4616ac73095SBeniamino Galvani static void meson_gpio_free(struct gpio_chip *chip, unsigned gpio) 4626ac73095SBeniamino Galvani { 4636ac73095SBeniamino Galvani struct meson_domain *domain = to_meson_domain(chip); 4646ac73095SBeniamino Galvani 4656ac73095SBeniamino Galvani pinctrl_free_gpio(domain->data->pin_base + gpio); 4666ac73095SBeniamino Galvani } 4676ac73095SBeniamino Galvani 4686ac73095SBeniamino Galvani static int meson_gpio_direction_input(struct gpio_chip *chip, unsigned gpio) 4696ac73095SBeniamino Galvani { 4706ac73095SBeniamino Galvani struct meson_domain *domain = to_meson_domain(chip); 4716ac73095SBeniamino Galvani unsigned int reg, bit, pin; 4726ac73095SBeniamino Galvani struct meson_bank *bank; 4736ac73095SBeniamino Galvani int ret; 4746ac73095SBeniamino Galvani 4756ac73095SBeniamino Galvani pin = domain->data->pin_base + gpio; 4766ac73095SBeniamino Galvani ret = meson_get_bank(domain, pin, &bank); 4776ac73095SBeniamino Galvani if (ret) 4786ac73095SBeniamino Galvani return ret; 4796ac73095SBeniamino Galvani 4806ac73095SBeniamino Galvani meson_calc_reg_and_bit(bank, pin, REG_DIR, ®, &bit); 4816ac73095SBeniamino Galvani 4826ac73095SBeniamino Galvani return regmap_update_bits(domain->reg_gpio, reg, BIT(bit), BIT(bit)); 4836ac73095SBeniamino Galvani } 4846ac73095SBeniamino Galvani 4856ac73095SBeniamino Galvani static int meson_gpio_direction_output(struct gpio_chip *chip, unsigned gpio, 4866ac73095SBeniamino Galvani int value) 4876ac73095SBeniamino Galvani { 4886ac73095SBeniamino Galvani struct meson_domain *domain = to_meson_domain(chip); 4896ac73095SBeniamino Galvani unsigned int reg, bit, pin; 4906ac73095SBeniamino Galvani struct meson_bank *bank; 4916ac73095SBeniamino Galvani int ret; 4926ac73095SBeniamino Galvani 4936ac73095SBeniamino Galvani pin = domain->data->pin_base + gpio; 4946ac73095SBeniamino Galvani ret = meson_get_bank(domain, pin, &bank); 4956ac73095SBeniamino Galvani if (ret) 4966ac73095SBeniamino Galvani return ret; 4976ac73095SBeniamino Galvani 4986ac73095SBeniamino Galvani meson_calc_reg_and_bit(bank, pin, REG_DIR, ®, &bit); 4996ac73095SBeniamino Galvani ret = regmap_update_bits(domain->reg_gpio, reg, BIT(bit), 0); 5006ac73095SBeniamino Galvani if (ret) 5016ac73095SBeniamino Galvani return ret; 5026ac73095SBeniamino Galvani 5036ac73095SBeniamino Galvani meson_calc_reg_and_bit(bank, pin, REG_OUT, ®, &bit); 5046ac73095SBeniamino Galvani return regmap_update_bits(domain->reg_gpio, reg, BIT(bit), 5056ac73095SBeniamino Galvani value ? BIT(bit) : 0); 5066ac73095SBeniamino Galvani } 5076ac73095SBeniamino Galvani 5086ac73095SBeniamino Galvani static void meson_gpio_set(struct gpio_chip *chip, unsigned gpio, int value) 5096ac73095SBeniamino Galvani { 5106ac73095SBeniamino Galvani struct meson_domain *domain = to_meson_domain(chip); 5116ac73095SBeniamino Galvani unsigned int reg, bit, pin; 5126ac73095SBeniamino Galvani struct meson_bank *bank; 5136ac73095SBeniamino Galvani int ret; 5146ac73095SBeniamino Galvani 5156ac73095SBeniamino Galvani pin = domain->data->pin_base + gpio; 5166ac73095SBeniamino Galvani ret = meson_get_bank(domain, pin, &bank); 5176ac73095SBeniamino Galvani if (ret) 5186ac73095SBeniamino Galvani return; 5196ac73095SBeniamino Galvani 5206ac73095SBeniamino Galvani meson_calc_reg_and_bit(bank, pin, REG_OUT, ®, &bit); 5216ac73095SBeniamino Galvani regmap_update_bits(domain->reg_gpio, reg, BIT(bit), 5226ac73095SBeniamino Galvani value ? BIT(bit) : 0); 5236ac73095SBeniamino Galvani } 5246ac73095SBeniamino Galvani 5256ac73095SBeniamino Galvani static int meson_gpio_get(struct gpio_chip *chip, unsigned gpio) 5266ac73095SBeniamino Galvani { 5276ac73095SBeniamino Galvani struct meson_domain *domain = to_meson_domain(chip); 5286ac73095SBeniamino Galvani unsigned int reg, bit, val, pin; 5296ac73095SBeniamino Galvani struct meson_bank *bank; 5306ac73095SBeniamino Galvani int ret; 5316ac73095SBeniamino Galvani 5326ac73095SBeniamino Galvani pin = domain->data->pin_base + gpio; 5336ac73095SBeniamino Galvani ret = meson_get_bank(domain, pin, &bank); 5346ac73095SBeniamino Galvani if (ret) 5356ac73095SBeniamino Galvani return ret; 5366ac73095SBeniamino Galvani 5376ac73095SBeniamino Galvani meson_calc_reg_and_bit(bank, pin, REG_IN, ®, &bit); 5386ac73095SBeniamino Galvani regmap_read(domain->reg_gpio, reg, &val); 5396ac73095SBeniamino Galvani 5406ac73095SBeniamino Galvani return !!(val & BIT(bit)); 5416ac73095SBeniamino Galvani } 5426ac73095SBeniamino Galvani 5436ac73095SBeniamino Galvani static const struct of_device_id meson_pinctrl_dt_match[] = { 5446ac73095SBeniamino Galvani { 5456ac73095SBeniamino Galvani .compatible = "amlogic,meson8-pinctrl", 5466ac73095SBeniamino Galvani .data = &meson8_pinctrl_data, 5476ac73095SBeniamino Galvani }, 5486ac73095SBeniamino Galvani { }, 5496ac73095SBeniamino Galvani }; 5506ac73095SBeniamino Galvani MODULE_DEVICE_TABLE(of, meson_pinctrl_dt_match); 5516ac73095SBeniamino Galvani 5526ac73095SBeniamino Galvani static int meson_gpiolib_register(struct meson_pinctrl *pc) 5536ac73095SBeniamino Galvani { 5546ac73095SBeniamino Galvani struct meson_domain *domain; 5556ac73095SBeniamino Galvani int i, ret; 5566ac73095SBeniamino Galvani 5576ac73095SBeniamino Galvani for (i = 0; i < pc->data->num_domains; i++) { 5586ac73095SBeniamino Galvani domain = &pc->domains[i]; 5596ac73095SBeniamino Galvani 5606ac73095SBeniamino Galvani domain->chip.label = domain->data->name; 5616ac73095SBeniamino Galvani domain->chip.dev = pc->dev; 5626ac73095SBeniamino Galvani domain->chip.request = meson_gpio_request; 5636ac73095SBeniamino Galvani domain->chip.free = meson_gpio_free; 5646ac73095SBeniamino Galvani domain->chip.direction_input = meson_gpio_direction_input; 5656ac73095SBeniamino Galvani domain->chip.direction_output = meson_gpio_direction_output; 5666ac73095SBeniamino Galvani domain->chip.get = meson_gpio_get; 5676ac73095SBeniamino Galvani domain->chip.set = meson_gpio_set; 5686ac73095SBeniamino Galvani domain->chip.base = -1; 5696ac73095SBeniamino Galvani domain->chip.ngpio = domain->data->num_pins; 5706ac73095SBeniamino Galvani domain->chip.can_sleep = false; 5716ac73095SBeniamino Galvani domain->chip.of_node = domain->of_node; 5726ac73095SBeniamino Galvani domain->chip.of_gpio_n_cells = 2; 5736ac73095SBeniamino Galvani 5746ac73095SBeniamino Galvani ret = gpiochip_add(&domain->chip); 5756ac73095SBeniamino Galvani if (ret) { 5766ac73095SBeniamino Galvani dev_err(pc->dev, "can't add gpio chip %s\n", 5776ac73095SBeniamino Galvani domain->data->name); 5786ac73095SBeniamino Galvani goto fail; 5796ac73095SBeniamino Galvani } 5806ac73095SBeniamino Galvani 5816ac73095SBeniamino Galvani ret = gpiochip_add_pin_range(&domain->chip, dev_name(pc->dev), 5826ac73095SBeniamino Galvani 0, domain->data->pin_base, 5836ac73095SBeniamino Galvani domain->chip.ngpio); 5846ac73095SBeniamino Galvani if (ret) { 5856ac73095SBeniamino Galvani dev_err(pc->dev, "can't add pin range\n"); 5866ac73095SBeniamino Galvani goto fail; 5876ac73095SBeniamino Galvani } 5886ac73095SBeniamino Galvani } 5896ac73095SBeniamino Galvani 5906ac73095SBeniamino Galvani return 0; 5916ac73095SBeniamino Galvani fail: 5926ac73095SBeniamino Galvani for (i--; i >= 0; i--) 5936ac73095SBeniamino Galvani gpiochip_remove(&pc->domains[i].chip); 5946ac73095SBeniamino Galvani 5956ac73095SBeniamino Galvani return ret; 5966ac73095SBeniamino Galvani } 5976ac73095SBeniamino Galvani 5986ac73095SBeniamino Galvani static struct meson_domain_data *meson_get_domain_data(struct meson_pinctrl *pc, 5996ac73095SBeniamino Galvani struct device_node *np) 6006ac73095SBeniamino Galvani { 6016ac73095SBeniamino Galvani int i; 6026ac73095SBeniamino Galvani 6036ac73095SBeniamino Galvani for (i = 0; i < pc->data->num_domains; i++) { 6046ac73095SBeniamino Galvani if (!strcmp(np->name, pc->data->domain_data[i].name)) 6056ac73095SBeniamino Galvani return &pc->data->domain_data[i]; 6066ac73095SBeniamino Galvani } 6076ac73095SBeniamino Galvani 6086ac73095SBeniamino Galvani return NULL; 6096ac73095SBeniamino Galvani } 6106ac73095SBeniamino Galvani 6116ac73095SBeniamino Galvani static struct regmap_config meson_regmap_config = { 6126ac73095SBeniamino Galvani .reg_bits = 32, 6136ac73095SBeniamino Galvani .val_bits = 32, 6146ac73095SBeniamino Galvani .reg_stride = 4, 6156ac73095SBeniamino Galvani }; 6166ac73095SBeniamino Galvani 6176ac73095SBeniamino Galvani static struct regmap *meson_map_resource(struct meson_pinctrl *pc, 6186ac73095SBeniamino Galvani struct device_node *node, char *name) 6196ac73095SBeniamino Galvani { 6206ac73095SBeniamino Galvani struct resource res; 6216ac73095SBeniamino Galvani void __iomem *base; 6226ac73095SBeniamino Galvani int i; 6236ac73095SBeniamino Galvani 6246ac73095SBeniamino Galvani i = of_property_match_string(node, "reg-names", name); 6256ac73095SBeniamino Galvani if (of_address_to_resource(node, i, &res)) 6266ac73095SBeniamino Galvani return ERR_PTR(-ENOENT); 6276ac73095SBeniamino Galvani 6286ac73095SBeniamino Galvani base = devm_ioremap_resource(pc->dev, &res); 6296ac73095SBeniamino Galvani if (IS_ERR(base)) 6306ac73095SBeniamino Galvani return ERR_CAST(base); 6316ac73095SBeniamino Galvani 6326ac73095SBeniamino Galvani meson_regmap_config.max_register = resource_size(&res) - 4; 6336ac73095SBeniamino Galvani meson_regmap_config.name = devm_kasprintf(pc->dev, GFP_KERNEL, 6346ac73095SBeniamino Galvani "%s-%s", node->name, 6356ac73095SBeniamino Galvani name); 6366ac73095SBeniamino Galvani if (!meson_regmap_config.name) 6376ac73095SBeniamino Galvani return ERR_PTR(-ENOMEM); 6386ac73095SBeniamino Galvani 6396ac73095SBeniamino Galvani return devm_regmap_init_mmio(pc->dev, base, &meson_regmap_config); 6406ac73095SBeniamino Galvani } 6416ac73095SBeniamino Galvani 6426ac73095SBeniamino Galvani static int meson_pinctrl_parse_dt(struct meson_pinctrl *pc, 6436ac73095SBeniamino Galvani struct device_node *node) 6446ac73095SBeniamino Galvani { 6456ac73095SBeniamino Galvani struct device_node *np; 6466ac73095SBeniamino Galvani struct meson_domain *domain; 6476ac73095SBeniamino Galvani int i = 0, num_domains = 0; 6486ac73095SBeniamino Galvani 6496ac73095SBeniamino Galvani for_each_child_of_node(node, np) { 6506ac73095SBeniamino Galvani if (!of_find_property(np, "gpio-controller", NULL)) 6516ac73095SBeniamino Galvani continue; 6526ac73095SBeniamino Galvani num_domains++; 6536ac73095SBeniamino Galvani } 6546ac73095SBeniamino Galvani 6556ac73095SBeniamino Galvani if (num_domains != pc->data->num_domains) { 6566ac73095SBeniamino Galvani dev_err(pc->dev, "wrong number of subnodes\n"); 6576ac73095SBeniamino Galvani return -EINVAL; 6586ac73095SBeniamino Galvani } 6596ac73095SBeniamino Galvani 6606ac73095SBeniamino Galvani pc->domains = devm_kzalloc(pc->dev, num_domains * 6616ac73095SBeniamino Galvani sizeof(struct meson_domain), GFP_KERNEL); 6626ac73095SBeniamino Galvani if (!pc->domains) 6636ac73095SBeniamino Galvani return -ENOMEM; 6646ac73095SBeniamino Galvani 6656ac73095SBeniamino Galvani for_each_child_of_node(node, np) { 6666ac73095SBeniamino Galvani if (!of_find_property(np, "gpio-controller", NULL)) 6676ac73095SBeniamino Galvani continue; 6686ac73095SBeniamino Galvani 6696ac73095SBeniamino Galvani domain = &pc->domains[i]; 6706ac73095SBeniamino Galvani 6716ac73095SBeniamino Galvani domain->data = meson_get_domain_data(pc, np); 6726ac73095SBeniamino Galvani if (!domain->data) { 6736ac73095SBeniamino Galvani dev_err(pc->dev, "domain data not found for node %s\n", 6746ac73095SBeniamino Galvani np->name); 6756ac73095SBeniamino Galvani return -ENODEV; 6766ac73095SBeniamino Galvani } 6776ac73095SBeniamino Galvani 6786ac73095SBeniamino Galvani domain->of_node = np; 6796ac73095SBeniamino Galvani 6806ac73095SBeniamino Galvani domain->reg_mux = meson_map_resource(pc, np, "mux"); 6816ac73095SBeniamino Galvani if (IS_ERR(domain->reg_mux)) { 6826ac73095SBeniamino Galvani dev_err(pc->dev, "mux registers not found\n"); 6836ac73095SBeniamino Galvani return PTR_ERR(domain->reg_mux); 6846ac73095SBeniamino Galvani } 6856ac73095SBeniamino Galvani 6866ac73095SBeniamino Galvani domain->reg_pull = meson_map_resource(pc, np, "pull"); 6876ac73095SBeniamino Galvani if (IS_ERR(domain->reg_pull)) { 6886ac73095SBeniamino Galvani dev_err(pc->dev, "pull registers not found\n"); 6896ac73095SBeniamino Galvani return PTR_ERR(domain->reg_pull); 6906ac73095SBeniamino Galvani } 6916ac73095SBeniamino Galvani 6926ac73095SBeniamino Galvani domain->reg_pullen = meson_map_resource(pc, np, "pull-enable"); 6936ac73095SBeniamino Galvani /* Use pull region if pull-enable one is not present */ 6946ac73095SBeniamino Galvani if (IS_ERR(domain->reg_pullen)) 6956ac73095SBeniamino Galvani domain->reg_pullen = domain->reg_pull; 6966ac73095SBeniamino Galvani 6976ac73095SBeniamino Galvani domain->reg_gpio = meson_map_resource(pc, np, "gpio"); 6986ac73095SBeniamino Galvani if (IS_ERR(domain->reg_gpio)) { 6996ac73095SBeniamino Galvani dev_err(pc->dev, "gpio registers not found\n"); 7006ac73095SBeniamino Galvani return PTR_ERR(domain->reg_gpio); 7016ac73095SBeniamino Galvani } 7026ac73095SBeniamino Galvani 7036ac73095SBeniamino Galvani i++; 7046ac73095SBeniamino Galvani } 7056ac73095SBeniamino Galvani 7066ac73095SBeniamino Galvani return 0; 7076ac73095SBeniamino Galvani } 7086ac73095SBeniamino Galvani 7096ac73095SBeniamino Galvani static int meson_pinctrl_probe(struct platform_device *pdev) 7106ac73095SBeniamino Galvani { 7116ac73095SBeniamino Galvani const struct of_device_id *match; 7126ac73095SBeniamino Galvani struct device *dev = &pdev->dev; 7136ac73095SBeniamino Galvani struct meson_pinctrl *pc; 7146ac73095SBeniamino Galvani int ret; 7156ac73095SBeniamino Galvani 7166ac73095SBeniamino Galvani pc = devm_kzalloc(dev, sizeof(struct meson_pinctrl), GFP_KERNEL); 7176ac73095SBeniamino Galvani if (!pc) 7186ac73095SBeniamino Galvani return -ENOMEM; 7196ac73095SBeniamino Galvani 7206ac73095SBeniamino Galvani pc->dev = dev; 7216ac73095SBeniamino Galvani match = of_match_node(meson_pinctrl_dt_match, pdev->dev.of_node); 7226ac73095SBeniamino Galvani pc->data = (struct meson_pinctrl_data *)match->data; 7236ac73095SBeniamino Galvani 7246ac73095SBeniamino Galvani ret = meson_pinctrl_parse_dt(pc, pdev->dev.of_node); 7256ac73095SBeniamino Galvani if (ret) 7266ac73095SBeniamino Galvani return ret; 7276ac73095SBeniamino Galvani 7286ac73095SBeniamino Galvani pc->desc.name = "pinctrl-meson"; 7296ac73095SBeniamino Galvani pc->desc.owner = THIS_MODULE; 7306ac73095SBeniamino Galvani pc->desc.pctlops = &meson_pctrl_ops; 7316ac73095SBeniamino Galvani pc->desc.pmxops = &meson_pmx_ops; 7326ac73095SBeniamino Galvani pc->desc.confops = &meson_pinconf_ops; 7336ac73095SBeniamino Galvani pc->desc.pins = pc->data->pins; 7346ac73095SBeniamino Galvani pc->desc.npins = pc->data->num_pins; 7356ac73095SBeniamino Galvani 7366ac73095SBeniamino Galvani pc->pcdev = pinctrl_register(&pc->desc, pc->dev, pc); 7376ac73095SBeniamino Galvani if (!pc->pcdev) { 7386ac73095SBeniamino Galvani dev_err(pc->dev, "can't register pinctrl device"); 7396ac73095SBeniamino Galvani return -EINVAL; 7406ac73095SBeniamino Galvani } 7416ac73095SBeniamino Galvani 7426ac73095SBeniamino Galvani ret = meson_gpiolib_register(pc); 7436ac73095SBeniamino Galvani if (ret) { 7446ac73095SBeniamino Galvani pinctrl_unregister(pc->pcdev); 7456ac73095SBeniamino Galvani return ret; 7466ac73095SBeniamino Galvani } 7476ac73095SBeniamino Galvani 7486ac73095SBeniamino Galvani return 0; 7496ac73095SBeniamino Galvani } 7506ac73095SBeniamino Galvani 7516ac73095SBeniamino Galvani static struct platform_driver meson_pinctrl_driver = { 7526ac73095SBeniamino Galvani .probe = meson_pinctrl_probe, 7536ac73095SBeniamino Galvani .driver = { 7546ac73095SBeniamino Galvani .name = "meson-pinctrl", 7556ac73095SBeniamino Galvani .of_match_table = meson_pinctrl_dt_match, 7566ac73095SBeniamino Galvani }, 7576ac73095SBeniamino Galvani }; 7586ac73095SBeniamino Galvani module_platform_driver(meson_pinctrl_driver); 7596ac73095SBeniamino Galvani 7606ac73095SBeniamino Galvani MODULE_AUTHOR("Beniamino Galvani <b.galvani@gmail.com>"); 7616ac73095SBeniamino Galvani MODULE_DESCRIPTION("Amlogic Meson pinctrl driver"); 7626ac73095SBeniamino Galvani MODULE_LICENSE("GPL v2"); 763