summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMary Ruthven <mruthven@chromium.org>2016-10-07 16:36:17 -0700
committerchrome-bot <chrome-bot@chromium.org>2016-10-11 23:01:59 -0700
commit4aa7cd72cfde2d98e5a7e587b709f8bdac28527e (patch)
treece4031260d9d8019e6d4407aaca9c08db8db7321
parent02915f491f1621df97de8b1829ffebe62f8de0fe (diff)
downloadchrome-ec-4aa7cd72cfde2d98e5a7e587b709f8bdac28527e.tar.gz
g: use devid 0 and 1 to create a serial number
To be able to identify different cr50 devices connected to the same machine we need a serial number. This change uses dev id 0 and 1 to come up with one. BUG=chrome-os-partner:56641 BUG=chrome-os-partner:58342 BRANCH=none TEST=lsusb -vd 18d1:5014 | grep iSerial shows different numbers for different devices. Verify when ccd is disabled the serial number is 0. Change-Id: I85c54af4a21bdfd0542019c02aa8420d9a879fae Signed-off-by: Mary Ruthven <mruthven@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/395633 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
-rw-r--r--board/cr50/board.c1
-rw-r--r--board/cr50/board.h3
-rw-r--r--board/cr50/rdd.c2
-rw-r--r--chip/g/usb.c80
-rw-r--r--common/case_closed_debug.c5
-rw-r--r--include/case_closed_debug.h5
6 files changed, 93 insertions, 3 deletions
diff --git a/board/cr50/board.c b/board/cr50/board.c
index ed34fa3000..e7b8bc1988 100644
--- a/board/cr50/board.c
+++ b/board/cr50/board.c
@@ -324,6 +324,7 @@ const void * const usb_strings[] = {
[USB_STR_EC_NAME] = USB_STRING_DESC("EC"),
[USB_STR_UPGRADE_NAME] = USB_STRING_DESC("Firmware upgrade"),
[USB_STR_SPI_NAME] = USB_STRING_DESC("AP EC upgrade"),
+ [USB_STR_SERIALNO] = USB_STRING_DESC(DEFAULT_SERIALNO),
};
BUILD_ASSERT(ARRAY_SIZE(usb_strings) == USB_STR_COUNT);
#endif
diff --git a/board/cr50/board.h b/board/cr50/board.h
index 10f99b7a75..120928afce 100644
--- a/board/cr50/board.h
+++ b/board/cr50/board.h
@@ -65,6 +65,8 @@
#define CONFIG_USB_INHIBIT_INIT
#define CONFIG_USB_SELECT_PHY
#define CONFIG_USB_SPI
+#define CONFIG_USB_SERIALNO
+#define DEFAULT_SERIALNO "0"
#define CONFIG_STREAM_USART
#define CONFIG_STREAM_USB
@@ -115,6 +117,7 @@ enum usb_strings {
USB_STR_EC_NAME,
USB_STR_UPGRADE_NAME,
USB_STR_SPI_NAME,
+ USB_STR_SERIALNO,
USB_STR_COUNT
};
diff --git a/board/cr50/rdd.c b/board/cr50/rdd.c
index 49bb0297d0..9345210f2c 100644
--- a/board/cr50/rdd.c
+++ b/board/cr50/rdd.c
@@ -34,7 +34,7 @@ static struct uart_config uarts[] = {
static int ccd_is_enabled(void)
{
- return !gpio_get_level(GPIO_CCD_MODE_L);
+ return ccd_get_mode() == CCD_MODE_ENABLED;
}
int is_utmi_wakeup_allowed(void)
diff --git a/chip/g/usb.c b/chip/g/usb.c
index a0a0c5b98d..1e93b0ac04 100644
--- a/chip/g/usb.c
+++ b/chip/g/usb.c
@@ -3,6 +3,7 @@
* found in the LICENSE file.
*/
+#include "case_closed_debug.h"
#include "clock.h"
#include "common.h"
#include "config.h"
@@ -11,6 +12,7 @@
#include "hooks.h"
#include "init_chip.h"
#include "link_defs.h"
+#include "printf.h"
#include "registers.h"
#include "system.h"
#include "task.h"
@@ -26,6 +28,13 @@
#define CPRINTS(format, args...) cprints(CC_USB, format, ## args)
#define CPRINTF(format, args...) cprintf(CC_USB, format, ## args)
+#define USE_SERIAL_NUMBER (defined(CONFIG_USB_SERIALNO) && \
+ defined(CONFIG_CASE_CLOSED_DEBUG))
+
+#if !USE_SERIAL_NUMBER
+#define USB_STR_SERIALNO 0
+#endif
+
/* This is not defined anywhere else. Change it here to debug. */
#undef DEBUG_ME
#ifdef DEBUG_ME
@@ -213,7 +222,7 @@ static const struct usb_device_descriptor dev_desc = {
.bcdDevice = CONFIG_USB_BCD_DEV,
.iManufacturer = USB_STR_VENDOR,
.iProduct = USB_STR_PRODUCT,
- .iSerialNumber = 0,
+ .iSerialNumber = USB_STR_SERIALNO,
.bNumConfigurations = 1
};
@@ -598,7 +607,13 @@ static int handle_setup_with_in_stage(enum table_case tc,
case USB_DT_STRING:
if (idx >= USB_STR_COUNT)
return -1;
- data = usb_strings[idx];
+#if USE_SERIAL_NUMBER
+ if (idx == USB_STR_SERIALNO &&
+ ccd_get_mode() == CCD_MODE_ENABLED)
+ data = usb_serialno_desc;
+ else
+#endif
+ data = usb_strings[idx];
len = *(uint8_t *)data;
break;
case USB_DT_DEVICE_QUALIFIER:
@@ -1407,3 +1422,64 @@ static int command_usb(int argc, char **argv)
DECLARE_CONSOLE_COMMAND(usb, command_usb,
"[<BOOLEAN> | a | b]",
"Get/set the USB connection state and PHY selection");
+
+#if USE_SERIAL_NUMBER
+/* This will be subbed into USB_STR_SERIALNO. */
+struct usb_string_desc *usb_serialno_desc =
+ USB_WR_STRING_DESC(DEFAULT_SERIALNO);
+
+/* Update serial number */
+static int usb_set_serial(const char *serialno)
+{
+ struct usb_string_desc *sd = usb_serialno_desc;
+ int i;
+
+ if (!serialno)
+ return EC_ERROR_INVAL;
+
+ /* Convert into unicode usb string desc. */
+ for (i = 0; i < USB_STRING_LEN; i++) {
+ sd->_data[i] = serialno[i];
+ if (serialno[i] == 0)
+ break;
+ }
+ /* Count wchars (w/o null terminator) plus size & type bytes. */
+ sd->_len = (i * 2) + 2;
+ sd->_type = USB_DT_STRING;
+
+ return EC_SUCCESS;
+}
+
+static void usb_load_serialno(void)
+{
+ char devid_str[20];
+
+ snprintf(devid_str, 20, "%08X-%08X", GREG32(FUSE, DEV_ID0),
+ GREG32(FUSE, DEV_ID1));
+
+ usb_set_serial(devid_str);
+}
+DECLARE_HOOK(HOOK_INIT, usb_load_serialno, HOOK_PRIO_DEFAULT - 1);
+
+static int command_serialno(int argc, char **argv)
+{
+ struct usb_string_desc *sd = usb_serialno_desc;
+ char buf[USB_STRING_LEN];
+ int rv = EC_SUCCESS;
+ int i;
+
+ if (argc != 1) {
+ ccprintf("Setting serial number\n");
+ rv = usb_set_serial(argv[1]);
+ }
+
+ for (i = 0; i < USB_STRING_LEN; i++)
+ buf[i] = sd->_data[i];
+ ccprintf("Serial number: %s\n", buf);
+ return rv;
+}
+
+DECLARE_CONSOLE_COMMAND(serialno, command_serialno,
+ "[value]",
+ "Read and write USB serial number");
+#endif
diff --git a/common/case_closed_debug.c b/common/case_closed_debug.c
index 52a6c98e27..94fd164330 100644
--- a/common/case_closed_debug.c
+++ b/common/case_closed_debug.c
@@ -60,3 +60,8 @@ void ccd_set_mode(enum ccd_mode new_mode)
usb_init();
#endif
}
+
+enum ccd_mode ccd_get_mode(void)
+{
+ return current_mode;
+}
diff --git a/include/case_closed_debug.h b/include/case_closed_debug.h
index ed2f13d099..c1f43dd4d3 100644
--- a/include/case_closed_debug.h
+++ b/include/case_closed_debug.h
@@ -37,4 +37,9 @@ void ccd_set_mode(enum ccd_mode new_mode);
/* Initialize the PHY based on CCD state */
void ccd_phy_init(int enable_ccd);
+
+/*
+ * Get current CCD mode.
+ */
+enum ccd_mode ccd_get_mode(void);
#endif /* __CROS_EC_CASE_CLOSED_DEBUG_H */