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

Jeremy Kerr jk at ozlabs.org
Thu Feb 11 19:26:05 AEDT 2016


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>
---
 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



More information about the openbmc mailing list