Skip to contentSkip to conversation

i2c-pnx: Improvements and fixes

PATCH In review [email protected] 2 participants 8 messages Mar 16, 2010 – Apr 5, 2010 3 messages not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

This patch set fixes a stop condition issue with transfers, caps the maximum computed divider generated from the parent clock, and disables the I2C peripheral clock when the I2C bus isn't in use (to save power).

Patch 3 was previously posted a few months ago, but I didn't follow up on getting it into the driver.

All code is tested on the lpc3250.

A message that is not in the archive (sent off-list or not yet received): 1268780138-10019-1-git-send-email-wellsk40-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#2 lore raw

PATCH 1/3 i2c-pnx: Limit maximum divider to 1023

From: Kevin Wells <[email protected]>

Limit maximum divider to 0x3ff on divider computations. On high I2C parent clock rates, the divider can exceed 0x3ff. This will help prevent some very odd clock rates.

---
 drivers/i2c/busses/i2c-pnx.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
drivers/i2c/busses/i2c-pnx.c +2 -0
index 9532dee..77919fa 100644
@@ -632,6 +632,8 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev)
 	 */
 
 	tmp = ((freq / 1000) / I2C_PNX_SPEED_KHZ) / 2 - 2;
+	if (tmp > 0x3FF)
+		tmp = 0x3FF;
 	iowrite32(tmp, I2C_REG_CKH(alg_data));
 	iowrite32(tmp, I2C_REG_CKL(alg_data));
 
Signature · 1 line
1.6.6
#3 lore raw

PATCH 1/3 i2c-pnx: Limit maximum divider to 1023

In reply to a message not in the archive

From: Kevin Wells <[email protected]>

Limit maximum divider to 0x3ff to divider computations. On high I2C parent clock rates, the divider can exceed 0x3ff. This will help prevent some very odd clock rates.

---
 drivers/i2c/busses/i2c-pnx.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
drivers/i2c/busses/i2c-pnx.c +2 -0
index 9532dee..77919fa 100644
@@ -632,6 +632,8 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev)
 	 */
 
 	tmp = ((freq / 1000) / I2C_PNX_SPEED_KHZ) / 2 - 2;
+	if (tmp > 0x3FF)
+		tmp = 0x3FF;
 	iowrite32(tmp, I2C_REG_CKH(alg_data));
 	iowrite32(tmp, I2C_REG_CKL(alg_data));
 
Signature · 1 line
1.6.6
#4 lore raw

PATCH 2/3 i2c-pnx: Add stop conditions for end of transfer

In reply to a message not in the archive

From: Kevin Wells <[email protected]>

Add a stop condition bit flag to the last byte in the transfer. This will generate an extra clock to handle the stop condition and prevent devices from staying in an ACK'd state.

---
 drivers/i2c/busses/i2c-pnx.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
drivers/i2c/busses/i2c-pnx.c +6 -0
index 77919fa..6bb6ff7 100644
@@ -172,6 +172,9 @@ static int i2c_pnx_master_xmit(struct i2c_pnx_algo_data *alg_data)
 		/* We still have something to talk about... */
 		val = *alg_data->mif.buf++;
 
+		if (alg_data->mif.len == 1)
+			val |= stop_bit;
+
 		alg_data->mif.len--;
 		iowrite32(val, I2C_REG_TX(alg_data));
 
@@ -245,6 +248,9 @@ static int i2c_pnx_master_rcv(struct i2c_pnx_algo_data *alg_data)
 			__func__);
 
 		if (alg_data->mif.len == 1) {
+			/* Last byte, do not acknowledge next rcv. */
+			val |= stop_bit;
+
 			/*
 			 * Enable interrupt RFDAIE (data in Rx fifo),
 			 * and disable DRMIE (need data for Tx)
Signature · 1 line
1.6.6
#5 lore raw

PATCH 3/3 i2c-pnx: Disable/enable clocks only when needed to reduce power

In reply to a message not in the archive

From: Kevin Wells <[email protected]>

Enable I2C peripheral clocking at the start of a transfer and disable on transfer completion to reduce peripheral power use when bus is not in use.

---
 drivers/i2c/busses/i2c-pnx.c |   33 +++++++--------------------------
 1 files changed, 7 insertions(+), 26 deletions(-)
drivers/i2c/busses/i2c-pnx.c +7 -26
index 6bb6ff7..23bd556 100644
@@ -448,6 +448,8 @@ i2c_pnx_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
 		"%s(): entering: %d messages, stat = %04x.\n",
 		__func__, num, ioread32(I2C_REG_STS(alg_data)));
 
+	clk_enable(alg_data->clk);
+
 	bus_reset_if_active(alg_data);
 
 	/* Process transactions in a loop. */
@@ -516,6 +518,8 @@ i2c_pnx_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
 
 	bus_reset_if_active(alg_data);
 
+	clk_disable(alg_data->clk);
+
 	/* Cleanup to be sure... */
 	alg_data->mif.buf = NULL;
 	alg_data->mif.len = 0;
@@ -539,29 +543,6 @@ static struct i2c_algorithm pnx_algorithm = {
 	.functionality = i2c_pnx_func,
 };
 
-#ifdef CONFIG_PM
-static int i2c_pnx_controller_suspend(struct platform_device *pdev,
-				      pm_message_t state)
-{
-	struct i2c_pnx_algo_data *alg_data = platform_get_drvdata(pdev);
-
-	/* FIXME: shouldn't this be clk_disable? */
-	clk_enable(alg_data->clk);
-
-	return 0;
-}
-
-static int i2c_pnx_controller_resume(struct platform_device *pdev)
-{
-	struct i2c_pnx_algo_data *alg_data = platform_get_drvdata(pdev);
-
-	return clk_enable(alg_data->clk);
-}
-#else
-#define i2c_pnx_controller_suspend	NULL
-#define i2c_pnx_controller_resume	NULL
-#endif
-
 static int __devinit i2c_pnx_probe(struct platform_device *pdev)
 {
 	unsigned long tmp;
@@ -665,6 +646,9 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev)
 	dev_dbg(&pdev->dev, "%s: Master at %#8x, irq %d.\n",
 	       alg_data->adapter.name, i2c_pnx->base, i2c_pnx->irq);
 
+	/* Disable clock until needed */
+	clk_disable(alg_data->clk);
+
 	return 0;
 
 out_irq:
@@ -692,7 +676,6 @@ static int __devexit i2c_pnx_remove(struct platform_device *pdev)
 
 	free_irq(i2c_pnx->irq, alg_data);
 	i2c_del_adapter(&alg_data->adapter);
-	clk_disable(alg_data->clk);
 	iounmap(alg_data->ioaddr);
 	release_mem_region(i2c_pnx->base, I2C_PNX_REGION_SIZE);
 	clk_put(alg_data->clk);
@@ -709,8 +692,6 @@ static struct platform_driver i2c_pnx_driver = {
 	},
 	.probe = i2c_pnx_probe,
 	.remove = __devexit_p(i2c_pnx_remove),
-	.suspend = i2c_pnx_controller_suspend,
-	.resume = i2c_pnx_controller_resume,
 };
 
 static int __init i2c_adap_pnx_init(void)
Signature · 1 line
1.6.6

A message that is not in the archive (sent off-list or not yet received): 1268780138-10019-5-git-send-email-wellsk40-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#7 lore raw

Re: [PATCH 3/3] i2c-pnx: Disable/enable clocks only when needed to reduce power

Quoted 5 lines · On Tue, Mar 16, 2010 at 03:55:38PM -0700…

From: Kevin Wells <[email protected]>

Enable I2C peripheral clocking at the start of a transfer and disable on transfer completion to reduce peripheral power use when bus is not in use.

I'm going to leave this one for -next as it isn't really a bugfix.

Quoted 91 lines
---
 drivers/i2c/busses/i2c-pnx.c |   33 +++++++--------------------------
 1 files changed, 7 insertions(+), 26 deletions(-)
drivers/i2c/busses/i2c-pnx.c +7 -26
index 6bb6ff7..23bd556 100644
@@ -448,6 +448,8 @@ i2c_pnx_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
 		"%s(): entering: %d messages, stat = %04x.\n",
 		__func__, num, ioread32(I2C_REG_STS(alg_data)));
 
+	clk_enable(alg_data->clk);
+
 	bus_reset_if_active(alg_data);
 
 	/* Process transactions in a loop. */
@@ -516,6 +518,8 @@ i2c_pnx_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
 
 	bus_reset_if_active(alg_data);
 
+	clk_disable(alg_data->clk);
+
 	/* Cleanup to be sure... */
 	alg_data->mif.buf = NULL;
 	alg_data->mif.len = 0;
@@ -539,29 +543,6 @@ static struct i2c_algorithm pnx_algorithm = {
 	.functionality = i2c_pnx_func,
 };
 
-#ifdef CONFIG_PM
-static int i2c_pnx_controller_suspend(struct platform_device *pdev,
-				      pm_message_t state)
-{
-	struct i2c_pnx_algo_data *alg_data = platform_get_drvdata(pdev);
-
-	/* FIXME: shouldn't this be clk_disable? */
-	clk_enable(alg_data->clk);
-
-	return 0;
-}
-
-static int i2c_pnx_controller_resume(struct platform_device *pdev)
-{
-	struct i2c_pnx_algo_data *alg_data = platform_get_drvdata(pdev);
-
-	return clk_enable(alg_data->clk);
-}
-#else
-#define i2c_pnx_controller_suspend	NULL
-#define i2c_pnx_controller_resume	NULL
-#endif
-
 static int __devinit i2c_pnx_probe(struct platform_device *pdev)
 {
 	unsigned long tmp;
@@ -665,6 +646,9 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev)
 	dev_dbg(&pdev->dev, "%s: Master at %#8x, irq %d.\n",
 	       alg_data->adapter.name, i2c_pnx->base, i2c_pnx->irq);
 
+	/* Disable clock until needed */
+	clk_disable(alg_data->clk);
+
 	return 0;
 
 out_irq:
@@ -692,7 +676,6 @@ static int __devexit i2c_pnx_remove(struct platform_device *pdev)
 
 	free_irq(i2c_pnx->irq, alg_data);
 	i2c_del_adapter(&alg_data->adapter);
-	clk_disable(alg_data->clk);
 	iounmap(alg_data->ioaddr);
 	release_mem_region(i2c_pnx->base, I2C_PNX_REGION_SIZE);
 	clk_put(alg_data->clk);
@@ -709,8 +692,6 @@ static struct platform_driver i2c_pnx_driver = {
 	},
 	.probe = i2c_pnx_probe,
 	.remove = __devexit_p(i2c_pnx_remove),
-	.suspend = i2c_pnx_controller_suspend,
-	.resume = i2c_pnx_controller_resume,
 };
 
 static int __init i2c_adap_pnx_init(void)
Signature · 6 lines
1.6.6

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Signature · 3 lines
Ben ([email protected], http://www.fluff.org/)

  'a smiley only costs 4 bytes'
#8 lore raw
In reply to a message not in the archive

Hi Vitaly,

Can you please ack these patches for the i2c-pnx driver? These are all important changes for the i2c-pnx.

thanks,
Kevin

Quoted 11 lines · On Tue, Mar 16, 2010 at 3:55 PM, <[email protected]…

This patch set fixes a stop condition issue with transfers, caps the maximum computed divider generated from the parent clock, and disables the I2C peripheral clock when the I2C bus isn't in use (to save power).

Patch 3 was previously posted a few months ago, but I didn't follow up on getting it into the driver.

All code is tested on the lpc3250.

A message that is not in the archive (sent off-list or not yet received): a08234131003221009j1ec74009jc2eb289386455b65-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#10 lore raw
Quoted 4 lines · Kevin Wells

Hi Vitaly,

Can you please ack these patches for the i2c-pnx driver? These are all important changes for the i2c-pnx.

I'm going to take no news as good news, and apply these unless anyone objects before the pull request.

Quoted 19 lines

thanks,
Kevin

Quoted 11 lines · On Tue, Mar 16, 2010 at 3:55 PM, <[email protected]…

This patch set fixes a stop condition issue with transfers, caps the maximum computed divider generated from the parent clock, and disables the I2C peripheral clock when the I2C bus isn't in use (to save power).

Patch 3 was previously posted a few months ago, but I didn't follow up on getting it into the driver.

All code is tested on the lpc3250.

--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 3 lines
Ben ([email protected], http://www.fluff.org/)

  'a smiley only costs 4 bytes'