diff mbox series

gpio: mxc_gpio: Improve to use ofdata_to_platdata

Message ID 1591759791-16145-3-git-send-email-ye.li@nxp.com
State Accepted
Commit 6103e570cdd0d0e854b071ee17b14589356a82bd
Headers show
Series gpio: mxc_gpio: Improve to use ofdata_to_platdata | expand

Commit Message

Ye Li June 10, 2020, 3:29 a.m. UTC
Current mxc_gpio DM driver allocates the platdata in bind function to
handle both OF_CONTROL enabled case and disabled case. This implementation
puts the devfdt_get_addr in bind, which introduces much overhead especially
in board_f phase.

Change the driver to a common way for handling the cases by using
ofdata_to_platdata and using DM framework to allocate platdata.

Signed-off-by: Ye Li <ye.li at nxp.com>
Reviewed-by: Peng Fan <peng.fan at nxp.com>
---
 drivers/gpio/mxc_gpio.c | 36 +++++++++---------------------------
 1 file changed, 9 insertions(+), 27 deletions(-)
diff mbox series

Patch

diff --git a/drivers/gpio/mxc_gpio.c b/drivers/gpio/mxc_gpio.c
index c924e52..a851893 100644
--- a/drivers/gpio/mxc_gpio.c
+++ b/drivers/gpio/mxc_gpio.c
@@ -292,46 +292,26 @@  static int mxc_gpio_probe(struct udevice *dev)
 	return 0;
 }
 
-static int mxc_gpio_bind(struct udevice *dev)
+static int mxc_gpio_ofdata_to_platdata(struct udevice *dev)
 {
-	struct mxc_gpio_plat *plat = dev->platdata;
 	fdt_addr_t addr;
-
-	/*
-	 * If platdata already exsits, directly return.
-	 * Actually only when DT is not supported, platdata
-	 * is statically initialized in U_BOOT_DEVICES.Here
-	 * will return.
-	 */
-	if (plat)
-		return 0;
+	struct mxc_gpio_plat *plat = dev_get_platdata(dev);
 
 	addr = devfdt_get_addr(dev);
 	if (addr == FDT_ADDR_T_NONE)
 		return -EINVAL;
 
-	/*
-	 * TODO:
-	 * When every board is converted to driver model and DT is supported,
-	 * this can be done by auto-alloc feature, but not using calloc
-	 * to alloc memory for platdata.
-	 *
-	 * For example mxc_plat below uses platform data rather than device
-	 * tree.
-	 *
-	 * NOTE: DO NOT COPY this code if you are using device tree.
-	 */
-	plat = calloc(1, sizeof(*plat));
-	if (!plat)
-		return -ENOMEM;
-
 	plat->regs = (struct gpio_regs *)addr;
 	plat->bank_index = dev->req_seq;
-	dev->platdata = plat;
 
 	return 0;
 }
 
+static int mxc_gpio_bind(struct udevice *dev)
+{
+	return 0;
+}
+
 static const struct udevice_id mxc_gpio_ids[] = {
 	{ .compatible = "fsl,imx35-gpio" },
 	{ }
@@ -342,6 +322,8 @@  U_BOOT_DRIVER(gpio_mxc) = {
 	.id	= UCLASS_GPIO,
 	.ops	= &gpio_mxc_ops,
 	.probe	= mxc_gpio_probe,
+	.ofdata_to_platdata = mxc_gpio_ofdata_to_platdata,
+	.platdata_auto_alloc_size = sizeof(struct mxc_gpio_plat),
 	.priv_auto_alloc_size = sizeof(struct mxc_bank_info),
 	.of_match = mxc_gpio_ids,
 	.bind	= mxc_gpio_bind,