Commit 703ee055 authored by Daniel Mack's avatar Daniel Mack Committed by Mark Brown

ASoC: max98396: add voltage regulators

The device has up to 5 potentially independent power supplies:
AVDD, DVDD, DVVDIO, VBAT and PVDD. The former 3 are mandatory for the
device to function. One of VBAT and PVDD should also be made available.

Regulators are enabled during probe time and will stay active except when in
suspend mode.

Futher, the chip needs to be informed about the presence of VBAT through a
bit in register 0x20a0.
Signed-off-by: default avatarDaniel Mack <daniel@zonque.org>
Link: https://lore.kernel.org/r/20220624104712.1934484-5-daniel@zonque.orgSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 0ce44afd
...@@ -5,11 +5,18 @@ ...@@ -5,11 +5,18 @@
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/module.h> #include <linux/module.h>
#include <sound/pcm_params.h> #include <sound/pcm_params.h>
#include <linux/regulator/consumer.h>
#include <sound/soc.h> #include <sound/soc.h>
#include <linux/gpio.h> #include <linux/gpio.h>
#include <sound/tlv.h> #include <sound/tlv.h>
#include "max98396.h" #include "max98396.h"
static const char * const max98396_core_supplies[MAX98396_NUM_CORE_SUPPLIES] = {
"avdd",
"dvdd",
"dvddio",
};
static struct reg_default max98396_reg[] = { static struct reg_default max98396_reg[] = {
{MAX98396_R2000_SW_RESET, 0x00}, {MAX98396_R2000_SW_RESET, 0x00},
{MAX98396_R2001_INT_RAW1, 0x00}, {MAX98396_R2001_INT_RAW1, 0x00},
...@@ -1329,6 +1336,12 @@ static int max98396_probe(struct snd_soc_component *component) ...@@ -1329,6 +1336,12 @@ static int max98396_probe(struct snd_soc_component *component)
regmap_write(max98396->regmap, regmap_write(max98396->regmap,
MAX98397_R2057_PCM_RX_SRC2, 0x10); MAX98397_R2057_PCM_RX_SRC2, 0x10);
} }
/* Supply control */
regmap_update_bits(max98396->regmap,
MAX98396_R20A0_AMP_SUPPLY_CTL,
MAX98396_AMP_SUPPLY_NOVBAT,
(max98396->vbat == NULL) ?
MAX98396_AMP_SUPPLY_NOVBAT : 0);
/* Enable DC blocker */ /* Enable DC blocker */
regmap_update_bits(max98396->regmap, regmap_update_bits(max98396->regmap,
MAX98396_R2092_AMP_DSP_CFG, 1, 1); MAX98396_R2092_AMP_DSP_CFG, 1, 1);
...@@ -1424,12 +1437,38 @@ static int max98396_suspend(struct device *dev) ...@@ -1424,12 +1437,38 @@ static int max98396_suspend(struct device *dev)
regcache_cache_only(max98396->regmap, true); regcache_cache_only(max98396->regmap, true);
regcache_mark_dirty(max98396->regmap); regcache_mark_dirty(max98396->regmap);
regulator_bulk_disable(MAX98396_NUM_CORE_SUPPLIES,
max98396->core_supplies);
if (max98396->pvdd)
regulator_disable(max98396->pvdd);
if (max98396->vbat)
regulator_disable(max98396->vbat);
return 0; return 0;
} }
static int max98396_resume(struct device *dev) static int max98396_resume(struct device *dev)
{ {
struct max98396_priv *max98396 = dev_get_drvdata(dev); struct max98396_priv *max98396 = dev_get_drvdata(dev);
int ret;
ret = regulator_bulk_enable(MAX98396_NUM_CORE_SUPPLIES,
max98396->core_supplies);
if (ret < 0)
return ret;
if (max98396->pvdd) {
ret = regulator_enable(max98396->pvdd);
if (ret < 0)
return ret;
}
if (max98396->vbat) {
ret = regulator_enable(max98396->vbat);
if (ret < 0)
return ret;
}
regcache_cache_only(max98396->regmap, false); regcache_cache_only(max98396->regmap, false);
max98396_reset(max98396, dev); max98396_reset(max98396, dev);
...@@ -1513,11 +1552,24 @@ static void max98396_read_device_property(struct device *dev, ...@@ -1513,11 +1552,24 @@ static void max98396_read_device_property(struct device *dev,
max98396->bypass_slot = 0; max98396->bypass_slot = 0;
} }
static void max98396_core_supplies_disable(void *priv)
{
struct max98396_priv *max98396 = priv;
regulator_bulk_disable(MAX98396_NUM_CORE_SUPPLIES,
max98396->core_supplies);
}
static void max98396_supply_disable(void *r)
{
regulator_disable((struct regulator *) r);
}
static int max98396_i2c_probe(struct i2c_client *i2c, static int max98396_i2c_probe(struct i2c_client *i2c,
const struct i2c_device_id *id) const struct i2c_device_id *id)
{ {
struct max98396_priv *max98396 = NULL; struct max98396_priv *max98396 = NULL;
int ret, reg; int i, ret, reg;
max98396 = devm_kzalloc(&i2c->dev, sizeof(*max98396), GFP_KERNEL); max98396 = devm_kzalloc(&i2c->dev, sizeof(*max98396), GFP_KERNEL);
...@@ -1543,6 +1595,69 @@ static int max98396_i2c_probe(struct i2c_client *i2c, ...@@ -1543,6 +1595,69 @@ static int max98396_i2c_probe(struct i2c_client *i2c,
return ret; return ret;
} }
/* Obtain regulator supplies */
for (i = 0; i < MAX98396_NUM_CORE_SUPPLIES; i++)
max98396->core_supplies[i].supply = max98396_core_supplies[i];
ret = devm_regulator_bulk_get(&i2c->dev, MAX98396_NUM_CORE_SUPPLIES,
max98396->core_supplies);
if (ret < 0) {
dev_err(&i2c->dev, "Failed to request core supplies: %d\n", ret);
return ret;
}
max98396->vbat = devm_regulator_get_optional(&i2c->dev, "vbat");
if (IS_ERR(max98396->vbat)) {
if (PTR_ERR(max98396->vbat) == -EPROBE_DEFER)
return -EPROBE_DEFER;
max98396->vbat = NULL;
}
max98396->pvdd = devm_regulator_get_optional(&i2c->dev, "pvdd");
if (IS_ERR(max98396->pvdd)) {
if (PTR_ERR(max98396->pvdd) == -EPROBE_DEFER)
return -EPROBE_DEFER;
max98396->pvdd = NULL;
}
ret = regulator_bulk_enable(MAX98396_NUM_CORE_SUPPLIES,
max98396->core_supplies);
if (ret < 0) {
dev_err(&i2c->dev, "Unable to enable core supplies: %d", ret);
return ret;
}
ret = devm_add_action_or_reset(&i2c->dev, max98396_core_supplies_disable,
max98396);
if (ret < 0)
return ret;
if (max98396->pvdd) {
ret = regulator_enable(max98396->pvdd);
if (ret < 0)
return ret;
ret = devm_add_action_or_reset(&i2c->dev,
max98396_supply_disable,
max98396->pvdd);
if (ret < 0)
return ret;
}
if (max98396->vbat) {
ret = regulator_enable(max98396->vbat);
if (ret < 0)
return ret;
ret = devm_add_action_or_reset(&i2c->dev,
max98396_supply_disable,
max98396->vbat);
if (ret < 0)
return ret;
}
/* update interleave mode info */ /* update interleave mode info */
if (device_property_read_bool(&i2c->dev, "adi,interleave_mode")) if (device_property_read_bool(&i2c->dev, "adi,interleave_mode"))
max98396->interleave_mode = true; max98396->interleave_mode = true;
......
...@@ -274,6 +274,9 @@ ...@@ -274,6 +274,9 @@
#define MAX98396_DSP_SPK_SAFE_EN_SHIFT (5) #define MAX98396_DSP_SPK_SAFE_EN_SHIFT (5)
#define MAX98396_DSP_SPK_WB_FLT_EN_SHIFT (6) #define MAX98396_DSP_SPK_WB_FLT_EN_SHIFT (6)
/* MAX98396_R20A0_AMP_SUPPLY_CTL */
#define MAX98396_AMP_SUPPLY_NOVBAT (0x1 << 0)
/* MAX98396_R20E0_IV_SENSE_PATH_CFG */ /* MAX98396_R20E0_IV_SENSE_PATH_CFG */
#define MAX98396_IV_SENSE_DCBLK_EN_MASK (0x3 << 0) #define MAX98396_IV_SENSE_DCBLK_EN_MASK (0x3 << 0)
#define MAX98396_IV_SENSE_DCBLK_EN_SHIFT (0) #define MAX98396_IV_SENSE_DCBLK_EN_SHIFT (0)
...@@ -291,9 +294,13 @@ enum { ...@@ -291,9 +294,13 @@ enum {
CODEC_TYPE_MAX98397, CODEC_TYPE_MAX98397,
}; };
#define MAX98396_NUM_CORE_SUPPLIES 3
struct max98396_priv { struct max98396_priv {
struct regmap *regmap; struct regmap *regmap;
struct gpio_desc *reset_gpio; struct gpio_desc *reset_gpio;
struct regulator_bulk_data core_supplies[MAX98396_NUM_CORE_SUPPLIES];
struct regulator *pvdd, *vbat;
unsigned int v_slot; unsigned int v_slot;
unsigned int i_slot; unsigned int i_slot;
unsigned int bypass_slot; unsigned int bypass_slot;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment