diff --git a/sys/dev/extres/syscon/syscon.c b/sys/dev/extres/syscon/syscon.c index d2d87e6e53b7..d1f4fe0838b0 100644 --- a/sys/dev/extres/syscon/syscon.c +++ b/sys/dev/extres/syscon/syscon.c @@ -254,3 +254,14 @@ syscon_get_by_ofw_property(device_t cdev, phandle_t cnode, char *name, return (0); } #endif + +int +syscon_get_handle_default(device_t dev, struct syscon **syscon) +{ + device_t parent; + + parent = device_get_parent(dev); + if (parent == NULL) + return (ENODEV); + return (SYSCON_GET_HANDLE(parent, syscon)); +} diff --git a/sys/dev/extres/syscon/syscon_if.m b/sys/dev/extres/syscon/syscon_if.m index b394927842d7..98008340cc9d 100644 --- a/sys/dev/extres/syscon/syscon_if.m +++ b/sys/dev/extres/syscon/syscon_if.m @@ -32,6 +32,7 @@ INTERFACE syscon; HEADER { struct syscon; + int syscon_get_handle_default(device_t dev, struct syscon **syscon); } METHOD int init { @@ -62,3 +63,11 @@ METHOD int modify_4 { uint32_t clear_bits; uint32_t set_bits; }; + +/** + * Get syscon handle from parent driver + */ +METHOD int get_handle { + device_t dev; + struct syscon **syscon; +} DEFAULT syscon_get_handle_default; diff --git a/sys/dev/fdt/simple_mfd.c b/sys/dev/fdt/simple_mfd.c index 596043629ea6..61868657d80b 100644 --- a/sys/dev/fdt/simple_mfd.c +++ b/sys/dev/fdt/simple_mfd.c @@ -49,14 +49,16 @@ __FBSDID("$FreeBSD$"); device_t simple_mfd_add_device(device_t dev, phandle_t node, u_int order, const char *name, int unit, struct simplebus_devinfo *di); -struct simplebus_devinfo *simple_mfd_setup_dinfo(device_t dev, phandle_t node, struct simplebus_devinfo *di); +struct simplebus_devinfo *simple_mfd_setup_dinfo(device_t dev, phandle_t node, + struct simplebus_devinfo *di); #include "syscon_if.h" #include MALLOC_DECLARE(M_SYSCON); -static uint32_t simple_mfd_syscon_read_4(struct syscon *syscon, bus_size_t offset); +static uint32_t simple_mfd_syscon_read_4(struct syscon *syscon, + bus_size_t offset); static int simple_mfd_syscon_write_4(struct syscon *syscon, bus_size_t offset, uint32_t val); static int simple_mfd_syscon_modify_4(struct syscon *syscon, bus_size_t offset, @@ -125,6 +127,17 @@ simple_mfd_syscon_modify_4(struct syscon *syscon, bus_size_t offset, SYSCON_UNLOCK(sc); return (0); } +static int +simple_mfd_syscon_get_handle(device_t dev, struct syscon **syscon) +{ + struct simple_mfd_softc *sc; + + sc = device_get_softc(dev); + *syscon = sc->syscon; + if (syscon == NULL) + return (ENODEV); + return (0); +} static int simple_mfd_probe(device_t dev) @@ -278,6 +291,8 @@ simple_mfd_add_device(device_t dev, phandle_t node, u_int order, } static device_method_t simple_mfd_methods[] = { + /* syscon interface */ + DEVMETHOD(syscon_get_handle, simple_mfd_syscon_get_handle), /* Device interface */ DEVMETHOD(device_probe, simple_mfd_probe), DEVMETHOD(device_attach, simple_mfd_attach),