All of lore.kernel.org
 help / color / mirror / Atom feed
* [Question] When should a driver issue STOP condition?
@ 2018-08-31  7:36 Masahiro Yamada
  2018-08-31  9:53 ` Wolfram Sang
  0 siblings, 1 reply; 3+ messages in thread
From: Masahiro Yamada @ 2018-08-31  7:36 UTC (permalink / raw)
  To: linux-i2c, Wolfram Sang; +Cc: Linux Kernel Mailing List

Hi.


A problem was found in my drivers.


Before sending out patches, please let me
ask a question to make sure the right fix.


The problem is, my driver is forcibly setting
STOP condition unless the next message is read.

Please see this line:
https://github.com/torvalds/linux/blob/v4.19-rc1/drivers/i2c/busses/i2c-uniphier-f.c#L405


Obviously, it it disturbing the I2C_RDWR ioctl functionality.

Documentation/i2c/dev-interface says:
ioctl(file, I2C_RDWR, struct i2c_rdwr_ioctl_data *msgset)
  Do combined read/write transaction without stop in between.


So, I want to be sure
what a driver should (or should not) do.

A driver should issue STOP when and only when the I2C_M_STOP flag
is set in msg->flags.

Is this correct?


In other words, do user-space programs need to explicitly set
I2C_M_STOP where the STOP condition is desired?



Then, another question popped up.

User-space programs can send a single transaction
with read() / write().

I2C_M_STOP is not set in this case.


If a driver does not take care of the STOP condition at all,
the I2C bus is never released.
Is this the right thing to do?


-- 
Best Regards
Masahiro Yamada

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Question] When should a driver issue STOP condition?
  2018-08-31  7:36 [Question] When should a driver issue STOP condition? Masahiro Yamada
@ 2018-08-31  9:53 ` Wolfram Sang
  2018-08-31 14:39   ` Masahiro Yamada
  0 siblings, 1 reply; 3+ messages in thread
From: Wolfram Sang @ 2018-08-31  9:53 UTC (permalink / raw)
  To: Masahiro Yamada; +Cc: linux-i2c, Wolfram Sang, Linux Kernel Mailing List

[-- Attachment #1: Type: text/plain, Size: 638 bytes --]


> The problem is, my driver is forcibly setting
> STOP condition unless the next message is read.

This likely is a problem.

In Linux I2C terminology, a transfer is everything between a START and a
STOP. A transfer may consist of multiple messages, connected with
REP_START [1].

So, a STOP should be generated after the last message of a transfer or
of I2C_M_STOP is set in a message. The latter should be super-rare
because mostly you should be able to use multiple transfers with a
regular STOP instead.

[1] Slide 8 illustrates this:
http://events17.linuxfoundation.org/sites/events/files/slides/ELCE17-WSang-I2C-Fault-Injector.pdf

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Question] When should a driver issue STOP condition?
  2018-08-31  9:53 ` Wolfram Sang
@ 2018-08-31 14:39   ` Masahiro Yamada
  0 siblings, 0 replies; 3+ messages in thread
From: Masahiro Yamada @ 2018-08-31 14:39 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: linux-i2c, Wolfram Sang, Linux Kernel Mailing List

Hi Wolfram,


2018-08-31 18:53 GMT+09:00 Wolfram Sang <wsa@the-dreams.de>:
>
>> The problem is, my driver is forcibly setting
>> STOP condition unless the next message is read.
>
> This likely is a problem.


Oh, my drivers were wrong from the beginning.

I've sent patches.


> In Linux I2C terminology, a transfer is everything between a START and a
> STOP. A transfer may consist of multiple messages, connected with
> REP_START [1].
>
> So, a STOP should be generated after the last message of a transfer or
> of I2C_M_STOP is set in a message.

I see.
I hope this is documented somewhere if it has not been yet.


> The latter should be super-rare
> because mostly you should be able to use multiple transfers with a
> regular STOP instead.
>
> [1] Slide 8 illustrates this:
> http://events17.linuxfoundation.org/sites/events/files/slides/ELCE17-WSang-I2C-Fault-Injector.pdf

Awesome!

I should follow "When to not use bus recovery" check-list.

Thanks.

-- 
Best Regards
Masahiro Yamada

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-08-31 14:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-31  7:36 [Question] When should a driver issue STOP condition? Masahiro Yamada
2018-08-31  9:53 ` Wolfram Sang
2018-08-31 14:39   ` Masahiro Yamada

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.