1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
26 #include "power-gigabeat-s.h"
27 #include "backlight.h"
28 #include "backlight-target.h"
29 #include "avic-imx31.h"
31 #include "dvfs_dptc-imx31.h"
33 #include "fmradio_i2c.h"
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
);
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
;
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
;
72 power_status
&= ~POWER_INPUT_USB_CHARGER
;
75 /* charging_state is implemented in powermgmt-imx31.c */
77 void ide_power_enable(bool on
)
81 /* Bus must be isolated before power off */
82 imx31_regset32(&GPIO2_DR
, (1 << 16));
86 imx31_regmod32(&GPIO3_DR
, on
? (1 << 5) : 0, (1 << 5));
90 /* Bus switch may be turned on after powerup */
92 imx31_regclr32(&GPIO2_DR
, (1 << 16));
96 bool ide_powered(void)
98 return (GPIO3_DR
& (1 << 5)) != 0;
102 static bool tuner_on
= false;
104 bool tuner_power(bool status
)
106 if (status
!= tuner_on
)
109 /* Handle power and pin setup */
110 fmradio_i2c_enable(status
);
117 bool tuner_powered(void)
121 #endif /* #if CONFIG_TUNER */
125 /* Turn off voltage and frequency scaling */
134 /* Set user off mode */
135 mc13783_set(MC13783_POWER_CONTROL0
, MC13783_USEROFFSPI
);
137 /* Wait for power cut */
141 void power_init(void)
147 /* Poll initial state */
148 charger_main_detect_event();
150 /* Enable detect event */
151 mc13783_enable_event(MC13783_SE1_EVENT
);