blob: e5791c28dd0b53e18af31a2bebd4643f8734285a [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
82#ifndef CONFIG_SYS_MMC_MAX_BLK_COUNT
83#define CONFIG_SYS_MMC_MAX_BLK_COUNT 65535
84#endif
85/*mmc.h*/
86
Bo Lv72d0e902023-01-02 14:27:34 +000087/* bootloader operation */
88#define AML_BL_USER (0x1 << 0)
89#define AML_BL_BOOT0 (0x1 << 1)
90#define AML_BL_BOOT1 (0x1 << 2)
91#define AML_BL_BOOT (0x6)
92#define AML_BL_ALL (0x7)
93
jinbiao48315772024-05-16 05:22:01 +000094/* delay_cell=70ps, 1ns/delay_cell */
95#define DELAY_CELL_COUNTS 14
96
Bo Lv72d0e902023-01-02 14:27:34 +000097/** For actually partitions with mask 8 store into bootinfo
98 * name: partition name.
99 * addr: sector addr of the partition
100 * size: sector cont of the partition
101*/
102struct part_property
103{
104 char name[8];
105 uint32_t addr;
106 uint32_t size;
107};
108#define PART_PROPERTY_SIZE sizeof(struct part_property)
109#define BOOTINFO_MAX_PARTITIONS (4)
110#define BOOTINFO_PARTITIONS_SIZE (PART_PROPERTY_SIZE * BOOTINFO_MAX_PARTITIONS)
111
112
113#define VPART_PROPERTY_SIZE sizeof(struct vpart_property)
114struct vpart_property {
115 u32 addr;
116 u32 size;
117};
118
119/*
120 * sizeof(struct storage_emmc_boot_info) is strictly
121 * smaller than or equal to one sector. we will bind
122 * it in one sector with u-boot.bin together and
123 * write into boot loader area.
124 * @rsv_base_addr : the sector address of reserved area
125 * @dtb : the sector address and size of dtb property
126 * @ddr : the sector address and size of ddr property
127 */
128#define EMMC_BOOT_INFO_SIZE 512
129struct storage_emmc_boot_info {
130 u32 version;
131 u32 rsv_base_addr;
132 struct vpart_property dtb;
133 struct vpart_property ddr;
134
135 struct part_property parts[BOOTINFO_MAX_PARTITIONS];
136 uint8_t reserved[512 - 2 * VPART_PROPERTY_SIZE - BOOTINFO_PARTITIONS_SIZE - 12];
137 u32 checksum;
138};
139
Ruixuan.lifd943de2024-01-19 15:48:40 +0800140#define stamp_after(a,b) ((int)(b) - (int)(a) < 0)
141
Bo Lv72d0e902023-01-02 14:27:34 +0000142int amlmmc_write_bootloader(int dev, int map,
143 unsigned int size, const void *src);
144int amlmmc_erase_bootloader(int dev, int map);
145
Bo Lv72d0e902023-01-02 14:27:34 +0000146/* interface on reserved area. */
jinbiao5da7d892024-05-13 12:19:47 +0000147void mmc_write_cali_mattern(void *addr, struct aml_pattern *table);
Bo Lv72d0e902023-01-02 14:27:34 +0000148
149/* dtb operation */
150int dtb_write(void *addr);
151
152/* emmc key operation */
153int mmc_key_read(unsigned char *buf,
154 unsigned int size, uint32_t *actual_length);
155int mmc_key_write(unsigned char *buf,
156 unsigned int size, uint32_t *actual_length);
157int mmc_key_erase(void);
158
159/* partition operation */
160int renew_partition_tbl(unsigned char *buffer);
161int find_dev_num_by_partition_name (char const *name);
162
163#ifdef CONFIG_AML_PARTITION
164int emmc_update_mbr(unsigned char *buffer);
165#endif
166
167/*mmc ext_csd register operation*/
168int mmc_get_ext_csd(struct mmc *mmc, u8 *ext_csd);
169int mmc_set_ext_csd(struct mmc *mmc, u8 index, u8 value);
170
171/* mmc caps quirks */
172int emmc_quirks(void);
173#endif /* __AML_MMC_H__ */