* [PATCH master 1/3] video: dw-hdmi: populate missing I2C adapter device node
@ 2024-12-15 9:54 Ahmad Fatoum
2024-12-15 9:54 ` [PATCH master 2/3] i2c: i2c: fix getting adapter.nr for I2C muxes Ahmad Fatoum
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2024-12-15 9:54 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
By recording the correct device tree node, it's possible to use OF
aliases for deterministic numbering of the I2C adapter.
Fixes: aea9e8bac578 ("video: add dw-hdmi driver")
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/video/dw-hdmi.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/video/dw-hdmi.c b/drivers/video/dw-hdmi.c
index 73201836b7e5..cd5de17e9bd7 100644
--- a/drivers/video/dw-hdmi.c
+++ b/drivers/video/dw-hdmi.c
@@ -433,6 +433,7 @@ static struct i2c_adapter *dw_hdmi_i2c_adapter(struct dw_hdmi *hdmi)
adap = &i2c->adap;
adap->dev.parent = hdmi->dev;
+ adap->dev.of_node = hdmi->dev->of_node;
adap->master_xfer = dw_hdmi_i2c_xfer;
adap->nr = -1;
--
2.39.5
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH master 2/3] i2c: i2c: fix getting adapter.nr for I2C muxes
2024-12-15 9:54 [PATCH master 1/3] video: dw-hdmi: populate missing I2C adapter device node Ahmad Fatoum
@ 2024-12-15 9:54 ` Ahmad Fatoum
2024-12-15 9:54 ` [PATCH master 3/3] i2c: order dynamically numbered adapter after highest alias id Ahmad Fatoum
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2024-12-15 9:54 UTC (permalink / raw)
To: barebox; +Cc: Alexander Shiyan, Ahmad Fatoum
When probed from device tree, "real" I2C controllers are virtual
devices that have the OF device as parent.
For those the current logic of using the alias of the parent
device's of_node works.
I2C muxes are different, because their parent device is the virtual
device of their controller. Using that controller's alias is often
destined to result in an -EBUSY:
pca9450-i2c pca9450b0: PMIC Chip ID: 0x3
ERROR: i2c1: failed to add mux-adapter (error=-16)
ERROR: pca954x pca95450: failed to register multiplexed adapter0
As a single I2C mux can have multiple channels, there may also be just
one OF device for multiple virtual adapters. As all I2C adapters being
registered in barebox also have the of_node of the virtual device
populated, let's just consult that.
Fixes: b4746725454c ("i2c: get adapter.nr from device tree")
Reported-by: Alexander Shiyan <eagle.alexander923@gmail.com>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/i2c/i2c.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
index d19506af2627..017842f026dd 100644
--- a/drivers/i2c/i2c.c
+++ b/drivers/i2c/i2c.c
@@ -705,8 +705,8 @@ int i2c_add_numbered_adapter(struct i2c_adapter *adapter)
struct device *hw_dev;
int ret;
- if (adapter->nr < 0 && adapter->dev.parent && adapter->dev.parent->of_node)
- adapter->nr = of_alias_get_id(adapter->dev.parent->of_node, "i2c");
+ if (adapter->nr < 0 && dev_of_node(&adapter->dev))
+ adapter->nr = of_alias_get_id(adapter->dev.of_node, "i2c");
if (adapter->nr < 0) {
int nr;
--
2.39.5
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH master 3/3] i2c: order dynamically numbered adapter after highest alias id
2024-12-15 9:54 [PATCH master 1/3] video: dw-hdmi: populate missing I2C adapter device node Ahmad Fatoum
2024-12-15 9:54 ` [PATCH master 2/3] i2c: i2c: fix getting adapter.nr for I2C muxes Ahmad Fatoum
@ 2024-12-15 9:54 ` Ahmad Fatoum
2024-12-16 7:16 ` [PATCH master 1/3] video: dw-hdmi: populate missing I2C adapter device node Sascha Hauer
2024-12-17 13:04 ` Alexander Shiyan
3 siblings, 0 replies; 5+ messages in thread
From: Ahmad Fatoum @ 2024-12-15 9:54 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Instead of assuming there is at most 32 aliased adapters, let's
determine at runtime how many aliases we have and assign unaliased
adapters IDs directly following the highest aliased id.
This has the added benefit that we may avoid moving around adapter
numbers for many boards.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/i2c/i2c.c | 21 ++++++++++++++++++---
drivers/of/base.c | 24 ++++++++++++++++++++++++
include/of.h | 6 ++++++
3 files changed, 48 insertions(+), 3 deletions(-)
diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c
index 017842f026dd..0d11a61593d8 100644
--- a/drivers/i2c/i2c.c
+++ b/drivers/i2c/i2c.c
@@ -685,6 +685,20 @@ void i2c_parse_fw_timings(struct device *dev, struct i2c_timings *t,
}
EXPORT_SYMBOL_GPL(i2c_parse_fw_timings);
+/**
+ * i2c_first_nonreserved_index() - get the first index that is not reserved
+ */
+static int i2c_first_nonreserved_index(void)
+{
+ int max;
+
+ max = of_alias_get_highest_id("i2c");
+ if (max < 0)
+ return 0;
+
+ return max + 1;
+}
+
/**
* i2c_add_numbered_adapter - declare i2c adapter, use static bus number
* @adapter: the adapter to register (with adap->nr initialized)
@@ -711,9 +725,10 @@ int i2c_add_numbered_adapter(struct i2c_adapter *adapter)
if (adapter->nr < 0) {
int nr;
- for (nr = 32;; nr++)
- if (!i2c_get_adapter(nr))
- break;
+ for (nr = i2c_first_nonreserved_index();
+ i2c_get_adapter(nr); nr++)
+ ;
+
adapter->nr = nr;
} else {
if (i2c_get_adapter(adapter->nr))
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 97b2306a75b1..125f24056eec 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -270,6 +270,30 @@ int of_alias_get_id(struct device_node *np, const char *stem)
}
EXPORT_SYMBOL_GPL(of_alias_get_id);
+/**
+ * of_alias_get_highest_id - Get highest alias id for the given stem
+ * @stem: Alias stem to be examined
+ *
+ * The function travels the lookup table to get the highest alias id for the
+ * given alias stem. It returns the alias id if found.
+ */
+int of_alias_get_highest_id(const char *stem)
+{
+ struct alias_prop *app;
+ int id = -ENODEV;
+
+ list_for_each_entry(app, &aliases_lookup, link) {
+ if (strcmp(app->stem, stem) != 0)
+ continue;
+
+ if (app->id > id)
+ id = app->id;
+ }
+
+ return id;
+}
+EXPORT_SYMBOL_GPL(of_alias_get_highest_id);
+
int of_alias_get_id_from(struct device_node *root, struct device_node *np,
const char *stem)
{
diff --git a/include/of.h b/include/of.h
index c0577404c320..bc8afd9cf540 100644
--- a/include/of.h
+++ b/include/of.h
@@ -311,6 +311,7 @@ extern void of_alias_scan(void);
extern int of_alias_get_id(struct device_node *np, const char *stem);
extern int of_alias_get_id_from(struct device_node *root, struct device_node *np,
const char *stem);
+extern int of_alias_get_highest_id(const char *stem);
extern const char *of_alias_get(struct device_node *np);
extern int of_modalias_node(struct device_node *node, char *modalias, int len);
@@ -941,6 +942,11 @@ static inline int of_alias_get_id_from(struct device_node *root, struct device_n
return -ENOSYS;
}
+static inline int of_alias_get_highest_id(const char *stem)
+{
+ return -ENOSYS;
+}
+
static inline const char *of_alias_get(struct device_node *np)
{
return NULL;
--
2.39.5
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH master 1/3] video: dw-hdmi: populate missing I2C adapter device node
2024-12-15 9:54 [PATCH master 1/3] video: dw-hdmi: populate missing I2C adapter device node Ahmad Fatoum
2024-12-15 9:54 ` [PATCH master 2/3] i2c: i2c: fix getting adapter.nr for I2C muxes Ahmad Fatoum
2024-12-15 9:54 ` [PATCH master 3/3] i2c: order dynamically numbered adapter after highest alias id Ahmad Fatoum
@ 2024-12-16 7:16 ` Sascha Hauer
2024-12-17 13:04 ` Alexander Shiyan
3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2024-12-16 7:16 UTC (permalink / raw)
To: barebox, Ahmad Fatoum
On Sun, 15 Dec 2024 10:54:10 +0100, Ahmad Fatoum wrote:
> By recording the correct device tree node, it's possible to use OF
> aliases for deterministic numbering of the I2C adapter.
>
>
Applied, thanks!
[1/3] video: dw-hdmi: populate missing I2C adapter device node
https://git.pengutronix.de/cgit/barebox/commit/?id=474b6cb42ea5 (link may not be stable)
[2/3] i2c: i2c: fix getting adapter.nr for I2C muxes
https://git.pengutronix.de/cgit/barebox/commit/?id=699a132c8de4 (link may not be stable)
[3/3] i2c: order dynamically numbered adapter after highest alias id
https://git.pengutronix.de/cgit/barebox/commit/?id=90129a1e4b45 (link may not be stable)
Best regards,
--
Sascha Hauer <s.hauer@pengutronix.de>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH master 1/3] video: dw-hdmi: populate missing I2C adapter device node
2024-12-15 9:54 [PATCH master 1/3] video: dw-hdmi: populate missing I2C adapter device node Ahmad Fatoum
` (2 preceding siblings ...)
2024-12-16 7:16 ` [PATCH master 1/3] video: dw-hdmi: populate missing I2C adapter device node Sascha Hauer
@ 2024-12-17 13:04 ` Alexander Shiyan
3 siblings, 0 replies; 5+ messages in thread
From: Alexander Shiyan @ 2024-12-17 13:04 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox
ERROR: i2c11: of_i2c: invalid reg on /hdmi@fe0a0000/ports
dwhdmi-rockchip fe0a0000.hdmi@fe0a0000.of: registered I2C bus driver
dwhdmi-rockchip fe0a0000.hdmi@fe0a0000.of: Detected HDMI TX controller
v2.11a with HDCP (DWC HDMI 2.0 TX PHY)
rockchip-vop2 fe040000.vop@fe040000.of: Registered fb0 on VP0, window
Smart0-win0, type primary
rockchip-vop2 fe040000.vop@fe040000.of: Registered fb0_0 on VP0,
window Esmart1-win0, type overlay
NOTICE: rockchip-vop2 fe040000.vop@fe040000.of: no modes found on vp1
rockchip-vop2 fe040000.vop@fe040000.of: Registered fb1 on VP1, window
Smart1-win0, type primary
rockchip-vop2 fe040000.vop@fe040000.of: Registered fb1_0 on VP1,
window Esmart0-win0, type overlay
ERROR: i2c11: of_i2c: invalid reg on /hdmi@fe0a0000/ports
вс, 15 дек. 2024 г. в 12:54, Ahmad Fatoum <a.fatoum@pengutronix.de>:
>
> By recording the correct device tree node, it's possible to use OF
> aliases for deterministic numbering of the I2C adapter.
>
> Fixes: aea9e8bac578 ("video: add dw-hdmi driver")
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> drivers/video/dw-hdmi.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/video/dw-hdmi.c b/drivers/video/dw-hdmi.c
> index 73201836b7e5..cd5de17e9bd7 100644
> --- a/drivers/video/dw-hdmi.c
> +++ b/drivers/video/dw-hdmi.c
> @@ -433,6 +433,7 @@ static struct i2c_adapter *dw_hdmi_i2c_adapter(struct dw_hdmi *hdmi)
>
> adap = &i2c->adap;
> adap->dev.parent = hdmi->dev;
> + adap->dev.of_node = hdmi->dev->of_node;
> adap->master_xfer = dw_hdmi_i2c_xfer;
> adap->nr = -1;
>
> --
> 2.39.5
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-12-17 13:05 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-12-15 9:54 [PATCH master 1/3] video: dw-hdmi: populate missing I2C adapter device node Ahmad Fatoum
2024-12-15 9:54 ` [PATCH master 2/3] i2c: i2c: fix getting adapter.nr for I2C muxes Ahmad Fatoum
2024-12-15 9:54 ` [PATCH master 3/3] i2c: order dynamically numbered adapter after highest alias id Ahmad Fatoum
2024-12-16 7:16 ` [PATCH master 1/3] video: dw-hdmi: populate missing I2C adapter device node Sascha Hauer
2024-12-17 13:04 ` Alexander Shiyan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox