* [PATCH 1/5] i2c: Add missing result check
2013-05-20 20:11 Sascha Hauer
@ 2013-05-20 20:11 ` Sascha Hauer
2013-05-20 20:11 ` [PATCH 2/5] i2c: remove dead code Sascha Hauer
` (3 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2013-05-20 20:11 UTC (permalink / raw)
To: barebox
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/i2c/i2c.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
index 4862df3..488b636 100644
--- a/drivers/i2c/i2c.c
+++ b/drivers/i2c/i2c.c
@@ -260,6 +260,10 @@ struct i2c_client *i2c_new_device(struct i2c_adapter *adapter,
client->dev.parent = &adapter->dev;
status = register_device(&client->dev);
+ if (status) {
+ free(client);
+ return NULL;
+ }
#if 0
/* drivers may modify this initial i/o setup */
--
1.8.2.rc2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 2/5] i2c: remove dead code
2013-05-20 20:11 Sascha Hauer
2013-05-20 20:11 ` [PATCH 1/5] i2c: Add missing result check Sascha Hauer
@ 2013-05-20 20:11 ` Sascha Hauer
2013-05-20 20:11 ` [PATCH 3/5] i2c: Add support for dynamic i2c bus numbers Sascha Hauer
` (2 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2013-05-20 20:11 UTC (permalink / raw)
To: barebox
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/i2c/i2c.c | 16 ----------------
1 file changed, 16 deletions(-)
diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
index 488b636..53a11fe 100644
--- a/drivers/i2c/i2c.c
+++ b/drivers/i2c/i2c.c
@@ -265,23 +265,7 @@ struct i2c_client *i2c_new_device(struct i2c_adapter *adapter,
return NULL;
}
-#if 0
- /* drivers may modify this initial i/o setup */
- status = master->setup(client);
- if (status < 0) {
- printf("can't setup %s, status %d\n",
- client->dev.name, status);
- goto fail;
- }
-#endif
-
return client;
-
-#if 0
- fail:
- free(proxy);
- return NULL;
-#endif
}
EXPORT_SYMBOL(i2c_new_device);
--
1.8.2.rc2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 3/5] i2c: Add support for dynamic i2c bus numbers
2013-05-20 20:11 Sascha Hauer
2013-05-20 20:11 ` [PATCH 1/5] i2c: Add missing result check Sascha Hauer
2013-05-20 20:11 ` [PATCH 2/5] i2c: remove dead code Sascha Hauer
@ 2013-05-20 20:11 ` Sascha Hauer
2013-05-20 22:27 ` [SPAM] " Jean-Christophe PLAGNIOL-VILLARD
2013-05-20 20:11 ` [PATCH 4/5] i2c: Add devicetree support Sascha Hauer
2013-05-20 20:11 ` [PATCH 5/5] i2c: fsl: Add devicetree probe support Sascha Hauer
4 siblings, 1 reply; 8+ messages in thread
From: Sascha Hauer @ 2013-05-20 20:11 UTC (permalink / raw)
To: barebox
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/i2c/i2c.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
index 53a11fe..ddf0082 100644
--- a/drivers/i2c/i2c.c
+++ b/drivers/i2c/i2c.c
@@ -384,8 +384,17 @@ int i2c_add_numbered_adapter(struct i2c_adapter *adapter)
{
int ret;
- if (i2c_get_adapter(adapter->nr))
- return -EBUSY;
+ if (adapter->nr < 0) {
+ int nr;
+
+ for (nr = 0;; nr++)
+ if (!i2c_get_adapter(nr))
+ break;
+ adapter->nr = nr;
+ } else {
+ if (i2c_get_adapter(adapter->nr))
+ return -EBUSY;
+ }
adapter->dev.id = adapter->nr;
strcpy(adapter->dev.name, "i2c");
--
1.8.2.rc2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [SPAM] [PATCH 3/5] i2c: Add support for dynamic i2c bus numbers
2013-05-20 20:11 ` [PATCH 3/5] i2c: Add support for dynamic i2c bus numbers Sascha Hauer
@ 2013-05-20 22:27 ` Jean-Christophe PLAGNIOL-VILLARD
2013-05-21 6:49 ` Sascha Hauer
0 siblings, 1 reply; 8+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-05-20 22:27 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
On 22:11 Mon 20 May , Sascha Hauer wrote:
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
> drivers/i2c/i2c.c | 13 +++++++++++--
> 1 file changed, 11 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
> index 53a11fe..ddf0082 100644
> --- a/drivers/i2c/i2c.c
> +++ b/drivers/i2c/i2c.c
> @@ -384,8 +384,17 @@ int i2c_add_numbered_adapter(struct i2c_adapter *adapter)
> {
> int ret;
>
> - if (i2c_get_adapter(adapter->nr))
> - return -EBUSY;
> + if (adapter->nr < 0) {
> + int nr;
> +
> + for (nr = 0;; nr++)
> + if (!i2c_get_adapter(nr))
> + break;
> + adapter->nr = nr;
> + } else {
> + if (i2c_get_adapter(adapter->nr))
> + return -EBUSY;
> + }
I send a patch exactly the same on spi and you refuse it
Best Regards,
J.
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [SPAM] [PATCH 3/5] i2c: Add support for dynamic i2c bus numbers
2013-05-20 22:27 ` [SPAM] " Jean-Christophe PLAGNIOL-VILLARD
@ 2013-05-21 6:49 ` Sascha Hauer
0 siblings, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2013-05-21 6:49 UTC (permalink / raw)
To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox
On Tue, May 21, 2013 at 12:27:47AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> On 22:11 Mon 20 May , Sascha Hauer wrote:
> > Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> > ---
> > drivers/i2c/i2c.c | 13 +++++++++++--
> > 1 file changed, 11 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
> > index 53a11fe..ddf0082 100644
> > --- a/drivers/i2c/i2c.c
> > +++ b/drivers/i2c/i2c.c
> > @@ -384,8 +384,17 @@ int i2c_add_numbered_adapter(struct i2c_adapter *adapter)
> > {
> > int ret;
> >
> > - if (i2c_get_adapter(adapter->nr))
> > - return -EBUSY;
> > + if (adapter->nr < 0) {
> > + int nr;
> > +
> > + for (nr = 0;; nr++)
> > + if (!i2c_get_adapter(nr))
> > + break;
> > + adapter->nr = nr;
> > + } else {
> > + if (i2c_get_adapter(adapter->nr))
> > + return -EBUSY;
> > + }
>
> I send a patch exactly the same on spi and you refuse it
The time you sent it we talked about platform devices and I still think
that it's not a good idea to register the SPI masters with dynamic bus
numbers and to have statically assigned numbers in the spi_board_info.
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 4/5] i2c: Add devicetree support
2013-05-20 20:11 Sascha Hauer
` (2 preceding siblings ...)
2013-05-20 20:11 ` [PATCH 3/5] i2c: Add support for dynamic i2c bus numbers Sascha Hauer
@ 2013-05-20 20:11 ` Sascha Hauer
2013-05-20 20:11 ` [PATCH 5/5] i2c: fsl: Add devicetree probe support Sascha Hauer
4 siblings, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2013-05-20 20:11 UTC (permalink / raw)
To: barebox
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/i2c/i2c.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
include/i2c/i2c.h | 1 +
2 files changed, 46 insertions(+)
diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
index ddf0082..067224b 100644
--- a/drivers/i2c/i2c.c
+++ b/drivers/i2c/i2c.c
@@ -254,6 +254,7 @@ struct i2c_client *i2c_new_device(struct i2c_adapter *adapter,
client->dev.platform_data = chip->platform_data;
client->dev.id = DEVICE_ID_DYNAMIC;
client->dev.bus = &i2c_bus;
+ client->dev.device_node = chip->of_node;
client->adapter = adapter;
client->addr = chip->addr;
@@ -269,6 +270,44 @@ struct i2c_client *i2c_new_device(struct i2c_adapter *adapter,
}
EXPORT_SYMBOL(i2c_new_device);
+void of_i2c_register_devices(struct i2c_adapter *adap)
+{
+ struct device_node *n;
+
+ /* Only register child devices if the adapter has a node pointer set */
+ if (!IS_ENABLED(CONFIG_OFDEVICE) || !adap->dev.device_node)
+ return;
+
+ device_node_for_nach_child(adap->dev.device_node, n) {
+ struct i2c_board_info info = {};
+ struct i2c_client *result;
+ const __be32 *addr;
+ int len;
+
+ strcpy(info.type, n->name);
+ info.of_node = n;
+
+ addr = of_get_property(n, "reg", &len);
+ if (!addr || (len < sizeof(int))) {
+ dev_err(&adap->dev, "of_i2c: invalid reg on %s\n",
+ n->full_name);
+ continue;
+ }
+
+ info.addr = be32_to_cpup(addr);
+ if (info.addr > (1 << 10) - 1) {
+ dev_err(&adap->dev, "of_i2c: invalid addr=%x on %s\n",
+ info.addr, n->full_name);
+ continue;
+ }
+
+ result = i2c_new_device(adap, &info);
+ if (!result)
+ dev_err(&adap->dev, "of_i2c: Failure registering %s\n",
+ n->full_name);
+ }
+}
+
/**
* i2c_new_dummy - return a new i2c device bound to a dummy driver
* @adapter: the adapter managing the device
@@ -408,6 +447,8 @@ int i2c_add_numbered_adapter(struct i2c_adapter *adapter)
/* populate children from any i2c device tables */
scan_boardinfo(adapter);
+ of_i2c_register_devices(adapter);
+
return 0;
}
EXPORT_SYMBOL(i2c_add_numbered_adapter);
@@ -417,6 +458,10 @@ static int i2c_match(struct device_d *dev, struct driver_d *drv)
if (!strcmp(dev->name, drv->name))
return 0;
+ if (IS_ENABLED(CONFIG_OFDEVICE) && dev->device_node &&
+ drv->of_compatible)
+ return of_match(dev, drv);
+
if (drv->id_table) {
struct platform_device_id *id = drv->id_table;
diff --git a/include/i2c/i2c.h b/include/i2c/i2c.h
index 7b59a51..3b4be45 100644
--- a/include/i2c/i2c.h
+++ b/include/i2c/i2c.h
@@ -102,6 +102,7 @@ struct i2c_board_info {
char type[I2C_NAME_SIZE]; /**< name of device */
unsigned short addr; /**< stored in i2c_client.addr */
void *platform_data; /**< platform data for device */
+ struct device_node *of_node;
};
/**
--
1.8.2.rc2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 5/5] i2c: fsl: Add devicetree probe support
2013-05-20 20:11 Sascha Hauer
` (3 preceding siblings ...)
2013-05-20 20:11 ` [PATCH 4/5] i2c: Add devicetree support Sascha Hauer
@ 2013-05-20 20:11 ` Sascha Hauer
4 siblings, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2013-05-20 20:11 UTC (permalink / raw)
To: barebox
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/i2c/busses/i2c-imx.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index 9fcfd5c..c607bcb 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -545,6 +545,7 @@ static int __init i2c_fsl_probe(struct device_d *pdev)
i2c_fsl->adapter.master_xfer = i2c_fsl_xfer;
i2c_fsl->adapter.nr = pdev->id;
i2c_fsl->adapter.dev.parent = pdev;
+ i2c_fsl->adapter.dev.device_node = pdev->device_node;
i2c_fsl->base = dev_request_mem_region(pdev, 0);
i2c_fsl->dfsrr = -1;
@@ -572,8 +573,17 @@ fail:
return ret;
}
+static __maybe_unused struct of_device_id imx_i2c_dt_ids[] = {
+ {
+ .compatible = "fsl,imx21-i2c",
+ }, {
+ /* sentinel */
+ }
+};
+
static struct driver_d i2c_fsl_driver = {
.probe = i2c_fsl_probe,
.name = DRIVER_NAME,
+ .of_compatible = DRV_OF_COMPAT(imx_i2c_dt_ids),
};
device_platform_driver(i2c_fsl_driver);
--
1.8.2.rc2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread