Re: [PATCH 2/2] i2c: driver for the Conexant Digicolor I2C controller

2015-03-19 Thread Baruch Siach
Hi Wolfram,

On Wed, Mar 18, 2015 at 10:07:30PM +0100, Wolfram Sang wrote:
> On Mon, Feb 16, 2015 at 03:20:04PM +0200, Baruch Siach wrote:
> > This commit adds a driver for the I2C master controller on the CX92755 SoC. 
> > The
> > CX92755 is one SoC in the Conexant Digicolor series. This driver should 
> > support
> > other SoCs from that series.
> > 
> > Only 7bit slave addresses are currently supported.
> > 
> > Tested on the Equinox CX92755 EVK, using i2c-tools utilities to read and 
> > write
> > the on-chip (sic) audio codec.
> > 
> > Signed-off-by: Baruch Siach 
> 
> Looks mostly good.
> 
> > +static u32 dc_i2c_func(struct i2c_adapter *adap)
> > +{
> > +   return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
> > +}
> 
> You probably want to advertise I2C_FUNC_NOSTART here, too?

OK.

> And if you could rebase to something after 4.0-rc1, that would be much
> appreciated.

Did that some time ago along with the rest of my queue for that platform. Just 
waited for some review before reposting.

Thanks for reviewing,
baruch

-- 
 http://baruch.siach.name/blog/  ~. .~   Tk Open Systems
=}ooO--U--Ooo{=
   - bar...@tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -
--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/2] i2c: driver for the Conexant Digicolor I2C controller

2015-03-18 Thread Wolfram Sang
Hi,

On Mon, Feb 16, 2015 at 03:20:04PM +0200, Baruch Siach wrote:
> This commit adds a driver for the I2C master controller on the CX92755 SoC. 
> The
> CX92755 is one SoC in the Conexant Digicolor series. This driver should 
> support
> other SoCs from that series.
> 
> Only 7bit slave addresses are currently supported.
> 
> Tested on the Equinox CX92755 EVK, using i2c-tools utilities to read and write
> the on-chip (sic) audio codec.
> 
> Signed-off-by: Baruch Siach 

Looks mostly good.

> +static u32 dc_i2c_func(struct i2c_adapter *adap)
> +{
> + return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
> +}

You probably want to advertise I2C_FUNC_NOSTART here, too?

And if you could rebase to something after 4.0-rc1, that would be much
appreciated.

Thanks,

   Wolfram


signature.asc
Description: Digital signature


[PATCH 2/2] i2c: driver for the Conexant Digicolor I2C controller

2015-02-16 Thread Baruch Siach
This commit adds a driver for the I2C master controller on the CX92755 SoC. The
CX92755 is one SoC in the Conexant Digicolor series. This driver should support
other SoCs from that series.

Only 7bit slave addresses are currently supported.

Tested on the Equinox CX92755 EVK, using i2c-tools utilities to read and write
the on-chip (sic) audio codec.

Signed-off-by: Baruch Siach 
---
 drivers/i2c/busses/Kconfig |   9 +
 drivers/i2c/busses/Makefile|   1 +
 drivers/i2c/busses/i2c-digicolor.c | 384 +
 3 files changed, 394 insertions(+)
 create mode 100644 drivers/i2c/busses/i2c-digicolor.c

diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index 31e8308ba899..08cf8acf87aa 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -465,6 +465,15 @@ config I2C_DESIGNWARE_PCI
  This driver can also be built as a module.  If so, the module
  will be called i2c-designware-pci.
 
+config I2C_DIGICOLOR
+   tristate "Conexang Digicolor I2C driver"
+   depends on ARCH_DIGICOLOR
+   help
+ Support for Conexant Digicolor SoCs (CX92755) I2C controller driver.
+
+ This driver can also be built as a module.  If so, the module
+ will be called i2c-digicolor.
+
 config I2C_EFM32
tristate "EFM32 I2C controller"
depends on ARCH_EFM32 || COMPILE_TEST
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
index 56388f658d2f..1b1830d50651 100644
--- a/drivers/i2c/busses/Makefile
+++ b/drivers/i2c/busses/Makefile
@@ -43,6 +43,7 @@ obj-$(CONFIG_I2C_DESIGNWARE_PLATFORM) += 
i2c-designware-platform.o
 i2c-designware-platform-objs := i2c-designware-platdrv.o
 obj-$(CONFIG_I2C_DESIGNWARE_PCI)   += i2c-designware-pci.o
 i2c-designware-pci-objs := i2c-designware-pcidrv.o
+obj-$(CONFIG_I2C_DIGICOLOR)+= i2c-digicolor.o
 obj-$(CONFIG_I2C_EFM32)+= i2c-efm32.o
 obj-$(CONFIG_I2C_EG20T)+= i2c-eg20t.o
 obj-$(CONFIG_I2C_EXYNOS5)  += i2c-exynos5.o
diff --git a/drivers/i2c/busses/i2c-digicolor.c 
b/drivers/i2c/busses/i2c-digicolor.c
new file mode 100644
index ..0ec0eafb8fb6
--- /dev/null
+++ b/drivers/i2c/busses/i2c-digicolor.c
@@ -0,0 +1,384 @@
+/*
+ * I2C bus driver for Conexant Digicolor SoCs
+ *
+ * Author: Baruch Siach 
+ *
+ * Copyright (C) 2015 Paradox Innovation Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define DEFAULT_FREQ   10
+#define TIMEOUT_MS 100
+
+#define II_CONTROL 0x0
+#define II_CONTROL_LOCAL_RESET BIT(0)
+
+#define II_CLOCKTIME   0x1
+
+#define II_COMMAND 0x2
+#define II_CMD_START   1
+#define II_CMD_RESTART 2
+#define II_CMD_SEND_ACK3
+#define II_CMD_GET_ACK 6
+#define II_CMD_GET_NOACK   7
+#define II_CMD_STOP10
+#define II_COMMAND_GO  BIT(7)
+#define II_COMMAND_COMPLETION_STATUS(r)(((r) >> 5) & 3)
+#define II_CMD_STATUS_NORMAL   0
+#define II_CMD_STATUS_ACK_GOOD 1
+#define II_CMD_STATUS_ACK_BAD  2
+#define II_CMD_STATUS_ABORT3
+
+#define II_DATA0x3
+#define II_INTFLAG_CLEAR   0x8
+#define II_INTENABLE   0xa
+
+struct dc_i2c {
+   struct i2c_adapter  adap;
+   struct device   *dev;
+   void __iomem*regs;
+   struct clk  *clk;
+   unsigned intfrequency;
+
+   struct i2c_msg  *msg;
+   unsigned intmsgbuf_ptr;
+   int last;
+   spinlock_t  lock;
+   struct completion   done;
+   int state;
+   int error;
+};
+
+enum {
+STATE_IDLE,
+STATE_START,
+STATE_ADDR,
+STATE_WRITE,
+STATE_READ,
+STATE_STOP,
+};
+
+static void dc_i2c_cmd(struct dc_i2c *i2c, u8 cmd)
+{
+   writeb_relaxed(cmd | II_COMMAND_GO, i2c->regs + II_COMMAND);
+}
+
+static u8 dc_i2c_addr_cmd(struct i2c_msg *msg)
+{
+   u8 addr = (msg->addr & 0x7f) << 1;
+
+   if (msg->flags & I2C_M_RD)
+   addr |= 1;
+
+   return addr;
+}
+
+static void dc_i2c_data(struct dc_i2c *i2c, u8 data)
+{
+   writeb_relaxed(data, i2c->regs + II_DATA);
+}
+
+static void dc_i2c_write_byte(struct dc_i2c *i2c, u8 byte)
+{
+   dc_i2c_data(i2c, byte);
+   dc_i2c_cmd(i2c, II_CMD_SEND_ACK);
+}
+
+static void dc_i2c_write_buf(struct dc_i2c *i2c)
+{
+   dc_i2c_write_byte(i2c, i2c->msg->buf[i2c->msgbuf_ptr++]);
+}
+
+static void dc_i2c_next_read(struct dc_i2c *i2c)
+{
+   bool last = (i2c->msgbuf_ptr+1 == i2c->msg->len);
+   dc_i2c_cmd(i2c, last ? II_