Landfall

Annotated pkg/landfall-examples/hw_info/common.h

229:810ca800993b
11 months ago Paul Boddie Employ a picture representation compatible with 16-bit SPI transfers over DMA. cpm-library-improvements
paul@218 1
/*
paul@218 2
 * Access various peripherals on a board.
paul@218 3
 *
paul@218 4
 * Copyright (C) 2023 Paul Boddie <paul@boddie.org.uk>
paul@218 5
 *
paul@218 6
 * This program is free software; you can redistribute it and/or
paul@218 7
 * modify it under the terms of the GNU General Public License as
paul@218 8
 * published by the Free Software Foundation; either version 2 of
paul@218 9
 * the License, or (at your option) any later version.
paul@218 10
 *
paul@218 11
 * This program is distributed in the hope that it will be useful,
paul@218 12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
paul@218 13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
paul@218 14
 * GNU General Public License for more details.
paul@218 15
 *
paul@218 16
 * You should have received a copy of the GNU General Public License
paul@218 17
 * along with this program; if not, write to the Free Software
paul@218 18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
paul@218 19
 * Boston, MA  02110-1301, USA
paul@218 20
 */
paul@218 21
paul@218 22
#pragma once
paul@218 23
paul@218 24
#include <l4/re/c/dma_space.h>
paul@218 25
#include <l4/sys/types.h>
paul@218 26
#include <l4/devices/clocks.h>
paul@218 27
#include <l4/devices/gpio.h>
paul@218 28
#include <stdint.h>
paul@218 29
paul@218 30
paul@218 31
paul@218 32
/* AIC adapter functions. */
paul@218 33
paul@218 34
void *aic_init(l4_addr_t aic_start, l4_addr_t start, l4_addr_t end, void *cpm);
paul@218 35
paul@218 36
void *aic_get_channel(void *aic, int num, void *channel);
paul@218 37
paul@221 38
unsigned int aic_transfer(void *channel, l4re_dma_space_dma_addr_t paddr,
paul@221 39
                          uint32_t count, uint32_t sample_rate,
paul@218 40
                          uint8_t sample_size);
paul@218 41
paul@218 42
paul@218 43
paul@218 44
/* CPM adapter functions. */
paul@218 45
paul@218 46
void *cpm_init(l4_addr_t cpm_base);
paul@218 47
paul@218 48
const char *cpm_clock_type(void *cpm, enum Clock_identifiers clock);
paul@218 49
paul@218 50
int cpm_have_clock(void *cpm, enum Clock_identifiers clock);
paul@218 51
paul@218 52
void cpm_start_clock(void *cpm, enum Clock_identifiers clock);
paul@218 53
paul@218 54
void cpm_stop_clock(void *cpm, enum Clock_identifiers clock);
paul@218 55
paul@218 56
int cpm_get_parameters(void *cpm, enum Clock_identifiers clock,
paul@218 57
                       uint32_t parameters[]);
paul@218 58
paul@218 59
int cpm_set_parameters(void *cpm, enum Clock_identifiers clock,
paul@218 60
                       int num_parameters, uint32_t parameters[]);
paul@218 61
paul@218 62
uint8_t cpm_get_source(void *cpm, enum Clock_identifiers clock);
paul@218 63
paul@218 64
void cpm_set_source(void *cpm, enum Clock_identifiers clock, uint8_t source);
paul@218 65
paul@218 66
enum Clock_identifiers cpm_get_source_clock(void *cpm, enum Clock_identifiers clock);
paul@218 67
paul@218 68
void cpm_set_source_clock(void *cpm, enum Clock_identifiers clock,
paul@218 69
                          enum Clock_identifiers source);
paul@218 70
paul@218 71
uint64_t cpm_get_source_frequency(void *cpm, enum Clock_identifiers clock);
paul@218 72
paul@218 73
uint64_t cpm_get_frequency(void *cpm, enum Clock_identifiers clock);
paul@218 74
paul@218 75
int cpm_set_frequency(void *cpm, enum Clock_identifiers clock, uint64_t frequency);
paul@218 76
paul@218 77
paul@218 78
paul@218 79
/* DMA adapter functions. */
paul@218 80
paul@218 81
void *dma_init(l4_addr_t start, l4_addr_t end, void *cpm);
paul@218 82
paul@218 83
void dma_disable(void *dma_chip);
paul@218 84
paul@218 85
void dma_enable(void *dma_chip);
paul@218 86
paul@218 87
void *dma_get_channel(void *dma, uint8_t channel, l4_cap_idx_t irq);
paul@218 88
paul@218 89
unsigned int dma_transfer(void *dma_channel,
paul@218 90
                          uint32_t source, uint32_t destination,
paul@218 91
                          unsigned int count,
paul@218 92
                          int source_increment, int destination_increment,
paul@218 93
                          uint8_t source_width, uint8_t destination_width,
paul@218 94
                          uint8_t transfer_unit_size,
paul@218 95
                          int type);
paul@218 96
paul@218 97
unsigned int dma_wait(void *dma_channel);
paul@218 98
paul@218 99
paul@218 100
paul@218 101
/* GPIO adapter functions. */
paul@218 102
paul@218 103
void *gpio_init(l4_addr_t start, l4_addr_t end, unsigned pins,
paul@218 104
                       l4_uint32_t pull_ups, l4_uint32_t pull_downs);
paul@218 105
paul@218 106
void gpio_setup(void *gpio, unsigned pin, unsigned mode, int value);
paul@218 107
paul@218 108
void gpio_config_pull(void *gpio, unsigned pin, unsigned mode);
paul@218 109
paul@218 110
void gpio_config_pad(void *gpio, unsigned pin, unsigned func, unsigned value);
paul@218 111
paul@218 112
void gpio_config_get(void *gpio, unsigned pin, unsigned reg, unsigned *value);
paul@218 113
paul@218 114
void gpio_config_pad_get(void *gpio, unsigned pin, unsigned *func, unsigned *value);
paul@218 115
paul@218 116
void gpio_multi_setup(void *gpio, Pin_slice const *mask, unsigned mode, unsigned outvalues);
paul@218 117
paul@218 118
void gpio_multi_config_pad(void *gpio, Pin_slice const *mask, unsigned func, unsigned value);
paul@218 119
paul@218 120
void gpio_multi_set(void *gpio, Pin_slice const *mask, unsigned data);
paul@218 121
paul@218 122
unsigned gpio_multi_get(void *gpio, unsigned offset);
paul@218 123
paul@218 124
int gpio_get(void *gpio, unsigned pin);
paul@218 125
paul@218 126
void gpio_set(void *gpio, unsigned pin, int value);
paul@218 127
paul@218 128
void *gpio_get_irq(void *gpio, unsigned pin);
paul@218 129
paul@218 130
bool gpio_irq_set_mode(void *gpio_irq, unsigned mode);
paul@218 131
paul@218 132
paul@218 133
paul@218 134
/* I2C adapter functions. */
paul@218 135
paul@218 136
void *i2c_init(l4_addr_t start, l4_addr_t end, void *cpm, uint32_t frequency);
paul@218 137
paul@218 138
void *i2c_get_channel(void *i2c, uint8_t channel);
paul@218 139
paul@218 140
uint32_t i2c_get_frequency(void *i2c_channel);
paul@218 141
paul@218 142
void i2c_set_target(void *i2c_channel, uint8_t addr);
paul@218 143
paul@218 144
void i2c_start_read(void *i2c_channel, uint8_t buf[], unsigned int total,
paul@218 145
                    int stop);
paul@218 146
paul@218 147
void i2c_read(void *i2c_channel);
paul@218 148
paul@218 149
void i2c_start_write(void *i2c_channel, uint8_t buf[], unsigned int total,
paul@218 150
                     int stop);
paul@218 151
paul@218 152
void i2c_write(void *i2c_channel);
paul@218 153
paul@218 154
int i2c_read_done(void *i2c_channel);
paul@218 155
paul@218 156
int i2c_write_done(void *i2c_channel);
paul@218 157
paul@218 158
unsigned int i2c_have_read(void *i2c_channel);
paul@218 159
paul@218 160
unsigned int i2c_have_written(void *i2c_channel);
paul@218 161
paul@218 162
int i2c_failed(void *i2c_channel);
paul@218 163
paul@218 164
void i2c_stop(void *i2c_channel);
paul@218 165
paul@218 166
paul@218 167
paul@218 168
/* SPI adapter functions. */
paul@218 169
paul@221 170
void *spi_init(l4_addr_t spi_start, l4_addr_t start, l4_addr_t end, void *cpm);
paul@221 171
paul@222 172
void *spi_get_channel(void *spi, uint8_t num, void *channel, uint64_t frequency,
paul@222 173
                      void *control_chip, int control_pin, int control_alt_func);
paul@218 174
paul@222 175
void *spi_get_channel_gpio(uint64_t frequency,
paul@222 176
                           void *clock_chip, int clock_pin,
paul@221 177
                           void *data_chip, int data_pin,
paul@221 178
                           void *enable_chip, int enable_pin,
paul@222 179
                           void *control_chip, int control_pin);
paul@222 180
paul@222 181
void spi_acquire_control(void *channel, int level);
paul@221 182
paul@222 183
void spi_release_control(void *channel);
paul@221 184
paul@222 185
void spi_send_gpio(void *channel, uint32_t bytes, const uint8_t data[]);
paul@222 186
paul@222 187
void spi_send_units(void *channel, uint32_t bytes, const uint8_t data[],
paul@222 188
                    uint8_t unit_size, uint8_t char_size);
paul@221 189
paul@221 190
uint32_t spi_transfer(void *channel, l4re_dma_space_dma_addr_t paddr,
paul@223 191
                      uint32_t count, uint8_t unit_size, uint8_t char_size,
paul@223 192
                      l4_addr_t desc_vaddr, l4re_dma_space_dma_addr_t desc_paddr);
paul@218 193
paul@218 194
paul@218 195
paul@218 196
/* Memory regions. */
paul@218 197
paul@218 198
enum memory_regions
paul@218 199
{
paul@221 200
  AIC, CPM, DMA, GPIO, I2C, SSI
paul@218 201
};
paul@218 202
paul@218 203
paul@218 204
paul@218 205
/* CPM definitions. */
paul@218 206
paul@218 207
struct clock_info
paul@218 208
{
paul@218 209
  const char *id;
paul@218 210
  enum Clock_identifiers clock;
paul@218 211
  const char *name;
paul@218 212
};
paul@218 213
paul@218 214
paul@218 215
paul@218 216
/* DMA definitions. */
paul@218 217
paul@218 218
struct dma_region
paul@218 219
{
paul@218 220
  unsigned int size;
paul@218 221
  unsigned int align;
paul@218 222
  l4_addr_t vaddr;
paul@218 223
  l4re_dma_space_dma_addr_t paddr;
paul@218 224
  l4_cap_idx_t mem;
paul@218 225
};
paul@218 226
paul@218 227
paul@218 228
paul@218 229
/* GPIO definitions. */
paul@218 230
paul@218 231
struct gpio_port
paul@218 232
{
paul@218 233
  const uint32_t pull_ups, pull_downs;
paul@218 234
};