2018-05-01 06:15:48 +01:00
|
|
|
/*
|
2018-08-05 12:40:32 +01:00
|
|
|
* Copyright (c) 2018 naehrwert
|
2019-10-18 16:02:06 +01:00
|
|
|
* Copyright (c) 2018 CTCaer
|
2018-08-05 12:40:32 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2018-05-01 06:15:48 +01:00
|
|
|
|
|
|
|
#ifndef _SDMMC_H_
|
|
|
|
#define _SDMMC_H_
|
|
|
|
|
2020-06-14 14:45:45 +01:00
|
|
|
#include <utils/types.h>
|
|
|
|
#include <storage/sdmmc_driver.h>
|
2018-05-01 06:15:48 +01:00
|
|
|
|
2020-05-08 23:32:44 +01:00
|
|
|
extern u32 sd_power_cycle_time_start;
|
2019-09-12 21:08:38 +01:00
|
|
|
|
2020-04-29 19:43:07 +01:00
|
|
|
typedef enum _sdmmc_type
|
|
|
|
{
|
|
|
|
MMC_SD = 0,
|
|
|
|
MMC_EMMC = 1,
|
|
|
|
|
|
|
|
EMMC_GPP = 0,
|
|
|
|
EMMC_BOOT0 = 1,
|
|
|
|
EMMC_BOOT1 = 2
|
|
|
|
} sdmmc_type;
|
|
|
|
|
2018-05-13 23:28:27 +01:00
|
|
|
typedef struct _mmc_cid
|
|
|
|
{
|
|
|
|
u32 manfid;
|
|
|
|
u8 prod_name[8];
|
|
|
|
u8 card_bga;
|
|
|
|
u8 prv;
|
|
|
|
u32 serial;
|
|
|
|
u16 oemid;
|
|
|
|
u16 year;
|
|
|
|
u8 hwrev;
|
|
|
|
u8 fwrev;
|
|
|
|
u8 month;
|
|
|
|
} mmc_cid_t;
|
|
|
|
|
|
|
|
typedef struct _mmc_csd
|
|
|
|
{
|
2018-05-15 18:17:56 +01:00
|
|
|
u8 structure;
|
|
|
|
u8 mmca_vsn;
|
|
|
|
u16 cmdclass;
|
|
|
|
u32 c_size;
|
|
|
|
u32 r2w_factor;
|
|
|
|
u32 max_dtr;
|
|
|
|
u32 erase_size; /* In sectors */
|
|
|
|
u32 read_blkbits;
|
|
|
|
u32 write_blkbits;
|
|
|
|
u32 capacity;
|
2019-04-14 00:19:04 +01:00
|
|
|
u8 write_protect;
|
2018-06-23 04:45:29 +01:00
|
|
|
u16 busspeed;
|
2018-05-13 23:28:27 +01:00
|
|
|
} mmc_csd_t;
|
|
|
|
|
|
|
|
typedef struct _mmc_ext_csd
|
|
|
|
{
|
|
|
|
u32 sectors;
|
|
|
|
int bkops; /* background support bit */
|
|
|
|
int bkops_en; /* manual bkops enable bit */
|
2020-08-15 11:16:37 +01:00
|
|
|
u8 rev;
|
2018-05-13 23:28:27 +01:00
|
|
|
u8 ext_struct; /* 194 */
|
|
|
|
u8 card_type; /* 196 */
|
|
|
|
u8 bkops_status; /* 246 */
|
2020-08-15 11:16:37 +01:00
|
|
|
u8 pre_eol_info;
|
|
|
|
u8 dev_life_est_a;
|
|
|
|
u8 dev_life_est_b;
|
2018-05-13 23:28:27 +01:00
|
|
|
u8 boot_mult;
|
|
|
|
u8 rpmb_mult;
|
2020-08-15 11:16:37 +01:00
|
|
|
u16 dev_version;
|
2018-05-13 23:28:27 +01:00
|
|
|
} mmc_ext_csd_t;
|
|
|
|
|
|
|
|
typedef struct _sd_scr
|
|
|
|
{
|
|
|
|
u8 sda_vsn;
|
|
|
|
u8 sda_spec3;
|
|
|
|
u8 bus_widths;
|
|
|
|
u8 cmds;
|
|
|
|
} sd_scr_t;
|
|
|
|
|
2018-08-05 12:40:32 +01:00
|
|
|
typedef struct _sd_ssr
|
|
|
|
{
|
2018-05-13 23:28:27 +01:00
|
|
|
u8 bus_width;
|
|
|
|
u8 speed_class;
|
|
|
|
u8 uhs_grade;
|
|
|
|
u8 video_class;
|
|
|
|
u8 app_class;
|
2020-07-17 15:01:40 +01:00
|
|
|
u32 protected_size;
|
2018-05-13 23:28:27 +01:00
|
|
|
} sd_ssr_t;
|
|
|
|
|
2018-05-01 06:15:48 +01:00
|
|
|
/*! SDMMC storage context. */
|
|
|
|
typedef struct _sdmmc_storage_t
|
|
|
|
{
|
|
|
|
sdmmc_t *sdmmc;
|
|
|
|
u32 rca;
|
|
|
|
int has_sector_access;
|
|
|
|
u32 sec_cnt;
|
|
|
|
int is_low_voltage;
|
|
|
|
u32 partition;
|
2018-05-13 23:28:27 +01:00
|
|
|
u8 raw_cid[0x10];
|
|
|
|
u8 raw_csd[0x10];
|
|
|
|
u8 raw_scr[8];
|
|
|
|
u8 raw_ssr[0x40];
|
|
|
|
mmc_cid_t cid;
|
|
|
|
mmc_csd_t csd;
|
|
|
|
mmc_ext_csd_t ext_csd;
|
|
|
|
sd_scr_t scr;
|
|
|
|
sd_ssr_t ssr;
|
2018-05-01 06:15:48 +01:00
|
|
|
} sdmmc_storage_t;
|
|
|
|
|
|
|
|
int sdmmc_storage_end(sdmmc_storage_t *storage);
|
|
|
|
int sdmmc_storage_read(sdmmc_storage_t *storage, u32 sector, u32 num_sectors, void *buf);
|
|
|
|
int sdmmc_storage_write(sdmmc_storage_t *storage, u32 sector, u32 num_sectors, void *buf);
|
2020-04-29 16:53:29 +01:00
|
|
|
int sdmmc_storage_init_mmc(sdmmc_storage_t *storage, sdmmc_t *sdmmc, u32 bus_width, u32 type);
|
2018-05-01 06:15:48 +01:00
|
|
|
int sdmmc_storage_set_mmc_partition(sdmmc_storage_t *storage, u32 partition);
|
2019-08-28 00:39:43 +01:00
|
|
|
void sdmmc_storage_init_wait_sd();
|
2020-04-29 16:53:29 +01:00
|
|
|
int sdmmc_storage_init_sd(sdmmc_storage_t *storage, sdmmc_t *sdmmc, u32 bus_width, u32 type);
|
2018-05-01 06:15:48 +01:00
|
|
|
int sdmmc_storage_init_gc(sdmmc_storage_t *storage, sdmmc_t *sdmmc);
|
|
|
|
|
|
|
|
#endif
|