* [PATCH v2 0/5] i2c: pca-platform: updates
@ 2017-06-20 1:18 Chris Packham
2017-06-20 1:18 ` [PATCH v2 1/5] dt-bindings: add bindings for i2c-pca-platform Chris Packham
` (5 more replies)
0 siblings, 6 replies; 36+ messages in thread
From: Chris Packham @ 2017-06-20 1:18 UTC (permalink / raw)
To: wsa, robh+dt, linux-i2c, devicetree; +Cc: linux-kernel, Chris Packham
We're using a PCA9564 on an embedded platform to provide an i2c
controller. This adds devicetree support and I've included some
cleanups for the driver while I was at it.
Chris Packham (5):
dt-bindings: add bindings for i2c-pca-platform
i2c: pca-platform: add devicetree awareness
i2c: pca-platform: use gpio_is_valid
i2c: pca-platform: use device managed allocations
i2c: pca-platform: use dev_warn/dev_info instead of printk
.../devicetree/bindings/i2c/i2c-pca-platform.txt | 18 ++++
drivers/i2c/busses/i2c-pca-platform.c | 97 +++++++++-------------
2 files changed, 57 insertions(+), 58 deletions(-)
create mode 100644 Documentation/devicetree/bindings/i2c/i2c-pca-platform.txt
--
2.13.0
^ permalink raw reply [flat|nested] 36+ messages in thread
* [PATCH v2 1/5] dt-bindings: add bindings for i2c-pca-platform
2017-06-20 1:18 [PATCH v2 0/5] i2c: pca-platform: updates Chris Packham
@ 2017-06-20 1:18 ` Chris Packham
2017-06-22 8:22 ` Wolfram Sang
2017-06-20 1:18 ` [PATCH v2 2/5] i2c: pca-platform: add devicetree awareness Chris Packham
` (4 subsequent siblings)
5 siblings, 1 reply; 36+ messages in thread
From: Chris Packham @ 2017-06-20 1:18 UTC (permalink / raw)
To: wsa, robh+dt, linux-i2c, devicetree
Cc: linux-kernel, Chris Packham, Mark Rutland
Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
---
Changes in v2:
- Split dt-binding to separate patch, use "reset-gpios" instead of "gpios".
.../devicetree/bindings/i2c/i2c-pca-platform.txt | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
create mode 100644 Documentation/devicetree/bindings/i2c/i2c-pca-platform.txt
diff --git a/Documentation/devicetree/bindings/i2c/i2c-pca-platform.txt b/Documentation/devicetree/bindings/i2c/i2c-pca-platform.txt
new file mode 100644
index 000000000000..86abf249b194
--- /dev/null
+++ b/Documentation/devicetree/bindings/i2c/i2c-pca-platform.txt
@@ -0,0 +1,18 @@
+* NXP PCA PCA9564/PCA9665 I2C controller
+
+The PCA9564/PCA9665 serves as an interface between most standard
+parallel-bus microcontrollers/microprocessors and the serial I2C-bus
+and allows the parallel bus system to communicate bi-directionally
+with the I2C-bus.
+
+Required properties :
+
+ - reg : Offset and length of the register set for the device
+ - compatible : one of "nxp,pca9564" or "nxp,pca9665"
+
+Optional properties
+ - interrupts : the interrupt number
+ - interrupt-parent : the phandle for the interrupt controller.
+ If an interrupt is not specified polling will be used.
+ - reset-gpios : gpio specifier for gpio connected to RESET_N pin.
+ - clock-frequency : I2C bus frequency.
--
2.13.0
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [PATCH v2 2/5] i2c: pca-platform: add devicetree awareness
2017-06-20 1:18 [PATCH v2 0/5] i2c: pca-platform: updates Chris Packham
2017-06-20 1:18 ` [PATCH v2 1/5] dt-bindings: add bindings for i2c-pca-platform Chris Packham
@ 2017-06-20 1:18 ` Chris Packham
2017-06-20 1:18 ` [PATCH v2 3/5] i2c: pca-platform: use gpio_is_valid Chris Packham
` (3 subsequent siblings)
5 siblings, 0 replies; 36+ messages in thread
From: Chris Packham @ 2017-06-20 1:18 UTC (permalink / raw)
To: wsa, robh+dt, linux-i2c, devicetree; +Cc: linux-kernel, Chris Packham
Allow devices that use this driver to be registered via a
devicetree.
Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
---
Changes in v2:
- Set i2c->adap.dev.of_node so that child nodes are automatically probed
- Split dt-binding to separate patch, use "reset-gpios" instead of "gpios".
drivers/i2c/busses/i2c-pca-platform.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/drivers/i2c/busses/i2c-pca-platform.c b/drivers/i2c/busses/i2c-pca-platform.c
index 3bd2e7d06e4b..87ca2f02f607 100644
--- a/drivers/i2c/busses/i2c-pca-platform.c
+++ b/drivers/i2c/busses/i2c-pca-platform.c
@@ -23,6 +23,9 @@
#include <linux/i2c-pca-platform.h>
#include <linux/gpio.h>
#include <linux/io.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/of_gpio.h>
#include <asm/irq.h>
@@ -136,12 +139,15 @@ static int i2c_pca_pf_probe(struct platform_device *pdev)
struct resource *res;
struct i2c_pca9564_pf_platform_data *platform_data =
dev_get_platdata(&pdev->dev);
+ struct device_node *np = pdev->dev.of_node;
int ret = 0;
int irq;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
irq = platform_get_irq(pdev, 0);
/* If irq is 0, we do polling. */
+ if (irq < 0)
+ irq = 0;
if (res == NULL) {
ret = -ENODEV;
@@ -177,11 +183,17 @@ static int i2c_pca_pf_probe(struct platform_device *pdev)
(unsigned long) res->start);
i2c->adap.algo_data = &i2c->algo_data;
i2c->adap.dev.parent = &pdev->dev;
+ i2c->adap.dev.of_node = np;
if (platform_data) {
i2c->adap.timeout = platform_data->timeout;
i2c->algo_data.i2c_clock = platform_data->i2c_clock_speed;
i2c->gpio = platform_data->gpio;
+ } else if (np) {
+ i2c->adap.timeout = HZ;
+ i2c->gpio = of_get_named_gpio(np, "reset-gpios", 0);
+ of_property_read_u32_index(np, "clock-frequency", 0,
+ &i2c->algo_data.i2c_clock);
} else {
i2c->adap.timeout = HZ;
i2c->algo_data.i2c_clock = 59000;
@@ -275,11 +287,21 @@ static int i2c_pca_pf_remove(struct platform_device *pdev)
return 0;
}
+#ifdef CONFIG_OF
+static const struct of_device_id i2c_pca_of_match_table[] = {
+ { .compatible = "nxp,pca9564" },
+ { .compatible = "nxp,pca9665" },
+ {},
+};
+MODULE_DEVICE_TABLE(of, i2c_pca_of_match_table);
+#endif
+
static struct platform_driver i2c_pca_pf_driver = {
.probe = i2c_pca_pf_probe,
.remove = i2c_pca_pf_remove,
.driver = {
.name = "i2c-pca-platform",
+ .of_match_table = of_match_ptr(i2c_pca_of_match_table),
},
};
--
2.13.0
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [PATCH v2 3/5] i2c: pca-platform: use gpio_is_valid
2017-06-20 1:18 [PATCH v2 0/5] i2c: pca-platform: updates Chris Packham
2017-06-20 1:18 ` [PATCH v2 1/5] dt-bindings: add bindings for i2c-pca-platform Chris Packham
2017-06-20 1:18 ` [PATCH v2 2/5] i2c: pca-platform: add devicetree awareness Chris Packham
@ 2017-06-20 1:18 ` Chris Packham
2017-06-20 1:18 ` [PATCH v2 4/5] i2c: pca-platform: use device managed allocations Chris Packham
` (2 subsequent siblings)
5 siblings, 0 replies; 36+ messages in thread
From: Chris Packham @ 2017-06-20 1:18 UTC (permalink / raw)
To: wsa, robh+dt, linux-i2c, devicetree; +Cc: linux-kernel, Chris Packham
Use gpio_is_valid() instead of gpio > -1.
Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
---
drivers/i2c/busses/i2c-pca-platform.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/drivers/i2c/busses/i2c-pca-platform.c b/drivers/i2c/busses/i2c-pca-platform.c
index 87ca2f02f607..3a9845bae9a4 100644
--- a/drivers/i2c/busses/i2c-pca-platform.c
+++ b/drivers/i2c/busses/i2c-pca-platform.c
@@ -197,7 +197,7 @@ static int i2c_pca_pf_probe(struct platform_device *pdev)
} else {
i2c->adap.timeout = HZ;
i2c->algo_data.i2c_clock = 59000;
- i2c->gpio = -1;
+ i2c->gpio = -ENODEV;
}
i2c->algo_data.data = i2c;
@@ -220,8 +220,7 @@ static int i2c_pca_pf_probe(struct platform_device *pdev)
break;
}
- /* Use gpio_is_valid() when in mainline */
- if (i2c->gpio > -1) {
+ if (gpio_is_valid(i2c->gpio)) {
ret = gpio_request(i2c->gpio, i2c->adap.name);
if (ret == 0) {
gpio_direction_output(i2c->gpio, 1);
@@ -255,7 +254,7 @@ static int i2c_pca_pf_probe(struct platform_device *pdev)
if (irq)
free_irq(irq, i2c);
e_reqirq:
- if (i2c->gpio > -1)
+ if (gpio_is_valid(i2c->gpio))
gpio_free(i2c->gpio);
iounmap(i2c->reg_base);
@@ -277,7 +276,7 @@ static int i2c_pca_pf_remove(struct platform_device *pdev)
if (i2c->irq)
free_irq(i2c->irq, i2c);
- if (i2c->gpio > -1)
+ if (gpio_is_valid(i2c->gpio))
gpio_free(i2c->gpio);
iounmap(i2c->reg_base);
--
2.13.0
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [PATCH v2 4/5] i2c: pca-platform: use device managed allocations
2017-06-20 1:18 [PATCH v2 0/5] i2c: pca-platform: updates Chris Packham
` (2 preceding siblings ...)
2017-06-20 1:18 ` [PATCH v2 3/5] i2c: pca-platform: use gpio_is_valid Chris Packham
@ 2017-06-20 1:18 ` Chris Packham
2017-06-20 1:18 ` [PATCH v2 5/5] i2c: pca-platform: use dev_warn/dev_info instead of printk Chris Packham
2017-06-26 0:44 ` [PATCH v3 0/5] i2c: pca-platform: updates Chris Packham
5 siblings, 0 replies; 36+ messages in thread
From: Chris Packham @ 2017-06-20 1:18 UTC (permalink / raw)
To: wsa, robh+dt, linux-i2c, devicetree; +Cc: linux-kernel, Chris Packham
Switch to using the devm_ APIs and remove the now unnecessary error
handling and most of the device removal code.
Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
---
drivers/i2c/busses/i2c-pca-platform.c | 61 +++++++----------------------------
1 file changed, 11 insertions(+), 50 deletions(-)
diff --git a/drivers/i2c/busses/i2c-pca-platform.c b/drivers/i2c/busses/i2c-pca-platform.c
index 3a9845bae9a4..12ab0cafa7c9 100644
--- a/drivers/i2c/busses/i2c-pca-platform.c
+++ b/drivers/i2c/busses/i2c-pca-platform.c
@@ -143,35 +143,23 @@ static int i2c_pca_pf_probe(struct platform_device *pdev)
int ret = 0;
int irq;
- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
irq = platform_get_irq(pdev, 0);
/* If irq is 0, we do polling. */
if (irq < 0)
irq = 0;
- if (res == NULL) {
- ret = -ENODEV;
- goto e_print;
- }
+ i2c = devm_kzalloc(&pdev->dev, sizeof(*i2c), GFP_KERNEL);
+ if (!i2c)
+ return -ENOMEM;
- if (!request_mem_region(res->start, resource_size(res), res->name)) {
- ret = -ENOMEM;
- goto e_print;
- }
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ i2c->reg_base = devm_ioremap_resource(&pdev->dev, res);
+ if (IS_ERR(i2c->reg_base))
+ return PTR_ERR(i2c->reg_base);
- i2c = kzalloc(sizeof(struct i2c_pca_pf_data), GFP_KERNEL);
- if (!i2c) {
- ret = -ENOMEM;
- goto e_alloc;
- }
init_waitqueue_head(&i2c->wait);
- i2c->reg_base = ioremap(res->start, resource_size(res));
- if (!i2c->reg_base) {
- ret = -ENOMEM;
- goto e_remap;
- }
i2c->io_base = res->start;
i2c->io_size = resource_size(res);
i2c->irq = irq;
@@ -221,7 +209,7 @@ static int i2c_pca_pf_probe(struct platform_device *pdev)
}
if (gpio_is_valid(i2c->gpio)) {
- ret = gpio_request(i2c->gpio, i2c->adap.name);
+ ret = devm_gpio_request(&pdev->dev, i2c->gpio, i2c->adap.name);
if (ret == 0) {
gpio_direction_output(i2c->gpio, 1);
i2c->algo_data.reset_chip = i2c_pca_pf_resetchip;
@@ -233,15 +221,14 @@ static int i2c_pca_pf_probe(struct platform_device *pdev)
}
if (irq) {
- ret = request_irq(irq, i2c_pca_pf_handler,
+ ret = devm_request_irq(&pdev->dev, irq, i2c_pca_pf_handler,
IRQF_TRIGGER_FALLING, pdev->name, i2c);
if (ret)
- goto e_reqirq;
+ return ret;
}
if (i2c_pca_add_numbered_bus(&i2c->adap) < 0) {
- ret = -ENODEV;
- goto e_adapt;
+ return -ENODEV;
}
platform_set_drvdata(pdev, i2c);
@@ -249,22 +236,6 @@ static int i2c_pca_pf_probe(struct platform_device *pdev)
printk(KERN_INFO "%s registered.\n", i2c->adap.name);
return 0;
-
-e_adapt:
- if (irq)
- free_irq(irq, i2c);
-e_reqirq:
- if (gpio_is_valid(i2c->gpio))
- gpio_free(i2c->gpio);
-
- iounmap(i2c->reg_base);
-e_remap:
- kfree(i2c);
-e_alloc:
- release_mem_region(res->start, resource_size(res));
-e_print:
- printk(KERN_ERR "Registering PCA9564/PCA9665 FAILED! (%d)\n", ret);
- return ret;
}
static int i2c_pca_pf_remove(struct platform_device *pdev)
@@ -273,16 +244,6 @@ static int i2c_pca_pf_remove(struct platform_device *pdev)
i2c_del_adapter(&i2c->adap);
- if (i2c->irq)
- free_irq(i2c->irq, i2c);
-
- if (gpio_is_valid(i2c->gpio))
- gpio_free(i2c->gpio);
-
- iounmap(i2c->reg_base);
- release_mem_region(i2c->io_base, i2c->io_size);
- kfree(i2c);
-
return 0;
}
--
2.13.0
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [PATCH v2 5/5] i2c: pca-platform: use dev_warn/dev_info instead of printk
2017-06-20 1:18 [PATCH v2 0/5] i2c: pca-platform: updates Chris Packham
` (3 preceding siblings ...)
2017-06-20 1:18 ` [PATCH v2 4/5] i2c: pca-platform: use device managed allocations Chris Packham
@ 2017-06-20 1:18 ` Chris Packham
2017-06-26 0:44 ` [PATCH v3 0/5] i2c: pca-platform: updates Chris Packham
5 siblings, 0 replies; 36+ messages in thread
From: Chris Packham @ 2017-06-20 1:18 UTC (permalink / raw)
To: wsa, robh+dt, linux-i2c, devicetree; +Cc: linux-kernel, Chris Packham
Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
---
drivers/i2c/busses/i2c-pca-platform.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/drivers/i2c/busses/i2c-pca-platform.c b/drivers/i2c/busses/i2c-pca-platform.c
index 12ab0cafa7c9..27175d681548 100644
--- a/drivers/i2c/busses/i2c-pca-platform.c
+++ b/drivers/i2c/busses/i2c-pca-platform.c
@@ -107,8 +107,8 @@ static int i2c_pca_pf_waitforcompletion(void *pd)
static void i2c_pca_pf_dummyreset(void *pd)
{
struct i2c_pca_pf_data *i2c = pd;
- printk(KERN_WARNING "%s: No reset-pin found. Chip may get stuck!\n",
- i2c->adap.name);
+
+ dev_warn(&i2c->adap.dev, "No reset-pin found. Chip may get stuck!\n");
}
static void i2c_pca_pf_resetchip(void *pd)
@@ -214,8 +214,7 @@ static int i2c_pca_pf_probe(struct platform_device *pdev)
gpio_direction_output(i2c->gpio, 1);
i2c->algo_data.reset_chip = i2c_pca_pf_resetchip;
} else {
- printk(KERN_WARNING "%s: Registering gpio failed!\n",
- i2c->adap.name);
+ dev_warn(&pdev->dev, "Registering gpio failed!\n");
i2c->gpio = ret;
}
}
@@ -233,7 +232,7 @@ static int i2c_pca_pf_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, i2c);
- printk(KERN_INFO "%s registered.\n", i2c->adap.name);
+ dev_info(&pdev->dev, "registered.\n");
return 0;
}
--
2.13.0
^ permalink raw reply related [flat|nested] 36+ messages in thread
* Re: [PATCH v2 1/5] dt-bindings: add bindings for i2c-pca-platform
2017-06-20 1:18 ` [PATCH v2 1/5] dt-bindings: add bindings for i2c-pca-platform Chris Packham
@ 2017-06-22 8:22 ` Wolfram Sang
2017-06-22 21:20 ` Chris Packham
0 siblings, 1 reply; 36+ messages in thread
From: Wolfram Sang @ 2017-06-22 8:22 UTC (permalink / raw)
To: Chris Packham; +Cc: robh+dt, linux-i2c, devicetree, linux-kernel, Mark Rutland
[-- Attachment #1: Type: text/plain, Size: 142 bytes --]
> + - reset-gpios : gpio specifier for gpio connected to RESET_N pin.
What about the 'active' state that Rob mentioned in his last review?
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH v2 1/5] dt-bindings: add bindings for i2c-pca-platform
2017-06-22 8:22 ` Wolfram Sang
@ 2017-06-22 21:20 ` Chris Packham
2017-06-23 8:17 ` Wolfram Sang
2017-06-23 21:41 ` Rob Herring
0 siblings, 2 replies; 36+ messages in thread
From: Chris Packham @ 2017-06-22 21:20 UTC (permalink / raw)
To: Wolfram Sang; +Cc: robh+dt, linux-i2c, devicetree, linux-kernel, Mark Rutland
On 22/06/17 20:23, Wolfram Sang wrote:
>
>> + - reset-gpios : gpio specifier for gpio connected to RESET_N pin.
>
> What about the 'active' state that Rob mentioned in his last review?
>
My intention was that by saying it is connected to the RESET_N bin the
active state is covered.
I personally always get a little confused when talking about reset
lines. The _N denotes that the line is active low but because it is a
reset line writing 1 releases the reset so from a what-the-user-wants
perspective it's active high.
dt-binding-wise what we want here is GPIO_ACTIVE_HIGH, as in the driver
writes 1 to release reset so don't do any polarity inversion. I'd be
happy do add something to that effect in a v3 but I actually felt saying
the gpio is connected to RESET_N was less ambiguous.
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH v2 1/5] dt-bindings: add bindings for i2c-pca-platform
2017-06-22 21:20 ` Chris Packham
@ 2017-06-23 8:17 ` Wolfram Sang
2017-06-23 21:41 ` Rob Herring
1 sibling, 0 replies; 36+ messages in thread
From: Wolfram Sang @ 2017-06-23 8:17 UTC (permalink / raw)
To: Chris Packham; +Cc: robh+dt, linux-i2c, devicetree, linux-kernel, Mark Rutland
[-- Attachment #1: Type: text/plain, Size: 1021 bytes --]
On Thu, Jun 22, 2017 at 09:20:59PM +0000, Chris Packham wrote:
> On 22/06/17 20:23, Wolfram Sang wrote:
> >
> >> + - reset-gpios : gpio specifier for gpio connected to RESET_N pin.
> >
> > What about the 'active' state that Rob mentioned in his last review?
> >
>
> My intention was that by saying it is connected to the RESET_N bin the
> active state is covered.
>
> I personally always get a little confused when talking about reset
> lines. The _N denotes that the line is active low but because it is a
> reset line writing 1 releases the reset so from a what-the-user-wants
> perspective it's active high.
>
> dt-binding-wise what we want here is GPIO_ACTIVE_HIGH, as in the driver
> writes 1 to release reset so don't do any polarity inversion. I'd be
> happy do add something to that effect in a v3 but I actually felt saying
> the gpio is connected to RESET_N was less ambiguous.
Okay. Thanks for the explanation. I am fine with it but I'll leave the
final decision to Rob.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH v2 1/5] dt-bindings: add bindings for i2c-pca-platform
2017-06-22 21:20 ` Chris Packham
2017-06-23 8:17 ` Wolfram Sang
@ 2017-06-23 21:41 ` Rob Herring
1 sibling, 0 replies; 36+ messages in thread
From: Rob Herring @ 2017-06-23 21:41 UTC (permalink / raw)
To: Chris Packham
Cc: Wolfram Sang, linux-i2c, devicetree, linux-kernel, Mark Rutland
On Thu, Jun 22, 2017 at 09:20:59PM +0000, Chris Packham wrote:
> On 22/06/17 20:23, Wolfram Sang wrote:
> >
> >> + - reset-gpios : gpio specifier for gpio connected to RESET_N pin.
> >
> > What about the 'active' state that Rob mentioned in his last review?
> >
>
> My intention was that by saying it is connected to the RESET_N bin the
> active state is covered.
I would say okay, but based on below it's not.
> I personally always get a little confused when talking about reset
> lines. The _N denotes that the line is active low but because it is a
> reset line writing 1 releases the reset so from a what-the-user-wants
> perspective it's active high.
>
> dt-binding-wise what we want here is GPIO_ACTIVE_HIGH, as in the driver
> writes 1 to release reset so don't do any polarity inversion. I'd be
> happy do add something to that effect in a v3 but I actually felt saying
> the gpio is connected to RESET_N was less ambiguous.
No, the driver is wrong. The binding should say GPIO_ACTIVE_LOW because
that is how the pin is defined. The driver needs to set it to inactive.
Rob
^ permalink raw reply [flat|nested] 36+ messages in thread
* [PATCH v3 0/5] i2c: pca-platform: updates
2017-06-20 1:18 [PATCH v2 0/5] i2c: pca-platform: updates Chris Packham
` (4 preceding siblings ...)
2017-06-20 1:18 ` [PATCH v2 5/5] i2c: pca-platform: use dev_warn/dev_info instead of printk Chris Packham
@ 2017-06-26 0:44 ` Chris Packham
2017-06-26 0:44 ` [PATCH v3 1/5] dt-bindings: add bindings for i2c-pca-platform Chris Packham
` (4 more replies)
5 siblings, 5 replies; 36+ messages in thread
From: Chris Packham @ 2017-06-26 0:44 UTC (permalink / raw)
To: wsa, robh+dt, linux-i2c; +Cc: linux-kernel, Chris Packham
We're using a PCA9564 on an embedded platform to provide an i2c
controller. This adds devicetree support and I've included some
cleanups for the driver while I was at it.
Chris Packham (5):
dt-bindings: add bindings for i2c-pca-platform
i2c: pca-platform: switch to struct gpio_desc
i2c: pca-platform: add devicetree awareness
i2c: pca-platform: use device managed allocations
i2c: pca-platform: use dev_warn/dev_info instead of printk
.../devicetree/bindings/i2c/i2c-pca-platform.txt | 29 +++++
drivers/i2c/busses/i2c-pca-platform.c | 125 +++++++++------------
2 files changed, 84 insertions(+), 70 deletions(-)
create mode 100644 Documentation/devicetree/bindings/i2c/i2c-pca-platform.txt
--
2.13.0
^ permalink raw reply [flat|nested] 36+ messages in thread
* [PATCH v3 1/5] dt-bindings: add bindings for i2c-pca-platform
2017-06-26 0:44 ` [PATCH v3 0/5] i2c: pca-platform: updates Chris Packham
@ 2017-06-26 0:44 ` Chris Packham
2017-06-26 14:06 ` Rob Herring
2017-06-27 19:53 ` Wolfram Sang
2017-06-26 0:44 ` [PATCH v3 2/5] i2c: pca-platform: switch to struct gpio_desc Chris Packham
` (3 subsequent siblings)
4 siblings, 2 replies; 36+ messages in thread
From: Chris Packham @ 2017-06-26 0:44 UTC (permalink / raw)
To: wsa, robh+dt, linux-i2c
Cc: linux-kernel, Chris Packham, Mark Rutland, devicetree
Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
---
Changes in v2:
- Split dt-binding to separate patch, use "reset-gpios" instead of "gpios".
Changes in v3:
- State the gpio is active low
- Add example
.../devicetree/bindings/i2c/i2c-pca-platform.txt | 29 ++++++++++++++++++++++
1 file changed, 29 insertions(+)
create mode 100644 Documentation/devicetree/bindings/i2c/i2c-pca-platform.txt
diff --git a/Documentation/devicetree/bindings/i2c/i2c-pca-platform.txt b/Documentation/devicetree/bindings/i2c/i2c-pca-platform.txt
new file mode 100644
index 000000000000..f1f3876bb8e8
--- /dev/null
+++ b/Documentation/devicetree/bindings/i2c/i2c-pca-platform.txt
@@ -0,0 +1,29 @@
+* NXP PCA PCA9564/PCA9665 I2C controller
+
+The PCA9564/PCA9665 serves as an interface between most standard
+parallel-bus microcontrollers/microprocessors and the serial I2C-bus
+and allows the parallel bus system to communicate bi-directionally
+with the I2C-bus.
+
+Required properties :
+
+ - reg : Offset and length of the register set for the device
+ - compatible : one of "nxp,pca9564" or "nxp,pca9665"
+
+Optional properties
+ - interrupts : the interrupt number
+ - interrupt-parent : the phandle for the interrupt controller.
+ If an interrupt is not specified polling will be used.
+ - reset-gpios : gpio specifier for gpio connected to RESET_N pin. As the line
+ is active low, it should be marked GPIO_ACTIVE_LOW.
+ - clock-frequency : I2C bus frequency.
+
+Example:
+ i2c0: i2c@80000 {
+ compatible = "nxp,pca9564";
+ #address-cells = <1>;
+ #size-cells = <0>;
+ reg = <0x80000 0x4>;
+ reset-gpios = <&gpio1 0 GPIO_ACTIVE_LOW>;
+ clock-frequency = <100000>;
+ };
--
2.13.0
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [PATCH v3 2/5] i2c: pca-platform: switch to struct gpio_desc
2017-06-26 0:44 ` [PATCH v3 0/5] i2c: pca-platform: updates Chris Packham
2017-06-26 0:44 ` [PATCH v3 1/5] dt-bindings: add bindings for i2c-pca-platform Chris Packham
@ 2017-06-26 0:44 ` Chris Packham
2017-06-27 19:53 ` Wolfram Sang
2017-06-28 9:25 ` Andy Shevchenko
2017-06-26 0:44 ` [PATCH v3 3/5] i2c: pca-platform: add devicetree awareness Chris Packham
` (2 subsequent siblings)
4 siblings, 2 replies; 36+ messages in thread
From: Chris Packham @ 2017-06-26 0:44 UTC (permalink / raw)
To: wsa, robh+dt, linux-i2c; +Cc: linux-kernel, Chris Packham
Make use of struct gpio_desc which allows us to specify the active state
of the reset pin.
Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
---
Changes in v3:
- New, replaces "i2c: pca-platform: use gpio_is_valid"
- Using struct gpio_desc is required to make the flags stick. Because those
flags now correctly indicate that RESET_N is active low, the logic for
resetting the chip is inverted.
drivers/i2c/busses/i2c-pca-platform.c | 43 ++++++++++++++++-------------------
1 file changed, 19 insertions(+), 24 deletions(-)
diff --git a/drivers/i2c/busses/i2c-pca-platform.c b/drivers/i2c/busses/i2c-pca-platform.c
index 3bd2e7d06e4b..9f995b8ed587 100644
--- a/drivers/i2c/busses/i2c-pca-platform.c
+++ b/drivers/i2c/busses/i2c-pca-platform.c
@@ -22,6 +22,7 @@
#include <linux/i2c-algo-pca.h>
#include <linux/i2c-pca-platform.h>
#include <linux/gpio.h>
+#include <linux/gpio/consumer.h>
#include <linux/io.h>
#include <asm/irq.h>
@@ -29,7 +30,7 @@
struct i2c_pca_pf_data {
void __iomem *reg_base;
int irq; /* if 0, use polling */
- int gpio;
+ struct gpio_desc *gpio;
wait_queue_head_t wait;
struct i2c_adapter adap;
struct i2c_algo_pca_data algo_data;
@@ -112,9 +113,9 @@ static void i2c_pca_pf_resetchip(void *pd)
{
struct i2c_pca_pf_data *i2c = pd;
- gpio_set_value(i2c->gpio, 0);
+ gpiod_set_value(i2c->gpio, 1);
ndelay(100);
- gpio_set_value(i2c->gpio, 1);
+ gpiod_set_value(i2c->gpio, 0);
}
static irqreturn_t i2c_pca_pf_handler(int this_irq, void *dev_id)
@@ -181,11 +182,24 @@ static int i2c_pca_pf_probe(struct platform_device *pdev)
if (platform_data) {
i2c->adap.timeout = platform_data->timeout;
i2c->algo_data.i2c_clock = platform_data->i2c_clock_speed;
- i2c->gpio = platform_data->gpio;
+ if (gpio_is_valid(platform_data->gpio)) {
+ ret = devm_gpio_request_one(&pdev->dev,
+ platform_data->gpio,
+ GPIOF_ACTIVE_LOW,
+ i2c->adap.name);
+ if (ret == 0) {
+ i2c->gpio = gpio_to_desc(platform_data->gpio);
+ gpiod_direction_output(i2c->gpio, 0);
+ i2c->algo_data.reset_chip = i2c_pca_pf_resetchip;
+ } else {
+ dev_warn(&pdev->dev, "Registering gpio failed!\n");
+ i2c->gpio = NULL;
+ }
+ }
} else {
i2c->adap.timeout = HZ;
i2c->algo_data.i2c_clock = 59000;
- i2c->gpio = -1;
+ i2c->gpio = NULL;
}
i2c->algo_data.data = i2c;
@@ -208,19 +222,6 @@ static int i2c_pca_pf_probe(struct platform_device *pdev)
break;
}
- /* Use gpio_is_valid() when in mainline */
- if (i2c->gpio > -1) {
- ret = gpio_request(i2c->gpio, i2c->adap.name);
- if (ret == 0) {
- gpio_direction_output(i2c->gpio, 1);
- i2c->algo_data.reset_chip = i2c_pca_pf_resetchip;
- } else {
- printk(KERN_WARNING "%s: Registering gpio failed!\n",
- i2c->adap.name);
- i2c->gpio = ret;
- }
- }
-
if (irq) {
ret = request_irq(irq, i2c_pca_pf_handler,
IRQF_TRIGGER_FALLING, pdev->name, i2c);
@@ -243,9 +244,6 @@ static int i2c_pca_pf_probe(struct platform_device *pdev)
if (irq)
free_irq(irq, i2c);
e_reqirq:
- if (i2c->gpio > -1)
- gpio_free(i2c->gpio);
-
iounmap(i2c->reg_base);
e_remap:
kfree(i2c);
@@ -265,9 +263,6 @@ static int i2c_pca_pf_remove(struct platform_device *pdev)
if (i2c->irq)
free_irq(i2c->irq, i2c);
- if (i2c->gpio > -1)
- gpio_free(i2c->gpio);
-
iounmap(i2c->reg_base);
release_mem_region(i2c->io_base, i2c->io_size);
kfree(i2c);
--
2.13.0
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [PATCH v3 3/5] i2c: pca-platform: add devicetree awareness
2017-06-26 0:44 ` [PATCH v3 0/5] i2c: pca-platform: updates Chris Packham
2017-06-26 0:44 ` [PATCH v3 1/5] dt-bindings: add bindings for i2c-pca-platform Chris Packham
2017-06-26 0:44 ` [PATCH v3 2/5] i2c: pca-platform: switch to struct gpio_desc Chris Packham
@ 2017-06-26 0:44 ` Chris Packham
2017-06-27 19:55 ` Wolfram Sang
2017-06-28 9:20 ` Andy Shevchenko
2017-06-26 0:44 ` [PATCH v3 4/5] i2c: pca-platform: use device managed allocations Chris Packham
2017-06-26 0:44 ` [PATCH v3 5/5] i2c: pca-platform: use dev_warn/dev_info instead of printk Chris Packham
4 siblings, 2 replies; 36+ messages in thread
From: Chris Packham @ 2017-06-26 0:44 UTC (permalink / raw)
To: wsa, robh+dt, linux-i2c; +Cc: linux-kernel, Chris Packham
Allow devices that use this driver to be registered via a
devicetree.
Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
---
Changes in v2:
- Set i2c->adap.dev.of_node so that child nodes are automatically probed
- Split dt-binding to separate patch, use "reset-gpios" instead of "gpios".
Changes in v3:
- None
drivers/i2c/busses/i2c-pca-platform.c | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/drivers/i2c/busses/i2c-pca-platform.c b/drivers/i2c/busses/i2c-pca-platform.c
index 9f995b8ed587..a6df6b8d2289 100644
--- a/drivers/i2c/busses/i2c-pca-platform.c
+++ b/drivers/i2c/busses/i2c-pca-platform.c
@@ -24,6 +24,8 @@
#include <linux/gpio.h>
#include <linux/gpio/consumer.h>
#include <linux/io.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
#include <asm/irq.h>
@@ -137,12 +139,15 @@ static int i2c_pca_pf_probe(struct platform_device *pdev)
struct resource *res;
struct i2c_pca9564_pf_platform_data *platform_data =
dev_get_platdata(&pdev->dev);
+ struct device_node *np = pdev->dev.of_node;
int ret = 0;
int irq;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
irq = platform_get_irq(pdev, 0);
/* If irq is 0, we do polling. */
+ if (irq < 0)
+ irq = 0;
if (res == NULL) {
ret = -ENODEV;
@@ -178,6 +183,7 @@ static int i2c_pca_pf_probe(struct platform_device *pdev)
(unsigned long) res->start);
i2c->adap.algo_data = &i2c->algo_data;
i2c->adap.dev.parent = &pdev->dev;
+ i2c->adap.dev.of_node = np;
if (platform_data) {
i2c->adap.timeout = platform_data->timeout;
@@ -196,6 +202,13 @@ static int i2c_pca_pf_probe(struct platform_device *pdev)
i2c->gpio = NULL;
}
}
+ } else if (np) {
+ i2c->adap.timeout = HZ;
+ i2c->gpio = devm_gpiod_get_optional(&pdev->dev, "reset-gpios", GPIOD_OUT_LOW);
+ if (IS_ERR(i2c->gpio))
+ return PTR_ERR(i2c->gpio);
+ of_property_read_u32_index(np, "clock-frequency", 0,
+ &i2c->algo_data.i2c_clock);
} else {
i2c->adap.timeout = HZ;
i2c->algo_data.i2c_clock = 59000;
@@ -270,11 +283,21 @@ static int i2c_pca_pf_remove(struct platform_device *pdev)
return 0;
}
+#ifdef CONFIG_OF
+static const struct of_device_id i2c_pca_of_match_table[] = {
+ { .compatible = "nxp,pca9564" },
+ { .compatible = "nxp,pca9665" },
+ {},
+};
+MODULE_DEVICE_TABLE(of, i2c_pca_of_match_table);
+#endif
+
static struct platform_driver i2c_pca_pf_driver = {
.probe = i2c_pca_pf_probe,
.remove = i2c_pca_pf_remove,
.driver = {
.name = "i2c-pca-platform",
+ .of_match_table = of_match_ptr(i2c_pca_of_match_table),
},
};
--
2.13.0
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [PATCH v3 4/5] i2c: pca-platform: use device managed allocations
2017-06-26 0:44 ` [PATCH v3 0/5] i2c: pca-platform: updates Chris Packham
` (2 preceding siblings ...)
2017-06-26 0:44 ` [PATCH v3 3/5] i2c: pca-platform: add devicetree awareness Chris Packham
@ 2017-06-26 0:44 ` Chris Packham
2017-06-27 19:55 ` Wolfram Sang
2017-06-28 9:23 ` Andy Shevchenko
2017-06-26 0:44 ` [PATCH v3 5/5] i2c: pca-platform: use dev_warn/dev_info instead of printk Chris Packham
4 siblings, 2 replies; 36+ messages in thread
From: Chris Packham @ 2017-06-26 0:44 UTC (permalink / raw)
To: wsa, robh+dt, linux-i2c; +Cc: linux-kernel, Chris Packham
Switch to using the devm_ APIs and remove the now unnecessary error
handling and most of the device removal code.
Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
---
drivers/i2c/busses/i2c-pca-platform.c | 53 +++++++----------------------------
1 file changed, 10 insertions(+), 43 deletions(-)
diff --git a/drivers/i2c/busses/i2c-pca-platform.c b/drivers/i2c/busses/i2c-pca-platform.c
index a6df6b8d2289..7db481cbf402 100644
--- a/drivers/i2c/busses/i2c-pca-platform.c
+++ b/drivers/i2c/busses/i2c-pca-platform.c
@@ -143,35 +143,23 @@ static int i2c_pca_pf_probe(struct platform_device *pdev)
int ret = 0;
int irq;
- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
irq = platform_get_irq(pdev, 0);
/* If irq is 0, we do polling. */
if (irq < 0)
irq = 0;
- if (res == NULL) {
- ret = -ENODEV;
- goto e_print;
- }
+ i2c = devm_kzalloc(&pdev->dev, sizeof(*i2c), GFP_KERNEL);
+ if (!i2c)
+ return -ENOMEM;
- if (!request_mem_region(res->start, resource_size(res), res->name)) {
- ret = -ENOMEM;
- goto e_print;
- }
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ i2c->reg_base = devm_ioremap_resource(&pdev->dev, res);
+ if (IS_ERR(i2c->reg_base))
+ return PTR_ERR(i2c->reg_base);
- i2c = kzalloc(sizeof(struct i2c_pca_pf_data), GFP_KERNEL);
- if (!i2c) {
- ret = -ENOMEM;
- goto e_alloc;
- }
init_waitqueue_head(&i2c->wait);
- i2c->reg_base = ioremap(res->start, resource_size(res));
- if (!i2c->reg_base) {
- ret = -ENOMEM;
- goto e_remap;
- }
i2c->io_base = res->start;
i2c->io_size = resource_size(res);
i2c->irq = irq;
@@ -236,15 +224,14 @@ static int i2c_pca_pf_probe(struct platform_device *pdev)
}
if (irq) {
- ret = request_irq(irq, i2c_pca_pf_handler,
+ ret = devm_request_irq(&pdev->dev, irq, i2c_pca_pf_handler,
IRQF_TRIGGER_FALLING, pdev->name, i2c);
if (ret)
- goto e_reqirq;
+ return ret;
}
if (i2c_pca_add_numbered_bus(&i2c->adap) < 0) {
- ret = -ENODEV;
- goto e_adapt;
+ return -ENODEV;
}
platform_set_drvdata(pdev, i2c);
@@ -252,19 +239,6 @@ static int i2c_pca_pf_probe(struct platform_device *pdev)
printk(KERN_INFO "%s registered.\n", i2c->adap.name);
return 0;
-
-e_adapt:
- if (irq)
- free_irq(irq, i2c);
-e_reqirq:
- iounmap(i2c->reg_base);
-e_remap:
- kfree(i2c);
-e_alloc:
- release_mem_region(res->start, resource_size(res));
-e_print:
- printk(KERN_ERR "Registering PCA9564/PCA9665 FAILED! (%d)\n", ret);
- return ret;
}
static int i2c_pca_pf_remove(struct platform_device *pdev)
@@ -273,13 +247,6 @@ static int i2c_pca_pf_remove(struct platform_device *pdev)
i2c_del_adapter(&i2c->adap);
- if (i2c->irq)
- free_irq(i2c->irq, i2c);
-
- iounmap(i2c->reg_base);
- release_mem_region(i2c->io_base, i2c->io_size);
- kfree(i2c);
-
return 0;
}
--
2.13.0
^ permalink raw reply related [flat|nested] 36+ messages in thread
* [PATCH v3 5/5] i2c: pca-platform: use dev_warn/dev_info instead of printk
2017-06-26 0:44 ` [PATCH v3 0/5] i2c: pca-platform: updates Chris Packham
` (3 preceding siblings ...)
2017-06-26 0:44 ` [PATCH v3 4/5] i2c: pca-platform: use device managed allocations Chris Packham
@ 2017-06-26 0:44 ` Chris Packham
2017-06-27 19:55 ` Wolfram Sang
2017-06-28 9:28 ` Andy Shevchenko
4 siblings, 2 replies; 36+ messages in thread
From: Chris Packham @ 2017-06-26 0:44 UTC (permalink / raw)
To: wsa, robh+dt, linux-i2c; +Cc: linux-kernel, Chris Packham
Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
---
drivers/i2c/busses/i2c-pca-platform.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/i2c/busses/i2c-pca-platform.c b/drivers/i2c/busses/i2c-pca-platform.c
index 7db481cbf402..395eca0cbb1f 100644
--- a/drivers/i2c/busses/i2c-pca-platform.c
+++ b/drivers/i2c/busses/i2c-pca-platform.c
@@ -107,8 +107,8 @@ static int i2c_pca_pf_waitforcompletion(void *pd)
static void i2c_pca_pf_dummyreset(void *pd)
{
struct i2c_pca_pf_data *i2c = pd;
- printk(KERN_WARNING "%s: No reset-pin found. Chip may get stuck!\n",
- i2c->adap.name);
+
+ dev_warn(&i2c->adap.dev, "No reset-pin found. Chip may get stuck!\n");
}
static void i2c_pca_pf_resetchip(void *pd)
@@ -236,7 +236,7 @@ static int i2c_pca_pf_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, i2c);
- printk(KERN_INFO "%s registered.\n", i2c->adap.name);
+ dev_info(&pdev->dev, "registered.\n");
return 0;
}
--
2.13.0
^ permalink raw reply related [flat|nested] 36+ messages in thread
* Re: [PATCH v3 1/5] dt-bindings: add bindings for i2c-pca-platform
2017-06-26 0:44 ` [PATCH v3 1/5] dt-bindings: add bindings for i2c-pca-platform Chris Packham
@ 2017-06-26 14:06 ` Rob Herring
2017-06-27 19:53 ` Wolfram Sang
1 sibling, 0 replies; 36+ messages in thread
From: Rob Herring @ 2017-06-26 14:06 UTC (permalink / raw)
To: Chris Packham; +Cc: wsa, linux-i2c, linux-kernel, Mark Rutland, devicetree
On Sun, Jun 25, 2017 at 7:44 PM, Chris Packham
<chris.packham@alliedtelesis.co.nz> wrote:
> Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
> ---
> Changes in v2:
> - Split dt-binding to separate patch, use "reset-gpios" instead of "gpios".
> Changes in v3:
> - State the gpio is active low
> - Add example
>
> .../devicetree/bindings/i2c/i2c-pca-platform.txt | 29 ++++++++++++++++++++++
> 1 file changed, 29 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/i2c/i2c-pca-platform.txt
Acked-by: Rob Herring <robh@kernel.org>
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH v3 1/5] dt-bindings: add bindings for i2c-pca-platform
2017-06-26 0:44 ` [PATCH v3 1/5] dt-bindings: add bindings for i2c-pca-platform Chris Packham
2017-06-26 14:06 ` Rob Herring
@ 2017-06-27 19:53 ` Wolfram Sang
1 sibling, 0 replies; 36+ messages in thread
From: Wolfram Sang @ 2017-06-27 19:53 UTC (permalink / raw)
To: Chris Packham; +Cc: robh+dt, linux-i2c, linux-kernel, Mark Rutland, devicetree
[-- Attachment #1: Type: text/plain, Size: 161 bytes --]
On Mon, Jun 26, 2017 at 12:44:30PM +1200, Chris Packham wrote:
> Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
Applied to for-next, thanks!
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH v3 2/5] i2c: pca-platform: switch to struct gpio_desc
2017-06-26 0:44 ` [PATCH v3 2/5] i2c: pca-platform: switch to struct gpio_desc Chris Packham
@ 2017-06-27 19:53 ` Wolfram Sang
2017-06-28 9:25 ` Andy Shevchenko
1 sibling, 0 replies; 36+ messages in thread
From: Wolfram Sang @ 2017-06-27 19:53 UTC (permalink / raw)
To: Chris Packham; +Cc: robh+dt, linux-i2c, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 267 bytes --]
On Mon, Jun 26, 2017 at 12:44:31PM +1200, Chris Packham wrote:
> Make use of struct gpio_desc which allows us to specify the active state
> of the reset pin.
>
> Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
Applied to for-next, thanks!
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH v3 3/5] i2c: pca-platform: add devicetree awareness
2017-06-26 0:44 ` [PATCH v3 3/5] i2c: pca-platform: add devicetree awareness Chris Packham
@ 2017-06-27 19:55 ` Wolfram Sang
2017-06-28 9:20 ` Andy Shevchenko
1 sibling, 0 replies; 36+ messages in thread
From: Wolfram Sang @ 2017-06-27 19:55 UTC (permalink / raw)
To: Chris Packham; +Cc: robh+dt, linux-i2c, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 673 bytes --]
On Mon, Jun 26, 2017 at 12:44:32PM +1200, Chris Packham wrote:
> Allow devices that use this driver to be registered via a
> devicetree.
>
> Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
...
> + if (IS_ERR(i2c->gpio))
> + return PTR_ERR(i2c->gpio);
coccicheck reported:
drivers/i2c/busses/i2c-pca-platform.c:209:3-9: ERROR: missing iounmap; ioremap on line 170 and execution via conditional on line 208
I fixed it like this (incremental diff):
- if (IS_ERR(i2c->gpio))
- return PTR_ERR(i2c->gpio);
+ if (IS_ERR(i2c->gpio)) {
+ ret = PTR_ERR(i2c->gpio);
+ goto e_reqirq;
+ }
and applied to for-next, thanks!
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH v3 4/5] i2c: pca-platform: use device managed allocations
2017-06-26 0:44 ` [PATCH v3 4/5] i2c: pca-platform: use device managed allocations Chris Packham
@ 2017-06-27 19:55 ` Wolfram Sang
2017-06-28 9:23 ` Andy Shevchenko
1 sibling, 0 replies; 36+ messages in thread
From: Wolfram Sang @ 2017-06-27 19:55 UTC (permalink / raw)
To: Chris Packham; +Cc: robh+dt, linux-i2c, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 577 bytes --]
On Mon, Jun 26, 2017 at 12:44:33PM +1200, Chris Packham wrote:
> Switch to using the devm_ APIs and remove the now unnecessary error
> handling and most of the device removal code.
>
> Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
And "reverted" the previous fix here:
- if (IS_ERR(i2c->gpio)) {
- ret = PTR_ERR(i2c->gpio);
- goto e_reqirq;
- }
+ if (IS_ERR(i2c->gpio))
+ return PTR_ERR(i2c->gpio);
Applied to for-next, thanks!
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH v3 5/5] i2c: pca-platform: use dev_warn/dev_info instead of printk
2017-06-26 0:44 ` [PATCH v3 5/5] i2c: pca-platform: use dev_warn/dev_info instead of printk Chris Packham
@ 2017-06-27 19:55 ` Wolfram Sang
2017-06-28 9:28 ` Andy Shevchenko
1 sibling, 0 replies; 36+ messages in thread
From: Wolfram Sang @ 2017-06-27 19:55 UTC (permalink / raw)
To: Chris Packham; +Cc: robh+dt, linux-i2c, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 161 bytes --]
On Mon, Jun 26, 2017 at 12:44:34PM +1200, Chris Packham wrote:
> Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
Applied to for-next, thanks!
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH v3 3/5] i2c: pca-platform: add devicetree awareness
2017-06-26 0:44 ` [PATCH v3 3/5] i2c: pca-platform: add devicetree awareness Chris Packham
2017-06-27 19:55 ` Wolfram Sang
@ 2017-06-28 9:20 ` Andy Shevchenko
2017-06-28 9:42 ` Wolfram Sang
2017-06-28 21:15 ` Chris Packham
1 sibling, 2 replies; 36+ messages in thread
From: Andy Shevchenko @ 2017-06-28 9:20 UTC (permalink / raw)
To: Chris Packham; +Cc: Wolfram Sang, Rob Herring, linux-i2c, linux-kernel
On Mon, Jun 26, 2017 at 3:44 AM, Chris Packham
<chris.packham@alliedtelesis.co.nz> wrote:
> Allow devices that use this driver to be registered via a
> devicetree.
Device Tree
Wolfram was being a bit faster to apply it...
> +#include <linux/of.h>
> +#include <linux/of_device.h>
> + struct device_node *np = pdev->dev.of_node;
> /* If irq is 0, we do polling. */
> + if (irq < 0)
> + irq = 0;
This does not belong to what is written in commit message. Looks like
a separate fix.
> + i2c->adap.dev.of_node = np;
> + } else if (np) {
> + i2c->adap.timeout = HZ;
> + i2c->gpio = devm_gpiod_get_optional(&pdev->dev, "reset-gpios", GPIOD_OUT_LOW);
> + if (IS_ERR(i2c->gpio))
> + return PTR_ERR(i2c->gpio);
> + of_property_read_u32_index(np, "clock-frequency", 0,
> + &i2c->algo_data.i2c_clock);
And what prevents you to use device_property_read_*() here and get rid
of OFstuff?
> +#ifdef CONFIG_OF
Better not to put it...
> + .of_match_table = of_match_ptr(i2c_pca_of_match_table),
...and get rid of of_match_ptr().
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH v3 4/5] i2c: pca-platform: use device managed allocations
2017-06-26 0:44 ` [PATCH v3 4/5] i2c: pca-platform: use device managed allocations Chris Packham
2017-06-27 19:55 ` Wolfram Sang
@ 2017-06-28 9:23 ` Andy Shevchenko
2017-06-28 9:38 ` Wolfram Sang
1 sibling, 1 reply; 36+ messages in thread
From: Andy Shevchenko @ 2017-06-28 9:23 UTC (permalink / raw)
To: Chris Packham; +Cc: Wolfram Sang, Rob Herring, linux-i2c, linux-kernel
On Mon, Jun 26, 2017 at 3:44 AM, Chris Packham
<chris.packham@alliedtelesis.co.nz> wrote:
> Switch to using the devm_ APIs and remove the now unnecessary error
> handling and most of the device removal code.
> if (i2c_pca_add_numbered_bus(&i2c->adap) < 0) {
> - ret = -ENODEV;
> - goto e_adapt;
> + return -ENODEV;
This is still shadows the actual error code.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH v3 2/5] i2c: pca-platform: switch to struct gpio_desc
2017-06-26 0:44 ` [PATCH v3 2/5] i2c: pca-platform: switch to struct gpio_desc Chris Packham
2017-06-27 19:53 ` Wolfram Sang
@ 2017-06-28 9:25 ` Andy Shevchenko
2017-06-28 21:25 ` Chris Packham
1 sibling, 1 reply; 36+ messages in thread
From: Andy Shevchenko @ 2017-06-28 9:25 UTC (permalink / raw)
To: Chris Packham; +Cc: Wolfram Sang, Rob Herring, linux-i2c, linux-kernel
On Mon, Jun 26, 2017 at 3:44 AM, Chris Packham
<chris.packham@alliedtelesis.co.nz> wrote:
> Make use of struct gpio_desc which allows us to specify the active state
> of the reset pin.
> + if (gpio_is_valid(platform_data->gpio)) {
No way, it should be provided by GPIO lookup table.
> + ret = devm_gpio_request_one(&pdev->dev,
> + platform_data->gpio,
> + GPIOF_ACTIVE_LOW,
> + i2c->adap.name);
> + if (ret == 0) {
> + i2c->gpio = gpio_to_desc(platform_data->gpio);
This has to be devm_gpiod_get() instead.
Wolfram, I suggested to drop the series for now and wait for improvements.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH v3 5/5] i2c: pca-platform: use dev_warn/dev_info instead of printk
2017-06-26 0:44 ` [PATCH v3 5/5] i2c: pca-platform: use dev_warn/dev_info instead of printk Chris Packham
2017-06-27 19:55 ` Wolfram Sang
@ 2017-06-28 9:28 ` Andy Shevchenko
2017-06-28 9:37 ` Wolfram Sang
1 sibling, 1 reply; 36+ messages in thread
From: Andy Shevchenko @ 2017-06-28 9:28 UTC (permalink / raw)
To: Chris Packham; +Cc: Wolfram Sang, Rob Herring, linux-i2c, linux-kernel
On Mon, Jun 26, 2017 at 3:44 AM, Chris Packham
<chris.packham@alliedtelesis.co.nz> wrote:
On the first glance I have thought this is _the_ only patch that
doesn't make my eyes hurt.
Not a chance! Where is the commit message?
Code below though looks fine.
> @@ -107,8 +107,8 @@ static int i2c_pca_pf_waitforcompletion(void *pd)
> static void i2c_pca_pf_dummyreset(void *pd)
> {
> struct i2c_pca_pf_data *i2c = pd;
> - printk(KERN_WARNING "%s: No reset-pin found. Chip may get stuck!\n",
> - i2c->adap.name);
> +
> + dev_warn(&i2c->adap.dev, "No reset-pin found. Chip may get stuck!\n");
> }
>
> static void i2c_pca_pf_resetchip(void *pd)
> @@ -236,7 +236,7 @@ static int i2c_pca_pf_probe(struct platform_device *pdev)
>
> platform_set_drvdata(pdev, i2c);
>
> - printk(KERN_INFO "%s registered.\n", i2c->adap.name);
> + dev_info(&pdev->dev, "registered.\n");
>
> return 0;
> }
> --
> 2.13.0
>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH v3 5/5] i2c: pca-platform: use dev_warn/dev_info instead of printk
2017-06-28 9:28 ` Andy Shevchenko
@ 2017-06-28 9:37 ` Wolfram Sang
2017-06-28 10:57 ` Andy Shevchenko
0 siblings, 1 reply; 36+ messages in thread
From: Wolfram Sang @ 2017-06-28 9:37 UTC (permalink / raw)
To: Andy Shevchenko; +Cc: Chris Packham, Rob Herring, linux-i2c, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 90 bytes --]
> Not a chance! Where is the commit message?
Don't you think $subject is clear enough?
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH v3 4/5] i2c: pca-platform: use device managed allocations
2017-06-28 9:23 ` Andy Shevchenko
@ 2017-06-28 9:38 ` Wolfram Sang
2017-06-28 10:54 ` Andy Shevchenko
0 siblings, 1 reply; 36+ messages in thread
From: Wolfram Sang @ 2017-06-28 9:38 UTC (permalink / raw)
To: Andy Shevchenko; +Cc: Chris Packham, Rob Herring, linux-i2c, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 317 bytes --]
> > if (i2c_pca_add_numbered_bus(&i2c->adap) < 0) {
> > - ret = -ENODEV;
> > - goto e_adapt;
> > + return -ENODEV;
>
> This is still shadows the actual error code.
Nice catch. But since it fixes a seperate issue, I'd prefer an
incremental change here.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH v3 3/5] i2c: pca-platform: add devicetree awareness
2017-06-28 9:20 ` Andy Shevchenko
@ 2017-06-28 9:42 ` Wolfram Sang
2017-06-28 21:15 ` Chris Packham
1 sibling, 0 replies; 36+ messages in thread
From: Wolfram Sang @ 2017-06-28 9:42 UTC (permalink / raw)
To: Andy Shevchenko; +Cc: Chris Packham, Rob Herring, linux-i2c, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 687 bytes --]
> > /* If irq is 0, we do polling. */
> > + if (irq < 0)
> > + irq = 0;
>
> This does not belong to what is written in commit message. Looks like
> a separate fix.
True, this needs explanation.
> > + of_property_read_u32_index(np, "clock-frequency", 0,
> > + &i2c->algo_data.i2c_clock);
>
> And what prevents you to use device_property_read_*() here and get rid
> of OFstuff?
device_* functions are not super much known yet. Even I tend to forget
them occasionally like here. We can fix it incrementally, too. But I
agree, it would be nice to have it right from the beginning.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH v3 4/5] i2c: pca-platform: use device managed allocations
2017-06-28 9:38 ` Wolfram Sang
@ 2017-06-28 10:54 ` Andy Shevchenko
2017-06-28 21:03 ` Chris Packham
0 siblings, 1 reply; 36+ messages in thread
From: Andy Shevchenko @ 2017-06-28 10:54 UTC (permalink / raw)
To: Wolfram Sang; +Cc: Chris Packham, Rob Herring, linux-i2c, linux-kernel
On Wed, Jun 28, 2017 at 12:38 PM, Wolfram Sang <wsa@the-dreams.de> wrote:
>
>> > if (i2c_pca_add_numbered_bus(&i2c->adap) < 0) {
>> > - ret = -ENODEV;
>> > - goto e_adapt;
>> > + return -ENODEV;
>>
>> This is still shadows the actual error code.
>
> Nice catch. But since it fixes a seperate issue, I'd prefer an
> incremental change here.
Agreed.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH v3 5/5] i2c: pca-platform: use dev_warn/dev_info instead of printk
2017-06-28 9:37 ` Wolfram Sang
@ 2017-06-28 10:57 ` Andy Shevchenko
2017-06-28 12:01 ` Wolfram Sang
0 siblings, 1 reply; 36+ messages in thread
From: Andy Shevchenko @ 2017-06-28 10:57 UTC (permalink / raw)
To: Wolfram Sang; +Cc: Chris Packham, Rob Herring, linux-i2c, linux-kernel
On Wed, Jun 28, 2017 at 12:37 PM, Wolfram Sang <wsa@the-dreams.de> wrote:
>
>> Not a chance! Where is the commit message?
>
> Don't you think $subject is clear enough?
I would add the comment at least on how the output is changed since
pr_*("%s:"..., i2c->adap.name,...) to dev_*(&pdev->dev, ...)
replacement.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH v3 5/5] i2c: pca-platform: use dev_warn/dev_info instead of printk
2017-06-28 10:57 ` Andy Shevchenko
@ 2017-06-28 12:01 ` Wolfram Sang
0 siblings, 0 replies; 36+ messages in thread
From: Wolfram Sang @ 2017-06-28 12:01 UTC (permalink / raw)
To: Andy Shevchenko; +Cc: Chris Packham, Rob Herring, linux-i2c, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 442 bytes --]
On Wed, Jun 28, 2017 at 01:57:01PM +0300, Andy Shevchenko wrote:
> On Wed, Jun 28, 2017 at 12:37 PM, Wolfram Sang <wsa@the-dreams.de> wrote:
> >
> >> Not a chance! Where is the commit message?
> >
> > Don't you think $subject is clear enough?
>
> I would add the comment at least on how the output is changed since
> pr_*("%s:"..., i2c->adap.name,...) to dev_*(&pdev->dev, ...)
> replacement.
Yes, that could have been done.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH v3 4/5] i2c: pca-platform: use device managed allocations
2017-06-28 10:54 ` Andy Shevchenko
@ 2017-06-28 21:03 ` Chris Packham
0 siblings, 0 replies; 36+ messages in thread
From: Chris Packham @ 2017-06-28 21:03 UTC (permalink / raw)
To: Andy Shevchenko, Wolfram Sang; +Cc: Rob Herring, linux-i2c, linux-kernel
On 28/06/17 22:54, Andy Shevchenko wrote:
> On Wed, Jun 28, 2017 at 12:38 PM, Wolfram Sang <wsa@the-dreams.de> wrote:
>>
>>>> if (i2c_pca_add_numbered_bus(&i2c->adap) < 0) {
>>>> - ret = -ENODEV;
>>>> - goto e_adapt;
>>>> + return -ENODEV;
>>>
>>> This is still shadows the actual error code.
>>
>> Nice catch. But since it fixes a seperate issue, I'd prefer an
>> incremental change here.
>
> Agreed.
>
OK I can send another patch for that.
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH v3 3/5] i2c: pca-platform: add devicetree awareness
2017-06-28 9:20 ` Andy Shevchenko
2017-06-28 9:42 ` Wolfram Sang
@ 2017-06-28 21:15 ` Chris Packham
1 sibling, 0 replies; 36+ messages in thread
From: Chris Packham @ 2017-06-28 21:15 UTC (permalink / raw)
To: Andy Shevchenko; +Cc: Wolfram Sang, Rob Herring, linux-i2c, linux-kernel
On 28/06/17 21:20, Andy Shevchenko wrote:
>> + i2c->adap.dev.of_node = np;
>> + } else if (np) {
>> + i2c->adap.timeout = HZ;
>> + i2c->gpio = devm_gpiod_get_optional(&pdev->dev, "reset-gpios", GPIOD_OUT_LOW);
>> + if (IS_ERR(i2c->gpio))
>> + return PTR_ERR(i2c->gpio);
>> + of_property_read_u32_index(np, "clock-frequency", 0,
>> + &i2c->algo_data.i2c_clock);
> And what prevents you to use device_property_read_*() here and get rid
> of OFstuff?
>
Nothing particular. I think I just found more instances of parsing a
"clock-frequency" this way. Happy to change this.
>> +#ifdef CONFIG_OF
> Better not to put it...
>
>> + .of_match_table = of_match_ptr(i2c_pca_of_match_table),
> ...and get rid of of_match_ptr().
So what's the current best practice with this? I gather the intent is to
keep the kernel size down by only including the of_match tables on
platforms that actually use a device tree. There are just shy of 1000
instances of of_match_ptr in the current tree (a handful of which are in
drivers/i2c). Have we now reached a point where there are more dt-aware
platforms than unaware ones?
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH v3 2/5] i2c: pca-platform: switch to struct gpio_desc
2017-06-28 9:25 ` Andy Shevchenko
@ 2017-06-28 21:25 ` Chris Packham
2017-06-28 22:18 ` Wolfram Sang
0 siblings, 1 reply; 36+ messages in thread
From: Chris Packham @ 2017-06-28 21:25 UTC (permalink / raw)
To: Andy Shevchenko; +Cc: Wolfram Sang, Rob Herring, linux-i2c, linux-kernel
On 28/06/17 21:25, Andy Shevchenko wrote:
> On Mon, Jun 26, 2017 at 3:44 AM, Chris Packham
> <chris.packham@alliedtelesis.co.nz> wrote:
>> Make use of struct gpio_desc which allows us to specify the active state
>> of the reset pin.
>
>> + if (gpio_is_valid(platform_data->gpio)) {
>
> No way, it should be provided by GPIO lookup table.
>
Can do. The only platform that would be affected is
arch/sh/boards/board-sh7785lcr.c and the fact that it sets gpio = 0
makes me think that this might be an error.
>> + ret = devm_gpio_request_one(&pdev->dev,
>> + platform_data->gpio,
>> + GPIOF_ACTIVE_LOW,
>> + i2c->adap.name);
>> + if (ret == 0) {
>> + i2c->gpio = gpio_to_desc(platform_data->gpio);
>
> This has to be devm_gpiod_get() instead.
I can just make the devm_gpiod_get_optional() call I add in 3/5
unconditional.
>
> Wolfram, I suggested to drop the series for now and wait for improvements.
>
Wolframs call. I don't mind either way. I can send a v4 or send a new
series on top of i2c.git#for-next.
^ permalink raw reply [flat|nested] 36+ messages in thread
* Re: [PATCH v3 2/5] i2c: pca-platform: switch to struct gpio_desc
2017-06-28 21:25 ` Chris Packham
@ 2017-06-28 22:18 ` Wolfram Sang
0 siblings, 0 replies; 36+ messages in thread
From: Wolfram Sang @ 2017-06-28 22:18 UTC (permalink / raw)
To: Chris Packham; +Cc: Andy Shevchenko, Rob Herring, linux-i2c, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 194 bytes --]
> Wolframs call. I don't mind either way. I can send a v4 or send a new
> series on top of i2c.git#for-next.
I think we can work incrementally on what I pushed out already.
Thanks!
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 36+ messages in thread
end of thread, other threads:[~2017-06-28 22:18 UTC | newest]
Thread overview: 36+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-20 1:18 [PATCH v2 0/5] i2c: pca-platform: updates Chris Packham
2017-06-20 1:18 ` [PATCH v2 1/5] dt-bindings: add bindings for i2c-pca-platform Chris Packham
2017-06-22 8:22 ` Wolfram Sang
2017-06-22 21:20 ` Chris Packham
2017-06-23 8:17 ` Wolfram Sang
2017-06-23 21:41 ` Rob Herring
2017-06-20 1:18 ` [PATCH v2 2/5] i2c: pca-platform: add devicetree awareness Chris Packham
2017-06-20 1:18 ` [PATCH v2 3/5] i2c: pca-platform: use gpio_is_valid Chris Packham
2017-06-20 1:18 ` [PATCH v2 4/5] i2c: pca-platform: use device managed allocations Chris Packham
2017-06-20 1:18 ` [PATCH v2 5/5] i2c: pca-platform: use dev_warn/dev_info instead of printk Chris Packham
2017-06-26 0:44 ` [PATCH v3 0/5] i2c: pca-platform: updates Chris Packham
2017-06-26 0:44 ` [PATCH v3 1/5] dt-bindings: add bindings for i2c-pca-platform Chris Packham
2017-06-26 14:06 ` Rob Herring
2017-06-27 19:53 ` Wolfram Sang
2017-06-26 0:44 ` [PATCH v3 2/5] i2c: pca-platform: switch to struct gpio_desc Chris Packham
2017-06-27 19:53 ` Wolfram Sang
2017-06-28 9:25 ` Andy Shevchenko
2017-06-28 21:25 ` Chris Packham
2017-06-28 22:18 ` Wolfram Sang
2017-06-26 0:44 ` [PATCH v3 3/5] i2c: pca-platform: add devicetree awareness Chris Packham
2017-06-27 19:55 ` Wolfram Sang
2017-06-28 9:20 ` Andy Shevchenko
2017-06-28 9:42 ` Wolfram Sang
2017-06-28 21:15 ` Chris Packham
2017-06-26 0:44 ` [PATCH v3 4/5] i2c: pca-platform: use device managed allocations Chris Packham
2017-06-27 19:55 ` Wolfram Sang
2017-06-28 9:23 ` Andy Shevchenko
2017-06-28 9:38 ` Wolfram Sang
2017-06-28 10:54 ` Andy Shevchenko
2017-06-28 21:03 ` Chris Packham
2017-06-26 0:44 ` [PATCH v3 5/5] i2c: pca-platform: use dev_warn/dev_info instead of printk Chris Packham
2017-06-27 19:55 ` Wolfram Sang
2017-06-28 9:28 ` Andy Shevchenko
2017-06-28 9:37 ` Wolfram Sang
2017-06-28 10:57 ` Andy Shevchenko
2017-06-28 12:01 ` Wolfram Sang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).