diff options
author | Edward Hill <ecgh@chromium.org> | 2018-03-16 14:20:42 -0600 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-03-18 23:11:01 -0700 |
commit | 3404320f874cdeef74294c5910c8bdf63db769ed (patch) | |
tree | f0390a20afc5032e888cb6ca9cc496794899f24d /board/grunt | |
parent | 25039a3ba16615bafcd18c1d913f3c6474d70c7c (diff) | |
download | chrome-ec-3404320f874cdeef74294c5910c8bdf63db769ed.tar.gz |
grunt: Read SKU ID and report it to AP
Add 2 ADC channels for SKU ID. Each channel gives a 0-15 level,
these are combined to give a 0-255 SKU ID. The AP reads this
using EC_CMD_GET_SKU_ID.
BUG=b:75285661
BRANCH=none
TEST=EC_CMD_GET_SKU_ID (HC 0x0e) now succeeds
TEST=dmidecode | grep sku
Change-Id: I5b03e478518a1bb0ce7107451d71a82b7e48ec86
Signed-off-by: Edward Hill <ecgh@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/967223
Diffstat (limited to 'board/grunt')
-rw-r--r-- | board/grunt/board.c | 63 | ||||
-rw-r--r-- | board/grunt/board.h | 3 | ||||
-rw-r--r-- | board/grunt/gpio.inc | 2 |
3 files changed, 68 insertions, 0 deletions
diff --git a/board/grunt/board.c b/board/grunt/board.c index b9b477f19a..b302ce63d1 100644 --- a/board/grunt/board.c +++ b/board/grunt/board.c @@ -126,6 +126,12 @@ const struct adc_t adc_channels[] = { [ADC_VBUS] = { "VBUS", NPCX_ADC_CH8, ADC_MAX_VOLT*10, ADC_READ_MAX+1, 0 }, + [ADC_SKU_ID1] = { + "SKU1", NPCX_ADC_CH9, ADC_MAX_VOLT, ADC_READ_MAX+1, 0 + }, + [ADC_SKU_ID2] = { + "SKU2", NPCX_ADC_CH4, ADC_MAX_VOLT, ADC_READ_MAX+1, 0 + }, }; BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT); @@ -643,3 +649,60 @@ void lid_angle_peripheral_enable(int enable) keyboard_scan_enable(enable, KB_SCAN_DISABLE_LID_ANGLE); } #endif + +static const int sku_thresh_mv[] = { + /* Vin = 3.3V, Ideal voltage, R2 values listed below */ + /* R1 = 51.1 kOhm */ + 200, /* 124 mV, 2.0 Kohm */ + 366, /* 278 mV, 4.7 Kohm */ + 550, /* 456 mV, 8.2 Kohm */ + 752, /* 644 mV, 12.4 Kohm */ + 927, /* 860 mV, 18.0 Kohm */ + 1073, /* 993 mV, 22.0 Kohm */ + 1235, /* 1152 mV, 27.4 Kohm */ + 1386, /* 1318 mV, 34.0 Kohm */ + 1552, /* 1453 mV, 40.2 Kohm */ + /* R1 = 10.0 kOhm */ + 1739, /* 1650 mV, 10.0 Kohm */ + 1976, /* 1827 mV, 12.4 Kohm */ + 2197, /* 2121 mV, 18.0 Kohm */ + 2344, /* 2269 mV, 22.0 Kohm */ + 2484, /* 2418 mV, 27.4 Kohm */ + 2636, /* 2550 mV, 34.0 Kohm */ + 2823, /* 2721 mV, 47.0 Kohm */ +}; + +static int board_read_sku_adc(enum adc_channel chan) +{ + int mv; + int i; + + mv = adc_read_channel(chan); + + if (mv == ADC_READ_ERROR) + return -1; + + for (i = 0; i < ARRAY_SIZE(sku_thresh_mv); i++) + if (mv < sku_thresh_mv[i]) + return i; + + return -1; +} + +uint32_t system_get_sku_id(void) +{ + static uint32_t sku_id = -1; + int sku_id1, sku_id2; + + if (sku_id != -1) + return sku_id; + + sku_id1 = board_read_sku_adc(ADC_SKU_ID1); + sku_id2 = board_read_sku_adc(ADC_SKU_ID2); + + if (sku_id1 < 0 || sku_id2 < 0) + return 0; + + sku_id = (sku_id2 << 4) | sku_id1; + return sku_id; +} diff --git a/board/grunt/board.h b/board/grunt/board.h index 65e3d1ebb5..c14b0e5cec 100644 --- a/board/grunt/board.h +++ b/board/grunt/board.h @@ -34,6 +34,7 @@ #define CONFIG_BACKLIGHT_LID #define CONFIG_BACKLIGHT_LID_ACTIVE_LOW #define CONFIG_BOARD_VERSION +#define CONFIG_HOSTCMD_SKUID #define CONFIG_I2C #define CONFIG_I2C_MASTER #define CONFIG_LPC @@ -173,6 +174,8 @@ enum adc_channel { ADC_TEMP_SENSOR_CHARGER, ADC_TEMP_SENSOR_SOC, ADC_VBUS, + ADC_SKU_ID1, + ADC_SKU_ID2, ADC_CH_COUNT }; diff --git a/board/grunt/gpio.inc b/board/grunt/gpio.inc index 458cd6a41a..9522364776 100644 --- a/board/grunt/gpio.inc +++ b/board/grunt/gpio.inc @@ -103,6 +103,8 @@ ALTERNATE(PIN_MASK(D, 0x03), 1, MODULE_I2C, 0) /* I2C3 */ ALTERNATE(PIN_MASK(3, 0x48), 1, MODULE_I2C, 0) /* I2C5 */ ALTERNATE(PIN_MASK(B, 0x0C), 1, MODULE_I2C, 0) /* I2C7 */ ALTERNATE(PIN_MASK(4, 0x30), 1, MODULE_ADC, 0) /* ADC0-1 */ +ALTERNATE(PIN_MASK(4, 0x02), 1, MODULE_ADC, 0) /* ADC4 */ +ALTERNATE(PIN_MASK(F, 0x01), 1, MODULE_ADC, 0) /* ADC9 */ ALTERNATE(PIN_MASK(B, 0x80), 1, MODULE_PWM, 0) /* KB Backlight */ ALTERNATE(PIN_MASK(C, 0x18), 1, MODULE_PWM, 0) /* LED 1 & 2 */ |