1 /*
2 * Copyright (c) 2024 Vogl Electronic GmbH
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/kernel.h>
8 #include <zephyr/drivers/spi.h>
9 #include <zephyr/sys/byteorder.h>
10 #include <zephyr/sys_clock.h>
11
12 #include "spi_context.h"
13 #include <soc.h>
14
get_dfs_value(const struct spi_config * config)15 static inline uint8_t get_dfs_value(const struct spi_config *config)
16 {
17 switch (SPI_WORD_SIZE_GET(config->operation)) {
18 case 8:
19 return 1;
20 case 16:
21 return 2;
22 case 24:
23 return 3;
24 case 32:
25 return 4;
26 default:
27 return 1;
28 }
29 }
30
litex_spi_tx_put(uint8_t len,uint32_t * txd,const uint8_t * tx_buf)31 static inline void litex_spi_tx_put(uint8_t len, uint32_t *txd, const uint8_t *tx_buf)
32 {
33 switch (len) {
34 case 4:
35 *txd = sys_get_be32(tx_buf);
36 break;
37 case 3:
38 *txd = sys_get_be24(tx_buf);
39 break;
40 case 2:
41 *txd = sys_get_be16(tx_buf);
42 break;
43 default:
44 *txd = *tx_buf;
45 break;
46 }
47 }
48
litex_spi_rx_put(uint8_t len,uint32_t * rxd,uint8_t * rx_buf)49 static inline void litex_spi_rx_put(uint8_t len, uint32_t *rxd, uint8_t *rx_buf)
50 {
51 switch (len) {
52 case 4:
53 sys_put_be32(*rxd, rx_buf);
54 break;
55 case 3:
56 sys_put_be24(*rxd, rx_buf);
57 break;
58 case 2:
59 sys_put_be16(*rxd, rx_buf);
60 break;
61 default:
62 *rx_buf = *rxd;
63 break;
64 }
65 }
66