173450c4aSEmmanuel Vadot /*-
24d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
373450c4aSEmmanuel Vadot *
473450c4aSEmmanuel Vadot * Copyright (c) 2018 Rubicon Communications, LLC (Netgate)
573450c4aSEmmanuel Vadot *
673450c4aSEmmanuel Vadot * Redistribution and use in source and binary forms, with or without
773450c4aSEmmanuel Vadot * modification, are permitted provided that the following conditions
873450c4aSEmmanuel Vadot * are met:
973450c4aSEmmanuel Vadot * 1. Redistributions of source code must retain the above copyright
1073450c4aSEmmanuel Vadot * notice, this list of conditions and the following disclaimer.
1173450c4aSEmmanuel Vadot * 2. Redistributions in binary form must reproduce the above copyright
1273450c4aSEmmanuel Vadot * notice, this list of conditions and the following disclaimer in the
1373450c4aSEmmanuel Vadot * documentation and/or other materials provided with the distribution.
1473450c4aSEmmanuel Vadot *
1573450c4aSEmmanuel Vadot * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1673450c4aSEmmanuel Vadot * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1773450c4aSEmmanuel Vadot * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1873450c4aSEmmanuel Vadot * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1973450c4aSEmmanuel Vadot * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2073450c4aSEmmanuel Vadot * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2173450c4aSEmmanuel Vadot * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2273450c4aSEmmanuel Vadot * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2373450c4aSEmmanuel Vadot * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2473450c4aSEmmanuel Vadot * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2573450c4aSEmmanuel Vadot * SUCH DAMAGE.
2673450c4aSEmmanuel Vadot */
2773450c4aSEmmanuel Vadot
2873450c4aSEmmanuel Vadot #include <sys/param.h>
2973450c4aSEmmanuel Vadot #include <sys/systm.h>
3073450c4aSEmmanuel Vadot #include <sys/bus.h>
3173450c4aSEmmanuel Vadot
3273450c4aSEmmanuel Vadot #include <sys/kernel.h>
3373450c4aSEmmanuel Vadot #include <sys/module.h>
3473450c4aSEmmanuel Vadot #include <sys/rman.h>
3573450c4aSEmmanuel Vadot #include <sys/lock.h>
3673450c4aSEmmanuel Vadot #include <sys/mutex.h>
3773450c4aSEmmanuel Vadot
3873450c4aSEmmanuel Vadot #include <machine/bus.h>
3973450c4aSEmmanuel Vadot #include <machine/resource.h>
4073450c4aSEmmanuel Vadot #include <machine/intr.h>
4173450c4aSEmmanuel Vadot
42be82b3a0SEmmanuel Vadot #include <dev/clk/clk_fixed.h>
43be82b3a0SEmmanuel Vadot #include <dev/clk/clk_gate.h>
44*62e8ccc3SEmmanuel Vadot #include <dev/syscon/syscon.h>
4573450c4aSEmmanuel Vadot
4673450c4aSEmmanuel Vadot #include <dev/ofw/ofw_bus.h>
4773450c4aSEmmanuel Vadot #include <dev/ofw/ofw_bus_subr.h>
4873450c4aSEmmanuel Vadot
4973450c4aSEmmanuel Vadot #include <arm/mv/mv_cp110_clock.h>
5073450c4aSEmmanuel Vadot
5173450c4aSEmmanuel Vadot #include "clkdev_if.h"
524b84206bSMichal Meloun #include "syscon_if.h"
5373450c4aSEmmanuel Vadot
5473450c4aSEmmanuel Vadot /* Clocks */
5573450c4aSEmmanuel Vadot static struct clk_fixed_def cp110_clk_pll_0 = {
5673450c4aSEmmanuel Vadot .clkdef.id = CP110_PLL_0,
5773450c4aSEmmanuel Vadot .freq = 1000000000,
5873450c4aSEmmanuel Vadot };
5973450c4aSEmmanuel Vadot
6073450c4aSEmmanuel Vadot static const char *clk_parents_0[] = {"cp110-pll0-0"};
6173450c4aSEmmanuel Vadot static const char *clk_parents_1[] = {"cp110-pll0-1"};
6273450c4aSEmmanuel Vadot
6373450c4aSEmmanuel Vadot static struct clk_fixed_def cp110_clk_ppv2_core = {
6473450c4aSEmmanuel Vadot .clkdef.id = CP110_PPV2_CORE,
6573450c4aSEmmanuel Vadot .clkdef.parent_cnt = 1,
6673450c4aSEmmanuel Vadot .mult = 1,
6773450c4aSEmmanuel Vadot .div = 3,
6873450c4aSEmmanuel Vadot };
6973450c4aSEmmanuel Vadot
7073450c4aSEmmanuel Vadot static struct clk_fixed_def cp110_clk_x2core = {
7173450c4aSEmmanuel Vadot .clkdef.id = CP110_X2CORE,
7273450c4aSEmmanuel Vadot .clkdef.parent_cnt = 1,
7373450c4aSEmmanuel Vadot .mult = 1,
7473450c4aSEmmanuel Vadot .div = 2,
7573450c4aSEmmanuel Vadot };
7673450c4aSEmmanuel Vadot
7773450c4aSEmmanuel Vadot static const char *core_parents_0[] = {"cp110-x2core-0"};
7873450c4aSEmmanuel Vadot static const char *core_parents_1[] = {"cp110-x2core-1"};
7973450c4aSEmmanuel Vadot
8073450c4aSEmmanuel Vadot static struct clk_fixed_def cp110_clk_core = {
8173450c4aSEmmanuel Vadot .clkdef.id = CP110_CORE,
8273450c4aSEmmanuel Vadot .clkdef.parent_cnt = 1,
8373450c4aSEmmanuel Vadot .mult = 1,
8473450c4aSEmmanuel Vadot .div = 2,
8573450c4aSEmmanuel Vadot };
8673450c4aSEmmanuel Vadot
8773450c4aSEmmanuel Vadot static struct clk_fixed_def cp110_clk_sdio = {
8873450c4aSEmmanuel Vadot .clkdef.id = CP110_SDIO,
8973450c4aSEmmanuel Vadot .clkdef.parent_cnt = 1,
9073450c4aSEmmanuel Vadot .mult = 2,
9173450c4aSEmmanuel Vadot .div = 5,
9273450c4aSEmmanuel Vadot };
9373450c4aSEmmanuel Vadot
9473450c4aSEmmanuel Vadot /* Gates */
9573450c4aSEmmanuel Vadot
9673450c4aSEmmanuel Vadot static struct cp110_gate cp110_gates[] = {
9773450c4aSEmmanuel Vadot CCU_GATE(CP110_GATE_AUDIO, "cp110-gate-audio", 0)
9873450c4aSEmmanuel Vadot CCU_GATE(CP110_GATE_COMM_UNIT, "cp110-gate-comm_unit", 1)
9973450c4aSEmmanuel Vadot /* CCU_GATE(CP110_GATE_NAND, "cp110-gate-nand", 2) */
10073450c4aSEmmanuel Vadot CCU_GATE(CP110_GATE_PPV2, "cp110-gate-ppv2", 3)
10173450c4aSEmmanuel Vadot CCU_GATE(CP110_GATE_SDIO, "cp110-gate-sdio", 4)
10273450c4aSEmmanuel Vadot CCU_GATE(CP110_GATE_MG, "cp110-gate-mg", 5)
10373450c4aSEmmanuel Vadot CCU_GATE(CP110_GATE_MG_CORE, "cp110-gate-mg_core", 6)
10473450c4aSEmmanuel Vadot CCU_GATE(CP110_GATE_XOR1, "cp110-gate-xor1", 7)
10573450c4aSEmmanuel Vadot CCU_GATE(CP110_GATE_XOR0, "cp110-gate-xor0", 8)
10673450c4aSEmmanuel Vadot CCU_GATE(CP110_GATE_GOP_DP, "cp110-gate-gop_dp", 9)
10773450c4aSEmmanuel Vadot CCU_GATE(CP110_GATE_PCIE_X1_0, "cp110-gate-pcie_x10", 11)
10873450c4aSEmmanuel Vadot CCU_GATE(CP110_GATE_PCIE_X1_1, "cp110-gate-pcie_x11", 12)
10973450c4aSEmmanuel Vadot CCU_GATE(CP110_GATE_PCIE_X4, "cp110-gate-pcie_x4", 13)
11073450c4aSEmmanuel Vadot CCU_GATE(CP110_GATE_PCIE_XOR, "cp110-gate-pcie_xor", 14)
11173450c4aSEmmanuel Vadot CCU_GATE(CP110_GATE_SATA, "cp110-gate-sata", 15)
11273450c4aSEmmanuel Vadot CCU_GATE(CP110_GATE_SATA_USB, "cp110-gate-sata_usb", 16)
11373450c4aSEmmanuel Vadot CCU_GATE(CP110_GATE_MAIN, "cp110-gate-main", 17)
11473450c4aSEmmanuel Vadot CCU_GATE(CP110_GATE_SDMMC_GOP, "cp110-gate-sdmmc_gop", 18)
11573450c4aSEmmanuel Vadot CCU_GATE(CP110_GATE_SLOW_IO, "cp110-gate-slow_io", 21)
11673450c4aSEmmanuel Vadot CCU_GATE(CP110_GATE_USB3H0, "cp110-gate-usb3h0", 22)
11773450c4aSEmmanuel Vadot CCU_GATE(CP110_GATE_USB3H1, "cp110-gate-usb3h1", 23)
11873450c4aSEmmanuel Vadot CCU_GATE(CP110_GATE_USB3DEV, "cp110-gate-usb3dev", 24)
11973450c4aSEmmanuel Vadot CCU_GATE(CP110_GATE_EIP150, "cp110-gate-eip150", 25)
12073450c4aSEmmanuel Vadot CCU_GATE(CP110_GATE_EIP197, "cp110-gate-eip197", 26)
12173450c4aSEmmanuel Vadot };
12273450c4aSEmmanuel Vadot
12373450c4aSEmmanuel Vadot struct mv_cp110_clock_softc {
12473450c4aSEmmanuel Vadot device_t dev;
1254b84206bSMichal Meloun struct syscon *syscon;
12673450c4aSEmmanuel Vadot struct mtx mtx;
12773450c4aSEmmanuel Vadot };
12873450c4aSEmmanuel Vadot
12973450c4aSEmmanuel Vadot static struct ofw_compat_data compat_data[] = {
13073450c4aSEmmanuel Vadot {"marvell,cp110-clock", 1},
13173450c4aSEmmanuel Vadot {NULL, 0}
13273450c4aSEmmanuel Vadot };
13373450c4aSEmmanuel Vadot
1344b84206bSMichal Meloun #define RD4(sc, reg) SYSCON_READ_4((sc)->syscon, (reg))
1354b84206bSMichal Meloun #define WR4(sc, reg, val) SYSCON_WRITE_4((sc)->syscon, (reg), (val))
13673450c4aSEmmanuel Vadot
13773450c4aSEmmanuel Vadot static char *
mv_cp110_clock_name(device_t dev,const char * name)13873450c4aSEmmanuel Vadot mv_cp110_clock_name(device_t dev, const char *name)
13973450c4aSEmmanuel Vadot {
14073450c4aSEmmanuel Vadot char *clkname = NULL;
14173450c4aSEmmanuel Vadot int unit;
14273450c4aSEmmanuel Vadot
14373450c4aSEmmanuel Vadot unit = device_get_unit(dev);
14473450c4aSEmmanuel Vadot if (asprintf(&clkname, M_DEVBUF, "%s-%d", name, unit) <= 0)
14573450c4aSEmmanuel Vadot panic("Cannot generate unique clock name for %s\n", name);
14673450c4aSEmmanuel Vadot return (clkname);
14773450c4aSEmmanuel Vadot }
14873450c4aSEmmanuel Vadot
14973450c4aSEmmanuel Vadot static int
mv_cp110_clock_probe(device_t dev)15073450c4aSEmmanuel Vadot mv_cp110_clock_probe(device_t dev)
15173450c4aSEmmanuel Vadot {
15273450c4aSEmmanuel Vadot
15373450c4aSEmmanuel Vadot if (!ofw_bus_status_okay(dev))
15473450c4aSEmmanuel Vadot return (ENXIO);
15573450c4aSEmmanuel Vadot
15673450c4aSEmmanuel Vadot if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0)
15773450c4aSEmmanuel Vadot return (ENXIO);
15873450c4aSEmmanuel Vadot
15973450c4aSEmmanuel Vadot device_set_desc(dev, "Marvell CP110 Clock Controller");
16073450c4aSEmmanuel Vadot return (BUS_PROBE_DEFAULT);
16173450c4aSEmmanuel Vadot }
16273450c4aSEmmanuel Vadot
16373450c4aSEmmanuel Vadot static int
cp110_ofw_map(struct clkdom * clkdom,uint32_t ncells,phandle_t * cells,struct clknode ** clk)16473450c4aSEmmanuel Vadot cp110_ofw_map(struct clkdom *clkdom, uint32_t ncells,
16573450c4aSEmmanuel Vadot phandle_t *cells, struct clknode **clk)
16673450c4aSEmmanuel Vadot {
16773450c4aSEmmanuel Vadot int id = 0;
16873450c4aSEmmanuel Vadot
16973450c4aSEmmanuel Vadot if (ncells != 2)
17073450c4aSEmmanuel Vadot return (ENXIO);
17173450c4aSEmmanuel Vadot
17273450c4aSEmmanuel Vadot id = cells[1];
17373450c4aSEmmanuel Vadot if (cells[0] == 1)
17473450c4aSEmmanuel Vadot id += CP110_MAX_CLOCK;
17573450c4aSEmmanuel Vadot
17673450c4aSEmmanuel Vadot *clk = clknode_find_by_id(clkdom, id);
17773450c4aSEmmanuel Vadot
17873450c4aSEmmanuel Vadot return (0);
17973450c4aSEmmanuel Vadot }
18073450c4aSEmmanuel Vadot
18173450c4aSEmmanuel Vadot static int
mv_cp110_clock_attach(device_t dev)18273450c4aSEmmanuel Vadot mv_cp110_clock_attach(device_t dev)
18373450c4aSEmmanuel Vadot {
18473450c4aSEmmanuel Vadot struct mv_cp110_clock_softc *sc;
18573450c4aSEmmanuel Vadot struct clkdom *clkdom;
18673450c4aSEmmanuel Vadot struct clk_gate_def def;
18773450c4aSEmmanuel Vadot char *pll0_name;
18873450c4aSEmmanuel Vadot int unit, i;
18973450c4aSEmmanuel Vadot
19073450c4aSEmmanuel Vadot sc = device_get_softc(dev);
19173450c4aSEmmanuel Vadot sc->dev = dev;
19273450c4aSEmmanuel Vadot
1934b84206bSMichal Meloun if (SYSCON_GET_HANDLE(sc->dev, &sc->syscon) != 0 ||
1944b84206bSMichal Meloun sc->syscon == NULL) {
1954b84206bSMichal Meloun device_printf(dev, "cannot get syscon for device\n");
19673450c4aSEmmanuel Vadot return (ENXIO);
19773450c4aSEmmanuel Vadot }
19873450c4aSEmmanuel Vadot
19973450c4aSEmmanuel Vadot unit = device_get_unit(dev);
20073450c4aSEmmanuel Vadot if (unit > 1) {
20173450c4aSEmmanuel Vadot device_printf(dev, "Bogus cp110-system-controller unit %d\n", unit);
20273450c4aSEmmanuel Vadot return (ENXIO);
20373450c4aSEmmanuel Vadot }
20473450c4aSEmmanuel Vadot
20573450c4aSEmmanuel Vadot mtx_init(&sc->mtx, device_get_nameunit(dev), NULL, MTX_DEF);
20673450c4aSEmmanuel Vadot
20773450c4aSEmmanuel Vadot clkdom = clkdom_create(dev);
20873450c4aSEmmanuel Vadot clkdom_set_ofw_mapper(clkdom, cp110_ofw_map);
20973450c4aSEmmanuel Vadot
21073450c4aSEmmanuel Vadot pll0_name = mv_cp110_clock_name(dev, "cp110-pll0");
21173450c4aSEmmanuel Vadot cp110_clk_pll_0.clkdef.name = pll0_name;
21273450c4aSEmmanuel Vadot clknode_fixed_register(clkdom, &cp110_clk_pll_0);
21373450c4aSEmmanuel Vadot
21473450c4aSEmmanuel Vadot cp110_clk_ppv2_core.clkdef.name = mv_cp110_clock_name(dev, "cp110-ppv2");
21573450c4aSEmmanuel Vadot cp110_clk_ppv2_core.clkdef.parent_names = (unit == 0) ? clk_parents_0 : clk_parents_1;
21673450c4aSEmmanuel Vadot clknode_fixed_register(clkdom, &cp110_clk_ppv2_core);
21773450c4aSEmmanuel Vadot
21873450c4aSEmmanuel Vadot cp110_clk_x2core.clkdef.name = mv_cp110_clock_name(dev, "cp110-x2core");
21973450c4aSEmmanuel Vadot cp110_clk_x2core.clkdef.parent_names = (unit == 0) ? clk_parents_0 : clk_parents_1;
22073450c4aSEmmanuel Vadot clknode_fixed_register(clkdom, &cp110_clk_x2core);
22173450c4aSEmmanuel Vadot
22273450c4aSEmmanuel Vadot cp110_clk_core.clkdef.name = mv_cp110_clock_name(dev, "cp110-core");
22373450c4aSEmmanuel Vadot cp110_clk_core.clkdef.parent_names = (unit == 0) ? core_parents_0 : core_parents_1;
22473450c4aSEmmanuel Vadot clknode_fixed_register(clkdom, &cp110_clk_core);
22573450c4aSEmmanuel Vadot
22673450c4aSEmmanuel Vadot /* NAND missing */
22773450c4aSEmmanuel Vadot
22873450c4aSEmmanuel Vadot cp110_clk_sdio.clkdef.name = mv_cp110_clock_name(dev, "cp110-sdio");
22973450c4aSEmmanuel Vadot cp110_clk_sdio.clkdef.parent_names = (unit == 0) ? clk_parents_0 : clk_parents_1;
23073450c4aSEmmanuel Vadot clknode_fixed_register(clkdom, &cp110_clk_sdio);
23173450c4aSEmmanuel Vadot
23273450c4aSEmmanuel Vadot for (i = 0; i < nitems(cp110_gates); i++) {
23373450c4aSEmmanuel Vadot if (cp110_gates[i].name == NULL)
23473450c4aSEmmanuel Vadot continue;
23573450c4aSEmmanuel Vadot
23673450c4aSEmmanuel Vadot memset(&def, 0, sizeof(def));
23773450c4aSEmmanuel Vadot def.clkdef.id = CP110_MAX_CLOCK + i;
23873450c4aSEmmanuel Vadot def.clkdef.name = mv_cp110_clock_name(dev, cp110_gates[i].name);
23973450c4aSEmmanuel Vadot def.clkdef.parent_cnt = 1;
24073450c4aSEmmanuel Vadot def.offset = CP110_CLOCK_GATING_OFFSET;
24173450c4aSEmmanuel Vadot def.shift = cp110_gates[i].shift;
24273450c4aSEmmanuel Vadot def.mask = 1;
24373450c4aSEmmanuel Vadot def.on_value = 1;
24473450c4aSEmmanuel Vadot def.off_value = 0;
24573450c4aSEmmanuel Vadot
24673450c4aSEmmanuel Vadot switch (i) {
24773450c4aSEmmanuel Vadot case CP110_GATE_MG:
24873450c4aSEmmanuel Vadot case CP110_GATE_GOP_DP:
24973450c4aSEmmanuel Vadot case CP110_GATE_PPV2:
25073450c4aSEmmanuel Vadot def.clkdef.parent_names = &cp110_clk_ppv2_core.clkdef.name;
25173450c4aSEmmanuel Vadot break;
25273450c4aSEmmanuel Vadot case CP110_GATE_SDIO:
25373450c4aSEmmanuel Vadot def.clkdef.parent_names = &cp110_clk_sdio.clkdef.name;
25473450c4aSEmmanuel Vadot break;
25573450c4aSEmmanuel Vadot case CP110_GATE_MAIN:
25673450c4aSEmmanuel Vadot case CP110_GATE_PCIE_XOR:
25773450c4aSEmmanuel Vadot case CP110_GATE_PCIE_X4:
25873450c4aSEmmanuel Vadot case CP110_GATE_EIP150:
25973450c4aSEmmanuel Vadot case CP110_GATE_EIP197:
26073450c4aSEmmanuel Vadot def.clkdef.parent_names = &cp110_clk_x2core.clkdef.name;
26173450c4aSEmmanuel Vadot break;
26273450c4aSEmmanuel Vadot default:
26373450c4aSEmmanuel Vadot def.clkdef.parent_names = &cp110_clk_core.clkdef.name;
26473450c4aSEmmanuel Vadot break;
26573450c4aSEmmanuel Vadot }
26673450c4aSEmmanuel Vadot
26773450c4aSEmmanuel Vadot clknode_gate_register(clkdom, &def);
26873450c4aSEmmanuel Vadot }
26973450c4aSEmmanuel Vadot
27073450c4aSEmmanuel Vadot clkdom_finit(clkdom);
27173450c4aSEmmanuel Vadot
27273450c4aSEmmanuel Vadot if (bootverbose)
27373450c4aSEmmanuel Vadot clkdom_dump(clkdom);
27473450c4aSEmmanuel Vadot
27573450c4aSEmmanuel Vadot return (0);
27673450c4aSEmmanuel Vadot }
27773450c4aSEmmanuel Vadot
27873450c4aSEmmanuel Vadot static int
mv_cp110_clock_detach(device_t dev)27973450c4aSEmmanuel Vadot mv_cp110_clock_detach(device_t dev)
28073450c4aSEmmanuel Vadot {
28173450c4aSEmmanuel Vadot
28273450c4aSEmmanuel Vadot return (EBUSY);
28373450c4aSEmmanuel Vadot }
28473450c4aSEmmanuel Vadot
28573450c4aSEmmanuel Vadot static int
mv_cp110_clock_write_4(device_t dev,bus_addr_t addr,uint32_t val)28673450c4aSEmmanuel Vadot mv_cp110_clock_write_4(device_t dev, bus_addr_t addr, uint32_t val)
28773450c4aSEmmanuel Vadot {
28873450c4aSEmmanuel Vadot struct mv_cp110_clock_softc *sc;
28973450c4aSEmmanuel Vadot
29073450c4aSEmmanuel Vadot sc = device_get_softc(dev);
29173450c4aSEmmanuel Vadot WR4(sc, addr, val);
29273450c4aSEmmanuel Vadot return (0);
29373450c4aSEmmanuel Vadot }
29473450c4aSEmmanuel Vadot
29573450c4aSEmmanuel Vadot static int
mv_cp110_clock_read_4(device_t dev,bus_addr_t addr,uint32_t * val)29673450c4aSEmmanuel Vadot mv_cp110_clock_read_4(device_t dev, bus_addr_t addr, uint32_t *val)
29773450c4aSEmmanuel Vadot {
29873450c4aSEmmanuel Vadot struct mv_cp110_clock_softc *sc;
29973450c4aSEmmanuel Vadot
30073450c4aSEmmanuel Vadot sc = device_get_softc(dev);
30173450c4aSEmmanuel Vadot
30273450c4aSEmmanuel Vadot *val = RD4(sc, addr);
30373450c4aSEmmanuel Vadot return (0);
30473450c4aSEmmanuel Vadot }
30573450c4aSEmmanuel Vadot
30673450c4aSEmmanuel Vadot static int
mv_cp110_clock_modify_4(device_t dev,bus_addr_t addr,uint32_t clr,uint32_t set)30773450c4aSEmmanuel Vadot mv_cp110_clock_modify_4(device_t dev, bus_addr_t addr, uint32_t clr, uint32_t set)
30873450c4aSEmmanuel Vadot {
30973450c4aSEmmanuel Vadot struct mv_cp110_clock_softc *sc;
31073450c4aSEmmanuel Vadot uint32_t reg;
31173450c4aSEmmanuel Vadot
31273450c4aSEmmanuel Vadot sc = device_get_softc(dev);
31373450c4aSEmmanuel Vadot
31473450c4aSEmmanuel Vadot reg = RD4(sc, addr);
31573450c4aSEmmanuel Vadot reg &= ~clr;
31673450c4aSEmmanuel Vadot reg |= set;
31773450c4aSEmmanuel Vadot WR4(sc, addr, reg);
31873450c4aSEmmanuel Vadot
31973450c4aSEmmanuel Vadot return (0);
32073450c4aSEmmanuel Vadot }
32173450c4aSEmmanuel Vadot
32273450c4aSEmmanuel Vadot static void
mv_cp110_clock_device_lock(device_t dev)32373450c4aSEmmanuel Vadot mv_cp110_clock_device_lock(device_t dev)
32473450c4aSEmmanuel Vadot {
32573450c4aSEmmanuel Vadot struct mv_cp110_clock_softc *sc;
32673450c4aSEmmanuel Vadot
32773450c4aSEmmanuel Vadot sc = device_get_softc(dev);
32873450c4aSEmmanuel Vadot mtx_lock(&sc->mtx);
32973450c4aSEmmanuel Vadot }
33073450c4aSEmmanuel Vadot
33173450c4aSEmmanuel Vadot static void
mv_cp110_clock_device_unlock(device_t dev)33273450c4aSEmmanuel Vadot mv_cp110_clock_device_unlock(device_t dev)
33373450c4aSEmmanuel Vadot {
33473450c4aSEmmanuel Vadot struct mv_cp110_clock_softc *sc;
33573450c4aSEmmanuel Vadot
33673450c4aSEmmanuel Vadot sc = device_get_softc(dev);
33773450c4aSEmmanuel Vadot mtx_unlock(&sc->mtx);
33873450c4aSEmmanuel Vadot }
33973450c4aSEmmanuel Vadot
34073450c4aSEmmanuel Vadot static device_method_t mv_cp110_clock_methods[] = {
34173450c4aSEmmanuel Vadot /* Device interface */
34273450c4aSEmmanuel Vadot DEVMETHOD(device_probe, mv_cp110_clock_probe),
34373450c4aSEmmanuel Vadot DEVMETHOD(device_attach, mv_cp110_clock_attach),
34473450c4aSEmmanuel Vadot DEVMETHOD(device_detach, mv_cp110_clock_detach),
34573450c4aSEmmanuel Vadot
34673450c4aSEmmanuel Vadot /* clkdev interface */
34773450c4aSEmmanuel Vadot DEVMETHOD(clkdev_write_4, mv_cp110_clock_write_4),
34873450c4aSEmmanuel Vadot DEVMETHOD(clkdev_read_4, mv_cp110_clock_read_4),
34973450c4aSEmmanuel Vadot DEVMETHOD(clkdev_modify_4, mv_cp110_clock_modify_4),
35073450c4aSEmmanuel Vadot DEVMETHOD(clkdev_device_lock, mv_cp110_clock_device_lock),
35173450c4aSEmmanuel Vadot DEVMETHOD(clkdev_device_unlock, mv_cp110_clock_device_unlock),
35273450c4aSEmmanuel Vadot
35373450c4aSEmmanuel Vadot DEVMETHOD_END
35473450c4aSEmmanuel Vadot };
35573450c4aSEmmanuel Vadot
35673450c4aSEmmanuel Vadot static driver_t mv_cp110_clock_driver = {
35773450c4aSEmmanuel Vadot "mv_cp110_clock",
35873450c4aSEmmanuel Vadot mv_cp110_clock_methods,
35973450c4aSEmmanuel Vadot sizeof(struct mv_cp110_clock_softc),
36073450c4aSEmmanuel Vadot };
36173450c4aSEmmanuel Vadot
362a3b866cbSJohn Baldwin EARLY_DRIVER_MODULE(mv_cp110_clock, simplebus, mv_cp110_clock_driver, 0, 0,
363a3b866cbSJohn Baldwin BUS_PASS_RESOURCE + BUS_PASS_ORDER_LATE);
364