1/*-
2 * Copyright (c) 2011 Damjan Marion.
3 * Copyright (c) 1994-1998 Mark Brinicombe.
4 * Copyright (c) 1994 Brini.
5 * All rights reserved.
6 *
7 * This code is derived from software written for Brini by Mark Brinicombe
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 *    notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 *    notice, this list of conditions and the following disclaimer in the
16 *    documentation and/or other materials provided with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 *
30 * from: FreeBSD: //depot/projects/arm/src/sys/arm/mv/mv_machdep.c
31 */
32
33#include "opt_ddb.h"
34#include "opt_platform.h"
35
36#include <sys/cdefs.h>
37__FBSDID("$FreeBSD$");
38
39#define _ARM32_BUS_DMA_PRIVATE
40#include <sys/param.h>
41#include <sys/systm.h>
42#include <sys/bus.h>
43
44#include <vm/vm.h>
45#include <vm/pmap.h>
46
47#include <machine/bus.h>
48#include <machine/frame.h> /* For trapframe_t, used in <machine/machdep.h> */
49#include <machine/machdep.h>
50#include <machine/pmap.h>
51
52#include <dev/fdt/fdt_common.h>
53
54/* FIXME move to tegrareg.h */
55#define TEGRA2_BASE			0xE0000000	/* KVM base for peripherials */
56#define TEGRA2_UARTA_VA_BASE		0xE0006000
57#define TEGRA2_UARTA_PA_BASE		0x70006000
58
59#define TEGRA2_CLK_RST_PA_BASE		0x60006000
60
61#define TEGRA2_CLK_RST_OSC_FREQ_DET_REG		0x58
62#define TEGRA2_CLK_RST_OSC_FREQ_DET_STAT_REG	0x5C
63#define OSC_FREQ_DET_TRIG			(1<<31)
64#define OSC_FREQ_DET_BUSY               	(1<<31)
65
66#if 0
67static int
68tegra2_osc_freq_detect(void)
69{
70	bus_space_handle_t	bsh;
71	uint32_t		c;
72	uint32_t		r=0;
73	int			i=0;
74
75	struct {
76		uint32_t val;
77		uint32_t freq;
78	} freq_det_cnts[] = {
79		{ 732,  12000000 },
80		{ 794,  13000000 },
81		{1172,  19200000 },
82		{1587,  26000000 },
83		{  -1,         0 },
84	};
85
86	printf("Measuring...\n");
87	bus_space_map(fdtbus_bs_tag,TEGRA2_CLK_RST_PA_BASE, 0x1000, 0, &bsh);
88
89	bus_space_write_4(fdtbus_bs_tag, bsh, TEGRA2_CLK_RST_OSC_FREQ_DET_REG,
90			OSC_FREQ_DET_TRIG | 1 );
91	do {} while (bus_space_read_4(fdtbus_bs_tag, bsh,
92			TEGRA2_CLK_RST_OSC_FREQ_DET_STAT_REG) & OSC_FREQ_DET_BUSY);
93
94	c = bus_space_read_4(fdtbus_bs_tag, bsh, TEGRA2_CLK_RST_OSC_FREQ_DET_STAT_REG);
95
96	while (freq_det_cnts[i].val > 0) {
97		if (((freq_det_cnts[i].val - 3) < c) && (c < (freq_det_cnts[i].val + 3)))
98			r = freq_det_cnts[i].freq;
99		i++;
100	}
101	printf("c=%u r=%u\n",c,r );
102	bus_space_free(fdtbus_bs_tag, bsh, 0x1000);
103	return r;
104}
105#endif
106
107vm_offset_t
108initarm_lastaddr(void)
109{
110
111	if (fdt_immr_addr(TEGRA2_BASE) != 0)				/* FIXME ???? */
112		while (1);
113
114	return (fdt_immr_va - ARM_NOCACHE_KVA_SIZE);
115}
116
117void
118initarm_gpio_init(void)
119{
120}
121
122void
123initarm_late_init(void)
124{
125}
126
127#define FDT_DEVMAP_MAX	(1 + 2 + 1 + 1)	/* FIXME */
128static struct pmap_devmap fdt_devmap[FDT_DEVMAP_MAX] = {
129	{ 0, 0, 0, 0, 0, }
130};
131
132/*
133 * Construct pmap_devmap[] with DT-derived config data.
134 */
135int
136platform_devmap_init(void)
137{
138	int i = 0;
139	fdt_devmap[i].pd_va = 0xe0000000;
140	fdt_devmap[i].pd_pa = 0x70000000;
141	fdt_devmap[i].pd_size = 0x100000;
142	fdt_devmap[i].pd_prot = VM_PROT_READ | VM_PROT_WRITE;
143	fdt_devmap[i].pd_cache = PTE_NOCACHE;
144	i++;
145
146	pmap_devmap_bootstrap_table = &fdt_devmap[0];
147	return (0);
148}
149
150struct arm32_dma_range *
151bus_dma_get_range(void)
152{
153
154	return (NULL);
155}
156
157int
158bus_dma_get_range_nb(void)
159{
160
161	return (0);
162}
163
164