Skip to contentSkip to conversation

gpiolib: add missing initialisation of bgc->dir

PATCH New Lothar Waßmann 2 participants 8 messages Jul 1, 2011 – Jul 4, 2011 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpiolib: add missing initialisation of bgc->dir

bgpio_init() does not initialise the shadow variable for the GPIO_GDIR register. Thus the first 'set_direction' call will clear the whole GPIO_GDIR register of the affected GPIO bank.

#1 lore raw

PATCH 1/1 add missing intialisation of bgc->dir

---
 drivers/gpio/basic_mmio_gpio.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/gpio/basic_mmio_gpio.c +1 -0
index 8152e9f..e69a453 100644
@@ -399,6 +399,7 @@ int __devinit bgpio_init(struct bgpio_chip *bgc,
 		return ret;
 
 	bgc->data = bgc->read_reg(bgc->reg_dat);
+	bgc->dir = bgc->read_reg(bgc->reg_dir);
 
 	return ret;
 }
Signature · 1 line
1.5.6.5
#2 lore raw

Re: [PATCH] add missing intialisation of bgc->dir

drivers/gpio/basic_mmio_gpio.c int __devinit bgpio_init(struct bgpio_chip *bgc, · line 402

Quoted 13 lines · Lothar Waßmann
---
 drivers/gpio/basic_mmio_gpio.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/gpio/basic_mmio_gpio.c +1 -0
index 8152e9f..e69a453 100644
@@ -399,6 +399,7 @@ int __devinit bgpio_init(struct bgpio_chip *bgc,
 		return ret;
 
 	bgc->data = bgc->read_reg(bgc->reg_dat);
+	bgc->dir = bgc->read_reg(bgc->reg_dir);

Hi Lothar.

You'll need to double check your email setup. The patch got emailed separately from the description.

I don't know if this is a valid thing to do or not. Not every GPIO controller supports reading back the initial state from the direction register. I suspect it is better to leave initialization of the direction to the gpio controller driver itself.

g.

#3 lore raw

Re: [PATCH] add missing intialisation of bgc->dir

Hi,

Quoted 12 lines · Grant Likely
Quoted 11 lines · Lothar Waßmann
---
 drivers/gpio/basic_mmio_gpio.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/gpio/basic_mmio_gpio.c +0 -0
index 8152e9f..e69a453 100644
@@ -399,6 +399,7 @@ int __devinit bgpio_init(struct bgpio_chip *bgc,
 		return ret;
 
Quoted 8 lines

drivers/gpio/basic_mmio_gpio.c int __devinit bgpio_init(struct bgpio_chip *bgc, · line 402

Quoted 2 lines
drivers/gpio/basic_mmio_gpio.c +1 -0
 	bgc->data = bgc->read_reg(bgc->reg_dat);
+	bgc->dir = bgc->read_reg(bgc->reg_dir);

Hi Lothar.

You'll need to double check your email setup. The patch got emailed separately from the description.

git-send-email did that.

Quoted 5 lines

I don't know if this is a valid thing to do or not. Not every GPIO controller supports reading back the initial state from the direction register. I suspect it is better to leave initialization of the direction to the gpio controller driver itself.

That would mean, that external software would have to have access to the bgpio internal data structures which is a Bad Thing(TM) IMO. Or we need a function that allows to explicitly initialize the internal shadow registers.

Lothar Waßmann

Signature · 9 lines
___________________________________________________________

Ka-Ro electronics GmbH | Pascalstraße 22 | D - 52076 Aachen
Phone: +49 2408 1402-0 | Fax: +49 2408 1402-10
Geschäftsführer: Matthias Kaussen
Handelsregistereintrag: Amtsgericht Aachen, HRB 4996

www.karo-electronics.de | [email protected]
___________________________________________________________
#4 lore raw

Re: [PATCH] add missing intialisation of bgc->dir

Quoted 20 lines · Lothar Waßmann

Hi,

Quoted 17 lines · Grant Likely

drivers/gpio/basic_mmio_gpio.c int __devinit bgpio_init(struct bgpio_chip *bgc, · line 402

Quoted 13 lines · Lothar Waßmann
---
 drivers/gpio/basic_mmio_gpio.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/gpio/basic_mmio_gpio.c +1 -0
index 8152e9f..e69a453 100644
@@ -399,6 +399,7 @@ int __devinit bgpio_init(struct bgpio_chip *bgc,
 		return ret;
 
 	bgc->data = bgc->read_reg(bgc->reg_dat);
+	bgc->dir = bgc->read_reg(bgc->reg_dir);

Hi Lothar.

Quoted 4 lines
Quoted 3 lines

You'll need to double check your email setup. The patch got emailed separately from the description.

git-send-email did that.

It appears that you asked it to send a cover letter, which you usually don't want when sending a single patch. The patch description should be part of the git commit itself.

Quoted 10 lines
Quoted 6 lines

I don't know if this is a valid thing to do or not. Not every GPIO controller supports reading back the initial state from the direction register. I suspect it is better to leave initialization of the direction to the gpio controller driver itself.

That would mean, that external software would have to have access to the bgpio internal data structures which is a Bad Thing(TM) IMO. Or we need a function that allows to explicitly initialize the internal shadow registers.

What device are you using this for. Are you using the basic gpio platform_driver, or do you have a driver using the library part of the basic gpio code?

g.

#5 lore raw

Re: [PATCH] add missing intialisation of bgc->dir

Hi,

Quoted 21 lines · Grant Likely
Quoted 20 lines · Lothar Waßmann

Hi,

Quoted 17 lines · Grant Likely

drivers/gpio/basic_mmio_gpio.c int __devinit bgpio_init(struct bgpio_chip *bgc, · line 402

Quoted 13 lines · Lothar Waßmann
---
 drivers/gpio/basic_mmio_gpio.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/gpio/basic_mmio_gpio.c +1 -0
index 8152e9f..e69a453 100644
@@ -399,6 +399,7 @@ int __devinit bgpio_init(struct bgpio_chip *bgc,
 		return ret;
 
 	bgc->data = bgc->read_reg(bgc->reg_dat);
+	bgc->dir = bgc->read_reg(bgc->reg_dir);

Hi Lothar.

Quoted 9 lines
Quoted 4 lines
Quoted 3 lines

You'll need to double check your email setup. The patch got emailed separately from the description.

git-send-email did that.

It appears that you asked it to send a cover letter, which you usually don't want when sending a single patch. The patch description should be part of the git commit itself.

Yes, I noticed that already.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

I don't know if this is a valid thing to do or not. Not every GPIO controller supports reading back the initial state from the direction register. I suspect it is better to leave initialization of the direction to the gpio controller driver itself.

Quoted 9 lines
Quoted 4 lines

That would mean, that external software would have to have access to the bgpio internal data structures which is a Bad Thing(TM) IMO. Or we need a function that allows to explicitly initialize the internal shadow registers.

What device are you using this for. Are you using the basic gpio platform_driver, or do you have a driver using the library part of the basic gpio code?

I'm using it via drivers/gpio/gpio-mxc.

Lothar Waßmann

Signature · 9 lines
___________________________________________________________

Ka-Ro electronics GmbH | Pascalstraße 22 | D - 52076 Aachen
Phone: +49 2408 1402-0 | Fax: +49 2408 1402-10
Geschäftsführer: Matthias Kaussen
Handelsregistereintrag: Amtsgericht Aachen, HRB 4996

www.karo-electronics.de | [email protected]
___________________________________________________________
#6 lore raw

Re: [PATCH] add missing intialisation of bgc->dir

Quoted 45 lines · Lothar Waßmann

Hi,

Quoted 21 lines · Grant Likely
Quoted 20 lines · Lothar Waßmann

Hi,

Quoted 17 lines · Grant Likely

drivers/gpio/basic_mmio_gpio.c int __devinit bgpio_init(struct bgpio_chip *bgc, · line 402

Quoted 13 lines · Lothar Waßmann

---
 drivers/gpio/basic_mmio_gpio.c |    1 +

 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/gpio/basic_mmio_gpio.c +1 -0
index 8152e9f..e69a453 100644
@@ -399,6 +399,7 @@ int __devinit bgpio_init(struct bgpio_chip *bgc,
                 return ret;
 
         bgc->data = bgc->read_reg(bgc->reg_dat);
+       bgc->dir = bgc->read_reg(bgc->reg_dir);

Hi Lothar.

Quoted 9 lines
Quoted 4 lines
Quoted 3 lines

You'll need to double check your email setup.  The patch got emailed separately from the description.

git-send-email did that.

It appears that you asked it to send a cover letter, which you usually don't want when sending a single patch.  The patch description should be part of the git commit itself.

Yes, I noticed that already.

Quoted 10 lines
Quoted 9 lines
Quoted 5 lines

I don't know if this is a valid thing to do or not.  Not every GPIO controller supports reading back the initial state from the direction register.  I suspect it is better to leave initialization of the direction to the gpio controller driver itself.

That would mean, that external software would have to have access to the bgpio internal data structures which is a Bad Thing(TM) IMO. Or we need a function that allows to explicitly initialize the internal shadow registers.

Quoted 5 lines
Quoted 4 lines

What device are you using this for.  Are you using the basic gpio platform_driver, or do you have a driver using the library part of the basic gpio code?

I'm using it via drivers/gpio/gpio-mxc.

You can safely do the "bgc->dir = bgc->read_reg(bgc->reg_dir);" in gpio-mxc after bgpio_init returns.

g.

#7 lore raw

Re: [PATCH] add missing intialisation of bgc->dir

Hi,

Quoted 13 lines · Grant Likely
Quoted 12 lines · Lothar Waßmann

Hi,

Quoted 10 lines
Quoted 9 lines
Quoted 5 lines

I don't know if this is a valid thing to do or not.  Not every GPIO controller supports reading back the initial state from the direction register.  I suspect it is better to leave initialization of the direction to the gpio controller driver itself.

That would mean, that external software would have to have access to the bgpio internal data structures which is a Bad Thing(TM) IMO. Or we need a function that allows to explicitly initialize the internal shadow registers.

Quoted 9 lines
Quoted 5 lines
Quoted 4 lines

What device are you using this for.  Are you using the basic gpio platform_driver, or do you have a driver using the library part of the basic gpio code?

I'm using it via drivers/gpio/gpio-mxc.

You can safely do the "bgc->dir = bgc->read_reg(bgc->reg_dir);" in gpio-mxc after bgpio_init returns.

I know I can do that, but IMO it's a horrible way of programming, to let a higher SW layer freely mess with the data structures of another SW layer. There should be accessor functions to do that!

Lothar Waßmann

Signature · 9 lines
___________________________________________________________

Ka-Ro electronics GmbH | Pascalstraße 22 | D - 52076 Aachen
Phone: +49 2408 1402-0 | Fax: +49 2408 1402-10
Geschäftsführer: Matthias Kaussen
Handelsregistereintrag: Amtsgericht Aachen, HRB 4996

www.karo-electronics.de | [email protected]
___________________________________________________________