rendered paste body/*************************************************************************** * __________ __ ___. * Open \______ \ ____ ____ | | _\_ |__ _______ ___ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ * \/ \/ \/ \/ \/ * $Id $ * * Copyright (C) 2006,2007 by Marcoen Hirschberg * * All files in this archive are subject to the GNU General Public License. * See the file COPYING in the source tree root for full license agreement. * * 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 "thread.h"#include "system.h"#include "power.h"#include "panic.h"#include "pcf50606.h"#include "ata-target.h"#include "mmu-imx31.h"#include "backlight-target.h"#include "system-imx31.h"#define INTERRUPT_PENDING (*(volatile long*)0x43F8C024)#define DMA_PENDING (1 << 3)#define CONTROLLER_IDLE (1 << 4)#define ATA_RST (1 << 6)void ata_reset(void){ ATA_CONTROL &= ~ATA_RST; sleep(1); ATA_CONTROL |= ATA_RST; sleep(1);}/* This function is called before enabling the USB bus */void ata_enable(bool on){ (void)on;}bool ata_is_coldstart(void){ return 0;}unsigned long mxc_clock_ckih(void) { return 27000000;}unsigned long get_pll(bool serial) { unsigned long mfi, mfn, mfd, pdf, ref_clk; unsigned long reg = 0, ccmr; unsigned long long temp; unsigned int prcs; ccmr = *((unsigned long*)0x53F80000); prcs == (ccmr & 0x6) >> 1; if(prcs == 0x1) { ref_clk = 32768 * 1024; } else { ref_clk = mxc_clock_ckih(); } if(serial) { reg = *((unsigned long*)0x53F80018); } else { if((ccmr & 0x8) == 0) return ref_clk; if((ccmr & 0x80) != 0) return ref_clk; reg = *((unsigned long*)0x53F80010); } pdf = (reg & (0x7 << 26)) >> 26; mfd = (reg & (0x3FF << 16)) >> 16; mfi = (reg & (0xF << 10)) >> 10; mfi = (mfi <= 5) ? 5 : mfi; mfn = (reg & 0x3FF); if(mfn < 0x200) { temp = (unsigned long long)2 *ref_clk * mfn; temp /= (mfd + 1); temp = (unsigned long long)2 *ref_clk * mfi + temp; temp /= (pdf + 1); } else { temp = (unsigned long long)2 *ref_clk * (0x400 - mfn); temp /= (mfd + 1); temp = (unsigned long long)2 *ref_clk * mfi - temp; temp /= (pdf + 1); } return (unsigned long)temp;}unsigned long get_ata_clock(void) { unsigned long pll, ret_val, hclk, max_pdf, ipg_pdf; max_pdf = (*((unsigned long*)0x53F80004))& 0x7; ipg_pdf = ((*((unsigned long*)0x53F80004))& 0x38) >> 3; if(((*((unsigned long*)0x53F8005C))&0xC0000000 ) == 0) { pll = get_pll(true); } else { pll = get_pll(false); } return ret_val;}void ata_device_init(void){ ATA_CONTROL |= ATA_RST; /* Make sure we're not in reset mode */ int T = 1000 * 1000 * 1000 / get_ata_clock(); TIME_OFF = 3; TIME_ON = 3; TIME_1 = (T + 70)/T; TIME_2W = (T + 290)/T; TIME_2R = (T + 290)/T; TIME_AX = (T + 50)/T; TIME_PIO_RDX = 1; TIME_4 = (T + 30)/T; TIME_9 = (T + 20)/T;}