[Skiboot] [PATCH v2 2/5] npu2-opencapi: Rework adapter reset

Frederic Barrat fbarrat at linux.ibm.com
Thu May 24 03:25:42 AEST 2018


From: Frederic Barrat <fbarrat at linux.vnet.ibm.com>

Rework a bit the code to reset the opencapi adapter:
- make clearer which i2c pin is resetting which device
- break the reset operation in smaller chunks. This is really to
  prepare for a future patch.

No functional changes.

Signed-off-by: Frederic Barrat <fbarrat at linux.vnet.ibm.com>
---
v2:
	use literals in platform_ocapi structure


 core/platform.c          | 12 ++++----
 hw/npu2-opencapi.c       | 71 ++++++++++++++++++++++++++++++++++--------------
 include/platform.h       |  6 ++--
 platforms/astbmc/zaius.c | 13 ++++-----
 platforms/ibm-fsp/zz.c   | 12 ++++----
 5 files changed, 72 insertions(+), 42 deletions(-)

diff --git a/core/platform.c b/core/platform.c
index 92b118ba..3282227c 100644
--- a/core/platform.c
+++ b/core/platform.c
@@ -170,11 +170,11 @@ static int generic_start_preload_resource(enum resource_id id, uint32_t subid,
 
 /* These values will work for a ZZ booted using BML */
 const struct platform_ocapi generic_ocapi = {
-	.i2c_engine	= 1,
-	.i2c_port	= 4,
-	.i2c_offset	= { 0x3, 0x1, 0x1 },
-	.i2c_odl0_data	= { 0xFD, 0xFD, 0xFF },
-	.i2c_odl1_data	= { 0xBF, 0xBF, 0xFF },
+	.i2c_engine        = 1,
+	.i2c_port          = 4,
+	.i2c_reset_addr    = 0x20,
+	.i2c_reset_odl0    = (1 << 1),
+	.i2c_reset_odl1    = (1 << 6),
 	.i2c_presence_addr = 0x20,
 	.i2c_presence_odl0 = (1 << 2), /* bottom connector */
 	.i2c_presence_odl1 = (1 << 7), /* top connector */
@@ -184,7 +184,7 @@ const struct platform_ocapi generic_ocapi = {
 	 * force presence.
 	 */
 	.force_presence    = true,
-	.odl_phy_swap   = true,
+	.odl_phy_swap      = true,
 };
 
 static struct bmc_platform generic_bmc = {
diff --git a/hw/npu2-opencapi.c b/hw/npu2-opencapi.c
index b2bc0628..be0707ea 100644
--- a/hw/npu2-opencapi.c
+++ b/hw/npu2-opencapi.c
@@ -794,39 +794,70 @@ static void otl_enabletx(uint32_t gcid, uint32_t scom_base, uint64_t index)
 
 static void reset_ocapi_device(struct npu2_dev *dev)
 {
-	uint8_t data[3];
+	uint8_t pin, data;
 	int rc;
-	int i;
 
 	switch (dev->index) {
 	case 2:
 	case 4:
-		memcpy(data, platform.ocapi->i2c_odl0_data, sizeof(data));
+		pin = platform.ocapi->i2c_reset_odl0;
 		break;
 	case 3:
 	case 5:
-		memcpy(data, platform.ocapi->i2c_odl1_data, sizeof(data));
+		pin = platform.ocapi->i2c_reset_odl1;
 		break;
 	default:
 		assert(false);
 	}
 
-	for (i = 0; i < 3; i++) {
-		rc = i2c_request_send(dev->i2c_port_id_ocapi, 0x20, SMBUS_WRITE,
-				      platform.ocapi->i2c_offset[i], 1,
-				      &data[i], sizeof(data[i]), 120);
-		if (rc) {
-			/**
-			 * @fwts-label OCAPIDeviceResetFailed
-			 * @fwts-advice There was an error attempting to send
-			 * a reset signal over I2C to the OpenCAPI device.
-			 */
-			prlog(PR_ERR, "OCAPI: Error writing I2C reset signal: %d\n", rc);
-			break;
-		}
-		if (i != 0)
-			time_wait_ms(5);
-	}
+	/*
+	 * set the i2c reset pin in output mode
+	 *
+	 * On the 9554 device, register 3 is the configuration
+	 * register and a pin is in output mode if its value is 0
+	 */
+	data = ~pin;
+	rc = i2c_request_send(dev->i2c_port_id_ocapi,
+			platform.ocapi->i2c_reset_addr, SMBUS_WRITE,
+			0x3, 1,
+			&data, sizeof(data), 120);
+	if (rc)
+		goto err;
+
+	/*
+	 * assert i2c reset for 5ms
+	 * register 1 controls the signal, reset is active low
+	 */
+	data = ~pin;
+	rc = i2c_request_send(dev->i2c_port_id_ocapi,
+			platform.ocapi->i2c_reset_addr, SMBUS_WRITE,
+			0x1, 1,
+			&data, sizeof(data), 120);
+	if (rc)
+		goto err;
+	time_wait_ms(5);
+
+	/*
+	 * deassert i2c reset and wait 5ms
+	 */
+	data = 0xFF;
+	rc = i2c_request_send(dev->i2c_port_id_ocapi,
+			platform.ocapi->i2c_reset_addr, SMBUS_WRITE,
+			0x1, 1,
+			&data, sizeof(data), 120);
+	if (rc)
+		goto err;
+	time_wait_ms(5);
+
+	return;
+
+err:
+	/**
+	 * @fwts-label OCAPIDeviceResetFailed
+	 * @fwts-advice There was an error attempting to send
+	 * a reset signal over I2C to the OpenCAPI device.
+	 */
+	prlog(PR_ERR, "OCAPI: Error writing I2C reset signal: %d\n", rc);
 }
 
 static bool i2c_presence_detect(struct npu2_dev *dev)
diff --git a/include/platform.h b/include/platform.h
index 6fa016c2..1a35a86a 100644
--- a/include/platform.h
+++ b/include/platform.h
@@ -48,9 +48,9 @@ struct bmc_platform {
 struct platform_ocapi {
 	uint8_t i2c_engine;		/* I2C engine number */
 	uint8_t i2c_port;		/* I2C port number */
-	uint32_t i2c_offset[3];		/* Offsets on I2C device */
-	uint8_t i2c_odl0_data[3];	/* Data to reset ODL0 */
-	uint8_t i2c_odl1_data[3];	/* Data to reset ODL1 */
+	uint8_t i2c_reset_addr;		/* I2C address for reset */
+	uint8_t i2c_reset_odl0;		/* I2C pin to write to reset ODL0 */
+	uint8_t i2c_reset_odl1;		/* I2C pin to write to reset ODL1 */
 	uint8_t i2c_presence_addr;	/* I2C address for presence detection */
 	uint8_t i2c_presence_odl0;	/* I2C mask for detection on ODL0 */
 	uint8_t i2c_presence_odl1;	/* I2C mask for detection on ODL1 */
diff --git a/platforms/astbmc/zaius.c b/platforms/astbmc/zaius.c
index 52b072af..8bc649c1 100644
--- a/platforms/astbmc/zaius.c
+++ b/platforms/astbmc/zaius.c
@@ -24,17 +24,16 @@
 
 #include "astbmc.h"
 
-
 const struct platform_ocapi zaius_ocapi = {
-	.i2c_engine	= 1,
-	.i2c_port	= 4,
-	.i2c_offset	= { 0x3, 0x1, 0x1 },
-	.i2c_odl0_data	= { 0xFD, 0xFD, 0xFF },
-	.i2c_odl1_data	= { 0xBF, 0xBF, 0xFF },
+	.i2c_engine        = 1,
+	.i2c_port          = 4,
+	.i2c_reset_addr    = 0x20,
+	.i2c_reset_odl0    = (1 << 1),
+	.i2c_reset_odl1    = (1 << 6),
 	.i2c_presence_addr = 0x20,
 	.i2c_presence_odl0 = (1 << 2), /* bottom connector */
 	.i2c_presence_odl1 = (1 << 7), /* top connector */
-	.odl_phy_swap   = true,
+	.odl_phy_swap      = true,
 };
 
 #define NPU_BASE 0x5011000
diff --git a/platforms/ibm-fsp/zz.c b/platforms/ibm-fsp/zz.c
index 6c8411ec..dc48768b 100644
--- a/platforms/ibm-fsp/zz.c
+++ b/platforms/ibm-fsp/zz.c
@@ -29,11 +29,11 @@
 
 /* We don't yet create NPU device nodes on ZZ, but these values are correct */
 const struct platform_ocapi zz_ocapi = {
-	.i2c_engine	= 1,
-	.i2c_port	= 4,
-	.i2c_offset	= { 0x3, 0x1, 0x1 },
-	.i2c_odl0_data	= { 0xFD, 0xFD, 0xFF },
-	.i2c_odl1_data	= { 0xBF, 0xBF, 0xFF },
+	.i2c_engine        = 1,
+	.i2c_port          = 4,
+	.i2c_reset_addr    = 0x20,
+	.i2c_reset_odl0    = (1 << 1),
+	.i2c_reset_odl1    = (1 << 6),
 	.i2c_presence_addr = 0x20,
 	.i2c_presence_odl0 = (1 << 2), /* bottom connector */
 	.i2c_presence_odl1 = (1 << 7), /* top connector */
@@ -42,7 +42,7 @@ const struct platform_ocapi zz_ocapi = {
 	 * force the presence until all our systems are upgraded
 	 */
 	.force_presence    = true,
-	.odl_phy_swap   = true,
+	.odl_phy_swap      = true,
 };
 
 static bool zz_probe(void)
-- 
2.14.1



More information about the Skiboot mailing list