Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 494edd26 authored by Matti Vaittinen's avatar Matti Vaittinen Committed by Mark Brown
Browse files

regulator/mfd: Support ROHM BD71847 power management IC



BD71847 is reduced version of BD71837. DVS bucks 3 and 4 are
removed as is LDO7. Voltage ranges of some regulators are
expanded.

Add initial support for BD71847 with BD71837 driver.

Signed-off-by: default avatarMatti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
Acked-by: default avatarLee Jones <lee.jones@linaro.org>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent 2e0fe4d0
Loading
Loading
Loading
Loading
+29 −41
Original line number Diff line number Diff line
@@ -7,21 +7,16 @@
// Datasheet available from
// https://www.rohm.com/datasheet/BD71837MWV/bd71837mwv-e

#include <linux/gpio_keys.h>
#include <linux/i2c.h>
#include <linux/input.h>
#include <linux/interrupt.h>
#include <linux/mfd/rohm-bd718x7.h>
#include <linux/mfd/core.h>
#include <linux/module.h>
#include <linux/of_device.h>
#include <linux/regmap.h>

/*
 * gpio_keys.h requires definiton of bool. It is brought in
 * by above includes. Keep this as last until gpio_keys.h gets fixed.
 */
#include <linux/gpio_keys.h>

static const u8 supported_revisions[] = { 0xA2 /* BD71837 */ };
#include <linux/types.h>

static struct gpio_keys_button button = {
	.code = KEY_POWER,
@@ -41,8 +36,8 @@ static struct mfd_cell bd71837_mfd_cells[] = {
		.platform_data = &bd718xx_powerkey_data,
		.pdata_size = sizeof(bd718xx_powerkey_data),
	},
	{ .name = "bd71837-clk", },
	{ .name = "bd71837-pmic", },
	{ .name = "bd718xx-clk", },
	{ .name = "bd718xx-pmic", },
};

static const struct regmap_irq bd71837_irqs[] = {
@@ -61,16 +56,16 @@ static struct regmap_irq_chip bd71837_irq_chip = {
	.num_irqs = ARRAY_SIZE(bd71837_irqs),
	.num_regs = 1,
	.irq_reg_stride = 1,
	.status_base = BD71837_REG_IRQ,
	.mask_base = BD71837_REG_MIRQ,
	.ack_base = BD71837_REG_IRQ,
	.status_base = BD718XX_REG_IRQ,
	.mask_base = BD718XX_REG_MIRQ,
	.ack_base = BD718XX_REG_IRQ,
	.init_ack_masked = true,
	.mask_invert = false,
};

static const struct regmap_range pmic_status_range = {
	.range_min = BD71837_REG_IRQ,
	.range_max = BD71837_REG_POW_STATE,
	.range_min = BD718XX_REG_IRQ,
	.range_max = BD718XX_REG_POW_STATE,
};

static const struct regmap_access_table volatile_regs = {
@@ -82,7 +77,7 @@ static const struct regmap_config bd71837_regmap_config = {
	.reg_bits = 8,
	.val_bits = 8,
	.volatile_table = &volatile_regs,
	.max_register = BD71837_MAX_REGISTER - 1,
	.max_register = BD718XX_MAX_REGISTER - 1,
	.cache_type = REGCACHE_RBTREE,
};

@@ -90,8 +85,12 @@ static int bd71837_i2c_probe(struct i2c_client *i2c,
			    const struct i2c_device_id *id)
{
	struct bd71837 *bd71837;
	int ret, i;
	unsigned int val;
	int ret;

	if (!i2c->irq) {
		dev_err(&i2c->dev, "No IRQ configured\n");
		return -EINVAL;
	}

	bd71837 = devm_kzalloc(&i2c->dev, sizeof(struct bd71837), GFP_KERNEL);

@@ -99,12 +98,8 @@ static int bd71837_i2c_probe(struct i2c_client *i2c,
		return -ENOMEM;

	bd71837->chip_irq = i2c->irq;

	if (!bd71837->chip_irq) {
		dev_err(&i2c->dev, "No IRQ configured\n");
		return -EINVAL;
	}

	bd71837->chip_type = (unsigned int)(uintptr_t)
				of_device_get_match_data(&i2c->dev);
	bd71837->dev = &i2c->dev;
	dev_set_drvdata(&i2c->dev, bd71837);

@@ -114,20 +109,6 @@ static int bd71837_i2c_probe(struct i2c_client *i2c,
		return PTR_ERR(bd71837->regmap);
	}

	ret = regmap_read(bd71837->regmap, BD71837_REG_REV, &val);
	if (ret) {
		dev_err(&i2c->dev, "Read BD71837_REG_DEVICE failed\n");
		return ret;
	}
	for (i = 0; i < ARRAY_SIZE(supported_revisions); i++)
		if (supported_revisions[i] == val)
			break;

	if (i == ARRAY_SIZE(supported_revisions)) {
		dev_err(&i2c->dev, "Unsupported chip revision\n");
		return -ENODEV;
	}

	ret = devm_regmap_add_irq_chip(&i2c->dev, bd71837->regmap,
				       bd71837->chip_irq, IRQF_ONESHOT, 0,
				       &bd71837_irq_chip, &bd71837->irq_data);
@@ -138,7 +119,7 @@ static int bd71837_i2c_probe(struct i2c_client *i2c,

	/* Configure short press to 10 milliseconds */
	ret = regmap_update_bits(bd71837->regmap,
				 BD71837_REG_PWRONCONFIG0,
				 BD718XX_REG_PWRONCONFIG0,
				 BD718XX_PWRBTN_PRESS_DURATION_MASK,
				 BD718XX_PWRBTN_SHORT_PRESS_10MS);
	if (ret) {
@@ -149,7 +130,7 @@ static int bd71837_i2c_probe(struct i2c_client *i2c,

	/* Configure long press to 10 seconds */
	ret = regmap_update_bits(bd71837->regmap,
				 BD71837_REG_PWRONCONFIG1,
				 BD718XX_REG_PWRONCONFIG1,
				 BD718XX_PWRBTN_PRESS_DURATION_MASK,
				 BD718XX_PWRBTN_LONG_PRESS_10S);

@@ -179,7 +160,14 @@ static int bd71837_i2c_probe(struct i2c_client *i2c,
}

static const struct of_device_id bd71837_of_match[] = {
	{ .compatible = "rohm,bd71837", },
	{
		.compatible = "rohm,bd71837",
		.data = (void *)BD718XX_TYPE_BD71837,
	},
	{
		.compatible = "rohm,bd71847",
		.data = (void *)BD718XX_TYPE_BD71847,
	},
	{ }
};
MODULE_DEVICE_TABLE(of, bd71837_of_match);