vf_common.c revision 258057
1258057Sbr/*-
2258057Sbr * Copyright (c) 2013 Ruslan Bukin <br@bsdpad.com>
3258057Sbr * All rights reserved.
4258057Sbr *
5258057Sbr * Redistribution and use in source and binary forms, with or without
6258057Sbr * modification, are permitted provided that the following conditions
7258057Sbr * are met:
8258057Sbr * 1. Redistributions of source code must retain the above copyright
9258057Sbr *    notice, this list of conditions and the following disclaimer.
10258057Sbr * 2. Redistributions in binary form must reproduce the above copyright
11258057Sbr *    notice, this list of conditions and the following disclaimer in the
12258057Sbr *    documentation and/or other materials provided with the distribution.
13258057Sbr *
14258057Sbr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15258057Sbr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16258057Sbr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17258057Sbr * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18258057Sbr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19258057Sbr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20258057Sbr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21258057Sbr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22258057Sbr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23258057Sbr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24258057Sbr * SUCH DAMAGE.
25258057Sbr */
26258057Sbr
27258057Sbr#include <sys/cdefs.h>
28258057Sbr__FBSDID("$FreeBSD: head/sys/arm/freescale/vybrid/vf_common.c 258057 2013-11-12 18:02:56Z br $");
29258057Sbr
30258057Sbr#include <sys/param.h>
31258057Sbr#include <sys/systm.h>
32258057Sbr#include <sys/bus.h>
33258057Sbr#include <sys/kernel.h>
34258057Sbr
35258057Sbr#include <dev/fdt/fdt_common.h>
36258057Sbr#include <dev/ofw/openfirm.h>
37258057Sbr
38258057Sbr#include <machine/bus.h>
39258057Sbr#include <machine/fdt.h>
40258057Sbr
41258057Sbr#include <arm/freescale/vybrid/vf_src.h>
42258057Sbr
43258057Sbrvoid
44258057Sbrcpu_reset(void)
45258057Sbr{
46258057Sbr	phandle_t src;
47258057Sbr	uint32_t addr, paddr;
48258057Sbr	bus_addr_t vaddr;
49258057Sbr
50258057Sbr	if (src_swreset() == 0)
51258057Sbr		goto end;
52258057Sbr
53258057Sbr	src = OF_finddevice("src");
54258057Sbr	if ((src != 0) && (OF_getprop(src, "reg", &paddr, sizeof(paddr))) > 0) {
55258057Sbr		addr = fdt32_to_cpu(paddr);
56258057Sbr		if (bus_space_map(fdtbus_bs_tag, addr, 0x10, 0, &vaddr) == 0) {
57258057Sbr			bus_space_write_4(fdtbus_bs_tag, vaddr, 0x00, SW_RST);
58258057Sbr		}
59258057Sbr	}
60258057Sbr
61258057Sbrend:
62258057Sbr	while (1);
63258057Sbr}
64258057Sbr
65258057Sbrstruct fdt_fixup_entry fdt_fixup_table[] = {
66258057Sbr	{ NULL, NULL }
67258057Sbr};
68258057Sbr
69258057Sbrstatic int
70258057Sbrfdt_pic_decode_ic(phandle_t node, pcell_t *intr, int *interrupt, int *trig,
71258057Sbr    int *pol)
72258057Sbr{
73258057Sbr
74258057Sbr	if (!fdt_is_compatible(node, "arm,gic"))
75258057Sbr		return (ENXIO);
76258057Sbr
77258057Sbr	*interrupt = fdt32_to_cpu(intr[0]);
78258057Sbr	*trig = INTR_TRIGGER_CONFORM;
79258057Sbr	*pol = INTR_POLARITY_CONFORM;
80258057Sbr	return (0);
81258057Sbr}
82258057Sbr
83258057Sbrfdt_pic_decode_t fdt_pic_table[] = {
84258057Sbr	&fdt_pic_decode_ic,
85258057Sbr	NULL
86258057Sbr};
87