am3_prcm.c revision 1.1 1 1.1 jmcneill /* $NetBSD: am3_prcm.c,v 1.1 2017/10/26 23:28:15 jmcneill Exp $ */
2 1.1 jmcneill
3 1.1 jmcneill /*-
4 1.1 jmcneill * Copyright (c) 2017 Jared McNeill <jmcneill (at) invisible.ca>
5 1.1 jmcneill * All rights reserved.
6 1.1 jmcneill *
7 1.1 jmcneill * Redistribution and use in source and binary forms, with or without
8 1.1 jmcneill * modification, are permitted provided that the following conditions
9 1.1 jmcneill * are met:
10 1.1 jmcneill * 1. Redistributions of source code must retain the above copyright
11 1.1 jmcneill * notice, this list of conditions and the following disclaimer.
12 1.1 jmcneill * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 jmcneill * notice, this list of conditions and the following disclaimer in the
14 1.1 jmcneill * documentation and/or other materials provided with the distribution.
15 1.1 jmcneill *
16 1.1 jmcneill * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.1 jmcneill * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.1 jmcneill * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.1 jmcneill * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.1 jmcneill * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 1.1 jmcneill * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 1.1 jmcneill * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 1.1 jmcneill * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 1.1 jmcneill * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.1 jmcneill * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.1 jmcneill * SUCH DAMAGE.
27 1.1 jmcneill */
28 1.1 jmcneill
29 1.1 jmcneill #include <sys/cdefs.h>
30 1.1 jmcneill
31 1.1 jmcneill __KERNEL_RCSID(1, "$NetBSD: am3_prcm.c,v 1.1 2017/10/26 23:28:15 jmcneill Exp $");
32 1.1 jmcneill
33 1.1 jmcneill #include <sys/param.h>
34 1.1 jmcneill #include <sys/bus.h>
35 1.1 jmcneill #include <sys/device.h>
36 1.1 jmcneill #include <sys/systm.h>
37 1.1 jmcneill
38 1.1 jmcneill #include <dev/fdt/fdtvar.h>
39 1.1 jmcneill
40 1.1 jmcneill #define TI_PRCM_PRIVATE
41 1.1 jmcneill #include <arm/ti/ti_prcm.h>
42 1.1 jmcneill
43 1.1 jmcneill #define AM3_PRCM_CM_PER 0x0000
44 1.1 jmcneill #define AM3_PRCM_CM_WKUP 0x0400
45 1.1 jmcneill #define AM3_PRCM_CM_DPLL 0x0500
46 1.1 jmcneill #define AM3_PRCM_CM_MPU 0x0600
47 1.1 jmcneill #define AM3_PRCM_CM_DEVICE 0x0700
48 1.1 jmcneill #define AM3_PRCM_CM_RTC 0x0800
49 1.1 jmcneill #define AM3_PRCM_CM_GFX 0x0900
50 1.1 jmcneill #define AM3_PRCM_CM_CEFUSE 0x0a00
51 1.1 jmcneill
52 1.1 jmcneill #define AM3_PRCM_CLKCTRL_MODULEMODE __BITS(1,0)
53 1.1 jmcneill #define AM3_PRCM_CLKCTRL_MODULEMODE_ENABLE 0x2
54 1.1 jmcneill
55 1.1 jmcneill static int am3_prcm_match(device_t, cfdata_t, void *);
56 1.1 jmcneill static void am3_prcm_attach(device_t, device_t, void *);
57 1.1 jmcneill
58 1.1 jmcneill static int
59 1.1 jmcneill am3_prcm_hwmod_enable(struct ti_prcm_softc *sc, struct ti_prcm_clk *tc, int enable)
60 1.1 jmcneill {
61 1.1 jmcneill uint32_t val;
62 1.1 jmcneill
63 1.1 jmcneill val = PRCM_READ(sc, tc->u.hwmod.reg);
64 1.1 jmcneill val &= ~AM3_PRCM_CLKCTRL_MODULEMODE;
65 1.1 jmcneill if (enable)
66 1.1 jmcneill val |= __SHIFTIN(AM3_PRCM_CLKCTRL_MODULEMODE_ENABLE,
67 1.1 jmcneill AM3_PRCM_CLKCTRL_MODULEMODE);
68 1.1 jmcneill PRCM_WRITE(sc, tc->u.hwmod.reg, val);
69 1.1 jmcneill
70 1.1 jmcneill return 0;
71 1.1 jmcneill }
72 1.1 jmcneill
73 1.1 jmcneill #define AM3_PRCM_HWMOD_PER(_name, _reg, _parent) \
74 1.1 jmcneill TI_PRCM_HWMOD((_name), AM3_PRCM_CM_PER + (_reg), (_parent), am3_prcm_hwmod_enable)
75 1.1 jmcneill #define AM3_PRCM_HWMOD_WKUP(_name, _reg, _parent) \
76 1.1 jmcneill TI_PRCM_HWMOD((_name), AM3_PRCM_CM_WKUP + (_reg), (_parent), am3_prcm_hwmod_enable)
77 1.1 jmcneill
78 1.1 jmcneill static const char * const compatible[] = {
79 1.1 jmcneill "ti,am3-prcm",
80 1.1 jmcneill NULL
81 1.1 jmcneill };
82 1.1 jmcneill
83 1.1 jmcneill CFATTACH_DECL_NEW(am3_prcm, sizeof(struct ti_prcm_softc),
84 1.1 jmcneill am3_prcm_match, am3_prcm_attach, NULL, NULL);
85 1.1 jmcneill
86 1.1 jmcneill static struct ti_prcm_clk am3_prcm_clks[] = {
87 1.1 jmcneill /* XXX until we get a proper clock tree */
88 1.1 jmcneill TI_PRCM_FIXED("FIXED_32K", 32768),
89 1.1 jmcneill TI_PRCM_FIXED("FIXED_48MHZ", 48000000),
90 1.1 jmcneill TI_PRCM_FIXED("FIXED_96MHZ", 96000000),
91 1.1 jmcneill TI_PRCM_FIXED_FACTOR("PERIPH_CLK", 1, 1, "FIXED_48MHZ"),
92 1.1 jmcneill TI_PRCM_FIXED_FACTOR("MMC_CLK", 1, 1, "FIXED_96MHZ"),
93 1.1 jmcneill
94 1.1 jmcneill AM3_PRCM_HWMOD_PER("uart1", 0x6c, "PERIPH_CLK"),
95 1.1 jmcneill AM3_PRCM_HWMOD_PER("uart2", 0x70, "PERIPH_CLK"),
96 1.1 jmcneill AM3_PRCM_HWMOD_PER("uart3", 0x74, "PERIPH_CLK"),
97 1.1 jmcneill AM3_PRCM_HWMOD_PER("uart4", 0x78, "PERIPH_CLK"),
98 1.1 jmcneill AM3_PRCM_HWMOD_PER("uart5", 0x38, "PERIPH_CLK"),
99 1.1 jmcneill
100 1.1 jmcneill AM3_PRCM_HWMOD_WKUP("timer0", 0x10, "FIXED_32K"),
101 1.1 jmcneill AM3_PRCM_HWMOD_PER("timer2", 0x80, "PERIPH_CLK"),
102 1.1 jmcneill AM3_PRCM_HWMOD_PER("timer3", 0x84, "PERIPH_CLK"),
103 1.1 jmcneill AM3_PRCM_HWMOD_PER("timer4", 0x88, "PERIPH_CLK"),
104 1.1 jmcneill AM3_PRCM_HWMOD_PER("timer5", 0xec, "PERIPH_CLK"),
105 1.1 jmcneill AM3_PRCM_HWMOD_PER("timer6", 0xf0, "PERIPH_CLK"),
106 1.1 jmcneill AM3_PRCM_HWMOD_PER("timer7", 0x7c, "PERIPH_CLK"),
107 1.1 jmcneill
108 1.1 jmcneill AM3_PRCM_HWMOD_PER("mmc0", 0x3c, "MMC_CLK"),
109 1.1 jmcneill AM3_PRCM_HWMOD_PER("mmc1", 0xf4, "MMC_CLK"),
110 1.1 jmcneill AM3_PRCM_HWMOD_PER("mmc2", 0xf8, "MMC_CLK"),
111 1.1 jmcneill };
112 1.1 jmcneill
113 1.1 jmcneill static int
114 1.1 jmcneill am3_prcm_match(device_t parent, cfdata_t cf, void *aux)
115 1.1 jmcneill {
116 1.1 jmcneill struct fdt_attach_args * const faa = aux;
117 1.1 jmcneill
118 1.1 jmcneill return of_match_compatible(faa->faa_phandle, compatible);
119 1.1 jmcneill }
120 1.1 jmcneill
121 1.1 jmcneill static void
122 1.1 jmcneill am3_prcm_attach(device_t parent, device_t self, void *aux)
123 1.1 jmcneill {
124 1.1 jmcneill struct ti_prcm_softc * const sc = device_private(self);
125 1.1 jmcneill struct fdt_attach_args * const faa = aux;
126 1.1 jmcneill
127 1.1 jmcneill sc->sc_dev = self;
128 1.1 jmcneill sc->sc_phandle = faa->faa_phandle;
129 1.1 jmcneill sc->sc_bst = faa->faa_bst;
130 1.1 jmcneill
131 1.1 jmcneill sc->sc_clks = am3_prcm_clks;
132 1.1 jmcneill sc->sc_nclks = __arraycount(am3_prcm_clks);
133 1.1 jmcneill
134 1.1 jmcneill if (ti_prcm_attach(sc) != 0)
135 1.1 jmcneill return;
136 1.1 jmcneill
137 1.1 jmcneill aprint_naive("\n");
138 1.1 jmcneill aprint_normal(": AM3xxx PRCM\n");
139 1.1 jmcneill }
140