From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jason Hui Subject: Re: [PATCH V2 3/3] serial/imx: parse from device tree support Date: Tue, 8 Mar 2011 10:56:33 +0800 Message-ID: References: <1299503160-9910-1-git-send-email-jason.hui@linaro.org> <1299503160-9910-4-git-send-email-jason.hui@linaro.org> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Return-path: In-Reply-To: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: devicetree-discuss-bounces+gldd-devicetree-discuss=m.gmane.org-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org Sender: devicetree-discuss-bounces+gldd-devicetree-discuss=m.gmane.org-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org To: Grant Likely Cc: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org, linaro-dev-cunTk1MwBs8s++Sfvej+rw@public.gmane.org, patches-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org List-Id: devicetree@vger.kernel.org Hi, Grant, On Tue, Mar 8, 2011 at 12:22 AM, Grant Likely w= rote: > On Mon, Mar 7, 2011 at 6:06 AM, Jason Liu wrote: >> Signed-off-by: Jason Liu >> Signed-off-by: Jeremy Kerr > > Hi Jason, > > comments below. > >> --- >> =A0drivers/tty/serial/imx.c | =A0 79 +++++++++++++++++++++++++++++++++++= +++++------ >> =A01 files changed, 69 insertions(+), 10 deletions(-) >> >> diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c >> index dfcf4b1..1ebca28 100644 >> --- a/drivers/tty/serial/imx.c >> +++ b/drivers/tty/serial/imx.c >> @@ -53,6 +53,9 @@ >> =A0#include >> =A0#include >> >> +#include >> +#include >> + >> =A0/* Register definitions */ >> =A0#define URXD0 0x0 =A0/* Receiver Register */ >> =A0#define URTX0 0x40 /* Transmitter Register */ >> @@ -1224,6 +1227,53 @@ static int serial_imx_resume(struct platform_devi= ce *dev) >> =A0 =A0 =A0 =A0return 0; >> =A0} >> >> +#ifdef CONFIG_OF >> +static int serial_imx_probe_dt(struct imx_port *sport, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 struct platform_device *pdev) >> +{ >> + =A0 =A0 =A0 struct device_node *node =3D pdev->dev.of_node; >> + =A0 =A0 =A0 static int line; >> + >> + =A0 =A0 =A0 if (!node) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return -ENODEV; >> + >> + =A0 =A0 =A0 if (of_get_property(node, "rts-cts", NULL)) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 sport->have_rtscts =3D 1; >> + >> + =A0 =A0 =A0 if (of_get_property(node, "irda", NULL)) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 sport->use_irda =3D 1; > > These properties need to be documented in > Documentation/devicetree/bindings/serial. =A0Also, for device specific > properties, it is considered good practice to prefix the property name > with the vendor name; so "fsl,rts-cts" and "fsl,irda". =A0Also, slightly > more descriptive property names would probably be helpful: > "fsl,has-rts-cts" and "fsl,irda-mode" OK, > >> + >> + =A0 =A0 =A0 sport->port.line =3D line++; >> + >> + =A0 =A0 =A0 return 0; >> +} >> +#else >> +static int serial_imx_probe_dt(struct imx_port *sport, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 struct platform_device *pdev) >> +{ >> + =A0 =A0 =A0 return -ENODEV; >> +} >> +#endif >> + >> +static int serial_imx_probe_pdata(struct imx_port *sport, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 struct platform_device *pdev) >> +{ >> + =A0 =A0 =A0 struct imxuart_platform_data *pdata =3D pdev->dev.platform= _data; >> + >> + =A0 =A0 =A0 if (!pdata) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return 0; >> + >> + =A0 =A0 =A0 if (pdata->flags & IMXUART_HAVE_RTSCTS) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 sport->have_rtscts =3D 1; >> + >> +#ifdef CONFIG_IRDA >> + =A0 =A0 =A0 if (pdata->flags & IMXUART_IRDA) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 sport->use_irda =3D 1; >> +#endif >> + =A0 =A0 =A0 sport->port.line =3D pdev->id; >> + >> + =A0 =A0 =A0 return 0; >> +} >> =A0static int serial_imx_probe(struct platform_device *pdev) >> =A0{ >> =A0 =A0 =A0 =A0struct imx_port *sport; >> @@ -1236,6 +1286,12 @@ static int serial_imx_probe(struct platform_devic= e *pdev) >> =A0 =A0 =A0 =A0if (!sport) >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return -ENOMEM; >> >> + =A0 =A0 =A0 ret =3D serial_imx_probe_dt(sport, pdev); >> + =A0 =A0 =A0 if (ret =3D=3D -ENODEV) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D serial_imx_probe_pdata(sport, pdev= ); >> + =A0 =A0 =A0 if (ret) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto free; >> + >> =A0 =A0 =A0 =A0res =3D platform_get_resource(pdev, IORESOURCE_MEM, 0); >> =A0 =A0 =A0 =A0if (!res) { >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0ret =3D -ENODEV; >> @@ -1260,7 +1316,6 @@ static int serial_imx_probe(struct platform_device= *pdev) >> =A0 =A0 =A0 =A0sport->port.fifosize =3D 32; >> =A0 =A0 =A0 =A0sport->port.ops =3D &imx_pops; >> =A0 =A0 =A0 =A0sport->port.flags =3D UPF_BOOT_AUTOCONF; >> - =A0 =A0 =A0 sport->port.line =3D pdev->id; >> =A0 =A0 =A0 =A0init_timer(&sport->timer); >> =A0 =A0 =A0 =A0sport->timer.function =3D imx_timeout; >> =A0 =A0 =A0 =A0sport->timer.data =A0 =A0 =3D (unsigned long)sport; >> @@ -1274,17 +1329,13 @@ static int serial_imx_probe(struct platform_devi= ce *pdev) >> >> =A0 =A0 =A0 =A0sport->port.uartclk =3D clk_get_rate(sport->clk); >> >> - =A0 =A0 =A0 imx_ports[pdev->id] =3D sport; >> + =A0 =A0 =A0 if (imx_ports[sport->port.line]) { >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D -EBUSY; >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto clkput; >> + =A0 =A0 =A0 } >> + =A0 =A0 =A0 imx_ports[sport->port.line] =3D sport; >> >> =A0 =A0 =A0 =A0pdata =3D pdev->dev.platform_data; >> - =A0 =A0 =A0 if (pdata && (pdata->flags & IMXUART_HAVE_RTSCTS)) >> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 sport->have_rtscts =3D 1; >> - >> -#ifdef CONFIG_IRDA >> - =A0 =A0 =A0 if (pdata && (pdata->flags & IMXUART_IRDA)) >> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 sport->use_irda =3D 1; >> -#endif >> - >> =A0 =A0 =A0 =A0if (pdata && pdata->init) { >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0ret =3D pdata->init(pdev); >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (ret) >> @@ -1336,6 +1387,11 @@ static int serial_imx_remove(struct platform_devi= ce *pdev) >> =A0 =A0 =A0 =A0return 0; >> =A0} >> >> +static struct of_device_id imx_uart_matches[] =3D { >> + =A0 =A0 =A0 { .compatible =3D "imx-uart" }, > > Should be "fsl,imx51-uart". =A0It is always a good idea to specify the ex= act part. OK, > >> + =A0 =A0 =A0 {}, >> +}; >> + >> =A0static struct platform_driver serial_imx_driver =3D { >> =A0 =A0 =A0 =A0.probe =A0 =A0 =A0 =A0 =A0=3D serial_imx_probe, >> =A0 =A0 =A0 =A0.remove =A0 =A0 =A0 =A0 =3D serial_imx_remove, >> @@ -1345,6 +1401,9 @@ static struct platform_driver serial_imx_driver = =3D { >> =A0 =A0 =A0 =A0.driver =A0 =A0 =A0 =A0 =3D { >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0.name =A0 =3D "imx-uart", >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0.owner =A0=3D THIS_MODULE, >> +#if defined(CONFIG_OF) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 .of_match_table =3D imx_uart_matches, >> +#endif >> =A0 =A0 =A0 =A0}, >> =A0}; >> >> -- >> 1.7.0.4 >> >> > > > > -- > Grant Likely, B.Sc., P.Eng. > Secret Lab Technologies Ltd. >