efe0ef7b |
1 | /* |
2 | * Copyright (c) 2017 Ian Sutton <ian@ce.gl> |
3 | * Copyright (c) 2013 Oleksandr Tymoshenko <gonzo@freebsd.org> |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
8 | * 1. Redistributions of source code must retain the above copyright |
9 | * notice, this list of conditions and the following disclaimer. |
10 | * 2. Redistributions in binary form must reproduce the above copyright |
11 | * notice, this list of conditions and the following disclaimer in the |
12 | * documentation and/or other materials provided with the distribution. |
13 | * |
14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
22 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
23 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
24 | * SUCH DAMAGE. |
25 | */ |
26 | |
27 | #include <sys/param.h> |
28 | #include <sys/systm.h> |
29 | #include <sys/device.h> |
30 | #include <sys/kernel.h> |
31 | |
32 | #include <dev/ofw/openfirm.h> |
33 | #include <dev/ofw/fdt.h> |
34 | |
35 | #include <machine/fdt.h> |
36 | |
37 | #include <armv7/omap/prcmvar.h> |
38 | #include <armv7/omap/sitara_cm.h> |
39 | |
40 | #include <arm/simplebus/simplebusvar.h> |
41 | |
42 | #define DEVNAME(_s) ((_s)->sc_dev.dv_xname) |
43 | |
44 | #define AMMUSB_DEBUG /* XXX */ |
45 | |
46 | #ifdef AMMUSB_DEBUG |
47 | int ammusb_debug = 20; |
48 | #define DPRINTF(n,s) do { if ((n) <= ammusb_debug) printf s; } while (0) |
49 | #else |
50 | #define DPRINTF(n,s) do {} |
51 | #endif |
52 | |
53 | #define HREAD4(sc, reg) \ |
54 | (bus_space_read_4((sc)->sc_iot, (sc)->sc_ioh, (reg))) |
55 | #define HWRITE4(sc, reg, val) \ |
56 | bus_space_write_4((sc)->sc_iot, (sc)->sc_ioh, (reg), (val)) |
57 | #define HSET4(sc, reg, bits) \ |
58 | HWRITE4((sc), (reg), HREAD4((sc), (reg)) | (bits)) |
59 | #define HCLR4(sc, reg, bits) \ |
60 | HWRITE4((sc), (reg), HREAD4((sc), (reg)) & ~(bits)) |
61 | |
62 | struct ammusb_softc { |
63 | struct device sc_dev; |
64 | bus_space_tag_t sc_iot; |
65 | bus_space_handle_t sc_ioh; |
66 | void *sc_ih; |
67 | }; |
68 | |
69 | /* core decl */ |
70 | int ammusb_match(struct device *, void *, void *); |
71 | void ammusb_attach(struct device *, struct device *, void *); |
72 | int ammusb_detach(struct device *, int); |
73 | int ammusb_intr(void *); |
74 | void ammusb_reset(struct ammusb_softc *); |
75 | |
76 | /* debug decl */ |
77 | void ammusb_preg(uint32_t, char *, struct ammusb_softc *); |
78 | void ammusb_dumpregs(struct ammusb_softc *); |
79 | |
80 | /* core/iomux.c def */ |
81 | struct cfattach ammusb_ca = { |
82 | sizeof (struct ammusb_softc), ammusb_match, ammusb_attach, ammusb_detach |
83 | }; |
84 | |
85 | struct cfdriver ammusb_cd = { |
86 | NULL, "ammusb", DV_DULL |
87 | }; |
88 | |
89 | int |
90 | ammusb_match(struct device *parent, void *v, void *aux) |
91 | { |
92 | struct fdt_attach_args *faa = aux; |
93 | /* int node; |
94 | char name[32]; |
95 | |
96 | if (OF_is_compatible(faa->fa_node, "ti,am33xx-usb")) { |
97 | printf("!!HIT!!\n"); |
98 | for (node = OF_child(faa->fa_node); node; node = OF_peer(node)) { |
99 | |
100 | } |
101 | }*/ |
102 | printf("MAYBE: %d\n", faa->fa_node); |
103 | return OF_is_compatible(faa->fa_node, "ti,musb-am33xx"); |
104 | } |
105 | |
106 | void |
107 | ammusb_attach(struct device *parent, struct device *self, void *args) |
108 | { |
109 | struct ammusb_softc *sc = (struct ammusb_softc *) self; |
110 | struct fdt_attach_args *faa = args; |
111 | |
112 | uint32_t rev; |
113 | |
114 | sc->sc_iot = faa->fa_iot; |
115 | if (bus_space_map(sc->sc_iot, faa->fa_reg[0].addr, faa->fa_reg[0].size, 0, |
116 | &sc->sc_ioh)) |
117 | panic("%s: bus_space_map failed!", __func__); |
118 | |
119 | rev = HREAD4(sc, 0x0); |
120 | printf(" rev 0x%08x\n", rev); |
121 | printf("%s: phys: 0x%08llx, size: %08llx\n", DEVNAME(sc), faa->fa_reg[0].addr, |
122 | faa->fa_reg[0].size); |
123 | } |
124 | |
125 | int |
126 | ammusb_detach(struct device *self, int flags) |
127 | { |
128 | return 0; /* XXX */ |
129 | } |
130 | |
131 | int |
132 | ammusb_intr(void * arg) |
133 | { |
134 | return 0; /* XXX */ |
135 | } |