| 
									
										
										
										
											2007-09-16 21:08:06 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2007-04-06 16:49:48 +00:00
										 |  |  |  * SD Memory Card emulation.  Mostly correct for MMC too. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright (c) 2006 Andrzej Zaborowski  <balrog@zabor.org> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Redistribution and use in source and binary forms, with or without | 
					
						
							|  |  |  |  * modification, are permitted provided that the following conditions | 
					
						
							|  |  |  |  * are met: | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * 1. Redistributions of source code must retain the above copyright | 
					
						
							|  |  |  |  *    notice, this list of conditions and the following disclaimer. | 
					
						
							|  |  |  |  * 2. Redistributions in binary form must reproduce the above copyright | 
					
						
							|  |  |  |  *    notice, this list of conditions and the following disclaimer in | 
					
						
							|  |  |  |  *    the documentation and/or other materials provided with the | 
					
						
							|  |  |  |  *    distribution. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' | 
					
						
							|  |  |  |  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | 
					
						
							|  |  |  |  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | 
					
						
							|  |  |  |  * PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR | 
					
						
							|  |  |  |  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 
					
						
							|  |  |  |  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 
					
						
							|  |  |  |  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 
					
						
							|  |  |  |  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 
					
						
							|  |  |  |  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 
					
						
							|  |  |  |  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 
					
						
							|  |  |  |  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | #ifndef __hw_sd_h
 | 
					
						
							|  |  |  | #define __hw_sd_h		1
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define OUT_OF_RANGE		(1 << 31)
 | 
					
						
							|  |  |  | #define ADDRESS_ERROR		(1 << 30)
 | 
					
						
							|  |  |  | #define BLOCK_LEN_ERROR		(1 << 29)
 | 
					
						
							|  |  |  | #define ERASE_SEQ_ERROR		(1 << 28)
 | 
					
						
							|  |  |  | #define ERASE_PARAM		(1 << 27)
 | 
					
						
							|  |  |  | #define WP_VIOLATION		(1 << 26)
 | 
					
						
							|  |  |  | #define CARD_IS_LOCKED		(1 << 25)
 | 
					
						
							|  |  |  | #define LOCK_UNLOCK_FAILED	(1 << 24)
 | 
					
						
							|  |  |  | #define COM_CRC_ERROR		(1 << 23)
 | 
					
						
							|  |  |  | #define ILLEGAL_COMMAND		(1 << 22)
 | 
					
						
							|  |  |  | #define CARD_ECC_FAILED		(1 << 21)
 | 
					
						
							|  |  |  | #define CC_ERROR		(1 << 20)
 | 
					
						
							|  |  |  | #define SD_ERROR		(1 << 19)
 | 
					
						
							|  |  |  | #define CID_CSD_OVERWRITE	(1 << 16)
 | 
					
						
							|  |  |  | #define WP_ERASE_SKIP		(1 << 15)
 | 
					
						
							|  |  |  | #define CARD_ECC_DISABLED	(1 << 14)
 | 
					
						
							|  |  |  | #define ERASE_RESET		(1 << 13)
 | 
					
						
							|  |  |  | #define CURRENT_STATE		(7 << 9)
 | 
					
						
							|  |  |  | #define READY_FOR_DATA		(1 << 8)
 | 
					
						
							|  |  |  | #define APP_CMD			(1 << 5)
 | 
					
						
							|  |  |  | #define AKE_SEQ_ERROR		(1 << 3)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef enum { | 
					
						
							|  |  |  |     sd_none = -1, | 
					
						
							|  |  |  |     sd_bc = 0,	/* broadcast -- no response */ | 
					
						
							| 
									
										
										
										
											2007-07-30 23:54:51 +00:00
										 |  |  |     sd_bcr,	/* broadcast with response */ | 
					
						
							|  |  |  |     sd_ac,	/* addressed -- no data transfer */ | 
					
						
							| 
									
										
										
										
											2007-04-06 16:49:48 +00:00
										 |  |  |     sd_adtc,	/* addressed with data transfer */ | 
					
						
							| 
									
										
										
										
											2009-10-01 16:12:16 -05:00
										 |  |  | } sd_cmd_type_t; | 
					
						
							| 
									
										
										
										
											2007-04-06 16:49:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-10 01:44:56 +01:00
										 |  |  | typedef struct { | 
					
						
							| 
									
										
										
										
											2007-04-06 16:49:48 +00:00
										 |  |  |     uint8_t cmd; | 
					
						
							|  |  |  |     uint32_t arg; | 
					
						
							|  |  |  |     uint8_t crc; | 
					
						
							| 
									
										
										
										
											2009-05-10 01:44:56 +01:00
										 |  |  | } SDRequest; | 
					
						
							| 
									
										
										
										
											2007-04-06 16:49:48 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | typedef struct SDState SDState; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-24 23:35:08 +00:00
										 |  |  | SDState *sd_init(BlockDriverState *bs, int is_spi); | 
					
						
							| 
									
										
										
										
											2009-05-10 01:44:56 +01:00
										 |  |  | int sd_do_command(SDState *sd, SDRequest *req, | 
					
						
							| 
									
										
										
										
											2007-04-06 16:49:48 +00:00
										 |  |  |                   uint8_t *response); | 
					
						
							|  |  |  | void sd_write_data(SDState *sd, uint8_t value); | 
					
						
							|  |  |  | uint8_t sd_read_data(SDState *sd); | 
					
						
							| 
									
										
										
										
											2007-11-17 14:34:44 +00:00
										 |  |  | void sd_set_cb(SDState *sd, qemu_irq readonly, qemu_irq insert); | 
					
						
							| 
									
										
										
										
											2007-04-06 16:49:48 +00:00
										 |  |  | int sd_data_ready(SDState *sd); | 
					
						
							| 
									
										
										
										
											2008-04-14 21:05:22 +00:00
										 |  |  | void sd_enable(SDState *sd, int enable); | 
					
						
							| 
									
										
										
										
											2007-04-06 16:49:48 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #endif	/* __hw_sd_h */
 |