Skip to content

Commit

Permalink
Merge remote-tracking branches 'regulator/topic/supply', 'regulator/t…
Browse files Browse the repository at this point in the history
…opic/tps6105x' and 'regulator/topic/tps65023' into regulator-next
  • Loading branch information
broonie committed Nov 4, 2015
4 parents 2dab48e + d9b96d3 + c2f4160 + 2d3eda6 commit 62e544b
Show file tree
Hide file tree
Showing 6 changed files with 371 additions and 324 deletions.
60 changes: 60 additions & 0 deletions Documentation/devicetree/bindings/regulator/tps65023.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
TPS65023 family of regulators

Required properties:
- compatible: Must be one of the following.
"ti,tps65020",
"ti,tps65021",
"ti,tps65023",
- reg: I2C slave address
- regulators: list of regulators provided by this controller, must be named
after their hardware counterparts: VDCDC[1-3] and LDO[1-2]
- regulators: This is the list of child nodes that specify the regulator
initialization data for defined regulators. The definition for each of
these nodes is defined using the standard binding for regulators found at
Documentation/devicetree/bindings/regulator/regulator.txt.

Each regulator is defined using the standard binding for regulators.

Example:

tps65023@48 {
compatible = "ti,tps65023";
reg = <0x48>;

regulators {
VDCDC1 {
regulator-name = "vdd_mpu";
regulator-always-on;
regulator-min-microvolt = <1200000>;
regulator-max-microvolt = <1200000>;
};

VDCDC2 {
regulator-name = "vdd_core";
regulator-always-on;
regulator-min-microvolt = <3300000>;
regulator-max-microvolt = <3300000>;
};

VDCDC3 {
regulator-name = "vdd_io";
regulator-always-on;
regulator-min-microvolt = <1800000>;
regulator-max-microvolt = <1800000>;
};

LDO1 {
regulator-name = "vdd_usb18";
regulator-always-on;
regulator-min-microvolt = <1800000>;
regulator-max-microvolt = <1800000>;
};

LDO2 {
regulator-name = "vdd_usb33";
regulator-always-on;
regulator-min-microvolt = <3300000>;
regulator-max-microvolt = <3300000>;
};
};
};
78 changes: 13 additions & 65 deletions drivers/mfd/tps6105x.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <linux/module.h>
#include <linux/init.h>
#include <linux/i2c.h>
#include <linux/mutex.h>
#include <linux/regmap.h>
#include <linux/gpio.h>
#include <linux/spinlock.h>
#include <linux/slab.h>
Expand All @@ -25,73 +25,18 @@
#include <linux/mfd/core.h>
#include <linux/mfd/tps6105x.h>

int tps6105x_set(struct tps6105x *tps6105x, u8 reg, u8 value)
{
int ret;

ret = mutex_lock_interruptible(&tps6105x->lock);
if (ret)
return ret;
ret = i2c_smbus_write_byte_data(tps6105x->client, reg, value);
mutex_unlock(&tps6105x->lock);
if (ret < 0)
return ret;

return 0;
}
EXPORT_SYMBOL(tps6105x_set);

int tps6105x_get(struct tps6105x *tps6105x, u8 reg, u8 *buf)
{
int ret;

ret = mutex_lock_interruptible(&tps6105x->lock);
if (ret)
return ret;
ret = i2c_smbus_read_byte_data(tps6105x->client, reg);
mutex_unlock(&tps6105x->lock);
if (ret < 0)
return ret;

*buf = ret;
return 0;
}
EXPORT_SYMBOL(tps6105x_get);

/*
* Masks off the bits in the mask and sets the bits in the bitvalues
* parameter in one atomic operation
*/
int tps6105x_mask_and_set(struct tps6105x *tps6105x, u8 reg,
u8 bitmask, u8 bitvalues)
{
int ret;
u8 regval;

ret = mutex_lock_interruptible(&tps6105x->lock);
if (ret)
return ret;
ret = i2c_smbus_read_byte_data(tps6105x->client, reg);
if (ret < 0)
goto fail;
regval = ret;
regval = (~bitmask & regval) | (bitmask & bitvalues);
ret = i2c_smbus_write_byte_data(tps6105x->client, reg, regval);
fail:
mutex_unlock(&tps6105x->lock);
if (ret < 0)
return ret;

return 0;
}
EXPORT_SYMBOL(tps6105x_mask_and_set);
static struct regmap_config tps6105x_regmap_config = {
.reg_bits = 8,
.val_bits = 8,
.max_register = TPS6105X_REG_3,
};

static int tps6105x_startup(struct tps6105x *tps6105x)
{
int ret;
u8 regval;
unsigned int regval;

ret = tps6105x_get(tps6105x, TPS6105X_REG_0, &regval);
ret = regmap_read(tps6105x->regmap, TPS6105X_REG_0, &regval);
if (ret)
return ret;
switch (regval >> TPS6105X_REG0_MODE_SHIFT) {
Expand Down Expand Up @@ -145,11 +90,14 @@ static int tps6105x_probe(struct i2c_client *client,
if (!tps6105x)
return -ENOMEM;

tps6105x->regmap = devm_regmap_init_i2c(client, &tps6105x_regmap_config);
if (IS_ERR(tps6105x->regmap))
return PTR_ERR(tps6105x->regmap);

i2c_set_clientdata(client, tps6105x);
tps6105x->client = client;
pdata = dev_get_platdata(&client->dev);
tps6105x->pdata = pdata;
mutex_init(&tps6105x->lock);

ret = tps6105x_startup(tps6105x);
if (ret) {
Expand Down Expand Up @@ -198,7 +146,7 @@ static int tps6105x_remove(struct i2c_client *client)
mfd_remove_devices(&client->dev);

/* Put chip in shutdown mode */
tps6105x_mask_and_set(tps6105x, TPS6105X_REG_0,
regmap_update_bits(tps6105x->regmap, TPS6105X_REG_0,
TPS6105X_REG0_MODE_MASK,
TPS6105X_MODE_SHUTDOWN << TPS6105X_REG0_MODE_SHIFT);

Expand Down
Loading

0 comments on commit 62e544b

Please sign in to comment.