-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'i2c/for-next' of git://git.kernel.org/pub/scm/linux/ker…
…nel/git/wsa/linux Pull i2c updates from Wolfram Sang: "Most notable: - introducing the i2c_quirk infrastructure. Now, flaws of I2C controllers can be described and the core will check if the flaws collide with the messages to be sent - wait_for_completion return type cleanup series - new drivers for Digicolor, Netlogic XLP, Ingenic JZ4780 - updates to the I2C slave framework which include API changes. Its only user was updated, too. Documentation was finally added - changed dynamic bus numbering for the DT case. This could change bus numbers for users. However, it fixes a collision where dynamic and static busses request the same id. - driver bugfixes, cleanups" * 'i2c/for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux: (52 commits) i2c: xlp9xx: Driver for Netlogic XLP9XX/5XX I2C controller of: Add vendor prefix 'netlogic' i2c: davinci: use ICPFUNC to toggle I2C as gpio for bus recovery i2c: davinci: use bus recovery infrastructure i2c: change input parameter to i2c_adapter for prepare/unprepare_recovery i2c: i2c-mux-gpio: remove error messages for probe deferrals i2c: jz4780: Add i2c bus controller driver for Ingenic JZ4780 i2c: dln2: set the device tree node of the adapter i2c: davinci: fixup wait_for_completion_timeout handling i2c: mpc: Fix ISR return value i2c: slave-eeprom: add more info when to increase the pointer i2c: slave: add documentation for i2c-slave-eeprom Documentation: i2c: describe the new slave mode i2c: slave: rework the slave API i2c: add support for the Digicolor I2C controller i2c: busses with dynamic ids should start after fixed ids for DT of: base: add function to get highest id of an alias stem i2c: designware: Suppress error message if platform_get_irq() < 0 i2c: mpc: assign the correct prescaler from SVR i2c: img-scb: fixup of wait_for_completion_timeout return handling ...
- Loading branch information
Showing
46 changed files
with
2,483 additions
and
276 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
Conexant Digicolor I2C controller | ||
|
||
Required properties: | ||
- compatible: must be "cnxt,cx92755-i2c" | ||
- reg: physical address and length of the device registers | ||
- interrupts: a single interrupt specifier | ||
- clocks: clock for the device | ||
- #address-cells: should be <1> | ||
- #size-cells: should be <0> | ||
|
||
Optional properties: | ||
- clock-frequency: the desired I2C bus clock frequency in Hz; in | ||
absence of this property the default value is used (100 kHz). | ||
|
||
Example: | ||
|
||
i2c: i2c@f0000120 { | ||
compatible = "cnxt,cx92755-i2c"; | ||
reg = <0xf0000120 0x10>; | ||
interrupts = <28>; | ||
clocks = <&main_clk>; | ||
clock-frequency = <100000>; | ||
#address-cells = <1>; | ||
#size-cells = <0>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
* Ingenic JZ4780 I2C Bus controller | ||
|
||
Required properties: | ||
- compatible: should be "ingenic,jz4780-i2c" | ||
- reg: Should contain the address & size of the I2C controller registers. | ||
- interrupts: Should specify the interrupt provided by parent. | ||
- clocks: Should contain a single clock specifier for the JZ4780 I2C clock. | ||
- clock-frequency: desired I2C bus clock frequency in Hz. | ||
|
||
Recommended properties: | ||
- pinctrl-names: should be "default"; | ||
- pinctrl-0: phandle to pinctrl function | ||
|
||
Optional properties: | ||
- interrupt-parent: Should be the phandle of the interrupt controller that | ||
delivers interrupts to the I2C block. | ||
|
||
Example | ||
|
||
/ { | ||
i2c4: i2c4@0x10054000 { | ||
compatible = "ingenic,jz4780-i2c"; | ||
reg = <0x10054000 0x1000>; | ||
|
||
interrupt-parent = <&intc>; | ||
interrupts = <56>; | ||
|
||
clocks = <&cgu JZ4780_CLK_SMB4>; | ||
clock-frequency = <100000>; | ||
pinctrl-names = "default"; | ||
pinctrl-0 = <&pins_i2c4_data>; | ||
|
||
}; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Device tree configuration for the I2C controller on the XLP9xx/5xx SoC | ||
|
||
Required properties: | ||
- compatible : should be "netlogic,xlp980-i2c" | ||
- reg : bus address start and address range size of device | ||
- interrupts : interrupt number | ||
|
||
Optional properties: | ||
- clock-frequency : frequency of bus clock in Hz | ||
Defaults to 100 KHz when the property is not specified | ||
|
||
Example: | ||
|
||
i2c0: i2c@113100 { | ||
compatible = "netlogic,xlp980-i2c"; | ||
#address-cells = <1>; | ||
#size-cells = <0>; | ||
reg = <0 0x113100 0x100>; | ||
clock-frequency = <400000>; | ||
interrupts = <30>; | ||
interrupt-parent = <&pic>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Linux I2C slave eeprom backend | ||
============================== | ||
|
||
by Wolfram Sang <wsa@sang-engineering.com> in 2014-15 | ||
|
||
This is a proof-of-concept backend which acts like an EEPROM on the connected | ||
I2C bus. The memory contents can be modified from userspace via this file | ||
located in sysfs: | ||
|
||
/sys/bus/i2c/devices/<device-direcory>/slave-eeprom | ||
|
||
As of 2015, Linux doesn't support poll on binary sysfs files, so there is no | ||
notfication when another master changed the content. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
Linux I2C slave interface description | ||
===================================== | ||
|
||
by Wolfram Sang <wsa@sang-engineering.com> in 2014-15 | ||
|
||
Linux can also be an I2C slave in case I2C controllers have slave support. | ||
Besides this HW requirement, one also needs a software backend providing the | ||
actual functionality. An example for this is the slave-eeprom driver, which | ||
acts as a dual memory driver. While another I2C master on the bus can access it | ||
like a regular EEPROM, the Linux I2C slave can access the content via sysfs and | ||
retrieve/provide information as needed. The software backend driver and the I2C | ||
bus driver communicate via events. Here is a small graph visualizing the data | ||
flow and the means by which data is transported. The dotted line marks only one | ||
example. The backend could also use e.g. a character device, be in-kernel | ||
only, or something completely different: | ||
|
||
|
||
e.g. sysfs I2C slave events I/O registers | ||
+-----------+ v +---------+ v +--------+ v +------------+ | ||
| Userspace +........+ Backend +-----------+ Driver +-----+ Controller | | ||
+-----------+ +---------+ +--------+ +------------+ | ||
| | | ||
----------------------------------------------------------------+-- I2C | ||
--------------------------------------------------------------+---- Bus | ||
|
||
Note: Technically, there is also the I2C core between the backend and the | ||
driver. However, at this time of writing, the layer is transparent. | ||
|
||
|
||
User manual | ||
=========== | ||
|
||
I2C slave backends behave like standard I2C clients. So, you can instantiate | ||
them like described in the document 'instantiating-devices'. A quick example | ||
for instantiating the slave-eeprom driver from userspace: | ||
|
||
# echo 0-0064 > /sys/bus/i2c/drivers/i2c-slave-eeprom/bind | ||
|
||
Each backend should come with separate documentation to describe its specific | ||
behaviour and setup. | ||
|
||
|
||
Developer manual | ||
================ | ||
|
||
I2C slave events | ||
---------------- | ||
|
||
The bus driver sends an event to the backend using the following function: | ||
|
||
ret = i2c_slave_event(client, event, &val) | ||
|
||
'client' describes the i2c slave device. 'event' is one of the special event | ||
types described hereafter. 'val' holds an u8 value for the data byte to be | ||
read/written and is thus bidirectional. The pointer to val must always be | ||
provided even if val is not used for an event, i.e. don't use NULL here. 'ret' | ||
is the return value from the backend. Mandatory events must be provided by the | ||
bus drivers and must be checked for by backend drivers. | ||
|
||
Event types: | ||
|
||
* I2C_SLAVE_WRITE_REQUESTED (mandatory) | ||
|
||
'val': unused | ||
'ret': always 0 | ||
|
||
Another I2C master wants to write data to us. This event should be sent once | ||
our own address and the write bit was detected. The data did not arrive yet, so | ||
there is nothing to process or return. Wakeup or initialization probably needs | ||
to be done, though. | ||
|
||
* I2C_SLAVE_READ_REQUESTED (mandatory) | ||
|
||
'val': backend returns first byte to be sent | ||
'ret': always 0 | ||
|
||
Another I2C master wants to read data from us. This event should be sent once | ||
our own address and the read bit was detected. After returning, the bus driver | ||
should transmit the first byte. | ||
|
||
* I2C_SLAVE_WRITE_RECEIVED (mandatory) | ||
|
||
'val': bus driver delivers received byte | ||
'ret': 0 if the byte should be acked, some errno if the byte should be nacked | ||
|
||
Another I2C master has sent a byte to us which needs to be set in 'val'. If 'ret' | ||
is zero, the bus driver should ack this byte. If 'ret' is an errno, then the byte | ||
should be nacked. | ||
|
||
* I2C_SLAVE_READ_PROCESSED (mandatory) | ||
|
||
'val': backend returns next byte to be sent | ||
'ret': always 0 | ||
|
||
The bus driver requests the next byte to be sent to another I2C master in | ||
'val'. Important: This does not mean that the previous byte has been acked, it | ||
only means that the previous byte is shifted out to the bus! To ensure seamless | ||
transmission, most hardware requests the next byte when the previous one is | ||
still shifted out. If the master sends NACK and stops reading after the byte | ||
currently shifted out, this byte requested here is never used. It very likely | ||
needs to be sent again on the next I2C_SLAVE_READ_REQUEST, depending a bit on | ||
your backend, though. | ||
|
||
* I2C_SLAVE_STOP (mandatory) | ||
|
||
'val': unused | ||
'ret': always 0 | ||
|
||
A stop condition was received. This can happen anytime and the backend should | ||
reset its state machine for I2C transfers to be able to receive new requests. | ||
|
||
|
||
Software backends | ||
----------------- | ||
|
||
If you want to write a software backend: | ||
|
||
* use a standard i2c_driver and its matching mechanisms | ||
* write the slave_callback which handles the above slave events | ||
(best using a state machine) | ||
* register this callback via i2c_slave_register() | ||
|
||
Check the i2c-slave-eeprom driver as an example. | ||
|
||
|
||
Bus driver support | ||
------------------ | ||
|
||
If you want to add slave support to the bus driver: | ||
|
||
* implement calls to register/unregister the slave and add those to the | ||
struct i2c_algorithm. When registering, you probably need to set the i2c | ||
slave address and enable slave specific interrupts. If you use runtime pm, you | ||
should use pm_runtime_forbid() because your device usually needs to be powered | ||
on always to be able to detect its slave address. When unregistering, do the | ||
inverse of the above. | ||
|
||
* Catch the slave interrupts and send appropriate i2c_slave_events to the backend. | ||
|
||
Check the i2c-rcar driver as an example. | ||
|
||
|
||
About ACK/NACK | ||
-------------- | ||
|
||
It is good behaviour to always ACK the address phase, so the master knows if a | ||
device is basically present or if it mysteriously disappeared. Using NACK to | ||
state being busy is troublesome. SMBus demands to always ACK the address phase, | ||
while the I2C specification is more loose on that. Most I2C controllers also | ||
automatically ACK when detecting their slave addresses, so there is no option | ||
to NACK them. For those reasons, this API does not support NACK in the address | ||
phase. | ||
|
||
Currently, there is no slave event to report if the master did ACK or NACK a | ||
byte when it reads from us. We could make this an optional event if the need | ||
arises. However, cases should be extremely rare because the master is expected | ||
to send STOP after that and we have an event for that. Also, keep in mind not | ||
all I2C controllers have the possibility to report that event. | ||
|
||
|
||
About buffers | ||
------------- | ||
|
||
During development of this API, the question of using buffers instead of just | ||
bytes came up. Such an extension might be possible, usefulness is unclear at | ||
this time of writing. Some points to keep in mind when using buffers: | ||
|
||
* Buffers should be opt-in and slave drivers will always have to support | ||
byte-based transactions as the ultimate fallback because this is how the | ||
majority of HW works. | ||
|
||
* For backends simulating hardware registers, buffers are not helpful because | ||
on writes an action should be immediately triggered. For reads, the data in | ||
the buffer might get stale. | ||
|
||
* A master can send STOP at any time. For partially transferred buffers, this | ||
means additional code to handle this exception. Such code tends to be | ||
error-prone. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.