1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 2021, Adrian Chadd <adrian@FreeBSD.org>
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice unmodified, this list of conditions, and the following
11 * disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 /* Driver for Qualcomm IPQ4018 clock and reset device */
29
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
32
33 #include <sys/param.h>
34 #include <sys/kernel.h>
35 #include <sys/malloc.h>
36 #include <sys/module.h>
37 #include <sys/sglist.h>
38 #include <sys/random.h>
39 #include <sys/stdatomic.h>
40 #include <sys/mutex.h>
41
42 #include <machine/bus.h>
43 #include <machine/resource.h>
44 #include <sys/bus.h>
45
46 #include <dev/fdt/fdt_common.h>
47 #include <dev/ofw/ofw_bus.h>
48 #include <dev/ofw/ofw_bus_subr.h>
49
50 #include <dev/extres/hwreset/hwreset.h>
51
52 #include "hwreset_if.h"
53
54 #include <dt-bindings/clock/qcom,gcc-ipq4019.h>
55
56 #include "qcom_gcc_ipq4018_var.h"
57
58
59 static const struct qcom_gcc_ipq4018_reset_entry gcc_ipq4019_reset_list[] = {
60 [WIFI0_CPU_INIT_RESET] = { 0x1f008, 5 },
61 [WIFI0_RADIO_SRIF_RESET] = { 0x1f008, 4 },
62 [WIFI0_RADIO_WARM_RESET] = { 0x1f008, 3 },
63 [WIFI0_RADIO_COLD_RESET] = { 0x1f008, 2 },
64 [WIFI0_CORE_WARM_RESET] = { 0x1f008, 1 },
65 [WIFI0_CORE_COLD_RESET] = { 0x1f008, 0 },
66 [WIFI1_CPU_INIT_RESET] = { 0x20008, 5 },
67 [WIFI1_RADIO_SRIF_RESET] = { 0x20008, 4 },
68 [WIFI1_RADIO_WARM_RESET] = { 0x20008, 3 },
69 [WIFI1_RADIO_COLD_RESET] = { 0x20008, 2 },
70 [WIFI1_CORE_WARM_RESET] = { 0x20008, 1 },
71 [WIFI1_CORE_COLD_RESET] = { 0x20008, 0 },
72 [USB3_UNIPHY_PHY_ARES] = { 0x1e038, 5 },
73 [USB3_HSPHY_POR_ARES] = { 0x1e038, 4 },
74 [USB3_HSPHY_S_ARES] = { 0x1e038, 2 },
75 [USB2_HSPHY_POR_ARES] = { 0x1e01c, 4 },
76 [USB2_HSPHY_S_ARES] = { 0x1e01c, 2 },
77 [PCIE_PHY_AHB_ARES] = { 0x1d010, 11 },
78 [PCIE_AHB_ARES] = { 0x1d010, 10 },
79 [PCIE_PWR_ARES] = { 0x1d010, 9 },
80 [PCIE_PIPE_STICKY_ARES] = { 0x1d010, 8 },
81 [PCIE_AXI_M_STICKY_ARES] = { 0x1d010, 7 },
82 [PCIE_PHY_ARES] = { 0x1d010, 6 },
83 [PCIE_PARF_XPU_ARES] = { 0x1d010, 5 },
84 [PCIE_AXI_S_XPU_ARES] = { 0x1d010, 4 },
85 [PCIE_AXI_M_VMIDMT_ARES] = { 0x1d010, 3 },
86 [PCIE_PIPE_ARES] = { 0x1d010, 2 },
87 [PCIE_AXI_S_ARES] = { 0x1d010, 1 },
88 [PCIE_AXI_M_ARES] = { 0x1d010, 0 },
89 [ESS_RESET] = { 0x12008, 0},
90 [GCC_BLSP1_BCR] = {0x01000, 0},
91 [GCC_BLSP1_QUP1_BCR] = {0x02000, 0},
92 [GCC_BLSP1_UART1_BCR] = {0x02038, 0},
93 [GCC_BLSP1_QUP2_BCR] = {0x03008, 0},
94 [GCC_BLSP1_UART2_BCR] = {0x03028, 0},
95 [GCC_BIMC_BCR] = {0x04000, 0},
96 [GCC_TLMM_BCR] = {0x05000, 0},
97 [GCC_IMEM_BCR] = {0x0E000, 0},
98 [GCC_ESS_BCR] = {0x12008, 0},
99 [GCC_PRNG_BCR] = {0x13000, 0},
100 [GCC_BOOT_ROM_BCR] = {0x13008, 0},
101 [GCC_CRYPTO_BCR] = {0x16000, 0},
102 [GCC_SDCC1_BCR] = {0x18000, 0},
103 [GCC_SEC_CTRL_BCR] = {0x1A000, 0},
104 [GCC_AUDIO_BCR] = {0x1B008, 0},
105 [GCC_QPIC_BCR] = {0x1C000, 0},
106 [GCC_PCIE_BCR] = {0x1D000, 0},
107 [GCC_USB2_BCR] = {0x1E008, 0},
108 [GCC_USB2_PHY_BCR] = {0x1E018, 0},
109 [GCC_USB3_BCR] = {0x1E024, 0},
110 [GCC_USB3_PHY_BCR] = {0x1E034, 0},
111 [GCC_SYSTEM_NOC_BCR] = {0x21000, 0},
112 [GCC_PCNOC_BCR] = {0x2102C, 0},
113 [GCC_DCD_BCR] = {0x21038, 0},
114 [GCC_SNOC_BUS_TIMEOUT0_BCR] = {0x21064, 0},
115 [GCC_SNOC_BUS_TIMEOUT1_BCR] = {0x2106C, 0},
116 [GCC_SNOC_BUS_TIMEOUT2_BCR] = {0x21074, 0},
117 [GCC_SNOC_BUS_TIMEOUT3_BCR] = {0x2107C, 0},
118 [GCC_PCNOC_BUS_TIMEOUT0_BCR] = {0x21084, 0},
119 [GCC_PCNOC_BUS_TIMEOUT1_BCR] = {0x2108C, 0},
120 [GCC_PCNOC_BUS_TIMEOUT2_BCR] = {0x21094, 0},
121 [GCC_PCNOC_BUS_TIMEOUT3_BCR] = {0x2109C, 0},
122 [GCC_PCNOC_BUS_TIMEOUT4_BCR] = {0x210A4, 0},
123 [GCC_PCNOC_BUS_TIMEOUT5_BCR] = {0x210AC, 0},
124 [GCC_PCNOC_BUS_TIMEOUT6_BCR] = {0x210B4, 0},
125 [GCC_PCNOC_BUS_TIMEOUT7_BCR] = {0x210BC, 0},
126 [GCC_PCNOC_BUS_TIMEOUT8_BCR] = {0x210C4, 0},
127 [GCC_PCNOC_BUS_TIMEOUT9_BCR] = {0x210CC, 0},
128 [GCC_TCSR_BCR] = {0x22000, 0},
129 [GCC_MPM_BCR] = {0x24000, 0},
130 [GCC_SPDM_BCR] = {0x25000, 0},
131 };
132
133 int
134 qcom_gcc_ipq4018_hwreset_assert(device_t dev, intptr_t id, bool reset)
135 {
136 struct qcom_gcc_ipq4018_softc *sc;
137 uint32_t reg;
138
139 sc = device_get_softc(dev);
140
141 if (id > nitems(gcc_ipq4019_reset_list)) {
142 device_printf(dev, "%s: invalid id (%d)\n", __func__, id);
143 return (EINVAL);
144 }
145
146 mtx_lock(&sc->mtx);
147 reg = bus_read_4(sc->reg, gcc_ipq4019_reset_list[id].reg);
148 if (reset)
149 reg |= (1U << gcc_ipq4019_reset_list[id].bit);
150 else
151 reg &= ~(1U << gcc_ipq4019_reset_list[id].bit);
152 bus_write_4(sc->reg, gcc_ipq4019_reset_list[id].reg, reg);
153 mtx_unlock(&sc->mtx);
154 return (0);
155 }
156
157 int
158 qcom_gcc_ipq4018_hwreset_is_asserted(device_t dev, intptr_t id, bool *reset)
159 {
160 struct qcom_gcc_ipq4018_softc *sc;
161 uint32_t reg;
162
163 sc = device_get_softc(dev);
164
165 if (id > nitems(gcc_ipq4019_reset_list)) {
166 device_printf(dev, "%s: invalid id (%d)\n", __func__, id);
167 return (EINVAL);
168 }
169 mtx_lock(&sc->mtx);
170 reg = bus_read_4(sc->reg, gcc_ipq4019_reset_list[id].reg);
171 if (reg & ((1U << gcc_ipq4019_reset_list[id].bit)))
172 *reset = true;
173 else
174 *reset = false;
175 mtx_unlock(&sc->mtx);
176
177 device_printf(dev, "called; id=%d\n", id);
178 return (0);
179 }
180
Cache object: ac1f8f1dfc62b18a327eb7a1c92295f7
|