Introduce bb_miiphy_alloc()/bb_miiphy_free() wrappers to allocate and free struct bb_miiphy_bus. Make struct bb_miiphy_bus wrap struct mii_dev, which will become useful later in bb_miiphy_bus accessors, which would be able to access struct bb_miiphy_bus using container_of, even if the PHY stack only passes in the inner struct mii_dev .
Reviewed-by: Paul Barker <paul.barker...@bp.renesas.com> Signed-off-by: Marek Vasut <marek.vasut+rene...@mailbox.org> --- Cc: Christian Marangi <ansuels...@gmail.com> Cc: Ilias Apalodimas <ilias.apalodi...@linaro.org> Cc: Jerome Forissier <jerome.foriss...@linaro.org> Cc: Jim Liu <jjl...@nuvoton.com> Cc: Joe Hershberger <joe.hershber...@ni.com> Cc: Mario Six <mario....@gdsys.cc> Cc: Michal Simek <michal.si...@amd.com> Cc: Nobuhiro Iwamatsu <iwama...@nigauri.org> Cc: Paul Barker <paul.barker...@bp.renesas.com> Cc: Ramon Fried <rfried....@gmail.com> Cc: Simon Glass <s...@chromium.org> Cc: Sughosh Ganu <sughosh.g...@linaro.org> Cc: Tom Rini <tr...@konsulko.com> Cc: u-boot@lists.denx.de --- V2: Update commit message, fix duplicate _free() V3: Add RB from Paul --- drivers/net/phy/miiphybb.c | 19 +++++++++++++++++++ include/miiphy.h | 4 ++++ 2 files changed, 23 insertions(+) diff --git a/drivers/net/phy/miiphybb.c b/drivers/net/phy/miiphybb.c index 75d9537b355..66d98d6cc26 100644 --- a/drivers/net/phy/miiphybb.c +++ b/drivers/net/phy/miiphybb.c @@ -14,6 +14,7 @@ #include <ioports.h> #include <ppc_asm.tmpl> +#include <malloc.h> #include <miiphy.h> #include <asm/global_data.h> @@ -30,6 +31,24 @@ static inline struct bb_miiphy_bus *bb_miiphy_getbus(const char *devname) return NULL; } +struct bb_miiphy_bus *bb_miiphy_alloc(void) +{ + struct bb_miiphy_bus *bus; + + bus = malloc(sizeof(*bus)); + if (!bus) + return bus; + + mdio_init(&bus->mii); + + return bus; +} + +void bb_miiphy_free(struct bb_miiphy_bus *bus) +{ + free(bus); +} + /***************************************************************************** * * Utility to send the preamble, address, and register (common to read diff --git a/include/miiphy.h b/include/miiphy.h index 40eb14669b8..42300ee5386 100644 --- a/include/miiphy.h +++ b/include/miiphy.h @@ -73,11 +73,15 @@ struct bb_miiphy_bus { int (*set_mdc)(struct bb_miiphy_bus *bus, int v); int (*delay)(struct bb_miiphy_bus *bus); void *priv; + struct mii_dev mii; }; extern struct bb_miiphy_bus bb_miiphy_buses[]; extern int bb_miiphy_buses_num; +struct bb_miiphy_bus *bb_miiphy_alloc(void); +void bb_miiphy_free(struct bb_miiphy_bus *bus); + int bb_miiphy_read(struct mii_dev *miidev, int addr, int devad, int reg); int bb_miiphy_write(struct mii_dev *miidev, int addr, int devad, int reg, u16 value); -- 2.47.2