1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/pkg/devices/lib/spi/src/x1600.cc Fri Jun 07 16:12:32 2024 +0200
1.3 @@ -0,0 +1,111 @@
1.4 +/*
1.5 + * Perform SPI communication using the X1600 SPI peripheral.
1.6 + *
1.7 + * Copyright (C) 2023, 2024 Paul Boddie <paul@boddie.org.uk>
1.8 + *
1.9 + * This program is free software; you can redistribute it and/or
1.10 + * modify it under the terms of the GNU General Public License as
1.11 + * published by the Free Software Foundation; either version 2 of
1.12 + * the License, or (at your option) any later version.
1.13 + *
1.14 + * This program is distributed in the hope that it will be useful,
1.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.17 + * GNU General Public License for more details.
1.18 + *
1.19 + * You should have received a copy of the GNU General Public License
1.20 + * along with this program; if not, write to the Free Software
1.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
1.22 + * Boston, MA 02110-1301, USA
1.23 + */
1.24 +
1.25 +#include <l4/devices/spi-x1600.h>
1.26 +
1.27 +
1.28 +
1.29 +/* Initialise a channel. */
1.30 +
1.31 +Spi_x1600_channel::Spi_x1600_channel(l4_addr_t spi_start, l4_addr_t start,
1.32 + enum Clock_identifiers clock,
1.33 + Cpm_chip *cpm,
1.34 + Dma_channel *dma,
1.35 + enum Dma_x1600_request_type request_type,
1.36 + uint64_t frequency)
1.37 +: Spi_channel(spi_start, start, clock, cpm, dma, request_type, frequency)
1.38 +{
1.39 +}
1.40 +
1.41 +
1.42 +
1.43 +/* Initialise the peripheral abstraction. */
1.44 +
1.45 +Spi_x1600_chip::Spi_x1600_chip(l4_addr_t spi_start, l4_addr_t start,
1.46 + l4_addr_t end, Cpm_chip *cpm)
1.47 +: Spi_chip(spi_start, start, end, cpm)
1.48 +{
1.49 +}
1.50 +
1.51 +Spi_channel *
1.52 +Spi_x1600_chip::_get_channel(uint8_t channel, Dma_channel *dma,
1.53 + uint64_t frequency)
1.54 +{
1.55 + (void) channel;
1.56 +
1.57 + // NOTE: Only sending is supported.
1.58 +
1.59 + return new Spi_x1600_channel(_spi_start, _start, Clock_ssi0,
1.60 + _cpm, dma, Dma_request_ssi0_out, frequency);
1.61 +}
1.62 +
1.63 +
1.64 +
1.65 +/* C language interface. */
1.66 +
1.67 +void *x1600_spi_init(l4_addr_t spi_start, l4_addr_t start, l4_addr_t end, void *cpm)
1.68 +{
1.69 + return new Spi_x1600_chip(spi_start, start, end, static_cast<Cpm_chip *>(cpm));
1.70 +}
1.71 +
1.72 +void *x1600_spi_get_channel(void *spi, uint8_t channel, void *dma, uint64_t frequency)
1.73 +{
1.74 + return static_cast<Spi_x1600_chip *>(spi)->get_channel(channel,
1.75 + static_cast<Dma_channel *>(dma), frequency);
1.76 +}
1.77 +
1.78 +uint32_t x1600_spi_send(void *channel, uint32_t bytes, const uint8_t data[])
1.79 +{
1.80 + return static_cast<Spi_x1600_channel *>(channel)->send(bytes, data);
1.81 +}
1.82 +
1.83 +uint32_t x1600_spi_send_dc(void *channel, uint32_t bytes, const uint8_t data[],
1.84 + const int dc[], uint8_t char_size, int big_endian)
1.85 +{
1.86 + return static_cast<Spi_x1600_channel *>(channel)->send_dc(bytes, data, dc,
1.87 + char_size, big_endian);
1.88 +}
1.89 +
1.90 +uint32_t x1600_spi_send_units(void *channel, uint32_t bytes, const uint8_t data[],
1.91 + uint8_t unit_size, uint8_t char_size, int big_endian)
1.92 +{
1.93 + return static_cast<Spi_x1600_channel *>(channel)->send_units(bytes, data,
1.94 + unit_size, char_size, big_endian);
1.95 +}
1.96 +
1.97 +uint32_t x1600_spi_transfer(void *channel, l4_addr_t vaddr,
1.98 + l4re_dma_space_dma_addr_t paddr,
1.99 + uint32_t count, uint8_t unit_size,
1.100 + uint8_t char_size)
1.101 +{
1.102 + return static_cast<Spi_x1600_channel *>(channel)->transfer(vaddr, paddr,
1.103 + count, unit_size, char_size);
1.104 +}
1.105 +
1.106 +uint32_t x1600_spi_transfer_descriptor(void *channel, l4_addr_t vaddr,
1.107 + l4re_dma_space_dma_addr_t paddr,
1.108 + uint32_t count, uint8_t unit_size,
1.109 + uint8_t char_size, l4_addr_t desc_vaddr,
1.110 + l4re_dma_space_dma_addr_t desc_paddr)
1.111 +{
1.112 + return static_cast<Spi_x1600_channel *>(channel)->transfer(vaddr, paddr,
1.113 + count, unit_size, char_size, desc_vaddr, desc_paddr);
1.114 +}