Re: [PATCH 2/2] i2c: designware_i2c: Check if the device is powered

2020-05-29 Thread Heiko Schocher

Hello Simon,

Am 22.04.2020 um 18:13 schrieb Simon Glass:

From: Raul E Rangel 

If the device doesn't return a version that means the device is
non-functional.

The dw_i2c_regs had invalid offsets for the version field. I got the
correct value from the DesignWare databook. It also matches what the
Picasso PPR says.

Signed-off-by: Raul E Rangel 
Reviewed-by: Simon Glass 
Reviewed-by: Furquan Shaikh 
Tested on chromebook_coral:
Signed-off-by: Simon Glass 
---

  drivers/i2c/designware_i2c.c | 17 +
  1 file changed, 17 insertions(+)


Applied to u-boot-i2c master

Thanks!

bye,
HEiko
--
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: h...@denx.de


[PATCH 2/2] i2c: designware_i2c: Check if the device is powered

2020-04-22 Thread Simon Glass
From: Raul E Rangel 

If the device doesn't return a version that means the device is
non-functional.

The dw_i2c_regs had invalid offsets for the version field. I got the
correct value from the DesignWare databook. It also matches what the
Picasso PPR says.

Signed-off-by: Raul E Rangel 
Reviewed-by: Simon Glass 
Reviewed-by: Furquan Shaikh 
Tested on chromebook_coral:
Signed-off-by: Simon Glass 
---

 drivers/i2c/designware_i2c.c | 17 +
 1 file changed, 17 insertions(+)

diff --git a/drivers/i2c/designware_i2c.c b/drivers/i2c/designware_i2c.c
index ac170769f4..f7a48f6225 100644
--- a/drivers/i2c/designware_i2c.c
+++ b/drivers/i2c/designware_i2c.c
@@ -16,6 +16,12 @@
 #include 
 #include 
 
+/*
+ * This assigned unique hex value is constant and is derived from the two ASCII
+ * letters 'DW' followed by a 16-bit unsigned number
+ */
+#define DW_I2C_COMP_TYPE   0x44570140
+
 #ifdef CONFIG_SYS_I2C_DW_ENABLE_STATUS_UNSUPPORTED
 static int  dw_i2c_enable(struct i2c_regs *i2c_base, bool enable)
 {
@@ -764,6 +770,17 @@ int designware_i2c_ofdata_to_platdata(struct udevice *bus)
 int designware_i2c_probe(struct udevice *bus)
 {
struct dw_i2c *priv = dev_get_priv(bus);
+   uint comp_type;
+
+   comp_type = readl(&priv->regs->comp_type);
+   if (comp_type != DW_I2C_COMP_TYPE) {
+   log_err("I2C bus %s has unknown type %#x\n", bus->name,
+   comp_type);
+   return -ENXIO;
+   }
+
+   log_info("I2C bus %s version %#x\n", bus->name,
+readl(&priv->regs->comp_version));
 
return __dw_i2c_init(priv->regs, 0, 0);
 }
-- 
2.26.1.301.g55bc3eb7cb9-goog