* [PATCH 2/4] ARM: clps711x: Remove the special name for the syscon driver
2014-01-23 17:22 [PATCH 1/4] mfd: syscon: Introduce syscon_base_lookup_by_phandle() function Alexander Shiyan
@ 2014-01-23 17:22 ` Alexander Shiyan
2014-01-23 17:22 ` [PATCH 3/4] gpio: clps711x: Update driver Alexander Shiyan
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Alexander Shiyan @ 2014-01-23 17:22 UTC (permalink / raw)
To: barebox
No reason to make SYSCON driver name unique to that processor.
Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
---
arch/arm/mach-clps711x/devices.c | 6 +++---
drivers/mfd/syscon.c | 3 ---
drivers/serial/serial_clps711x.c | 4 ++--
3 files changed, 5 insertions(+), 8 deletions(-)
diff --git a/arch/arm/mach-clps711x/devices.c b/arch/arm/mach-clps711x/devices.c
index 9eeff5c..b5060ba 100644
--- a/arch/arm/mach-clps711x/devices.c
+++ b/arch/arm/mach-clps711x/devices.c
@@ -121,13 +121,13 @@ coredevice_initcall(clps711x_gpio_init);
static __init int clps711x_syscon_init(void)
{
/* SYSCON1, SYSFLG1 */
- add_generic_device("clps711x-syscon", 1, NULL, SYSCON1, SZ_128,
+ add_generic_device("syscon", 1, NULL, SYSCON1, SZ_128,
IORESOURCE_MEM, NULL);
/* SYSCON2, SYSFLG2 */
- add_generic_device("clps711x-syscon", 2, NULL, SYSCON2, SZ_128,
+ add_generic_device("syscon", 2, NULL, SYSCON2, SZ_128,
IORESOURCE_MEM, NULL);
/* SYSCON3 */
- add_generic_device("clps711x-syscon", 3, NULL, SYSCON3, SZ_64,
+ add_generic_device("syscon", 3, NULL, SYSCON3, SZ_64,
IORESOURCE_MEM, NULL);
return 0;
diff --git a/drivers/mfd/syscon.c b/drivers/mfd/syscon.c
index 6437344..8fc84c3 100644
--- a/drivers/mfd/syscon.c
+++ b/drivers/mfd/syscon.c
@@ -92,9 +92,6 @@ static int syscon_probe(struct device_d *dev)
static struct platform_device_id syscon_ids[] = {
{ "syscon", },
-#ifdef CONFIG_ARCH_CLPS711X
- { "clps711x-syscon", },
-#endif
{ }
};
diff --git a/drivers/serial/serial_clps711x.c b/drivers/serial/serial_clps711x.c
index e43d141..d8dec57 100644
--- a/drivers/serial/serial_clps711x.c
+++ b/drivers/serial/serial_clps711x.c
@@ -110,7 +110,7 @@ static void clps711x_flush(struct console_device *cdev)
static int clps711x_probe(struct device_d *dev)
{
struct clps711x_uart *s;
- char syscon_dev[18];
+ char syscon_dev[8];
BUG_ON(dev->num_resources != 2);
BUG_ON((dev->id != 0) && (dev->id != 1));
@@ -122,7 +122,7 @@ static int clps711x_probe(struct device_d *dev)
s->UBRLCR = dev_get_mem_region(dev, 0);
s->UARTDR = dev_get_mem_region(dev, 1);
- sprintf(syscon_dev, "clps711x-syscon%i", dev->id + 1);
+ sprintf(syscon_dev, "syscon%i", dev->id + 1);
s->syscon = syscon_base_lookup_by_pdevname(syscon_dev);
BUG_ON(IS_ERR(s->syscon));
--
1.8.3.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 3/4] gpio: clps711x: Update driver
2014-01-23 17:22 [PATCH 1/4] mfd: syscon: Introduce syscon_base_lookup_by_phandle() function Alexander Shiyan
2014-01-23 17:22 ` [PATCH 2/4] ARM: clps711x: Remove the special name for the syscon driver Alexander Shiyan
@ 2014-01-23 17:22 ` Alexander Shiyan
2014-01-23 17:22 ` [PATCH 4/4] serial: " Alexander Shiyan
2014-01-24 22:10 ` [PATCH 1/4] mfd: syscon: Introduce syscon_base_lookup_by_phandle() function Sascha Hauer
3 siblings, 0 replies; 5+ messages in thread
From: Alexander Shiyan @ 2014-01-23 17:22 UTC (permalink / raw)
To: barebox
This patch updates the CLPS711X GPIO driver.
The update adds support for use with devicetree and
optimizes "probe" a bit.
Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
---
drivers/gpio/gpio-clps711x.c | 39 +++++++++++++++++++++++++--------------
1 file changed, 25 insertions(+), 14 deletions(-)
diff --git a/drivers/gpio/gpio-clps711x.c b/drivers/gpio/gpio-clps711x.c
index feead51..2f12439 100644
--- a/drivers/gpio/gpio-clps711x.c
+++ b/drivers/gpio/gpio-clps711x.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 Alexander Shiyan <shc_work@mail.ru>
+ * Copyright (C) 2013-2014 Alexander Shiyan <shc_work@mail.ru>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -15,15 +15,18 @@
static int clps711x_gpio_probe(struct device_d *dev)
{
- int err;
+ int err, id = dev->id;
void __iomem *dat, *dir = NULL, *dir_inv = NULL;
struct bgpio_chip *bgc;
- if ((dev->id < 0) || (dev->id > 4))
+ if (dev->device_node)
+ id = of_alias_get_id(dev->device_node, "gpio");
+
+ if (id < 0 || id > 4)
return -ENODEV;
dat = dev_request_mem_region(dev, 0);
- switch (dev->id) {
+ switch (id) {
case 3:
dir_inv = dev_request_mem_region(dev, 1);
break;
@@ -40,27 +43,35 @@ static int clps711x_gpio_probe(struct device_d *dev)
return -ENOMEM;
err = bgpio_init(bgc, dev, 1, dat, NULL, NULL, dir, dir_inv, 0);
- if (err) {
- free(bgc);
- return err;
- }
+ if (err)
+ goto out_err;
- bgc->gc.base = dev->id * 8;
- switch (dev->id) {
+ bgc->gc.base = id * 8;
+ switch (id) {
case 4:
bgc->gc.ngpio = 3;
break;
default:
- bgc->gc.ngpio = 8;
break;
}
- return gpiochip_add(&bgc->gc);
+ err = gpiochip_add(&bgc->gc);
+
+out_err:
+ if (err)
+ free(bgc);
+
+ return err;
}
+static struct of_device_id __maybe_unused clps711x_gpio_dt_ids[] = {
+ { .compatible = "cirrus,clps711x-gpio", },
+};
+
static struct driver_d clps711x_gpio_driver = {
- .name = "clps711x-gpio",
- .probe = clps711x_gpio_probe,
+ .name = "clps711x-gpio",
+ .probe = clps711x_gpio_probe,
+ .of_compatible = DRV_OF_COMPAT(clps711x_gpio_dt_ids),
};
static __init int clps711x_gpio_register(void)
--
1.8.3.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 4/4] serial: clps711x: Update driver
2014-01-23 17:22 [PATCH 1/4] mfd: syscon: Introduce syscon_base_lookup_by_phandle() function Alexander Shiyan
2014-01-23 17:22 ` [PATCH 2/4] ARM: clps711x: Remove the special name for the syscon driver Alexander Shiyan
2014-01-23 17:22 ` [PATCH 3/4] gpio: clps711x: Update driver Alexander Shiyan
@ 2014-01-23 17:22 ` Alexander Shiyan
2014-01-24 22:10 ` [PATCH 1/4] mfd: syscon: Introduce syscon_base_lookup_by_phandle() function Sascha Hauer
3 siblings, 0 replies; 5+ messages in thread
From: Alexander Shiyan @ 2014-01-23 17:22 UTC (permalink / raw)
To: barebox
This patch updates the CLPS711X UART driver.
The update adds support for use with devicetree and
makes driver comatible with current driver from kernel.
Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
---
arch/arm/mach-clps711x/devices.c | 14 ++---
drivers/serial/serial_clps711x.c | 118 +++++++++++++++++++++++++++------------
2 files changed, 88 insertions(+), 44 deletions(-)
diff --git a/arch/arm/mach-clps711x/devices.c b/arch/arm/mach-clps711x/devices.c
index b5060ba..c7a2fbd 100644
--- a/arch/arm/mach-clps711x/devices.c
+++ b/arch/arm/mach-clps711x/devices.c
@@ -51,26 +51,24 @@ void clps711x_setup_memcfg(int bank, u32 val)
}
static struct resource uart0_resources[] = {
- DEFINE_RES_MEM(UBRLCR1, SZ_4),
- DEFINE_RES_MEM(UARTDR1, SZ_4),
+ DEFINE_RES_MEM(UARTDR1, SZ_128),
};
static struct resource uart1_resources[] = {
- DEFINE_RES_MEM(UBRLCR2, SZ_4),
- DEFINE_RES_MEM(UARTDR2, SZ_4),
+ DEFINE_RES_MEM(UARTDR2, SZ_128),
};
void clps711x_add_uart(unsigned int id)
{
switch (id) {
case 0:
- clk_add_alias(NULL, "clps711x_serial0", "uart", NULL);
- add_generic_device_res("clps711x_serial", 0, uart0_resources,
+ clk_add_alias(NULL, "clps711x-uart0", "uart", NULL);
+ add_generic_device_res("clps711x-uart", 0, uart0_resources,
ARRAY_SIZE(uart0_resources), NULL);
break;
case 1:
- clk_add_alias(NULL, "clps711x_serial1", "uart", NULL);
- add_generic_device_res("clps711x_serial", 1, uart1_resources,
+ clk_add_alias(NULL, "clps711x-uart1", "uart", NULL);
+ add_generic_device_res("clps711x-uart", 1, uart1_resources,
ARRAY_SIZE(uart1_resources), NULL);
break;
}
diff --git a/drivers/serial/serial_clps711x.c b/drivers/serial/serial_clps711x.c
index d8dec57..a75547c 100644
--- a/drivers/serial/serial_clps711x.c
+++ b/drivers/serial/serial_clps711x.c
@@ -1,7 +1,7 @@
/*
* Simple CLPS711X serial driver
*
- * (C) Copyright 2012 Alexander Shiyan <shc_work@mail.ru>
+ * (C) Copyright 2012-2014 Alexander Shiyan <shc_work@mail.ru>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -17,19 +17,37 @@
#include <linux/err.h>
#include <mfd/syscon.h>
-#include <mach/clps711x.h>
+#define UARTDR 0x00
+# define UARTDR_FRMERR (1 << 8)
+# define UARTDR_PARERR (1 << 9)
+# define UARTDR_OVERR (1 << 10)
+#define UBRLCR 0x40
+# define UBRLCR_BAUD_MASK ((1 << 12) - 1)
+# define UBRLCR_BREAK (1 << 12)
+# define UBRLCR_PRTEN (1 << 13)
+# define UBRLCR_EVENPRT (1 << 14)
+# define UBRLCR_XSTOP (1 << 15)
+# define UBRLCR_FIFOEN (1 << 16)
+# define UBRLCR_WRDLEN5 (0 << 17)
+# define UBRLCR_WRDLEN6 (1 << 17)
+# define UBRLCR_WRDLEN7 (2 << 17)
+# define UBRLCR_WRDLEN8 (3 << 17)
+# define UBRLCR_WRDLEN_MASK (3 << 17)
+
+#define SYSCON 0x00
+# define SYSCON_UARTEN (1 << 8)
+#define SYSFLG 0x40
+# define SYSFLG_UBUSY (1 << 11)
+# define SYSFLG_URXFE (1 << 22)
+# define SYSFLG_UTXFF (1 << 23)
struct clps711x_uart {
- void __iomem *UBRLCR;
- void __iomem *UARTDR;
+ void __iomem *base;
void __iomem *syscon;
struct clk *uart_clk;
struct console_device cdev;
};
-#define SYSCON(x) ((x)->syscon + 0x00)
-#define SYSFLG(x) ((x)->syscon + 0x40)
-
static int clps711x_setbaudrate(struct console_device *cdev, int baudrate)
{
struct clps711x_uart *s = cdev->dev->priv;
@@ -38,9 +56,9 @@ static int clps711x_setbaudrate(struct console_device *cdev, int baudrate)
divisor = (clk_get_rate(s->uart_clk) / 16) / baudrate;
- tmp = readl(s->UBRLCR) & ~UBRLCR_BAUD_MASK;
+ tmp = readl(s->base + UBRLCR) & ~UBRLCR_BAUD_MASK;
tmp |= divisor - 1;
- writel(tmp, s->UBRLCR);
+ writel(tmp, s->base + UBRLCR);
return 0;
}
@@ -51,15 +69,17 @@ static void clps711x_init_port(struct console_device *cdev)
u32 tmp;
/* Disable the UART */
- writel(readl(SYSCON(s)) & ~SYSCON_UARTEN, SYSCON(s));
+ tmp = readl(s->syscon + SYSCON);
+ writel(tmp & ~SYSCON_UARTEN, s->syscon + SYSCON);
/* Setup Line Control Register */
- tmp = readl(s->UBRLCR) & UBRLCR_BAUD_MASK;
+ tmp = readl(s->base + UBRLCR) & UBRLCR_BAUD_MASK;
tmp |= UBRLCR_FIFOEN | UBRLCR_WRDLEN8; /* FIFO on, 8N1 mode */
- writel(tmp, s->UBRLCR);
+ writel(tmp, s->base + UBRLCR);
/* Enable the UART */
- writel(readl(SYSCON(s)) | SYSCON_UARTEN, SYSCON(s));
+ tmp = readl(s->syscon + SYSCON);
+ writel(tmp | SYSCON_UARTEN, s->syscon + SYSCON);
}
static void clps711x_putc(struct console_device *cdev, char c)
@@ -67,11 +87,11 @@ static void clps711x_putc(struct console_device *cdev, char c)
struct clps711x_uart *s = cdev->dev->priv;
/* Wait until there is space in the FIFO */
- while (readl(SYSFLG(s)) & SYSFLG_UTXFF)
- barrier();
+ do {
+ } while (readl(s->syscon + SYSFLG) & SYSFLG_UTXFF);
/* Send the character */
- writew(c, s->UARTDR);
+ writew(c, s->base + UARTDR);
}
static int clps711x_getc(struct console_device *cdev)
@@ -80,10 +100,10 @@ static int clps711x_getc(struct console_device *cdev)
u16 data;
/* Wait until there is data in the FIFO */
- while (readl(SYSFLG(s)) & SYSFLG_URXFE)
- barrier();
+ do {
+ } while (readl(s->syscon + SYSFLG) & SYSFLG_URXFE);
- data = readw(s->UARTDR);
+ data = readw(s->base + UARTDR);
/* Check for an error flag */
if (data & (UARTDR_FRMERR | UARTDR_PARERR | UARTDR_OVERR))
@@ -96,35 +116,50 @@ static int clps711x_tstc(struct console_device *cdev)
{
struct clps711x_uart *s = cdev->dev->priv;
- return !(readl(SYSFLG(s)) & SYSFLG_URXFE);
+ return !(readl(s->syscon + SYSFLG) & SYSFLG_URXFE);
}
static void clps711x_flush(struct console_device *cdev)
{
struct clps711x_uart *s = cdev->dev->priv;
- while (readl(SYSFLG(s)) & SYSFLG_UBUSY)
- barrier();
+ do {
+ } while (readl(s->syscon + SYSFLG) & SYSFLG_UBUSY);
}
static int clps711x_probe(struct device_d *dev)
{
struct clps711x_uart *s;
+ int err, id = dev->id;
char syscon_dev[8];
- BUG_ON(dev->num_resources != 2);
- BUG_ON((dev->id != 0) && (dev->id != 1));
+ if (dev->device_node)
+ id = of_alias_get_id(dev->device_node, "serial");
+
+ if (id != 0 && id != 1)
+ return -EINVAL;
s = xzalloc(sizeof(struct clps711x_uart));
s->uart_clk = clk_get(dev, NULL);
- BUG_ON(IS_ERR(s->uart_clk));
-
- s->UBRLCR = dev_get_mem_region(dev, 0);
- s->UARTDR = dev_get_mem_region(dev, 1);
-
- sprintf(syscon_dev, "syscon%i", dev->id + 1);
- s->syscon = syscon_base_lookup_by_pdevname(syscon_dev);
- BUG_ON(IS_ERR(s->syscon));
+ if (IS_ERR(s->uart_clk)) {
+ err = PTR_ERR(s->uart_clk);
+ goto out_err;
+ }
+
+ s->base = dev_get_mem_region(dev, 0);
+
+ if (!dev->device_node) {
+ sprintf(syscon_dev, "syscon%i", id + 1);
+ s->syscon = syscon_base_lookup_by_pdevname(syscon_dev);
+ } else {
+ s->syscon = syscon_base_lookup_by_phandle(dev->device_node,
+ "syscon");
+ }
+
+ if (IS_ERR(s->syscon)) {
+ err = PTR_ERR(s->syscon);
+ goto out_err;
+ }
dev->priv = s;
s->cdev.dev = dev;
@@ -135,7 +170,13 @@ static int clps711x_probe(struct device_d *dev)
s->cdev.setbrg = clps711x_setbaudrate;
clps711x_init_port(&s->cdev);
- return console_register(&s->cdev);
+ err = console_register(&s->cdev);
+
+out_err:
+ if (err)
+ free(s);
+
+ return err;
}
static void clps711x_remove(struct device_d *dev)
@@ -147,9 +188,14 @@ static void clps711x_remove(struct device_d *dev)
free(s);
}
+static struct of_device_id __maybe_unused clps711x_uart_dt_ids[] = {
+ { .compatible = "cirrus,clps711x-uart", },
+};
+
static struct driver_d clps711x_driver = {
- .name = "clps711x_serial",
- .probe = clps711x_probe,
- .remove = clps711x_remove,
+ .name = "clps711x-uart",
+ .probe = clps711x_probe,
+ .remove = clps711x_remove,
+ .of_compatible = DRV_OF_COMPAT(clps711x_uart_dt_ids),
};
console_platform_driver(clps711x_driver);
--
1.8.3.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/4] mfd: syscon: Introduce syscon_base_lookup_by_phandle() function
2014-01-23 17:22 [PATCH 1/4] mfd: syscon: Introduce syscon_base_lookup_by_phandle() function Alexander Shiyan
` (2 preceding siblings ...)
2014-01-23 17:22 ` [PATCH 4/4] serial: " Alexander Shiyan
@ 2014-01-24 22:10 ` Sascha Hauer
3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2014-01-24 22:10 UTC (permalink / raw)
To: Alexander Shiyan; +Cc: barebox
On Thu, Jan 23, 2014 at 09:22:04PM +0400, Alexander Shiyan wrote:
> Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
Applied this series.
Thanks
Sascha
> ---
> drivers/mfd/syscon.c | 20 ++++++++++++++++++++
> include/mfd/syscon.h | 8 ++++++++
> 2 files changed, 28 insertions(+)
>
> diff --git a/drivers/mfd/syscon.c b/drivers/mfd/syscon.c
> index 52cb433..6437344 100644
> --- a/drivers/mfd/syscon.c
> +++ b/drivers/mfd/syscon.c
> @@ -41,6 +41,26 @@ void __iomem *syscon_base_lookup_by_pdevname(const char *s)
> return ERR_PTR(-ENODEV);
> }
>
> +void __iomem *syscon_base_lookup_by_phandle(struct device_node *np,
> + const char *property)
> +{
> + struct device_node *node;
> + struct syscon *syscon;
> + struct device_d *dev;
> +
> + node = of_parse_phandle(np, property, 0);
> + if (!node)
> + return ERR_PTR(-ENODEV);
> +
> + dev = of_find_device_by_node(node);
> + if (!dev)
> + return ERR_PTR(-ENODEV);
> +
> + syscon = dev->priv;
> +
> + return syscon->base;
> +}
> +
> static int syscon_probe(struct device_d *dev)
> {
> struct syscon *syscon;
> diff --git a/include/mfd/syscon.h b/include/mfd/syscon.h
> index 68432b7..0eccd5c 100644
> --- a/include/mfd/syscon.h
> +++ b/include/mfd/syscon.h
> @@ -16,11 +16,19 @@
>
> #ifdef CONFIG_MFD_SYSCON
> void __iomem *syscon_base_lookup_by_pdevname(const char *);
> +void __iomem *syscon_base_lookup_by_phandle
> + (struct device_node *np, const char *property);
> #else
> static inline void __iomem *syscon_base_lookup_by_pdevname(const char *)
> {
> return NULL;
> }
> +
> +static inline void __iomem *syscon_base_lookup_by_phandle
> + (struct device_node *np, const char *property)
> +{
> + return NULL;
> +}
> #endif
>
> #endif
> --
> 1.8.3.2
>
>
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
>
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread