Topcliff: Update PCH_I2C driver to 2.6.35
PATCH 1/1 Topcliff: Update PCH_I2C driver to 2.6.35
I2C driver of Topcliff PCH
Topcliff PCH is the platform controller hub that is going to be used in Intel's upcoming general embedded platform. All IO peripherals in Topcliff PCH are actually devices sitting on AMBA bus. Topcliff PCH has I2C I/F. Using this I/F, it is able to access system devices connected to I2C.
--- drivers/i2c/busses/Kconfig | 18 + drivers/i2c/busses/Makefile | 1 + drivers/i2c/busses/i2c-pch.c | 966 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 985 insertions(+), 0 deletions(-) create mode 100644 drivers/i2c/busses/i2c-pch.c
drivers/i2c/busses/Kconfig +18 -0
@@ -613,6 +613,24 @@ config I2C_XILINX This driver can also be built as a module. If so, the module will be called xilinx_i2c. +config PCH_I2C + tristate "PCH I2C of Intel Topcliff" + depends on PCI + help + This driver is for PCH(Platform controller Hub) I2C of Topcliff which + is an IOH(Input/Output Hub) for x86 embedded processor. + This driver can access PCH I2C bus device. + +config PCH_I2C_CH_COUNT + int "PCH I2C the number of channel count" + range 1 2 + depends on PCH_I2C + help + This driver is for PCH(Platform controller Hub) I2C of Topcliff which + is an IOH(Input/Output Hub) for x86 embedded processor. + The number of I2C buses/channels supported by the PCH I2C controller. + PCH I2C of Topcliff supports only one channel. + comment "External I2C/SMBus adapter drivers" config I2C_PARPORT
drivers/i2c/busses/Makefile +1 -0
@@ -59,6 +59,7 @@ obj-$(CONFIG_I2C_STU300) += i2c-stu300.o obj-$(CONFIG_I2C_VERSATILE) += i2c-versatile.o obj-$(CONFIG_I2C_OCTEON) += i2c-octeon.o obj-$(CONFIG_I2C_XILINX) += i2c-xiic.o +obj-$(CONFIG_PCH_I2C) += i2c-pch.o # External I2C/SMBus adapter drivers obj-$(CONFIG_I2C_PARPORT) += i2c-parport.o
drivers/i2c/busses/i2c-pch.c new file +966 -0
966 lines not on this page · raw message
Signature · 1 line
1.6.0.6
Quoted 2 lines · Masayuki Ohtak
I2C driver of Topcliff PCH
+++b/drivers/i2c/busses/i2c-pch.c
[]
Quoted 1 line
+static void
pch_init(struct i2c_algo_pch_data *adap)
[]
drivers/i2c/busses/i2c-pch.c line 225
Quoted 4 lines
drivers/i2c/busses/i2c-pch.c new file +4
-0+if (pch_i2c_speed ==FAST_MODE_CLK ) { + reg_value |=FAST_MODE_EN ; +dev_dbg (adap->pch_adapter.dev.parent,"Fast mode enabled\n" ); + }
Just a suggestion below, ignore it at your pleasure...
These dev_<level> calls might be easier to read if you had some #defines like:
#define pch_dbg(adap, fmt, arg...) \ dev_dbg(adap->pch_adapter.dev.parent, fmt, ##arg) #define pch_err(adap, fmt, arg...) \ dev_err(adap->pch_adapter.dev.parent, fmt, ##arg) #define pch_info(adap, fmt, arg...) \ dev_info(adap->pch_adapter.dev.parent, fmt, ##arg)
then the last dev_dbg becomes:
pch_dbg(adap, "Fast mode enabled\n");
Many modules use similar wrapper #defines.
drivers/i2c/busses/i2c-pch.c line 243
Quoted 4 lines
drivers/i2c/busses/i2c-pch.c new file +4
-0+dev_dbg (adap->pch_adapter.dev.parent, +"%s: I2CCTL=%x pch_i2cbc=%x pch_i2ctmr=%x Enable interrupts\n" , + __func__,ioread32 (p +PCH_I2CCTL ), + pch_i2cbc, pch_i2ctmr);
pch_dbg(adap, etc...)
etc.
cheers, Joe
Hi Joe,
Thank you for your comments.
We will update.
Thanks, Ohtake(OKISemi)
----- Original Message -----
From: "Joe Perches" <[email protected]>
To: "Masayuki Ohtak" <masa-korg-ECg8zkTtlr0C6LszWs/[email protected]>
Cc: "Jean Delvare (PC drivers, core)" <[email protected]>; "Ben Dooks (embedded platforms)" <[email protected]>; "Crane Cai" <[email protected]>; "Samuel Ortiz" <sameo-VuQAYsv1563Yd54FQh9/[email protected]>; "Linus Walleij" <linus.walleij-0IS4wlFg1OjSUeElwK9/[email protected]>; "Ralf Baechle" <ralf-6z/[email protected]>; "srinidhi kasagar" <srinidhi.kasagar-0IS4wlFg1OjSUeElwK9/[email protected]>; <[email protected]>; <[email protected]>; "Wang Yong Y"" <[email protected]>; "Wang Qi"" <[email protected]>; "Andrew"" <[email protected]>; <arjan-VuQAYsv1563Yd54FQh9/[email protected]>; "Tomoya MORINAGA" <morinaga526-ECg8zkTtlr0C6LszWs/[email protected]>; "Arnd Bergmann" <[email protected]>
Sent: Wednesday, September 01, 2010 11:43 AM
Subject: Re: [MeeGo-Dev][PATCH] Topcliff: Update PCH_I2C driver to 2.6.35
Quoted 40 lines · Masayuki Ohtak
Quoted 2 lines
I2C driver of Topcliff PCH
+++b/drivers/i2c/busses/i2c-pch.c[]
Quoted 1 line
+static void
pch_init(struct i2c_algo_pch_data *adap)[]
Quoted 4 lines
+ if (
pch_i2c_speed==FAST_MODE_CLK) {
+reg_value|=FAST_MODE_EN;
+dev_dbg(adap->pch_adapter.dev.parent, "Fast mode enabled\n");
+ }Just a suggestion below, ignore it at your pleasure...
These dev_<level> calls might be easier to read if you had some #defines like:
#define
pch_dbg(adap, fmt, arg...)\dev_dbg(adap->pch_adapter.dev.parent, fmt, ##arg)#definepch_err(adap, fmt, arg...)\dev_err(adap->pch_adapter.dev.parent, fmt, ##arg)#definepch_info(adap, fmt, arg...)\dev_info(adap->pch_adapter.dev.parent, fmt, ##arg)then the last
dev_dbgbecomes:
pch_dbg(adap, "Fast mode enabled\n");Many modules use similar wrapper #defines.
Quoted 4 lines
+ dev_dbg(adap->pch_adapter.dev.parent,
+ "%s: I2CCTL=%x pch_i2cbc=%x pch_i2ctmr=%x Enable interrupts\n",
+__func__,ioread32(p + PCH_I2CCTL),
+pch_i2cbc,pch_i2ctmr);
pch_dbg(adap, etc...)etc.
cheers, Joe
Hi Joe,
I have a question.
Current our I2C driver has the following 2 patterns dev_err().
(1) dev_err(adap->pch_adapter.dev.parent, "...");
(2) dev_err(&pdev->dev, "...");
Quoted 2 lines
#define
pch_err(adap, fmt, arg...)\dev_err(adap->pch_adapter.dev.parent, fmt, ##arg)
In case of using the above code, pattern (1) can apply, but (2) can't.
As to (2),
Should we use as dev_err or define another macro?
Thanks, Ohtake(OKISemi)
----- Original Message -----
From: "Joe Perches" <[email protected]>
To: "Masayuki Ohtak" <masa-korg-ECg8zkTtlr0C6LszWs/[email protected]>
Cc: "Jean Delvare (PC drivers, core)" <[email protected]>; "Ben Dooks (embedded platforms)" <[email protected]>; "Crane Cai" <[email protected]>; "Samuel Ortiz" <sameo-VuQAYsv1563Yd54FQh9/[email protected]>; "Linus Walleij" <linus.walleij-0IS4wlFg1OjSUeElwK9/[email protected]>; "Ralf Baechle" <ralf-6z/[email protected]>; "srinidhi kasagar" <srinidhi.kasagar-0IS4wlFg1OjSUeElwK9/[email protected]>; <[email protected]>; <[email protected]>; "Wang Yong Y"" <[email protected]>; "Wang Qi"" <[email protected]>; "Andrew"" <[email protected]>; <arjan-VuQAYsv1563Yd54FQh9/[email protected]>; "Tomoya MORINAGA" <morinaga526-ECg8zkTtlr0C6LszWs/[email protected]>; "Arnd Bergmann" <[email protected]>
Sent: Wednesday, September 01, 2010 11:43 AM
Subject: Re: [MeeGo-Dev][PATCH] Topcliff: Update PCH_I2C driver to 2.6.35
Quoted 40 lines · Masayuki Ohtak
Quoted 2 lines
I2C driver of Topcliff PCH
+++b/drivers/i2c/busses/i2c-pch.c[]
Quoted 1 line
+static void
pch_init(struct i2c_algo_pch_data *adap)[]
Quoted 4 lines
+ if (
pch_i2c_speed==FAST_MODE_CLK) {
+reg_value|=FAST_MODE_EN;
+dev_dbg(adap->pch_adapter.dev.parent, "Fast mode enabled\n");
+ }Just a suggestion below, ignore it at your pleasure...
These dev_<level> calls might be easier to read if you had some #defines like:
#define
pch_dbg(adap, fmt, arg...)\dev_dbg(adap->pch_adapter.dev.parent, fmt, ##arg)#definepch_err(adap, fmt, arg...)\dev_err(adap->pch_adapter.dev.parent, fmt, ##arg)#definepch_info(adap, fmt, arg...)\dev_info(adap->pch_adapter.dev.parent, fmt, ##arg)then the last
dev_dbgbecomes:
pch_dbg(adap, "Fast mode enabled\n");Many modules use similar wrapper #defines.
Quoted 4 lines
+ dev_dbg(adap->pch_adapter.dev.parent,
+ "%s: I2CCTL=%x pch_i2cbc=%x pch_i2ctmr=%x Enable interrupts\n",
+__func__,ioread32(p + PCH_I2CCTL),
+pch_i2cbc,pch_i2ctmr);
pch_dbg(adap, etc...)etc.
cheers, Joe
Quoted 9 lines · Masayuki Ohtake
I have a question.
Current our I2C driver has the following 2 patternsdev_err().
(1)dev_err(adap->pch_adapter.dev.parent, "...");
(2)dev_err(&pdev->dev, "...");Quoted 2 lines
#define
pch_err(adap, fmt, arg...)\dev_err(adap->pch_adapter.dev.parent, fmt, ##arg)In case of using the above code, pattern (1) can apply, but (2) can't. As to (2),
Should we use asdev_error define another macro?
Hello Ohtake.
To me, it's a visual complexity vs std pattern trade-off.
A 2 level dereference like dev_info(&dev->dev, ...) isn't overly difficult to read.
3 or more dereferences can be harder and a bit error prone. So I would only use pch_<level> for (1) and dev_err for (2).
There are also times when there are additional standard arguments that you want to prefix to dev_<level> calls and that can be simplified with a custom XXX_<level> define for dev_<level>
Look at the current uses in the tree and see what you like.
$ grep -rP --include=*.[ch] "#define\s*.+\s+dev_[a-z]{3,7}\s*\(" *These aren't requirements, do what you think best.
cheers, Joe
Hi Joe,
Thank you for your comments.
Best Regards,
Ohtake(OKISemi)
----- Original Message -----
From: "Joe Perches" <[email protected]>
To: "Masayuki Ohtake" <masa-korg-ECg8zkTtlr0C6LszWs/[email protected]>
Cc: "Jean Delvare (PC drivers, core)" <[email protected]>; "Ben Dooks (embedded platforms)" <[email protected]>; "Crane Cai" <[email protected]>; "Samuel Ortiz" <sameo-VuQAYsv1563Yd54FQh9/[email protected]>; "Linus Walleij" <linus.walleij-0IS4wlFg1OjSUeElwK9/[email protected]>; "Ralf Baechle" <ralf-6z/[email protected]>; "srinidhi kasagar" <srinidhi.kasagar-0IS4wlFg1OjSUeElwK9/[email protected]>; <[email protected]>; <[email protected]>; "Wang Yong Y"" <[email protected]>; "Wang Qi"" <[email protected]>; "Andrew"" <[email protected]>; <arjan-VuQAYsv1563Yd54FQh9/[email protected]>; "Tomoya MORINAGA" <morinaga526-ECg8zkTtlr0C6LszWs/[email protected]>; "Arnd Bergmann" <[email protected]>
Sent: Wednesday, September 01, 2010 2:24 PM
Subject: Re: [MeeGo-Dev][PATCH] Topcliff: Update PCH_I2C driver to 2.6.35
Quoted 33 lines · Masayuki Ohtake
Quoted 9 lines
I have a question.
Current our I2C driver has the following 2 patternsdev_err().
(1)dev_err(adap->pch_adapter.dev.parent, "...");
(2)dev_err(&pdev->dev, "...");Quoted 2 lines
#define
pch_err(adap, fmt, arg...)\dev_err(adap->pch_adapter.dev.parent, fmt, ##arg)In case of using the above code, pattern (1) can apply, but (2) can't. As to (2),
Should we use asdev_error define another macro?Hello Ohtake.
To me, it's a visual complexity vs std pattern trade-off.
A 2 level dereference like
dev_info(&dev->dev, ...)isn't overly difficult to read.
3 or more dereferences can be harder and a bit error prone. So I would only use pch_<level> for (1) anddev_errfor (2).There are also times when there are additional standard arguments that you want to prefix to dev_<level> calls and that can be simplified with a custom XXX_<level> define for dev_<level>
Look at the current uses in the tree and see what you like.
$ grep -rP --include=*.[ch] "#define\s*.+\s+dev_[a-z]{3,7}\s*\(" *These aren't requirements, do what you think best.
cheers, Joe
2010/9/1 Masayuki Ohtak <masa-korg-ECg8zkTtlr0C6LszWs/[email protected]>:
Quoted 18 lines
I2C driver of Topcliff PCH
(...)
+++b/drivers/i2c/busses/i2c-pch.c
(...)drivers/i2c/busses/i2c-pch.c new file +14
-0+/** +* pch_wait_for_bus_idle() - check the status of bus. +* @adap: Pointer to struct i2c_algo_pch_data. +* @timeout: waiting time counter (us). +*/ +static s32 pch_wait_for_bus_idle (struct i2c_algo_pch_data *adap, + s32 timeout) +{ + void __iomem *p = adap->pch_base_address; + + /* MAX timeout value is timeout*1000*1000nsec */ + ktime_t ns_val = ktime_add_ns(ktime_get(), timeout*1000*1000); + do { + if ((ioread32(p + PCH_I2CSR) & I2CMBB_BIT) == 0)
drivers/i2c/busses/i2c-pch.c line 276
Quoted 10 lines
drivers/i2c/busses/i2c-pch.c new file +10
-0+ break; + msleep(1); + } while (ktime_lt(ktime_get(), ns_val)); + + dev_dbg(adap->pch_adapter.dev.parent, + "%s : I2CSR = %x\n", __func__, ioread32(p + PCH_I2CSR)); + + if (timeout == 0) { + dev_err(adap->pch_adapter.dev.parent, + "%s :return%d\n", __func__, -ETIME);
Why not just return -ETIME; here?
Quoted 4 lines
+ } else {
+ dev_dbg(adap->pch_adapter.dev.parent,
+ "%s : return %d\n",__func__, 0);
+ }
Delete this else clause, who is interested in return 0???
Quoted 1 line
+ return ((timeout <= 0) ? (
-ETIME) : (0));
return 0;
drivers/i2c/busses/i2c-pch.c line 309
Quoted 12 lines
(...)
drivers/i2c/busses/i2c-pch.c new file +11
-0+/** +* pch_wait_for_xfer_complete() - initiates a wait for the tx complete event +* @adap: Pointer to struct i2c_algo_pch_data. +*/ +static s32 pch_wait_for_xfer_complete (struct i2c_algo_pch_data *adap) +{ + s32 ret; + ret = wait_event_interruptible_timeout(pch_event, + (adap->pch_event_flag != 0), msecs_to_jiffies(50)); + if (ret < 0) + goto out;
The goto construction is unnecessary, just
return ret;
Quoted 4 lines
+
+ if (ret == 0) {
+ ret =-ETIMEDOUT;
+ goto out;
return -ETIMEDOUT;
Quoted 7 lines
+ }
+
+ if (adap->pch_event_flag&I2C_ERROR_MASK) {
+ ret =-EIO;
+ dev_err(adap->pch_adapter.dev.parent,
+ "error bits set: %x\n",adap->pch_event_flag);
+ goto out;
Skip ret assignment
return -EIO;
Quoted 4 lines
+ }
+
+adap->pch_event_flag= 0;
+ ret = 0;
Skip this
Quoted 2 lines
+out:
+ return ret;
return 0;
Quoted 10 lines
drivers/i2c/busses/i2c-pch.c new file +9
-0+} +/** +* pch_getack() - to confirm ACK/NACK +* @adap: Pointer to struct i2c_algo_pch_data. +*/ +static s32 pch_getack (struct i2c_algo_pch_data *adap) +{ + u32 reg_val; + void __iomem *p = adap->pch_base_address;
drivers/i2c/busses/i2c-pch.c line 346
Quoted 10 lines
drivers/i2c/busses/i2c-pch.c new file +10
-0+ reg_val = ioread32(p + PCH_I2CSR) & PCH_GETACK; + + if (reg_val == 0) + dev_dbg(adap->pch_adapter.dev.parent, "%s : return 0\n", + __func__); + else + dev_dbg(adap->pch_adapter.dev.parent, "%s : return%d\n", + __func__, -EPROTO); + + return (((reg_val) == 0) ? (0) : (-EPROTO));
Refactor this like the other function, no weirdo debug prints return 0;
Quoted 11 lines
drivers/i2c/busses/i2c-pch.c new file +10
-0+} +/** +* pch_writebytes() - write data to I2C bus in normal mode +* @i2c_adap: Pointer to the struct i2c_adapter. +* @last: specifies whether last message or not. +* In the case of compound mode it will be 1 for last message, +* otherwise 0. +* @first: specifies whether first message or not. +* 1 for first message otherwise 0. +*/
drivers/i2c/busses/i2c-pch.c line 392
Quoted 10 lines
drivers/i2c/busses/i2c-pch.c new file +10
-0+static s32 pch_writebytes (struct i2c_adapter *i2c_adap,struct i2c_msg *msgs, + u32 last, u32 first) +{ + struct i2c_algo_pch_data *adap = i2c_adap->algo_data; + u8 *buf; + u32 length; + u32 addr; + u32 addr_2_msb; + u32 addr_8_lsb; + s32 wrcount;
You don't assign anything to wrcount...
Quoted 29 lines
+ void
__iomem*p =adap->pch_base_address;
+ length =msgs->len;
+ buf =msgs->buf;
+ addr =msgs->addr;
+ /* enable master tx */
+pch_setbit((adap->pch_base_address), PCH_I2CCTL, I2C_TX_MODE);drivers/i2c/busses/i2c-pch.c new file +23
-0+ + dev_dbg(adap->pch_adapter.dev.parent, + "%s : I2CCTL = %x msgs->len = %d\n", __func__, + ioread32(p + PCH_I2CCTL), length); + + if (first) { + if (pch_wait_for_bus_idle(adap, BUS_IDLE_TIMEOUT) == -ETIME) + return -ETIME; + } + + if (msgs->flags & I2C_M_TEN) { + addr_2_msb = ((addr & I2C_MSB_2B_MSK) >> 7); + iowrite32(addr_2_msb | TEN_BIT_ADDR_MASK, p + PCH_I2CDR); + if (first) + pch_start(adap); + if ((pch_wait_for_xfer_complete(adap) == 0) && + (pch_getack(adap) == 0)) { + addr_8_lsb = (addr & I2C_ADDR_MSK); + iowrite32(addr_8_lsb, p + PCH_I2CDR); + } else { + pch_stop(adap); + return -ETIME; + }
drivers/i2c/busses/i2c-pch.c line 431
Quoted 10 lines
drivers/i2c/busses/i2c-pch.c new file +10
-0+ } else { + /* set 7 bit slave address and R/W bit as 0 */ + iowrite32(addr << 1, p + PCH_I2CDR); + if (first) + pch_start(adap); + } + + if ((pch_wait_for_xfer_complete(adap) == 0) && + (pch_getack(adap) == 0)) { + for (wrcount = 0; wrcount < length; ++wrcount) {
...but it is only conditionally used here...
Quoted 23 lines
+ /* write buffer value to I2C data register */
+iowrite32(buf[wrcount], p + PCH_I2CDR);
+ dev_dbg(adap->pch_adapter.dev.parent,
+ "%s : writing %x to Data register\n",
+__func__, buf[wrcount]);drivers/i2c/busses/i2c-pch.c new file +18
-0+ + if (pch_wait_for_xfer_complete(adap) != 0) { + wrcount = -ETIME; + break; + } + + dev_dbg(adap->pch_adapter.dev.parent, + "%s return %d", __func__, 0); + + if (pch_getack(adap)) { + wrcount = -ETIME; + break; + } + } + + /* check if this is the last message */ + if (last) + pch_stop(adap);
drivers/i2c/busses/i2c-pch.c line 464
Quoted 10 lines
drivers/i2c/busses/i2c-pch.c new file +10
-0+ else + pch_repstart(adap); + } else { + pch_stop(adap); + } + + dev_dbg(adap->pch_adapter.dev.parent, + "%s return=%d\n", __func__, wrcount); + + return wrcount;
...and then you return it, leading to a possibly unassigned state.
Quoted 6 lines
drivers/i2c/busses/i2c-pch.c new file +5
-0+} +/** +* pch_readbytes() - read data from I2C bus in normal mode. +* @i2c_adap: Pointer to the struct i2c_adapter. +* @msgs: Pointer to i2c_msg structure.
drivers/i2c/busses/i2c-pch.c line 504
Quoted 10 lines
drivers/i2c/busses/i2c-pch.c new file +10
-0+* @last: specifies whether last message or not. +* @first: specifies whether first message or not. +*/ +s32 pch_readbytes (struct i2c_adapter *i2c_adap,struct i2c_msg *msgs, + u32 last, u32 first) +{ + struct i2c_algo_pch_data *adap = i2c_adap->algo_data; + + u8 *buf; + u32 count;
Same problem here. Initialize to 0.
Quoted 91 lines
+ u32 length;
+ u32 addr;
+ u32addr_2_msb;
+ void__iomem*p =adap->pch_base_address;
+ length =msgs->len;
+ buf =msgs->buf;
+ addr =msgs->addr;drivers/i2c/busses/i2c-pch.c new file +82
-0+ + /* enable master reception */ + pch_clrbit((adap->pch_base_address), PCH_I2CCTL, I2C_TX_MODE); + + if (first) { + if (pch_wait_for_bus_idle(adap, BUS_IDLE_TIMEOUT) == -ETIME) + return -ETIME; + } + + if (msgs->flags & I2C_M_TEN) { + addr_2_msb = (((addr & I2C_MSB_2B_MSK) >> 7) | (I2C_RD)); + iowrite32(addr_2_msb | TEN_BIT_ADDR_MASK, p + PCH_I2CDR); + + } else { + /* 7 address bits + R/W bit */ + addr = (((addr) << 1) | (I2C_RD)); + iowrite32(addr, p + PCH_I2CDR); + } + + /* check if it is the first message */ + if (first) + pch_start(adap); + + if ((pch_wait_for_xfer_complete(adap) == 0) + && (pch_getack(adap) == 0)) { + dev_dbg(adap->pch_adapter.dev.parent, + "%s return %d", __func__, 0); + + if (length == 0) { + pch_stop(adap); + ioread32(p + PCH_I2CDR); /* Dummy read needs */ + + count = length; + } else { + int read_index; + int loop; + pch_sendack(adap); + + /* Dummy read */ + for (loop = 1, read_index = 0; loop < length; loop++) { + buf[read_index] = ioread32(p + PCH_I2CDR); + + if (loop != 1) + read_index++; + + if (pch_wait_for_xfer_complete(adap) != 0) { + pch_stop(adap); + return -ETIME; + } + } /* end for */ + + pch_sendnack(adap); + + buf[read_index] = ioread32(p + PCH_I2CDR); + + if (length != 1) + read_index++; + + if (pch_wait_for_xfer_complete(adap) == 0) { + if (last) + pch_stop(adap); + else + pch_repstart(adap); + + buf[read_index++] = ioread32(p + PCH_I2CDR); + count = read_index; + } else { + count = -ETIME; + } + + } + } else { + count = -ETIME; + pch_stop(adap); + } + + return count; +} +/** +* pch_handler_ch0() - interrupt handler for the PCH I2C controller +* @irq: irq number. +* @pData: cookie passed back to the handler function.
drivers/i2c/busses/i2c-pch.c line 630
Quoted 10 lines
drivers/i2c/busses/i2c-pch.c new file +10
-0+*/ +static irqreturn_t pch_handler_ch0 (int irq,void *pData) +{ + s32 reg_val; + + struct i2c_algo_pch_data *adap_data = (struct i2c_algo_pch_data *)pData; + void __iomem *p = adap_data->pch_base_address; + u32 mode = ioread32(p + PCH_I2CMOD) & (BUFFER_MODE | EEPROM_SR_MODE); + + if (mode == NORMAL_MODE) {
No.
if (mode != NORMAL_MODE) {
dev_err(...)
return IRQ_NONE;
}
Then de-indent the rest and remove the else clause.
Quoted 31 lines
+
reg_val=ioread32(p + PCH_I2CSR);
+ if (reg_val& (I2CMAL_BIT|I2CMCF_BIT|I2CMIF_BIT))
+pch_cb_ch0(adap_data);
+ else
+ gotoerr_out;
+ } else {
+ dev_err(adap_data->pch_adapter.dev.parent,
+ "%s I2C mode is not supported\n",__func__);
+ gotoerr_out;
+ }
+ returnIRQ_HANDLED;drivers/i2c/busses/i2c-pch.c new file +18
-0+ +err_out: + return IRQ_NONE; +} +/** +* pch_xfer() - Reading adnd writing data through I2C bus +* @i2c_adap: Pointer to the struct i2c_adapter. +* @msgs: Pointer to i2c_msg structure. +* @num: number of messages. +*/ +static s32 pch_xfer (struct i2c_adapter *i2c_adap, + struct i2c_msg *msgs, s32 num) +{ + struct i2c_msg *pmsg; + u32 i; + u32 status; + u32 msglen; + u32 subaddrlen;
drivers/i2c/busses/i2c-pch.c line 670
Quoted 10 lines
drivers/i2c/busses/i2c-pch.c new file +10
-0+ s32 ret; + + struct i2c_algo_pch_data *adap = i2c_adap->algo_data; + + ret = mutex_lock_interruptible(&pch_mutex); + if (ret) { + ret = -ERESTARTSYS; + goto return_err_nomutex; + } + if (adap->p_adapter_info->pch_suspended == false) {
No.
if (adap->p_adapter_info->pch_suspended) {
mutex_unlock(&pch_nomutex);
return -EBUSY;
}
De-indent the rest and remove the else clause.
Quoted 60 lines
+ dev_dbg(adap->pch_adapter.dev.parent,
+ "%sadap->p_adapter_info->pch_suspendedis %d\n",
+__func__,adap->p_adapter_info->pch_suspended);
+ /* transfer not completed */
+adap->pch_xfer_in_progress= true;drivers/i2c/busses/i2c-pch.c new file +53
-0+ + ret = -EBUSY; + for (i = 0; i < num; i++) { + pmsg = &msgs[i]; + pmsg->flags |= adap->pch_buff_mode_en; + status = pmsg->flags; + dev_dbg(adap->pch_adapter.dev.parent, + "After invoking I2C_MODE_SEL :flag= 0x%x\n", + status); + /* calculate sub address length and message length */ + /* these are applicable only for buffer mode */ + subaddrlen = pmsg->buf[0]; + /* calculate actual message length excluding + * the sub address fields */ + msglen = (pmsg->len) - (subaddrlen + 1); + if (status & (I2C_M_RD)) { + dev_dbg(adap->pch_adapter.dev.parent, + "%s invoking pch_readbytes\n", + __func__); + ret = pch_readbytes(i2c_adap, pmsg, + (i + 1 == num), + (i == 0)); + } else { + dev_dbg(adap->pch_adapter.dev.parent, + "%s invoking pch_writebytes\n", + __func__); + ret = pch_writebytes(i2c_adap, pmsg, + (i + 1 == num), + (i == 0)); + } + + } + + adap->pch_xfer_in_progress = false; /* transfer completed */ + + dev_dbg(adap->pch_adapter.dev.parent, + "adap->pch_xfer_in_progress is %d\n", + adap->pch_xfer_in_progress); + } else { + ret = -EBUSY; + } + + mutex_unlock(&pch_mutex); +return_err_nomutex: + dev_dbg(adap->pch_adapter.dev.parent, "%s return:%d\n\n\n\n", + __func__, ret); + return ret; +} +static int __devinit pch_probe (struct pci_dev *pdev, + const struct pci_device_id *id) +{ + int i; + void __iomem *base_addr;
drivers/i2c/busses/i2c-pch.c line 771
Quoted 10 lines
drivers/i2c/busses/i2c-pch.c new file +10
-0+ s32 ret; + struct adapter_info *adap_info = + kzalloc((sizeof(struct adapter_info)), GFP_KERNEL); + + dev_dbg(&pdev->dev, "Enterred in %s\n", __func__); + + if (adap_info == NULL) { + dev_err(&pdev->dev, "Memory allocation failed FAILED"); + ret = -ENOMEM; + goto return_err;
Just
return -ENOMEM;
Goto construction unnecessary here.
Quoted 9 lines
(...)
drivers/i2c/busses/i2c-pch.c new file +8
-0+#ifdef CONFIG_PM +static int pch_suspend (struct pci_dev *pdev,pm_message_t state) +{ + int i; + int ret; + + struct adapter_info *adap_info = pci_get_drvdata(pdev); + void __iomem *p = adap_info->pch_data[0].pch_base_address;
drivers/i2c/busses/i2c-pch.c line 889
Quoted 10 lines
drivers/i2c/busses/i2c-pch.c new file +10
-0+ + adap_info->pch_suspended = true; + + for (i = 0; i < PCH_MAX_CHN; i++) { + while ((adap_info->pch_data[i].pch_xfer_in_progress)) { + /* It is assumed that any pending transfer will + * be completed after the delay + */ + msleep(1); + }
The comment seems to be a lie. It is not assumed that it will be completed at all, because you're sleeping repeatedly until all transfers are completed.
What you are doing is you are waiting for channel zero to complete transfers, then channel 1 etc up to channel PCH_MAX_CHN.
Quoted 14 lines
+ /* Disable the i2c interrupts */
+pch_disbl_int(&adap_info->pch_data[i]);
+ }drivers/i2c/busses/i2c-pch.c new file +11
-0+ + dev_dbg(&pdev->dev, + "I2CSR = %x I2CBUFSTA = %x I2CESRSTA = %x " + "invoked function pch_disbl_int successfully\n", + ioread32(p + 0x08), + ioread32(p + 0x30), + ioread32(p + 0x44)); + + ret = pci_save_state(pdev); + + if (ret) {
drivers/i2c/busses/i2c-pch.c line 913
Quoted 10 lines
drivers/i2c/busses/i2c-pch.c new file +10
-0+ dev_err(&pdev->dev, "pci_save_state failed\n"); + return ret; + } + + pci_enable_wake(pdev, PCI_D3hot, 0); + pci_disable_device(pdev); + pci_set_power_state(pdev, pci_choose_state(pdev, state)); + + return 0; +}
Yours,
Linus Walleij
Quoted 4 lines
----- Original Message -----
From: "Linus Walleij" <[email protected]>
To: "Masayuki Ohtak" <masa-korg-ECg8zkTtlr0C6LszWs/[email protected]>
Cc: "Jean Delvare (PC drivers, core)" <[email protected]>; "Ben Dooks (embedded platforms)" <[email protected]>;
"Crane Cai" <[email protected]>; "Samuel Ortiz" <sameo-VuQAYsv1563Yd54FQh9/[email protected]>; "Ralf Baechle" <ralf-6z/[email protected]>; "srinidhi kasagar" <srinidhi.kasagar-0IS4wlFg1OjSUeElwK9/[email protected]>; <[email protected]>; <[email protected]>; "Wang Yong Y"" <[email protected]>; "Wang Qi"" <[email protected]>; "Andrew"" <[email protected]>; <arjan-VuQAYsv1563Yd54FQh9/[email protected]>; "Tomoya MORINAGA" <morinaga526-ECg8zkTtlr0C6LszWs/[email protected]>; "Arnd Bergmann" <[email protected]>
Quoted 231 lines
Sent: Thursday, September 02, 2010 4:44 AM
Subject: Re: [MeeGo-Dev][PATCH] Topcliff: UpdatePCH_I2Cdriver to 2.6.352010/9/1 Masayuki Ohtak <masa-korg-ECg8zkTtlr0C6LszWs/[email protected]>:
Quoted 18 lines
I2C driver of Topcliff PCH
(...)
+++b/drivers/i2c/busses/i2c-pch.c
(...)drivers/i2c/busses/i2c-pch.c new file +14
-0+/** +* pch_wait_for_bus_idle() - check the status of bus. +* @adap: Pointer to struct i2c_algo_pch_data. +* @timeout: waiting time counter (us). +*/ +static s32 pch_wait_for_bus_idle (struct i2c_algo_pch_data *adap, +s32 timeout) +{ +void __iomem *p = adap->pch_base_address; + +/* MAX timeout value is timeout*1000*1000nsec */ +ktime_t ns_val =ktime_add_ns (ktime_get (), timeout*1000 *1000 ); + do { + if ((ioread32(p + PCH_I2CSR) & I2CMBB_BIT) == 0)drivers/i2c/busses/i2c-pch.c line 276
Quoted 10 lines
drivers/i2c/busses/i2c-pch.c new file +10
-0+break ; +msleep (1 ); + }while (ktime_lt (ktime_get (), ns_val)); + +dev_dbg (adap->pch_adapter.dev.parent, +"%s : I2CSR = %x\n" , __func__,ioread32 (p +PCH_I2CSR )); + +if (timeout ==0 ) { +dev_err (adap->pch_adapter.dev.parent, +"%s :return%d\n" , __func__, -ETIME );Why not just return
-ETIME; here?Quoted 4 lines
+ } else {
+ dev_dbg(adap->pch_adapter.dev.parent,
+ "%s : return %d\n",__func__, 0);
+ }Delete this else clause, who is interested in return 0???
Quoted 1 line
+ return ((timeout <= 0) ? (
-ETIME) : (0));return 0;
drivers/i2c/busses/i2c-pch.c line 309
Quoted 12 lines
(...)
drivers/i2c/busses/i2c-pch.c new file +11
-0+/** +* pch_wait_for_xfer_complete() - initiates a wait for the tx complete event +* @adap: Pointer to struct i2c_algo_pch_data. +*/ +static s32 pch_wait_for_xfer_complete (struct i2c_algo_pch_data *adap) +{ +s32 ret; + ret =wait_event_interruptible_timeout (pch_event, + (adap->pch_event_flag !=0 ),msecs_to_jiffies (50 )); +if (ret <0 ) + goto out;The goto construction is unnecessary, just
return ret;
Quoted 4 lines
+
+ if (ret == 0) {
+ ret =-ETIMEDOUT;
+ goto out;return
-ETIMEDOUT;Quoted 7 lines
+ }
+
+ if (adap->pch_event_flag&I2C_ERROR_MASK) {
+ ret =-EIO;
+ dev_err(adap->pch_adapter.dev.parent,
+ "error bits set: %x\n",adap->pch_event_flag);
+ goto out;Skip ret assignment
return-EIO;Quoted 4 lines
+ }
+
+adap->pch_event_flag= 0;
+ ret = 0;Skip this
Quoted 2 lines
+out:
+ return ret;return 0;
Quoted 10 lines
drivers/i2c/busses/i2c-pch.c new file +9
-0+} +/** +* pch_getack() - to confirm ACK/NACK +* @adap: Pointer to struct i2c_algo_pch_data. +*/ +static s32 pch_getack (struct i2c_algo_pch_data *adap) +{ +u32 reg_val; +void __iomem *p = adap->pch_base_address;drivers/i2c/busses/i2c-pch.c line 346
Quoted 10 lines
drivers/i2c/busses/i2c-pch.c new file +10
-0+ reg_val =ioread32 (p +PCH_I2CSR ) &PCH_GETACK ; + +if (reg_val ==0 ) +dev_dbg (adap->pch_adapter.dev.parent,"%s : return 0\n" , + __func__); +else +dev_dbg (adap->pch_adapter.dev.parent,"%s : return%d\n" , + __func__, -EPROTO ); + +return (((reg_val) ==0 ) ? (0 ) : (-EPROTO ));Refactor this like the other function, no weirdo debug prints return 0;
Quoted 11 lines
drivers/i2c/busses/i2c-pch.c new file +10
-0+} +/** +* pch_writebytes() - write data to I2C bus in normal mode +* @i2c_adap: Pointer to the struct i2c_adapter. +* @last: specifies whether last message or not. +* In the case of compound mode it will be 1 for last message, +* otherwise 0. +* @first: specifies whether first message or not. +* 1 for first message otherwise 0. +*/ drivers/i2c/busses/i2c-pch.c line 392
Quoted 10 lines
drivers/i2c/busses/i2c-pch.c new file +10
-0+static s32 pch_writebytes (struct i2c_adapter *i2c_adap,struct i2c_msg *msgs, +u32 last,u32 first) +{ +struct i2c_algo_pch_data *adap = i2c_adap->algo_data; +u8 *buf; +u32 length; +u32 addr; +u32 addr_2_msb; +u32 addr_8_lsb; +s32 wrcount;You don't assign anything to wrcount...
Quoted 29 lines
+ void
__iomem*p =adap->pch_base_address;
+ length =msgs->len;
+ buf =msgs->buf;
+ addr =msgs->addr;
+ /* enable master tx */
+pch_setbit((adap->pch_base_address), PCH_I2CCTL, I2C_TX_MODE);drivers/i2c/busses/i2c-pch.c new file +23
-0+ +dev_dbg (adap->pch_adapter.dev.parent, +"%s : I2CCTL = %x msgs->len = %d\n" , __func__, +ioread32 (p +PCH_I2CCTL ), length); + +if (first) { +if (pch_wait_for_bus_idle (adap,BUS_IDLE_TIMEOUT ) == -ETIME ) +return -ETIME ; + } + +if (msgs->flags &I2C_M_TEN ) { + addr_2_msb = ((addr &I2C_MSB_2B_MSK ) >>7 ); +iowrite32 (addr_2_msb |TEN_BIT_ADDR_MASK , p +PCH_I2CDR ); +if (first) +pch_start (adap); +if ((pch_wait_for_xfer_complete (adap) ==0 ) && + (pch_getack (adap) ==0 )) { + addr_8_lsb = (addr &I2C_ADDR_MSK ); +iowrite32 (addr_8_lsb, p +PCH_I2CDR ); + }else { +pch_stop (adap); +return -ETIME ; + }drivers/i2c/busses/i2c-pch.c line 431
Quoted 10 lines
drivers/i2c/busses/i2c-pch.c new file +10
-0+ }else { +/* set 7 bit slave address and R/W bit as 0 */ +iowrite32 (addr <<1 , p +PCH_I2CDR ); +if (first) +pch_start (adap); + } + +if ((pch_wait_for_xfer_complete (adap) ==0 ) && + (pch_getack (adap) ==0 )) { +for (wrcount =0 ; wrcount < length; ++wrcount) {...but it is only conditionally used here...
Quoted 23 lines
+ /* write buffer value to I2C data register */
+iowrite32(buf[wrcount], p + PCH_I2CDR);
+ dev_dbg(adap->pch_adapter.dev.parent,
+ "%s : writing %x to Data register\n",
+__func__, buf[wrcount]);drivers/i2c/busses/i2c-pch.c new file +18
-0+ +if (pch_wait_for_xfer_complete (adap) !=0 ) { + wrcount = -ETIME ; +break ; + } + +dev_dbg (adap->pch_adapter.dev.parent, +"%s return %d" , __func__,0 ); + +if (pch_getack (adap)) { + wrcount = -ETIME ; +break ; + } + } + +/* check if this is the last message */ +if (last) +pch_stop (adap);drivers/i2c/busses/i2c-pch.c line 464
Quoted 10 lines
drivers/i2c/busses/i2c-pch.c new file +10
-0+else +pch_repstart (adap); + }else { +pch_stop (adap); + } + +dev_dbg (adap->pch_adapter.dev.parent, +"%s return=%d\n" , __func__, wrcount); + +return wrcount;...and then you return it, leading to a possibly unassigned state.
Quoted 10 lines
drivers/i2c/busses/i2c-pch.c new file +9
-0+} +/** +* pch_readbytes() - read data from I2C bus in normal mode. +* @i2c_adap: Pointer to the struct i2c_adapter. +* @msgs: Pointer to i2c_msg structure. +* @last: specifies whether last message or not. +* @first: specifies whether first message or not. +*/ +s32 pch_readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs,
Quoted 8 lines
drivers/i2c/busses/i2c-pch.c line 504
Quoted 6 lines
+ u32 last, u32 first)
drivers/i2c/busses/i2c-pch.c new file +5
-0+{ +struct i2c_algo_pch_data *adap = i2c_adap->algo_data; + +u8 *buf; +u32 count;Same problem here. Initialize to 0.
When I submit other patch to upstream,
a maintainer said "variable shouldn't initialize to 0". Thus, we don't do.
Can you admit above?
Quoted 286 lines
Quoted 92 lines
+ u32 length;
+ u32 addr;
+ u32addr_2_msb;
+ void__iomem*p =adap->pch_base_address;
+ length =msgs->len;
+ buf =msgs->buf;
+ addr =msgs->addr;drivers/i2c/busses/i2c-pch.c new file +82
-0+ +/* enable master reception */ +pch_clrbit ((adap->pch_base_address),PCH_I2CCTL ,I2C_TX_MODE ); + +if (first) { +if (pch_wait_for_bus_idle (adap,BUS_IDLE_TIMEOUT ) == -ETIME ) +return -ETIME ; + } + +if (msgs->flags &I2C_M_TEN ) { + addr_2_msb = (((addr &I2C_MSB_2B_MSK ) >>7 ) | (I2C_RD )); +iowrite32 (addr_2_msb |TEN_BIT_ADDR_MASK , p +PCH_I2CDR ); + + }else { +/* 7 address bits + R/W bit */ + addr = (((addr) <<1 ) | (I2C_RD )); +iowrite32 (addr, p +PCH_I2CDR ); + } + +/* check if it is the first message */ +if (first) +pch_start (adap); + +if ((pch_wait_for_xfer_complete (adap) ==0 ) + && (pch_getack (adap) ==0 )) { +dev_dbg (adap->pch_adapter.dev.parent, +"%s return %d" , __func__,0 ); + +if (length ==0 ) { +pch_stop (adap); +ioread32 (p +PCH_I2CDR );/* Dummy read needs */ + + count = length; + }else { +int read_index; +int loop; +pch_sendack (adap); + +/* Dummy read */ +for (loop =1 , read_index =0 ; loop < length; loop++) { + buf[read_index] =ioread32 (p +PCH_I2CDR ); + +if (loop !=1 ) + read_index++; + +if (pch_wait_for_xfer_complete (adap) !=0 ) { +pch_stop (adap); +return -ETIME ; + } + }/* end for */ + +pch_sendnack (adap); + + buf[read_index] =ioread32 (p +PCH_I2CDR ); + +if (length !=1 ) + read_index++; + +if (pch_wait_for_xfer_complete (adap) ==0 ) { +if (last) +pch_stop (adap); +else +pch_repstart (adap); + + buf[read_index++] =ioread32 (p +PCH_I2CDR ); + count = read_index; + }else { + count = -ETIME ; + } + + } + }else { + count = -ETIME ; +pch_stop (adap); + } + +return count; +} +/** +* pch_handler_ch0() - interrupt handler for the PCH I2C controller +* @irq: irq number. +* @pData: cookie passed back to the handler function. drivers/i2c/busses/i2c-pch.c line 630
Quoted 10 lines
drivers/i2c/busses/i2c-pch.c new file +10
-0+*/ +static irqreturn_t pch_handler_ch0 (int irq,void *pData) +{ +s32 reg_val; + +struct i2c_algo_pch_data *adap_data = (struct i2c_algo_pch_data *)pData; +void __iomem *p = adap_data->pch_base_address; +u32 mode =ioread32 (p +PCH_I2CMOD ) & (BUFFER_MODE |EEPROM_SR_MODE ); + +if (mode ==NORMAL_MODE ) {No.
if (mode !=
NORMAL_MODE) {
dev_err(...)
returnIRQ_NONE;
}Then de-indent the rest and remove the else clause.
Quoted 31 lines
+
reg_val=ioread32(p + PCH_I2CSR);
+ if (reg_val& (I2CMAL_BIT|I2CMCF_BIT|I2CMIF_BIT))
+pch_cb_ch0(adap_data);
+ else
+ gotoerr_out;
+ } else {
+ dev_err(adap_data->pch_adapter.dev.parent,
+ "%s I2C mode is not supported\n",__func__);
+ gotoerr_out;
+ }
+ returnIRQ_HANDLED;drivers/i2c/busses/i2c-pch.c new file +18
-0+ +err_out: +return IRQ_NONE ; +} +/** +* pch_xfer() - Reading adnd writing data through I2C bus +* @i2c_adap: Pointer to the struct i2c_adapter. +* @msgs: Pointer to i2c_msg structure. +* @num: number of messages. +*/ +static s32 pch_xfer (struct i2c_adapter *i2c_adap, +struct i2c_msg *msgs,s32 num) +{ +struct i2c_msg *pmsg; +u32 i; +u32 status; +u32 msglen; +u32 subaddrlen;drivers/i2c/busses/i2c-pch.c line 670
Quoted 10 lines
drivers/i2c/busses/i2c-pch.c new file +10
-0+s32 ret; + +struct i2c_algo_pch_data *adap = i2c_adap->algo_data; + + ret =mutex_lock_interruptible (&pch_mutex); +if (ret) { + ret = -ERESTARTSYS ; + goto return_err_nomutex; + } +if (adap->p_adapter_info->pch_suspended == false) {No.
if (adap->p_adapter_info->pch_suspended) { mutex_unlock(&pch_nomutex); return -EBUSY; }De-indent the rest and remove the else clause.
Quoted 60 lines
+ dev_dbg(adap->pch_adapter.dev.parent,
+ "%sadap->p_adapter_info->pch_suspendedis %d\n",
+__func__,adap->p_adapter_info->pch_suspended);
+ /* transfer not completed */
+adap->pch_xfer_in_progress= true;drivers/i2c/busses/i2c-pch.c new file +53
-0+ + ret = -EBUSY ; +for (i =0 ; i < num; i++) { + pmsg = &msgs[i]; + pmsg->flags |= adap->pch_buff_mode_en; + status = pmsg->flags; +dev_dbg (adap->pch_adapter.dev.parent, +"After invoking I2C_MODE_SEL :flag= 0x%x\n" , + status); +/* calculate sub address length and message length */ +/* these are applicable only for buffer mode */ + subaddrlen = pmsg->buf[0 ]; +/* calculate actual message length excluding +* the sub address fields */ + msglen = (pmsg->len) - (subaddrlen +1 ); +if (status & (I2C_M_RD )) { +dev_dbg (adap->pch_adapter.dev.parent, +"%s invoking pch_readbytes\n" , + __func__); + ret =pch_readbytes (i2c_adap, pmsg, + (i +1 == num), + (i ==0 )); + }else { +dev_dbg (adap->pch_adapter.dev.parent, +"%s invoking pch_writebytes\n" , + __func__); + ret =pch_writebytes (i2c_adap, pmsg, + (i +1 == num), + (i ==0 )); + } + + } + + adap->pch_xfer_in_progress = false;/* transfer completed */ + +dev_dbg (adap->pch_adapter.dev.parent, +"adap->pch_xfer_in_progress is %d\n" , + adap->pch_xfer_in_progress); + }else { + ret = -EBUSY ; + } + +mutex_unlock (&pch_mutex); +return_err_nomutex: +dev_dbg (adap->pch_adapter.dev.parent,"%s return:%d\n\n\n\n" , + __func__, ret); +return ret; +} +static int __devinit pch_probe (struct pci_dev *pdev, +const struct pci_device_id *id) +{ +int i; +void __iomem *base_addr;drivers/i2c/busses/i2c-pch.c line 771
Quoted 10 lines
drivers/i2c/busses/i2c-pch.c new file +10
-0+s32 ret; +struct adapter_info *adap_info = +kzalloc ((sizeof (struct adapter_info )),GFP_KERNEL ); + +dev_dbg (&pdev->dev,"Enterred in %s\n" , __func__); + +if (adap_info ==NULL ) { +dev_err (&pdev->dev,"Memory allocation failed FAILED" ); + ret = -ENOMEM ; + goto return_err;Just
return-ENOMEM;Goto construction unnecessary here.
Quoted 9 lines
(...)
drivers/i2c/busses/i2c-pch.c new file +8
-0+#ifdef CONFIG_PM +static int pch_suspend (struct pci_dev *pdev,pm_message_t state) +{ +int i; +int ret; + +struct adapter_info *adap_info =pci_get_drvdata (pdev); +void __iomem *p = adap_info->pch_data[0 ].pch_base_address;drivers/i2c/busses/i2c-pch.c line 889
Quoted 10 lines
drivers/i2c/busses/i2c-pch.c new file +10
-0+ + adap_info->pch_suspended = true; + +for (i =0 ; i <PCH_MAX_CHN ; i++) { +while ((adap_info->pch_data[i].pch_xfer_in_progress)) { +/* It is assumed that any pending transfer will +* be completed after the delay +*/ +msleep (1 ); + }The comment seems to be a lie. It is not assumed that it will be completed at all, because you're sleeping repeatedly until all transfers are completed.
What you are doing is you are waiting for channel zero to complete transfers, then channel 1 etc up to channel
PCH_MAX_CHN.Quoted 20 lines
+ /* Disable the i2c interrupts */
+pch_disbl_int(&adap_info->pch_data[i]);
+ }drivers/i2c/busses/i2c-pch.c new file +17
-0+ +dev_dbg (&pdev->dev, +"I2CSR = %x I2CBUFSTA = %x I2CESRSTA = %x " +"invoked function pch_disbl_int successfully\n" , +ioread32 (p +0x08 ), +ioread32 (p +0x30 ), +ioread32 (p +0x44 )); + + ret =pci_save_state (pdev); + +if (ret) { +dev_err (&pdev->dev,"pci_save_state failed\n" ); +return ret; + } + +pci_enable_wake (pdev, PCI_D3hot,0 ); +pci_disable_device (pdev);
Quoted 8 lines
drivers/i2c/busses/i2c-pch.c line 844
Quoted 4 lines
+
pci_set_power_state(pdev, pci_choose_state(pdev, state));drivers/i2c/busses/i2c-pch.c new file +3
-0+ +return 0 ; +}Yours,
Linus Walleij
Thanks, Ohtake(OKISemi)