From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 3/6] serial: ns16550: introduce private struct
Date: Tue, 23 Jul 2013 08:40:07 +0200 [thread overview]
Message-ID: <1374561610-686-4-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1374561610-686-1-git-send-email-s.hauer@pengutronix.de>
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
next prev parent reply other threads:[~2013-07-23 6:40 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1374561610-686-4-git-send-email-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox