<commit_before>/* Copyright 2019 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "adc.h"
#include "adc_chip.h"
#include "backlight.h"
#include "button.h"
#include "charge_manager.h"
#include "charge_state.h"
#include "charger.h"
#include "chipset.h"
#include "common.h"
#include "console.h"
#include "cros_board_info.h"
#include "driver/accelgyro_bmi160.h"
#include "driver/als_opt3001.h"
#include "driver/battery/max17055.h"
#include "driver/charger/rt946x.h"
#include "driver/sync.h"
#include "driver/tcpm/mt6370.h"
#include "driver/temp_sensor/tmp432.h"
#include "ec_commands.h"
#include "extpower.h"
#include "gpio.h"
#include "hooks.h"
#include "host_command.h"
#include "i2c.h"
#include "power.h"
#include "power_button.h"
#include "lid_switch.h"
#include "pwm.h"
#include "pwm_chip.h"
#include "registers.h"
#include "spi.h"
#include "switch.h"
#include "system.h"
#include "task.h"
#include "tcpm.h"
#include "temp_sensor.h"
#include "temp_sensor_chip.h"
#include "thermal.h"
#include "timer.h"
#include "usb_charge.h"
#include "usb_mux.h"
#include "usb_pd_tcpm.h"
#include "util.h"
#include "driver/wpc/p9221.h"


#define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ## args)
#define CPRINTF(format, args...) cprintf(CC_USBCHARGE, format, ## args)

/* LCM_ID is embedded in SKU_ID bit[19-16] */
#define SKU_ID_TO_LCM_ID(x)	(((x) >> PANEL_ID_BIT_POSITION) & 0xf)
#define LCM_ID_TO_SKU_ID(x)	(((x) & 0xf) << PANEL_ID_BIT_POSITION)

static const struct mv_to_id panels[] = {
	{ PANEL_BOE_TV101WUM_NG0,	74 },
	{ PANEL_BOE_TV080WUM_NG0,	212 },
	{ PANEL_INX_OTA7290D10P,	1191 },
	{ PANEL_AUO_NT51021D8P,		1027 },
};
BUILD_ASSERT(ARRAY_SIZE(panels) < PANEL_COUNT);
BUILD_ASSERT(PANEL_COUNT <= PANEL_UNINITIALIZED);

uint16_t board_version;
uint8_t oem;
uint32_t sku = LCM_ID_TO_SKU_ID(PANEL_UNINITIALIZED);

int board_read_id(enum adc_channel ch, const struct mv_to_id *table, int size)
{
	int mv = adc_read_channel(ch);
	int i;

	if (mv == ADC_READ_ERROR)
		mv = adc_read_channel(ch);

	for (i = 0; i < size; i++) {
		if (ABS(mv - table[i].median_mv) < ADC_MARGIN_MV)
			return table[i].id;
	}

	return ADC_READ_ERROR;
}

static void board_setup_panel(void)
{
	uint8_t channel;
	uint8_t dim;
	int rv = 0;

	if (board_version >= 3) {
		switch (SKU_ID_TO_LCM_ID(sku)) {
		case PANEL_BOE_TV080WUM_NG0:<commit_msg>flapjack: Customize EOC according to battery specification<commit_after>/* Copyright 2019 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "adc.h"
#include "adc_chip.h"
#include "backlight.h"
#include "button.h"
#include "charge_manager.h"
#include "charge_state.h"
#include "charger.h"
#include "chipset.h"
#include "common.h"
#include "console.h"
#include "cros_board_info.h"
#include "driver/accelgyro_bmi160.h"
#include "driver/als_opt3001.h"
#include "driver/battery/max17055.h"
#include "driver/charger/rt946x.h"
#include "driver/sync.h"
#include "driver/tcpm/mt6370.h"
#include "driver/temp_sensor/tmp432.h"
#include "ec_commands.h"
#include "extpower.h"
#include "gpio.h"
#include "hooks.h"
#include "host_command.h"
#include "i2c.h"
#include "power.h"
#include "power_button.h"
#include "lid_switch.h"
#include "pwm.h"
#include "pwm_chip.h"
#include "registers.h"
#include "spi.h"
#include "switch.h"
#include "system.h"
#include "task.h"
#include "tcpm.h"
#include "temp_sensor.h"
#include "temp_sensor_chip.h"
#include "thermal.h"
#include "timer.h"
#include "usb_charge.h"
#include "usb_mux.h"
#include "usb_pd_tcpm.h"
#include "util.h"
#include "driver/wpc/p9221.h"


#define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ## args)
#define CPRINTF(format, args...) cprintf(CC_USBCHARGE, format, ## args)

/* LCM_ID is embedded in SKU_ID bit[19-16] */
#define SKU_ID_TO_LCM_ID(x)	(((x) >> PANEL_ID_BIT_POSITION) & 0xf)
#define LCM_ID_TO_SKU_ID(x)	(((x) & 0xf) << PANEL_ID_BIT_POSITION)

static const struct mv_to_id panels[] = {
	{ PANEL_BOE_TV101WUM_NG0,	74 },
	{ PANEL_BOE_TV080WUM_NG0,	212 },
	{ PANEL_INX_OTA7290D10P,	1191 },
	{ PANEL_AUO_NT51021D8P,		1027 },
};
BUILD_ASSERT(ARRAY_SIZE(panels) < PANEL_COUNT);
BUILD_ASSERT(PANEL_COUNT <= PANEL_UNINITIALIZED);

uint16_t board_version;
uint8_t oem;
uint32_t sku = LCM_ID_TO_SKU_ID(PANEL_UNINITIALIZED);

static const struct rt946x_init_setting battery_init_setting = {
	.eoc_current = 150,
	.mivr = 4000,
	.ircmp_vclamp = 32,
	.ircmp_res = 25,
	.boost_voltage = 5050,
	.boost_current = 1500,
};

int board_read_id(enum adc_channel ch, const struct mv_to_id *table, int size)
{
	int mv = adc_read_channel(ch);
	int i;

	if (mv == ADC_READ_ERROR)
		mv = adc_read_channel(ch);

	for (i = 0; i < size; i++) {
		if (ABS(mv - table[i].median_mv) < ADC_MARGIN_MV)
			return table[i].id;
	}

	return ADC_READ_ERROR;
}

const struct rt946x_init_setting *board_rt946x_init_setting(void)
{
	return &battery_init_setting;
}

static void board_setup_panel(void)
{
	uint8_t channel;
	uint8_t dim;
	int rv = 0;

	if (board_version >= 3) {
		switch (SKU_ID_TO_LCM_ID(sku)) {
		case PANEL_BOE_TV080WUM_NG0:
{'fraction_non_alphanumeric': 0.1437607820586544, 'fraction_numerical': 0.03756948437799502, 'mean_word_length': 5.457920792079208, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7020521', 'n_tokens_mistral': 2422, 'n_tokens_neox': 2250, 'n_words': 468}