Lines Matching +full:syscon +full:- +full:dev
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
40 #include <dev/fdt/simplebus.h>
42 #include <dev/ofw/ofw_bus.h>
43 #include <dev/ofw/ofw_bus_subr.h>
45 #include <dev/fdt/simple_mfd.h>
47 device_t simple_mfd_add_device(device_t dev, phandle_t node, u_int order,
49 struct simplebus_devinfo *simple_mfd_setup_dinfo(device_t dev, phandle_t node,
53 #include <dev/syscon/syscon.h>
57 static uint32_t simple_mfd_syscon_read_4(struct syscon *syscon,
59 static int simple_mfd_syscon_write_4(struct syscon *syscon, bus_size_t offset,
61 static int simple_mfd_syscon_modify_4(struct syscon *syscon, bus_size_t offset,
64 #define SYSCON_LOCK(_sc) mtx_lock_spin(&(_sc)->mtx)
65 #define SYSCON_UNLOCK(_sc) mtx_unlock_spin(&(_sc)->mtx)
66 #define SYSCON_LOCK_INIT(_sc) mtx_init(&(_sc)->mtx, \
67 device_get_nameunit((_sc)->dev), "syscon", MTX_SPIN)
68 #define SYSCON_LOCK_DESTROY(_sc) mtx_destroy(&(_sc)->mtx);
69 #define SYSCON_ASSERT_LOCKED(_sc) mtx_assert(&(_sc)->mtx, MA_OWNED);
70 #define SYSCON_ASSERT_UNLOCKED(_sc) mtx_assert(&(_sc)->mtx, MA_NOTOWNED);
83 simple_mfd_syscon_read_4(struct syscon *syscon, bus_size_t offset) in simple_mfd_syscon_read_4() argument
88 sc = device_get_softc(syscon->pdev); in simple_mfd_syscon_read_4()
90 val = bus_read_4(sc->mem_res, offset); in simple_mfd_syscon_read_4()
95 simple_mfd_syscon_write_4(struct syscon *syscon, bus_size_t offset, in simple_mfd_syscon_write_4() argument
100 sc = device_get_softc(syscon->pdev); in simple_mfd_syscon_write_4()
102 bus_write_4(sc->mem_res, offset, val); in simple_mfd_syscon_write_4()
107 simple_mfd_syscon_modify_4(struct syscon *syscon, bus_size_t offset, in simple_mfd_syscon_modify_4() argument
113 sc = device_get_softc(syscon->pdev); in simple_mfd_syscon_modify_4()
115 val = bus_read_4(sc->mem_res, offset); in simple_mfd_syscon_modify_4()
118 bus_write_4(sc->mem_res, offset, val); in simple_mfd_syscon_modify_4()
123 simple_mfd_syscon_get_handle(device_t dev, struct syscon **syscon) in simple_mfd_syscon_get_handle() argument
127 sc = device_get_softc(dev); in simple_mfd_syscon_get_handle()
128 *syscon = sc->syscon; in simple_mfd_syscon_get_handle()
129 if (*syscon == NULL) in simple_mfd_syscon_get_handle()
135 simple_mfd_syscon_lock(device_t dev) in simple_mfd_syscon_lock() argument
139 sc = device_get_softc(dev); in simple_mfd_syscon_lock()
144 simple_mfd_syscon_unlock(device_t dev) in simple_mfd_syscon_unlock() argument
148 sc = device_get_softc(dev); in simple_mfd_syscon_unlock()
153 simple_mfd_probe(device_t dev) in simple_mfd_probe() argument
156 if (!ofw_bus_status_okay(dev)) in simple_mfd_probe()
158 if (!ofw_bus_is_compatible(dev, "simple-mfd")) in simple_mfd_probe()
161 device_set_desc(dev, "Simple MFD (Multi-Functions Device)"); in simple_mfd_probe()
167 simple_mfd_attach(device_t dev) in simple_mfd_attach() argument
173 sc = device_get_softc(dev); in simple_mfd_attach()
174 node = ofw_bus_get_node(dev); in simple_mfd_attach()
176 sc->dev = dev; in simple_mfd_attach()
179 /* Parse address-cells and size-cells from the parent node as a fallback */ in simple_mfd_attach()
180 if (OF_getencprop(node, "#address-cells", &sc->sc.acells, in simple_mfd_attach()
181 sizeof(sc->sc.acells)) == -1) { in simple_mfd_attach()
182 if (OF_getencprop(OF_parent(node), "#address-cells", &sc->sc.acells, in simple_mfd_attach()
183 sizeof(sc->sc.acells)) == -1) { in simple_mfd_attach()
184 sc->sc.acells = 2; in simple_mfd_attach()
187 if (OF_getencprop(node, "#size-cells", &sc->sc.scells, in simple_mfd_attach()
188 sizeof(sc->sc.scells)) == -1) { in simple_mfd_attach()
189 if (OF_getencprop(OF_parent(node), "#size-cells", &sc->sc.scells, in simple_mfd_attach()
190 sizeof(sc->sc.scells)) == -1) { in simple_mfd_attach()
191 sc->sc.scells = 1; in simple_mfd_attach()
197 if (simplebus_fill_ranges(node, &sc->sc) < 0) { in simple_mfd_attach()
198 device_printf(dev, "could not get ranges\n"); in simple_mfd_attach()
205 (void)simple_mfd_add_device(dev, child, 0, NULL, -1, NULL); in simple_mfd_attach()
208 if (ofw_bus_is_compatible(dev, "syscon")) { in simple_mfd_attach()
209 sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, in simple_mfd_attach()
211 if (sc->mem_res == NULL) { in simple_mfd_attach()
212 device_printf(dev, in simple_mfd_attach()
218 sc->syscon = syscon_create_ofw_node(dev, in simple_mfd_attach()
219 &simple_mfd_syscon_class, ofw_bus_get_node(dev)); in simple_mfd_attach()
220 if (sc->syscon == NULL) { in simple_mfd_attach()
221 device_printf(dev, in simple_mfd_attach()
222 "Failed to create/register syscon\n"); in simple_mfd_attach()
226 bus_attach_children(dev); in simple_mfd_attach()
231 simple_mfd_detach(device_t dev) in simple_mfd_detach() argument
235 sc = device_get_softc(dev); in simple_mfd_detach()
236 if (ofw_bus_is_compatible(dev, "syscon")) { in simple_mfd_detach()
237 if (sc->syscon != NULL) { in simple_mfd_detach()
238 syscon_unregister(sc->syscon); in simple_mfd_detach()
239 free(sc->syscon, M_SYSCON); in simple_mfd_detach()
244 if (sc->mem_res != NULL) in simple_mfd_detach()
245 bus_release_resource(dev, SYS_RES_MEMORY, 0, in simple_mfd_detach()
246 sc->mem_res); in simple_mfd_detach()
252 simple_mfd_setup_dinfo(device_t dev, phandle_t node, in simple_mfd_setup_dinfo() argument
258 sc = device_get_softc(dev); in simple_mfd_setup_dinfo()
263 if (ofw_bus_gen_setup_devinfo(&ndi->obdinfo, node) != 0) { in simple_mfd_setup_dinfo()
270 resource_list_init(&ndi->rl); in simple_mfd_setup_dinfo()
271 ofw_bus_reg_to_rl(dev, OF_parent(node), sc->acells, sc->scells, &ndi->rl); in simple_mfd_setup_dinfo()
272 ofw_bus_intr_to_rl(dev, node, &ndi->rl, NULL); in simple_mfd_setup_dinfo()
278 simple_mfd_add_device(device_t dev, phandle_t node, u_int order, in simple_mfd_add_device() argument
284 if ((ndi = simple_mfd_setup_dinfo(dev, node, di)) == NULL) in simple_mfd_add_device()
286 cdev = device_add_child_ordered(dev, order, name, unit); in simple_mfd_add_device()
288 device_printf(dev, "<%s>: device_add_child failed\n", in simple_mfd_add_device()
289 ndi->obdinfo.obd_name); in simple_mfd_add_device()
290 resource_list_free(&ndi->rl); in simple_mfd_add_device()
291 ofw_bus_gen_destroy_devinfo(&ndi->obdinfo); in simple_mfd_add_device()
302 /* syscon interface */