source: rtems/c/src/lib/libbsp/arm/beagle/include/bsp.h @ 151e53f

5
Last change on this file since 151e53f was 151e53f, checked in by Ketul Shah <ketulshah1993@…>, on 08/18/15 at 14:30:48

Beagle: GPIO support (for BBB)

GPIO Driver Development for BeagleBone? Black based on the generic GPIO API

  • Property mode set to 100644
File size: 8.7 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup arm_beagle
5 *
6 * @brief Global BSP definitions.
7 */
8
9/*
10 * Copyright (c) 2012 Claas Ziemke. All rights reserved.
11 *
12 *  Claas Ziemke
13 *  Kernerstrasse 11
14 *  70182 Stuttgart
15 *  Germany
16 *  <claas.ziemke@gmx.net>
17 *
18 * The license and distribution terms for this file may be
19 * found in the file LICENSE in this distribution or at
20 * http://www.rtems.org/license/LICENSE.
21 *
22 * Modified by Ben Gras <beng@shrike-systems.com> to add lots
23 * of beagleboard/beaglebone definitions, delete lpc32xx specific
24 * ones, and merge with some other header files.
25 */
26
27#ifndef LIBBSP_ARM_BEAGLE_BSP_H
28#define LIBBSP_ARM_BEAGLE_BSP_H
29
30#include <bspopts.h>
31#include <stdint.h>
32#include <bsp/start.h>
33#include <bsp/default-initial-extension.h>
34#include <bsp/beagleboneblack.h>
35
36#include <rtems.h>
37#include <rtems/irq-extension.h>
38
39#include <libcpu/omap3.h>
40#include <libcpu/am335x.h>
41
42#define BSP_FEATURE_IRQ_EXTENSION
43
44/* UART base clock frequency */
45#define UART_CLOCK     48000000
46
47/* Access memory-mapped I/O devices */
48#define mmio_read(a)    (*(volatile uint32_t *)(a))
49#define mmio_write(a,v) (*(volatile uint32_t *)(a) = (v))
50#define mmio_set(a,v)   mmio_write((a), mmio_read((a)) | (v))
51#define mmio_clear(a,v) mmio_write((a), mmio_read((a)) & ~(v))
52
53#define REG16(x)(*((volatile uint16_t *)(x)))
54#define REG(x)(*((volatile uint32_t *)(x)))
55#define BIT(x)(0x1 << x)
56
57#define udelay(u) rtems_task_wake_after(1 + ((u)/rtems_configuration_get_microseconds_per_tick()))
58
59/* Write a uint32_t value to a memory address. */
60static inline void
61write32(uint32_t address, uint32_t value)
62{
63    REG(address) = value;
64}
65
66/* Read an uint32_t from a memory address */
67static inline uint32_t
68read32(uint32_t address)
69{
70    return REG(address);
71}
72
73/* Set a 32 bits value depending on a mask */
74static inline void
75set32(uint32_t address, uint32_t mask, uint32_t value)
76{
77    uint32_t val;
78    val = read32(address);
79    /* clear the bits */
80    val &= ~(mask);
81    /* apply the value using the mask */
82    val |= (value & mask);
83    write32(address, val);
84}
85
86/* Write a uint16_t value to a memory address. */
87static inline void
88write16(uint32_t address, uint16_t value)
89{
90    REG16(address) = value;
91}
92
93/* Read an uint16_t from a memory address */
94static inline uint16_t
95read16(uint32_t address)
96{
97    return REG16(address);
98}
99
100/* Data synchronization barrier */
101static inline void dsb(void)
102{
103    asm volatile("dsb" : : : "memory");
104}
105
106/* Instruction synchronization barrier */
107static inline void isb(void)
108{
109    asm volatile("isb" : : : "memory");
110}
111
112/* flush data cache */
113static inline void flush_data_cache(void)
114{
115    asm volatile("mov r0, #0; mcr p15, #0, r0, c7, c10, #4" : : : "memory");
116}
117
118#define __arch_getb(a)      (*(volatile unsigned char *)(a))
119#define __arch_getw(a)      (*(volatile unsigned short *)(a))
120#define __arch_getl(a)      (*(volatile unsigned int *)(a))
121
122#define __arch_putb(v,a)    (*(volatile unsigned char *)(a) = (v))
123#define __arch_putw(v,a)    (*(volatile unsigned short *)(a) = (v))
124#define __arch_putl(v,a)    (*(volatile unsigned int *)(a) = (v))
125
126#define writeb(v,c) ({ unsigned char  __v = v; __arch_putb(__v,c); __v; })
127#define writew(v,c) ({ unsigned short __v = v; __arch_putw(__v,c); __v; })
128#define writel(v,c) ({ unsigned int __v = v; __arch_putl(__v,c); __v; })
129
130#define readb(c)  ({ unsigned char  __v = __arch_getb(c); __v; })
131#define readw(c)  ({ unsigned short __v = __arch_getw(c); __v; })
132#define readl(c)  ({ unsigned int __v = __arch_getl(c); __v; })
133
134#define SYSTEM_CLOCK_12       12000000
135#define SYSTEM_CLOCK_13       13000000
136#define SYSTEM_CLOCK_192      19200000
137#define SYSTEM_CLOCK_96       96000000
138
139#if !defined(IS_DM3730) && !defined(IS_AM335X)
140#error Unrecognized BSP configured.
141#endif
142
143#if IS_DM3730
144#define BSP_DEVICEMEM_START 0x48000000
145#define BSP_DEVICEMEM_END   0x5F000000
146#endif
147
148#if IS_AM335X
149#define BSP_DEVICEMEM_START 0x44000000
150#define BSP_DEVICEMEM_END   0x57000000
151#endif
152
153/* per-target uart config */
154#if IS_AM335X
155#define BSP_CONSOLE_UART        1
156#define BSP_CONSOLE_UART_BASE   BEAGLE_BASE_UART_1
157#define BSP_CONSOLE_UART_IRQ    OMAP3_UART1_IRQ
158#define BEAGLE_BASE_UART_1      0x44E09000
159#define BEAGLE_BASE_UART_2      0x48022000
160#define BEAGLE_BASE_UART_3      0x48024000
161#endif
162
163/* per-target uart config */
164#if IS_DM3730
165#define BSP_CONSOLE_UART        3
166#define BSP_CONSOLE_UART_BASE   BEAGLE_BASE_UART_3
167#define BSP_CONSOLE_UART_IRQ    OMAP3_UART3_IRQ
168#define BEAGLE_BASE_UART_1      0x4806A000
169#define BEAGLE_BASE_UART_2      0x4806C000
170#define BEAGLE_BASE_UART_3      0x49020000
171#endif
172
173/* GPIO pin config */
174#if IS_AM335X
175#define BSP_GPIO_PIN_COUNT 128
176#define BSP_GPIO_PINS_PER_BANK 32
177#endif
178
179#if IS_DM3730
180#define BSP_GPIO_PIN_COUNT 192
181#define BSP_GPIO_PINS_PER_BANK 32
182#endif
183
184/* i2c stuff */
185typedef struct {
186    uint32_t rx_or_tx;
187    uint32_t stat;
188    uint32_t ctrl;
189    uint32_t clk_hi;
190    uint32_t clk_lo;
191    uint32_t adr;
192    uint32_t rxfl;
193    uint32_t txfl;
194    uint32_t rxb;
195    uint32_t txb;
196    uint32_t s_tx;
197    uint32_t s_txfl;
198} beagle_i2c;
199
200/* sctlr */
201/* Read System Control Register */
202static inline uint32_t read_sctlr()
203{
204    uint32_t ctl;
205
206    asm volatile("mrc p15, 0, %[ctl], c1, c0, 0 @ Read SCTLR\n\t"
207        : [ctl] "=r" (ctl));
208    return ctl;
209}
210
211/* Write System Control Register */
212static inline void write_sctlr(uint32_t ctl)
213{
214    asm volatile("mcr p15, 0, %[ctl], c1, c0, 0 @ Write SCTLR\n\t"
215        : : [ctl] "r" (ctl));
216    isb();
217}
218
219/* Read Auxiliary Control Register */
220static inline uint32_t read_actlr()
221{
222    uint32_t ctl;
223
224    asm volatile("mrc p15, 0, %[ctl], c1, c0, 1 @ Read ACTLR\n\t"
225            : [ctl] "=r" (ctl));
226    return ctl;
227}
228
229/* Write Auxiliary Control Register */
230static inline void write_actlr(uint32_t ctl)
231{
232    asm volatile("mcr p15, 0, %[ctl], c1, c0, 1 @ Write ACTLR\n\t"
233        : : [ctl] "r" (ctl));
234    isb();
235}
236
237/* Write Translation Table Base Control Register */
238static inline void write_ttbcr(uint32_t bcr)
239{
240        asm volatile("mcr p15, 0, %[bcr], c2, c0, 2 @ Write TTBCR\n\t"
241                        : : [bcr] "r" (bcr));
242
243        isb();
244}
245
246/* Read Domain Access Control Register */
247static inline uint32_t read_dacr()
248{
249        uint32_t dacr;
250
251        asm volatile("mrc p15, 0, %[dacr], c3, c0, 0 @ Read DACR\n\t"
252                        : [dacr] "=r" (dacr));
253
254        return dacr;
255}
256
257
258/* Write Domain Access Control Register */
259static inline void write_dacr(uint32_t dacr)
260{
261        asm volatile("mcr p15, 0, %[dacr], c3, c0, 0 @ Write DACR\n\t"
262                        : : [dacr] "r" (dacr));
263
264        isb();
265}
266
267static inline void refresh_tlb(void)
268{
269    dsb();
270
271    /* Invalidate entire unified TLB */
272    asm volatile("mcr p15, 0, %[zero], c8, c7, 0 @ TLBIALL\n\t"
273        : : [zero] "r" (0));
274
275    /* Invalidate all instruction caches to PoU.
276     * Also flushes branch target cache. */
277    asm volatile("mcr p15, 0, %[zero], c7, c5, 0"
278        : : [zero] "r" (0));
279
280    /* Invalidate entire branch predictor array */
281    asm volatile("mcr p15, 0, %[zero], c7, c5, 6"
282        : : [zero] "r" (0)); /* flush BTB */
283
284    dsb();
285    isb();
286}
287
288/* Read Translation Table Base Register 0 */
289static inline uint32_t read_ttbr0()
290{
291    uint32_t bar;
292
293    asm volatile("mrc p15, 0, %[bar], c2, c0, 0 @ Read TTBR0\n\t"
294        : [bar] "=r" (bar));
295
296    return bar & ARM_TTBR_ADDR_MASK;
297}
298
299
300/* Read Translation Table Base Register 0 */
301static inline uint32_t read_ttbr0_unmasked()
302{
303    uint32_t bar;
304
305    asm volatile("mrc p15, 0, %[bar], c2, c0, 0 @ Read TTBR0\n\t"
306        : [bar] "=r" (bar));
307
308    return bar;
309}
310
311/* Write Translation Table Base Register 0 */
312static inline void write_ttbr0(uint32_t bar)
313{
314    dsb();
315    isb();
316    /* In our setup TTBR contains the base address *and* the flags
317       but other pieces of the kernel code expect ttbr to be the
318       base address of the l1 page table. We therefore add the
319       flags here and remove them in the read_ttbr0 */
320    uint32_t v  =  (bar  & ARM_TTBR_ADDR_MASK ) | ARM_TTBR_FLAGS_CACHED;
321    asm volatile("mcr p15, 0, %[bar], c2, c0, 0 @ Write TTBR0\n\t"
322        : : [bar] "r" (v));
323
324    refresh_tlb();
325}
326
327/* Behaviour on fatal error; default: test-friendly.
328 * set breakpoint to bsp_fatal_extension.
329 */
330/* Enabling BSP_PRESS_KEY_FOR_RESET prevents noninteractive testing */
331/*#define  BSP_PRESS_KEY_FOR_RESET     1 */
332#define    BSP_PRINT_EXCEPTION_CONTEXT 1
333    /* human-readable exception info */
334#define    BSP_RESET_BOARD_AT_EXIT 1
335    /* causes qemu to exit, signaling end of test */
336
337
338/**
339 * @defgroup arm_beagle Beaglebone, Beagleboard Support
340 *
341 * @ingroup bsp_arm
342 *
343 * @brief Beaglebones and beagleboards support package
344 *
345 */
346
347/**
348 * @brief Beagleboard specific set up of the MMU.
349 *
350 * Provide in the application to override.
351 */
352BSP_START_TEXT_SECTION void beagle_setup_mmu_and_cache(void);
353
354#endif /* LIBBSP_ARM_BEAGLE_BSP_H */
Note: See TracBrowser for help on using the repository browser.