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, 16faa246deSCarlo Caione * BOOT,CARD for meson6, X,Y,DV,H,Z,AO,BOOT,CARD for meson8 and 17faa246deSCarlo Caione * X,Y,DV,H,AO,BOOT,CARD,DIF for meson8b) and each bank has a 18faa246deSCarlo 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 * 24db80f0e1SBeniamino Galvani * For each pin controller there are 4 different register ranges that 25db80f0e1SBeniamino Galvani * control the following properties of the pins: 266ac73095SBeniamino Galvani * 1) pin muxing 276ac73095SBeniamino Galvani * 2) pull enable/disable 286ac73095SBeniamino Galvani * 3) pull up/down 296ac73095SBeniamino Galvani * 4) GPIO direction, output value, input value 306ac73095SBeniamino Galvani * 316ac73095SBeniamino Galvani * In some cases the register ranges for pull enable and pull 326ac73095SBeniamino Galvani * direction are the same and thus there are only 3 register ranges. 336ac73095SBeniamino Galvani * 34e66dd48eSXingyu Chen * Since Meson G12A SoC, the ao register ranges for gpio, pull enable 35e66dd48eSXingyu Chen * and pull direction are the same, so there are only 2 register ranges. 36e66dd48eSXingyu Chen * 376ac73095SBeniamino Galvani * For the pull and GPIO configuration every bank uses a contiguous 386ac73095SBeniamino Galvani * set of bits in the register sets described above; the same register 396ac73095SBeniamino Galvani * can be shared by more banks with different offsets. 406ac73095SBeniamino Galvani * 416ac73095SBeniamino Galvani * In addition to this there are some registers shared between all 426ac73095SBeniamino Galvani * banks that control the IRQ functionality. This feature is not 436ac73095SBeniamino Galvani * supported at the moment by the driver. 446ac73095SBeniamino Galvani */ 456ac73095SBeniamino Galvani 466ac73095SBeniamino Galvani #include <linux/device.h> 471c5fb66aSLinus Walleij #include <linux/gpio/driver.h> 486ac73095SBeniamino Galvani #include <linux/init.h> 496ac73095SBeniamino Galvani #include <linux/io.h> 506ac73095SBeniamino Galvani #include <linux/of.h> 516ac73095SBeniamino Galvani #include <linux/of_address.h> 52277d14ebSJerome Brunet #include <linux/of_device.h> 536ac73095SBeniamino Galvani #include <linux/pinctrl/pinconf-generic.h> 546ac73095SBeniamino Galvani #include <linux/pinctrl/pinconf.h> 556ac73095SBeniamino Galvani #include <linux/pinctrl/pinctrl.h> 566ac73095SBeniamino Galvani #include <linux/pinctrl/pinmux.h> 576ac73095SBeniamino Galvani #include <linux/platform_device.h> 586ac73095SBeniamino Galvani #include <linux/regmap.h> 596ac73095SBeniamino Galvani #include <linux/seq_file.h> 606ac73095SBeniamino Galvani 616ac73095SBeniamino Galvani #include "../core.h" 626ac73095SBeniamino Galvani #include "../pinctrl-utils.h" 636ac73095SBeniamino Galvani #include "pinctrl-meson.h" 646ac73095SBeniamino Galvani 656ac73095SBeniamino Galvani /** 666ac73095SBeniamino Galvani * meson_get_bank() - find the bank containing a given pin 676ac73095SBeniamino Galvani * 68db80f0e1SBeniamino Galvani * @pc: the pinctrl instance 696ac73095SBeniamino Galvani * @pin: the pin number 706ac73095SBeniamino Galvani * @bank: the found bank 716ac73095SBeniamino Galvani * 726ac73095SBeniamino Galvani * Return: 0 on success, a negative value on error 736ac73095SBeniamino Galvani */ 74db80f0e1SBeniamino Galvani static int meson_get_bank(struct meson_pinctrl *pc, unsigned int pin, 756ac73095SBeniamino Galvani struct meson_bank **bank) 766ac73095SBeniamino Galvani { 776ac73095SBeniamino Galvani int i; 786ac73095SBeniamino Galvani 79db80f0e1SBeniamino Galvani for (i = 0; i < pc->data->num_banks; i++) { 80db80f0e1SBeniamino Galvani if (pin >= pc->data->banks[i].first && 81db80f0e1SBeniamino Galvani pin <= pc->data->banks[i].last) { 82db80f0e1SBeniamino Galvani *bank = &pc->data->banks[i]; 836ac73095SBeniamino Galvani return 0; 846ac73095SBeniamino Galvani } 856ac73095SBeniamino Galvani } 866ac73095SBeniamino Galvani 876ac73095SBeniamino Galvani return -EINVAL; 886ac73095SBeniamino Galvani } 896ac73095SBeniamino Galvani 906ac73095SBeniamino Galvani /** 916ac73095SBeniamino Galvani * meson_calc_reg_and_bit() - calculate register and bit for a pin 926ac73095SBeniamino Galvani * 936ac73095SBeniamino Galvani * @bank: the bank containing the pin 946ac73095SBeniamino Galvani * @pin: the pin number 956ac73095SBeniamino Galvani * @reg_type: the type of register needed (pull-enable, pull, etc...) 966ac73095SBeniamino Galvani * @reg: the computed register offset 976ac73095SBeniamino Galvani * @bit: the computed bit 986ac73095SBeniamino Galvani */ 996ac73095SBeniamino Galvani static void meson_calc_reg_and_bit(struct meson_bank *bank, unsigned int pin, 1006ac73095SBeniamino Galvani enum meson_reg_type reg_type, 1016ac73095SBeniamino Galvani unsigned int *reg, unsigned int *bit) 1026ac73095SBeniamino Galvani { 1036ac73095SBeniamino Galvani struct meson_reg_desc *desc = &bank->regs[reg_type]; 1046ac73095SBeniamino Galvani 1056ac73095SBeniamino Galvani *reg = desc->reg * 4; 1066ac73095SBeniamino Galvani *bit = desc->bit + pin - bank->first; 1076ac73095SBeniamino Galvani } 1086ac73095SBeniamino Galvani 1096ac73095SBeniamino Galvani static int meson_get_groups_count(struct pinctrl_dev *pcdev) 1106ac73095SBeniamino Galvani { 1116ac73095SBeniamino Galvani struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); 1126ac73095SBeniamino Galvani 1136ac73095SBeniamino Galvani return pc->data->num_groups; 1146ac73095SBeniamino Galvani } 1156ac73095SBeniamino Galvani 1166ac73095SBeniamino Galvani static const char *meson_get_group_name(struct pinctrl_dev *pcdev, 1176ac73095SBeniamino Galvani unsigned selector) 1186ac73095SBeniamino Galvani { 1196ac73095SBeniamino Galvani struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); 1206ac73095SBeniamino Galvani 1216ac73095SBeniamino Galvani return pc->data->groups[selector].name; 1226ac73095SBeniamino Galvani } 1236ac73095SBeniamino Galvani 1246ac73095SBeniamino Galvani static int meson_get_group_pins(struct pinctrl_dev *pcdev, unsigned selector, 1256ac73095SBeniamino Galvani const unsigned **pins, unsigned *num_pins) 1266ac73095SBeniamino Galvani { 1276ac73095SBeniamino Galvani struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); 1286ac73095SBeniamino Galvani 1296ac73095SBeniamino Galvani *pins = pc->data->groups[selector].pins; 1306ac73095SBeniamino Galvani *num_pins = pc->data->groups[selector].num_pins; 1316ac73095SBeniamino Galvani 1326ac73095SBeniamino Galvani return 0; 1336ac73095SBeniamino Galvani } 1346ac73095SBeniamino Galvani 1356ac73095SBeniamino Galvani static void meson_pin_dbg_show(struct pinctrl_dev *pcdev, struct seq_file *s, 1366ac73095SBeniamino Galvani unsigned offset) 1376ac73095SBeniamino Galvani { 1386ac73095SBeniamino Galvani seq_printf(s, " %s", dev_name(pcdev->dev)); 1396ac73095SBeniamino Galvani } 1406ac73095SBeniamino Galvani 1416ac73095SBeniamino Galvani static const struct pinctrl_ops meson_pctrl_ops = { 1426ac73095SBeniamino Galvani .get_groups_count = meson_get_groups_count, 1436ac73095SBeniamino Galvani .get_group_name = meson_get_group_name, 1446ac73095SBeniamino Galvani .get_group_pins = meson_get_group_pins, 1456ac73095SBeniamino Galvani .dt_node_to_map = pinconf_generic_dt_node_to_map_all, 146d32f7fd3SIrina Tirdea .dt_free_map = pinctrl_utils_free_map, 1476ac73095SBeniamino Galvani .pin_dbg_show = meson_pin_dbg_show, 1486ac73095SBeniamino Galvani }; 1496ac73095SBeniamino Galvani 150ce385aa2SJerome Brunet int meson_pmx_get_funcs_count(struct pinctrl_dev *pcdev) 1516ac73095SBeniamino Galvani { 1526ac73095SBeniamino Galvani struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); 1536ac73095SBeniamino Galvani 1546ac73095SBeniamino Galvani return pc->data->num_funcs; 1556ac73095SBeniamino Galvani } 1566ac73095SBeniamino Galvani 157ce385aa2SJerome Brunet const char *meson_pmx_get_func_name(struct pinctrl_dev *pcdev, 1586ac73095SBeniamino Galvani unsigned selector) 1596ac73095SBeniamino Galvani { 1606ac73095SBeniamino Galvani struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); 1616ac73095SBeniamino Galvani 1626ac73095SBeniamino Galvani return pc->data->funcs[selector].name; 1636ac73095SBeniamino Galvani } 1646ac73095SBeniamino Galvani 165ce385aa2SJerome Brunet int meson_pmx_get_groups(struct pinctrl_dev *pcdev, unsigned selector, 1666ac73095SBeniamino Galvani const char * const **groups, 1676ac73095SBeniamino Galvani unsigned * const num_groups) 1686ac73095SBeniamino Galvani { 1696ac73095SBeniamino Galvani struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); 1706ac73095SBeniamino Galvani 1716ac73095SBeniamino Galvani *groups = pc->data->funcs[selector].groups; 1726ac73095SBeniamino Galvani *num_groups = pc->data->funcs[selector].num_groups; 1736ac73095SBeniamino Galvani 1746ac73095SBeniamino Galvani return 0; 1756ac73095SBeniamino Galvani } 1766ac73095SBeniamino Galvani 177*b22a7f85SJerome Brunet static int meson_pinconf_set_gpio_bit(struct meson_pinctrl *pc, 178*b22a7f85SJerome Brunet unsigned int pin, 179*b22a7f85SJerome Brunet unsigned int reg_type, 180*b22a7f85SJerome Brunet bool arg) 181*b22a7f85SJerome Brunet { 182*b22a7f85SJerome Brunet struct meson_bank *bank; 183*b22a7f85SJerome Brunet unsigned int reg, bit; 184*b22a7f85SJerome Brunet int ret; 185*b22a7f85SJerome Brunet 186*b22a7f85SJerome Brunet ret = meson_get_bank(pc, pin, &bank); 187*b22a7f85SJerome Brunet if (ret) 188*b22a7f85SJerome Brunet return ret; 189*b22a7f85SJerome Brunet 190*b22a7f85SJerome Brunet meson_calc_reg_and_bit(bank, pin, reg_type, ®, &bit); 191*b22a7f85SJerome Brunet return regmap_update_bits(pc->reg_gpio, reg, BIT(bit), 192*b22a7f85SJerome Brunet arg ? BIT(bit) : 0); 193*b22a7f85SJerome Brunet } 194*b22a7f85SJerome Brunet 195*b22a7f85SJerome Brunet static int meson_pinconf_get_gpio_bit(struct meson_pinctrl *pc, 196*b22a7f85SJerome Brunet unsigned int pin, 197*b22a7f85SJerome Brunet unsigned int reg_type) 198*b22a7f85SJerome Brunet { 199*b22a7f85SJerome Brunet struct meson_bank *bank; 200*b22a7f85SJerome Brunet unsigned int reg, bit, val; 201*b22a7f85SJerome Brunet int ret; 202*b22a7f85SJerome Brunet 203*b22a7f85SJerome Brunet ret = meson_get_bank(pc, pin, &bank); 204*b22a7f85SJerome Brunet if (ret) 205*b22a7f85SJerome Brunet return ret; 206*b22a7f85SJerome Brunet 207*b22a7f85SJerome Brunet meson_calc_reg_and_bit(bank, pin, reg_type, ®, &bit); 208*b22a7f85SJerome Brunet ret = regmap_read(pc->reg_gpio, reg, &val); 209*b22a7f85SJerome Brunet if (ret) 210*b22a7f85SJerome Brunet return ret; 211*b22a7f85SJerome Brunet 212*b22a7f85SJerome Brunet return BIT(bit) & val ? 1 : 0; 213*b22a7f85SJerome Brunet } 214*b22a7f85SJerome Brunet 215*b22a7f85SJerome Brunet static int meson_pinconf_set_output(struct meson_pinctrl *pc, 216*b22a7f85SJerome Brunet unsigned int pin, 217*b22a7f85SJerome Brunet bool out) 218*b22a7f85SJerome Brunet { 219*b22a7f85SJerome Brunet return meson_pinconf_set_gpio_bit(pc, pin, REG_DIR, !out); 220*b22a7f85SJerome Brunet } 221*b22a7f85SJerome Brunet 222*b22a7f85SJerome Brunet static int meson_pinconf_get_output(struct meson_pinctrl *pc, 223*b22a7f85SJerome Brunet unsigned int pin) 224*b22a7f85SJerome Brunet { 225*b22a7f85SJerome Brunet int ret = meson_pinconf_get_gpio_bit(pc, pin, REG_DIR); 226*b22a7f85SJerome Brunet 227*b22a7f85SJerome Brunet if (ret < 0) 228*b22a7f85SJerome Brunet return ret; 229*b22a7f85SJerome Brunet 230*b22a7f85SJerome Brunet return !ret; 231*b22a7f85SJerome Brunet } 232*b22a7f85SJerome Brunet 233*b22a7f85SJerome Brunet static int meson_pinconf_set_drive(struct meson_pinctrl *pc, 234*b22a7f85SJerome Brunet unsigned int pin, 235*b22a7f85SJerome Brunet bool high) 236*b22a7f85SJerome Brunet { 237*b22a7f85SJerome Brunet return meson_pinconf_set_gpio_bit(pc, pin, REG_OUT, high); 238*b22a7f85SJerome Brunet } 239*b22a7f85SJerome Brunet 240*b22a7f85SJerome Brunet static int meson_pinconf_get_drive(struct meson_pinctrl *pc, 241*b22a7f85SJerome Brunet unsigned int pin) 242*b22a7f85SJerome Brunet { 243*b22a7f85SJerome Brunet return meson_pinconf_get_gpio_bit(pc, pin, REG_OUT); 244*b22a7f85SJerome Brunet } 245*b22a7f85SJerome Brunet 246*b22a7f85SJerome Brunet static int meson_pinconf_set_output_drive(struct meson_pinctrl *pc, 247*b22a7f85SJerome Brunet unsigned int pin, 248*b22a7f85SJerome Brunet bool high) 249*b22a7f85SJerome Brunet { 250*b22a7f85SJerome Brunet int ret; 251*b22a7f85SJerome Brunet 252*b22a7f85SJerome Brunet ret = meson_pinconf_set_output(pc, pin, true); 253*b22a7f85SJerome Brunet if (ret) 254*b22a7f85SJerome Brunet return ret; 255*b22a7f85SJerome Brunet 256*b22a7f85SJerome Brunet return meson_pinconf_set_drive(pc, pin, high); 257*b22a7f85SJerome Brunet } 258*b22a7f85SJerome Brunet 2599959d9a7SGuillaume La Roque static int meson_pinconf_disable_bias(struct meson_pinctrl *pc, 2609959d9a7SGuillaume La Roque unsigned int pin) 2616ac73095SBeniamino Galvani { 2626ac73095SBeniamino Galvani struct meson_bank *bank; 2639959d9a7SGuillaume La Roque unsigned int reg, bit = 0; 2649959d9a7SGuillaume La Roque int ret; 2656ac73095SBeniamino Galvani 266db80f0e1SBeniamino Galvani ret = meson_get_bank(pc, pin, &bank); 2676ac73095SBeniamino Galvani if (ret) 2686ac73095SBeniamino Galvani return ret; 2696ac73095SBeniamino Galvani 2709959d9a7SGuillaume La Roque meson_calc_reg_and_bit(bank, pin, REG_PULLEN, ®, &bit); 2719959d9a7SGuillaume La Roque ret = regmap_update_bits(pc->reg_pullen, reg, BIT(bit), 0); 2729959d9a7SGuillaume La Roque if (ret) 2739959d9a7SGuillaume La Roque return ret; 2749959d9a7SGuillaume La Roque 2759959d9a7SGuillaume La Roque return 0; 2769959d9a7SGuillaume La Roque } 2779959d9a7SGuillaume La Roque 2789959d9a7SGuillaume La Roque static int meson_pinconf_enable_bias(struct meson_pinctrl *pc, unsigned int pin, 2799959d9a7SGuillaume La Roque bool pull_up) 2809959d9a7SGuillaume La Roque { 2819959d9a7SGuillaume La Roque struct meson_bank *bank; 2829959d9a7SGuillaume La Roque unsigned int reg, bit, val = 0; 2839959d9a7SGuillaume La Roque int ret; 2849959d9a7SGuillaume La Roque 2859959d9a7SGuillaume La Roque ret = meson_get_bank(pc, pin, &bank); 2869959d9a7SGuillaume La Roque if (ret) 2879959d9a7SGuillaume La Roque return ret; 2889959d9a7SGuillaume La Roque 2899959d9a7SGuillaume La Roque meson_calc_reg_and_bit(bank, pin, REG_PULL, ®, &bit); 2909959d9a7SGuillaume La Roque if (pull_up) 2919959d9a7SGuillaume La Roque val = BIT(bit); 2929959d9a7SGuillaume La Roque 2939959d9a7SGuillaume La Roque ret = regmap_update_bits(pc->reg_pull, reg, BIT(bit), val); 2949959d9a7SGuillaume La Roque if (ret) 2959959d9a7SGuillaume La Roque return ret; 2969959d9a7SGuillaume La Roque 2979959d9a7SGuillaume La Roque meson_calc_reg_and_bit(bank, pin, REG_PULLEN, ®, &bit); 2989959d9a7SGuillaume La Roque ret = regmap_update_bits(pc->reg_pullen, reg, BIT(bit), BIT(bit)); 2999959d9a7SGuillaume La Roque if (ret) 3009959d9a7SGuillaume La Roque return ret; 3019959d9a7SGuillaume La Roque 3029959d9a7SGuillaume La Roque return 0; 3039959d9a7SGuillaume La Roque } 3049959d9a7SGuillaume La Roque 3056ea3e3bbSGuillaume La Roque static int meson_pinconf_set_drive_strength(struct meson_pinctrl *pc, 3066ea3e3bbSGuillaume La Roque unsigned int pin, 3076ea3e3bbSGuillaume La Roque u16 drive_strength_ua) 3086ea3e3bbSGuillaume La Roque { 3096ea3e3bbSGuillaume La Roque struct meson_bank *bank; 3106ea3e3bbSGuillaume La Roque unsigned int reg, bit, ds_val; 3116ea3e3bbSGuillaume La Roque int ret; 3126ea3e3bbSGuillaume La Roque 3136ea3e3bbSGuillaume La Roque if (!pc->reg_ds) { 3146ea3e3bbSGuillaume La Roque dev_err(pc->dev, "drive-strength not supported\n"); 3156ea3e3bbSGuillaume La Roque return -ENOTSUPP; 3166ea3e3bbSGuillaume La Roque } 3176ea3e3bbSGuillaume La Roque 3186ea3e3bbSGuillaume La Roque ret = meson_get_bank(pc, pin, &bank); 3196ea3e3bbSGuillaume La Roque if (ret) 3206ea3e3bbSGuillaume La Roque return ret; 3216ea3e3bbSGuillaume La Roque 3226ea3e3bbSGuillaume La Roque meson_calc_reg_and_bit(bank, pin, REG_DS, ®, &bit); 3236ea3e3bbSGuillaume La Roque bit = bit << 1; 3246ea3e3bbSGuillaume La Roque 3256ea3e3bbSGuillaume La Roque if (drive_strength_ua <= 500) { 3266ea3e3bbSGuillaume La Roque ds_val = MESON_PINCONF_DRV_500UA; 3276ea3e3bbSGuillaume La Roque } else if (drive_strength_ua <= 2500) { 3286ea3e3bbSGuillaume La Roque ds_val = MESON_PINCONF_DRV_2500UA; 3296ea3e3bbSGuillaume La Roque } else if (drive_strength_ua <= 3000) { 3306ea3e3bbSGuillaume La Roque ds_val = MESON_PINCONF_DRV_3000UA; 3316ea3e3bbSGuillaume La Roque } else if (drive_strength_ua <= 4000) { 3326ea3e3bbSGuillaume La Roque ds_val = MESON_PINCONF_DRV_4000UA; 3336ea3e3bbSGuillaume La Roque } else { 3346ea3e3bbSGuillaume La Roque dev_warn_once(pc->dev, 3356ea3e3bbSGuillaume La Roque "pin %u: invalid drive-strength : %d , default to 4mA\n", 3366ea3e3bbSGuillaume La Roque pin, drive_strength_ua); 3376ea3e3bbSGuillaume La Roque ds_val = MESON_PINCONF_DRV_4000UA; 3386ea3e3bbSGuillaume La Roque } 3396ea3e3bbSGuillaume La Roque 3406ea3e3bbSGuillaume La Roque ret = regmap_update_bits(pc->reg_ds, reg, 0x3 << bit, ds_val << bit); 3416ea3e3bbSGuillaume La Roque if (ret) 3426ea3e3bbSGuillaume La Roque return ret; 3436ea3e3bbSGuillaume La Roque 3446ea3e3bbSGuillaume La Roque return 0; 3456ea3e3bbSGuillaume La Roque } 3466ea3e3bbSGuillaume La Roque 3479959d9a7SGuillaume La Roque static int meson_pinconf_set(struct pinctrl_dev *pcdev, unsigned int pin, 3489959d9a7SGuillaume La Roque unsigned long *configs, unsigned num_configs) 3499959d9a7SGuillaume La Roque { 3509959d9a7SGuillaume La Roque struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); 3519959d9a7SGuillaume La Roque enum pin_config_param param; 352*b22a7f85SJerome Brunet unsigned int arg = 0; 3539959d9a7SGuillaume La Roque int i, ret; 3549959d9a7SGuillaume La Roque 3556ac73095SBeniamino Galvani for (i = 0; i < num_configs; i++) { 3566ac73095SBeniamino Galvani param = pinconf_to_config_param(configs[i]); 3576ac73095SBeniamino Galvani 3586ac73095SBeniamino Galvani switch (param) { 359*b22a7f85SJerome Brunet case PIN_CONFIG_DRIVE_STRENGTH_UA: 360*b22a7f85SJerome Brunet case PIN_CONFIG_OUTPUT_ENABLE: 361*b22a7f85SJerome Brunet case PIN_CONFIG_OUTPUT: 362*b22a7f85SJerome Brunet arg = pinconf_to_config_argument(configs[i]); 363*b22a7f85SJerome Brunet break; 364*b22a7f85SJerome Brunet 365*b22a7f85SJerome Brunet default: 366*b22a7f85SJerome Brunet break; 367*b22a7f85SJerome Brunet } 368*b22a7f85SJerome Brunet 369*b22a7f85SJerome Brunet switch (param) { 3706ac73095SBeniamino Galvani case PIN_CONFIG_BIAS_DISABLE: 3719959d9a7SGuillaume La Roque ret = meson_pinconf_disable_bias(pc, pin); 3726ac73095SBeniamino Galvani break; 3736ac73095SBeniamino Galvani case PIN_CONFIG_BIAS_PULL_UP: 3749959d9a7SGuillaume La Roque ret = meson_pinconf_enable_bias(pc, pin, true); 3756ac73095SBeniamino Galvani break; 3766ac73095SBeniamino Galvani case PIN_CONFIG_BIAS_PULL_DOWN: 3779959d9a7SGuillaume La Roque ret = meson_pinconf_enable_bias(pc, pin, false); 3786ac73095SBeniamino Galvani break; 3796ea3e3bbSGuillaume La Roque case PIN_CONFIG_DRIVE_STRENGTH_UA: 380*b22a7f85SJerome Brunet ret = meson_pinconf_set_drive_strength(pc, pin, arg); 381*b22a7f85SJerome Brunet break; 382*b22a7f85SJerome Brunet case PIN_CONFIG_OUTPUT_ENABLE: 383*b22a7f85SJerome Brunet ret = meson_pinconf_set_output(pc, pin, arg); 384*b22a7f85SJerome Brunet break; 385*b22a7f85SJerome Brunet case PIN_CONFIG_OUTPUT: 386*b22a7f85SJerome Brunet ret = meson_pinconf_set_output_drive(pc, pin, arg); 3876ea3e3bbSGuillaume La Roque break; 3886ac73095SBeniamino Galvani default: 389*b22a7f85SJerome Brunet ret = -ENOTSUPP; 3906ac73095SBeniamino Galvani } 391*b22a7f85SJerome Brunet 392*b22a7f85SJerome Brunet if (ret) 393*b22a7f85SJerome Brunet return ret; 3946ac73095SBeniamino Galvani } 3956ac73095SBeniamino Galvani 3966ac73095SBeniamino Galvani return 0; 3976ac73095SBeniamino Galvani } 3986ac73095SBeniamino Galvani 3996ac73095SBeniamino Galvani static int meson_pinconf_get_pull(struct meson_pinctrl *pc, unsigned int pin) 4006ac73095SBeniamino Galvani { 4016ac73095SBeniamino Galvani struct meson_bank *bank; 4026ac73095SBeniamino Galvani unsigned int reg, bit, val; 4036ac73095SBeniamino Galvani int ret, conf; 4046ac73095SBeniamino Galvani 405db80f0e1SBeniamino Galvani ret = meson_get_bank(pc, pin, &bank); 4066ac73095SBeniamino Galvani if (ret) 4076ac73095SBeniamino Galvani return ret; 4086ac73095SBeniamino Galvani 4096ac73095SBeniamino Galvani meson_calc_reg_and_bit(bank, pin, REG_PULLEN, ®, &bit); 4106ac73095SBeniamino Galvani 411db80f0e1SBeniamino Galvani ret = regmap_read(pc->reg_pullen, reg, &val); 4126ac73095SBeniamino Galvani if (ret) 4136ac73095SBeniamino Galvani return ret; 4146ac73095SBeniamino Galvani 4156ac73095SBeniamino Galvani if (!(val & BIT(bit))) { 4166ac73095SBeniamino Galvani conf = PIN_CONFIG_BIAS_DISABLE; 4176ac73095SBeniamino Galvani } else { 4186ac73095SBeniamino Galvani meson_calc_reg_and_bit(bank, pin, REG_PULL, ®, &bit); 4196ac73095SBeniamino Galvani 420db80f0e1SBeniamino Galvani ret = regmap_read(pc->reg_pull, reg, &val); 4216ac73095SBeniamino Galvani if (ret) 4226ac73095SBeniamino Galvani return ret; 4236ac73095SBeniamino Galvani 4246ac73095SBeniamino Galvani if (val & BIT(bit)) 4256ac73095SBeniamino Galvani conf = PIN_CONFIG_BIAS_PULL_UP; 4266ac73095SBeniamino Galvani else 4276ac73095SBeniamino Galvani conf = PIN_CONFIG_BIAS_PULL_DOWN; 4286ac73095SBeniamino Galvani } 4296ac73095SBeniamino Galvani 4306ac73095SBeniamino Galvani return conf; 4316ac73095SBeniamino Galvani } 4326ac73095SBeniamino Galvani 4336ea3e3bbSGuillaume La Roque static int meson_pinconf_get_drive_strength(struct meson_pinctrl *pc, 4346ea3e3bbSGuillaume La Roque unsigned int pin, 4356ea3e3bbSGuillaume La Roque u16 *drive_strength_ua) 4366ea3e3bbSGuillaume La Roque { 4376ea3e3bbSGuillaume La Roque struct meson_bank *bank; 4386ea3e3bbSGuillaume La Roque unsigned int reg, bit; 4396ea3e3bbSGuillaume La Roque unsigned int val; 4406ea3e3bbSGuillaume La Roque int ret; 4416ea3e3bbSGuillaume La Roque 4426ea3e3bbSGuillaume La Roque if (!pc->reg_ds) 4436ea3e3bbSGuillaume La Roque return -ENOTSUPP; 4446ea3e3bbSGuillaume La Roque 4456ea3e3bbSGuillaume La Roque ret = meson_get_bank(pc, pin, &bank); 4466ea3e3bbSGuillaume La Roque if (ret) 4476ea3e3bbSGuillaume La Roque return ret; 4486ea3e3bbSGuillaume La Roque 4496ea3e3bbSGuillaume La Roque meson_calc_reg_and_bit(bank, pin, REG_DS, ®, &bit); 4506ea3e3bbSGuillaume La Roque 4516ea3e3bbSGuillaume La Roque ret = regmap_read(pc->reg_ds, reg, &val); 4526ea3e3bbSGuillaume La Roque if (ret) 4536ea3e3bbSGuillaume La Roque return ret; 4546ea3e3bbSGuillaume La Roque 4556ea3e3bbSGuillaume La Roque switch ((val >> bit) & 0x3) { 4566ea3e3bbSGuillaume La Roque case MESON_PINCONF_DRV_500UA: 4576ea3e3bbSGuillaume La Roque *drive_strength_ua = 500; 4586ea3e3bbSGuillaume La Roque break; 4596ea3e3bbSGuillaume La Roque case MESON_PINCONF_DRV_2500UA: 4606ea3e3bbSGuillaume La Roque *drive_strength_ua = 2500; 4616ea3e3bbSGuillaume La Roque break; 4626ea3e3bbSGuillaume La Roque case MESON_PINCONF_DRV_3000UA: 4636ea3e3bbSGuillaume La Roque *drive_strength_ua = 3000; 4646ea3e3bbSGuillaume La Roque break; 4656ea3e3bbSGuillaume La Roque case MESON_PINCONF_DRV_4000UA: 4666ea3e3bbSGuillaume La Roque *drive_strength_ua = 4000; 4676ea3e3bbSGuillaume La Roque break; 4686ea3e3bbSGuillaume La Roque default: 4696ea3e3bbSGuillaume La Roque return -EINVAL; 4706ea3e3bbSGuillaume La Roque } 4716ea3e3bbSGuillaume La Roque 4726ea3e3bbSGuillaume La Roque return 0; 4736ea3e3bbSGuillaume La Roque } 4746ea3e3bbSGuillaume La Roque 4756ac73095SBeniamino Galvani static int meson_pinconf_get(struct pinctrl_dev *pcdev, unsigned int pin, 4766ac73095SBeniamino Galvani unsigned long *config) 4776ac73095SBeniamino Galvani { 4786ac73095SBeniamino Galvani struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); 4796ac73095SBeniamino Galvani enum pin_config_param param = pinconf_to_config_param(*config); 4806ac73095SBeniamino Galvani u16 arg; 4816ea3e3bbSGuillaume La Roque int ret; 4826ac73095SBeniamino Galvani 4836ac73095SBeniamino Galvani switch (param) { 4846ac73095SBeniamino Galvani case PIN_CONFIG_BIAS_DISABLE: 4856ac73095SBeniamino Galvani case PIN_CONFIG_BIAS_PULL_DOWN: 4866ac73095SBeniamino Galvani case PIN_CONFIG_BIAS_PULL_UP: 4876ac73095SBeniamino Galvani if (meson_pinconf_get_pull(pc, pin) == param) 4886ac73095SBeniamino Galvani arg = 1; 4896ac73095SBeniamino Galvani else 4906ac73095SBeniamino Galvani return -EINVAL; 4916ac73095SBeniamino Galvani break; 4926ea3e3bbSGuillaume La Roque case PIN_CONFIG_DRIVE_STRENGTH_UA: 4936ea3e3bbSGuillaume La Roque ret = meson_pinconf_get_drive_strength(pc, pin, &arg); 4946ea3e3bbSGuillaume La Roque if (ret) 4956ea3e3bbSGuillaume La Roque return ret; 4966ea3e3bbSGuillaume La Roque break; 497*b22a7f85SJerome Brunet case PIN_CONFIG_OUTPUT_ENABLE: 498*b22a7f85SJerome Brunet ret = meson_pinconf_get_output(pc, pin); 499*b22a7f85SJerome Brunet if (ret <= 0) 500*b22a7f85SJerome Brunet return -EINVAL; 501*b22a7f85SJerome Brunet arg = 1; 502*b22a7f85SJerome Brunet break; 503*b22a7f85SJerome Brunet case PIN_CONFIG_OUTPUT: 504*b22a7f85SJerome Brunet ret = meson_pinconf_get_output(pc, pin); 505*b22a7f85SJerome Brunet if (ret <= 0) 506*b22a7f85SJerome Brunet return -EINVAL; 507*b22a7f85SJerome Brunet 508*b22a7f85SJerome Brunet ret = meson_pinconf_get_drive(pc, pin); 509*b22a7f85SJerome Brunet if (ret < 0) 510*b22a7f85SJerome Brunet return -EINVAL; 511*b22a7f85SJerome Brunet 512*b22a7f85SJerome Brunet arg = ret; 513*b22a7f85SJerome Brunet break; 514*b22a7f85SJerome Brunet 5156ac73095SBeniamino Galvani default: 5166ac73095SBeniamino Galvani return -ENOTSUPP; 5176ac73095SBeniamino Galvani } 5186ac73095SBeniamino Galvani 5196ac73095SBeniamino Galvani *config = pinconf_to_config_packed(param, arg); 5206ac73095SBeniamino Galvani dev_dbg(pc->dev, "pinconf for pin %u is %lu\n", pin, *config); 5216ac73095SBeniamino Galvani 5226ac73095SBeniamino Galvani return 0; 5236ac73095SBeniamino Galvani } 5246ac73095SBeniamino Galvani 5256ac73095SBeniamino Galvani static int meson_pinconf_group_set(struct pinctrl_dev *pcdev, 5266ac73095SBeniamino Galvani unsigned int num_group, 5276ac73095SBeniamino Galvani unsigned long *configs, unsigned num_configs) 5286ac73095SBeniamino Galvani { 5296ac73095SBeniamino Galvani struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); 5306ac73095SBeniamino Galvani struct meson_pmx_group *group = &pc->data->groups[num_group]; 5316ac73095SBeniamino Galvani int i; 5326ac73095SBeniamino Galvani 5336ac73095SBeniamino Galvani dev_dbg(pc->dev, "set pinconf for group %s\n", group->name); 5346ac73095SBeniamino Galvani 5356ac73095SBeniamino Galvani for (i = 0; i < group->num_pins; i++) { 5366ac73095SBeniamino Galvani meson_pinconf_set(pcdev, group->pins[i], configs, 5376ac73095SBeniamino Galvani num_configs); 5386ac73095SBeniamino Galvani } 5396ac73095SBeniamino Galvani 5406ac73095SBeniamino Galvani return 0; 5416ac73095SBeniamino Galvani } 5426ac73095SBeniamino Galvani 5436ac73095SBeniamino Galvani static int meson_pinconf_group_get(struct pinctrl_dev *pcdev, 5446ac73095SBeniamino Galvani unsigned int group, unsigned long *config) 5456ac73095SBeniamino Galvani { 5461ffbf50bSJerome Brunet return -ENOTSUPP; 5476ac73095SBeniamino Galvani } 5486ac73095SBeniamino Galvani 5496ac73095SBeniamino Galvani static const struct pinconf_ops meson_pinconf_ops = { 5506ac73095SBeniamino Galvani .pin_config_get = meson_pinconf_get, 5516ac73095SBeniamino Galvani .pin_config_set = meson_pinconf_set, 5526ac73095SBeniamino Galvani .pin_config_group_get = meson_pinconf_group_get, 5536ac73095SBeniamino Galvani .pin_config_group_set = meson_pinconf_group_set, 5546ac73095SBeniamino Galvani .is_generic = true, 5556ac73095SBeniamino Galvani }; 5566ac73095SBeniamino Galvani 5576ac73095SBeniamino Galvani static int meson_gpio_direction_input(struct gpio_chip *chip, unsigned gpio) 5586ac73095SBeniamino Galvani { 559*b22a7f85SJerome Brunet return meson_pinconf_set_output(gpiochip_get_data(chip), gpio, false); 5606ac73095SBeniamino Galvani } 5616ac73095SBeniamino Galvani 5626ac73095SBeniamino Galvani static int meson_gpio_direction_output(struct gpio_chip *chip, unsigned gpio, 5636ac73095SBeniamino Galvani int value) 5646ac73095SBeniamino Galvani { 565*b22a7f85SJerome Brunet return meson_pinconf_set_output_drive(gpiochip_get_data(chip), 566*b22a7f85SJerome Brunet gpio, value); 5676ac73095SBeniamino Galvani } 5686ac73095SBeniamino Galvani 5696ac73095SBeniamino Galvani static void meson_gpio_set(struct gpio_chip *chip, unsigned gpio, int value) 5706ac73095SBeniamino Galvani { 571*b22a7f85SJerome Brunet meson_pinconf_set_drive(gpiochip_get_data(chip), gpio, value); 5726ac73095SBeniamino Galvani } 5736ac73095SBeniamino Galvani 5746ac73095SBeniamino Galvani static int meson_gpio_get(struct gpio_chip *chip, unsigned gpio) 5756ac73095SBeniamino Galvani { 576db80f0e1SBeniamino Galvani struct meson_pinctrl *pc = gpiochip_get_data(chip); 57770e5ecb1SJerome Brunet unsigned int reg, bit, val; 5786ac73095SBeniamino Galvani struct meson_bank *bank; 5796ac73095SBeniamino Galvani int ret; 5806ac73095SBeniamino Galvani 58170e5ecb1SJerome Brunet ret = meson_get_bank(pc, gpio, &bank); 5826ac73095SBeniamino Galvani if (ret) 5836ac73095SBeniamino Galvani return ret; 5846ac73095SBeniamino Galvani 58570e5ecb1SJerome Brunet meson_calc_reg_and_bit(bank, gpio, REG_IN, ®, &bit); 586db80f0e1SBeniamino Galvani regmap_read(pc->reg_gpio, reg, &val); 5876ac73095SBeniamino Galvani 5886ac73095SBeniamino Galvani return !!(val & BIT(bit)); 5896ac73095SBeniamino Galvani } 5906ac73095SBeniamino Galvani 5916ac73095SBeniamino Galvani static int meson_gpiolib_register(struct meson_pinctrl *pc) 5926ac73095SBeniamino Galvani { 5939dab1868SCarlo Caione int ret; 5946ac73095SBeniamino Galvani 595db80f0e1SBeniamino Galvani pc->chip.label = pc->data->name; 596db80f0e1SBeniamino Galvani pc->chip.parent = pc->dev; 597634e40b0SJerome Brunet pc->chip.request = gpiochip_generic_request; 598634e40b0SJerome Brunet pc->chip.free = gpiochip_generic_free; 599db80f0e1SBeniamino Galvani pc->chip.direction_input = meson_gpio_direction_input; 600db80f0e1SBeniamino Galvani pc->chip.direction_output = meson_gpio_direction_output; 601db80f0e1SBeniamino Galvani pc->chip.get = meson_gpio_get; 602db80f0e1SBeniamino Galvani pc->chip.set = meson_gpio_set; 603634e40b0SJerome Brunet pc->chip.base = -1; 604db80f0e1SBeniamino Galvani pc->chip.ngpio = pc->data->num_pins; 605db80f0e1SBeniamino Galvani pc->chip.can_sleep = false; 606db80f0e1SBeniamino Galvani pc->chip.of_node = pc->of_node; 607db80f0e1SBeniamino Galvani pc->chip.of_gpio_n_cells = 2; 6086ac73095SBeniamino Galvani 609db80f0e1SBeniamino Galvani ret = gpiochip_add_data(&pc->chip, pc); 6106ac73095SBeniamino Galvani if (ret) { 6116ac73095SBeniamino Galvani dev_err(pc->dev, "can't add gpio chip %s\n", 612db80f0e1SBeniamino Galvani pc->data->name); 613c7fc5fbaSNeil Armstrong return ret; 6146ac73095SBeniamino Galvani } 6156ac73095SBeniamino Galvani 6166ac73095SBeniamino Galvani return 0; 6176ac73095SBeniamino Galvani } 6186ac73095SBeniamino Galvani 6196ac73095SBeniamino Galvani static struct regmap_config meson_regmap_config = { 6206ac73095SBeniamino Galvani .reg_bits = 32, 6216ac73095SBeniamino Galvani .val_bits = 32, 6226ac73095SBeniamino Galvani .reg_stride = 4, 6236ac73095SBeniamino Galvani }; 6246ac73095SBeniamino Galvani 6256ac73095SBeniamino Galvani static struct regmap *meson_map_resource(struct meson_pinctrl *pc, 6266ac73095SBeniamino Galvani struct device_node *node, char *name) 6276ac73095SBeniamino Galvani { 6286ac73095SBeniamino Galvani struct resource res; 6296ac73095SBeniamino Galvani void __iomem *base; 6306ac73095SBeniamino Galvani int i; 6316ac73095SBeniamino Galvani 6326ac73095SBeniamino Galvani i = of_property_match_string(node, "reg-names", name); 6336ac73095SBeniamino Galvani if (of_address_to_resource(node, i, &res)) 6346ac73095SBeniamino Galvani return ERR_PTR(-ENOENT); 6356ac73095SBeniamino Galvani 6366ac73095SBeniamino Galvani base = devm_ioremap_resource(pc->dev, &res); 6376ac73095SBeniamino Galvani if (IS_ERR(base)) 6386ac73095SBeniamino Galvani return ERR_CAST(base); 6396ac73095SBeniamino Galvani 6406ac73095SBeniamino Galvani meson_regmap_config.max_register = resource_size(&res) - 4; 6416ac73095SBeniamino Galvani meson_regmap_config.name = devm_kasprintf(pc->dev, GFP_KERNEL, 64294f4e54cSRob Herring "%pOFn-%s", node, 6436ac73095SBeniamino Galvani name); 6446ac73095SBeniamino Galvani if (!meson_regmap_config.name) 6456ac73095SBeniamino Galvani return ERR_PTR(-ENOMEM); 6466ac73095SBeniamino Galvani 6476ac73095SBeniamino Galvani return devm_regmap_init_mmio(pc->dev, base, &meson_regmap_config); 6486ac73095SBeniamino Galvani } 6496ac73095SBeniamino Galvani 6506ac73095SBeniamino Galvani static int meson_pinctrl_parse_dt(struct meson_pinctrl *pc, 6516ac73095SBeniamino Galvani struct device_node *node) 6526ac73095SBeniamino Galvani { 653db80f0e1SBeniamino Galvani struct device_node *np, *gpio_np = NULL; 6546ac73095SBeniamino Galvani 6556ac73095SBeniamino Galvani for_each_child_of_node(node, np) { 6566ac73095SBeniamino Galvani if (!of_find_property(np, "gpio-controller", NULL)) 6576ac73095SBeniamino Galvani continue; 658db80f0e1SBeniamino Galvani if (gpio_np) { 659db80f0e1SBeniamino Galvani dev_err(pc->dev, "multiple gpio nodes\n"); 660db80f0e1SBeniamino Galvani return -EINVAL; 661db80f0e1SBeniamino Galvani } 662db80f0e1SBeniamino Galvani gpio_np = np; 6636ac73095SBeniamino Galvani } 6646ac73095SBeniamino Galvani 665db80f0e1SBeniamino Galvani if (!gpio_np) { 666db80f0e1SBeniamino Galvani dev_err(pc->dev, "no gpio node found\n"); 6676ac73095SBeniamino Galvani return -EINVAL; 6686ac73095SBeniamino Galvani } 6696ac73095SBeniamino Galvani 670db80f0e1SBeniamino Galvani pc->of_node = gpio_np; 6716ac73095SBeniamino Galvani 672db80f0e1SBeniamino Galvani pc->reg_mux = meson_map_resource(pc, gpio_np, "mux"); 673db80f0e1SBeniamino Galvani if (IS_ERR(pc->reg_mux)) { 6746ac73095SBeniamino Galvani dev_err(pc->dev, "mux registers not found\n"); 675db80f0e1SBeniamino Galvani return PTR_ERR(pc->reg_mux); 6766ac73095SBeniamino Galvani } 6776ac73095SBeniamino Galvani 678db80f0e1SBeniamino Galvani pc->reg_gpio = meson_map_resource(pc, gpio_np, "gpio"); 679db80f0e1SBeniamino Galvani if (IS_ERR(pc->reg_gpio)) { 6806ac73095SBeniamino Galvani dev_err(pc->dev, "gpio registers not found\n"); 681db80f0e1SBeniamino Galvani return PTR_ERR(pc->reg_gpio); 6826ac73095SBeniamino Galvani } 6836ac73095SBeniamino Galvani 684e66dd48eSXingyu Chen pc->reg_pull = meson_map_resource(pc, gpio_np, "pull"); 685e66dd48eSXingyu Chen /* Use gpio region if pull one is not present */ 686e66dd48eSXingyu Chen if (IS_ERR(pc->reg_pull)) 687e66dd48eSXingyu Chen pc->reg_pull = pc->reg_gpio; 688e66dd48eSXingyu Chen 689e66dd48eSXingyu Chen pc->reg_pullen = meson_map_resource(pc, gpio_np, "pull-enable"); 690e66dd48eSXingyu Chen /* Use pull region if pull-enable one is not present */ 691e66dd48eSXingyu Chen if (IS_ERR(pc->reg_pullen)) 692e66dd48eSXingyu Chen pc->reg_pullen = pc->reg_pull; 693e66dd48eSXingyu Chen 69464856974SJerome Brunet pc->reg_ds = meson_map_resource(pc, gpio_np, "ds"); 69564856974SJerome Brunet if (IS_ERR(pc->reg_ds)) { 69664856974SJerome Brunet dev_dbg(pc->dev, "ds registers not found - skipping\n"); 69764856974SJerome Brunet pc->reg_ds = NULL; 69864856974SJerome Brunet } 69964856974SJerome Brunet 7006ac73095SBeniamino Galvani return 0; 7016ac73095SBeniamino Galvani } 7026ac73095SBeniamino Galvani 703277d14ebSJerome Brunet int meson_pinctrl_probe(struct platform_device *pdev) 7046ac73095SBeniamino Galvani { 7056ac73095SBeniamino Galvani struct device *dev = &pdev->dev; 7066ac73095SBeniamino Galvani struct meson_pinctrl *pc; 7076ac73095SBeniamino Galvani int ret; 7086ac73095SBeniamino Galvani 7096ac73095SBeniamino Galvani pc = devm_kzalloc(dev, sizeof(struct meson_pinctrl), GFP_KERNEL); 7106ac73095SBeniamino Galvani if (!pc) 7116ac73095SBeniamino Galvani return -ENOMEM; 7126ac73095SBeniamino Galvani 7136ac73095SBeniamino Galvani pc->dev = dev; 714277d14ebSJerome Brunet pc->data = (struct meson_pinctrl_data *) of_device_get_match_data(dev); 7156ac73095SBeniamino Galvani 716277d14ebSJerome Brunet ret = meson_pinctrl_parse_dt(pc, dev->of_node); 7176ac73095SBeniamino Galvani if (ret) 7186ac73095SBeniamino Galvani return ret; 7196ac73095SBeniamino Galvani 7206ac73095SBeniamino Galvani pc->desc.name = "pinctrl-meson"; 7216ac73095SBeniamino Galvani pc->desc.owner = THIS_MODULE; 7226ac73095SBeniamino Galvani pc->desc.pctlops = &meson_pctrl_ops; 723ce385aa2SJerome Brunet pc->desc.pmxops = pc->data->pmx_ops; 7246ac73095SBeniamino Galvani pc->desc.confops = &meson_pinconf_ops; 7256ac73095SBeniamino Galvani pc->desc.pins = pc->data->pins; 7266ac73095SBeniamino Galvani pc->desc.npins = pc->data->num_pins; 7276ac73095SBeniamino Galvani 728e649f7ecSLaxman Dewangan pc->pcdev = devm_pinctrl_register(pc->dev, &pc->desc, pc); 729323de9efSMasahiro Yamada if (IS_ERR(pc->pcdev)) { 7306ac73095SBeniamino Galvani dev_err(pc->dev, "can't register pinctrl device"); 731323de9efSMasahiro Yamada return PTR_ERR(pc->pcdev); 7326ac73095SBeniamino Galvani } 7336ac73095SBeniamino Galvani 7345b236d0fSWei Yongjun return meson_gpiolib_register(pc); 7356ac73095SBeniamino Galvani } 736