22
22
#include <linux/spi/spi.h>
23
23
#include <linux/acpi.h>
24
24
#include <linux/property.h>
25
+ #include <linux/sizes.h>
25
26
26
27
#define QSPI_COMMAND1 0x000
27
28
#define QSPI_BIT_LENGTH (x ) (((x) & 0x1f) << 0)
134
135
#define QSPI_COMMAND_VALUE_SET (X ) (((x) & 0xFF) << 0)
135
136
136
137
#define QSPI_CMB_SEQ_CMD_CFG 0x1a0
137
- #define QSPI_COMMAND_X1_X2_X4 (x ) (((x ) & 0x3) << 13)
138
+ #define QSPI_COMMAND_X1_X2_X4 (x ) ((((x) >> 1 ) & 0x3) << 13)
138
139
#define QSPI_COMMAND_X1_X2_X4_MASK (0x03 << 13)
139
140
#define QSPI_COMMAND_SDR_DDR BIT(12)
140
141
#define QSPI_COMMAND_SIZE_SET (x ) (((x) & 0xFF) << 0)
147
148
#define QSPI_ADDRESS_VALUE_SET (X ) (((x) & 0xFFFF) << 0)
148
149
149
150
#define QSPI_CMB_SEQ_ADDR_CFG 0x1ac
150
- #define QSPI_ADDRESS_X1_X2_X4 (x ) (((x ) & 0x3) << 13)
151
+ #define QSPI_ADDRESS_X1_X2_X4 (x ) ((((x) >> 1 ) & 0x3) << 13)
151
152
#define QSPI_ADDRESS_X1_X2_X4_MASK (0x03 << 13)
152
153
#define QSPI_ADDRESS_SDR_DDR BIT(12)
153
154
#define QSPI_ADDRESS_SIZE_SET (x ) (((x) & 0xFF) << 0)
156
157
#define DATA_DIR_RX BIT(1)
157
158
158
159
#define QSPI_DMA_TIMEOUT (msecs_to_jiffies(1000))
159
- #define DEFAULT_QSPI_DMA_BUF_LEN (64 * 1024)
160
- #define CMD_TRANSFER 0
161
- #define ADDR_TRANSFER 1
162
- #define DATA_TRANSFER 2
160
+ #define DEFAULT_QSPI_DMA_BUF_LEN SZ_64K
161
+
162
+ enum tegra_qspi_transfer_type {
163
+ CMD_TRANSFER = 0 ,
164
+ ADDR_TRANSFER = 1 ,
165
+ DUMMY_TRANSFER = 2 ,
166
+ DATA_TRANSFER = 3
167
+ };
163
168
164
169
struct tegra_qspi_soc_data {
165
170
bool has_dma ;
@@ -1036,10 +1041,6 @@ static u32 tegra_qspi_addr_config(bool is_ddr, u8 bus_width, u8 len)
1036
1041
{
1037
1042
u32 addr_config = 0 ;
1038
1043
1039
- /* Extract Address configuration and value */
1040
- is_ddr = 0 ; //Only SDR mode supported
1041
- bus_width = 0 ; //X1 mode
1042
-
1043
1044
if (is_ddr )
1044
1045
addr_config |= QSPI_ADDRESS_SDR_DDR ;
1045
1046
else
@@ -1079,16 +1080,23 @@ static int tegra_qspi_combined_seq_xfer(struct tegra_qspi *tqspi,
1079
1080
switch (transfer_phase ) {
1080
1081
case CMD_TRANSFER :
1081
1082
/* X1 SDR mode */
1082
- cmd_config = tegra_qspi_cmd_config (false, 0 ,
1083
+ cmd_config = tegra_qspi_cmd_config (false, xfer -> tx_nbits ,
1083
1084
xfer -> len );
1084
1085
cmd_value = * ((const u8 * )(xfer -> tx_buf ));
1085
1086
break ;
1086
1087
case ADDR_TRANSFER :
1087
1088
/* X1 SDR mode */
1088
- addr_config = tegra_qspi_addr_config (false, 0 ,
1089
+ addr_config = tegra_qspi_addr_config (false, xfer -> tx_nbits ,
1089
1090
xfer -> len );
1090
1091
address_value = * ((const u32 * )(xfer -> tx_buf ));
1091
1092
break ;
1093
+ case DUMMY_TRANSFER :
1094
+ if (xfer -> dummy_data ) {
1095
+ tqspi -> dummy_cycles = xfer -> len * 8 / xfer -> tx_nbits ;
1096
+ break ;
1097
+ }
1098
+ transfer_phase ++ ;
1099
+ fallthrough ;
1092
1100
case DATA_TRANSFER :
1093
1101
/* Program Command, Address value in register */
1094
1102
tegra_qspi_writel (tqspi , cmd_value , QSPI_CMB_SEQ_CMD );
@@ -1163,26 +1171,22 @@ static int tegra_qspi_combined_seq_xfer(struct tegra_qspi *tqspi,
1163
1171
ret = - EIO ;
1164
1172
goto exit ;
1165
1173
}
1166
- if (!xfer -> cs_change ) {
1167
- tegra_qspi_transfer_end (spi );
1168
- spi_transfer_delay_exec (xfer );
1169
- }
1170
1174
break ;
1171
1175
default :
1172
1176
ret = - EINVAL ;
1173
1177
goto exit ;
1174
1178
}
1175
1179
msg -> actual_length += xfer -> len ;
1180
+ if (!xfer -> cs_change && transfer_phase == DATA_TRANSFER ) {
1181
+ tegra_qspi_transfer_end (spi );
1182
+ spi_transfer_delay_exec (xfer );
1183
+ }
1176
1184
transfer_phase ++ ;
1177
1185
}
1178
1186
ret = 0 ;
1179
1187
1180
1188
exit :
1181
1189
msg -> status = ret ;
1182
- if (ret < 0 ) {
1183
- tegra_qspi_transfer_end (spi );
1184
- spi_transfer_delay_exec (xfer );
1185
- }
1186
1190
1187
1191
return ret ;
1188
1192
}
@@ -1300,7 +1304,9 @@ static bool tegra_qspi_validate_cmb_seq(struct tegra_qspi *tqspi,
1300
1304
list_for_each_entry (xfer , & msg -> transfers , transfer_list ) {
1301
1305
transfer_count ++ ;
1302
1306
}
1303
- if (!tqspi -> soc_data -> cmb_xfer_capable || transfer_count != 3 )
1307
+ if (!tqspi -> soc_data -> cmb_xfer_capable )
1308
+ return false;
1309
+ if (transfer_count > 4 || transfer_count < 3 )
1304
1310
return false;
1305
1311
xfer = list_first_entry (& msg -> transfers , typeof (* xfer ),
1306
1312
transfer_list );
@@ -1310,6 +1316,13 @@ static bool tegra_qspi_validate_cmb_seq(struct tegra_qspi *tqspi,
1310
1316
if (xfer -> len > 4 || xfer -> len < 3 )
1311
1317
return false;
1312
1318
xfer = list_next_entry (xfer , transfer_list );
1319
+ if (transfer_count == 4 ) {
1320
+ if (xfer -> dummy_data != 1 )
1321
+ return false;
1322
+ if ((xfer -> len * 8 / xfer -> tx_nbits ) > QSPI_DUMMY_CYCLES_MAX )
1323
+ return false;
1324
+ xfer = list_next_entry (xfer , transfer_list );
1325
+ }
1313
1326
if (!tqspi -> soc_data -> has_dma && xfer -> len > (QSPI_FIFO_DEPTH << 2 ))
1314
1327
return false;
1315
1328
0 commit comments