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 #include <l4/devices/spi-x1600.h> 23 24 25 26 /* Initialise a channel. */ 27 28 Spi_x1600_channel::Spi_x1600_channel(l4_addr_t spi_start, l4_addr_t start, 29 enum Clock_identifiers clock, 30 Cpm_chip *cpm, 31 Dma_channel *dma, 32 enum Dma_x1600_request_type request_type, 33 uint64_t frequency) 34 : Spi_channel(spi_start, start, clock, cpm, dma, request_type, frequency) 35 { 36 } 37 38 39 40 /* Initialise the peripheral abstraction. */ 41 42 Spi_x1600_chip::Spi_x1600_chip(l4_addr_t spi_start, l4_addr_t start, 43 l4_addr_t end, Cpm_chip *cpm) 44 : Spi_chip(spi_start, start, end, cpm) 45 { 46 } 47 48 Spi_channel * 49 Spi_x1600_chip::_get_channel(uint8_t channel, Dma_channel *dma, 50 uint64_t frequency) 51 { 52 (void) channel; 53 54 // NOTE: Only sending is supported. 55 56 return new Spi_x1600_channel(_spi_start, _start, Clock_ssi0, 57 _cpm, dma, Dma_request_ssi0_out, frequency); 58 } 59 60 61 62 /* C language interface. */ 63 64 void *x1600_spi_init(l4_addr_t spi_start, l4_addr_t start, l4_addr_t end, void *cpm) 65 { 66 return new Spi_x1600_chip(spi_start, start, end, static_cast<Cpm_chip *>(cpm)); 67 } 68 69 void *x1600_spi_get_channel(void *spi, uint8_t channel, void *dma, uint64_t frequency) 70 { 71 return static_cast<Spi_x1600_chip *>(spi)->get_channel(channel, 72 static_cast<Dma_channel *>(dma), frequency); 73 } 74 75 uint32_t x1600_spi_send(void *channel, uint32_t bytes, const uint8_t data[]) 76 { 77 return static_cast<Spi_x1600_channel *>(channel)->send(bytes, data); 78 } 79 80 uint32_t x1600_spi_send_dc(void *channel, uint32_t bytes, const uint8_t data[], 81 const int dc[], uint8_t char_size, int big_endian) 82 { 83 return static_cast<Spi_x1600_channel *>(channel)->send_dc(bytes, data, dc, 84 char_size, big_endian); 85 } 86 87 uint32_t x1600_spi_send_units(void *channel, uint32_t bytes, const uint8_t data[], 88 uint8_t unit_size, uint8_t char_size, int big_endian) 89 { 90 return static_cast<Spi_x1600_channel *>(channel)->send_units(bytes, data, 91 unit_size, char_size, big_endian); 92 } 93 94 uint32_t x1600_spi_transfer(void *channel, l4_addr_t vaddr, 95 l4re_dma_space_dma_addr_t paddr, 96 uint32_t count, uint8_t unit_size, 97 uint8_t char_size) 98 { 99 return static_cast<Spi_x1600_channel *>(channel)->transfer(vaddr, paddr, 100 count, unit_size, char_size); 101 } 102 103 uint32_t x1600_spi_transfer_descriptor(void *channel, l4_addr_t vaddr, 104 l4re_dma_space_dma_addr_t paddr, 105 uint32_t count, uint8_t unit_size, 106 uint8_t char_size, l4_addr_t desc_vaddr, 107 l4re_dma_space_dma_addr_t desc_paddr) 108 { 109 return static_cast<Spi_x1600_channel *>(channel)->transfer(vaddr, paddr, 110 count, unit_size, char_size, desc_vaddr, desc_paddr); 111 }