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