summaryrefslogtreecommitdiff
path: root/firmware/target
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target')
-rw-r--r--firmware/target/arm/tms320dm320/creative-zvm/adc-creativezvm.c32
-rw-r--r--firmware/target/arm/tms320dm320/creative-zvm/adc-target.h38
-rw-r--r--firmware/target/arm/tms320dm320/creative-zvm/ata-creativezvm.c101
-rw-r--r--firmware/target/arm/tms320dm320/creative-zvm/ata-target.h68
-rw-r--r--firmware/target/arm/tms320dm320/creative-zvm/audio-creativezvm.c44
-rw-r--r--firmware/target/arm/tms320dm320/creative-zvm/backlight-target.h31
-rw-r--r--firmware/target/arm/tms320dm320/creative-zvm/button-target.h57
-rw-r--r--firmware/target/arm/tms320dm320/creative-zvm/lcd-creativezvm.c405
-rw-r--r--firmware/target/arm/tms320dm320/creative-zvm/lcd-target.h28
-rw-r--r--firmware/target/arm/tms320dm320/creative-zvm/pcm-creativezvm.c81
-rw-r--r--firmware/target/arm/tms320dm320/creative-zvm/pic-creativezvm.c323
-rw-r--r--firmware/target/arm/tms320dm320/creative-zvm/power-creativezvm.c68
-rw-r--r--firmware/target/arm/tms320dm320/creative-zvm/powermgmt-creativezvm.c57
-rw-r--r--firmware/target/arm/tms320dm320/creative-zvm/usb-creativezvm.c65
-rw-r--r--firmware/target/arm/tms320dm320/creative-zvm/usb-target.h76
-rwxr-xr-xfirmware/target/arm/tms320dm320/crt0.S2
-rwxr-xr-xfirmware/target/arm/tms320dm320/debug-dm320.c70
-rw-r--r--firmware/target/arm/tms320dm320/kernel-dm320.c15
-rw-r--r--firmware/target/arm/tms320dm320/spi-dm320.c23
-rw-r--r--firmware/target/arm/tms320dm320/spi-target.h4
-rw-r--r--firmware/target/arm/tms320dm320/system-dm320.c56
-rw-r--r--firmware/target/arm/tms320dm320/timer-dm320.c20
-rw-r--r--firmware/target/arm/tms320dm320/uart-dm320.c8
23 files changed, 1640 insertions, 32 deletions
diff --git a/firmware/target/arm/tms320dm320/creative-zvm/adc-creativezvm.c b/firmware/target/arm/tms320dm320/creative-zvm/adc-creativezvm.c
new file mode 100644
index 0000000000..d634a71f70
--- /dev/null
+++ b/firmware/target/arm/tms320dm320/creative-zvm/adc-creativezvm.c
@@ -0,0 +1,32 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: adc-mr500.c 14817 2007-09-22 15:43:38Z kkurbjun $
9 *
10 * Copyright (C) 2007 by Karl Kurbjun
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
20#include "cpu.h"
21#include "adc-target.h"
22#include "kernel.h"
23
24void adc_init(void)
25{
26}
27
28/* Called to get the recent ADC reading */
29inline unsigned short adc_read(int channel)
30{
31 return (short)channel;
32}
diff --git a/firmware/target/arm/tms320dm320/creative-zvm/adc-target.h b/firmware/target/arm/tms320dm320/creative-zvm/adc-target.h
new file mode 100644
index 0000000000..aa0f7eb364
--- /dev/null
+++ b/firmware/target/arm/tms320dm320/creative-zvm/adc-target.h
@@ -0,0 +1,38 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: adc-target.h 14817 2007-09-22 15:43:38Z kkurbjun $
9 *
10 * Copyright (C) 2007 by Karl Kurbjun
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
20#ifndef _ADC_TARGET_H_
21#define _ADC_TARGET_H_
22
23/* only two channels used by the Gigabeat */
24#define NUM_ADC_CHANNELS 2
25
26#define ADC_BATTERY 0
27#define ADC_HPREMOTE 1
28#define ADC_UNKNOWN_3 2
29#define ADC_UNKNOWN_4 3
30#define ADC_UNKNOWN_5 4
31#define ADC_UNKNOWN_6 5
32#define ADC_UNKNOWN_7 6
33#define ADC_UNKNOWN_8 7
34
35#define ADC_UNREG_POWER ADC_BATTERY /* For compatibility */
36#define ADC_READ_ERROR 0xFFFF
37
38#endif
diff --git a/firmware/target/arm/tms320dm320/creative-zvm/ata-creativezvm.c b/firmware/target/arm/tms320dm320/creative-zvm/ata-creativezvm.c
new file mode 100644
index 0000000000..5cbcd72415
--- /dev/null
+++ b/firmware/target/arm/tms320dm320/creative-zvm/ata-creativezvm.c
@@ -0,0 +1,101 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2008 by Maurus Cuelenaere
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
20#include "config.h"
21#include "cpu.h"
22#include "kernel.h"
23#include "thread.h"
24#include "system.h"
25#include "power.h"
26#include "panic.h"
27#include "ata-target.h"
28
29void ide_power_enable(bool on){
30#if 0
31 IO_INTC_EINT1 &= ~INTR_EINT1_EXT2;
32 if(on)
33 {
34 IO_GIO_BITSET0 = (1 << 14);
35 ata_reset();
36 }
37 else
38 IO_GIO_BITCLR0 = (1 << 14);
39 IO_INTC_EINT1 |= INTR_EINT1_EXT2;
40 return;
41#endif
42}
43
44inline bool ide_powered(){
45#if 0
46 return (IO_GIO_BITSET0 & (1 << 14));
47#else
48 return true;
49#endif
50}
51
52void ata_reset(void)
53{
54/* Disabled until figured out what's wrong */
55 IO_INTC_EINT1 &= ~INTR_EINT1_EXT2; //disable GIO2 interrupt
56 if(!ide_powered())
57 {
58 ide_power_enable(true);
59 sleep(150);
60 }
61 else
62 {
63 IO_GIO_BITSET0 = (1 << 5);
64 IO_GIO_BITCLR0 = (1 << 3);
65 sleep(1);
66 }
67 IO_GIO_BITCLR0 = (1 << 5);
68 sleep(10);
69 IO_GIO_BITSET0 = (1 << 3);
70 while(!(ATA_COMMAND & STATUS_RDY))
71 sleep(10);
72 IO_INTC_EINT1 |= INTR_EINT1_EXT2; //enable GIO2 interrupt
73 return;
74}
75
76void ata_enable(bool on)
77{
78 (void)on;
79 return;
80}
81
82bool ata_is_coldstart(void)
83{
84 return true;
85}
86
87void ata_device_init(void)
88{
89 IO_INTC_EINT1 |= INTR_EINT1_EXT2; //enable GIO2 interrupt
90 //TODO: mimic OF inits...
91 return;
92}
93
94void GIO2(void)
95{
96#ifdef DEBUG
97 //printf("GIO2 interrupt...");
98#endif
99 IO_INTC_IRQ1 = INTR_IRQ1_EXT2; //Mask GIO2 interrupt
100 return;
101}
diff --git a/firmware/target/arm/tms320dm320/creative-zvm/ata-target.h b/firmware/target/arm/tms320dm320/creative-zvm/ata-target.h
new file mode 100644
index 0000000000..b098396d5e
--- /dev/null
+++ b/firmware/target/arm/tms320dm320/creative-zvm/ata-target.h
@@ -0,0 +1,68 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2007 by Maurus Cuelenaere
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
20#ifndef ATA_TARGET_H
21#define ATA_TARGET_H
22
23/* Plain C read & write loops */
24#define PREFER_C_READING
25#define PREFER_C_WRITING
26
27#define ATA_IOBASE 0x50FEE000
28#define ATA_DATA (*((volatile unsigned short*)(ATA_IOBASE)))
29#define ATA_ERROR (*((volatile unsigned char*)(ATA_IOBASE+0x2)))
30#define ATA_NSECTOR (*((volatile unsigned char*)(ATA_IOBASE+0x4)))
31#define ATA_SECTOR (*((volatile unsigned char*)(ATA_IOBASE+0x6)))
32#define ATA_LCYL (*((volatile unsigned char*)(ATA_IOBASE+0x8)))
33#define ATA_HCYL (*((volatile unsigned char*)(ATA_IOBASE+0xA)))
34#define ATA_SELECT (*((volatile unsigned char*)(ATA_IOBASE+0xC)))
35#define ATA_COMMAND (*((volatile unsigned char*)(ATA_IOBASE+0xE)))
36#define ATA_CONTROL (*((volatile unsigned char*)(ATA_IOBASE+0x800C)))
37
38#define STATUS_BSY 0x80
39#define STATUS_RDY 0x40
40#define STATUS_DF 0x20
41#define STATUS_DRQ 0x08
42#define STATUS_ERR 0x01
43#define ERROR_ABRT 0x04
44
45#define WRITE_PATTERN1 0xa5
46#define WRITE_PATTERN2 0x5a
47#define WRITE_PATTERN3 0xaa
48#define WRITE_PATTERN4 0x55
49
50#define READ_PATTERN1 0xa5
51#define READ_PATTERN2 0x5a
52#define READ_PATTERN3 0xaa
53#define READ_PATTERN4 0x55
54
55#define READ_PATTERN1_MASK 0xff
56#define READ_PATTERN2_MASK 0xff
57#define READ_PATTERN3_MASK 0xff
58#define READ_PATTERN4_MASK 0xff
59
60#define SET_REG(reg,val) reg = (val)
61#define SET_16BITREG(reg,val) reg = (val)
62
63void ata_reset(void);
64void ata_device_init(void);
65bool ata_is_coldstart(void);
66void ide_power_enable(bool on);
67
68#endif
diff --git a/firmware/target/arm/tms320dm320/creative-zvm/audio-creativezvm.c b/firmware/target/arm/tms320dm320/creative-zvm/audio-creativezvm.c
new file mode 100644
index 0000000000..1e5676b19e
--- /dev/null
+++ b/firmware/target/arm/tms320dm320/creative-zvm/audio-creativezvm.c
@@ -0,0 +1,44 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: audio-c200_e200.c 14624 2007-09-06 03:01:41Z lowlight $
9 *
10 * Copyright (C) 2007 by Michael Sevakis
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 "cpu.h"
20#include "kernel.h"
21#include "sound.h"
22
23const struct sound_settings_info audiohw_settings[] = {
24 [SOUND_VOLUME] = {"dB", 0, 1, -74, 6, -25},
25 [SOUND_BASS] = {"dB", 1, 15, -60, 90, 0},
26 [SOUND_TREBLE] = {"dB", 1, 15, -60, 90, 0},
27 [SOUND_BALANCE] = {"%", 0, 1,-100, 100, 0},
28 [SOUND_CHANNELS] = {"", 0, 1, 0, 5, 0},
29 [SOUND_STEREO_WIDTH] = {"%", 0, 5, 0, 250, 100},
30};
31
32
33void audiohw_init(void)
34{
35}
36
37void audiohw_close(void)
38{
39}
40
41void audiohw_mute(bool mute)
42{
43 (void) mute;
44}
diff --git a/firmware/target/arm/tms320dm320/creative-zvm/backlight-target.h b/firmware/target/arm/tms320dm320/creative-zvm/backlight-target.h
new file mode 100644
index 0000000000..446c5640aa
--- /dev/null
+++ b/firmware/target/arm/tms320dm320/creative-zvm/backlight-target.h
@@ -0,0 +1,31 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: backlight-target.h 15599 2007-11-12 18:49:53Z amiconn $
9 *
10 * Copyright (C) 2007 by Karl Kurbjun
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
20#ifndef BACKLIGHT_TARGET_H
21#define BACKLIGHT_TARGET_H
22
23bool _backlight_init(void);
24void _backlight_on(void);
25void _backlight_off(void);
26void _backlight_set_brightness(int brightness);
27
28/* true: backlight fades off - false: backlight fades on */
29void __backlight_dim(bool dim);
30
31#endif
diff --git a/firmware/target/arm/tms320dm320/creative-zvm/button-target.h b/firmware/target/arm/tms320dm320/creative-zvm/button-target.h
new file mode 100644
index 0000000000..1b63895374
--- /dev/null
+++ b/firmware/target/arm/tms320dm320/creative-zvm/button-target.h
@@ -0,0 +1,57 @@
1/***************************************************************************
2* __________ __ ___.
3* Open \______ \ ____ ____ | | _\_ |__ _______ ___
4* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7* \/ \/ \/ \/ \/
8* $Id$
9*
10* Copyright (C) 2008 by Maurus Cuelenaere
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
20#ifndef _BUTTON_TARGET_H_
21#define _BUTTON_TARGET_H_
22
23#include "config.h"
24
25#define BUTTON_BACK (1 << 0)
26#define BUTTON_CUSTOM (1 << 1)
27#define BUTTON_MENU (1 << 2)
28
29#define BUTTON_LEFT (1 << 3)
30#define BUTTON_RIGHT (1 << 4)
31#define BUTTON_UP (1 << 5)
32#define BUTTON_DOWN (1 << 6)
33#define BUTTON_SELECT (1 << 7)
34
35#define BUTTON_POWER (1 << 8)
36#define BUTTON_PLAY (1 << 9)
37
38#define BUTTON_HOLD (1 << 10)
39
40#define BUTTON_REMOTE 0
41
42#define BUTTON_MAIN ( BUTTON_BACK | BUTTON_MENU | BUTTON_LEFT | BUTTON_RIGHT \
43 | BUTTON_UP | BUTTON_DOWN | BUTTON_SELECT | BUTTON_POWER \
44 | BUTTON_PLAY | BUTTON_HOLD | BUTTON_CUSTOM )
45
46#define POWEROFF_BUTTON BUTTON_POWER
47#define POWEROFF_COUNT 10
48
49void button_init_device(void);
50int button_read_device(void);
51bool headphones_inserted(void);
52bool button_hold(void);
53bool button_usb_connected(void);
54
55int get_debug_info(int choice);
56
57#endif /* _BUTTON_TARGET_H_ */
diff --git a/firmware/target/arm/tms320dm320/creative-zvm/lcd-creativezvm.c b/firmware/target/arm/tms320dm320/creative-zvm/lcd-creativezvm.c
new file mode 100644
index 0000000000..dec20ad72f
--- /dev/null
+++ b/firmware/target/arm/tms320dm320/creative-zvm/lcd-creativezvm.c
@@ -0,0 +1,405 @@
1/***************************************************************************
2* __________ __ ___.
3* Open \______ \ ____ ____ | | _\_ |__ _______ ___
4* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7* \/ \/ \/ \/ \/
8* $Id$
9*
10* Copyright (C) 2008 by Maurus Cuelenaere
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
21#include "hwcompat.h"
22#include "kernel.h"
23#include "lcd.h"
24#include "system.h"
25#include "memory.h"
26#include "cpu.h"
27#include "spi.h"
28#include "spi-target.h"
29#include "lcd-target.h"
30
31/* Power and display status */
32static bool display_on = true; /* Is the display turned on? */
33static bool direct_fb_access = false; /* Does the DM320 has direct access to the FB? */
34
35int lcd_default_contrast(void)
36{
37 return 0x1f;
38}
39
40void lcd_set_contrast(int val)
41{
42 /* iirc there is an ltv250qv command to do this */
43 #warning function not implemented
44 (void)val;
45}
46
47void lcd_set_invert_display(bool yesno) {
48 (void) yesno;
49 // TODO:
50}
51
52void lcd_set_flip(bool yesno) {
53 (void) yesno;
54 // TODO:
55}
56
57
58/* LTV250QV panel functions */
59
60static void lcd_write_reg(unsigned char reg, unsigned short val)
61{
62 unsigned char block[3];
63 block[0] = 0x74;
64 block[1] = 0;
65 block[2] = reg | 0xFF;
66 spi_block_transfer(SPI_target_LTV250QV, block, sizeof(block), NULL, 0);
67 block[0] = 0x76;
68 block[1] = (val >> 8) & 0xFF;
69 block[2] = val & 0xFF;
70 spi_block_transfer(SPI_target_LTV250QV, block, sizeof(block), NULL, 0);
71}
72
73static void sleep_ms(unsigned int ms)
74{
75 sleep(ms*HZ/1000);
76}
77
78static void lcd_display_on(void)
79{
80 /* Enable main power */
81 IO_GIO_BITSET2 |= (1 << 3);
82
83 /* power on sequence as per the ZVM firmware */
84 sleep_ms(250);
85 IO_GIO_BITSET1 = (1 << 13);
86 sleep_ms(5);
87 IO_GIO_BITSET2 = (1 << 5);
88 IO_GIO_BITSET2 = (1 << 8);
89 sleep_ms(1);
90
91 //Init SPI here...
92 sleep_ms(32);
93
94 IO_GIO_BITSET2 = (1 << 0);
95 sleep_ms(5);
96 IO_GIO_BITSET2 = (1 << 7);
97 sleep_ms(5);
98 IO_GIO_BITSET2 = (1 << 4);
99 sleep_ms(5);
100 IO_GIO_BITCLR2 = (1 << 8);
101 //TODO: figure out what OF does after this...
102 IO_GIO_BITSET2 = (1 << 8);
103 sleep_ms(1);
104
105 lcd_write_reg(1, 0x1D);
106 lcd_write_reg(2, 0x0);
107 lcd_write_reg(3, 0x0);
108 lcd_write_reg(4, 0x0);
109 lcd_write_reg(5, 0x40A3);
110 lcd_write_reg(6, 0x0);
111 lcd_write_reg(7, 0x0);
112 lcd_write_reg(8, 0x0);
113 lcd_write_reg(9, 0x0);
114 lcd_write_reg(10, 0x0);
115 lcd_write_reg(16, 0x0);
116 lcd_write_reg(17, 0x0);
117 lcd_write_reg(18, 0x0);
118 lcd_write_reg(19, 0x0);
119 lcd_write_reg(20, 0x0);
120 lcd_write_reg(21, 0x0);
121 lcd_write_reg(22, 0x0);
122 lcd_write_reg(23, 0x0);
123 lcd_write_reg(24, 0x0);
124 lcd_write_reg(25, 0x0);
125 sleep_ms(10);
126
127 lcd_write_reg(9, 0x4055);
128 lcd_write_reg(10, 0x0);
129 sleep_ms(40);
130
131 lcd_write_reg(10, 0x2000);
132 sleep_ms(40);
133
134 lcd_write_reg(1, 0x401D);
135 lcd_write_reg(2, 0x204);
136 lcd_write_reg(3, 0x100);
137 lcd_write_reg(4, 0x1000);
138 lcd_write_reg(5, 0x5033);
139 lcd_write_reg(6, 0x5);
140 lcd_write_reg(7, 0x1B);
141 lcd_write_reg(8, 0x800);
142 lcd_write_reg(16, 0x203);
143 lcd_write_reg(17, 0x302);
144 lcd_write_reg(18, 0xC08);
145 lcd_write_reg(19, 0xC08);
146 lcd_write_reg(20, 0x707);
147 lcd_write_reg(21, 0x707);
148 lcd_write_reg(22, 0x104);
149 lcd_write_reg(23, 0x306);
150 lcd_write_reg(24, 0x0);
151 lcd_write_reg(25, 0x0);
152 sleep_ms(60);
153
154 lcd_write_reg(9, 0xA55);
155 lcd_write_reg(10, 0x111A);
156 sleep_ms(10);
157
158 //TODO: other stuff!
159
160 /* tell that we're on now */
161 display_on = true;
162}
163
164static void lcd_display_off(void)
165{
166 display_on = false;
167
168 /* LQV shutdown sequence */
169 lcd_write_reg(9, 0x855);
170 sleep_ms(20);
171
172 lcd_write_reg(9, 0x55);
173 lcd_write_reg(5, 0x4033);
174 lcd_write_reg(10, 0x0);
175 sleep_ms(20);
176
177 lcd_write_reg(9, 0x0);
178 sleep_ms(10);
179 unsigned char temp[1];
180 temp[0] = 0;
181 spi_block_transfer(SPI_target_LTV250QV, temp, sizeof(temp), NULL, 0);
182
183 IO_GIO_BITCLR2 = (1 << 4);
184 sleep_ms(5);
185 IO_GIO_BITCLR2 = (1 << 7);
186 sleep_ms(5);
187 IO_GIO_BITCLR2 = (1 << 0);
188 sleep_ms(2);
189 IO_GIO_BITCLR2 = (1 << 8);
190 IO_GIO_BITCLR2 = (1 << 5);
191
192 /* Disable main power */
193 IO_GIO_BITCLR2 |= (1 << 3);
194}
195
196
197
198void lcd_enable(bool on)
199{
200 if (on == display_on)
201 return;
202
203 if (on)
204 {
205 display_on = true; //TODO: remove me!
206 //lcd_display_on(); /* Turn on display */
207 lcd_update(); /* Resync display */
208 }
209 else
210 {
211 display_on = false; //TODO: remove me!
212 //lcd_display_off(); /* Turn off display */
213 }
214}
215
216bool lcd_enabled(void)
217{
218 return display_on;
219}
220
221void lcd_set_direct_fb(bool yes)
222{
223 unsigned int addr;
224 direct_fb_access = yes;
225 if(yes)
226 addr = ((unsigned int)&lcd_framebuffer-CONFIG_SDRAM_START) / 32;
227 else
228 addr = ((unsigned int)FRAME-CONFIG_SDRAM_START) / 32;
229 IO_OSD_OSDWINADH = addr >> 16;
230 IO_OSD_OSDWIN0ADL = addr & 0xFFFF;
231}
232
233bool lcd_get_direct_fb(void)
234{
235 return direct_fb_access;
236}
237
238void lcd_init_device(void)
239{
240 /* Based on lcd-mr500.c from Catalin Patulea */
241 unsigned int addr;
242
243 /* Clear the Frame */
244 memset16(FRAME, 0x0000, LCD_WIDTH*LCD_HEIGHT);
245
246 IO_OSD_MODE = 0x00ff;
247 IO_OSD_VIDWINMD = 0x0002;
248 IO_OSD_OSDWINMD0 = 0x2001;
249 IO_OSD_OSDWINMD1 = 0x0002;
250 IO_OSD_ATRMD = 0x0000;
251 IO_OSD_RECTCUR = 0x0000;
252
253 IO_OSD_OSDWIN0OFST = (LCD_WIDTH*16) / 256;
254 addr = ((unsigned int)FRAME-CONFIG_SDRAM_START) / 32;
255 IO_OSD_OSDWINADH = addr >> 16;
256 IO_OSD_OSDWIN0ADL = addr & 0xFFFF;
257
258#ifndef ZEN_VISION
259 IO_OSD_BASEPX=26;
260 IO_OSD_BASEPY=5;
261#else
262 IO_OSD_BASEPX=80;
263 IO_OSD_BASEPY=0;
264#endif
265
266 IO_OSD_OSDWIN0XP = 0;
267 IO_OSD_OSDWIN0YP = 0;
268 IO_OSD_OSDWIN0XL = LCD_WIDTH;
269 IO_OSD_OSDWIN0YL = LCD_HEIGHT;
270#if 0
271 //TODO: set LCD clock!
272 IO_CLK_MOD1 &= ~0x18; // disable OSD clock and VENC clock
273 IO_CLK_02DIV = 3;
274 IO_CLK_OSEL = (IO_CLK_OSEL & ~0xF00) | 0x400; // reset 'General purpose clock output (GIO26, GIO34)' and set to 'PLLIN clock'
275 IO_CLK_SEL1 = (IO_CLK_SEL1 | 7) | 0x1000; // set to 'GP clock output 2 (GIO26, GIO34)' and turn on 'VENC clock'
276 IO_CLK_MOD1 |= 0x18; // enable OSD clock and VENC clock
277
278 /* Set LCD values in OSD */
279 IO_VID_ENC_VMOD = ( ( (IO_VID_ENC_VMOD & 0xFFFF8C00) | 0x14) | 0x2400 ); // disable NTSC/PAL encoder & set mode to RGB666 parallel 18 bit
280 IO_VID_ENC_VDCTL = ( ( (IO_VID_ENC_VDCTL & 0xFFFFCFE8) | 0x20) | 0x4000 );
281 //TODO: finish this...
282#endif
283}
284
285
286/*** Update functions ***/
287
288
289
290/* Update a fraction of the display. */
291void lcd_update_rect(int x, int y, int width, int height)
292{
293 register fb_data *dst, *src;
294
295 if (!display_on || direct_fb_access)
296 return;
297
298 if (x + width > LCD_WIDTH)
299 width = LCD_WIDTH - x; /* Clip right */
300 if (x < 0)
301 width += x, x = 0; /* Clip left */
302 if (width <= 0)
303 return; /* nothing left to do */
304
305 if (y + height > LCD_HEIGHT)
306 height = LCD_HEIGHT - y; /* Clip bottom */
307 if (y < 0)
308 height += y, y = 0; /* Clip top */
309 if (height <= 0)
310 return; /* nothing left to do */
311
312#if CONFIG_ORIENTATION == SCREEN_PORTAIT
313 dst = (fb_data *)FRAME + LCD_WIDTH*y + x;
314 src = &lcd_framebuffer[y][x];
315
316 /* Copy part of the Rockbox framebuffer to the second framebuffer */
317 if (width < LCD_WIDTH)
318 {
319 /* Not full width - do line-by-line */
320 lcd_copy_buffer_rect(dst, src, width, height);
321 }
322 else
323 {
324 /* Full width - copy as one line */
325 lcd_copy_buffer_rect(dst, src, LCD_WIDTH*height, 1);
326 }
327#else
328 src = &lcd_framebuffer[y][x];
329
330 register int xc, yc;
331 register fb_data *start=FRAME + LCD_HEIGHT*(LCD_WIDTH-x-1) + y + 1;
332
333 for(yc=0;yc<height;yc++)
334 {
335 dst=start+yc;
336 for(xc=0; xc<width; xc++)
337 {
338 *dst=*src++;
339 dst-=LCD_HEIGHT;
340 }
341 src+=x;
342 }
343#endif
344}
345
346/* Update the display.
347This must be called after all other LCD functions that change the display. */
348void lcd_update(void)
349{
350 if (!display_on || direct_fb_access)
351 return;
352#if CONFIG_ORIENTATION == SCREEN_PORTAIT
353 lcd_copy_buffer_rect((fb_data *)FRAME, &lcd_framebuffer[0][0],
354 LCD_WIDTH*LCD_HEIGHT, 1);
355#else
356 lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT);
357#endif
358}
359
360/* Line write helper function for lcd_yuv_blit. Write two lines of yuv420. */
361extern void lcd_write_yuv420_lines(fb_data *dst,
362unsigned char chroma_buf[LCD_HEIGHT/2*3],
363unsigned char const * const src[3],
364int width,
365int stride);
366/* Performance function to blit a YUV bitmap directly to the LCD */
367/* For the Gigabeat - show it rotated */
368/* So the LCD_WIDTH is now the height */
369void lcd_blit_yuv(unsigned char * const src[3],
370int src_x, int src_y, int stride,
371int x, int y, int width, int height)
372{
373 /* Caches for chroma data so it only need be recalculated every other
374 line */
375 unsigned char chroma_buf[LCD_HEIGHT/2*3]; /* 480 bytes */
376 unsigned char const * yuv_src[3];
377 off_t z;
378
379 if (!display_on || direct_fb_access)
380 return;
381
382 /* Sorry, but width and height must be >= 2 or else */
383 width &= ~1;
384 height >>= 1;
385
386 fb_data *dst = (fb_data*)FRAME + x * LCD_WIDTH + (LCD_WIDTH - y) - 1;
387
388 z = stride*src_y;
389 yuv_src[0] = src[0] + z + src_x;
390 yuv_src[1] = src[1] + (z >> 2) + (src_x >> 1);
391 yuv_src[2] = src[2] + (yuv_src[1] - src[1]);
392
393 do
394 {
395 lcd_write_yuv420_lines(dst, chroma_buf, yuv_src, width,
396 stride);
397
398 yuv_src[0] += stride << 1; /* Skip down two luma lines */
399 yuv_src[1] += stride >> 1; /* Skip down one chroma line */
400 yuv_src[2] += stride >> 1;
401 dst -= 2;
402 }
403 while (--height > 0);
404}
405
diff --git a/firmware/target/arm/tms320dm320/creative-zvm/lcd-target.h b/firmware/target/arm/tms320dm320/creative-zvm/lcd-target.h
new file mode 100644
index 0000000000..da63187637
--- /dev/null
+++ b/firmware/target/arm/tms320dm320/creative-zvm/lcd-target.h
@@ -0,0 +1,28 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2007 by Karl Kurbjun
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
20#ifndef _LCD_TARGET_H_
21#define _LCD_TARGET_H_
22
23extern void lcd_enable(bool state);
24
25void lcd_set_direct_fb(bool yes);
26bool lcd_get_direct_fb(void);
27
28#endif
diff --git a/firmware/target/arm/tms320dm320/creative-zvm/pcm-creativezvm.c b/firmware/target/arm/tms320dm320/creative-zvm/pcm-creativezvm.c
new file mode 100644
index 0000000000..6501125f9e
--- /dev/null
+++ b/firmware/target/arm/tms320dm320/creative-zvm/pcm-creativezvm.c
@@ -0,0 +1,81 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2007 by Karl Kurbjun
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 "system.h"
20#include "kernel.h"
21#include "logf.h"
22#include "audio.h"
23#include "sound.h"
24#include "file.h"
25
26void pcm_postinit(void)
27{
28
29}
30
31const void * pcm_play_dma_get_peak_buffer(int *count)
32{
33 (void) count;
34 return 0;
35}
36
37void pcm_play_dma_init(void)
38{
39
40}
41
42void pcm_apply_settings(void)
43{
44
45}
46
47void pcm_set_frequency(unsigned int frequency)
48{
49 (void) frequency;
50}
51
52void pcm_play_dma_start(const void *addr, size_t size)
53{
54 (void) addr;
55 (void) size;
56}
57
58void pcm_play_dma_stop(void)
59{
60
61}
62
63void pcm_play_lock(void)
64{
65
66}
67
68void pcm_play_unlock(void)
69{
70
71}
72
73void pcm_play_dma_pause(bool pause)
74{
75 (void) pause;
76}
77
78size_t pcm_get_bytes_waiting(void)
79{
80 return 0;
81}
diff --git a/firmware/target/arm/tms320dm320/creative-zvm/pic-creativezvm.c b/firmware/target/arm/tms320dm320/creative-zvm/pic-creativezvm.c
new file mode 100644
index 0000000000..35e6bd31fb
--- /dev/null
+++ b/firmware/target/arm/tms320dm320/creative-zvm/pic-creativezvm.c
@@ -0,0 +1,323 @@
1/***************************************************************************
2* __________ __ ___.
3* Open \______ \ ____ ____ | | _\_ |__ _______ ___
4* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7* \/ \/ \/ \/ \/
8* $Id$
9*
10* Copyright (C) 2008 by Maurus Cuelenaere
11*
12* Creative Zen Vision:M interrupt based PIC driver
13*
14* All files in this archive are subject to the GNU General Public License.
15* See the file COPYING in the source tree root for full license agreement.
16*
17* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18* KIND, either express or implied.
19*
20****************************************************************************/
21
22#include "config.h"
23#include "system.h"
24#include "kernel.h"
25#include "button-target.h"
26#include "i2c-dm320.h"
27
28
29#include "lcd-target.h"
30#include "lcd.h"
31#include "sprintf.h"
32#include "font.h"
33
34#ifndef ZEN_VISION
35/* Creative Zen Vision:M */
36#define BTN_LEFT 0x5F00
37#define BTN_RIGHT 0x4F00
38#define BTN_BACK 0xBF00
39#define BTN_CUSTOM 0x8F00
40#define BTN_PLAY 0x2F00
41#define BTN_POWER 0x0F00
42#define BTN_MENU 0x9F00
43#define BTN_HOLD 0x9F06
44#define BTN_UNHOLD 0xAF06
45
46#define BTN_REL 1
47
48#define BTN_TOUCHPAD_PRESS 0x1F00
49#define BTN_TOUCHPAD_CORNER_DOWN 0xAF00
50#define BTN_TOUCHPAD_CORNER_UP 0x3F00
51
52#define HEADPHONE_PLUGIN_A 0x5707
53#define HEADPHONE_PLUGIN_B 0x5F07
54#define HEADPHONE_UNPLUG_A 0x3707
55#define HEADPHONE_UNPLUG_B 0x3F07
56
57#define DOCK_INSERT 0x6707
58#define DOCK_UNPLUG 0xDF06
59#define DOCK_USB_INSERT 0x2F06
60#define DOCK_USB_UNPLUG 0x3F06
61#define DOCK_POWER_INSERT 0x2707
62#define DOCK_POWER_UNPLUG 0x2F07
63
64#else
65/* Creative Zen Vision */
66#define BTN_LEFT 0xCF00
67#define BTN_RIGHT 0xEF00
68#define BTN_BACK 0xBF00
69#define BTN_CUSTOM 0x0
70#define BTN_PLAY 0x2F00
71#define BTN_POWER 0x0F00
72#define BTN_MENU 0x9F00
73#define BTN_HOLD 0x9F06
74#define BTN_UNHOLD 0xAF06
75/* TODO: other values
76First number is just pressing it, second is when you release it or keep it pressed a bit longer
77On/Off = 0F00 && 0F01
78Hold = 9F06 && AF06
79Volume Up = 6F00 && 6F01
80Vol Down = 7F00 && 7F01
81Up = DF00 && DF01
82Right = EF00 && EF01
83Down = FF00 && FF01
84Left = CF00 && CF01
85Back = BF00 && BF01
86Menu = 9F00 && Etcetera
87Ok = 1F00
88Play = 2F00
89Next = 4F00
90Prev = 5F00
91
92USB = 2F06
93USB ouot = 3F06
94Headphones= AF06
95Hdphns out= BF06
96Charger = 4F06 -> 9F05
97Chgrout = 5F06 -> 8F05
98AV in = 8F06
99AV out = 9F06 */
100
101#define BTN_REL 1
102
103#define BTN_TOUCHPAD_PRESS 0x8F00
104#define BTN_TOUCHPAD_LONG_PRESS 0x0F00
105#define BTN_TOUCHPAD_CORNER_DOWN 0xD700
106#define BTN_TOUCHPAD_CORNER_LONG_DOWN 0x5700
107#define BTN_TOUCHPAD_CORNER_UP 0x9F00
108#define BTN_TOUCHPAD_CORNER_LONG_UP 0x1F00
109
110#define HEADPHONE_PLUGIN_A 0xAF06
111#define HEADPHONE_PLUGIN_B 0xAF06
112#define HEADPHONE_UNPLUG_A 0xBF06
113#define HEADPHONE_UNPLUG_B 0xBF06
114
115#define DOCK_INSERT 0x0
116#define DOCK_UNPLUG 0x0
117#define DOCK_USB_INSERT 0x2F06
118#define DOCK_USB_UNPLUG_A 0x3F06
119#define DOCK_USB_UNPLUG_B 0x3F06
120#define DOCK_POWER_INSERT 0x4F06
121#define DOCK_POWER_UNPLUG 0x5F06
122#define DOCK_AV_INSERT 0x8F06
123#define DOCK_AV_UNPLUG 0x9F06
124#endif
125
126#define PIC_ADR 0x07
127
128#define MASK_TV_OUT(x) ((x >> 14) & 1)
129#define MASK_xx1(x) ((x >> 9) & 3)
130#define MASK_xx2(x) ((x >> 4) & 1)
131#define MASK_xx3(x) ((x >> 5) & 1)
132#define MASK_xx4(x) ((x >> 6) & 1)
133#define MASK_xx5(x) ((x >> 13) & 1)
134#define MASK_xx6(x) ((x >> 12) & 1)
135#define MASK_xx7(x) ((x >> 11) & 1)
136
137#define NONBUTTON_HEADPHONE (1 << 0)
138#define NONBUTTON_DOCK (1 << 1)
139#define NONBUTTON_USB (1 << 2)
140#define NONBUTTON_POWER (1 << 3)
141#define NONBUTTON_VIDEOUT (1 << 4)
142
143static unsigned int btn;
144static bool hold_switch;
145static unsigned char nonbtn;
146static unsigned int pic_init_value;
147static unsigned int pic_init2_value;
148static unsigned int last_btn;
149static long last_tick;
150static int tick_diff;
151
152#define TICK_MIN 0x33
153#define TICK_MAX 0x34
154
155/* Taken from scramble.c and modified */
156static inline unsigned short le2short(unsigned char* buf)
157{
158 return (unsigned short)((buf[1] << 8) | buf[0]);
159}
160
161#define map_button(BtN,BtN2) case BtN: \
162 btn ^= BtN2; \
163 btn &= BtN2; \
164 break; \
165 case BtN ^ BTN_REL: \
166 btn ^= BtN2; \
167 btn &= BtN2; \
168 break;
169
170#ifdef BUTTON_DEBUG
171static bool sw = false;
172#endif
173
174void GIO0(void)
175{
176 unsigned char msg[4];
177 i2c_read(PIC_ADR, msg, sizeof(msg));
178 tick_diff = current_tick - last_tick;
179 last_tick = current_tick;
180 unsigned short btn_press = le2short(msg);
181 if(tick_diff >= TICK_MIN && tick_diff <= TICK_MAX)
182 {
183 /* Ignore this, as it is a hold event */
184 IO_INTC_IRQ1 = INTR_IRQ1_EXT0;
185 return;
186 }
187 last_btn = btn_press;
188 switch(btn_press)
189 {
190 map_button(BTN_LEFT, BUTTON_LEFT);
191 map_button(BTN_RIGHT, BUTTON_RIGHT);
192 map_button(BTN_BACK, BUTTON_BACK);
193 map_button(BTN_CUSTOM, BUTTON_CUSTOM);
194 map_button(BTN_MENU, BUTTON_MENU);
195 map_button(BTN_PLAY, BUTTON_PLAY);
196 map_button(BTN_POWER, BUTTON_POWER);
197 map_button(BTN_TOUCHPAD_PRESS, BUTTON_SELECT);
198 map_button(BTN_TOUCHPAD_CORNER_DOWN, BUTTON_DOWN);
199 map_button(BTN_TOUCHPAD_CORNER_UP, BUTTON_UP);
200 case BTN_HOLD:
201 hold_switch = true;
202 break;
203 case BTN_UNHOLD:
204 hold_switch = false;
205 break;
206 case HEADPHONE_PLUGIN_A:
207 case HEADPHONE_PLUGIN_B:
208 nonbtn |= NONBUTTON_HEADPHONE;
209 break;
210 case HEADPHONE_UNPLUG_A:
211 case HEADPHONE_UNPLUG_B:
212 nonbtn &= ~NONBUTTON_HEADPHONE;
213 break;
214 case DOCK_INSERT:
215 nonbtn |= NONBUTTON_DOCK;
216 break;
217 case DOCK_UNPLUG:
218 nonbtn &= ~(NONBUTTON_DOCK | NONBUTTON_USB | NONBUTTON_POWER);
219 break;
220 case DOCK_USB_INSERT:
221 nonbtn |= NONBUTTON_USB;
222 break;
223 case DOCK_USB_UNPLUG:
224 nonbtn &= ~NONBUTTON_USB;
225 break;
226 case DOCK_POWER_INSERT:
227 nonbtn |= NONBUTTON_POWER;
228 break;
229 case DOCK_POWER_UNPLUG:
230 nonbtn &= ~NONBUTTON_POWER;
231 break;
232 }
233#ifdef BUTTON_DEBUG
234 unsigned char weergvn[10];
235#ifdef BOOTLOADER
236 lcd_set_foreground((sw ? LCD_RGBPACK(255,0,0) : LCD_RGBPACK(0,255,0) ));
237#endif
238 snprintf(weergvn, sizeof(char)*10, "%x", (unsigned int)((msg[3] << 24) | (msg[2] << 16) | (msg[1] << 8) | msg[0]));
239 lcd_putsxy(LCD_WIDTH-SYSFONT_WIDTH*10, LCD_HEIGHT-SYSFONT_HEIGHT*10, weergvn);
240 snprintf(weergvn, sizeof(char)*10, "%x", btn);
241 lcd_putsxy(LCD_WIDTH-SYSFONT_WIDTH*10, LCD_HEIGHT-SYSFONT_HEIGHT*7, weergvn);
242#ifdef BOOTLOADER
243 lcd_set_foreground(LCD_BLACK);
244#endif
245 lcd_update();
246 sw = !sw;
247#endif
248 /* Mask GIO0 interrupt */
249 IO_INTC_IRQ1 = INTR_IRQ1_EXT0;
250}
251
252void send_command_to_pic(unsigned char in, unsigned char* out, unsigned int length)
253{
254 /* Disable GIO0 interrupt */
255 IO_INTC_EINT1 &= ~INTR_EINT1_EXT0;
256 /* Clear EXT0 interrupt */
257 IO_INTC_IRQ1 = INTR_IRQ1_EXT0;
258 /* Write command to I²C */
259 restart:
260 i2c_write(PIC_ADR, &in, 1);
261 /* Wait for PIC */
262 int i = 0;
263 while(!(IO_INTC_IRQ1 & INTR_IRQ1_EXT0))
264 {
265 sleep(0);
266 i++;
267 if(i > 50)
268 goto restart;
269 }
270 /* Read return from I²C */
271 i2c_read(PIC_ADR, out, length);
272 /* Re-enable GIO0 interrupt */
273 IO_INTC_EINT1 |= INTR_EINT1_EXT0;
274}
275
276bool headphones_inserted(void)
277{
278 return (bool)(nonbtn & NONBUTTON_HEADPHONE);
279}
280
281void button_init_device(void)
282{
283 /* TODO: I suppose GIO0 has to be set to input and enable interrupts on it? */
284 /* Enable GIO0 interrupt */
285 IO_INTC_EINT1 |= INTR_EINT1_EXT0;
286 btn = nonbtn = pic_init_value = pic_init2_value = last_btn = hold_switch = 0;
287 /* Initialize PIC */
288 send_command_to_pic(1, &pic_init_value, sizeof(pic_init_value));
289 send_command_to_pic(2, &pic_init2_value, sizeof(pic_init2_value));
290}
291
292int get_debug_info(int choice)
293{
294 switch(choice)
295 {
296 case 1:
297 return pic_init_value;
298 case 2:
299 return pic_init2_value;
300 case 3:
301 return last_btn;
302 case 4:
303 return nonbtn;
304 case 5:
305 return tick_diff;
306 }
307 return -1;
308}
309
310int button_read_device(void)
311{
312 return btn;
313}
314
315bool button_hold(void)
316{
317 return hold_switch;
318}
319
320bool button_usb_connected(void)
321{
322 return (bool)(nonbtn & NONBUTTON_USB);
323}
diff --git a/firmware/target/arm/tms320dm320/creative-zvm/power-creativezvm.c b/firmware/target/arm/tms320dm320/creative-zvm/power-creativezvm.c
new file mode 100644
index 0000000000..5a72deced9
--- /dev/null
+++ b/firmware/target/arm/tms320dm320/creative-zvm/power-creativezvm.c
@@ -0,0 +1,68 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: power-mr500.c 15599 2007-11-12 18:49:53Z amiconn $
9 *
10 * Copyright (C) 2007 by Karl Kurbjun
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
20#include "config.h"
21#include "cpu.h"
22#include <stdbool.h>
23#include "kernel.h"
24#include "system.h"
25#include "power.h"
26#include "backlight.h"
27#include "backlight-target.h"
28
29#ifndef SIMULATOR
30
31void power_init(void)
32{
33 /* Initialize IDE power pin */
34 /* set ATA power on and output */
35 /* Charger detect */
36}
37
38bool charger_inserted(void)
39{
40 return false;
41}
42
43/* Returns true if the unit is charging the batteries. */
44bool charging_state(void) {
45 return false;
46}
47
48void power_off(void)
49{
50}
51
52#else /* SIMULATOR */
53
54bool charger_inserted(void)
55{
56 return false;
57}
58
59void charger_enable(bool on)
60{
61 (void)on;
62}
63
64void power_off(void)
65{
66}
67
68#endif /* SIMULATOR */
diff --git a/firmware/target/arm/tms320dm320/creative-zvm/powermgmt-creativezvm.c b/firmware/target/arm/tms320dm320/creative-zvm/powermgmt-creativezvm.c
new file mode 100644
index 0000000000..6e8ea7cae5
--- /dev/null
+++ b/firmware/target/arm/tms320dm320/creative-zvm/powermgmt-creativezvm.c
@@ -0,0 +1,57 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2007 by Karl Kurbjun
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
20#include "config.h"
21#include "adc.h"
22#include "powermgmt.h"
23#include "kernel.h"
24
25/* THIS CONTAINS CURRENTLY DUMMY CODE! */
26
27unsigned short current_voltage = 3910;
28const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] =
29{
30 0
31};
32
33const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] =
34{
35 0
36};
37
38/* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */
39const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] =
40{
41 { 100, 300, 400, 500, 600, 700, 800, 900, 1000, 1200, 1320 },
42};
43
44/* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */
45const unsigned short percent_to_volt_charge[11] =
46{
47 100, 300, 400, 500, 600, 700, 800, 900, 1000, 1200, 1320,
48};
49void read_battery_inputs(void)
50{
51}
52
53/* Returns battery voltage from ADC [millivolts] */
54unsigned int battery_adc_voltage(void)
55{
56 return current_voltage;
57}
diff --git a/firmware/target/arm/tms320dm320/creative-zvm/usb-creativezvm.c b/firmware/target/arm/tms320dm320/creative-zvm/usb-creativezvm.c
new file mode 100644
index 0000000000..6bbd08c135
--- /dev/null
+++ b/firmware/target/arm/tms320dm320/creative-zvm/usb-creativezvm.c
@@ -0,0 +1,65 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2008 by Maurus Cuelenaere
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
20#include "config.h"
21#include "system.h"
22#include "kernel.h"
23#include "usb.h"
24#include "usb-target.h"
25#include "usb_drv.h"
26#include "usb_core.h"
27#include "isp1583.h"
28
29#define printf
30
31bool usb_drv_connected(void)
32{
33 return button_usb_connected();
34}
35
36int usb_detect(void)
37{
38 if(button_usb_connected())
39 return USB_INSERTED;
40 else
41 return USB_EXTRACTED;
42}
43
44void usb_init_device(void)
45{
46 return;
47}
48
49void usb_enable(bool on)
50{
51 if(on)
52 usb_core_init();
53 else
54 usb_core_exit();
55}
56
57void GIO7(void)
58{
59#ifdef DEBUG
60 //printf("GIO7 interrupt... [%d]", current_tick);
61#endif
62 usb_drv_int();
63
64 IO_INTC_IRQ1 = INTR_IRQ1_EXT7;
65}
diff --git a/firmware/target/arm/tms320dm320/creative-zvm/usb-target.h b/firmware/target/arm/tms320dm320/creative-zvm/usb-target.h
new file mode 100644
index 0000000000..4e3303911c
--- /dev/null
+++ b/firmware/target/arm/tms320dm320/creative-zvm/usb-target.h
@@ -0,0 +1,76 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2008 by Maurus Cuelenaere
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
20#ifndef USB_TARGET_H
21#define USB_TARGET_H
22
23#include "dm320.h"
24
25#define ISP1583_IOBASE 0x60FFC000
26#define ISP1583_H_OVERRIDE
27
28#define ISP1583_INIT_ADDRESS (*((volatile unsigned char*)(ISP1583_IOBASE+0x0))) //char
29#define ISP1583_INIT_MODE (*((volatile unsigned short*)(ISP1583_IOBASE+0xC*2)))
30#define ISP1583_INIT_INTCONF (*((volatile unsigned char*)(ISP1583_IOBASE+0x10*2))) //char
31#define ISP1583_INIT_OTG (*((volatile unsigned char*)(ISP1583_IOBASE+0x12*2))) //char
32#define ISP1583_INIT_INTEN_A (*((volatile unsigned short*)(ISP1583_IOBASE+0x14*2)))
33#define ISP1583_INIT_INTEN_B (*((volatile unsigned short*)(ISP1583_IOBASE+0x14*2+4)))
34#define ISP1583_INIT_INTEN_READ (unsigned long)( (ISP1583_INIT_INTEN_A & 0xFFFF) | ((ISP1583_INIT_INTEN_B & 0xFFFF) << 16) )
35/* Data flow registers */
36#define ISP1583_DFLOW_EPINDEX (*((volatile unsigned char*)(ISP1583_IOBASE+0xC2*2))) //char
37#define ISP1583_DFLOW_CTRLFUN (*((volatile unsigned char*)(ISP1583_IOBASE+0x28*2))) //char
38#define ISP1583_DFLOW_DATA (*((volatile unsigned short*)(ISP1583_IOBASE+0x20*2)))
39#define ISP1583_DFLOW_BUFLEN (*((volatile unsigned short*)(ISP1583_IOBASE+0x1C*2)))
40#define ISP1583_DFLOW_BUFSTAT (*((volatile unsigned char*)(ISP1583_IOBASE+0x1E*2))) //char
41#define ISP1583_DFLOW_MAXPKSZ (*((volatile unsigned short*)(ISP1583_IOBASE+0x04*2)))
42#define ISP1583_DFLOW_EPTYPE (*((volatile unsigned short*)(ISP1583_IOBASE+0x08*2)))
43/* DMA registers */
44#define ISP1583_DMA_ENDPOINT (*((volatile unsigned char*)(ISP1583_IOBASE+0x58*2)))
45/* General registers */
46#define ISP1583_GEN_INT_A (*((volatile unsigned short*)(ISP1583_IOBASE+0x18*2)))
47#define ISP1583_GEN_INT_B (*((volatile unsigned short*)(ISP1583_IOBASE+0x18*2+4)))
48#define ISP1583_GEN_INT_READ (unsigned long)( (ISP1583_GEN_INT_A & 0xFFFF) | ((ISP1583_GEN_INT_B & 0xFFFF) << 16))
49#define ISP1583_GEN_CHIPID_A (*((volatile unsigned short*)(ISP1583_IOBASE+0x70*2)))
50#define ISP1583_GEN_CHIPID_B (*((volatile unsigned char*)(ISP1583_IOBASE+0x70*2+4))) //char
51#define ISP1583_GEN_CHIPID (unsigned long)( (ISP1583_GEN_CHIPID_A & 0xFFFF) | ((ISP1583_GEN_CHIPID_B & 0xFFFF) << 16) )
52#define ISP1583_GEN_FRAMEN0 (*((volatile unsigned short*)(ISP1583_IOBASE+0x74*2)))
53#define ISP1583_GEN_SCRATCH (*((volatile unsigned short*)(ISP1583_IOBASE+0x78*2)))
54#define ISP1583_GEN_UNLCKDEV (*((volatile unsigned short*)(ISP1583_IOBASE+0x7C*2)))
55#define ISP1583_GEN_TSTMOD (*((volatile unsigned char*)(ISP1583_IOBASE+0x84*2))) //char
56
57#define EN_INT_CPU_TARGET IO_INTC_EINT1 |= INTR_EINT1_EXT7
58#define DIS_INT_CPU_TARGET IO_INTC_EINT1 &= ~INTR_EINT1_EXT7
59#define INT_CONF_TARGET 0
60//#define INT_CONF_TARGET 2
61#define set_int_value(a,b,value) a = value & 0xFFFF; \
62 b = value >> 16;
63
64
65#define ZVM_SPECIFIC asm volatile( \
66 "LDR R12, =0x50FFC000\n" \
67 "LDRH R12, [R12]\n" \
68 : : : "r12")
69//#define ZVM_SPECIFIC
70
71#include "kernel.h"
72int usb_detect(void);
73void usb_init_device(void);
74bool usb_drv_connected(void);
75
76#endif
diff --git a/firmware/target/arm/tms320dm320/crt0.S b/firmware/target/arm/tms320dm320/crt0.S
index 461afdd91a..8c3d36e086 100755
--- a/firmware/target/arm/tms320dm320/crt0.S
+++ b/firmware/target/arm/tms320dm320/crt0.S
@@ -153,7 +153,7 @@ start:
153 msr cpsr_c, #0xd3 153 msr cpsr_c, #0xd3
154 ldr sp, =stackend 154 ldr sp, =stackend
155 155
156#ifdef BOOTLOADER 156#if defined(BOOTLOADER) && !defined(CREATIVE_ZVM)
157 /* get the high part of our execute address */ 157 /* get the high part of our execute address */
158 ldr r2, =0xffffff00 158 ldr r2, =0xffffff00
159 and r4, pc, r2 159 and r4, pc, r2
diff --git a/firmware/target/arm/tms320dm320/debug-dm320.c b/firmware/target/arm/tms320dm320/debug-dm320.c
index 1a987b4dda..abfb5b09bc 100755
--- a/firmware/target/arm/tms320dm320/debug-dm320.c
+++ b/firmware/target/arm/tms320dm320/debug-dm320.c
@@ -27,18 +27,24 @@
27#include "sprintf.h" 27#include "sprintf.h"
28#include "font.h" 28#include "font.h"
29#include "debug-target.h" 29#include "debug-target.h"
30#include "lcd-target.h"
30 31
31bool __dbg_ports(void) 32bool __dbg_ports(void)
32{ 33{
33 return false; 34 return false;
34} 35}
35 36
37#ifndef CREATIVE_ZVM
36extern char r_buffer[5]; 38extern char r_buffer[5];
37extern int r_button; 39extern int r_button;
40#endif
38bool __dbg_hw_info(void) 41bool __dbg_hw_info(void)
39{ 42{
40 int line = 0, button, oldline; 43 int line = 0, oldline;
44 int button;
45#ifndef CREATIVE_ZVM
41 int *address=0x0; 46 int *address=0x0;
47#endif
42 bool done=false; 48 bool done=false;
43 char buf[100]; 49 char buf[100];
44 50
@@ -50,6 +56,7 @@ bool __dbg_hw_info(void)
50 lcd_puts(0, line++, "[Hardware info]"); 56 lcd_puts(0, line++, "[Hardware info]");
51 57
52 lcd_puts(0, line++, "Clock info:"); 58 lcd_puts(0, line++, "Clock info:");
59#if LCD_WIDTH > 320
53 snprintf(buf, sizeof(buf), "IO_CLK_PLLA: 0x%04x IO_CLK_PLLB: 0x%04x IO_CLK_SEL0: 0x%04x IO_CLK_SEL1: 0x%04x", 60 snprintf(buf, sizeof(buf), "IO_CLK_PLLA: 0x%04x IO_CLK_PLLB: 0x%04x IO_CLK_SEL0: 0x%04x IO_CLK_SEL1: 0x%04x",
54 IO_CLK_PLLA, IO_CLK_PLLB, IO_CLK_SEL0, IO_CLK_SEL1); lcd_puts(0, line++, buf); 61 IO_CLK_PLLA, IO_CLK_PLLB, IO_CLK_SEL0, IO_CLK_SEL1); lcd_puts(0, line++, buf);
55 snprintf(buf, sizeof(buf), "IO_CLK_SEL2: 0x%04x IO_CLK_DIV0: 0x%04x IO_CLK_DIV1: 0x%04x IO_CLK_DIV2: 0x%04x", 62 snprintf(buf, sizeof(buf), "IO_CLK_SEL2: 0x%04x IO_CLK_DIV0: 0x%04x IO_CLK_DIV1: 0x%04x IO_CLK_DIV2: 0x%04x",
@@ -58,12 +65,45 @@ bool __dbg_hw_info(void)
58 IO_CLK_DIV3, IO_CLK_DIV4, IO_CLK_BYP, IO_CLK_INV); lcd_puts(0, line++, buf); 65 IO_CLK_DIV3, IO_CLK_DIV4, IO_CLK_BYP, IO_CLK_INV); lcd_puts(0, line++, buf);
59 snprintf(buf, sizeof(buf), "IO_CLK_MOD0: 0x%04x IO_CLK_MOD1: 0x%04x IO_CLK_MOD2: 0x%04x IO_CLK_LPCTL0: 0x%04x", 66 snprintf(buf, sizeof(buf), "IO_CLK_MOD0: 0x%04x IO_CLK_MOD1: 0x%04x IO_CLK_MOD2: 0x%04x IO_CLK_LPCTL0: 0x%04x",
60 IO_CLK_MOD0, IO_CLK_MOD1, IO_CLK_MOD2, IO_CLK_LPCTL0); lcd_puts(0, line++, buf); 67 IO_CLK_MOD0, IO_CLK_MOD1, IO_CLK_MOD2, IO_CLK_LPCTL0); lcd_puts(0, line++, buf);
68#else
69 snprintf(buf, sizeof(buf), " IO_CLK_PLLA: 0x%04x IO_CLK_PLLB: 0x%04x", IO_CLK_PLLA, IO_CLK_PLLB);
70 lcd_puts(0, line++, buf);
71 snprintf(buf, sizeof(buf), " IO_CLK_SEL0: 0x%04x IO_CLK_SEL1: 0x%04x", IO_CLK_SEL0, IO_CLK_SEL1);
72 lcd_puts(0, line++, buf);
73 snprintf(buf, sizeof(buf), " IO_CLK_SEL2: 0x%04x IO_CLK_DIV0: 0x%04x", IO_CLK_SEL2, IO_CLK_DIV0);
74 lcd_puts(0, line++, buf);
75 snprintf(buf, sizeof(buf), " IO_CLK_DIV1: 0x%04x IO_CLK_DIV2: 0x%04x", IO_CLK_DIV1, IO_CLK_DIV2);
76 lcd_puts(0, line++, buf);
77 snprintf(buf, sizeof(buf), " IO_CLK_DIV3: 0x%04x IO_CLK_DIV4: 0x%04x", IO_CLK_DIV3, IO_CLK_DIV4);
78 lcd_puts(0, line++, buf);
79 snprintf(buf, sizeof(buf), " IO_CLK_BYP : 0x%04x IO_CLK_INV : 0x%04x", IO_CLK_BYP, IO_CLK_INV);
80 lcd_puts(0, line++, buf);
81 snprintf(buf, sizeof(buf), " IO_CLK_MOD0: 0x%04x IO_CLK_MOD1: 0x%04x ", IO_CLK_MOD0, IO_CLK_MOD1);
82 lcd_puts(0, line++, buf);
83 snprintf(buf, sizeof(buf), " IO_CLK_MOD2: 0x%04x IO_CLK_LPCTL0: 0x%04x ", IO_CLK_MOD2, IO_CLK_LPCTL0);
84 lcd_puts(0, line++, buf);
85#endif
86
87 lcd_puts(0, line++, "Board revision:");
88 switch (IO_BUSC_REVR) {
89 case 0x0010:
90 lcd_puts(0, line++, " DM320 Rev. A");
91 break;
92 case 0x0011:
93 lcd_puts(0, line++, " DM320 Rev. B/C");
94 break;
95 default:
96 lcd_puts(0, line++, " Unknown DM320 Chip ID");
97 }
61 98
99#ifndef CREATIVE_ZVM
62 line++; 100 line++;
101#endif
63 oldline=line; 102 oldline=line;
64 while(!done) 103 while(!done)
65 { 104 {
66 line = oldline; 105 line = oldline;
106#ifndef CREATIVE_ZVM
67 button = button_get(false); 107 button = button_get(false);
68 button&=~BUTTON_REPEAT; 108 button&=~BUTTON_REPEAT;
69 if (button == BUTTON_POWER) 109 if (button == BUTTON_POWER)
@@ -81,14 +121,42 @@ bool __dbg_hw_info(void)
81 r_buffer[0], r_buffer[1], r_buffer[2], r_buffer[3],r_buffer[4] ); lcd_puts(0, line++, buf); 121 r_buffer[0], r_buffer[1], r_buffer[2], r_buffer[3],r_buffer[4] ); lcd_puts(0, line++, buf);
82 snprintf(buf, sizeof(buf), "Button: 0x%08x, HWread: 0x%08x", 122 snprintf(buf, sizeof(buf), "Button: 0x%08x, HWread: 0x%08x",
83 (unsigned int)button, r_button); lcd_puts(0, line++, buf); 123 (unsigned int)button, r_button); lcd_puts(0, line++, buf);
124#else
125 button = button_get(false);
126 if(button & BUTTON_POWER)
127 done = true;
128 else if(button & BUTTON_LEFT)
129 lcd_set_direct_fb(false);
130 else if(button & BUTTON_RIGHT)
131 lcd_set_direct_fb(true);
132
133 lcd_puts(0, line++, "PIC info:");
134 snprintf(buf, sizeof(buf), " Init value 1: 0x%04x", get_debug_info(1));
135 lcd_puts(0, line++, buf);
136 snprintf(buf, sizeof(buf), " Init value 2: 0x%04x", get_debug_info(2));
137 lcd_puts(0, line++, buf);
138 snprintf(buf, sizeof(buf), " Last button value: 0x%04x Raw value: 0x%04x", get_debug_info(3), button_read_device());
139 lcd_puts(0, line++, buf);
140 snprintf(buf, sizeof(buf), " Last button at: 0x%04x", get_debug_info(5));
141 lcd_puts(0, line++, buf);
142 snprintf(buf, sizeof(buf), " Dock values: 0x%04x", get_debug_info(4));
143 lcd_puts(0, line++, buf);
144 lcd_puts(0, line++, "LCD info:");
145 snprintf(buf, sizeof(buf), " LCD direct FB access? %s", (lcd_get_direct_fb() ? "yes" : "no"));
146 lcd_puts(0, line++, buf);
147 line++;
148#endif
149 lcd_puts(0, line++, "[Rockbox info]");
84 snprintf(buf, sizeof(buf), "current tick: %08x Seconds running: %08d", 150 snprintf(buf, sizeof(buf), "current tick: %08x Seconds running: %08d",
85 (unsigned int)current_tick, (unsigned int)current_tick/100); lcd_puts(0, line++, buf); 151 (unsigned int)current_tick, (unsigned int)current_tick/100); lcd_puts(0, line++, buf);
152#ifndef CREATIVE_ZVM
86 snprintf(buf, sizeof(buf), "Address: 0x%08x Data: 0x%08x", 153 snprintf(buf, sizeof(buf), "Address: 0x%08x Data: 0x%08x",
87 (unsigned int)address, *address); lcd_puts(0, line++, buf); 154 (unsigned int)address, *address); lcd_puts(0, line++, buf);
88 snprintf(buf, sizeof(buf), "Address: 0x%08x Data: 0x%08x", 155 snprintf(buf, sizeof(buf), "Address: 0x%08x Data: 0x%08x",
89 (unsigned int)(address+1), *(address+1)); lcd_puts(0, line++, buf); 156 (unsigned int)(address+1), *(address+1)); lcd_puts(0, line++, buf);
90 snprintf(buf, sizeof(buf), "Address: 0x%08x Data: 0x%08x", 157 snprintf(buf, sizeof(buf), "Address: 0x%08x Data: 0x%08x",
91 (unsigned int)(address+2), *(address+2)); lcd_puts(0, line++, buf); 158 (unsigned int)(address+2), *(address+2)); lcd_puts(0, line++, buf);
159#endif
92 160
93 lcd_update(); 161 lcd_update();
94 } 162 }
diff --git a/firmware/target/arm/tms320dm320/kernel-dm320.c b/firmware/target/arm/tms320dm320/kernel-dm320.c
index 6608aea096..2b2e783c3f 100644
--- a/firmware/target/arm/tms320dm320/kernel-dm320.c
+++ b/firmware/target/arm/tms320dm320/kernel-dm320.c
@@ -27,6 +27,10 @@ extern void (*tick_funcs[MAX_NUM_TICK_TASKS])(void);
27 27
28void tick_start(unsigned int interval_in_ms) 28void tick_start(unsigned int interval_in_ms)
29{ 29{
30/* TODO: set up TIMER1 clock settings
31 IO_CLK_MOD2 &= ~CLK_MOD2_TMR1; //disable TIMER1 clock
32 IO_CLK_SEL0 |= (1 << 2); //set TIMER1 clock to PLLIN*/
33 IO_CLK_MOD2 |= CLK_MOD2_TMR1; //enable TIMER1 clock!!!!!!!!!
30 IO_TIMER1_TMMD = CONFIG_TIMER1_TMMD_STOP; 34 IO_TIMER1_TMMD = CONFIG_TIMER1_TMMD_STOP;
31 35
32 /* Setup the Prescalar (Divide by 10) 36 /* Setup the Prescalar (Divide by 10)
@@ -35,13 +39,13 @@ void tick_start(unsigned int interval_in_ms)
35 IO_TIMER1_TMPRSCL = 0x0009; 39 IO_TIMER1_TMPRSCL = 0x0009;
36 40
37 /* Setup the Divisor */ 41 /* Setup the Divisor */
38 IO_TIMER1_TMDIV = (TIMER_FREQ / (10*1000))*interval_in_ms; 42 IO_TIMER1_TMDIV = (TIMER_FREQ / (10*1000))*interval_in_ms - 1;
39 43
40 /* Turn Timer1 to Free Run mode */ 44 /* Turn Timer1 to Free Run mode */
41 IO_TIMER1_TMMD = CONFIG_TIMER1_TMMD_FREE_RUN; 45 IO_TIMER1_TMMD = CONFIG_TIMER1_TMMD_FREE_RUN;
42 46
43 /* Enable the interrupt */ 47 /* Enable the interrupt */
44 IO_INTC_EINT0 |= 1<<IRQ_TIMER1; 48 IO_INTC_EINT0 |= INTR_EINT0_TMR1;
45} 49}
46 50
47void TIMER1(void) 51void TIMER1(void)
@@ -56,8 +60,7 @@ void TIMER1(void)
56 tick_funcs[i](); 60 tick_funcs[i]();
57 } 61 }
58 } 62 }
59
60 current_tick++; 63 current_tick++;
61 64
62 IO_INTC_IRQ0 = 1<<IRQ_TIMER1; 65 IO_INTC_IRQ0 = INTR_IRQ0_TMR1;
63} 66}
diff --git a/firmware/target/arm/tms320dm320/spi-dm320.c b/firmware/target/arm/tms320dm320/spi-dm320.c
index d8f338f592..a7b4fc678e 100644
--- a/firmware/target/arm/tms320dm320/spi-dm320.c
+++ b/firmware/target/arm/tms320dm320/spi-dm320.c
@@ -31,6 +31,7 @@
31#define GIO_TS_ENABLE (1<<2) 31#define GIO_TS_ENABLE (1<<2)
32#define GIO_RTC_ENABLE (1<<12) 32#define GIO_RTC_ENABLE (1<<12)
33#define GIO_BL_ENABLE (1<<13) 33#define GIO_BL_ENABLE (1<<13)
34#define GIO_LCD_ENABLE (1<<5)
34 35
35struct mutex spi_mtx; 36struct mutex spi_mtx;
36 37
@@ -39,14 +40,21 @@ struct SPI_info {
39 volatile unsigned short *clrreg; 40 volatile unsigned short *clrreg;
40 int bit; 41 int bit;
41}; 42};
42#define reg(a) ((volatile unsigned short *)(PHY_IO_BASE+a)) 43
43struct SPI_info spi_targets[] = 44struct SPI_info spi_targets[] =
44{ 45{
46#ifndef CREATIVE_ZVM
45 [SPI_target_TSC2100] = { &IO_GIO_BITCLR1, &IO_GIO_BITSET1, GIO_TS_ENABLE }, 47 [SPI_target_TSC2100] = { &IO_GIO_BITCLR1, &IO_GIO_BITSET1, GIO_TS_ENABLE },
46 [SPI_target_RX5X348AB] = { &IO_GIO_BITSET0, &IO_GIO_BITCLR0, GIO_RTC_ENABLE }, 48 [SPI_target_RX5X348AB] = { &IO_GIO_BITSET0, &IO_GIO_BITCLR0, GIO_RTC_ENABLE},
47 [SPI_target_BACKLIGHT] = { &IO_GIO_BITCLR1, &IO_GIO_BITSET1, GIO_BL_ENABLE }, 49 [SPI_target_BACKLIGHT] = { &IO_GIO_BITCLR1, &IO_GIO_BITSET1, GIO_BL_ENABLE },
50#else
51 [SPI_target_LTV250QV] = { &IO_GIO_BITCLR2, &IO_GIO_BITSET2, GIO_LCD_ENABLE},
52#endif
48}; 53};
49 54
55#define IO_SERIAL0_XMIT (0x100)
56#define IO_SERIAL0_MODE_SCLK (1 << 10)
57
50static void spi_disable_all_targets(void) 58static void spi_disable_all_targets(void)
51{ 59{
52 int i; 60 int i;
@@ -70,7 +78,7 @@ int spi_block_transfer(enum SPI_target target,
70 IO_SERIAL0_TX_DATA = *tx_bytes++; 78 IO_SERIAL0_TX_DATA = *tx_bytes++;
71 79
72 /* Wait until transfer finished */ 80 /* Wait until transfer finished */
73 while (IO_SERIAL0_RX_DATA & 0x100); 81 while (IO_SERIAL0_RX_DATA & IO_SERIAL0_XMIT);
74 } 82 }
75 83
76 while (rx_size--) 84 while (rx_size--)
@@ -80,7 +88,7 @@ int spi_block_transfer(enum SPI_target target,
80 88
81 /* Wait until transfer finished */ 89 /* Wait until transfer finished */
82 unsigned short data; 90 unsigned short data;
83 while ((data = IO_SERIAL0_RX_DATA) & 0x100); 91 while ((data = IO_SERIAL0_RX_DATA) & IO_SERIAL0_XMIT);
84 92
85 *rx_bytes++ = data & 0xff; 93 *rx_bytes++ = data & 0xff;
86 } 94 }
@@ -95,14 +103,15 @@ void spi_init(void)
95{ 103{
96 mutex_init(&spi_mtx); 104 mutex_init(&spi_mtx);
97 /* Set SCLK idle level = 0 */ 105 /* Set SCLK idle level = 0 */
98 IO_SERIAL0_MODE |= 1<<10; 106 IO_SERIAL0_MODE |= IO_SERIAL0_MODE_SCLK;
99 /* Enable TX */ 107 /* Enable TX */
100 IO_SERIAL0_TX_ENABLE = 0x0001; 108 IO_SERIAL0_TX_ENABLE = 0x0001;
101 109#ifndef CREATIVE_ZVM
102 /* Set GIO 18 to output for touch screen slave enable */ 110 /* Set GIO 18 to output for touch screen slave enable */
103 IO_GIO_DIR1 &= ~GIO_TS_ENABLE; 111 IO_GIO_DIR1 &= ~GIO_TS_ENABLE;
104 /* Set GIO 12 to output for rtc slave enable */ 112 /* Set GIO 12 to output for rtc slave enable */
105 IO_GIO_DIR0 &= ~GIO_RTC_ENABLE; 113 IO_GIO_DIR0 &= ~GIO_RTC_ENABLE;
106 114#endif
107 spi_disable_all_targets(); /* make sure only one is ever enabled at a time */ 115 spi_disable_all_targets(); /* make sure only one is ever enabled at a time */
116
108} 117}
diff --git a/firmware/target/arm/tms320dm320/spi-target.h b/firmware/target/arm/tms320dm320/spi-target.h
index fe229d8bda..704867d92b 100644
--- a/firmware/target/arm/tms320dm320/spi-target.h
+++ b/firmware/target/arm/tms320dm320/spi-target.h
@@ -24,9 +24,13 @@
24#include <stdbool.h> 24#include <stdbool.h>
25 25
26enum SPI_target { 26enum SPI_target {
27#ifndef CREATIVE_ZVM
27 SPI_target_TSC2100 = 0, 28 SPI_target_TSC2100 = 0,
28 SPI_target_RX5X348AB, 29 SPI_target_RX5X348AB,
29 SPI_target_BACKLIGHT, 30 SPI_target_BACKLIGHT,
31#else
32 SPI_target_LTV250QV = 0,
33#endif
30 SPI_MAX_TARGETS, 34 SPI_MAX_TARGETS,
31}; 35};
32 36
diff --git a/firmware/target/arm/tms320dm320/system-dm320.c b/firmware/target/arm/tms320dm320/system-dm320.c
index da3b9913a2..c03e05522c 100644
--- a/firmware/target/arm/tms320dm320/system-dm320.c
+++ b/firmware/target/arm/tms320dm320/system-dm320.c
@@ -114,7 +114,12 @@ void irq_handler(void)
114 114
115 asm volatile( "stmfd sp!, {r0-r7, ip, lr} \n" /* Store context */ 115 asm volatile( "stmfd sp!, {r0-r7, ip, lr} \n" /* Store context */
116 "sub sp, sp, #8 \n"); /* Reserve stack */ 116 "sub sp, sp, #8 \n"); /* Reserve stack */
117 irqvector[(IO_INTC_IRQENTRY0>>2)-1](); 117 unsigned short addr = IO_INTC_IRQENTRY0>>2;
118 if(addr != 0)
119 {
120 addr--;
121 irqvector[addr]();
122 }
118 asm volatile( "add sp, sp, #8 \n" /* Cleanup stack */ 123 asm volatile( "add sp, sp, #8 \n" /* Cleanup stack */
119 "ldmfd sp!, {r0-r7, ip, lr} \n" /* Restore context */ 124 "ldmfd sp!, {r0-r7, ip, lr} \n" /* Restore context */
120 "subs pc, lr, #4 \n"); /* Return from FIQ */ 125 "subs pc, lr, #4 \n"); /* Return from FIQ */
@@ -130,18 +135,34 @@ void fiq_handler(void)
130 "sub lr, lr, #4 \r\n" 135 "sub lr, lr, #4 \r\n"
131 "stmfd sp!, {r0-r3, ip, lr} \r\n" 136 "stmfd sp!, {r0-r3, ip, lr} \r\n"
132 "mov r0, #0x00030000 \r\n" 137 "mov r0, #0x00030000 \r\n"
133 "ldr r0, [r0, #0x518] \r\n" 138 "ldr r0, [r0, #0x518] \r\n"
139 "sub r0, r0, #1 \r\n"
134 "ldr r1, =irqvector \r\n" 140 "ldr r1, =irqvector \r\n"
135 "ldr r1, [r1, r0, lsl #2] \r\n" 141 "ldr r1, [r1, r0, lsl #2] \r\n"
136 "mov lr, pc \r\n" 142 "blx r1 \r\n"
137 "bx r1 \r\n"
138 "ldmfd sp!, {r0-r3, ip, pc}^ \r\n" 143 "ldmfd sp!, {r0-r3, ip, pc}^ \r\n"
139 ); 144 );
140} 145}
141 146
142void system_reboot(void) 147void system_reboot(void)
143{ 148{
144 149 /* Code taken from linux/include/asm-arm/arch-itdm320-20/system.h at NeuroSVN */
150 __asm__ __volatile__(
151 "mov ip, #0 \n"
152 "mcr p15, 0, ip, c7, c7, 0 @ invalidate cache \n"
153 "mcr p15, 0, ip, c7, c10,4 @ drain WB \n"
154 "mcr p15, 0, ip, c8, c7, 0 @ flush TLB (v4) \n"
155 "mrc p15, 0, ip, c1, c0, 0 @ get ctrl register\n"
156 "bic ip, ip, #0x000f @ ............wcam \n"
157 "bic ip, ip, #0x2100 @ ..v....s........ \n"
158 "mcr p15, 0, ip, c1, c0, 0 @ ctrl register \n"
159 "mov ip, #0xFF000000 \n"
160 "orr ip, ip, #0xFF0000 @ ip = 0xFFFF0000 \n"
161 "mov pc, ip \n"
162 :
163 :
164 : "cc"
165 );
145} 166}
146 167
147void system_init(void) 168void system_init(void)
@@ -167,16 +188,28 @@ void system_init(void)
167 IO_INTC_FISEL1 = 0; 188 IO_INTC_FISEL1 = 0;
168 IO_INTC_FISEL2 = 0; 189 IO_INTC_FISEL2 = 0;
169 190
191 /* IRQENTRY only reflects enabled interrupts */
192 IO_INTC_RAW = 0;
193
170 IO_INTC_ENTRY_TBA0 = 0; 194 IO_INTC_ENTRY_TBA0 = 0;
171 IO_INTC_ENTRY_TBA1 = 0; 195 IO_INTC_ENTRY_TBA1 = 0;
172 196
173 /* Turn off other timers */ 197 unsigned short i;
198 /* Reset interrupt priorities to default values */
199 for(i = 0; i < 23; i++)
200 DM320_REG(0x0540+i*2) = ( (i*2+1) << 8 ) | i*2 ;//IO_INTC_PRIORITYx
201
202 /* Turn off all timers */
203 IO_TIMER0_TMMD = CONFIG_TIMER0_TMMD_STOP;
204 IO_TIMER1_TMMD = CONFIG_TIMER1_TMMD_STOP;
174 IO_TIMER2_TMMD = CONFIG_TIMER2_TMMD_STOP; 205 IO_TIMER2_TMMD = CONFIG_TIMER2_TMMD_STOP;
175 IO_TIMER3_TMMD = CONFIG_TIMER3_TMMD_STOP; 206 IO_TIMER3_TMMD = CONFIG_TIMER3_TMMD_STOP;
176 207
208#ifndef CREATIVE_ZVM
177 /* set GIO26 (reset pin) to output and low */ 209 /* set GIO26 (reset pin) to output and low */
178 IO_GIO_BITCLR1=(1<<10); 210 IO_GIO_BITCLR1=(1<<10);
179 IO_GIO_DIR1&=~(1<<10); 211 IO_GIO_DIR1&=~(1<<10);
212#endif
180 213
181 uart_init(); 214 uart_init();
182 spi_init(); 215 spi_init();
@@ -186,9 +219,18 @@ void system_init(void)
186 /* Make sure everything is mapped on itself */ 219 /* Make sure everything is mapped on itself */
187 map_section(0, 0, 0x1000, CACHE_NONE); 220 map_section(0, 0, 0x1000, CACHE_NONE);
188 /* Enable caching for RAM */ 221 /* Enable caching for RAM */
189 map_section(0x00900000, 0x00900000, 64, CACHE_ALL); 222 map_section(CONFIG_SDRAM_START, CONFIG_SDRAM_START, MEM, CACHE_ALL);
190 /* enable buffered writing for the framebuffer */ 223 /* enable buffered writing for the framebuffer */
191 map_section((int)FRAME, (int)FRAME, 1, BUFFERED); 224 map_section((int)FRAME, (int)FRAME, 1, BUFFERED);
225#ifdef CREATIVE_ZVM
226 //mimic OF
227 map_section(0x00100000, 0x00100000, 4, CACHE_NONE);
228 map_section(0x04700000, 0x04700000, 2, BUFFERED);
229 map_section(0x40000000, 0x40000000, 16, CACHE_NONE);
230 map_section(0x50000000, 0x50000000, 16, CACHE_NONE);
231 map_section(0x60000000, 0x60000000, 16, CACHE_NONE);
232 map_section(0x80000000, 0x80000000, 1, CACHE_NONE);
233#endif
192 enable_mmu(); 234 enable_mmu();
193} 235}
194 236
diff --git a/firmware/target/arm/tms320dm320/timer-dm320.c b/firmware/target/arm/tms320dm320/timer-dm320.c
index 7895005d46..52b433fac5 100644
--- a/firmware/target/arm/tms320dm320/timer-dm320.c
+++ b/firmware/target/arm/tms320dm320/timer-dm320.c
@@ -24,12 +24,12 @@
24#include "logf.h" 24#include "logf.h"
25 25
26/* GPB0/TOUT0 should already have been configured as output so that pin 26/* GPB0/TOUT0 should already have been configured as output so that pin
27 should not be a functional pin and TIMER0 output unseen there */ 27 should not be a functional pin and TIMER0 output unseen there */
28void TIMER0(void) 28void TIMER0(void)
29{ 29{
30 if (pfn_timer != NULL) 30 if (pfn_timer != NULL)
31 pfn_timer(); 31 pfn_timer();
32 IO_INTC_IRQ0 |= 1<<IRQ_TIMER0; 32 IO_INTC_IRQ0 = INTR_IRQ0_TMR0; //clear TIMER0 interrupt
33} 33}
34 34
35bool __timer_set(long cycles, bool start) 35bool __timer_set(long cycles, bool start)
@@ -40,6 +40,10 @@ bool __timer_set(long cycles, bool start)
40 if(cycles<1) 40 if(cycles<1)
41 return false; 41 return false;
42 42
43 oldlevel = set_irq_level(HIGHEST_IRQ_LEVEL);
44
45 IO_CLK_MOD2 |= CLK_MOD2_TMR0; //enable TIMER0 clock!!!!!!!!!
46
43 IO_TIMER0_TMMD = CONFIG_TIMER0_TMMD_STOP; 47 IO_TIMER0_TMMD = CONFIG_TIMER0_TMMD_STOP;
44 48
45 if (start && pfn_unregister != NULL) 49 if (start && pfn_unregister != NULL)
@@ -67,23 +71,27 @@ bool __timer_set(long cycles, bool start)
67 71
68static void stop_timer(void) 72static void stop_timer(void)
69{ 73{
70 IO_INTC_EINT0 &= ~(1<<IRQ_TIMER0); 74 IO_INTC_EINT0 &= ~INTR_EINT0_TMR0; //disable TIMER0 interrupt
71 75
72 IO_INTC_IRQ0 |= 1<<IRQ_TIMER0; 76 IO_INTC_IRQ0 = INTR_IRQ0_TMR0; //clear TIMER0 interrupt
73 77
74 IO_TIMER0_TMMD = CONFIG_TIMER0_TMMD_STOP; 78 IO_TIMER0_TMMD = CONFIG_TIMER0_TMMD_STOP;
79
80 IO_CLK_MOD2 &= ~CLK_MOD2_TMR0; //disable TIMER0 clock
75} 81}
76 82
77bool __timer_register(void) 83bool __timer_register(void)
78{ 84{
79 int oldstatus = disable_interrupt_save(IRQ_FIQ_STATUS); 85 int oldstatus = disable_interrupt_save(IRQ_FIQ_STATUS);
80 86
81 stop_timer(); 87 stop_timer();
88
89 IO_CLK_MOD2 |= CLK_MOD2_TMR0; //enable TIMER0 clock!!!!!!!!!
82 90
83 /* Turn Timer0 to Free Run mode */ 91 /* Turn Timer0 to Free Run mode */
84 IO_TIMER0_TMMD = CONFIG_TIMER0_TMMD_FREE_RUN; 92 IO_TIMER0_TMMD = CONFIG_TIMER0_TMMD_FREE_RUN;
85 93
86 IO_INTC_EINT0 |= 1<<IRQ_TIMER0; 94 IO_INTC_EINT0 |= INTR_EINT0_TMR0; //enable TIMER0 interrupt
87 95
88 restore_interrupt(oldstatus); 96 restore_interrupt(oldstatus);
89 97
diff --git a/firmware/target/arm/tms320dm320/uart-dm320.c b/firmware/target/arm/tms320dm320/uart-dm320.c
index 151ad2921c..c3dd5459eb 100644
--- a/firmware/target/arm/tms320dm320/uart-dm320.c
+++ b/firmware/target/arm/tms320dm320/uart-dm320.c
@@ -50,7 +50,7 @@ void uart_init(void)
50 uart1_recieve_write=0; 50 uart1_recieve_write=0;
51 51
52 /* Enable the interrupt */ 52 /* Enable the interrupt */
53 IO_INTC_EINT0 |= (1<<IRQ_UART1); 53 IO_INTC_EINT0 |= INTR_EINT0_UART1;
54} 54}
55 55
56void uart1_putc(char ch) 56void uart1_putc(char ch)
@@ -75,7 +75,7 @@ void uart1_puts(const char *str, int size)
75/* This function returns the number of bytes left in the queue after a read is done (negative if fail)*/ 75/* This function returns the number of bytes left in the queue after a read is done (negative if fail)*/
76int uart1_gets_queue(char *str, unsigned int size) 76int uart1_gets_queue(char *str, unsigned int size)
77{ 77{
78 IO_INTC_EINT0 &= ~(1<<IRQ_UART1); 78 IO_INTC_EINT0 &= ~INTR_EINT0_UART1;
79 int retval; 79 int retval;
80 80
81 if(uart1_recieve_count<size) 81 if(uart1_recieve_count<size)
@@ -106,7 +106,7 @@ int uart1_gets_queue(char *str, unsigned int size)
106 } 106 }
107 107
108 /* Enable the interrupt */ 108 /* Enable the interrupt */
109 IO_INTC_EINT0 |= (1<<IRQ_UART1); 109 IO_INTC_EINT0 |= INTR_EINT0_UART1;
110 110
111 return retval; 111 return retval;
112} 112}
@@ -129,5 +129,5 @@ void UART1(void)
129 } 129 }
130 } 130 }
131 131
132 IO_INTC_IRQ0 = (1<<IRQ_UART1); 132 IO_INTC_IRQ0 = INTR_IRQ0_UART1;
133} 133}