1/*	$Id: at91busvar.h,v 1.8 2023/04/21 15:00:48 skrll Exp $	*/
2/*	$NetBSD: at91busvar.h,v 1.8 2023/04/21 15:00:48 skrll Exp $ */
3
4/*
5 * Copyright (c) 2007 Embedtronics Oy
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
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.
16 *
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
27 * SUCH DAMAGE.
28 */
29
30#ifndef _AT91BUSVAR_H_
31#define _AT91BUSVAR_H_
32
33#include <sys/conf.h>
34#include <sys/device.h>
35#include <sys/queue.h>
36
37#include <sys/bus.h>
38#include <arm/at91/at91piovar.h>
39
40
41/* clocks: */
42struct at91bus_clocks {
43	uint32_t		slow;		/* slow clock in Hz	*/
44	uint32_t		main;		/* main clock in Hz	*/
45	uint32_t		cpu;		/* processor clock in Hz */
46	uint32_t		master;		/* master clock in Hz	*/
47	uint32_t		plla;		/* PLLA clock */
48	uint32_t		pllb;		/* PLLB clock */
49};
50
51extern struct at91bus_clocks at91bus_clocks;
52
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
59
60
61/* at91bus attach arguments: */
62struct 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	*/
68};
69
70
71struct at91bus_softc {
72	device_t		sc_dev;
73	bus_space_tag_t		sc_iot;
74	bus_space_handle_t	sc_ioh;
75	bus_dma_tag_t		sc_dmat;
76};
77
78struct trapframe;
79
80struct at91bus_machdep {
81	/* initialization: */
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);
85
86	/* clocking support: */
87	void (*peripheral_clock)(int pid, int enable);
88
89	/* PIO support: */
90	at91pio_port (*pio_port)(int pid);
91	uint32_t (*gpio_mask)(int pid);
92
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 trapframe *);
99
100	/* configuration */
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));
104};
105typedef const struct at91bus_machdep * at91bus_tag_t;
106
107#ifdef	AT91RM9200
108extern const struct at91bus_machdep at91rm9200bus;
109#endif
110
111extern uint32_t at91_chip_id;
112#define	AT91_CHIP_ID()	at91_chip_id
113extern at91bus_tag_t at91bus_tag;
114extern struct bus_space at91_bs_tag;
115extern struct arm32_bus_dma_tag at91_bd_tag;
116
117
118extern int at91bus_init(void);
119struct _BootConfig;
120extern vaddr_t at91bus_setup(struct _BootConfig *);
121extern bus_dma_tag_t at91_bus_dma_init(struct arm32_bus_dma_tag *);
122
123static __inline const struct pmap_devmap *
124at91_devmap(void)
125{
126	return (*at91bus_tag->devmap)();
127}
128
129static __inline void
130at91_peripheral_clock(int pid, int enable)
131{
132	return (*at91bus_tag->peripheral_clock)(pid, enable);
133}
134
135static __inline const char *
136at91_peripheral_name(int pid)
137{
138	return (*at91bus_tag->peripheral_name)(pid);
139}
140
141static __inline at91pio_port
142at91_pio_port(int pid)
143{
144	return (*at91bus_tag->pio_port)(pid);
145}
146
147static __inline uint32_t
148at91_gpio_mask(int pid)
149{
150	return (*at91bus_tag->gpio_mask)(pid);
151}
152
153static __inline void
154at91_intr_init(void)
155{
156	return (*at91bus_tag->intr_init)();
157}
158
159static __inline void *
160at91_intr_establish(int pid, int ipl, int type,
161		     int (*ih_func)(void *), void *ih_arg)
162{
163	return (*at91bus_tag->intr_establish)(pid, ipl, type, ih_func, ih_arg);
164}
165
166static __inline void
167at91_intr_disestablish(void *cookie)
168{
169	return (*at91bus_tag->intr_disestablish)(cookie);
170}
171
172static __inline void
173at91_intr_poll(void *cookie, int flags)
174{
175	return (*at91bus_tag->intr_poll)(cookie, flags);
176}
177
178static __inline void
179at91_search_peripherals(device_t self,
180			device_t (*found_func)(device_t, bus_addr_t, int pid))
181{
182	return (*at91bus_tag->search_peripherals)(self, found_func);
183}
184
185
186#endif /* _AT91BUSVAR_H_ */
187