Message ID | 1457935279-7881-1-git-send-email-wxt@rock-chips.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Hi Caesar, Am Montag, 14. März 2016, 14:01:19 schrieb Caesar Wang: > This patch adds the get_direction to support the gpio > interface. > > The gpio direction is not used on rockchip platform when use the gpio > debugfs. > > Tested on kylin board. (RK3036 SoCs) > The repro steps: > $/sys/class/gpio/ > echo 53 > export > $/sys/class/gpio/gpio53# cat direction > in > In general, the gpio53 should be out value, but the direction is the > default value 'in', since the get_direction didn't supported in rockchip > pinctrl. > > So, we should add this patch to support it. > > Reported-by: Jeffy Chen <jeffy.chen@rock-chips.com> > Signed-off-by: Caesar Wang <wxt@rock-chips.com> > Cc: Linus Walleij <linus.walleij@linaro.org> > Cc: Heiko Stuebner <heiko@sntech.de> > Cc: linux-gpio@vger.kernel.org > Cc: linux-rockchip@lists.infradead.org > > --- > > Changes in RESEND: > - Remove the change-id > > drivers/pinctrl/pinctrl-rockchip.c | 13 +++++++++++++ > 1 file changed, 13 insertions(+) > > diff --git a/drivers/pinctrl/pinctrl-rockchip.c > b/drivers/pinctrl/pinctrl-rockchip.c index bf032b9..f22a186 100644 > --- a/drivers/pinctrl/pinctrl-rockchip.c > +++ b/drivers/pinctrl/pinctrl-rockchip.c > @@ -1208,6 +1208,18 @@ static int rockchip_pmx_set(struct pinctrl_dev > *pctldev, unsigned selector, return 0; > } > > +static int rockchip_gpio_get_direction(struct gpio_chip *chip, unsigned > offset) +{ > + struct rockchip_pin_bank *bank = gpiochip_get_data(chip); > + int pin; > + u32 data; > + > + pin = offset - chip->base; > + data = readl_relaxed(bank->reg_base + GPIO_SWPORT_DDR); > + > + return !!(data & BIT(pin)); TRM (at least rk3288 and rk3036) says for the SWPORT_DDR register: (data & BIT(pin)) = 0 = input (data & BIT(pin)) = 1 = output struct gpio_chip docs [0] says: @get_direction: returns 0=out, 1=in, So shouldn't that be return !(data & BIT(pin)); with only one "!" instead of two? Or as happens sometimes, am I just blind? :-) Thanks Heiko [0] http://lxr.free-electrons.com/source/include/linux/gpio/driver.h#L33
diff --git a/drivers/pinctrl/pinctrl-rockchip.c b/drivers/pinctrl/pinctrl-rockchip.c index bf032b9..f22a186 100644 --- a/drivers/pinctrl/pinctrl-rockchip.c +++ b/drivers/pinctrl/pinctrl-rockchip.c @@ -1208,6 +1208,18 @@ static int rockchip_pmx_set(struct pinctrl_dev *pctldev, unsigned selector, return 0; } +static int rockchip_gpio_get_direction(struct gpio_chip *chip, unsigned offset) +{ + struct rockchip_pin_bank *bank = gpiochip_get_data(chip); + int pin; + u32 data; + + pin = offset - chip->base; + data = readl_relaxed(bank->reg_base + GPIO_SWPORT_DDR); + + return !!(data & BIT(pin)); +} + /* * The calls to gpio_direction_output() and gpio_direction_input() * leads to this function call (via the pinctrl_gpio_direction_{input|output}() @@ -1741,6 +1753,7 @@ static const struct gpio_chip rockchip_gpiolib_chip = { .free = gpiochip_generic_free, .set = rockchip_gpio_set, .get = rockchip_gpio_get, + .get_direction = rockchip_gpio_get_direction, .direction_input = rockchip_gpio_direction_input, .direction_output = rockchip_gpio_direction_output, .to_irq = rockchip_gpio_to_irq,
This patch adds the get_direction to support the gpio interface. The gpio direction is not used on rockchip platform when use the gpio debugfs. Tested on kylin board. (RK3036 SoCs) The repro steps: $/sys/class/gpio/ echo 53 > export $/sys/class/gpio/gpio53# cat direction in In general, the gpio53 should be out value, but the direction is the default value 'in', since the get_direction didn't supported in rockchip pinctrl. So, we should add this patch to support it. Reported-by: Jeffy Chen <jeffy.chen@rock-chips.com> Signed-off-by: Caesar Wang <wxt@rock-chips.com> Cc: Linus Walleij <linus.walleij@linaro.org> Cc: Heiko Stuebner <heiko@sntech.de> Cc: linux-gpio@vger.kernel.org Cc: linux-rockchip@lists.infradead.org --- Changes in RESEND: - Remove the change-id drivers/pinctrl/pinctrl-rockchip.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)