Skip to contentSkip to conversation

i2c: sirf: get the i2c pin group by pinctrl api

PATCH New Barry Song 4 participants 8 messages Mar 18, 2013 – Mar 27, 2013 I2C subsystem host drivers

lore
Share & tools
lore

Barry Song

author
#0 lore raw

PATCH 1/1 i2c: sirf: get the i2c pin group by pinctrl api

From: Barry Song <[email protected]>

hardcode set i2c pin group to i2c function before, here we move to use standard pinctrl API to get pins of the group.

Cc Linus Walleij <[email protected]>
---
 drivers/i2c/busses/i2c-sirf.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)
drivers/i2c/busses/i2c-sirf.c +9 -0
index 5a7ad24..dd4004e 100644
@@ -16,6 +16,7 @@
 #include <linux/clk.h>
 #include <linux/err.h>
 #include <linux/io.h>
+#include <linux/pinctrl/consumer.h>
 
 #define SIRFSOC_I2C_CLK_CTRL		0x00
 #define SIRFSOC_I2C_STATUS		0x0C
@@ -265,6 +266,7 @@ static int i2c_sirfsoc_probe(struct platform_device *pdev)
 	struct i2c_adapter *adap;
 	struct resource *mem_res;
 	struct clk *clk;
+	struct pinctrl *pinctrl;
 	int bitrate;
 	int ctrl_speed;
 	int irq;
@@ -272,6 +274,12 @@ static int i2c_sirfsoc_probe(struct platform_device *pdev)
 	int err;
 	u32 regval;
 
+	pinctrl = devm_pinctrl_get_select_default(&pdev->dev);
+	if (IS_ERR(pinctrl)) {
+		err = PTR_ERR(pinctrl);
+		goto failed_pin;
+	}
+
 	clk = clk_get(&pdev->dev, NULL);
 	if (IS_ERR(clk)) {
 		err = PTR_ERR(clk);
@@ -385,6 +393,7 @@ err_clk_en:
 err_clk_prep:
 	clk_put(clk);
 err_get_clk:
+failed_pin:
 	return err;
 }
 
Signature · 6 lines
1.7.5.4



Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
More information can be found at www.csr.com. Follow CSR on Twitter at http://twitter.com/CSR_PLC and read our blog at www.csr.com/blog
#1 lore raw

PATCH 1/1 i2c: sirf: get the i2c pin group by pinctrl api

Hi,

Quoted 32 lines · Barry Song

From: Barry Song<[email protected]>

hardcode set i2c pin group to i2c function before, here we move to use standard pinctrl API to get pins of the group.

Cc Linus Walleij<[email protected]>
---
  drivers/i2c/busses/i2c-sirf.c |    9 +++++++++
  1 files changed, 9 insertions(+), 0 deletions(-)
drivers/i2c/busses/i2c-sirf.c +2 -0
index 5a7ad24..dd4004e 100644
@@ -16,6 +16,7 @@
  #include<linux/clk.h>
  #include<linux/err.h>
  #include<linux/io.h>
+#include<linux/pinctrl/consumer.h>
 
  #define SIRFSOC_I2C_CLK_CTRL		0x00
  #define SIRFSOC_I2C_STATUS		0x0C
@@ -265,6 +266,7 @@ static int i2c_sirfsoc_probe(struct platform_device *pdev)
  	struct i2c_adapter *adap;
  	struct resource *mem_res;
  	struct clk *clk;
+	struct pinctrl *pinctrl;
  	int bitrate;
  	int ctrl_speed;
  	int irq;

drivers/i2c/busses/i2c-sirf.c static int i2c_sirfsoc_probe(struct platform_device *pdev) · line 282

Quoted 9 lines
drivers/i2c/busses/i2c-sirf.c +6 -0
@@ -272,6 +274,12 @@ static int i2c_sirfsoc_probe(struct platform_device *pdev)
  	int err;
  	u32 regval;
 
+	pinctrl = devm_pinctrl_get_select_default(&pdev->dev);
+	if (IS_ERR(pinctrl)) {
+		err = PTR_ERR(pinctrl);
+		goto failed_pin;
+	}
+

I think, you should also add an "EPROBE_DEFER" check here ?

Quoted 11 lines
drivers/i2c/busses/i2c-sirf.c +1 -0
  	clk = clk_get(&pdev->dev, NULL);
  	if (IS_ERR(clk)) {
  		err = PTR_ERR(clk);
@@ -385,6 +393,7 @@ err_clk_en:
  err_clk_prep:
  	clk_put(clk);
  err_get_clk:
+failed_pin:
  	return err;
  }
 
#2 lore raw

PATCH 1/1 i2c: sirf: get the i2c pin group by pinctrl api

2013/3/18 Sourav Poddar <[email protected]>:

Quoted 41 lines

Hi,

Quoted 38 lines · Barry Song

From: Barry Song<[email protected]>

hardcode set i2c pin group to i2c function before, here we move to use standard pinctrl API to get pins of the group.

Cc Linus Walleij<[email protected]>
---
  drivers/i2c/busses/i2c-sirf.c |    9 +++++++++
  1 files changed, 9 insertions(+), 0 deletions(-)
drivers/i2c/busses/i2c-sirf.c +2 -0
index 5a7ad24..dd4004e 100644
@@ -16,6 +16,7 @@
  #include<linux/clk.h>
  #include<linux/err.h>
  #include<linux/io.h>
+#include<linux/pinctrl/consumer.h>
 
  #define SIRFSOC_I2C_CLK_CTRL          0x00
  #define SIRFSOC_I2C_STATUS            0x0C
@@ -265,6 +266,7 @@ static int i2c_sirfsoc_probe(struct platform_device
 *pdev)
        struct i2c_adapter *adap;
        struct resource *mem_res;
        struct clk *clk;
+       struct pinctrl *pinctrl;
        int bitrate;
        int ctrl_speed;
        int irq;
drivers/i2c/busses/i2c-sirf.c +0 -0
@@ -272,6 +274,12 @@ static int i2c_sirfsoc_probe(struct platform_device
 *pdev)
        int err;
        u32 regval;
 
Quoted 8 lines

drivers/i2c/busses/i2c-sirf.c static int i2c_sirfsoc_probe(struct platform_device *pdev) · line 282

Quoted 6 lines
drivers/i2c/busses/i2c-sirf.c +6 -0
+       pinctrl = devm_pinctrl_get_select_default(&pdev->dev);
+       if (IS_ERR(pinctrl)) {
+               err = PTR_ERR(pinctrl);
+               goto failed_pin;
+       }
+

I think, you should also add an "EPROBE_DEFER" check here ?

why would the driver require a probe retry since getting the pinctrl has returned an error? before the driver executes, pinctrl driver has run earlier and DT has been extended.

all people are using IS_ERR(pinctrl) to check the ret of devm_pinctrl_get_select_default.

Quoted 11 lines

drivers/i2c/busses/i2c-sirf.c err_clk_en: · line 398

Quoted 11 lines
drivers/i2c/busses/i2c-sirf.c +0 -0
        clk = clk_get(&pdev->dev, NULL);
        if (IS_ERR(clk)) {
                err = PTR_ERR(clk);
drivers/i2c/busses/i2c-sirf.c +1 -0
@@ -385,6 +393,7 @@ err_clk_en:
  err_clk_prep:
        clk_put(clk);
  err_get_clk:
+failed_pin:
        return err;
  }

-barry

#3 lore raw

PATCH 1/1 i2c: sirf: get the i2c pin group by pinctrl api

Hi,

Quoted 48 lines · Barry Song

2013/3/18 Sourav Poddar<[email protected]>:

Quoted 40 lines

Hi,

Quoted 37 lines · Barry Song

From: Barry Song<[email protected]>

hardcode set i2c pin group to i2c function before, here we move to use standard pinctrl API to get pins of the group.

Cc Linus Walleij<[email protected]>
---
   drivers/i2c/busses/i2c-sirf.c |    9 +++++++++
   1 files changed, 9 insertions(+), 0 deletions(-)
drivers/i2c/busses/i2c-sirf.c +2 -0
index 5a7ad24..dd4004e 100644
@@ -16,6 +16,7 @@
   #include<linux/clk.h>
   #include<linux/err.h>
   #include<linux/io.h>
+#include<linux/pinctrl/consumer.h>
 
   #define SIRFSOC_I2C_CLK_CTRL          0x00
   #define SIRFSOC_I2C_STATUS            0x0C
@@ -265,6 +266,7 @@ static int i2c_sirfsoc_probe(struct platform_device
 *pdev)
         struct i2c_adapter *adap;
         struct resource *mem_res;
         struct clk *clk;
+       struct pinctrl *pinctrl;
         int bitrate;
         int ctrl_speed;
         int irq;
drivers/i2c/busses/i2c-sirf.c +0 -0
@@ -272,6 +274,12 @@ static int i2c_sirfsoc_probe(struct platform_device
 *pdev)
         int err;
         u32 regval;
 
Quoted 7 lines

drivers/i2c/busses/i2c-sirf.c static int i2c_sirfsoc_probe(struct platform_device *pdev) · line 282

Quoted 6 lines
drivers/i2c/busses/i2c-sirf.c +6 -0
+       pinctrl = devm_pinctrl_get_select_default(&pdev->dev);
+       if (IS_ERR(pinctrl)) {
+               err = PTR_ERR(pinctrl);
+               goto failed_pin;
+       }
+

I think, you should also add an "EPROBE_DEFER" check here ?

Quoted 4 lines

why would the driver require a probe retry since getting the pinctrl has returned an error? before the driver executes, pinctrl driver has run earlier and DT has been extended.

There might be modules who need some early pinctrl muxing. Some drivers might also use subsys_initcall instead of module_init. In such cases,
"EPROBE_DEFER" might be useful.

Quoted 3 lines

all people are using IS_ERR(pinctrl) to check the ret of devm_pinctrl_get_select_default.

Yes, we will keep using this check. DEFER check will be embedded inside this.
Something like below, which has been done for omap i2c..

+ dev->pins = devm_pinctrl_get_select_default(&pdev->dev);
+ if (IS_ERR(dev->pins)) {
+ if (PTR_ERR(dev->pins) == -EPROBE_DEFER)
+ return -EPROBE_DEFER;
+
+ dev_warn(&pdev->dev, "did not get pins for i2c error:
%li\n",
+ PTR_ERR(dev->pins));
+ dev->pins = NULL;
+ }
+

Quoted 11 lines
Quoted 10 lines

drivers/i2c/busses/i2c-sirf.c err_clk_en: · line 398

Quoted 10 lines
drivers/i2c/busses/i2c-sirf.c +0 -0
         clk = clk_get(&pdev->dev, NULL);
         if (IS_ERR(clk)) {
                 err = PTR_ERR(clk);
drivers/i2c/busses/i2c-sirf.c +1 -0
@@ -385,6 +393,7 @@ err_clk_en:
   err_clk_prep:
         clk_put(clk);
   err_get_clk:
+failed_pin:
         return err;
   }

-barry

~Sourav

#4 lore raw

PATCH 1/1 i2c: sirf: get the i2c pin group by pinctrl api

2013/3/18 Sourav Poddar <[email protected]>:

Quoted 57 lines

Hi,

Quoted 54 lines · Barry Song

2013/3/18 Sourav Poddar<[email protected]>:

Quoted 51 lines

Hi,

Quoted 35 lines · Barry Song

From: Barry Song<[email protected]>

hardcode set i2c pin group to i2c function before, here we move to use standard pinctrl API to get pins of the group.

Cc Linus Walleij<[email protected]>
---
   drivers/i2c/busses/i2c-sirf.c |    9 +++++++++
   1 files changed, 9 insertions(+), 0 deletions(-)
drivers/i2c/busses/i2c-sirf.c +2 -0
index 5a7ad24..dd4004e 100644
@@ -16,6 +16,7 @@
   #include<linux/clk.h>
   #include<linux/err.h>
   #include<linux/io.h>
+#include<linux/pinctrl/consumer.h>
 
   #define SIRFSOC_I2C_CLK_CTRL          0x00
   #define SIRFSOC_I2C_STATUS            0x0C
@@ -265,6 +266,7 @@ static int i2c_sirfsoc_probe(struct platform_device
 *pdev)
         struct i2c_adapter *adap;
         struct resource *mem_res;
         struct clk *clk;
+       struct pinctrl *pinctrl;
         int bitrate;
         int ctrl_speed;
         int irq;

drivers/i2c/busses/i2c-sirf.c static int i2c_sirfsoc_probe(struct platform_device · line 283

Quoted 10 lines
drivers/i2c/busses/i2c-sirf.c +6 -0
@@ -272,6 +274,12 @@ static int i2c_sirfsoc_probe(struct platform_device
 *pdev)
         int err;
         u32 regval;
 
+       pinctrl = devm_pinctrl_get_select_default(&pdev->dev);
+       if (IS_ERR(pinctrl)) {
+               err = PTR_ERR(pinctrl);
+               goto failed_pin;
+       }
+

I think, you should also add an "EPROBE_DEFER" check here ?

Quoted 8 lines
Quoted 4 lines

why would the driver require a probe retry since getting the pinctrl has returned an error? before the driver executes, pinctrl driver has run earlier and DT has been extended.

There might be modules who need some early pinctrl muxing. Some drivers might also use subsys_initcall instead of module_init. In such cases,
"EPROBE_DEFER" might be useful.

yes. that is right. here these is no this issue.
in my case, sirf pinctrl is initialized by arch_initcall, i2c probing is handled by module_init.
that makes i2c is a later user of pinctrl.

Quoted 7 lines
Quoted 4 lines

all people are using IS_ERR(pinctrl) to check the ret of devm_pinctrl_get_select_default.

Yes, we will keep using this check. DEFER check will be embedded inside this.
Something like below, which has been done for omap i2c..

-barry

#5 lore raw

PATCH 1/1 i2c: sirf: get the i2c pin group by pinctrl api

In reply to Barry Song
Quoted 7 lines · Barry Song

From: Barry Song <[email protected]>

hardcode set i2c pin group to i2c function before, here we move to use standard pinctrl API to get pins of the group.

Cc Linus Walleij <[email protected]>

NAK.

This is done by the device core as of commit ab78029ecc347debbd737f06688d788bd9d60c1d "drivers/pinctrl: grab default handles from device core".

You only need to fetch pinctrl handles in drivers if you're using anything else than the default state.

Yours,
Linus Walleij

#6 lore raw

PATCH 1/1 i2c: sirf: get the i2c pin group by pinctrl api

2013/3/27 Linus Walleij <[email protected]>:

Quoted 10 lines · Barry Song
Quoted 8 lines

From: Barry Song <[email protected]>

hardcode set i2c pin group to i2c function before, here we move to use standard pinctrl API to get pins of the group.

Cc Linus Walleij <[email protected]>
Quoted 8 lines

NAK.

This is done by the device core as of commit ab78029ecc347debbd737f06688d788bd9d60c1d "drivers/pinctrl: grab default handles from device core".

You only need to fetch pinctrl handles in drivers if you're using anything else than the default state.

well. missed this recent commit.
it should mean we hould drop all devm_pinctrl_get_select_default() if the driver only takes the default pinctrl?

it looks like there are still a lot of drivers doing that. anyway, i will drop them in SiRFsoc drivers. and involve you in the coming patch.

Quoted 4 lines

Yours,
Linus Walleij

-barry

#7 lore raw

PATCH 1/1 i2c: sirf: get the i2c pin group by pinctrl api

Quoted 8 lines · Barry Song

2013/3/27 Linus Walleij <[email protected]>:

Quoted 2 lines

You only need to fetch pinctrl handles in drivers if you're using anything else than the default state.

well. missed this recent commit.
it should mean we hould drop all devm_pinctrl_get_select_default() if the driver only takes the default pinctrl?

Yes.

Quoted 3 lines

it looks like there are still a lot of drivers doing that. anyway, i will drop them in SiRFsoc drivers. and involve you in the coming patch.

I am meaning to fix that up. Just haven't had time to... Prior to that patch it was the right thing to do.

Yours,
Linus Walleij