[PATCHv3 1/2] i2c: cadence: Move to sensible power management

2015-11-23 Thread Shubhrajyoti Datta
Currently the clocks are enabled at probe and disabled at remove.
Which keeps the clocks enabled even if no transaction is going on.
This patch enables the clocks at the start of transfer and disables
after it.

Also adapts to runtime pm.

converts dev pm to const to silence a checkpatch warning.

Signed-off-by: Shubhrajyoti Datta 
---
v2: update the cc list
v3: split the runtime and the suspended flag change

 drivers/i2c/busses/i2c-cadence.c |   66 ++
 1 files changed, 45 insertions(+), 21 deletions(-)

diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c
index 84deed6..d54ad46 100644
--- a/drivers/i2c/busses/i2c-cadence.c
+++ b/drivers/i2c/busses/i2c-cadence.c
@@ -18,6 +18,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /* Register offsets for the I2C device. */
 #define CDNS_I2C_CR_OFFSET 0x00 /* Control Register, RW */
@@ -96,6 +97,8 @@
 CDNS_I2C_IXR_COMP)
 
 #define CDNS_I2C_TIMEOUT   msecs_to_jiffies(1000)
+/* timeout for pm runtime autosuspend */
+#define CNDS_I2C_PM_TIMEOUT1000/* ms */
 
 #define CDNS_I2C_FIFO_DEPTH16
 /* FIFO depth at which the DATA interrupt occurs */
@@ -141,6 +144,7 @@
  * @quirks:flag for broken hold bit usage in r1p10
  */
 struct cdns_i2c {
+   struct device   *dev;
void __iomem *membase;
struct i2c_adapter adap;
struct i2c_msg *p_msg;
@@ -569,9 +573,14 @@ static int cdns_i2c_master_xfer(struct i2c_adapter *adap, 
struct i2c_msg *msgs,
struct cdns_i2c *id = adap->algo_data;
bool hold_quirk;
 
+   ret = pm_runtime_get_sync(id->dev);
+   if (ret < 0)
+   return ret;
/* Check if the bus is free */
-   if (cdns_i2c_readreg(CDNS_I2C_SR_OFFSET) & CDNS_I2C_SR_BA)
-   return -EAGAIN;
+   if (cdns_i2c_readreg(CDNS_I2C_SR_OFFSET) & CDNS_I2C_SR_BA) {
+   ret = -EAGAIN;
+   goto out;
+   }
 
hold_quirk = !!(id->quirks & CDNS_I2C_BROKEN_HOLD_BIT);
/*
@@ -590,7 +599,8 @@ static int cdns_i2c_master_xfer(struct i2c_adapter *adap, 
struct i2c_msg *msgs,
if (msgs[count].flags & I2C_M_RD) {
dev_warn(adap->dev.parent,
 "Can't do repeated start after a 
receive message\n");
-   return -EOPNOTSUPP;
+   ret = -EOPNOTSUPP;
+   goto out;
}
}
id->bus_hold_flag = 1;
@@ -608,20 +618,26 @@ static int cdns_i2c_master_xfer(struct i2c_adapter *adap, 
struct i2c_msg *msgs,
 
ret = cdns_i2c_process_msg(id, msgs, adap);
if (ret)
-   return ret;
+   goto out;
 
/* Report the other error interrupts to application */
if (id->err_status) {
cdns_i2c_master_reset(adap);
 
-   if (id->err_status & CDNS_I2C_IXR_NACK)
-   return -ENXIO;
-
-   return -EIO;
+   if (id->err_status & CDNS_I2C_IXR_NACK) {
+   ret = -ENXIO;
+   goto out;
+   }
+   ret = -EIO;
+   goto out;
}
}
 
-   return num;
+   ret = num;
+out:
+   pm_runtime_mark_last_busy(id->dev);
+   pm_runtime_put_autosuspend(id->dev);
+   return ret;
 }
 
 /**
@@ -808,10 +824,9 @@ static int cdns_i2c_clk_notifier_cb(struct notifier_block 
*nb, unsigned long
  *
  * Return: 0 always
  */
-static int __maybe_unused cdns_i2c_suspend(struct device *_dev)
+static int __maybe_unused cdns_i2c_runtime_suspend(struct device *dev)
 {
-   struct platform_device *pdev = container_of(_dev,
-   struct platform_device, dev);
+   struct platform_device *pdev = to_platform_device(dev);
struct cdns_i2c *xi2c = platform_get_drvdata(pdev);
 
clk_disable(xi2c->clk);
@@ -828,16 +843,15 @@ static int __maybe_unused cdns_i2c_suspend(struct device 
*_dev)
  *
  * Return: 0 on success and error value on error
  */
-static int __maybe_unused cdns_i2c_resume(struct device *_dev)
+static int __maybe_unused cdns_i2c_runtime_resume(struct device *dev)
 {
-   struct platform_device *pdev = container_of(_dev,
-   struct platform_device, dev);
+   struct platform_device *pdev = to_platform_device(dev);
struct cdns_i2c *xi2c = platform_get_drvdata(pdev);
int ret;
 
ret = clk_enable(xi2c->clk);
if (ret) {
-   dev_err(_dev, "Cannot enable clock.\n");
+   dev_err(dev, "Cannot enable clock.\n");
return ret;
}
 
@@ -846,8 +860,10 @@ static int

[PATCHv3 2/2] i2c: cadence: Remove the suspended flag

2015-11-23 Thread Shubhrajyoti Datta
The suspended flag is a flag holding the device's PM status.
The runtime framework does that for us.
Use pm_runtime_suspended call instead.

Signed-off-by: Shubhrajyoti Datta 
---
v3: split the patches

 drivers/i2c/busses/i2c-cadence.c |7 +--
 1 files changed, 1 insertions(+), 6 deletions(-)

diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c
index d54ad46..6b08d16 100644
--- a/drivers/i2c/busses/i2c-cadence.c
+++ b/drivers/i2c/busses/i2c-cadence.c
@@ -131,7 +131,6 @@
  * @xfer_done: Transfer complete status
  * @p_send_buf:Pointer to transmit buffer
  * @p_recv_buf:Pointer to receive buffer
- * @suspended: Flag holding the device's PM status
  * @send_count:Number of bytes still expected to send
  * @recv_count:Number of bytes still expected to receive
  * @curr_recv_count:   Number of bytes to be received in current transfer
@@ -152,7 +151,6 @@ struct cdns_i2c {
struct completion xfer_done;
unsigned char *p_send_buf;
unsigned char *p_recv_buf;
-   u8 suspended;
unsigned int send_count;
unsigned int recv_count;
unsigned int curr_recv_count;
@@ -776,7 +774,7 @@ static int cdns_i2c_clk_notifier_cb(struct notifier_block 
*nb, unsigned long
struct clk_notifier_data *ndata = data;
struct cdns_i2c *id = to_cdns_i2c(nb);
 
-   if (id->suspended)
+   if (pm_runtime_suspended(id->dev))
return NOTIFY_OK;
 
switch (event) {
@@ -830,7 +828,6 @@ static int __maybe_unused cdns_i2c_runtime_suspend(struct 
device *dev)
struct cdns_i2c *xi2c = platform_get_drvdata(pdev);
 
clk_disable(xi2c->clk);
-   xi2c->suspended = 1;
 
return 0;
 }
@@ -855,8 +852,6 @@ static int __maybe_unused cdns_i2c_runtime_resume(struct 
device *dev)
return ret;
}
 
-   xi2c->suspended = 0;
-
return 0;
 }
 
-- 
1.7.1

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


[PATCHv3 1/2] i2c: cadence: Move to sensible power management

2015-11-23 Thread Shubhrajyoti Datta
Currently the clocks are enabled at probe and disabled at remove.
Which keeps the clocks enabled even if no transaction is going on.
This patch enables the clocks at the start of transfer and disables
after it.

Also adapts to runtime pm.

converts dev pm to const to silence a checkpatch warning.

Signed-off-by: Shubhrajyoti Datta 
---
v2: update the cc list
v3: split the runtime and the suspended flag change

 drivers/i2c/busses/i2c-cadence.c |   66 ++
 1 files changed, 45 insertions(+), 21 deletions(-)

diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c
index 84deed6..d54ad46 100644
--- a/drivers/i2c/busses/i2c-cadence.c
+++ b/drivers/i2c/busses/i2c-cadence.c
@@ -18,6 +18,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /* Register offsets for the I2C device. */
 #define CDNS_I2C_CR_OFFSET 0x00 /* Control Register, RW */
@@ -96,6 +97,8 @@
 CDNS_I2C_IXR_COMP)
 
 #define CDNS_I2C_TIMEOUT   msecs_to_jiffies(1000)
+/* timeout for pm runtime autosuspend */
+#define CNDS_I2C_PM_TIMEOUT1000/* ms */
 
 #define CDNS_I2C_FIFO_DEPTH16
 /* FIFO depth at which the DATA interrupt occurs */
@@ -141,6 +144,7 @@
  * @quirks:flag for broken hold bit usage in r1p10
  */
 struct cdns_i2c {
+   struct device   *dev;
void __iomem *membase;
struct i2c_adapter adap;
struct i2c_msg *p_msg;
@@ -569,9 +573,14 @@ static int cdns_i2c_master_xfer(struct i2c_adapter *adap, 
struct i2c_msg *msgs,
struct cdns_i2c *id = adap->algo_data;
bool hold_quirk;
 
+   ret = pm_runtime_get_sync(id->dev);
+   if (ret < 0)
+   return ret;
/* Check if the bus is free */
-   if (cdns_i2c_readreg(CDNS_I2C_SR_OFFSET) & CDNS_I2C_SR_BA)
-   return -EAGAIN;
+   if (cdns_i2c_readreg(CDNS_I2C_SR_OFFSET) & CDNS_I2C_SR_BA) {
+   ret = -EAGAIN;
+   goto out;
+   }
 
hold_quirk = !!(id->quirks & CDNS_I2C_BROKEN_HOLD_BIT);
/*
@@ -590,7 +599,8 @@ static int cdns_i2c_master_xfer(struct i2c_adapter *adap, 
struct i2c_msg *msgs,
if (msgs[count].flags & I2C_M_RD) {
dev_warn(adap->dev.parent,
 "Can't do repeated start after a 
receive message\n");
-   return -EOPNOTSUPP;
+   ret = -EOPNOTSUPP;
+   goto out;
}
}
id->bus_hold_flag = 1;
@@ -608,20 +618,26 @@ static int cdns_i2c_master_xfer(struct i2c_adapter *adap, 
struct i2c_msg *msgs,
 
ret = cdns_i2c_process_msg(id, msgs, adap);
if (ret)
-   return ret;
+   goto out;
 
/* Report the other error interrupts to application */
if (id->err_status) {
cdns_i2c_master_reset(adap);
 
-   if (id->err_status & CDNS_I2C_IXR_NACK)
-   return -ENXIO;
-
-   return -EIO;
+   if (id->err_status & CDNS_I2C_IXR_NACK) {
+   ret = -ENXIO;
+   goto out;
+   }
+   ret = -EIO;
+   goto out;
}
}
 
-   return num;
+   ret = num;
+out:
+   pm_runtime_mark_last_busy(id->dev);
+   pm_runtime_put_autosuspend(id->dev);
+   return ret;
 }
 
 /**
@@ -808,10 +824,9 @@ static int cdns_i2c_clk_notifier_cb(struct notifier_block 
*nb, unsigned long
  *
  * Return: 0 always
  */
-static int __maybe_unused cdns_i2c_suspend(struct device *_dev)
+static int __maybe_unused cdns_i2c_runtime_suspend(struct device *dev)
 {
-   struct platform_device *pdev = container_of(_dev,
-   struct platform_device, dev);
+   struct platform_device *pdev = to_platform_device(dev);
struct cdns_i2c *xi2c = platform_get_drvdata(pdev);
 
clk_disable(xi2c->clk);
@@ -828,16 +843,15 @@ static int __maybe_unused cdns_i2c_suspend(struct device 
*_dev)
  *
  * Return: 0 on success and error value on error
  */
-static int __maybe_unused cdns_i2c_resume(struct device *_dev)
+static int __maybe_unused cdns_i2c_runtime_resume(struct device *dev)
 {
-   struct platform_device *pdev = container_of(_dev,
-   struct platform_device, dev);
+   struct platform_device *pdev = to_platform_device(dev);
struct cdns_i2c *xi2c = platform_get_drvdata(pdev);
int ret;
 
ret = clk_enable(xi2c->clk);
if (ret) {
-   dev_err(_dev, "Cannot enable clock.\n");
+   dev_err(dev, "Cannot enable clock.\n");
return ret;
}
 
@@ -846,8 +860,10 @@ static int

[PATCH v4] i2c: taos-evm: replace simple_strtoul by kstrtou8

2015-11-23 Thread LABBE Corentin
The simple_strtoul function is marked as obsolete.
This patch replace it by kstrtou8.

Reviewed-by: Jean Delvare 
Tested-by: Jean Delvare 
Signed-off-by: LABBE Corentin 
---
 drivers/i2c/busses/i2c-taos-evm.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-taos-evm.c 
b/drivers/i2c/busses/i2c-taos-evm.c
index 4c7fc2d..210ca82 100644
--- a/drivers/i2c/busses/i2c-taos-evm.c
+++ b/drivers/i2c/busses/i2c-taos-evm.c
@@ -130,7 +130,13 @@ static int taos_smbus_xfer(struct i2c_adapter *adapter, 
u16 addr,
return 0;
} else {
if (p[0] == 'x') {
-   data->byte = simple_strtol(p + 1, NULL, 16);
+   /*
+* Voluntarily dropping error code of kstrtou8 since all
+* error code that it could return are invalid according
+* to Documentation/i2c/fault-codes.
+*/
+   if (kstrtou8(p + 1, 16, &data->byte))
+   return -EPROTO;
return 0;
}
}
-- 
2.4.10

--
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 v4] i2c: taos-evm: replace simple_strtoul by kstrto

2015-11-23 Thread LABBE Corentin
Hello

Change since v3
- Added reviewed-by and tested-by
- Fix Capital letter and missing dot in the comment.

Changes since v2
- removed err variable
- fix a spelling issue

Changes since v1
- drop the return code of kstrtou8 and return -EPROTO
  as suggested by Jean Delvare
- Added a comment on the return code drop

Regards

LABBE Corentin (1):
  i2c: taos-evm: replace simple_strtoul by kstrtou8

 drivers/i2c/busses/i2c-taos-evm.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

-- 
2.4.10

--
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 v2] i2c: cadence: Move to sensible power management

2015-11-23 Thread Shubhrajyoti Datta
On Tue, Nov 24, 2015 at 12:17 AM, Sören Brinkmann
 wrote:
> On Sat, 2015-11-21 at 07:00PM +0530, Shubhrajyoti Datta wrote:
>> On Thu, Oct 29, 2015 at 8:27 PM, Shubhrajyoti Datta
>>  wrote:
>> > On Wed, Oct 28, 2015 at 9:48 PM, Sören Brinkmann
>> >  wrote:
>> >> Hi Shubhrajyoti,
>> >>
>> >>
>> >> On Wed, 2015-10-28 at 12:56PM +0530, Shubhrajyoti Datta wrote:
>> >>> Currently the clocks are enabled at probe and disabled at remove.
>> >>> Which keeps the clocks enabled even if no transaction is going on.
>> >>> This patch enables the clocks at the start of transfer and disables
>> >>> after it.
>> >>>
>> >>> Also adapts to runtime pm.
>> >>> Remove xi2c->suspended and use pm runtime status instead.
>> >>>
>> >>> converts dev pm to const to silence a checkpatch warning.
>> >>>
>> >>> Signed-off-by: Shubhrajyoti Datta 
>> >>
>> >> To me, this looks all good. Just one small concern below.
>> >
>> > Thanks for the review.
>> Soren ,
>> Do are you ok with the change or do you want me to resend without the
>> suspended flag change.
>
> I'm always for removing code that is not needed. If things are tested
> and well and work without throwing any warnings I'm OK with it.

It should be also having a suspended book-keeping in the driver is not
needed the pm does that for us.

I will spilt the patch and resend.

Thanks,

>
> Sören
--
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 v2] i2c: cadence: Move to sensible power management

2015-11-23 Thread Sören Brinkmann
On Sat, 2015-11-21 at 07:00PM +0530, Shubhrajyoti Datta wrote:
> On Thu, Oct 29, 2015 at 8:27 PM, Shubhrajyoti Datta
>  wrote:
> > On Wed, Oct 28, 2015 at 9:48 PM, Sören Brinkmann
> >  wrote:
> >> Hi Shubhrajyoti,
> >>
> >>
> >> On Wed, 2015-10-28 at 12:56PM +0530, Shubhrajyoti Datta wrote:
> >>> Currently the clocks are enabled at probe and disabled at remove.
> >>> Which keeps the clocks enabled even if no transaction is going on.
> >>> This patch enables the clocks at the start of transfer and disables
> >>> after it.
> >>>
> >>> Also adapts to runtime pm.
> >>> Remove xi2c->suspended and use pm runtime status instead.
> >>>
> >>> converts dev pm to const to silence a checkpatch warning.
> >>>
> >>> Signed-off-by: Shubhrajyoti Datta 
> >>
> >> To me, this looks all good. Just one small concern below.
> >
> > Thanks for the review.
> Soren ,
> Do are you ok with the change or do you want me to resend without the
> suspended flag change.

I'm always for removing code that is not needed. If things are tested
and well and work without throwing any warnings I'm OK with it.

Sören
--
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: i2c slave support für i.mx6

2015-11-23 Thread Michael Bachmeier
Hi,

Is the recognition of IAAS a hardware interrupt (according to manual,
yes)? I set IEN (I2C enable) and IIEN (Interrupt Enable).
I set the slave address to 0x1c (chosen at random). The IMX bus driver
is unchanged. With my external Master I ask for the address on the
bus. But the IAAS bit is never set.
In this test, I want to see if the hardware interrupt work.
Should i modified the bus driver (IRQ handler???) or is this a real
hardware interrupt?

Where is my misconception?

Best regards

2015-11-18 12:11 GMT+01:00 Wolfram Sang :
> Hi,
>
>> thanks to your comments in the rcar driver, I understand the function
>> of each register. But I'd like a manual of this board. Where is
>> accurately entered into the individual registers.
>
> As far as I know, there is no public user manual for RCar SoCs. I can
> ask, though.
>
>> Had someone for me a manual by the individual registers are explained.
>> So that I can understand the rcar driver better.
>
> However, if you have a specific question, you could ask and I could try
> improving the driver's documentation :)
>
> Regards,
>
>Wolfram
>
--
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