Skip to content

Commit 396c84b

Browse files
shenkicminyard
authored andcommitted
ipmi: bt-bmc: Use registers directly
This driver was originally written to use the regmap abstraction with no clear benefit. As the registers are always mmio and there is no sharing of the region with other devices, we can safely read and write without the locking that regmap provides. This reduces the code size of the driver by about 25%. Signed-off-by: Joel Stanley <[email protected]> Message-Id: <[email protected]> Signed-off-by: Corey Minyard <[email protected]>
1 parent 39ce735 commit 396c84b

File tree

1 file changed

+16
-52
lines changed

1 file changed

+16
-52
lines changed

drivers/char/ipmi/bt-bmc.c

Lines changed: 16 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@
88
#include <linux/errno.h>
99
#include <linux/interrupt.h>
1010
#include <linux/io.h>
11-
#include <linux/mfd/syscon.h>
1211
#include <linux/miscdevice.h>
1312
#include <linux/module.h>
1413
#include <linux/of.h>
1514
#include <linux/platform_device.h>
1615
#include <linux/poll.h>
17-
#include <linux/regmap.h>
1816
#include <linux/sched.h>
1917
#include <linux/timer.h>
2018

@@ -59,8 +57,7 @@
5957
struct bt_bmc {
6058
struct device dev;
6159
struct miscdevice miscdev;
62-
struct regmap *map;
63-
int offset;
60+
void __iomem *base;
6461
int irq;
6562
wait_queue_head_t queue;
6663
struct timer_list poll_timer;
@@ -69,29 +66,14 @@ struct bt_bmc {
6966

7067
static atomic_t open_count = ATOMIC_INIT(0);
7168

72-
static const struct regmap_config bt_regmap_cfg = {
73-
.reg_bits = 32,
74-
.val_bits = 32,
75-
.reg_stride = 4,
76-
};
77-
7869
static u8 bt_inb(struct bt_bmc *bt_bmc, int reg)
7970
{
80-
uint32_t val = 0;
81-
int rc;
82-
83-
rc = regmap_read(bt_bmc->map, bt_bmc->offset + reg, &val);
84-
WARN(rc != 0, "regmap_read() failed: %d\n", rc);
85-
86-
return rc == 0 ? (u8) val : 0;
71+
return readb(bt_bmc->base + reg);
8772
}
8873

8974
static void bt_outb(struct bt_bmc *bt_bmc, u8 data, int reg)
9075
{
91-
int rc;
92-
93-
rc = regmap_write(bt_bmc->map, bt_bmc->offset + reg, data);
94-
WARN(rc != 0, "regmap_write() failed: %d\n", rc);
76+
writeb(data, bt_bmc->base + reg);
9577
}
9678

9779
static void clr_rd_ptr(struct bt_bmc *bt_bmc)
@@ -376,18 +358,15 @@ static irqreturn_t bt_bmc_irq(int irq, void *arg)
376358
{
377359
struct bt_bmc *bt_bmc = arg;
378360
u32 reg;
379-
int rc;
380361

381-
rc = regmap_read(bt_bmc->map, bt_bmc->offset + BT_CR2, &reg);
382-
if (rc)
383-
return IRQ_NONE;
362+
reg = readl(bt_bmc->base + BT_CR2);
384363

385364
reg &= BT_CR2_IRQ_H2B | BT_CR2_IRQ_HBUSY;
386365
if (!reg)
387366
return IRQ_NONE;
388367

389368
/* ack pending IRQs */
390-
regmap_write(bt_bmc->map, bt_bmc->offset + BT_CR2, reg);
369+
writel(reg, bt_bmc->base + BT_CR2);
391370

392371
wake_up(&bt_bmc->queue);
393372
return IRQ_HANDLED;
@@ -398,6 +377,7 @@ static int bt_bmc_config_irq(struct bt_bmc *bt_bmc,
398377
{
399378
struct device *dev = &pdev->dev;
400379
int rc;
380+
u32 reg;
401381

402382
bt_bmc->irq = platform_get_irq_optional(pdev, 0);
403383
if (bt_bmc->irq < 0)
@@ -417,11 +397,11 @@ static int bt_bmc_config_irq(struct bt_bmc *bt_bmc,
417397
* will be cleared (along with B2H) when we can write the next
418398
* message to the BT buffer
419399
*/
420-
rc = regmap_update_bits(bt_bmc->map, bt_bmc->offset + BT_CR1,
421-
(BT_CR1_IRQ_H2B | BT_CR1_IRQ_HBUSY),
422-
(BT_CR1_IRQ_H2B | BT_CR1_IRQ_HBUSY));
400+
reg = readl(bt_bmc->base + BT_CR1);
401+
reg |= BT_CR1_IRQ_H2B | BT_CR1_IRQ_HBUSY;
402+
writel(reg, bt_bmc->base + BT_CR1);
423403

424-
return rc;
404+
return 0;
425405
}
426406

427407
static int bt_bmc_probe(struct platform_device *pdev)
@@ -439,25 +419,9 @@ static int bt_bmc_probe(struct platform_device *pdev)
439419

440420
dev_set_drvdata(&pdev->dev, bt_bmc);
441421

442-
bt_bmc->map = syscon_node_to_regmap(pdev->dev.parent->of_node);
443-
if (IS_ERR(bt_bmc->map)) {
444-
void __iomem *base;
445-
446-
/*
447-
* Assume it's not the MFD-based devicetree description, in
448-
* which case generate a regmap ourselves
449-
*/
450-
base = devm_platform_ioremap_resource(pdev, 0);
451-
if (IS_ERR(base))
452-
return PTR_ERR(base);
453-
454-
bt_bmc->map = devm_regmap_init_mmio(dev, base, &bt_regmap_cfg);
455-
bt_bmc->offset = 0;
456-
} else {
457-
rc = of_property_read_u32(dev->of_node, "reg", &bt_bmc->offset);
458-
if (rc)
459-
return rc;
460-
}
422+
bt_bmc->base = devm_platform_ioremap_resource(pdev, 0);
423+
if (IS_ERR(bt_bmc->base))
424+
return PTR_ERR(bt_bmc->base);
461425

462426
mutex_init(&bt_bmc->mutex);
463427
init_waitqueue_head(&bt_bmc->queue);
@@ -483,12 +447,12 @@ static int bt_bmc_probe(struct platform_device *pdev)
483447
add_timer(&bt_bmc->poll_timer);
484448
}
485449

486-
regmap_write(bt_bmc->map, bt_bmc->offset + BT_CR0,
487-
(BT_IO_BASE << BT_CR0_IO_BASE) |
450+
writel((BT_IO_BASE << BT_CR0_IO_BASE) |
488451
(BT_IRQ << BT_CR0_IRQ) |
489452
BT_CR0_EN_CLR_SLV_RDP |
490453
BT_CR0_EN_CLR_SLV_WRP |
491-
BT_CR0_ENABLE_IBT);
454+
BT_CR0_ENABLE_IBT,
455+
bt_bmc->base + BT_CR0);
492456

493457
clr_b_busy(bt_bmc);
494458

0 commit comments

Comments
 (0)