xref: /rk3399_rockchip-uboot/drivers/ufs/ufs-rockchip-usbplug.h (revision 3d58a3e83e9c707ced8b4cf0dcff35e39d1eedf8)
12c3d2faaSYifeng Zhao // SPDX-License-Identifier: GPL-2.0+
22c3d2faaSYifeng Zhao /*
32c3d2faaSYifeng Zhao  * Rockchip UFS Host Controller driver
42c3d2faaSYifeng Zhao  *
52c3d2faaSYifeng Zhao  * Copyright (C) 2024 Rockchip Electronics Co.Ltd.
62c3d2faaSYifeng Zhao  */
72c3d2faaSYifeng Zhao 
82c3d2faaSYifeng Zhao #define WELL_BOOT_LU_A		0x01
92c3d2faaSYifeng Zhao #define WELL_BOOT_LU_B		0x02
102c3d2faaSYifeng Zhao 
112c3d2faaSYifeng Zhao #define DEFAULT_BOOT_LUN	WELL_BOOT_LU_A
122c3d2faaSYifeng Zhao #define DEFAULT_ACTIVE_LUN	0
132c3d2faaSYifeng Zhao 
142c3d2faaSYifeng Zhao #define CONFIGURATION_DESC_V31_LENGTH	0xE6
15*3d58a3e8SYifeng Zhao #define CONFIGURATION_DESC_V30_LENGTH	0xE2
162c3d2faaSYifeng Zhao #define CONFIGURATION_DESC_V22_LENGTH	0x90
172c3d2faaSYifeng Zhao #define UNIT_DESCS_COUNT		8
182c3d2faaSYifeng Zhao 
192c3d2faaSYifeng Zhao /* Byte swap u16 */
swap_16(uint16_t val)202c3d2faaSYifeng Zhao static inline uint16_t swap_16(uint16_t val)
212c3d2faaSYifeng Zhao {
222c3d2faaSYifeng Zhao 	return (uint16_t)((val << 8) | (val >> 8)); /* shift 8 */
232c3d2faaSYifeng Zhao }
242c3d2faaSYifeng Zhao 
252c3d2faaSYifeng Zhao /* Byte swap unsigned int */
swap_32(uint32_t val)262c3d2faaSYifeng Zhao static inline uint32_t swap_32(uint32_t val)
272c3d2faaSYifeng Zhao {
282c3d2faaSYifeng Zhao 	val = ((val << 8) & 0xFF00FF00) | ((val >> 8) & 0xFF00FF); /* shift 8 */
292c3d2faaSYifeng Zhao 	return (uint32_t)((val << 16) | (val >> 16)); /* shift 16 */
302c3d2faaSYifeng Zhao }
312c3d2faaSYifeng Zhao 
to_bigendian16(uint16_t val)322c3d2faaSYifeng Zhao static inline uint16_t to_bigendian16(uint16_t val)
332c3d2faaSYifeng Zhao {
342c3d2faaSYifeng Zhao #ifdef HOST_BIG_ENDIAN
352c3d2faaSYifeng Zhao 	return val;
362c3d2faaSYifeng Zhao #else
372c3d2faaSYifeng Zhao 	return swap_16(val);
382c3d2faaSYifeng Zhao #endif
392c3d2faaSYifeng Zhao }
402c3d2faaSYifeng Zhao 
to_bigendian32(uint32_t val)412c3d2faaSYifeng Zhao static inline uint32_t to_bigendian32(uint32_t val)
422c3d2faaSYifeng Zhao {
432c3d2faaSYifeng Zhao #ifdef HOST_BIG_ENDIAN
442c3d2faaSYifeng Zhao 	return val;
452c3d2faaSYifeng Zhao #else
462c3d2faaSYifeng Zhao 	return swap_32(val);
472c3d2faaSYifeng Zhao #endif
482c3d2faaSYifeng Zhao }
492c3d2faaSYifeng Zhao 
502c3d2faaSYifeng Zhao enum attr_id {
512c3d2faaSYifeng Zhao 	B_BOOT_LUNEN = 0x0,
522c3d2faaSYifeng Zhao 	B_CURRENT_PM = 0x2,
532c3d2faaSYifeng Zhao 	B_ACTIV_ICC_LEVEL = 0x3,
542c3d2faaSYifeng Zhao 	B_OUT_OF_ORDER_DATAEN = 0x4,
552c3d2faaSYifeng Zhao 	B_BCKGND_OPS_STATUS = 0x5,
562c3d2faaSYifeng Zhao 	B_PURGE_STATUS = 0x6,
572c3d2faaSYifeng Zhao 	B_MAX_DATA_IN_SIZE = 0x7,
582c3d2faaSYifeng Zhao 	B_MAX_DATA_OUT_SIZE = 0x8,
592c3d2faaSYifeng Zhao 	D_DYN_CAP_NEEDED = 0x9,
602c3d2faaSYifeng Zhao 	B_REFCLK_FREQ = 0xA,
612c3d2faaSYifeng Zhao 	B_CONFIG_DESC_LOCK = 0xB,
622c3d2faaSYifeng Zhao 	B_MAX_NUM_OF_RTT = 0xC,
632c3d2faaSYifeng Zhao 	W_EXCEPTION_EVENT_CONTROL = 0xD,
642c3d2faaSYifeng Zhao 	W_EXCEPTION_EVENT_STATUS = 0xE,
652c3d2faaSYifeng Zhao 	D_SECONDS_PASSED = 0xF,
662c3d2faaSYifeng Zhao 	W_CONTEXT_CONF = 0x10,
672c3d2faaSYifeng Zhao 	D_CORR_PRG_BLKNUM = 0x11
682c3d2faaSYifeng Zhao };
692c3d2faaSYifeng Zhao 
702c3d2faaSYifeng Zhao struct ufs_dev_desc_configuration_param {
712c3d2faaSYifeng Zhao 	uint8_t b_length;
722c3d2faaSYifeng Zhao 	uint8_t b_descriptor_idn;
732c3d2faaSYifeng Zhao 	uint8_t b_conf_desc_continue;
742c3d2faaSYifeng Zhao 	uint8_t b_boot_enable;
752c3d2faaSYifeng Zhao 	uint8_t b_descr_access_en;
762c3d2faaSYifeng Zhao 	uint8_t b_init_power_mode;
772c3d2faaSYifeng Zhao 	uint8_t b_high_priority_lun;
782c3d2faaSYifeng Zhao 	uint8_t b_secure_removal_type;
792c3d2faaSYifeng Zhao 	uint8_t b_init_active_icc_level;
802c3d2faaSYifeng Zhao 	uint16_t w_periodic_rtc_update;
811865a7e4SYifeng Zhao 	uint8_t reserved[5]; /* 5 reserved, 11 in ufs3.1 */
821865a7e4SYifeng Zhao 	uint8_t b_write_booster_buffer_reserve_user_space_en;
831865a7e4SYifeng Zhao 	uint8_t b_write_booster_buffer_type;
841865a7e4SYifeng Zhao 	uint32_t d_num_shared_write_booster_buffer_alloc_units;
852c3d2faaSYifeng Zhao } __attribute__ ((packed));
862c3d2faaSYifeng Zhao 
872c3d2faaSYifeng Zhao struct ufs_unit_desc_configuration_param {
882c3d2faaSYifeng Zhao 	uint8_t b_lu_enable;
892c3d2faaSYifeng Zhao 	uint8_t b_boot_lun_id;
902c3d2faaSYifeng Zhao 	uint8_t b_lu_write_protect;
912c3d2faaSYifeng Zhao 	uint8_t b_memory_type;
922c3d2faaSYifeng Zhao 	uint32_t d_num_alloc_units;
932c3d2faaSYifeng Zhao 	uint8_t b_data_reliability;
942c3d2faaSYifeng Zhao 	uint8_t b_logical_block_size;
952c3d2faaSYifeng Zhao 	uint8_t b_provisioning_type;
962c3d2faaSYifeng Zhao 	uint16_t w_context_capabilities;
972c3d2faaSYifeng Zhao 	uint8_t reserved[13]; /* 3 reserved, 13 in ufs3.1 */
982c3d2faaSYifeng Zhao } __attribute__ ((packed));
992c3d2faaSYifeng Zhao 
1002c3d2faaSYifeng Zhao struct ufs_configuration_descriptor {
1012c3d2faaSYifeng Zhao 	struct ufs_dev_desc_configuration_param dev_desc_conf_param;
1022c3d2faaSYifeng Zhao 	struct ufs_unit_desc_configuration_param unit_desc_conf_param[UNIT_DESCS_COUNT];
1032c3d2faaSYifeng Zhao } __attribute__ ((packed));
1042c3d2faaSYifeng Zhao 
1052c3d2faaSYifeng Zhao struct ufs_geometry_descriptor {
1062c3d2faaSYifeng Zhao 	uint8_t b_length;
1072c3d2faaSYifeng Zhao 	uint8_t b_descriptor_idn;
1082c3d2faaSYifeng Zhao 	uint8_t b_media_technology;
1092c3d2faaSYifeng Zhao 	uint8_t reserved;
1102c3d2faaSYifeng Zhao 	uint64_t q_total_raw_device_capacity;
1112c3d2faaSYifeng Zhao 	uint8_t b_max_number_lu;
1122c3d2faaSYifeng Zhao 	uint32_t d_segment_size;
1132c3d2faaSYifeng Zhao 	uint8_t b_allocation_unit_size;
1142c3d2faaSYifeng Zhao 	uint8_t b_min_addr_block_size;
1152c3d2faaSYifeng Zhao 	uint8_t b_optimal_read_block_size;
1162c3d2faaSYifeng Zhao 	uint8_t b_optimal_write_block_size;
1172c3d2faaSYifeng Zhao 	uint8_t b_max_in_buffer_size;
1182c3d2faaSYifeng Zhao 	uint8_t b_max_out_buffer_size;
1192c3d2faaSYifeng Zhao 	uint8_t b_rpmb_read_write_size;
1202c3d2faaSYifeng Zhao 	uint8_t b_dynamic_capacity_resource_policy;
1212c3d2faaSYifeng Zhao 	uint8_t b_data_ordering;
1222c3d2faaSYifeng Zhao 	uint8_t b_max_contex_id_number;
1232c3d2faaSYifeng Zhao 	uint8_t b_sys_data_tag_unit_size;
1242c3d2faaSYifeng Zhao 	uint8_t b_sys_data_tag_res_size;
1252c3d2faaSYifeng Zhao 	uint8_t b_supported_sec_rtypes;
1262c3d2faaSYifeng Zhao 	uint16_t w_supported_memory_types;
1272c3d2faaSYifeng Zhao 	uint32_t d_system_code_max_alloc_u;
1282c3d2faaSYifeng Zhao 	uint16_t w_system_code_cap_adj_fac;
1292c3d2faaSYifeng Zhao 	uint32_t d_non_persist_max_alloc_u;
1302c3d2faaSYifeng Zhao 	uint16_t w_non_persist_cap_adj_fac;
1312c3d2faaSYifeng Zhao 	uint32_t d_enhanced1_max_alloc_u;
1322c3d2faaSYifeng Zhao 	uint16_t w_enhanced1_cap_adj_fac;
1332c3d2faaSYifeng Zhao 	uint32_t d_enhanced2_max_alloc_u;
1342c3d2faaSYifeng Zhao 	uint16_t w_enhanced2_cap_adj_fac;
1352c3d2faaSYifeng Zhao 	uint32_t d_enhanced3_max_alloc_u;
1362c3d2faaSYifeng Zhao 	uint16_t w_enhanced3_cap_adj_fac;
1372c3d2faaSYifeng Zhao 	uint32_t d_enhanced4_max_alloc_u;
1382c3d2faaSYifeng Zhao 	uint16_t w_enhanced4_cap_adj_fac;
1392c3d2faaSYifeng Zhao 	uint32_t d_optimal_logical_block_size;
1401865a7e4SYifeng Zhao 	/* 15 reserved in ufs3.1 */
1411865a7e4SYifeng Zhao 	uint8_t b_hpb_region_size;
1421865a7e4SYifeng Zhao 	uint8_t b_hpb_number_lu;
1431865a7e4SYifeng Zhao 	uint8_t b_hpb_sub_region_size;
1441865a7e4SYifeng Zhao 	uint16_t w_device_max_active_hpb_regions;
1451865a7e4SYifeng Zhao 	uint16_t w_eserved;
1461865a7e4SYifeng Zhao 	uint32_t d_write_booster_buffer_max_alloc_units;
1471865a7e4SYifeng Zhao 	uint8_t b_device_max_write_booster_lus;
1481865a7e4SYifeng Zhao 	uint8_t b_write_booster_buffer_cap_adj_fac;
1491865a7e4SYifeng Zhao 	uint8_t b_supported_write_booster_buffer_user_space_reduction_types;
1501865a7e4SYifeng Zhao 	uint8_t b_supported_write_booster_buffer_types;
1512c3d2faaSYifeng Zhao } __attribute__ ((packed));
152