From 123bebeada5dce220d8ce96d31ed711cb13d8d05 Mon Sep 17 00:00:00 2001 From: Marcin Bukat Date: Fri, 12 Nov 2010 21:52:29 +0000 Subject: MPIO: move files a bit in preparation for HD300 port git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28567 a1c6a512-1295-4272-9138-f99709370657 --- firmware/SOURCES | 14 +-- firmware/target/coldfire/mpio/adc-mpio.c | 97 +++++++++++++++ firmware/target/coldfire/mpio/adc-target.h | 41 +++++++ firmware/target/coldfire/mpio/backlight-mpio.c | 94 +++++++++++++++ firmware/target/coldfire/mpio/backlight-target.h | 35 ++++++ firmware/target/coldfire/mpio/button-target.h | 68 ----------- firmware/target/coldfire/mpio/hd200/adc-hd200.c | 97 --------------- firmware/target/coldfire/mpio/hd200/adc-target.h | 41 ------- .../target/coldfire/mpio/hd200/backlight-hd200.c | 94 --------------- .../target/coldfire/mpio/hd200/backlight-target.h | 35 ------ .../target/coldfire/mpio/hd200/button-target.h | 68 +++++++++++ firmware/target/coldfire/mpio/hd200/power-hd200.c | 130 --------------------- firmware/target/coldfire/mpio/hd200/system-hd200.c | 125 -------------------- firmware/target/coldfire/mpio/hd200/usb-hd200.c | 75 ------------ firmware/target/coldfire/mpio/power-mpio.c | 130 +++++++++++++++++++++ firmware/target/coldfire/mpio/system-mpio.c | 125 ++++++++++++++++++++ firmware/target/coldfire/mpio/usb-mpio.c | 75 ++++++++++++ 17 files changed, 672 insertions(+), 672 deletions(-) create mode 100644 firmware/target/coldfire/mpio/adc-mpio.c create mode 100644 firmware/target/coldfire/mpio/adc-target.h create mode 100644 firmware/target/coldfire/mpio/backlight-mpio.c create mode 100644 firmware/target/coldfire/mpio/backlight-target.h delete mode 100644 firmware/target/coldfire/mpio/button-target.h delete mode 100644 firmware/target/coldfire/mpio/hd200/adc-hd200.c delete mode 100644 firmware/target/coldfire/mpio/hd200/adc-target.h delete mode 100644 firmware/target/coldfire/mpio/hd200/backlight-hd200.c delete mode 100644 firmware/target/coldfire/mpio/hd200/backlight-target.h create mode 100644 firmware/target/coldfire/mpio/hd200/button-target.h delete mode 100644 firmware/target/coldfire/mpio/hd200/power-hd200.c delete mode 100644 firmware/target/coldfire/mpio/hd200/system-hd200.c delete mode 100644 firmware/target/coldfire/mpio/hd200/usb-hd200.c create mode 100644 firmware/target/coldfire/mpio/power-mpio.c create mode 100644 firmware/target/coldfire/mpio/system-mpio.c create mode 100644 firmware/target/coldfire/mpio/usb-mpio.c diff --git a/firmware/SOURCES b/firmware/SOURCES index 29dc8644ee..01aa1c4eef 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES @@ -1682,17 +1682,17 @@ target/arm/usb-fw-pp502x.c #ifdef MPIO_HD200 #ifndef SIMULATOR /* TODO: currently including all files */ -target/coldfire/mpio/hd200/adc-hd200.c +target/coldfire/ata-as-coldfire.S +target/coldfire/mpio/system-mpio.c +target/coldfire/mpio/power-mpio.c +target/coldfire/mpio/backlight-mpio.c +target/coldfire/mpio/usb-mpio.c +target/coldfire/mpio/ata-mpio.c +target/coldfire/mpio/adc-mpio.c target/coldfire/mpio/hd200/button-hd200.c target/coldfire/mpio/hd200/lcd-hd200.c target/coldfire/mpio/hd200/lcd-as-hd200.S -target/coldfire/mpio/hd200/power-hd200.c target/coldfire/mpio/hd200/powermgmt-hd200.c -target/coldfire/mpio/hd200/backlight-hd200.c -target/coldfire/mpio/hd200/system-hd200.c -target/coldfire/mpio/hd200/usb-hd200.c -target/coldfire/mpio/ata-mpio.c -target/coldfire/ata-as-coldfire.S #ifndef BOOTLOADER target/coldfire/mpio/audio-mpio.c target/coldfire/wmcodec-coldfire.c diff --git a/firmware/target/coldfire/mpio/adc-mpio.c b/firmware/target/coldfire/mpio/adc-mpio.c new file mode 100644 index 0000000000..92b9479279 --- /dev/null +++ b/firmware/target/coldfire/mpio/adc-mpio.c @@ -0,0 +1,97 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2010 Marcin Bukat + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include "config.h" +#include "cpu.h" +#include "system.h" +#include "kernel.h" +#include "thread.h" +#include "adc.h" + +volatile unsigned short adc_data[NUM_ADC_CHANNELS] IBSS_ATTR; + +/* Reading takes 4096 adclk ticks + * 1) tick task is created that enables ADC interrupt + * 2) On interrupt single channel is readed and + * ADC is prepared for next channel + * 3) When all 4 channels are scanned ADC interrupt is disabled + */ + +void ADC(void) __attribute__ ((interrupt_handler,section(".icode"))); +void ADC(void) +{ + static unsigned char channel IBSS_ATTR; + /* read current value */ + adc_data[(channel&0x03)] = ADVALUE; + + /* switch channel + * + * set source remark + * ADCONFIG is 16bit wide so we have to shift data by 16bits left + * thats why we shift <<24 instead of <<8 + */ + + channel++; + + and_l(~(0x03<<24),&ADCONFIG); + or_l( (((channel&0x03) << 8 )|(1<<7))<<16, &ADCONFIG); + + if ( (channel & 0x03) == 0 ) + /* disable ADC interrupt */ + and_l((~(1<<6))<<16,&ADCONFIG); +} + +unsigned short adc_scan(int channel) +{ + /* maybe we can drop &0x03 part */ + return adc_data[(channel&0x03)]; +} + +void adc_tick(void) +{ + /* enable ADC interrupt */ + or_l( ((1<<6))<<16, &ADCONFIG); +} + +void adc_init(void) +{ + /* GPIO38 GPIO39 */ + and_l(~((1<<6)|(1<<7)), &GPIO1_FUNCTION); + + /* ADOUT_SEL = 01 + * SOURCE SELECT = 000 + * CLEAR INTERRUPT FLAG + * ENABLE INTERRUPT = 0 + * ADOUT_DRIVE = 00 + * ADCLK_SEL = 011 (busclk/8) + */ + + ADCONFIG = (1<<10)|(1<<8)|(1<<7)|0x03; + + /* ADC interrupt level 4.0 */ + or_l((4<<28), &INTPRI8); + + /* create tick task which enables ADC interrupt */ + tick_add_task(adc_tick); + + /* let the interrupt handler fill readout array */ + sleep(2); +} diff --git a/firmware/target/coldfire/mpio/adc-target.h b/firmware/target/coldfire/mpio/adc-target.h new file mode 100644 index 0000000000..fb541833cf --- /dev/null +++ b/firmware/target/coldfire/mpio/adc-target.h @@ -0,0 +1,41 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2010 Marcin Bukat + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#ifndef _ADC_TARGET_H_ +#define _ADC_TARGET_H_ + +#define NUM_ADC_CHANNELS 4 + +#define ADC_BUTTONS 1 +#define ADC_REMOTE 0 +#define ADC_BATTERY 2 +#define ADC_REMOTEDETECT 3 +#define ADC_UNREG_POWER ADC_BATTERY /* For compatibility */ + +/* Force a scan now */ +unsigned short adc_scan(int channel); + +static inline unsigned short adc_read(int channel) +{ + return adc_scan(channel); +} + +#endif /* _ADC_TARGET_H_ */ diff --git a/firmware/target/coldfire/mpio/backlight-mpio.c b/firmware/target/coldfire/mpio/backlight-mpio.c new file mode 100644 index 0000000000..1e40e9bb88 --- /dev/null +++ b/firmware/target/coldfire/mpio/backlight-mpio.c @@ -0,0 +1,94 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2010 Marcin Bukat + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include "config.h" +#include "cpu.h" +#include "kernel.h" +#include "system.h" +#include "backlight.h" +#include "backlight-target.h" +#include "lcd.h" + +static bool _backlight_on = true; +static int _brightness = DEFAULT_BRIGHTNESS_SETTING; + +/* Returns the current state of the backlight (true=ON, false=OFF). */ +bool _backlight_init(void) +{ +#ifdef BOOTLOADER + and_l(~(1<<28),&GPIO_OUT); +#endif + or_l((1<<28),&GPIO_FUNCTION); + or_l((1<<28),&GPIO_ENABLE); + return true; +} + +void _backlight_hw_on(void) +{ +#ifndef BOOTLOADER + if (_backlight_on) + return; +#endif + + _backlight_set_brightness(_brightness); + _backlight_on = true; + +} + +void _backlight_hw_off(void) +{ + /* GPIO28 low */ + and_l(~(1<<28),&GPIO_OUT); + _backlight_on = false; +} + +void _backlight_set_brightness(int val) +{ + unsigned char i; + +#ifndef BOOTLOADER + if( _brightness == val && _backlight_on == true ) + return; +#endif + + and_l(~(1<<28),&GPIO_OUT); + sleep(4); + + for (i=0;i ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2010 Marcin Bukat + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#ifndef BACKLIGHT_TARGET_H +#define BACKLIGHT_TARGET_H + +bool _backlight_init(void); /* Returns backlight current state (true=ON). */ +void _backlight_hw_on(void); +void _backlight_hw_off(void); +void _backlight_set_brightness(int val); + +#define _backlight_on() _backlight_hw_on() +#define _backlight_off() _backlight_hw_off() +#define _backlight_on_isr() _backlight_hw_on() +#define _backlight_off_isr() _backlight_hw_off() +#define _backlight_on_normal() _backlight_hw_on() +#define _backlight_off_normal() _backlight_hw_off() +#endif diff --git a/firmware/target/coldfire/mpio/button-target.h b/firmware/target/coldfire/mpio/button-target.h deleted file mode 100644 index b7c31f8c59..0000000000 --- a/firmware/target/coldfire/mpio/button-target.h +++ /dev/null @@ -1,68 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2010 Marcin Bukat - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - ****************************************************************************/ -#ifndef _BUTTON_TARGET_H_ -#define _BUTTON_TARGET_H_ - -#include -#include "config.h" - -#define HAS_BUTTON_HOLD -#define HAS_REMOTE_BUTTON_HOLD - -bool button_hold(void); -bool remote_button_hold(void); -void button_init_device(void); -int button_read_device(void); - -/* HD200 specific button codes */ -/* Main unit's buttons - flags as in original firmware*/ -#define BUTTON_PLAY 0x00000001 - -#define BUTTON_REW 0x00000004 -#define BUTTON_FF 0x00000002 -#define BUTTON_VOL_UP 0x00000008 -#define BUTTON_VOL_DOWN 0x00000010 -#define BUTTON_REC 0x00000020 -#define BUTTON_FUNC 0x00002000 - -#define BUTTON_RC_PLAY 0x00010000 - -#define BUTTON_RC_REW 0x00040000 -#define BUTTON_RC_FF 0x00020000 -#define BUTTON_RC_VOL_UP 0x00080000 -#define BUTTON_RC_VOL_DOWN 0x00100000 -#define BUTTON_RC_FUNC 0x20000000 - -#define BUTTON_LEFT BUTTON_REW -#define BUTTON_RIGHT BUTTON_FF -#define BUTTON_ON BUTTON_PLAY - -#define BUTTON_MAIN (BUTTON_PLAY|BUTTON_REW|BUTTON_FF|BUTTON_VOL_UP|\ - BUTTON_VOL_DOWN|BUTTON_REC|BUTTON_FUNC) - -#define BUTTON_REMOTE (BUTTON_RC_PLAY|BUTTON_RC_REW|BUTTON_RC_FF|\ - BUTTON_RC_VOL_UP|BUTTON_RC_VOL_DOWN|BUTTON_RC_FUNC) - -#define POWEROFF_BUTTON BUTTON_PLAY -#define RC_POWEROFF_BUTTON BUTTON_RC_PLAY -#define POWEROFF_COUNT 30 - -#endif /* _BUTTON_TARGET_H_ */ diff --git a/firmware/target/coldfire/mpio/hd200/adc-hd200.c b/firmware/target/coldfire/mpio/hd200/adc-hd200.c deleted file mode 100644 index 92b9479279..0000000000 --- a/firmware/target/coldfire/mpio/hd200/adc-hd200.c +++ /dev/null @@ -1,97 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2010 Marcin Bukat - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - ****************************************************************************/ - -#include "config.h" -#include "cpu.h" -#include "system.h" -#include "kernel.h" -#include "thread.h" -#include "adc.h" - -volatile unsigned short adc_data[NUM_ADC_CHANNELS] IBSS_ATTR; - -/* Reading takes 4096 adclk ticks - * 1) tick task is created that enables ADC interrupt - * 2) On interrupt single channel is readed and - * ADC is prepared for next channel - * 3) When all 4 channels are scanned ADC interrupt is disabled - */ - -void ADC(void) __attribute__ ((interrupt_handler,section(".icode"))); -void ADC(void) -{ - static unsigned char channel IBSS_ATTR; - /* read current value */ - adc_data[(channel&0x03)] = ADVALUE; - - /* switch channel - * - * set source remark - * ADCONFIG is 16bit wide so we have to shift data by 16bits left - * thats why we shift <<24 instead of <<8 - */ - - channel++; - - and_l(~(0x03<<24),&ADCONFIG); - or_l( (((channel&0x03) << 8 )|(1<<7))<<16, &ADCONFIG); - - if ( (channel & 0x03) == 0 ) - /* disable ADC interrupt */ - and_l((~(1<<6))<<16,&ADCONFIG); -} - -unsigned short adc_scan(int channel) -{ - /* maybe we can drop &0x03 part */ - return adc_data[(channel&0x03)]; -} - -void adc_tick(void) -{ - /* enable ADC interrupt */ - or_l( ((1<<6))<<16, &ADCONFIG); -} - -void adc_init(void) -{ - /* GPIO38 GPIO39 */ - and_l(~((1<<6)|(1<<7)), &GPIO1_FUNCTION); - - /* ADOUT_SEL = 01 - * SOURCE SELECT = 000 - * CLEAR INTERRUPT FLAG - * ENABLE INTERRUPT = 0 - * ADOUT_DRIVE = 00 - * ADCLK_SEL = 011 (busclk/8) - */ - - ADCONFIG = (1<<10)|(1<<8)|(1<<7)|0x03; - - /* ADC interrupt level 4.0 */ - or_l((4<<28), &INTPRI8); - - /* create tick task which enables ADC interrupt */ - tick_add_task(adc_tick); - - /* let the interrupt handler fill readout array */ - sleep(2); -} diff --git a/firmware/target/coldfire/mpio/hd200/adc-target.h b/firmware/target/coldfire/mpio/hd200/adc-target.h deleted file mode 100644 index fb541833cf..0000000000 --- a/firmware/target/coldfire/mpio/hd200/adc-target.h +++ /dev/null @@ -1,41 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2010 Marcin Bukat - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - ****************************************************************************/ - -#ifndef _ADC_TARGET_H_ -#define _ADC_TARGET_H_ - -#define NUM_ADC_CHANNELS 4 - -#define ADC_BUTTONS 1 -#define ADC_REMOTE 0 -#define ADC_BATTERY 2 -#define ADC_REMOTEDETECT 3 -#define ADC_UNREG_POWER ADC_BATTERY /* For compatibility */ - -/* Force a scan now */ -unsigned short adc_scan(int channel); - -static inline unsigned short adc_read(int channel) -{ - return adc_scan(channel); -} - -#endif /* _ADC_TARGET_H_ */ diff --git a/firmware/target/coldfire/mpio/hd200/backlight-hd200.c b/firmware/target/coldfire/mpio/hd200/backlight-hd200.c deleted file mode 100644 index 1e40e9bb88..0000000000 --- a/firmware/target/coldfire/mpio/hd200/backlight-hd200.c +++ /dev/null @@ -1,94 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2010 Marcin Bukat - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - ****************************************************************************/ - -#include "config.h" -#include "cpu.h" -#include "kernel.h" -#include "system.h" -#include "backlight.h" -#include "backlight-target.h" -#include "lcd.h" - -static bool _backlight_on = true; -static int _brightness = DEFAULT_BRIGHTNESS_SETTING; - -/* Returns the current state of the backlight (true=ON, false=OFF). */ -bool _backlight_init(void) -{ -#ifdef BOOTLOADER - and_l(~(1<<28),&GPIO_OUT); -#endif - or_l((1<<28),&GPIO_FUNCTION); - or_l((1<<28),&GPIO_ENABLE); - return true; -} - -void _backlight_hw_on(void) -{ -#ifndef BOOTLOADER - if (_backlight_on) - return; -#endif - - _backlight_set_brightness(_brightness); - _backlight_on = true; - -} - -void _backlight_hw_off(void) -{ - /* GPIO28 low */ - and_l(~(1<<28),&GPIO_OUT); - _backlight_on = false; -} - -void _backlight_set_brightness(int val) -{ - unsigned char i; - -#ifndef BOOTLOADER - if( _brightness == val && _backlight_on == true ) - return; -#endif - - and_l(~(1<<28),&GPIO_OUT); - sleep(4); - - for (i=0;i ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2010 Marcin Bukat - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - ****************************************************************************/ -#ifndef BACKLIGHT_TARGET_H -#define BACKLIGHT_TARGET_H - -bool _backlight_init(void); /* Returns backlight current state (true=ON). */ -void _backlight_hw_on(void); -void _backlight_hw_off(void); -void _backlight_set_brightness(int val); - -#define _backlight_on() _backlight_hw_on() -#define _backlight_off() _backlight_hw_off() -#define _backlight_on_isr() _backlight_hw_on() -#define _backlight_off_isr() _backlight_hw_off() -#define _backlight_on_normal() _backlight_hw_on() -#define _backlight_off_normal() _backlight_hw_off() -#endif diff --git a/firmware/target/coldfire/mpio/hd200/button-target.h b/firmware/target/coldfire/mpio/hd200/button-target.h new file mode 100644 index 0000000000..b7c31f8c59 --- /dev/null +++ b/firmware/target/coldfire/mpio/hd200/button-target.h @@ -0,0 +1,68 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2010 Marcin Bukat + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#ifndef _BUTTON_TARGET_H_ +#define _BUTTON_TARGET_H_ + +#include +#include "config.h" + +#define HAS_BUTTON_HOLD +#define HAS_REMOTE_BUTTON_HOLD + +bool button_hold(void); +bool remote_button_hold(void); +void button_init_device(void); +int button_read_device(void); + +/* HD200 specific button codes */ +/* Main unit's buttons - flags as in original firmware*/ +#define BUTTON_PLAY 0x00000001 + +#define BUTTON_REW 0x00000004 +#define BUTTON_FF 0x00000002 +#define BUTTON_VOL_UP 0x00000008 +#define BUTTON_VOL_DOWN 0x00000010 +#define BUTTON_REC 0x00000020 +#define BUTTON_FUNC 0x00002000 + +#define BUTTON_RC_PLAY 0x00010000 + +#define BUTTON_RC_REW 0x00040000 +#define BUTTON_RC_FF 0x00020000 +#define BUTTON_RC_VOL_UP 0x00080000 +#define BUTTON_RC_VOL_DOWN 0x00100000 +#define BUTTON_RC_FUNC 0x20000000 + +#define BUTTON_LEFT BUTTON_REW +#define BUTTON_RIGHT BUTTON_FF +#define BUTTON_ON BUTTON_PLAY + +#define BUTTON_MAIN (BUTTON_PLAY|BUTTON_REW|BUTTON_FF|BUTTON_VOL_UP|\ + BUTTON_VOL_DOWN|BUTTON_REC|BUTTON_FUNC) + +#define BUTTON_REMOTE (BUTTON_RC_PLAY|BUTTON_RC_REW|BUTTON_RC_FF|\ + BUTTON_RC_VOL_UP|BUTTON_RC_VOL_DOWN|BUTTON_RC_FUNC) + +#define POWEROFF_BUTTON BUTTON_PLAY +#define RC_POWEROFF_BUTTON BUTTON_RC_PLAY +#define POWEROFF_COUNT 30 + +#endif /* _BUTTON_TARGET_H_ */ diff --git a/firmware/target/coldfire/mpio/hd200/power-hd200.c b/firmware/target/coldfire/mpio/hd200/power-hd200.c deleted file mode 100644 index 3034bab82d..0000000000 --- a/firmware/target/coldfire/mpio/hd200/power-hd200.c +++ /dev/null @@ -1,130 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2010 Marcin Bukat - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - ****************************************************************************/ - -#include "config.h" -#include "cpu.h" -#include -#include "kernel.h" -#include "system.h" -#include "lcd.h" -#include "power.h" - -#if CONFIG_TUNER -bool tuner_power(bool status) -{ - if (status) - and_l(~(1<<17), &GPIO1_OUT); - else - or_l((1<<17), &GPIO1_OUT); - - return status; -} -#endif /* #if CONFIG_TUNER */ - -void power_init(void) -{ - /* GPIO53 has to be high - low resets device - * it is setup in crt0.S - */ - - /* GPIO50 is ATA power (default OFF) */ - or_l((1<<18), &GPIO1_OUT); - or_l((1<<18), &GPIO1_ENABLE); - or_l((1<<18), &GPIO1_FUNCTION); - - /* GPIO49 is FM power (default OFF) */ - or_l((1<<17), &GPIO1_OUT); - or_l((1<<17), &GPIO1_ENABLE); - or_l((1<<17), &GPIO1_FUNCTION); - - /* GPIO46 is wall charger detect (input) */ - and_l(~(1<<14), &GPIO1_ENABLE); - or_l((1<<14), &GPIO1_FUNCTION); - - /* GPIO31 needs to be low */ - and_l(~(1<<31), &GPIO_OUT); - or_l((1<<31),&GPIO_ENABLE); - or_l((1<<31),&GPIO_FUNCTION); - - /* turn off charger by default*/ - or_l((1<<23), &GPIO_OUT); - or_l((1<<23), &GPIO_ENABLE); - or_l((1<<23), &GPIO_FUNCTION); - - /* high current charge mode */ - or_l((1<<15), &GPIO_OUT); - or_l((1<<15),&GPIO_ENABLE); - or_l((1<<15),&GPIO_FUNCTION); - -#ifndef BOOTLOADER - /* The boot loader controls the power */ - ide_power_enable(true); -#endif -} - -unsigned int power_input_status(void) -{ - unsigned int status = POWER_INPUT_NONE; -/* GPIO46 is AC plug detect (low = AC plugged) */ - if (!(GPIO1_READ & (1<<14))) - { - status |= POWER_INPUT_MAIN_CHARGER; - /* tristate GPIO23 to start charging cycle */ - and_l(~(1<<23), &GPIO_ENABLE); - } - else - { - /* drive GPIO23 high to enter LTC1733 shutdown mode */ - or_l((1<<23), &GPIO_ENABLE); - } - return status; -} - -/* Returns true if the unit is charging the batteries. */ -bool charging_state(void) -{ - if (!(GPIO1_READ & (1<<14))) - return (GPIO_READ & (1<<30) )?false:true; - else - return false; -} - -void ide_power_enable(bool on) -{ - if (on) - and_l(~(1<<18),&GPIO1_OUT); - else - or_l((1<<18),&GPIO1_OUT); -} - -bool ide_powered(void) -{ - return (GPIO1_OUT & (1<<18))?false:true; -} - -void power_off(void) -{ - lcd_shutdown(); - set_irq_level(DISABLE_INTERRUPTS); - and_l(~(1<<21), &GPIO1_OUT); /* pull KEEPACT low */ - asm("halt"); - while(1); -} diff --git a/firmware/target/coldfire/mpio/hd200/system-hd200.c b/firmware/target/coldfire/mpio/hd200/system-hd200.c deleted file mode 100644 index 0bd0e07386..0000000000 --- a/firmware/target/coldfire/mpio/hd200/system-hd200.c +++ /dev/null @@ -1,125 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2010 by Marcin Bukat - * Copyright (C) 2006 by Linus Nielsen Feltzing - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - ****************************************************************************/ -#include "config.h" -#include "cpu.h" -#include "kernel.h" -#include "system.h" -#include "power.h" -#include "timer.h" - -/* Settings for all possible clock frequencies (with properly working timers) - * NOTE: Some 5249 chips don't like having PLLDIV set to 0. We must avoid that! - * - * xxx_REFRESH_TIMER below - * system.h, CPUFREQ_xxx_MULT | - * | | - * V V - * PLLCR & Refreshtim. IDECONFIG1/IDECONFIG2 - * CPUCLK/Hz MULT ~0x70400000 16MB 32MB CSCR0 CSCR1 CSCR3 CS2Pre CS2Post CS2Wait - * --------------------------------------------------------------------------------------- - * 11289600 1 0x00800200 4 1 0x0180 0x0180 0x0180 1 1 0 - * 22579200 2 0x0589e025 10 4 0x0180 0x0180 0x0180 1 1 0 - * 33868800 3 0x0388e025 15 7 0x0180 0x0180 0x0180 1 1 0 - * 45158400 4 0x0589e021 21 10 0x0580 0x0180 0x0580 1 1 0 - * 56448000 5 0x0289e025 26 12 0x0580 0x0580 0x0980 2 1 0 - * 67737600 6 0x0388e021 32 15 0x0980 0x0980 0x0d80 2 1 0 - * 79027200 7 0x038a6021 37 18 0x0980 0x0d80 0x1180 2 1 0 - * 90316800 8 0x038be021 43 21 0x0d80 0x0d80 0x1580 2 1 0 - * 101606400 9 0x01892025 48 23 0x0d80 0x1180 0x1980 2 1 0 - * 112896000 10 0x0189e025 54 26 0x1180 0x1580 0x1d80 3 1 0 - * 124185600 11 0x018ae025 59 29 0x1180 0x1580 0x2180 3 1 1 - */ - -#define MAX_REFRESH_TIMER 59 -#define NORMAL_REFRESH_TIMER 21 -#define DEFAULT_REFRESH_TIMER 4 - -#ifdef HAVE_ADJUSTABLE_CPU_FREQ -void set_cpu_frequency (long) __attribute__ ((section (".icode"))); -void set_cpu_frequency(long frequency) -#else -void cf_set_cpu_frequency (long) __attribute__ ((section (".icode"))); -void cf_set_cpu_frequency(long frequency) -#endif -{ - switch(frequency) - { - case CPUFREQ_MAX: - DCR = (0x8200 | DEFAULT_REFRESH_TIMER); - /* Refresh timer for bypass frequency */ - PLLCR &= ~1; /* Bypass mode */ - timers_adjust_prescale(CPUFREQ_DEFAULT_MULT, false); - PLLCR = 0x018ae025 | (PLLCR & 0x70400000); - CSCR0 = 0x00001180; /* Flash: 4 wait states */ - CSCR3 = 0x00000980; /* LCD: 2 wait states */ - while(!(PLLCR & 0x80000000)) {}; /* Wait until the PLL has locked. - This may take up to 10ms! */ - timers_adjust_prescale(CPUFREQ_MAX_MULT, true); - DCR = (0x8200 | MAX_REFRESH_TIMER); /* Refresh timer */ - cpu_frequency = CPUFREQ_MAX; - IDECONFIG1 = (1<<28)|(1<<20)|(1<<18)|(1<<13)|(3<<10); - /* BUFEN2 enable on /CS2 | CS2Post 1 clock| CS2Pre 3 clocks*/ - IDECONFIG2 = (1<<18)|(1<<16)|(1<<8)|(1<<0); /* TA /CS2 enable + CS2wait */ - - and_l(~(0x07<<16), &ADCONFIG); - or_l((0x05)<<16, &ADCONFIG); /* adclk = busclk/32 */ - break; - - case CPUFREQ_NORMAL: - DCR = (DCR & ~0x01ff) | DEFAULT_REFRESH_TIMER; - /* Refresh timer for bypass frequency */ - PLLCR &= ~1; /* Bypass mode */ - timers_adjust_prescale(CPUFREQ_DEFAULT_MULT, false); - PLLCR = 0x0589e021 | (PLLCR & 0x70400000); - CSCR0 = 0x00000580; /* Flash: 1 wait state */ - CSCR3 = 0x00000580; /* LCD: 1 wait state */ - while(!(PLLCR & 0x80000000)) {}; /* Wait until the PLL has locked. - This may take up to 10ms! */ - timers_adjust_prescale(CPUFREQ_NORMAL_MULT, true); - DCR = (0x8000 | NORMAL_REFRESH_TIMER); /* Refresh timer */ - cpu_frequency = CPUFREQ_NORMAL; - IDECONFIG1 = (1<<28)|(1<<20)|(1<<18)|(1<<13)|(1<<10); - IDECONFIG2 = (1<<18)|(1<<16); - - and_l(~(0x07<<16), &ADCONFIG); - or_l((0x03)<<16, &ADCONFIG); /* adclk = busclk/8 */ - break; - - default: - DCR = (DCR & ~0x01ff) | DEFAULT_REFRESH_TIMER; - /* Refresh timer for bypass frequency */ - PLLCR &= ~1; /* Bypass mode */ - timers_adjust_prescale(CPUFREQ_DEFAULT_MULT, true); - /* Power down PLL, but keep CLSEL and CRSEL */ - PLLCR = 0x00800200 | (PLLCR & 0x70400000); - CSCR0 = 0x00000180; /* Flash: 0 wait states */ - CSCR3 = 0x00000180; /* LCD: 0 wait states */ - DCR = (0x8000 | DEFAULT_REFRESH_TIMER); /* Refresh timer */ - cpu_frequency = CPUFREQ_DEFAULT; - IDECONFIG1 = (1<<28)|(1<<20)|(1<<18)|(1<<13)|(1<<10); - IDECONFIG2 = (1<<18)|(1<<16); - - and_l(~(0x07<<16), &ADCONFIG); - or_l((0x01)<<16, &ADCONFIG); /* adclk = busclk/2 */ - break; - } -} diff --git a/firmware/target/coldfire/mpio/hd200/usb-hd200.c b/firmware/target/coldfire/mpio/hd200/usb-hd200.c deleted file mode 100644 index a8c3db85bd..0000000000 --- a/firmware/target/coldfire/mpio/hd200/usb-hd200.c +++ /dev/null @@ -1,75 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2010 Marcin Bukat - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - ****************************************************************************/ -#include "config.h" -#include -#include "cpu.h" -#include "system.h" -#include "kernel.h" -#include "usb.h" - -void usb_init_device(void) -{ - /* GPIO42 is USB detect input - * but it also serves as MCLK2 for DAC - */ - and_l(~(1<<4), &GPIO1_OUT); /* GPIO36 low */ - or_l((1<<4), &GPIO1_ENABLE); /* GPIO36 */ - or_l((1<<4)|(1<<5), &GPIO1_FUNCTION); /* GPIO36 GPIO37 */ - - /* GPIO22 GPIO30 high */ - or_l((1<<22)|(1<<30), &GPIO_OUT); - or_l((1<<22)|(1<<30), &GPIO_ENABLE); - or_l((1<<22)|(1<<30), &GPIO_FUNCTION); -} - -int usb_detect(void) -{ - /* GPIO42 active low*/ - return (GPIO1_READ & (1<<10)) ? USB_EXTRACTED : USB_INSERTED; -} - -void usb_enable(bool on) -{ - /* one second timeout */ - unsigned char timeout = 10; - - if(on) - { - and_l(~(1<<30),&GPIO_OUT); /* GPIO30 low */ - and_l(~(1<<22),&GPIO_OUT); /* GPIO22 low */ - - or_l((1<<4),&GPIO1_OUT); /* GPIO36 high */ - - } - else - { - or_l((1<<22),&GPIO_OUT); /* GPIO22 high */ - or_l((1<<30),&GPIO_OUT); /* GPIO30 high */ - - and_l(~(1<<4),&GPIO1_OUT); /* GPIO36 low */ - - while ( !(GPIO1_READ & (1<<5)) && timeout--) - { - sleep(HZ/10); - } - sleep(HZ); - } -} diff --git a/firmware/target/coldfire/mpio/power-mpio.c b/firmware/target/coldfire/mpio/power-mpio.c new file mode 100644 index 0000000000..3034bab82d --- /dev/null +++ b/firmware/target/coldfire/mpio/power-mpio.c @@ -0,0 +1,130 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2010 Marcin Bukat + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include "config.h" +#include "cpu.h" +#include +#include "kernel.h" +#include "system.h" +#include "lcd.h" +#include "power.h" + +#if CONFIG_TUNER +bool tuner_power(bool status) +{ + if (status) + and_l(~(1<<17), &GPIO1_OUT); + else + or_l((1<<17), &GPIO1_OUT); + + return status; +} +#endif /* #if CONFIG_TUNER */ + +void power_init(void) +{ + /* GPIO53 has to be high - low resets device + * it is setup in crt0.S + */ + + /* GPIO50 is ATA power (default OFF) */ + or_l((1<<18), &GPIO1_OUT); + or_l((1<<18), &GPIO1_ENABLE); + or_l((1<<18), &GPIO1_FUNCTION); + + /* GPIO49 is FM power (default OFF) */ + or_l((1<<17), &GPIO1_OUT); + or_l((1<<17), &GPIO1_ENABLE); + or_l((1<<17), &GPIO1_FUNCTION); + + /* GPIO46 is wall charger detect (input) */ + and_l(~(1<<14), &GPIO1_ENABLE); + or_l((1<<14), &GPIO1_FUNCTION); + + /* GPIO31 needs to be low */ + and_l(~(1<<31), &GPIO_OUT); + or_l((1<<31),&GPIO_ENABLE); + or_l((1<<31),&GPIO_FUNCTION); + + /* turn off charger by default*/ + or_l((1<<23), &GPIO_OUT); + or_l((1<<23), &GPIO_ENABLE); + or_l((1<<23), &GPIO_FUNCTION); + + /* high current charge mode */ + or_l((1<<15), &GPIO_OUT); + or_l((1<<15),&GPIO_ENABLE); + or_l((1<<15),&GPIO_FUNCTION); + +#ifndef BOOTLOADER + /* The boot loader controls the power */ + ide_power_enable(true); +#endif +} + +unsigned int power_input_status(void) +{ + unsigned int status = POWER_INPUT_NONE; +/* GPIO46 is AC plug detect (low = AC plugged) */ + if (!(GPIO1_READ & (1<<14))) + { + status |= POWER_INPUT_MAIN_CHARGER; + /* tristate GPIO23 to start charging cycle */ + and_l(~(1<<23), &GPIO_ENABLE); + } + else + { + /* drive GPIO23 high to enter LTC1733 shutdown mode */ + or_l((1<<23), &GPIO_ENABLE); + } + return status; +} + +/* Returns true if the unit is charging the batteries. */ +bool charging_state(void) +{ + if (!(GPIO1_READ & (1<<14))) + return (GPIO_READ & (1<<30) )?false:true; + else + return false; +} + +void ide_power_enable(bool on) +{ + if (on) + and_l(~(1<<18),&GPIO1_OUT); + else + or_l((1<<18),&GPIO1_OUT); +} + +bool ide_powered(void) +{ + return (GPIO1_OUT & (1<<18))?false:true; +} + +void power_off(void) +{ + lcd_shutdown(); + set_irq_level(DISABLE_INTERRUPTS); + and_l(~(1<<21), &GPIO1_OUT); /* pull KEEPACT low */ + asm("halt"); + while(1); +} diff --git a/firmware/target/coldfire/mpio/system-mpio.c b/firmware/target/coldfire/mpio/system-mpio.c new file mode 100644 index 0000000000..0bd0e07386 --- /dev/null +++ b/firmware/target/coldfire/mpio/system-mpio.c @@ -0,0 +1,125 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2010 by Marcin Bukat + * Copyright (C) 2006 by Linus Nielsen Feltzing + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#include "config.h" +#include "cpu.h" +#include "kernel.h" +#include "system.h" +#include "power.h" +#include "timer.h" + +/* Settings for all possible clock frequencies (with properly working timers) + * NOTE: Some 5249 chips don't like having PLLDIV set to 0. We must avoid that! + * + * xxx_REFRESH_TIMER below + * system.h, CPUFREQ_xxx_MULT | + * | | + * V V + * PLLCR & Refreshtim. IDECONFIG1/IDECONFIG2 + * CPUCLK/Hz MULT ~0x70400000 16MB 32MB CSCR0 CSCR1 CSCR3 CS2Pre CS2Post CS2Wait + * --------------------------------------------------------------------------------------- + * 11289600 1 0x00800200 4 1 0x0180 0x0180 0x0180 1 1 0 + * 22579200 2 0x0589e025 10 4 0x0180 0x0180 0x0180 1 1 0 + * 33868800 3 0x0388e025 15 7 0x0180 0x0180 0x0180 1 1 0 + * 45158400 4 0x0589e021 21 10 0x0580 0x0180 0x0580 1 1 0 + * 56448000 5 0x0289e025 26 12 0x0580 0x0580 0x0980 2 1 0 + * 67737600 6 0x0388e021 32 15 0x0980 0x0980 0x0d80 2 1 0 + * 79027200 7 0x038a6021 37 18 0x0980 0x0d80 0x1180 2 1 0 + * 90316800 8 0x038be021 43 21 0x0d80 0x0d80 0x1580 2 1 0 + * 101606400 9 0x01892025 48 23 0x0d80 0x1180 0x1980 2 1 0 + * 112896000 10 0x0189e025 54 26 0x1180 0x1580 0x1d80 3 1 0 + * 124185600 11 0x018ae025 59 29 0x1180 0x1580 0x2180 3 1 1 + */ + +#define MAX_REFRESH_TIMER 59 +#define NORMAL_REFRESH_TIMER 21 +#define DEFAULT_REFRESH_TIMER 4 + +#ifdef HAVE_ADJUSTABLE_CPU_FREQ +void set_cpu_frequency (long) __attribute__ ((section (".icode"))); +void set_cpu_frequency(long frequency) +#else +void cf_set_cpu_frequency (long) __attribute__ ((section (".icode"))); +void cf_set_cpu_frequency(long frequency) +#endif +{ + switch(frequency) + { + case CPUFREQ_MAX: + DCR = (0x8200 | DEFAULT_REFRESH_TIMER); + /* Refresh timer for bypass frequency */ + PLLCR &= ~1; /* Bypass mode */ + timers_adjust_prescale(CPUFREQ_DEFAULT_MULT, false); + PLLCR = 0x018ae025 | (PLLCR & 0x70400000); + CSCR0 = 0x00001180; /* Flash: 4 wait states */ + CSCR3 = 0x00000980; /* LCD: 2 wait states */ + while(!(PLLCR & 0x80000000)) {}; /* Wait until the PLL has locked. + This may take up to 10ms! */ + timers_adjust_prescale(CPUFREQ_MAX_MULT, true); + DCR = (0x8200 | MAX_REFRESH_TIMER); /* Refresh timer */ + cpu_frequency = CPUFREQ_MAX; + IDECONFIG1 = (1<<28)|(1<<20)|(1<<18)|(1<<13)|(3<<10); + /* BUFEN2 enable on /CS2 | CS2Post 1 clock| CS2Pre 3 clocks*/ + IDECONFIG2 = (1<<18)|(1<<16)|(1<<8)|(1<<0); /* TA /CS2 enable + CS2wait */ + + and_l(~(0x07<<16), &ADCONFIG); + or_l((0x05)<<16, &ADCONFIG); /* adclk = busclk/32 */ + break; + + case CPUFREQ_NORMAL: + DCR = (DCR & ~0x01ff) | DEFAULT_REFRESH_TIMER; + /* Refresh timer for bypass frequency */ + PLLCR &= ~1; /* Bypass mode */ + timers_adjust_prescale(CPUFREQ_DEFAULT_MULT, false); + PLLCR = 0x0589e021 | (PLLCR & 0x70400000); + CSCR0 = 0x00000580; /* Flash: 1 wait state */ + CSCR3 = 0x00000580; /* LCD: 1 wait state */ + while(!(PLLCR & 0x80000000)) {}; /* Wait until the PLL has locked. + This may take up to 10ms! */ + timers_adjust_prescale(CPUFREQ_NORMAL_MULT, true); + DCR = (0x8000 | NORMAL_REFRESH_TIMER); /* Refresh timer */ + cpu_frequency = CPUFREQ_NORMAL; + IDECONFIG1 = (1<<28)|(1<<20)|(1<<18)|(1<<13)|(1<<10); + IDECONFIG2 = (1<<18)|(1<<16); + + and_l(~(0x07<<16), &ADCONFIG); + or_l((0x03)<<16, &ADCONFIG); /* adclk = busclk/8 */ + break; + + default: + DCR = (DCR & ~0x01ff) | DEFAULT_REFRESH_TIMER; + /* Refresh timer for bypass frequency */ + PLLCR &= ~1; /* Bypass mode */ + timers_adjust_prescale(CPUFREQ_DEFAULT_MULT, true); + /* Power down PLL, but keep CLSEL and CRSEL */ + PLLCR = 0x00800200 | (PLLCR & 0x70400000); + CSCR0 = 0x00000180; /* Flash: 0 wait states */ + CSCR3 = 0x00000180; /* LCD: 0 wait states */ + DCR = (0x8000 | DEFAULT_REFRESH_TIMER); /* Refresh timer */ + cpu_frequency = CPUFREQ_DEFAULT; + IDECONFIG1 = (1<<28)|(1<<20)|(1<<18)|(1<<13)|(1<<10); + IDECONFIG2 = (1<<18)|(1<<16); + + and_l(~(0x07<<16), &ADCONFIG); + or_l((0x01)<<16, &ADCONFIG); /* adclk = busclk/2 */ + break; + } +} diff --git a/firmware/target/coldfire/mpio/usb-mpio.c b/firmware/target/coldfire/mpio/usb-mpio.c new file mode 100644 index 0000000000..a8c3db85bd --- /dev/null +++ b/firmware/target/coldfire/mpio/usb-mpio.c @@ -0,0 +1,75 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2010 Marcin Bukat + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#include "config.h" +#include +#include "cpu.h" +#include "system.h" +#include "kernel.h" +#include "usb.h" + +void usb_init_device(void) +{ + /* GPIO42 is USB detect input + * but it also serves as MCLK2 for DAC + */ + and_l(~(1<<4), &GPIO1_OUT); /* GPIO36 low */ + or_l((1<<4), &GPIO1_ENABLE); /* GPIO36 */ + or_l((1<<4)|(1<<5), &GPIO1_FUNCTION); /* GPIO36 GPIO37 */ + + /* GPIO22 GPIO30 high */ + or_l((1<<22)|(1<<30), &GPIO_OUT); + or_l((1<<22)|(1<<30), &GPIO_ENABLE); + or_l((1<<22)|(1<<30), &GPIO_FUNCTION); +} + +int usb_detect(void) +{ + /* GPIO42 active low*/ + return (GPIO1_READ & (1<<10)) ? USB_EXTRACTED : USB_INSERTED; +} + +void usb_enable(bool on) +{ + /* one second timeout */ + unsigned char timeout = 10; + + if(on) + { + and_l(~(1<<30),&GPIO_OUT); /* GPIO30 low */ + and_l(~(1<<22),&GPIO_OUT); /* GPIO22 low */ + + or_l((1<<4),&GPIO1_OUT); /* GPIO36 high */ + + } + else + { + or_l((1<<22),&GPIO_OUT); /* GPIO22 high */ + or_l((1<<30),&GPIO_OUT); /* GPIO30 high */ + + and_l(~(1<<4),&GPIO1_OUT); /* GPIO36 low */ + + while ( !(GPIO1_READ & (1<<5)) && timeout--) + { + sleep(HZ/10); + } + sleep(HZ); + } +} -- cgit v1.2.3