summaryrefslogtreecommitdiff
path: root/firmware/target/coldfire
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/coldfire')
-rw-r--r--firmware/target/coldfire/iriver/ata-iriver.c66
-rw-r--r--firmware/target/coldfire/iriver/ata-target.h26
-rw-r--r--firmware/target/coldfire/iriver/backlight-target.h27
-rw-r--r--firmware/target/coldfire/iriver/h100/adc-h100.c117
-rw-r--r--firmware/target/coldfire/iriver/h100/adc-target.h41
-rw-r--r--firmware/target/coldfire/iriver/h100/backlight-h100.c45
-rw-r--r--firmware/target/coldfire/iriver/h100/power-h100.c143
-rw-r--r--firmware/target/coldfire/iriver/h100/usb-h100.c51
-rw-r--r--firmware/target/coldfire/iriver/h300/adc-h300.c83
-rw-r--r--firmware/target/coldfire/iriver/h300/adc-target.h41
-rw-r--r--firmware/target/coldfire/iriver/h300/backlight-h300.c49
-rw-r--r--firmware/target/coldfire/iriver/h300/power-h300.c101
-rw-r--r--firmware/target/coldfire/iriver/h300/usb-h300.c56
-rw-r--r--firmware/target/coldfire/iriver/system-iriver.c133
-rw-r--r--firmware/target/coldfire/iriver/usb-target.h24
15 files changed, 1003 insertions, 0 deletions
diff --git a/firmware/target/coldfire/iriver/ata-iriver.c b/firmware/target/coldfire/iriver/ata-iriver.c
new file mode 100644
index 0000000000..82dae32a97
--- /dev/null
+++ b/firmware/target/coldfire/iriver/ata-iriver.c
@@ -0,0 +1,66 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 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 "kernel.h"
23#include "system.h"
24#include "power.h"
25#include "pcf50606.h"
26
27void ata_reset(void)
28{
29 and_l(~0x00080000, &GPIO_OUT);
30 sleep(1); /* > 25us */
31
32 or_l(0x00080000, &GPIO_OUT);
33 sleep(1); /* > 25us */
34}
35
36void ata_enable(bool on)
37{
38 if(on)
39 and_l(~0x0040000, &GPIO_OUT);
40 else
41 or_l(0x0040000, &GPIO_OUT);
42
43 or_l(0x00040000, &GPIO_ENABLE);
44 or_l(0x00040000, &GPIO_FUNCTION);
45}
46
47bool ata_is_coldstart(void)
48{
49 return (GPIO_FUNCTION & 0x00080000) == 0;
50}
51
52void ata_device_init(void)
53{
54#ifdef HAVE_ATA_LED_CTRL
55 /* Enable disk LED & ISD chip power control */
56 and_l(~0x0000240, &GPIO_OUT);
57 or_l(0x00000240, &GPIO_ENABLE);
58 or_l(0x00000200, &GPIO_FUNCTION);
59#endif
60
61 /* ATA reset */
62 or_l(0x00080000, &GPIO_OUT);
63 or_l(0x00080000, &GPIO_ENABLE);
64 or_l(0x00080000, &GPIO_FUNCTION);
65
66}
diff --git a/firmware/target/coldfire/iriver/ata-target.h b/firmware/target/coldfire/iriver/ata-target.h
new file mode 100644
index 0000000000..1801a7d376
--- /dev/null
+++ b/firmware/target/coldfire/iriver/ata-target.h
@@ -0,0 +1,26 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 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#ifndef ATA_TARGET_H
20#define ATA_TARGET_H
21
22void ata_reset(void);
23void ata_device_init(void);
24bool ata_is_coldstart(void);
25
26#endif
diff --git a/firmware/target/coldfire/iriver/backlight-target.h b/firmware/target/coldfire/iriver/backlight-target.h
new file mode 100644
index 0000000000..262650ae24
--- /dev/null
+++ b/firmware/target/coldfire/iriver/backlight-target.h
@@ -0,0 +1,27 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 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#ifndef BACKLIGHT_TARGET_H
20#define BACKLIGHT_TARGET_H
21
22void __backlight_on(void);
23void __backlight_off(void);
24void __remote_backlight_on(void);
25void __remote_backlight_off(void);
26
27#endif
diff --git a/firmware/target/coldfire/iriver/h100/adc-h100.c b/firmware/target/coldfire/iriver/h100/adc-h100.c
new file mode 100644
index 0000000000..b29a2247ad
--- /dev/null
+++ b/firmware/target/coldfire/iriver/h100/adc-h100.c
@@ -0,0 +1,117 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 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 "system.h"
22#include "kernel.h"
23#include "thread.h"
24#include "adc.h"
25static unsigned char adcdata[NUM_ADC_CHANNELS];
26
27
28#define CS_LO and_l(~0x80, &GPIO_OUT)
29#define CS_HI or_l(0x80, &GPIO_OUT)
30#define CLK_LO and_l(~0x00400000, &GPIO_OUT)
31#define CLK_HI or_l(0x00400000, &GPIO_OUT)
32#define DO (GPIO_READ & 0x80000000)
33#define DI_LO and_l(~0x00200000, &GPIO_OUT)
34#define DI_HI or_l(0x00200000, &GPIO_OUT)
35
36/* delay loop */
37#define DELAY do { int _x; for(_x=0;_x<10;_x++);} while (0)
38
39unsigned short adc_scan(int channel)
40{
41 unsigned char data = 0;
42 int i;
43
44 CS_LO;
45
46 DI_HI; /* Start bit */
47 DELAY;
48 CLK_HI;
49 DELAY;
50 CLK_LO;
51
52 DI_HI; /* Single channel */
53 DELAY;
54 CLK_HI;
55 DELAY;
56 CLK_LO;
57
58 if(channel & 1) /* LSB of channel number */
59 DI_HI;
60 else
61 DI_LO;
62 DELAY;
63 CLK_HI;
64 DELAY;
65 CLK_LO;
66
67 if(channel & 2) /* MSB of channel number */
68 DI_HI;
69 else
70 DI_LO;
71 DELAY;
72 CLK_HI;
73 DELAY;
74 CLK_LO;
75
76 DELAY;
77
78 for(i = 0;i < 8;i++) /* 8 bits of data */
79 {
80 CLK_HI;
81 DELAY;
82 CLK_LO;
83 DELAY;
84 data <<= 1;
85 data |= DO?1:0;
86 }
87
88 CS_HI;
89
90 adcdata[channel] = data;
91
92 return data;
93}
94unsigned short adc_read(int channel)
95{
96 return adcdata[channel];
97}
98
99static int adc_counter;
100
101static void adc_tick(void)
102{
103 if(++adc_counter == HZ)
104 {
105 adc_counter = 0;
106 adc_scan(ADC_BATTERY);
107 adc_scan(ADC_REMOTEDETECT); /* Temporary. Remove when the remote
108 detection feels stable. */
109 }
110}
111
112void adc_init(void)
113{
114 adc_scan(ADC_BATTERY);
115
116 tick_add_task(adc_tick);
117}
diff --git a/firmware/target/coldfire/iriver/h100/adc-target.h b/firmware/target/coldfire/iriver/h100/adc-target.h
new file mode 100644
index 0000000000..54e7bc936a
--- /dev/null
+++ b/firmware/target/coldfire/iriver/h100/adc-target.h
@@ -0,0 +1,41 @@
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/* for the iriver h1x0 */
20
21#ifndef _ADC_TARGET_H_
22#define _ADC_TARGET_H_
23
24#define NUM_ADC_CHANNELS 4
25
26#define ADC_BUTTONS 0
27#define ADC_REMOTE 1
28#define ADC_BATTERY 2
29#define ADC_REMOTEDETECT 3
30#define ADC_UNREG_POWER ADC_BATTERY /* For compatibility */
31
32/* ADC values for different remote control types */
33#define ADCVAL_H300_LCD_REMOTE 0x5E
34#define ADCVAL_H100_LCD_REMOTE 0x96
35#define ADCVAL_H300_LCD_REMOTE_HOLD 0xCC
36#define ADCVAL_H100_LCD_REMOTE_HOLD 0xEA
37
38/* Force a scan now */
39unsigned short adc_scan(int channel);
40
41#endif /* _ADC_TARGET_H_ */
diff --git a/firmware/target/coldfire/iriver/h100/backlight-h100.c b/firmware/target/coldfire/iriver/h100/backlight-h100.c
new file mode 100644
index 0000000000..8ceac8a6ff
--- /dev/null
+++ b/firmware/target/coldfire/iriver/h100/backlight-h100.c
@@ -0,0 +1,45 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 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 "kernel.h"
22#include "thread.h"
23#include "system.h"
24#include "backlight.h"
25#include "lcd.h"
26
27void __backlight_on(void)
28{
29 and_l(~0x00020000, &GPIO1_OUT);
30}
31
32void __backlight_off(void)
33{
34 or_l(0x00020000, &GPIO1_OUT);
35}
36
37void __remote_backlight_on(void)
38{
39 and_l(~0x00000800, &GPIO_OUT);
40}
41
42void __remote_backlight_off(void)
43{
44 or_l(0x00000800, &GPIO_OUT);
45}
diff --git a/firmware/target/coldfire/iriver/h100/power-h100.c b/firmware/target/coldfire/iriver/h100/power-h100.c
new file mode 100644
index 0000000000..0714ab2d3f
--- /dev/null
+++ b/firmware/target/coldfire/iriver/h100/power-h100.c
@@ -0,0 +1,143 @@
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 "kernel.h"
23#include "system.h"
24#include "power.h"
25
26
27#ifdef CONFIG_TUNER
28
29static bool powered = false;
30
31bool radio_powered(void)
32{
33 return powered;
34}
35
36bool radio_power(bool status)
37{
38 bool old_status = powered;
39 powered = status;
40 return old_status;
41}
42
43#endif /* #ifdef CONFIG_TUNER */
44
45#ifndef SIMULATOR
46
47void power_init(void)
48{
49 or_l(0x00080000, &GPIO1_OUT);
50 or_l(0x00080000, &GPIO1_ENABLE);
51 or_l(0x00080000, &GPIO1_FUNCTION);
52
53#ifndef BOOTLOADER
54 /* The boot loader controls the power */
55 ide_power_enable(true);
56#endif
57 or_l(0x80000000, &GPIO_ENABLE);
58 or_l(0x80000000, &GPIO_FUNCTION);
59#ifdef HAVE_SPDIF_POWER
60 spdif_power_enable(false);
61#endif
62}
63
64
65bool charger_inserted(void)
66{
67 return (GPIO1_READ & 0x00400000)?true:false;
68}
69/* Returns true if the unit is charging the batteries. */
70bool charging_state(void) {
71 return charger_inserted();
72}
73
74#ifdef HAVE_SPDIF_POWER
75void spdif_power_enable(bool on)
76{
77 or_l(0x01000000, &GPIO1_FUNCTION);
78 or_l(0x01000000, &GPIO1_ENABLE);
79
80#ifdef SPDIF_POWER_INVERTED
81 if(!on)
82#else
83 if(on)
84#endif
85 and_l(~0x01000000, &GPIO1_OUT);
86 else
87 or_l(0x01000000, &GPIO1_OUT);
88}
89#endif
90
91void ide_power_enable(bool on)
92{
93 if(on)
94 and_l(~0x80000000, &GPIO_OUT);
95 else
96 or_l(0x80000000, &GPIO_OUT);
97}
98
99
100bool ide_powered(void)
101{
102 return (GPIO_OUT & 0x80000000)?false:true;
103}
104
105
106void power_off(void)
107{
108 set_irq_level(HIGHEST_IRQ_LEVEL);
109 and_l(~0x00080000, &GPIO1_OUT);
110 asm("halt");
111 while(1)
112 yield();
113}
114
115#else
116
117bool charger_inserted(void)
118{
119 return false;
120}
121
122void charger_enable(bool on)
123{
124 (void)on;
125}
126
127void power_off(void)
128{
129}
130
131void ide_power_enable(bool on)
132{
133 (void)on;
134}
135
136#ifdef HAVE_SPDIF_POWER
137void spdif_power_enable(bool on)
138{
139 (void)on;
140}
141#endif
142
143#endif /* SIMULATOR */
diff --git a/firmware/target/coldfire/iriver/h100/usb-h100.c b/firmware/target/coldfire/iriver/h100/usb-h100.c
new file mode 100644
index 0000000000..3b00e967da
--- /dev/null
+++ b/firmware/target/coldfire/iriver/h100/usb-h100.c
@@ -0,0 +1,51 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 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 <stdbool.h>
21#include "cpu.h"
22#include "system.h"
23#include "kernel.h"
24
25void usb_init_device(void)
26{
27 or_l(0x00000080, &GPIO1_FUNCTION); /* GPIO39 is the USB detect input */
28 and_l(~0x01000040, &GPIO_OUT); /* GPIO24 is the Cypress chip power */
29 or_l(0x01000040, &GPIO_ENABLE);
30 or_l(0x01000040, &GPIO_FUNCTION);
31}
32
33bool usb_detect(void)
34{
35 return (GPIO1_READ & 0x80)?true:false;
36}
37
38void usb_enable(bool on)
39{
40 if(on)
41 {
42 /* Power on the Cypress chip */
43 or_l(0x01000040, &GPIO_OUT);
44 sleep(2);
45 }
46 else
47 {
48 /* Power off the Cypress chip */
49 and_l(~0x01000040, &GPIO_OUT);
50 }
51}
diff --git a/firmware/target/coldfire/iriver/h300/adc-h300.c b/firmware/target/coldfire/iriver/h300/adc-h300.c
new file mode 100644
index 0000000000..31702eaef1
--- /dev/null
+++ b/firmware/target/coldfire/iriver/h300/adc-h300.c
@@ -0,0 +1,83 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 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 "system.h"
22#include "kernel.h"
23#include "thread.h"
24#include "adc.h"
25#include "pcf50606.h"
26
27static unsigned char adcdata[NUM_ADC_CHANNELS];
28
29static int adcc2_parms[] =
30{
31 [ADC_BUTTONS] = 0x80 | (5 << 1) | 1, /* ADCIN2 */
32 [ADC_REMOTE] = 0x80 | (6 << 1) | 1, /* ADCIN3 */
33 [ADC_BATTERY] = 0x80 | (0 << 1) | 1, /* BATVOLT, resistive divider */
34 [ADC_REMOTEDETECT] = 0x80 | (2 << 1) | 1, /* ADCIN1, resistive divider */
35};
36
37unsigned short adc_scan(int channel)
38{
39 int level = set_irq_level(HIGHEST_IRQ_LEVEL);
40 unsigned char data;
41
42 pcf50606_write(0x2f, adcc2_parms[channel]);
43 data = pcf50606_read(0x30);
44
45 adcdata[channel] = data;
46
47 set_irq_level(level);
48 return data;
49}
50
51
52unsigned short adc_read(int channel)
53{
54 return adcdata[channel];
55}
56
57static int adc_counter;
58
59static void adc_tick(void)
60{
61 if(++adc_counter == HZ)
62 {
63 adc_counter = 0;
64 adc_scan(ADC_BATTERY);
65 adc_scan(ADC_REMOTEDETECT); /* Temporary. Remove when the remote
66 detection feels stable. */
67 }
68}
69
70void adc_init(void)
71{
72 or_l(0x80600080, &GPIO_FUNCTION); /* GPIO7: CS
73 GPIO21: Data In (to the ADC)
74 GPIO22: CLK
75 GPIO31: Data Out (from the ADC) */
76 or_l(0x00600080, &GPIO_ENABLE);
77 or_l(0x80, &GPIO_OUT); /* CS high */
78 and_l(~0x00400000, &GPIO_OUT); /* CLK low */
79
80 adc_scan(ADC_BATTERY);
81
82 tick_add_task(adc_tick);
83}
diff --git a/firmware/target/coldfire/iriver/h300/adc-target.h b/firmware/target/coldfire/iriver/h300/adc-target.h
new file mode 100644
index 0000000000..04200904a2
--- /dev/null
+++ b/firmware/target/coldfire/iriver/h300/adc-target.h
@@ -0,0 +1,41 @@
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/* for the iriver h3x0 */
20
21#ifndef _ADC_TARGET_H_
22#define _ADC_TARGET_H_
23
24#define NUM_ADC_CHANNELS 4
25
26#define ADC_BUTTONS 0
27#define ADC_REMOTE 1
28#define ADC_BATTERY 2
29#define ADC_REMOTEDETECT 3
30#define ADC_UNREG_POWER ADC_BATTERY /* For compatibility */
31
32/* ADC values for different remote control types */
33#define ADCVAL_H300_LCD_REMOTE 0x35
34#define ADCVAL_H100_LCD_REMOTE 0x54
35#define ADCVAL_H300_LCD_REMOTE_HOLD 0x72
36#define ADCVAL_H100_LCD_REMOTE_HOLD 0x83
37
38/* Force a scan now */
39unsigned short adc_scan(int channel);
40
41#endif /* _ADC_TARGET_H_ */
diff --git a/firmware/target/coldfire/iriver/h300/backlight-h300.c b/firmware/target/coldfire/iriver/h300/backlight-h300.c
new file mode 100644
index 0000000000..d5322c2cf7
--- /dev/null
+++ b/firmware/target/coldfire/iriver/h300/backlight-h300.c
@@ -0,0 +1,49 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 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 "kernel.h"
22#include "thread.h"
23#include "system.h"
24#include "backlight.h"
25#include "pcf50606.h"
26#include "lcd.h"
27
28void __backlight_on(void)
29{
30 lcd_enable(true);
31 sleep(HZ/100); /* lcd needs time - avoid flashing for dark screens */
32 or_l(0x00020000, &GPIO1_OUT);
33}
34
35void __backlight_off(void)
36{
37 and_l(~0x00020000, &GPIO1_OUT);
38 lcd_enable(false);
39}
40
41void __remote_backlight_on(void)
42{
43 and_l(~0x00000002, &GPIO1_OUT);
44}
45
46void __remote_backlight_off(void)
47{
48 or_l(0x00000002, &GPIO1_OUT);
49}
diff --git a/firmware/target/coldfire/iriver/h300/power-h300.c b/firmware/target/coldfire/iriver/h300/power-h300.c
new file mode 100644
index 0000000000..7c95aaf200
--- /dev/null
+++ b/firmware/target/coldfire/iriver/h300/power-h300.c
@@ -0,0 +1,101 @@
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 "kernel.h"
23#include "system.h"
24#include "power.h"
25#include "pcf50606.h"
26
27
28#ifdef CONFIG_TUNER
29
30static bool powered = false;
31
32bool radio_powered(void)
33{
34 return powered;
35}
36
37bool radio_power(bool status)
38{
39 bool old_status = powered;
40 powered = status;
41 return old_status;
42}
43
44#endif /* #ifdef CONFIG_TUNER */
45
46#ifndef SIMULATOR
47
48void power_init(void)
49{
50 or_l(0x00080000, &GPIO1_OUT);
51 or_l(0x00080000, &GPIO1_ENABLE);
52 or_l(0x00080000, &GPIO1_FUNCTION);
53
54#ifndef BOOTLOADER
55 /* The boot loader controls the power */
56 ide_power_enable(true);
57#endif
58 or_l(0x80000000, &GPIO_ENABLE);
59 or_l(0x80000000, &GPIO_FUNCTION);
60 pcf50606_init();
61}
62
63
64#ifdef CONFIG_CHARGING
65bool charger_inserted(void)
66{
67 return (GPIO1_READ & 0x00400000)?true:false;
68}
69#endif /* CONFIG_CHARGING */
70
71/* Returns true if the unit is charging the batteries. */
72bool charging_state(void) {
73 return (GPIO_READ & 0x00800000)?true:false;
74}
75
76
77void ide_power_enable(bool on)
78{
79 if(on)
80 and_l(~0x80000000, &GPIO_OUT);
81 else
82 or_l(0x80000000, &GPIO_OUT);
83}
84
85
86bool ide_powered(void)
87{
88 return (GPIO_OUT & 0x80000000)?false:true;
89}
90
91
92void power_off(void)
93{
94 set_irq_level(HIGHEST_IRQ_LEVEL);
95 and_l(~0x00080000, &GPIO1_OUT);
96 asm("halt");
97 while(1)
98 yield();
99}
100
101#endif /* SIMULATOR */
diff --git a/firmware/target/coldfire/iriver/h300/usb-h300.c b/firmware/target/coldfire/iriver/h300/usb-h300.c
new file mode 100644
index 0000000000..d08cc24dba
--- /dev/null
+++ b/firmware/target/coldfire/iriver/h300/usb-h300.c
@@ -0,0 +1,56 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 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 <stdbool.h>
21#include "cpu.h"
22#include "system.h"
23#include "kernel.h"
24
25void usb_init_device(void)
26{
27 or_l(0x00000080, &GPIO1_FUNCTION); /* GPIO39 is the USB detect input */
28 /* ISD300 3.3V ON */
29 or_l(8,&GPIO1_FUNCTION);
30 or_l(8,&GPIO1_OUT);
31 or_l(8,&GPIO1_ENABLE);
32
33 /* Tristate the SCK/SDA to the ISD300 config EEPROM */
34 and_l(~0x03000000, &GPIO_ENABLE);
35 or_l(0x03000000, &GPIO_FUNCTION);
36}
37
38bool usb_detect(void)
39{
40 return (GPIO1_READ & 0x80)?true:false;
41}
42
43void usb_enable(bool on)
44{
45 if(on)
46 {
47 /* Power on the Cypress chip */
48 and_l(~0x00000008,&GPIO1_OUT);
49 sleep(2);
50 }
51 else
52 {
53 /* Power off the Cypress chip */
54 or_l(0x00000008,&GPIO1_OUT);
55 }
56}
diff --git a/firmware/target/coldfire/iriver/system-iriver.c b/firmware/target/coldfire/iriver/system-iriver.c
new file mode 100644
index 0000000000..5f404fb8cf
--- /dev/null
+++ b/firmware/target/coldfire/iriver/system-iriver.c
@@ -0,0 +1,133 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 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 "kernel.h"
22#include "system.h"
23#include "power.h"
24#include "timer.h"
25#include "pcf50606.h"
26
27#if MEM < 32
28#define MAX_REFRESH_TIMER 59
29#define NORMAL_REFRESH_TIMER 21
30#define DEFAULT_REFRESH_TIMER 4
31#else
32#define MAX_REFRESH_TIMER 29
33#define NORMAL_REFRESH_TIMER 10
34#define DEFAULT_REFRESH_TIMER 1
35#endif
36
37#ifdef IRIVER_H300_SERIES
38#define RECALC_DELAYS(f) \
39 pcf50606_i2c_recalc_delay(f)
40#else
41#define RECALC_DELAYS(f)
42#endif
43
44#ifdef HAVE_SERIAL
45#define BAUD_RATE 57600
46#define BAUDRATE_DIV_DEFAULT (CPUFREQ_DEFAULT/(BAUD_RATE*32*2))
47#define BAUDRATE_DIV_NORMAL (CPUFREQ_NORMAL/(BAUD_RATE*32*2))
48#define BAUDRATE_DIV_MAX (CPUFREQ_MAX/(BAUD_RATE*32*2))
49#endif
50
51void set_cpu_frequency (long) __attribute__ ((section (".icode")));
52void set_cpu_frequency(long frequency)
53{
54 switch(frequency)
55 {
56 case CPUFREQ_MAX:
57 DCR = (0x8200 | DEFAULT_REFRESH_TIMER);
58 /* Refresh timer for bypass frequency */
59 PLLCR &= ~1; /* Bypass mode */
60 timers_adjust_prescale(CPUFREQ_DEFAULT_MULT, false);
61 RECALC_DELAYS(CPUFREQ_MAX);
62 PLLCR = 0x11c56005;
63 CSCR0 = 0x00001180; /* Flash: 4 wait states */
64 CSCR1 = 0x00000980; /* LCD: 2 wait states */
65#if CONFIG_USBOTG == USBOTG_ISP1362
66 CSCR3 = 0x00002180; /* USBOTG: 8 wait states */
67#endif
68 while(!(PLLCR & 0x80000000)) {}; /* Wait until the PLL has locked.
69 This may take up to 10ms! */
70 timers_adjust_prescale(CPUFREQ_MAX_MULT, true);
71 DCR = (0x8200 | MAX_REFRESH_TIMER); /* Refresh timer */
72 cpu_frequency = CPUFREQ_MAX;
73 IDECONFIG1 = 0x10100000 | (1 << 13) | (2 << 10);
74 /* SRE active on write (H300 USBOTG) | BUFEN2 enable | CS2Post | CS2Pre */
75 IDECONFIG2 = 0x40000 | (2 << 8); /* TA enable + CS2wait */
76
77#ifdef HAVE_SERIAL
78 UBG10 = BAUDRATE_DIV_MAX >> 8;
79 UBG20 = BAUDRATE_DIV_MAX & 0xff;
80#endif
81 break;
82
83 case CPUFREQ_NORMAL:
84 DCR = (DCR & ~0x01ff) | DEFAULT_REFRESH_TIMER;
85 /* Refresh timer for bypass frequency */
86 PLLCR &= ~1; /* Bypass mode */
87 timers_adjust_prescale(CPUFREQ_DEFAULT_MULT, false);
88 RECALC_DELAYS(CPUFREQ_NORMAL);
89 PLLCR = 0x13c5e005;
90 CSCR0 = 0x00000580; /* Flash: 1 wait state */
91 CSCR1 = 0x00000180; /* LCD: 0 wait states */
92#if CONFIG_USBOTG == USBOTG_ISP1362
93 CSCR3 = 0x00000580; /* USBOTG: 1 wait state */
94#endif
95 while(!(PLLCR & 0x80000000)) {}; /* Wait until the PLL has locked.
96 This may take up to 10ms! */
97 timers_adjust_prescale(CPUFREQ_NORMAL_MULT, true);
98 DCR = (0x8000 | NORMAL_REFRESH_TIMER); /* Refresh timer */
99 cpu_frequency = CPUFREQ_NORMAL;
100 IDECONFIG1 = 0x10100000 | (0 << 13) | (1 << 10);
101 /* SRE active on write (H300 USBOTG) | BUFEN2 enable | CS2Post | CS2Pre */
102 IDECONFIG2 = 0x40000 | (0 << 8); /* TA enable + CS2wait */
103
104#ifdef HAVE_SERIAL
105 UBG10 = BAUDRATE_DIV_NORMAL >> 8;
106 UBG20 = BAUDRATE_DIV_NORMAL & 0xff;
107#endif
108 break;
109 default:
110 DCR = (DCR & ~0x01ff) | DEFAULT_REFRESH_TIMER;
111 /* Refresh timer for bypass frequency */
112 PLLCR &= ~1; /* Bypass mode */
113 timers_adjust_prescale(CPUFREQ_DEFAULT_MULT, true);
114 RECALC_DELAYS(CPUFREQ_DEFAULT);
115 PLLCR = 0x10c00200; /* Power down PLL, but keep CLSEL and CRSEL */
116 CSCR0 = 0x00000180; /* Flash: 0 wait states */
117 CSCR1 = 0x00000180; /* LCD: 0 wait states */
118#if CONFIG_USBOTG == USBOTG_ISP1362
119 CSCR3 = 0x00000180; /* USBOTG: 0 wait states */
120#endif
121 DCR = (0x8000 | DEFAULT_REFRESH_TIMER); /* Refresh timer */
122 cpu_frequency = CPUFREQ_DEFAULT;
123 IDECONFIG1 = 0x10100000 | (0 << 13) | (1 << 10);
124 /* SRE active on write (H300 USBOTG) | BUFEN2 enable | CS2Post | CS2Pre */
125 IDECONFIG2 = 0x40000 | (0 << 8); /* TA enable + CS2wait */
126
127#ifdef HAVE_SERIAL
128 UBG10 = BAUDRATE_DIV_DEFAULT >> 8;
129 UBG20 = BAUDRATE_DIV_DEFAULT & 0xff;
130#endif
131 break;
132 }
133}
diff --git a/firmware/target/coldfire/iriver/usb-target.h b/firmware/target/coldfire/iriver/usb-target.h
new file mode 100644
index 0000000000..ab8cac6f99
--- /dev/null
+++ b/firmware/target/coldfire/iriver/usb-target.h
@@ -0,0 +1,24 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 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#ifndef USB_TARGET_H
20#define USB_TARGET_H
21
22bool usb_init_device(void);
23
24#endif