change source file mode to 0644 instead of 0755
[profile/mobile/platform/kernel/u-boot-tm1.git] / drivers / mmc / sp8810_mmc.c
1 /*
2  * (C) Copyright 2008
3  * Texas Instruments, <www.ti.com>
4  * Sukumar Ghorai <s-ghorai@ti.com>
5  *
6  * See file CREDITS for list of people who contributed to this
7  * project.
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License as
11  * published by the Free Software Foundation's version 2 of
12  * the License.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22  * MA 02111-1307 USA
23  */
24
25 #include <config.h>
26 #include <common.h>
27 #include <mmc.h>
28 #include <asm/errno.h>
29 #include <part.h>
30 #include <asm/io.h>
31 #include <asm/arch/sc8810_reg_base.h>
32 #include <asm/arch/mfp.h>
33 #include <asm/arch/sc8810_reg_ahb.h>
34 //#include <asm/arch/mmc_host_def.h>
35 #include <asm/arch/ldo.h>
36 #include <asm/arch/sdio_reg_v3.h>
37 #include <asm/arch/chip_drv_common_io.h>
38 #include <asm/arch/sc8810_reg_global.h>
39 #include <asm/arch/sc8810_module_config.h>
40
41
42 #define MMCSD_SECTOR_SIZE 512
43
44
45 #define REG_AHB_CTL0                            (*((volatile unsigned int *)(AHB_CTL0)))
46 #define REG_AHB_SOFT_RST                        (*((volatile unsigned int *)(AHB_SOFT_RST)))
47 #define REG_AHB_SDIO_CTL                        (*((volatile unsigned int *)(AHB_SDIO_CTL)))
48
49
50 SDIO_REG_CFG *mmc_base;
51 static struct mmc_cmd command;
52 static block_dev_desc_t sprd_mmc_dev;
53 static unsigned char mmc_rsp_buf[16];
54
55 block_dev_desc_t *mmc_get_dev(int dev)
56 {
57         return ((block_dev_desc_t *) & sprd_mmc_dev);
58 }
59
60 static unsigned long mmc_bwrite(int dev_num, unsigned long blknr,
61                 lbaint_t blkcnt, void *dst)
62 {
63         if(Emmc_Write(0, blknr, blkcnt, (uint8*)dst))
64         {
65                 return blkcnt;
66         }       
67         else
68         {
69                 return 0;
70         }
71 }
72
73
74 static unsigned long mmc_bread(int dev_num, unsigned long blknr,
75                 lbaint_t blkcnt, void *dst)
76 {
77         if(Emmc_Read(0, blknr, blkcnt, (uint8*)dst))
78         {
79                 return blkcnt;
80         }       
81         else
82         {
83                 return 0;
84         }
85 }
86
87
88 int mmc_legacy_init(int dev)
89 {
90         int retries, rc = -ENODEV;
91         uint32_t cid_resp[4];
92         uint32_t *resp;
93         uint16_t rca = 0;
94
95         if(TRUE == Emmc_Init())
96         {       
97                 sprd_mmc_dev.if_type = IF_TYPE_UNKNOWN;
98                 sprd_mmc_dev.if_type = IF_TYPE_MMC;
99                 sprd_mmc_dev.part_type = PART_TYPE_EFI;
100                 sprd_mmc_dev.dev = 0;
101                 sprd_mmc_dev.lun = 0;
102                 sprd_mmc_dev.type = 0;
103
104                 /* FIXME fill in the correct size (is set to 32MByte) */
105                 sprd_mmc_dev.blksz = MMCSD_SECTOR_SIZE;
106                 
107                 sprd_mmc_dev.lba = Emmc_GetCapacity(0);;
108                 sprd_mmc_dev.removable = 0;
109                 sprd_mmc_dev.block_read = mmc_bread;
110                 sprd_mmc_dev.block_write = mmc_bwrite;                    
111         }
112         return rc;
113 }
114