Re: [PATCH v3 2/3] i2c: iproc: Add Broadcom iProc I2C Driver

2015-01-16 Thread Ray Jui


On 1/15/2015 3:59 AM, Wolfram Sang wrote:
 +  case M_CMD_STATUS_LOST_ARB:
 +  dev_err(dev->device, "lost bus arbitration\n");
>>> I wouldn't dev_err that, only dev_dbg. I'm not sure how usual the errors
>>> for the next two cases is, maybe degrade them to dev_dbg, too?
>>>
>> These errors are rare, and it's nice to keep them at the dev_err level
>> so the user will be more aware.
> 
> This is wrong. Arbitration lost and NACK is pretty standard stuff on an
> I2C bus. User doesn't need to know about it, it is just noise in the
> logs. Timeout is different, you can report that (although I should
> probably move such a message into the core). Please also use the proper
> errno codes defined in Documentation/i2c/fault-codes. They should be
> distinct enough to drop the messages.
> 
Okay will do.

>>
 +  return -EREMOTEIO;
 +
 +  case M_CMD_STATUS_NACK_ADDR:
 +  dev_err(dev->device, "NAK addr:0x%02x\n", dev->msg->addr);
 +  return -EREMOTEIO;
 +
 +  case M_CMD_STATUS_NACK_DATA:
 +  dev_err(dev->device, "NAK data\n");
 +  return -EREMOTEIO;
 +
 +  case M_CMD_STATUS_TIMEOUT:
 +  dev_err(dev->device, "bus timeout\n");
 +  return -ETIMEDOUT;
 +
 +  default:
 +  dev_err(dev->device, "unknown error code=%d\n", val);
 +  return -EREMOTEIO;
 +  }
 +
 +  return -EREMOTEIO;
 +}
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3 2/3] i2c: iproc: Add Broadcom iProc I2C Driver

2015-01-15 Thread Wolfram Sang
> >> +  case M_CMD_STATUS_LOST_ARB:
> >> +  dev_err(dev->device, "lost bus arbitration\n");
> > I wouldn't dev_err that, only dev_dbg. I'm not sure how usual the errors
> > for the next two cases is, maybe degrade them to dev_dbg, too?
> > 
> These errors are rare, and it's nice to keep them at the dev_err level
> so the user will be more aware.

This is wrong. Arbitration lost and NACK is pretty standard stuff on an
I2C bus. User doesn't need to know about it, it is just noise in the
logs. Timeout is different, you can report that (although I should
probably move such a message into the core). Please also use the proper
errno codes defined in Documentation/i2c/fault-codes. They should be
distinct enough to drop the messages.

> 
> >> +  return -EREMOTEIO;
> >> +
> >> +  case M_CMD_STATUS_NACK_ADDR:
> >> +  dev_err(dev->device, "NAK addr:0x%02x\n", dev->msg->addr);
> >> +  return -EREMOTEIO;
> >> +
> >> +  case M_CMD_STATUS_NACK_DATA:
> >> +  dev_err(dev->device, "NAK data\n");
> >> +  return -EREMOTEIO;
> >> +
> >> +  case M_CMD_STATUS_TIMEOUT:
> >> +  dev_err(dev->device, "bus timeout\n");
> >> +  return -ETIMEDOUT;
> >> +
> >> +  default:
> >> +  dev_err(dev->device, "unknown error code=%d\n", val);
> >> +  return -EREMOTEIO;
> >> +  }
> >> +
> >> +  return -EREMOTEIO;
> >> +}


signature.asc
Description: Digital signature


Re: [PATCH v3 2/3] i2c: iproc: Add Broadcom iProc I2C Driver

2015-01-14 Thread Ray Jui


On 1/13/2015 11:51 PM, Uwe Kleine-König wrote:
> Hello,
> 
> On Tue, Jan 13, 2015 at 06:14:17PM -0800, Ray Jui wrote:
 +  irq = platform_get_irq(pdev, 0);
 +  if (irq < 0) {
>>> irq == 0 should be handled as error, too.
>>>
>> Ah. I thought zero is a valid global interrupt number, and I see other
>> drivers checking against < 0 as well. Is my understanding incorrect?
> These are wrong, too. 0 should never be a valid interrupt number. There
> are some exceptions but mostly for historic reasons. The right handling
> is used for example in drivers/i2c/busses/i2c-efm32.c.
> 
Okay. Will check against <= 0. Thanks.

 +  dev_err(dev->device, "no irq resource\n");
 +  return irq;
 +  }
>> [...]
 +static int bcm_iproc_i2c_remove(struct platform_device *pdev)
 +{
 +  struct bcm_iproc_i2c_dev *dev = platform_get_drvdata(pdev);
 +
 +  i2c_del_adapter(&dev->adapter);
 +  bcm_iproc_i2c_disable(dev);
>>> I think you have a problem here if bcm_iproc_i2c_remove is called while
>>> an irq is still being serviced. I'm not sure how to prevent this
>>> properly for a shared interrupt.
>>>
>> Can I grab i2c_lock_adapter to ensure the bus is locked (so there's no
>> outstanding transactions or IRQs by the time we remove the adapter)? But
>> I see no I2C bus driver does this in their remove function...
> The problem I pointed out is the reason for some driver authors not to
> use devm_request_irq. If you use plain request_irq and the matching
> free_irq in the .remove callback you can be sure that the irq isn't
> running any more as soon as free_irq returns.
> 
Okay. Will change to use request_irq and make sure that it's freed in
the remove function. Also, the interrupt is dedicated to the I2C
controller, so I'll remove the IRQF_SHARED flag.

> BTW, if you use vim, you can add
> 
>   set cinoptions=(,:
>   if has("autocmd")
>   filetype plugin indent on
>   endif
> 
> to your .vimrc. Then while typing vim does the indention right and
> consistent, and with the = command you can reindent.
> 
Wow this is excellent! Just tried and it works perfectly. Thanks a lot!!!

> Best regards
> Uwe
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3 2/3] i2c: iproc: Add Broadcom iProc I2C Driver

2015-01-13 Thread Uwe Kleine-König
Hello,

On Tue, Jan 13, 2015 at 06:14:17PM -0800, Ray Jui wrote:
> >> +  irq = platform_get_irq(pdev, 0);
> >> +  if (irq < 0) {
> > irq == 0 should be handled as error, too.
> > 
> Ah. I thought zero is a valid global interrupt number, and I see other
> drivers checking against < 0 as well. Is my understanding incorrect?
These are wrong, too. 0 should never be a valid interrupt number. There
are some exceptions but mostly for historic reasons. The right handling
is used for example in drivers/i2c/busses/i2c-efm32.c.

> >> +  dev_err(dev->device, "no irq resource\n");
> >> +  return irq;
> >> +  }
> [...]
> >> +static int bcm_iproc_i2c_remove(struct platform_device *pdev)
> >> +{
> >> +  struct bcm_iproc_i2c_dev *dev = platform_get_drvdata(pdev);
> >> +
> >> +  i2c_del_adapter(&dev->adapter);
> >> +  bcm_iproc_i2c_disable(dev);
> > I think you have a problem here if bcm_iproc_i2c_remove is called while
> > an irq is still being serviced. I'm not sure how to prevent this
> > properly for a shared interrupt.
> > 
> Can I grab i2c_lock_adapter to ensure the bus is locked (so there's no
> outstanding transactions or IRQs by the time we remove the adapter)? But
> I see no I2C bus driver does this in their remove function...
The problem I pointed out is the reason for some driver authors not to
use devm_request_irq. If you use plain request_irq and the matching
free_irq in the .remove callback you can be sure that the irq isn't
running any more as soon as free_irq returns.

BTW, if you use vim, you can add

set cinoptions=(,:
if has("autocmd")
filetype plugin indent on
endif

to your .vimrc. Then while typing vim does the indention right and
consistent, and with the = command you can reindent.

Best regards
Uwe

-- 
Pengutronix e.K.   | Uwe Kleine-König|
Industrial Linux Solutions | http://www.pengutronix.de/  |
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3 2/3] i2c: iproc: Add Broadcom iProc I2C Driver

2015-01-13 Thread Ray Jui


On 1/13/2015 2:50 PM, Uwe Kleine-König wrote:
> Hello,
> 
> On Tue, Dec 09, 2014 at 07:57:11PM -0800, Ray Jui wrote:
>> Add initial support to the Broadcom iProc I2C controller found in the
>> iProc family of SoCs.
>>
>> The iProc I2C controller has separate internal TX and RX FIFOs, each has
>> a size of 64 bytes. The iProc I2C controller supports two bus speeds
>> including standard mode (100kHz) and fast mode (400kHz)
>>
>> Signed-off-by: Ray Jui 
>> Reviewed-by: Scott Branden 
>> ---
>>  drivers/i2c/busses/Kconfig |   10 +
>>  drivers/i2c/busses/Makefile|1 +
>>  drivers/i2c/busses/i2c-bcm-iproc.c |  500 
>> 
>>  3 files changed, 511 insertions(+)
>>  create mode 100644 drivers/i2c/busses/i2c-bcm-iproc.c
>>
>> diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
>> index c1351d9..df21366 100644
>> --- a/drivers/i2c/busses/Kconfig
>> +++ b/drivers/i2c/busses/Kconfig
>> @@ -372,6 +372,16 @@ config I2C_BCM2835
>>This support is also available as a module.  If so, the module
>>will be called i2c-bcm2835.
>>  
>> +config I2C_BCM_IPROC
>> +tristate "Broadcom iProc I2C controller"
>> +depends on ARCH_BCM_IPROC
>> +default y
> It would be nice to have the following here to improve compile coverage
> testing:
> 
>   depends on ARCH_BCM_IPROC || COMPILE_TEST
>   default ARCH_BCM_IPROC
> 
Sure will do!

>> +help
>> +  If you say yes to this option, support will be included for the
>> +  Broadcom iProc I2C controller.
>> +
>> +  If you don't know what to do here, say N.
>> +
>>  config I2C_BCM_KONA
>>  tristate "BCM Kona I2C adapter"
>>  depends on ARCH_BCM_MOBILE
>> diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
>> index 5e6c822..216e7be 100644
>> --- a/drivers/i2c/busses/Makefile
>> +++ b/drivers/i2c/busses/Makefile
>> @@ -33,6 +33,7 @@ obj-$(CONFIG_I2C_AT91) += i2c-at91.o
>>  obj-$(CONFIG_I2C_AU1550)+= i2c-au1550.o
>>  obj-$(CONFIG_I2C_AXXIA) += i2c-axxia.o
>>  obj-$(CONFIG_I2C_BCM2835)   += i2c-bcm2835.o
>> +obj-$(CONFIG_I2C_BCM_IPROC) += i2c-bcm-iproc.o
>>  obj-$(CONFIG_I2C_BLACKFIN_TWI)  += i2c-bfin-twi.o
>>  obj-$(CONFIG_I2C_CADENCE)   += i2c-cadence.o
>>  obj-$(CONFIG_I2C_CBUS_GPIO) += i2c-cbus-gpio.o
>> diff --git a/drivers/i2c/busses/i2c-bcm-iproc.c 
>> b/drivers/i2c/busses/i2c-bcm-iproc.c
>> new file mode 100644
>> index 000..35ac497
>> --- /dev/null
>> +++ b/drivers/i2c/busses/i2c-bcm-iproc.c
>> @@ -0,0 +1,500 @@
>> +/*
>> + * Copyright (C) 2014 Broadcom Corporation
>> + *
>> + * 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 version 2.
>> + *
>> + * This program is distributed "as is" WITHOUT ANY WARRANTY of any
>> + * kind, whether express or implied; without even the implied warranty
>> + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>> + * GNU General Public License for more details.
>> + */
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#define CFG_OFFSET   0x00
>> +#define CFG_RESET_SHIFT  31
>> +#define CFG_EN_SHIFT 30
>> +#define CFG_M_RETRY_CNT_SHIFT16
>> +#define CFG_M_RETRY_CNT_MASK 0x0f
>> +
>> +#define TIM_CFG_OFFSET   0x04
>> +#define TIME_CFG_MODE_400_SHIFT  31
>> +
>> +#define M_FIFO_CTRL_OFFSET   0x0c
>> +#define M_FIFO_RX_FLUSH_SHIFT31
>> +#define M_FIFO_TX_FLUSH_SHIFT30
>> +#define M_FIFO_RX_CNT_SHIFT  16
>> +#define M_FIFO_RX_CNT_MASK   0x7f
>> +#define M_FIFO_RX_THLD_SHIFT 8
>> +#define M_FIFO_RX_THLD_MASK  0x3f
>> +
>> +#define M_CMD_OFFSET 0x30
>> +#define M_CMD_START_BUSY_SHIFT   31
>> +#define M_CMD_STATUS_SHIFT   25
>> +#define M_CMD_STATUS_MASK0x07
>> +#define M_CMD_STATUS_SUCCESS 0x0
>> +#define M_CMD_STATUS_LOST_ARB0x1
>> +#define M_CMD_STATUS_NACK_ADDR   0x2
>> +#define M_CMD_STATUS_NACK_DATA   0x3
>> +#define M_CMD_STATUS_TIMEOUT 0x4
>> +#define M_CMD_PROTOCOL_SHIFT 9
>> +#define M_CMD_PROTOCOL_MASK  0xf
>> +#define M_CMD_PROTOCOL_BLK_WR0x7
>> +#define M_CMD_PROTOCOL_BLK_RD0x8
>> +#define M_CMD_PEC_SHIFT  8
>> +#define M_CMD_RD_CNT_SHIFT   0
>> +#define M_CMD_RD_CNT_MASK0xff
>> +
>> +#define IE_OFFSET0x38
>> +#define IE_M_RX_FIFO_FULL_SHIFT  31
>> +#define IE_M_RX_THLD_SHIFT   30
>> +#define IE_M_START_BUSY_SHIFT28
>> +
>> +#define IS_OFFSET0x3c
>> +#define IS_M_RX_FIFO_FULL_SHIFT  31
>> +#define IS_M_RX_THLD_SHIFT   30
>> +#define IS_M_START_BUSY_SHIFT28
>> +
>> +#defin

Re: [PATCH v3 2/3] i2c: iproc: Add Broadcom iProc I2C Driver

2015-01-13 Thread Uwe Kleine-König
Hello,

On Tue, Dec 09, 2014 at 07:57:11PM -0800, Ray Jui wrote:
> Add initial support to the Broadcom iProc I2C controller found in the
> iProc family of SoCs.
> 
> The iProc I2C controller has separate internal TX and RX FIFOs, each has
> a size of 64 bytes. The iProc I2C controller supports two bus speeds
> including standard mode (100kHz) and fast mode (400kHz)
> 
> Signed-off-by: Ray Jui 
> Reviewed-by: Scott Branden 
> ---
>  drivers/i2c/busses/Kconfig |   10 +
>  drivers/i2c/busses/Makefile|1 +
>  drivers/i2c/busses/i2c-bcm-iproc.c |  500 
> 
>  3 files changed, 511 insertions(+)
>  create mode 100644 drivers/i2c/busses/i2c-bcm-iproc.c
> 
> diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
> index c1351d9..df21366 100644
> --- a/drivers/i2c/busses/Kconfig
> +++ b/drivers/i2c/busses/Kconfig
> @@ -372,6 +372,16 @@ config I2C_BCM2835
> This support is also available as a module.  If so, the module
> will be called i2c-bcm2835.
>  
> +config I2C_BCM_IPROC
> + tristate "Broadcom iProc I2C controller"
> + depends on ARCH_BCM_IPROC
> + default y
It would be nice to have the following here to improve compile coverage
testing:

depends on ARCH_BCM_IPROC || COMPILE_TEST
default ARCH_BCM_IPROC

> + help
> +   If you say yes to this option, support will be included for the
> +   Broadcom iProc I2C controller.
> +
> +   If you don't know what to do here, say N.
> +
>  config I2C_BCM_KONA
>   tristate "BCM Kona I2C adapter"
>   depends on ARCH_BCM_MOBILE
> diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
> index 5e6c822..216e7be 100644
> --- a/drivers/i2c/busses/Makefile
> +++ b/drivers/i2c/busses/Makefile
> @@ -33,6 +33,7 @@ obj-$(CONFIG_I2C_AT91)  += i2c-at91.o
>  obj-$(CONFIG_I2C_AU1550) += i2c-au1550.o
>  obj-$(CONFIG_I2C_AXXIA)  += i2c-axxia.o
>  obj-$(CONFIG_I2C_BCM2835)+= i2c-bcm2835.o
> +obj-$(CONFIG_I2C_BCM_IPROC)  += i2c-bcm-iproc.o
>  obj-$(CONFIG_I2C_BLACKFIN_TWI)   += i2c-bfin-twi.o
>  obj-$(CONFIG_I2C_CADENCE)+= i2c-cadence.o
>  obj-$(CONFIG_I2C_CBUS_GPIO)  += i2c-cbus-gpio.o
> diff --git a/drivers/i2c/busses/i2c-bcm-iproc.c 
> b/drivers/i2c/busses/i2c-bcm-iproc.c
> new file mode 100644
> index 000..35ac497
> --- /dev/null
> +++ b/drivers/i2c/busses/i2c-bcm-iproc.c
> @@ -0,0 +1,500 @@
> +/*
> + * Copyright (C) 2014 Broadcom Corporation
> + *
> + * 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 version 2.
> + *
> + * This program is distributed "as is" WITHOUT ANY WARRANTY of any
> + * kind, whether express or implied; without even the implied warranty
> + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define CFG_OFFSET   0x00
> +#define CFG_RESET_SHIFT  31
> +#define CFG_EN_SHIFT 30
> +#define CFG_M_RETRY_CNT_SHIFT16
> +#define CFG_M_RETRY_CNT_MASK 0x0f
> +
> +#define TIM_CFG_OFFSET   0x04
> +#define TIME_CFG_MODE_400_SHIFT  31
> +
> +#define M_FIFO_CTRL_OFFSET   0x0c
> +#define M_FIFO_RX_FLUSH_SHIFT31
> +#define M_FIFO_TX_FLUSH_SHIFT30
> +#define M_FIFO_RX_CNT_SHIFT  16
> +#define M_FIFO_RX_CNT_MASK   0x7f
> +#define M_FIFO_RX_THLD_SHIFT 8
> +#define M_FIFO_RX_THLD_MASK  0x3f
> +
> +#define M_CMD_OFFSET 0x30
> +#define M_CMD_START_BUSY_SHIFT   31
> +#define M_CMD_STATUS_SHIFT   25
> +#define M_CMD_STATUS_MASK0x07
> +#define M_CMD_STATUS_SUCCESS 0x0
> +#define M_CMD_STATUS_LOST_ARB0x1
> +#define M_CMD_STATUS_NACK_ADDR   0x2
> +#define M_CMD_STATUS_NACK_DATA   0x3
> +#define M_CMD_STATUS_TIMEOUT 0x4
> +#define M_CMD_PROTOCOL_SHIFT 9
> +#define M_CMD_PROTOCOL_MASK  0xf
> +#define M_CMD_PROTOCOL_BLK_WR0x7
> +#define M_CMD_PROTOCOL_BLK_RD0x8
> +#define M_CMD_PEC_SHIFT  8
> +#define M_CMD_RD_CNT_SHIFT   0
> +#define M_CMD_RD_CNT_MASK0xff
> +
> +#define IE_OFFSET0x38
> +#define IE_M_RX_FIFO_FULL_SHIFT  31
> +#define IE_M_RX_THLD_SHIFT   30
> +#define IE_M_START_BUSY_SHIFT28
> +
> +#define IS_OFFSET0x3c
> +#define IS_M_RX_FIFO_FULL_SHIFT  31
> +#define IS_M_RX_THLD_SHIFT   30
> +#define IS_M_START_BUSY_SHIFT28
> +
> +#define M_TX_OFFSET  0x40
> +#define M_TX_WR_STATUS_SHIFT 31
> +#define M_TX_DATA_SHIFT  0
> +#define M_TX_DATA_MASK   0xff
> +
> +#define M

[PATCH v3 2/3] i2c: iproc: Add Broadcom iProc I2C Driver

2014-12-09 Thread Ray Jui
Add initial support to the Broadcom iProc I2C controller found in the
iProc family of SoCs.

The iProc I2C controller has separate internal TX and RX FIFOs, each has
a size of 64 bytes. The iProc I2C controller supports two bus speeds
including standard mode (100kHz) and fast mode (400kHz)

Signed-off-by: Ray Jui 
Reviewed-by: Scott Branden 
---
 drivers/i2c/busses/Kconfig |   10 +
 drivers/i2c/busses/Makefile|1 +
 drivers/i2c/busses/i2c-bcm-iproc.c |  500 
 3 files changed, 511 insertions(+)
 create mode 100644 drivers/i2c/busses/i2c-bcm-iproc.c

diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index c1351d9..df21366 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -372,6 +372,16 @@ config I2C_BCM2835
  This support is also available as a module.  If so, the module
  will be called i2c-bcm2835.
 
+config I2C_BCM_IPROC
+   tristate "Broadcom iProc I2C controller"
+   depends on ARCH_BCM_IPROC
+   default y
+   help
+ If you say yes to this option, support will be included for the
+ Broadcom iProc I2C controller.
+
+ If you don't know what to do here, say N.
+
 config I2C_BCM_KONA
tristate "BCM Kona I2C adapter"
depends on ARCH_BCM_MOBILE
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
index 5e6c822..216e7be 100644
--- a/drivers/i2c/busses/Makefile
+++ b/drivers/i2c/busses/Makefile
@@ -33,6 +33,7 @@ obj-$(CONFIG_I2C_AT91)+= i2c-at91.o
 obj-$(CONFIG_I2C_AU1550)   += i2c-au1550.o
 obj-$(CONFIG_I2C_AXXIA)+= i2c-axxia.o
 obj-$(CONFIG_I2C_BCM2835)  += i2c-bcm2835.o
+obj-$(CONFIG_I2C_BCM_IPROC)+= i2c-bcm-iproc.o
 obj-$(CONFIG_I2C_BLACKFIN_TWI) += i2c-bfin-twi.o
 obj-$(CONFIG_I2C_CADENCE)  += i2c-cadence.o
 obj-$(CONFIG_I2C_CBUS_GPIO)+= i2c-cbus-gpio.o
diff --git a/drivers/i2c/busses/i2c-bcm-iproc.c 
b/drivers/i2c/busses/i2c-bcm-iproc.c
new file mode 100644
index 000..35ac497
--- /dev/null
+++ b/drivers/i2c/busses/i2c-bcm-iproc.c
@@ -0,0 +1,500 @@
+/*
+ * Copyright (C) 2014 Broadcom Corporation
+ *
+ * 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 version 2.
+ *
+ * This program is distributed "as is" WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define CFG_OFFSET   0x00
+#define CFG_RESET_SHIFT  31
+#define CFG_EN_SHIFT 30
+#define CFG_M_RETRY_CNT_SHIFT16
+#define CFG_M_RETRY_CNT_MASK 0x0f
+
+#define TIM_CFG_OFFSET   0x04
+#define TIME_CFG_MODE_400_SHIFT  31
+
+#define M_FIFO_CTRL_OFFSET   0x0c
+#define M_FIFO_RX_FLUSH_SHIFT31
+#define M_FIFO_TX_FLUSH_SHIFT30
+#define M_FIFO_RX_CNT_SHIFT  16
+#define M_FIFO_RX_CNT_MASK   0x7f
+#define M_FIFO_RX_THLD_SHIFT 8
+#define M_FIFO_RX_THLD_MASK  0x3f
+
+#define M_CMD_OFFSET 0x30
+#define M_CMD_START_BUSY_SHIFT   31
+#define M_CMD_STATUS_SHIFT   25
+#define M_CMD_STATUS_MASK0x07
+#define M_CMD_STATUS_SUCCESS 0x0
+#define M_CMD_STATUS_LOST_ARB0x1
+#define M_CMD_STATUS_NACK_ADDR   0x2
+#define M_CMD_STATUS_NACK_DATA   0x3
+#define M_CMD_STATUS_TIMEOUT 0x4
+#define M_CMD_PROTOCOL_SHIFT 9
+#define M_CMD_PROTOCOL_MASK  0xf
+#define M_CMD_PROTOCOL_BLK_WR0x7
+#define M_CMD_PROTOCOL_BLK_RD0x8
+#define M_CMD_PEC_SHIFT  8
+#define M_CMD_RD_CNT_SHIFT   0
+#define M_CMD_RD_CNT_MASK0xff
+
+#define IE_OFFSET0x38
+#define IE_M_RX_FIFO_FULL_SHIFT  31
+#define IE_M_RX_THLD_SHIFT   30
+#define IE_M_START_BUSY_SHIFT28
+
+#define IS_OFFSET0x3c
+#define IS_M_RX_FIFO_FULL_SHIFT  31
+#define IS_M_RX_THLD_SHIFT   30
+#define IS_M_START_BUSY_SHIFT28
+
+#define M_TX_OFFSET  0x40
+#define M_TX_WR_STATUS_SHIFT 31
+#define M_TX_DATA_SHIFT  0
+#define M_TX_DATA_MASK   0xff
+
+#define M_RX_OFFSET  0x44
+#define M_RX_STATUS_SHIFT30
+#define M_RX_STATUS_MASK 0x03
+#define M_RX_PEC_ERR_SHIFT   29
+#define M_RX_DATA_SHIFT  0
+#define M_RX_DATA_MASK   0xff
+
+#define I2C_TIMEOUT_MESC 100
+#define M_TX_RX_FIFO_SIZE64
+
+enum bus_speed_index {
+   I2C_SPD_100K = 0,
+   I2C_SPD_400K,
+};
+
+struct bcm_iproc_i2c_dev {
+   struct device *device;