From 3e7a09cb0dee0ee04b5c77f427bf89d990ec8d0b Mon Sep 17 00:00:00 2001 From: Dana Conrad Date: Sat, 26 Jun 2021 12:07:11 -0500 Subject: New Port: Eros Q Native What works: - LCD: 16-bit RGB565 - all buttons, including scrollwheel - SD Card - Battery level and charging/not charging status - USB - audio - sample rate switching - HP / LO detect, with "safe" fixed LO volume - LO volume will only be put to user-defined max volume if headphones are not present. - rtc - Plugins build, tried a couple and they seem OK - Bootloader, installable to nand via usbboot What doesn't work: - Dual Boot - power on/off has intermittent, low volume audio click (sometimes it's completely silent, sometimes there's a click) - Audio uses 16-bit volume scaling, so clicking/popping is pretty bad at lower volumes - need 32 bit volume scaling, 24 bit I2S data - USB HID keys not yet defined - no jztool support Unknowns: - Stereo Switch pins: Direction select, AC_DC (probably not even hooked up) - What is the actual purpose of the Stereo Swtich? - How does the bluetooth module connect? "Someday" stuff: - get LCD working at higher bit depth - Bluetooth Change-Id: I70dda8fc092c6e3f4352f2245e4164193f803c33 --- .../ingenic_x1000/erosqnative/power-erosqnative.c | 110 +++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 firmware/target/mips/ingenic_x1000/erosqnative/power-erosqnative.c (limited to 'firmware/target/mips/ingenic_x1000/erosqnative/power-erosqnative.c') diff --git a/firmware/target/mips/ingenic_x1000/erosqnative/power-erosqnative.c b/firmware/target/mips/ingenic_x1000/erosqnative/power-erosqnative.c new file mode 100644 index 0000000000..c466db66b1 --- /dev/null +++ b/firmware/target/mips/ingenic_x1000/erosqnative/power-erosqnative.c @@ -0,0 +1,110 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2021 Aidan MacDonald, Dana Conrad + * + * 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; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +// whole file copied from m3k + +#include "power.h" +#include "adc.h" +#include "system.h" +#include "kernel.h" +#ifdef HAVE_USB_CHARGING_ENABLE +# include "usb_core.h" +#endif +#include "axp-pmu.h" +#include "i2c-x1000.h" + +const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] = +{ + 3470 +}; + +/* the OF shuts down at this voltage */ +const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] = +{ + 3400 +}; + +/* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */ +const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] = +{ + { 3400, 3639, 3697, 3723, 3757, 3786, 3836, 3906, 3980, 4050, 4159 } +}; + +/* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */ +const unsigned short percent_to_volt_charge[11] = +{ + 3485, 3780, 3836, 3857, 3890, 3930, 3986, 4062, 4158, 4185, 4196 +}; + +void power_init(void) +{ + /* Initialize driver */ + i2c_x1000_set_freq(2, I2C_FREQ_400K); + axp_init(); + + /* Set lowest sample rate */ + axp_adc_set_rate(AXP_ADC_RATE_25HZ); + + /* Ensure battery voltage ADC is enabled */ + int bits = axp_adc_get_enabled(); + bits |= (1 << ADC_BATTERY_VOLTAGE); + axp_adc_set_enabled(bits); + + /* Turn on all power outputs */ + i2c_reg_modify1(AXP_PMU_BUS, AXP_PMU_ADDR, + AXP_REG_PWROUTPUTCTRL2, 0, 0x5f, NULL); + i2c_reg_modify1(AXP_PMU_BUS, AXP_PMU_ADDR, + AXP_REG_DCDCWORKINGMODE, 0, 0xc0, NULL); + + /* Set the default charging current. This is the same as the + * OF's setting, although it's not strictly within the USB spec. */ + axp_set_charge_current(780); + + /* Short delay to give power outputs time to stabilize */ + mdelay(5); +} + +#ifdef HAVE_USB_CHARGING_ENABLE +void usb_charging_maxcurrent_change(int maxcurrent) +{ + axp_set_charge_current(maxcurrent); +} +#endif + +void adc_init(void) +{ +} + +void power_off(void) +{ + axp_power_off(); + while(1); +} + +bool charging_state(void) +{ + return axp_battery_status() == AXP_BATT_CHARGING; +} + +int _battery_voltage(void) +{ + return axp_adc_read(ADC_BATTERY_VOLTAGE); +} -- cgit v1.2.3