Samsung YP-S3: allow player to stay powered up without the USB cable plugged and...
[kugel-rb/myfork.git] / firmware / target / arm / s5l8700 / yps3 / power-yps3.c
blobea41b861cf1bcad827cc0ec237288e9fc40fea4f
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright © 2009 Bertrik Sikken
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 <stdbool.h>
22 #include "config.h"
23 #include "s5l8700.h"
24 #include "power.h"
26 /* Power handling for the S5L8700 based Samsung YP-S3
28 Pins involved in power management:
29 * P0.1: stay powered up (even with the USB cable unplugged)
30 * P1.1: USB power detect
31 * P4.7: tuner power/enable
32 * P5.2: unknown output
33 * P5.3: unknown output, related to charging (perhaps charge current?)
34 * P5.4: charge status input (only valid if charger enabled)
35 * P5.6: charger enable
38 void power_off(void)
40 /* take down P0.1 to power off (plugged USB cable overrides this though) */
41 PDAT0 &= ~(1 << 1);
43 while(1); /* wait for system to shut down */
46 void power_init(void)
48 /* configure P0.1 as output for power-up and stay powered up */
49 PCON0 = (PCON0 & ~(3 << 2)) | (1 << 2);
50 PDAT0 |= (1 << 1);
52 /* configure P1.1 as input for USB power detect */
53 PCON1 = (PCON1 & ~0x000000F0) | 0x00000000;
55 /* configure P4.7 as output for tuner power and turn power off */
56 PCON4 = (PCON4 & ~0xF0000000) | 0x10000000;
57 PDAT4 &= ~(1 << 7);
59 /* configure P5.2 / P5.3 / P5.6 as output, P5.4 as input */
60 PCON5 = (PCON5 & ~0x0F0FFF00) | 0x01001100;
61 PDAT5 &= ~((1 << 2) | (1 << 3) | (1 << 6));
64 #if CONFIG_CHARGING
65 unsigned int power_input_status(void)
67 /* check USB power on P1.1 */
68 if (PDAT1 & (1 << 1)) {
69 return POWER_INPUT_USB;
72 return POWER_INPUT_NONE;
75 bool charging_state(void)
77 /* check if charger is enabled */
78 if (PDAT5 & (1 << 6)) {
79 /* check if charging is busy */
80 return (PDAT5 & (1 << 4));
82 return false;
84 #endif /* CONFIG_CHARGING */
86 #if CONFIG_TUNER
87 bool tuner_power(bool status)
89 if (status) {
90 PDAT4 |= (1 << 7);
92 else {
93 PDAT4 &= ~(1 << 7);
95 /* TODO what should we return here? */
96 return status;
99 bool tuner_powered(void)
101 return (PDAT4 & (1 << 7));
103 #endif /* CONFIG_TUNER */