2018-10-12 07:27:15 +02:00
|
|
|
/*
|
|
|
|
* This file is part of the coreboot project.
|
|
|
|
*
|
|
|
|
* Copyright 2018 MediaTek Inc.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <boardid.h>
|
|
|
|
#include <soc/auxadc.h>
|
2019-02-23 04:25:02 +01:00
|
|
|
#include <ec/google/chromeec/ec.h>
|
2018-10-12 07:27:15 +02:00
|
|
|
#include <stddef.h>
|
|
|
|
|
2019-02-26 18:33:50 +01:00
|
|
|
/* For CBI un-provisioned/corrupted Flapjack board. */
|
|
|
|
#define FLAPJACK_UNDEF_SKU_ID 0
|
2019-02-23 04:25:02 +01:00
|
|
|
|
2018-10-12 07:27:15 +02:00
|
|
|
static uint32_t get_index(unsigned int channel, uint32_t *cached_id)
|
|
|
|
{
|
|
|
|
static const int voltages[] = {
|
|
|
|
/* ID : Voltage (unit: uV) */
|
|
|
|
/* 0 : */ 74000,
|
|
|
|
/* 1 : */ 212000,
|
|
|
|
/* 2 : */ 319000,
|
|
|
|
/* 3 : */ 429000,
|
|
|
|
/* 4 : */ 542000,
|
|
|
|
/* 5 : */ 666000,
|
|
|
|
/* 6 : */ 781000,
|
|
|
|
/* 7 : */ 900000,
|
|
|
|
/* 8 : */ 1023000,
|
|
|
|
/* 9 : */ 1137000,
|
|
|
|
/* 10 : */ 1240000,
|
|
|
|
/* 11 : */ 1343000,
|
2019-01-03 08:23:59 +01:00
|
|
|
/* 12 : */ 1457000,
|
|
|
|
/* 13 : */ 1576000,
|
|
|
|
/* 14 : */ 1684000,
|
|
|
|
/* 15 : */ 1800000,
|
2018-10-12 07:27:15 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
uint32_t id;
|
|
|
|
|
2019-01-03 08:22:26 +01:00
|
|
|
if (*cached_id != BOARD_ID_INIT)
|
2018-10-12 07:27:15 +02:00
|
|
|
return *cached_id;
|
|
|
|
|
|
|
|
int value = auxadc_get_voltage(channel);
|
|
|
|
/* Find the closest voltage */
|
|
|
|
for (id = 0; id < ARRAY_SIZE(voltages) - 1; id++)
|
|
|
|
if (value < (voltages[id] + voltages[id + 1]) / 2)
|
|
|
|
break;
|
|
|
|
|
|
|
|
const int tolerance = 10000; /* 10,000 uV */
|
|
|
|
assert(ABS(value - voltages[id]) < tolerance);
|
|
|
|
|
|
|
|
*cached_id = id;
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2019-01-03 07:31:04 +01:00
|
|
|
/* board_id is provided by ec/google/chromeec/ec_boardid.c */
|
|
|
|
|
|
|
|
uint32_t sku_id(void)
|
2018-10-12 07:27:15 +02:00
|
|
|
{
|
2019-01-03 07:31:04 +01:00
|
|
|
static uint32_t cached_sku_id = BOARD_ID_INIT;
|
|
|
|
|
2019-02-26 18:33:50 +01:00
|
|
|
/* On Flapjack, getting the SKU via CBI. */
|
2019-03-06 01:53:33 +01:00
|
|
|
if (CONFIG(BOARD_GOOGLE_FLAPJACK)) {
|
2019-02-23 04:25:02 +01:00
|
|
|
if (cached_sku_id == BOARD_ID_INIT &&
|
|
|
|
google_chromeec_cbi_get_sku_id(&cached_sku_id))
|
|
|
|
cached_sku_id = FLAPJACK_UNDEF_SKU_ID;
|
|
|
|
return cached_sku_id;
|
|
|
|
}
|
|
|
|
|
2019-01-03 07:31:04 +01:00
|
|
|
/* Quirk for KUKUI: All P1/SKU0 had incorrectly set SKU=1. */
|
2019-03-06 01:53:33 +01:00
|
|
|
if (CONFIG(BOARD_GOOGLE_KUKUI)) {
|
2019-01-03 07:31:04 +01:00
|
|
|
if (cached_sku_id == BOARD_ID_INIT && board_id() == 1) {
|
|
|
|
cached_sku_id = 0;
|
|
|
|
return cached_sku_id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return get_index(4, &cached_sku_id);
|
2018-10-12 07:27:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t ram_code(void)
|
|
|
|
{
|
2019-01-03 08:22:26 +01:00
|
|
|
static uint32_t cached_ram_code = BOARD_ID_INIT;
|
2018-10-12 07:27:15 +02:00
|
|
|
return get_index(3, &cached_ram_code);
|
|
|
|
}
|