1 /* 2 * Perform SPI communication using the X1600 SPI peripheral. 3 * 4 * Copyright (C) 2023, 2024 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA 20 */ 21 22 #pragma once 23 24 #include <l4/re/c/dma_space.h> 25 #include <l4/sys/types.h> 26 #include <stdint.h> 27 28 29 30 #ifdef __cplusplus 31 32 #include <l4/devices/dma-x1600.h> 33 #include <l4/devices/spi-common.h> 34 35 /* SPI peripheral channel. */ 36 37 class Spi_x1600_channel : public Spi_channel 38 { 39 public: 40 explicit Spi_x1600_channel(l4_addr_t spi_start, l4_addr_t start, 41 enum Clock_identifiers clock, 42 Cpm_chip *cpm, 43 Dma_channel *dma, 44 enum Dma_x1600_request_type request_type, 45 uint64_t frequency); 46 }; 47 48 /* SPI peripheral. */ 49 50 class Spi_x1600_chip : public Spi_chip 51 { 52 protected: 53 unsigned int num_channels() 54 { return 1; } 55 56 Spi_channel *_get_channel(uint8_t channel, Dma_channel *dma, 57 uint64_t frequency); 58 59 public: 60 explicit Spi_x1600_chip(l4_addr_t spi_start, l4_addr_t start, l4_addr_t end, Cpm_chip *cpm); 61 }; 62 63 #endif /* __cplusplus */ 64 65 66 67 /* C language interface. */ 68 69 EXTERN_C_BEGIN 70 71 void *x1600_spi_init(l4_addr_t spi_start, l4_addr_t start, l4_addr_t end, 72 void *cpm); 73 74 void *x1600_spi_get_channel(void *spi, uint8_t channel, void *dma, uint64_t frequency); 75 76 uint32_t x1600_spi_send(void *channel, uint32_t bytes, const uint8_t data[]); 77 78 uint32_t x1600_spi_send_dc(void *channel, uint32_t bytes, const uint8_t data[], 79 const int dc[], uint8_t char_size, int big_endian); 80 81 uint32_t x1600_spi_send_units(void *channel, uint32_t bytes, const uint8_t data[], 82 uint8_t unit_size, uint8_t char_size, int big_endian); 83 84 uint32_t x1600_spi_transfer(void *channel, l4_addr_t vaddr, 85 l4re_dma_space_dma_addr_t paddr, uint32_t count, 86 uint8_t unit_size, uint8_t char_size); 87 88 uint32_t x1600_spi_transfer_descriptor(void *channel, l4_addr_t vaddr, 89 l4re_dma_space_dma_addr_t paddr, 90 uint32_t count, uint8_t unit_size, 91 uint8_t char_size, l4_addr_t desc_vaddr, 92 l4re_dma_space_dma_addr_t desc_paddr); 93 94 EXTERN_C_END