Skip to contentSkip to conversation

Blackfin I2C Driver: Functional power management support

PATCH In review Bryan Wu 3 participants 6 messages Jul 27, 2008 – Jul 28, 2008 5 messages not in the archive I2C subsystem host drivers

lore
Share & tools
lore

Bryan Wu

author
#0 lore raw

PATCH 1/1 Blackfin I2C Driver: Functional power management support

From: Michael Hennerich <[email protected]>

PM_SUSPEND_MEM: Blackfin does not maintain register state through Hibernate. Save and restore peripheral base initialization during PM transitions.

---
 drivers/i2c/busses/i2c-bfin-twi.c |   35 ++++++++++++++++++++++++-----------
 1 files changed, 24 insertions(+), 11 deletions(-)
drivers/i2c/busses/i2c-bfin-twi.c +24 -11
index 48d084b..3c855ff 100644
@@ -49,6 +49,8 @@ struct bfin_twi_iface {
 	struct i2c_msg 		*pmsg;
 	int			msg_num;
 	int			cur_msg;
+	u16			saved_clkdiv;
+	u16			saved_control;
 	void __iomem		*regs_base;
 };
 
@@ -565,32 +567,43 @@ static u32 bfin_twi_functionality(struct i2c_adapter *adap)
 	       I2C_FUNC_I2C;
 }
 
-
 static struct i2c_algorithm bfin_twi_algorithm = {
 	.master_xfer   = bfin_twi_master_xfer,
 	.smbus_xfer    = bfin_twi_smbus_xfer,
 	.functionality = bfin_twi_functionality,
 };
 
-
-static int i2c_bfin_twi_suspend(struct platform_device *dev, pm_message_t state)
+static int i2c_bfin_twi_suspend(struct platform_device *pdev, pm_message_t state)
 {
-	struct bfin_twi_iface *iface = platform_get_drvdata(dev);
+	struct bfin_twi_iface *iface = platform_get_drvdata(pdev);
+
+	iface->saved_clkdiv = read_CLKDIV(iface);
+	iface->saved_control = read_CONTROL(iface);
+
+	free_irq(iface->irq, iface);
 
 	/* Disable TWI */
-	write_CONTROL(iface, read_CONTROL(iface) & ~TWI_ENA);
-	SSYNC();
+	write_CONTROL(iface, iface->saved_control & ~TWI_ENA);
 
 	return 0;
 }
 
-static int i2c_bfin_twi_resume(struct platform_device *dev)
+static int i2c_bfin_twi_resume(struct platform_device *pdev)
 {
-	struct bfin_twi_iface *iface = platform_get_drvdata(dev);
+	struct bfin_twi_iface *iface = platform_get_drvdata(pdev);
 
-	/* Enable TWI */
-	write_CONTROL(iface, read_CONTROL(iface) | TWI_ENA);
-	SSYNC();
+	int rc = request_irq(iface->irq, bfin_twi_interrupt_entry,
+		IRQF_DISABLED, pdev->name, iface);
+	if (rc) {
+		dev_err(&pdev->dev, "Can't get IRQ %d !\n", iface->irq);
+		return -ENODEV;
+	}
+
+	/* Resume TWI interface clock as specified */
+	write_CLKDIV(iface, iface->saved_clkdiv);
+
+	/* Resume TWI */
+	write_CONTROL(iface, iface->saved_control);
 
 	return 0;
 }
Signature · 7 lines
1.5.6


_______________________________________________
i2c mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/i2c

A message that is not in the archive (sent off-list or not yet received): 1217140914-21718-1-git-send-email-cooloney-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org

#2 lore raw
Quoted 42 lines · Bryan Wu

From: Michael Hennerich <[email protected]>

PM_SUSPEND_MEM: Blackfin does not maintain register state through Hibernate. Save and restore peripheral base initialization during PM transitions.

---
 drivers/i2c/busses/i2c-bfin-twi.c |   35 ++++++++++++++++++++++++-----------
 1 files changed, 24 insertions(+), 11 deletions(-)
drivers/i2c/busses/i2c-bfin-twi.c +4 -4
index 48d084b..3c855ff 100644
@@ -49,6 +49,8 @@ struct bfin_twi_iface {
 	struct i2c_msg 		*pmsg;
 	int			msg_num;
 	int			cur_msg;
+	u16			saved_clkdiv;
+	u16			saved_control;
 	void __iomem		*regs_base;
 };
 
@@ -565,32 +567,43 @@ static u32 bfin_twi_functionality(struct i2c_adapter *adap)
 	       I2C_FUNC_I2C;
 }
 
-
 static struct i2c_algorithm bfin_twi_algorithm = {
 	.master_xfer   = bfin_twi_master_xfer,
 	.smbus_xfer    = bfin_twi_smbus_xfer,
 	.functionality = bfin_twi_functionality,
 };
 
-
-static int i2c_bfin_twi_suspend(struct platform_device *dev, pm_message_t state)
+static int i2c_bfin_twi_suspend(struct platform_device *pdev, pm_message_t state)
 {
-	struct bfin_twi_iface *iface = platform_get_drvdata(dev);
+	struct bfin_twi_iface *iface = platform_get_drvdata(pdev);

drivers/i2c/busses/i2c-bfin-twi.c static u32 bfin_twi_functionality(struct i2c_adapter *adap) · line 586

Quoted 10 lines
drivers/i2c/busses/i2c-bfin-twi.c +6 -2
+
+	iface->saved_clkdiv = read_CLKDIV(iface);
+	iface->saved_control = read_CONTROL(iface);
+
+	free_irq(iface->irq, iface);
 
 	/* Disable TWI */
-	write_CONTROL(iface, read_CONTROL(iface) & ~TWI_ENA);
-	SSYNC();
+	write_CONTROL(iface, iface->saved_control & ~TWI_ENA);

I assume removing the SSYNC() call is valid?

Quoted 29 lines
drivers/i2c/busses/i2c-bfin-twi.c +14 -5
 	return 0;
 }
 
-static int i2c_bfin_twi_resume(struct platform_device *dev)
+static int i2c_bfin_twi_resume(struct platform_device *pdev)
 {
-	struct bfin_twi_iface *iface = platform_get_drvdata(dev);
+	struct bfin_twi_iface *iface = platform_get_drvdata(pdev);
 
-	/* Enable TWI */
-	write_CONTROL(iface, read_CONTROL(iface) | TWI_ENA);
-	SSYNC();
+	int rc = request_irq(iface->irq, bfin_twi_interrupt_entry,
+		IRQF_DISABLED, pdev->name, iface);
+	if (rc) {
+		dev_err(&pdev->dev, "Can't get IRQ %d !\n", iface->irq);
+		return -ENODEV;
+	}
+
+	/* Resume TWI interface clock as specified */
+	write_CLKDIV(iface, iface->saved_clkdiv);
+
+	/* Resume TWI */
+	write_CONTROL(iface, iface->saved_control);
 
 	return 0;
 }
Signature · 1 line
1.5.6

if removing the SSYNC() call is ok, then I'll queue this into my tree which I will be requesting a pull asap.

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

  'a smiley only costs 4 bytes'

_______________________________________________
i2c mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/i2c

A message that is not in the archive (sent off-list or not yet received): [email protected]

author
#4 lore raw
Quoted 49 lines · Ben Dooks
Quoted 48 lines · Bryan Wu

From: Michael Hennerich <[email protected]>

PM_SUSPEND_MEM: Blackfin does not maintain register state through Hibernate. Save and restore peripheral base initialization during PM transitions.

---
 drivers/i2c/busses/i2c-bfin-twi.c |   35 ++++++++++++++++++++++++-----------
 1 files changed, 24 insertions(+), 11 deletions(-)
drivers/i2c/busses/i2c-bfin-twi.c +9 -4
index 48d084b..3c855ff 100644
@@ -49,6 +49,8 @@ struct bfin_twi_iface {
      struct i2c_msg          *pmsg;
      int                     msg_num;
      int                     cur_msg;
+     u16                     saved_clkdiv;
+     u16                     saved_control;
      void __iomem            *regs_base;
 };
 
@@ -565,32 +567,43 @@ static u32 bfin_twi_functionality(struct i2c_adapter *adap)
             I2C_FUNC_I2C;
 }
 
-
 static struct i2c_algorithm bfin_twi_algorithm = {
      .master_xfer   = bfin_twi_master_xfer,
      .smbus_xfer    = bfin_twi_smbus_xfer,
      .functionality = bfin_twi_functionality,
 };
 
-
-static int i2c_bfin_twi_suspend(struct platform_device *dev, pm_message_t state)
+static int i2c_bfin_twi_suspend(struct platform_device *pdev, pm_message_t state)
 {
-     struct bfin_twi_iface *iface = platform_get_drvdata(dev);
+     struct bfin_twi_iface *iface = platform_get_drvdata(pdev);
+
+     iface->saved_clkdiv = read_CLKDIV(iface);
+     iface->saved_control = read_CONTROL(iface);
+
+     free_irq(iface->irq, iface);
 
Quoted 7 lines

drivers/i2c/busses/i2c-bfin-twi.c static u32 bfin_twi_functionality(struct i2c_adapter *adap) · line 586

Quoted 4 lines
drivers/i2c/busses/i2c-bfin-twi.c +1 -2
      /* Disable TWI */
-     write_CONTROL(iface, read_CONTROL(iface) & ~TWI_ENA);
-     SSYNC();
+     write_CONTROL(iface, iface->saved_control & ~TWI_ENA);

I assume removing the SSYNC() call is valid?

Yes, I think it is OK for that. We tested on our platform. Actually, keeping the SSYNC() is not a big deal for this driver. How do you think Michael?

Quoted 25 lines
Quoted 25 lines
drivers/i2c/busses/i2c-bfin-twi.c +14 -5
      return 0;
 }
 
-static int i2c_bfin_twi_resume(struct platform_device *dev)
+static int i2c_bfin_twi_resume(struct platform_device *pdev)
 {
-     struct bfin_twi_iface *iface = platform_get_drvdata(dev);
+     struct bfin_twi_iface *iface = platform_get_drvdata(pdev);
 
-     /* Enable TWI */
-     write_CONTROL(iface, read_CONTROL(iface) | TWI_ENA);
-     SSYNC();
+     int rc = request_irq(iface->irq, bfin_twi_interrupt_entry,
+             IRQF_DISABLED, pdev->name, iface);
+     if (rc) {
+             dev_err(&pdev->dev, "Can't get IRQ %d !\n", iface->irq);
+             return -ENODEV;
+     }
+
+     /* Resume TWI interface clock as specified */
+     write_CLKDIV(iface, iface->saved_clkdiv);
+
+     /* Resume TWI */
+     write_CONTROL(iface, iface->saved_control);
 
Quoted 8 lines
Quoted 4 lines
drivers/i2c/busses/i2c-bfin-twi.c +0 -1
      return 0;
 }
--

1.5.6

if removing the SSYNC() call is ok, then I'll queue this into my tree which I will be requesting a pull asap.

Thanks lot, I'd like to see that.
-Bryan

_______________________________________________
i2c mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/i2c

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

#6 lore raw
Quoted 58 lines · Bryan Wu
Quoted 49 lines · Ben Dooks
Quoted 48 lines · Bryan Wu

From: Michael Hennerich <[email protected]>

PM_SUSPEND_MEM: Blackfin does not maintain register state through Hibernate. Save and restore peripheral base initialization during PM transitions.

---
 drivers/i2c/busses/i2c-bfin-twi.c |   35 ++++++++++++++++++++++++-----------
 1 files changed, 24 insertions(+), 11 deletions(-)
drivers/i2c/busses/i2c-bfin-twi.c +9 -4
index 48d084b..3c855ff 100644
@@ -49,6 +49,8 @@ struct bfin_twi_iface {
      struct i2c_msg          *pmsg;
      int                     msg_num;
      int                     cur_msg;
+     u16                     saved_clkdiv;
+     u16                     saved_control;
      void __iomem            *regs_base;
 };
 
@@ -565,32 +567,43 @@ static u32 bfin_twi_functionality(struct i2c_adapter *adap)
             I2C_FUNC_I2C;
 }
 
-
 static struct i2c_algorithm bfin_twi_algorithm = {
      .master_xfer   = bfin_twi_master_xfer,
      .smbus_xfer    = bfin_twi_smbus_xfer,
      .functionality = bfin_twi_functionality,
 };
 
-
-static int i2c_bfin_twi_suspend(struct platform_device *dev, pm_message_t state)
+static int i2c_bfin_twi_suspend(struct platform_device *pdev, pm_message_t state)
 {
-     struct bfin_twi_iface *iface = platform_get_drvdata(dev);
+     struct bfin_twi_iface *iface = platform_get_drvdata(pdev);
+
+     iface->saved_clkdiv = read_CLKDIV(iface);
+     iface->saved_control = read_CONTROL(iface);
+
+     free_irq(iface->irq, iface);
 
Quoted 7 lines

drivers/i2c/busses/i2c-bfin-twi.c static u32 bfin_twi_functionality(struct i2c_adapter *adap) · line 586

Quoted 4 lines
drivers/i2c/busses/i2c-bfin-twi.c +1 -2
      /* Disable TWI */
-     write_CONTROL(iface, read_CONTROL(iface) & ~TWI_ENA);
-     SSYNC();
+     write_CONTROL(iface, iface->saved_control & ~TWI_ENA);

I assume removing the SSYNC() call is valid?

Quoted 36 lines

Yes, I think it is OK for that. We tested on our platform. Actually, keeping the SSYNC() is not a big deal for this driver. How do you think Michael?

Quoted 32 lines
Quoted 28 lines
drivers/i2c/busses/i2c-bfin-twi.c +14 -6
      return 0;
 }
 
-static int i2c_bfin_twi_resume(struct platform_device *dev)
+static int i2c_bfin_twi_resume(struct platform_device *pdev)
 {
-     struct bfin_twi_iface *iface = platform_get_drvdata(dev);
+     struct bfin_twi_iface *iface = platform_get_drvdata(pdev);
 
-     /* Enable TWI */
-     write_CONTROL(iface, read_CONTROL(iface) | TWI_ENA);
-     SSYNC();
+     int rc = request_irq(iface->irq, bfin_twi_interrupt_entry,
+             IRQF_DISABLED, pdev->name, iface);
+     if (rc) {
+             dev_err(&pdev->dev, "Can't get IRQ %d !\n", iface->irq);
+             return -ENODEV;
+     }
+
+     /* Resume TWI interface clock as specified */
+     write_CLKDIV(iface, iface->saved_clkdiv);
+
+     /* Resume TWI */
+     write_CONTROL(iface, iface->saved_control);
 
      return 0;
 }
--
Quoted 1 line

1.5.6

if removing the SSYNC() call is ok, then I'll queue this into my tree which I will be requesting a pull asap.

ok, this is in my queue, unless anyone objects then it'll be pushed out later today.

Signature · 10 lines
Ben

Q:      What's a light-year?
A:      One-third less calories than a regular year.


_______________________________________________
i2c mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/i2c

A message that is not in the archive (sent off-list or not yet received): 20080728110845.GX26938-SMNkleLxa3Z6Wcw2j4pizdi2O/[email protected]

#8 lore raw
Quoted 6 lines

From: Ben Dooks [mailto:[email protected]]

Quoted 1 line · Bryan Wu

On Mon, Jul 28, 2008 at 5:23 PM, Ben Dooks <[email protected]>

Quoted 11 lines · wrote:
Quoted 11 lines
Quoted 11 lines · Bryan Wu
Quoted 10 lines

From: Michael Hennerich <[email protected]>

PM_SUSPEND_MEM: Blackfin does not maintain register state through Hibernate. Save and restore peripheral base initialization during PM transitions.

---
 drivers/i2c/busses/i2c-bfin-twi.c |   35

++++++++++++++++++++++++----

Quoted 64 lines

-------

Quoted 3 lines
Quoted 3 lines

Review

Quoted 3 lines
 1 files changed, 24 insertions(+), 11 deletions(-)
(quoted diff) +0 -0

b/drivers/i2c/busses/i2c-bfin-twi.c

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

index 48d084b..3c855ff 100644

drivers/i2c/busses/i2c-bfin-twi.c +2 -0
@@ -49,6 +49,8 @@ struct bfin_twi_iface {
      struct i2c_msg          *pmsg;
      int                     msg_num;
      int                     cur_msg;
+     u16                     saved_clkdiv;
+     u16                     saved_control;
      void __iomem            *regs_base;
 };
 
Quoted 1 line
Quoted 1 line

drivers/i2c/busses/i2c-bfin-twi.c static u32 bfin_twi_functionality(struct

Quoted 1 line
drivers/i2c/busses/i2c-bfin-twi.c +0 -0
@@ -565,32 +567,43 @@ static u32 bfin_twi_functionality(struct

i2c_adapter *adap)

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
drivers/i2c/busses/i2c-bfin-twi.c +0 -1
             I2C_FUNC_I2C;
 }
 
-
 static struct i2c_algorithm bfin_twi_algorithm = {
      .master_xfer   = bfin_twi_master_xfer,
      .smbus_xfer    = bfin_twi_smbus_xfer,
      .functionality = bfin_twi_functionality,
 };
 
Quoted 2 lines
Quoted 2 lines

drivers/i2c/busses/i2c-bfin-twi.c static u32 bfin_twi_functionality(struct · line 576

Quoted 2 lines
drivers/i2c/busses/i2c-bfin-twi.c +0 -2
-
-static int i2c_bfin_twi_suspend(struct platform_device *dev,

pm_message_t state)

Quoted 1 line
Quoted 1 line

drivers/i2c/busses/i2c-bfin-twi.c static u32 bfin_twi_functionality(struct · line 576

Quoted 1 line
drivers/i2c/busses/i2c-bfin-twi.c +1 -0
+static int i2c_bfin_twi_suspend(struct platform_device *pdev,

pm_message_t state)

Quoted 30 lines
Quoted 9 lines
Quoted 9 lines
drivers/i2c/busses/i2c-bfin-twi.c +6 -1
 {
-     struct bfin_twi_iface *iface = platform_get_drvdata(dev);
+     struct bfin_twi_iface *iface = platform_get_drvdata(pdev);
+
+     iface->saved_clkdiv = read_CLKDIV(iface);
+     iface->saved_control = read_CONTROL(iface);
+
+     free_irq(iface->irq, iface);
 
Quoted 7 lines

drivers/i2c/busses/i2c-bfin-twi.c static u32 bfin_twi_functionality(struct · line 586

Quoted 4 lines
drivers/i2c/busses/i2c-bfin-twi.c +1 -2
      /* Disable TWI */
-     write_CONTROL(iface, read_CONTROL(iface) & ~TWI_ENA);
-     SSYNC();
+     write_CONTROL(iface, iface->saved_control & ~TWI_ENA);

I assume removing the SSYNC() call is valid?

Yes, I think it is OK for that. We tested on our platform. Actually, keeping the SSYNC() is not a big deal for this driver. How do you think Michael?

Quoted 9 lines
Quoted 9 lines
drivers/i2c/busses/i2c-bfin-twi.c +2 -2
      return 0;
 }
 
-static int i2c_bfin_twi_resume(struct platform_device *dev)
+static int i2c_bfin_twi_resume(struct platform_device *pdev)
 {
-     struct bfin_twi_iface *iface = platform_get_drvdata(dev);
+     struct bfin_twi_iface *iface = platform_get_drvdata(pdev);
 
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drivers/i2c/busses/i2c-bfin-twi.c static u32 bfin_twi_functionality(struct · line 597

Quoted 7 lines
drivers/i2c/busses/i2c-bfin-twi.c +4 -3
-     /* Enable TWI */
-     write_CONTROL(iface, read_CONTROL(iface) | TWI_ENA);
-     SSYNC();
+     int rc = request_irq(iface->irq, bfin_twi_interrupt_entry,
+             IRQF_DISABLED, pdev->name, iface);
+     if (rc) {
+             dev_err(&pdev->dev, "Can't get IRQ %d !\n",

iface->irq);

Quoted 17 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/i2c/busses/i2c-bfin-twi.c +8 -0
+             return -ENODEV;
+     }
+
+     /* Resume TWI interface clock as specified */
+     write_CLKDIV(iface, iface->saved_clkdiv);
+
+     /* Resume TWI */
+     write_CONTROL(iface, iface->saved_control);
 
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
drivers/i2c/busses/i2c-bfin-twi.c +0 -1
      return 0;
 }
--

1.5.6

if removing the SSYNC() call is ok, then I'll queue this into my tree which I will be requesting a pull asap.

Quoted 2 lines

ok, this is in my queue, unless anyone objects then it'll be pushed out later today.

Removing this SSYNC is absolutely safe. There are potentially many other ones that can be removed too.

Michael

Quoted 6 lines

--
Ben

Q:      What's a light-year?
A:      One-third less calories than a regular year.

_______________________________________________
i2c mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/i2c

A message that is not in the archive (sent off-list or not yet received): 8A42379416420646B9BFAC9682273B6D035F0772-pcKY8lWzTjquVPpjEGsWsTcYPEmu4y7e@public.gmane.org

#10 lore raw
Quoted 10 lines · Michael
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

if removing the SSYNC() call is ok, then I'll queue this into my tree which I will be requesting a pull asap.

ok, this is in my queue, unless anyone objects then it'll be pushed out later today.

Removing this SSYNC is absolutely safe. There are potentially many other ones that can be removed too.

Ok, next time a note to this effect in the description would be useful to inform everyone that you've not just accidentally removed something the driver might rely on having.

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

  'a smiley only costs 4 bytes'

_______________________________________________
i2c mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/i2c