@@ -180,9 +180,11 @@ static inline u32 rx_max(struct dw_spi *dws)
180
180
181
181
static void dw_writer (struct dw_spi * dws )
182
182
{
183
- u32 max = tx_max ( dws ) ;
183
+ u32 max ;
184
184
u16 txw = 0 ;
185
185
186
+ spin_lock (& dws -> buf_lock );
187
+ max = tx_max (dws );
186
188
while (max -- ) {
187
189
/* Set the tx word if the transfer's original "tx" is not null */
188
190
if (dws -> tx_end - dws -> len ) {
@@ -194,13 +196,16 @@ static void dw_writer(struct dw_spi *dws)
194
196
dw_write_io_reg (dws , DW_SPI_DR , txw );
195
197
dws -> tx += dws -> n_bytes ;
196
198
}
199
+ spin_unlock (& dws -> buf_lock );
197
200
}
198
201
199
202
static void dw_reader (struct dw_spi * dws )
200
203
{
201
- u32 max = rx_max ( dws ) ;
204
+ u32 max ;
202
205
u16 rxw ;
203
206
207
+ spin_lock (& dws -> buf_lock );
208
+ max = rx_max (dws );
204
209
while (max -- ) {
205
210
rxw = dw_read_io_reg (dws , DW_SPI_DR );
206
211
/* Care rx only if the transfer's original "rx" is not null */
@@ -212,6 +217,7 @@ static void dw_reader(struct dw_spi *dws)
212
217
}
213
218
dws -> rx += dws -> n_bytes ;
214
219
}
220
+ spin_unlock (& dws -> buf_lock );
215
221
}
216
222
217
223
static void int_error_stop (struct dw_spi * dws , const char * msg )
@@ -284,18 +290,20 @@ static int dw_spi_transfer_one(struct spi_master *master,
284
290
{
285
291
struct dw_spi * dws = spi_master_get_devdata (master );
286
292
struct chip_data * chip = spi_get_ctldata (spi );
293
+ unsigned long flags ;
287
294
u8 imask = 0 ;
288
295
u16 txlevel = 0 ;
289
296
u32 cr0 ;
290
297
int ret ;
291
298
292
299
dws -> dma_mapped = 0 ;
293
-
300
+ spin_lock_irqsave ( & dws -> buf_lock , flags );
294
301
dws -> tx = (void * )transfer -> tx_buf ;
295
302
dws -> tx_end = dws -> tx + transfer -> len ;
296
303
dws -> rx = transfer -> rx_buf ;
297
304
dws -> rx_end = dws -> rx + transfer -> len ;
298
305
dws -> len = transfer -> len ;
306
+ spin_unlock_irqrestore (& dws -> buf_lock , flags );
299
307
300
308
spi_enable_chip (dws , 0 );
301
309
@@ -487,6 +495,7 @@ int dw_spi_add_host(struct device *dev, struct dw_spi *dws)
487
495
dws -> dma_inited = 0 ;
488
496
dws -> dma_addr = (dma_addr_t )(dws -> paddr + DW_SPI_DR );
489
497
snprintf (dws -> name , sizeof (dws -> name ), "dw_spi%d" , dws -> bus_num );
498
+ spin_lock_init (& dws -> buf_lock );
490
499
491
500
ret = request_irq (dws -> irq , dw_spi_irq , IRQF_SHARED , dws -> name , master );
492
501
if (ret < 0 ) {
0 commit comments