1 /* $Id: at91busvar.h,v 1.3 2009/10/23 06:53:13 snj Exp $ */
2 /* $NetBSD: at91busvar.h,v 1.2 2008/07/03 01:15:38 matt Exp $ */
5 * Copyright (c) 2007 Embedtronics Oy
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY ICHIRO FUKUHARA ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL ICHIRO FUKUHARA OR THE VOICES IN HIS HEAD BE LIABLE FOR
21 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #ifndef _AT91BUSVAR_H_
31 #define _AT91BUSVAR_H_
34 #include <sys/device.h>
35 #include <sys/queue.h>
37 #include <machine/bus.h>
38 #include <arm/at91/at91piovar.h>
42 struct at91bus_clocks
{
43 u_int32_t slow
; /* slow clock in Hz */
44 u_int32_t main
; /* main clock in Hz */
45 u_int32_t cpu
; /* processor clock in Hz */
46 u_int32_t master
; /* master clock in Hz */
47 u_int32_t plla
; /* PLLA clock */
48 u_int32_t pllb
; /* PLLB clock */
51 extern struct at91bus_clocks at91bus_clocks
;
53 #define AT91_SCLK at91bus_clocks.slow
54 #define AT91_MCLK at91bus_clocks.main
55 #define AT91_PCLK at91bus_clocks.cpu
56 #define AT91_MSTCLK at91bus_clocks.master
57 #define AT91_PLLACLK at91bus_clocks.plla
58 #define AT91_PLLBCLK at91bus_clocks.pllb
61 /* at91bus attach arguments: */
62 struct at91bus_attach_args
{
63 bus_space_tag_t sa_iot
; /* bus tag */
64 bus_dma_tag_t sa_dmat
; /* DMA tag */
65 bus_addr_t sa_addr
; /* I/O base address */
66 bus_size_t sa_size
; /* I/O space size */
67 int sa_pid
; /* peripheral ID */
71 struct at91bus_softc
{
73 bus_space_tag_t sc_iot
;
74 bus_space_handle_t sc_ioh
;
75 bus_dma_tag_t sc_dmat
;
80 struct at91bus_machdep
{
82 void (*init
)(struct at91bus_clocks
*);
83 void (*attach_cn
)(bus_space_tag_t
, int speed
, int flags
);
84 const struct pmap_devmap
*(*devmap
)(void);
86 /* clocking support: */
87 void (*peripheral_clock
)(int pid
, int enable
);
90 at91pio_port (*pio_port
)(int pid
);
91 uint32_t (*gpio_mask
)(int pid
);
93 /* interrupt handling support: */
94 void (*intr_init
)(void);
95 void *(*intr_establish
)(int pid
, int ipl
, int type
, int (*ih_func
)(void *), void *arg
);
96 void (*intr_disestablish
)(void *cookie
);
97 void (*intr_poll
)(void *cookie
, int flags
);
98 void (*intr_dispatch
)(struct irqframe
*);
101 const char *(*peripheral_name
)(int pid
);
102 void (*search_peripherals
)(device_t self
,
103 device_t (*found_func
)(device_t
, bus_addr_t
, int pid
));
105 typedef const struct at91bus_machdep
* at91bus_tag_t
;
108 extern const struct at91bus_machdep at91rm9200bus
;
111 extern u_int32_t at91_chip_id
;
112 #define AT91_CHIP_ID() at91_chip_id
113 extern at91bus_tag_t at91bus_tag
;
114 extern struct bus_space at91_bs_tag
;
115 extern struct arm32_bus_dma_tag at91_bd_tag
;
118 extern int at91bus_init(void);
120 extern u_int
at91bus_setup(struct _BootConfig
*);
121 extern bus_dma_tag_t
at91_bus_dma_init(struct arm32_bus_dma_tag
*);
123 static __inline
const struct pmap_devmap
*
126 return (*at91bus_tag
->devmap
)();
130 at91_peripheral_clock(int pid
, int enable
)
132 return (*at91bus_tag
->peripheral_clock
)(pid
, enable
);
135 static __inline
const char *
136 at91_peripheral_name(int pid
)
138 return (*at91bus_tag
->peripheral_name
)(pid
);
141 static __inline at91pio_port
142 at91_pio_port(int pid
)
144 return (*at91bus_tag
->pio_port
)(pid
);
147 static __inline
uint32_t
148 at91_gpio_mask(int pid
)
150 return (*at91bus_tag
->gpio_mask
)(pid
);
156 return (*at91bus_tag
->intr_init
)();
159 static __inline
void *
160 at91_intr_establish(int pid
, int ipl
, int type
,
161 int (*ih_func
)(void *), void *ih_arg
)
163 return (*at91bus_tag
->intr_establish
)(pid
, ipl
, type
, ih_func
, ih_arg
);
167 at91_intr_disestablish(void *cookie
)
169 return (*at91bus_tag
->intr_disestablish
)(cookie
);
173 at91_intr_poll(void *cookie
, int flags
)
175 return (*at91bus_tag
->intr_poll
)(cookie
, flags
);
179 at91_search_peripherals(device_t self
,
180 device_t (*found_func
)(device_t
, bus_addr_t
, int pid
))
182 return (*at91bus_tag
->search_peripherals
)(self
, found_func
);
186 #endif /* _AT91BUSVAR_H_ */