📄 bbu_mmc.s
字号:
;*********************************************************************************
;
; COPYRIGHT (C) 2006-2007 Marvell International Ltd. All Rights Reserved.
;
; The information in this file is furnished for informational use only,
; is subject to change without notice, and should not be construed as
; a commitment by Marvell. Marvell assumes no responsibility or liability
; for any errors or inaccuracies that may appear in this software or any
; documenation that may be provided in association with this software.
;
;*********************************************************************************
;
; BBU_MMC.s
; Source file for code that deals with the MultiMedia Card interface
;
; Include files
;
INCLUDE xlli_PXA3xx_defs.inc ; xlli Monahans defs
INCLUDE xlli_Platform_defs.inc ; Littleton Platform defs
INCLUDE bbu_Monahans_defs.inc ; BBU Monahans defs
INCLUDE bbu_Littleton_defs.inc ; Littleton specific defs
;
; External references
;
EXTERN xlli_MFPR_offset_table ; Address of offset table
EXTERN BBU_msWait ; BBU delay routine
EXTERN BBU_tickWait ; Tick Wait routine
EXTERN BBU_puthexd
EXTERN BBU_crlf
EXTERN BBU_ibuf ; BBU's input buffer
;
; Globals
;
GLOBAL BBU_MMC_Init ; MMC interface init code for BBU
GLOBAL BBU_MMC_ID ; Inits am MMC card
GLOBAL BBU_MMC_Cmd ; Sends commands to MMC card
GLOBAL BBU_MMC_Read ; Read a block of data from a MMC/SD card
GLOBAL BBU_MMC_Erase ; Erase a block of data from the MMC
GLOBAL BBU_MMC_Write ; Write a block of data to the MMC
GLOBAL BBU_RCA ; SD/MMC card relative address
GLOBAL BBU_MMC_FREQ ; Maximum card frequency
GLOBAL BBU_MMC_EGS ; SD/MMC Erase Group Size
;
; Definitions used in this file (MFPR setup) GPIO number shifted left 1 bit
;
MFPR_MMC_DAT0 EQU 3<<1 ; MMC Data<0>
MFPR_MMC_DAT1 EQU 4<<1 ; MMC Data<1>
MFPR_MMC_DAT2 EQU 5<<1 ; MMC Data<2>
MFPR_MMC_DAT3 EQU 6<<1 ; MMC Data<3>
MFPR_MMC_CLK EQU 7<<1 ; MMC Clock
MFPR_MMC_CMD EQU 8<<1 ; MMC CMD<0>
;
; MMC register offsets
;
BBU_MMC_STRPCL_offset EQU 0x00 ; Offset to MMC Clock start/stop register
BBU_MMC_STAT_offset EQU 0x04 ; Offset to MMC status register
BBU_MMC_CLKRT_offset EQU 0x08 ; Offset to MMC clock rate register
BBU_MMC_CMDAT_offset EQU 0x10 ; Offset to Command sequence register
BBU_MMC_RESTO_offset EQU 0x14 ; Offest to command response time out register
BBU_MMC_BLKLEN_offset EQU 0x1C ; Offset to block length register
BBU_MMC_NUMBLK_offset EQU 0x20 ; Offset to number of blocks to be transfered
BBU_MMC_I_REG_offset EQU 0x2C ; Offset to interrupt status register
BBU_MMC_CMD_offset EQU 0x30 ; Offset to MMC CMD register
BBU_MMC_ARGH_offset EQU 0x34 ; Offset to MMC command argument register MSW
BBU_MMC_ARGL_offset EQU 0x38 ; Offset to MMC command argument register LSW
BBU_MMC_RES_FIFO_offset EQU 0x3C ; Offset to command response FIFO
BBU_MMC_RXFIFO_offset EQU 0x40 ; Offset to receive register for MMC
BBU_MMC_TXFIFO_offset EQU 0x44 ; Offset to transment register for MMC
;
; MMC register bit settings
;
BBU_stop_clk EQU 0x00000001 ; Stop clock bit
BBU_strt_clk EQU 0x00000002 ; Start clock bit
BBU_clk_en EQU 0x00000100 ; Clock enable bit
BBU_MMC_CMDAT_init EQU 0x00000040 ; Controller init bit.
BBU_MMC_CMDAT_wr_rd EQU 0x00000008 ; Write / Read bit (0b1 = write)
BBU_data_tran_done EQU 0x00000001 ; Data transmission / time out complete
BBU_rxfifo_rd_req EQU 0x00000020 ; Read FIFO request bit
BBU_end_cmd_res EQU 0x00002000 ; End Command Response bit
BBU_dat_err EQU 0x00000100 ; Data error bit
BBU_time_out_res EQU 0x00000002 ; result time out bit
BBU_MMC_RD_REQ EQU 0x00000020 ; Read request in MMC_I_REG
BBU_MMC_WR_REQ EQU 0x00000040 ; Write request in MMC_I_REG
BBU_MMC_TINT EQU 0x00000080 ; Time out interrupt in MMC_I_REG
AREA |text|,CODE,READONLY,ALIGN=5
;
;*********************************************************************************
;
; ****************
; * *
; * BBU_MMC_Init *
; * *
; ****************
;
; This subroutine initalizes the MultiMedia Card interface to the Monahans/
; Littleton platform
;
; PARAMETER PASSING:
;
; INPUT:
; r0 = 0 to init MMC interface #0
; r0 = 2 to init MMC interface #2
;
; OUTPUT:
; none
;
; NOTES:
;
; Card detect lines are not sensed.
;
;
BBU_MMC_Init FUNCTION
stmfd sp!, {r1-r6, lr} ; Save used registers
;
; Enable MMC Controller Clocks
;
ldr r3, =xlli_CLKREGS_PHYSICAL_BASE ; Base address of clock unit
ldr r2, [r3, #xlli_D0CKEN_A_offset] ; Get current setting of clock enable register
orr r2, r2, #0x3000 ; Set bits 12 & 13 (MMC1 & MMC2 Clock Enable)
str r2, [r3, #xlli_D0CKEN_A_offset] ; Write the register back
;
; Initalize the controller
;
cmp r0, #2 ; Init MMC interface #2?
ldreq r1, =BBU_MMC2_PHYSICAL_BASE ; Yes - use this base address
ldrne r1, =BBU_MMC1_PHYSICAL_BASE ; No - use this base address
ldr r4, =BBU_MMC_lastInit ; Addrs where port # is saved
strb r0, [r4] ; Save this value
;
; Stop the clock while setting up registers (it may be stopped already)
;
mov r4, #BBU_stop_clk ; Set the stop clock bit
str r4, [r1, #BBU_MMC_STRPCL_offset] ; Stop the clock
7 ldr r4, [r1, #BBU_MMC_STAT_offset] ; Get the status
ands r4, r4, #BBU_clk_en ; Test the clock enable bit
bne %B7 ; Loop until clock is stopped
;
; Set up the controller
;
mov r3, #0x6 ; Select 304 KHz for "ID clock rate"
str r3, [r1, #BBU_MMC_CLKRT_offset] ; Update clock rate register
mov r2, #0x7F ; Maximum response time
str r2, [r1, #BBU_MMC_RESTO_offset] ; Store in controller register
;
; Clear out extra bits to be set when MMC/SD commands are sent
;
ldr r4, =BBU_MMC_CMDAT_value ; Address of other bits to be set
mov r3, #0 ; Set work register to zero
str r3, [r4] ; Clear this data word
;
; Controller ready for use - Exit path
;
ldmfd sp!, {r1-r6, pc} ; Restore used registers and return to caller
ENDFUNC
;
;*********************************************************************************
;
; **************
; * *
; * BBU_MMC_ID *
; * *
; **************
;
; This subroutine sets up the MMC/SD for communication and data transfer.
; The following steps are taken by this subroutine:
;
; 1) Resets all cards (there is only 1 per bus on Zylonite).
; 2) Request the card's CID data - Places CID ASCII string in BBU's ibuf location.
; 3) Assigns a Relative Card Address (RCA) of 5 to a MMC.
; In the case of a SD card, BBU gets the RCA from the card.
; 4) Fetches the Card Specific Data (CSD) from the MMC/SD and saves it in BBU.
; 5) Calculates the block length and sets up the MMC_BLKLEN register.
; 6) Sets the MMC_NUMBLK register to 1.
; 7) Calculates the number of bytes in the device from data returned in the CSD.
;
; PARAMETER PASSING:
;
; INPUT -
;
; NONE
;
; OUTPUT -
;
; r0 = 0xFF if there was a MMC communication error detected
; r0 = 0x71 if a MMC card was detected.
; r0 = 0x73 if a SD card was detected.
; r1 = size of the device in bytes (calculated from the CSD register)
; BBU_ibuf = NULL terminated Ascii string with manufacturers text
;
BBU_MMC_ID FUNCTION
stmfd sp!, {r2-r6, lr} ; Save used registers
;
; CMD00 - GO_IDLE_STATE - Resets all cards to idle state
;
mov r5, #8 ; Set up loop count (DEBUG CODE)
5 mov r0, #0 ; Data to be sent (zero)
mov r1, #0x40 ; Command to be sent (zero) with INIT
ldr r2, =bbu_MiscBuffer ; Address where data goes
bl BBU_MMC_Cmd ; Send out command
cmp r0, #0xFF ; Error detected?
beq %F40 ; Yes - return to caller
mov r0, #0x100 ; Set up for a short delay
bl BBU_tickWait ; Delay
subs r5, r5, #1 ; Decrement loop count
bne %B5 ; Loop until zero
;
; Send out CMD01 until ready bit is set (checking for MMC card)
;
mov r3, #0x200 ; loop count - typicially about 50 needed.
10 ldr r0, =0x20000 ; Data to be sent (BC code = 0x20000 - 3.0V)
mov r1, #1 ; Command to be sent (CMD01)
ldr r2, =bbu_MiscBuffer ; Address where data goes
bl BBU_MMC_Cmd ; Send out command
cmp r0, #0xFF ; Error detected?
beq %F12 ; Yes - Check for SD card
mov r6, #0x71 ; Set return indicator to "MMC" card type
mov r0, #0x1 ; Set up for a short delay
bl BBU_msWait ; Delay r0 milliseconds
ldr r2, =bbu_MiscBuffer ; Address where data was sent
ldr r4, [r2] ; Fetch data
ands r4, r4, #0x80 ; is bit 7 set? (this is really bit 31 of the OCR)
bne %F20 ; Yes - Continue the init process
subs r3, r3, #1 ; decrement loop count
bne %B10 ; loop until zero
mov r0, #0xFF ; Indicate error
b %F40 ; ...and take the exit path
;
; No MMC card detected - check for the presence of a SD card in the slot.
;
; Code jumps here if error on sending the CMD01 command. Either there was
; no MMC card in the slot or there is a SD card present. Check to see if
; we get a response from the ACMD41 command. This is done by sending the
; APP_CMD (CMD55) command followed by CMD41 (The two commands put together
; generate the ACMD41 command).
;
12 mov r3, #0x200 ; Set up loop counter
14 mov r0, #0 ; No data
mov r1, #55 ; APP_CMD Command (CMD055)
ldr r2, =bbu_MiscBuffer ; Address where data goes
bl BBU_MMC_Cmd ; Send out command
cmp r0, #0xFF ; Error detected?
beq %F40 ; Yes - return to caller
ldr r0, =0x00020000 ; Data to be sent (BC code = 0x20000)
mov r1, #41 ; ACMD41 Command (CMD055 + CMD41)
ldr r2, =bbu_MiscBuffer ; Address where data goes
bl BBU_MMC_Cmd ; Send out command
cmp r0, #0xFF ; Error detected?
beq %F40 ; Yes - return to caller
mov r6, #0x73 ; Set return indicator to "SD" card type
mov r0, #0x1 ; Set up for a short delay
bl BBU_msWait ; Delay r0 milliseconds
ldr r2, =bbu_MiscBuffer ; Address where data was sent
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -