aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKhiem Nguyen <khiem.nguyen.xt@renesas.com>2019-03-07 18:20:18 +0700
committerRyo Kataoka <ryo.kataoka.wt@renesas.com>2019-03-22 20:50:36 +0900
commitbb3b2d661d23fb569ed96b9e5706f980e6ff1466 (patch)
tree30ca9a4854ab82c2d3f104251af62143eadbc998
parent538d41278caaf9b4066db035a11c4ef38f5912f3 (diff)
downloadrenesas-bsp-bb3b2d661d23fb569ed96b9e5706f980e6ff1466.tar.gz
mfd: bd9571mwv: Make the driver more generic
Since the driver supports BD9571MWV PMIC only, this patch makes the functions and data structure become more generic so that it can support other PMIC variants as well. Signed-off-by: Khiem Nguyen <khiem.nguyen.xt@renesas.com>
-rw-r--r--drivers/mfd/bd9571mwv.c59
-rw-r--r--include/linux/mfd/bd9571mwv.h14
2 files changed, 55 insertions, 18 deletions
diff --git a/drivers/mfd/bd9571mwv.c b/drivers/mfd/bd9571mwv.c
index 98192d4863e4c..db07e6426ed50 100644
--- a/drivers/mfd/bd9571mwv.c
+++ b/drivers/mfd/bd9571mwv.c
@@ -2,6 +2,7 @@
* ROHM BD9571MWV-M MFD driver
*
* Copyright (C) 2017 Marek Vasut <marek.vasut+renesas@gmail.com>
+ * Copyright (C) 2019 Renesas Electronics Corporation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2 as
@@ -27,6 +28,8 @@ static const struct mfd_cell bd9571mwv_cells[] = {
{ .name = "bd9571mwv-gpio", },
};
+static const struct bd957x_data *bd_data;
+
static const struct regmap_range bd9571mwv_readable_yes_ranges[] = {
regmap_reg_range(BD9571MWV_VENDOR_CODE, BD9571MWV_PRODUCT_REVISION),
regmap_reg_range(BD9571MWV_AVS_SET_MONI, BD9571MWV_AVS_DVFS_VID(3)),
@@ -108,6 +111,25 @@ static struct regmap_irq_chip bd9571mwv_irq_chip = {
.num_irqs = ARRAY_SIZE(bd9571mwv_irqs),
};
+static const struct of_device_id bd9571mwv_of_match_table[] = {
+ { .compatible = "rohm,bd9571mwv", },
+ { /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, bd9571mwv_of_match_table);
+
+static const struct i2c_device_id bd9571mwv_id_table[] = {
+ { "bd9571mwv", 0 },
+ { /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(i2c, bd9571mwv_id_table);
+
+static const struct bd957x_data bd9571mwv_data __initconst = {
+ .product_code_val = BD9571MWV_PRODUCT_CODE_VAL,
+ .part_number = BD9571MWV_PART_NUMBER,
+ .regmap_config = &bd9571mwv_regmap_config,
+ .irq_chip = &bd9571mwv_irq_chip,
+};
+
static int bd9571mwv_identify(struct bd9571mwv *bd)
{
struct device *dev = bd->dev;
@@ -134,12 +156,11 @@ static int bd9571mwv_identify(struct bd9571mwv *bd)
return ret;
}
- if (value != BD9571MWV_PRODUCT_CODE_VAL) {
+ if (value != bd_data->product_code_val) {
dev_err(dev, "Invalid product code ID %02x (expected %02x)\n",
- value, BD9571MWV_PRODUCT_CODE_VAL);
+ value, bd_data->product_code_val);
return -EINVAL;
}
-
ret = regmap_read(bd->regmap, BD9571MWV_PRODUCT_REVISION, &value);
if (ret) {
dev_err(dev, "Failed to read revision register (ret=%i)\n",
@@ -147,7 +168,8 @@ static int bd9571mwv_identify(struct bd9571mwv *bd)
return ret;
}
- dev_info(dev, "Device: BD9571MWV rev. %d\n", value & 0xff);
+ dev_info(dev, "Device: %s rev. %d\n", bd_data->part_number,
+ value & 0xff);
return 0;
}
@@ -156,6 +178,7 @@ static int bd9571mwv_probe(struct i2c_client *client,
const struct i2c_device_id *ids)
{
struct bd9571mwv *bd;
+ unsigned int product_code;
int ret;
bd = devm_kzalloc(&client->dev, sizeof(*bd), GFP_KERNEL);
@@ -166,7 +189,19 @@ static int bd9571mwv_probe(struct i2c_client *client,
bd->dev = &client->dev;
bd->irq = client->irq;
- bd->regmap = devm_regmap_init_i2c(client, &bd9571mwv_regmap_config);
+ ret = i2c_smbus_read_byte_data(client, BD9571MWV_PRODUCT_CODE);
+ if (ret < 0) {
+ dev_err(&client->dev, "failed reading at 0x%02x\n",
+ BD9571MWV_PRODUCT_CODE);
+ return ret;
+ }
+
+ product_code = (unsigned int)ret;
+
+ if (product_code == BD9571MWV_PRODUCT_CODE_VAL)
+ bd_data = &bd9571mwv_data;
+
+ bd->regmap = devm_regmap_init_i2c(client, bd_data->regmap_config);
if (IS_ERR(bd->regmap)) {
dev_err(bd->dev, "Failed to initialize register map\n");
return PTR_ERR(bd->regmap);
@@ -177,7 +212,7 @@ static int bd9571mwv_probe(struct i2c_client *client,
return ret;
ret = regmap_add_irq_chip(bd->regmap, bd->irq, IRQF_ONESHOT, 0,
- &bd9571mwv_irq_chip, &bd->irq_data);
+ bd_data->irq_chip, &bd->irq_data);
if (ret) {
dev_err(bd->dev, "Failed to register IRQ chip\n");
return ret;
@@ -203,18 +238,6 @@ static int bd9571mwv_remove(struct i2c_client *client)
return 0;
}
-static const struct of_device_id bd9571mwv_of_match_table[] = {
- { .compatible = "rohm,bd9571mwv", },
- { /* sentinel */ }
-};
-MODULE_DEVICE_TABLE(of, bd9571mwv_of_match_table);
-
-static const struct i2c_device_id bd9571mwv_id_table[] = {
- { "bd9571mwv", 0 },
- { /* sentinel */ }
-};
-MODULE_DEVICE_TABLE(i2c, bd9571mwv_id_table);
-
static struct i2c_driver bd9571mwv_driver = {
.driver = {
.name = "bd9571mwv",
diff --git a/include/linux/mfd/bd9571mwv.h b/include/linux/mfd/bd9571mwv.h
index f0708ba4cbbae..8b14126e86025 100644
--- a/include/linux/mfd/bd9571mwv.h
+++ b/include/linux/mfd/bd9571mwv.h
@@ -2,6 +2,7 @@
* ROHM BD9571MWV-M driver
*
* Copyright (C) 2017 Marek Vasut <marek.vasut+renesas@gmail.com>
+ * Copyright (C) 2019 Renesas Electronics Corporation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2 as
@@ -86,6 +87,8 @@
#define BD9571MWV_ACCESS_KEY 0xff
+#define BD9571MWV_PART_NUMBER "BD9571MWV"
+
/* Define the BD9571MWV IRQ numbers */
enum bd9571mwv_irqs {
BD9571MWV_IRQ_MD1,
@@ -112,4 +115,15 @@ struct bd9571mwv {
struct regmap_irq_chip_data *irq_data;
};
+/**
+ * struct bd957x_data - internal data for the bd957x driver
+ *
+ * Internal data to distinguish bd9571mwv chip and bd9574mwf chip
+ */
+struct bd957x_data {
+ int product_code_val;
+ char *part_number;
+ const struct regmap_config *regmap_config;
+ const struct regmap_irq_chip *irq_chip;
+};
#endif /* __LINUX_MFD_BD9571MWV_H */