diff options
Diffstat (limited to 'firmware/target/arm/s5l8702/ipod6g/power-6g.c')
-rw-r--r-- | firmware/target/arm/s5l8702/ipod6g/power-6g.c | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/firmware/target/arm/s5l8702/ipod6g/power-6g.c b/firmware/target/arm/s5l8702/ipod6g/power-6g.c new file mode 100644 index 0000000000..1a8e1e1a7e --- /dev/null +++ b/firmware/target/arm/s5l8702/ipod6g/power-6g.c | |||
@@ -0,0 +1,134 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: power-nano2g.c 28190 2010-10-01 18:09:10Z Buschel $ | ||
9 | * | ||
10 | * Copyright © 2009 Bertrik Sikken | ||
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 | #include <stdbool.h> | ||
22 | #include "config.h" | ||
23 | #include "inttypes.h" | ||
24 | #include "s5l8702.h" | ||
25 | #include "power.h" | ||
26 | #include "panic.h" | ||
27 | #include "pmu-target.h" | ||
28 | #include "usb_core.h" /* for usb_charging_maxcurrent_change */ | ||
29 | |||
30 | static int idepowered; | ||
31 | |||
32 | void power_off(void) | ||
33 | { | ||
34 | /* USB inserted or EXTON1 */ | ||
35 | pmu_set_wake_condition( | ||
36 | PCF5063X_OOCWAKE_EXTON2 | PCF5063X_OOCWAKE_EXTON1); | ||
37 | pmu_enter_standby(); | ||
38 | |||
39 | while(1); | ||
40 | } | ||
41 | |||
42 | void power_init(void) | ||
43 | { | ||
44 | pmu_init(); | ||
45 | |||
46 | idepowered = false; | ||
47 | |||
48 | /* DOWN1CTL: CPU DVM step time = 30us (default: no DVM) */ | ||
49 | pmu_write(0x20, 2); | ||
50 | |||
51 | /* USB power configuration: | ||
52 | * | ||
53 | * GPIO C0 is probably related to the LTC4066's CLPROG | ||
54 | * pin (see datasheet). Setting it high allows to double | ||
55 | * the maximum current selected by HPWR: | ||
56 | * | ||
57 | * GPIO B6 GPIO C0 USB current | ||
58 | * HPWR CLPROG ??? limit (mA) | ||
59 | * ------- ---------- ----------- | ||
60 | * 0 0 100 | ||
61 | * 1 0 500 | ||
62 | * 0 1 200 | ||
63 | * 1 1 1000 ??? (max.seen ~750mA) | ||
64 | * | ||
65 | * USB current limit includes battery charge and device | ||
66 | * consumption. Battery charge has it's own limit at | ||
67 | * 330~340 mA (configured using RPROG). | ||
68 | * | ||
69 | * Setting either of GPIO C1 or GPIO C2 disables battery | ||
70 | * charge, power needed for device consumptiom is drained | ||
71 | * from USB or AC adaptor when present. If external power | ||
72 | * is not present or it is insufficient or limited, | ||
73 | * additional required power is drained from battery. | ||
74 | */ | ||
75 | PCONB = (PCONB & 0x000000ff) | ||
76 | | (0xe << 8) /* route D+ to ADC2: off */ | ||
77 | | (0xe << 12) /* route D- to ADC2: off */ | ||
78 | | (0x0 << 16) /* USB related input, POL pin ??? */ | ||
79 | | (0x0 << 20) /* USB related input, !CHRG pin ??? */ | ||
80 | | (0xe << 24) /* HPWR: 100mA */ | ||
81 | | (0xe << 28); /* USB suspend: off */ | ||
82 | |||
83 | PCONC = (PCONC & 0xffff0000) | ||
84 | | (0xe << 0) /* double HPWR limit: off */ | ||
85 | | (0xe << 4) /* disable battery charge: off */ | ||
86 | | (0xe << 8) /* disable battery charge: off */ | ||
87 | | (0x0 << 12); /* USB inserted/not inserted */ | ||
88 | } | ||
89 | |||
90 | void ide_power_enable(bool on) | ||
91 | { | ||
92 | idepowered = on; | ||
93 | pmu_hdd_power(on); | ||
94 | } | ||
95 | |||
96 | bool ide_powered() | ||
97 | { | ||
98 | return idepowered; | ||
99 | } | ||
100 | |||
101 | #if CONFIG_CHARGING | ||
102 | |||
103 | #ifdef HAVE_USB_CHARGING_ENABLE | ||
104 | void usb_charging_maxcurrent_change(int maxcurrent) | ||
105 | { | ||
106 | bool suspend_charging = (maxcurrent < 100); | ||
107 | bool fast_charging = (maxcurrent >= 500); | ||
108 | |||
109 | /* This GPIO is connected to the LTC4066's SUSP pin */ | ||
110 | /* Setting it high prevents any power being drawn over USB */ | ||
111 | /* which supports USB suspend */ | ||
112 | GPIOCMD = 0xb070e | (suspend_charging ? 1 : 0); | ||
113 | |||
114 | /* This GPIO is connected to the LTC4066's HPWR pin */ | ||
115 | /* Setting it low limits current to 100mA, setting it high allows 500mA */ | ||
116 | GPIOCMD = 0xb060e | (fast_charging ? 1 : 0); | ||
117 | } | ||
118 | #endif | ||
119 | |||
120 | unsigned int power_input_status(void) | ||
121 | { | ||
122 | unsigned int status = POWER_INPUT_NONE; | ||
123 | if (usb_detect() == USB_INSERTED) | ||
124 | status |= POWER_INPUT_USB_CHARGER; | ||
125 | if (pmu_firewire_present()) | ||
126 | status |= POWER_INPUT_MAIN_CHARGER; | ||
127 | return status; | ||
128 | } | ||
129 | |||
130 | bool charging_state(void) | ||
131 | { | ||
132 | return (PDAT(11) & 0x10) ? 0 : 1; | ||
133 | } | ||
134 | #endif /* CONFIG_CHARGING */ | ||