Skip to content

Commit ba0ae18

Browse files
aentingerMaxPayne86
authored andcommitted
Partial revert to single transmit buffer.
1 parent 9144a1a commit ba0ae18

File tree

1 file changed

+26
-60
lines changed

1 file changed

+26
-60
lines changed

x8h7_drv.c

Lines changed: 26 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,10 @@
5353

5454
struct spidev_data {
5555
struct spi_device *spi;
56-
struct mutex spi_lock;
56+
struct mutex lock;
5757
u32 speed_hz;
58-
struct mutex txb_lock;
59-
u8 *x8h7_txb_1;
60-
u8 *x8h7_txb_2;
61-
u8 *x8h7_txb_active;
62-
u8 *x8h7_txb_transfer;
63-
u16 x8h7_txl_active;
64-
u16 x8h7_txl_transfer;
58+
u8 *x8h7_txb;
59+
u16 x8h7_txl;
6560
u8 *x8h7_rxb;
6661
};
6762

@@ -182,9 +177,9 @@ int x8h7_pkt_enq(uint8_t peripheral, uint8_t opcode, uint16_t size, void *data)
182177
x8h7_subpkt_t *pkt;
183178
uint8_t *ptr;
184179

185-
mutex_lock(&spidev->txb_lock);
180+
mutex_lock(&spidev->lock);
186181

187-
ptr = spidev->x8h7_txb_active;
182+
ptr = spidev->x8h7_txb;
188183
hdr = (x8h7_pkthdr_t*)ptr;
189184

190185
if ((hdr->size + sizeof(x8h7_subpkt_t) + size) < X8H7_BUF_SIZE) {
@@ -203,12 +198,12 @@ int x8h7_pkt_enq(uint8_t peripheral, uint8_t opcode, uint16_t size, void *data)
203198
}
204199
hdr->size += sizeof(x8h7_subpkt_t) + size;
205200
hdr->checksum = hdr->size ^ 0x5555;
206-
spidev->x8h7_txl_active = hdr->size;
207-
mutex_unlock(&spidev->txb_lock);
201+
spidev->x8h7_txl = hdr->size;
202+
mutex_unlock(&spidev->lock);
208203
return 0;
209204
}
210205

211-
mutex_unlock(&spidev->txb_lock);
206+
mutex_unlock(&spidev->lock);
212207

213208
return -1;
214209
}
@@ -320,47 +315,35 @@ static inline int x8h7_pkt_send_priv(int arg)
320315
x8h7_pkthdr_t *hdr;
321316
int len;
322317

323-
DBG_PRINT("\n");
324-
325-
mutex_lock(&spidev->txb_lock);
326-
327-
spidev->x8h7_txb_transfer = spidev->x8h7_txb_active;
328-
spidev->x8h7_txb_active = (spidev->x8h7_txb_active == spidev->x8h7_txb_1) ? spidev->x8h7_txb_2 : spidev->x8h7_txb_1;
329-
memset(spidev->x8h7_txb_active, 0, X8H7_BUF_SIZE);
330-
331-
spidev->x8h7_txl_transfer = spidev->x8h7_txl_active;
332-
spidev->x8h7_txl_active = 0;
333-
334-
mutex_unlock(&spidev->txb_lock);
318+
mutex_lock(&spidev->lock);
335319

336-
337-
mutex_lock(&spidev->spi_lock);
320+
DBG_PRINT("\n");
338321

339322
/* Exchange of the packet header. */
340323
x8h7_spi_trx(spidev->spi,
341-
spidev->x8h7_txb_transfer, spidev->x8h7_rxb, sizeof(x8h7_pkthdr_t));
324+
spidev->x8h7_txb, spidev->x8h7_rxb, sizeof(x8h7_pkthdr_t));
342325

343326
hdr = (x8h7_pkthdr_t*)spidev->x8h7_rxb;
344327
if ((hdr->size != 0) && ((hdr->size ^ 0x5555) != hdr->checksum)) {
345328
DBG_ERROR("Out of sync %04x %04x\n", hdr->size, hdr->checksum);
346-
mutex_unlock(&spidev->spi_lock);
329+
mutex_unlock(&spidev->lock);
347330
return -1;
348331
}
349332

350-
len = max(hdr->size, spidev->x8h7_txl_transfer);
333+
len = max(hdr->size, spidev->x8h7_txl);
351334
if (len == 0) {
352335
DBG_ERROR("Transaction length is zero\n");
353336
x8h7_spi_trx(spidev->spi,
354-
spidev->x8h7_txb_transfer + sizeof(x8h7_pkthdr_t), spidev->x8h7_rxb,
337+
spidev->x8h7_txb + sizeof(x8h7_pkthdr_t), spidev->x8h7_rxb,
355338
sizeof(x8h7_pkthdr_t));
356-
mutex_unlock(&spidev->spi_lock);
339+
mutex_unlock(&spidev->lock);
357340
return 0;
358341
}
359342

360-
pkt_dump("Send", spidev->x8h7_txb_transfer);
343+
pkt_dump("Send", spidev->x8h7_txb);
361344

362345
x8h7_spi_trx(spidev->spi,
363-
spidev->x8h7_txb_transfer + sizeof(x8h7_pkthdr_t),
346+
spidev->x8h7_txb + sizeof(x8h7_pkthdr_t),
364347
spidev->x8h7_rxb + sizeof(x8h7_pkthdr_t), len);
365348

366349
hdr = (x8h7_pkthdr_t*)spidev->x8h7_rxb;
@@ -375,7 +358,7 @@ static inline int x8h7_pkt_send_priv(int arg)
375358

376359
memset(spidev->x8h7_rxb, 0, X8H7_BUF_SIZE);
377360

378-
mutex_unlock(&spidev->spi_lock);
361+
mutex_unlock(&spidev->lock);
379362
return 0;
380363
}
381364

@@ -434,7 +417,7 @@ static int x8h7_probe(struct spi_device *spi)
434417

435418
/* Initialize the driver data */
436419
spidev->spi = spi;
437-
mutex_init(&spidev->spi_lock);
420+
mutex_init(&spidev->lock);
438421

439422
/* Device speed */
440423
if (!of_property_read_u32(spi->dev.of_node, "spi-max-frequency", &value))
@@ -443,35 +426,14 @@ static int x8h7_probe(struct spi_device *spi)
443426

444427
status = 0;
445428

446-
mutex_init(&spidev->txb_lock);
447-
448-
if (status == 0) {
449-
spidev->x8h7_txb_1 = devm_kzalloc(&spi->dev, X8H7_BUF_SIZE, GFP_KERNEL);
450-
if (!spidev->x8h7_txb_1) {
451-
DBG_ERROR("X8H7 Tx buffer 1 memory fail\n");
452-
status = -ENOMEM;
453-
}
454-
}
455-
456429
if (status == 0) {
457-
spidev->x8h7_txb_2 = devm_kzalloc(&spi->dev, X8H7_BUF_SIZE, GFP_KERNEL);
458-
if (!spidev->x8h7_txb_2) {
459-
DBG_ERROR("X8H7 Tx buffer 2 memory fail\n");
430+
spidev->x8h7_txb = devm_kzalloc(&spi->dev, X8H7_BUF_SIZE, GFP_KERNEL);
431+
if (!spidev->x8h7_txb) {
432+
DBG_ERROR("X8H7 Tx buffer memory fail\n");
460433
status = -ENOMEM;
461434
}
462435
}
463436

464-
if (status == 0)
465-
{
466-
memset(spidev->x8h7_txb_1, 0, X8H7_BUF_SIZE);
467-
memset(spidev->x8h7_txb_2, 0, X8H7_BUF_SIZE);
468-
469-
spidev->x8h7_txb_active = spidev->x8h7_txb_1;
470-
spidev->x8h7_txb_transfer = 0;
471-
spidev->x8h7_txl_active = 0;
472-
spidev->x8h7_txl_transfer = 0;
473-
}
474-
475437
if (status == 0) {
476438
spidev->x8h7_rxb = devm_kzalloc(&spi->dev, X8H7_BUF_SIZE, GFP_KERNEL);
477439
if (!spidev->x8h7_rxb) {
@@ -480,6 +442,10 @@ static int x8h7_probe(struct spi_device *spi)
480442
}
481443
}
482444

445+
memset(spidev->x8h7_txb, 0, X8H7_BUF_SIZE);
446+
memset(spidev->x8h7_rxb, 0, X8H7_BUF_SIZE);
447+
spidev->x8h7_txl = 0;
448+
483449
/* Configure interrupt request */
484450
if (spi->irq > 0) {
485451
int ret;

0 commit comments

Comments
 (0)