summaryrefslogtreecommitdiffstats
path: root/drivers/pinctrl/mediatek
diff options
context:
space:
mode:
authorSean Wang <sean.wang@mediatek.com>2018-09-08 07:07:32 -0400
committerLinus Walleij <linus.walleij@linaro.org>2018-09-18 17:53:22 -0400
commitb7d7f9eeca551f9cf1f6418749cd609d371faf55 (patch)
treebd3acab198ae52c6787d3d6d9ecea0cb632d4d39 /drivers/pinctrl/mediatek
parent9d9b171c6897265c5af870affd83fe3c51f1df76 (diff)
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>
Diffstat (limited to 'drivers/pinctrl/mediatek')
-rw-r--r--drivers/pinctrl/mediatek/pinctrl-moore.c28
-rw-r--r--drivers/pinctrl/mediatek/pinctrl-moore.h8
-rw-r--r--drivers/pinctrl/mediatek/pinctrl-mt7622.c5
-rw-r--r--drivers/pinctrl/mediatek/pinctrl-mt7623.c5
-rw-r--r--drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h36
5 files changed, 62 insertions, 20 deletions
diff --git a/drivers/pinctrl/mediatek/pinctrl-moore.c b/drivers/pinctrl/mediatek/pinctrl-moore.c
index 2817e470c431..f0390b34cae5 100644
--- a/drivers/pinctrl/mediatek/pinctrl-moore.c
+++ b/drivers/pinctrl/mediatek/pinctrl-moore.c
@@ -475,10 +475,10 @@ static int mtk_gpio_to_irq(struct gpio_chip *chip, unsigned int offset)
475 475
476 desc = (const struct mtk_pin_desc *)&hw->soc->pins[offset]; 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 return -ENOTSUPP; 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
484static int mtk_gpio_set_config(struct gpio_chip *chip, unsigned int offset, 484static int mtk_gpio_set_config(struct gpio_chip *chip, unsigned int offset,
@@ -492,12 +492,12 @@ static int mtk_gpio_set_config(struct gpio_chip *chip, unsigned int offset,
492 492
493 if (!hw->eint || 493 if (!hw->eint ||
494 pinconf_to_config_param(config) != PIN_CONFIG_INPUT_DEBOUNCE || 494 pinconf_to_config_param(config) != PIN_CONFIG_INPUT_DEBOUNCE ||
495 desc->eint_n == EINT_NA) 495 desc->eint.eint_n == EINT_NA)
496 return -ENOTSUPP; 496 return -ENOTSUPP;
497 497
498 debounce = pinconf_to_config_argument(config); 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
503static int mtk_build_gpiochip(struct mtk_pinctrl *hw, struct device_node *np) 503static int mtk_build_gpiochip(struct mtk_pinctrl *hw, struct device_node *np)
@@ -593,7 +593,7 @@ static int mtk_xt_find_eint_num(struct mtk_pinctrl *hw,
593 desc = (const struct mtk_pin_desc *)hw->soc->pins; 593 desc = (const struct mtk_pin_desc *)hw->soc->pins;
594 594
595 while (i < hw->soc->npins) { 595 while (i < hw->soc->npins) {
596 if (desc[i].eint_n == eint_n) 596 if (desc[i].eint.eint_n == eint_n)
597 return desc[i].number; 597 return desc[i].number;
598 i++; 598 i++;
599 } 599 }
@@ -612,7 +612,7 @@ static int mtk_xt_get_gpio_n(void *data, unsigned long eint_n,
612 *gpio_chip = &hw->chip; 612 *gpio_chip = &hw->chip;
613 613
614 /* Be greedy to guess first gpio_n is equal to eint_n */ 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 *gpio_n = eint_n; 616 *gpio_n = eint_n;
617 else 617 else
618 *gpio_n = mtk_xt_find_eint_num(hw, eint_n); 618 *gpio_n = mtk_xt_find_eint_num(hw, eint_n);
@@ -649,7 +649,7 @@ static int mtk_xt_set_gpio_as_eint(void *data, unsigned long eint_n)
649 desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio_n]; 649 desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio_n];
650 650
651 err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_MODE, 651 err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_MODE,
652 hw->soc->eint_m); 652 desc->eint.eint_m);
653 if (err) 653 if (err)
654 return err; 654 return err;
655 655
@@ -711,6 +711,7 @@ mtk_build_eint(struct mtk_pinctrl *hw, struct platform_device *pdev)
711int mtk_moore_pinctrl_probe(struct platform_device *pdev, 711int mtk_moore_pinctrl_probe(struct platform_device *pdev,
712 const struct mtk_pin_soc *soc) 712 const struct mtk_pin_soc *soc)
713{ 713{
714 struct pinctrl_pin_desc *pins;
714 struct resource *res; 715 struct resource *res;
715 struct mtk_pinctrl *hw; 716 struct mtk_pinctrl *hw;
716 int err, i; 717 int err, i;
@@ -748,8 +749,19 @@ int mtk_moore_pinctrl_probe(struct platform_device *pdev,
748 749
749 hw->nbase = hw->soc->nbase_names; 750 hw->nbase = hw->soc->nbase_names;
750 751
752 /* Copy from internal struct mtk_pin_desc to register to the core */
753 pins = devm_kmalloc_array(&pdev->dev, hw->soc->npins, sizeof(*pins),
754 GFP_KERNEL);
755 if (IS_ERR(pins))
756 return PTR_ERR(pins);
757
758 for (i = 0; i < hw->soc->npins; i++) {
759 pins[i].number = hw->soc->pins[i].number;
760 pins[i].name = hw->soc->pins[i].name;
761 }
762
751 /* Setup pins descriptions per SoC types */ 763 /* Setup pins descriptions per SoC types */
752 mtk_desc.pins = (const struct pinctrl_pin_desc *)hw->soc->pins; 764 mtk_desc.pins = (const struct pinctrl_pin_desc *)pins;
753 mtk_desc.npins = hw->soc->npins; 765 mtk_desc.npins = hw->soc->npins;
754 mtk_desc.num_custom_params = ARRAY_SIZE(mtk_custom_bindings); 766 mtk_desc.num_custom_params = ARRAY_SIZE(mtk_custom_bindings);
755 mtk_desc.custom_params = mtk_custom_bindings; 767 mtk_desc.custom_params = mtk_custom_bindings;
diff --git a/drivers/pinctrl/mediatek/pinctrl-moore.h b/drivers/pinctrl/mediatek/pinctrl-moore.h
index b965cc1ba9f6..74a6568a9220 100644
--- a/drivers/pinctrl/mediatek/pinctrl-moore.h
+++ b/drivers/pinctrl/mediatek/pinctrl-moore.h
@@ -28,11 +28,15 @@
28 28
29#define MTK_RANGE(_a) { .range = (_a), .nranges = ARRAY_SIZE(_a), } 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 .number = _number, \ 32 .number = _number, \
33 .name = _name, \ 33 .name = _name, \
34 .eint_n = _eint_n, \ 34 .eint = { \
35 .eint_m = _eint_m, \
36 .eint_n = _eint_n, \
37 }, \
35 .drv_n = _drv_n, \ 38 .drv_n = _drv_n, \
39 .funcs = NULL, \
36 } 40 }
37 41
38#define PINCTRL_PIN_GROUP(name, id) \ 42#define PINCTRL_PIN_GROUP(name, id) \
diff --git a/drivers/pinctrl/mediatek/pinctrl-mt7622.c b/drivers/pinctrl/mediatek/pinctrl-mt7622.c
index 769b36aff91e..ce4a8a0cc19c 100644
--- a/drivers/pinctrl/mediatek/pinctrl-mt7622.c
+++ b/drivers/pinctrl/mediatek/pinctrl-mt7622.c
@@ -9,7 +9,7 @@
9#include "pinctrl-moore.h" 9#include "pinctrl-moore.h"
10 10
11#define MT7622_PIN(_number, _name) \ 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
14static const struct mtk_pin_field_calc mt7622_pin_mode_range[] = { 14static const struct mtk_pin_field_calc mt7622_pin_mode_range[] = {
15 PIN_FIELD(0, 0, 0x320, 0x10, 16, 4), 15 PIN_FIELD(0, 0, 0x320, 0x10, 16, 4),
@@ -758,7 +758,7 @@ static const struct mtk_eint_hw mt7622_eint_hw = {
758 758
759static const struct mtk_pin_soc mt7622_data = { 759static const struct mtk_pin_soc mt7622_data = {
760 .reg_cal = mt7622_reg_cals, 760 .reg_cal = mt7622_reg_cals,
761 .pins = (const struct pinctrl_pin_desc *)mt7622_pins, 761 .pins = mt7622_pins,
762 .npins = ARRAY_SIZE(mt7622_pins), 762 .npins = ARRAY_SIZE(mt7622_pins),
763 .grps = mt7622_groups, 763 .grps = mt7622_groups,
764 .ngrps = ARRAY_SIZE(mt7622_groups), 764 .ngrps = ARRAY_SIZE(mt7622_groups),
@@ -766,7 +766,6 @@ static const struct mtk_pin_soc mt7622_data = {
766 .nfuncs = ARRAY_SIZE(mt7622_functions), 766 .nfuncs = ARRAY_SIZE(mt7622_functions),
767 .eint_hw = &mt7622_eint_hw, 767 .eint_hw = &mt7622_eint_hw,
768 .gpio_m = 1, 768 .gpio_m = 1,
769 .eint_m = 1,
770 .ies_present = false, 769 .ies_present = false,
771 .base_names = mtk_default_register_base_names, 770 .base_names = mtk_default_register_base_names,
772 .nbase_names = ARRAY_SIZE(mtk_default_register_base_names), 771 .nbase_names = ARRAY_SIZE(mtk_default_register_base_names),
diff --git a/drivers/pinctrl/mediatek/pinctrl-mt7623.c b/drivers/pinctrl/mediatek/pinctrl-mt7623.c
index 1f2030c3f782..b8d9d31db74f 100644
--- a/drivers/pinctrl/mediatek/pinctrl-mt7623.c
+++ b/drivers/pinctrl/mediatek/pinctrl-mt7623.c
@@ -30,7 +30,7 @@
30 _x_bits, 16, 1) 30 _x_bits, 16, 1)
31 31
32#define MT7623_PIN(_number, _name, _eint_n, _drv_grp) \ 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
35static const struct mtk_pin_field_calc mt7623_pin_mode_range[] = { 35static const struct mtk_pin_field_calc mt7623_pin_mode_range[] = {
36 PIN_FIELD15(0, 278, 0x760, 0x10, 0, 3), 36 PIN_FIELD15(0, 278, 0x760, 0x10, 0, 3),
@@ -1373,7 +1373,7 @@ static const struct mtk_eint_hw mt7623_eint_hw = {
1373 1373
1374static struct mtk_pin_soc mt7623_data = { 1374static struct mtk_pin_soc mt7623_data = {
1375 .reg_cal = mt7623_reg_cals, 1375 .reg_cal = mt7623_reg_cals,
1376 .pins = (const struct pinctrl_pin_desc *)mt7623_pins, 1376 .pins = mt7623_pins,
1377 .npins = ARRAY_SIZE(mt7623_pins), 1377 .npins = ARRAY_SIZE(mt7623_pins),
1378 .grps = mt7623_groups, 1378 .grps = mt7623_groups,
1379 .ngrps = ARRAY_SIZE(mt7623_groups), 1379 .ngrps = ARRAY_SIZE(mt7623_groups),
@@ -1381,7 +1381,6 @@ static struct mtk_pin_soc mt7623_data = {
1381 .nfuncs = ARRAY_SIZE(mt7623_functions), 1381 .nfuncs = ARRAY_SIZE(mt7623_functions),
1382 .eint_hw = &mt7623_eint_hw, 1382 .eint_hw = &mt7623_eint_hw,
1383 .gpio_m = 0, 1383 .gpio_m = 0,
1384 .eint_m = 0,
1385 .ies_present = true, 1384 .ies_present = true,
1386 .base_names = mtk_default_register_base_names, 1385 .base_names = mtk_default_register_base_names,
1387 .nbase_names = ARRAY_SIZE(mtk_default_register_base_names), 1386 .nbase_names = ARRAY_SIZE(mtk_default_register_base_names),
diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h
index 040c6b79fd71..d5819ca98c3c 100644
--- a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h
+++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h
@@ -134,18 +134,44 @@ struct mtk_pin_reg_calc {
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 */
142struct 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 */
153struct mtk_eint_desc {
154 u8 eint_m;
155 u16 eint_n;
156};
157
158/**
137 * struct mtk_pin_desc - the structure that providing information 159 * struct mtk_pin_desc - the structure that providing information
138 * for each pin of chips 160 * for each pin of chips
139 * @number: unique pin number from the global pin number space 161 * @number: unique pin number from the global pin number space
140 * @name: name for this pin 162 * @name: name for this pin
141 * @eint_n: the eint number for this pin 163 * @eint: the eint data for this pin
142 * @drv_n: the index with the driving group 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 */
144struct mtk_pin_desc { 169struct mtk_pin_desc {
145 unsigned int number; 170 unsigned int number;
146 const char *name; 171 const char *name;
147 u16 eint_n; 172 struct mtk_eint_desc eint;
148 u8 drv_n; 173 u8 drv_n;
174 struct mtk_func_desc *funcs;
149}; 175};
150 176
151struct mtk_pinctrl; 177struct mtk_pinctrl;
@@ -153,7 +179,7 @@ struct mtk_pinctrl;
153/* struct mtk_pin_soc - the structure that holds SoC-specific data */ 179/* struct mtk_pin_soc - the structure that holds SoC-specific data */
154struct mtk_pin_soc { 180struct mtk_pin_soc {
155 const struct mtk_pin_reg_calc *reg_cal; 181 const struct mtk_pin_reg_calc *reg_cal;
156 const struct pinctrl_pin_desc *pins; 182 const struct mtk_pin_desc *pins;
157 unsigned int npins; 183 unsigned int npins;
158 const struct group_desc *grps; 184 const struct group_desc *grps;
159 unsigned int ngrps; 185 unsigned int ngrps;
@@ -164,7 +190,6 @@ struct mtk_pin_soc {
164 190
165 /* Specific parameters per SoC */ 191 /* Specific parameters per SoC */
166 u8 gpio_m; 192 u8 gpio_m;
167 u8 eint_m;
168 bool ies_present; 193 bool ies_present;
169 const char * const *base_names; 194 const char * const *base_names;
170 unsigned int nbase_names; 195 unsigned int nbase_names;
@@ -190,6 +215,9 @@ struct mtk_pin_soc {
190 int (*adv_pull_get)(struct mtk_pinctrl *hw, 215 int (*adv_pull_get)(struct mtk_pinctrl *hw,
191 const struct mtk_pin_desc *desc, bool pullup, 216 const struct mtk_pin_desc *desc, bool pullup,
192 u32 *val); 217 u32 *val);
218
219 /* Specific driver data */
220 void *driver_data;
193}; 221};
194 222
195struct mtk_pinctrl { 223struct mtk_pinctrl {