blob: daf6ec9c6a12618223fa5b7f87855ebb3f001e2d [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
59#define EXT_CSD_CLASS_6_CTRL 59 /*R/W/E_P*/
60#define EXT_CSD_DRIVER_STRENGTH 197 /* RO */
61#define EXT_CSD_DEV_LIFETIME_EST_TYP_A 268 /* RO */
62#define EXT_CSD_DEV_LIFETIME_EST_TYP_B 269 /* RO */
63#define EXT_CSD_SUPPORTED_MODES 493 /* RO */
64#define EXT_CSD_FW_VERSION 254 /* RO, 261:254 */
65#define EXT_CSD_FW_CFG 169 /* R/W */
66#define EXT_CSD_MODE_CFG 30 /* R/W */
67#define EXT_CSD_FFU_STATUS 26 /* RO */
68
69#define US_PWR_WP_DIS_BIT 1<<3
70#define US_PERM_WP_DIS_BIT 1<<4
71#define WP_CLEAR_TYPE 0
72#define WP_POWER_ON_TYPE (1<<1)
73#define WP_TEMPORARY_TYPE 1
74#define WP_PERMANENT_TYPE ((1<<0)|(1<<1))
75#define WP_TYPE_MASK 3
76#define WP_ENABLE_MASK 7
77#define WP_TEMPORARY_EN_BIT 0
78#define WP_POWER_ON_EN_BIT (1<<0)
79#define WP_PERM_EN_BIT (1<<2)
80#define WP_GRP_SIZE_MASK 31
81
jinbiaodca5d7c2024-11-05 19:08:30 +080082#define MAX_TUNING_RETRY (4)
83#define CALI_BLK_CNT (1024)
84#define REFIX_BLK_CNT (100)
85#define TUNING_NUM_PER_POINT 40
86#define MMC_MAX_DESC_NUM 512
87#define MAX_RESPONSE_BYTES 4
88#define SD_EMMC_DESC_MAX_BLKS 511
89
Ruixuan.lib5755732024-02-01 16:01:14 +080090#ifndef CONFIG_SYS_MMC_MAX_BLK_COUNT
jinbiaodca5d7c2024-11-05 19:08:30 +080091#define CONFIG_SYS_MMC_MAX_BLK_COUNT (MMC_MAX_DESC_NUM * SD_EMMC_DESC_MAX_BLKS)
Ruixuan.lib5755732024-02-01 16:01:14 +080092#endif
93/*mmc.h*/
94
Bo Lv72d0e902023-01-02 14:27:34 +000095/* bootloader operation */
96#define AML_BL_USER (0x1 << 0)
97#define AML_BL_BOOT0 (0x1 << 1)
98#define AML_BL_BOOT1 (0x1 << 2)
99#define AML_BL_BOOT (0x6)
100#define AML_BL_ALL (0x7)
101
jinbiao48315772024-05-16 05:22:01 +0000102/* delay_cell=70ps, 1ns/delay_cell */
103#define DELAY_CELL_COUNTS 14
104
Bo Lv72d0e902023-01-02 14:27:34 +0000105/** For actually partitions with mask 8 store into bootinfo
106 * name: partition name.
107 * addr: sector addr of the partition
108 * size: sector cont of the partition
109*/
110struct part_property
111{
112 char name[8];
113 uint32_t addr;
114 uint32_t size;
115};
116#define PART_PROPERTY_SIZE sizeof(struct part_property)
117#define BOOTINFO_MAX_PARTITIONS (4)
118#define BOOTINFO_PARTITIONS_SIZE (PART_PROPERTY_SIZE * BOOTINFO_MAX_PARTITIONS)
119
120
121#define VPART_PROPERTY_SIZE sizeof(struct vpart_property)
122struct vpart_property {
123 u32 addr;
124 u32 size;
125};
126
127/*
128 * sizeof(struct storage_emmc_boot_info) is strictly
129 * smaller than or equal to one sector. we will bind
130 * it in one sector with u-boot.bin together and
131 * write into boot loader area.
132 * @rsv_base_addr : the sector address of reserved area
133 * @dtb : the sector address and size of dtb property
134 * @ddr : the sector address and size of ddr property
135 */
136#define EMMC_BOOT_INFO_SIZE 512
137struct storage_emmc_boot_info {
138 u32 version;
139 u32 rsv_base_addr;
140 struct vpart_property dtb;
141 struct vpart_property ddr;
142
143 struct part_property parts[BOOTINFO_MAX_PARTITIONS];
144 uint8_t reserved[512 - 2 * VPART_PROPERTY_SIZE - BOOTINFO_PARTITIONS_SIZE - 12];
145 u32 checksum;
146};
147
Ruixuan.lifd943de2024-01-19 15:48:40 +0800148#define stamp_after(a,b) ((int)(b) - (int)(a) < 0)
149
Bo Lv72d0e902023-01-02 14:27:34 +0000150int amlmmc_write_bootloader(int dev, int map,
151 unsigned int size, const void *src);
152int amlmmc_erase_bootloader(int dev, int map);
153
Bo Lv72d0e902023-01-02 14:27:34 +0000154/* interface on reserved area. */
jinbiao5da7d892024-05-13 12:19:47 +0000155void mmc_write_cali_mattern(void *addr, struct aml_pattern *table);
Bo Lv72d0e902023-01-02 14:27:34 +0000156
157/* dtb operation */
158int dtb_write(void *addr);
159
160/* emmc key operation */
161int mmc_key_read(unsigned char *buf,
162 unsigned int size, uint32_t *actual_length);
163int mmc_key_write(unsigned char *buf,
164 unsigned int size, uint32_t *actual_length);
165int mmc_key_erase(void);
166
167/* partition operation */
168int renew_partition_tbl(unsigned char *buffer);
169int find_dev_num_by_partition_name (char const *name);
170
171#ifdef CONFIG_AML_PARTITION
172int emmc_update_mbr(unsigned char *buffer);
173#endif
174
175/*mmc ext_csd register operation*/
176int mmc_get_ext_csd(struct mmc *mmc, u8 *ext_csd);
177int mmc_set_ext_csd(struct mmc *mmc, u8 index, u8 value);
178
179/* mmc caps quirks */
180int emmc_quirks(void);
181#endif /* __AML_MMC_H__ */