diff mbox

[U-Boot] gpio: vybrid: Use proper parameter name for gpio offset

Message ID 1433859884.10944.1.camel@ingics.com
State Superseded
Delegated to: Stefano Babic
Headers show

Commit Message

Axel Lin June 9, 2015, 2:24 p.m. UTC
It's confusing to use gpio as gpio offset parameter so rename it to offset
for better readability.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
 drivers/gpio/vybrid_gpio.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

Comments

Bhuvanchandra DV June 9, 2015, 2:37 p.m. UTC | #1
On 06/09/2015 07:54 PM, Axel Lin wrote:
> It's confusing to use gpio as gpio offset parameter so rename it to offset
> for better readability.
Agreed, but IMHO these offsets any way at the end are the gpio numbers 
of individual gpio chip instances. e.g: gpio 2 of gpio chip 1 which is 
gpio 34.

>
> Signed-off-by: Axel Lin <axel.lin@ingics.com>
> ---
>   drivers/gpio/vybrid_gpio.c | 24 ++++++++++++------------
>   1 file changed, 12 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/gpio/vybrid_gpio.c b/drivers/gpio/vybrid_gpio.c
> index 6eaf0a9..14ba7e5 100644
> --- a/drivers/gpio/vybrid_gpio.c
> +++ b/drivers/gpio/vybrid_gpio.c
> @@ -21,54 +21,54 @@ struct vybrid_gpios {
>   	struct vybrid_gpio_regs *reg;
>   };
>
> -static int vybrid_gpio_direction_input(struct udevice *dev, unsigned gpio)
> +static int vybrid_gpio_direction_input(struct udevice *dev, unsigned offset)
>   {
>   	const struct vybrid_gpios *gpios = dev_get_priv(dev);
> +	unsigned gpio = offset + (gpios->chip * VYBRID_GPIO_COUNT);
>
> -	gpio = gpio + (gpios->chip * VYBRID_GPIO_COUNT);
>   	imx_iomux_gpio_set_direction(gpio, VF610_GPIO_DIRECTION_IN);
>
>   	return 0;
>   }
>
> -static int vybrid_gpio_direction_output(struct udevice *dev, unsigned gpio,
> +static int vybrid_gpio_direction_output(struct udevice *dev, unsigned offset,
>   					 int value)
>   {
>   	const struct vybrid_gpios *gpios = dev_get_priv(dev);
> +	unsigned gpio = offset + (gpios->chip * VYBRID_GPIO_COUNT);
>
> -	gpio = gpio + (gpios->chip * VYBRID_GPIO_COUNT);
>   	gpio_set_value(gpio, value);
>   	imx_iomux_gpio_set_direction(gpio, VF610_GPIO_DIRECTION_OUT);
>
>   	return 0;
>   }
>
> -static int vybrid_gpio_get_value(struct udevice *dev, unsigned gpio)
> +static int vybrid_gpio_get_value(struct udevice *dev, unsigned offset)
>   {
>   	const struct vybrid_gpios *gpios = dev_get_priv(dev);
>
> -	return ((readl(&gpios->reg->gpio_pdir) & (1 << gpio))) ? 1 : 0;
> +	return ((readl(&gpios->reg->gpio_pdir) & (1 << offset))) ? 1 : 0;
>   }
>
> -static int vybrid_gpio_set_value(struct udevice *dev, unsigned gpio,
> +static int vybrid_gpio_set_value(struct udevice *dev, unsigned offset,
>   				  int value)
>   {
>   	const struct vybrid_gpios *gpios = dev_get_priv(dev);
> +
>   	if (value)
> -		writel((1 << gpio), &gpios->reg->gpio_psor);
> +		writel((1 << offset), &gpios->reg->gpio_psor);
>   	else
> -		writel((1 << gpio), &gpios->reg->gpio_pcor);
> +		writel((1 << offset), &gpios->reg->gpio_pcor);
>
>   	return 0;
>   }
>
> -static int vybrid_gpio_get_function(struct udevice *dev, unsigned gpio)
> +static int vybrid_gpio_get_function(struct udevice *dev, unsigned offset)
>   {
>   	const struct vybrid_gpios *gpios = dev_get_priv(dev);
> +	unsigned gpio = offset + (gpios->chip * VYBRID_GPIO_COUNT);
>   	u32 g_state = 0;
>
> -	gpio = gpio + (gpios->chip * VYBRID_GPIO_COUNT);
> -
>   	imx_iomux_gpio_get_function(gpio, &g_state);
>
>   	if (((g_state & (0x07 << PAD_MUX_MODE_SHIFT)) >> PAD_MUX_MODE_SHIFT) > 0)
>

Best regards,
Bhuvan
Axel Lin June 10, 2015, 12:39 a.m. UTC | #2
2015-06-09 22:37 GMT+08:00 Bhuvanchandra DV <bhuvanchandra.dv@toradex.com>:
> On 06/09/2015 07:54 PM, Axel Lin wrote:
>>
>> It's confusing to use gpio as gpio offset parameter so rename it to offset
>> for better readability.
>
> Agreed, but IMHO these offsets any way at the end are the gpio numbers of
> individual gpio chip instances. e.g: gpio 2 of gpio chip 1 which is gpio 34.

struct dm_gpio_ops {
        int (*request)(struct udevice *dev, unsigned offset, const char *label);
        int (*free)(struct udevice *dev, unsigned offset);
        int (*direction_input)(struct udevice *dev, unsigned offset);
        int (*direction_output)(struct udevice *dev, unsigned offset,
int value);
        int (*get_value)(struct udevice *dev, unsigned offset);
        int (*set_value)(struct udevice *dev, unsigned offset, int value);
        int (*get_function)(struct udevice *dev, unsigned offset);

All the callbacks of struct dm_gpio_ops takes offset rather than gpio number,
had better use offset here.

The gpio numbers of individual gpio chip instances actually means offset, don't
mix it with the actually gpio number.
diff mbox

Patch

diff --git a/drivers/gpio/vybrid_gpio.c b/drivers/gpio/vybrid_gpio.c
index 6eaf0a9..14ba7e5 100644
--- a/drivers/gpio/vybrid_gpio.c
+++ b/drivers/gpio/vybrid_gpio.c
@@ -21,54 +21,54 @@  struct vybrid_gpios {
 	struct vybrid_gpio_regs *reg;
 };
 
-static int vybrid_gpio_direction_input(struct udevice *dev, unsigned gpio)
+static int vybrid_gpio_direction_input(struct udevice *dev, unsigned offset)
 {
 	const struct vybrid_gpios *gpios = dev_get_priv(dev);
+	unsigned gpio = offset + (gpios->chip * VYBRID_GPIO_COUNT);
 
-	gpio = gpio + (gpios->chip * VYBRID_GPIO_COUNT);
 	imx_iomux_gpio_set_direction(gpio, VF610_GPIO_DIRECTION_IN);
 
 	return 0;
 }
 
-static int vybrid_gpio_direction_output(struct udevice *dev, unsigned gpio,
+static int vybrid_gpio_direction_output(struct udevice *dev, unsigned offset,
 					 int value)
 {
 	const struct vybrid_gpios *gpios = dev_get_priv(dev);
+	unsigned gpio = offset + (gpios->chip * VYBRID_GPIO_COUNT);
 
-	gpio = gpio + (gpios->chip * VYBRID_GPIO_COUNT);
 	gpio_set_value(gpio, value);
 	imx_iomux_gpio_set_direction(gpio, VF610_GPIO_DIRECTION_OUT);
 
 	return 0;
 }
 
-static int vybrid_gpio_get_value(struct udevice *dev, unsigned gpio)
+static int vybrid_gpio_get_value(struct udevice *dev, unsigned offset)
 {
 	const struct vybrid_gpios *gpios = dev_get_priv(dev);
 
-	return ((readl(&gpios->reg->gpio_pdir) & (1 << gpio))) ? 1 : 0;
+	return ((readl(&gpios->reg->gpio_pdir) & (1 << offset))) ? 1 : 0;
 }
 
-static int vybrid_gpio_set_value(struct udevice *dev, unsigned gpio,
+static int vybrid_gpio_set_value(struct udevice *dev, unsigned offset,
 				  int value)
 {
 	const struct vybrid_gpios *gpios = dev_get_priv(dev);
+
 	if (value)
-		writel((1 << gpio), &gpios->reg->gpio_psor);
+		writel((1 << offset), &gpios->reg->gpio_psor);
 	else
-		writel((1 << gpio), &gpios->reg->gpio_pcor);
+		writel((1 << offset), &gpios->reg->gpio_pcor);
 
 	return 0;
 }
 
-static int vybrid_gpio_get_function(struct udevice *dev, unsigned gpio)
+static int vybrid_gpio_get_function(struct udevice *dev, unsigned offset)
 {
 	const struct vybrid_gpios *gpios = dev_get_priv(dev);
+	unsigned gpio = offset + (gpios->chip * VYBRID_GPIO_COUNT);
 	u32 g_state = 0;
 
-	gpio = gpio + (gpios->chip * VYBRID_GPIO_COUNT);
-
 	imx_iomux_gpio_get_function(gpio, &g_state);
 
 	if (((g_state & (0x07 << PAD_MUX_MODE_SHIFT)) >> PAD_MUX_MODE_SHIFT) > 0)