Skip to contentSkip to conversation

sh-sci: Get register size from platform data

PATCH Superseded Yoshinori Sato 2 participants 3 messages May 16, 2015 – May 17, 2015

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Yoshinori Sato

author maintainer
#0 lore raw

PATCH v2 1/1 sh-sci: Get register size from platform data

There is much implement of SCI,
So the register size should be acquired from platform data.

---
 drivers/tty/serial/sh-sci.c | 34 +++++++++++++---------------------
 1 file changed, 13 insertions(+), 21 deletions(-)
drivers/tty/serial/sh-sci.c +13 -21
index 1468ec5..784650b 100644
@@ -84,7 +84,7 @@ struct sci_port {
 	int			overrun_bit;
 	unsigned int		error_mask;
 	unsigned int		sampling_rate;
-
+	unsigned int		reg_size;
 
 	/* Break timer */
 	struct timer_list	break_timer;
@@ -2073,23 +2073,9 @@ static const char *sci_type(struct uart_port *port)
 	return NULL;
 }
 
-static inline unsigned long sci_port_size(struct uart_port *port)
-{
-	/*
-	 * Pick an arbitrary size that encapsulates all of the base
-	 * registers by default. This can be optimized later, or derived
-	 * from platform resource data at such a time that ports begin to
-	 * behave more erratically.
-	 */
-	if (port->type = PORT_HSCIF)
-		return 96;
-	else
-		return 64;
-}
-
 static int sci_remap_port(struct uart_port *port)
 {
-	unsigned long size = sci_port_size(port);
+	struct sci_port *sport = to_sci_port(port);
 
 	/*
 	 * Nothing to do if there's already an established membase.
@@ -2098,7 +2084,7 @@ static int sci_remap_port(struct uart_port *port)
 		return 0;
 
 	if (port->flags & UPF_IOREMAP) {
-		port->membase = ioremap_nocache(port->mapbase, size);
+		port->membase = ioremap_nocache(port->mapbase, sport->reg_size);
 		if (unlikely(!port->membase)) {
 			dev_err(port->dev, "can't remap port#%d\n", port->line);
 			return -ENXIO;
@@ -2117,23 +2103,28 @@ static int sci_remap_port(struct uart_port *port)
 
 static void sci_release_port(struct uart_port *port)
 {
+	struct sci_port *sport = to_sci_port(port);
+
 	if (port->flags & UPF_IOREMAP) {
 		iounmap(port->membase);
 		port->membase = NULL;
 	}
 
-	release_mem_region(port->mapbase, sci_port_size(port));
+	release_mem_region(port->mapbase, sport->reg_size);
 }
 
 static int sci_request_port(struct uart_port *port)
 {
-	unsigned long size = sci_port_size(port);
 	struct resource *res;
+	struct sci_port *sport = to_sci_port(port);
 	int ret;
 
-	res = request_mem_region(port->mapbase, size, dev_name(port->dev));
-	if (unlikely(res = NULL))
+	res = request_mem_region(port->mapbase, sport->reg_size,
+				 dev_name(port->dev));
+	if (unlikely(res = NULL)) {
+		dev_err(port->dev, "request_mem_region failed.");
 		return -EBUSY;
+	}
 
 	ret = sci_remap_port(port);
 	if (unlikely(ret != 0)) {
@@ -2207,6 +2198,7 @@ static int sci_init_single(struct platform_device *dev,
 		return -ENOMEM;
 
 	port->mapbase = res->start;
+	sci_port->reg_size = res->end - res->start + 1;
 
 	for (i = 0; i < ARRAY_SIZE(sci_port->irqs); ++i)
 		sci_port->irqs[i] = platform_get_irq(dev, i);
Signature · 1 line
2.1.4
#1 lore raw

Hello.

Quoted 1 line · Yoshinori Sato

There is much implement of SCI,

Many implementations, you mean?

Quoted 1 line

So the register size should be acquired from platform data.

You're not acquiring them from the platform data, you're using platform
device resources for that.

Quoted 1 line

[...]

drivers/tty/serial/sh-sci.c static int sci_init_single(struct platform_device *dev, · line 2201

Quoted 5 lines
drivers/tty/serial/sh-sci.c +1 -0
@@ -2207,6 +2198,7 @@ static int sci_init_single(struct platform_device *dev,
  		return -ENOMEM;
 
  	port->mapbase = res->start;
+	sci_port->reg_size = res->end - res->start + 1;

Use resource_size(res) instead, please.

[...]

WBR, Sergei

author maintainer
#2 lore raw
In reply to Yoshinori Sato
Quoted 8 lines · Sergei Shtylyov

Hello.

Quoted 1 line · Yoshinori Sato

There is much implement of SCI,

Many implementations, you mean?

There is much SCI of SoC having within,
and the register size is also different in everyone.

Quoted 4 lines
Quoted 1 line

So the register size should be acquired from platform data.

You're not acquiring them from the platform data, you're using
platform device resources for that.

Yes.
platform device is correct.

Quoted 10 lines
Quoted 1 line

[...]

drivers/tty/serial/sh-sci.c static int sci_init_single(struct platform_device *dev, · line 2201

Quoted 5 lines
drivers/tty/serial/sh-sci.c +1 -0
@@ -2207,6 +2198,7 @@ static int sci_init_single(struct platform_device *dev,
  		return -ENOMEM;
 
  	port->mapbase = res->start;
+	sci_port->reg_size = res->end - res->start + 1;

Use resource_size(res) instead, please.

OK.
I'll update.

Thanks.

Quoted 4 lines

[...]

WBR, Sergei

Signature · 2 lines
Yoshinori Sato
<[email protected]>