erosqnative hw1/hw2: Check for DAC in bootloader

Check for the ES9018K2M dac in the bootloader for
hw1/hw2 devices. Assume that all devices newer than
hw2 have ES9018K2M DAC unconditionally.

All devices will now report the correct hw revision
in the debug menu under Device Data.

Add devicedata.version field, current version 0.

Rename device_data.lcd_version to device_data.hw_rev.

hw2 devices with older bootloaders which ID as hw1 are special-
cased to keep using hwvol on them. They should still upgrade though.

Change-Id: If0fd5ce3bc6e85e511047721ec18e42fb89312e7
This commit is contained in:
Dana Conrad 2024-11-30 20:51:15 +00:00 committed by Solomon Peachy
parent f895167345
commit adbd0125fd
13 changed files with 110 additions and 38 deletions

View file

@ -32,6 +32,7 @@
#include "aic-x1000.h"
#include "i2c-x1000.h"
#include "gpio-x1000.h"
#include "devicedata.h"
/*
* Earlier devices audio path appears to be:
@ -42,7 +43,7 @@
* DAC --> HP Amp --> Stereo Switch \--> HP OUT
* \-> LO OUT
*/
#if !defined(BOOTLOADER)
void audiohw_init(void)
{
/* explicitly mute everything */
@ -93,11 +94,18 @@ void audiohw_postinit(void)
i2c_x1000_set_freq(ES9018K2M_BUS, I2C_FREQ_400K);
int ret = es9018k2m_read_reg(ES9018K2M_REG0_SYSTEM_SETTINGS);
if (ret >= 0) /* Detected ES9018K2M DAC */
// devices hw2 and newer use es9018k2m i2c dac
// hw1 devices use swvol
// special case hw2 devices with bootloaders identifying as hw1 (pre-version field)
if (device_data.hw_rev >= 2 || \
(device_data.version == 0xff && eros_qn_discover_dac(true)))
{
logf("ES9018K2M found: ret=%d", ret);
es9018k2m_present_flag = 1;
#if defined(LOGF_ENABLE)
if (device_data.version == 0xff) {
logf("OLD BOOTLOADER FOUND, UPDATE IT!");
}
#endif
es9018k2m_present_flag = true;
/* Default is 32-bit data, and it works ok. Enabling the following
* causes issue. Which is weird, I definitely thought AIC was configured
@ -128,8 +136,6 @@ void audiohw_postinit(void)
* ! will hear random dropouts. (Fixed my SurfansF20 v3.2 dropouts) */
es9018k2m_write_reg(ES9018K2M_REG12_DPLL_SETTINGS, 0xda);
} else { /* Default to SWVOL for PCM5102A DAC */
logf("Default to SWVOL: ret=%d", ret);
}
}
@ -205,4 +211,5 @@ void audiohw_set_filter_roll_off(int value)
{
es9018k2m_set_filter_roll_off(value);
}
}
}
#endif /* !defined(BOOTLOADER) */

View file

@ -205,7 +205,7 @@ void button_init_device(void)
/* Set up headphone and line out detect polling */
#ifndef BOOTLOADER
hp_detect_init(device_data.lcd_version);
hp_detect_init(device_data.hw_rev);
#endif
}
@ -266,7 +266,7 @@ int button_read_device(void)
if((d & (1 << 5)) == 0) r |= BUTTON_BACK;
# endif
#else
if (device_data.lcd_version >= 4){
if (device_data.hw_rev >= 4){
if((b & (1 << 31)) == 0) r |= BUTTON_POWER;
if((a & (1 << 18)) == 0) r |= BUTTON_BACK;
} else {
@ -280,7 +280,7 @@ int button_read_device(void)
if((c & (1 << 24)) == 0) r |= BUTTON_NEXT;
#ifndef BOOTLOADER
if (device_data.lcd_version >= 4){
if (device_data.hw_rev >= 4){
// get new HP/LO detect states
// HP_detect PB14 --> hp_detect bit 4
// LO_detect PB22 --> hp_detect bit 5

View file

@ -297,7 +297,7 @@ void lcd_tgt_enable(bool enable)
gpio_set_level(GPIO_LCD_PWR_HW1, 1);
# endif
#else
if (device_data.lcd_version <= 3)
if (device_data.hw_rev <= 3)
{
gpio_set_level(GPIO_LCD_PWR_HW1, 1);
}
@ -322,7 +322,7 @@ void lcd_tgt_enable(bool enable)
lcd_exec_commands(&erosqnative_lcd_cmd_enable_v1[0]);
# endif
#else
if (device_data.lcd_version >= 3)
if (device_data.hw_rev >= 3)
{
lcd_exec_commands(&erosqnative_lcd_cmd_enable_v3[0]);
}

View file

@ -65,7 +65,7 @@ void power_init(void)
#if defined(BOOTLOADER)
devicever = EROSQN_VER;
#else
devicever = device_data.lcd_version;
devicever = device_data.hw_rev;
#endif
if (devicever >= 4){
uint8_t regread;
@ -165,7 +165,7 @@ void usb_charging_maxcurrent_change(int maxcurrent)
#if defined(BOOTLOADER)
devicever = EROSQN_VER;
#else
devicever = device_data.lcd_version;
devicever = device_data.hw_rev;
#endif
if (devicever >= 4){
axp2101_set_charge_current(maxcurrent);
@ -186,7 +186,7 @@ void power_off(void)
#if defined(BOOTLOADER)
devicever = EROSQN_VER;
#else
devicever = device_data.lcd_version;
devicever = device_data.hw_rev;
#endif
if (devicever >= 4){
axp2101_power_off();
@ -202,7 +202,7 @@ bool charging_state(void)
#if defined(BOOTLOADER)
devicever = EROSQN_VER;
#else
devicever = device_data.lcd_version;
devicever = device_data.hw_rev;
#endif
if (devicever >= 4){
return axp2101_battery_status() == AXP2101_BATT_CHARGING;
@ -217,7 +217,7 @@ int _battery_voltage(void)
#if defined(BOOTLOADER)
devicever = EROSQN_VER;
#else
devicever = device_data.lcd_version;
devicever = device_data.hw_rev;
#endif
if (devicever >= 4){
return axp2101_adc_read(AXP2101_ADC_VBAT_VOLTAGE);
@ -233,7 +233,7 @@ int _battery_current(void)
#if defined(BOOTLOADER)
devicever = EROSQN_VER;
#else
devicever = device_data.lcd_version;
devicever = device_data.hw_rev;
#endif
if (devicever <= 3){
if(charging_state())

View file

@ -67,7 +67,7 @@ void gpio_init(void)
# if defined(BOOTLOADER)
devicever = EROSQN_VER;
# else
devicever = device_data.lcd_version;
devicever = device_data.hw_rev;
# endif
#endif
/* Apply all initial GPIO settings */

View file

@ -41,6 +41,10 @@
#include "devicedata.h"
#endif
#if defined(EROS_QN)
#include "eros_qn_codec.h"
#endif
#ifdef X1000_CPUIDLE_STATS
int __cpu_idle_avg = 0;
int __cpu_idle_cur = 0;
@ -89,14 +93,23 @@ void system_early_init(void)
#if defined (HAVE_DEVICEDATA) && defined(EROS_QN)
void fill_devicedata(struct device_data_t *data)
{
#ifdef BOOTLOADER
# ifdef BOOTLOADER
memset(data->payload, 0xff, data->length);
data->lcd_version = EROSQN_VER;
#else
uint8_t lcd_version = device_data.lcd_version;
# if EROSQN_VER == 1
// version 2 has newer dac, 1 has old dac.
data->hw_rev = eros_qn_discover_dac(false) ? 2 : 1;
# else
// versions 3 and 4 both have new dac
data->hw_rev = EROSQN_VER;
# endif
data->version = DEIVCE_DATA_VERSION;
# else
uint8_t hw_rev = device_data.hw_rev;
uint8_t version = device_data.version;
memset(data->payload, 0xff, data->length);
data->lcd_version = lcd_version;
#endif
data->hw_rev = hw_rev;
data->version = version;
# endif
}
#endif