i.MX31/Gigabeat S: Implement frequency and voltage scaling-- 1.6V for 528MHz, and...
[kugel-rb.git] / firmware / target / arm / imx31 / gigabeat-s / power-gigabeat-s.c
blobd7fe87f168ff4302003ffb041440569993100195
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2006 by Linus Nielsen Feltzing
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
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 #include "dvfs_dptc-imx31.h"
32 #if CONFIG_TUNER
33 #include "fmradio_i2c.h"
34 #endif
36 static unsigned int power_status = POWER_INPUT_NONE;
38 /* Detect which power sources are present. */
39 unsigned int power_input_status(void)
41 unsigned int status = power_status;
43 if (GPIO3_DR & (1 << 20))
44 status |= POWER_INPUT_BATTERY;
46 if (usb_allowed_current() < 500)
48 /* ACK that USB is connected but NOT chargeable */
49 status &= ~(POWER_INPUT_USB_CHARGER & POWER_INPUT_CHARGER);
52 return status;
55 /* Detect changes in presence of the AC adaptor. */
56 void charger_main_detect_event(void)
58 if (mc13783_read(MC13783_INTERRUPT_SENSE0) & MC13783_SE1S)
59 power_status |= POWER_INPUT_MAIN_CHARGER;
60 else
61 power_status &= ~POWER_INPUT_MAIN_CHARGER;
64 /* Detect changes in USB bus power. Called from usb connect event handler. */
65 void charger_usb_detect_event(int status)
67 /* USB plugged does not imply charging is possible or even
68 * powering the device to maintain the battery. */
69 if (status == USB_INSERTED)
70 power_status |= POWER_INPUT_USB_CHARGER;
71 else
72 power_status &= ~POWER_INPUT_USB_CHARGER;
75 /* charging_state is implemented in powermgmt-imx31.c */
77 void ide_power_enable(bool on)
79 if (!on)
81 /* Bus must be isolated before power off */
82 imx31_regset32(&GPIO2_DR, (1 << 16));
85 /* HD power switch */
86 imx31_regmod32(&GPIO3_DR, on ? (1 << 5) : 0, (1 << 5));
88 if (on)
90 /* Bus switch may be turned on after powerup */
91 sleep(HZ/10);
92 imx31_regclr32(&GPIO2_DR, (1 << 16));
96 bool ide_powered(void)
98 return (GPIO3_DR & (1 << 5)) != 0;
101 #if CONFIG_TUNER
102 static bool tuner_on = false;
104 bool tuner_power(bool status)
106 if (status != tuner_on)
108 tuner_on = status;
109 /* Handle power and pin setup */
110 fmradio_i2c_enable(status);
111 status = !status;
114 return status;
117 bool tuner_powered(void)
119 return tuner_on;
121 #endif /* #if CONFIG_TUNER */
123 void power_off(void)
125 /* Turn off voltage and frequency scaling */
126 dvfs_dptc_stop();
128 /* Cut backlight */
129 _backlight_off();
131 /* Let it fade */
132 sleep(5*HZ/4);
134 /* Set user off mode */
135 mc13783_set(MC13783_POWER_CONTROL0, MC13783_USEROFFSPI);
137 /* Wait for power cut */
138 system_halt();
141 void power_init(void)
143 #if CONFIG_TUNER
144 fmradio_i2c_init();
145 #endif
147 /* Poll initial state */
148 charger_main_detect_event();
150 /* Enable detect event */
151 mc13783_enable_event(MC13783_SE1_EVENT);