Skip to content

Commit

Permalink
ASoC: tas5720: add basic support for TAS5722 devices
Browse files Browse the repository at this point in the history
The TI TAS5722 digital amplifier is very similar to the TAS5720 from an
overall and register map perspective. Therefore the existing driver can be
extended easily to support this additional device. This commit allows
TAS5722 devices to be used in a "subset" type of fashion, without exposing
any of the additional features they offer.

Signed-off-by: Andreas Dannenberg <dannenberg@ti.com>
Signed-off-by: Andrew F. Davis <afd@ti.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
  • Loading branch information
Andreas Dannenberg authored and Mark Brown committed Dec 12, 2017
1 parent 4fbd8d1 commit 872bcad
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
4 changes: 3 additions & 1 deletion Documentation/devicetree/bindings/sound/tas5720.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ audio playback. For more product information please see the links below:

http://www.ti.com/product/TAS5720L
http://www.ti.com/product/TAS5720M
http://www.ti.com/product/TAS5722L

Required properties:

- compatible : "ti,tas5720"
- compatible : "ti,tas5720",
"ti,tas5722"
- reg : I2C slave address
- dvdd-supply : phandle to a 3.3-V supply for the digital circuitry
- pvdd-supply : phandle to a supply used for the Class-D amp and the analog
Expand Down
38 changes: 31 additions & 7 deletions sound/soc/codecs/tas5720.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
/* Define how often to check (and clear) the fault status register (in ms) */
#define TAS5720_FAULT_CHECK_INTERVAL 200

enum tas572x_type {
TAS5720,
TAS5722,
};

static const char * const tas5720_supply_names[] = {
"dvdd", /* Digital power supply. Connect to 3.3-V supply. */
"pvdd", /* Class-D amp and analog power supply (connected). */
Expand All @@ -47,6 +52,7 @@ struct tas5720_data {
struct snd_soc_codec *codec;
struct regmap *regmap;
struct i2c_client *tas5720_client;
enum tas572x_type devtype;
struct regulator_bulk_data supplies[TAS5720_NUM_SUPPLIES];
struct delayed_work fault_check_work;
unsigned int last_fault;
Expand Down Expand Up @@ -264,7 +270,7 @@ static void tas5720_fault_check_work(struct work_struct *work)
static int tas5720_codec_probe(struct snd_soc_codec *codec)
{
struct tas5720_data *tas5720 = snd_soc_codec_get_drvdata(codec);
unsigned int device_id;
unsigned int device_id, expected_device_id;
int ret;

tas5720->codec = codec;
Expand All @@ -276,20 +282,34 @@ static int tas5720_codec_probe(struct snd_soc_codec *codec)
return ret;
}

/*
* Take a liberal approach to checking the device ID to allow the
* driver to be used even if the device ID does not match, however
* issue a warning if there is a mismatch.
*/
ret = regmap_read(tas5720->regmap, TAS5720_DEVICE_ID_REG, &device_id);
if (ret < 0) {
dev_err(codec->dev, "failed to read device ID register: %d\n",
ret);
goto probe_fail;
}

if (device_id != TAS5720_DEVICE_ID) {
dev_err(codec->dev, "wrong device ID. expected: %u read: %u\n",
TAS5720_DEVICE_ID, device_id);
ret = -ENODEV;
goto probe_fail;
switch (tas5720->devtype) {
case TAS5720:
expected_device_id = TAS5720_DEVICE_ID;
break;
case TAS5722:
expected_device_id = TAS5722_DEVICE_ID;
break;
default:
dev_err(codec->dev, "unexpected private driver data\n");
return -EINVAL;
}

if (device_id != expected_device_id)
dev_warn(codec->dev, "wrong device ID. expected: %u read: %u\n",
expected_device_id, device_id);

/* Set device to mute */
ret = snd_soc_update_bits(codec, TAS5720_DIGITAL_CTRL2_REG,
TAS5720_MUTE, TAS5720_MUTE);
Expand Down Expand Up @@ -552,6 +572,8 @@ static int tas5720_probe(struct i2c_client *client,
return -ENOMEM;

data->tas5720_client = client;
data->devtype = id->driver_data;

data->regmap = devm_regmap_init_i2c(client, &tas5720_regmap_config);
if (IS_ERR(data->regmap)) {
ret = PTR_ERR(data->regmap);
Expand Down Expand Up @@ -592,14 +614,16 @@ static int tas5720_remove(struct i2c_client *client)
}

static const struct i2c_device_id tas5720_id[] = {
{ "tas5720", 0 },
{ "tas5720", TAS5720 },
{ "tas5722", TAS5722 },
{ }
};
MODULE_DEVICE_TABLE(i2c, tas5720_id);

#if IS_ENABLED(CONFIG_OF)
static const struct of_device_id tas5720_of_match[] = {
{ .compatible = "ti,tas5720", },
{ .compatible = "ti,tas5722", },
{ },
};
MODULE_DEVICE_TABLE(of, tas5720_of_match);
Expand Down
1 change: 1 addition & 0 deletions sound/soc/codecs/tas5720.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

/* TAS5720_DEVICE_ID_REG */
#define TAS5720_DEVICE_ID 0x01
#define TAS5722_DEVICE_ID 0x12

/* TAS5720_POWER_CTRL_REG */
#define TAS5720_DIG_CLIP_MASK GENMASK(7, 2)
Expand Down

0 comments on commit 872bcad

Please sign in to comment.