blob: 3a69b37953b5d6937686f7c4ea18afc2cf790028 [file] [log] [blame]
Linus Nielsen Feltzing7cafe7a2002-07-04 16:09:23 +00001/***************************************************************************
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 "sh7034.h"
20#include <stdbool.h>
21#include "config.h"
22#include "adc.h"
Linus Nielsen Feltzing297a2562002-09-25 19:28:01 +000023#include "kernel.h"
Jörg Hohensohn75bab492003-11-06 01:34:50 +000024#include "system.h"
Linus Nielsen Feltzing7cafe7a2002-07-04 16:09:23 +000025#include "power.h"
26
Heikki Hannikainen3f809e72002-08-06 10:50:50 +000027#ifdef HAVE_CHARGE_CTRL
Linus Nielsen Feltzing53ee3442003-08-25 08:57:49 +000028bool charger_enabled;
Heikki Hannikainen3f809e72002-08-06 10:50:50 +000029#endif
30
Jörg Hohensohn91f93502004-10-17 08:53:18 +000031
32#ifdef CONFIG_TUNER
33
34static int fmstatus = 0;
35
36void radio_set_status(int status)
37{
38 fmstatus = status;
39#ifdef HAVE_TUNER_PWR_CTRL
40 if (status)
41 {
Jörg Hohensohn954e5882004-10-17 09:58:05 +000042 and_b(~0x04, &PADRL); /* drive PA2 low for tuner enable */
Jörg Hohensohn91f93502004-10-17 08:53:18 +000043 sleep(1); /* let the voltage settle */
44 }
45 else
Jörg Hohensohn954e5882004-10-17 09:58:05 +000046 or_b(0x04, &PADRL); /* drive PA2 high for tuner disable */
Jörg Hohensohn91f93502004-10-17 08:53:18 +000047#endif
48}
49
50int radio_get_status(void)
51{
52 return fmstatus;
53}
54
55#endif /* #ifdef CONFIG_TUNER */
56
Linus Nielsen Feltzing7cafe7a2002-07-04 16:09:23 +000057#ifndef SIMULATOR
58
Linus Nielsen Feltzing53ee3442003-08-25 08:57:49 +000059void power_init(void)
60{
61#ifdef HAVE_CHARGE_CTRL
Linus Nielsen Feltzingbef7ab02003-11-07 12:15:24 +000062 or_b(0x20, &PBIORL); /* Set charging control bit to output */
Jörg Hohensohn75bab492003-11-06 01:34:50 +000063 charger_enable(false); /* Default to charger OFF */
Linus Nielsen Feltzing53ee3442003-08-25 08:57:49 +000064#endif
Jörg Hohensohn91f93502004-10-17 08:53:18 +000065#ifdef HAVE_TUNER_PWR_CTRL
Jörg Hohensohn954e5882004-10-17 09:58:05 +000066 PACR2 &= ~0x0030; /* GPIO for PA2 */
67 or_b(0x04, &PADRL); /* drive PA2 high for tuner disable */
68 or_b(0x04, &PAIORL); /* output for PA2 */
Jörg Hohensohn91f93502004-10-17 08:53:18 +000069#endif
Linus Nielsen Feltzing53ee3442003-08-25 08:57:49 +000070}
71
Linus Nielsen Feltzing7cafe7a2002-07-04 16:09:23 +000072bool charger_inserted(void)
Jens Arnold0fc34c72004-10-13 23:21:57 +000073{
74#ifdef HAVE_CHARGING
Daniel Stenbergd7b46452003-01-16 15:11:29 +000075#ifdef HAVE_CHARGE_CTRL
Uwe Freesecc9b62f2003-02-13 21:45:19 +000076 /* Recorder */
77 return adc_read(ADC_EXT_POWER) > 0x100;
78#else
Daniel Stenbergd7b46452003-01-16 15:11:29 +000079#ifdef HAVE_FMADC
Linus Nielsen Feltzinga258fe12004-02-05 13:44:04 +000080 /* FM or V2, can also charge from the USB port */
81 return (adc_read(ADC_CHARGE_REGULATOR) < 0x1FF) ||
82 (adc_read(ADC_USB_POWER) < 0x1FF);
Daniel Stenbergd7b46452003-01-16 15:11:29 +000083#else
Uwe Freesecc9b62f2003-02-13 21:45:19 +000084 /* Player */
Linus Nielsen Feltzing7cafe7a2002-07-04 16:09:23 +000085 return (PADR & 1) == 0;
Uwe Freesecc9b62f2003-02-13 21:45:19 +000086#endif /* HAVE_FMADC */
87#endif /* HAVE_CHARGE_CTRL */
Jens Arnold0fc34c72004-10-13 23:21:57 +000088#else
89 /* Ondio */
90 return false;
91#endif /* HAVE_CHARGING */
Linus Nielsen Feltzing7cafe7a2002-07-04 16:09:23 +000092}
93
Linus Nielsen Feltzing7cafe7a2002-07-04 16:09:23 +000094void charger_enable(bool on)
95{
Jens Arnold0fc34c72004-10-13 23:21:57 +000096 (void)on;
Heikki Hannikainen3f809e72002-08-06 10:50:50 +000097#ifdef HAVE_CHARGE_CTRL
Jörg Hohensohn75bab492003-11-06 01:34:50 +000098 if(on)
99 {
Linus Nielsen Feltzingbef7ab02003-11-07 12:15:24 +0000100 and_b(~0x20, &PBDRL);
Heikki Hannikainen3f809e72002-08-06 10:50:50 +0000101 charger_enabled = 1;
Jörg Hohensohn75bab492003-11-06 01:34:50 +0000102 }
103 else
104 {
Linus Nielsen Feltzingbef7ab02003-11-07 12:15:24 +0000105 or_b(0x20, &PBDRL);
Heikki Hannikainen3f809e72002-08-06 10:50:50 +0000106 charger_enabled = 0;
107 }
Linus Nielsen Feltzing7cafe7a2002-07-04 16:09:23 +0000108#endif
109}
110
Jens Arnold0fc34c72004-10-13 23:21:57 +0000111#ifndef HAVE_MMC
Linus Nielsen Feltzing7cafe7a2002-07-04 16:09:23 +0000112void ide_power_enable(bool on)
113{
Jörg Hohensohn44298162003-12-03 01:03:54 +0000114 (void)on;
115 bool touched = false;
116
117#ifdef NEEDS_ATA_POWER_ON
Jörg Hohensohn61750ac2003-07-17 20:15:57 +0000118 if(on)
Jörg Hohensohn44298162003-12-03 01:03:54 +0000119 {
Linus Nielsen Feltzingbef7ab02003-11-07 12:15:24 +0000120 or_b(0x20, &PADRL);
Jörg Hohensohn44298162003-12-03 01:03:54 +0000121 touched = true;
122 }
123#endif
124#ifdef HAVE_ATA_POWER_OFF
125 if(!on)
126 {
Linus Nielsen Feltzingbef7ab02003-11-07 12:15:24 +0000127 and_b(~0x20, &PADRL);
Jörg Hohensohn44298162003-12-03 01:03:54 +0000128 touched = true;
129 }
130#endif
131
132/* late port preparation, else problems with read/modify/write
133 of other bits on same port, while input and floating high */
134 if (touched)
135 {
136 or_b(0x20, &PAIORL); /* PA5 is an output */
137 PACR2 &= 0xFBFF; /* GPIO for PA5 */
138 }
139}
Jens Arnold0fc34c72004-10-13 23:21:57 +0000140#endif /* !HAVE_MMC */
Jörg Hohensohn44298162003-12-03 01:03:54 +0000141
142
143bool ide_powered(void)
144{
145#if defined(NEEDS_ATA_POWER_ON) || defined(HAVE_ATA_POWER_OFF)
Jörg Hohensohn816234f2003-12-03 18:50:19 +0000146 if ((PACR2 & 0x0400) || !(PAIOR & 0x0020)) /* not configured for output */
147 return true; /* would be floating high, disk on */
Jörg Hohensohn44298162003-12-03 01:03:54 +0000148 else
149 return (PADR & 0x0020) != 0;
Linus Nielsen Feltzing7cafe7a2002-07-04 16:09:23 +0000150#else
Jörg Hohensohn816234f2003-12-03 18:50:19 +0000151 return true; /* pretend always powered if not controlable */
Linus Nielsen Feltzing7cafe7a2002-07-04 16:09:23 +0000152#endif
153}
154
Jörg Hohensohn44298162003-12-03 01:03:54 +0000155
Linus Nielsen Feltzing4edf8ae2002-07-05 07:10:22 +0000156void power_off(void)
157{
Linus Nielsen Feltzing111a9722004-03-02 11:32:59 +0000158 set_irq_level(HIGHEST_IRQ_LEVEL);
Daniel Stenbergaaa84432003-01-21 19:37:29 +0000159#ifdef HAVE_POWEROFF_ON_PBDR
Linus Nielsen Feltzingbef7ab02003-11-07 12:15:24 +0000160 and_b(~0x10, &PBDRL);
161 or_b(0x10, &PBIORL);
Linus Nielsen Feltzing70e33312003-02-21 01:12:00 +0000162#elif defined(HAVE_POWEROFF_ON_PB5)
Linus Nielsen Feltzingbef7ab02003-11-07 12:15:24 +0000163 and_b(~0x20, &PBDRL);
164 or_b(0x20, &PBIORL);
Linus Nielsen Feltzing4edf8ae2002-07-05 07:10:22 +0000165#else
Linus Nielsen Feltzingb1af93c2004-07-14 10:06:02 +0000166 /* Disable the backlight */
167 and_b(~0x40, &PAIORH);
168
Linus Nielsen Feltzingbef7ab02003-11-07 12:15:24 +0000169 and_b(~0x08, &PADRH);
170 or_b(0x08, &PAIORH);
Linus Nielsen Feltzing4edf8ae2002-07-05 07:10:22 +0000171#endif
Linus Nielsen Feltzing297a2562002-09-25 19:28:01 +0000172 while(1);
Linus Nielsen Feltzing4edf8ae2002-07-05 07:10:22 +0000173}
174
Linus Nielsen Feltzing7cafe7a2002-07-04 16:09:23 +0000175#else
176
177bool charger_inserted(void)
178{
179 return false;
180}
181
Linus Nielsen Feltzing7cafe7a2002-07-04 16:09:23 +0000182void charger_enable(bool on)
183{
Jens Arnold0fc34c72004-10-13 23:21:57 +0000184 (void)on;
Linus Nielsen Feltzing7cafe7a2002-07-04 16:09:23 +0000185}
186
Linus Nielsen Feltzing4edf8ae2002-07-05 07:10:22 +0000187void power_off(void)
188{
189}
190
Mats Lidellbd49e5f2003-07-20 00:08:47 +0000191void ide_power_enable(bool on)
192{
Jens Arnold0fc34c72004-10-13 23:21:57 +0000193 (void)on;
Mats Lidellbd49e5f2003-07-20 00:08:47 +0000194}
195
Linus Nielsen Feltzing7cafe7a2002-07-04 16:09:23 +0000196#endif /* SIMULATOR */