diff options
author | Michal Meloun <mmel@FreeBSD.org> | 2016-07-10 18:28:15 +0000 |
---|---|---|
committer | Michal Meloun <mmel@FreeBSD.org> | 2016-07-10 18:28:15 +0000 |
commit | dac935533b354a9be9167013e999d128bfc8392b (patch) | |
tree | 8b7ffcc52987f5e05c0f5384d9d04ebc168605bd /sys/dev | |
parent | 5fa69ff0151ee425246714f9a7805caf0690af3a (diff) | |
download | src-dac935533b354a9be9167013e999d128bfc8392b.tar.gz src-dac935533b354a9be9167013e999d128bfc8392b.zip |
EXTRES: Add OF node as argument to all <foo>_get_by_ofw_<bar>() functions.
In some cases, the driver must handle given properties located in
specific OF subnode. Instead of creating duplicate set of function, add
'node' as argument to existing functions, defaulting it to device OF node.
MFC after: 3 weeks
Notes
Notes:
svn path=/head/; revision=302528
Diffstat (limited to 'sys/dev')
-rw-r--r-- | sys/dev/dwc/if_dwc.c | 4 | ||||
-rw-r--r-- | sys/dev/extres/clk/clk.c | 33 | ||||
-rw-r--r-- | sys/dev/extres/clk/clk.h | 7 | ||||
-rw-r--r-- | sys/dev/extres/clk/clk_fixed.c | 2 | ||||
-rw-r--r-- | sys/dev/extres/hwreset/hwreset.c | 17 | ||||
-rw-r--r-- | sys/dev/extres/hwreset/hwreset.h | 6 | ||||
-rw-r--r-- | sys/dev/extres/phy/phy.c | 23 | ||||
-rw-r--r-- | sys/dev/extres/phy/phy.h | 11 | ||||
-rw-r--r-- | sys/dev/extres/regulator/regulator.c | 8 | ||||
-rw-r--r-- | sys/dev/extres/regulator/regulator.h | 3 | ||||
-rw-r--r-- | sys/dev/iicbus/twsi/a10_twsi.c | 4 | ||||
-rw-r--r-- | sys/dev/uart/uart_dev_snps.c | 8 | ||||
-rw-r--r-- | sys/dev/usb/controller/generic_ohci.c | 6 |
13 files changed, 70 insertions, 62 deletions
diff --git a/sys/dev/dwc/if_dwc.c b/sys/dev/dwc/if_dwc.c index a34879b95b47..769fa66d9f05 100644 --- a/sys/dev/dwc/if_dwc.c +++ b/sys/dev/dwc/if_dwc.c @@ -1097,7 +1097,7 @@ dwc_clock_init(device_t dev) int error; /* Enable clock */ - if (clk_get_by_ofw_name(dev, "stmmaceth", &clk) == 0) { + if (clk_get_by_ofw_name(dev, 0, "stmmaceth", &clk) == 0) { error = clk_enable(clk); if (error != 0) { device_printf(dev, "could not enable main clock\n"); @@ -1106,7 +1106,7 @@ dwc_clock_init(device_t dev) } /* De-assert reset */ - if (hwreset_get_by_ofw_name(dev, "stmmaceth", &rst) == 0) { + if (hwreset_get_by_ofw_name(dev, 0, "stmmaceth", &rst) == 0) { error = hwreset_deassert(rst); if (error != 0) { device_printf(dev, "could not de-assert reset\n"); diff --git a/sys/dev/extres/clk/clk.c b/sys/dev/extres/clk/clk.c index 092279bddfb3..bcb0a263027e 100644 --- a/sys/dev/extres/clk/clk.c +++ b/sys/dev/extres/clk/clk.c @@ -1196,22 +1196,7 @@ clk_get_by_id(device_t dev, struct clkdom *clkdom, intptr_t id, clk_t *clk) #ifdef FDT int -clk_get_by_ofw_index(device_t dev, int idx, clk_t *clk) -{ - phandle_t cnode; - - cnode = ofw_bus_get_node(dev); - if (cnode <= 0) { - device_printf(dev, "%s called on not ofw based device\n", - __func__); - return (ENXIO); - } - - return (clk_get_by_ofw_node_index(dev, cnode, idx, clk)); -} - -int -clk_get_by_ofw_node_index(device_t dev, phandle_t cnode, int idx, clk_t *clk) +clk_get_by_ofw_index(device_t dev, phandle_t cnode, int idx, clk_t *clk) { phandle_t parent, *cells; device_t clockdev; @@ -1220,6 +1205,14 @@ clk_get_by_ofw_node_index(device_t dev, phandle_t cnode, int idx, clk_t *clk) struct clknode *clknode; *clk = NULL; + if (cnode <= 0) + cnode = ofw_bus_get_node(dev); + if (cnode <= 0) { + device_printf(dev, "%s called on not ofw based device\n", + __func__); + return (ENXIO); + } + rv = ofw_bus_parse_xref_list_alloc(cnode, "clocks", "#clock-cells", idx, &parent, &ncells, &cells); @@ -1254,12 +1247,12 @@ done: } int -clk_get_by_ofw_name(device_t dev, const char *name, clk_t *clk) +clk_get_by_ofw_name(device_t dev, phandle_t cnode, const char *name, clk_t *clk) { int rv, idx; - phandle_t cnode; - cnode = ofw_bus_get_node(dev); + if (cnode <= 0) + cnode = ofw_bus_get_node(dev); if (cnode <= 0) { device_printf(dev, "%s called on not ofw based device\n", __func__); @@ -1268,7 +1261,7 @@ clk_get_by_ofw_name(device_t dev, const char *name, clk_t *clk) rv = ofw_bus_find_string_index(cnode, "clock-names", name, &idx); if (rv != 0) return (rv); - return (clk_get_by_ofw_index(dev, idx, clk)); + return (clk_get_by_ofw_index(dev, cnode, idx, clk)); } /* -------------------------------------------------------------------------- diff --git a/sys/dev/extres/clk/clk.h b/sys/dev/extres/clk/clk.h index 55cec53fc9fd..60b8d2b77b75 100644 --- a/sys/dev/extres/clk/clk.h +++ b/sys/dev/extres/clk/clk.h @@ -129,10 +129,9 @@ int clk_set_parent_by_clk(clk_t clk, clk_t parent); const char *clk_get_name(clk_t clk); #ifdef FDT -int clk_get_by_ofw_index(device_t dev, int idx, clk_t *clk); -int clk_get_by_ofw_name(device_t dev, const char *name, clk_t *clk); -int clk_get_by_ofw_node_index(device_t dev, phandle_t node, int idx, - clk_t *clk); +int clk_get_by_ofw_index(device_t dev, phandle_t node, int idx, clk_t *clk); +int clk_get_by_ofw_name(device_t dev, phandle_t node, const char *name, + clk_t *clk); int clk_parse_ofw_out_names(device_t dev, phandle_t node, const char ***out_names, uint32_t **indices); int clk_parse_ofw_clk_name(device_t dev, phandle_t node, const char **name); diff --git a/sys/dev/extres/clk/clk_fixed.c b/sys/dev/extres/clk/clk_fixed.c index 133a38a6c014..fd20bb61e9df 100644 --- a/sys/dev/extres/clk/clk_fixed.c +++ b/sys/dev/extres/clk/clk_fixed.c @@ -195,7 +195,7 @@ clk_fixed_init_fixed_factor(struct clk_fixed_softc *sc, phandle_t node, if (rv <= 0) return (ENXIO); /* Get name of parent clock */ - rv = clk_get_by_ofw_index(sc->dev, 0, &parent); + rv = clk_get_by_ofw_index(sc->dev, 0, 0, &parent); if (rv != 0) return (ENXIO); def->clkdef.parent_names = malloc(sizeof(char *), M_OFWPROP, M_WAITOK); diff --git a/sys/dev/extres/hwreset/hwreset.c b/sys/dev/extres/hwreset/hwreset.c index 8623b60e5b23..40ee915e3aac 100644 --- a/sys/dev/extres/hwreset/hwreset.c +++ b/sys/dev/extres/hwreset/hwreset.c @@ -109,15 +109,17 @@ hwreset_default_ofw_map(device_t provider_dev, phandle_t xref, int ncells, } int -hwreset_get_by_ofw_idx(device_t consumer_dev, int idx, hwreset_t *rst) +hwreset_get_by_ofw_idx(device_t consumer_dev, phandle_t cnode, int idx, + hwreset_t *rst) { - phandle_t cnode, xnode; + phandle_t xnode; pcell_t *cells; device_t rstdev; int ncells, rv; intptr_t id; - cnode = ofw_bus_get_node(consumer_dev); + if (cnode <= 0) + cnode = ofw_bus_get_node(consumer_dev); if (cnode <= 0) { device_printf(consumer_dev, "%s called on not ofw based device\n", __func__); @@ -145,12 +147,13 @@ hwreset_get_by_ofw_idx(device_t consumer_dev, int idx, hwreset_t *rst) } int -hwreset_get_by_ofw_name(device_t consumer_dev, char *name, hwreset_t *rst) +hwreset_get_by_ofw_name(device_t consumer_dev, phandle_t cnode, char *name, + hwreset_t *rst) { int rv, idx; - phandle_t cnode; - cnode = ofw_bus_get_node(consumer_dev); + if (cnode <= 0) + cnode = ofw_bus_get_node(consumer_dev); if (cnode <= 0) { device_printf(consumer_dev, "%s called on not ofw based device\n", __func__); @@ -159,7 +162,7 @@ hwreset_get_by_ofw_name(device_t consumer_dev, char *name, hwreset_t *rst) rv = ofw_bus_find_string_index(cnode, "reset-names", name, &idx); if (rv != 0) return (rv); - return (hwreset_get_by_ofw_idx(consumer_dev, idx, rst)); + return (hwreset_get_by_ofw_idx(consumer_dev, cnode, idx, rst)); } void diff --git a/sys/dev/extres/hwreset/hwreset.h b/sys/dev/extres/hwreset/hwreset.h index 75e653a5c2ae..6366351cc4cc 100644 --- a/sys/dev/extres/hwreset/hwreset.h +++ b/sys/dev/extres/hwreset/hwreset.h @@ -58,8 +58,10 @@ int hwreset_deassert(hwreset_t rst); int hwreset_is_asserted(hwreset_t rst, bool *value); #ifdef FDT -int hwreset_get_by_ofw_name(device_t consumer_dev, char *name, hwreset_t *rst); -int hwreset_get_by_ofw_idx(device_t consumer_dev, int idx, hwreset_t *rst); +int hwreset_get_by_ofw_name(device_t consumer_dev, phandle_t node, char *name, + hwreset_t *rst); +int hwreset_get_by_ofw_idx(device_t consumer_dev, phandle_t node, int idx, + hwreset_t *rst); #endif diff --git a/sys/dev/extres/phy/phy.c b/sys/dev/extres/phy/phy.c index a4dc621d905e..dc454a2dd4dc 100644 --- a/sys/dev/extres/phy/phy.c +++ b/sys/dev/extres/phy/phy.c @@ -124,15 +124,16 @@ int phy_default_map(device_t provider, phandle_t xref, int ncells, } int -phy_get_by_ofw_idx(device_t consumer_dev, int idx, phy_t *phy) +phy_get_by_ofw_idx(device_t consumer_dev, phandle_t cnode, int idx, phy_t *phy) { - phandle_t cnode, xnode; + phandle_t xnode; pcell_t *cells; device_t phydev; int ncells, rv; intptr_t id; - cnode = ofw_bus_get_node(consumer_dev); + if (cnode <= 0) + cnode = ofw_bus_get_node(consumer_dev); if (cnode <= 0) { device_printf(consumer_dev, "%s called on not ofw based device\n", __func__); @@ -159,12 +160,13 @@ phy_get_by_ofw_idx(device_t consumer_dev, int idx, phy_t *phy) } int -phy_get_by_ofw_name(device_t consumer_dev, char *name, phy_t *phy) +phy_get_by_ofw_name(device_t consumer_dev, phandle_t cnode, char *name, + phy_t *phy) { int rv, idx; - phandle_t cnode; - cnode = ofw_bus_get_node(consumer_dev); + if (cnode <= 0) + cnode = ofw_bus_get_node(consumer_dev); if (cnode <= 0) { device_printf(consumer_dev, "%s called on not ofw based device\n", __func__); @@ -173,19 +175,20 @@ phy_get_by_ofw_name(device_t consumer_dev, char *name, phy_t *phy) rv = ofw_bus_find_string_index(cnode, "phy-names", name, &idx); if (rv != 0) return (rv); - return (phy_get_by_ofw_idx(consumer_dev, idx, phy)); + return (phy_get_by_ofw_idx(consumer_dev, cnode, idx, phy)); } int -phy_get_by_ofw_property(device_t consumer_dev, char *name, phy_t *phy) +phy_get_by_ofw_property(device_t consumer_dev, phandle_t cnode, char *name, + phy_t *phy) { - phandle_t cnode; pcell_t *cells; device_t phydev; int ncells, rv; intptr_t id; - cnode = ofw_bus_get_node(consumer_dev); + if (cnode <= 0) + cnode = ofw_bus_get_node(consumer_dev); if (cnode <= 0) { device_printf(consumer_dev, "%s called on not ofw based device\n", __func__); diff --git a/sys/dev/extres/phy/phy.h b/sys/dev/extres/phy/phy.h index 93b4fe4d83ed..2d0e3f8b8c21 100644 --- a/sys/dev/extres/phy/phy.h +++ b/sys/dev/extres/phy/phy.h @@ -50,9 +50,14 @@ void phy_unregister_provider(device_t provider); int phy_get_by_id(device_t consumer_dev, device_t provider_dev, intptr_t id, phy_t *phy); void phy_release(phy_t phy); -int phy_get_by_ofw_name(device_t consumer, char *name, phy_t *phy); -int phy_get_by_ofw_idx(device_t consumer, int idx, phy_t *phy); -int phy_get_by_ofw_property(device_t consumer, char *name, phy_t *phy); + +#ifdef FDT +int phy_get_by_ofw_name(device_t consumer, phandle_t node, char *name, + phy_t *phy); +int phy_get_by_ofw_idx(device_t consumer, phandle_t node, int idx, phy_t *phy); +int phy_get_by_ofw_property(device_t consumer, phandle_t node, char *name, + phy_t *phy); +#endif int phy_init(device_t consumer, phy_t phy); int phy_deinit(device_t consumer, phy_t phy); diff --git a/sys/dev/extres/regulator/regulator.c b/sys/dev/extres/regulator/regulator.c index 84cd8fde4548..729de6b69b10 100644 --- a/sys/dev/extres/regulator/regulator.c +++ b/sys/dev/extres/regulator/regulator.c @@ -945,16 +945,18 @@ regulator_parse_ofw_stdparam(device_t pdev, phandle_t node, } int -regulator_get_by_ofw_property(device_t cdev, char *name, regulator_t *reg) +regulator_get_by_ofw_property(device_t cdev, phandle_t cnode, char *name, + regulator_t *reg) { - phandle_t cnode, *cells; + phandle_t *cells; device_t regdev; int ncells, rv; intptr_t id; *reg = NULL; - cnode = ofw_bus_get_node(cdev); + if (cnode <= 0) + cnode = ofw_bus_get_node(cdev); if (cnode <= 0) { device_printf(cdev, "%s called on not ofw based device\n", __func__); diff --git a/sys/dev/extres/regulator/regulator.h b/sys/dev/extres/regulator/regulator.h index 380bad63f915..e509a7e74349 100644 --- a/sys/dev/extres/regulator/regulator.h +++ b/sys/dev/extres/regulator/regulator.h @@ -119,7 +119,8 @@ int regulator_get_voltage(regulator_t reg, int *uvolt); int regulator_set_voltage(regulator_t reg, int min_uvolt, int max_uvolt); #ifdef FDT -int regulator_get_by_ofw_property(device_t dev, char *name, regulator_t *reg); +int regulator_get_by_ofw_property(device_t dev, phandle_t node, char *name, + regulator_t *reg); int regulator_parse_ofw_stdparam(device_t dev, phandle_t node, struct regnode_init_def *def); #endif diff --git a/sys/dev/iicbus/twsi/a10_twsi.c b/sys/dev/iicbus/twsi/a10_twsi.c index c32e6fa6debf..b468f088531d 100644 --- a/sys/dev/iicbus/twsi/a10_twsi.c +++ b/sys/dev/iicbus/twsi/a10_twsi.c @@ -95,7 +95,7 @@ a10_twsi_attach(device_t dev) sc = device_get_softc(dev); /* De-assert reset */ - if (hwreset_get_by_ofw_idx(dev, 0, &rst) == 0) { + if (hwreset_get_by_ofw_idx(dev, 0, 0, &rst) == 0) { error = hwreset_deassert(rst); if (error != 0) { device_printf(dev, "could not de-assert reset\n"); @@ -104,7 +104,7 @@ a10_twsi_attach(device_t dev) } /* Activate clock */ - error = clk_get_by_ofw_index(dev, 0, &clk); + error = clk_get_by_ofw_index(dev, 0, 0, &clk); if (error != 0) { device_printf(dev, "could not find clock\n"); return (error); diff --git a/sys/dev/uart/uart_dev_snps.c b/sys/dev/uart/uart_dev_snps.c index af4000f693b1..c0e3d79cce8e 100644 --- a/sys/dev/uart/uart_dev_snps.c +++ b/sys/dev/uart/uart_dev_snps.c @@ -119,12 +119,12 @@ snps_get_clocks(device_t dev, clk_t *baudclk, clk_t *apb_pclk) /* Baud clock is either named "baudclk", or there is a single * unnamed clock. */ - if (clk_get_by_ofw_name(dev, "baudclk", baudclk) != 0 && - clk_get_by_ofw_index(dev, 0, baudclk) != 0) + if (clk_get_by_ofw_name(dev, 0, "baudclk", baudclk) != 0 && + clk_get_by_ofw_index(dev, 0, 0, baudclk) != 0) return (ENOENT); /* APB peripheral clock is optional */ - (void)clk_get_by_ofw_name(dev, "apb_pclk", apb_pclk); + (void)clk_get_by_ofw_name(dev, 0, "apb_pclk", apb_pclk); return (0); } @@ -163,7 +163,7 @@ snps_probe(device_t dev) clock = 0; #ifdef EXT_RESOURCES - if (hwreset_get_by_ofw_idx(dev, 0, &reset) == 0) { + if (hwreset_get_by_ofw_idx(dev, 0, 0, &reset) == 0) { error = hwreset_deassert(reset); if (error != 0) { device_printf(dev, "cannot de-assert reset\n"); diff --git a/sys/dev/usb/controller/generic_ohci.c b/sys/dev/usb/controller/generic_ohci.c index 9656c8faa1c8..beafd0614b67 100644 --- a/sys/dev/usb/controller/generic_ohci.c +++ b/sys/dev/usb/controller/generic_ohci.c @@ -161,7 +161,7 @@ generic_ohci_attach(device_t dev) #ifdef EXT_RESOURCES TAILQ_INIT(&sc->clk_list); /* Enable clock */ - for (off = 0; clk_get_by_ofw_index(dev, off, &clk) == 0; off++) { + for (off = 0; clk_get_by_ofw_index(dev, 0, off, &clk) == 0; off++) { err = clk_enable(clk); if (err != 0) { device_printf(dev, "Could not enable clock %s\n", @@ -174,7 +174,7 @@ generic_ohci_attach(device_t dev) } /* De-assert reset */ - if (hwreset_get_by_ofw_idx(dev, 0, &sc->rst) == 0) { + if (hwreset_get_by_ofw_idx(dev, 0, 0, &sc->rst) == 0) { err = hwreset_deassert(sc->rst); if (err != 0) { device_printf(dev, "Could not de-assert reset %d\n", @@ -184,7 +184,7 @@ generic_ohci_attach(device_t dev) } /* Enable phy */ - if (phy_get_by_ofw_name(dev, "usb", &sc->phy) == 0) { + if (phy_get_by_ofw_name(dev, 0, "usb", &sc->phy) == 0) { err = phy_enable(dev, sc->phy); if (err != 0) { device_printf(dev, "Could not enable phy\n"); |