1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/pkg/devices/lib/spi/include/spi-jz4780.h Tue Nov 07 19:20:32 2023 +0100
1.3 @@ -0,0 +1,105 @@
1.4 +/*
1.5 + * Perform SPI communication using the JZ4780 SPI peripheral.
1.6 + *
1.7 + * Copyright (C) 2023 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 +#pragma once
1.26 +
1.27 +#include <l4/re/c/dma_space.h>
1.28 +#include <l4/sys/types.h>
1.29 +#include <stdint.h>
1.30 +
1.31 +
1.32 +
1.33 +#ifdef __cplusplus
1.34 +
1.35 +#include <l4/devices/cpm-jz4780.h>
1.36 +#include <l4/devices/dma-jz4780.h>
1.37 +#include <l4/devices/hw_mmio_register_block.h>
1.38 +
1.39 +/* SPI peripheral channel. */
1.40 +
1.41 +class Spi_jz4780_channel
1.42 +{
1.43 + Hw::Register_block<32> _regs;
1.44 +
1.45 + /* Initialisation parameters. */
1.46 +
1.47 + l4_addr_t _spi_start;
1.48 + enum Clock_identifiers _clock;
1.49 + Cpm_jz4780_chip *_cpm;
1.50 + Dma_jz4780_channel *_dma;
1.51 + enum Dma_jz4780_request_type _request_type;
1.52 + uint64_t _frequency;
1.53 +
1.54 + void configure_transfer(uint8_t char_size);
1.55 +
1.56 +public:
1.57 + explicit Spi_jz4780_channel(l4_addr_t spi_start, l4_addr_t start,
1.58 + enum Clock_identifiers clock,
1.59 + Cpm_jz4780_chip *cpm,
1.60 + Dma_jz4780_channel *dma,
1.61 + enum Dma_jz4780_request_type request_type,
1.62 + uint64_t frequency);
1.63 +
1.64 + /* DMA operations. */
1.65 +
1.66 + uint32_t transfer(l4re_dma_space_dma_addr_t paddr, uint32_t count,
1.67 + uint8_t unit_size, uint8_t char_size);
1.68 +
1.69 + /* Convenience operations. */
1.70 +
1.71 + uint32_t send(uint32_t bytes, const uint8_t data[], uint8_t unit_size,
1.72 + uint8_t char_size);
1.73 +};
1.74 +
1.75 +/* SPI peripheral. */
1.76 +
1.77 +class Spi_jz4780_chip
1.78 +{
1.79 +private:
1.80 + l4_addr_t _spi_start, _start, _end;
1.81 + Cpm_jz4780_chip *_cpm;
1.82 +
1.83 +public:
1.84 + explicit Spi_jz4780_chip(l4_addr_t spi_start, l4_addr_t start, l4_addr_t end, Cpm_jz4780_chip *cpm);
1.85 +
1.86 + Spi_jz4780_channel *get_channel(uint8_t channel, Dma_jz4780_channel *dma, uint64_t frequency);
1.87 +};
1.88 +
1.89 +#endif /* __cplusplus */
1.90 +
1.91 +
1.92 +
1.93 +/* C language interface. */
1.94 +
1.95 +EXTERN_C_BEGIN
1.96 +
1.97 +void *jz4780_spi_init(l4_addr_t spi_start, l4_addr_t start, l4_addr_t end,
1.98 + void *cpm);
1.99 +
1.100 +void *jz4780_spi_get_channel(void *spi, uint8_t channel, void *dma, uint64_t frequency);
1.101 +
1.102 +uint32_t jz4780_spi_send(void *channel, uint32_t bytes, const uint8_t data[],
1.103 + uint8_t unit_size, uint8_t char_size);
1.104 +
1.105 +uint32_t jz4780_spi_transfer(void *channel, l4re_dma_space_dma_addr_t paddr,
1.106 + uint32_t count, uint8_t unit_size, uint8_t char_size);
1.107 +
1.108 +EXTERN_C_END