mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-27 18:25:05 +00:00
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>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
@@ -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)
|
||||
|
||||
80
chip/g/usb.c
80
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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user