Skip to contentSkip to conversation

arm nomadik: gpio and i2c

PATCH New Alessandro Rubini 6 participants 20 messages Jul 19, 2009 – Jul 28, 2009 I2C

lore
Share & tools
lore
#0 lore raw

cover arm nomadik: gpio and i2c

This adds gpio and i2c support for the Nomadik evaluation kit. They are needed to turn on the LCD backlight in order to later add LCD support.

I have one doubt and some questions on gpio:

To use soft_i2c I need to define some macros in the config file. Instead of writing hard numbers there I called the gpio functions, but the config file is inluded from asm sources as well. I don't think my approach is beautiful at all (both #ifndef __ASSEMBLY__ and #include "../board/"), but I didn't find a better solution.

I would like to add a gpio command, and I've found no generic gpio stuff. Only one board (cm-bf527) has a gpio commands, but quite a few have similar commands to set leds or other bits. Is time ripe for a generic gpio driver with board-specific limits and operations? Would that be interesting for u-boot-next? Should I process with a board-specific gpio command by now?

/alessandro

Alessandro Rubini (2):
arm nomadik: add gpio support
arm nomadik: add i2c

 board/st/nhk8815/Makefile  |    2 +-
 board/st/nhk8815/gpio.c    |   99 ++++++++++++++++++++++++++++++++++++++++++++
 board/st/nhk8815/gpio.h    |   42 ++++++++++++++++++
 board/st/nhk8815/nhk8815.c |   16 ++++++-
 include/configs/nhk8815.h  |   18 ++++++++-
 5 files changed, 173 insertions(+), 4 deletions(-)
 create mode 100644 board/st/nhk8815/gpio.c
 create mode 100644 board/st/nhk8815/gpio.h
#1 lore raw

cover arm nomadik: gpio and i2c

Dear Alessandro Rubini,

Quoted 6 lines · In message <[email protected]> you wrote:

To use soft_i2c I need to define some macros in the config file. Instead of writing hard numbers there I called the gpio functions, but the config file is inluded from asm sources as well. I don't think my approach is beautiful at all (both #ifndef __ASSEMBLY__ and #include "../board/"), but I didn't find a better solution.

Agreed. It's a bit intricate to get this done, but I don't see a better way either.

Quoted 6 lines

I would like to add a gpio command, and I've found no generic gpio stuff. Only one board (cm-bf527) has a gpio commands, but quite a few have similar commands to set leds or other bits. Is time ripe for a generic gpio driver with board-specific limits and operations? Would that be interesting for u-boot-next? Should I process with a board-specific gpio command by now?

Well, my opinion on that is a clear "yes, but..." :-)

Yes, some generic gpio framework would be nice - for example, if it would allow us to get rid of the 14 largely similar "led.c" files, to name just one.

On the other hand, the design of such a framework should be lean and not necessarily try to cover 100% of all possible use cases - I'd rather have a small and beautiful solution that covers 90% of the cases and use board-specific exceptions where really needed, instead of a fat thing that solves each and every problem but costs 50 kB.

Best regards,

Wolfgang Denk

Signature · 6 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
The years of peak mental activity are undoubtedly between the ages of
four and eighteen. At four we know all the questions, at eighteen all
the answers.
#2 lore raw

cover arm nomadik: gpio and i2c

Hello Wolfgang,

Quoted 11 lines · Wolfgang Denk

Dear Alessandro Rubini,

Quoted 5 lines · In message <[email protected]> you wrote:

To use soft_i2c I need to define some macros in the config file. Instead of writing hard numbers there I called the gpio functions, but the config file is inluded from asm sources as well. I don't think my approach is beautiful at all (both #ifndef __ASSEMBLY__ and #include "../board/"), but I didn't find a better solution.

Agreed. It's a bit intricate to get this done, but I don't see a better way either.

Hmm.. maybe my previous patch is a better solution?

Quoted 13 lines
Quoted 6 lines

I would like to add a gpio command, and I've found no generic gpio stuff. Only one board (cm-bf527) has a gpio commands, but quite a few have similar commands to set leds or other bits. Is time ripe for a generic gpio driver with board-specific limits and operations? Would that be interesting for u-boot-next? Should I process with a board-specific gpio command by now?

Well, my opinion on that is a clear "yes, but..." :-)

Yes, some generic gpio framework would be nice - for example, if it would allow us to get rid of the 14 largely similar "led.c" files, to name just one.

Quoted 5 lines

On the other hand, the design of such a framework should be lean and not necessarily try to cover 100% of all possible use cases - I'd rather have a small and beautiful solution that covers 90% of the cases and use board-specific exceptions where really needed, instead of a fat thing that solves each and every problem but costs 50 kB.

Agreed. So we need an gpio_core.c / .h which defines the following functions (just a proposal):

typedef struct gpio_adapter {
	int	(*init_pin)(int pin);
	int	(*set)(int pin, value);
	int	(*get)(int pin);
	int	(*dir)(int pin, int direction);	
	int	(*level)(int pin, int level);
}

int gpio_init(gpio_adapter *adap);
int gpio_init_pin(pin);
? maybe with setting a marker, that this pin is initialized,
so this can be checked in the above functions ... ?
int gpio_set(pin, value);
int gpio_get(pin);
int gpio_dir(pin, dir);
int gpio_level(pin, dir);

bye
Heiko

#3 lore raw

cover arm nomadik: gpio and i2c

Quoted 2 lines

Agreed. So we need an gpio_core.c / .h which defines the following functions (just a proposal):

Yes.

Quoted 7 lines
typedef struct gpio_adapter {
	int	(*init_pin)(int pin);
	int	(*set)(int pin, value);
	int	(*get)(int pin);
	int	(*dir)(int pin, int direction);	
	int	(*level)(int pin, int level);
}

I don't understand the init_pin function, nor what "level" is. Actually, even "dir" can be dropped: a get configures as input, a set configures as output, the extra instruction is very little overhead.

But an alternate function configuration is definitely needed: everybody has alternate functions associated to the pins. Just say "0" is gpio and 1...n is SoC-specific.

So, are you going to write it? Or should someone else do that?

thanks
/alessandro

#4 lore raw

cover arm nomadik: gpio and i2c

Hello Alessandro,

Quoted 13 lines · Alessandro Rubini
Quoted 2 lines

Agreed. So we need an gpio_core.c / .h which defines the following functions (just a proposal):

Yes.

Quoted 7 lines
typedef struct gpio_adapter {
	int	(*init_pin)(int pin);
	int	(*set)(int pin, value);
	int	(*get)(int pin);
	int	(*dir)(int pin, int direction);	
	int	(*level)(int pin, int level);
}
Quoted 1 line

I don't understand the init_pin function, nor what "level" is.

init_pin:
you call this function, if you want to use this pin as an gpio. (BTW: init pin should look like this,
changing init_pin(pin, dir, value);
with value only used if setting it as an output)
functionality:
- Setup the GPIO registers for using this pin as GPIO
- Maybe setting a marker in the gpio_core, that this pin is usable now for gpio. This marker can be checked in the other functions, which use this pin ...

level:
we can set the output level with this function directly ... ok, not really needed ... but maybe nice to have ... if thinking for the i2c bitbang driver, we save on all set() calls the output settings ... maybe more then one register changes, if switching between input/output ...

Quoted 2 lines

Actually, even "dir" can be dropped: a get configures as input, a set configures as output, the extra instruction is very little overhead.

See my comment above. I just like the idea, that a user can control this separately.

Quoted 3 lines

But an alternate function configuration is definitely needed: everybody has alternate functions associated to the pins. Just say "0" is gpio and 1...n is SoC-specific.

what with deinit_pin(pin, function)? That would be in shape with init_pin()?

(There, we could also unset the marker, that this pin is no longer used for gpio ...)

Quoted 1 line

So, are you going to write it? Or should someone else do that?

Hmm... if nobody else volunteers, maybe I find time for it ... but I think, there should be more ratings, if this is a way to go ... also, if we make a gpio_core, would we have some commands for it (show status of gpios, directly access the gpios per commandshell, ...)?

Also, a board can have more then one gpio adapter, how we address such a case?

Just a fast thought about that:
- adding to typedef struct gpio_adapter also a "name" field
- allow to register more than one gpio adapter
- addressing the different adapters through an int ... called gpio_device?

So the core functions look something like that:

int gpio_init(gpio_adap *adap); (returns a int gpio_device)

int gpio_init_pin(gpio_device, pin, dir, value);
int gpio_set(gpio_device, pin, value)
int gpio_get(gpio_device, pin)
int gpio_dir(gpio_device, pin, dir)
int gpio_level(gpio_device, pin, level)

bye
Heiko

Signature · 2 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
#5 lore raw

cover arm nomadik: gpio and i2c

Quoted 1 line

what with deinit_pin(pin, function)? That would be in shape with init_pin()?

No, it's not clear what it is. I'd rename "init" to "setup", adding an AF argument. So I can setup it as AF2, or as GPIO-OUT, or whatever.

Quoted 2 lines

(There, we could also unset the marker, that this pin is no longer used for gpio ...)

No, I wouldn't like the marker. It's a boot loader, it shouldn't overdo sanity checks. Most of the times it runs the same "bootcmd" over and over. In the rare but important case it's a debugging tool, it shouldn't force policy, in my opinion (I already have problems with the kernel gpiolib, that doesn't let me fix mishaps at will).

Quoted 2 lines

Also, a board can have more then one gpio adapter, how we address such a case?

As Wolfgang suggested, we don't. If atmel calls it PORTC-12 I have no problem calling it gpio-76 by concatentating the ports as 0..31, 32..64, ... It's still better to have a gpio command than doing "mw <addr> <val>" over and over.

In my old-fashioned way, it should be as simple as possible, but no simpler.

/alessandro

#6 lore raw

cover arm nomadik: gpio and i2c

Hello Alessandro,

Quoted 3 lines · Alessandro Rubini
Quoted 1 line

what with deinit_pin(pin, function)? That would be in shape with init_pin()?

No, it's not clear what it is. I'd rename "init" to "setup", adding an AF

ok.

Quoted 1 line

argument. So I can setup it as AF2, or as GPIO-OUT, or whatever.

No I don;t understand you ;-) What means AF? Ah, while typing this, my brain parsed AF to Alternate Function, right?

So, I am fine with that.

Quoted 8 lines
Quoted 2 lines

(There, we could also unset the marker, that this pin is no longer used for gpio ...)

No, I wouldn't like the marker. It's a boot loader, it shouldn't overdo sanity checks. Most of the times it runs the same "bootcmd" over and over. In the rare but important case it's a debugging tool, it shouldn't force policy, in my opinion (I already have problems with the kernel gpiolib, that doesn't let me fix mishaps at will).

Ok, it was just a thought. If others agree I am fine with it.

Quoted 7 lines
Quoted 2 lines

Also, a board can have more then one gpio adapter, how we address such a case?

As Wolfgang suggested, we don't. If atmel calls it PORTC-12 I have no problem calling it gpio-76 by concatentating the ports as 0..31, 32..64, ... It's still better to have a gpio command than doing "mw <addr> <val>" over and over.

Huh, missed I an Email? Didn;t see a response from Wolfgang ...

Ah, yes, this is also an option, so we need to configure when adding a gpio_adapter, with which GPIO number the GPIOs in this adapter starts and how many GPIOs are accessible through it... OK, I am also fine with such an option.

Quoted 1 line

In my old-fashioned way, it should be as simple as possible, but no simpler.

;-)

bye
Heiko

Signature · 2 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
#7 lore raw

cover arm nomadik: gpio and i2c

In reply to Heiko Schocher

Dear Heiko Schocher,

Quoted 3 lines · In message <[email protected]> you wrote:

Also, a board can have more then one gpio adapter, how we address such a case?

How far do you want to take that? What about an I/O expander at the I2C bus?

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
When it is incorrect, it is, at least *authoritatively* incorrect.
                                    - Hitchiker's Guide To The Galaxy
#8 lore raw

cover arm nomadik: gpio and i2c

Hello Wolfgang,

Quoted 8 lines · Wolfgang Denk

Dear Heiko Schocher,

Quoted 2 lines · In message <[email protected]> you wrote:

Also, a board can have more then one gpio adapter, how we address such a case?

How far do you want to take that? What about an I/O expander at the I2C bus?

Hmmm.. good question ;-)

But I don;t think it is not so exotic to have more than one gpio adapter on one board. On the suen3 plattform where I actually work, there are the CPU GPIO pins and GPIO pins over an I/O Expander used ... so it should be possible to have more than one gpio adapter I think. And to make such an I/O Expander gpio adapter should not so difficult ... and if we now really make such a gpio lib, it should support more than one adapter ...

I like Alessandros suggestion for concatening such multiple adapters, see:
http://lists.denx.de/pipermail/u-boot/2009-July/056949.html

bye
Heiko

Signature · 2 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
#9 lore raw

cover arm nomadik: gpio and i2c

In reply to Heiko Schocher

Dear Heiko Schocher,

Quoted 9 lines · In message <[email protected]> you wrote:
typedef struct gpio_adapter {
	int	(*init_pin)(int pin);
	int	(*set)(int pin, value);
	int	(*get)(int pin);
	int	(*dir)(int pin, int direction);	
	int	(*level)(int pin, int level);
}
Quoted 8 lines

int gpio_init(gpio_adapter *adap);
int gpio_init_pin(pin);
? maybe with setting a marker, that this pin is initialized,
so this can be checked in the above functions ... ?
int gpio_set(pin, value);
int gpio_get(pin);
int gpio_dir(pin, dir);
int gpio_level(pin, dir);

What does "level" mean in this context?

gpio_init_pin() and gpio_dir() seem to be redundant - or does pin initialization not include the setting of the direction (and, in case of an output pin, it's initial state) ?

gpio_get() returns the current state of the pin?

gpio_set() returns the previous state of the pin? Or the new state? If it returns the new state, we could use value=1 to set a pin, value=0 to unset a pin, and value=-1 to just read it's value without changing it; then we could "#define gpio_get(pin) gpio_set(pin,-1)".

Best regards,

Wolfgang Denk

Signature · 4 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
The speed of time is one second per second.
#10 lore raw

cover arm nomadik: gpio and i2c

Hello Wolfgang,

Quoted 20 lines · Wolfgang Denk

Dear Heiko Schocher,

Quoted 8 lines · In message <[email protected]> you wrote:
typedef struct gpio_adapter {
	int	(*init_pin)(int pin);
	int	(*set)(int pin, value);
	int	(*get)(int pin);
	int	(*dir)(int pin, int direction);	
	int	(*level)(int pin, int level);
}
Quoted 8 lines

int gpio_init(gpio_adapter *adap);
int gpio_init_pin(pin);
? maybe with setting a marker, that this pin is initialized,
so this can be checked in the above functions ... ?
int gpio_set(pin, value);
int gpio_get(pin);
int gpio_dir(pin, dir);
int gpio_level(pin, dir);

Quoted 1 line

What does "level" mean in this context?

Yesterday, when I emailed with Alessandro, it looked like, if we call gpio_set(), we also set the direction to output, so I thought, it would be nice to have a function which really just sets the value.

Now, I think, we should set the direction only with gpio_dir() (if output also set the value).

And with gpio_set() we only set the output value, without switching the direction ...

Or should we do allways a set direction, when calling gpio_set() ...?

Quoted 3 lines

gpio_init_pin() and gpio_dir() seem to be redundant - or does pin initialization not include the setting of the direction (and, in case of an output pin, it's initial state) ?

Yes, you are right, also redundant.

Quoted 1 line

gpio_get() returns the current state of the pin?

Yep.

Quoted 4 lines

gpio_set() returns the previous state of the pin? Or the new state? If it returns the new state, we could use value=1 to set a pin, value=0 to unset a pin, and value=-1 to just read it's value without changing it; then we could "#define gpio_get(pin) gpio_set(pin,-1)".

Yes, thats a good point.

bye
Heiko

Signature · 2 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
#11 lore raw

cover arm nomadik: gpio and i2c

Dear Heiko Schocher,

Quoted 3 lines · In message <[email protected]> you wrote:

And with gpio_set() we only set the output value, without switching the direction ...

Right.

Quoted 1 line

Or should we do allways a set direction, when calling gpio_set() ...?

This makes no sense to me.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
A little suffering is good for the soul.
	-- Kirk, "The Corbomite Maneuver", stardate 1514.0
#12 lore raw

cover arm nomadik: gpio and i2c

In reply to Alessandro Rubini

Hello Alessandro,

Quoted 11 lines · Alessandro Rubini

This adds gpio and i2c support for the Nomadik evaluation kit. They are needed to turn on the LCD backlight in order to later add LCD support.

I have one doubt and some questions on gpio:

To use soft_i2c I need to define some macros in the config file. Instead of writing hard numbers there I called the gpio functions, but the config file is inluded from asm sources as well. I don't think my approach is beautiful at all (both #ifndef __ASSEMBLY__ and #include "../board/"), but I didn't find a better solution.

Yes, thats a problem ... if we had a GPIO Framework it would be solved by including gpio.h ...

Or, maybe, we can make a soft_i2c.h which which gets only included if saying CONFIG_I2C_SOFT_INCLUDE is defined. soft_i2c.h defines for example:

#define I2C_SDA(x) i2c_soft_sda(bit)

void i2c_soft_sda(int pin);

and you can define this function i2c_soft_sda(int pin) in your board specific code ... maybe a cleaner option?

to speak in c, I tried the following patch on the suen3 plattform, where I have actually a similiar problem, and this worked fine :-)

[PATCH] i2c, soft: added soft_i2c.h

In case you must define functions for the I2C_XXX defines, it is necessary to have a soft_i2c.h, which defines functions for this macros. This functions can then be programmed in board specific code. To activate this it must be CONFIG_I2C_SOFT_INCLUDE defined in the board config file.

---
 drivers/i2c/soft_i2c.c |    3 +++
 include/soft_i2c.h     |   16 ++++++++++++++++
 2 files changed, 19 insertions(+), 0 deletions(-)
 create mode 100644 include/soft_i2c.h
drivers/i2c/soft_i2c.c +3 -0
index 59883a5..30e24f3 100644
@@ -43,6 +43,9 @@
 #if defined(CONFIG_MPC852T) || defined(CONFIG_MPC866)
 #include <asm/io.h>
 #endif
+#if defined(CONFIG_SOFT_I2C_INCLUDE)
+#include <soft_i2c.h>
+#endif
 #include <i2c.h>
 
 /* #define	DEBUG_I2C	*/
include/soft_i2c.h new file +16 -0
new file mode 100644
index 0000000..39f9a35
@@ -0,0 +1,16 @@
+#ifndef _CONFIG_SOFT_I2C
+#define _CONFIG_SOFT_I2C
+#define I2C_ACTIVE	i2c_soft_active();
+#define I2C_TRISTATE	i2c_soft_tristate();
+#define I2C_READ	i2c_soft_read();
+#define I2C_SDA(bit)	i2c_soft_sda(bit);
+#define I2C_SCL(bit)	i2c_soft_scl(bit);
+#define	I2C_DELAY	i2c_soft_delay();
+
+void	i2c_soft_active(void);
+void	i2c_soft_tristate(void);
+int	i2c_soft_read(void);
+void	i2c_soft_sda(int value);
+void	i2c_soft_scl(int value);
+void	i2c_soft_delay(void);
+#endif
Signature · 3 lines
1.6.0.GIT

Maybe you can try it too?
Quoted 6 lines

I would like to add a gpio command, and I've found no generic gpio stuff. Only one board (cm-bf527) has a gpio commands, but quite a few have similar commands to set leds or other bits. Is time ripe for a generic gpio driver with board-specific limits and operations? Would that be interesting for u-boot-next? Should I process with a board-specific gpio command by now?

I vote for making a gpio framework, but that will take a while I think ... Hmm.. maybe we use my proposal for such a soft_i2c.h, so I think, it is okay for such a board specific gpio (unless we have a gpio framework).

bye
Heiko

Signature · 2 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
#13 lore raw

cover arm nomadik: gpio and i2c

Hello Heiko,

Quoted 92 lines · Heiko Schocher

Hello Alessandro,

Quoted 11 lines · Alessandro Rubini

This adds gpio and i2c support for the Nomadik evaluation kit. They are needed to turn on the LCD backlight in order to later add LCD support.

I have one doubt and some questions on gpio:

To use soft_i2c I need to define some macros in the config file. Instead of writing hard numbers there I called the gpio functions, but the config file is inluded from asm sources as well. I don't think my approach is beautiful at all (both #ifndef __ASSEMBLY__ and #include "../board/"), but I didn't find a better solution.

Yes, thats a problem ... if we had a GPIO Framework it would be solved by including gpio.h ...

Or, maybe, we can make a soft_i2c.h which which gets only included if saying CONFIG_I2C_SOFT_INCLUDE is defined. soft_i2c.h defines for example:

#define I2C_SDA(x) i2c_soft_sda(bit)

void i2c_soft_sda(int pin);

and you can define this function i2c_soft_sda(int pin) in your board specific code ... maybe a cleaner option?

to speak in c, I tried the following patch on the suen3 plattform, where I have actually a similiar problem, and this worked fine :-)

[PATCH] i2c, soft: added soft_i2c.h

In case you must define functions for the I2C_XXX defines, it is necessary to have a soft_i2c.h, which defines functions for this macros. This functions can then be programmed in board specific code. To activate this it must be CONFIG_I2C_SOFT_INCLUDE defined in the board config file.

---
 drivers/i2c/soft_i2c.c |    3 +++
 include/soft_i2c.h     |   16 ++++++++++++++++
 2 files changed, 19 insertions(+), 0 deletions(-)
 create mode 100644 include/soft_i2c.h
drivers/i2c/soft_i2c.c +3 -0
index 59883a5..30e24f3 100644
@@ -43,6 +43,9 @@
 #if defined(CONFIG_MPC852T) || defined(CONFIG_MPC866)
 #include <asm/io.h>
 #endif
+#if defined(CONFIG_SOFT_I2C_INCLUDE)
+#include <soft_i2c.h>
+#endif
 #include <i2c.h>
 
 /* #define	DEBUG_I2C	*/
include/soft_i2c.h new file +16 -1
new file mode 100644
index 0000000..39f9a35
@@ -0,0 +1,16 @@
+#ifndef _CONFIG_SOFT_I2C
+#define _CONFIG_SOFT_I2C
+#define I2C_ACTIVE	i2c_soft_active();
+#define I2C_TRISTATE	i2c_soft_tristate();
+#define I2C_READ	i2c_soft_read();
+#define I2C_SDA(bit)	i2c_soft_sda(bit);
+#define I2C_SCL(bit)	i2c_soft_scl(bit);
+#define	I2C_DELAY	i2c_soft_delay();
+
+void	i2c_soft_active(void);
+void	i2c_soft_tristate(void);
+int	i2c_soft_read(void);
+void	i2c_soft_sda(int value);
+void	i2c_soft_scl(int value);
+void	i2c_soft_delay(void);
+#endif
-- 1.6.0.GIT Maybe you can try it too?
Quoted 6 lines

I would like to add a gpio command, and I've found no generic gpio stuff. Only one board (cm-bf527) has a gpio commands, but quite a few have similar commands to set leds or other bits. Is time ripe for a generic gpio driver with board-specific limits and operations? Would that be interesting for u-boot-next? Should I process with a board-specific gpio command by now?

Quoted 6 lines

I vote for making a gpio framework, but that will take a while I think ... Hmm.. maybe we use my proposal for such a soft_i2c.h, so I think, it is okay for such a board specific gpio (unless we have a gpio framework).

bye
Heiko

I tried your patch on AT91SAM9263EK based OTC-570 board (patch will come to ML within next merge window). It worked fine on it.
But some boards (the OTC-570 too) need a i2c_soft_init() function. So I extended your patch as follows:

[PATCH] i2c, soft: added soft_i2c.h

In case you must define functions for the I2C_XXX defines, it is necessary to have a soft_i2c.h, which defines functions for this macros. This functions can then be programmed in board specific code. To activate this it must be CONFIG_I2C_SOFT_INCLUDE defined in the board config file.

---
 drivers/i2c/soft_i2c.c |    3 +++
 include/soft_i2c.h     |   20 ++++++++++++++++++++
 2 files changed, 23 insertions(+), 0 deletions(-)
 create mode 100644 include/soft_i2c.h
drivers/i2c/soft_i2c.c +3 -0
index 59883a5..30e24f3 100644
@@ -43,6 +43,9 @@
 #if defined(CONFIG_MPC852T) || defined(CONFIG_MPC866)
 #include <asm/io.h>
 #endif
+#if defined(CONFIG_SOFT_I2C_INCLUDE)
+#include <soft_i2c.h>
+#endif
 #include <i2c.h>
 
 /* #define	DEBUG_I2C	*/
include/soft_i2c.h new file +20 -0
new file mode 100644
index 0000000..c1b770d
@@ -0,0 +1,20 @@
+#ifndef _CONFIG_SOFT_I2C
+#define _CONFIG_SOFT_I2C
+#ifdef CONFIG_SOFT_I2C_INIT
+#define I2C_INIT	i2c_soft_init()
+#endif
+#define I2C_ACTIVE	i2c_soft_active()
+#define I2C_TRISTATE	i2c_soft_tristate()
+#define I2C_READ	i2c_soft_read()
+#define I2C_SDA(bit)	i2c_soft_sda(bit)
+#define I2C_SCL(bit)	i2c_soft_scl(bit)
+#define	I2C_DELAY	i2c_soft_delay()
+
+void	i2c_soft_init(void);
+void	i2c_soft_active(void);
+void	i2c_soft_tristate(void);
+int	i2c_soft_read(void);
+void	i2c_soft_sda(int value);
+void	i2c_soft_scl(int value);
+void	i2c_soft_delay(void);
+#endif
Signature · 9 lines
1.5.3

Moreover I removed the semicolons at the end of the #define lines,
they are not needed.
Maybe you apply these changes to your I2C tree?
(Or is there a better solution in the meantime?)

Bye
Daniel
#14 lore raw

cover arm nomadik: gpio and i2c

Quoted 15 lines

I tried your patch on AT91SAM9263EK based OTC-570 board (patch will come to ML within next merge window). It worked fine on it.
But some boards (the OTC-570 too) need a i2c_soft_init() function. So I extended your patch as follows:

[PATCH] i2c, soft: added soft_i2c.h

In case you must define functions for the I2C_XXX defines, it is necessary to have a soft_i2c.h, which defines functions for this macros. This functions can then be programmed in board specific code. To activate this it must be CONFIG_I2C_SOFT_INCLUDE defined in the board config file.

Quoted 2 lines

---

Best Regards,
J.

#15 lore raw

cover arm nomadik: gpio and i2c

In reply to Daniel Gorsulowski

Hello Daniel,

Quoted 47 lines · Daniel Gorsulowski
Quoted 46 lines · Heiko Schocher

Hello Alessandro,

Quoted 11 lines · Alessandro Rubini

This adds gpio and i2c support for the Nomadik evaluation kit. They are needed to turn on the LCD backlight in order to later add LCD support.

I have one doubt and some questions on gpio:

To use soft_i2c I need to define some macros in the config file. Instead of writing hard numbers there I called the gpio functions, but the config file is inluded from asm sources as well. I don't think my approach is beautiful at all (both #ifndef __ASSEMBLY__ and #include "../board/"), but I didn't find a better solution.

Yes, thats a problem ... if we had a GPIO Framework it would be solved by including gpio.h ...

Or, maybe, we can make a soft_i2c.h which which gets only included if saying CONFIG_I2C_SOFT_INCLUDE is defined. soft_i2c.h defines for example:

#define I2C_SDA(x) i2c_soft_sda(bit)

void i2c_soft_sda(int pin);

and you can define this function i2c_soft_sda(int pin) in your board specific code ... maybe a cleaner option?

to speak in c, I tried the following patch on the suen3 plattform, where I have actually a similiar problem, and this worked fine :-)

[PATCH] i2c, soft: added soft_i2c.h

In case you must define functions for the I2C_XXX defines, it is necessary to have a soft_i2c.h, which defines functions for this macros. This functions can then be programmed in board specific code. To activate this it must be CONFIG_I2C_SOFT_INCLUDE defined in the board config file.

---
 drivers/i2c/soft_i2c.c |    3 +++
 include/soft_i2c.h     |   16 ++++++++++++++++
 2 files changed, 19 insertions(+), 0 deletions(-)
 create mode 100644 include/soft_i2c.h

[...]

Quoted 11 lines
Quoted 11 lines

-- 1.6.0.GIT Maybe you can try it too?

Quoted 6 lines

I would like to add a gpio command, and I've found no generic gpio stuff. Only one board (cm-bf527) has a gpio commands, but quite a few have similar commands to set leds or other bits. Is time ripe for a generic gpio driver with board-specific limits and operations? Would that be interesting for u-boot-next? Should I process with a board-specific gpio command by now?

I vote for making a gpio framework, but that will take a while I think ... Hmm.. maybe we use my proposal for such a soft_i2c.h, so I think, it is okay for such a board specific gpio (unless we have a gpio framework).

Quoted 7 lines
Quoted 2 lines

bye
Heiko

I tried your patch on AT91SAM9263EK based OTC-570 board (patch will come to ML within next merge window). It worked fine on it.
But some boards (the OTC-570 too) need a i2c_soft_init() function. So I extended your patch as follows:

[...]

OK, thanks, but this patch was just a fast thought, and as I wrote, I think, Wolfgang will not Ack this patch ... Wolfgang?

bye
Heiko

Signature · 2 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
#16 lore raw

cover arm nomadik: gpio and i2c

Dear Heiko,

Quoted 4 lines · in message <[email protected]> you wrote:

OK, thanks, but this patch was just a fast thought, and as I wrote, I think, Wolfgang will not Ack this patch ... Wolfgang?

Correct. If we are going to rework the Soft-I2C implementation, this should be done for all boards (which is a pretty big action), and probably should be done as part of the "i2c: rework multibus/multi- adapter functionality" changes.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"It is better to have tried and failed than to have  failed  to  try,
but the result's the same."                           - Mike Dennison
#17 lore raw

cover arm nomadik: gpio and i2c

Hello Wolfgang,

Quoted 9 lines · Wolfgang Denk
Quoted 3 lines · in message <[email protected]> you wrote:

OK, thanks, but this patch was just a fast thought, and as I wrote, I think, Wolfgang will not Ack this patch ... Wolfgang?

Correct. If we are going to rework the Soft-I2C implementation, this should be done for all boards (which is a pretty big action), and probably should be done as part of the "i2c: rework multibus/multi- adapter functionality" changes.

Hmm... I don;t understand why we must rework all I2C Soft implementations. Just boards, who must/want call functions instead of direct using the I2C_XXX macros, can use this patch ... existing boards are work as they are ... but as we discussed this, this patch is not a need, because we can do this functionality also at the moment (of course with this unlovley include in the config file) If this is in future a no go (as Jean-Christophe suggested for the Kconfig support), we can then maybe switch to this proposal ...

Hmm... also I don;t want to do this with the "multibus/multiadapter" rework, because this rework is for themselve a big change, which where I wouldn;t add one more big change ... so we maybe lost control, why things no longer work ...

bye
Heiko

Signature · 2 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
#18 lore raw

cover arm nomadik: gpio and i2c

Dear Heiko Schocher,

Quoted 9 lines · In message <[email protected]> you wrote:
Quoted 5 lines

Correct. If we are going to rework the Soft-I2C implementation, this should be done for all boards (which is a pretty big action), and probably should be done as part of the "i2c: rework multibus/multi- adapter functionality" changes.

Hmm... I don;t understand why we must rework all I2C Soft implementations. Just boards, who must/want call functions instead of direct using the I2C_XXX macros, can use this patch ... existing boards are

Maybe I miss the point - but what is the problem with "direct using the I2C_XXX macros"? You can always #define the I2C_XXX macros sucht hat they indeed call the required functions, right? I really don;t get the point.

Quoted 3 lines

work as they are ... but as we discussed this, this patch is not a need, because we can do this functionality also at the moment (of course with this unlovley include in the config file)

What's the difference between include one file or another? I see no real difference between including <asm/gpio.h> versus <soft_i2c.h>.

Quoted 2 lines

If this is in future a no go (as Jean-Christophe suggested for the Kconfig support), we can then maybe switch to this proposal ...

Well, we should not assume that we can use Kconfig to sole all configuration issues. This is IMO not possible with reasonable efforts and within a reasonable time frame. Let's be happy when we cover 95 or even 90%, and then focus on the rest. But don't lets make (eventually false) assumptions which constructs may or may not conflict with a not even yet existing implementation.

You know - early optimizian has never been a good idea.

Quoted 4 lines

Hmm... also I don;t want to do this with the "multibus/multiadapter" rework, because this rework is for themselve a big change, which where I wouldn;t add one more big change ... so we maybe lost control, why things no longer work ...

Heh. Clever, you didn't swallow the bait ;-)

Best regards,

Wolfgang Denk

Signature · 4 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
If all you have is a hammer, everything looks like a nail.
#19 lore raw

cover arm nomadik: gpio and i2c

Hello Wolfgang,

Quoted 5 lines · Wolfgang Denk
Quoted 4 lines · In message <[email protected]> you wrote:
Quoted 4 lines

Correct. If we are going to rework the Soft-I2C implementation, this should be done for all boards (which is a pretty big action), and probably should be done as part of the "i2c: rework multibus/multi- adapter functionality" changes.

Quoted 8 lines
Quoted 3 lines

Hmm... I don;t understand why we must rework all I2C Soft implementations. Just boards, who must/want call functions instead of direct using the I2C_XXX macros, can use this patch ... existing boards are

Maybe I miss the point - but what is the problem with "direct using the I2C_XXX macros"? You can always #define the I2C_XXX macros sucht hat they indeed call the required functions, right? I really don;t get the point.

The problem is actual (if I see this right ;-) ), that if someone wants to call a function, this function is somewhere defined, and the soft_i2c driver didn;t know how this function look like ... and my patch just defines an "API", so that not everybody comes with new names and new includes ... And this include sits no longer in the config file but in the soft_i2c driver ... thats it.
I just did this as a fast proposal for what Alessandro suggested:
"I don't think my approach is beautiful at all (both #ifndef __ASSEMBLY__ and #include "../board/"), but I didn't find a better solution" see:

http://lists.denx.de/pipermail/u-boot/2009-July/056867.html

So, I thought, to prevent such includes in a lot of config files, and a lot of new function names for the same thing, it would be nice to have such an "API" ...

Quoted 6 lines
Quoted 3 lines

work as they are ... but as we discussed this, this patch is not a need, because we can do this functionality also at the moment (of course with this unlovley include in the config file)

What's the difference between include one file or another? I see no real difference between including <asm/gpio.h> versus <soft_i2c.h>.

This is true if we have gpio api! So we just include the gpio.h in soft_i2c.c and it works, but we have not such an API yet ...

Quoted 10 lines
Quoted 2 lines

If this is in future a no go (as Jean-Christophe suggested for the Kconfig support), we can then maybe switch to this proposal ...

Well, we should not assume that we can use Kconfig to sole all configuration issues. This is IMO not possible with reasonable efforts and within a reasonable time frame. Let's be happy when we cover 95 or even 90%, and then focus on the rest. But don't lets make (eventually false) assumptions which constructs may or may not conflict with a not even yet existing implementation.

Quoted 8 lines

You know - early optimizian has never been a good idea.

Quoted 4 lines

Hmm... also I don;t want to do this with the "multibus/multiadapter" rework, because this rework is for themselve a big change, which where I wouldn;t add one more big change ... so we maybe lost control, why things no longer work ...

Heh. Clever, you didn't swallow the bait ;-)

:-)

bye
Heiko

Signature · 2 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany