[PATCH V7 2/2] i2c/designware: Provide i2c bus recovery support

2012-11-24 Thread Viresh Kumar
Add bus recovery support for designware_i2c controller. It uses generic gpio
based i2c_gpio_recover_bus() routine. Platforms need to pass struct
i2c_bus_recovery_info as platform data designware I2C controller.

Signed-off-by: Vincenzo Frascino 
Signed-off-by: Shiraz Hashim 
Signed-off-by: Viresh Kumar 
---
V6->V7:
- removed include/linux/i2c/i2c-designware.h and use struct
  i2c_bus_recovery_info as platform data.
- initialize recover_bus with i2c_generic_gpio_recovery()

 drivers/i2c/busses/i2c-designware-core.c|  6 +-
 drivers/i2c/busses/i2c-designware-platdrv.c | 18 --
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/drivers/i2c/busses/i2c-designware-core.c 
b/drivers/i2c/busses/i2c-designware-core.c
index cbba7db..24feaaf 100644
--- a/drivers/i2c/busses/i2c-designware-core.c
+++ b/drivers/i2c/busses/i2c-designware-core.c
@@ -538,7 +538,11 @@ i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg 
msgs[], int num)
ret = wait_for_completion_interruptible_timeout(&dev->cmd_complete, HZ);
if (ret == 0) {
dev_err(dev->dev, "controller timed out\n");
-   i2c_dw_init(dev);
+   if (adap->bus_recovery_info) {
+   dev_dbg(dev->dev, "try i2c bus recovery\n");
+   adap->bus_recovery_info->recover_bus(adap);
+   }
+
ret = -ETIMEDOUT;
goto done;
} else if (ret < 0)
diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c 
b/drivers/i2c/busses/i2c-designware-platdrv.c
index 0506fef..c7725b2 100644
--- a/drivers/i2c/busses/i2c-designware-platdrv.c
+++ b/drivers/i2c/busses/i2c-designware-platdrv.c
@@ -55,6 +55,7 @@ static int __devinit dw_i2c_probe(struct platform_device 
*pdev)
struct dw_i2c_dev *dev;
struct i2c_adapter *adap;
struct resource *mem, *ioarea;
+   struct i2c_bus_recovery_info *recovery_info;
int irq, r;
 
/* NOTE: driver uses the static register mapping */
@@ -141,17 +142,28 @@ static int __devinit dw_i2c_probe(struct platform_device 
*pdev)
adap->dev.parent = &pdev->dev;
adap->dev.of_node = pdev->dev.of_node;
 
+   /* Bus recovery support */
+   recovery_info = dev_get_platdata(&pdev->dev);
+   if (recovery_info) {
+   recovery_info->recover_bus = i2c_generic_gpio_recovery;
+   recovery_info->clock_rate_khz = clk_get_rate(dev->clk) / 1000;
+   adap->bus_recovery_info = recovery_info;
+   } else {
+   adap->bus_recovery_info = NULL;
+   }
+
adap->nr = pdev->id;
r = i2c_add_numbered_adapter(adap);
if (r) {
dev_err(&pdev->dev, "failure adding adapter\n");
-   goto err_free_irq;
+   goto err_free_recovery_info;
}
of_i2c_register_devices(adap);
 
return 0;
 
-err_free_irq:
+err_free_recovery_info:
+   kfree(recovery_info);
free_irq(dev->irq, dev);
 err_iounmap:
iounmap(dev->base);
@@ -174,6 +186,8 @@ static int __devexit dw_i2c_remove(struct platform_device 
*pdev)
struct dw_i2c_dev *dev = platform_get_drvdata(pdev);
struct resource *mem;
 
+   kfree(dev->adapter.bus_recovery_info);
+
platform_set_drvdata(pdev, NULL);
i2c_del_adapter(&dev->adapter);
put_device(&pdev->dev);
-- 
1.7.12.rc2.18.g61b472e

--
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


[PATCH V7 1/2] i2c/adapter: Add bus recovery infrastructure

2012-11-24 Thread Viresh Kumar
Add i2c bus recovery infrastructure to i2c adapters as specified in the i2c
protocol Rev. 03 section 3.1.16 titled "Bus clear".

http://www.nxp.com/documents/user_manual/UM10204.pdf

Sometimes during operation i2c bus hangs and we need to give dummy clocks to
slave device to start the transfer again. Now we may have capability in the bus
controller to generate these clocks or platform may have gpio pins which can be
toggled to generate dummy clocks. This patch supports both.

This patch also adds in generic bus recovery routines gpio or scl line based
which can be used by bus controller. In addition controller driver may provide
its own version of the bus recovery routine.

This doesn't support multi-master recovery for now.

Signed-off-by: Viresh Kumar 
---

Hi Wolfram,

I am sending V7 before closing our comments completely on V6 (Very few are left
now :) ), so that you can get an idea of what i am implementing now. It
incorporates all your comments leaving:
- removing skip_sda_polling
- removing clock_rate_khz
- calling recover_bus from core instead of controller driver

V6->V7:
- Lots of review comments from Wolfram incorporated
- get[put]_gpio updated to more generic [un]prepare_recovery with return type as
  void.
- prototypes of generic recovery routines are exposed to controller driver and
  they are now required to pass recover_bus()
- gpio flags removed from recovery info
- default clock rate is 100 KHz if not passed by controller driver
- clk count is 9, fixed.

V5->V6:
- Removed sda_gpio_flags
- Make scl_gpio_flags as GPIOF_OPEN_DRAIN | GPIOF_OUT_INIT_HIGH by default
- update bri->set_scl and bri->get_sda for gpio recovery case in i2c core
- Guaranteed to generate 9 falling-rising edges for bus recovery

V4->V5:
- section name corrected to 3.1.16
- merged gpio and non-gpio recovery routines to remove code redundancy
- Changed types of gpio and gpio-flags to unsigned and unsigned long
- Checking return value of get_gpio() now
- using DIV_ROUND_UP for calculating delay, to get more correct value

 drivers/i2c/i2c-core.c | 136 +
 include/linux/i2c.h|  47 +
 2 files changed, 183 insertions(+)

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index a7edf98..d100276 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -27,7 +27,9 @@
 
 #include 
 #include 
+#include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -104,6 +106,106 @@ static int i2c_device_uevent(struct device *dev, struct 
kobj_uevent_env *env)
 #define i2c_device_uevent  NULL
 #endif /* CONFIG_HOTPLUG */
 
+/* i2c bus recovery routines */
+#define RECOVERY_CLK_CNT   9
+#define DEFAULT_CLK_RATE   100 /* KHz */
+
+static void set_scl_gpio_value(struct i2c_adapter *adap, int val)
+{
+   gpio_set_value(adap->bus_recovery_info->scl_gpio, val);
+}
+
+static int get_sda_gpio_value(struct i2c_adapter *adap)
+{
+   return gpio_get_value(adap->bus_recovery_info->sda_gpio);
+}
+
+static int i2c_get_gpios_for_recovery(struct i2c_adapter *adap)
+{
+   struct i2c_bus_recovery_info *bri = adap->bus_recovery_info;
+   struct device *dev = &adap->dev;
+   int ret = 0;
+
+   ret = gpio_request_one(bri->scl_gpio, GPIOF_OPEN_DRAIN |
+   GPIOF_OUT_INIT_HIGH, "i2c-scl");
+   if (ret) {
+   dev_warn(dev, "gpio request fail: %d\n", bri->scl_gpio);
+   return ret;
+   }
+
+   if (!bri->skip_sda_polling) {
+   if (gpio_request_one(bri->sda_gpio, GPIOF_IN, "i2c-sda")) {
+   /* work without sda polling */
+   dev_warn(dev, "can't get sda: %d. Skip sda polling\n",
+   bri->sda_gpio);
+   bri->skip_sda_polling = true;
+   }
+   }
+
+   return ret;
+}
+
+static void i2c_put_gpios_for_recovery(struct i2c_adapter *adap)
+{
+   struct i2c_bus_recovery_info *bri = adap->bus_recovery_info;
+
+   if (!bri->skip_sda_polling)
+   gpio_free(bri->sda_gpio);
+
+   gpio_free(bri->scl_gpio);
+}
+
+static int i2c_generic_recovery(struct i2c_adapter *adap)
+{
+   struct i2c_bus_recovery_info *bri = adap->bus_recovery_info;
+   unsigned long delay = 100; /* 10^6/KHz for delay in ns */
+   int i, val = 0;
+
+   if (bri->prepare_recovery)
+   bri->prepare_recovery(bri);
+
+   /*
+* By this time SCL is high, as we need to give 9 falling-rising edges
+*/
+
+   delay = DIV_ROUND_UP(delay, bri->clock_rate_khz * 2);
+
+   for (i = 0; i < RECOVERY_CLK_CNT * 2; i++, val = !val) {
+   bri->set_scl(adap, val);
+   ndelay(delay);
+
+   /* break if sda got high, check only when scl line is high */
+   if (!bri->skip_sda_polling && val)
+   if (unlikely(bri->get_sda(adap)))
+   break;
+   }

Re: [PATCH V6 2/2] i2c/designware: Provide i2c bus recovery support

2012-11-24 Thread Viresh Kumar
On 25 November 2012 02:33, Wolfram Sang  wrote:
>> diff --git a/drivers/i2c/busses/i2c-designware-core.c 
>> b/drivers/i2c/busses/i2c-designware-core.c

>> @@ -538,7 +538,12 @@ i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg 
>> msgs[], int num)
>>   ret = wait_for_completion_interruptible_timeout(&dev->cmd_complete, 
>> HZ);
>>   if (ret == 0) {
>>   dev_err(dev->dev, "controller timed out\n");
>> - i2c_dw_init(dev);
>> + if (adap->bus_recovery_info &&
>> + adap->bus_recovery_info->recover_bus) {
>> + dev_dbg(dev->dev, "try i2c bus recovery\n");
>> + adap->bus_recovery_info->recover_bus(adap);
>> + }
>> +
>
> This should be in the core?

Because wait_for_completion() would fail in controllers, so i kept this
code here. How will we come to know about xfer failure in core?

Though i realize that check for adap->bus_recovery_info->recover_bus()
is just not required.

>> diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c 
>> b/drivers/i2c/busses/i2c-designware-platdrv.c
>> + /* Bus recovery support */
>> + pdata = dev_get_platdata(&pdev->dev);
>> + if (pdata) {
>> + recovery_info = kzalloc(sizeof(*recovery_info), GFP_KERNEL);
>> + if (!recovery_info) {
>> + adap->bus_recovery_info = NULL;
>> + dev_err(&pdev->dev,
>> + "failure to allocate memory for bus 
>> recovery\n");
>> + goto skip_recovery;
>> + }
>> +
>> + recovery_info->is_gpio_recovery = true;
>> + recovery_info->get_gpio = pdata->get_gpio;
>> + recovery_info->put_gpio = pdata->put_gpio;
>> + recovery_info->scl_gpio = pdata->scl_gpio;
>> + recovery_info->scl_gpio_flags = pdata->scl_gpio_flags;
>> + recovery_info->clock_rate_khz = clk_get_rate(dev->clk) / 1000;
>
> It is probably easier to define the whole bri structure in the platform
> and simply pass it on here? Hmm, now devicetree also comes to my mind.
> Will think about that a little, too, but main implementation should be
> left for someone needing that.

Ok. I didn't went for DT as recovery_info also has some routines, for which
we need special implementation for platforms.

--
viresh
--
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 V6 1/2] i2c/adapter: Add bus recovery infrastructure

2012-11-24 Thread Viresh Kumar
Hi Wolfram,

Thanks for sharing your opinion.

On 25 November 2012 02:29, Wolfram Sang  wrote:
> On Thu, Oct 04, 2012 at 04:34:53PM +0530, Viresh Kumar wrote:

>> diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c

>> +static int i2c_get_gpios_for_recovery(struct i2c_adapter *adap)
>> +{
>> + struct i2c_bus_recovery_info *bri = adap->bus_recovery_info;
>> + struct device *dev = &adap->dev;
>> + int ret = 0;
>> +
>> + if (bri->get_gpio) {
>> + ret = bri->get_gpio(bri->scl_gpio);
>> + if (ret) {
>> + dev_warn(dev, "scl get_gpio: %d\n", bri->scl_gpio);
>
> This warning is probably not very helpful to a user.

This is what i thought about it: This is a platform specific routine and
most probably it will fail the first time this code is ever hit and so a
warning would be very helpful for them.

But, now i think platforms should have these prints in their get_gpio
implementations. And we can make it have return type void.

>> + return ret;
>> + }
>> + }
>> +
>> + ret = gpio_request_one(bri->scl_gpio, bri->scl_gpio_flags, "i2c-scl");
>> + if (ret) {
>> + dev_warn(dev, "gpio request fail: %d\n", bri->scl_gpio);
>> + goto scl_put_gpio;
>> + }
>> +
>> + if (!bri->skip_sda_polling) {
>> + if (bri->get_gpio)
>> + ret = bri->get_gpio(bri->sda_gpio);
>> +
>> + if (unlikely(ret ||
>
> Since the unlikely() are not in hot-paths, you probably better skip
> them.

It will be removed as get_gpio() would have return type void.

>> + gpio_request_one(bri->sda_gpio, GPIOF_IN, "i2c-sda"))) 
>> {
>> + /* work without sda polling */
>> + dev_warn(dev, "can't get sda: %d. Skip sda polling\n",
>> + bri->sda_gpio);
>> + bri->skip_sda_polling = true;
>> + if (!ret && bri->put_gpio)
>> + bri->put_gpio(bri->sda_gpio);
>> +
>> + ret = 0;
>> + }
>> + }
>> +static int i2c_recover_bus(struct i2c_adapter *adap)
>> +{
>> + struct i2c_bus_recovery_info *bri = adap->bus_recovery_info;
>> + unsigned long delay = 100;
>
> What is this magic value?

10 ^ 6 For time conversion to ns. clock duration is given by:
1/ (1000 * KHz) sec = 10^6 /(10^6 * 1000 * KHz) sec = 10^6/KHz nsec

>> +/**
>> + * struct i2c_bus_recovery_info - I2c bus recovery information
>> + * @recover_bus: Recover routine. Either pass driver's recover_bus() 
>> routine, or
>> + *   pass it NULL to use generic ones, i.e. gpio or scl based.
>
> What about having those options?
>
> NULL or custom_pointer or i2c_generic_scl_recovery or 
> i2c_generic_gpio_recovery

Looks good. But NULL should be an error then ?

> where i2c_generic_gpio_recovery is probably:
>
> get_gpios_for_recovery
> i2c_generic_scl_recovery
> put_gpios_for_recovery

Ok.

> and i2c_generic_scl_recovery is basically your current
> i2c_generic_recovery. That makes it easier to add other generic routines
> if that should ever become necessary.

yes, that a good point.

>> + * @skip_sda_polling: if true, bus recovery will not poll sda line to check 
>> if
>> + *   it became high or not. Only required if recover_bus == NULL.
>
> Does a user really need to set this?

This was done for platforms and i2c controllers which don't have configuration
to control scl line. So i still feel we need it.

>> + * @is_gpio_recovery: true, select gpio type else scl type. Only required if
>> + *   recover_bus == NULL.
>
> This could be dropped in favor of i2c_generic_*_recovery in recover_bus

Yes.

>> + * @clock_rate_khz: clock rate of dummy clock in khz. Required for both 
>> gpio and
>> + *   scl type recovery.
>
> Does a user really need this? We could probably use something close to
> 100kHz always?

Not sure. Doesn't it depend on the current clk rate of controller ?
If not then yes it can be 100 KHz

>> + * @clock_cnt: count of max clocks to be generated. Required for both gpio 
>> and
>> + *   scl type recovery.
>
> Don't think this should be something else than 9. If so, it should be
> increased generally in the core and not inside some platform data.

I don't remember well, but somebody pointed it out in earlier version as
they require more of these. But will drop it for now and make it 9.

>> + * @set_scl: controller specific routine, if is_gpio_recovery == false.
>> + *   set_scl_gpio_value otherwise
>> + * @get_sda: controller specific routine, if is_gpio_recovery == false.
>> + *   get_sda_gpio_value otherwise
>
> Basically OK, documentation should be more user-centric not
> implementation centric :)

Yes, i realize it now.

>> + * @get_gpio: called before recover_bus() to get padmux configured for scl 
>> line.
>> + *   as gpio. Only required if is_gpio_recovery == true. Return 0 on 
>> success.
>> 

Re: [PATCH V6 2/2] i2c/designware: Provide i2c bus recovery support

2012-11-24 Thread Wolfram Sang
On Thu, Oct 04, 2012 at 04:34:54PM +0530, Viresh Kumar wrote:
> Add bus recovery support for designware_i2c controller. It uses generic gpio
> based i2c_gpio_recover_bus() routine.
> 
> Signed-off-by: Vincenzo Frascino 
> Signed-off-by: Shiraz Hashim 
> Signed-off-by: Viresh Kumar 
> ---
> V5->V6:
> - removed sda_gpio_flags
> 
>  drivers/i2c/busses/i2c-designware-core.c|  7 -
>  drivers/i2c/busses/i2c-designware-platdrv.c | 38 ++--
>  include/linux/i2c/i2c-designware.h  | 46 
> +
>  3 files changed, 88 insertions(+), 3 deletions(-)
>  create mode 100644 include/linux/i2c/i2c-designware.h
> 
> diff --git a/drivers/i2c/busses/i2c-designware-core.c 
> b/drivers/i2c/busses/i2c-designware-core.c
> index cbba7db..9b7c9bf 100644
> --- a/drivers/i2c/busses/i2c-designware-core.c
> +++ b/drivers/i2c/busses/i2c-designware-core.c
> @@ -538,7 +538,12 @@ i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg 
> msgs[], int num)
>   ret = wait_for_completion_interruptible_timeout(&dev->cmd_complete, HZ);
>   if (ret == 0) {
>   dev_err(dev->dev, "controller timed out\n");
> - i2c_dw_init(dev);
> + if (adap->bus_recovery_info &&
> + adap->bus_recovery_info->recover_bus) {
> + dev_dbg(dev->dev, "try i2c bus recovery\n");
> + adap->bus_recovery_info->recover_bus(adap);
> + }
> +

This should be in the core?

>   ret = -ETIMEDOUT;
>   goto done;
>   } else if (ret < 0)
> diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c 
> b/drivers/i2c/busses/i2c-designware-platdrv.c
> index 0506fef..afa0df9 100644
> --- a/drivers/i2c/busses/i2c-designware-platdrv.c
> +++ b/drivers/i2c/busses/i2c-designware-platdrv.c
> @@ -29,6 +29,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -45,6 +46,7 @@ static struct i2c_algorithm i2c_dw_algo = {
>   .master_xfer= i2c_dw_xfer,
>   .functionality  = i2c_dw_func,
>  };
> +
>  static u32 i2c_dw_get_clk_rate_khz(struct dw_i2c_dev *dev)
>  {
>   return clk_get_rate(dev->clk)/1000;
> @@ -55,6 +57,8 @@ static int __devinit dw_i2c_probe(struct platform_device 
> *pdev)
>   struct dw_i2c_dev *dev;
>   struct i2c_adapter *adap;
>   struct resource *mem, *ioarea;
> + struct i2c_dw_pdata *pdata;
> + struct i2c_bus_recovery_info *recovery_info = NULL;
>   int irq, r;
>  
>   /* NOTE: driver uses the static register mapping */
> @@ -141,17 +145,45 @@ static int __devinit dw_i2c_probe(struct 
> platform_device *pdev)
>   adap->dev.parent = &pdev->dev;
>   adap->dev.of_node = pdev->dev.of_node;
>  
> + /* Bus recovery support */
> + pdata = dev_get_platdata(&pdev->dev);
> + if (pdata) {
> + recovery_info = kzalloc(sizeof(*recovery_info), GFP_KERNEL);
> + if (!recovery_info) {
> + adap->bus_recovery_info = NULL;
> + dev_err(&pdev->dev,
> + "failure to allocate memory for bus 
> recovery\n");
> + goto skip_recovery;
> + }
> +
> + recovery_info->is_gpio_recovery = true;
> + recovery_info->get_gpio = pdata->get_gpio;
> + recovery_info->put_gpio = pdata->put_gpio;
> + recovery_info->scl_gpio = pdata->scl_gpio;
> + recovery_info->scl_gpio_flags = pdata->scl_gpio_flags;
> + recovery_info->clock_rate_khz = clk_get_rate(dev->clk) / 1000;

It is probably easier to define the whole bri structure in the platform
and simply pass it on here? Hmm, now devicetree also comes to my mind.
Will think about that a little, too, but main implementation should be
left for someone needing that.

> +
> + if (!pdata->skip_sda_polling)
> + recovery_info->sda_gpio = pdata->sda_gpio;
> +
> + adap->bus_recovery_info = recovery_info;
> + } else {
> + adap->bus_recovery_info = NULL;
> + }
> +
> +skip_recovery:
>   adap->nr = pdev->id;
>   r = i2c_add_numbered_adapter(adap);
>   if (r) {
>   dev_err(&pdev->dev, "failure adding adapter\n");
> - goto err_free_irq;
> + goto err_free_recovery_info;
>   }
>   of_i2c_register_devices(adap);
>  
>   return 0;
>  
> -err_free_irq:
> +err_free_recovery_info:
> + kfree(recovery_info);
>   free_irq(dev->irq, dev);
>  err_iounmap:
>   iounmap(dev->base);
> @@ -174,6 +206,8 @@ static int __devexit dw_i2c_remove(struct platform_device 
> *pdev)
>   struct dw_i2c_dev *dev = platform_get_drvdata(pdev);
>   struct resource *mem;
>  
> + kfree(dev->adapter.bus_recovery_info);
> +
>   platform_set_drvdata(pdev, NULL);
>   i2c_del_adapter(&dev->adapter);
>   put_device(&pdev->dev);
> diff --git a/include/linux/i2c/i2c-designware.h 
> b/in

Re: [PATCH V6 1/2] i2c/adapter: Add bus recovery infrastructure

2012-11-24 Thread Wolfram Sang
On Thu, Oct 04, 2012 at 04:34:53PM +0530, Viresh Kumar wrote:
> Add i2c bus recovery infrastructure to i2c adapters as specified in the i2c
> protocol Rev. 03 section 3.1.16 titled "Bus clear".
> 
> http://www.nxp.com/documents/user_manual/UM10204.pdf
> 
> Sometimes during operation i2c bus hangs and we need to give dummy clocks to
> slave device to start the transfer again. Now we may have capability in the 
> bus
> controller to generate these clocks or platform may have gpio pins which can 
> be
> toggled to generate dummy clocks. This patch supports both.
> 
> This patch also adds in generic bus recovery routines gpio or scl line based
> which can be used by bus controller. In addition controller driver may provide
> its own version of the bus recovery routine.
> 
> This doesn't support multi-master recovery for now.
> 
> Signed-off-by: Viresh Kumar 

As mentioned before, I still have issues with the API and have most
comments to that for now.

> ---
> V5->V6:
> - Removed sda_gpio_flags
> - Make scl_gpio_flags as GPIOF_OPEN_DRAIN | GPIOF_OUT_INIT_HIGH by default
> - update bri->set_scl and bri->get_sda for gpio recovery case in i2c core
> - Guaranteed to generate 9 falling-rising edges for bus recovery
> 
> V4->V5:
> - section name corrected to 3.1.16
> - merged gpio and non-gpio recovery routines to remove code redundancy
> - Changed types of gpio and gpio-flags to unsigned and unsigned long
> - Checking return value of get_gpio() now
> - using DIV_ROUND_UP for calculating delay, to get more correct value
> 
>  drivers/i2c/i2c-core.c | 156 
> +
>  include/linux/i2c.h|  55 +
>  2 files changed, 211 insertions(+)
> 
> diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
> index a7edf98..e78033b 100644
> --- a/drivers/i2c/i2c-core.c
> +++ b/drivers/i2c/i2c-core.c
> @@ -27,7 +27,9 @@
>  
>  #include 
>  #include 
> +#include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -104,6 +106,111 @@ static int i2c_device_uevent(struct device *dev, struct 
> kobj_uevent_env *env)
>  #define i2c_device_ueventNULL
>  #endif   /* CONFIG_HOTPLUG */
>  
> +/* i2c bus recovery routines */
> +static void set_scl_gpio_value(struct i2c_adapter *adap, int val)
> +{
> + gpio_set_value(adap->bus_recovery_info->scl_gpio, val);
> +}
> +
> +static int get_sda_gpio_value(struct i2c_adapter *adap)
> +{
> + return gpio_get_value(adap->bus_recovery_info->sda_gpio);
> +}
> +
> +static int i2c_get_gpios_for_recovery(struct i2c_adapter *adap)
> +{
> + struct i2c_bus_recovery_info *bri = adap->bus_recovery_info;
> + struct device *dev = &adap->dev;
> + int ret = 0;
> +
> + if (bri->get_gpio) {
> + ret = bri->get_gpio(bri->scl_gpio);
> + if (ret) {
> + dev_warn(dev, "scl get_gpio: %d\n", bri->scl_gpio);

This warning is probably not very helpful to a user.

> + return ret;
> + }
> + }
> +
> + ret = gpio_request_one(bri->scl_gpio, bri->scl_gpio_flags, "i2c-scl");
> + if (ret) {
> + dev_warn(dev, "gpio request fail: %d\n", bri->scl_gpio);
> + goto scl_put_gpio;
> + }
> +
> + if (!bri->skip_sda_polling) {
> + if (bri->get_gpio)
> + ret = bri->get_gpio(bri->sda_gpio);
> +
> + if (unlikely(ret ||

Since the unlikely() are not in hot-paths, you probably better skip
them.

> + gpio_request_one(bri->sda_gpio, GPIOF_IN, "i2c-sda"))) {
> + /* work without sda polling */
> + dev_warn(dev, "can't get sda: %d. Skip sda polling\n",
> + bri->sda_gpio);
> + bri->skip_sda_polling = true;
> + if (!ret && bri->put_gpio)
> + bri->put_gpio(bri->sda_gpio);
> +
> + ret = 0;
> + }
> + }
> +
> +scl_put_gpio:
> + if (bri->put_gpio)
> + bri->put_gpio(bri->scl_gpio);
> +
> + return ret;
> +}
> +
> +static void i2c_put_gpios_for_recovery(struct i2c_adapter *adap)
> +{
> + struct i2c_bus_recovery_info *bri = adap->bus_recovery_info;
> +
> + gpio_free(bri->scl_gpio);
> +
> + if (!bri->skip_sda_polling) {
> + gpio_free(bri->sda_gpio);
> +
> + if (bri->put_gpio)
> + bri->put_gpio(bri->sda_gpio);
> + }
> +}
> +
> +static int i2c_recover_bus(struct i2c_adapter *adap)
> +{
> + struct i2c_bus_recovery_info *bri = adap->bus_recovery_info;
> + unsigned long delay = 100;

What is this magic value?

> + int i, ret, val = 0;
> +
> + if (bri->is_gpio_recovery) {
> + ret = i2c_get_gpios_for_recovery(adap);
> + if (ret)
> + return ret;
> + } else {
> + bri->set_scl(adap, 1);
> + }
> +
> + /*
> +  * By this time SCL is high, as w

Re: [RESEND PATCH v3 0/3] i2c: at91: add dma support

2012-11-24 Thread Wolfram Sang
On Fri, Nov 23, 2012 at 10:09:01AM +0100, ludovic.desroc...@atmel.com wrote:
> From: Ludovic Desroches 
> 
> Hi Wolfram,
> 
> I've rebased the set of patches on 3.7-rc6. I hope you could apply them.

Yes, applied to for-next, thanks!

-- 
Pengutronix e.K.   | Wolfram Sang|
Industrial Linux Solutions | http://www.pengutronix.de/  |


signature.asc
Description: Digital signature


Re: [PATCH 13/24] MAINTAINERS: fix drivers/i2c/busses/i2c-stub.c

2012-11-24 Thread Jean Delvare
Hi Cesar,

On Fri, 23 Nov 2012 22:26:37 -0200, Cesar Eduardo Barros wrote:
> This file was moved to drivers/i2c/i2c-stub.c by commit 31d178b
> (i2c-stub: Move to drivers/i2c).
> 
> Cc: Jean Delvare 
> Cc: "Mark M. Hoffman" 
> Cc: linux-i2c@vger.kernel.org
> Signed-off-by: Cesar Eduardo Barros 
> ---
>  MAINTAINERS | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 91feba2..eaf1a59 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -3667,7 +3667,7 @@ I2C/SMBUS STUB DRIVER
>  M:   "Mark M. Hoffman" 
>  L:   linux-i2c@vger.kernel.org
>  S:   Maintained
> -F:   drivers/i2c/busses/i2c-stub.c
> +F:   drivers/i2c/i2c-stub.c

Right. I thought I had fixed it meanwhile, but either I forgot or it
got lost along the way. Applied, thanks.

BTW, Mark has been away from linux kernel development for years now and
he did even not reply to my latest e-mail, so maybe it would be better
to drop his entries from MAINTAINERS altogether. Mark, please speak up.

-- 
Jean Delvare
--
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