2 * Copyright (c) 2015 Oleksandr Tymoshenko <gonzo@freebsd.org>
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
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
18 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
22 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
23 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 * POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include <sys/param.h>
33 #include <sys/systm.h>
35 #include <sys/kernel.h>
37 #include <dev/ofw/openfirm.h>
38 #include <dev/ofw/ofw_bus.h>
39 #include <dev/ofw/ofw_bus_subr.h>
41 #include <machine/bus.h>
42 #include <machine/fdt.h>
44 #include <arm/ti/ti_prcm.h>
45 #include <arm/ti/ti_hwmods.h>
52 struct hwmod ti_hwmods[] = {
74 {"epwmss0", PWMSS0_CLK},
75 {"epwmss1", PWMSS1_CLK},
76 {"epwmss2", PWMSS2_CLK},
81 {"timer1", TIMER1_CLK},
82 {"timer2", TIMER2_CLK},
83 {"timer3", TIMER3_CLK},
84 {"timer4", TIMER4_CLK},
85 {"timer5", TIMER5_CLK},
86 {"timer6", TIMER6_CLK},
87 {"timer7", TIMER7_CLK},
101 ti_get_hwmods_prop(phandle_t node, void **name)
105 if ((len = OF_getprop_alloc(node, "ti,hwmods", name)) > 0)
107 return (OF_getprop_alloc(OF_parent(node), "ti,hwmods", name));
111 ti_hwmods_get_clock(device_t dev)
120 if ((node = ofw_bus_get_node(dev)) == 0)
121 return (INVALID_CLK_IDENT);
123 if ((len = ti_get_hwmods_prop(node, (void **)&name)) <= 0)
124 return (INVALID_CLK_IDENT);
128 clk = INVALID_CLK_IDENT;
129 while ((len > 0) && (clk == INVALID_CLK_IDENT)) {
130 for (hw = ti_hwmods; hw->name != NULL; ++hw) {
131 if (strcmp(hw->name, name) == 0) {
137 /* Slide to the next sub-string. */
138 l = strlen(name) + 1;
144 device_printf(dev, "WARNING: more than one ti,hwmod \n");
150 int ti_hwmods_contains(device_t dev, const char *hwmod)
158 if ((node = ofw_bus_get_node(dev)) == 0)
161 if ((len = ti_get_hwmods_prop(node, (void **)&name)) <= 0)
168 if (strcmp(name, hwmod) == 0) {
173 /* Slide to the next sub-string. */
174 l = strlen(name) + 1;
185 ti_hwmods_get_unit(device_t dev, const char *hwmod)
188 int l, len, hwmodlen, result;
192 if ((node = ofw_bus_get_node(dev)) == 0)
195 if ((len = ti_get_hwmods_prop(node, (void **)&name)) <= 0)
199 hwmodlen = strlen(hwmod);
202 if (strncmp(name, hwmod, hwmodlen) == 0) {
203 result = (int)strtoul(name + hwmodlen, NULL, 10);
206 /* Slide to the next sub-string. */
207 l = strlen(name) + 1;