Skip to content

Commit

Permalink
mfd: pm8008: Use i2c_new_dummy_device() API
Browse files Browse the repository at this point in the history
Use i2c_new_dummy_device() to register pm8008-regulator
client present at a different address space, instead of
defining a separate DT node. This avoids calling the probe
twice for the same chip, once for each client pm8008-infra
and pm8008-regulator.

As a part of this define pm8008_regmap_init() to do regmap
init for both the clients and define pm8008_get_regmap() to
pass the regmap to the regulator driver.

Signed-off-by: Satya Priya <quic_c_skakit@quicinc.com>
  • Loading branch information
Satya Priya authored and intel-lab-lkp committed May 5, 2022
1 parent 4a7e9fb commit 28e91ea
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
31 changes: 29 additions & 2 deletions drivers/mfd/qcom-pm8008.c
Expand Up @@ -57,6 +57,7 @@ enum {

struct pm8008_data {
struct device *dev;
struct regmap *regulators_regmap;
int irq;
struct regmap_irq_chip_data *irq_data;
};
Expand Down Expand Up @@ -150,6 +151,11 @@ static struct regmap_config qcom_mfd_regmap_cfg = {
.max_register = 0xFFFF,
};

struct regmap *pm8008_get_regmap(struct pm8008_data *chip)
{
return chip->regulators_regmap;
}

static int pm8008_init(struct regmap *regmap)
{
int rc;
Expand Down Expand Up @@ -217,23 +223,44 @@ static int pm8008_probe_irq_peripherals(struct pm8008_data *chip,
return 0;
}

static struct regmap *pm8008_regmap_init(struct i2c_client *client,
struct pm8008_data *chip)
{
struct regmap *regmap;

regmap = devm_regmap_init_i2c(client, &qcom_mfd_regmap_cfg);
if (!regmap)
return NULL;

i2c_set_clientdata(client, chip);
return regmap;
}

static int pm8008_probe(struct i2c_client *client)
{
int rc;
struct pm8008_data *chip;
struct gpio_desc *reset_gpio;
struct i2c_client *regulators_client;
struct regmap *regmap;

chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL);
if (!chip)
return -ENOMEM;

chip->dev = &client->dev;
regmap = devm_regmap_init_i2c(client, &qcom_mfd_regmap_cfg);
regmap = pm8008_regmap_init(client, chip);
if (!regmap)
return -ENODEV;

i2c_set_clientdata(client, chip);
regulators_client = i2c_new_dummy_device(client->adapter, client->addr + 1);
if (IS_ERR(regulators_client)) {
dev_err(&client->dev, "can't attach client\n");
return PTR_ERR(regulators_client);
}
chip->regulators_regmap = pm8008_regmap_init(regulators_client, chip);
if (!chip->regulators_regmap)
return -ENODEV;

if (of_property_read_bool(chip->dev->of_node, "interrupt-controller")) {
rc = pm8008_probe_irq_peripherals(chip, regmap, client->irq);
Expand Down
8 changes: 8 additions & 0 deletions include/linux/mfd/qcom_pm8008.h
@@ -0,0 +1,8 @@
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef __QCOM_PM8008_H__
#define __QCOM_PM8008_H__

struct pm8008_data;
struct regmap *pm8008_get_regmap(struct pm8008_data *chip);

#endif

0 comments on commit 28e91ea

Please sign in to comment.