All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] serial: fsl_lpuart: Remove the alias node dependence
@ 2016-12-14  8:33 ` Yuan Yao
  0 siblings, 0 replies; 5+ messages in thread
From: Yuan Yao @ 2016-12-14  8:33 UTC (permalink / raw)
  To: gregkh, jslaby; +Cc: linux-serial, linux-kernel, yao.yuan

From: Yuan Yao <yao.yuan@nxp.com>

Numbering the ttyLPn space should not depend on the generic name
"serial<n>".

If don't add the alias node like:"serial0 = &lpuart0;", then lpuart
will probe failed:
[    0.773410] fsl-lpuart 2950000.serial: failed to get alias id, errno -19

So remove the alias node dependence, and add the support for allocate the
line port automatically.

Signed-off-by: Yuan Yao <yao.yuan@nxp.com>
---
 drivers/tty/serial/fsl_lpuart.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c
index a1c6519..c6d639f 100644
--- a/drivers/tty/serial/fsl_lpuart.c
+++ b/drivers/tty/serial/fsl_lpuart.c
@@ -231,6 +231,8 @@
 #define DEV_NAME	"ttyLP"
 #define UART_NR		6
 
+static DECLARE_BITMAP(linemap, UART_NR);
+
 struct lpuart_port {
 	struct uart_port	port;
 	struct clk		*clk;
@@ -1963,9 +1965,13 @@ static int lpuart_probe(struct platform_device *pdev)
 
 	ret = of_alias_get_id(np, "serial");
 	if (ret < 0) {
-		dev_err(&pdev->dev, "failed to get alias id, errno %d\n", ret);
-		return ret;
+		ret = find_first_zero_bit(linemap, UART_NR);
+		if (ret >= UART_NR) {
+			dev_err(&pdev->dev, "port line is full, add device failed\n");
+			return ret;
+		}
 	}
+	set_bit(ret, linemap);
 	sport->port.line = ret;
 	sport->lpuart32 = of_device_is_compatible(np, "fsl,ls1021a-lpuart");
 
@@ -2047,6 +2053,7 @@ static int lpuart_remove(struct platform_device *pdev)
 	struct lpuart_port *sport = platform_get_drvdata(pdev);
 
 	uart_remove_one_port(&lpuart_reg, &sport->port);
+	clear_bit(sport->port.line, linemap);
 
 	clk_disable_unprepare(sport->clk);
 
-- 
2.1.0.27.g96db324

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH] serial: fsl_lpuart: Remove the alias node dependence
@ 2016-12-14  8:33 ` Yuan Yao
  0 siblings, 0 replies; 5+ messages in thread
From: Yuan Yao @ 2016-12-14  8:33 UTC (permalink / raw)
  To: gregkh, jslaby; +Cc: linux-serial, linux-kernel, yao.yuan

From: Yuan Yao <yao.yuan@nxp.com>

Numbering the ttyLPn space should not depend on the generic name
"serial<n>".

If don't add the alias node like:"serial0 = &lpuart0;", then lpuart
will probe failed:
[    0.773410] fsl-lpuart 2950000.serial: failed to get alias id, errno -19

So remove the alias node dependence, and add the support for allocate the
line port automatically.

Signed-off-by: Yuan Yao <yao.yuan@nxp.com>
---
 drivers/tty/serial/fsl_lpuart.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c
index a1c6519..c6d639f 100644
--- a/drivers/tty/serial/fsl_lpuart.c
+++ b/drivers/tty/serial/fsl_lpuart.c
@@ -231,6 +231,8 @@
 #define DEV_NAME	"ttyLP"
 #define UART_NR		6
 
+static DECLARE_BITMAP(linemap, UART_NR);
+
 struct lpuart_port {
 	struct uart_port	port;
 	struct clk		*clk;
@@ -1963,9 +1965,13 @@ static int lpuart_probe(struct platform_device *pdev)
 
 	ret = of_alias_get_id(np, "serial");
 	if (ret < 0) {
-		dev_err(&pdev->dev, "failed to get alias id, errno %d\n", ret);
-		return ret;
+		ret = find_first_zero_bit(linemap, UART_NR);
+		if (ret >= UART_NR) {
+			dev_err(&pdev->dev, "port line is full, add device failed\n");
+			return ret;
+		}
 	}
+	set_bit(ret, linemap);
 	sport->port.line = ret;
 	sport->lpuart32 = of_device_is_compatible(np, "fsl,ls1021a-lpuart");
 
@@ -2047,6 +2053,7 @@ static int lpuart_remove(struct platform_device *pdev)
 	struct lpuart_port *sport = platform_get_drvdata(pdev);
 
 	uart_remove_one_port(&lpuart_reg, &sport->port);
+	clear_bit(sport->port.line, linemap);
 
 	clk_disable_unprepare(sport->clk);
 
-- 
2.1.0.27.g96db324

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] serial: fsl_lpuart: Remove the alias node dependence
  2016-12-14  8:33 ` Yuan Yao
  (?)
@ 2017-01-11  7:24 ` Greg KH
  2017-01-12  2:27   ` Yao Yuan
  -1 siblings, 1 reply; 5+ messages in thread
From: Greg KH @ 2017-01-11  7:24 UTC (permalink / raw)
  To: Yuan Yao; +Cc: jslaby, linux-serial, linux-kernel, yao.yuan

On Wed, Dec 14, 2016 at 04:33:32PM +0800, Yuan Yao wrote:
> From: Yuan Yao <yao.yuan@nxp.com>
> 
> Numbering the ttyLPn space should not depend on the generic name
> "serial<n>".
> 
> If don't add the alias node like:"serial0 = &lpuart0;", then lpuart
> will probe failed:
> [    0.773410] fsl-lpuart 2950000.serial: failed to get alias id, errno -19
> 
> So remove the alias node dependence, and add the support for allocate the
> line port automatically.
> 
> Signed-off-by: Yuan Yao <yao.yuan@nxp.com>
> ---
>  drivers/tty/serial/fsl_lpuart.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c
> index a1c6519..c6d639f 100644
> --- a/drivers/tty/serial/fsl_lpuart.c
> +++ b/drivers/tty/serial/fsl_lpuart.c
> @@ -231,6 +231,8 @@
>  #define DEV_NAME	"ttyLP"
>  #define UART_NR		6
>  
> +static DECLARE_BITMAP(linemap, UART_NR);

Why a bitmap?

> +
>  struct lpuart_port {
>  	struct uart_port	port;
>  	struct clk		*clk;
> @@ -1963,9 +1965,13 @@ static int lpuart_probe(struct platform_device *pdev)
>  
>  	ret = of_alias_get_id(np, "serial");
>  	if (ret < 0) {
> -		dev_err(&pdev->dev, "failed to get alias id, errno %d\n", ret);
> -		return ret;
> +		ret = find_first_zero_bit(linemap, UART_NR);
> +		if (ret >= UART_NR) {
> +			dev_err(&pdev->dev, "port line is full, add device failed\n");
> +			return ret;
> +		}

Does this really remove the alias dependancy?

Please use an idr or ida for this instead of a bitmap.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [PATCH] serial: fsl_lpuart: Remove the alias node dependence
  2017-01-11  7:24 ` Greg KH
@ 2017-01-12  2:27   ` Yao Yuan
  2017-01-12  7:26     ` Greg KH
  0 siblings, 1 reply; 5+ messages in thread
From: Yao Yuan @ 2017-01-12  2:27 UTC (permalink / raw)
  To: Greg KH, Yuan Yao; +Cc: jslaby, linux-serial, linux-kernel

On Wed, Jan 11, 2016 at 04:33:32PM +0800, Greg KH wrote:
> On Wed, Dec 14, 2016 at 04:33:32PM +0800, Yuan Yao wrote:
> > From: Yuan Yao <yao.yuan@nxp.com>
> >
> > Numbering the ttyLPn space should not depend on the generic name
> > "serial<n>".
> >
> > If don't add the alias node like:"serial0 = &lpuart0;", then lpuart
> > will probe failed:
> > [    0.773410] fsl-lpuart 2950000.serial: failed to get alias id, errno -19
> >
> > So remove the alias node dependence, and add the support for allocate
> > the line port automatically.
> >
> > Signed-off-by: Yuan Yao <yao.yuan@nxp.com>
> > ---
> >  drivers/tty/serial/fsl_lpuart.c | 11 +++++++++--
> >  1 file changed, 9 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/tty/serial/fsl_lpuart.c
> > b/drivers/tty/serial/fsl_lpuart.c index a1c6519..c6d639f 100644
> > --- a/drivers/tty/serial/fsl_lpuart.c
> > +++ b/drivers/tty/serial/fsl_lpuart.c
> > @@ -231,6 +231,8 @@
> >  #define DEV_NAME	"ttyLP"
> >  #define UART_NR		6
> >
> > +static DECLARE_BITMAP(linemap, UART_NR);
> 
> Why a bitmap?

Because I think the bitmap is enough to meet the need.
Are there any shortcomings for bitmap used here?

> 
> > +
> >  struct lpuart_port {
> >  	struct uart_port	port;
> >  	struct clk		*clk;
> > @@ -1963,9 +1965,13 @@ static int lpuart_probe(struct platform_device
> > *pdev)
> >
> >  	ret = of_alias_get_id(np, "serial");
> >  	if (ret < 0) {
> > -		dev_err(&pdev->dev, "failed to get alias id, errno %d\n", ret);
> > -		return ret;
> > +		ret = find_first_zero_bit(linemap, UART_NR);
> > +		if (ret >= UART_NR) {
> > +			dev_err(&pdev->dev, "port line is full, add device
> failed\n");
> > +			return ret;
> > +		}
> 
> Does this really remove the alias dependancy?
> 
> Please use an idr or ida for this instead of a bitmap.
> 

Hi Greg,

Thanks for your review.

Is there any advantage for use an idr or ida instead of bitmap?
I will hope to get your guidance.

Thanks.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] serial: fsl_lpuart: Remove the alias node dependence
  2017-01-12  2:27   ` Yao Yuan
@ 2017-01-12  7:26     ` Greg KH
  0 siblings, 0 replies; 5+ messages in thread
From: Greg KH @ 2017-01-12  7:26 UTC (permalink / raw)
  To: Yao Yuan; +Cc: Yuan Yao, jslaby, linux-serial, linux-kernel

On Thu, Jan 12, 2017 at 02:27:45AM +0000, Yao Yuan wrote:
> On Wed, Jan 11, 2016 at 04:33:32PM +0800, Greg KH wrote:
> > On Wed, Dec 14, 2016 at 04:33:32PM +0800, Yuan Yao wrote:
> > > From: Yuan Yao <yao.yuan@nxp.com>
> > >
> > > Numbering the ttyLPn space should not depend on the generic name
> > > "serial<n>".
> > >
> > > If don't add the alias node like:"serial0 = &lpuart0;", then lpuart
> > > will probe failed:
> > > [    0.773410] fsl-lpuart 2950000.serial: failed to get alias id, errno -19
> > >
> > > So remove the alias node dependence, and add the support for allocate
> > > the line port automatically.
> > >
> > > Signed-off-by: Yuan Yao <yao.yuan@nxp.com>
> > > ---
> > >  drivers/tty/serial/fsl_lpuart.c | 11 +++++++++--
> > >  1 file changed, 9 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/drivers/tty/serial/fsl_lpuart.c
> > > b/drivers/tty/serial/fsl_lpuart.c index a1c6519..c6d639f 100644
> > > --- a/drivers/tty/serial/fsl_lpuart.c
> > > +++ b/drivers/tty/serial/fsl_lpuart.c
> > > @@ -231,6 +231,8 @@
> > >  #define DEV_NAME	"ttyLP"
> > >  #define UART_NR		6
> > >
> > > +static DECLARE_BITMAP(linemap, UART_NR);
> > 
> > Why a bitmap?
> 
> Because I think the bitmap is enough to meet the need.
> Are there any shortcomings for bitmap used here?
> 
> > 
> > > +
> > >  struct lpuart_port {
> > >  	struct uart_port	port;
> > >  	struct clk		*clk;
> > > @@ -1963,9 +1965,13 @@ static int lpuart_probe(struct platform_device
> > > *pdev)
> > >
> > >  	ret = of_alias_get_id(np, "serial");
> > >  	if (ret < 0) {
> > > -		dev_err(&pdev->dev, "failed to get alias id, errno %d\n", ret);
> > > -		return ret;
> > > +		ret = find_first_zero_bit(linemap, UART_NR);
> > > +		if (ret >= UART_NR) {
> > > +			dev_err(&pdev->dev, "port line is full, add device
> > failed\n");
> > > +			return ret;
> > > +		}
> > 
> > Does this really remove the alias dependancy?
> > 
> > Please use an idr or ida for this instead of a bitmap.
> > 
> 
> Hi Greg,
> 
> Thanks for your review.
> 
> Is there any advantage for use an idr or ida instead of bitmap?

Yes, it makes it so that we don't have to hand-audit your code for
proper use of a bitmap.  Using an idr is easy, and is obvious when you
do it correctly.  That's why using common apis is good for everyone, you
want someone else to be able to review your code.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-01-12  7:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-14  8:33 [PATCH] serial: fsl_lpuart: Remove the alias node dependence Yuan Yao
2016-12-14  8:33 ` Yuan Yao
2017-01-11  7:24 ` Greg KH
2017-01-12  2:27   ` Yao Yuan
2017-01-12  7:26     ` Greg KH

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.