pinctrl: rockchip: add rk3188 support
Subsystems (3)
Heiko Stübner
maintainerv2 cover pinctrl: rockchip: add rk3188 support
A patch series, finalizing support for the pin controller in the rk3188.
As mentioned in the individual patches, the rk3188 makes it even more complex due to its strange pull setting configuration. Therefore a bit of reordering needed to take place to accomodate this.
changes since v1:
- remove the of_device_is_any_of nonsense, as of_match_node is perfectly capable to reach the same goal, as pointed out by Mark Rutland
Heiko Stuebner (5):
pinctrl: rockchip: separate different sub-types more
pinctrl: rockchip: add support for multiple bank types
pinctrl: rockchip: remove redundant check
pinctrl: rockchip: add rk3188 specifics
pinctrl: rockchip: emulate both edge triggered interrupts
.../bindings/pinctrl/rockchip,pinctrl.txt | 46 ++- drivers/pinctrl/pinctrl-rockchip.c | 292 +++++++++++++++----- 2 files changed, 274 insertions(+), 64 deletions(-)
Signature · 1 line
1.7.10.4
Heiko Stübner
maintainerPATCH v2 1/5 pinctrl: rockchip: separate different sub-types more
Further investigation of the different Rockchip SoCs showed that the differences especially in the pull settings are quite deep. As further patches will show, the register layout for the pulls of the rk3188 is quite strange. Also it is to assume, that later Rockchip SoCs may introduce even more quirks in this regard, making it hard to support all of those using the current generic pull_* variables.
Therefore move the driver to hold the type of controller in an enum and do the handling according to it in the necessary places. Also instead of calculating the register in the get and set pull functions move it to a type-specific callback.
--- drivers/pinctrl/pinctrl-rockchip.c | 105 +++++++++++++++++++----------------- 1 file changed, 57 insertions(+), 48 deletions(-)
drivers/pinctrl/pinctrl-rockchip.c +57 -48
@@ -56,6 +56,12 @@#define GPIO_EXT_PORT 0x50#define GPIO_LS_SYNC 0x60 +enum rockchip_pinctrl_type { +RK2928 , +RK3066B , +RK3188 , +}; +/** * @reg_base: register base of the gpio bank * @clk: clock of the gpio bank
@@ -98,18 +104,16 @@ struct rockchip_pin_bank { }/** -* @pull_auto: some SoCs don't allow pulls to be specified as up or down, but -* instead decide this automatically based on the pad-type. */ struct rockchip_pin_ctrl {struct rockchip_pin_bank *pin_banks;u32 nr_banks;u32 nr_pins;char *label; +enum rockchip_pinctrl_type type;int mux_offset; -int pull_offset; -bool pull_auto; -int pull_bank_stride; +void (*pull_calc_reg)(struct rockchip_pin_bank *bank,int pin_num, +void __iomem **reg,u8 *bit); };struct rockchip_pin_config {
@@ -354,6 +358,22 @@ static void rockchip_set_mux(struct rockchip_pin_bank *bank, int pin, int mux)spin_unlock_irqrestore (&bank->slock, flags); } +#define RK2928_PULL_OFFSET 0x118 +#define RK2928_PULL_PINS_PER_REG 16 +#define RK2928_PULL_BANK_STRIDE 8 + +static void rk2928_calc_pull_reg_and_bit (struct rockchip_pin_bank *bank, +int pin_num,void __iomem **reg,u8 *bit) +{ +struct rockchip_pinctrl *info = bank->drvdata; + + *reg = info->reg_base +RK2928_PULL_OFFSET ; + *reg += bank->bank_num *RK2928_PULL_BANK_STRIDE ; + *reg += (pin_num /RK2928_PULL_PINS_PER_REG ) *4 ; + + *bit = pin_num %RK2928_PULL_PINS_PER_REG ; +}; +static int rockchip_get_pull (struct rockchip_pin_bank *bank,int pin_num) {struct rockchip_pinctrl *info = bank->drvdata;
@@ -362,23 +382,22 @@ static int rockchip_get_pull(struct rockchip_pin_bank *bank, int pin_num)u8 bit;/* rk3066b does support any pulls */ -if (!ctrl->pull_offset) +if (ctrl->type ==RK3066B )return PIN_CONFIG_BIAS_DISABLE ; - reg = info->reg_base + ctrl->pull_offset; - -if (ctrl->pull_auto) { - reg += bank->bank_num * ctrl->pull_bank_stride; - reg += (pin_num /16 ) *4 ; - bit = pin_num %16 ; - +switch (ctrl->type) { +case RK2928 : + ctrl->pull_calc_reg (bank, pin_num, ®, &bit);return !(readl_relaxed (reg) &BIT (bit)) ?PIN_CONFIG_BIAS_PULL_PIN_DEFAULT :PIN_CONFIG_BIAS_DISABLE ; - }else { +case RK3188 :dev_err (info->dev,"pull support for rk31xx not implemented\n" );return -EIO ; - } +default : +dev_err (info->dev,"unsupported pinctrl type\n" ); +return -EINVAL ; + }; } static int rockchip_set_pull(struct rockchip_pin_bank *bank,
@@ -395,21 +414,18 @@ static int rockchip_set_pull(struct rockchip_pin_bank *bank, bank->bank_num, pin_num, pull);/* rk3066b does support any pulls */ -if (!ctrl->pull_offset) +if (ctrl->type ==RK3066B )return pull ? -EINVAL :0 ; - reg = info->reg_base + ctrl->pull_offset; - -if (ctrl->pull_auto) { +switch (ctrl->type) { +case RK2928 :if (pull !=PIN_CONFIG_BIAS_PULL_PIN_DEFAULT && pull !=PIN_CONFIG_BIAS_DISABLE ) {dev_err (info->dev,"only PIN_DEFAULT and DISABLE allowed\n" );return -EINVAL ; } - reg += bank->bank_num * ctrl->pull_bank_stride; - reg += (pin_num /16 ) *4 ; - bit = pin_num %16 ; + ctrl->pull_calc_reg (bank, pin_num, ®, &bit);spin_lock_irqsave (&bank->slock, flags);
@@ -419,14 +435,13 @@ static int rockchip_set_pull(struct rockchip_pin_bank *bank,writel (data, reg);spin_unlock_irqrestore (&bank->slock, flags); - }else { -if (pull ==PIN_CONFIG_BIAS_PULL_PIN_DEFAULT ) { -dev_err (info->dev,"pull direction (up/down) needs to be specified\n" ); -return -EINVAL ; - } - +break ; +case RK3188 :dev_err (info->dev,"pull support for rk31xx not implemented\n" );return -EIO ; +default : +dev_err (info->dev,"unsupported pinctrl type\n" ); +return -EINVAL ; }return 0 ;
@@ -556,20 +571,17 @@ static const struct pinmux_ops rockchip_pmx_ops = {static bool rockchip_pinconf_pull_valid (struct rockchip_pin_ctrl *ctrl,enum pin_config_param pull) { -/* rk3066b does support any pulls */ -if (!ctrl->pull_offset) +switch (ctrl->type) { +case RK2928 : +return (pull ==PIN_CONFIG_BIAS_PULL_PIN_DEFAULT || + pull ==PIN_CONFIG_BIAS_DISABLE ); +case RK3066B :return pull ? false : true; - -if (ctrl->pull_auto) { -if (pull !=PIN_CONFIG_BIAS_PULL_PIN_DEFAULT && - pull !=PIN_CONFIG_BIAS_DISABLE ) -return false; - }else { -if (pull ==PIN_CONFIG_BIAS_PULL_PIN_DEFAULT ) -return false; +case RK3188 : +return (pull !=PIN_CONFIG_BIAS_PULL_PIN_DEFAULT ); } -return true; +return false; }/* set the pin config settings for a specified pin */
@@ -1315,10 +1327,9 @@ static struct rockchip_pin_ctrl rk2928_pin_ctrl = { .pin_banks = rk2928_pin_banks, .nr_banks = ARRAY_SIZE(rk2928_pin_banks), .label = "RK2928-GPIO", + .type = RK2928, .mux_offset = 0xa8, - .pull_offset = 0x118, - .pull_auto = 1, - .pull_bank_stride = 8, + .pull_calc_reg = rk2928_calc_pull_reg_and_bit, };static struct rockchip_pin_bank rk3066a_pin_banks[] = {
@@ -1334,10 +1345,9 @@ static struct rockchip_pin_ctrl rk3066a_pin_ctrl = { .pin_banks = rk3066a_pin_banks, .nr_banks = ARRAY_SIZE(rk3066a_pin_banks), .label = "RK3066a-GPIO", + .type = RK2928, .mux_offset = 0xa8, - .pull_offset = 0x118, - .pull_auto = 1, - .pull_bank_stride = 8, + .pull_calc_reg = rk2928_calc_pull_reg_and_bit, };static struct rockchip_pin_bank rk3066b_pin_banks[] = {
@@ -1351,8 +1361,8 @@ static struct rockchip_pin_ctrl rk3066b_pin_ctrl = { .pin_banks = rk3066b_pin_banks, .nr_banks = ARRAY_SIZE(rk3066b_pin_banks), .label = "RK3066b-GPIO", + .type = RK3066B, .mux_offset = 0x60, - .pull_offset = -EINVAL, };static struct rockchip_pin_bank rk3188_pin_banks[] = {
@@ -1366,9 +1376,8 @@ static struct rockchip_pin_ctrl rk3188_pin_ctrl = { .pin_banks = rk3188_pin_banks, .nr_banks = ARRAY_SIZE(rk3188_pin_banks), .label = "RK3188-GPIO", + .type = RK3188, .mux_offset = 0x68, - .pull_offset = 0x164, - .pull_bank_stride = 16, };static const struct of_device_id rockchip_pinctrl_dt_match[] = {
Signature · 1 line
1.7.10.4
Heiko Stübner
maintainerPATCH v2 2/5 pinctrl: rockchip: add support for multiple bank types
In reply to Heiko StübnerThere are Rockchip SoCs, namely the rk3188, that combine a set of regular banks with banks that need special handling for some settings.
Therefore add the possibility for the driver to handle more than one bank type.
--- drivers/pinctrl/pinctrl-rockchip.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
drivers/pinctrl/pinctrl-rockchip.c +14 -3
@@ -62,6 +62,10 @@ enum rockchip_pinctrl_type { RK3188, }; +enum rockchip_pin_bank_type { +COMMON_BANK , +}; +/** * @reg_base: register base of the gpio bank * @clk: clock of the gpio bank
@@ -86,6 +90,7 @@ struct rockchip_pin_bank {u8 nr_pins;char *name;u8 bank_num; +enum rockchip_pin_bank_type bank_type;bool valid;struct device_node *of_node;struct rockchip_pinctrl *drvdata;
@@ -668,7 +673,10 @@ static const struct pinconf_ops rockchip_pinconf_ops = { .pin_config_set = rockchip_pinconf_set, }; -static const char *gpio_compat ="rockchip,gpio-bank" ; +static const struct of_device_id rockchip_bank_match[] = { + { .compatible ="rockchip,gpio-bank" }, + {}, +};static void rockchip_pinctrl_child_count (struct rockchip_pinctrl *info,struct device_node *np)
@@ -676,7 +684,7 @@ static void rockchip_pinctrl_child_count(struct rockchip_pinctrl *info,struct device_node *child;for_each_child_of_node (np, child) { -if (of_device_is_compatible (child, gpio_compat)) +if (of_match_node (rockchip_bank_match, child))continue ; info->nfunctions++;
@@ -819,8 +827,9 @@ static int rockchip_pinctrl_parse_dt(struct platform_device *pdev, i =0 ;for_each_child_of_node (np, child) { -if (of_device_is_compatible (child, gpio_compat)) +if (of_match_node (rockchip_bank_match, child))continue ; + ret =rockchip_pinctrl_parse_functions (child, info, i++);if (ret) {dev_err (&pdev->dev,"failed to parse function\n" );
@@ -1217,6 +1226,8 @@ static int rockchip_get_bank_data(struct rockchip_pin_bank *bank,if (IS_ERR (bank->reg_base))return PTR_ERR (bank->reg_base); + bank->bank_type =COMMON_BANK ; + bank->irq =irq_of_parse_and_map (bank->of_node,0 ); bank->clk =of_clk_get (bank->of_node,0 );
Signature · 1 line
1.7.10.4
Heiko Stübner
maintainerPATCH v2 3/5 pinctrl: rockchip: remove redundant check
In reply to Heiko StübnerThe check limiting bias options to supported ones is already done thru rockchip_pinconf_pull_valid. Therefore this check is redundant and can be removed.
--- drivers/pinctrl/pinctrl-rockchip.c | 6 ------ 1 file changed, 6 deletions(-)
drivers/pinctrl/pinctrl-rockchip.c +0 -6
@@ -424,12 +424,6 @@ static int rockchip_set_pull(struct rockchip_pin_bank *bank,switch (ctrl->type) {case RK2928 : -if (pull !=PIN_CONFIG_BIAS_PULL_PIN_DEFAULT && - pull !=PIN_CONFIG_BIAS_DISABLE ) { -dev_err (info->dev,"only PIN_DEFAULT and DISABLE allowed\n" ); -return -EINVAL ; - } - ctrl->pull_calc_reg (bank, pin_num, ®, &bit);spin_lock_irqsave (&bank->slock, flags);
Signature · 1 line
1.7.10.4
Heiko Stübner
maintainerPATCH v2 4/5 pinctrl: rockchip: add rk3188 specifics
In reply to Heiko StübnerBesides the pull registers sitting in a separate place, the rk3188 also has the peculiarity that the pull registers of the first bank are split and the first half is sitting in the register space of the pmu.
Therefore this adds a special bank-type for the first bank, to handle the two register sources.
--- .../bindings/pinctrl/rockchip,pinctrl.txt | 46 +++++++- drivers/pinctrl/pinctrl-rockchip.c | 119 ++++++++++++++++++-- 2 files changed, 157 insertions(+), 8 deletions(-)
Documentation/devicetree/bindings/pinctrl/rockchip,pinctrl.txt +45 -1
@@ -21,10 +21,13 @@ defined as gpio sub-nodes of the pinmux controller. Required properties for iomux controller: - compatible: one of "rockchip,rk2928-pinctrl", "rockchip,rk3066a-pinctrl" "rockchip,rk3066b-pinctrl", "rockchip,rk3188-pinctrl" + - reg: first element is the general register space of the iomux controller + second element is the separate pull register space of the rk3188 Required properties for gpio sub nodes: - - compatible: "rockchip,gpio-bank" + - compatible: "rockchip,gpio-bank", "rockchip,rk3188-gpio-bank0" - reg: register of the gpio bank (different than the iomux registerset) + second element: separate pull register for rk3188 bank0 - interrupts: base interrupt of the gpio bank in the interrupt controller - clocks: clock that drives this bank - gpio-controller: identifies the node as a gpio controller and pin bank.
@@ -95,3 +98,44 @@ uart2: serial at 20064000 { pinctrl-names = "default"; pinctrl-0 = <&uart2_xfer>; }; + +Example for rk3188: + + pinctrl at 20008000 { + compatible = "rockchip,rk3188-pinctrl"; + reg = <0x20008000 0xa0>, + <0x20008164 0x1a0>; + #address-cells = <1>; + #size-cells = <1>; + ranges; + + gpio0: gpio0 at 0x2000a000 { + compatible = "rockchip,rk3188-gpio-bank0"; + reg = <0x2000a000 0x100>, + <0x20004064 0x8>; + interrupts = <GIC_SPI 54 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&clk_gates8 9>; + + gpio-controller; + #gpio-cells = <2>; + + interrupt-controller; + #interrupt-cells = <2>; + }; + + gpio1: gpio1 at 0x2003c000 { + compatible = "rockchip,gpio-bank"; + reg = <0x2003c000 0x100>; + interrupts = <GIC_SPI 55 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&clk_gates8 10>; + + gpio-controller; + #gpio-cells = <2>; + + interrupt-controller; + #interrupt-cells = <2>; + }; + + ... + + };
drivers/pinctrl/pinctrl-rockchip.c +112 -7
214 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Heiko Stübner
maintainerPATCH v2 5/5 pinctrl: rockchip: emulate both edge triggered interrupts
In reply to Heiko StübnerThe gpio interrupt controller on Rockchip socs can do edge triggers only for single edges but not both. Nevertheless a lot of gpio users rely on the availability of both-edge triggered interrupts - i.e. gpio-keys.
Therefore implement a solution similar to pinctrl-coh901 re-setting the triggering edge depending on the gpio value in the interrupt demuxer.
--- drivers/pinctrl/pinctrl-rockchip.c | 61 +++++++++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 7 deletions(-)
drivers/pinctrl/pinctrl-rockchip.c +54 -7
@@ -101,7 +101,7 @@ struct rockchip_pin_bank {struct gpio_chip gpio_chip;struct pinctrl_gpio_range grange;spinlock_t slock; - +u32 toggle_edge_mode; };#define PIN_BANK (id, pins, label) \
@@ -1078,7 +1078,9 @@ static void rockchip_irq_demux(unsigned int irq, struct irq_desc *desc) {struct irq_chip *chip =irq_get_chip (irq);struct rockchip_pin_bank *bank =irq_get_handler_data (irq); +u32 polarity =0 , data =0 ;u32 pend; +bool edge_changed = false;dev_dbg (bank->drvdata->dev,"got irq for bank %s\n" , bank->name);
@@ -1086,6 +1088,12 @@ static void rockchip_irq_demux(unsigned int irq, struct irq_desc *desc) pend =readl_relaxed (bank->reg_base +GPIO_INT_STATUS ); +if (bank->toggle_edge_mode) { + polarity =readl_relaxed (bank->reg_base + +GPIO_INT_POLARITY ); + data =readl_relaxed (bank->reg_base +GPIO_EXT_PORT ); + } +while (pend) {unsigned int virq;
@@ -1100,9 +1108,30 @@ static void rockchip_irq_demux(unsigned int irq, struct irq_desc *desc)dev_dbg (bank->drvdata->dev,"handling irq %d\n" , irq); +/* +* Triggering IRQ on both rising and falling edge +* needs manual intervention. +*/ +if (bank->toggle_edge_mode &BIT (irq)) { +if (data &BIT (irq)) + polarity &= ~BIT (irq); +else + polarity |=BIT (irq); + + edge_changed = true; + } +generic_handle_irq (virq); } +if (bank->toggle_edge_mode && edge_changed) { +/* Interrupt params should only be set with ints disabled */ + data =readl_relaxed (bank->reg_base +GPIO_INTEN ); +writel_relaxed (0 , bank->reg_base +GPIO_INTEN ); +writel (polarity, bank->reg_base +GPIO_INT_POLARITY ); +writel (data, bank->reg_base +GPIO_INTEN ); + } +chained_irq_exit (chip, desc); }
@@ -1115,6 +1144,12 @@ static int rockchip_irq_set_type(struct irq_data *d, unsigned int type)u32 level;u32 data; +/* make sure the pin is configured as gpio input */ +rockchip_set_mux (bank, d->hwirq,RK_FUNC_GPIO ); + data =readl_relaxed (bank->reg_base +GPIO_SWPORT_DDR ); + data &= ~mask; +writel_relaxed (data, bank->reg_base +GPIO_SWPORT_DDR ); +if (type &IRQ_TYPE_EDGE_BOTH )__irq_set_handler_locked (d->irq, handle_edge_irq);else
@@ -1126,19 +1161,37 @@ static int rockchip_irq_set_type(struct irq_data *d, unsigned int type) polarity =readl_relaxed (gc->reg_base +GPIO_INT_POLARITY );switch (type) { +case IRQ_TYPE_EDGE_BOTH : + bank->toggle_edge_mode |= mask; + level |= mask; + +/* +* Determine gpio state. If 1 next interrupt should be falling +* otherwise rising. +*/ + data =readl (bank->reg_base +GPIO_EXT_PORT ); +if (data & mask) + polarity &= ~mask; +else + polarity |= mask; +break ;case IRQ_TYPE_EDGE_RISING : + bank->toggle_edge_mode &= ~mask; level |= mask; polarity |= mask;break ;case IRQ_TYPE_EDGE_FALLING : + bank->toggle_edge_mode &= ~mask; level |= mask; polarity &= ~mask;break ;case IRQ_TYPE_LEVEL_HIGH : + bank->toggle_edge_mode &= ~mask; level &= ~mask; polarity |= mask;break ;case IRQ_TYPE_LEVEL_LOW : + bank->toggle_edge_mode &= ~mask; level &= ~mask; polarity &= ~mask;break ;
@@ -1152,12 +1205,6 @@ static int rockchip_irq_set_type(struct irq_data *d, unsigned int type)irq_gc_unlock (gc); -/* make sure the pin is configured as gpio input */ -rockchip_set_mux (bank, d->hwirq,RK_FUNC_GPIO ); - data =readl_relaxed (bank->reg_base +GPIO_SWPORT_DDR ); - data &= ~mask; -writel_relaxed (data, bank->reg_base +GPIO_SWPORT_DDR ); -return 0 ; }
Signature · 1 line
1.7.10.4
PATCH v2 1/5 pinctrl: rockchip: separate different sub-types more
In reply to Heiko StübnerQuoted 8 lines · Heiko St?bner
Further investigation of the different Rockchip SoCs showed that the differences especially in the pull settings are quite deep. As further patches will show, the register layout for the pulls of the rk3188 is quite strange. Also it is to assume, that later Rockchip SoCs may introduce even more quirks in this regard, making it hard to support all of those using the current generic pull_* variables.
Quoted 6 lines
Therefore move the driver to hold the type of controller in an enum and do the handling according to it in the necessary places. Also instead of calculating the register in the get and set pull functions move it to a type-specific callback.
Signed-off-by Heiko Stuebner <[email protected]>
Patch applied.
Yours,
Linus Walleij
PATCH v2 2/5 pinctrl: rockchip: add support for multiple bank types
In reply to Heiko StübnerQuoted 7 lines · Heiko St?bner
There are Rockchip SoCs, namely the rk3188, that combine a set of regular banks with banks that need special handling for some settings.
Therefore add the possibility for the driver to handle more than one bank type.
Signed-off-by Heiko Stuebner <[email protected]>
Patch applied.
Yours,
Linus Walleij
PATCH v2 3/5 pinctrl: rockchip: remove redundant check
In reply to Heiko StübnerQuoted 5 lines · Heiko St?bner
The check limiting bias options to supported ones is already done thru
rockchip_pinconf_pull_valid. Therefore this check is redundant and can be removed.Signed-off-by Heiko Stuebner <[email protected]>
Patch applied.
Yours,
Linus Walleij
PATCH v2 4/5 pinctrl: rockchip: add rk3188 specifics
In reply to Heiko StübnerQuoted 8 lines · Heiko St?bner
Besides the pull registers sitting in a separate place, the rk3188 also has the peculiarity that the pull registers of the first bank are split and the first half is sitting in the register space of the pmu.
Therefore this adds a special bank-type for the first bank, to handle the two register sources.
Signed-off-by Heiko Stuebner <[email protected]>
Another way to do the same thing is to use drivers/mfd/syscon.c and access it using a phandle.
But this seems to work fine as well so patch applied.
Yours,
Linus Walleij
PATCH v2 5/5 pinctrl: rockchip: emulate both edge triggered interrupts
In reply to Heiko StübnerQuoted 8 lines · Heiko St?bner
The gpio interrupt controller on Rockchip socs can do edge triggers only for single edges but not both. Nevertheless a lot of gpio users rely on the availability of both-edge triggered interrupts - i.e. gpio-keys.
Therefore implement a solution similar to pinctrl-coh901 re-setting the triggering edge depending on the gpio value in the interrupt demuxer.
Signed-off-by Heiko Stuebner <[email protected]>
Patch applied.
Yours,
Linus Walleij