Skip to contentSkip to conversation

serial/imx: only parse for iomem resources once

PATCH New Jeremy Kerr 3 participants 4 messages Apr 21, 2010 – May 5, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 serial/imx: only parse for iomem resources once

Currently, the iomem resources are parsed in serial_imx_probe, then again in imx_request_port and imx_release_port.

This change uses the imx_port data to retrieve the start and size of the memory region, rather than re-parsing the resources through platform_get_resource.

---
 drivers/serial/imx.c |   18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)
drivers/serial/imx.c +6 -12
index e579d7a..7de6bf7 100644
@@ -192,6 +192,7 @@ struct imx_port {
 	unsigned int		irda_inv_tx:1;
 	unsigned short		trcv_delay; /* transceiver delay */
 	struct clk		*clk;
+	unsigned long		mapsize;
 };
 
 #ifdef CONFIG_IRDA
@@ -945,11 +946,8 @@ static const char *imx_type(struct uart_port *port)
  */
 static void imx_release_port(struct uart_port *port)
 {
-	struct platform_device *pdev = to_platform_device(port->dev);
-	struct resource *mmres;
-
-	mmres = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	release_mem_region(mmres->start, mmres->end - mmres->start + 1);
+	struct imx_port *imx_port = container_of(port, struct imx_port, port);
+	release_mem_region(imx_port->port.mapbase, imx_port->mapsize);
 }
 
 /*
@@ -957,15 +955,10 @@ static void imx_release_port(struct uart_port *port)
  */
 static int imx_request_port(struct uart_port *port)
 {
-	struct platform_device *pdev = to_platform_device(port->dev);
-	struct resource *mmres;
+	struct imx_port *imx_port = container_of(port, struct imx_port, port);
 	void *ret;
 
-	mmres = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!mmres)
-		return -ENODEV;
-
-	ret = request_mem_region(mmres->start, mmres->end - mmres->start + 1,
+	ret = request_mem_region(imx_port->port.mapbase, imx_port->mapsize,
 			"imx-uart");
 
 	return  ret ? 0 : -EBUSY;
@@ -1245,6 +1238,7 @@ static int serial_imx_probe(struct platform_device *pdev)
 	sport->port.dev = &pdev->dev;
 	sport->port.mapbase = res->start;
 	sport->port.membase = base;
+	sport->mapsize = res->end - res->start + 1;
 	sport->port.type = PORT_IMX,
 	sport->port.iotype = UPIO_MEM;
 	sport->port.irq = platform_get_irq(pdev, 0);
#1 lore raw

PATCH 1/1 serial/imx: only parse for iomem resources once

Quoted 8 lines · Jeremy Kerr

Currently, the iomem resources are parsed in serial_imx_probe, then again in imx_request_port and imx_release_port.

This change uses the imx_port data to retrieve the start and size of the memory region, rather than re-parsing the resources through platform_get_resource.

What are the effects for this regarding run time? How often are request_port and release_port called? I wonder if it's worth to save the value. Or what else than run time is your concern?

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-K?nig            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
#2 lore raw

PATCH 1/1 serial/imx: only parse for iomem resources once

Hi Uwe,

Quoted 3 lines

What are the effects for this regarding run time? How often are request_port and release_port called? I wonder if it's worth to save the value. Or what else than run time is your concern?

I'm not too concerned with the reduction in run time here - I'd like to be able to parse the UART config from the device tree, rather than using platform_get_{irq,resource}.

With this patch, all of the existing parsing is done in serial_imx_probe(). This means we can just abstract the parsing once, rather than having to check what parsing method (platform or devtree) we're using in request_port and release_port as well.

See serial_imx_probe_pdata and serial_imx_probe_dt in:

http://kernel.ubuntu.com/git?p=jk/dt/linux-2.6.git;a=blob;f=drivers/serial/imx.c;h=a54f6464d35920a81fdcc9fd93de3283260ab839;hb=2610717ecacfba0db34ad5b28ed6379560108912

for my intended (work-in-progress) approach.

Cheers,

Jeremy

#3 lore raw

PATCH 1/1 serial/imx: only parse for iomem resources once

In reply to Jeremy Kerr

Hello.

Quoted 18 lines · Jeremy Kerr

Currently, the iomem resources are parsed in serial_imx_probe, then again in imx_request_port and imx_release_port.

This change uses the imx_port data to retrieve the start and size of the memory region, rather than re-parsing the resources through platform_get_resource.

---
 drivers/serial/imx.c |   18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)
drivers/serial/imx.c +0 -0
index e579d7a..7de6bf7 100644

[...]

drivers/serial/imx.c static int serial_imx_probe(struct platform_device *pdev) · line 1242

Quoted 6 lines
drivers/serial/imx.c +1 -0
@@ -1245,6 +1238,7 @@ static int serial_imx_probe(struct platform_device *pdev)
 	sport->port.dev = &pdev->dev;
 	sport->port.mapbase = res->start;
 	sport->port.membase = base;
+	sport->mapsize = res->end - res->start + 1;
 

There's resource_size() for this calculation.

WBR, Sergei