1 1.8 skrll /* $Id: at91busvar.h,v 1.8 2023/04/21 15:00:48 skrll Exp $ */ 2 1.8 skrll /* $NetBSD: at91busvar.h,v 1.8 2023/04/21 15:00:48 skrll Exp $ */ 3 1.2 matt 4 1.2 matt /* 5 1.2 matt * Copyright (c) 2007 Embedtronics Oy 6 1.2 matt * All rights reserved. 7 1.2 matt * 8 1.2 matt * Redistribution and use in source and binary forms, with or without 9 1.2 matt * modification, are permitted provided that the following conditions 10 1.2 matt * are met: 11 1.2 matt * 1. Redistributions of source code must retain the above copyright 12 1.2 matt * notice, this list of conditions and the following disclaimer. 13 1.2 matt * 2. Redistributions in binary form must reproduce the above copyright 14 1.2 matt * notice, this list of conditions and the following disclaimer in the 15 1.2 matt * documentation and/or other materials provided with the distribution. 16 1.2 matt * 17 1.2 matt * THIS SOFTWARE IS PROVIDED BY ICHIRO FUKUHARA ``AS IS'' AND ANY EXPRESS OR 18 1.2 matt * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 1.2 matt * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 1.2 matt * IN NO EVENT SHALL ICHIRO FUKUHARA OR THE VOICES IN HIS HEAD BE LIABLE FOR 21 1.2 matt * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 1.2 matt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 1.2 matt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 1.2 matt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 1.2 matt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 1.2 matt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 1.2 matt * SUCH DAMAGE. 28 1.2 matt */ 29 1.2 matt 30 1.2 matt #ifndef _AT91BUSVAR_H_ 31 1.2 matt #define _AT91BUSVAR_H_ 32 1.2 matt 33 1.2 matt #include <sys/conf.h> 34 1.2 matt #include <sys/device.h> 35 1.2 matt #include <sys/queue.h> 36 1.2 matt 37 1.4 dyoung #include <sys/bus.h> 38 1.2 matt #include <arm/at91/at91piovar.h> 39 1.2 matt 40 1.2 matt 41 1.2 matt /* clocks: */ 42 1.2 matt struct at91bus_clocks { 43 1.6 skrll uint32_t slow; /* slow clock in Hz */ 44 1.6 skrll uint32_t main; /* main clock in Hz */ 45 1.6 skrll uint32_t cpu; /* processor clock in Hz */ 46 1.6 skrll uint32_t master; /* master clock in Hz */ 47 1.6 skrll uint32_t plla; /* PLLA clock */ 48 1.6 skrll uint32_t pllb; /* PLLB clock */ 49 1.2 matt }; 50 1.2 matt 51 1.2 matt extern struct at91bus_clocks at91bus_clocks; 52 1.2 matt 53 1.2 matt #define AT91_SCLK at91bus_clocks.slow 54 1.2 matt #define AT91_MCLK at91bus_clocks.main 55 1.2 matt #define AT91_PCLK at91bus_clocks.cpu 56 1.2 matt #define AT91_MSTCLK at91bus_clocks.master 57 1.2 matt #define AT91_PLLACLK at91bus_clocks.plla 58 1.2 matt #define AT91_PLLBCLK at91bus_clocks.pllb 59 1.2 matt 60 1.2 matt 61 1.2 matt /* at91bus attach arguments: */ 62 1.2 matt struct at91bus_attach_args { 63 1.2 matt bus_space_tag_t sa_iot; /* bus tag */ 64 1.2 matt bus_dma_tag_t sa_dmat; /* DMA tag */ 65 1.2 matt bus_addr_t sa_addr; /* I/O base address */ 66 1.2 matt bus_size_t sa_size; /* I/O space size */ 67 1.2 matt int sa_pid; /* peripheral ID */ 68 1.2 matt }; 69 1.2 matt 70 1.2 matt 71 1.2 matt struct at91bus_softc { 72 1.2 matt device_t sc_dev; 73 1.2 matt bus_space_tag_t sc_iot; 74 1.2 matt bus_space_handle_t sc_ioh; 75 1.2 matt bus_dma_tag_t sc_dmat; 76 1.2 matt }; 77 1.2 matt 78 1.5 skrll struct trapframe; 79 1.2 matt 80 1.2 matt struct at91bus_machdep { 81 1.2 matt /* initialization: */ 82 1.2 matt void (*init)(struct at91bus_clocks *); 83 1.2 matt void (*attach_cn)(bus_space_tag_t, int speed, int flags); 84 1.2 matt const struct pmap_devmap *(*devmap)(void); 85 1.2 matt 86 1.2 matt /* clocking support: */ 87 1.2 matt void (*peripheral_clock)(int pid, int enable); 88 1.2 matt 89 1.2 matt /* PIO support: */ 90 1.2 matt at91pio_port (*pio_port)(int pid); 91 1.2 matt uint32_t (*gpio_mask)(int pid); 92 1.2 matt 93 1.2 matt /* interrupt handling support: */ 94 1.2 matt void (*intr_init)(void); 95 1.2 matt void *(*intr_establish)(int pid, int ipl, int type, int (*ih_func)(void *), void *arg); 96 1.2 matt void (*intr_disestablish)(void *cookie); 97 1.2 matt void (*intr_poll)(void *cookie, int flags); 98 1.5 skrll void (*intr_dispatch)(struct trapframe *); 99 1.2 matt 100 1.2 matt /* configuration */ 101 1.2 matt const char *(*peripheral_name)(int pid); 102 1.2 matt void (*search_peripherals)(device_t self, 103 1.2 matt device_t (*found_func)(device_t, bus_addr_t, int pid)); 104 1.2 matt }; 105 1.2 matt typedef const struct at91bus_machdep * at91bus_tag_t; 106 1.2 matt 107 1.2 matt #ifdef AT91RM9200 108 1.2 matt extern const struct at91bus_machdep at91rm9200bus; 109 1.2 matt #endif 110 1.2 matt 111 1.6 skrll extern uint32_t at91_chip_id; 112 1.2 matt #define AT91_CHIP_ID() at91_chip_id 113 1.2 matt extern at91bus_tag_t at91bus_tag; 114 1.2 matt extern struct bus_space at91_bs_tag; 115 1.2 matt extern struct arm32_bus_dma_tag at91_bd_tag; 116 1.2 matt 117 1.2 matt 118 1.2 matt extern int at91bus_init(void); 119 1.2 matt struct _BootConfig; 120 1.7 skrll extern vaddr_t at91bus_setup(struct _BootConfig *); 121 1.2 matt extern bus_dma_tag_t at91_bus_dma_init(struct arm32_bus_dma_tag *); 122 1.2 matt 123 1.2 matt static __inline const struct pmap_devmap * 124 1.2 matt at91_devmap(void) 125 1.2 matt { 126 1.2 matt return (*at91bus_tag->devmap)(); 127 1.2 matt } 128 1.2 matt 129 1.2 matt static __inline void 130 1.2 matt at91_peripheral_clock(int pid, int enable) 131 1.2 matt { 132 1.2 matt return (*at91bus_tag->peripheral_clock)(pid, enable); 133 1.2 matt } 134 1.2 matt 135 1.2 matt static __inline const char * 136 1.2 matt at91_peripheral_name(int pid) 137 1.2 matt { 138 1.2 matt return (*at91bus_tag->peripheral_name)(pid); 139 1.2 matt } 140 1.2 matt 141 1.2 matt static __inline at91pio_port 142 1.2 matt at91_pio_port(int pid) 143 1.2 matt { 144 1.2 matt return (*at91bus_tag->pio_port)(pid); 145 1.2 matt } 146 1.2 matt 147 1.2 matt static __inline uint32_t 148 1.2 matt at91_gpio_mask(int pid) 149 1.2 matt { 150 1.2 matt return (*at91bus_tag->gpio_mask)(pid); 151 1.2 matt } 152 1.2 matt 153 1.8 skrll static __inline void 154 1.2 matt at91_intr_init(void) 155 1.2 matt { 156 1.2 matt return (*at91bus_tag->intr_init)(); 157 1.2 matt } 158 1.2 matt 159 1.2 matt static __inline void * 160 1.2 matt at91_intr_establish(int pid, int ipl, int type, 161 1.2 matt int (*ih_func)(void *), void *ih_arg) 162 1.2 matt { 163 1.2 matt return (*at91bus_tag->intr_establish)(pid, ipl, type, ih_func, ih_arg); 164 1.2 matt } 165 1.2 matt 166 1.2 matt static __inline void 167 1.2 matt at91_intr_disestablish(void *cookie) 168 1.2 matt { 169 1.2 matt return (*at91bus_tag->intr_disestablish)(cookie); 170 1.2 matt } 171 1.2 matt 172 1.2 matt static __inline void 173 1.2 matt at91_intr_poll(void *cookie, int flags) 174 1.2 matt { 175 1.2 matt return (*at91bus_tag->intr_poll)(cookie, flags); 176 1.2 matt } 177 1.2 matt 178 1.2 matt static __inline void 179 1.2 matt at91_search_peripherals(device_t self, 180 1.2 matt device_t (*found_func)(device_t, bus_addr_t, int pid)) 181 1.2 matt { 182 1.2 matt return (*at91bus_tag->search_peripherals)(self, found_func); 183 1.2 matt } 184 1.2 matt 185 1.2 matt 186 1.2 matt #endif /* _AT91BUSVAR_H_ */ 187