1 // SPDX-License-Identifier: GPL-2.0+ 2 /* 3 * Rockchip UFS Host Controller driver 4 * 5 * Copyright (C) 2024 Rockchip Electronics Co.Ltd. 6 */ 7 8 #define WELL_BOOT_LU_A 0x01 9 #define WELL_BOOT_LU_B 0x02 10 11 #define DEFAULT_BOOT_LUN WELL_BOOT_LU_A 12 #define DEFAULT_ACTIVE_LUN 0 13 14 #define CONFIGURATION_DESC_V31_LENGTH 0xE6 15 #define CONFIGURATION_DESC_V22_LENGTH 0x90 16 #define UNIT_DESCS_COUNT 8 17 18 /* Byte swap u16 */ 19 static inline uint16_t swap_16(uint16_t val) 20 { 21 return (uint16_t)((val << 8) | (val >> 8)); /* shift 8 */ 22 } 23 24 /* Byte swap unsigned int */ 25 static inline uint32_t swap_32(uint32_t val) 26 { 27 val = ((val << 8) & 0xFF00FF00) | ((val >> 8) & 0xFF00FF); /* shift 8 */ 28 return (uint32_t)((val << 16) | (val >> 16)); /* shift 16 */ 29 } 30 31 static inline uint16_t to_bigendian16(uint16_t val) 32 { 33 #ifdef HOST_BIG_ENDIAN 34 return val; 35 #else 36 return swap_16(val); 37 #endif 38 } 39 40 static inline uint32_t to_bigendian32(uint32_t val) 41 { 42 #ifdef HOST_BIG_ENDIAN 43 return val; 44 #else 45 return swap_32(val); 46 #endif 47 } 48 49 enum attr_id { 50 B_BOOT_LUNEN = 0x0, 51 B_CURRENT_PM = 0x2, 52 B_ACTIV_ICC_LEVEL = 0x3, 53 B_OUT_OF_ORDER_DATAEN = 0x4, 54 B_BCKGND_OPS_STATUS = 0x5, 55 B_PURGE_STATUS = 0x6, 56 B_MAX_DATA_IN_SIZE = 0x7, 57 B_MAX_DATA_OUT_SIZE = 0x8, 58 D_DYN_CAP_NEEDED = 0x9, 59 B_REFCLK_FREQ = 0xA, 60 B_CONFIG_DESC_LOCK = 0xB, 61 B_MAX_NUM_OF_RTT = 0xC, 62 W_EXCEPTION_EVENT_CONTROL = 0xD, 63 W_EXCEPTION_EVENT_STATUS = 0xE, 64 D_SECONDS_PASSED = 0xF, 65 W_CONTEXT_CONF = 0x10, 66 D_CORR_PRG_BLKNUM = 0x11 67 }; 68 69 struct ufs_dev_desc_configuration_param { 70 uint8_t b_length; 71 uint8_t b_descriptor_idn; 72 uint8_t b_conf_desc_continue; 73 uint8_t b_boot_enable; 74 uint8_t b_descr_access_en; 75 uint8_t b_init_power_mode; 76 uint8_t b_high_priority_lun; 77 uint8_t b_secure_removal_type; 78 uint8_t b_init_active_icc_level; 79 uint16_t w_periodic_rtc_update; 80 uint8_t reserved[11]; /* 5 reserved, 11 in ufs3.1 */ 81 } __attribute__ ((packed)); 82 83 struct ufs_unit_desc_configuration_param { 84 uint8_t b_lu_enable; 85 uint8_t b_boot_lun_id; 86 uint8_t b_lu_write_protect; 87 uint8_t b_memory_type; 88 uint32_t d_num_alloc_units; 89 uint8_t b_data_reliability; 90 uint8_t b_logical_block_size; 91 uint8_t b_provisioning_type; 92 uint16_t w_context_capabilities; 93 uint8_t reserved[13]; /* 3 reserved, 13 in ufs3.1 */ 94 } __attribute__ ((packed)); 95 96 struct ufs_configuration_descriptor { 97 struct ufs_dev_desc_configuration_param dev_desc_conf_param; 98 struct ufs_unit_desc_configuration_param unit_desc_conf_param[UNIT_DESCS_COUNT]; 99 } __attribute__ ((packed)); 100 101 struct ufs_geometry_descriptor { 102 uint8_t b_length; 103 uint8_t b_descriptor_idn; 104 uint8_t b_media_technology; 105 uint8_t reserved; 106 uint64_t q_total_raw_device_capacity; 107 uint8_t b_max_number_lu; 108 uint32_t d_segment_size; 109 uint8_t b_allocation_unit_size; 110 uint8_t b_min_addr_block_size; 111 uint8_t b_optimal_read_block_size; 112 uint8_t b_optimal_write_block_size; 113 uint8_t b_max_in_buffer_size; 114 uint8_t b_max_out_buffer_size; 115 uint8_t b_rpmb_read_write_size; 116 uint8_t b_dynamic_capacity_resource_policy; 117 uint8_t b_data_ordering; 118 uint8_t b_max_contex_id_number; 119 uint8_t b_sys_data_tag_unit_size; 120 uint8_t b_sys_data_tag_res_size; 121 uint8_t b_supported_sec_rtypes; 122 uint16_t w_supported_memory_types; 123 uint32_t d_system_code_max_alloc_u; 124 uint16_t w_system_code_cap_adj_fac; 125 uint32_t d_non_persist_max_alloc_u; 126 uint16_t w_non_persist_cap_adj_fac; 127 uint32_t d_enhanced1_max_alloc_u; 128 uint16_t w_enhanced1_cap_adj_fac; 129 uint32_t d_enhanced2_max_alloc_u; 130 uint16_t w_enhanced2_cap_adj_fac; 131 uint32_t d_enhanced3_max_alloc_u; 132 uint16_t w_enhanced3_cap_adj_fac; 133 uint32_t d_enhanced4_max_alloc_u; 134 uint16_t w_enhanced4_cap_adj_fac; 135 uint32_t d_optimal_logical_block_size; 136 uint8_t reserved1[15]; /* 15 reserved in ufs3.1 */ 137 } __attribute__ ((packed)); 138