@@ -111,7 +111,7 @@ struct mchp_corespi {
111
111
int irq ;
112
112
int tx_len ;
113
113
int rx_len ;
114
- int pending ;
114
+ int n_bytes ;
115
115
};
116
116
117
117
static inline u32 mchp_corespi_read (struct mchp_corespi * spi , unsigned int reg )
@@ -135,20 +135,23 @@ static inline void mchp_corespi_disable(struct mchp_corespi *spi)
135
135
136
136
static inline void mchp_corespi_read_fifo (struct mchp_corespi * spi )
137
137
{
138
- u8 data ;
139
- int fifo_max , i = 0 ;
138
+ while ( spi -> rx_len >= spi -> n_bytes && !( mchp_corespi_read ( spi , REG_STATUS ) & STATUS_RXFIFO_EMPTY )) {
139
+ u32 data = mchp_corespi_read ( spi , REG_RX_DATA ) ;
140
140
141
- fifo_max = min ( spi -> rx_len , FIFO_DEPTH ) ;
141
+ spi -> rx_len -= spi -> n_bytes ;
142
142
143
- while (( i < fifo_max ) && !( mchp_corespi_read ( spi , REG_STATUS ) & STATUS_RXFIFO_EMPTY )) {
144
- data = mchp_corespi_read ( spi , REG_RX_DATA ) ;
143
+ if (! spi -> rx_buf )
144
+ continue ;
145
145
146
- if (spi -> rx_buf )
147
- * spi -> rx_buf ++ = data ;
148
- i ++ ;
146
+ if (spi -> n_bytes == 4 )
147
+ * ((u32 * )spi -> rx_buf ) = data ;
148
+ else if (spi -> n_bytes == 2 )
149
+ * ((u16 * )spi -> rx_buf ) = data ;
150
+ else
151
+ * spi -> rx_buf = data ;
152
+
153
+ spi -> rx_buf += spi -> n_bytes ;
149
154
}
150
- spi -> rx_len -= i ;
151
- spi -> pending -= i ;
152
155
}
153
156
154
157
static void mchp_corespi_enable_ints (struct mchp_corespi * spi )
@@ -210,20 +213,28 @@ static inline void mchp_corespi_set_xfer_size(struct mchp_corespi *spi, int len)
210
213
211
214
static inline void mchp_corespi_write_fifo (struct mchp_corespi * spi )
212
215
{
213
- u8 byte ;
214
216
int fifo_max , i = 0 ;
215
217
216
- fifo_max = min (spi -> tx_len , FIFO_DEPTH );
218
+ fifo_max = DIV_ROUND_UP ( min (spi -> tx_len , FIFO_DEPTH ), spi -> n_bytes );
217
219
mchp_corespi_set_xfer_size (spi , fifo_max );
218
220
219
221
while ((i < fifo_max ) && !(mchp_corespi_read (spi , REG_STATUS ) & STATUS_TXFIFO_FULL )) {
220
- byte = spi -> tx_buf ? * spi -> tx_buf ++ : 0xaa ;
221
- mchp_corespi_write (spi , REG_TX_DATA , byte );
222
+ u32 word ;
223
+
224
+ if (spi -> n_bytes == 4 )
225
+ word = spi -> tx_buf ? * ((u32 * )spi -> tx_buf ) : 0xaa ;
226
+ else if (spi -> n_bytes == 2 )
227
+ word = spi -> tx_buf ? * ((u16 * )spi -> tx_buf ) : 0xaa ;
228
+ else
229
+ word = spi -> tx_buf ? * spi -> tx_buf : 0xaa ;
230
+
231
+ mchp_corespi_write (spi , REG_TX_DATA , word );
232
+ if (spi -> tx_buf )
233
+ spi -> tx_buf += spi -> n_bytes ;
222
234
i ++ ;
223
235
}
224
236
225
- spi -> tx_len -= i ;
226
- spi -> pending += i ;
237
+ spi -> tx_len -= i * spi -> n_bytes ;
227
238
}
228
239
229
240
static inline void mchp_corespi_set_framesize (struct mchp_corespi * spi , int bt )
@@ -493,10 +504,9 @@ static int mchp_corespi_transfer_one(struct spi_controller *host,
493
504
spi -> rx_buf = xfer -> rx_buf ;
494
505
spi -> tx_len = xfer -> len ;
495
506
spi -> rx_len = xfer -> len ;
496
- spi -> pending = 0 ;
507
+ spi -> n_bytes = roundup_pow_of_two ( DIV_ROUND_UP ( xfer -> bits_per_word , BITS_PER_BYTE )) ;
497
508
498
- mchp_corespi_set_xfer_size (spi , (spi -> tx_len > FIFO_DEPTH )
499
- ? FIFO_DEPTH : spi -> tx_len );
509
+ mchp_corespi_set_framesize (spi , xfer -> bits_per_word );
500
510
501
511
mchp_corespi_write (spi , REG_COMMAND , COMMAND_RXFIFORST | COMMAND_TXFIFORST );
502
512
@@ -514,7 +524,6 @@ static int mchp_corespi_prepare_message(struct spi_controller *host,
514
524
struct spi_device * spi_dev = msg -> spi ;
515
525
struct mchp_corespi * spi = spi_controller_get_devdata (host );
516
526
517
- mchp_corespi_set_framesize (spi , DEFAULT_FRAMESIZE );
518
527
mchp_corespi_set_mode (spi , spi_dev -> mode );
519
528
520
529
return 0 ;
@@ -542,7 +551,7 @@ static int mchp_corespi_probe(struct platform_device *pdev)
542
551
host -> mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH ;
543
552
host -> use_gpio_descriptors = true;
544
553
host -> setup = mchp_corespi_setup ;
545
- host -> bits_per_word_mask = SPI_BPW_MASK ( 8 );
554
+ host -> bits_per_word_mask = SPI_BPW_RANGE_MASK ( 1 , 32 );
546
555
host -> transfer_one = mchp_corespi_transfer_one ;
547
556
host -> prepare_message = mchp_corespi_prepare_message ;
548
557
host -> set_cs = mchp_corespi_set_cs ;
0 commit comments