I2C support for NXP LPC18xx family
v2 cover I2C support for NXP LPC18xx family
This patch set adds a I2C driver and documentation for the I2C peripheral found on many NXP LPC MCUs.
The driver is a rework of an old driver by Kevin Wells. It has been modified to support modern resource allocation, device tree and generally cleaned up. Driver was originally written to support the LPC2xxx platforms.
Patches based on i2c/for-next and tested on Embedded Artists' LPC4357 Dev Kit and Hitex LPC4350 Eval board with several I2C devices.
This version address comments from Wolfram Sang.
Changes since v1:
- remove dev_dbg() leftovers from development/debugging
- use i2c_add_adapter
- change return value on NACK and arb lost
(I think all the others should be okay as they are)
- fix 80 char warnings (involved s/reg_base/base)
- rebase on i2c/for-next
Joachim Eastwood (2):
i2c: add i2c-lpc2k driver
doc: dt: add documentation for nxp,lpc1788-i2c
.../devicetree/bindings/i2c/i2c-lpc2k.txt | 33 ++ drivers/i2c/busses/Kconfig | 10 + drivers/i2c/busses/Makefile | 1 + drivers/i2c/busses/i2c-lpc2k.c | 513 +++++++++++++++++++++ 4 files changed, 557 insertions(+) create mode 100644 Documentation/devicetree/bindings/i2c/i2c-lpc2k.txt create mode 100644 drivers/i2c/busses/i2c-lpc2k.c
Signature · 1 line
1.8.0
PATCH v2 1/2 i2c: add i2c-lpc2k driver
Add support for the I2C controller found on several NXP devices including LPC2xxx, LPC178x/7x and LPC18xx/43xx. The controller is implemented as a state machine and the driver act upon the state changes when the bus is accessed.
The I2C controller supports master/slave operation, bus arbitration, programmable clock rate, and speeds up to 1 Mbit/s.
--- drivers/i2c/busses/Kconfig | 10 + drivers/i2c/busses/Makefile | 1 + drivers/i2c/busses/i2c-lpc2k.c | 513 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 524 insertions(+) create mode 100644 drivers/i2c/busses/i2c-lpc2k.c
drivers/i2c/busses/Kconfig +10 -0
@@ -619,6 +619,16 @@ config I2C_KEMPLD This driver can also be built as a module. If so, the module will be called i2c-kempld. +config I2C_LPC2K + tristate "I2C bus support for NXP LPC2K/LPC178x/18xx/43xx" + depends on OF && (ARCH_LPC18XX || COMPILE_TEST) + help + This driver supports the I2C interface found several NXP + devices including LPC2xxx, LPC178x/7x and LPC18xx/43xx. + + This driver can also be built as a module. If so, the module + will be called i2c-lpc2k. + config I2C_MESON tristate "Amlogic Meson I2C controller" depends on ARCH_MESON
drivers/i2c/busses/Makefile +1 -0
@@ -59,6 +59,7 @@ obj-$(CONFIG_I2C_IMX) += i2c-imx.o obj-$(CONFIG_I2C_IOP3XX) += i2c-iop3xx.o obj-$(CONFIG_I2C_JZ4780) += i2c-jz4780.o obj-$(CONFIG_I2C_KEMPLD) += i2c-kempld.o +obj-$(CONFIG_I2C_LPC2K) += i2c-lpc2k.o obj-$(CONFIG_I2C_MESON) += i2c-meson.o obj-$(CONFIG_I2C_MPC) += i2c-mpc.o obj-$(CONFIG_I2C_MT65XX) += i2c-mt65xx.o
drivers/i2c/busses/i2c-lpc2k.c new file +513 -0
513 lines not on this page · raw message
Signature · 1 line
1.8.0
PATCH v2 1/2 i2c: add i2c-lpc2k driver
On 16 Aug 08:10 PM, Joachim Eastwood wrote:
[..]
Quoted 11 lines
drivers/i2c/busses/i2c-lpc2k.c new file +11
-0+ +static int i2c_lpc2k_clear_arb (struct lpc2k_i2c *i2c) +{ +unsigned long timeout = jiffies +msecs_to_jiffies (1000 ); + +/* +* If the transfer needs to abort for some reason, we'll try to +* force a stop condition to clear any pending bus conditions +*/ +writel (LPC24XX_STO , i2c->base +LPC24XX_I2CONSET ); +
drivers/i2c/busses/i2c-lpc2k.c line 116
Quoted 10 lines
drivers/i2c/busses/i2c-lpc2k.c new file +10
-0+/* Wait for status change */ +while (readl (i2c->base +LPC24XX_I2STAT ) !=M_I2C_IDLE ) { +if (time_after (jiffies, timeout)) { +/* Bus was not idle, try to reset adapter */ +i2c_lpc2k_reset (i2c); +return -EBUSY ; + } + +cpu_relax (); + }
I believe you can use readl_{relaxed}_poll_timeout_{atomic} here.
Ccing Ariel, maybe he can help with a test.
Signature · 2 lines
Ezequiel Garcia, VanguardiaSur www.vanguardiasur.com.ar
PATCH v2 1/2 i2c: add i2c-lpc2k driver
Quoted 17 lines · Ezequiel Garcia
On 16 Aug 08:10 PM, Joachim Eastwood wrote:
[..]Quoted 15 lines
drivers/i2c/busses/i2c-lpc2k.c new file +15
-0+ +static int 2(struct lpc2k_i2c *i2c) +{ +unsigned long timeout = jiffies +msecs_to_jiffies (1000 ); + +/*1 +* If the transfer needs to abort for some reason, we'll try to +* force a stop condition to clear any pending bus conditions +*/ +writel (LPC24XX_STO , i2c->base +LPC24XX_I2CONSET ); + +/* Wait for status change */ +while (readl (i2c->base +LPC24XX_I2STAT ) !=M_I2C_IDLE ) { +if (time_after (jiffies, timeout)) { +/* Bus was not idle, try to reset adapter */
Quoted 8 lines
drivers/i2c/busses/i2c-lpc2k.c line 116
Quoted 6 lines
drivers/i2c/busses/i2c-lpc2k.c new file +6
-0+i2c_lpc2k_reset (i2c); +return -EBUSY ; + } + +cpu_relax (); + }I believe you can use readl_{relaxed}_poll_timeout_{atomic} here.
I did consider it, but since I don't have a good to way test the code path I left it as it was.
Also since readl_{relaxed}_poll_timeout_{atomic} takes parameters in us it seemed unsuitable for a 1s total sleep, but I may be wrong.
Quoted 1 line
Ccing Ariel, maybe he can help with a test.
That would be great.
regards,
Joachim Eastwood
PATCH v2 2/2 doc: dt: add documentation for nxp,lpc1788-i2c
In reply to Joachim EastwoodAdd binding documentation for the nxp,lpc1788-i2c controller which also can be found on LPC2xxx, LPC178x/7x and LPC18xx/43xx devices.
--- .../devicetree/bindings/i2c/i2c-lpc2k.txt | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Documentation/devicetree/bindings/i2c/i2c-lpc2k.txt
Documentation/devicetree/bindings/i2c/i2c-lpc2k.txt new file +33 -0
@@ -0,0 +1,33 @@ +NXP I2C controller for LPC2xxx/178x/18xx/43xx + +Required properties: + - compatible: must be "nxp,lpc1788-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: +i2c0: i2c at 400a1000 { + compatible = "nxp,lpc1788-i2c"; + reg = <0x400a1000 0x1000>; + interrupts = <18>; + clocks = <&ccu1 CLK_APB1_I2C0>; + #address-cells = <1>; + #size-cells = <0>; +}; + +&i2c0 { + clock-frequency = <400000>; + + lm75 at 48 { + compatible = "nxp,lm75"; + reg = <0x48>; + }; +}; +
Signature · 1 line
1.8.0
Wolfram Sang
Appliedv2 cover I2C support for NXP LPC18xx family
In reply to Joachim EastwoodQuoted 21 lines · Joachim Eastwood
This patch set adds a I2C driver and documentation for the I2C peripheral found on many NXP LPC MCUs.
The driver is a rework of an old driver by Kevin Wells. It has been modified to support modern resource allocation, device tree and generally cleaned up. Driver was originally written to support the LPC2xxx platforms.
Patches based on i2c/for-next and tested on Embedded Artists' LPC4357 Dev Kit and Hitex LPC4350 Eval board with several I2C devices.
This version address comments from Wolfram Sang.
Changes since v1:
- removedev_dbg()leftovers from development/debugging
- usei2c_add_adapter
- change return value on NACK and arb lost
(I think all the others should be okay as they are)
- fix 80 char warnings (involved s/reg_base/base)
- rebase on i2c/for-next
Quoted 3 lines
Joachim Eastwood (2):
i2c: add i2c-lpc2k driver
doc: dt: add documentation for nxp,lpc1788-i2c
Applied to for-next, thanks!
Changes regarding readl_poll_timeout() can be sent incrementally.
v2 cover I2C support for NXP LPC18xx family
Quoted 22 lines · Wolfram Sang
Quoted 21 lines · Joachim Eastwood
This patch set adds a I2C driver and documentation for the I2C peripheral found on many NXP LPC MCUs.
The driver is a rework of an old driver by Kevin Wells. It has been modified to support modern resource allocation, device tree and generally cleaned up. Driver was originally written to support the LPC2xxx platforms.
Patches based on i2c/for-next and tested on Embedded Artists' LPC4357 Dev Kit and Hitex LPC4350 Eval board with several I2C devices.
This version address comments from Wolfram Sang.
Changes since v1:
- removedev_dbg()leftovers from development/debugging
- usei2c_add_adapter
- change return value on NACK and arb lost
(I think all the others should be okay as they are)
- fix 80 char warnings (involved s/reg_base/base)
- rebase on i2c/for-next
Quoted 5 lines
Quoted 3 lines
Joachim Eastwood (2):
i2c: add i2c-lpc2k driver
doc: dt: add documentation for nxp,lpc1788-i2cApplied to for-next, thanks!
Thanks, Wolfram.
Quoted 1 line
Changes regarding
readl_poll_timeout()can be sent incrementally.
Got it. I'll see if I can figure out a way to test the code path properly.
regards,
Joachim Eastwood