sdram.c

Go to the documentation of this file.
00001 /* ************************************************************************
00002 
00003 Copyright (c) 2006, Atmel Corporation All rights reserved. 
00004 
00005 Redistribution and use in source and binary forms, with or without
00006 modification, are permitted provided that the following conditions are met:
00007 
00008 1. Redistributions of source code must retain the above copyright notice,
00009 this list of conditions and the 
00010 following disclaimer. 
00011 
00012 2. Redistributions in binary form must reproduce the above copyright notice,
00013 this list of conditions and the following disclaimer in the documentation
00014 and/or other materials provided with the distribution.
00015 
00016 3. The name of ATMEL may not be used to endorse or promote products 
00017 derived from this software without specific prior written permission.  
00018 
00019 THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS 
00020 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
00021 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 
00022 PARTICULAR PURPOSE ARE EXPRESSLY AND SPECIFICALLY 
00023 DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
00024 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
00025 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
00026 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
00027 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
00028 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
00029 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY 
00030 WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
00031 
00032 POSSIBILITY OF SUCH DAMAGE. 
00033 
00034 ************************************************************************ */
00035 
00036 #include "sdram.h"
00037 
00038 #define MODE_NORMAL             0
00039 #define MODE_NOP                1
00040 #define MODE_PRECHARGE          2
00041 #define MODE_LOAD_MR            3
00042 #define MODE_AUTOREFRESH        4
00043 #define MODE_EXT_LOAD_MR        5
00044 #define MODE_POWER_DOWN         6
00045 
00046 static void sdram_delay(int us)
00047 {
00048         volatile int i, loop_limit;
00049 
00050         loop_limit = us * 100;
00051         for (i=0; i<loop_limit;i++)
00052                 asm volatile("nop");
00053 
00054 }
00055 
00056 int sdram_init(const sdram_info *info)
00057 {
00058         volatile avr32_sdramc_t *sdram = &AVR32_SDRAMC;
00059         volatile avr32_hmatrix_t *hmatrix = &AVR32_HMATRIX;
00060         volatile avr32_pio_t *pio = &AVR32_PIOE;
00061 
00062         /* Enable SDRAM mode for CS1 in the BAMBI mux */
00063         hmatrix->sfr[AVR32_SDRAMC_HMATRIX_NR] |= 0x0002;
00064         hmatrix->sfr[AVR32_SDRAMC_HMATRIX_NR] |= 0x0100;
00065 
00066         /* Setup SDRAM info */
00067         sdram->cr = ( (info->cols-8) << AVR32_SDRAMC_CR_NC ) |
00068                 ( (info->rows-11) << AVR32_SDRAMC_CR_NR ) |
00069                 ( (info->banks-1) << AVR32_SDRAMC_CR_NB ) |
00070                 ( info->cas << AVR32_SDRAMC_CR_CAS ) |
00071                 ( info->twr << AVR32_SDRAMC_CR_TWR ) |
00072                 ( info->trc << AVR32_SDRAMC_CR_TRC ) |
00073                 ( info->trp << AVR32_SDRAMC_CR_TRP ) |
00074                 ( info->trcd << AVR32_SDRAMC_CR_TRCD ) |
00075                 ( info->tras << AVR32_SDRAMC_CR_TRAS ) |
00076                 ( info->txsr << AVR32_SDRAMC_CR_TXSR );
00077 
00078         if(info->bus_width == 16 ){
00079                 sdram->cr = 1<<AVR32_SDRAMC_CR_DBW_OFFSET;
00080         } else if ( info->bus_width == 32 ) {
00081                 // Initialize data bus bits 31-16 (muxed with the LCDC).
00082                 pio->asr |= 0x0000FFFF;
00083                 pio->pdr |= 0x0000FFFF;
00084         }
00085 
00086         sdram_delay(400);
00087 
00088         return SUCCESS;
00089 }

Generated on Wed May 7 16:03:17 2008 for AVR32114 Using the AVR32 LCD Controller by  doxygen 1.5.3-20071008