Re: [PATCH v4 3/3] i2c: at91: added slave mode support

2019-02-19 Thread Ludovic Desroches
Hi,

On Fri, Feb 15, 2019 at 10:18:47AM +0100, Wolfram Sang wrote:
> On Tue, Jan 15, 2019 at 11:43:51PM +0100, Wolfram Sang wrote:
> > 
> > > All errors (new ones prefixed by >>):
> > > 
> > > >> ERROR: "at91_init_twi_bus_slave" [drivers/i2c/busses/i2c-at91.ko] 
> > > >> undefined!
> > > >> ERROR: "at91_twi_probe_slave" [drivers/i2c/busses/i2c-at91.ko] 
> > > >> undefined!
> > 
> > That needs to be fixed. Rest looks good to me!
> 
> Ludovic, do you have time to fix it? I would really like to apply this
> series for the next merge window.
> 

Sorry it's in my todo list but I didn't have time to handle it. I'll try
to fix it beginning of next week.

Regards

Ludovic



> ___
> linux-arm-kernel mailing list
> linux-arm-ker...@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel



Re: [PATCH v4 3/3] i2c: at91: added slave mode support

2019-02-15 Thread Wolfram Sang
On Tue, Jan 15, 2019 at 11:43:51PM +0100, Wolfram Sang wrote:
> 
> > All errors (new ones prefixed by >>):
> > 
> > >> ERROR: "at91_init_twi_bus_slave" [drivers/i2c/busses/i2c-at91.ko] 
> > >> undefined!
> > >> ERROR: "at91_twi_probe_slave" [drivers/i2c/busses/i2c-at91.ko] undefined!
> 
> That needs to be fixed. Rest looks good to me!

Ludovic, do you have time to fix it? I would really like to apply this
series for the next merge window.



signature.asc
Description: PGP signature


Re: [PATCH v4 3/3] i2c: at91: added slave mode support

2019-01-15 Thread Wolfram Sang

> All errors (new ones prefixed by >>):
> 
> >> ERROR: "at91_init_twi_bus_slave" [drivers/i2c/busses/i2c-at91.ko] 
> >> undefined!
> >> ERROR: "at91_twi_probe_slave" [drivers/i2c/busses/i2c-at91.ko] undefined!

That needs to be fixed. Rest looks good to me!



signature.asc
Description: PGP signature


Re: [PATCH v4 3/3] i2c: at91: added slave mode support

2019-01-04 Thread kbuild test robot
Hi Juergen,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on wsa/i2c/for-next]
[also build test ERROR on v4.20 next-20190103]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Ludovic-Desroches/i2c-at91-slave-mode-support/20181227-231603
base:   https://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git 
i2c/for-next
config: arm-allmodconfig (attached as .config)
compiler: arm-linux-gnueabi-gcc (Debian 7.2.0-11) 7.2.0
reproduce:
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.2.0 make.cross ARCH=arm 

All errors (new ones prefixed by >>):

>> ERROR: "at91_init_twi_bus_slave" [drivers/i2c/busses/i2c-at91.ko] undefined!
>> ERROR: "at91_twi_probe_slave" [drivers/i2c/busses/i2c-at91.ko] undefined!

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: application/gzip


Re: [PATCH v4 3/3] i2c: at91: added slave mode support

2019-01-01 Thread Wolfram Sang

> Perhaps, you can use SPDX instead of boiler plate license text in the files?

I think we can do this incrementally.



signature.asc
Description: PGP signature


Re: [PATCH v4 3/3] i2c: at91: added slave mode support

2018-12-31 Thread Andy Shevchenko
> Slave mode driver is based on the concept of i2c-designware driver.

> +/*
> + *  i2c slave support for Atmel's AT91 Two-Wire Interface (TWI)
> + *
> + *  Copyright (C) 2017 Juergen Fitschen 
> + *
> + *  This program is free software; you can redistribute it and/or modify
> + *  it under the terms of the GNU General Public License as published by
> + *  the Free Software Foundation; either version 2 of the License, or
> + *  (at your option) any later version.
> + */

Perhaps, you can use SPDX instead of boiler plate license text in the files?

-- 
With Best Regards,
Andy Shevchenko




[PATCH v4 3/3] i2c: at91: added slave mode support

2018-12-27 Thread Ludovic Desroches
From: Juergen Fitschen 

Slave mode driver is based on the concept of i2c-designware driver.

Signed-off-by: Juergen Fitschen 
[ludovic.desroc...@microchip.com: rework Kconfig]
Signed-off-by: Ludovic Desroches 
---
 drivers/i2c/busses/Kconfig  |  13 +++
 drivers/i2c/busses/Makefile |   3 +
 drivers/i2c/busses/i2c-at91-core.c  |  13 ++-
 drivers/i2c/busses/i2c-at91-slave.c | 147 
 drivers/i2c/busses/i2c-at91.h   |  30 +-
 5 files changed, 202 insertions(+), 4 deletions(-)
 create mode 100644 drivers/i2c/busses/i2c-at91-slave.c

diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index f2c681971201..6b1f6dcdf533 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -387,6 +387,19 @@ config I2C_AT91
  the latency to fill the transmission register is too long. If you
  are facing this situation, use the i2c-gpio driver.
 
+config I2C_AT91_SLAVE_EXPERIMENTAL
+   tristate "Microchip AT91 I2C experimental slave mode"
+   depends on I2C_AT91
+   select I2C_SLAVE
+   help
+ If you say yes to this option, support for the slave mode will be
+ added. Caution: do not use it for production. This feature has not
+ been tested in a heavy way, help wanted.
+ There are known bugs:
+   - It can hang, on a SAMA5D4, after several transfers.
+   - There are some mismtaches with a SAMA5D4 as slave and a SAMA5D2 as
+   master.
+
 config I2C_AU1550
tristate "Au1550/Au1200/Au1300 SMBus interface"
depends on MIPS_ALCHEMY
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
index ea75a777940e..59b22fbef90a 100644
--- a/drivers/i2c/busses/Makefile
+++ b/drivers/i2c/busses/Makefile
@@ -36,6 +36,9 @@ obj-$(CONFIG_I2C_ALTERA)  += i2c-altera.o
 obj-$(CONFIG_I2C_ASPEED)   += i2c-aspeed.o
 obj-$(CONFIG_I2C_AT91) += i2c-at91.o
 i2c-at91-objs  := i2c-at91-core.o i2c-at91-master.o
+ifeq ($(CONFIG_I2C_AT91_SLAVE_EXPERIMENTAL),y)
+   i2c-at91-objs   += i2c-at91-slave.o
+endif
 obj-$(CONFIG_I2C_AU1550)   += i2c-au1550.o
 obj-$(CONFIG_I2C_AXXIA)+= i2c-axxia.o
 obj-$(CONFIG_I2C_BCM2835)  += i2c-bcm2835.o
diff --git a/drivers/i2c/busses/i2c-at91-core.c 
b/drivers/i2c/busses/i2c-at91-core.c
index 5d9c6c81e6ab..c74283fa567f 100644
--- a/drivers/i2c/busses/i2c-at91-core.c
+++ b/drivers/i2c/busses/i2c-at91-core.c
@@ -60,8 +60,10 @@ void at91_init_twi_bus(struct at91_twi_dev *dev)
 {
at91_disable_twi_interrupts(dev);
at91_twi_write(dev, AT91_TWI_CR, AT91_TWI_SWRST);
-
-   at91_init_twi_bus_master(dev);
+   if (dev->slave_detected)
+   at91_init_twi_bus_slave(dev);
+   else
+   at91_init_twi_bus_master(dev);
 }
 
 static struct at91_twi_pdata at91rm9200_config = {
@@ -243,7 +245,12 @@ static int at91_twi_probe(struct platform_device *pdev)
dev->adapter.timeout = AT91_I2C_TIMEOUT;
dev->adapter.dev.of_node = pdev->dev.of_node;
 
-   rc = at91_twi_probe_master(pdev, phy_addr, dev);
+   dev->slave_detected = i2c_detect_slave_mode(>dev);
+
+   if (dev->slave_detected)
+   rc = at91_twi_probe_slave(pdev, phy_addr, dev);
+   else
+   rc = at91_twi_probe_master(pdev, phy_addr, dev);
if (rc)
return rc;
 
diff --git a/drivers/i2c/busses/i2c-at91-slave.c 
b/drivers/i2c/busses/i2c-at91-slave.c
new file mode 100644
index ..4b4808e0c8f7
--- /dev/null
+++ b/drivers/i2c/busses/i2c-at91-slave.c
@@ -0,0 +1,147 @@
+/*
+ *  i2c slave support for Atmel's AT91 Two-Wire Interface (TWI)
+ *
+ *  Copyright (C) 2017 Juergen Fitschen 
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include "i2c-at91.h"
+
+static irqreturn_t atmel_twi_interrupt_slave(int irq, void *dev_id)
+{
+   struct at91_twi_dev *dev = dev_id;
+   const unsigned status = at91_twi_read(dev, AT91_TWI_SR);
+   const unsigned irqstatus = status & at91_twi_read(dev, AT91_TWI_IMR);
+   u8 value;
+
+   if (!irqstatus)
+   return IRQ_NONE;
+
+   /* slave address has been detected on I2C bus */
+   if (irqstatus & AT91_TWI_SVACC) {
+   if (status & AT91_TWI_SVREAD) {
+   i2c_slave_event(dev->slave,
+   I2C_SLAVE_READ_REQUESTED, );
+   writeb_relaxed(value, dev->base + AT91_TWI_THR);
+   at91_twi_write(dev, AT91_TWI_IER,
+  AT91_TWI_TXRDY | AT91_TWI_EOSACC);
+   } else {
+   i2c_slave_event(dev->slave,
+