Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

pinctrl: mediatek: extend struct mtk_pin_desc which per-pin driver depends on

Because the pincrl-mtk-common.c is an implementation for per-pin binding,
its pin descriptor includes more information than pinctrl-mtk-common-v2
so far can support. So, we complement these data before writing a driver
using pincrl-mtk-common-v2.c for per-pin binding. By the way, the size of
struct mtk_pin_desc would be larger than struct pinctrl_pin_desc can hold,
so it's necessary to have a copy before the pins information is being
registered into the core.

Signed-off-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

authored by

Sean Wang and committed by
Linus Walleij
b7d7f9ee 9d9b171c

+62 -20
+20 -8
drivers/pinctrl/mediatek/pinctrl-moore.c
··· 475 475 476 476 desc = (const struct mtk_pin_desc *)&hw->soc->pins[offset]; 477 477 478 - if (desc->eint_n == EINT_NA) 478 + if (desc->eint.eint_n == EINT_NA) 479 479 return -ENOTSUPP; 480 480 481 - return mtk_eint_find_irq(hw->eint, desc->eint_n); 481 + return mtk_eint_find_irq(hw->eint, desc->eint.eint_n); 482 482 } 483 483 484 484 static int mtk_gpio_set_config(struct gpio_chip *chip, unsigned int offset, ··· 492 492 493 493 if (!hw->eint || 494 494 pinconf_to_config_param(config) != PIN_CONFIG_INPUT_DEBOUNCE || 495 - desc->eint_n == EINT_NA) 495 + desc->eint.eint_n == EINT_NA) 496 496 return -ENOTSUPP; 497 497 498 498 debounce = pinconf_to_config_argument(config); 499 499 500 - return mtk_eint_set_debounce(hw->eint, desc->eint_n, debounce); 500 + return mtk_eint_set_debounce(hw->eint, desc->eint.eint_n, debounce); 501 501 } 502 502 503 503 static int mtk_build_gpiochip(struct mtk_pinctrl *hw, struct device_node *np) ··· 593 593 desc = (const struct mtk_pin_desc *)hw->soc->pins; 594 594 595 595 while (i < hw->soc->npins) { 596 - if (desc[i].eint_n == eint_n) 596 + if (desc[i].eint.eint_n == eint_n) 597 597 return desc[i].number; 598 598 i++; 599 599 } ··· 612 612 *gpio_chip = &hw->chip; 613 613 614 614 /* Be greedy to guess first gpio_n is equal to eint_n */ 615 - if (desc[eint_n].eint_n == eint_n) 615 + if (desc[eint_n].eint.eint_n == eint_n) 616 616 *gpio_n = eint_n; 617 617 else 618 618 *gpio_n = mtk_xt_find_eint_num(hw, eint_n); ··· 649 649 desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio_n]; 650 650 651 651 err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_MODE, 652 - hw->soc->eint_m); 652 + desc->eint.eint_m); 653 653 if (err) 654 654 return err; 655 655 ··· 711 711 int mtk_moore_pinctrl_probe(struct platform_device *pdev, 712 712 const struct mtk_pin_soc *soc) 713 713 { 714 + struct pinctrl_pin_desc *pins; 714 715 struct resource *res; 715 716 struct mtk_pinctrl *hw; 716 717 int err, i; ··· 749 748 750 749 hw->nbase = hw->soc->nbase_names; 751 750 751 + /* Copy from internal struct mtk_pin_desc to register to the core */ 752 + pins = devm_kmalloc_array(&pdev->dev, hw->soc->npins, sizeof(*pins), 753 + GFP_KERNEL); 754 + if (IS_ERR(pins)) 755 + return PTR_ERR(pins); 756 + 757 + for (i = 0; i < hw->soc->npins; i++) { 758 + pins[i].number = hw->soc->pins[i].number; 759 + pins[i].name = hw->soc->pins[i].name; 760 + } 761 + 752 762 /* Setup pins descriptions per SoC types */ 753 - mtk_desc.pins = (const struct pinctrl_pin_desc *)hw->soc->pins; 763 + mtk_desc.pins = (const struct pinctrl_pin_desc *)pins; 754 764 mtk_desc.npins = hw->soc->npins; 755 765 mtk_desc.num_custom_params = ARRAY_SIZE(mtk_custom_bindings); 756 766 mtk_desc.custom_params = mtk_custom_bindings;
+6 -2
drivers/pinctrl/mediatek/pinctrl-moore.h
··· 28 28 29 29 #define MTK_RANGE(_a) { .range = (_a), .nranges = ARRAY_SIZE(_a), } 30 30 31 - #define MTK_PIN(_number, _name, _eint_n, _drv_n) { \ 31 + #define MTK_PIN(_number, _name, _eint_m, _eint_n, _drv_n) { \ 32 32 .number = _number, \ 33 33 .name = _name, \ 34 - .eint_n = _eint_n, \ 34 + .eint = { \ 35 + .eint_m = _eint_m, \ 36 + .eint_n = _eint_n, \ 37 + }, \ 35 38 .drv_n = _drv_n, \ 39 + .funcs = NULL, \ 36 40 } 37 41 38 42 #define PINCTRL_PIN_GROUP(name, id) \
+2 -3
drivers/pinctrl/mediatek/pinctrl-mt7622.c
··· 9 9 #include "pinctrl-moore.h" 10 10 11 11 #define MT7622_PIN(_number, _name) \ 12 - MTK_PIN(_number, _name, _number, DRV_GRP0) 12 + MTK_PIN(_number, _name, 1, _number, DRV_GRP0) 13 13 14 14 static const struct mtk_pin_field_calc mt7622_pin_mode_range[] = { 15 15 PIN_FIELD(0, 0, 0x320, 0x10, 16, 4), ··· 758 758 759 759 static const struct mtk_pin_soc mt7622_data = { 760 760 .reg_cal = mt7622_reg_cals, 761 - .pins = (const struct pinctrl_pin_desc *)mt7622_pins, 761 + .pins = mt7622_pins, 762 762 .npins = ARRAY_SIZE(mt7622_pins), 763 763 .grps = mt7622_groups, 764 764 .ngrps = ARRAY_SIZE(mt7622_groups), ··· 766 766 .nfuncs = ARRAY_SIZE(mt7622_functions), 767 767 .eint_hw = &mt7622_eint_hw, 768 768 .gpio_m = 1, 769 - .eint_m = 1, 770 769 .ies_present = false, 771 770 .base_names = mtk_default_register_base_names, 772 771 .nbase_names = ARRAY_SIZE(mtk_default_register_base_names),
+2 -3
drivers/pinctrl/mediatek/pinctrl-mt7623.c
··· 30 30 _x_bits, 16, 1) 31 31 32 32 #define MT7623_PIN(_number, _name, _eint_n, _drv_grp) \ 33 - MTK_PIN(_number, _name, _eint_n, _drv_grp) 33 + MTK_PIN(_number, _name, 0, _eint_n, _drv_grp) 34 34 35 35 static const struct mtk_pin_field_calc mt7623_pin_mode_range[] = { 36 36 PIN_FIELD15(0, 278, 0x760, 0x10, 0, 3), ··· 1373 1373 1374 1374 static struct mtk_pin_soc mt7623_data = { 1375 1375 .reg_cal = mt7623_reg_cals, 1376 - .pins = (const struct pinctrl_pin_desc *)mt7623_pins, 1376 + .pins = mt7623_pins, 1377 1377 .npins = ARRAY_SIZE(mt7623_pins), 1378 1378 .grps = mt7623_groups, 1379 1379 .ngrps = ARRAY_SIZE(mt7623_groups), ··· 1381 1381 .nfuncs = ARRAY_SIZE(mt7623_functions), 1382 1382 .eint_hw = &mt7623_eint_hw, 1383 1383 .gpio_m = 0, 1384 - .eint_m = 0, 1385 1384 .ies_present = true, 1386 1385 .base_names = mtk_default_register_base_names, 1387 1386 .nbase_names = ARRAY_SIZE(mtk_default_register_base_names),
+32 -4
drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h
··· 134 134 }; 135 135 136 136 /** 137 + * struct mtk_func_desc - the structure that providing information 138 + * all the funcs for this pin 139 + * @name: the name of function 140 + * @muxval: the mux to the function 141 + */ 142 + struct mtk_func_desc { 143 + const char *name; 144 + u8 muxval; 145 + }; 146 + 147 + /** 148 + * struct mtk_eint_desc - the structure that providing information 149 + * for eint data per pin 150 + * @eint_m: the eint mux for this pin 151 + * @eitn_n: the eint number for this pin 152 + */ 153 + struct mtk_eint_desc { 154 + u8 eint_m; 155 + u16 eint_n; 156 + }; 157 + 158 + /** 137 159 * struct mtk_pin_desc - the structure that providing information 138 160 * for each pin of chips 139 161 * @number: unique pin number from the global pin number space 140 162 * @name: name for this pin 141 - * @eint_n: the eint number for this pin 163 + * @eint: the eint data for this pin 142 164 * @drv_n: the index with the driving group 165 + * @funcs: all available functions for this pins (only used in 166 + * those drivers compatible to pinctrl-mtk-common.c-like 167 + * ones) 143 168 */ 144 169 struct mtk_pin_desc { 145 170 unsigned int number; 146 171 const char *name; 147 - u16 eint_n; 172 + struct mtk_eint_desc eint; 148 173 u8 drv_n; 174 + struct mtk_func_desc *funcs; 149 175 }; 150 176 151 177 struct mtk_pinctrl; ··· 179 153 /* struct mtk_pin_soc - the structure that holds SoC-specific data */ 180 154 struct mtk_pin_soc { 181 155 const struct mtk_pin_reg_calc *reg_cal; 182 - const struct pinctrl_pin_desc *pins; 156 + const struct mtk_pin_desc *pins; 183 157 unsigned int npins; 184 158 const struct group_desc *grps; 185 159 unsigned int ngrps; ··· 190 164 191 165 /* Specific parameters per SoC */ 192 166 u8 gpio_m; 193 - u8 eint_m; 194 167 bool ies_present; 195 168 const char * const *base_names; 196 169 unsigned int nbase_names; ··· 215 190 int (*adv_pull_get)(struct mtk_pinctrl *hw, 216 191 const struct mtk_pin_desc *desc, bool pullup, 217 192 u32 *val); 193 + 194 + /* Specific driver data */ 195 + void *driver_data; 218 196 }; 219 197 220 198 struct mtk_pinctrl {