diff options
Diffstat (limited to 'firmware/target/sh/archos')
-rw-r--r-- | firmware/target/sh/archos/fm_v2/power-fm_v2.c | 109 | ||||
-rw-r--r-- | firmware/target/sh/archos/ondio/power-ondio.c | 78 | ||||
-rw-r--r-- | firmware/target/sh/archos/player/power-player.c | 87 | ||||
-rw-r--r-- | firmware/target/sh/archos/recorder/power-recorder.c | 103 |
4 files changed, 377 insertions, 0 deletions
diff --git a/firmware/target/sh/archos/fm_v2/power-fm_v2.c b/firmware/target/sh/archos/fm_v2/power-fm_v2.c new file mode 100644 index 0000000000..94a36339bb --- /dev/null +++ b/firmware/target/sh/archos/fm_v2/power-fm_v2.c | |||
@@ -0,0 +1,109 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Linus Nielsen Feltzing | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #include "config.h" | ||
20 | #include "cpu.h" | ||
21 | #include <stdbool.h> | ||
22 | #include "adc.h" | ||
23 | #include "kernel.h" | ||
24 | #include "system.h" | ||
25 | #include "power.h" | ||
26 | #include "usb.h" | ||
27 | |||
28 | #if CONFIG_TUNER | ||
29 | |||
30 | bool tuner_power(bool status) | ||
31 | { | ||
32 | (void)status; | ||
33 | return true; | ||
34 | } | ||
35 | |||
36 | #endif /* #if CONFIG_TUNER */ | ||
37 | |||
38 | void power_init(void) | ||
39 | { | ||
40 | PBCR2 &= ~0x0c00; /* GPIO for PB5 */ | ||
41 | or_b(0x20, &PBIORL); | ||
42 | or_b(0x20, &PBDRL); /* hold power */ | ||
43 | } | ||
44 | |||
45 | bool charger_inserted(void) | ||
46 | { | ||
47 | /* FM or V2 can also charge from the USB port */ | ||
48 | return (adc_read(ADC_CHARGE_REGULATOR) < 0x1FF); | ||
49 | } | ||
50 | |||
51 | /* Returns true if the unit is charging the batteries. */ | ||
52 | bool charging_state(void) | ||
53 | { | ||
54 | /* We use the information from the ADC_EXT_POWER ADC channel, which | ||
55 | tells us the charging current from the LTC1734. When DC is | ||
56 | connected (either via the external adapter, or via USB), we try | ||
57 | to determine if it is actively charging or only maintaining the | ||
58 | charge. My tests show that ADC readings below about 0x80 means | ||
59 | that the LTC1734 is only maintaining the charge. */ | ||
60 | return adc_read(ADC_EXT_POWER) >= 0x80; | ||
61 | } | ||
62 | |||
63 | void ide_power_enable(bool on) | ||
64 | { | ||
65 | bool touched = false; | ||
66 | |||
67 | if(on) | ||
68 | { | ||
69 | or_b(0x20, &PADRL); | ||
70 | touched = true; | ||
71 | } | ||
72 | #ifdef HAVE_ATA_POWER_OFF | ||
73 | if(!on) | ||
74 | { | ||
75 | and_b(~0x20, &PADRL); | ||
76 | touched = true; | ||
77 | } | ||
78 | #endif /* HAVE_ATA_POWER_OFF */ | ||
79 | |||
80 | /* late port preparation, else problems with read/modify/write | ||
81 | of other bits on same port, while input and floating high */ | ||
82 | if (touched) | ||
83 | { | ||
84 | or_b(0x20, &PAIORL); /* PA5 is an output */ | ||
85 | PACR2 &= 0xFBFF; /* GPIO for PA5 */ | ||
86 | } | ||
87 | } | ||
88 | |||
89 | |||
90 | bool ide_powered(void) | ||
91 | { | ||
92 | #ifdef HAVE_ATA_POWER_OFF | ||
93 | if ((PACR2 & 0x0400) || !(PAIORL & 0x20)) /* not configured for output */ | ||
94 | return true; /* would be floating high, disk on */ | ||
95 | else | ||
96 | return (PADRL & 0x20) != 0; | ||
97 | #else /* !defined(NEEDS_ATA_POWER_ON) && !defined(HAVE_ATA_POWER_OFF) */ | ||
98 | return true; /* pretend always powered if not controlable */ | ||
99 | #endif | ||
100 | } | ||
101 | |||
102 | void power_off(void) | ||
103 | { | ||
104 | set_irq_level(HIGHEST_IRQ_LEVEL); | ||
105 | and_b(~0x20, &PBDRL); | ||
106 | or_b(0x20, &PBIORL); | ||
107 | while(1) | ||
108 | yield(); | ||
109 | } | ||
diff --git a/firmware/target/sh/archos/ondio/power-ondio.c b/firmware/target/sh/archos/ondio/power-ondio.c new file mode 100644 index 0000000000..cedc3d10b9 --- /dev/null +++ b/firmware/target/sh/archos/ondio/power-ondio.c | |||
@@ -0,0 +1,78 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Linus Nielsen Feltzing | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #include "config.h" | ||
20 | #include "cpu.h" | ||
21 | #include <stdbool.h> | ||
22 | #include "adc.h" | ||
23 | #include "kernel.h" | ||
24 | #include "system.h" | ||
25 | #include "power.h" | ||
26 | #include "usb.h" | ||
27 | #include "backlight-target.h" | ||
28 | |||
29 | #if CONFIG_TUNER | ||
30 | |||
31 | static bool powered = false; | ||
32 | |||
33 | bool tuner_power(bool status) | ||
34 | { | ||
35 | bool old_status = powered; | ||
36 | |||
37 | powered = status; | ||
38 | if (status) | ||
39 | { | ||
40 | and_b(~0x04, &PADRL); /* drive PA2 low for tuner enable */ | ||
41 | sleep(1); /* let the voltage settle */ | ||
42 | } | ||
43 | else | ||
44 | or_b(0x04, &PADRL); /* drive PA2 high for tuner disable */ | ||
45 | return old_status; | ||
46 | } | ||
47 | |||
48 | #endif /* #if CONFIG_TUNER */ | ||
49 | |||
50 | void power_init(void) | ||
51 | { | ||
52 | PBCR2 &= ~0x0c00; /* GPIO for PB5 */ | ||
53 | or_b(0x20, &PBIORL); | ||
54 | or_b(0x20, &PBDRL); /* hold power */ | ||
55 | #ifndef HAVE_BACKLIGHT | ||
56 | /* Disable backlight on backlight-modded Ondios when running | ||
57 | * a standard build (always on otherwise). */ | ||
58 | PACR1 &= ~0x3000; /* Set PA14 (backlight control) to GPIO */ | ||
59 | and_b(~0x40, &PADRH); /* drive it low */ | ||
60 | or_b(0x40, &PAIORH); /* ..and output */ | ||
61 | #endif | ||
62 | PACR2 &= ~0x0030; /* GPIO for PA2 */ | ||
63 | or_b(0x04, &PADRL); /* drive PA2 high for tuner disable */ | ||
64 | or_b(0x04, &PAIORL); /* output for PA2 */ | ||
65 | } | ||
66 | |||
67 | void power_off(void) | ||
68 | { | ||
69 | set_irq_level(HIGHEST_IRQ_LEVEL); | ||
70 | #ifdef HAVE_BACKLIGHT | ||
71 | /* Switch off the light on backlight-modded Ondios */ | ||
72 | __backlight_off(); | ||
73 | #endif | ||
74 | and_b(~0x20, &PBDRL); | ||
75 | or_b(0x20, &PBIORL); | ||
76 | while(1) | ||
77 | yield(); | ||
78 | } | ||
diff --git a/firmware/target/sh/archos/player/power-player.c b/firmware/target/sh/archos/player/power-player.c new file mode 100644 index 0000000000..7d9d0d7d16 --- /dev/null +++ b/firmware/target/sh/archos/player/power-player.c | |||
@@ -0,0 +1,87 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Linus Nielsen Feltzing | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #include "config.h" | ||
20 | #include "cpu.h" | ||
21 | #include <stdbool.h> | ||
22 | #include "adc.h" | ||
23 | #include "kernel.h" | ||
24 | #include "system.h" | ||
25 | #include "power.h" | ||
26 | #include "usb.h" | ||
27 | |||
28 | void power_init(void) | ||
29 | { | ||
30 | } | ||
31 | |||
32 | bool charger_inserted(void) | ||
33 | { | ||
34 | /* Player */ | ||
35 | return (PADR & 1) == 0; | ||
36 | } | ||
37 | |||
38 | void ide_power_enable(bool on) | ||
39 | { | ||
40 | bool touched = false; | ||
41 | |||
42 | if(on) | ||
43 | { | ||
44 | or_b(0x10, &PBDRL); | ||
45 | touched = true; | ||
46 | } | ||
47 | #ifdef HAVE_ATA_POWER_OFF | ||
48 | if(!on) | ||
49 | { | ||
50 | and_b(~0x10, &PBDRL); | ||
51 | touched = true; | ||
52 | } | ||
53 | #endif /* HAVE_ATA_POWER_OFF */ | ||
54 | |||
55 | /* late port preparation, else problems with read/modify/write | ||
56 | of other bits on same port, while input and floating high */ | ||
57 | if (touched) | ||
58 | { | ||
59 | or_b(0x10, &PBIORL); /* PB4 is an output */ | ||
60 | PBCR2 &= ~0x0300; /* GPIO for PB4 */ | ||
61 | } | ||
62 | } | ||
63 | |||
64 | |||
65 | bool ide_powered(void) | ||
66 | { | ||
67 | #ifdef HAVE_ATA_POWER_OFF | ||
68 | /* This is not correct for very old players, since these are unable to | ||
69 | * control hd power. However, driving the pin doesn't hurt, because it | ||
70 | * is not connected anywhere */ | ||
71 | if ((PBCR2 & 0x0300) || !(PBIORL & 0x10)) /* not configured for output */ | ||
72 | return false; /* would be floating low, disk off */ | ||
73 | else | ||
74 | return (PBDRL & 0x10) != 0; | ||
75 | #else /* !defined(NEEDS_ATA_POWER_ON) && !defined(HAVE_ATA_POWER_OFF) */ | ||
76 | return true; /* pretend always powered if not controlable */ | ||
77 | #endif | ||
78 | } | ||
79 | |||
80 | void power_off(void) | ||
81 | { | ||
82 | set_irq_level(HIGHEST_IRQ_LEVEL); | ||
83 | and_b(~0x08, &PADRH); | ||
84 | or_b(0x08, &PAIORH); | ||
85 | while(1) | ||
86 | yield(); | ||
87 | } | ||
diff --git a/firmware/target/sh/archos/recorder/power-recorder.c b/firmware/target/sh/archos/recorder/power-recorder.c new file mode 100644 index 0000000000..2af8df1bb6 --- /dev/null +++ b/firmware/target/sh/archos/recorder/power-recorder.c | |||
@@ -0,0 +1,103 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Linus Nielsen Feltzing | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #include "config.h" | ||
20 | #include "cpu.h" | ||
21 | #include <stdbool.h> | ||
22 | #include "adc.h" | ||
23 | #include "kernel.h" | ||
24 | #include "system.h" | ||
25 | #include "power.h" | ||
26 | #include "usb.h" | ||
27 | |||
28 | bool charger_enabled; | ||
29 | |||
30 | void power_init(void) | ||
31 | { | ||
32 | PBCR2 &= ~0x0c00; /* GPIO for PB5 */ | ||
33 | or_b(0x20, &PBIORL); /* Set charging control bit to output */ | ||
34 | charger_enable(false); /* Default to charger OFF */ | ||
35 | } | ||
36 | |||
37 | bool charger_inserted(void) | ||
38 | { | ||
39 | /* Recorder */ | ||
40 | return adc_read(ADC_EXT_POWER) > 0x100; | ||
41 | } | ||
42 | |||
43 | void charger_enable(bool on) | ||
44 | { | ||
45 | if(on) | ||
46 | { | ||
47 | and_b(~0x20, &PBDRL); | ||
48 | charger_enabled = 1; | ||
49 | } | ||
50 | else | ||
51 | { | ||
52 | or_b(0x20, &PBDRL); | ||
53 | charger_enabled = 0; | ||
54 | } | ||
55 | } | ||
56 | |||
57 | void ide_power_enable(bool on) | ||
58 | { | ||
59 | bool touched = false; | ||
60 | |||
61 | if(on) | ||
62 | { | ||
63 | or_b(0x20, &PADRL); | ||
64 | touched = true; | ||
65 | } | ||
66 | #ifdef HAVE_ATA_POWER_OFF | ||
67 | if(!on) | ||
68 | { | ||
69 | and_b(~0x20, &PADRL); | ||
70 | touched = true; | ||
71 | } | ||
72 | #endif /* HAVE_ATA_POWER_OFF */ | ||
73 | |||
74 | /* late port preparation, else problems with read/modify/write | ||
75 | of other bits on same port, while input and floating high */ | ||
76 | if (touched) | ||
77 | { | ||
78 | or_b(0x20, &PAIORL); /* PA5 is an output */ | ||
79 | PACR2 &= 0xFBFF; /* GPIO for PA5 */ | ||
80 | } | ||
81 | } | ||
82 | |||
83 | |||
84 | bool ide_powered(void) | ||
85 | { | ||
86 | #ifdef HAVE_ATA_POWER_OFF | ||
87 | if ((PACR2 & 0x0400) || !(PAIORL & 0x20)) /* not configured for output */ | ||
88 | return true; /* would be floating high, disk on */ | ||
89 | else | ||
90 | return (PADRL & 0x20) != 0; | ||
91 | #else /* !defined(NEEDS_ATA_POWER_ON) && !defined(HAVE_ATA_POWER_OFF) */ | ||
92 | return true; /* pretend always powered if not controlable */ | ||
93 | #endif | ||
94 | } | ||
95 | |||
96 | void power_off(void) | ||
97 | { | ||
98 | set_irq_level(HIGHEST_IRQ_LEVEL); | ||
99 | and_b(~0x10, &PBDRL); | ||
100 | or_b(0x10, &PBIORL); | ||
101 | while(1) | ||
102 | yield(); | ||
103 | } | ||