diff options
author | Marcin Bukat <marcin.bukat@gmail.com> | 2010-04-26 21:40:16 +0000 |
---|---|---|
committer | Marcin Bukat <marcin.bukat@gmail.com> | 2010-04-26 21:40:16 +0000 |
commit | 28d54c6016459ffe93c0be2efea7de27c38d783c (patch) | |
tree | 9a7a71481f0a82599616a3e9f4e5bdad9fee8d6c /firmware/target/coldfire/mpio/hd200 | |
parent | b09d3aec392538ca0934644ff6357c41aaa4c323 (diff) | |
download | rockbox-28d54c6016459ffe93c0be2efea7de27c38d783c.tar.gz rockbox-28d54c6016459ffe93c0be2efea7de27c38d783c.zip |
Add MPIO HD200 port - new files
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25725 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target/coldfire/mpio/hd200')
-rw-r--r-- | firmware/target/coldfire/mpio/hd200/adc-hd200.c | 84 | ||||
-rw-r--r-- | firmware/target/coldfire/mpio/hd200/adc-target.h | 41 | ||||
-rw-r--r-- | firmware/target/coldfire/mpio/hd200/backlight-hd200.c | 86 | ||||
-rw-r--r-- | firmware/target/coldfire/mpio/hd200/backlight-target.h | 35 | ||||
-rw-r--r-- | firmware/target/coldfire/mpio/hd200/button-hd200.c | 123 | ||||
-rw-r--r-- | firmware/target/coldfire/mpio/hd200/lcd-as-hd200.S | 103 | ||||
-rw-r--r-- | firmware/target/coldfire/mpio/hd200/lcd-hd200.c | 241 | ||||
-rw-r--r-- | firmware/target/coldfire/mpio/hd200/power-hd200.c | 113 | ||||
-rw-r--r-- | firmware/target/coldfire/mpio/hd200/powermgmt-hd200.c | 59 | ||||
-rw-r--r-- | firmware/target/coldfire/mpio/hd200/system-hd200.c | 125 | ||||
-rw-r--r-- | firmware/target/coldfire/mpio/hd200/usb-hd200.c | 81 |
11 files changed, 1091 insertions, 0 deletions
diff --git a/firmware/target/coldfire/mpio/hd200/adc-hd200.c b/firmware/target/coldfire/mpio/hd200/adc-hd200.c new file mode 100644 index 0000000000..8bf96436bf --- /dev/null +++ b/firmware/target/coldfire/mpio/hd200/adc-hd200.c | |||
@@ -0,0 +1,84 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id:$ | ||
9 | * | ||
10 | * Copyright (C) 2010 Marcin Bukat | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
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 "cpu.h" | ||
24 | #include "system.h" | ||
25 | #include "kernel.h" | ||
26 | #include "thread.h" | ||
27 | #include "adc.h" | ||
28 | |||
29 | volatile unsigned short adc_data[NUM_ADC_CHANNELS] IBSS_ATTR; | ||
30 | |||
31 | /* Reading takes 4096 adclk ticks | ||
32 | * We do read one channel at once | ||
33 | * | ||
34 | * state FCPU Fbus Fadc bus/Fadc Fchannelread | ||
35 | * default 11.2896 MHz 5.6448 MHz 5.6448 MHz 2 172.2656 Hz | ||
36 | * normal 45.1584 MHz 22.5792 MHz 2.8224 MHz 8 172.2656 Hz | ||
37 | * max 124.1856 MHz 62.0928 MHz 1.9404 MHz 32 118.4326 Hz | ||
38 | */ | ||
39 | |||
40 | void ADC(void) __attribute__ ((interrupt_handler,section(".icode"))); | ||
41 | void ADC(void) | ||
42 | { | ||
43 | static unsigned char channel; | ||
44 | /* read current value */ | ||
45 | adc_data[(channel & 0x03)] = ADVALUE; | ||
46 | |||
47 | /* switch channel | ||
48 | * | ||
49 | * set source remark | ||
50 | * ADCONFIG is 16bit wide so we have to shift data by 16bits left | ||
51 | * thats why we shift <<24 instead of <<8 | ||
52 | */ | ||
53 | |||
54 | channel++; | ||
55 | |||
56 | and_l(~(3<<24),&ADCONFIG); | ||
57 | or_l( (((channel & 0x03) << 8 )|(1<<7))<<16, &ADCONFIG); | ||
58 | |||
59 | } | ||
60 | |||
61 | unsigned short adc_scan(int channel) | ||
62 | { | ||
63 | /* maybe we can drop &0x03 part */ | ||
64 | return adc_data[(channel&0x03)]; | ||
65 | } | ||
66 | |||
67 | void adc_init(void) | ||
68 | { | ||
69 | /* GPIO38 GPIO39 */ | ||
70 | and_l(~((1<<6)|(1<<7)), &GPIO1_FUNCTION); | ||
71 | |||
72 | /* ADOUT_SEL = 01 | ||
73 | * SOURCE SELECT = 000 | ||
74 | * CLEAR INTERRUPT FLAG | ||
75 | * ENABLE INTERRUPT = 1 | ||
76 | * ADOUT_DRIVE = 00 | ||
77 | * ADCLK_SEL = 011 (busclk/8) | ||
78 | */ | ||
79 | |||
80 | ADCONFIG = (1<<10)|(1<<7)|(1<<6)|(1<<1)|(1<<0); | ||
81 | |||
82 | /* ADC interrupt level 4.0 */ | ||
83 | or_l((4<<28), &INTPRI8); | ||
84 | } | ||
diff --git a/firmware/target/coldfire/mpio/hd200/adc-target.h b/firmware/target/coldfire/mpio/hd200/adc-target.h new file mode 100644 index 0000000000..2e61065695 --- /dev/null +++ b/firmware/target/coldfire/mpio/hd200/adc-target.h | |||
@@ -0,0 +1,41 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id:$ | ||
9 | * | ||
10 | * Copyright (C) 2010 Marcin Bukat | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
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 | #ifndef _ADC_TARGET_H_ | ||
23 | #define _ADC_TARGET_H_ | ||
24 | |||
25 | #define NUM_ADC_CHANNELS 4 | ||
26 | |||
27 | #define ADC_BUTTONS 1 | ||
28 | #define ADC_REMOTE 0 | ||
29 | #define ADC_BATTERY 2 | ||
30 | #define ADC_REMOTEDETECT 3 | ||
31 | #define ADC_UNREG_POWER ADC_BATTERY /* For compatibility */ | ||
32 | |||
33 | /* Force a scan now */ | ||
34 | unsigned short adc_scan(int channel); | ||
35 | |||
36 | static inline unsigned short adc_read(int channel) | ||
37 | { | ||
38 | return adc_scan(channel); | ||
39 | } | ||
40 | |||
41 | #endif /* _ADC_TARGET_H_ */ | ||
diff --git a/firmware/target/coldfire/mpio/hd200/backlight-hd200.c b/firmware/target/coldfire/mpio/hd200/backlight-hd200.c new file mode 100644 index 0000000000..783376c91e --- /dev/null +++ b/firmware/target/coldfire/mpio/hd200/backlight-hd200.c | |||
@@ -0,0 +1,86 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id:$ | ||
9 | * | ||
10 | * Copyright (C) 2010 Marcin Bukat | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
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 "cpu.h" | ||
24 | #include "kernel.h" | ||
25 | #include "system.h" | ||
26 | #include "backlight.h" | ||
27 | #include "backlight-target.h" | ||
28 | #include "lcd.h" | ||
29 | |||
30 | static bool _backlight_on = false; | ||
31 | static int _brightness = DEFAULT_BRIGHTNESS_SETTING; | ||
32 | |||
33 | /* Returns the current state of the backlight (true=ON, false=OFF). */ | ||
34 | bool _backlight_init(void) | ||
35 | { | ||
36 | and_l(~(1<<28),&GPIO_OUT); | ||
37 | or_l((1<<28),&GPIO_FUNCTION); | ||
38 | or_l((1<<28),&GPIO_ENABLE); | ||
39 | return true; | ||
40 | } | ||
41 | |||
42 | void _backlight_hw_on(void) | ||
43 | { | ||
44 | |||
45 | if (_backlight_on) | ||
46 | return; | ||
47 | |||
48 | _backlight_set_brightness(_brightness); | ||
49 | _backlight_on = true; | ||
50 | |||
51 | } | ||
52 | |||
53 | void _backlight_hw_off(void) | ||
54 | { | ||
55 | /* GPIO28 low */ | ||
56 | and_l(~(1<<28),&GPIO_OUT); | ||
57 | _backlight_on = false; | ||
58 | } | ||
59 | |||
60 | void _backlight_set_brightness(int val) | ||
61 | { | ||
62 | unsigned char i; | ||
63 | |||
64 | and_l(~(1<<28),&GPIO_OUT); | ||
65 | sleep(4); | ||
66 | |||
67 | for (i=0;i<val;i++) | ||
68 | { | ||
69 | or_l((1<<28),&GPIO_OUT); | ||
70 | and_l(~(1<<28),&GPIO_OUT); | ||
71 | } | ||
72 | |||
73 | or_l((1<<28),&GPIO_OUT); | ||
74 | |||
75 | _brightness = val; | ||
76 | } | ||
77 | |||
78 | void _remote_backlight_on(void) | ||
79 | { | ||
80 | /* I don't have remote to play with */ | ||
81 | } | ||
82 | |||
83 | void _remote_backlight_off(void) | ||
84 | { | ||
85 | /* I don't have remote to play with */ | ||
86 | } | ||
diff --git a/firmware/target/coldfire/mpio/hd200/backlight-target.h b/firmware/target/coldfire/mpio/hd200/backlight-target.h new file mode 100644 index 0000000000..0080ccac08 --- /dev/null +++ b/firmware/target/coldfire/mpio/hd200/backlight-target.h | |||
@@ -0,0 +1,35 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id:$ | ||
9 | * | ||
10 | * Copyright (C) 2010 Marcin Bukat | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | #ifndef BACKLIGHT_TARGET_H | ||
22 | #define BACKLIGHT_TARGET_H | ||
23 | |||
24 | bool _backlight_init(void); /* Returns backlight current state (true=ON). */ | ||
25 | void _backlight_hw_on(void); | ||
26 | void _backlight_hw_off(void); | ||
27 | void _backlight_set_brightness(int val); | ||
28 | |||
29 | #define _backlight_on() _backlight_hw_on() | ||
30 | #define _backlight_off() _backlight_hw_off() | ||
31 | #define _backlight_on_isr() _backlight_hw_on() | ||
32 | #define _backlight_off_isr() _backlight_hw_off() | ||
33 | #define _backlight_on_normal() _backlight_hw_on() | ||
34 | #define _backlight_off_normal() _backlight_hw_off() | ||
35 | #endif | ||
diff --git a/firmware/target/coldfire/mpio/hd200/button-hd200.c b/firmware/target/coldfire/mpio/hd200/button-hd200.c new file mode 100644 index 0000000000..b40c3324e1 --- /dev/null +++ b/firmware/target/coldfire/mpio/hd200/button-hd200.c | |||
@@ -0,0 +1,123 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id:$ | ||
9 | * | ||
10 | * Copyright (C) 2010 Marcin Bukat | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
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 "cpu.h" | ||
24 | #include "system.h" | ||
25 | #include "button.h" | ||
26 | #include "backlight.h" | ||
27 | #include "adc.h" | ||
28 | |||
29 | void button_init_device(void) | ||
30 | { | ||
31 | /* Set GPIO36, GPIO56 as general purpose inputs */ | ||
32 | or_l((1<<4)|(1<<24),&GPIO1_FUNCTION); | ||
33 | and_l(~((1<<4)|(1<<24)),&GPIO1_ENABLE); | ||
34 | } | ||
35 | |||
36 | bool button_hold(void) | ||
37 | { | ||
38 | /* GPIO36 active high */ | ||
39 | return (GPIO1_READ & (1<<4))?true:false; | ||
40 | } | ||
41 | |||
42 | |||
43 | /* | ||
44 | * Get button pressed from hardware | ||
45 | */ | ||
46 | int button_read_device(void) | ||
47 | { | ||
48 | int btn = BUTTON_NONE; | ||
49 | int data = 0; | ||
50 | static bool hold_button = false; | ||
51 | |||
52 | /* for moving average filter */ | ||
53 | static unsigned short button_filter[4]; | ||
54 | static unsigned char index; | ||
55 | |||
56 | bool hold_button_old; | ||
57 | |||
58 | /* normal buttons */ | ||
59 | hold_button_old = hold_button; | ||
60 | hold_button = button_hold(); | ||
61 | |||
62 | |||
63 | #ifndef BOOTLOADER | ||
64 | if (hold_button != hold_button_old) | ||
65 | backlight_hold_changed(hold_button); | ||
66 | #endif | ||
67 | |||
68 | if (!hold_button) | ||
69 | { | ||
70 | |||
71 | /* simple moving average filter with 4 item window */ | ||
72 | button_filter[index&0x03] = adc_scan(ADC_BUTTONS); | ||
73 | index++; | ||
74 | |||
75 | data = (button_filter[0]+button_filter[1] \ | ||
76 | +button_filter[2]+button_filter[3])>>2; | ||
77 | |||
78 | |||
79 | if (data < 2250) // valid button | ||
80 | { | ||
81 | if (data < 900) /* middle */ | ||
82 | { | ||
83 | if (data < 500) | ||
84 | { | ||
85 | if (data > 200) | ||
86 | /* 200 - 500 */ | ||
87 | btn = BUTTON_REC; | ||
88 | } | ||
89 | else /* 900 - 500 */ | ||
90 | btn = BUTTON_VOL_DOWN; | ||
91 | } | ||
92 | else /* 2250 - 900 */ | ||
93 | { | ||
94 | if (data < 1600) | ||
95 | { | ||
96 | /* 1600 - 900 */ | ||
97 | if (data < 1200) | ||
98 | /* 1200 - 900 */ | ||
99 | btn = BUTTON_VOL_UP; | ||
100 | else /* 1600 - 1200 */ | ||
101 | btn = BUTTON_NEXT; | ||
102 | } | ||
103 | else /* 1600 - 2250 */ | ||
104 | { | ||
105 | if (data < 1900) | ||
106 | /* 1900 - 1600 */ | ||
107 | btn = BUTTON_PREV; | ||
108 | else /* 1900 - 2250 */ | ||
109 | btn = BUTTON_SELECT; | ||
110 | } | ||
111 | } | ||
112 | } | ||
113 | } | ||
114 | |||
115 | |||
116 | data = GPIO1_READ; | ||
117 | |||
118 | /* GPIO56 active high main PLAY/PAUSE/ON */ | ||
119 | if (!hold_button && ((data & (1<<24)))) | ||
120 | btn |= BUTTON_PLAY; | ||
121 | |||
122 | return btn; | ||
123 | } | ||
diff --git a/firmware/target/coldfire/mpio/hd200/lcd-as-hd200.S b/firmware/target/coldfire/mpio/hd200/lcd-as-hd200.S new file mode 100644 index 0000000000..add9f694de --- /dev/null +++ b/firmware/target/coldfire/mpio/hd200/lcd-as-hd200.S | |||
@@ -0,0 +1,103 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id:$ | ||
9 | * | ||
10 | * Copyright (C) 2010 Marcin Bukat | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
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 "cpu.h" | ||
24 | |||
25 | |||
26 | #define LCD_BASE_ADDRESS 0xf0000000 | ||
27 | |||
28 | .section .icode,"ax",@progbits | ||
29 | |||
30 | .align 2 | ||
31 | .global lcd_write_command | ||
32 | .type lcd_write_command,@function | ||
33 | |||
34 | lcd_write_command: | ||
35 | move.l (4, %sp), %d0 | ||
36 | move.w %d0, LCD_BASE_ADDRESS /* data is 1byte but CF uses word | ||
37 | * transfers only */ | ||
38 | rts | ||
39 | .wc_end: | ||
40 | .size lcd_write_command,.wc_end-lcd_write_command | ||
41 | |||
42 | |||
43 | .align 2 | ||
44 | .global lcd_write_command_e | ||
45 | .type lcd_write_command_e,@function | ||
46 | |||
47 | lcd_write_command_e: | ||
48 | lea.l LCD_BASE_ADDRESS, %a0 | ||
49 | |||
50 | move.l (4, %sp), %d0 /* Command */ | ||
51 | move.w %d0, (%a0) | ||
52 | move.l (8, %sp), %d0 /* Data */ | ||
53 | move.w %d0, (%a0) /* Write to LCD */ | ||
54 | |||
55 | rts | ||
56 | .wce_end: | ||
57 | .size lcd_write_command_e,.wce_end-lcd_write_command_e | ||
58 | |||
59 | |||
60 | .align 2 | ||
61 | .global lcd_write_data | ||
62 | .type lcd_write_data,@function | ||
63 | |||
64 | /* PIXELFORMAT = VERTICAL_INTERLEAVED | ||
65 | * this means that data is packed verticaly in 8 pixels columns | ||
66 | * first byte is lsb of 2bit color in column | ||
67 | * second byte is msb of 2bit color in column | ||
68 | * so one word of data equals 8 pixels i 2bits color depth packed | ||
69 | * verticaly | ||
70 | */ | ||
71 | lcd_write_data: | ||
72 | movem.l (4, %sp), %a0 /* Data pointer */ | ||
73 | move.l (8, %sp), %d0 /* Length i in words */ | ||
74 | lea LCD_BASE_ADDRESS+2, %a1 /* LCD data port address */ | ||
75 | |||
76 | btst #0, %d0 /* longwords multiply? */ | ||
77 | beq .l_write | ||
78 | |||
79 | .w_write: | ||
80 | move.w (%a0)+, %d1 /* load data 3 cycles*/ | ||
81 | move.w %d1, (%a1) /* first byte 1 cycle*/ | ||
82 | lsr.l #8, %d1 /* load second byte 1 cycle*/ | ||
83 | move.w %d1, (%a1) /* transfer 1 cycle*/ | ||
84 | subq.l #1, %d0 /* decrement counter 1 cycle*/ | ||
85 | beq .write_end | ||
86 | |||
87 | .l_write: | ||
88 | move.l (%a0)+, %d1 /* load data 2 cycles*/ | ||
89 | swap %d1 /* 1 cycle */ | ||
90 | move.w %d1, (%a1) /* first byte 1 cycle*/ | ||
91 | lsr.l #8, %d1 /* 1 cycle */ | ||
92 | move.w %d1, (%a1) /* second byte 1 cycle*/ | ||
93 | lsr.l #8, %d1 /* 1 cycle */ | ||
94 | move.w %d1, (%a1) /* third byte 1 cycle*/ | ||
95 | lsr.l #8, %d1 /* 1 cycle */ | ||
96 | move.w %d1, (%a1) /* forth byte 1 cycle*/ | ||
97 | subq.l #2, %d0 /* decrement counter 1 cycle*/ | ||
98 | bne .l_write | ||
99 | |||
100 | .write_end: | ||
101 | rts | ||
102 | .size lcd_write_data,.wd_end-lcd_write_data | ||
103 | |||
diff --git a/firmware/target/coldfire/mpio/hd200/lcd-hd200.c b/firmware/target/coldfire/mpio/hd200/lcd-hd200.c new file mode 100644 index 0000000000..8cb9e8e087 --- /dev/null +++ b/firmware/target/coldfire/mpio/hd200/lcd-hd200.c | |||
@@ -0,0 +1,241 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id:$ | ||
9 | * | ||
10 | * Copyright (C) 2010 Marcin Bukat | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
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 | |||
24 | #include "system.h" | ||
25 | #include "kernel.h" | ||
26 | #include "lcd.h" | ||
27 | |||
28 | /*** definitions ***/ | ||
29 | /* TOMATO LSI 0350 - definitions and slightly tweaked functions | ||
30 | * taken from lcd-remote-iaudio.c | ||
31 | */ | ||
32 | |||
33 | #define LCD_SET_DUTY_RATIO 0x48 | ||
34 | #define LCD_SELECT_ADC 0xa0 | ||
35 | #define LCD_SELECT_SHL 0xc0 | ||
36 | #define LCD_SET_COM0 0x44 | ||
37 | #define LCD_OSC_ON 0xab | ||
38 | #define LCD_SELECT_DCDC 0x64 | ||
39 | #define LCD_SELECT_RES 0x20 | ||
40 | #define LCD_SET_VOLUME 0x81 | ||
41 | #define LCD_SET_BIAS 0x50 | ||
42 | #define LCD_CONTROL_POWER 0x28 | ||
43 | #define LCD_DISPLAY_ON 0xae | ||
44 | #define LCD_SET_INITLINE 0x40 | ||
45 | #define LCD_SET_COLUMN 0x10 | ||
46 | #define LCD_SET_PAGE 0xb0 | ||
47 | #define LCD_SET_GRAY 0x88 | ||
48 | #define LCD_SET_PWM_FRC 0x90 | ||
49 | #define LCD_SET_POWER_SAVE 0xa8 | ||
50 | #define LCD_REVERSE 0xa6 | ||
51 | #define LCD_RESET 0xe2 | ||
52 | |||
53 | /* cached settings */ | ||
54 | static bool cached_invert = false; | ||
55 | static bool cached_flip = false; | ||
56 | static int cached_contrast = DEFAULT_CONTRAST_SETTING; | ||
57 | bool lcd_initialized = false; | ||
58 | |||
59 | /*** hardware configuration ***/ | ||
60 | int lcd_default_contrast(void) | ||
61 | { | ||
62 | return DEFAULT_CONTRAST_SETTING; | ||
63 | } | ||
64 | |||
65 | void lcd_powersave(bool on) | ||
66 | { | ||
67 | /* What is the point of having else construct here? */ | ||
68 | if(lcd_initialized) { | ||
69 | if (on) | ||
70 | lcd_write_command(LCD_SET_POWER_SAVE | 1); | ||
71 | else | ||
72 | lcd_write_command(LCD_SET_POWER_SAVE | 1); | ||
73 | } | ||
74 | } | ||
75 | |||
76 | void lcd_set_contrast(int val) | ||
77 | { | ||
78 | if (val < MIN_CONTRAST_SETTING) | ||
79 | val = MIN_CONTRAST_SETTING; | ||
80 | else if (val > MAX_CONTRAST_SETTING) | ||
81 | val = MAX_CONTRAST_SETTING; | ||
82 | |||
83 | cached_contrast = val; | ||
84 | if(lcd_initialized) | ||
85 | lcd_write_command_e(LCD_SET_VOLUME, val); | ||
86 | } | ||
87 | |||
88 | void lcd_set_invert_display(bool yesno) | ||
89 | { | ||
90 | cached_invert = yesno; | ||
91 | if(lcd_initialized) | ||
92 | lcd_write_command(LCD_REVERSE | yesno); | ||
93 | |||
94 | } | ||
95 | |||
96 | /* turn the display upside down (call lcd_update() afterwards) */ | ||
97 | void lcd_set_flip(bool yesno) | ||
98 | { | ||
99 | cached_flip = yesno; | ||
100 | if(lcd_initialized) | ||
101 | { | ||
102 | if(yesno) | ||
103 | { | ||
104 | lcd_write_command(LCD_SELECT_ADC | 1); | ||
105 | lcd_write_command(LCD_SELECT_SHL | 0); | ||
106 | lcd_write_command_e(LCD_SET_COM0, 0); | ||
107 | } | ||
108 | else | ||
109 | { | ||
110 | lcd_write_command(LCD_SELECT_ADC | 0); | ||
111 | lcd_write_command(LCD_SELECT_SHL | 8); | ||
112 | lcd_write_command_e(LCD_SET_COM0, 0); | ||
113 | } | ||
114 | } | ||
115 | |||
116 | } | ||
117 | |||
118 | void lcd_shutdown(void) | ||
119 | { | ||
120 | /* Set power save -> Power OFF (VDD - VSS) .. that's it */ | ||
121 | if (lcd_initialized) | ||
122 | lcd_write_command(LCD_SET_POWER_SAVE | 1); | ||
123 | } | ||
124 | |||
125 | void lcd_init_device(void) | ||
126 | { | ||
127 | and_l(~0x00000800, &GPIO_FUNCTION); /* CS3 line */ | ||
128 | |||
129 | /* LCD Reset GPO34 */ | ||
130 | or_l(0x00000004, &GPIO1_ENABLE); /* set as output */ | ||
131 | or_l(0x00000004, &GPIO1_FUNCTION); /* switch to secondary function - GPIO */ | ||
132 | |||
133 | and_l(~0x00000004, &GPIO1_OUT); /* RESET low */ | ||
134 | sleep(1); /* delay at least 1000 ns */ | ||
135 | or_l(0x00000004, &GPIO1_OUT); /* RESET high */ | ||
136 | sleep(1); | ||
137 | |||
138 | /* parameters setup taken from original firmware */ | ||
139 | lcd_write_command(LCD_RESET); | ||
140 | lcd_write_command_e(LCD_SET_DUTY_RATIO,0x80); /* 1/128 */ | ||
141 | lcd_write_command(LCD_OSC_ON); | ||
142 | lcd_write_command(LCD_SELECT_DCDC | 3); /* DC/DC 6xboost */ | ||
143 | lcd_write_command(LCD_SELECT_RES | 7); /* Regulator resistor: 7.2 */ | ||
144 | lcd_write_command(LCD_SET_BIAS | 6); /* 1/11 */ | ||
145 | lcd_write_command(LCD_SET_PWM_FRC | 6); /* 3FRC + 12PWM */ | ||
146 | lcd_write_command_e(LCD_SET_GRAY | 0, 0x00); | ||
147 | lcd_write_command_e(LCD_SET_GRAY | 1, 0x00); | ||
148 | lcd_write_command_e(LCD_SET_GRAY | 2, 0x0c); | ||
149 | lcd_write_command_e(LCD_SET_GRAY | 3, 0x00); | ||
150 | lcd_write_command_e(LCD_SET_GRAY | 4, 0xc4); | ||
151 | lcd_write_command_e(LCD_SET_GRAY | 5, 0x00); | ||
152 | lcd_write_command_e(LCD_SET_GRAY | 6, 0xcc); | ||
153 | lcd_write_command_e(LCD_SET_GRAY | 7, 0x00); | ||
154 | |||
155 | lcd_write_command(LCD_CONTROL_POWER | 7); /* All circuits ON */ | ||
156 | lcd_write_command(LCD_DISPLAY_ON | 1); /* display on */ | ||
157 | |||
158 | /* Ok we are ready */ | ||
159 | lcd_initialized = true; | ||
160 | |||
161 | lcd_set_flip(cached_flip); | ||
162 | lcd_set_contrast(cached_contrast); | ||
163 | lcd_set_invert_display(cached_invert); | ||
164 | |||
165 | lcd_update(); | ||
166 | } | ||
167 | |||
168 | /* Update the display. | ||
169 | This must be called after all other LCD functions that change the display. */ | ||
170 | void lcd_update(void) ICODE_ATTR; | ||
171 | void lcd_update(void) | ||
172 | { | ||
173 | int y; | ||
174 | if(!lcd_initialized) | ||
175 | return; | ||
176 | |||
177 | for(y = 0;y < LCD_FBHEIGHT;y++) | ||
178 | { | ||
179 | lcd_write_command(LCD_SET_PAGE | y); | ||
180 | lcd_write_command_e(LCD_SET_COLUMN, 0); | ||
181 | lcd_write_data(lcd_framebuffer[y], LCD_WIDTH); | ||
182 | } | ||
183 | |||
184 | |||
185 | } | ||
186 | |||
187 | /* Update a fraction of the display. */ | ||
188 | void lcd_update_rect(int, int, int, int) ICODE_ATTR; | ||
189 | void lcd_update_rect(int x, int y, int width, int height) | ||
190 | { | ||
191 | int ymax; | ||
192 | |||
193 | if (!lcd_initialized) | ||
194 | return; | ||
195 | |||
196 | |||
197 | /* The Y coordinates have to work on even 8 pixel rows */ | ||
198 | ymax = (y + height-1) >> 3; | ||
199 | y >>= 3; | ||
200 | |||
201 | if(x + width > LCD_WIDTH) | ||
202 | width = LCD_WIDTH - x; | ||
203 | if (width <= 0) | ||
204 | return; /* nothing left to do, 0 is harmful to lcd_write_data() */ | ||
205 | if(ymax >= LCD_FBHEIGHT) | ||
206 | ymax = LCD_FBHEIGHT-1; | ||
207 | |||
208 | /* Copy specified rectange bitmap to hardware */ | ||
209 | for (; y <= ymax; y++) | ||
210 | { | ||
211 | lcd_write_command(LCD_SET_PAGE | y ); | ||
212 | lcd_write_command_e(LCD_SET_COLUMN | ((x >> 4) & 0xf), x & 0x0f); | ||
213 | lcd_write_data (&lcd_framebuffer[y][x], width); | ||
214 | } | ||
215 | |||
216 | } | ||
217 | |||
218 | void lcd_blit_grey_phase(unsigned char *values, unsigned char *phases, | ||
219 | int x, int by, int width, int bheight, int stride) | ||
220 | { | ||
221 | (void)values; | ||
222 | (void)phases; | ||
223 | (void)x; | ||
224 | (void)by; | ||
225 | (void)width; | ||
226 | (void)bheight; | ||
227 | (void)stride; | ||
228 | /* empty stub */ | ||
229 | } | ||
230 | |||
231 | void lcd_blit_mono(const unsigned char *data, int x, int by, int width, | ||
232 | int bheight, int stride) | ||
233 | { | ||
234 | (void)data; | ||
235 | (void)x; | ||
236 | (void)by; | ||
237 | (void)width; | ||
238 | (void)bheight; | ||
239 | (void)stride; | ||
240 | /* empty stub */ | ||
241 | } | ||
diff --git a/firmware/target/coldfire/mpio/hd200/power-hd200.c b/firmware/target/coldfire/mpio/hd200/power-hd200.c new file mode 100644 index 0000000000..dd8576b9e4 --- /dev/null +++ b/firmware/target/coldfire/mpio/hd200/power-hd200.c | |||
@@ -0,0 +1,113 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id:$ | ||
9 | * | ||
10 | * Copyright (C) 2010 Marcin Bukat | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
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 "cpu.h" | ||
24 | #include <stdbool.h> | ||
25 | #include "kernel.h" | ||
26 | #include "system.h" | ||
27 | #include "lcd.h" | ||
28 | #include "power.h" | ||
29 | |||
30 | #if CONFIG_TUNER | ||
31 | bool tuner_power(bool status) | ||
32 | { | ||
33 | (void)status; | ||
34 | if (status) | ||
35 | { | ||
36 | and_l(~(1<<17), &GPIO1_OUT); | ||
37 | } | ||
38 | else | ||
39 | { | ||
40 | or_l((1<<17), &GPIO1_OUT); | ||
41 | } | ||
42 | |||
43 | return status; | ||
44 | } | ||
45 | #endif /* #if CONFIG_TUNER */ | ||
46 | |||
47 | void power_init(void) | ||
48 | { | ||
49 | /* GPIO53 has to be high - low resets device */ | ||
50 | /* GPIO49 is FM related */ | ||
51 | or_l((1<<21)|(1<<17), &GPIO1_OUT); | ||
52 | or_l((1<<21)|(1<<17), &GPIO1_ENABLE); | ||
53 | or_l((1<<21)|(1<<17)|(1<<14), &GPIO1_FUNCTION); | ||
54 | |||
55 | and_l(~(1<<15), &GPIO_OUT); | ||
56 | or_l((1<<15),&GPIO_ENABLE); | ||
57 | or_l((1<<15),&GPIO_FUNCTION); | ||
58 | |||
59 | or_l((1<<23), &GPIO_OUT); | ||
60 | and_l(~(1<<23), &GPIO_ENABLE); | ||
61 | or_l((1<<23), &GPIO_FUNCTION); | ||
62 | |||
63 | #ifndef BOOTLOADER | ||
64 | /* The boot loader controls the power */ | ||
65 | ide_power_enable(true); | ||
66 | #endif | ||
67 | } | ||
68 | |||
69 | unsigned int power_input_status(void) | ||
70 | { | ||
71 | unsigned int status = POWER_INPUT_NONE; | ||
72 | /* GPIO46 is AC plug detect (low = AC plugged) */ | ||
73 | if (!(GPIO1_READ & (1<<14))) | ||
74 | status |= POWER_INPUT_MAIN_CHARGER; | ||
75 | |||
76 | return status; | ||
77 | } | ||
78 | |||
79 | /* Returns true if the unit is charging the batteries. */ | ||
80 | bool charging_state(void) | ||
81 | { | ||
82 | if (!(GPIO1_READ & (1<<14))) | ||
83 | return (GPIO_READ & (1<<30) )?false:true; | ||
84 | else | ||
85 | return false; | ||
86 | } | ||
87 | |||
88 | void ide_power_enable(bool on) | ||
89 | { | ||
90 | (void)on; | ||
91 | if (on) | ||
92 | and_l(~(1<<31),&GPIO_OUT); | ||
93 | else | ||
94 | or_l((1<<31),&GPIO_OUT); | ||
95 | |||
96 | or_l((1<<31),&GPIO_ENABLE); | ||
97 | or_l((1<<31),&GPIO_FUNCTION); | ||
98 | |||
99 | } | ||
100 | |||
101 | bool ide_powered(void) | ||
102 | { | ||
103 | return true; | ||
104 | } | ||
105 | |||
106 | void power_off(void) | ||
107 | { | ||
108 | lcd_shutdown(); | ||
109 | set_irq_level(DISABLE_INTERRUPTS); | ||
110 | and_l(~(1<<21), &GPIO1_OUT); /* pull KEEPACT low */ | ||
111 | asm("halt"); | ||
112 | while(1); | ||
113 | } | ||
diff --git a/firmware/target/coldfire/mpio/hd200/powermgmt-hd200.c b/firmware/target/coldfire/mpio/hd200/powermgmt-hd200.c new file mode 100644 index 0000000000..23a0bac927 --- /dev/null +++ b/firmware/target/coldfire/mpio/hd200/powermgmt-hd200.c | |||
@@ -0,0 +1,59 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id:$ | ||
9 | * | ||
10 | * Copyright (C) 2010 Marcin Bukat | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
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 "adc.h" | ||
24 | #include "powermgmt.h" | ||
25 | |||
26 | const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] = | ||
27 | { | ||
28 | 3700 | ||
29 | }; | ||
30 | |||
31 | const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] = | ||
32 | { | ||
33 | 3650 | ||
34 | }; | ||
35 | |||
36 | /* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */ | ||
37 | const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] = | ||
38 | { | ||
39 | /* from OF and measurements voltage range is 3.7-4.1 V */ | ||
40 | { 3700, 3740, 3780, 3820, 3860, 3900, 3940, 3980, 4020, 4060, 4100 } | ||
41 | }; | ||
42 | |||
43 | /* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */ | ||
44 | const unsigned short percent_to_volt_charge[11] = | ||
45 | { | ||
46 | /* values measured over one full charging cycle */ | ||
47 | 3540, 3860, 3930, 3980, 4000, 4020, 4040, 4080, 4130, 4180, 4230 /* LiPo */ | ||
48 | }; | ||
49 | |||
50 | /* 3.33V as reference */ | ||
51 | #define BATTERY_SCALE_FACTOR 3330 | ||
52 | |||
53 | |||
54 | /* Returns battery voltage from ADC [millivolts] */ | ||
55 | unsigned int battery_adc_voltage(void) | ||
56 | { | ||
57 | return (adc_read(ADC_BATTERY) * BATTERY_SCALE_FACTOR) >> 11; | ||
58 | } | ||
59 | |||
diff --git a/firmware/target/coldfire/mpio/hd200/system-hd200.c b/firmware/target/coldfire/mpio/hd200/system-hd200.c new file mode 100644 index 0000000000..06628c0835 --- /dev/null +++ b/firmware/target/coldfire/mpio/hd200/system-hd200.c | |||
@@ -0,0 +1,125 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id:$ | ||
9 | * | ||
10 | * Copyright (C) 2010 Marcin Bukat | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | #include "config.h" | ||
22 | #include "cpu.h" | ||
23 | #include "kernel.h" | ||
24 | #include "system.h" | ||
25 | #include "power.h" | ||
26 | #include "timer.h" | ||
27 | |||
28 | /* Settings for all possible clock frequencies (with properly working timers) | ||
29 | * | ||
30 | * xxx_REFRESH_TIMER below | ||
31 | * system.h, CPUFREQ_xxx_MULT | | ||
32 | * | | | ||
33 | * V V | ||
34 | * PLLCR & Rftim. IDECONFIG1/IDECONFIG2 | ||
35 | * CPUCLK/Hz MULT ~0x70c00000 16MB CSCR0 CSCR1 CS2Pre CS2Post CS2Wait | ||
36 | * ------------------------------------------------------------------------- | ||
37 | * 11289600 1 0x00000200 4 0x0180 0x0180 1 1 0 | ||
38 | * 22579200 2 0x05028049 10 0x0180 0x0180 1 1 0 | ||
39 | * 33868800 3 0x03024049 15 0x0180 0x0180 1 1 0 | ||
40 | * 45158400 4 0x05028045 21 0x0180 0x0180 1 1 0 | ||
41 | * 56448000 5 0x02028049 26 0x0580 0x0580 2 1 0 | ||
42 | * 67737600 6 0x03024045 32 0x0580 0x0980 2 1 0 | ||
43 | * 79027200 7 0x0302a045 37 0x0580 0x0d80 2 1 0 | ||
44 | * 90316800 8 0x03030045 43 0x0980 0x0d80 2 1 0 | ||
45 | * 101606400 9 0x01024049 48 0x0980 0x1180 2 1 0 | ||
46 | * 112896000 10 0x01028049 54 0x0980 0x1580 3 1 0 | ||
47 | * 124185600 11 0x0102c049 59 0x0980 0x1180 3 1 1 | ||
48 | */ | ||
49 | |||
50 | #define MAX_REFRESH_TIMER 59 | ||
51 | #define NORMAL_REFRESH_TIMER 21 | ||
52 | #define DEFAULT_REFRESH_TIMER 4 | ||
53 | |||
54 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ | ||
55 | void set_cpu_frequency (long) __attribute__ ((section (".icode"))); | ||
56 | void set_cpu_frequency(long frequency) | ||
57 | #else | ||
58 | void cf_set_cpu_frequency (long) __attribute__ ((section (".icode"))); | ||
59 | void cf_set_cpu_frequency(long frequency) | ||
60 | #endif | ||
61 | { | ||
62 | switch(frequency) | ||
63 | { | ||
64 | case CPUFREQ_MAX: | ||
65 | DCR = (0x8200 | DEFAULT_REFRESH_TIMER); | ||
66 | /* Refresh timer for bypass frequency */ | ||
67 | PLLCR &= ~1; /* Bypass mode */ | ||
68 | timers_adjust_prescale(CPUFREQ_DEFAULT_MULT, false); | ||
69 | PLLCR = 0x0102c049 | (PLLCR & 0x70C00000); | ||
70 | CSCR0 = 0x00001180; /* Flash: 4 wait states */ | ||
71 | CSCR3 = 0x00001180; /* LCD: 4 wait states */ | ||
72 | while(!(PLLCR & 0x80000000)) {}; /* Wait until the PLL has locked. | ||
73 | This may take up to 10ms! */ | ||
74 | timers_adjust_prescale(CPUFREQ_MAX_MULT, true); | ||
75 | DCR = (0x8200 | MAX_REFRESH_TIMER); /* Refresh timer */ | ||
76 | cpu_frequency = CPUFREQ_MAX; | ||
77 | IDECONFIG1 = (1<<28)|(1<<20)|(1<<18)|(1<<13)|(3<<10); | ||
78 | /* BUFEN2 enable on /CS2 | CS2Post 1 clock| CS2Pre 3 clocks*/ | ||
79 | IDECONFIG2 = (1<<18)|(1<<16)|(1<<8)|(1<<0); /* TA /CS2 enable + CS2wait */ | ||
80 | |||
81 | and_l(~(0x07<<16), &ADCONFIG); | ||
82 | or_l(((1<<7)|(1<<2)|(1<<0))<<16, &ADCONFIG); /* adclk = busclk/32 */ | ||
83 | |||
84 | break; | ||
85 | |||
86 | case CPUFREQ_NORMAL: | ||
87 | DCR = (DCR & ~0x01ff) | DEFAULT_REFRESH_TIMER; | ||
88 | /* Refresh timer for bypass frequency */ | ||
89 | PLLCR &= ~1; /* Bypass mode */ | ||
90 | timers_adjust_prescale(CPUFREQ_DEFAULT_MULT, false); | ||
91 | PLLCR = 0x05028045 | (PLLCR & 0x70C00000); | ||
92 | CSCR0 = 0x00000580; /* Flash: 1 wait state */ | ||
93 | CSCR3 = 0x00000980; /* LCD: 0 wait states */ | ||
94 | while(!(PLLCR & 0x80000000)) {}; /* Wait until the PLL has locked. | ||
95 | This may take up to 10ms! */ | ||
96 | timers_adjust_prescale(CPUFREQ_NORMAL_MULT, true); | ||
97 | DCR = (0x8000 | NORMAL_REFRESH_TIMER); /* Refresh timer */ | ||
98 | cpu_frequency = CPUFREQ_NORMAL; | ||
99 | IDECONFIG1 = (1<<28)|(1<<20)|(1<<18)|(1<<13)|(1<<10); | ||
100 | IDECONFIG2 = (1<<18)|(1<<16); | ||
101 | |||
102 | and_l(~(0x07<<16), &ADCONFIG); | ||
103 | or_l(((1<<7)|(1<<1)|(1<<0))<<16, &ADCONFIG); /* adclk = busclk/8 */ | ||
104 | |||
105 | break; | ||
106 | default: | ||
107 | DCR = (DCR & ~0x01ff) | DEFAULT_REFRESH_TIMER; | ||
108 | /* Refresh timer for bypass frequency */ | ||
109 | PLLCR &= ~1; /* Bypass mode */ | ||
110 | timers_adjust_prescale(CPUFREQ_DEFAULT_MULT, true); | ||
111 | /* Power down PLL, but keep CLSEL and CRSEL */ | ||
112 | PLLCR = 0x00000200 | (PLLCR & 0x70C00000); | ||
113 | CSCR0 = 0x00000180; /* Flash: 0 wait states */ | ||
114 | CSCR3 = 0x00000980; /* LCD: 0 wait states */ | ||
115 | DCR = (0x8000 | DEFAULT_REFRESH_TIMER); /* Refresh timer */ | ||
116 | cpu_frequency = CPUFREQ_DEFAULT; | ||
117 | IDECONFIG1 = (1<<28)|(1<<20)|(1<<18)|(1<<13)|(1<<10); | ||
118 | IDECONFIG2 = (1<<18)|(1<<16); | ||
119 | |||
120 | and_l(~(0x07<<16), &ADCONFIG); | ||
121 | or_l(((1<<7)|(1<<0))<<16, &ADCONFIG); /* adclk = busclk/2 */ | ||
122 | |||
123 | break; | ||
124 | } | ||
125 | } | ||
diff --git a/firmware/target/coldfire/mpio/hd200/usb-hd200.c b/firmware/target/coldfire/mpio/hd200/usb-hd200.c new file mode 100644 index 0000000000..8f348b8038 --- /dev/null +++ b/firmware/target/coldfire/mpio/hd200/usb-hd200.c | |||
@@ -0,0 +1,81 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id:$ | ||
9 | * | ||
10 | * Copyright (C) 2010 Marcin Bukat | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | #include "config.h" | ||
22 | #include <stdbool.h> | ||
23 | #include "cpu.h" | ||
24 | #include "system.h" | ||
25 | #include "kernel.h" | ||
26 | #include "usb.h" | ||
27 | |||
28 | void usb_init_device(void) | ||
29 | { | ||
30 | /* GPIO42 is USB detect input | ||
31 | * but it also serves as MCLK2 for DAC | ||
32 | */ | ||
33 | and_l(~(1<<4), &GPIO1_OUT); | ||
34 | or_l((1<<4)|(1<<18), &GPIO1_ENABLE); /* GPIO36 GPIO50 */ | ||
35 | or_l((1<<4)|(1<<18), &GPIO1_FUNCTION); | ||
36 | |||
37 | /* GPIO22 GPIO30*/ | ||
38 | /* GPIO31 has to be low to ATA work */ | ||
39 | or_l((1<<22)|(1<<30), &GPIO_OUT); | ||
40 | or_l((1<<22)|(1<<30)|(1<<31), &GPIO_ENABLE); | ||
41 | or_l((1<<22)|(1<<30)|(1<<31), &GPIO_FUNCTION); | ||
42 | } | ||
43 | |||
44 | int usb_detect(void) | ||
45 | { | ||
46 | /* GPIO42 active low*/ | ||
47 | return (GPIO1_READ & (1<<10)) ? USB_EXTRACTED : USB_INSERTED; | ||
48 | } | ||
49 | |||
50 | void usb_enable(bool on) | ||
51 | { | ||
52 | |||
53 | if(on) | ||
54 | { | ||
55 | or_l((1<<18),&GPIO1_OUT); /* GPIO50 high */ | ||
56 | |||
57 | and_l(~(1<<30),&GPIO_OUT); /* GPIO30 low */ | ||
58 | /* GPIO36 low delay GPIO36 high delay */ | ||
59 | and_l(~(1<<4),&GPIO1_OUT); | ||
60 | or_l((1<<4),&GPIO1_OUT); | ||
61 | |||
62 | and_l(~(1<<18),&GPIO1_OUT); /* GPIO50 low */ | ||
63 | sleep(HZ/5); /* delay 200 ms */ | ||
64 | and_l(~(1<<22),&GPIO_OUT); /* GPIO22 low */ | ||
65 | } | ||
66 | else | ||
67 | { | ||
68 | /* GPIO36 low delay GPIO36 high delay */ | ||
69 | and_l(~(1<<4),&GPIO1_OUT); | ||
70 | sleep(HZ/100); | ||
71 | or_l((1<<4),&GPIO1_OUT); | ||
72 | sleep(HZ/100); | ||
73 | |||
74 | or_l((1<<22),&GPIO_OUT); /* GPIO22 high */ | ||
75 | or_l((1<<30),&GPIO_OUT); /* GPIO30 high */ | ||
76 | |||
77 | and_l(~(1<<4),&GPIO1_OUT); /* GPIO36 low */ | ||
78 | |||
79 | //or_l((1<<18),&GPIO1_OUT); /* GPIO50 high */ | ||
80 | } | ||
81 | } | ||