summaryrefslogtreecommitdiff
path: root/firmware/target/coldfire/iriver/h300
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/coldfire/iriver/h300')
-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
5 files changed, 330 insertions, 0 deletions
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}