imx23_clkctrl.c revision 1.1.10.3 1 1.1.10.2 tls /* $Id: imx23_clkctrl.c,v 1.1.10.3 2017/12/03 11:35:53 jdolecek Exp $ */
2 1.1.10.2 tls
3 1.1.10.2 tls /*
4 1.1.10.2 tls * Copyright (c) 2013 The NetBSD Foundation, Inc.
5 1.1.10.2 tls * All rights reserved.
6 1.1.10.2 tls *
7 1.1.10.2 tls * This code is derived from software contributed to The NetBSD Foundation
8 1.1.10.2 tls * by Petri Laakso.
9 1.1.10.2 tls *
10 1.1.10.2 tls * Redistribution and use in source and binary forms, with or without
11 1.1.10.2 tls * modification, are permitted provided that the following conditions
12 1.1.10.2 tls * are met:
13 1.1.10.2 tls * 1. Redistributions of source code must retain the above copyright
14 1.1.10.2 tls * notice, this list of conditions and the following disclaimer.
15 1.1.10.2 tls * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.10.2 tls * notice, this list of conditions and the following disclaimer in the
17 1.1.10.2 tls * documentation and/or other materials provided with the distribution.
18 1.1.10.2 tls *
19 1.1.10.2 tls * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1.10.2 tls * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1.10.2 tls * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1.10.2 tls * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1.10.2 tls * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1.10.2 tls * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1.10.2 tls * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1.10.2 tls * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1.10.2 tls * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1.10.2 tls * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1.10.2 tls * POSSIBILITY OF SUCH DAMAGE.
30 1.1.10.2 tls */
31 1.1.10.2 tls
32 1.1.10.2 tls #include <sys/param.h>
33 1.1.10.2 tls #include <sys/types.h>
34 1.1.10.2 tls #include <sys/bus.h>
35 1.1.10.2 tls #include <sys/cdefs.h>
36 1.1.10.2 tls #include <sys/device.h>
37 1.1.10.2 tls #include <sys/errno.h>
38 1.1.10.2 tls
39 1.1.10.2 tls #include <arm/imx/imx23_clkctrlreg.h>
40 1.1.10.2 tls #include <arm/imx/imx23_clkctrlvar.h>
41 1.1.10.2 tls #include <arm/imx/imx23var.h>
42 1.1.10.2 tls
43 1.1.10.2 tls typedef struct clkctrl_softc {
44 1.1.10.2 tls device_t sc_dev;
45 1.1.10.2 tls bus_space_tag_t sc_iot;
46 1.1.10.2 tls bus_space_handle_t sc_hdl;
47 1.1.10.2 tls } *clkctrl_softc_t;
48 1.1.10.2 tls
49 1.1.10.2 tls static int clkctrl_match(device_t, cfdata_t, void *);
50 1.1.10.2 tls static void clkctrl_attach(device_t, device_t, void *);
51 1.1.10.2 tls static int clkctrl_activate(device_t, enum devact);
52 1.1.10.2 tls
53 1.1.10.2 tls static void clkctrl_init(struct clkctrl_softc *);
54 1.1.10.2 tls
55 1.1.10.2 tls static clkctrl_softc_t _sc = NULL;
56 1.1.10.2 tls
57 1.1.10.2 tls CFATTACH_DECL3_NEW(clkctrl,
58 1.1.10.2 tls sizeof(struct clkctrl_softc),
59 1.1.10.2 tls clkctrl_match,
60 1.1.10.2 tls clkctrl_attach,
61 1.1.10.2 tls NULL,
62 1.1.10.2 tls clkctrl_activate,
63 1.1.10.2 tls NULL,
64 1.1.10.2 tls NULL,
65 1.1.10.2 tls 0
66 1.1.10.2 tls );
67 1.1.10.2 tls
68 1.1.10.2 tls #define CLKCTRL_RD(sc, reg) \
69 1.1.10.2 tls bus_space_read_4(sc->sc_iot, sc->sc_hdl, (reg))
70 1.1.10.2 tls #define CLKCTRL_WR(sc, reg, val) \
71 1.1.10.2 tls bus_space_write_4(sc->sc_iot, sc->sc_hdl, (reg), (val))
72 1.1.10.2 tls
73 1.1.10.2 tls #define CLKCTRL_SOFT_RST_LOOP 455 /* At least 1 us ... */
74 1.1.10.2 tls
75 1.1.10.2 tls static int
76 1.1.10.2 tls clkctrl_match(device_t parent, cfdata_t match, void *aux)
77 1.1.10.2 tls {
78 1.1.10.2 tls struct apb_attach_args *aa = aux;
79 1.1.10.2 tls
80 1.1.10.2 tls if ((aa->aa_addr == HW_CLKCTRL_BASE) &&
81 1.1.10.2 tls (aa->aa_size == HW_CLKCTRL_SIZE))
82 1.1.10.2 tls return 1;
83 1.1.10.2 tls
84 1.1.10.2 tls return 0;
85 1.1.10.2 tls }
86 1.1.10.2 tls
87 1.1.10.2 tls static void
88 1.1.10.2 tls clkctrl_attach(device_t parent, device_t self, void *aux)
89 1.1.10.2 tls {
90 1.1.10.2 tls struct clkctrl_softc *sc = device_private(self);
91 1.1.10.2 tls struct apb_attach_args *aa = aux;
92 1.1.10.2 tls static int clkctrl_attached = 0;
93 1.1.10.2 tls
94 1.1.10.2 tls sc->sc_dev = self;
95 1.1.10.2 tls sc->sc_iot = aa->aa_iot;
96 1.1.10.2 tls
97 1.1.10.2 tls if (clkctrl_attached) {
98 1.1.10.2 tls aprint_error_dev(sc->sc_dev, "already attached\n");
99 1.1.10.2 tls return;
100 1.1.10.2 tls }
101 1.1.10.2 tls
102 1.1.10.2 tls if (bus_space_map(sc->sc_iot, aa->aa_addr, aa->aa_size, 0,
103 1.1.10.2 tls &sc->sc_hdl))
104 1.1.10.2 tls {
105 1.1.10.2 tls aprint_error_dev(sc->sc_dev, "Unable to map bus space\n");
106 1.1.10.2 tls return;
107 1.1.10.2 tls }
108 1.1.10.2 tls
109 1.1.10.2 tls
110 1.1.10.2 tls clkctrl_init(sc);
111 1.1.10.2 tls
112 1.1.10.2 tls aprint_normal("\n");
113 1.1.10.2 tls
114 1.1.10.2 tls clkctrl_attached = 1;
115 1.1.10.2 tls
116 1.1.10.2 tls return;
117 1.1.10.2 tls }
118 1.1.10.2 tls
119 1.1.10.2 tls static int
120 1.1.10.2 tls clkctrl_activate(device_t self, enum devact act)
121 1.1.10.2 tls {
122 1.1.10.2 tls
123 1.1.10.2 tls return EOPNOTSUPP;
124 1.1.10.2 tls }
125 1.1.10.2 tls
126 1.1.10.2 tls static void
127 1.1.10.2 tls clkctrl_init(struct clkctrl_softc *sc)
128 1.1.10.2 tls {
129 1.1.10.2 tls _sc = sc;
130 1.1.10.2 tls return;
131 1.1.10.2 tls }
132 1.1.10.2 tls
133 1.1.10.2 tls /*
134 1.1.10.2 tls * Power up 8-phase PLL outputs for USB PHY
135 1.1.10.2 tls *
136 1.1.10.2 tls */
137 1.1.10.2 tls void
138 1.1.10.2 tls clkctrl_en_usb(void)
139 1.1.10.2 tls {
140 1.1.10.2 tls struct clkctrl_softc *sc = _sc;
141 1.1.10.2 tls
142 1.1.10.2 tls if (sc == NULL) {
143 1.1.10.2 tls aprint_error("clkctrl is not initalized");
144 1.1.10.2 tls return;
145 1.1.10.2 tls }
146 1.1.10.2 tls
147 1.1.10.2 tls CLKCTRL_WR(sc, HW_CLKCTRL_PLLCTRL0_SET,
148 1.1.10.2 tls HW_CLKCTRL_PLLCTRL0_EN_USB_CLKS);
149 1.1.10.2 tls
150 1.1.10.2 tls return;
151 1.1.10.2 tls }
152 1.1.10.3 jdolecek
153 1.1.10.3 jdolecek /*
154 1.1.10.3 jdolecek * Enable 24MHz clock for the Digital Filter.
155 1.1.10.3 jdolecek *
156 1.1.10.3 jdolecek */
157 1.1.10.3 jdolecek void
158 1.1.10.3 jdolecek clkctrl_en_filtclk(void)
159 1.1.10.3 jdolecek {
160 1.1.10.3 jdolecek struct clkctrl_softc *sc = _sc;
161 1.1.10.3 jdolecek
162 1.1.10.3 jdolecek if (sc == NULL) {
163 1.1.10.3 jdolecek aprint_error("clkctrl is not initalized");
164 1.1.10.3 jdolecek return;
165 1.1.10.3 jdolecek }
166 1.1.10.3 jdolecek
167 1.1.10.3 jdolecek CLKCTRL_WR(sc, HW_CLKCTRL_XTAL_CLR, HW_CLKCTRL_XTAL_FILT_CLK24M_GATE);
168 1.1.10.3 jdolecek
169 1.1.10.3 jdolecek return;
170 1.1.10.3 jdolecek }
171