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