sarien: Set SPD page to 0 before reading

In some cases FSP might leave the SPD pointer set to page 1,
which will cause mosys to not be able to read the SPD info.
To fix this force a write to address 0x36 on the same I2C bus
which will set the page back to 0.

This change also switches to use a hard coded DIMM count rather
than reading it from SMBIOS.  This is because if there is a
DIMM only installed in slot B it will not be found if SMBIOS
says there is only 1 DIMM in the system.

BUG=b:123211109
BRANCH=none
TEST=test 'memory spd print all' on sarien/arcada with both
DIMMs installed, and with one DIMM installed in slot A or B.

Change-Id: Idcb872a8a54e374c6c344613772a24af7ba3e55e
Signed-off-by: Duncan Laurie <dlaurie@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1437739
Tested-by: Lijian Zhao <lijian.zhao@intel.com>
Tested-by: EricR Lai <ericr_lai@compal.corp-partner.google.com>
Reviewed-by: Furquan Shaikh <furquan@chromium.org>
Reviewed-by: Lijian Zhao <lijian.zhao@intel.com>
Reviewed-by: Shelley Chen <shchen@chromium.org>
diff --git a/platform/sarien/memory.c b/platform/sarien/memory.c
index 766c4b0..39ff399 100644
--- a/platform/sarien/memory.c
+++ b/platform/sarien/memory.c
@@ -45,16 +45,28 @@
 #include "sarien.h"
 
 #define SARIEN_DIMM_COUNT	2
+#define SARIEN_SPD_PAGE_0_ADDR	0x36
+#define SARIEN_SPD_PAGE_1_ADDR	0x37
+
+static int sarien_dimm_count(struct platform_intf *intf)
+{
+	return SARIEN_DIMM_COUNT;
+}
 
 static int sarien_spd_read(struct platform_intf *intf,
 		 int dimm, int reg, int spd_len, uint8_t *spd_buf)
 {
 	int bus;
 	int address;
+	uint8_t page_sel = 0;
 
 	bus = intf->cb->memory->dimm_map(intf, DIMM_TO_BUS, dimm);
 	address = intf->cb->memory->dimm_map(intf, DIMM_TO_ADDRESS, dimm);
 
+	/* First ensure SPD is pointing at page 0 */
+	intf->op->i2c->smbus_write_reg(intf, bus, SARIEN_SPD_PAGE_0_ADDR,
+				       0, sizeof(page_sel), &page_sel);
+
 	return spd_read_i2c(intf, bus, address, reg, spd_len, spd_buf);
 }
 
@@ -142,7 +154,7 @@
 };
 
 struct memory_cb sarien_memory_cb = {
-	.dimm_count	= smbios_dimm_count,
+	.dimm_count	= sarien_dimm_count,
 	.dimm_speed	= smbios_dimm_speed,
 	.dimm_map	= dimm_sarien_dimm_map,
 	.spd		= &sarien_spd_cb,