summaryrefslogtreecommitdiff
path: root/firmware/target/arm/imx31/gigabeat-s/power-gigabeat-s.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/imx31/gigabeat-s/power-gigabeat-s.c')
-rw-r--r--firmware/target/arm/imx31/gigabeat-s/power-gigabeat-s.c150
1 files changed, 150 insertions, 0 deletions
diff --git a/firmware/target/arm/imx31/gigabeat-s/power-gigabeat-s.c b/firmware/target/arm/imx31/gigabeat-s/power-gigabeat-s.c
new file mode 100644
index 0000000000..7e3b39dba8
--- /dev/null
+++ b/firmware/target/arm/imx31/gigabeat-s/power-gigabeat-s.c
@@ -0,0 +1,150 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 by Linus Nielsen Feltzing
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 "config.h"
22#include "system.h"
23#include "usb.h"
24#include "usb_core.h"
25#include "power.h"
26#include "power-gigabeat-s.h"
27#include "backlight.h"
28#include "backlight-target.h"
29#include "avic-imx31.h"
30#include "mc13783.h"
31#if CONFIG_TUNER
32#include "fmradio_i2c.h"
33#endif
34
35static unsigned int power_status = POWER_INPUT_NONE;
36
37/* Detect which power sources are present. */
38unsigned int power_input_status(void)
39{
40 unsigned int status = power_status;
41
42 if (GPIO3_DR & (1 << 20))
43 status |= POWER_INPUT_BATTERY;
44
45 if (usb_allowed_current() < 500)
46 {
47 /* ACK that USB is connected but NOT chargeable */
48 status &= ~(POWER_INPUT_USB_CHARGER & POWER_INPUT_CHARGER);
49 }
50
51 return status;
52}
53
54/* Detect changes in presence of the AC adaptor. */
55void charger_main_detect_event(void)
56{
57 if (mc13783_read(MC13783_INTERRUPT_SENSE0) & MC13783_SE1S)
58 power_status |= POWER_INPUT_MAIN_CHARGER;
59 else
60 power_status &= ~POWER_INPUT_MAIN_CHARGER;
61}
62
63/* Detect changes in USB bus power. Called from usb connect event handler. */
64void charger_usb_detect_event(int status)
65{
66 /* USB plugged does not imply charging is possible or even
67 * powering the device to maintain the battery. */
68 if (status == USB_INSERTED)
69 power_status |= POWER_INPUT_USB_CHARGER;
70 else
71 power_status &= ~POWER_INPUT_USB_CHARGER;
72}
73
74/* charging_state is implemented in powermgmt-imx31.c */
75
76void ide_power_enable(bool on)
77{
78 if (!on)
79 {
80 /* Bus must be isolated before power off */
81 imx31_regset32(&GPIO2_DR, (1 << 16));
82 }
83
84 /* HD power switch */
85 imx31_regmod32(&GPIO3_DR, on ? (1 << 5) : 0, (1 << 5));
86
87 if (on)
88 {
89 /* Bus switch may be turned on after powerup */
90 sleep(HZ/10);
91 imx31_regclr32(&GPIO2_DR, (1 << 16));
92 }
93}
94
95bool ide_powered(void)
96{
97 return (GPIO3_DR & (1 << 5)) != 0;
98}
99
100#if CONFIG_TUNER
101static bool tuner_on = false;
102
103bool tuner_power(bool status)
104{
105 if (status != tuner_on)
106 {
107 tuner_on = status;
108 /* Handle power and pin setup */
109 fmradio_i2c_enable(status);
110 status = !status;
111 }
112
113 return status;
114}
115
116bool tuner_powered(void)
117{
118 return tuner_on;
119}
120#endif /* #if CONFIG_TUNER */
121
122void power_off(void)
123{
124 /* Cut backlight */
125 _backlight_off();
126
127 /* Let it fade */
128 sleep(5*HZ/4);
129
130 /* Set user off mode */
131 mc13783_set(MC13783_POWER_CONTROL0, MC13783_USEROFFSPI);
132
133 /* Wait for power cut */
134 disable_interrupt(IRQ_FIQ_STATUS);
135
136 while (1);
137}
138
139void power_init(void)
140{
141#if CONFIG_TUNER
142 fmradio_i2c_init();
143#endif
144
145 /* Poll initial state */
146 charger_main_detect_event();
147
148 /* Enable detect event */
149 mc13783_enable_event(MC13783_SE1_EVENT);
150}