sh: i2c: Add support I2C controller of SH7734
PATCH 1/1 sh: i2c: Add support I2C controller of SH7734
Renesas SH7734 has two I2C interfaceis.
This supports these I2C.
V3: - Fix error for whitespace.
V2: - Changed bit control to use the clr|set|clrsetbits_* functions.
- Fix wrong comment style.
- Add new line before for loop in i2c_read.
--- drivers/i2c/Makefile | 1 + drivers/i2c/sh_sh7734_i2c.c | 445 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 446 insertions(+), 0 deletions(-) create mode 100644 drivers/i2c/sh_sh7734_i2c.c
drivers/i2c/Makefile +1 -0
@@ -44,6 +44,7 @@ COBJS-$(CONFIG_SPEAR_I2C) += spr_i2c.o COBJS-$(CONFIG_TSI108_I2C) += tsi108_i2c.o COBJS-$(CONFIG_U8500_I2C) += u8500_i2c.o COBJS-$(CONFIG_SH_I2C) += sh_i2c.o +COBJS-$(CONFIG_SH_SH7734_I2C) += sh_sh7734_i2c.o COBJS := $(COBJS-y) SRCS := $(COBJS:.o=.c)
drivers/i2c/sh_sh7734_i2c.c new file +445 -0
445 lines not on this page · raw message
Signature · 1 line
1.7.7.3
PATCH 1/1 sh: i2c: Add support I2C controller of SH7734
Quoted 7 lines · On Tuesday 21 February 2012 20:13:47 Nobuhiro Iwamatsu wrote:
drivers/i2c/sh_sh7734_i2c.c new file +4
-0+#if DEBUG +static void sh_i2c_dump_reg (struct sh_i2c *base) +{ +printf ("iccr1 : %02X\n" ,readb (&base->iccr1));
drivers/i2c/sh_sh7734_i2c.c line 189
Quoted 10 lines
drivers/i2c/sh_sh7734_i2c.c new file +10
-0+printf ("iccr2 : %02X\n" ,readb (&base->iccr2)); +printf ("icmr : %02X\n" ,readb (&base->icmr)); +printf ("icier : %02X\n" ,readb (&base->icier)); +printf ("icsr : %02X\n" ,readb (&base->icsr)); +printf ("sar : %02X\n" ,readb (&base->sar)); +printf ("icdrt : %02X\n" ,readb (&base->icdrt)); +printf ("icdrr : %02X\n" ,readb (&base->icdrr)); + printf("nf2cyc: %02X\n", readb(&base->nf2cyc)); +} +#endif
if you used debug(), you wouldn't need the DEBUG check
drivers/i2c/sh_sh7734_i2c.c line 252
Quoted 8 lines
drivers/i2c/sh_sh7734_i2c.c new file +8
-0+static int +i2c_raw_write (struct sh_i2c *base,u8 id,u8 reg,u8 *val,int size) +{ +int i; +u8 data; + +if (i2c_set_addr (base, id, reg)) { +printf ("Fail set slave address\n" );
should use puts() when there's no fmt
drivers/i2c/sh_sh7734_i2c.c line 256
Quoted 1 line
drivers/i2c/sh_sh7734_i2c.c new file +1
-0+for (i =0 ; i < size ; i++) {
no space before the semi-colon
Quoted 7 lines
drivers/i2c/sh_sh7734_i2c.c new file +7
-0+int i2c_set_bus_num (unsigned int bus) +{ +if ((bus <0 ) || (bus >=CONFIG_SYS_MAX_I2C_BUS )) { +printf ("Bad bus: %d\n" , bus); +return -1 ; + } +
drivers/i2c/sh_sh7734_i2c.c line 352
Quoted 10 lines
drivers/i2c/sh_sh7734_i2c.c new file +10
-0+switch (bus) { +case 0 : + base = (void *)CONFIG_SH_I2C_BASE0 ; +break ; +case 1 : + base = (void *)CONFIG_SH_I2C_BASE1 ; +break ; +default : +return -1 ; + }
do you need the if() check if you have default here ?
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120221/eafc816a/attachment.pgp>
PATCH 1/1 sh: i2c: Add support I2C controller of SH7734
Quoted 20 lines · On Tuesday 21 February 2012 20:13:47 Nobuhiro Iwamatsu wrote:
Quoted 7 lines
drivers/i2c/sh_sh7734_i2c.c new file +4
-0+#if DEBUG +static void sh_i2c_dump_reg (struct sh_i2c *base) +{ +printf ("iccr1 : %02X\n" ,readb (&base->iccr1));drivers/i2c/sh_sh7734_i2c.c line 189
Quoted 10 lines
drivers/i2c/sh_sh7734_i2c.c new file +10
-0+printf ("iccr2 : %02X\n" ,readb (&base->iccr2)); +printf ("icmr : %02X\n" ,readb (&base->icmr)); +printf ("icier : %02X\n" ,readb (&base->icier)); +printf ("icsr : %02X\n" ,readb (&base->icsr)); +printf ("sar : %02X\n" ,readb (&base->sar)); +printf ("icdrt : %02X\n" ,readb (&base->icdrt)); +printf ("icdrr : %02X\n" ,readb (&base->icdrr)); + printf("nf2cyc: %02X\n", readb(&base->nf2cyc)); +} +#endif if you used
debug(), you wouldn't need the DEBUG check
But this puts lower amount of strain on the CPP. It doesn't have to check if DEBUG is defined 10 times, but only once ;-) Putting this into one big debug() call is also possible btw., though I don't like it.
Quoted 27 lines
drivers/i2c/sh_sh7734_i2c.c line 252
Quoted 9 lines
drivers/i2c/sh_sh7734_i2c.c new file +8
-0+static int +i2c_raw_write (struct sh_i2c *base,u8 id,u8 reg,u8 *val,int size) +{ +int i; +u8 data; + +if (i2c_set_addr (base, id, reg)) { +printf ("Fail set slave address\n" );should use
puts()when there's no fmtdrivers/i2c/sh_sh7734_i2c.c line 256
Quoted 1 line
drivers/i2c/sh_sh7734_i2c.c new file +1
-0+for (i =0 ; i < size ; i++) {no space before the semi-colon
Quoted 11 lines
drivers/i2c/sh_sh7734_i2c.c new file +11
-0+int i2c_set_bus_num (unsigned int bus) +{ +if ((bus <0 ) || (bus >=CONFIG_SYS_MAX_I2C_BUS )) { +printf ("Bad bus: %d\n" , bus); +return -1 ; + } + +switch (bus) { +case 0 : + base = (void *)CONFIG_SH_I2C_BASE0 ; +break ;
Quoted 8 lines
drivers/i2c/sh_sh7734_i2c.c line 352
Quoted 6 lines
drivers/i2c/sh_sh7734_i2c.c new file +6
-0+case 1 : + base = (void *)CONFIG_SH_I2C_BASE1 ; +break ; +default : +return -1 ; + }do you need the
if()check if you have default here ?
CONFIG_SYS_MAX_I2C_BUS may be different in some obscure case?
M
Quoted 1 line
-mike
PATCH 1/1 sh: i2c: Add support I2C controller of SH7734
Quoted 21 lines · On Wednesday 22 February 2012 08:53:50 Marek Vasut wrote:
Quoted 20 lines · On Tuesday 21 February 2012 20:13:47 Nobuhiro Iwamatsu wrote:
Quoted 7 lines
drivers/i2c/sh_sh7734_i2c.c new file +4
-0+#if DEBUG +static void sh_i2c_dump_reg (struct sh_i2c *base) +{ +printf ("iccr1 : %02X\n" ,readb (&base->iccr1));drivers/i2c/sh_sh7734_i2c.c line 189
Quoted 10 lines
drivers/i2c/sh_sh7734_i2c.c new file +10
-0+printf ("iccr2 : %02X\n" ,readb (&base->iccr2)); +printf ("icmr : %02X\n" ,readb (&base->icmr)); +printf ("icier : %02X\n" ,readb (&base->icier)); +printf ("icsr : %02X\n" ,readb (&base->icsr)); +printf ("sar : %02X\n" ,readb (&base->sar)); +printf ("icdrt : %02X\n" ,readb (&base->icdrt)); +printf ("icdrr : %02X\n" ,readb (&base->icdrr)); + printf("nf2cyc: %02X\n", readb(&base->nf2cyc)); +} +#endif if you used
debug(), you wouldn't need the DEBUG check
Quoted 3 lines
But this puts lower amount of strain on the CPP. It doesn't have to check if DEBUG is defined 10 times, but only once ;-) Putting this into one big
debug()call is also possible btw., though I don't like it.
assuming you're not joking, i'm fairly certain that's now how the CPP engine works. we want to minimize ifdef's and let the compiler to code checking as much as possible and do DCE on unused stuff.
Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
drivers/i2c/sh_sh7734_i2c.c new file +11
-0+int i2c_set_bus_num (unsigned int bus) +{ +if ((bus <0 ) || (bus >=CONFIG_SYS_MAX_I2C_BUS )) { +printf ("Bad bus: %d\n" , bus); +return -1 ; + } + +switch (bus) { +case 0 : + base = (void *)CONFIG_SH_I2C_BASE0 ; +break ;Quoted 8 lines
drivers/i2c/sh_sh7734_i2c.c line 352
Quoted 6 lines
drivers/i2c/sh_sh7734_i2c.c new file +6
-0+case 1 : + base = (void *)CONFIG_SH_I2C_BASE1 ; +break ; +default : +return -1 ; + }do you need the
if()check if you have default here ?
Quoted 1 line
CONFIG_SYS_MAX_I2C_BUSmay be different in some obscure case?
unlikely, but you're right. the code could still be unified though:
if (bus >= CONFIG_SYS_MAX_I2C_BUS)
goto case_bad_bus;
switch (bus) {
case 0:
...
case 1:
...
case_bad_bus:
default:
printf("...warning...");
return -1;
}-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120222/c09d76af/attachment.pgp>
PATCH 1/1 sh: i2c: Add support I2C controller of SH7734
In reply to Mike FrysingerHi, Mike.
Thank you for your review.
2012/2/22 Mike Frysinger <[email protected]>:
Quoted 20 lines · On Tuesday 21 February 2012 20:13:47 Nobuhiro Iwamatsu wrote:
Quoted 7 lines
drivers/i2c/sh_sh7734_i2c.c new file +4
-0+#if DEBUG +static void sh_i2c_dump_reg (struct sh_i2c *base) +{ + ? ? printf("iccr1 : %02X\n", readb(&base->iccr1));drivers/i2c/sh_sh7734_i2c.c
Quoted 10 lines
drivers/i2c/sh_sh7734_i2c.c new file +10
-0+ ? ? printf("iccr2 : %02X\n", readb(&base->iccr2)); + ? ? printf("icmr ?: %02X\n", readb(&base->icmr)); + ? ? printf("icier : %02X\n", readb(&base->icier)); + ? ? printf("icsr ?: %02X\n", readb(&base->icsr)); + ? ? printf("sar ? : %02X\n", readb(&base->sar)); + ? ? printf("icdrt : %02X\n", readb(&base->icdrt)); + ? ? printf("icdrr : %02X\n", readb(&base->icdrr)); + ? ? printf("nf2cyc: %02X\n", readb(&base->nf2cyc)); +} +#endif if you used
debug(), you wouldn't need the DEBUG check
OK, but sh_i2c_dump_reg function is not referred from anywhere, I remove.
Quoted 11 lines
drivers/i2c/sh_sh7734_i2c.c
Quoted 9 lines
drivers/i2c/sh_sh7734_i2c.c new file +8
-0+static int +i2c_raw_write (struct sh_i2c *base,u8 id,u8 reg,u8 *val,int size) +{ + ? ? int i; + ? ? u8 data; + + ? ? if (i2c_set_addr(base, id, reg)) { + ? ? ? ? ? ? printf("Fail set slave address\n");should use
puts()when there's no fmt
OK.
Quoted 16 lines
Quoted 2 lines
+ ? ? for (i = 0 ; i < size ; i++) {
no space before the semi-colon
Quoted 11 lines
drivers/i2c/sh_sh7734_i2c.c new file +11
-0+int i2c_set_bus_num (unsigned int bus) +{ + ? ? if ((bus < 0) || (bus >= CONFIG_SYS_MAX_I2C_BUS)) { + ? ? ? ? ? ? printf("Bad bus: %d\n", bus); + ? ? ? ? ? ? return -1; + ? ? } + + ? ? switch (bus) { + ? ? case 0: + ? ? ? ? ? ? base = (void *)CONFIG_SH_I2C_BASE0; + ? ? ? ? ? ? break;
Quoted 8 lines
Quoted 6 lines
+ ? ? case 1:
+ ? ? ? ? ? ? base = (void *)CONFIG_SH_I2C_BASE1;
+ ? ? ? ? ? ? break;
+ ? ? default:
+ ? ? ? ? ? ? return -1;
+ ? ? }do you need the
if()check if you have default here ?
int i2c_set_bus_num(unsigned int bus)
{
switch (bus) {
case 0:
base = (void *)CONFIG_SH_I2C_BASE0;
break;
case 1:
base = (void *)CONFIG_SH_I2C_BASE1;
break;
default:
printf("Bad bus: %d\n", bus);
return -1;Bestr regards,
Nobuhiro
Signature · 1 line
Nobuhiro Iwamatsu