[RFC PATCH 2/2] serial/aspeed-vuart: Perform enable/disable on driver bind/unbind

Norman James njames at us.ibm.com
Fri Feb 12 15:45:09 AEDT 2016


Having the driver handle the enable is better.   Looks good to me.


Regards,
Norman James
IBM - POWER Systems Architect
Phone: 1-512-286-6807 (T/L: 363-6807)
Internet: njames at us.ibm.com




From:	Jeremy Kerr <jk at ozlabs.org>
To:	openbmc at lists.ozlabs.org
Date:	02/11/2016 03:03 AM
Subject:	[RFC PATCH 2/2] serial/aspeed-vuart: Perform enable/disable on
            driver bind/unbind
Sent by:	"openbmc" <openbmc-bounces+njames=us.ibm.com at lists.ozlabs.org>



Rather than exposing an enable sysfs attribute, we can just set the
VUART enabled bit when we bind to the device, and clear it on unbind.

We don't want to do this on open/release, as the host may be using this
bit to configure serial output modes, which is independent of whether
the devices has been opened by BMC userspace.

Signed-off-by: Jeremy Kerr <jk at ozlabs.org>
Reviewed-by:  Norman James <nkskjames at gmail.com>
---
 drivers/tty/serial/aspeed-vuart.c | 53 ++++++++++
+----------------------------
 1 file changed, 14 insertions(+), 39 deletions(-)

diff --git a/drivers/tty/serial/aspeed-vuart.c
b/drivers/tty/serial/aspeed-vuart.c
index 73bb0e7..020c815 100644
--- a/drivers/tty/serial/aspeed-vuart.c
+++ b/drivers/tty/serial/aspeed-vuart.c
@@ -35,42 +35,6 @@ struct ast_vuart {
 		 int		 		 		 line;
 };

-static ssize_t ast_vuart_show_enabled(struct device *dev,
-		 		 struct device_attribute *attr, char *buf)
-{
-		 struct ast_vuart *vuart = dev_get_drvdata(dev);
-		 u8 reg;
-
-		 reg = readb(vuart->regs + AST_VUART_GCRA) &
AST_VUART_GCRA_VUART_EN;
-
-		 return snprintf(buf, PAGE_SIZE - 1, "%u\n", reg ? 1 : 0);
-}
-
-static ssize_t ast_vuart_set_enabled(struct device *dev,
-		 		 struct device_attribute *attr,
-		 		 const char *buf, size_t count)
-{
-		 struct ast_vuart *vuart = dev_get_drvdata(dev);
-		 unsigned long val;
-		 int err;
-		 u8 reg;
-
-		 err = kstrtoul(buf, 0, &val);
-		 if (err)
-		 		 return err;
-
-		 reg = readb(vuart->regs + AST_VUART_GCRA);
-		 reg &= ~AST_VUART_GCRA_VUART_EN;
-		 if (val)
-		 		 reg |= AST_VUART_GCRA_VUART_EN;
-		 writeb(reg, vuart->regs + AST_VUART_GCRA);
-
-		 return count;
-}
-
-static DEVICE_ATTR(enabled, S_IWUSR | S_IRUGO,
-		 		 ast_vuart_show_enabled, ast_vuart_set_enabled);
-
 static ssize_t ast_vuart_show_addr(struct device *dev,
 		 		 struct device_attribute *attr, char *buf)
 {
@@ -144,6 +108,17 @@ static ssize_t ast_vuart_set_sirq(struct device *dev,
 static DEVICE_ATTR(sirq, S_IWUSR | S_IRUGO,
 		 		 ast_vuart_show_sirq, ast_vuart_set_sirq);

+static void ast_vuart_set_enabled(struct ast_vuart *vuart, bool enabled)
+{
+		 u8 reg;
+
+		 reg = readb(vuart->regs + AST_VUART_GCRA);
+		 reg &= ~AST_VUART_GCRA_VUART_EN;
+		 if (enabled)
+		 		 reg |= AST_VUART_GCRA_VUART_EN;
+		 writeb(reg, vuart->regs + AST_VUART_GCRA);
+}
+
 static void ast_vuart_set_host_tx_discard(struct ast_vuart *vuart, bool
discard)
 {
 		 u8 reg;
@@ -304,6 +279,7 @@ static int ast_vuart_probe(struct platform_device
*pdev)


 		 vuart->line = rc;
+		 ast_vuart_set_enabled(vuart, true);
 		 ast_vuart_set_host_tx_discard(vuart, true);
 		 platform_set_drvdata(pdev, vuart);

@@ -314,9 +290,6 @@ static int ast_vuart_probe(struct platform_device
*pdev)
 		 rc = device_create_file(&pdev->dev, &dev_attr_sirq);
 		 if (rc)
 		 		 dev_warn(&pdev->dev, "can't create sirq file\n");
-		 rc = device_create_file(&pdev->dev, &dev_attr_enabled);
-		 if (rc)
-		 		 dev_warn(&pdev->dev, "can't create enabled file
\n");

 		 return 0;

@@ -332,6 +305,8 @@ static int ast_vuart_remove(struct platform_device
*pdev)
 {
 		 struct ast_vuart *vuart = platform_get_drvdata(pdev);

+		 ast_vuart_set_enabled(vuart, false);
+
 		 if (vuart->clk)
 		 		 clk_disable_unprepare(vuart->clk);
 		 return 0;
--
2.5.0

_______________________________________________
openbmc mailing list
openbmc at lists.ozlabs.org
https://lists.ozlabs.org/listinfo/openbmc

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ozlabs.org/pipermail/openbmc/attachments/20160211/444ffdf9/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: graycol.gif
Type: image/gif
Size: 105 bytes
Desc: not available
URL: <http://lists.ozlabs.org/pipermail/openbmc/attachments/20160211/444ffdf9/attachment-0001.gif>


More information about the openbmc mailing list