summaryrefslogtreecommitdiff
path: root/firmware/target/mips/ingenic_x1000/fiiom3k/power-fiiom3k.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/mips/ingenic_x1000/fiiom3k/power-fiiom3k.c')
-rw-r--r--firmware/target/mips/ingenic_x1000/fiiom3k/power-fiiom3k.c97
1 files changed, 97 insertions, 0 deletions
diff --git a/firmware/target/mips/ingenic_x1000/fiiom3k/power-fiiom3k.c b/firmware/target/mips/ingenic_x1000/fiiom3k/power-fiiom3k.c
new file mode 100644
index 0000000000..3eb3146d97
--- /dev/null
+++ b/firmware/target/mips/ingenic_x1000/fiiom3k/power-fiiom3k.c
@@ -0,0 +1,97 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2021 Aidan MacDonald
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "power.h"
23#include "adc.h"
24#include "system.h"
25#include "kernel.h"
26#include "axp173.h"
27#include "i2c-x1000.h"
28#include "gpio-x1000.h"
29
30const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] =
31{
32 3470
33};
34
35/* the OF shuts down at this voltage */
36const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] =
37{
38 3400
39};
40
41/* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */
42const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] =
43{
44 { 3400, 3639, 3697, 3723, 3757, 3786, 3836, 3906, 3980, 4050, 4159 }
45};
46
47/* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */
48const unsigned short const percent_to_volt_charge[11] =
49{
50 3485, 3780, 3836, 3857, 3890, 3930, 3986, 4062, 4158, 4185, 4196
51};
52
53#define AXP173_IRQ_PORT GPIO_B
54#define AXP173_IRQ_PIN (1 << 10)
55
56void power_init(void)
57{
58 /* Initialize driver */
59 i2c_x1000_set_freq(2, I2C_FREQ_400K);
60 axp173_init();
61
62 /* Set lowest sample rate */
63 axp173_adc_set_rate(AXP173_ADC_RATE_25HZ);
64
65 /* Ensure battery voltage ADC is enabled */
66 int bits = axp173_adc_get_enabled();
67 bits |= (1 << ADC_BATTERY_VOLTAGE);
68 axp173_adc_set_enabled(bits);
69
70 /* Turn on all power outputs */
71 i2c_reg_modify1(AXP173_BUS, AXP173_ADDR, 0x12, 0, 0x5f, NULL);
72 i2c_reg_modify1(AXP173_BUS, AXP173_ADDR, 0x80, 0, 0xc0, NULL);
73
74 /* Short delay to give power outputs time to stabilize */
75 mdelay(5);
76}
77
78void adc_init(void)
79{
80}
81
82void power_off(void)
83{
84 /* Set the shutdown bit */
85 i2c_reg_setbit1(AXP173_BUS, AXP173_ADDR, 0x32, 7, 1, NULL);
86 while(1);
87}
88
89bool charging_state(void)
90{
91 return axp173_battery_status() == AXP173_BATT_CHARGING;
92}
93
94int _battery_voltage(void)
95{
96 return axp173_adc_read(ADC_BATTERY_VOLTAGE);
97}