Skip to contentSkip to conversation

ipmi: bt-bmc: Use a regmap for register access

PATCH Superseded Andrew Jeffery 4 participants 10 messages Dec 6, 2016 – Feb 20, 2017 IPMI

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ipmi: bt-bmc: Use a regmap for register access

The registers for the bt-bmc device live under the Aspeed LPC controller. Devicetree bindings have recently been introduced for the LPC controller where the "host" portion of the LPC register space is described as a syscon device. Future devicetrees describing the bt-bmc device should nest its node under the appropriate "simple-mfd", "syscon" compatible node.

This change allows the bt-bmc driver to function with both syscon and non-syscon- based devicetree descriptions by always using a regmap for register access, either retrieved from the parent syscon device or instantiated if none exists.

The patch has been tested on an OpenPOWER Palmetto machine, successfully booting, rebooting and powering down the host.

---
 drivers/char/ipmi/Kconfig  |  1 +
 drivers/char/ipmi/bt-bmc.c | 82 ++++++++++++++++++++++++++++++++++------------
 2 files changed, 62 insertions(+), 21 deletions(-)
drivers/char/ipmi/Kconfig +1 -0
index 7f816655cbbf..b5d48d9af124 100644
@@ -79,6 +79,7 @@ endif # IPMI_HANDLER
 
 config ASPEED_BT_IPMI_BMC
 	depends on ARCH_ASPEED
+        depends on REGMAP && REGMAP_MMIO && MFD_SYSCON
 	tristate "BT IPMI bmc driver"
 	help
 	  Provides a driver for the BT (Block Transfer) IPMI interface
drivers/char/ipmi/bt-bmc.c +61 -21

153 lines not on this page · raw message

Signature · 1 line
2.9.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 12 lines · Andrew Jeffery

The registers for the bt-bmc device live under the Aspeed LPC controller. Devicetree bindings have recently been introduced for the LPC controller where the "host" portion of the LPC register space is described as a syscon device. Future devicetrees describing the bt-bmc device should nest its node under the appropriate "simple-mfd", "syscon" compatible node.

This change allows the bt-bmc driver to function with both syscon and non-syscon- based devicetree descriptions by always using a regmap for register access, either retrieved from the parent syscon device or instantiated if none exists.

Quoted 4 lines

The patch has been tested on an OpenPOWER Palmetto machine, successfully booting, rebooting and powering down the host.

It would be nice to have an example of the associated binding. I did not see it. A part from that :

Thanks,

C.

Quoted 183 lines
---
 drivers/char/ipmi/Kconfig  |  1 +
 drivers/char/ipmi/bt-bmc.c | 82 ++++++++++++++++++++++++++++++++++------------
 2 files changed, 62 insertions(+), 21 deletions(-)
drivers/char/ipmi/Kconfig +1 -0
index 7f816655cbbf..b5d48d9af124 100644
@@ -79,6 +79,7 @@ endif # IPMI_HANDLER
 
 config ASPEED_BT_IPMI_BMC
 	depends on ARCH_ASPEED
+        depends on REGMAP && REGMAP_MMIO && MFD_SYSCON
 	tristate "BT IPMI bmc driver"
 	help
 	  Provides a driver for the BT (Block Transfer) IPMI interface
drivers/char/ipmi/bt-bmc.c +61 -21
index fc9e8891eae3..ca1e20f6c6c5 100644
@@ -12,10 +12,13 @@
 #include <linux/errno.h>
 #include <linux/interrupt.h>
 #include <linux/io.h>
+#include <linux/mfd/syscon.h>
 #include <linux/miscdevice.h>
 #include <linux/module.h>
+#include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/poll.h>
+#include <linux/regmap.h>
 #include <linux/sched.h>
 #include <linux/timer.h>
 
@@ -60,7 +63,8 @@
 struct bt_bmc {
 	struct device		dev;
 	struct miscdevice	miscdev;
-	void __iomem		*base;
+	struct regmap		*map;
+	int			offset;
 	int			irq;
 	wait_queue_head_t	queue;
 	struct timer_list	poll_timer;
@@ -69,14 +73,31 @@ struct bt_bmc {
 
 static atomic_t open_count = ATOMIC_INIT(0);
 
+static struct regmap_config bt_regmap_cfg = {
+	.reg_bits = 32,
+	.val_bits = 32,
+	.reg_stride = 4,
+};
+
 static u8 bt_inb(struct bt_bmc *bt_bmc, int reg)
 {
-	return ioread8(bt_bmc->base + reg);
+	uint32_t val = 0;
+	int rc;
+
+	rc = regmap_read(bt_bmc->map, bt_bmc->offset + reg, &val);
+	WARN(rc != 0, "%s:%d: regmap_read() failed: %d\n",
+			__FILE__, __LINE__, rc);
+
+	return rc == 0 ? (u8) val : 0;
 }
 
 static void bt_outb(struct bt_bmc *bt_bmc, u8 data, int reg)
 {
-	iowrite8(data, bt_bmc->base + reg);
+	int rc;
+
+	rc = regmap_write(bt_bmc->map, bt_bmc->offset + reg, data);
+	WARN(rc != 0, "%s:%d: regmap_write() failed: %d\n",
+			__FILE__, __LINE__, rc);
 }
 
 static void clr_rd_ptr(struct bt_bmc *bt_bmc)
@@ -367,14 +388,18 @@ static irqreturn_t bt_bmc_irq(int irq, void *arg)
 {
 	struct bt_bmc *bt_bmc = arg;
 	u32 reg;
+	int rc;
+
+	rc = regmap_read(bt_bmc->map, bt_bmc->offset + BT_CR2, &reg);
+	if (rc)
+		return IRQ_NONE;
 
-	reg = ioread32(bt_bmc->base + BT_CR2);
 	reg &= BT_CR2_IRQ_H2B | BT_CR2_IRQ_HBUSY;
 	if (!reg)
 		return IRQ_NONE;
 
 	/* ack pending IRQs */
-	iowrite32(reg, bt_bmc->base + BT_CR2);
+	regmap_write(bt_bmc->map, bt_bmc->offset + BT_CR2, reg);
 
 	wake_up(&bt_bmc->queue);
 	return IRQ_HANDLED;
@@ -384,7 +409,6 @@ static int bt_bmc_config_irq(struct bt_bmc *bt_bmc,
 			     struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
-	u32 reg;
 	int rc;
 
 	bt_bmc->irq = platform_get_irq(pdev, 0);
@@ -405,18 +429,17 @@ static int bt_bmc_config_irq(struct bt_bmc *bt_bmc,
 	 * will be cleared (along with B2H) when we can write the next
 	 * message to the BT buffer
 	 */
-	reg = ioread32(bt_bmc->base + BT_CR1);
-	reg |= BT_CR1_IRQ_H2B | BT_CR1_IRQ_HBUSY;
-	iowrite32(reg, bt_bmc->base + BT_CR1);
+	rc = regmap_update_bits(bt_bmc->map, bt_bmc->offset + BT_CR1,
+				(BT_CR1_IRQ_H2B | BT_CR1_IRQ_HBUSY),
+				(BT_CR1_IRQ_H2B | BT_CR1_IRQ_HBUSY));
 
-	return 0;
+	return rc;
 }
 
 static int bt_bmc_probe(struct platform_device *pdev)
 {
 	struct bt_bmc *bt_bmc;
 	struct device *dev;
-	struct resource *res;
 	int rc;
 
 	if (!pdev || !pdev->dev.of_node)
@@ -431,10 +454,27 @@ static int bt_bmc_probe(struct platform_device *pdev)
 
 	dev_set_drvdata(&pdev->dev, bt_bmc);
 
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	bt_bmc->base = devm_ioremap_resource(&pdev->dev, res);
-	if (IS_ERR(bt_bmc->base))
-		return PTR_ERR(bt_bmc->base);
+	bt_bmc->map = syscon_node_to_regmap(pdev->dev.parent->of_node);
+	if (IS_ERR(bt_bmc->map)) {
+		struct resource *res;
+		void __iomem *base;
+
+		/*
+		 * Assume it's not the MFD-based devicetree description, in
+		 * which case generate a regmap ourselves
+		 */
+		res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+		base = devm_ioremap_resource(&pdev->dev, res);
+		if (IS_ERR(base))
+			return PTR_ERR(base);
+
+		bt_bmc->map = devm_regmap_init_mmio(dev, base, &bt_regmap_cfg);
+		bt_bmc->offset = 0;
+	} else {
+		rc = of_property_read_u32(dev->of_node, "reg", &bt_bmc->offset);
+		if (rc)
+			return rc;
+	}
 
 	mutex_init(&bt_bmc->mutex);
 	init_waitqueue_head(&bt_bmc->queue);
@@ -461,12 +501,12 @@ static int bt_bmc_probe(struct platform_device *pdev)
 		add_timer(&bt_bmc->poll_timer);
 	}
 
-	iowrite32((BT_IO_BASE << BT_CR0_IO_BASE) |
-		  (BT_IRQ << BT_CR0_IRQ) |
-		  BT_CR0_EN_CLR_SLV_RDP |
-		  BT_CR0_EN_CLR_SLV_WRP |
-		  BT_CR0_ENABLE_IBT,
-		  bt_bmc->base + BT_CR0);
+	regmap_write(bt_bmc->map, bt_bmc->offset + BT_CR0,
+		     (BT_IO_BASE << BT_CR0_IO_BASE) |
+		     (BT_IRQ << BT_CR0_IRQ) |
+		     BT_CR0_EN_CLR_SLV_RDP |
+		     BT_CR0_EN_CLR_SLV_WRP |
+		     BT_CR0_ENABLE_IBT);
 
 	clr_b_busy(bt_bmc);
 
Reviewed-by on v1 1/1
#2 lore raw
In reply to Andrew Jeffery

[ this is a resend bc of some mailing list issues]

Quoted 12 lines · Andrew Jeffery

The registers for the bt-bmc device live under the Aspeed LPC controller. Devicetree bindings have recently been introduced for the LPC controller where the "host" portion of the LPC register space is described as a syscon device. Future devicetrees describing the bt-bmc device should nest its node under the appropriate "simple-mfd", "syscon" compatible node.

This change allows the bt-bmc driver to function with both syscon and non-syscon- based devicetree descriptions by always using a regmap for register access, either retrieved from the parent syscon device or instantiated if none exists.

Quoted 4 lines

The patch has been tested on an OpenPOWER Palmetto machine, successfully booting, rebooting and powering down the host.

It would be nice to have an example of the associated binding. I did not see it. A part from that :

Thanks,

C.

Quoted 183 lines
---
 drivers/char/ipmi/Kconfig  |  1 +
 drivers/char/ipmi/bt-bmc.c | 82 ++++++++++++++++++++++++++++++++++------------
 2 files changed, 62 insertions(+), 21 deletions(-)
drivers/char/ipmi/Kconfig +1 -0
index 7f816655cbbf..b5d48d9af124 100644
@@ -79,6 +79,7 @@ endif # IPMI_HANDLER
 
 config ASPEED_BT_IPMI_BMC
 	depends on ARCH_ASPEED
+        depends on REGMAP && REGMAP_MMIO && MFD_SYSCON
 	tristate "BT IPMI bmc driver"
 	help
 	  Provides a driver for the BT (Block Transfer) IPMI interface
drivers/char/ipmi/bt-bmc.c +61 -21
index fc9e8891eae3..ca1e20f6c6c5 100644
@@ -12,10 +12,13 @@
 #include <linux/errno.h>
 #include <linux/interrupt.h>
 #include <linux/io.h>
+#include <linux/mfd/syscon.h>
 #include <linux/miscdevice.h>
 #include <linux/module.h>
+#include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/poll.h>
+#include <linux/regmap.h>
 #include <linux/sched.h>
 #include <linux/timer.h>
 
@@ -60,7 +63,8 @@
 struct bt_bmc {
 	struct device		dev;
 	struct miscdevice	miscdev;
-	void __iomem		*base;
+	struct regmap		*map;
+	int			offset;
 	int			irq;
 	wait_queue_head_t	queue;
 	struct timer_list	poll_timer;
@@ -69,14 +73,31 @@ struct bt_bmc {
 
 static atomic_t open_count = ATOMIC_INIT(0);
 
+static struct regmap_config bt_regmap_cfg = {
+	.reg_bits = 32,
+	.val_bits = 32,
+	.reg_stride = 4,
+};
+
 static u8 bt_inb(struct bt_bmc *bt_bmc, int reg)
 {
-	return ioread8(bt_bmc->base + reg);
+	uint32_t val = 0;
+	int rc;
+
+	rc = regmap_read(bt_bmc->map, bt_bmc->offset + reg, &val);
+	WARN(rc != 0, "%s:%d: regmap_read() failed: %d\n",
+			__FILE__, __LINE__, rc);
+
+	return rc == 0 ? (u8) val : 0;
 }
 
 static void bt_outb(struct bt_bmc *bt_bmc, u8 data, int reg)
 {
-	iowrite8(data, bt_bmc->base + reg);
+	int rc;
+
+	rc = regmap_write(bt_bmc->map, bt_bmc->offset + reg, data);
+	WARN(rc != 0, "%s:%d: regmap_write() failed: %d\n",
+			__FILE__, __LINE__, rc);
 }
 
 static void clr_rd_ptr(struct bt_bmc *bt_bmc)
@@ -367,14 +388,18 @@ static irqreturn_t bt_bmc_irq(int irq, void *arg)
 {
 	struct bt_bmc *bt_bmc = arg;
 	u32 reg;
+	int rc;
+
+	rc = regmap_read(bt_bmc->map, bt_bmc->offset + BT_CR2, &reg);
+	if (rc)
+		return IRQ_NONE;
 
-	reg = ioread32(bt_bmc->base + BT_CR2);
 	reg &= BT_CR2_IRQ_H2B | BT_CR2_IRQ_HBUSY;
 	if (!reg)
 		return IRQ_NONE;
 
 	/* ack pending IRQs */
-	iowrite32(reg, bt_bmc->base + BT_CR2);
+	regmap_write(bt_bmc->map, bt_bmc->offset + BT_CR2, reg);
 
 	wake_up(&bt_bmc->queue);
 	return IRQ_HANDLED;
@@ -384,7 +409,6 @@ static int bt_bmc_config_irq(struct bt_bmc *bt_bmc,
 			     struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
-	u32 reg;
 	int rc;
 
 	bt_bmc->irq = platform_get_irq(pdev, 0);
@@ -405,18 +429,17 @@ static int bt_bmc_config_irq(struct bt_bmc *bt_bmc,
 	 * will be cleared (along with B2H) when we can write the next
 	 * message to the BT buffer
 	 */
-	reg = ioread32(bt_bmc->base + BT_CR1);
-	reg |= BT_CR1_IRQ_H2B | BT_CR1_IRQ_HBUSY;
-	iowrite32(reg, bt_bmc->base + BT_CR1);
+	rc = regmap_update_bits(bt_bmc->map, bt_bmc->offset + BT_CR1,
+				(BT_CR1_IRQ_H2B | BT_CR1_IRQ_HBUSY),
+				(BT_CR1_IRQ_H2B | BT_CR1_IRQ_HBUSY));
 
-	return 0;
+	return rc;
 }
 
 static int bt_bmc_probe(struct platform_device *pdev)
 {
 	struct bt_bmc *bt_bmc;
 	struct device *dev;
-	struct resource *res;
 	int rc;
 
 	if (!pdev || !pdev->dev.of_node)
@@ -431,10 +454,27 @@ static int bt_bmc_probe(struct platform_device *pdev)
 
 	dev_set_drvdata(&pdev->dev, bt_bmc);
 
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	bt_bmc->base = devm_ioremap_resource(&pdev->dev, res);
-	if (IS_ERR(bt_bmc->base))
-		return PTR_ERR(bt_bmc->base);
+	bt_bmc->map = syscon_node_to_regmap(pdev->dev.parent->of_node);
+	if (IS_ERR(bt_bmc->map)) {
+		struct resource *res;
+		void __iomem *base;
+
+		/*
+		 * Assume it's not the MFD-based devicetree description, in
+		 * which case generate a regmap ourselves
+		 */
+		res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+		base = devm_ioremap_resource(&pdev->dev, res);
+		if (IS_ERR(base))
+			return PTR_ERR(base);
+
+		bt_bmc->map = devm_regmap_init_mmio(dev, base, &bt_regmap_cfg);
+		bt_bmc->offset = 0;
+	} else {
+		rc = of_property_read_u32(dev->of_node, "reg", &bt_bmc->offset);
+		if (rc)
+			return rc;
+	}
 
 	mutex_init(&bt_bmc->mutex);
 	init_waitqueue_head(&bt_bmc->queue);
@@ -461,12 +501,12 @@ static int bt_bmc_probe(struct platform_device *pdev)
 		add_timer(&bt_bmc->poll_timer);
 	}
 
-	iowrite32((BT_IO_BASE << BT_CR0_IO_BASE) |
-		  (BT_IRQ << BT_CR0_IRQ) |
-		  BT_CR0_EN_CLR_SLV_RDP |
-		  BT_CR0_EN_CLR_SLV_WRP |
-		  BT_CR0_ENABLE_IBT,
-		  bt_bmc->base + BT_CR0);
+	regmap_write(bt_bmc->map, bt_bmc->offset + BT_CR0,
+		     (BT_IO_BASE << BT_CR0_IO_BASE) |
+		     (BT_IRQ << BT_CR0_IRQ) |
+		     BT_CR0_EN_CLR_SLV_RDP |
+		     BT_CR0_EN_CLR_SLV_WRP |
+		     BT_CR0_ENABLE_IBT);
 
 	clr_b_busy(bt_bmc);
 
#3 lore raw
Quoted 1 line · C?dric Le Goater

[ this is a resend bc of some mailing list issues]?

Thanks for resending.

Quoted 14 lines · Andrew Jeffery
Quoted 12 lines

The registers for the bt-bmc device live under the Aspeed LPC controller. Devicetree bindings have recently been introduced for the LPC controller where the "host" portion of the LPC register space is described as a syscon device. Future devicetrees describing the bt-bmc device should nest its node under the appropriate "simple-mfd", "syscon" compatible node.

This change allows the bt-bmc driver to function with both syscon and non-syscon- based devicetree descriptions by always using a regmap for register access, either retrieved from the parent syscon device or instantiated if none exists.

Quoted 7 lines
Quoted 4 lines

The patch has been tested on an OpenPOWER Palmetto machine, successfully booting, rebooting and powering down the host.

It would be nice to have an example of the associated binding.? I did not see it.

Essentially because the approach of the patch means there's no required change to the bindings documentation. So, pulling together the various patches I've sent out, a partial devicetree using the new bindings might look something like:

lpc: lpc at 1e789000 {
	compatible = "aspeed,ast2500-lpc", "simple-mfd";
	reg = <0x1e789000 0x1000>;

	#address-cells = <1>;
	#size-cells = <1>;
	ranges = <0 0x1e789000 0x1000>;

	lpc_bmc: lpc-bmc at 0 {
		compatible = "aspeed,ast2500-lpc-bmc";
		reg = <0x0 0x80>;
		reg-io-width = <1>;
	};

	lpc_host: lpc-host at 80 {
		compatible = "aspeed,ast2500-lpc-host", "simple-mfd", "syscon";
		reg = <0x80 0x1e0>;

		#address-cells = <1>;
		#size-cells = <1>;
		ranges = <0 0x80 0x1e0>;

		reg-io-width = <4>;

		ibt: ibt at c0 {
			compatible = "aspeed,ast2400-bt-bmc";
			reg = <0xc0 0x18>;
			interrupts = <8>;
		};
	};
};

It's a bit tedious, but as mentioned in the commit message we need a way to arbitrate access to other registers in the "host" portion of the LPC controller amongst other complications, and this layout gives us that capability without breaking any existing bindings.

Andrew

Quoted 193 lines

A part from that :

Quoted 1 line

Thanks,

C.

Quoted 183 lines

---
?drivers/char/ipmi/Kconfig??|??1 +
?drivers/char/ipmi/bt-bmc.c | 82 ++++++++++++++++++++++++++++++++++------------ ?2 files changed, 62 insertions(+), 21 deletions(-)

drivers/char/ipmi/Kconfig +0 -0
index 7f816655cbbf..b5d48d9af124 100644
@@ -79,6 +79,7 @@ endif # IPMI_HANDLER

?
?config ASPEED_BT_IPMI_BMC

Quoted 1 line
Quoted 1 line

? depends on ARCH_ASPEED

+????????depends on REGMAP && REGMAP_MMIO && MFD_SYSCON

Quoted 3 lines
Quoted 3 lines

? tristate "BT IPMI bmc driver"
? help
? ??Provides a driver for the BT (Block Transfer) IPMI interface

drivers/char/ipmi/bt-bmc.c +0 -0
index fc9e8891eae3..ca1e20f6c6c5 100644
@@ -12,10 +12,13 @@

?#include <linux/errno.h>
?#include <linux/interrupt.h>
?#include <linux/io.h>
+#include <linux/mfd/syscon.h>
?#include <linux/miscdevice.h>
?#include <linux/module.h>
+#include <linux/of.h>
?#include <linux/platform_device.h>
?#include <linux/poll.h>
+#include <linux/regmap.h>
?#include <linux/sched.h>
?#include <linux/timer.h>
?

drivers/char/ipmi/bt-bmc.c +0 -0
@@ -60,7 +63,8 @@
 ?struct bt_bmc {
 > > > > ?	struct device		dev;
 > > > > ?	struct miscdevice	miscdev;
 > > > > -	void __iomem		*base;
 > > > > +	struct regmap		*map;
 > > > > +	int			offset;
 > > > > ?	int			irq;
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

? wait_queue_head_t queue;
? struct timer_list poll_timer;

drivers/char/ipmi/bt-bmc.c +0 -0
@@ -69,14 +73,31 @@ struct bt_bmc {

?
?static atomic_t open_count = ATOMIC_INIT(0);
?
+static struct regmap_config bt_regmap_cfg = {

Quoted 3 lines
Quoted 3 lines
drivers/char/ipmi/bt-bmc.c +3 -0
+	.reg_bits = 32,
+	.val_bits = 32,
+	.reg_stride = 4,
drivers/char/ipmi/bt-bmc.c +2 -0
+};
+

?static u8 bt_inb(struct bt_bmc *bt_bmc, int reg)
?{

Quoted 3 lines

drivers/char/ipmi/bt-bmc.c struct bt_bmc { · line 85

Quoted 3 lines
drivers/char/ipmi/bt-bmc.c +2 -1
-	return ioread8(bt_bmc->base + reg);
+	uint32_t val = 0;
+	int rc;

+

Quoted 3 lines

drivers/char/ipmi/bt-bmc.c struct bt_bmc { · line 89

Quoted 3 lines
drivers/char/ipmi/bt-bmc.c +3 -0
+	rc = regmap_read(bt_bmc->map, bt_bmc->offset + reg, &val);
+	WARN(rc != 0, "%s:%d: regmap_read() failed: %d\n",
+			__FILE__, __LINE__, rc);

+

Quoted 1 line

drivers/char/ipmi/bt-bmc.c struct bt_bmc { · line 91

Quoted 1 line
drivers/char/ipmi/bt-bmc.c +1 -0
+	return rc == 0 ? (u8) val : 0;

?}
?
?static void bt_outb(struct bt_bmc *bt_bmc, u8 data, int reg) ?{

Quoted 2 lines

drivers/char/ipmi/bt-bmc.c struct bt_bmc { · line 96

Quoted 2 lines
drivers/char/ipmi/bt-bmc.c +1 -1
-	iowrite8(data, bt_bmc->base + reg);
+	int rc;

+

Quoted 3 lines

drivers/char/ipmi/bt-bmc.c struct bt_bmc { · line 100

Quoted 3 lines
drivers/char/ipmi/bt-bmc.c +3 -0
+	rc = regmap_write(bt_bmc->map, bt_bmc->offset + reg, data);
+	WARN(rc != 0, "%s:%d: regmap_write() failed: %d\n",
+			__FILE__, __LINE__, rc);

?}
?
?static void clr_rd_ptr(struct bt_bmc *bt_bmc)

drivers/char/ipmi/bt-bmc.c +1 -0
@@ -367,14 +388,18 @@ static irqreturn_t bt_bmc_irq(int irq, void *arg)
 ?{
 > > ?	struct bt_bmc *bt_bmc = arg;
 > > ?	u32 reg;
 > > +	int rc;
+
 > > +	rc = regmap_read(bt_bmc->map, bt_bmc->offset + BT_CR2, &reg);
 > > +	if (rc)
 > > +		return IRQ_NONE;

?

Quoted 4 lines
Quoted 4 lines
drivers/char/ipmi/bt-bmc.c +0 -1
-	reg = ioread32(bt_bmc->base + BT_CR2);

? reg &= BT_CR2_IRQ_H2B | BT_CR2_IRQ_HBUSY;
? if (!reg)
? return IRQ_NONE;

?

Quoted 3 lines

drivers/char/ipmi/bt-bmc.c static irqreturn_t bt_bmc_irq(int irq, void *arg) · line 402

Quoted 3 lines

? /* ack pending IRQs */

drivers/char/ipmi/bt-bmc.c +1 -1
-	iowrite32(reg, bt_bmc->base + BT_CR2);
+	regmap_write(bt_bmc->map, bt_bmc->offset + BT_CR2, reg);

?

Quoted 2 lines
Quoted 2 lines

? wake_up(&bt_bmc->queue);
? return IRQ_HANDLED;

drivers/char/ipmi/bt-bmc.c +0 -0
@@ -384,7 +409,6 @@ static int bt_bmc_config_irq(struct bt_bmc *bt_bmc,
 > > ?			?????struct platform_device *pdev)
 ?{
 > > ?	struct device *dev = &pdev->dev;
 > > -	u32 reg;
 > > ?	int rc;

?

Quoted 1 line
Quoted 1 line

? bt_bmc->irq = platform_get_irq(pdev, 0);

drivers/char/ipmi/bt-bmc.c +0 -0
@@ -405,18 +429,17 @@ static int bt_bmc_config_irq(struct bt_bmc *bt_bmc,
Quoted 9 lines

drivers/char/ipmi/bt-bmc.c static int bt_bmc_config_irq(struct bt_bmc *bt_bmc, · line 434

Quoted 9 lines

? ?* will be cleared (along with B2H) when we can write the next
? ?* message to the BT buffer
? ?*/

drivers/char/ipmi/bt-bmc.c +3 -3
-	reg = ioread32(bt_bmc->base + BT_CR1);
-	reg |= BT_CR1_IRQ_H2B | BT_CR1_IRQ_HBUSY;
-	iowrite32(reg, bt_bmc->base + BT_CR1);
+	rc = regmap_update_bits(bt_bmc->map, bt_bmc->offset + BT_CR1,
+				(BT_CR1_IRQ_H2B | BT_CR1_IRQ_HBUSY),
+				(BT_CR1_IRQ_H2B | BT_CR1_IRQ_HBUSY));

?

Quoted 2 lines

drivers/char/ipmi/bt-bmc.c static int bt_bmc_config_irq(struct bt_bmc *bt_bmc, · line 436

Quoted 2 lines
drivers/char/ipmi/bt-bmc.c +1 -1
-	return 0;
+	return rc;

?}
?
?static int bt_bmc_probe(struct platform_device *pdev) ?{

Quoted 4 lines
Quoted 4 lines

? struct bt_bmc *bt_bmc;
? struct device *dev;

drivers/char/ipmi/bt-bmc.c +0 -1
-	struct resource *res;

? int rc;

?

Quoted 1 line
Quoted 1 line

? if (!pdev || !pdev->dev.of_node)

drivers/char/ipmi/bt-bmc.c +0 -0
@@ -431,10 +454,27 @@ static int bt_bmc_probe(struct platform_device *pdev)

?

Quoted 1 line
Quoted 1 line

? dev_set_drvdata(&pdev->dev, bt_bmc);

?

Quoted 8 lines

drivers/char/ipmi/bt-bmc.c static int bt_bmc_probe(struct platform_device *pdev) · line 460

Quoted 8 lines
drivers/char/ipmi/bt-bmc.c +4 -4
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	bt_bmc->base = devm_ioremap_resource(&pdev->dev, res);
-	if (IS_ERR(bt_bmc->base))
-		return PTR_ERR(bt_bmc->base);
+	bt_bmc->map = syscon_node_to_regmap(pdev->dev.parent->of_node);
+	if (IS_ERR(bt_bmc->map)) {
+		struct resource *res;
+		void __iomem *base;

+

Quoted 8 lines

drivers/char/ipmi/bt-bmc.c static int bt_bmc_probe(struct platform_device *pdev) · line 469

Quoted 8 lines
drivers/char/ipmi/bt-bmc.c +8 -0
+		/*
+		?* Assume it's not the MFD-based devicetree description, in
+		?* which case generate a regmap ourselves
+		?*/
+		res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+		base = devm_ioremap_resource(&pdev->dev, res);
+		if (IS_ERR(base))
+			return PTR_ERR(base);

+

Quoted 7 lines

drivers/char/ipmi/bt-bmc.c static int bt_bmc_probe(struct platform_device *pdev) · line 477

Quoted 7 lines
drivers/char/ipmi/bt-bmc.c +7 -0
+		bt_bmc->map = devm_regmap_init_mmio(dev, base, &bt_regmap_cfg);
+		bt_bmc->offset = 0;
+	} else {
+		rc = of_property_read_u32(dev->of_node, "reg", &bt_bmc->offset);
+		if (rc)
+			return rc;
+	}

?

Quoted 2 lines
Quoted 2 lines

? mutex_init(&bt_bmc->mutex);
? init_waitqueue_head(&bt_bmc->queue);

drivers/char/ipmi/bt-bmc.c +0 -0
@@ -461,12 +501,12 @@ static int bt_bmc_probe(struct platform_device *pdev)
 > > ?		add_timer(&bt_bmc->poll_timer);
 > > ?	}

?

Quoted 4 lines
Quoted 4 lines
(quoted diff) +0 -4
-	iowrite32((BT_IO_BASE << BT_CR0_IO_BASE) |
-		??(BT_IRQ << BT_CR0_IRQ) |
-		??BT_CR0_EN_CLR_SLV_RDP |
-		??BT_CR0_EN_CLR_SLV_WRP |
Quoted 8 lines

Review

Quoted 8 lines
(quoted diff) +6 -2
-		??BT_CR0_ENABLE_IBT,
-		??bt_bmc->base + BT_CR0);
+	regmap_write(bt_bmc->map, bt_bmc->offset + BT_CR0,
+		?????(BT_IO_BASE << BT_CR0_IO_BASE) |
+		?????(BT_IRQ << BT_CR0_IRQ) |
+		?????BT_CR0_EN_CLR_SLV_RDP |
+		?????BT_CR0_EN_CLR_SLV_WRP |
+		?????BT_CR0_ENABLE_IBT);

?

Quoted 1 line
Quoted 1 line

? clr_b_busy(bt_bmc);

?

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: This is a digitally signed message part
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20161207/5506c9cf/attachment-0001.sig>

#4 lore raw
In reply to Cédric Le Goater

Hi Cory,

Quoted 18 lines · C?dric Le Goater

[ this is a resend bc of some mailing list issues]?

Quoted 15 lines · Andrew Jeffery

The registers for the bt-bmc device live under the Aspeed LPC controller. Devicetree bindings have recently been introduced for the LPC controller where the "host" portion of the LPC register space is described as a syscon device. Future devicetrees describing the bt-bmc device should nest its node under the appropriate "simple-mfd", "syscon" compatible node.

This change allows the bt-bmc driver to function with both syscon and non-syscon- based devicetree descriptions by always using a regmap for register access, either retrieved from the parent syscon device or instantiated if none exists.

The patch has been tested on an OpenPOWER Palmetto machine, successfully booting, rebooting and powering down the host.

Quoted 6 lines
Quoted 1 line

It would be nice to have an example of the associated binding.? I did not see it. A part from that :

Will this make it into 4.11?

Cheers,

Andrew
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: This is a digitally signed message part
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170220/1e44fe24/attachment.sig>

#5 lore raw
Quoted 21 lines · Andrew Jeffery

Hi Cory,

Quoted 18 lines · C?dric Le Goater

[ this is a resend bc of some mailing list issues]

Quoted 15 lines · Andrew Jeffery

The registers for the bt-bmc device live under the Aspeed LPC controller. Devicetree bindings have recently been introduced for the LPC controller where the "host" portion of the LPC register space is described as a syscon device. Future devicetrees describing the bt-bmc device should nest its node under the appropriate "simple-mfd", "syscon" compatible node.

This change allows the bt-bmc driver to function with both syscon and non-syscon- based devicetree descriptions by always using a regmap for register access, either retrieved from the parent syscon device or instantiated if none exists.

The patch has been tested on an OpenPOWER Palmetto machine, successfully booting, rebooting and powering down the host.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

It would be nice to have an example of the associated binding. I did not see it. A part from that :

Will this make it into 4.11?

I thought you were doing a v2 with a few little fixes. Get it to me quickly, if you can.

-corey

Quoted 3 lines

Cheers,

Andrew

#6 lore raw
Quoted 27 lines · Corey Minyard
Quoted 26 lines · Andrew Jeffery

Hi Cory,

Quoted 23 lines · C?dric Le Goater

[ this is a resend bc of some mailing list issues]

Quoted 12 lines · Andrew Jeffery

The registers for the bt-bmc device live under the Aspeed LPC controller. Devicetree bindings have recently been introduced for the LPC controller where the "host" portion of the LPC register space is described as a syscon device. Future devicetrees describing the bt-bmc device should nest its node under the appropriate "simple-mfd", "syscon" compatible node.

This change allows the bt-bmc driver to function with both syscon and non-syscon- based devicetree descriptions by always using a regmap for register access, either retrieved from the parent syscon device or instantiated if none exists.

Quoted 4 lines

The patch has been tested on an OpenPOWER Palmetto machine, successfully booting, rebooting and powering down the host.

It would be nice to have an example of the associated binding. I did not see it. A part from that :

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Will this make it into 4.11?

I thought you were doing a v2 with a few little fixes.??Get it to me? quickly, if you can.

Reading back it was a bit ambiguous. No worries, I'll roll in the small fixes and send a v2.

Cheers,

Andrew
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: This is a digitally signed message part
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170221/a3cf5595/attachment.sig>

#7 lore raw
Quoted 27 lines · Andrew Jeffery
Quoted 26 lines · Corey Minyard
Quoted 25 lines · Andrew Jeffery

Hi Cory,

Quoted 22 lines · C?dric Le Goater

[ this is a resend bc of some mailing list issues]

Quoted 12 lines · Andrew Jeffery

The registers for the bt-bmc device live under the Aspeed LPC controller. Devicetree bindings have recently been introduced for the LPC controller where the "host" portion of the LPC register space is described as a syscon device. Future devicetrees describing the bt-bmc device should nest its node under the appropriate "simple-mfd", "syscon" compatible node.

This change allows the bt-bmc driver to function with both syscon and non-syscon- based devicetree descriptions by always using a regmap for register access, either retrieved from the parent syscon device or instantiated if none exists.

Quoted 4 lines

The patch has been tested on an OpenPOWER Palmetto machine, successfully booting, rebooting and powering down the host.

It would be nice to have an example of the associated binding. I did not see it. A part from that :

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Quoted 1 line

Will this make it into 4.11?

I thought you were doing a v2 with a few little fixes. Get it to me quickly, if you can.

Reading back it was a bit ambiguous. No worries, I'll roll in the small fixes and send a v2.

Yeah, it was, sorry, I should have been clear there.

I'll leave it in the linux-next tree for a bit, then ask Linus for a pull.

Thanks,

-corey

Quoted 3 lines

Cheers,

Andrew

#8 lore raw
In reply to Andrew Jeffery
Quoted 26 lines · Andrew Jeffery

The registers for the bt-bmc device live under the Aspeed LPC controller. Devicetree bindings have recently been introduced for the LPC controller where the "host" portion of the LPC register space is described as a syscon device. Future devicetrees describing the bt-bmc device should nest its node under the appropriate "simple-mfd", "syscon" compatible node.

This change allows the bt-bmc driver to function with both syscon and non-syscon- based devicetree descriptions by always using a regmap for register access, either retrieved from the parent syscon device or instantiated if none exists.

The patch has been tested on an OpenPOWER Palmetto machine, successfully booting, rebooting and powering down the host.

---
 drivers/char/ipmi/Kconfig  |  1 +
 drivers/char/ipmi/bt-bmc.c | 82 ++++++++++++++++++++++++++++++++++------------
 2 files changed, 62 insertions(+), 21 deletions(-)
drivers/char/ipmi/Kconfig +0 -0
index 7f816655cbbf..b5d48d9af124 100644

drivers/char/ipmi/Kconfig endif # IPMI_HANDLER · line 81

Quoted 3 lines
drivers/char/ipmi/Kconfig +0 -0
@@ -79,6 +79,7 @@ endif # IPMI_HANDLER
 
 config ASPEED_BT_IPMI_BMC
        depends on ARCH_ASPEED

If you do a v2 of this series it would be great to add || COMPILE_TEST here.

Quoted 33 lines
drivers/char/ipmi/Kconfig +1 -0
+        depends on REGMAP && REGMAP_MMIO && MFD_SYSCON
        tristate "BT IPMI bmc driver"
        help
          Provides a driver for the BT (Block Transfer) IPMI interface
drivers/char/ipmi/bt-bmc.c +5 -1
index fc9e8891eae3..ca1e20f6c6c5 100644
@@ -12,10 +12,13 @@
 #include <linux/errno.h>
 #include <linux/interrupt.h>
 #include <linux/io.h>
+#include <linux/mfd/syscon.h>
 #include <linux/miscdevice.h>
 #include <linux/module.h>
+#include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/poll.h>
+#include <linux/regmap.h>
 #include <linux/sched.h>
 #include <linux/timer.h>
 
@@ -60,7 +63,8 @@
 struct bt_bmc {
        struct device           dev;
        struct miscdevice       miscdev;
-       void __iomem            *base;
+       struct regmap           *map;
+       int                     offset;
        int                     irq;
        wait_queue_head_t       queue;
        struct timer_list       poll_timer;

drivers/char/ipmi/bt-bmc.c struct bt_bmc { · line 76

Quoted 4 lines
drivers/char/ipmi/bt-bmc.c +1 -0
@@ -69,14 +73,31 @@ struct bt_bmc {
 
 static atomic_t open_count = ATOMIC_INIT(0);
 
+static struct regmap_config bt_regmap_cfg = {

const?

Quoted 4 lines
drivers/char/ipmi/bt-bmc.c +4 -0
+       .reg_bits = 32,
+       .val_bits = 32,
+       .reg_stride = 4,
+};

drivers/char/ipmi/bt-bmc.c struct bt_bmc { · line 89

Quoted 10 lines
drivers/char/ipmi/bt-bmc.c +7 -1
+
 static u8 bt_inb(struct bt_bmc *bt_bmc, int reg)
 {
-       return ioread8(bt_bmc->base + reg);
+       uint32_t val = 0;
+       int rc;
+
+       rc = regmap_read(bt_bmc->map, bt_bmc->offset + reg, &val);
+       WARN(rc != 0, "%s:%d: regmap_read() failed: %d\n",
+                       __FILE__, __LINE__, rc);

Under what circumstances do we expect the read to fail?

This isn't much cleaner, but I prefer it slightly:

rc = regmap_read(bt_bmc->map, bt_bmc->offset + reg, &val); if (rc) {
dev_warn(bt_bmc->dev, "read failed %d\n", rc); return rc;
}

return val;

Quoted 45 lines
drivers/char/ipmi/bt-bmc.c +13 -4
+
+       return rc == 0 ? (u8) val : 0;
 }
 
 static void bt_outb(struct bt_bmc *bt_bmc, u8 data, int reg)
 {
-       iowrite8(data, bt_bmc->base + reg);
+       int rc;
+
+       rc = regmap_write(bt_bmc->map, bt_bmc->offset + reg, data);
+       WARN(rc != 0, "%s:%d: regmap_write() failed: %d\n",
+                       __FILE__, __LINE__, rc);
 }
 
 static void clr_rd_ptr(struct bt_bmc *bt_bmc)
@@ -367,14 +388,18 @@ static irqreturn_t bt_bmc_irq(int irq, void *arg)
 {
        struct bt_bmc *bt_bmc = arg;
        u32 reg;
+       int rc;
+
+       rc = regmap_read(bt_bmc->map, bt_bmc->offset + BT_CR2, &reg);
+       if (rc)
+               return IRQ_NONE;
 
-       reg = ioread32(bt_bmc->base + BT_CR2);
        reg &= BT_CR2_IRQ_H2B | BT_CR2_IRQ_HBUSY;
        if (!reg)
                return IRQ_NONE;
 
        /* ack pending IRQs */
-       iowrite32(reg, bt_bmc->base + BT_CR2);
+       regmap_write(bt_bmc->map, bt_bmc->offset + BT_CR2, reg);
 
        wake_up(&bt_bmc->queue);
        return IRQ_HANDLED;
@@ -384,7 +409,6 @@ static int bt_bmc_config_irq(struct bt_bmc *bt_bmc,
                             struct platform_device *pdev)
 {
        struct device *dev = &pdev->dev;
-       u32 reg;
        int rc;
 
        bt_bmc->irq = platform_get_irq(pdev, 0);

drivers/char/ipmi/bt-bmc.c static int bt_bmc_config_irq(struct bt_bmc *bt_bmc, · line 434

Quoted 9 lines
drivers/char/ipmi/bt-bmc.c +3 -3
@@ -405,18 +429,17 @@ static int bt_bmc_config_irq(struct bt_bmc *bt_bmc,
         * will be cleared (along with B2H) when we can write the next
         * message to the BT buffer
         */
-       reg = ioread32(bt_bmc->base + BT_CR1);
-       reg |= BT_CR1_IRQ_H2B | BT_CR1_IRQ_HBUSY;
-       iowrite32(reg, bt_bmc->base + BT_CR1);
+       rc = regmap_update_bits(bt_bmc->map, bt_bmc->offset + BT_CR1,
+                               (BT_CR1_IRQ_H2B | BT_CR1_IRQ_HBUSY),
+                               (BT_CR1_IRQ_H2B | BT_CR1_IRQ_HBUSY));

You could drop the ( ) around the flags if you want.

Quoted 67 lines
drivers/char/ipmi/bt-bmc.c +28 -13
-       return 0;
+       return rc;
 }
 
 static int bt_bmc_probe(struct platform_device *pdev)
 {
        struct bt_bmc *bt_bmc;
        struct device *dev;
-       struct resource *res;
        int rc;
 
        if (!pdev || !pdev->dev.of_node)
@@ -431,10 +454,27 @@ static int bt_bmc_probe(struct platform_device *pdev)
 
        dev_set_drvdata(&pdev->dev, bt_bmc);
 
-       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-       bt_bmc->base = devm_ioremap_resource(&pdev->dev, res);
-       if (IS_ERR(bt_bmc->base))
-               return PTR_ERR(bt_bmc->base);
+       bt_bmc->map = syscon_node_to_regmap(pdev->dev.parent->of_node);
+       if (IS_ERR(bt_bmc->map)) {
+               struct resource *res;
+               void __iomem *base;
+
+               /*
+                * Assume it's not the MFD-based devicetree description, in
+                * which case generate a regmap ourselves
+                */
+               res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+               base = devm_ioremap_resource(&pdev->dev, res);
+               if (IS_ERR(base))
+                       return PTR_ERR(base);
+
+               bt_bmc->map = devm_regmap_init_mmio(dev, base, &bt_regmap_cfg);
+               bt_bmc->offset = 0;
+       } else {
+               rc = of_property_read_u32(dev->of_node, "reg", &bt_bmc->offset);
+               if (rc)
+                       return rc;
+       }
 
        mutex_init(&bt_bmc->mutex);
        init_waitqueue_head(&bt_bmc->queue);
@@ -461,12 +501,12 @@ static int bt_bmc_probe(struct platform_device *pdev)
                add_timer(&bt_bmc->poll_timer);
        }
 
-       iowrite32((BT_IO_BASE << BT_CR0_IO_BASE) |
-                 (BT_IRQ << BT_CR0_IRQ) |
-                 BT_CR0_EN_CLR_SLV_RDP |
-                 BT_CR0_EN_CLR_SLV_WRP |
-                 BT_CR0_ENABLE_IBT,
-                 bt_bmc->base + BT_CR0);
+       regmap_write(bt_bmc->map, bt_bmc->offset + BT_CR0,
+                    (BT_IO_BASE << BT_CR0_IO_BASE) |
+                    (BT_IRQ << BT_CR0_IRQ) |
+                    BT_CR0_EN_CLR_SLV_RDP |
+                    BT_CR0_EN_CLR_SLV_WRP |
+                    BT_CR0_ENABLE_IBT);
 
        clr_b_busy(bt_bmc);
 
--

2.9.3

#9 lore raw
Quoted 67 lines · Joel Stanley
Quoted 28 lines · Andrew Jeffery

The registers for the bt-bmc device live under the Aspeed LPC controller. Devicetree bindings have recently been introduced for the LPC controller where the "host" portion of the LPC register space is described as a syscon device. Future devicetrees describing the bt-bmc device should nest its node under the appropriate "simple-mfd", "syscon" compatible node.

This change allows the bt-bmc driver to function with both syscon and non-syscon- based devicetree descriptions by always using a regmap for register access, either retrieved from the parent syscon device or instantiated if none exists.

The patch has been tested on an OpenPOWER Palmetto machine, successfully booting, rebooting and powering down the host.

Quoted 1 line
Quoted 1 line

---
?drivers/char/ipmi/Kconfig??|??1 +
?drivers/char/ipmi/bt-bmc.c | 82 ++++++++++++++++++++++++++++++++++------------ ?2 files changed, 62 insertions(+), 21 deletions(-)

drivers/char/ipmi/Kconfig +0 -0
index 7f816655cbbf..b5d48d9af124 100644
@@ -79,6 +79,7 @@ endif # IPMI_HANDLER
 
Quoted 2 lines

?config ASPEED_BT_IPMI_BMC
????????depends on ARCH_ASPEED

If you do a v2 of this series it would be great to add || COMPILE_TEST here.

Quoted 34 lines

+????????depends on REGMAP && REGMAP_MMIO && MFD_SYSCON ????????tristate "BT IPMI bmc driver"
????????help
??????????Provides a driver for the BT (Block Transfer) IPMI interface

drivers/char/ipmi/bt-bmc.c +0 -0
index fc9e8891eae3..ca1e20f6c6c5 100644
@@ -12,10 +12,13 @@

?#include <linux/errno.h>
?#include <linux/interrupt.h>
?#include <linux/io.h>
+#include <linux/mfd/syscon.h>
?#include <linux/miscdevice.h>
?#include <linux/module.h>
+#include <linux/of.h>
?#include <linux/platform_device.h>
?#include <linux/poll.h>
+#include <linux/regmap.h>
?#include <linux/sched.h>
?#include <linux/timer.h>

drivers/char/ipmi/bt-bmc.c +2 -1
@@ -60,7 +63,8 @@
 ?struct bt_bmc {
 ????????struct device???????????dev;
 ????????struct miscdevice???????miscdev;
-???????void __iomem????????????*base;
+???????struct regmap???????????*map;
+???????int?????????????????????offset;
 ????????int?????????????????????irq;
 ????????wait_queue_head_t???????queue;
 ????????struct timer_list???????poll_timer;
@@ -69,14 +73,31 @@ struct bt_bmc {
 
Quoted 5 lines

drivers/char/ipmi/bt-bmc.c struct bt_bmc { · line 76

Quoted 3 lines
drivers/char/ipmi/bt-bmc.c +1 -0
 ?static atomic_t open_count = ATOMIC_INIT(0);
 
+static struct regmap_config bt_regmap_cfg = {

const?

Good point. Is it worth a v2?

Quoted 17 lines
Quoted 5 lines
drivers/char/ipmi/bt-bmc.c +4 -0
+???????.reg_bits = 32,
+???????.val_bits = 32,
+???????.reg_stride = 4,
+};

drivers/char/ipmi/bt-bmc.c struct bt_bmc { · line 89

Quoted 10 lines
drivers/char/ipmi/bt-bmc.c +7 -1
+
 ?static u8 bt_inb(struct bt_bmc *bt_bmc, int reg)
 ?{
-???????return ioread8(bt_bmc->base + reg);
+???????uint32_t val = 0;
+???????int rc;
+
+???????rc = regmap_read(bt_bmc->map, bt_bmc->offset + reg, &val);
+???????WARN(rc != 0, "%s:%d: regmap_read() failed: %d\n",
+???????????????????????__FILE__, __LINE__, rc);

Under what circumstances do we expect the read to fail?

By the regmap_read() implementation for MMIO it should never fail. If it does, then we should tell someone about it.

Quoted 10 lines

This isn't much cleaner, but I prefer it slightly:

rc = regmap_read(bt_bmc->map, bt_bmc->offset + reg, &val); if (rc) {
???dev_warn(bt_bmc->dev, "read failed %d\n", rc); ???return rc;
}

return val;

bt_inb() currently returns a u8 type, and as such no caller performs error checking. While your suggestion might seem slightly preferable, it feels likely "slightly preferable" might fail to take into account the cascading effect of changing the return type and testing for errors at each of the (transitive) call-sites.

I think the additional code required makes your suggestion less attractive given that the call should never fail.

If you decide you feel strongly about it I can make the change.

Quoted 44 lines
Quoted 44 lines
drivers/char/ipmi/bt-bmc.c +12 -2
+
+???????return rc == 0 ? (u8) val : 0;
 ?}
 
 ?static void bt_outb(struct bt_bmc *bt_bmc, u8 data, int reg)
 ?{
-???????iowrite8(data, bt_bmc->base + reg);
+???????int rc;
+
+???????rc = regmap_write(bt_bmc->map, bt_bmc->offset + reg, data);
+???????WARN(rc != 0, "%s:%d: regmap_write() failed: %d\n",
+???????????????????????__FILE__, __LINE__, rc);
 ?}
 
 ?static void clr_rd_ptr(struct bt_bmc *bt_bmc)
@@ -367,14 +388,18 @@ static irqreturn_t bt_bmc_irq(int irq, void *arg)
 ?{
 ????????struct bt_bmc *bt_bmc = arg;
 ????????u32 reg;
+???????int rc;
+
+???????rc = regmap_read(bt_bmc->map, bt_bmc->offset + BT_CR2, &reg);
+???????if (rc)
+???????????????return IRQ_NONE;
 
-???????reg = ioread32(bt_bmc->base + BT_CR2);
 ????????reg &= BT_CR2_IRQ_H2B | BT_CR2_IRQ_HBUSY;
 ????????if (!reg)
 ????????????????return IRQ_NONE;
 

????????/* ack pending IRQs */
-???????iowrite32(reg, bt_bmc->base + BT_CR2); +???????regmap_write(bt_bmc->map, bt_bmc->offset + BT_CR2, reg);

????????wake_up(&bt_bmc->queue);
????????return IRQ_HANDLED;

drivers/char/ipmi/bt-bmc.c +0 -1
@@ -384,7 +409,6 @@ static int bt_bmc_config_irq(struct bt_bmc *bt_bmc,
 ?????????????????????????????struct platform_device *pdev)
 ?{
 ????????struct device *dev = &pdev->dev;
-???????u32 reg;
 ????????int rc;
 
Quoted 13 lines
Quoted 11 lines
drivers/char/ipmi/bt-bmc.c +0 -0
 ????????bt_bmc->irq = platform_get_irq(pdev, 0);
@@ -405,18 +429,17 @@ static int bt_bmc_config_irq(struct bt_bmc *bt_bmc,

?????????* will be cleared (along with B2H) when we can write the next ?????????* message to the BT buffer
?????????*/
-???????reg = ioread32(bt_bmc->base + BT_CR1);
-???????reg |= BT_CR1_IRQ_H2B | BT_CR1_IRQ_HBUSY; -???????iowrite32(reg, bt_bmc->base + BT_CR1);
+???????rc = regmap_update_bits(bt_bmc->map, bt_bmc->offset + BT_CR1, +???????????????????????????????(BT_CR1_IRQ_H2B | BT_CR1_IRQ_HBUSY), +???????????????????????????????(BT_CR1_IRQ_H2B | BT_CR1_IRQ_HBUSY));

You could drop the ( ) around the flags if you want.

I think I wrote it this way when I was toying with different line- wraps, but regardless I think they are a nice visual queue.

Andrew

Quoted 63 lines
Quoted 63 lines

-???????return 0;
+???????return rc;
?}

?static int bt_bmc_probe(struct platform_device *pdev) ?{
????????struct bt_bmc *bt_bmc;
????????struct device *dev;
-???????struct resource *res;
????????int rc;

????????if (!pdev || !pdev->dev.of_node)

drivers/char/ipmi/bt-bmc.c +27 -10
@@ -431,10 +454,27 @@ static int bt_bmc_probe(struct platform_device *pdev)
 
 ????????dev_set_drvdata(&pdev->dev, bt_bmc);
 
-???????res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-???????bt_bmc->base = devm_ioremap_resource(&pdev->dev, res);
-???????if (IS_ERR(bt_bmc->base))
-???????????????return PTR_ERR(bt_bmc->base);
+???????bt_bmc->map = syscon_node_to_regmap(pdev->dev.parent->of_node);
+???????if (IS_ERR(bt_bmc->map)) {
+???????????????struct resource *res;
+???????????????void __iomem *base;
+
+???????????????/*
+????????????????* Assume it's not the MFD-based devicetree description, in
+????????????????* which case generate a regmap ourselves
+????????????????*/
+???????????????res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+???????????????base = devm_ioremap_resource(&pdev->dev, res);
+???????????????if (IS_ERR(base))
+???????????????????????return PTR_ERR(base);
+
+???????????????bt_bmc->map = devm_regmap_init_mmio(dev, base, &bt_regmap_cfg);
+???????????????bt_bmc->offset = 0;
+???????} else {
+???????????????rc = of_property_read_u32(dev->of_node, "reg", &bt_bmc->offset);
+???????????????if (rc)
+???????????????????????return rc;
+???????}
 
 ????????mutex_init(&bt_bmc->mutex);
 ????????init_waitqueue_head(&bt_bmc->queue);
@@ -461,12 +501,12 @@ static int bt_bmc_probe(struct platform_device *pdev)
 ????????????????add_timer(&bt_bmc->poll_timer);
 ????????}
 
-???????iowrite32((BT_IO_BASE << BT_CR0_IO_BASE) |
-?????????????????(BT_IRQ << BT_CR0_IRQ) |
-?????????????????BT_CR0_EN_CLR_SLV_RDP |
-?????????????????BT_CR0_EN_CLR_SLV_WRP |
-?????????????????BT_CR0_ENABLE_IBT,
-?????????????????bt_bmc->base + BT_CR0);
+???????regmap_write(bt_bmc->map, bt_bmc->offset + BT_CR0,
+????????????????????(BT_IO_BASE << BT_CR0_IO_BASE) |
+????????????????????(BT_IRQ << BT_CR0_IRQ) |
+????????????????????BT_CR0_EN_CLR_SLV_RDP |
+????????????????????BT_CR0_EN_CLR_SLV_WRP |
+????????????????????BT_CR0_ENABLE_IBT);
 
Quoted 5 lines
Quoted 5 lines
drivers/char/ipmi/bt-bmc.c +0 -1
 ????????clr_b_busy(bt_bmc);
 
--

2.9.3

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: This is a digitally signed message part
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20161214/bbfc992c/attachment-0001.sig>