Subject: kern/32212: Add flag to src/sys/dev/i2c/i2c_exec.c
To: None <kern-bug-people@netbsd.org, gnats-admin@netbsd.org,>
From: None <johnny@zweig.org>
List: netbsd-bugs
Date: 12/02/2005 02:37:00
>Number:         32212
>Category:       kern
>Synopsis:       Add flag to src/sys/dev/i2c/i2c_exec.c
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    kern-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Fri Dec 02 02:37:00 +0000 2005
>Originator:     Johnny Zweig
>Release:        2.0
>Organization:
Serious Cybernetics
>Environment:
N/A
>Description:
I would like to propose that iic_exec (in i2c_exec) pass a flag to the lower-layer I2C driver's initiate_xfer routine when it sends a RESTART (rather than an ordinary START).

The issue is that some I2C hardware returns a different status code after sending a repeated start than it does for a normal start, so my driver has to recover from the "I got an unexpected result code error" when waiting for the hardware to finish the "start" that initiate_xfer told it to send.

That is, iic_exec has state information to know when it is sending a repeated start, and my driver does not. This change would allow my driver to expect the right thing, rather than kludge around what (to my mind) is a shortcoming of the API.
>How-To-Repeat:

>Fix:
This amounts to adding a new definition for I2C_F_RESTART, and changing:

  if (I2C_OP_READ_P(op)) {
	/* Send REPEATED START. */
	if ((len + 1) == buflen &&
	    (error = iic_initiate_xfer(tag, addr, flags)) != 0)
		goto bad;
to:

  if (I2C_OP_READ_P(op)) {
	/* Send REPEATED START. */
	if ((len + 1) == buflen &&
	    (error = iic_initiate_xfer(tag, addr,
	     flags | I2C_F_RESTART)) != 0)
		goto bad;