RTEMS 7.0-rc1
Loading...
Searching...
No Matches
bsp.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
11/*
12 * Copyright (c) 2012 Claas Ziemke. All rights reserved.
13 *
14 * Claas Ziemke
15 * Kernerstrasse 11
16 * 70182 Stuttgart
17 * Germany
18 * <claas.ziemke@gmx.net>
19 *
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
22 * are met:
23 * 1. Redistributions of source code must retain the above copyright
24 * notice, this list of conditions and the following disclaimer.
25 * 2. Redistributions in binary form must reproduce the above copyright
26 * notice, this list of conditions and the following disclaimer in the
27 * documentation and/or other materials provided with the distribution.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
30 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
33 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
34 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
35 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
36 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
37 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39 * POSSIBILITY OF SUCH DAMAGE.
40 */
41
42#ifndef LIBBSP_ARM_BEAGLE_BSP_H
43#define LIBBSP_ARM_BEAGLE_BSP_H
44
55#include <bspopts.h>
56#include <stdint.h>
57#include <bsp/start.h>
59#include <bsp/beagleboneblack.h>
60
61#include <rtems.h>
62#include <rtems/irq-extension.h>
63
64#include <libcpu/omap3.h>
65#include <libcpu/am335x.h>
66
67#include <ofw/ofw.h>
68
69#define BSP_FEATURE_IRQ_EXTENSION
70
71/* UART base clock frequency */
72#define UART_CLOCK 48000000
73
74/* Access memory-mapped I/O devices */
75#define mmio_read(a) (*(volatile uint32_t *)(a))
76#define mmio_write(a,v) (*(volatile uint32_t *)(a) = (v))
77#define mmio_set(a,v) mmio_write((a), mmio_read((a)) | (v))
78#define mmio_clear(a,v) mmio_write((a), mmio_read((a)) & ~(v))
79
80#define REG16(x)(*((volatile uint16_t *)(x)))
81#define REG(x)(*((volatile uint32_t *)(x)))
82#define BIT(x)(0x1 << (x))
83// Start and End included
84#define BITS(Start, End) (((1 << (End+1)) - 1) & ~((1 << (Start)) - 1))
85
86#define udelay(u) rtems_task_wake_after(1 + ((u)/rtems_configuration_get_microseconds_per_tick()))
87
88int beagle_get_node_unit(phandle_t node);
89
90/* Write a uint32_t value to a memory address. */
91static inline void
92write32(uint32_t address, uint32_t value)
93{
94 REG(address) = value;
95}
96
97/* Read an uint32_t from a memory address */
98static inline uint32_t
99read32(uint32_t address)
100{
101 return REG(address);
102}
103
104/* Set a 32 bits value depending on a mask */
105static inline void
106set32(uint32_t address, uint32_t mask, uint32_t value)
107{
108 uint32_t val;
109 val = read32(address);
110 /* clear the bits */
111 val &= ~(mask);
112 /* apply the value using the mask */
113 val |= (value & mask);
114 write32(address, val);
115}
116
117/* Write a uint16_t value to a memory address. */
118static inline void
119write16(uint32_t address, uint16_t value)
120{
121 REG16(address) = value;
122}
123
124/* Read an uint16_t from a memory address */
125static inline uint16_t
126read16(uint32_t address)
127{
128 return REG16(address);
129}
130
131/* Data synchronization barrier */
132static inline void dsb(void)
133{
134 __asm__ volatile("dsb" : : : "memory");
135}
136
137/* Instruction synchronization barrier */
138static inline void isb(void)
139{
140 __asm__ volatile("isb" : : : "memory");
141}
142
143/* flush data cache */
144static inline void flush_data_cache(void)
145{
146 __asm__ volatile(
147 "mov r0, #0\n"
148 "mcr p15, #0, r0, c7, c10, #4\n"
149 : /* No outputs */
150 : /* No inputs */
151 : "r0","memory"
152 );
153}
154
155#define __arch_getb(a) (*(volatile unsigned char *)(a))
156#define __arch_getw(a) (*(volatile unsigned short *)(a))
157#define __arch_getl(a) (*(volatile unsigned int *)(a))
158
159#define __arch_putb(v,a) (*(volatile unsigned char *)(a) = (v))
160#define __arch_putw(v,a) (*(volatile unsigned short *)(a) = (v))
161#define __arch_putl(v,a) (*(volatile unsigned int *)(a) = (v))
162
163#define writeb(v,c) ({ unsigned char __v = v; __arch_putb(__v,c); __v; })
164#define writew(v,c) ({ unsigned short __v = v; __arch_putw(__v,c); __v; })
165#define writel(v,c) ({ unsigned int __v = v; __arch_putl(__v,c); __v; })
166
167#define readb(c) ({ unsigned char __v = __arch_getb(c); __v; })
168#define readw(c) ({ unsigned short __v = __arch_getw(c); __v; })
169#define readl(c) ({ unsigned int __v = __arch_getl(c); __v; })
170
171#define SYSTEM_CLOCK_12 12000000
172#define SYSTEM_CLOCK_13 13000000
173#define SYSTEM_CLOCK_192 19200000
174#define SYSTEM_CLOCK_96 96000000
175
176#if !defined(IS_DM3730) && !defined(IS_AM335X)
177#error Unrecognized BSP configured.
178#endif
179
180#if IS_DM3730
181#define BSP_DEVICEMEM_START 0x48000000
182#define BSP_DEVICEMEM_END 0x5F000000
183#endif
184
185#if IS_AM335X
186#define BSP_DEVICEMEM_START 0x44000000
187#define BSP_DEVICEMEM_END 0x57000000
188#endif
189
190/* per-target uart config */
191#if IS_AM335X
192#define BSP_CONSOLE_UART 1
193#define BSP_CONSOLE_UART_BASE BEAGLE_BASE_UART_1
194#define BSP_CONSOLE_UART_IRQ OMAP3_UART1_IRQ
195#define BEAGLE_BASE_UART_1 0x44E09000
196#define BEAGLE_BASE_UART_2 0x48022000
197#define BEAGLE_BASE_UART_3 0x48024000
198#endif
199
200/* per-target uart config */
201#if IS_DM3730
202#define BSP_CONSOLE_UART 3
203#define BSP_CONSOLE_UART_BASE BEAGLE_BASE_UART_3
204#define BSP_CONSOLE_UART_IRQ OMAP3_UART3_IRQ
205#define BEAGLE_BASE_UART_1 0x4806A000
206#define BEAGLE_BASE_UART_2 0x4806C000
207#define BEAGLE_BASE_UART_3 0x49020000
208#endif
209
210/* GPIO pin config */
211#if IS_AM335X
212#define BSP_GPIO_PIN_COUNT 128
213#define BSP_GPIO_PINS_PER_BANK 32
214#endif
215
216#if IS_DM3730
217#define BSP_GPIO_PIN_COUNT 192
218#define BSP_GPIO_PINS_PER_BANK 32
219#endif
220
221#if BSP_START_COPY_FDT_FROM_U_BOOT
222#define BSP_FDT_IS_SUPPORTED
223#endif
224
225/* i2c stuff */
226typedef struct {
227 uint32_t rx_or_tx;
228 uint32_t stat;
229 uint32_t ctrl;
230 uint32_t clk_hi;
231 uint32_t clk_lo;
232 uint32_t adr;
233 uint32_t rxfl;
234 uint32_t txfl;
235 uint32_t rxb;
236 uint32_t txb;
237 uint32_t s_tx;
238 uint32_t s_txfl;
239} beagle_i2c;
240
241/* sctlr */
242/* Read System Control Register */
243static inline uint32_t read_sctlr(void)
244{
245 uint32_t ctl;
246
247 __asm__ volatile("mrc p15, 0, %[ctl], c1, c0, 0 @ Read SCTLR\n\t"
248 : [ctl] "=r" (ctl));
249 return ctl;
250}
251
252/* Write System Control Register */
253static inline void write_sctlr(uint32_t ctl)
254{
255 __asm__ volatile("mcr p15, 0, %[ctl], c1, c0, 0 @ Write SCTLR\n\t"
256 : : [ctl] "r" (ctl));
257 isb();
258}
259
260/* Read Auxiliary Control Register */
261static inline uint32_t read_actlr(void)
262{
263 uint32_t ctl;
264
265 __asm__ volatile("mrc p15, 0, %[ctl], c1, c0, 1 @ Read ACTLR\n\t"
266 : [ctl] "=r" (ctl));
267 return ctl;
268}
269
270/* Write Auxiliary Control Register */
271static inline void write_actlr(uint32_t ctl)
272{
273 __asm__ volatile("mcr p15, 0, %[ctl], c1, c0, 1 @ Write ACTLR\n\t"
274 : : [ctl] "r" (ctl));
275 isb();
276}
277
278/* Write Translation Table Base Control Register */
279static inline void write_ttbcr(uint32_t bcr)
280{
281 __asm__ volatile("mcr p15, 0, %[bcr], c2, c0, 2 @ Write TTBCR\n\t"
282 : : [bcr] "r" (bcr));
283
284 isb();
285}
286
287/* Read Domain Access Control Register */
288static inline uint32_t read_dacr(void)
289{
290 uint32_t dacr;
291
292 __asm__ volatile("mrc p15, 0, %[dacr], c3, c0, 0 @ Read DACR\n\t"
293 : [dacr] "=r" (dacr));
294
295 return dacr;
296}
297
298
299/* Write Domain Access Control Register */
300static inline void write_dacr(uint32_t dacr)
301{
302 __asm__ volatile("mcr p15, 0, %[dacr], c3, c0, 0 @ Write DACR\n\t"
303 : : [dacr] "r" (dacr));
304
305 isb();
306}
307
308static inline void refresh_tlb(void)
309{
310 dsb();
311
312 /* Invalidate entire unified TLB */
313 __asm__ volatile("mcr p15, 0, %[zero], c8, c7, 0 @ TLBIALL\n\t"
314 : : [zero] "r" (0));
315
316 /* Invalidate all instruction caches to PoU.
317 * Also flushes branch target cache. */
318 __asm__ volatile("mcr p15, 0, %[zero], c7, c5, 0"
319 : : [zero] "r" (0));
320
321 /* Invalidate entire branch predictor array */
322 __asm__ volatile("mcr p15, 0, %[zero], c7, c5, 6"
323 : : [zero] "r" (0)); /* flush BTB */
324
325 dsb();
326 isb();
327}
328
329/* Read Translation Table Base Register 0 */
330static inline uint32_t read_ttbr0(void)
331{
332 uint32_t bar;
333
334 __asm__ volatile("mrc p15, 0, %[bar], c2, c0, 0 @ Read TTBR0\n\t"
335 : [bar] "=r" (bar));
336
337 return bar & ARM_TTBR_ADDR_MASK;
338}
339
340
341/* Read Translation Table Base Register 0 */
342static inline uint32_t read_ttbr0_unmasked(void)
343{
344 uint32_t bar;
345
346 __asm__ volatile("mrc p15, 0, %[bar], c2, c0, 0 @ Read TTBR0\n\t"
347 : [bar] "=r" (bar));
348
349 return bar;
350}
351
352/* Write Translation Table Base Register 0 */
353static inline void write_ttbr0(uint32_t bar)
354{
355 dsb();
356 isb();
357 /* In our setup TTBR contains the base address *and* the flags
358 but other pieces of the kernel code expect ttbr to be the
359 base address of the l1 page table. We therefore add the
360 flags here and remove them in the read_ttbr0 */
361 uint32_t v = (bar & ARM_TTBR_ADDR_MASK ) | ARM_TTBR_FLAGS_CACHED;
362 __asm__ volatile("mcr p15, 0, %[bar], c2, c0, 0 @ Write TTBR0\n\t"
363 : : [bar] "r" (v));
364
365 refresh_tlb();
366}
367
373BSP_START_TEXT_SECTION void beagle_setup_mmu_and_cache(void);
374
375/* @} */
376
377#endif /* LIBBSP_ARM_BEAGLE_BSP_H */
BeagleBone Black BSP definitions.
This header file provides the default definition of BSP_INITIAL_EXTENSION.
BSP_START_TEXT_SECTION void beagle_setup_mmu_and_cache(void)
Beagleboard specific set up of the MMU.
Definition: bspstartmmu.c:49
This header file is provided for backward compatiblility.
uint32_t phandle_t
Definition: ofw.h:56
This header file defines the RTEMS Classic API.
Definition: bsp.h:226