* [PATCH] serial: ns16550: Add devicetree support
@ 2013-07-23 6:40 Sascha Hauer
2013-07-23 6:40 ` [PATCH 1/6] clk: provide static inline wrappers Sascha Hauer
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: Sascha Hauer @ 2013-07-23 6:40 UTC (permalink / raw)
To: barebox
This adds the necessary preparations to make the ns16550 driver devicetree
aware and finally adds devicetree support to the driver.
----------------------------------------------------------------
Sascha Hauer (6):
clk: provide static inline wrappers
serial: ns16550: reorder functions to avoid forward declaration
serial: ns16550: introduce private struct
serial: ns16550: remove f_caps from platform_data
serial: ns16550: Add clk support and make platform_data optional
serial: ns16550: Add devicetree probe support
arch/arm/Kconfig | 3 +
drivers/clk/Kconfig | 3 +
drivers/serial/serial_ns16550.c | 134 ++++++++++++++++++++++++++++------------
include/linux/clk.h | 39 +++++++++++-
include/ns16550.h | 4 --
5 files changed, 139 insertions(+), 44 deletions(-)
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/6] clk: provide static inline wrappers
2013-07-23 6:40 [PATCH] serial: ns16550: Add devicetree support Sascha Hauer
@ 2013-07-23 6:40 ` Sascha Hauer
2013-07-23 6:40 ` [PATCH 2/6] serial: ns16550: reorder functions to avoid forward declaration Sascha Hauer
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2013-07-23 6:40 UTC (permalink / raw)
To: barebox
So that drivers can use clk_* functions without having to ifdef
them away.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
arch/arm/Kconfig | 3 +++
drivers/clk/Kconfig | 3 +++
include/linux/clk.h | 39 ++++++++++++++++++++++++++++++++++++++-
3 files changed, 44 insertions(+), 1 deletion(-)
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index e7d8cdd..3a74837 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -34,6 +34,7 @@ config ARCH_AT91
select CLKDEV_LOOKUP
select HAS_DEBUG_LL
select HAVE_MACH_ARM_HEAD
+ select HAVE_CLK
config ARCH_BCM2835
bool "Broadcom BCM2835 boards"
@@ -99,6 +100,7 @@ config ARCH_NOMADIK
bool "STMicroelectronics Nomadik"
select CPU_ARM926T
select CLOCKSOURCE_NOMADIK
+ select HAVE_CLK
help
Support for the Nomadik platform by ST-Ericsson
@@ -133,6 +135,7 @@ config ARCH_VERSATILE
bool "ARM Versatile boards (ARM926EJ-S)"
select CPU_ARM926T
select GPIOLIB
+ select HAVE_CLK
config ARCH_VEXPRESS
bool "ARM Vexpres boards"
diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
index a00e539..daf778a 100644
--- a/drivers/clk/Kconfig
+++ b/drivers/clk/Kconfig
@@ -1,8 +1,11 @@
+config HAVE_CLK
+ bool
config CLKDEV_LOOKUP
bool
config COMMON_CLK
+ select HAVE_CLK
bool
config COMMON_CLK_OF_PROVIDER
diff --git a/include/linux/clk.h b/include/linux/clk.h
index 0a565ef..6aed1de 100644
--- a/include/linux/clk.h
+++ b/include/linux/clk.h
@@ -19,12 +19,13 @@ struct device_d;
* The base API.
*/
-
/*
* struct clk - an machine class defined object / cookie.
*/
struct clk;
+#ifdef CONFIG_HAVE_CLK
+
/**
* clk_get - lookup and obtain a reference to a clock producer.
* @dev: device for clock "consumer"
@@ -157,6 +158,42 @@ struct clk *clk_get_sys(const char *dev_id, const char *con_id);
int clk_add_alias(const char *alias, const char *alias_dev_name, char *id,
struct device_d *dev);
+#else
+
+static inline struct clk *clk_get(struct device_d *dev, const char *id)
+{
+ return NULL;
+}
+
+static inline int clk_enable(struct clk *clk)
+{
+ return 0;
+}
+
+static inline void clk_disable(struct clk *clk)
+{
+}
+
+static inline unsigned long clk_get_rate(struct clk *clk)
+{
+ return 0;
+}
+
+static inline void clk_put(struct clk *clk)
+{
+}
+
+static inline long clk_round_rate(struct clk *clk, unsigned long rate)
+{
+ return 0;
+}
+
+static inline int clk_set_rate(struct clk *clk, unsigned long rate)
+{
+ return 0;
+}
+#endif
+
#ifdef CONFIG_COMMON_CLK
struct clk_ops {
int (*enable)(struct clk *clk);
--
1.8.3.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 2/6] serial: ns16550: reorder functions to avoid forward declaration
2013-07-23 6:40 [PATCH] serial: ns16550: Add devicetree support Sascha Hauer
2013-07-23 6:40 ` [PATCH 1/6] clk: provide static inline wrappers Sascha Hauer
@ 2013-07-23 6:40 ` Sascha Hauer
2013-07-23 6:40 ` [PATCH 3/6] serial: ns16550: introduce private struct Sascha Hauer
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2013-07-23 6:40 UTC (permalink / raw)
To: barebox
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/serial/serial_ns16550.c | 59 +++++++++++++++++++----------------------
1 file changed, 28 insertions(+), 31 deletions(-)
diff --git a/drivers/serial/serial_ns16550.c b/drivers/serial/serial_ns16550.c
index b7913aa..b792ba5 100644
--- a/drivers/serial/serial_ns16550.c
+++ b/drivers/serial/serial_ns16550.c
@@ -42,9 +42,6 @@
#include "serial_ns16550.h"
#include <ns16550.h>
-/*********** Private Functions **********************************/
-static int ns16550_setbaudrate(struct console_device *cdev, int baud_rate);
-
/**
* @brief read register
*
@@ -129,6 +126,34 @@ static inline unsigned int ns16550_calc_divisor(struct console_device *cdev,
}
/**
+ * @brief Set the baudrate for the uart port
+ *
+ * @param[in] cdev console device
+ * @param[in] baud_rate baud rate to set
+ *
+ * @return 0-implied to support the baudrate
+ */
+static int ns16550_setbaudrate(struct console_device *cdev, int baud_rate)
+{
+ unsigned int baud_divisor = ns16550_calc_divisor(cdev, baud_rate);
+ struct NS16550_plat *plat = (struct NS16550_plat *)
+ cdev->dev->platform_data;
+
+ ns16550_write(cdev, LCR_BKSE, lcr);
+ ns16550_write(cdev, baud_divisor & 0xff, dll);
+ ns16550_write(cdev, (baud_divisor >> 8) & 0xff, dlm);
+ ns16550_write(cdev, LCRVAL, lcr);
+ ns16550_write(cdev, MCRVAL, mcr);
+
+ if (plat->flags & NS16650_FLAG_DISABLE_FIFO)
+ ns16550_write(cdev, FCRVAL & ~FCR_FIFO_EN, fcr);
+ else
+ ns16550_write(cdev, FCRVAL, fcr);
+
+ return 0;
+}
+
+/**
* @brief Initialize the device
*
* @param[in] cdev pointer to console device
@@ -192,34 +217,6 @@ static int ns16550_tstc(struct console_device *cdev)
}
/**
- * @brief Set the baudrate for the uart port
- *
- * @param[in] cdev console device
- * @param[in] baud_rate baud rate to set
- *
- * @return 0-implied to support the baudrate
- */
-static int ns16550_setbaudrate(struct console_device *cdev, int baud_rate)
-{
- unsigned int baud_divisor = ns16550_calc_divisor(cdev, baud_rate);
- struct NS16550_plat *plat = (struct NS16550_plat *)
- cdev->dev->platform_data;
-
- ns16550_write(cdev, LCR_BKSE, lcr);
- ns16550_write(cdev, baud_divisor & 0xff, dll);
- ns16550_write(cdev, (baud_divisor >> 8) & 0xff, dlm);
- ns16550_write(cdev, LCRVAL, lcr);
- ns16550_write(cdev, MCRVAL, mcr);
-
- if (plat->flags & NS16650_FLAG_DISABLE_FIFO)
- ns16550_write(cdev, FCRVAL & ~FCR_FIFO_EN, fcr);
- else
- ns16550_write(cdev, FCRVAL, fcr);
-
- return 0;
-}
-
-/**
* @brief Probe entry point -called on the first match for device
*
* @param[in] dev matched device
--
1.8.3.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 3/6] serial: ns16550: introduce private struct
2013-07-23 6:40 [PATCH] serial: ns16550: Add devicetree support Sascha Hauer
2013-07-23 6:40 ` [PATCH 1/6] clk: provide static inline wrappers Sascha Hauer
2013-07-23 6:40 ` [PATCH 2/6] serial: ns16550: reorder functions to avoid forward declaration Sascha Hauer
@ 2013-07-23 6:40 ` Sascha Hauer
2013-07-23 6:40 ` [PATCH 4/6] serial: ns16550: remove f_caps from platform_data Sascha Hauer
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2013-07-23 6:40 UTC (permalink / raw)
To: barebox
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/serial/serial_ns16550.c | 37 ++++++++++++++++++++++++++++---------
1 file changed, 28 insertions(+), 9 deletions(-)
diff --git a/drivers/serial/serial_ns16550.c b/drivers/serial/serial_ns16550.c
index b792ba5..f9a17f4 100644
--- a/drivers/serial/serial_ns16550.c
+++ b/drivers/serial/serial_ns16550.c
@@ -42,6 +42,17 @@
#include "serial_ns16550.h"
#include <ns16550.h>
+struct ns16550_priv {
+ struct console_device cdev;
+ struct NS16550_plat plat;
+ int access_width;
+};
+
+static inline struct ns16550_priv *to_ns16550_priv(struct console_device *cdev)
+{
+ return container_of(cdev, struct ns16550_priv, cdev);
+}
+
/**
* @brief read register
*
@@ -52,9 +63,10 @@
*/
static uint32_t ns16550_read(struct console_device *cdev, uint32_t off)
{
+ struct ns16550_priv *priv = to_ns16550_priv(cdev);
struct device_d *dev = cdev->dev;
- struct NS16550_plat *plat = (struct NS16550_plat *)dev->platform_data;
- int width = dev->resource[0].flags & IORESOURCE_MEM_TYPE_MASK;
+ struct NS16550_plat *plat = &priv->plat;
+ int width = priv->access_width;
off <<= plat->shift;
@@ -82,9 +94,10 @@ static uint32_t ns16550_read(struct console_device *cdev, uint32_t off)
static void ns16550_write(struct console_device *cdev, uint32_t val,
uint32_t off)
{
+ struct ns16550_priv *priv = to_ns16550_priv(cdev);
struct device_d *dev = cdev->dev;
- struct NS16550_plat *plat = (struct NS16550_plat *)dev->platform_data;
- int width = dev->resource[0].flags & IORESOURCE_MEM_TYPE_MASK;
+ struct NS16550_plat *plat = &priv->plat;
+ int width = priv->access_width;
off <<= plat->shift;
@@ -117,8 +130,8 @@ static void ns16550_write(struct console_device *cdev, uint32_t val,
static inline unsigned int ns16550_calc_divisor(struct console_device *cdev,
unsigned int baudrate)
{
- struct NS16550_plat *plat = (struct NS16550_plat *)
- cdev->dev->platform_data;
+ struct ns16550_priv *priv = to_ns16550_priv(cdev);
+ struct NS16550_plat *plat = &priv->plat;
unsigned int clk = plat->clock;
return (clk / MODE_X_DIV / baudrate);
@@ -136,8 +149,8 @@ static inline unsigned int ns16550_calc_divisor(struct console_device *cdev,
static int ns16550_setbaudrate(struct console_device *cdev, int baud_rate)
{
unsigned int baud_divisor = ns16550_calc_divisor(cdev, baud_rate);
- struct NS16550_plat *plat = (struct NS16550_plat *)
- cdev->dev->platform_data;
+ struct ns16550_priv *priv = to_ns16550_priv(cdev);
+ struct NS16550_plat *plat = &priv->plat;
ns16550_write(cdev, LCR_BKSE, lcr);
ns16550_write(cdev, baud_divisor & 0xff, dll);
@@ -227,6 +240,7 @@ static int ns16550_tstc(struct console_device *cdev)
*/
static int ns16550_probe(struct device_d *dev)
{
+ struct ns16550_priv *priv;
struct console_device *cdev;
struct NS16550_plat *plat = (struct NS16550_plat *)dev->platform_data;
@@ -235,7 +249,12 @@ static int ns16550_probe(struct device_d *dev)
return -EINVAL;
dev->priv = dev_request_mem_region(dev, 0);
- cdev = xzalloc(sizeof(*cdev));
+ priv = xzalloc(sizeof(*priv));
+
+ cdev = &priv->cdev;
+ priv->plat = *plat;
+
+ priv->access_width = dev->resource[0].flags & IORESOURCE_MEM_TYPE_MASK;
cdev->dev = dev;
if (plat->f_caps)
--
1.8.3.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 4/6] serial: ns16550: remove f_caps from platform_data
2013-07-23 6:40 [PATCH] serial: ns16550: Add devicetree support Sascha Hauer
` (2 preceding siblings ...)
2013-07-23 6:40 ` [PATCH 3/6] serial: ns16550: introduce private struct Sascha Hauer
@ 2013-07-23 6:40 ` Sascha Hauer
2013-07-23 6:40 ` [PATCH 5/6] serial: ns16550: Add clk support and make platform_data optional Sascha Hauer
2013-07-23 6:40 ` [PATCH 6/6] serial: ns16550: Add devicetree probe support Sascha Hauer
5 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2013-07-23 6:40 UTC (permalink / raw)
To: barebox
So far no user had the need to set the flags, so just remove them
from platform data.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/serial/serial_ns16550.c | 5 +----
include/ns16550.h | 4 ----
2 files changed, 1 insertion(+), 8 deletions(-)
diff --git a/drivers/serial/serial_ns16550.c b/drivers/serial/serial_ns16550.c
index f9a17f4..dd50fc5 100644
--- a/drivers/serial/serial_ns16550.c
+++ b/drivers/serial/serial_ns16550.c
@@ -257,10 +257,7 @@ static int ns16550_probe(struct device_d *dev)
priv->access_width = dev->resource[0].flags & IORESOURCE_MEM_TYPE_MASK;
cdev->dev = dev;
- if (plat->f_caps)
- cdev->f_caps = plat->f_caps;
- else
- cdev->f_caps = CONSOLE_STDIN | CONSOLE_STDOUT | CONSOLE_STDERR;
+ cdev->f_caps = CONSOLE_STDIN | CONSOLE_STDOUT | CONSOLE_STDERR;
cdev->tstc = ns16550_tstc;
cdev->putc = ns16550_putc;
cdev->getc = ns16550_getc;
diff --git a/include/ns16550.h b/include/ns16550.h
index 27cb4cf..36aa5ff 100644
--- a/include/ns16550.h
+++ b/include/ns16550.h
@@ -33,10 +33,6 @@
struct NS16550_plat {
/** Clock speed */
unsigned int clock;
- /** Console capabilities:
- * CONSOLE_STDIN | CONSOLE_STDOUT | CONSOLE_STDERR @see console.h
- */
- unsigned char f_caps;
/**
* register read access capability
*/
--
1.8.3.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 5/6] serial: ns16550: Add clk support and make platform_data optional
2013-07-23 6:40 [PATCH] serial: ns16550: Add devicetree support Sascha Hauer
` (3 preceding siblings ...)
2013-07-23 6:40 ` [PATCH 4/6] serial: ns16550: remove f_caps from platform_data Sascha Hauer
@ 2013-07-23 6:40 ` Sascha Hauer
2013-07-23 6:40 ` [PATCH 6/6] serial: ns16550: Add devicetree probe support Sascha Hauer
5 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2013-07-23 6:40 UTC (permalink / raw)
To: barebox
The clockrate was the only really needed field from platform data.
Add clk support to retrieve the clockrate and make platform data
optional.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/serial/serial_ns16550.c | 26 +++++++++++++++++++++++---
1 file changed, 23 insertions(+), 3 deletions(-)
diff --git a/drivers/serial/serial_ns16550.c b/drivers/serial/serial_ns16550.c
index dd50fc5..b010785 100644
--- a/drivers/serial/serial_ns16550.c
+++ b/drivers/serial/serial_ns16550.c
@@ -38,6 +38,7 @@
#include <errno.h>
#include <malloc.h>
#include <io.h>
+#include <linux/clk.h>
#include "serial_ns16550.h"
#include <ns16550.h>
@@ -46,6 +47,7 @@ struct ns16550_priv {
struct console_device cdev;
struct NS16550_plat plat;
int access_width;
+ struct clk *clk;
};
static inline struct ns16550_priv *to_ns16550_priv(struct console_device *cdev)
@@ -243,10 +245,8 @@ static int ns16550_probe(struct device_d *dev)
struct ns16550_priv *priv;
struct console_device *cdev;
struct NS16550_plat *plat = (struct NS16550_plat *)dev->platform_data;
+ int ret;
- /* we do expect platform specific data */
- if (plat == NULL)
- return -EINVAL;
dev->priv = dev_request_mem_region(dev, 0);
priv = xzalloc(sizeof(*priv));
@@ -254,6 +254,21 @@ static int ns16550_probe(struct device_d *dev)
cdev = &priv->cdev;
priv->plat = *plat;
+ if (!plat || !plat->clock) {
+ priv->clk = clk_get(dev, NULL);
+ if (IS_ERR(priv->clk)) {
+ ret = PTR_ERR(priv->clk);
+ goto err;
+ }
+ priv->plat.clock = clk_get_rate(priv->clk);
+ }
+
+ if (priv->plat.clock == 0) {
+ dev_err(dev, "no valid clockrate\n");
+ ret = -EINVAL;
+ goto err;
+ }
+
priv->access_width = dev->resource[0].flags & IORESOURCE_MEM_TYPE_MASK;
cdev->dev = dev;
@@ -266,6 +281,11 @@ static int ns16550_probe(struct device_d *dev)
ns16550_serial_init_port(cdev);
return console_register(cdev);
+
+err:
+ free(priv);
+
+ return ret;
}
/**
--
1.8.3.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 6/6] serial: ns16550: Add devicetree probe support
2013-07-23 6:40 [PATCH] serial: ns16550: Add devicetree support Sascha Hauer
` (4 preceding siblings ...)
2013-07-23 6:40 ` [PATCH 5/6] serial: ns16550: Add clk support and make platform_data optional Sascha Hauer
@ 2013-07-23 6:40 ` Sascha Hauer
5 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2013-07-23 6:40 UTC (permalink / raw)
To: barebox
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/serial/serial_ns16550.c | 25 ++++++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)
diff --git a/drivers/serial/serial_ns16550.c b/drivers/serial/serial_ns16550.c
index b010785..ad3125a 100644
--- a/drivers/serial/serial_ns16550.c
+++ b/drivers/serial/serial_ns16550.c
@@ -231,6 +231,16 @@ static int ns16550_tstc(struct console_device *cdev)
return ((ns16550_read(cdev, lsr) & LSR_DR) != 0);
}
+static void ns16550_probe_dt(struct device_d *dev, struct ns16550_priv *priv)
+{
+ struct device_node *np = dev->device_node;
+
+ if (!IS_ENABLED(CONFIG_OFDEVICE))
+ return;
+
+ of_property_read_u32(np, "reg-shift", &priv->plat.shift);
+}
+
/**
* @brief Probe entry point -called on the first match for device
*
@@ -251,8 +261,12 @@ static int ns16550_probe(struct device_d *dev)
priv = xzalloc(sizeof(*priv));
+ if (plat)
+ priv->plat = *plat;
+ else
+ ns16550_probe_dt(dev, priv);
+
cdev = &priv->cdev;
- priv->plat = *plat;
if (!plat || !plat->clock) {
priv->clk = clk_get(dev, NULL);
@@ -288,11 +302,20 @@ err:
return ret;
}
+static struct of_device_id ns16550_serial_dt_ids[] = {
+ {
+ .compatible = "ns16550a",
+ }, {
+ /* sentinel */
+ },
+};
+
/**
* @brief Driver registration structure
*/
static struct driver_d ns16550_serial_driver = {
.name = "ns16550_serial",
.probe = ns16550_probe,
+ .of_compatible = DRV_OF_COMPAT(ns16550_serial_dt_ids),
};
console_platform_driver(ns16550_serial_driver);
--
1.8.3.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2013-07-23 6:40 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-23 6:40 [PATCH] serial: ns16550: Add devicetree support Sascha Hauer
2013-07-23 6:40 ` [PATCH 1/6] clk: provide static inline wrappers Sascha Hauer
2013-07-23 6:40 ` [PATCH 2/6] serial: ns16550: reorder functions to avoid forward declaration Sascha Hauer
2013-07-23 6:40 ` [PATCH 3/6] serial: ns16550: introduce private struct Sascha Hauer
2013-07-23 6:40 ` [PATCH 4/6] serial: ns16550: remove f_caps from platform_data Sascha Hauer
2013-07-23 6:40 ` [PATCH 5/6] serial: ns16550: Add clk support and make platform_data optional Sascha Hauer
2013-07-23 6:40 ` [PATCH 6/6] serial: ns16550: Add devicetree probe support Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox