blob: c41cd4d961b786e38f7a7935130a2e0d18d99694 [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>
11
Ruixuan.lib5755732024-02-01 16:01:14 +080012/*mmc.h*/
13#define NO_CARD_ERR -16
14#define UNUSABLE_ERR -17
15#define COMM_ERR -18
16#define TIMEOUT -19
17#define IN_PROGRESS -20
18#define SWITCH_ERR -21
19
20#define MESON_SD_EMMC_ADJ_IDX_LOG 0x20
21#define MESON_SD_EMMC_CLKTEST_LOG 0x24
22#define MESON_SD_EMMC_CLKTEST_OUT 0x28
23#define MESON_SD_EMMC_EYETEST_LOG 0x2C
24#define MESON_SD_EMMC_EYETEST_OUT0 0x30
25#define MESON_SD_EMMC_EYETEST_OUT1 0x34
26#define MESON_SD_EMMC_INTF3 0x38
27#define MMC_CMD23
28
29#define MMC_CMD_SET_WRITE_PROTECT 28
30#define MMC_CMD_CLR_WRITE_PROT 29
31#define MMC_CMD_SEND_WRITE_PROT 30
32#define MMC_CMD_SEND_WRITE_PROT_TYPE 31
33#define MMC_SD_HS_TUNING 70
34
35#define MMC_KEY_SIZE (256*1024)
36#define EMMC_KEY_DEV (1)
37
38#define EXT_CSD_CLASS_6_CTRL 59 /*R/W/E_P*/
39#define EXT_CSD_DRIVER_STRENGTH 197 /* RO */
40#define EXT_CSD_DEV_LIFETIME_EST_TYP_A 268 /* RO */
41#define EXT_CSD_DEV_LIFETIME_EST_TYP_B 269 /* RO */
42#define EXT_CSD_SUPPORTED_MODES 493 /* RO */
43#define EXT_CSD_FW_VERSION 254 /* RO, 261:254 */
44#define EXT_CSD_FW_CFG 169 /* R/W */
45#define EXT_CSD_MODE_CFG 30 /* R/W */
46#define EXT_CSD_FFU_STATUS 26 /* RO */
47
48#define US_PWR_WP_DIS_BIT 1<<3
49#define US_PERM_WP_DIS_BIT 1<<4
50#define WP_CLEAR_TYPE 0
51#define WP_POWER_ON_TYPE (1<<1)
52#define WP_TEMPORARY_TYPE 1
53#define WP_PERMANENT_TYPE ((1<<0)|(1<<1))
54#define WP_TYPE_MASK 3
55#define WP_ENABLE_MASK 7
56#define WP_TEMPORARY_EN_BIT 0
57#define WP_POWER_ON_EN_BIT (1<<0)
58#define WP_PERM_EN_BIT (1<<2)
59#define WP_GRP_SIZE_MASK 31
60
61#ifndef CONFIG_SYS_MMC_MAX_BLK_COUNT
62#define CONFIG_SYS_MMC_MAX_BLK_COUNT 65535
63#endif
64/*mmc.h*/
65
Bo Lv72d0e902023-01-02 14:27:34 +000066/* bootloader operation */
67#define AML_BL_USER (0x1 << 0)
68#define AML_BL_BOOT0 (0x1 << 1)
69#define AML_BL_BOOT1 (0x1 << 2)
70#define AML_BL_BOOT (0x6)
71#define AML_BL_ALL (0x7)
72
73/** For actually partitions with mask 8 store into bootinfo
74 * name: partition name.
75 * addr: sector addr of the partition
76 * size: sector cont of the partition
77*/
78struct part_property
79{
80 char name[8];
81 uint32_t addr;
82 uint32_t size;
83};
84#define PART_PROPERTY_SIZE sizeof(struct part_property)
85#define BOOTINFO_MAX_PARTITIONS (4)
86#define BOOTINFO_PARTITIONS_SIZE (PART_PROPERTY_SIZE * BOOTINFO_MAX_PARTITIONS)
87
88
89#define VPART_PROPERTY_SIZE sizeof(struct vpart_property)
90struct vpart_property {
91 u32 addr;
92 u32 size;
93};
94
95/*
96 * sizeof(struct storage_emmc_boot_info) is strictly
97 * smaller than or equal to one sector. we will bind
98 * it in one sector with u-boot.bin together and
99 * write into boot loader area.
100 * @rsv_base_addr : the sector address of reserved area
101 * @dtb : the sector address and size of dtb property
102 * @ddr : the sector address and size of ddr property
103 */
104#define EMMC_BOOT_INFO_SIZE 512
105struct storage_emmc_boot_info {
106 u32 version;
107 u32 rsv_base_addr;
108 struct vpart_property dtb;
109 struct vpart_property ddr;
110
111 struct part_property parts[BOOTINFO_MAX_PARTITIONS];
112 uint8_t reserved[512 - 2 * VPART_PROPERTY_SIZE - BOOTINFO_PARTITIONS_SIZE - 12];
113 u32 checksum;
114};
115
Ruixuan.lifd943de2024-01-19 15:48:40 +0800116#define stamp_after(a,b) ((int)(b) - (int)(a) < 0)
117
Bo Lv72d0e902023-01-02 14:27:34 +0000118int amlmmc_write_bootloader(int dev, int map,
119 unsigned int size, const void *src);
120int amlmmc_erase_bootloader(int dev, int map);
121
Bo Lv72d0e902023-01-02 14:27:34 +0000122/* interface on reserved area. */
123void mmc_write_cali_mattern(void *addr);
124
125/* dtb operation */
126int dtb_write(void *addr);
127
128/* emmc key operation */
129int mmc_key_read(unsigned char *buf,
130 unsigned int size, uint32_t *actual_length);
131int mmc_key_write(unsigned char *buf,
132 unsigned int size, uint32_t *actual_length);
133int mmc_key_erase(void);
134
135/* partition operation */
136int renew_partition_tbl(unsigned char *buffer);
137int find_dev_num_by_partition_name (char const *name);
138
139#ifdef CONFIG_AML_PARTITION
140int emmc_update_mbr(unsigned char *buffer);
141#endif
142
143/*mmc ext_csd register operation*/
144int mmc_get_ext_csd(struct mmc *mmc, u8 *ext_csd);
145int mmc_set_ext_csd(struct mmc *mmc, u8 index, u8 value);
146
147/* mmc caps quirks */
148int emmc_quirks(void);
149#endif /* __AML_MMC_H__ */