Skip to contentSkip to conversation

i2c: designware: Add driver support for AMD NAVI GPU

PATCH Superseded Sanket Goswami 2 participants 3 messages Mar 22, 2021 – Mar 25, 2021

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 i2c: designware: Add driver support for AMD NAVI GPU

The Latest AMD NAVI GPU card has an integrated Type-C controller and Designware I2C with PCI Interface. The Type-C controller can be accessed over I2C. The client driver is part of the USB Type-C UCSI driver.

Also, there exists a couple of notable IP limitations that are dealt as workarounds:
- I2C transaction work on a polling mode as IP does not generate interrupt.
- I2C read command sent twice to address the IP issues.

---
Changes in v2:
- Utilized existing functionality of i2c_dw_xfer_init to configure I2C bus.
- Removed i2c_dw_populate_client and rewrrient navi_amd_register_client to deduplicate from existing drivers.
- Addressed review comments from Andy.

drivers/i2c/busses/i2c-designware-common.c | 3 +

 drivers/i2c/busses/i2c-designware-core.h   |   3 +
 drivers/i2c/busses/i2c-designware-master.c | 136 +++++++++++++++++++++
 drivers/i2c/busses/i2c-designware-pcidrv.c |  57 +++++++++
 4 files changed, 199 insertions(+)
drivers/i2c/busses/i2c-designware-common.c +3 -0
index 3c19aada4b30..50883a70b482 100644
@@ -150,6 +150,9 @@ int i2c_dw_init_regmap(struct dw_i2c_dev *dev)
 	reg = readl(dev->base + DW_IC_COMP_TYPE);
 	i2c_dw_release_lock(dev);
 
+	if (dev->flags & AMD_NON_INTR_MODE)
+		map_cfg.max_register = AMD_UCSI_INTR_REG;
+
 	if (reg == swab32(DW_IC_COMP_TYPE_VALUE)) {
 		map_cfg.reg_read = dw_reg_read_swab;
 		map_cfg.reg_write = dw_reg_write_swab;
drivers/i2c/busses/i2c-designware-core.h +3 -0
index 5392b82f68a4..f29923c452ac 100644
@@ -293,9 +293,12 @@ struct dw_i2c_dev {
 #define ACCESS_INTR_MASK	BIT(0)
 #define ACCESS_NO_IRQ_SUSPEND	BIT(1)
 
+#define AMD_NON_INTR_MODE	BIT(2)
 #define MODEL_MSCC_OCELOT	BIT(8)
 #define MODEL_BAIKAL_BT1	BIT(9)
 #define MODEL_MASK		GENMASK(11, 8)
+#define AMD_UCSI_INTR_EN	0xd
+#define AMD_UCSI_INTR_REG	0x474
 
 int i2c_dw_init_regmap(struct dw_i2c_dev *dev);
 u32 i2c_dw_scl_hcnt(u32 ic_clk, u32 tSYMBOL, u32 tf, int cond, int offset);
drivers/i2c/busses/i2c-designware-master.c +136 -0

166 lines not on this page · raw message

drivers/i2c/busses/i2c-designware-pcidrv.c +57 -0

104 lines not on this page · raw message

Signature · 1 line
2.25.1
#1 lore raw

Hi

Quoted 76 lines · Sanket Goswami

The Latest AMD NAVI GPU card has an integrated Type-C controller and Designware I2C with PCI Interface. The Type-C controller can be accessed over I2C. The client driver is part of the USB Type-C UCSI driver.

Also, there exists a couple of notable IP limitations that are dealt as workarounds:
- I2C transaction work on a polling mode as IP does not generate interrupt.
- I2C read command sent twice to address the IP issues.

---
Changes in v2:
- Utilized existing functionality of i2c_dw_xfer_init to configure I2C bus.
- Removed i2c_dw_populate_client and rewrrient navi_amd_register_client to deduplicate from existing drivers.
- Addressed review comments from Andy.

drivers/i2c/busses/i2c-designware-common.c | 3 +

  drivers/i2c/busses/i2c-designware-core.h   |   3 +
  drivers/i2c/busses/i2c-designware-master.c | 136 +++++++++++++++++++++
  drivers/i2c/busses/i2c-designware-pcidrv.c |  57 +++++++++
  4 files changed, 199 insertions(+)
drivers/i2c/busses/i2c-designware-common.c +3 -0
index 3c19aada4b30..50883a70b482 100644
@@ -150,6 +150,9 @@ int i2c_dw_init_regmap(struct dw_i2c_dev *dev)
  	reg = readl(dev->base + DW_IC_COMP_TYPE);
  	i2c_dw_release_lock(dev);
 
+	if (dev->flags & AMD_NON_INTR_MODE)
+		map_cfg.max_register = AMD_UCSI_INTR_REG;
+
  	if (reg == swab32(DW_IC_COMP_TYPE_VALUE)) {
  		map_cfg.reg_read = dw_reg_read_swab;
  		map_cfg.reg_write = dw_reg_write_swab;
drivers/i2c/busses/i2c-designware-core.h +3 -0
index 5392b82f68a4..f29923c452ac 100644
@@ -293,9 +293,12 @@ struct dw_i2c_dev {
  #define ACCESS_INTR_MASK	BIT(0)
  #define ACCESS_NO_IRQ_SUSPEND	BIT(1)
 
+#define AMD_NON_INTR_MODE	BIT(2)
  #define MODEL_MSCC_OCELOT	BIT(8)
  #define MODEL_BAIKAL_BT1	BIT(9)
  #define MODEL_MASK		GENMASK(11, 8)
+#define AMD_UCSI_INTR_EN	0xd
+#define AMD_UCSI_INTR_REG	0x474
 
  int i2c_dw_init_regmap(struct dw_i2c_dev *dev);
  u32 i2c_dw_scl_hcnt(u32 ic_clk, u32 tSYMBOL, u32 tf, int cond, int offset);
drivers/i2c/busses/i2c-designware-master.c +4 -0
index dd27b9dbe931..a76e1f992850 100644
@@ -23,6 +23,10 @@
 
  #include "i2c-designware-core.h"
 
+#define AMD_TIMEOUT_MIN_MSEC	10000
+#define AMD_TIMEOUT_MAX_MSEC	11000
+#define AMD_MASTERCFG_MASK	GENMASK(15, 0)
+
  static void i2c_dw_configure_fifo_master(struct dw_i2c_dev *dev)
  {
  	/* Configure Tx/Rx FIFO threshold levels */

drivers/i2c/busses/i2c-designware-master.c static int i2c_dw_init_master(struct dw_i2c_dev *dev) · line 221

Quoted 10 lines
drivers/i2c/busses/i2c-designware-master.c +7 -0
@@ -208,6 +212,13 @@ static int i2c_dw_init_master(struct dw_i2c_dev *dev)
  	if (dev->sda_hold_time)
  		regmap_write(dev->map, DW_IC_SDA_HOLD, dev->sda_hold_time);
 
+	/*
+	 * In order to enable the interrupt for UCSI i.e. AMD NAVI GPU card,
+	 * it is mandatory to set the right value in specific register
+	 * (offset:0x474) as per the hardware IP specification.
+	 */
+	if (dev->flags & AMD_NON_INTR_MODE)
+		regmap_write(dev->map, AMD_UCSI_INTR_REG, AMD_UCSI_INTR_EN);

This confuses me - this patch is about adding support for DesignWare IP that does not generate interrupts but here code is enabling an interrupt. I guess it's for UCSI but should above code then go to a driver handling that IP?

Quoted 1 line
drivers/i2c/busses/i2c-designware-master.c +1 -0
+static int i2c_dw_check_stopbit(struct dw_i2c_dev *i2cd)

...

Quoted 1 line

+static int i2c_dw_status(struct dw_i2c_dev *i2cd)

...

Quoted 1 line

+static int amd_i2c_dw_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num_msgs)

...

drivers/i2c/busses/i2c-designware-master.c

Quoted 2 lines
drivers/i2c/busses/i2c-designware-master.c +2 -0
+{
+	struct dw_i2c_dev *i2cd = i2c_get_adapdata(adap);

For uniformity I'd use struct dw_i2c_dev *dev name instead of *i2cd since that what driver uses currently in other places.

drivers/i2c/busses/i2c-designware-master.c i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) · line 597

Quoted 12 lines
drivers/i2c/busses/i2c-designware-master.c +7 -0
@@ -461,6 +587,13 @@ i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
  	dev_dbg(dev->dev, "%s: msgs: %d\n", __func__, num);
 
  	pm_runtime_get_sync(dev->dev);
+	/*
+	 * Initiate I2C message transfer when AMD NAVI GPU card is enabled,
+	 * As it is polling based transfer mechanism, which does not support
+	 * interrupt based functionalities of existing DesignWare driver.
+	 */
+	if (dev->flags & AMD_NON_INTR_MODE)
+		return amd_i2c_dw_master_xfer(adap, msgs, num);
 

Does runtime PM go out of sync here?

Jarkko

#2 lore raw

Hi Jarkko,

Quoted 84 lines · Jarkko Nikula

[CAUTION: External Email]

Hi

Quoted 79 lines · Sanket Goswami

The Latest AMD NAVI GPU card has an integrated Type-C controller and Designware I2C with PCI Interface. The Type-C controller can be accessed over I2C. The client driver is part of the USB Type-C UCSI driver.

Also, there exists a couple of notable IP limitations that are dealt as workarounds:
- I2C transaction work on a polling mode as IP does not generate interrupt.
- I2C read command sent twice to address the IP issues.

---
Changes in v2:
- Utilized existing functionality of i2c_dw_xfer_init to configure I2C bus.
- Removed i2c_dw_populate_client and rewrrient navi_amd_register_client to deduplicate from existing drivers.
- Addressed review comments from Andy.

drivers/i2c/busses/i2c-designware-common.c |   3 + drivers/i2c/busses/i2c-designware-core.h   |   3 + drivers/i2c/busses/i2c-designware-master.c | 136 +++++++++++++++++++++ drivers/i2c/busses/i2c-designware-pcidrv.c |  57 +++++++++

  4 files changed, 199 insertions(+)
drivers/i2c/busses/i2c-designware-common.c +3 -0
index 3c19aada4b30..50883a70b482 100644
@@ -150,6 +150,9 @@ int i2c_dw_init_regmap(struct dw_i2c_dev *dev)
       reg = readl(dev->base + DW_IC_COMP_TYPE);
       i2c_dw_release_lock(dev);
 
+     if (dev->flags & AMD_NON_INTR_MODE)
+             map_cfg.max_register = AMD_UCSI_INTR_REG;
+
       if (reg == swab32(DW_IC_COMP_TYPE_VALUE)) {
               map_cfg.reg_read = dw_reg_read_swab;
               map_cfg.reg_write = dw_reg_write_swab;
drivers/i2c/busses/i2c-designware-core.h +3 -0
index 5392b82f68a4..f29923c452ac 100644
@@ -293,9 +293,12 @@ struct dw_i2c_dev {
   #define ACCESS_INTR_MASK    BIT(0)
   #define ACCESS_NO_IRQ_SUSPEND       BIT(1)
 
+#define AMD_NON_INTR_MODE    BIT(2)
   #define MODEL_MSCC_OCELOT   BIT(8)
   #define MODEL_BAIKAL_BT1    BIT(9)
   #define MODEL_MASK          GENMASK(11, 8)
+#define AMD_UCSI_INTR_EN     0xd
+#define AMD_UCSI_INTR_REG    0x474
 
   int i2c_dw_init_regmap(struct dw_i2c_dev *dev);
   u32 i2c_dw_scl_hcnt(u32 ic_clk, u32 tSYMBOL, u32 tf, int cond, int offset);
drivers/i2c/busses/i2c-designware-master.c +4 -0
index dd27b9dbe931..a76e1f992850 100644
@@ -23,6 +23,10 @@
 
   #include "i2c-designware-core.h"
 
+#define AMD_TIMEOUT_MIN_MSEC 10000
+#define AMD_TIMEOUT_MAX_MSEC 11000
+#define AMD_MASTERCFG_MASK   GENMASK(15, 0)
+
   static void i2c_dw_configure_fifo_master(struct dw_i2c_dev *dev)
   {
       /* Configure Tx/Rx FIFO threshold levels */
@@ -208,6 +212,13 @@ static int i2c_dw_init_master(struct dw_i2c_dev *dev)
       if (dev->sda_hold_time)
               regmap_write(dev->map, DW_IC_SDA_HOLD, dev->sda_hold_time);
 
Quoted 12 lines

drivers/i2c/busses/i2c-designware-master.c static int i2c_dw_init_master(struct dw_i2c_dev *dev) · line 221

Quoted 7 lines
drivers/i2c/busses/i2c-designware-master.c +7 -0
+     /*
+      * In order to enable the interrupt for UCSI i.e. AMD NAVI GPU card,
+      * it is mandatory to set the right value in specific register
+      * (offset:0x474) as per the hardware IP specification.
+      */
+     if (dev->flags & AMD_NON_INTR_MODE)
+             regmap_write(dev->map, AMD_UCSI_INTR_REG, AMD_UCSI_INTR_EN);

This confuses me - this patch is about adding support for DesignWare IP that does not generate interrupts but here code is enabling an interrupt. I guess it's for UCSI but should above code then go to a driver handling that IP?

That's true, This patch is regarding DesignWare IP. However, interrupt enablement for UCSI has to be performed from the I2C master driver as AMD_UCSI_INTR_REG is part of this DesignWare IP specification. Hence, we feel this should not be part of the UCSI driver. Please suggest if you have any alternate thoughts.

Quoted 4 lines
Quoted 2 lines
drivers/i2c/busses/i2c-designware-master.c +1 -0
+static int i2c_dw_check_stopbit(struct dw_i2c_dev *i2cd)

...

Quoted 1 line

+static int i2c_dw_status(struct dw_i2c_dev *i2cd)

Quoted 8 lines

...

Quoted 1 line

+static int amd_i2c_dw_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num_msgs)

...

Quoted 2 lines

+{
+     struct dw_i2c_dev *i2cd = i2c_get_adapdata(adap);

For uniformity I'd use struct dw_i2c_dev *dev name instead of *i2cd since that what driver uses currently in other places.

Got your point, it will be addressed in v3.

Quoted 4 lines
Quoted 4 lines
drivers/i2c/busses/i2c-designware-master.c +0 -0
@@ -461,6 +587,13 @@ i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
       dev_dbg(dev->dev, "%s: msgs: %d\n", __func__, num);
 
Quoted 10 lines

drivers/i2c/busses/i2c-designware-master.c i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) · line 597

Quoted 9 lines
drivers/i2c/busses/i2c-designware-master.c +7 -0
       pm_runtime_get_sync(dev->dev);
+     /*
+      * Initiate I2C message transfer when AMD NAVI GPU card is enabled,
+      * As it is polling based transfer mechanism, which does not support
+      * interrupt based functionalities of existing DesignWare driver.
+      */
+     if (dev->flags & AMD_NON_INTR_MODE)
+             return amd_i2c_dw_master_xfer(adap, msgs, num);
 

Does runtime PM go out of sync here?

Thanks for pointing out this, It will be also addressed in v3.

Quoted 2 lines

Jarkko

Thanks,
Sanket