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