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