2 * Copyright (c) 2016 Jared McNeill <jmcneill@invisible.ca>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
21 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22 * 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
30 * Allwinner oscillator clock
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
36 #include <sys/param.h>
37 #include <sys/systm.h>
40 #include <sys/kernel.h>
41 #include <sys/module.h>
43 #include <dev/ofw/ofw_bus.h>
44 #include <dev/ofw/ofw_bus_subr.h>
46 #include <dev/extres/clk/clk_fixed.h>
49 aw_oscclk_probe(device_t dev)
51 if (!ofw_bus_status_okay(dev))
54 if (!ofw_bus_is_compatible(dev, "allwinner,sun4i-a10-osc-clk"))
57 device_set_desc(dev, "Allwinner Oscillator Clock");
58 return (BUS_PROBE_DEFAULT);
62 aw_oscclk_attach(device_t dev)
64 struct clk_fixed_def def;
65 struct clkdom *clkdom;
70 node = ofw_bus_get_node(dev);
72 if (OF_getencprop(node, "clock-frequency", &freq, sizeof(freq)) <= 0) {
73 device_printf(dev, "missing clock-frequency property\n");
78 clkdom = clkdom_create(dev);
80 memset(&def, 0, sizeof(def));
83 error = clk_parse_ofw_clk_name(dev, node, &def.clkdef.name);
85 device_printf(dev, "cannot parse clock name\n");
90 error = clknode_fixed_register(clkdom, &def);
92 device_printf(dev, "cannot register fixed clock\n");
97 if (clkdom_finit(clkdom) != 0) {
98 device_printf(dev, "cannot finalize clkdom initialization\n");
106 OF_prop_free(__DECONST(char *, def.clkdef.name));
111 OF_prop_free(__DECONST(char *, def.clkdef.name));
115 static device_method_t aw_oscclk_methods[] = {
116 /* Device interface */
117 DEVMETHOD(device_probe, aw_oscclk_probe),
118 DEVMETHOD(device_attach, aw_oscclk_attach),
123 static driver_t aw_oscclk_driver = {
129 static devclass_t aw_oscclk_devclass;
131 EARLY_DRIVER_MODULE(aw_oscclk, simplebus, aw_oscclk_driver,
132 aw_oscclk_devclass, 0, 0, BUS_PASS_BUS + BUS_PASS_ORDER_MIDDLE);