blob: eec7f73436ccf03a811d67c69376c652e9847903 [file] [log] [blame]
Bo Lv72d0e902023-01-02 14:27:34 +00001/* SPDX-License-Identifier: (GPL-2.0+ OR MIT) */
2/*
3 * Copyright (c) 2019 Amlogic, Inc. All rights reserved.
4 */
5
6#ifndef __AML_MMC_H__
7#define __AML_MMC_H__
8
9#include <common.h>
10#include <mmc.h>
jinbiao5da7d892024-05-13 12:19:47 +000011#include "emmc_partitions.h"
Bo Lv72d0e902023-01-02 14:27:34 +000012
Ruixuan.lib5755732024-02-01 16:01:14 +080013/*mmc.h*/
14#define NO_CARD_ERR -16
15#define UNUSABLE_ERR -17
16#define COMM_ERR -18
17#define TIMEOUT -19
18#define IN_PROGRESS -20
19#define SWITCH_ERR -21
20
jinbiao48315772024-05-16 05:22:01 +000021#define MESON_SD_EMMC_CALOUT 0x10
22#define MESON_SD_EMMC_ADJ_IDX_LOG 0x20
23#define MESON_SD_EMMC_CLKTEST_LOG 0x24
24#define CLKTEST_TIMES_MASK GENMASK(30, 0)
25#define CLKTEST_DONE BIT(31)
26#define MESON_SD_EMMC_CLKTEST_OUT 0x28
27#define MESON_SD_EMMC_EYETEST_LOG 0x2c
28#define EYETEST_TIMES_MASK GENMASK(30, 0)
29#define EYETEST_DONE BIT(31)
30#define MESON_SD_EMMC_EYETEST_OUT0 0x30
31#define MESON_SD_EMMC_EYETEST_OUT1 0x34
32#define MESON_SD_EMMC_INTF3 0x38
33#define CLKTEST_EXP_MASK GENMASK(4, 0)
34#define CLKTEST_ON_M BIT(5)
35#define EYETEST_EXP_MASK GENMASK(10, 6)
36#define EYETEST_ON BIT(11)
37#define DS_SHT_M_MASK GENMASK(17, 12)
38#define DS_SHT_EXP_MASK GENMASK(21, 18)
39#define SD_INTF3 BIT(22)
40#define EYETEST_SEL BIT(26)
41#define RESP_SEL BIT(27)
42#define CFG_RX_SEL BIT(26)
43#define CFG_RX_PN BIT(27)
44#define RESP_OLD BIT(28)
45#define RESP_PN BIT(29)
46#define RESP_DS BIT(30)
47
Ruixuan.lib5755732024-02-01 16:01:14 +080048#define MMC_CMD23
49
50#define MMC_CMD_SET_WRITE_PROTECT 28
51#define MMC_CMD_CLR_WRITE_PROT 29
52#define MMC_CMD_SEND_WRITE_PROT 30
53#define MMC_CMD_SEND_WRITE_PROT_TYPE 31
54#define MMC_SD_HS_TUNING 70
55
56#define MMC_KEY_SIZE (256*1024)
57#define EMMC_KEY_DEV (1)
58
jinbiao1c8ee412024-12-16 16:42:58 +080059/* FFU operation */
60#define SAMSUNG_MID 0x15
61#define KINGSTON_MID 0x70
62#define BIWIN_MID 0xf4
63#define SAMSUNG_FFU_ADDR 0xc7810000
64#define KINGSTON_FFU_ADDR 0x0000ffff
65#define BIWIN_FFU_ADDR 0x0
66
67#define EXT_CSD_CLASS_6_CTRL 59 /*R/W/E_P*/
68#define EXT_CSD_DRIVER_STRENGTH 197 /* RO */
Ruixuan.lib5755732024-02-01 16:01:14 +080069#define EXT_CSD_DEV_LIFETIME_EST_TYP_A 268 /* RO */
70#define EXT_CSD_DEV_LIFETIME_EST_TYP_B 269 /* RO */
jinbiao1c8ee412024-12-16 16:42:58 +080071#define EXT_CSD_SUPPORTED_MODES 493 /* RO */
72#define EXT_CSD_FW_VERSION 254 /* RO, 261:254 */
73#define EXT_CSD_FW_CFG 169 /* R/W */
74#define EXT_CSD_MODE_CFG 30 /* R/W */
75#define EXT_CSD_FFU_STATUS 26 /* RO */
Ruixuan.lib5755732024-02-01 16:01:14 +080076
77#define US_PWR_WP_DIS_BIT 1<<3
78#define US_PERM_WP_DIS_BIT 1<<4
79#define WP_CLEAR_TYPE 0
80#define WP_POWER_ON_TYPE (1<<1)
81#define WP_TEMPORARY_TYPE 1
82#define WP_PERMANENT_TYPE ((1<<0)|(1<<1))
83#define WP_TYPE_MASK 3
84#define WP_ENABLE_MASK 7
85#define WP_TEMPORARY_EN_BIT 0
86#define WP_POWER_ON_EN_BIT (1<<0)
87#define WP_PERM_EN_BIT (1<<2)
88#define WP_GRP_SIZE_MASK 31
89
jinbiaodca5d7c2024-11-05 19:08:30 +080090#define MAX_TUNING_RETRY (4)
91#define CALI_BLK_CNT (1024)
92#define REFIX_BLK_CNT (100)
93#define TUNING_NUM_PER_POINT 40
94#define MMC_MAX_DESC_NUM 512
95#define MAX_RESPONSE_BYTES 4
96#define SD_EMMC_DESC_MAX_BLKS 511
97
Ruixuan.lib5755732024-02-01 16:01:14 +080098#ifndef CONFIG_SYS_MMC_MAX_BLK_COUNT
jinbiaodca5d7c2024-11-05 19:08:30 +080099#define CONFIG_SYS_MMC_MAX_BLK_COUNT (MMC_MAX_DESC_NUM * SD_EMMC_DESC_MAX_BLKS)
Ruixuan.lib5755732024-02-01 16:01:14 +0800100#endif
101/*mmc.h*/
102
Bo Lv72d0e902023-01-02 14:27:34 +0000103/* bootloader operation */
104#define AML_BL_USER (0x1 << 0)
105#define AML_BL_BOOT0 (0x1 << 1)
106#define AML_BL_BOOT1 (0x1 << 2)
107#define AML_BL_BOOT (0x6)
108#define AML_BL_ALL (0x7)
109
jinbiao48315772024-05-16 05:22:01 +0000110/* delay_cell=70ps, 1ns/delay_cell */
111#define DELAY_CELL_COUNTS 14
112
Bo Lv72d0e902023-01-02 14:27:34 +0000113/** For actually partitions with mask 8 store into bootinfo
114 * name: partition name.
115 * addr: sector addr of the partition
116 * size: sector cont of the partition
117*/
118struct part_property
119{
120 char name[8];
121 uint32_t addr;
122 uint32_t size;
123};
124#define PART_PROPERTY_SIZE sizeof(struct part_property)
125#define BOOTINFO_MAX_PARTITIONS (4)
126#define BOOTINFO_PARTITIONS_SIZE (PART_PROPERTY_SIZE * BOOTINFO_MAX_PARTITIONS)
127
128
129#define VPART_PROPERTY_SIZE sizeof(struct vpart_property)
130struct vpart_property {
131 u32 addr;
132 u32 size;
133};
134
135/*
136 * sizeof(struct storage_emmc_boot_info) is strictly
137 * smaller than or equal to one sector. we will bind
138 * it in one sector with u-boot.bin together and
139 * write into boot loader area.
140 * @rsv_base_addr : the sector address of reserved area
141 * @dtb : the sector address and size of dtb property
142 * @ddr : the sector address and size of ddr property
143 */
144#define EMMC_BOOT_INFO_SIZE 512
145struct storage_emmc_boot_info {
146 u32 version;
147 u32 rsv_base_addr;
148 struct vpart_property dtb;
149 struct vpart_property ddr;
150
151 struct part_property parts[BOOTINFO_MAX_PARTITIONS];
152 uint8_t reserved[512 - 2 * VPART_PROPERTY_SIZE - BOOTINFO_PARTITIONS_SIZE - 12];
153 u32 checksum;
154};
155
Ruixuan.lifd943de2024-01-19 15:48:40 +0800156#define stamp_after(a,b) ((int)(b) - (int)(a) < 0)
157
Bo Lv72d0e902023-01-02 14:27:34 +0000158int amlmmc_write_bootloader(int dev, int map,
159 unsigned int size, const void *src);
160int amlmmc_erase_bootloader(int dev, int map);
161
Bo Lv72d0e902023-01-02 14:27:34 +0000162/* interface on reserved area. */
jinbiao5da7d892024-05-13 12:19:47 +0000163void mmc_write_cali_mattern(void *addr, struct aml_pattern *table);
Bo Lv72d0e902023-01-02 14:27:34 +0000164
165/* dtb operation */
166int dtb_write(void *addr);
167
168/* emmc key operation */
169int mmc_key_read(unsigned char *buf,
170 unsigned int size, uint32_t *actual_length);
171int mmc_key_write(unsigned char *buf,
172 unsigned int size, uint32_t *actual_length);
173int mmc_key_erase(void);
174
175/* partition operation */
176int renew_partition_tbl(unsigned char *buffer);
177int find_dev_num_by_partition_name (char const *name);
178
179#ifdef CONFIG_AML_PARTITION
180int emmc_update_mbr(unsigned char *buffer);
181#endif
182
183/*mmc ext_csd register operation*/
184int mmc_get_ext_csd(struct mmc *mmc, u8 *ext_csd);
185int mmc_set_ext_csd(struct mmc *mmc, u8 index, u8 value);
186
187/* mmc caps quirks */
188int emmc_quirks(void);
189#endif /* __AML_MMC_H__ */