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>
|
2019-04-18 11:31:55 +02:00
|
|
|
#include <console/console.h>
|
2018-10-12 07:27:15 +02:00
|
|
|
#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
|
|
|
|
2019-04-10 10:52:21 +02:00
|
|
|
#define ADC_LEVELS 12
|
|
|
|
|
|
|
|
enum {
|
|
|
|
LCM_ID_CHANNEL = 2, /* ID of LCD Module on schematics. */
|
|
|
|
RAM_ID_CHANNEL = 3,
|
|
|
|
SKU_ID_CHANNEL = 4,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const int ram_voltages[ADC_LEVELS] = {
|
2018-10-12 07:27:15 +02:00
|
|
|
/* 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-04-10 10:52:21 +02:00
|
|
|
};
|
2018-10-12 07:27:15 +02:00
|
|
|
|
2019-04-10 10:52:21 +02:00
|
|
|
static const int lcm_voltages[ADC_LEVELS] = {
|
|
|
|
/* ID : Voltage (unit: uV) */
|
|
|
|
/* 0 : */ 0,
|
|
|
|
/* 1 : */ 283000,
|
2019-07-10 09:55:24 +02:00
|
|
|
/* 2 : */ 394000,
|
2019-04-10 10:52:21 +02:00
|
|
|
/* 3 : */ 503000,
|
|
|
|
/* 4 : */ 608000,
|
2019-07-10 09:55:24 +02:00
|
|
|
/* 5 : */ 712000,
|
|
|
|
/* 6 : */ 823000,
|
|
|
|
/* 7 : */ 937000,
|
|
|
|
/* 8 : */ 1046000,
|
|
|
|
/* 9 : */ 1155000,
|
|
|
|
/* 10 : */ 1277000,
|
2019-04-10 10:52:21 +02:00
|
|
|
/* 11 : */ 1434000,
|
|
|
|
};
|
2018-10-12 07:27:15 +02:00
|
|
|
|
2019-04-10 10:52:21 +02:00
|
|
|
static const int *adc_voltages[] = {
|
|
|
|
[LCM_ID_CHANNEL] = lcm_voltages,
|
|
|
|
[RAM_ID_CHANNEL] = ram_voltages,
|
|
|
|
[SKU_ID_CHANNEL] = ram_voltages, /* SKU ID is sharing RAM voltages. */
|
|
|
|
};
|
2018-10-12 07:27:15 +02:00
|
|
|
|
2019-04-10 10:52:21 +02:00
|
|
|
static uint32_t get_adc_index(unsigned int channel)
|
|
|
|
{
|
2018-10-12 07:27:15 +02:00
|
|
|
int value = auxadc_get_voltage(channel);
|
2019-04-10 10:52:21 +02:00
|
|
|
|
|
|
|
assert(channel < ARRAY_SIZE(adc_voltages));
|
|
|
|
const int *voltages = adc_voltages[channel];
|
|
|
|
assert(voltages);
|
|
|
|
|
2018-10-12 07:27:15 +02:00
|
|
|
/* Find the closest voltage */
|
2019-04-10 10:52:21 +02:00
|
|
|
uint32_t id;
|
|
|
|
for (id = 0; id < ADC_LEVELS - 1; id++)
|
2018-10-12 07:27:15 +02:00
|
|
|
if (value < (voltages[id] + voltages[id + 1]) / 2)
|
|
|
|
break;
|
2019-07-09 10:38:36 +02:00
|
|
|
printk(BIOS_DEBUG, "ADC[%d]: Raw value=%d ID=%d\n", channel, value, id);
|
2018-10-12 07:27:15 +02:00
|
|
|
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-04-10 10:52:21 +02:00
|
|
|
if (cached_sku_id != BOARD_ID_INIT)
|
|
|
|
return cached_sku_id;
|
|
|
|
|
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-04-10 10:52:21 +02:00
|
|
|
if (google_chromeec_cbi_get_sku_id(&cached_sku_id))
|
2019-02-23 04:25:02 +01:00
|
|
|
cached_sku_id = FLAPJACK_UNDEF_SKU_ID;
|
|
|
|
return cached_sku_id;
|
|
|
|
}
|
|
|
|
|
2019-04-10 10:52:21 +02:00
|
|
|
/* Quirk for Kukui: All Rev1/Sku0 had incorrectly set SKU_ID=1. */
|
2019-03-06 01:53:33 +01:00
|
|
|
if (CONFIG(BOARD_GOOGLE_KUKUI)) {
|
2019-04-10 10:52:21 +02:00
|
|
|
if (board_id() == 1) {
|
2019-01-03 07:31:04 +01:00
|
|
|
cached_sku_id = 0;
|
|
|
|
return cached_sku_id;
|
|
|
|
}
|
|
|
|
}
|
2019-04-10 10:52:21 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The SKU (later used for device tree matching) is combined from:
|
|
|
|
* ADC2[4bit/H] = straps on LCD module (type of panel).
|
|
|
|
* ADC4[4bit/L] = SKU ID from board straps.
|
|
|
|
*/
|
|
|
|
cached_sku_id = (get_adc_index(LCM_ID_CHANNEL) << 4 |
|
|
|
|
get_adc_index(SKU_ID_CHANNEL));
|
|
|
|
return 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;
|
2019-04-10 10:52:21 +02:00
|
|
|
|
|
|
|
if (cached_ram_code == BOARD_ID_INIT)
|
|
|
|
cached_ram_code = get_adc_index(RAM_ID_CHANNEL);
|
|
|
|
return cached_ram_code;
|
2018-10-12 07:27:15 +02:00
|
|
|
}
|