13c910ecbSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 26ac73095SBeniamino Galvani /* 36ac73095SBeniamino Galvani * Pin controller and GPIO driver for Amlogic Meson SoCs 46ac73095SBeniamino Galvani * 56ac73095SBeniamino Galvani * Copyright (C) 2014 Beniamino Galvani <b.galvani@gmail.com> 66ac73095SBeniamino Galvani */ 76ac73095SBeniamino Galvani 86ac73095SBeniamino Galvani /* 96ac73095SBeniamino Galvani * The available pins are organized in banks (A,B,C,D,E,X,Y,Z,AO, 10faa246deSCarlo Caione * BOOT,CARD for meson6, X,Y,DV,H,Z,AO,BOOT,CARD for meson8 and 11faa246deSCarlo Caione * X,Y,DV,H,AO,BOOT,CARD,DIF for meson8b) and each bank has a 12faa246deSCarlo Caione * variable number of pins. 136ac73095SBeniamino Galvani * 146ac73095SBeniamino Galvani * The AO bank is special because it belongs to the Always-On power 156ac73095SBeniamino Galvani * domain which can't be powered off; the bank also uses a set of 166ac73095SBeniamino Galvani * registers different from the other banks. 176ac73095SBeniamino Galvani * 18db80f0e1SBeniamino Galvani * For each pin controller there are 4 different register ranges that 19db80f0e1SBeniamino Galvani * control the following properties of the pins: 206ac73095SBeniamino Galvani * 1) pin muxing 216ac73095SBeniamino Galvani * 2) pull enable/disable 226ac73095SBeniamino Galvani * 3) pull up/down 236ac73095SBeniamino Galvani * 4) GPIO direction, output value, input value 246ac73095SBeniamino Galvani * 256ac73095SBeniamino Galvani * In some cases the register ranges for pull enable and pull 266ac73095SBeniamino Galvani * direction are the same and thus there are only 3 register ranges. 276ac73095SBeniamino Galvani * 28e66dd48eSXingyu Chen * Since Meson G12A SoC, the ao register ranges for gpio, pull enable 29e66dd48eSXingyu Chen * and pull direction are the same, so there are only 2 register ranges. 30e66dd48eSXingyu Chen * 316ac73095SBeniamino Galvani * For the pull and GPIO configuration every bank uses a contiguous 326ac73095SBeniamino Galvani * set of bits in the register sets described above; the same register 336ac73095SBeniamino Galvani * can be shared by more banks with different offsets. 346ac73095SBeniamino Galvani * 356ac73095SBeniamino Galvani * In addition to this there are some registers shared between all 366ac73095SBeniamino Galvani * banks that control the IRQ functionality. This feature is not 376ac73095SBeniamino Galvani * supported at the moment by the driver. 386ac73095SBeniamino Galvani */ 396ac73095SBeniamino Galvani 406ac73095SBeniamino Galvani #include <linux/device.h> 411c5fb66aSLinus Walleij #include <linux/gpio/driver.h> 426ac73095SBeniamino Galvani #include <linux/init.h> 436ac73095SBeniamino Galvani #include <linux/io.h> 446ac73095SBeniamino Galvani #include <linux/of.h> 456ac73095SBeniamino Galvani #include <linux/of_address.h> 46277d14ebSJerome Brunet #include <linux/of_device.h> 476ac73095SBeniamino Galvani #include <linux/pinctrl/pinconf-generic.h> 486ac73095SBeniamino Galvani #include <linux/pinctrl/pinconf.h> 496ac73095SBeniamino Galvani #include <linux/pinctrl/pinctrl.h> 506ac73095SBeniamino Galvani #include <linux/pinctrl/pinmux.h> 516ac73095SBeniamino Galvani #include <linux/platform_device.h> 526ac73095SBeniamino Galvani #include <linux/regmap.h> 536ac73095SBeniamino Galvani #include <linux/seq_file.h> 546ac73095SBeniamino Galvani 556ac73095SBeniamino Galvani #include "../core.h" 566ac73095SBeniamino Galvani #include "../pinctrl-utils.h" 576ac73095SBeniamino Galvani #include "pinctrl-meson.h" 586ac73095SBeniamino Galvani 596ac73095SBeniamino Galvani /** 606ac73095SBeniamino Galvani * meson_get_bank() - find the bank containing a given pin 616ac73095SBeniamino Galvani * 62db80f0e1SBeniamino Galvani * @pc: the pinctrl instance 636ac73095SBeniamino Galvani * @pin: the pin number 646ac73095SBeniamino Galvani * @bank: the found bank 656ac73095SBeniamino Galvani * 666ac73095SBeniamino Galvani * Return: 0 on success, a negative value on error 676ac73095SBeniamino Galvani */ 68db80f0e1SBeniamino Galvani static int meson_get_bank(struct meson_pinctrl *pc, unsigned int pin, 696ac73095SBeniamino Galvani struct meson_bank **bank) 706ac73095SBeniamino Galvani { 716ac73095SBeniamino Galvani int i; 726ac73095SBeniamino Galvani 73db80f0e1SBeniamino Galvani for (i = 0; i < pc->data->num_banks; i++) { 74db80f0e1SBeniamino Galvani if (pin >= pc->data->banks[i].first && 75db80f0e1SBeniamino Galvani pin <= pc->data->banks[i].last) { 76db80f0e1SBeniamino Galvani *bank = &pc->data->banks[i]; 776ac73095SBeniamino Galvani return 0; 786ac73095SBeniamino Galvani } 796ac73095SBeniamino Galvani } 806ac73095SBeniamino Galvani 816ac73095SBeniamino Galvani return -EINVAL; 826ac73095SBeniamino Galvani } 836ac73095SBeniamino Galvani 846ac73095SBeniamino Galvani /** 856ac73095SBeniamino Galvani * meson_calc_reg_and_bit() - calculate register and bit for a pin 866ac73095SBeniamino Galvani * 876ac73095SBeniamino Galvani * @bank: the bank containing the pin 886ac73095SBeniamino Galvani * @pin: the pin number 896ac73095SBeniamino Galvani * @reg_type: the type of register needed (pull-enable, pull, etc...) 906ac73095SBeniamino Galvani * @reg: the computed register offset 916ac73095SBeniamino Galvani * @bit: the computed bit 926ac73095SBeniamino Galvani */ 936ac73095SBeniamino Galvani static void meson_calc_reg_and_bit(struct meson_bank *bank, unsigned int pin, 946ac73095SBeniamino Galvani enum meson_reg_type reg_type, 956ac73095SBeniamino Galvani unsigned int *reg, unsigned int *bit) 966ac73095SBeniamino Galvani { 976ac73095SBeniamino Galvani struct meson_reg_desc *desc = &bank->regs[reg_type]; 986ac73095SBeniamino Galvani 996ac73095SBeniamino Galvani *reg = desc->reg * 4; 1006ac73095SBeniamino Galvani *bit = desc->bit + pin - bank->first; 1016ac73095SBeniamino Galvani } 1026ac73095SBeniamino Galvani 1036ac73095SBeniamino Galvani static int meson_get_groups_count(struct pinctrl_dev *pcdev) 1046ac73095SBeniamino Galvani { 1056ac73095SBeniamino Galvani struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); 1066ac73095SBeniamino Galvani 1076ac73095SBeniamino Galvani return pc->data->num_groups; 1086ac73095SBeniamino Galvani } 1096ac73095SBeniamino Galvani 1106ac73095SBeniamino Galvani static const char *meson_get_group_name(struct pinctrl_dev *pcdev, 1116ac73095SBeniamino Galvani unsigned selector) 1126ac73095SBeniamino Galvani { 1136ac73095SBeniamino Galvani struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); 1146ac73095SBeniamino Galvani 1156ac73095SBeniamino Galvani return pc->data->groups[selector].name; 1166ac73095SBeniamino Galvani } 1176ac73095SBeniamino Galvani 1186ac73095SBeniamino Galvani static int meson_get_group_pins(struct pinctrl_dev *pcdev, unsigned selector, 1196ac73095SBeniamino Galvani const unsigned **pins, unsigned *num_pins) 1206ac73095SBeniamino Galvani { 1216ac73095SBeniamino Galvani struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); 1226ac73095SBeniamino Galvani 1236ac73095SBeniamino Galvani *pins = pc->data->groups[selector].pins; 1246ac73095SBeniamino Galvani *num_pins = pc->data->groups[selector].num_pins; 1256ac73095SBeniamino Galvani 1266ac73095SBeniamino Galvani return 0; 1276ac73095SBeniamino Galvani } 1286ac73095SBeniamino Galvani 1296ac73095SBeniamino Galvani static void meson_pin_dbg_show(struct pinctrl_dev *pcdev, struct seq_file *s, 1306ac73095SBeniamino Galvani unsigned offset) 1316ac73095SBeniamino Galvani { 1326ac73095SBeniamino Galvani seq_printf(s, " %s", dev_name(pcdev->dev)); 1336ac73095SBeniamino Galvani } 1346ac73095SBeniamino Galvani 1356ac73095SBeniamino Galvani static const struct pinctrl_ops meson_pctrl_ops = { 1366ac73095SBeniamino Galvani .get_groups_count = meson_get_groups_count, 1376ac73095SBeniamino Galvani .get_group_name = meson_get_group_name, 1386ac73095SBeniamino Galvani .get_group_pins = meson_get_group_pins, 1396ac73095SBeniamino Galvani .dt_node_to_map = pinconf_generic_dt_node_to_map_all, 140d32f7fd3SIrina Tirdea .dt_free_map = pinctrl_utils_free_map, 1416ac73095SBeniamino Galvani .pin_dbg_show = meson_pin_dbg_show, 1426ac73095SBeniamino Galvani }; 1436ac73095SBeniamino Galvani 144ce385aa2SJerome Brunet int meson_pmx_get_funcs_count(struct pinctrl_dev *pcdev) 1456ac73095SBeniamino Galvani { 1466ac73095SBeniamino Galvani struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); 1476ac73095SBeniamino Galvani 1486ac73095SBeniamino Galvani return pc->data->num_funcs; 1496ac73095SBeniamino Galvani } 1506ac73095SBeniamino Galvani 151ce385aa2SJerome Brunet const char *meson_pmx_get_func_name(struct pinctrl_dev *pcdev, 1526ac73095SBeniamino Galvani unsigned selector) 1536ac73095SBeniamino Galvani { 1546ac73095SBeniamino Galvani struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); 1556ac73095SBeniamino Galvani 1566ac73095SBeniamino Galvani return pc->data->funcs[selector].name; 1576ac73095SBeniamino Galvani } 1586ac73095SBeniamino Galvani 159ce385aa2SJerome Brunet int meson_pmx_get_groups(struct pinctrl_dev *pcdev, unsigned selector, 1606ac73095SBeniamino Galvani const char * const **groups, 1616ac73095SBeniamino Galvani unsigned * const num_groups) 1626ac73095SBeniamino Galvani { 1636ac73095SBeniamino Galvani struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); 1646ac73095SBeniamino Galvani 1656ac73095SBeniamino Galvani *groups = pc->data->funcs[selector].groups; 1666ac73095SBeniamino Galvani *num_groups = pc->data->funcs[selector].num_groups; 1676ac73095SBeniamino Galvani 1686ac73095SBeniamino Galvani return 0; 1696ac73095SBeniamino Galvani } 1706ac73095SBeniamino Galvani 171b22a7f85SJerome Brunet static int meson_pinconf_set_gpio_bit(struct meson_pinctrl *pc, 172b22a7f85SJerome Brunet unsigned int pin, 173b22a7f85SJerome Brunet unsigned int reg_type, 174b22a7f85SJerome Brunet bool arg) 1756ac73095SBeniamino Galvani { 1766ac73095SBeniamino Galvani struct meson_bank *bank; 1776ac73095SBeniamino Galvani unsigned int reg, bit; 178b22a7f85SJerome Brunet int ret; 1796ac73095SBeniamino Galvani 180db80f0e1SBeniamino Galvani ret = meson_get_bank(pc, pin, &bank); 1816ac73095SBeniamino Galvani if (ret) 1826ac73095SBeniamino Galvani return ret; 1836ac73095SBeniamino Galvani 184b22a7f85SJerome Brunet meson_calc_reg_and_bit(bank, pin, reg_type, ®, &bit); 185b22a7f85SJerome Brunet return regmap_update_bits(pc->reg_gpio, reg, BIT(bit), 186b22a7f85SJerome Brunet arg ? BIT(bit) : 0); 187b22a7f85SJerome Brunet } 188b22a7f85SJerome Brunet 189b22a7f85SJerome Brunet static int meson_pinconf_get_gpio_bit(struct meson_pinctrl *pc, 190b22a7f85SJerome Brunet unsigned int pin, 191b22a7f85SJerome Brunet unsigned int reg_type) 192b22a7f85SJerome Brunet { 193b22a7f85SJerome Brunet struct meson_bank *bank; 194b22a7f85SJerome Brunet unsigned int reg, bit, val; 195b22a7f85SJerome Brunet int ret; 196b22a7f85SJerome Brunet 197b22a7f85SJerome Brunet ret = meson_get_bank(pc, pin, &bank); 198b22a7f85SJerome Brunet if (ret) 199b22a7f85SJerome Brunet return ret; 200b22a7f85SJerome Brunet 201b22a7f85SJerome Brunet meson_calc_reg_and_bit(bank, pin, reg_type, ®, &bit); 202b22a7f85SJerome Brunet ret = regmap_read(pc->reg_gpio, reg, &val); 203b22a7f85SJerome Brunet if (ret) 204b22a7f85SJerome Brunet return ret; 205b22a7f85SJerome Brunet 206b22a7f85SJerome Brunet return BIT(bit) & val ? 1 : 0; 207b22a7f85SJerome Brunet } 208b22a7f85SJerome Brunet 209b22a7f85SJerome Brunet static int meson_pinconf_set_output(struct meson_pinctrl *pc, 210b22a7f85SJerome Brunet unsigned int pin, 211b22a7f85SJerome Brunet bool out) 212b22a7f85SJerome Brunet { 213b22a7f85SJerome Brunet return meson_pinconf_set_gpio_bit(pc, pin, REG_DIR, !out); 214b22a7f85SJerome Brunet } 215b22a7f85SJerome Brunet 216b22a7f85SJerome Brunet static int meson_pinconf_get_output(struct meson_pinctrl *pc, 217b22a7f85SJerome Brunet unsigned int pin) 218b22a7f85SJerome Brunet { 219b22a7f85SJerome Brunet int ret = meson_pinconf_get_gpio_bit(pc, pin, REG_DIR); 220b22a7f85SJerome Brunet 221b22a7f85SJerome Brunet if (ret < 0) 222b22a7f85SJerome Brunet return ret; 223b22a7f85SJerome Brunet 224b22a7f85SJerome Brunet return !ret; 225b22a7f85SJerome Brunet } 226b22a7f85SJerome Brunet 227b22a7f85SJerome Brunet static int meson_pinconf_set_drive(struct meson_pinctrl *pc, 228b22a7f85SJerome Brunet unsigned int pin, 229b22a7f85SJerome Brunet bool high) 230b22a7f85SJerome Brunet { 231b22a7f85SJerome Brunet return meson_pinconf_set_gpio_bit(pc, pin, REG_OUT, high); 232b22a7f85SJerome Brunet } 233b22a7f85SJerome Brunet 234b22a7f85SJerome Brunet static int meson_pinconf_get_drive(struct meson_pinctrl *pc, 235b22a7f85SJerome Brunet unsigned int pin) 236b22a7f85SJerome Brunet { 237b22a7f85SJerome Brunet return meson_pinconf_get_gpio_bit(pc, pin, REG_OUT); 238b22a7f85SJerome Brunet } 239b22a7f85SJerome Brunet 240b22a7f85SJerome Brunet static int meson_pinconf_set_output_drive(struct meson_pinctrl *pc, 241b22a7f85SJerome Brunet unsigned int pin, 242b22a7f85SJerome Brunet bool high) 243b22a7f85SJerome Brunet { 244b22a7f85SJerome Brunet int ret; 245b22a7f85SJerome Brunet 246b22a7f85SJerome Brunet ret = meson_pinconf_set_output(pc, pin, true); 247b22a7f85SJerome Brunet if (ret) 248b22a7f85SJerome Brunet return ret; 249b22a7f85SJerome Brunet 250b22a7f85SJerome Brunet return meson_pinconf_set_drive(pc, pin, high); 251b22a7f85SJerome Brunet } 252b22a7f85SJerome Brunet 2539959d9a7SGuillaume La Roque static int meson_pinconf_disable_bias(struct meson_pinctrl *pc, 2549959d9a7SGuillaume La Roque unsigned int pin) 2556ac73095SBeniamino Galvani { 2566ac73095SBeniamino Galvani struct meson_bank *bank; 2579959d9a7SGuillaume La Roque unsigned int reg, bit = 0; 2589959d9a7SGuillaume La Roque int ret; 2596ac73095SBeniamino Galvani 2606ac73095SBeniamino Galvani ret = meson_get_bank(pc, pin, &bank); 2616ac73095SBeniamino Galvani if (ret) 2626ac73095SBeniamino Galvani return ret; 2636ac73095SBeniamino Galvani 2649959d9a7SGuillaume La Roque meson_calc_reg_and_bit(bank, pin, REG_PULLEN, ®, &bit); 2659959d9a7SGuillaume La Roque ret = regmap_update_bits(pc->reg_pullen, reg, BIT(bit), 0); 2669959d9a7SGuillaume La Roque if (ret) 2679959d9a7SGuillaume La Roque return ret; 2689959d9a7SGuillaume La Roque 2699959d9a7SGuillaume La Roque return 0; 2709959d9a7SGuillaume La Roque } 2719959d9a7SGuillaume La Roque 2729959d9a7SGuillaume La Roque static int meson_pinconf_enable_bias(struct meson_pinctrl *pc, unsigned int pin, 2739959d9a7SGuillaume La Roque bool pull_up) 2749959d9a7SGuillaume La Roque { 2759959d9a7SGuillaume La Roque struct meson_bank *bank; 2769959d9a7SGuillaume La Roque unsigned int reg, bit, val = 0; 2779959d9a7SGuillaume La Roque int ret; 2789959d9a7SGuillaume La Roque 2799959d9a7SGuillaume La Roque ret = meson_get_bank(pc, pin, &bank); 2809959d9a7SGuillaume La Roque if (ret) 2819959d9a7SGuillaume La Roque return ret; 2829959d9a7SGuillaume La Roque 2839959d9a7SGuillaume La Roque meson_calc_reg_and_bit(bank, pin, REG_PULL, ®, &bit); 2849959d9a7SGuillaume La Roque if (pull_up) 2859959d9a7SGuillaume La Roque val = BIT(bit); 2869959d9a7SGuillaume La Roque 2879959d9a7SGuillaume La Roque ret = regmap_update_bits(pc->reg_pull, reg, BIT(bit), val); 2889959d9a7SGuillaume La Roque if (ret) 2899959d9a7SGuillaume La Roque return ret; 2909959d9a7SGuillaume La Roque 2919959d9a7SGuillaume La Roque meson_calc_reg_and_bit(bank, pin, REG_PULLEN, ®, &bit); 2929959d9a7SGuillaume La Roque ret = regmap_update_bits(pc->reg_pullen, reg, BIT(bit), BIT(bit)); 2939959d9a7SGuillaume La Roque if (ret) 2949959d9a7SGuillaume La Roque return ret; 2959959d9a7SGuillaume La Roque 2969959d9a7SGuillaume La Roque return 0; 2979959d9a7SGuillaume La Roque } 2989959d9a7SGuillaume La Roque 2996ea3e3bbSGuillaume La Roque static int meson_pinconf_set_drive_strength(struct meson_pinctrl *pc, 3006ea3e3bbSGuillaume La Roque unsigned int pin, 3016ea3e3bbSGuillaume La Roque u16 drive_strength_ua) 3026ea3e3bbSGuillaume La Roque { 3036ea3e3bbSGuillaume La Roque struct meson_bank *bank; 3046ea3e3bbSGuillaume La Roque unsigned int reg, bit, ds_val; 3056ea3e3bbSGuillaume La Roque int ret; 3066ea3e3bbSGuillaume La Roque 3076ea3e3bbSGuillaume La Roque if (!pc->reg_ds) { 3086ea3e3bbSGuillaume La Roque dev_err(pc->dev, "drive-strength not supported\n"); 3096ea3e3bbSGuillaume La Roque return -ENOTSUPP; 3106ea3e3bbSGuillaume La Roque } 3116ea3e3bbSGuillaume La Roque 3126ea3e3bbSGuillaume La Roque ret = meson_get_bank(pc, pin, &bank); 3136ea3e3bbSGuillaume La Roque if (ret) 3146ea3e3bbSGuillaume La Roque return ret; 3156ea3e3bbSGuillaume La Roque 3166ea3e3bbSGuillaume La Roque meson_calc_reg_and_bit(bank, pin, REG_DS, ®, &bit); 3176ea3e3bbSGuillaume La Roque bit = bit << 1; 3186ea3e3bbSGuillaume La Roque 3196ea3e3bbSGuillaume La Roque if (drive_strength_ua <= 500) { 3206ea3e3bbSGuillaume La Roque ds_val = MESON_PINCONF_DRV_500UA; 3216ea3e3bbSGuillaume La Roque } else if (drive_strength_ua <= 2500) { 3226ea3e3bbSGuillaume La Roque ds_val = MESON_PINCONF_DRV_2500UA; 3236ea3e3bbSGuillaume La Roque } else if (drive_strength_ua <= 3000) { 3246ea3e3bbSGuillaume La Roque ds_val = MESON_PINCONF_DRV_3000UA; 3256ea3e3bbSGuillaume La Roque } else if (drive_strength_ua <= 4000) { 3266ea3e3bbSGuillaume La Roque ds_val = MESON_PINCONF_DRV_4000UA; 3276ea3e3bbSGuillaume La Roque } else { 3286ea3e3bbSGuillaume La Roque dev_warn_once(pc->dev, 3296ea3e3bbSGuillaume La Roque "pin %u: invalid drive-strength : %d , default to 4mA\n", 3306ea3e3bbSGuillaume La Roque pin, drive_strength_ua); 3316ea3e3bbSGuillaume La Roque ds_val = MESON_PINCONF_DRV_4000UA; 3326ea3e3bbSGuillaume La Roque } 3336ea3e3bbSGuillaume La Roque 3346ea3e3bbSGuillaume La Roque ret = regmap_update_bits(pc->reg_ds, reg, 0x3 << bit, ds_val << bit); 3356ea3e3bbSGuillaume La Roque if (ret) 3366ea3e3bbSGuillaume La Roque return ret; 3376ea3e3bbSGuillaume La Roque 3386ea3e3bbSGuillaume La Roque return 0; 3396ea3e3bbSGuillaume La Roque } 3406ea3e3bbSGuillaume La Roque 3419959d9a7SGuillaume La Roque static int meson_pinconf_set(struct pinctrl_dev *pcdev, unsigned int pin, 3429959d9a7SGuillaume La Roque unsigned long *configs, unsigned num_configs) 3439959d9a7SGuillaume La Roque { 3449959d9a7SGuillaume La Roque struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); 3459959d9a7SGuillaume La Roque enum pin_config_param param; 346b22a7f85SJerome Brunet unsigned int arg = 0; 3479959d9a7SGuillaume La Roque int i, ret; 3489959d9a7SGuillaume La Roque 3496ac73095SBeniamino Galvani for (i = 0; i < num_configs; i++) { 3506ac73095SBeniamino Galvani param = pinconf_to_config_param(configs[i]); 3516ac73095SBeniamino Galvani 3526ac73095SBeniamino Galvani switch (param) { 353b22a7f85SJerome Brunet case PIN_CONFIG_DRIVE_STRENGTH_UA: 354b22a7f85SJerome Brunet case PIN_CONFIG_OUTPUT_ENABLE: 355b22a7f85SJerome Brunet case PIN_CONFIG_OUTPUT: 356b22a7f85SJerome Brunet arg = pinconf_to_config_argument(configs[i]); 357b22a7f85SJerome Brunet break; 3586ac73095SBeniamino Galvani 359b22a7f85SJerome Brunet default: 360b22a7f85SJerome Brunet break; 361b22a7f85SJerome Brunet } 362b22a7f85SJerome Brunet 363b22a7f85SJerome Brunet switch (param) { 3646ac73095SBeniamino Galvani case PIN_CONFIG_BIAS_DISABLE: 3659959d9a7SGuillaume La Roque ret = meson_pinconf_disable_bias(pc, pin); 3666ac73095SBeniamino Galvani break; 3676ac73095SBeniamino Galvani case PIN_CONFIG_BIAS_PULL_UP: 3689959d9a7SGuillaume La Roque ret = meson_pinconf_enable_bias(pc, pin, true); 3696ac73095SBeniamino Galvani break; 3706ac73095SBeniamino Galvani case PIN_CONFIG_BIAS_PULL_DOWN: 3719959d9a7SGuillaume La Roque ret = meson_pinconf_enable_bias(pc, pin, false); 3726ac73095SBeniamino Galvani break; 3736ea3e3bbSGuillaume La Roque case PIN_CONFIG_DRIVE_STRENGTH_UA: 374b22a7f85SJerome Brunet ret = meson_pinconf_set_drive_strength(pc, pin, arg); 375b22a7f85SJerome Brunet break; 376b22a7f85SJerome Brunet case PIN_CONFIG_OUTPUT_ENABLE: 377b22a7f85SJerome Brunet ret = meson_pinconf_set_output(pc, pin, arg); 378b22a7f85SJerome Brunet break; 379b22a7f85SJerome Brunet case PIN_CONFIG_OUTPUT: 380b22a7f85SJerome Brunet ret = meson_pinconf_set_output_drive(pc, pin, arg); 3816ac73095SBeniamino Galvani break; 3826ac73095SBeniamino Galvani default: 383b22a7f85SJerome Brunet ret = -ENOTSUPP; 3846ac73095SBeniamino Galvani } 385b22a7f85SJerome Brunet 386b22a7f85SJerome Brunet if (ret) 387b22a7f85SJerome Brunet return ret; 3886ac73095SBeniamino Galvani } 3896ac73095SBeniamino Galvani 3906ac73095SBeniamino Galvani return 0; 3916ac73095SBeniamino Galvani } 3926ac73095SBeniamino Galvani 3936ac73095SBeniamino Galvani static int meson_pinconf_get_pull(struct meson_pinctrl *pc, unsigned int pin) 3946ac73095SBeniamino Galvani { 3956ac73095SBeniamino Galvani struct meson_bank *bank; 3966ac73095SBeniamino Galvani unsigned int reg, bit, val; 3976ac73095SBeniamino Galvani int ret, conf; 3986ac73095SBeniamino Galvani 399db80f0e1SBeniamino Galvani ret = meson_get_bank(pc, pin, &bank); 4006ac73095SBeniamino Galvani if (ret) 4016ac73095SBeniamino Galvani return ret; 4026ac73095SBeniamino Galvani 4036ac73095SBeniamino Galvani meson_calc_reg_and_bit(bank, pin, REG_PULLEN, ®, &bit); 4046ac73095SBeniamino Galvani 405db80f0e1SBeniamino Galvani ret = regmap_read(pc->reg_pullen, reg, &val); 4066ac73095SBeniamino Galvani if (ret) 4076ac73095SBeniamino Galvani return ret; 4086ac73095SBeniamino Galvani 4096ac73095SBeniamino Galvani if (!(val & BIT(bit))) { 4106ac73095SBeniamino Galvani conf = PIN_CONFIG_BIAS_DISABLE; 4116ac73095SBeniamino Galvani } else { 4126ac73095SBeniamino Galvani meson_calc_reg_and_bit(bank, pin, REG_PULL, ®, &bit); 4136ac73095SBeniamino Galvani 414db80f0e1SBeniamino Galvani ret = regmap_read(pc->reg_pull, reg, &val); 4156ac73095SBeniamino Galvani if (ret) 4166ac73095SBeniamino Galvani return ret; 4176ac73095SBeniamino Galvani 4186ac73095SBeniamino Galvani if (val & BIT(bit)) 4196ac73095SBeniamino Galvani conf = PIN_CONFIG_BIAS_PULL_UP; 4206ac73095SBeniamino Galvani else 4216ac73095SBeniamino Galvani conf = PIN_CONFIG_BIAS_PULL_DOWN; 4226ac73095SBeniamino Galvani } 4236ac73095SBeniamino Galvani 4246ac73095SBeniamino Galvani return conf; 4256ac73095SBeniamino Galvani } 4266ac73095SBeniamino Galvani 4276ea3e3bbSGuillaume La Roque static int meson_pinconf_get_drive_strength(struct meson_pinctrl *pc, 4286ea3e3bbSGuillaume La Roque unsigned int pin, 4296ea3e3bbSGuillaume La Roque u16 *drive_strength_ua) 4306ea3e3bbSGuillaume La Roque { 4316ea3e3bbSGuillaume La Roque struct meson_bank *bank; 4326ea3e3bbSGuillaume La Roque unsigned int reg, bit; 4336ea3e3bbSGuillaume La Roque unsigned int val; 4346ea3e3bbSGuillaume La Roque int ret; 4356ea3e3bbSGuillaume La Roque 4366ea3e3bbSGuillaume La Roque if (!pc->reg_ds) 4376ea3e3bbSGuillaume La Roque return -ENOTSUPP; 4386ea3e3bbSGuillaume La Roque 4396ea3e3bbSGuillaume La Roque ret = meson_get_bank(pc, pin, &bank); 4406ea3e3bbSGuillaume La Roque if (ret) 4416ea3e3bbSGuillaume La Roque return ret; 4426ea3e3bbSGuillaume La Roque 4436ea3e3bbSGuillaume La Roque meson_calc_reg_and_bit(bank, pin, REG_DS, ®, &bit); 44435c60be2SQianggui Song bit = bit << 1; 4456ea3e3bbSGuillaume La Roque 4466ea3e3bbSGuillaume La Roque ret = regmap_read(pc->reg_ds, reg, &val); 4476ea3e3bbSGuillaume La Roque if (ret) 4486ea3e3bbSGuillaume La Roque return ret; 4496ea3e3bbSGuillaume La Roque 4506ea3e3bbSGuillaume La Roque switch ((val >> bit) & 0x3) { 4516ea3e3bbSGuillaume La Roque case MESON_PINCONF_DRV_500UA: 4526ea3e3bbSGuillaume La Roque *drive_strength_ua = 500; 4536ea3e3bbSGuillaume La Roque break; 4546ea3e3bbSGuillaume La Roque case MESON_PINCONF_DRV_2500UA: 4556ea3e3bbSGuillaume La Roque *drive_strength_ua = 2500; 4566ea3e3bbSGuillaume La Roque break; 4576ea3e3bbSGuillaume La Roque case MESON_PINCONF_DRV_3000UA: 4586ea3e3bbSGuillaume La Roque *drive_strength_ua = 3000; 4596ea3e3bbSGuillaume La Roque break; 4606ea3e3bbSGuillaume La Roque case MESON_PINCONF_DRV_4000UA: 4616ea3e3bbSGuillaume La Roque *drive_strength_ua = 4000; 4626ea3e3bbSGuillaume La Roque break; 4636ea3e3bbSGuillaume La Roque default: 4646ea3e3bbSGuillaume La Roque return -EINVAL; 4656ea3e3bbSGuillaume La Roque } 4666ea3e3bbSGuillaume La Roque 4676ea3e3bbSGuillaume La Roque return 0; 4686ea3e3bbSGuillaume La Roque } 4696ea3e3bbSGuillaume La Roque 4706ac73095SBeniamino Galvani static int meson_pinconf_get(struct pinctrl_dev *pcdev, unsigned int pin, 4716ac73095SBeniamino Galvani unsigned long *config) 4726ac73095SBeniamino Galvani { 4736ac73095SBeniamino Galvani struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); 4746ac73095SBeniamino Galvani enum pin_config_param param = pinconf_to_config_param(*config); 4756ac73095SBeniamino Galvani u16 arg; 4766ea3e3bbSGuillaume La Roque int ret; 4776ac73095SBeniamino Galvani 4786ac73095SBeniamino Galvani switch (param) { 4796ac73095SBeniamino Galvani case PIN_CONFIG_BIAS_DISABLE: 4806ac73095SBeniamino Galvani case PIN_CONFIG_BIAS_PULL_DOWN: 4816ac73095SBeniamino Galvani case PIN_CONFIG_BIAS_PULL_UP: 4826ac73095SBeniamino Galvani if (meson_pinconf_get_pull(pc, pin) == param) 4836ac73095SBeniamino Galvani arg = 1; 4846ac73095SBeniamino Galvani else 4856ac73095SBeniamino Galvani return -EINVAL; 4866ac73095SBeniamino Galvani break; 4876ea3e3bbSGuillaume La Roque case PIN_CONFIG_DRIVE_STRENGTH_UA: 4886ea3e3bbSGuillaume La Roque ret = meson_pinconf_get_drive_strength(pc, pin, &arg); 4896ea3e3bbSGuillaume La Roque if (ret) 4906ea3e3bbSGuillaume La Roque return ret; 4916ea3e3bbSGuillaume La Roque break; 492b22a7f85SJerome Brunet case PIN_CONFIG_OUTPUT_ENABLE: 493b22a7f85SJerome Brunet ret = meson_pinconf_get_output(pc, pin); 494b22a7f85SJerome Brunet if (ret <= 0) 495b22a7f85SJerome Brunet return -EINVAL; 496b22a7f85SJerome Brunet arg = 1; 497b22a7f85SJerome Brunet break; 498b22a7f85SJerome Brunet case PIN_CONFIG_OUTPUT: 499b22a7f85SJerome Brunet ret = meson_pinconf_get_output(pc, pin); 500b22a7f85SJerome Brunet if (ret <= 0) 501b22a7f85SJerome Brunet return -EINVAL; 502b22a7f85SJerome Brunet 503b22a7f85SJerome Brunet ret = meson_pinconf_get_drive(pc, pin); 504b22a7f85SJerome Brunet if (ret < 0) 505b22a7f85SJerome Brunet return -EINVAL; 506b22a7f85SJerome Brunet 507b22a7f85SJerome Brunet arg = ret; 508b22a7f85SJerome Brunet break; 509b22a7f85SJerome Brunet 5106ac73095SBeniamino Galvani default: 5116ac73095SBeniamino Galvani return -ENOTSUPP; 5126ac73095SBeniamino Galvani } 5136ac73095SBeniamino Galvani 5146ac73095SBeniamino Galvani *config = pinconf_to_config_packed(param, arg); 5156ac73095SBeniamino Galvani dev_dbg(pc->dev, "pinconf for pin %u is %lu\n", pin, *config); 5166ac73095SBeniamino Galvani 5176ac73095SBeniamino Galvani return 0; 5186ac73095SBeniamino Galvani } 5196ac73095SBeniamino Galvani 5206ac73095SBeniamino Galvani static int meson_pinconf_group_set(struct pinctrl_dev *pcdev, 5216ac73095SBeniamino Galvani unsigned int num_group, 5226ac73095SBeniamino Galvani unsigned long *configs, unsigned num_configs) 5236ac73095SBeniamino Galvani { 5246ac73095SBeniamino Galvani struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); 5256ac73095SBeniamino Galvani struct meson_pmx_group *group = &pc->data->groups[num_group]; 5266ac73095SBeniamino Galvani int i; 5276ac73095SBeniamino Galvani 5286ac73095SBeniamino Galvani dev_dbg(pc->dev, "set pinconf for group %s\n", group->name); 5296ac73095SBeniamino Galvani 5306ac73095SBeniamino Galvani for (i = 0; i < group->num_pins; i++) { 5316ac73095SBeniamino Galvani meson_pinconf_set(pcdev, group->pins[i], configs, 5326ac73095SBeniamino Galvani num_configs); 5336ac73095SBeniamino Galvani } 5346ac73095SBeniamino Galvani 5356ac73095SBeniamino Galvani return 0; 5366ac73095SBeniamino Galvani } 5376ac73095SBeniamino Galvani 5386ac73095SBeniamino Galvani static int meson_pinconf_group_get(struct pinctrl_dev *pcdev, 5396ac73095SBeniamino Galvani unsigned int group, unsigned long *config) 5406ac73095SBeniamino Galvani { 5411ffbf50bSJerome Brunet return -ENOTSUPP; 5426ac73095SBeniamino Galvani } 5436ac73095SBeniamino Galvani 5446ac73095SBeniamino Galvani static const struct pinconf_ops meson_pinconf_ops = { 5456ac73095SBeniamino Galvani .pin_config_get = meson_pinconf_get, 5466ac73095SBeniamino Galvani .pin_config_set = meson_pinconf_set, 5476ac73095SBeniamino Galvani .pin_config_group_get = meson_pinconf_group_get, 5486ac73095SBeniamino Galvani .pin_config_group_set = meson_pinconf_group_set, 5496ac73095SBeniamino Galvani .is_generic = true, 5506ac73095SBeniamino Galvani }; 5516ac73095SBeniamino Galvani 552*ef1d0bceSMartin Blumenstingl static int meson_gpio_get_direction(struct gpio_chip *chip, unsigned gpio) 553*ef1d0bceSMartin Blumenstingl { 554*ef1d0bceSMartin Blumenstingl struct meson_pinctrl *pc = gpiochip_get_data(chip); 555*ef1d0bceSMartin Blumenstingl int ret; 556*ef1d0bceSMartin Blumenstingl 557*ef1d0bceSMartin Blumenstingl ret = meson_pinconf_get_output(pc, gpio); 558*ef1d0bceSMartin Blumenstingl if (ret < 0) 559*ef1d0bceSMartin Blumenstingl return ret; 560*ef1d0bceSMartin Blumenstingl 561*ef1d0bceSMartin Blumenstingl return ret ? GPIO_LINE_DIRECTION_OUT : GPIO_LINE_DIRECTION_IN; 562*ef1d0bceSMartin Blumenstingl } 563*ef1d0bceSMartin Blumenstingl 5646ac73095SBeniamino Galvani static int meson_gpio_direction_input(struct gpio_chip *chip, unsigned gpio) 5656ac73095SBeniamino Galvani { 566b22a7f85SJerome Brunet return meson_pinconf_set_output(gpiochip_get_data(chip), gpio, false); 5676ac73095SBeniamino Galvani } 5686ac73095SBeniamino Galvani 5696ac73095SBeniamino Galvani static int meson_gpio_direction_output(struct gpio_chip *chip, unsigned gpio, 5706ac73095SBeniamino Galvani int value) 5716ac73095SBeniamino Galvani { 572b22a7f85SJerome Brunet return meson_pinconf_set_output_drive(gpiochip_get_data(chip), 573b22a7f85SJerome Brunet gpio, value); 5746ac73095SBeniamino Galvani } 5756ac73095SBeniamino Galvani 5766ac73095SBeniamino Galvani static void meson_gpio_set(struct gpio_chip *chip, unsigned gpio, int value) 5776ac73095SBeniamino Galvani { 578b22a7f85SJerome Brunet meson_pinconf_set_drive(gpiochip_get_data(chip), gpio, value); 5796ac73095SBeniamino Galvani } 5806ac73095SBeniamino Galvani 5816ac73095SBeniamino Galvani static int meson_gpio_get(struct gpio_chip *chip, unsigned gpio) 5826ac73095SBeniamino Galvani { 583db80f0e1SBeniamino Galvani struct meson_pinctrl *pc = gpiochip_get_data(chip); 58470e5ecb1SJerome Brunet unsigned int reg, bit, val; 5856ac73095SBeniamino Galvani struct meson_bank *bank; 5866ac73095SBeniamino Galvani int ret; 5876ac73095SBeniamino Galvani 58870e5ecb1SJerome Brunet ret = meson_get_bank(pc, gpio, &bank); 5896ac73095SBeniamino Galvani if (ret) 5906ac73095SBeniamino Galvani return ret; 5916ac73095SBeniamino Galvani 59270e5ecb1SJerome Brunet meson_calc_reg_and_bit(bank, gpio, REG_IN, ®, &bit); 593db80f0e1SBeniamino Galvani regmap_read(pc->reg_gpio, reg, &val); 5946ac73095SBeniamino Galvani 5956ac73095SBeniamino Galvani return !!(val & BIT(bit)); 5966ac73095SBeniamino Galvani } 5976ac73095SBeniamino Galvani 5986ac73095SBeniamino Galvani static int meson_gpiolib_register(struct meson_pinctrl *pc) 5996ac73095SBeniamino Galvani { 6009dab1868SCarlo Caione int ret; 6016ac73095SBeniamino Galvani 602db80f0e1SBeniamino Galvani pc->chip.label = pc->data->name; 603db80f0e1SBeniamino Galvani pc->chip.parent = pc->dev; 604634e40b0SJerome Brunet pc->chip.request = gpiochip_generic_request; 605634e40b0SJerome Brunet pc->chip.free = gpiochip_generic_free; 606*ef1d0bceSMartin Blumenstingl pc->chip.get_direction = meson_gpio_get_direction; 607db80f0e1SBeniamino Galvani pc->chip.direction_input = meson_gpio_direction_input; 608db80f0e1SBeniamino Galvani pc->chip.direction_output = meson_gpio_direction_output; 609db80f0e1SBeniamino Galvani pc->chip.get = meson_gpio_get; 610db80f0e1SBeniamino Galvani pc->chip.set = meson_gpio_set; 611634e40b0SJerome Brunet pc->chip.base = -1; 612db80f0e1SBeniamino Galvani pc->chip.ngpio = pc->data->num_pins; 613db80f0e1SBeniamino Galvani pc->chip.can_sleep = false; 614db80f0e1SBeniamino Galvani pc->chip.of_node = pc->of_node; 615db80f0e1SBeniamino Galvani pc->chip.of_gpio_n_cells = 2; 6166ac73095SBeniamino Galvani 617db80f0e1SBeniamino Galvani ret = gpiochip_add_data(&pc->chip, pc); 6186ac73095SBeniamino Galvani if (ret) { 6196ac73095SBeniamino Galvani dev_err(pc->dev, "can't add gpio chip %s\n", 620db80f0e1SBeniamino Galvani pc->data->name); 621c7fc5fbaSNeil Armstrong return ret; 6226ac73095SBeniamino Galvani } 6236ac73095SBeniamino Galvani 6246ac73095SBeniamino Galvani return 0; 6256ac73095SBeniamino Galvani } 6266ac73095SBeniamino Galvani 6276ac73095SBeniamino Galvani static struct regmap_config meson_regmap_config = { 6286ac73095SBeniamino Galvani .reg_bits = 32, 6296ac73095SBeniamino Galvani .val_bits = 32, 6306ac73095SBeniamino Galvani .reg_stride = 4, 6316ac73095SBeniamino Galvani }; 6326ac73095SBeniamino Galvani 6336ac73095SBeniamino Galvani static struct regmap *meson_map_resource(struct meson_pinctrl *pc, 6346ac73095SBeniamino Galvani struct device_node *node, char *name) 6356ac73095SBeniamino Galvani { 6366ac73095SBeniamino Galvani struct resource res; 6376ac73095SBeniamino Galvani void __iomem *base; 6386ac73095SBeniamino Galvani int i; 6396ac73095SBeniamino Galvani 6406ac73095SBeniamino Galvani i = of_property_match_string(node, "reg-names", name); 6416ac73095SBeniamino Galvani if (of_address_to_resource(node, i, &res)) 642fd422964SQianggui Song return NULL; 6436ac73095SBeniamino Galvani 6446ac73095SBeniamino Galvani base = devm_ioremap_resource(pc->dev, &res); 6456ac73095SBeniamino Galvani if (IS_ERR(base)) 6466ac73095SBeniamino Galvani return ERR_CAST(base); 6476ac73095SBeniamino Galvani 6486ac73095SBeniamino Galvani meson_regmap_config.max_register = resource_size(&res) - 4; 6496ac73095SBeniamino Galvani meson_regmap_config.name = devm_kasprintf(pc->dev, GFP_KERNEL, 65094f4e54cSRob Herring "%pOFn-%s", node, 6516ac73095SBeniamino Galvani name); 6526ac73095SBeniamino Galvani if (!meson_regmap_config.name) 6536ac73095SBeniamino Galvani return ERR_PTR(-ENOMEM); 6546ac73095SBeniamino Galvani 6556ac73095SBeniamino Galvani return devm_regmap_init_mmio(pc->dev, base, &meson_regmap_config); 6566ac73095SBeniamino Galvani } 6576ac73095SBeniamino Galvani 6586ac73095SBeniamino Galvani static int meson_pinctrl_parse_dt(struct meson_pinctrl *pc, 6596ac73095SBeniamino Galvani struct device_node *node) 6606ac73095SBeniamino Galvani { 661db80f0e1SBeniamino Galvani struct device_node *np, *gpio_np = NULL; 6626ac73095SBeniamino Galvani 6636ac73095SBeniamino Galvani for_each_child_of_node(node, np) { 6646ac73095SBeniamino Galvani if (!of_find_property(np, "gpio-controller", NULL)) 6656ac73095SBeniamino Galvani continue; 666db80f0e1SBeniamino Galvani if (gpio_np) { 667db80f0e1SBeniamino Galvani dev_err(pc->dev, "multiple gpio nodes\n"); 6682ff110bbSNishka Dasgupta of_node_put(np); 669db80f0e1SBeniamino Galvani return -EINVAL; 670db80f0e1SBeniamino Galvani } 671db80f0e1SBeniamino Galvani gpio_np = np; 6726ac73095SBeniamino Galvani } 6736ac73095SBeniamino Galvani 674db80f0e1SBeniamino Galvani if (!gpio_np) { 675db80f0e1SBeniamino Galvani dev_err(pc->dev, "no gpio node found\n"); 6766ac73095SBeniamino Galvani return -EINVAL; 6776ac73095SBeniamino Galvani } 6786ac73095SBeniamino Galvani 679db80f0e1SBeniamino Galvani pc->of_node = gpio_np; 6806ac73095SBeniamino Galvani 681db80f0e1SBeniamino Galvani pc->reg_mux = meson_map_resource(pc, gpio_np, "mux"); 682fd422964SQianggui Song if (IS_ERR_OR_NULL(pc->reg_mux)) { 6836ac73095SBeniamino Galvani dev_err(pc->dev, "mux registers not found\n"); 684fd422964SQianggui Song return pc->reg_mux ? PTR_ERR(pc->reg_mux) : -ENOENT; 6856ac73095SBeniamino Galvani } 6866ac73095SBeniamino Galvani 687db80f0e1SBeniamino Galvani pc->reg_gpio = meson_map_resource(pc, gpio_np, "gpio"); 688fd422964SQianggui Song if (IS_ERR_OR_NULL(pc->reg_gpio)) { 6896ac73095SBeniamino Galvani dev_err(pc->dev, "gpio registers not found\n"); 690fd422964SQianggui Song return pc->reg_gpio ? PTR_ERR(pc->reg_gpio) : -ENOENT; 6916ac73095SBeniamino Galvani } 6926ac73095SBeniamino Galvani 693e66dd48eSXingyu Chen pc->reg_pull = meson_map_resource(pc, gpio_np, "pull"); 694e66dd48eSXingyu Chen if (IS_ERR(pc->reg_pull)) 695fd422964SQianggui Song pc->reg_pull = NULL; 696e66dd48eSXingyu Chen 697e66dd48eSXingyu Chen pc->reg_pullen = meson_map_resource(pc, gpio_np, "pull-enable"); 698e66dd48eSXingyu Chen if (IS_ERR(pc->reg_pullen)) 699fd422964SQianggui Song pc->reg_pullen = NULL; 700e66dd48eSXingyu Chen 70164856974SJerome Brunet pc->reg_ds = meson_map_resource(pc, gpio_np, "ds"); 70264856974SJerome Brunet if (IS_ERR(pc->reg_ds)) { 70364856974SJerome Brunet dev_dbg(pc->dev, "ds registers not found - skipping\n"); 70464856974SJerome Brunet pc->reg_ds = NULL; 70564856974SJerome Brunet } 70664856974SJerome Brunet 707fd422964SQianggui Song if (pc->data->parse_dt) 708fd422964SQianggui Song return pc->data->parse_dt(pc); 709fd422964SQianggui Song 710fd422964SQianggui Song return 0; 711fd422964SQianggui Song } 712fd422964SQianggui Song 713fd422964SQianggui Song int meson8_aobus_parse_dt_extra(struct meson_pinctrl *pc) 714fd422964SQianggui Song { 715fd422964SQianggui Song if (!pc->reg_pull) 716fd422964SQianggui Song return -EINVAL; 717fd422964SQianggui Song 718fd422964SQianggui Song pc->reg_pullen = pc->reg_pull; 719fd422964SQianggui Song 7206ac73095SBeniamino Galvani return 0; 7216ac73095SBeniamino Galvani } 7226ac73095SBeniamino Galvani 723dabad1ffSQianggui Song int meson_a1_parse_dt_extra(struct meson_pinctrl *pc) 724dabad1ffSQianggui Song { 725dabad1ffSQianggui Song pc->reg_pull = pc->reg_gpio; 726dabad1ffSQianggui Song pc->reg_pullen = pc->reg_gpio; 727dabad1ffSQianggui Song pc->reg_ds = pc->reg_gpio; 728dabad1ffSQianggui Song 729dabad1ffSQianggui Song return 0; 730dabad1ffSQianggui Song } 731dabad1ffSQianggui Song 732277d14ebSJerome Brunet int meson_pinctrl_probe(struct platform_device *pdev) 7336ac73095SBeniamino Galvani { 7346ac73095SBeniamino Galvani struct device *dev = &pdev->dev; 7356ac73095SBeniamino Galvani struct meson_pinctrl *pc; 7366ac73095SBeniamino Galvani int ret; 7376ac73095SBeniamino Galvani 7386ac73095SBeniamino Galvani pc = devm_kzalloc(dev, sizeof(struct meson_pinctrl), GFP_KERNEL); 7396ac73095SBeniamino Galvani if (!pc) 7406ac73095SBeniamino Galvani return -ENOMEM; 7416ac73095SBeniamino Galvani 7426ac73095SBeniamino Galvani pc->dev = dev; 743277d14ebSJerome Brunet pc->data = (struct meson_pinctrl_data *) of_device_get_match_data(dev); 7446ac73095SBeniamino Galvani 745277d14ebSJerome Brunet ret = meson_pinctrl_parse_dt(pc, dev->of_node); 7466ac73095SBeniamino Galvani if (ret) 7476ac73095SBeniamino Galvani return ret; 7486ac73095SBeniamino Galvani 7496ac73095SBeniamino Galvani pc->desc.name = "pinctrl-meson"; 7506ac73095SBeniamino Galvani pc->desc.owner = THIS_MODULE; 7516ac73095SBeniamino Galvani pc->desc.pctlops = &meson_pctrl_ops; 752ce385aa2SJerome Brunet pc->desc.pmxops = pc->data->pmx_ops; 7536ac73095SBeniamino Galvani pc->desc.confops = &meson_pinconf_ops; 7546ac73095SBeniamino Galvani pc->desc.pins = pc->data->pins; 7556ac73095SBeniamino Galvani pc->desc.npins = pc->data->num_pins; 7566ac73095SBeniamino Galvani 757e649f7ecSLaxman Dewangan pc->pcdev = devm_pinctrl_register(pc->dev, &pc->desc, pc); 758323de9efSMasahiro Yamada if (IS_ERR(pc->pcdev)) { 7596ac73095SBeniamino Galvani dev_err(pc->dev, "can't register pinctrl device"); 760323de9efSMasahiro Yamada return PTR_ERR(pc->pcdev); 7616ac73095SBeniamino Galvani } 7626ac73095SBeniamino Galvani 7635b236d0fSWei Yongjun return meson_gpiolib_register(pc); 7646ac73095SBeniamino Galvani } 765