blob: 6f845bd5ff846a8243c3745b142bbe9e3867d728 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright © 2009 Bertrik Sikken
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include <stdbool.h>
#include "config.h"
#include "s5l87xx.h"
#include "power.h"
/* Power handling for the S5L8700 based Samsung YP-S3
Pins involved in power management:
* P0.1: stay powered up (even with the USB cable unplugged)
* P1.1: USB power detect
* P4.7: tuner power/enable
* P5.2: unknown output
* P5.3: unknown output, related to charging (perhaps charge current?)
* P5.4: charge status input (only valid if charger enabled)
* P5.6: charger enable
*/
void power_off(void)
{
/* take down P0.1 to power off (plugged USB cable overrides this though) */
PDAT0 &= ~(1 << 1);
while(1); /* wait for system to shut down */
}
void power_init(void)
{
/* configure P0.1 as output for power-up and stay powered up */
PCON0 = (PCON0 & ~(3 << 2)) | (1 << 2);
PDAT0 |= (1 << 1);
/* configure P1.1 as input for USB power detect */
PCON1 = (PCON1 & ~0x000000F0) | 0x00000000;
/* configure P4.7 as output for tuner power and turn power off */
PCON4 = (PCON4 & ~0xF0000000) | 0x10000000;
PDAT4 &= ~(1 << 7);
/* configure P5.2 / P5.3 / P5.6 as output, P5.4 as input */
PCON5 = (PCON5 & ~0x0F0FFF00) | 0x01001100;
PDAT5 &= ~((1 << 2) | (1 << 3) | (1 << 6));
}
#if CONFIG_CHARGING
unsigned int power_input_status(void)
{
/* check USB power on P1.1 */
if (PDAT1 & (1 << 1)) {
return POWER_INPUT_USB;
}
return POWER_INPUT_NONE;
}
bool charging_state(void)
{
/* check if charger is enabled */
if (PDAT5 & (1 << 6)) {
/* check if charging is busy */
return (PDAT5 & (1 << 4));
}
return false;
}
#endif /* CONFIG_CHARGING */
#if CONFIG_TUNER
bool tuner_power(bool status)
{
if (status) {
PDAT4 |= (1 << 7);
}
else {
PDAT4 &= ~(1 << 7);
}
/* TODO what should we return here? */
return status;
}
bool tuner_powered(void)
{
return (PDAT4 & (1 << 7));
}
#endif /* CONFIG_TUNER */
|