2018-04-23 08:02:11 +08:00
|
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
|
//
|
|
|
|
|
// sgtl5000.c -- SGTL5000 ALSA SoC Audio driver
|
|
|
|
|
//
|
|
|
|
|
// Copyright 2010-2011 Freescale Semiconductor, Inc. All Rights Reserved.
|
2011-02-24 02:08:21 +08:00
|
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
|
#include <linux/moduleparam.h>
|
|
|
|
|
#include <linux/init.h>
|
|
|
|
|
#include <linux/delay.h>
|
|
|
|
|
#include <linux/slab.h>
|
|
|
|
|
#include <linux/pm.h>
|
|
|
|
|
#include <linux/i2c.h>
|
|
|
|
|
#include <linux/clk.h>
|
2014-10-14 14:43:11 +08:00
|
|
|
|
#include <linux/log2.h>
|
2013-05-05 02:39:34 +08:00
|
|
|
|
#include <linux/regmap.h>
|
2011-02-24 02:08:21 +08:00
|
|
|
|
#include <linux/regulator/driver.h>
|
|
|
|
|
#include <linux/regulator/machine.h>
|
|
|
|
|
#include <linux/regulator/consumer.h>
|
2011-07-22 00:28:51 +08:00
|
|
|
|
#include <linux/of_device.h>
|
2011-02-24 02:08:21 +08:00
|
|
|
|
#include <sound/core.h>
|
|
|
|
|
#include <sound/tlv.h>
|
|
|
|
|
#include <sound/pcm.h>
|
|
|
|
|
#include <sound/pcm_params.h>
|
|
|
|
|
#include <sound/soc.h>
|
|
|
|
|
#include <sound/soc-dapm.h>
|
|
|
|
|
#include <sound/initval.h>
|
|
|
|
|
|
|
|
|
|
#include "sgtl5000.h"
|
|
|
|
|
|
|
|
|
|
#define SGTL5000_DAP_REG_OFFSET 0x0100
|
|
|
|
|
#define SGTL5000_MAX_REG_OFFSET 0x013A
|
|
|
|
|
|
2019-07-19 18:05:31 +08:00
|
|
|
|
/* Delay for the VAG ramp up */
|
|
|
|
|
#define SGTL5000_VAG_POWERUP_DELAY 500 /* ms */
|
|
|
|
|
/* Delay for the VAG ramp down */
|
|
|
|
|
#define SGTL5000_VAG_POWERDOWN_DELAY 500 /* ms */
|
|
|
|
|
|
|
|
|
|
#define SGTL5000_OUTPUTS_MUTE (SGTL5000_HP_MUTE | SGTL5000_LINE_OUT_MUTE)
|
|
|
|
|
|
ASoC: sgtl5000: fix cache handling
Cache handling in this driver is broken. The chip has 16-bit registers, yet the
register numbers also increase by 2 per register, i.e. there are only
even-numbered registers. The cache in this driver, though, simply increments
register numbers, so it does need some mapping as seen in
sgtl5000_restore_regs(), note the '>> 1':
snd_soc_write(codec, SGTL5000_CHIP_LINREG_CTRL,
cache[SGTL5000_CHIP_LINREG_CTRL >> 1]);
That, of course, won't work with snd_soc_update_bits(). (Thus, we won't even
notice the missing register 0x1c in the default regs which shifted all follwing
registers to wrong values.) Noticed on the MX28EVK where enabling the regulators
simply locked up the chip.
Refactor the routines and use a properly sized default_regs array which matches
the register layout of the underlying chip, i.e. create a truly flat cache.
This also saves some code which should make up for the bigger array a little.
When soc-core will somewhen have another cache type which handles a step size,
this conversion will also ease the transition.
Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
Tested-by: Dong Aisheng <b29396@freescale.com>
Tested-by: Shawn Guo <shawn.guo@linaro.org>
Acked-by: Liam Girdwood <lrg@ti.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Cc: stable@kernel.org
2011-08-03 01:42:19 +08:00
|
|
|
|
/* default value of sgtl5000 registers */
|
2013-05-05 02:39:34 +08:00
|
|
|
|
static const struct reg_default sgtl5000_reg_defaults[] = {
|
2014-05-26 21:34:20 +08:00
|
|
|
|
{ SGTL5000_CHIP_DIG_POWER, 0x0000 },
|
2013-05-05 02:39:34 +08:00
|
|
|
|
{ SGTL5000_CHIP_I2S_CTRL, 0x0010 },
|
2013-07-05 07:01:02 +08:00
|
|
|
|
{ SGTL5000_CHIP_SSS_CTRL, 0x0010 },
|
2014-05-26 21:34:20 +08:00
|
|
|
|
{ SGTL5000_CHIP_ADCDAC_CTRL, 0x020c },
|
2013-05-05 02:39:34 +08:00
|
|
|
|
{ SGTL5000_CHIP_DAC_VOL, 0x3c3c },
|
|
|
|
|
{ SGTL5000_CHIP_PAD_STRENGTH, 0x015f },
|
2014-05-26 21:34:20 +08:00
|
|
|
|
{ SGTL5000_CHIP_ANA_ADC_CTRL, 0x0000 },
|
2013-05-05 02:39:34 +08:00
|
|
|
|
{ SGTL5000_CHIP_ANA_HP_CTRL, 0x1818 },
|
|
|
|
|
{ SGTL5000_CHIP_ANA_CTRL, 0x0111 },
|
2014-05-26 21:34:20 +08:00
|
|
|
|
{ SGTL5000_CHIP_REF_CTRL, 0x0000 },
|
|
|
|
|
{ SGTL5000_CHIP_MIC_CTRL, 0x0000 },
|
|
|
|
|
{ SGTL5000_CHIP_LINE_OUT_CTRL, 0x0000 },
|
2013-05-05 02:39:34 +08:00
|
|
|
|
{ SGTL5000_CHIP_LINE_OUT_VOL, 0x0404 },
|
|
|
|
|
{ SGTL5000_CHIP_PLL_CTRL, 0x5000 },
|
2014-05-26 21:34:20 +08:00
|
|
|
|
{ SGTL5000_CHIP_CLK_TOP_CTRL, 0x0000 },
|
|
|
|
|
{ SGTL5000_CHIP_ANA_STATUS, 0x0000 },
|
|
|
|
|
{ SGTL5000_CHIP_SHORT_CTRL, 0x0000 },
|
|
|
|
|
{ SGTL5000_CHIP_ANA_TEST2, 0x0000 },
|
|
|
|
|
{ SGTL5000_DAP_CTRL, 0x0000 },
|
|
|
|
|
{ SGTL5000_DAP_PEQ, 0x0000 },
|
2013-05-05 02:39:34 +08:00
|
|
|
|
{ SGTL5000_DAP_BASS_ENHANCE, 0x0040 },
|
|
|
|
|
{ SGTL5000_DAP_BASS_ENHANCE_CTRL, 0x051f },
|
2014-05-26 21:34:20 +08:00
|
|
|
|
{ SGTL5000_DAP_AUDIO_EQ, 0x0000 },
|
2013-05-05 02:39:34 +08:00
|
|
|
|
{ SGTL5000_DAP_SURROUND, 0x0040 },
|
|
|
|
|
{ SGTL5000_DAP_EQ_BASS_BAND0, 0x002f },
|
|
|
|
|
{ SGTL5000_DAP_EQ_BASS_BAND1, 0x002f },
|
|
|
|
|
{ SGTL5000_DAP_EQ_BASS_BAND2, 0x002f },
|
|
|
|
|
{ SGTL5000_DAP_EQ_BASS_BAND3, 0x002f },
|
|
|
|
|
{ SGTL5000_DAP_EQ_BASS_BAND4, 0x002f },
|
|
|
|
|
{ SGTL5000_DAP_MAIN_CHAN, 0x8000 },
|
2014-05-26 21:34:20 +08:00
|
|
|
|
{ SGTL5000_DAP_MIX_CHAN, 0x0000 },
|
ASoC: sgtl5000: set DAP_AVC_CTRL register to correct default value on probe
According to the SGTL5000 datasheet [1], the DAP_AVC_CTRL register has
the following bit field definitions:
| BITS | FIELD | RW | RESET | DEFINITION |
| 15 | RSVD | RO | 0x0 | Reserved |
| 14 | RSVD | RW | 0x1 | Reserved |
| 13:12 | MAX_GAIN | RW | 0x1 | Max Gain of AVC in expander mode |
| 11:10 | RSVD | RO | 0x0 | Reserved |
| 9:8 | LBI_RESP | RW | 0x1 | Integrator Response |
| 7:6 | RSVD | RO | 0x0 | Reserved |
| 5 | HARD_LMT_EN | RW | 0x0 | Enable hard limiter mode |
| 4:1 | RSVD | RO | 0x0 | Reserved |
| 0 | EN | RW | 0x0 | Enable/Disable AVC |
The original default value written to the DAP_AVC_CTRL register during
sgtl5000_i2c_probe() was 0x0510. This would incorrectly write values to
bits 4 and 10, which are defined as RESERVED. It would also not set
bits 12 and 14 to their correct RESET values of 0x1, and instead set
them to 0x0. While the DAP_AVC module is effectively disabled because
the EN bit is 0, this default value is still writing invalid values to
registers that are marked as read-only and RESERVED as well as not
setting bits 12 and 14 to their correct default values as defined by the
datasheet.
The correct value that should be written to the DAP_AVC_CTRL register is
0x5100, which configures the register bits to the default values defined
by the datasheet, and prevents any writes to bits defined as
'read-only'. Generally speaking, it is best practice to NOT attempt to
write values to registers/bits defined as RESERVED, as it generally
produces unwanted/undefined behavior, or errors.
Also, all credit for this patch should go to my colleague Dan MacDonald
<dmacdonald@curbellmedical.com> for finding this error in the first
place.
[1] https://www.nxp.com/docs/en/data-sheet/SGTL5000.pdf
Signed-off-by: Benjamin Rood <benjaminjrood@gmail.com>
Reviewed-by: Fabio Estevam <festevam@gmail.com>
Link: https://lore.kernel.org/r/20210219183308.GA2117@ubuntu-dev
Signed-off-by: Mark Brown <broonie@kernel.org>
2021-02-20 02:33:08 +08:00
|
|
|
|
{ SGTL5000_DAP_AVC_CTRL, 0x5100 },
|
2013-05-05 02:39:34 +08:00
|
|
|
|
{ SGTL5000_DAP_AVC_THRESHOLD, 0x1473 },
|
|
|
|
|
{ SGTL5000_DAP_AVC_ATTACK, 0x0028 },
|
|
|
|
|
{ SGTL5000_DAP_AVC_DECAY, 0x0050 },
|
2011-02-24 02:08:21 +08:00
|
|
|
|
};
|
|
|
|
|
|
2017-06-14 16:36:12 +08:00
|
|
|
|
/* AVC: Threshold dB -> register: pre-calculated values */
|
|
|
|
|
static const u16 avc_thr_db2reg[97] = {
|
|
|
|
|
0x5168, 0x488E, 0x40AA, 0x39A1, 0x335D, 0x2DC7, 0x28CC, 0x245D, 0x2068,
|
|
|
|
|
0x1CE2, 0x19BE, 0x16F1, 0x1472, 0x1239, 0x103E, 0x0E7A, 0x0CE6, 0x0B7F,
|
|
|
|
|
0x0A3F, 0x0922, 0x0824, 0x0741, 0x0677, 0x05C3, 0x0522, 0x0493, 0x0414,
|
|
|
|
|
0x03A2, 0x033D, 0x02E3, 0x0293, 0x024B, 0x020B, 0x01D2, 0x019F, 0x0172,
|
|
|
|
|
0x014A, 0x0126, 0x0106, 0x00E9, 0x00D0, 0x00B9, 0x00A5, 0x0093, 0x0083,
|
|
|
|
|
0x0075, 0x0068, 0x005D, 0x0052, 0x0049, 0x0041, 0x003A, 0x0034, 0x002E,
|
|
|
|
|
0x0029, 0x0025, 0x0021, 0x001D, 0x001A, 0x0017, 0x0014, 0x0012, 0x0010,
|
|
|
|
|
0x000E, 0x000D, 0x000B, 0x000A, 0x0009, 0x0008, 0x0007, 0x0006, 0x0005,
|
|
|
|
|
0x0005, 0x0004, 0x0004, 0x0003, 0x0003, 0x0002, 0x0002, 0x0002, 0x0002,
|
|
|
|
|
0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0000, 0x0000, 0x0000,
|
|
|
|
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000};
|
|
|
|
|
|
2011-02-24 02:08:21 +08:00
|
|
|
|
/* regulator supplies for sgtl5000, VDDD is an optional external supply */
|
|
|
|
|
enum sgtl5000_regulator_supplies {
|
|
|
|
|
VDDA,
|
|
|
|
|
VDDIO,
|
|
|
|
|
VDDD,
|
|
|
|
|
SGTL5000_SUPPLY_NUM
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* vddd is optional supply */
|
|
|
|
|
static const char *supply_names[SGTL5000_SUPPLY_NUM] = {
|
|
|
|
|
"VDDA",
|
|
|
|
|
"VDDIO",
|
|
|
|
|
"VDDD"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#define LDO_VOLTAGE 1200000
|
2016-06-07 07:14:50 +08:00
|
|
|
|
#define LINREG_VDDD ((1600 - LDO_VOLTAGE / 1000) / 50)
|
2011-02-24 02:08:21 +08:00
|
|
|
|
|
2014-10-14 14:43:11 +08:00
|
|
|
|
enum sgtl5000_micbias_resistor {
|
|
|
|
|
SGTL5000_MICBIAS_OFF = 0,
|
|
|
|
|
SGTL5000_MICBIAS_2K = 2,
|
|
|
|
|
SGTL5000_MICBIAS_4K = 4,
|
|
|
|
|
SGTL5000_MICBIAS_8K = 8,
|
|
|
|
|
};
|
|
|
|
|
|
2017-04-05 22:32:34 +08:00
|
|
|
|
enum {
|
|
|
|
|
I2S_LRCLK_STRENGTH_DISABLE,
|
|
|
|
|
I2S_LRCLK_STRENGTH_LOW,
|
|
|
|
|
I2S_LRCLK_STRENGTH_MEDIUM,
|
|
|
|
|
I2S_LRCLK_STRENGTH_HIGH,
|
|
|
|
|
};
|
|
|
|
|
|
2018-12-26 08:59:53 +08:00
|
|
|
|
enum {
|
|
|
|
|
I2S_SCLK_STRENGTH_DISABLE,
|
|
|
|
|
I2S_SCLK_STRENGTH_LOW,
|
|
|
|
|
I2S_SCLK_STRENGTH_MEDIUM,
|
|
|
|
|
I2S_SCLK_STRENGTH_HIGH,
|
|
|
|
|
};
|
|
|
|
|
|
2019-07-19 18:05:31 +08:00
|
|
|
|
enum {
|
|
|
|
|
HP_POWER_EVENT,
|
|
|
|
|
DAC_POWER_EVENT,
|
|
|
|
|
ADC_POWER_EVENT,
|
|
|
|
|
LAST_POWER_EVENT = ADC_POWER_EVENT
|
|
|
|
|
};
|
|
|
|
|
|
2011-02-24 02:08:21 +08:00
|
|
|
|
/* sgtl5000 private structure in codec */
|
|
|
|
|
struct sgtl5000_priv {
|
|
|
|
|
int sysclk; /* sysclk rate */
|
|
|
|
|
int master; /* i2s master or not */
|
|
|
|
|
int fmt; /* i2s data format */
|
|
|
|
|
struct regulator_bulk_data supplies[SGTL5000_SUPPLY_NUM];
|
2016-06-07 07:14:48 +08:00
|
|
|
|
int num_supplies;
|
2013-05-05 02:39:34 +08:00
|
|
|
|
struct regmap *regmap;
|
2013-06-10 09:07:46 +08:00
|
|
|
|
struct clk *mclk;
|
2013-12-13 14:43:02 +08:00
|
|
|
|
int revision;
|
2014-10-14 14:43:11 +08:00
|
|
|
|
u8 micbias_resistor;
|
2014-10-14 14:43:12 +08:00
|
|
|
|
u8 micbias_voltage;
|
2017-04-05 22:32:34 +08:00
|
|
|
|
u8 lrclk_strength;
|
2018-12-26 08:59:53 +08:00
|
|
|
|
u8 sclk_strength;
|
2019-07-19 18:05:31 +08:00
|
|
|
|
u16 mute_state[LAST_POWER_EVENT + 1];
|
2011-02-24 02:08:21 +08:00
|
|
|
|
};
|
|
|
|
|
|
2019-07-19 18:05:31 +08:00
|
|
|
|
static inline int hp_sel_input(struct snd_soc_component *component)
|
|
|
|
|
{
|
2020-06-16 13:20:33 +08:00
|
|
|
|
return (snd_soc_component_read(component, SGTL5000_CHIP_ANA_CTRL) &
|
2019-07-19 18:05:31 +08:00
|
|
|
|
SGTL5000_HP_SEL_MASK) >> SGTL5000_HP_SEL_SHIFT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline u16 mute_output(struct snd_soc_component *component,
|
|
|
|
|
u16 mute_mask)
|
|
|
|
|
{
|
2020-06-16 13:20:33 +08:00
|
|
|
|
u16 mute_reg = snd_soc_component_read(component,
|
2019-07-19 18:05:31 +08:00
|
|
|
|
SGTL5000_CHIP_ANA_CTRL);
|
|
|
|
|
|
|
|
|
|
snd_soc_component_update_bits(component, SGTL5000_CHIP_ANA_CTRL,
|
|
|
|
|
mute_mask, mute_mask);
|
|
|
|
|
return mute_reg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void restore_output(struct snd_soc_component *component,
|
|
|
|
|
u16 mute_mask, u16 mute_reg)
|
|
|
|
|
{
|
|
|
|
|
snd_soc_component_update_bits(component, SGTL5000_CHIP_ANA_CTRL,
|
|
|
|
|
mute_mask, mute_reg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void vag_power_on(struct snd_soc_component *component, u32 source)
|
|
|
|
|
{
|
2020-06-16 13:20:33 +08:00
|
|
|
|
if (snd_soc_component_read(component, SGTL5000_CHIP_ANA_POWER) &
|
2019-07-19 18:05:31 +08:00
|
|
|
|
SGTL5000_VAG_POWERUP)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
snd_soc_component_update_bits(component, SGTL5000_CHIP_ANA_POWER,
|
|
|
|
|
SGTL5000_VAG_POWERUP, SGTL5000_VAG_POWERUP);
|
|
|
|
|
|
|
|
|
|
/* When VAG powering on to get local loop from Line-In, the sleep
|
|
|
|
|
* is required to avoid loud pop.
|
|
|
|
|
*/
|
|
|
|
|
if (hp_sel_input(component) == SGTL5000_HP_SEL_LINE_IN &&
|
|
|
|
|
source == HP_POWER_EVENT)
|
|
|
|
|
msleep(SGTL5000_VAG_POWERUP_DELAY);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int vag_power_consumers(struct snd_soc_component *component,
|
|
|
|
|
u16 ana_pwr_reg, u32 source)
|
|
|
|
|
{
|
|
|
|
|
int consumers = 0;
|
|
|
|
|
|
|
|
|
|
/* count dac/adc consumers unconditional */
|
|
|
|
|
if (ana_pwr_reg & SGTL5000_DAC_POWERUP)
|
|
|
|
|
consumers++;
|
|
|
|
|
if (ana_pwr_reg & SGTL5000_ADC_POWERUP)
|
|
|
|
|
consumers++;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* If the event comes from HP and Line-In is selected,
|
|
|
|
|
* current action is 'DAC to be powered down'.
|
|
|
|
|
* As HP_POWERUP is not set when HP muxed to line-in,
|
|
|
|
|
* we need to keep VAG power ON.
|
|
|
|
|
*/
|
|
|
|
|
if (source == HP_POWER_EVENT) {
|
|
|
|
|
if (hp_sel_input(component) == SGTL5000_HP_SEL_LINE_IN)
|
|
|
|
|
consumers++;
|
|
|
|
|
} else {
|
|
|
|
|
if (ana_pwr_reg & SGTL5000_HP_POWERUP)
|
|
|
|
|
consumers++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return consumers;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void vag_power_off(struct snd_soc_component *component, u32 source)
|
|
|
|
|
{
|
2020-06-16 13:20:33 +08:00
|
|
|
|
u16 ana_pwr = snd_soc_component_read(component,
|
2019-07-19 18:05:31 +08:00
|
|
|
|
SGTL5000_CHIP_ANA_POWER);
|
|
|
|
|
|
|
|
|
|
if (!(ana_pwr & SGTL5000_VAG_POWERUP))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This function calls when any of VAG power consumers is disappearing.
|
|
|
|
|
* Thus, if there is more than one consumer at the moment, as minimum
|
|
|
|
|
* one consumer will definitely stay after the end of the current
|
|
|
|
|
* event.
|
|
|
|
|
* Don't clear VAG_POWERUP if 2 or more consumers of VAG present:
|
|
|
|
|
* - LINE_IN (for HP events) / HP (for DAC/ADC events)
|
|
|
|
|
* - DAC
|
|
|
|
|
* - ADC
|
|
|
|
|
* (the current consumer is disappearing right now)
|
|
|
|
|
*/
|
|
|
|
|
if (vag_power_consumers(component, ana_pwr, source) >= 2)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
snd_soc_component_update_bits(component, SGTL5000_CHIP_ANA_POWER,
|
|
|
|
|
SGTL5000_VAG_POWERUP, 0);
|
|
|
|
|
/* In power down case, we need wait 400-1000 ms
|
|
|
|
|
* when VAG fully ramped down.
|
|
|
|
|
* As longer we wait, as smaller pop we've got.
|
|
|
|
|
*/
|
|
|
|
|
msleep(SGTL5000_VAG_POWERDOWN_DELAY);
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-24 02:08:21 +08:00
|
|
|
|
/*
|
|
|
|
|
* mic_bias power on/off share the same register bits with
|
|
|
|
|
* output impedance of mic bias, when power on mic bias, we
|
|
|
|
|
* need reclaim it to impedance value.
|
|
|
|
|
* 0x0 = Powered off
|
|
|
|
|
* 0x1 = 2Kohm
|
|
|
|
|
* 0x2 = 4Kohm
|
|
|
|
|
* 0x3 = 8Kohm
|
|
|
|
|
*/
|
|
|
|
|
static int mic_bias_event(struct snd_soc_dapm_widget *w,
|
|
|
|
|
struct snd_kcontrol *kcontrol, int event)
|
|
|
|
|
{
|
2018-01-29 12:37:53 +08:00
|
|
|
|
struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
|
|
|
|
|
struct sgtl5000_priv *sgtl5000 = snd_soc_component_get_drvdata(component);
|
2014-10-14 14:43:11 +08:00
|
|
|
|
|
2011-02-24 02:08:21 +08:00
|
|
|
|
switch (event) {
|
|
|
|
|
case SND_SOC_DAPM_POST_PMU:
|
2014-10-14 14:43:11 +08:00
|
|
|
|
/* change mic bias resistor */
|
2018-01-29 12:37:53 +08:00
|
|
|
|
snd_soc_component_update_bits(component, SGTL5000_CHIP_MIC_CTRL,
|
2014-10-14 14:43:11 +08:00
|
|
|
|
SGTL5000_BIAS_R_MASK,
|
|
|
|
|
sgtl5000->micbias_resistor << SGTL5000_BIAS_R_SHIFT);
|
2011-02-24 02:08:21 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SND_SOC_DAPM_PRE_PMD:
|
2018-01-29 12:37:53 +08:00
|
|
|
|
snd_soc_component_update_bits(component, SGTL5000_CHIP_MIC_CTRL,
|
2011-10-19 11:00:42 +08:00
|
|
|
|
SGTL5000_BIAS_R_MASK, 0);
|
2011-02-24 02:08:21 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-19 18:05:31 +08:00
|
|
|
|
static int vag_and_mute_control(struct snd_soc_component *component,
|
|
|
|
|
int event, int event_source)
|
2011-02-24 02:08:21 +08:00
|
|
|
|
{
|
2019-07-19 18:05:31 +08:00
|
|
|
|
static const u16 mute_mask[] = {
|
|
|
|
|
/*
|
|
|
|
|
* Mask for HP_POWER_EVENT.
|
|
|
|
|
* Muxing Headphones have to be wrapped with mute/unmute
|
|
|
|
|
* headphones only.
|
|
|
|
|
*/
|
|
|
|
|
SGTL5000_HP_MUTE,
|
|
|
|
|
/*
|
|
|
|
|
* Masks for DAC_POWER_EVENT/ADC_POWER_EVENT.
|
|
|
|
|
* Muxing DAC or ADC block have to wrapped with mute/unmute
|
|
|
|
|
* both headphones and line-out.
|
|
|
|
|
*/
|
|
|
|
|
SGTL5000_OUTPUTS_MUTE,
|
|
|
|
|
SGTL5000_OUTPUTS_MUTE
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct sgtl5000_priv *sgtl5000 =
|
|
|
|
|
snd_soc_component_get_drvdata(component);
|
2013-07-31 22:44:29 +08:00
|
|
|
|
|
2011-02-24 02:08:21 +08:00
|
|
|
|
switch (event) {
|
2019-07-19 18:05:31 +08:00
|
|
|
|
case SND_SOC_DAPM_PRE_PMU:
|
|
|
|
|
sgtl5000->mute_state[event_source] =
|
|
|
|
|
mute_output(component, mute_mask[event_source]);
|
|
|
|
|
break;
|
2013-05-29 02:55:56 +08:00
|
|
|
|
case SND_SOC_DAPM_POST_PMU:
|
2019-07-19 18:05:31 +08:00
|
|
|
|
vag_power_on(component, event_source);
|
|
|
|
|
restore_output(component, mute_mask[event_source],
|
|
|
|
|
sgtl5000->mute_state[event_source]);
|
2011-02-24 02:08:21 +08:00
|
|
|
|
break;
|
2013-05-29 02:55:56 +08:00
|
|
|
|
case SND_SOC_DAPM_PRE_PMD:
|
2019-07-19 18:05:31 +08:00
|
|
|
|
sgtl5000->mute_state[event_source] =
|
|
|
|
|
mute_output(component, mute_mask[event_source]);
|
|
|
|
|
vag_power_off(component, event_source);
|
|
|
|
|
break;
|
|
|
|
|
case SND_SOC_DAPM_POST_PMD:
|
|
|
|
|
restore_output(component, mute_mask[event_source],
|
|
|
|
|
sgtl5000->mute_state[event_source]);
|
2011-02-24 02:08:21 +08:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-19 18:05:31 +08:00
|
|
|
|
/*
|
|
|
|
|
* Mute Headphone when power it up/down.
|
|
|
|
|
* Control VAG power on HP power path.
|
|
|
|
|
*/
|
|
|
|
|
static int headphone_pga_event(struct snd_soc_dapm_widget *w,
|
|
|
|
|
struct snd_kcontrol *kcontrol, int event)
|
|
|
|
|
{
|
|
|
|
|
struct snd_soc_component *component =
|
|
|
|
|
snd_soc_dapm_to_component(w->dapm);
|
|
|
|
|
|
|
|
|
|
return vag_and_mute_control(component, event, HP_POWER_EVENT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* As manual describes, ADC/DAC powering up/down requires
|
|
|
|
|
* to mute outputs to avoid pops.
|
|
|
|
|
* Control VAG power on ADC/DAC power path.
|
|
|
|
|
*/
|
|
|
|
|
static int adc_updown_depop(struct snd_soc_dapm_widget *w,
|
|
|
|
|
struct snd_kcontrol *kcontrol, int event)
|
|
|
|
|
{
|
|
|
|
|
struct snd_soc_component *component =
|
|
|
|
|
snd_soc_dapm_to_component(w->dapm);
|
|
|
|
|
|
|
|
|
|
return vag_and_mute_control(component, event, ADC_POWER_EVENT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int dac_updown_depop(struct snd_soc_dapm_widget *w,
|
|
|
|
|
struct snd_kcontrol *kcontrol, int event)
|
|
|
|
|
{
|
|
|
|
|
struct snd_soc_component *component =
|
|
|
|
|
snd_soc_dapm_to_component(w->dapm);
|
|
|
|
|
|
|
|
|
|
return vag_and_mute_control(component, event, DAC_POWER_EVENT);
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-24 02:08:21 +08:00
|
|
|
|
/* input sources for ADC */
|
|
|
|
|
static const char *adc_mux_text[] = {
|
|
|
|
|
"MIC_IN", "LINE_IN"
|
|
|
|
|
};
|
|
|
|
|
|
2014-02-18 17:16:31 +08:00
|
|
|
|
static SOC_ENUM_SINGLE_DECL(adc_enum,
|
|
|
|
|
SGTL5000_CHIP_ANA_CTRL, 2,
|
|
|
|
|
adc_mux_text);
|
2011-02-24 02:08:21 +08:00
|
|
|
|
|
|
|
|
|
static const struct snd_kcontrol_new adc_mux =
|
|
|
|
|
SOC_DAPM_ENUM("Capture Mux", adc_enum);
|
|
|
|
|
|
2018-02-19 17:03:45 +08:00
|
|
|
|
/* input sources for headphone */
|
|
|
|
|
static const char *hp_mux_text[] = {
|
|
|
|
|
"DAC", "LINE_IN"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static SOC_ENUM_SINGLE_DECL(hp_enum,
|
|
|
|
|
SGTL5000_CHIP_ANA_CTRL, 6,
|
|
|
|
|
hp_mux_text);
|
|
|
|
|
|
|
|
|
|
static const struct snd_kcontrol_new hp_mux =
|
|
|
|
|
SOC_DAPM_ENUM("Headphone Mux", hp_enum);
|
|
|
|
|
|
2011-02-24 02:08:21 +08:00
|
|
|
|
/* input sources for DAC */
|
|
|
|
|
static const char *dac_mux_text[] = {
|
2018-02-19 17:03:45 +08:00
|
|
|
|
"ADC", "I2S", "Rsvrd", "DAP"
|
2011-02-24 02:08:21 +08:00
|
|
|
|
};
|
|
|
|
|
|
2014-02-18 17:16:31 +08:00
|
|
|
|
static SOC_ENUM_SINGLE_DECL(dac_enum,
|
2018-02-19 17:03:45 +08:00
|
|
|
|
SGTL5000_CHIP_SSS_CTRL, SGTL5000_DAC_SEL_SHIFT,
|
2014-02-18 17:16:31 +08:00
|
|
|
|
dac_mux_text);
|
2011-02-24 02:08:21 +08:00
|
|
|
|
|
|
|
|
|
static const struct snd_kcontrol_new dac_mux =
|
2018-02-19 17:03:45 +08:00
|
|
|
|
SOC_DAPM_ENUM("Digital Input Mux", dac_enum);
|
|
|
|
|
|
|
|
|
|
/* input sources for DAP */
|
|
|
|
|
static const char *dap_mux_text[] = {
|
|
|
|
|
"ADC", "I2S"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static SOC_ENUM_SINGLE_DECL(dap_enum,
|
|
|
|
|
SGTL5000_CHIP_SSS_CTRL, SGTL5000_DAP_SEL_SHIFT,
|
|
|
|
|
dap_mux_text);
|
|
|
|
|
|
|
|
|
|
static const struct snd_kcontrol_new dap_mux =
|
|
|
|
|
SOC_DAPM_ENUM("DAP Mux", dap_enum);
|
|
|
|
|
|
|
|
|
|
/* input sources for DAP mix */
|
|
|
|
|
static const char *dapmix_mux_text[] = {
|
|
|
|
|
"ADC", "I2S"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static SOC_ENUM_SINGLE_DECL(dapmix_enum,
|
|
|
|
|
SGTL5000_CHIP_SSS_CTRL, SGTL5000_DAP_MIX_SEL_SHIFT,
|
|
|
|
|
dapmix_mux_text);
|
|
|
|
|
|
|
|
|
|
static const struct snd_kcontrol_new dapmix_mux =
|
|
|
|
|
SOC_DAPM_ENUM("DAP MIX Mux", dapmix_enum);
|
|
|
|
|
|
2011-02-24 02:08:21 +08:00
|
|
|
|
|
|
|
|
|
static const struct snd_soc_dapm_widget sgtl5000_dapm_widgets[] = {
|
|
|
|
|
SND_SOC_DAPM_INPUT("LINE_IN"),
|
|
|
|
|
SND_SOC_DAPM_INPUT("MIC_IN"),
|
|
|
|
|
|
|
|
|
|
SND_SOC_DAPM_OUTPUT("HP_OUT"),
|
|
|
|
|
SND_SOC_DAPM_OUTPUT("LINE_OUT"),
|
|
|
|
|
|
2012-03-29 03:51:43 +08:00
|
|
|
|
SND_SOC_DAPM_SUPPLY("Mic Bias", SGTL5000_CHIP_MIC_CTRL, 8, 0,
|
|
|
|
|
mic_bias_event,
|
|
|
|
|
SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
|
2011-02-24 02:08:21 +08:00
|
|
|
|
|
2019-07-19 18:05:31 +08:00
|
|
|
|
SND_SOC_DAPM_PGA_E("HP", SGTL5000_CHIP_ANA_POWER, 4, 0, NULL, 0,
|
|
|
|
|
headphone_pga_event,
|
|
|
|
|
SND_SOC_DAPM_PRE_POST_PMU |
|
|
|
|
|
SND_SOC_DAPM_PRE_POST_PMD),
|
2012-03-30 00:13:02 +08:00
|
|
|
|
SND_SOC_DAPM_PGA("LO", SGTL5000_CHIP_ANA_POWER, 0, 0, NULL, 0),
|
2011-02-24 02:08:21 +08:00
|
|
|
|
|
|
|
|
|
SND_SOC_DAPM_MUX("Capture Mux", SND_SOC_NOPM, 0, 0, &adc_mux),
|
2018-02-19 17:03:45 +08:00
|
|
|
|
SND_SOC_DAPM_MUX("Headphone Mux", SND_SOC_NOPM, 0, 0, &hp_mux),
|
|
|
|
|
SND_SOC_DAPM_MUX("Digital Input Mux", SND_SOC_NOPM, 0, 0, &dac_mux),
|
|
|
|
|
SND_SOC_DAPM_MUX("DAP Mux", SGTL5000_DAP_CTRL, 0, 0, &dap_mux),
|
|
|
|
|
SND_SOC_DAPM_MUX("DAP MIX Mux", SGTL5000_DAP_CTRL, 4, 0, &dapmix_mux),
|
|
|
|
|
SND_SOC_DAPM_MIXER("DAP", SGTL5000_CHIP_DIG_POWER, 4, 0, NULL, 0),
|
|
|
|
|
|
2011-02-24 02:08:21 +08:00
|
|
|
|
|
|
|
|
|
/* aif for i2s input */
|
|
|
|
|
SND_SOC_DAPM_AIF_IN("AIFIN", "Playback",
|
|
|
|
|
0, SGTL5000_CHIP_DIG_POWER,
|
|
|
|
|
0, 0),
|
|
|
|
|
|
|
|
|
|
/* aif for i2s output */
|
|
|
|
|
SND_SOC_DAPM_AIF_OUT("AIFOUT", "Capture",
|
|
|
|
|
0, SGTL5000_CHIP_DIG_POWER,
|
|
|
|
|
1, 0),
|
|
|
|
|
|
2019-07-19 18:05:31 +08:00
|
|
|
|
SND_SOC_DAPM_ADC_E("ADC", "Capture", SGTL5000_CHIP_ANA_POWER, 1, 0,
|
|
|
|
|
adc_updown_depop, SND_SOC_DAPM_PRE_POST_PMU |
|
|
|
|
|
SND_SOC_DAPM_PRE_POST_PMD),
|
|
|
|
|
SND_SOC_DAPM_DAC_E("DAC", "Playback", SGTL5000_CHIP_ANA_POWER, 3, 0,
|
|
|
|
|
dac_updown_depop, SND_SOC_DAPM_PRE_POST_PMU |
|
|
|
|
|
SND_SOC_DAPM_PRE_POST_PMD),
|
2011-02-24 02:08:21 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* routes for sgtl5000 */
|
2012-01-23 00:49:42 +08:00
|
|
|
|
static const struct snd_soc_dapm_route sgtl5000_dapm_routes[] = {
|
2011-02-24 02:08:21 +08:00
|
|
|
|
{"Capture Mux", "LINE_IN", "LINE_IN"}, /* line_in --> adc_mux */
|
|
|
|
|
{"Capture Mux", "MIC_IN", "MIC_IN"}, /* mic_in --> adc_mux */
|
|
|
|
|
|
|
|
|
|
{"ADC", NULL, "Capture Mux"}, /* adc_mux --> adc */
|
|
|
|
|
{"AIFOUT", NULL, "ADC"}, /* adc --> i2s_out */
|
|
|
|
|
|
2018-02-19 17:03:45 +08:00
|
|
|
|
{"DAP Mux", "ADC", "ADC"}, /* adc --> DAP mux */
|
|
|
|
|
{"DAP Mux", NULL, "AIFIN"}, /* i2s --> DAP mux */
|
|
|
|
|
{"DAP", NULL, "DAP Mux"}, /* DAP mux --> dap */
|
|
|
|
|
|
|
|
|
|
{"DAP MIX Mux", "ADC", "ADC"}, /* adc --> DAP MIX mux */
|
|
|
|
|
{"DAP MIX Mux", NULL, "AIFIN"}, /* i2s --> DAP MIX mux */
|
|
|
|
|
{"DAP", NULL, "DAP MIX Mux"}, /* DAP MIX mux --> dap */
|
|
|
|
|
|
|
|
|
|
{"Digital Input Mux", "ADC", "ADC"}, /* adc --> audio mux */
|
|
|
|
|
{"Digital Input Mux", NULL, "AIFIN"}, /* i2s --> audio mux */
|
|
|
|
|
{"Digital Input Mux", NULL, "DAP"}, /* dap --> audio mux */
|
|
|
|
|
{"DAC", NULL, "Digital Input Mux"}, /* audio mux --> dac */
|
|
|
|
|
|
2011-02-24 02:08:21 +08:00
|
|
|
|
{"Headphone Mux", "DAC", "DAC"}, /* dac --> hp_mux */
|
|
|
|
|
{"LO", NULL, "DAC"}, /* dac --> line_out */
|
|
|
|
|
|
|
|
|
|
{"Headphone Mux", "LINE_IN", "LINE_IN"},/* line_in --> hp_mux */
|
|
|
|
|
{"HP", NULL, "Headphone Mux"}, /* hp_mux --> hp */
|
|
|
|
|
|
|
|
|
|
{"LINE_OUT", NULL, "LO"},
|
|
|
|
|
{"HP_OUT", NULL, "HP"},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* custom function to fetch info of PCM playback volume */
|
|
|
|
|
static int dac_info_volsw(struct snd_kcontrol *kcontrol,
|
|
|
|
|
struct snd_ctl_elem_info *uinfo)
|
|
|
|
|
{
|
|
|
|
|
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
|
|
|
|
|
uinfo->count = 2;
|
|
|
|
|
uinfo->value.integer.min = 0;
|
|
|
|
|
uinfo->value.integer.max = 0xfc - 0x3c;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* custom function to get of PCM playback volume
|
|
|
|
|
*
|
|
|
|
|
* dac volume register
|
|
|
|
|
* 15-------------8-7--------------0
|
|
|
|
|
* | R channel vol | L channel vol |
|
|
|
|
|
* -------------------------------
|
|
|
|
|
*
|
|
|
|
|
* PCM volume with 0.5017 dB steps from 0 to -90 dB
|
|
|
|
|
*
|
|
|
|
|
* register values map to dB
|
|
|
|
|
* 0x3B and less = Reserved
|
|
|
|
|
* 0x3C = 0 dB
|
|
|
|
|
* 0x3D = -0.5 dB
|
|
|
|
|
* 0xF0 = -90 dB
|
|
|
|
|
* 0xFC and greater = Muted
|
|
|
|
|
*
|
|
|
|
|
* register value map to userspace value
|
|
|
|
|
*
|
|
|
|
|
* register value 0x3c(0dB) 0xf0(-90dB)0xfc
|
|
|
|
|
* ------------------------------
|
|
|
|
|
* userspace value 0xc0 0
|
|
|
|
|
*/
|
|
|
|
|
static int dac_get_volsw(struct snd_kcontrol *kcontrol,
|
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
|
|
|
|
{
|
2018-01-29 12:37:53 +08:00
|
|
|
|
struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
|
2011-02-24 02:08:21 +08:00
|
|
|
|
int reg;
|
|
|
|
|
int l;
|
|
|
|
|
int r;
|
|
|
|
|
|
2020-06-16 13:20:33 +08:00
|
|
|
|
reg = snd_soc_component_read(component, SGTL5000_CHIP_DAC_VOL);
|
2011-02-24 02:08:21 +08:00
|
|
|
|
|
|
|
|
|
/* get left channel volume */
|
|
|
|
|
l = (reg & SGTL5000_DAC_VOL_LEFT_MASK) >> SGTL5000_DAC_VOL_LEFT_SHIFT;
|
|
|
|
|
|
|
|
|
|
/* get right channel volume */
|
|
|
|
|
r = (reg & SGTL5000_DAC_VOL_RIGHT_MASK) >> SGTL5000_DAC_VOL_RIGHT_SHIFT;
|
|
|
|
|
|
|
|
|
|
/* make sure value fall in (0x3c,0xfc) */
|
|
|
|
|
l = clamp(l, 0x3c, 0xfc);
|
|
|
|
|
r = clamp(r, 0x3c, 0xfc);
|
|
|
|
|
|
|
|
|
|
/* invert it and map to userspace value */
|
|
|
|
|
l = 0xfc - l;
|
|
|
|
|
r = 0xfc - r;
|
|
|
|
|
|
|
|
|
|
ucontrol->value.integer.value[0] = l;
|
|
|
|
|
ucontrol->value.integer.value[1] = r;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* custom function to put of PCM playback volume
|
|
|
|
|
*
|
|
|
|
|
* dac volume register
|
|
|
|
|
* 15-------------8-7--------------0
|
|
|
|
|
* | R channel vol | L channel vol |
|
|
|
|
|
* -------------------------------
|
|
|
|
|
*
|
|
|
|
|
* PCM volume with 0.5017 dB steps from 0 to -90 dB
|
|
|
|
|
*
|
|
|
|
|
* register values map to dB
|
|
|
|
|
* 0x3B and less = Reserved
|
|
|
|
|
* 0x3C = 0 dB
|
|
|
|
|
* 0x3D = -0.5 dB
|
|
|
|
|
* 0xF0 = -90 dB
|
|
|
|
|
* 0xFC and greater = Muted
|
|
|
|
|
*
|
|
|
|
|
* userspace value map to register value
|
|
|
|
|
*
|
|
|
|
|
* userspace value 0xc0 0
|
|
|
|
|
* ------------------------------
|
|
|
|
|
* register value 0x3c(0dB) 0xf0(-90dB)0xfc
|
|
|
|
|
*/
|
|
|
|
|
static int dac_put_volsw(struct snd_kcontrol *kcontrol,
|
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
|
|
|
|
{
|
2018-01-29 12:37:53 +08:00
|
|
|
|
struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
|
2011-02-24 02:08:21 +08:00
|
|
|
|
int reg;
|
|
|
|
|
int l;
|
|
|
|
|
int r;
|
|
|
|
|
|
|
|
|
|
l = ucontrol->value.integer.value[0];
|
|
|
|
|
r = ucontrol->value.integer.value[1];
|
|
|
|
|
|
|
|
|
|
/* make sure userspace volume fall in (0, 0xfc-0x3c) */
|
|
|
|
|
l = clamp(l, 0, 0xfc - 0x3c);
|
|
|
|
|
r = clamp(r, 0, 0xfc - 0x3c);
|
|
|
|
|
|
|
|
|
|
/* invert it, get the value can be set to register */
|
|
|
|
|
l = 0xfc - l;
|
|
|
|
|
r = 0xfc - r;
|
|
|
|
|
|
|
|
|
|
/* shift to get the register value */
|
|
|
|
|
reg = l << SGTL5000_DAC_VOL_LEFT_SHIFT |
|
|
|
|
|
r << SGTL5000_DAC_VOL_RIGHT_SHIFT;
|
|
|
|
|
|
2018-01-29 12:37:53 +08:00
|
|
|
|
snd_soc_component_write(component, SGTL5000_CHIP_DAC_VOL, reg);
|
2011-02-24 02:08:21 +08:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-14 16:36:12 +08:00
|
|
|
|
/*
|
|
|
|
|
* custom function to get AVC threshold
|
|
|
|
|
*
|
|
|
|
|
* The threshold dB is calculated by rearranging the calculation from the
|
|
|
|
|
* avc_put_threshold function: register_value = 10^(dB/20) * 0.636 * 2^15 ==>
|
|
|
|
|
* dB = ( fls(register_value) - 14.347 ) * 6.02
|
|
|
|
|
*
|
2018-04-23 08:02:10 +08:00
|
|
|
|
* As this calculation is expensive and the threshold dB values may not exceed
|
2017-06-14 16:36:12 +08:00
|
|
|
|
* 0 to 96 we use pre-calculated values.
|
|
|
|
|
*/
|
|
|
|
|
static int avc_get_threshold(struct snd_kcontrol *kcontrol,
|
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
|
|
|
|
{
|
2018-01-29 12:37:53 +08:00
|
|
|
|
struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
|
2017-06-14 16:36:12 +08:00
|
|
|
|
int db, i;
|
2020-06-16 13:20:33 +08:00
|
|
|
|
u16 reg = snd_soc_component_read(component, SGTL5000_DAP_AVC_THRESHOLD);
|
2017-06-14 16:36:12 +08:00
|
|
|
|
|
|
|
|
|
/* register value 0 => -96dB */
|
|
|
|
|
if (!reg) {
|
|
|
|
|
ucontrol->value.integer.value[0] = 96;
|
|
|
|
|
ucontrol->value.integer.value[1] = 96;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* get dB from register value (rounded down) */
|
|
|
|
|
for (i = 0; avc_thr_db2reg[i] > reg; i++)
|
|
|
|
|
;
|
|
|
|
|
db = i;
|
|
|
|
|
|
|
|
|
|
ucontrol->value.integer.value[0] = db;
|
|
|
|
|
ucontrol->value.integer.value[1] = db;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* custom function to put AVC threshold
|
|
|
|
|
*
|
|
|
|
|
* The register value is calculated by following formula:
|
|
|
|
|
* register_value = 10^(dB/20) * 0.636 * 2^15
|
2018-04-23 08:02:10 +08:00
|
|
|
|
* As this calculation is expensive and the threshold dB values may not exceed
|
2017-06-14 16:36:12 +08:00
|
|
|
|
* 0 to 96 we use pre-calculated values.
|
|
|
|
|
*/
|
|
|
|
|
static int avc_put_threshold(struct snd_kcontrol *kcontrol,
|
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
|
|
|
|
{
|
2018-01-29 12:37:53 +08:00
|
|
|
|
struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
|
2017-06-14 16:36:12 +08:00
|
|
|
|
int db;
|
|
|
|
|
u16 reg;
|
|
|
|
|
|
|
|
|
|
db = (int)ucontrol->value.integer.value[0];
|
|
|
|
|
if (db < 0 || db > 96)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
reg = avc_thr_db2reg[db];
|
2018-01-29 12:37:53 +08:00
|
|
|
|
snd_soc_component_write(component, SGTL5000_DAP_AVC_THRESHOLD, reg);
|
2017-06-14 16:36:12 +08:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-24 02:08:21 +08:00
|
|
|
|
static const DECLARE_TLV_DB_SCALE(capture_6db_attenuate, -600, 600, 0);
|
|
|
|
|
|
|
|
|
|
/* tlv for mic gain, 0db 20db 30db 40db */
|
2015-08-02 23:19:53 +08:00
|
|
|
|
static const DECLARE_TLV_DB_RANGE(mic_gain_tlv,
|
2011-02-24 02:08:21 +08:00
|
|
|
|
0, 0, TLV_DB_SCALE_ITEM(0, 0, 0),
|
2015-08-02 23:19:53 +08:00
|
|
|
|
1, 3, TLV_DB_SCALE_ITEM(2000, 1000, 0)
|
|
|
|
|
);
|
2011-02-24 02:08:21 +08:00
|
|
|
|
|
2018-02-19 17:03:45 +08:00
|
|
|
|
/* tlv for DAP channels, 0% - 100% - 200% */
|
|
|
|
|
static const DECLARE_TLV_DB_SCALE(dap_volume, 0, 1, 0);
|
|
|
|
|
|
2018-02-19 17:03:46 +08:00
|
|
|
|
/* tlv for bass bands, -11.75db to 12.0db, step .25db */
|
|
|
|
|
static const DECLARE_TLV_DB_SCALE(bass_band, -1175, 25, 0);
|
|
|
|
|
|
2011-02-24 02:08:21 +08:00
|
|
|
|
/* tlv for hp volume, -51.5db to 12.0db, step .5db */
|
|
|
|
|
static const DECLARE_TLV_DB_SCALE(headphone_volume, -5150, 50, 0);
|
|
|
|
|
|
2016-07-12 16:41:18 +08:00
|
|
|
|
/* tlv for lineout volume, 31 steps of .5db each */
|
|
|
|
|
static const DECLARE_TLV_DB_SCALE(lineout_volume, -1550, 50, 0);
|
|
|
|
|
|
2017-06-14 16:36:12 +08:00
|
|
|
|
/* tlv for dap avc max gain, 0db, 6db, 12db */
|
|
|
|
|
static const DECLARE_TLV_DB_SCALE(avc_max_gain, 0, 600, 0);
|
|
|
|
|
|
|
|
|
|
/* tlv for dap avc threshold, */
|
|
|
|
|
static const DECLARE_TLV_DB_MINMAX(avc_threshold, 0, 9600);
|
|
|
|
|
|
2011-02-24 02:08:21 +08:00
|
|
|
|
static const struct snd_kcontrol_new sgtl5000_snd_controls[] = {
|
|
|
|
|
/* SOC_DOUBLE_S8_TLV with invert */
|
|
|
|
|
{
|
|
|
|
|
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
|
|
|
|
|
.name = "PCM Playback Volume",
|
|
|
|
|
.access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |
|
|
|
|
|
SNDRV_CTL_ELEM_ACCESS_READWRITE,
|
|
|
|
|
.info = dac_info_volsw,
|
|
|
|
|
.get = dac_get_volsw,
|
|
|
|
|
.put = dac_put_volsw,
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
SOC_DOUBLE("Capture Volume", SGTL5000_CHIP_ANA_ADC_CTRL, 0, 4, 0xf, 0),
|
|
|
|
|
SOC_SINGLE_TLV("Capture Attenuate Switch (-6dB)",
|
|
|
|
|
SGTL5000_CHIP_ANA_ADC_CTRL,
|
2013-07-31 22:44:30 +08:00
|
|
|
|
8, 1, 0, capture_6db_attenuate),
|
2011-02-24 02:08:21 +08:00
|
|
|
|
SOC_SINGLE("Capture ZC Switch", SGTL5000_CHIP_ANA_CTRL, 1, 1, 0),
|
2019-07-19 18:05:34 +08:00
|
|
|
|
SOC_SINGLE("Capture Switch", SGTL5000_CHIP_ANA_CTRL, 0, 1, 1),
|
2011-02-24 02:08:21 +08:00
|
|
|
|
|
|
|
|
|
SOC_DOUBLE_TLV("Headphone Playback Volume",
|
|
|
|
|
SGTL5000_CHIP_ANA_HP_CTRL,
|
|
|
|
|
0, 8,
|
|
|
|
|
0x7f, 1,
|
|
|
|
|
headphone_volume),
|
2016-08-31 15:26:31 +08:00
|
|
|
|
SOC_SINGLE("Headphone Playback Switch", SGTL5000_CHIP_ANA_CTRL,
|
|
|
|
|
4, 1, 1),
|
2011-02-24 02:08:21 +08:00
|
|
|
|
SOC_SINGLE("Headphone Playback ZC Switch", SGTL5000_CHIP_ANA_CTRL,
|
|
|
|
|
5, 1, 0),
|
|
|
|
|
|
|
|
|
|
SOC_SINGLE_TLV("Mic Volume", SGTL5000_CHIP_MIC_CTRL,
|
2012-12-24 01:45:31 +08:00
|
|
|
|
0, 3, 0, mic_gain_tlv),
|
2016-07-12 16:41:18 +08:00
|
|
|
|
|
|
|
|
|
SOC_DOUBLE_TLV("Lineout Playback Volume",
|
|
|
|
|
SGTL5000_CHIP_LINE_OUT_VOL,
|
|
|
|
|
SGTL5000_LINE_OUT_VOL_LEFT_SHIFT,
|
|
|
|
|
SGTL5000_LINE_OUT_VOL_RIGHT_SHIFT,
|
|
|
|
|
0x1f, 1,
|
|
|
|
|
lineout_volume),
|
2016-08-31 15:26:31 +08:00
|
|
|
|
SOC_SINGLE("Lineout Playback Switch", SGTL5000_CHIP_ANA_CTRL, 8, 1, 1),
|
2017-06-14 16:36:12 +08:00
|
|
|
|
|
2018-02-19 17:03:45 +08:00
|
|
|
|
SOC_SINGLE_TLV("DAP Main channel", SGTL5000_DAP_MAIN_CHAN,
|
|
|
|
|
0, 0xffff, 0, dap_volume),
|
|
|
|
|
|
|
|
|
|
SOC_SINGLE_TLV("DAP Mix channel", SGTL5000_DAP_MIX_CHAN,
|
|
|
|
|
0, 0xffff, 0, dap_volume),
|
2017-06-14 16:36:12 +08:00
|
|
|
|
/* Automatic Volume Control (DAP AVC) */
|
|
|
|
|
SOC_SINGLE("AVC Switch", SGTL5000_DAP_AVC_CTRL, 0, 1, 0),
|
|
|
|
|
SOC_SINGLE("AVC Hard Limiter Switch", SGTL5000_DAP_AVC_CTRL, 5, 1, 0),
|
|
|
|
|
SOC_SINGLE_TLV("AVC Max Gain Volume", SGTL5000_DAP_AVC_CTRL, 12, 2, 0,
|
|
|
|
|
avc_max_gain),
|
|
|
|
|
SOC_SINGLE("AVC Integrator Response", SGTL5000_DAP_AVC_CTRL, 8, 3, 0),
|
|
|
|
|
SOC_SINGLE_EXT_TLV("AVC Threshold Volume", SGTL5000_DAP_AVC_THRESHOLD,
|
|
|
|
|
0, 96, 0, avc_get_threshold, avc_put_threshold,
|
|
|
|
|
avc_threshold),
|
2018-02-19 17:03:46 +08:00
|
|
|
|
|
|
|
|
|
SOC_SINGLE_TLV("BASS 0", SGTL5000_DAP_EQ_BASS_BAND0,
|
|
|
|
|
0, 0x5F, 0, bass_band),
|
|
|
|
|
|
|
|
|
|
SOC_SINGLE_TLV("BASS 1", SGTL5000_DAP_EQ_BASS_BAND1,
|
|
|
|
|
0, 0x5F, 0, bass_band),
|
|
|
|
|
|
|
|
|
|
SOC_SINGLE_TLV("BASS 2", SGTL5000_DAP_EQ_BASS_BAND2,
|
|
|
|
|
0, 0x5F, 0, bass_band),
|
|
|
|
|
|
|
|
|
|
SOC_SINGLE_TLV("BASS 3", SGTL5000_DAP_EQ_BASS_BAND3,
|
|
|
|
|
0, 0x5F, 0, bass_band),
|
|
|
|
|
|
|
|
|
|
SOC_SINGLE_TLV("BASS 4", SGTL5000_DAP_EQ_BASS_BAND4,
|
|
|
|
|
0, 0x5F, 0, bass_band),
|
2011-02-24 02:08:21 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* mute the codec used by alsa core */
|
2020-07-09 09:56:20 +08:00
|
|
|
|
static int sgtl5000_mute_stream(struct snd_soc_dai *codec_dai, int mute, int direction)
|
2011-02-24 02:08:21 +08:00
|
|
|
|
{
|
2018-01-29 12:37:53 +08:00
|
|
|
|
struct snd_soc_component *component = codec_dai->component;
|
2018-02-02 20:10:29 +08:00
|
|
|
|
u16 i2s_pwr = SGTL5000_I2S_IN_POWERUP;
|
2011-02-24 02:08:21 +08:00
|
|
|
|
|
2018-02-02 20:10:29 +08:00
|
|
|
|
/*
|
|
|
|
|
* During 'digital mute' do not mute DAC
|
|
|
|
|
* because LINE_IN would be muted aswell. We want to mute
|
|
|
|
|
* only I2S block - this can be done by powering it off
|
|
|
|
|
*/
|
2018-02-14 23:39:30 +08:00
|
|
|
|
snd_soc_component_update_bits(component, SGTL5000_CHIP_DIG_POWER,
|
2018-02-02 20:10:29 +08:00
|
|
|
|
i2s_pwr, mute ? 0 : i2s_pwr);
|
2011-02-24 02:08:21 +08:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* set codec format */
|
|
|
|
|
static int sgtl5000_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
|
|
|
|
|
{
|
2018-01-29 12:37:53 +08:00
|
|
|
|
struct snd_soc_component *component = codec_dai->component;
|
|
|
|
|
struct sgtl5000_priv *sgtl5000 = snd_soc_component_get_drvdata(component);
|
2011-02-24 02:08:21 +08:00
|
|
|
|
u16 i2sctl = 0;
|
|
|
|
|
|
|
|
|
|
sgtl5000->master = 0;
|
|
|
|
|
/*
|
|
|
|
|
* i2s clock and frame master setting.
|
|
|
|
|
* ONLY support:
|
|
|
|
|
* - clock and frame slave,
|
|
|
|
|
* - clock and frame master
|
|
|
|
|
*/
|
|
|
|
|
switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
|
|
|
|
|
case SND_SOC_DAIFMT_CBS_CFS:
|
|
|
|
|
break;
|
|
|
|
|
case SND_SOC_DAIFMT_CBM_CFM:
|
|
|
|
|
i2sctl |= SGTL5000_I2S_MASTER;
|
|
|
|
|
sgtl5000->master = 1;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* setting i2s data format */
|
|
|
|
|
switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
|
|
|
|
|
case SND_SOC_DAIFMT_DSP_A:
|
2015-01-30 19:58:24 +08:00
|
|
|
|
i2sctl |= SGTL5000_I2S_MODE_PCM << SGTL5000_I2S_MODE_SHIFT;
|
2011-02-24 02:08:21 +08:00
|
|
|
|
break;
|
|
|
|
|
case SND_SOC_DAIFMT_DSP_B:
|
2015-01-30 19:58:24 +08:00
|
|
|
|
i2sctl |= SGTL5000_I2S_MODE_PCM << SGTL5000_I2S_MODE_SHIFT;
|
2011-02-24 02:08:21 +08:00
|
|
|
|
i2sctl |= SGTL5000_I2S_LRALIGN;
|
|
|
|
|
break;
|
|
|
|
|
case SND_SOC_DAIFMT_I2S:
|
2015-01-30 19:58:24 +08:00
|
|
|
|
i2sctl |= SGTL5000_I2S_MODE_I2S_LJ << SGTL5000_I2S_MODE_SHIFT;
|
2011-02-24 02:08:21 +08:00
|
|
|
|
break;
|
|
|
|
|
case SND_SOC_DAIFMT_RIGHT_J:
|
2015-01-30 19:58:24 +08:00
|
|
|
|
i2sctl |= SGTL5000_I2S_MODE_RJ << SGTL5000_I2S_MODE_SHIFT;
|
2011-02-24 02:08:21 +08:00
|
|
|
|
i2sctl |= SGTL5000_I2S_LRPOL;
|
|
|
|
|
break;
|
|
|
|
|
case SND_SOC_DAIFMT_LEFT_J:
|
2015-01-30 19:58:24 +08:00
|
|
|
|
i2sctl |= SGTL5000_I2S_MODE_I2S_LJ << SGTL5000_I2S_MODE_SHIFT;
|
2011-02-24 02:08:21 +08:00
|
|
|
|
i2sctl |= SGTL5000_I2S_LRALIGN;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sgtl5000->fmt = fmt & SND_SOC_DAIFMT_FORMAT_MASK;
|
|
|
|
|
|
|
|
|
|
/* Clock inversion */
|
|
|
|
|
switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
|
|
|
|
|
case SND_SOC_DAIFMT_NB_NF:
|
|
|
|
|
break;
|
|
|
|
|
case SND_SOC_DAIFMT_IB_NF:
|
|
|
|
|
i2sctl |= SGTL5000_I2S_SCLK_INV;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-29 12:37:53 +08:00
|
|
|
|
snd_soc_component_write(component, SGTL5000_CHIP_I2S_CTRL, i2sctl);
|
2011-02-24 02:08:21 +08:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* set codec sysclk */
|
|
|
|
|
static int sgtl5000_set_dai_sysclk(struct snd_soc_dai *codec_dai,
|
|
|
|
|
int clk_id, unsigned int freq, int dir)
|
|
|
|
|
{
|
2018-01-29 12:37:53 +08:00
|
|
|
|
struct snd_soc_component *component = codec_dai->component;
|
|
|
|
|
struct sgtl5000_priv *sgtl5000 = snd_soc_component_get_drvdata(component);
|
2011-02-24 02:08:21 +08:00
|
|
|
|
|
|
|
|
|
switch (clk_id) {
|
|
|
|
|
case SGTL5000_SYSCLK:
|
|
|
|
|
sgtl5000->sysclk = freq;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* set clock according to i2s frame clock,
|
2014-10-07 21:50:56 +08:00
|
|
|
|
* sgtl5000 provides 2 clock sources:
|
|
|
|
|
* 1. sys_mclk: sample freq can only be configured to
|
2011-02-24 02:08:21 +08:00
|
|
|
|
* 1/256, 1/384, 1/512 of sys_mclk.
|
2014-10-07 21:50:56 +08:00
|
|
|
|
* 2. pll: can derive any audio clocks.
|
2011-02-24 02:08:21 +08:00
|
|
|
|
*
|
|
|
|
|
* clock setting rules:
|
2014-10-07 21:50:56 +08:00
|
|
|
|
* 1. in slave mode, only sys_mclk can be used
|
|
|
|
|
* 2. as constraint by sys_mclk, sample freq should be set to 32 kHz, 44.1 kHz
|
|
|
|
|
* and above.
|
|
|
|
|
* 3. usage of sys_mclk is preferred over pll to save power.
|
2011-02-24 02:08:21 +08:00
|
|
|
|
*/
|
2018-01-29 12:37:53 +08:00
|
|
|
|
static int sgtl5000_set_clock(struct snd_soc_component *component, int frame_rate)
|
2011-02-24 02:08:21 +08:00
|
|
|
|
{
|
2018-01-29 12:37:53 +08:00
|
|
|
|
struct sgtl5000_priv *sgtl5000 = snd_soc_component_get_drvdata(component);
|
2011-02-24 02:08:21 +08:00
|
|
|
|
int clk_ctl = 0;
|
|
|
|
|
int sys_fs; /* sample freq */
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* sample freq should be divided by frame clock,
|
2014-10-07 21:50:56 +08:00
|
|
|
|
* if frame clock is lower than 44.1 kHz, sample freq should be set to
|
|
|
|
|
* 32 kHz or 44.1 kHz.
|
2011-02-24 02:08:21 +08:00
|
|
|
|
*/
|
|
|
|
|
switch (frame_rate) {
|
|
|
|
|
case 8000:
|
|
|
|
|
case 16000:
|
|
|
|
|
sys_fs = 32000;
|
|
|
|
|
break;
|
|
|
|
|
case 11025:
|
|
|
|
|
case 22050:
|
|
|
|
|
sys_fs = 44100;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
sys_fs = frame_rate;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* set divided factor of frame clock */
|
|
|
|
|
switch (sys_fs / frame_rate) {
|
|
|
|
|
case 4:
|
|
|
|
|
clk_ctl |= SGTL5000_RATE_MODE_DIV_4 << SGTL5000_RATE_MODE_SHIFT;
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
clk_ctl |= SGTL5000_RATE_MODE_DIV_2 << SGTL5000_RATE_MODE_SHIFT;
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
clk_ctl |= SGTL5000_RATE_MODE_DIV_1 << SGTL5000_RATE_MODE_SHIFT;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* set the sys_fs according to frame rate */
|
|
|
|
|
switch (sys_fs) {
|
|
|
|
|
case 32000:
|
|
|
|
|
clk_ctl |= SGTL5000_SYS_FS_32k << SGTL5000_SYS_FS_SHIFT;
|
|
|
|
|
break;
|
|
|
|
|
case 44100:
|
|
|
|
|
clk_ctl |= SGTL5000_SYS_FS_44_1k << SGTL5000_SYS_FS_SHIFT;
|
|
|
|
|
break;
|
|
|
|
|
case 48000:
|
|
|
|
|
clk_ctl |= SGTL5000_SYS_FS_48k << SGTL5000_SYS_FS_SHIFT;
|
|
|
|
|
break;
|
|
|
|
|
case 96000:
|
|
|
|
|
clk_ctl |= SGTL5000_SYS_FS_96k << SGTL5000_SYS_FS_SHIFT;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2018-01-29 12:37:53 +08:00
|
|
|
|
dev_err(component->dev, "frame rate %d not supported\n",
|
2011-02-24 02:08:21 +08:00
|
|
|
|
frame_rate);
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* calculate the divider of mclk/sample_freq,
|
2014-10-07 21:50:56 +08:00
|
|
|
|
* factor of freq = 96 kHz can only be 256, since mclk is in the range
|
|
|
|
|
* of 8 MHz - 27 MHz
|
2011-02-24 02:08:21 +08:00
|
|
|
|
*/
|
ASoC: sgtl5000: Allow 8kHz playback in codec slave mode
When trying to play a 8kHz file with codec in slave mode we get the following
error on a mx28evk:
$ aplay -Dhw:0,0 stereo_8k.wav
Playing WAVE 'stereo_8k.wav' : Signed 16 bit Little Endian, Rate 8000 Hz, Stereo
[ 21.218647] sgtl5000 0-000a: PLL not supported in slave mode
[ 21.224559] sgtl5000 0-000a: 128 ratio is not supported. SYS_MCLK needs to be 256, 384 or 512 * fs
[ 21.233687] sgtl5000 0-000a: ASoC: can't set sgtl5000 hw params: -22
aplay: set_params:1123: Unable to install hw params:
This error happens because we are using 'sys_fs' instead of 'frame_rate' in the
valid ratio check.
Use the real'frame_rate' so that the ratio is correctly calculated and the
playback can run.
sgtl5000 codec manual states that in 'Synchronous SYS_MCLK input' mode that the
following SYS_CLK frequencies are allowed: 256*fs, 384*fs, 512*fs.
, where fs is the sampling frequency, which can be in the range of:
8, 11.025, 16, 22.5, 32, 44.1, 48, 96 kHz.
Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2014-11-27 23:02:01 +08:00
|
|
|
|
switch (sgtl5000->sysclk / frame_rate) {
|
2011-02-24 02:08:21 +08:00
|
|
|
|
case 256:
|
|
|
|
|
clk_ctl |= SGTL5000_MCLK_FREQ_256FS <<
|
|
|
|
|
SGTL5000_MCLK_FREQ_SHIFT;
|
|
|
|
|
break;
|
|
|
|
|
case 384:
|
|
|
|
|
clk_ctl |= SGTL5000_MCLK_FREQ_384FS <<
|
|
|
|
|
SGTL5000_MCLK_FREQ_SHIFT;
|
|
|
|
|
break;
|
|
|
|
|
case 512:
|
|
|
|
|
clk_ctl |= SGTL5000_MCLK_FREQ_512FS <<
|
|
|
|
|
SGTL5000_MCLK_FREQ_SHIFT;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2014-10-07 21:50:56 +08:00
|
|
|
|
/* if mclk does not satisfy the divider, use pll */
|
2011-02-24 02:08:21 +08:00
|
|
|
|
if (sgtl5000->master) {
|
|
|
|
|
clk_ctl |= SGTL5000_MCLK_FREQ_PLL <<
|
|
|
|
|
SGTL5000_MCLK_FREQ_SHIFT;
|
|
|
|
|
} else {
|
2018-01-29 12:37:53 +08:00
|
|
|
|
dev_err(component->dev,
|
2011-02-24 02:08:21 +08:00
|
|
|
|
"PLL not supported in slave mode\n");
|
2018-01-29 12:37:53 +08:00
|
|
|
|
dev_err(component->dev, "%d ratio is not supported. "
|
2014-10-03 03:16:50 +08:00
|
|
|
|
"SYS_MCLK needs to be 256, 384 or 512 * fs\n",
|
ASoC: sgtl5000: Allow 8kHz playback in codec slave mode
When trying to play a 8kHz file with codec in slave mode we get the following
error on a mx28evk:
$ aplay -Dhw:0,0 stereo_8k.wav
Playing WAVE 'stereo_8k.wav' : Signed 16 bit Little Endian, Rate 8000 Hz, Stereo
[ 21.218647] sgtl5000 0-000a: PLL not supported in slave mode
[ 21.224559] sgtl5000 0-000a: 128 ratio is not supported. SYS_MCLK needs to be 256, 384 or 512 * fs
[ 21.233687] sgtl5000 0-000a: ASoC: can't set sgtl5000 hw params: -22
aplay: set_params:1123: Unable to install hw params:
This error happens because we are using 'sys_fs' instead of 'frame_rate' in the
valid ratio check.
Use the real'frame_rate' so that the ratio is correctly calculated and the
playback can run.
sgtl5000 codec manual states that in 'Synchronous SYS_MCLK input' mode that the
following SYS_CLK frequencies are allowed: 256*fs, 384*fs, 512*fs.
, where fs is the sampling frequency, which can be in the range of:
8, 11.025, 16, 22.5, 32, 44.1, 48, 96 kHz.
Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2014-11-27 23:02:01 +08:00
|
|
|
|
sgtl5000->sysclk / frame_rate);
|
2011-02-24 02:08:21 +08:00
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* if using pll, please check manual 6.4.2 for detail */
|
|
|
|
|
if ((clk_ctl & SGTL5000_MCLK_FREQ_MASK) == SGTL5000_MCLK_FREQ_PLL) {
|
|
|
|
|
u64 out, t;
|
|
|
|
|
int div2;
|
|
|
|
|
int pll_ctl;
|
|
|
|
|
unsigned int in, int_div, frac_div;
|
|
|
|
|
|
|
|
|
|
if (sgtl5000->sysclk > 17000000) {
|
|
|
|
|
div2 = 1;
|
|
|
|
|
in = sgtl5000->sysclk / 2;
|
|
|
|
|
} else {
|
|
|
|
|
div2 = 0;
|
|
|
|
|
in = sgtl5000->sysclk;
|
|
|
|
|
}
|
|
|
|
|
if (sys_fs == 44100)
|
|
|
|
|
out = 180633600;
|
|
|
|
|
else
|
|
|
|
|
out = 196608000;
|
|
|
|
|
t = do_div(out, in);
|
|
|
|
|
int_div = out;
|
|
|
|
|
t *= 2048;
|
|
|
|
|
do_div(t, in);
|
|
|
|
|
frac_div = t;
|
|
|
|
|
pll_ctl = int_div << SGTL5000_PLL_INT_DIV_SHIFT |
|
|
|
|
|
frac_div << SGTL5000_PLL_FRAC_DIV_SHIFT;
|
|
|
|
|
|
2018-01-29 12:37:53 +08:00
|
|
|
|
snd_soc_component_write(component, SGTL5000_CHIP_PLL_CTRL, pll_ctl);
|
2011-02-24 02:08:21 +08:00
|
|
|
|
if (div2)
|
2018-01-29 12:37:53 +08:00
|
|
|
|
snd_soc_component_update_bits(component,
|
2011-02-24 02:08:21 +08:00
|
|
|
|
SGTL5000_CHIP_CLK_TOP_CTRL,
|
|
|
|
|
SGTL5000_INPUT_FREQ_DIV2,
|
|
|
|
|
SGTL5000_INPUT_FREQ_DIV2);
|
|
|
|
|
else
|
2018-01-29 12:37:53 +08:00
|
|
|
|
snd_soc_component_update_bits(component,
|
2011-02-24 02:08:21 +08:00
|
|
|
|
SGTL5000_CHIP_CLK_TOP_CTRL,
|
|
|
|
|
SGTL5000_INPUT_FREQ_DIV2,
|
|
|
|
|
0);
|
|
|
|
|
|
|
|
|
|
/* power up pll */
|
2018-01-29 12:37:53 +08:00
|
|
|
|
snd_soc_component_update_bits(component, SGTL5000_CHIP_ANA_POWER,
|
2011-02-24 02:08:21 +08:00
|
|
|
|
SGTL5000_PLL_POWERUP | SGTL5000_VCOAMP_POWERUP,
|
|
|
|
|
SGTL5000_PLL_POWERUP | SGTL5000_VCOAMP_POWERUP);
|
2013-08-05 15:36:02 +08:00
|
|
|
|
|
|
|
|
|
/* if using pll, clk_ctrl must be set after pll power up */
|
2018-01-29 12:37:53 +08:00
|
|
|
|
snd_soc_component_write(component, SGTL5000_CHIP_CLK_CTRL, clk_ctl);
|
2011-02-24 02:08:21 +08:00
|
|
|
|
} else {
|
2013-08-05 15:36:02 +08:00
|
|
|
|
/* otherwise, clk_ctrl must be set before pll power down */
|
2018-01-29 12:37:53 +08:00
|
|
|
|
snd_soc_component_write(component, SGTL5000_CHIP_CLK_CTRL, clk_ctl);
|
2013-08-05 15:36:02 +08:00
|
|
|
|
|
2011-02-24 02:08:21 +08:00
|
|
|
|
/* power down pll */
|
2018-01-29 12:37:53 +08:00
|
|
|
|
snd_soc_component_update_bits(component, SGTL5000_CHIP_ANA_POWER,
|
2011-02-24 02:08:21 +08:00
|
|
|
|
SGTL5000_PLL_POWERUP | SGTL5000_VCOAMP_POWERUP,
|
|
|
|
|
0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Set PCM DAI bit size and sample rate.
|
|
|
|
|
* input: params_rate, params_fmt
|
|
|
|
|
*/
|
|
|
|
|
static int sgtl5000_pcm_hw_params(struct snd_pcm_substream *substream,
|
|
|
|
|
struct snd_pcm_hw_params *params,
|
|
|
|
|
struct snd_soc_dai *dai)
|
|
|
|
|
{
|
2018-01-29 12:37:53 +08:00
|
|
|
|
struct snd_soc_component *component = dai->component;
|
|
|
|
|
struct sgtl5000_priv *sgtl5000 = snd_soc_component_get_drvdata(component);
|
2011-02-24 02:08:21 +08:00
|
|
|
|
int channels = params_channels(params);
|
|
|
|
|
int i2s_ctl = 0;
|
|
|
|
|
int stereo;
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
/* sysclk should already set */
|
|
|
|
|
if (!sgtl5000->sysclk) {
|
2018-01-29 12:37:53 +08:00
|
|
|
|
dev_err(component->dev, "%s: set sysclk first!\n", __func__);
|
2011-02-24 02:08:21 +08:00
|
|
|
|
return -EFAULT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
|
|
|
|
|
stereo = SGTL5000_DAC_STEREO;
|
|
|
|
|
else
|
|
|
|
|
stereo = SGTL5000_ADC_STEREO;
|
|
|
|
|
|
|
|
|
|
/* set mono to save power */
|
2018-01-29 12:37:53 +08:00
|
|
|
|
snd_soc_component_update_bits(component, SGTL5000_CHIP_ANA_POWER, stereo,
|
2011-02-24 02:08:21 +08:00
|
|
|
|
channels == 1 ? 0 : stereo);
|
|
|
|
|
|
|
|
|
|
/* set codec clock base on lrclk */
|
2018-01-29 12:37:53 +08:00
|
|
|
|
ret = sgtl5000_set_clock(component, params_rate(params));
|
2011-02-24 02:08:21 +08:00
|
|
|
|
if (ret)
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
|
|
/* set i2s data format */
|
2014-07-31 19:46:05 +08:00
|
|
|
|
switch (params_width(params)) {
|
|
|
|
|
case 16:
|
2011-02-24 02:08:21 +08:00
|
|
|
|
if (sgtl5000->fmt == SND_SOC_DAIFMT_RIGHT_J)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
i2s_ctl |= SGTL5000_I2S_DLEN_16 << SGTL5000_I2S_DLEN_SHIFT;
|
|
|
|
|
i2s_ctl |= SGTL5000_I2S_SCLKFREQ_32FS <<
|
|
|
|
|
SGTL5000_I2S_SCLKFREQ_SHIFT;
|
|
|
|
|
break;
|
2014-07-31 19:46:05 +08:00
|
|
|
|
case 20:
|
2011-02-24 02:08:21 +08:00
|
|
|
|
i2s_ctl |= SGTL5000_I2S_DLEN_20 << SGTL5000_I2S_DLEN_SHIFT;
|
|
|
|
|
i2s_ctl |= SGTL5000_I2S_SCLKFREQ_64FS <<
|
|
|
|
|
SGTL5000_I2S_SCLKFREQ_SHIFT;
|
|
|
|
|
break;
|
2014-07-31 19:46:05 +08:00
|
|
|
|
case 24:
|
2011-02-24 02:08:21 +08:00
|
|
|
|
i2s_ctl |= SGTL5000_I2S_DLEN_24 << SGTL5000_I2S_DLEN_SHIFT;
|
|
|
|
|
i2s_ctl |= SGTL5000_I2S_SCLKFREQ_64FS <<
|
|
|
|
|
SGTL5000_I2S_SCLKFREQ_SHIFT;
|
|
|
|
|
break;
|
2014-07-31 19:46:05 +08:00
|
|
|
|
case 32:
|
2011-02-24 02:08:21 +08:00
|
|
|
|
if (sgtl5000->fmt == SND_SOC_DAIFMT_RIGHT_J)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
i2s_ctl |= SGTL5000_I2S_DLEN_32 << SGTL5000_I2S_DLEN_SHIFT;
|
|
|
|
|
i2s_ctl |= SGTL5000_I2S_SCLKFREQ_64FS <<
|
|
|
|
|
SGTL5000_I2S_SCLKFREQ_SHIFT;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-29 12:37:53 +08:00
|
|
|
|
snd_soc_component_update_bits(component, SGTL5000_CHIP_I2S_CTRL,
|
2011-10-21 09:54:43 +08:00
|
|
|
|
SGTL5000_I2S_DLEN_MASK | SGTL5000_I2S_SCLKFREQ_MASK,
|
|
|
|
|
i2s_ctl);
|
2011-02-24 02:08:21 +08:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* set dac bias
|
|
|
|
|
* common state changes:
|
|
|
|
|
* startup:
|
|
|
|
|
* off --> standby --> prepare --> on
|
|
|
|
|
* standby --> prepare --> on
|
|
|
|
|
*
|
|
|
|
|
* stop:
|
|
|
|
|
* on --> prepare --> standby
|
|
|
|
|
*/
|
2018-01-29 12:37:53 +08:00
|
|
|
|
static int sgtl5000_set_bias_level(struct snd_soc_component *component,
|
2011-02-24 02:08:21 +08:00
|
|
|
|
enum snd_soc_bias_level level)
|
|
|
|
|
{
|
2018-02-16 23:29:19 +08:00
|
|
|
|
struct sgtl5000_priv *sgtl = snd_soc_component_get_drvdata(component);
|
2018-02-16 21:58:54 +08:00
|
|
|
|
int ret;
|
|
|
|
|
|
2011-02-24 02:08:21 +08:00
|
|
|
|
switch (level) {
|
|
|
|
|
case SND_SOC_BIAS_ON:
|
|
|
|
|
case SND_SOC_BIAS_PREPARE:
|
|
|
|
|
case SND_SOC_BIAS_STANDBY:
|
2018-02-16 21:58:54 +08:00
|
|
|
|
regcache_cache_only(sgtl->regmap, false);
|
|
|
|
|
ret = regcache_sync(sgtl->regmap);
|
|
|
|
|
if (ret) {
|
|
|
|
|
regcache_cache_only(sgtl->regmap, true);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-29 12:37:53 +08:00
|
|
|
|
snd_soc_component_update_bits(component, SGTL5000_CHIP_ANA_POWER,
|
2016-06-07 07:14:52 +08:00
|
|
|
|
SGTL5000_REFTOP_POWERUP,
|
|
|
|
|
SGTL5000_REFTOP_POWERUP);
|
2011-02-24 02:08:21 +08:00
|
|
|
|
break;
|
|
|
|
|
case SND_SOC_BIAS_OFF:
|
2018-02-16 21:58:54 +08:00
|
|
|
|
regcache_cache_only(sgtl->regmap, true);
|
2018-01-29 12:37:53 +08:00
|
|
|
|
snd_soc_component_update_bits(component, SGTL5000_CHIP_ANA_POWER,
|
2016-06-07 07:14:52 +08:00
|
|
|
|
SGTL5000_REFTOP_POWERUP, 0);
|
2011-02-24 02:08:21 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define SGTL5000_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
|
|
|
|
|
SNDRV_PCM_FMTBIT_S20_3LE |\
|
|
|
|
|
SNDRV_PCM_FMTBIT_S24_LE |\
|
|
|
|
|
SNDRV_PCM_FMTBIT_S32_LE)
|
|
|
|
|
|
2011-11-23 18:40:40 +08:00
|
|
|
|
static const struct snd_soc_dai_ops sgtl5000_ops = {
|
2011-02-24 02:08:21 +08:00
|
|
|
|
.hw_params = sgtl5000_pcm_hw_params,
|
2020-07-09 09:56:20 +08:00
|
|
|
|
.mute_stream = sgtl5000_mute_stream,
|
2011-02-24 02:08:21 +08:00
|
|
|
|
.set_fmt = sgtl5000_set_dai_fmt,
|
|
|
|
|
.set_sysclk = sgtl5000_set_dai_sysclk,
|
2020-07-09 09:56:20 +08:00
|
|
|
|
.no_capture_mute = 1,
|
2011-02-24 02:08:21 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static struct snd_soc_dai_driver sgtl5000_dai = {
|
|
|
|
|
.name = "sgtl5000",
|
|
|
|
|
.playback = {
|
|
|
|
|
.stream_name = "Playback",
|
|
|
|
|
.channels_min = 1,
|
|
|
|
|
.channels_max = 2,
|
|
|
|
|
/*
|
|
|
|
|
* only support 8~48K + 96K,
|
|
|
|
|
* TODO modify hw_param to support more
|
|
|
|
|
*/
|
|
|
|
|
.rates = SNDRV_PCM_RATE_8000_48000 | SNDRV_PCM_RATE_96000,
|
|
|
|
|
.formats = SGTL5000_FORMATS,
|
|
|
|
|
},
|
|
|
|
|
.capture = {
|
|
|
|
|
.stream_name = "Capture",
|
|
|
|
|
.channels_min = 1,
|
|
|
|
|
.channels_max = 2,
|
|
|
|
|
.rates = SNDRV_PCM_RATE_8000_48000 | SNDRV_PCM_RATE_96000,
|
|
|
|
|
.formats = SGTL5000_FORMATS,
|
|
|
|
|
},
|
|
|
|
|
.ops = &sgtl5000_ops,
|
2021-01-15 12:55:40 +08:00
|
|
|
|
.symmetric_rate = 1,
|
2011-02-24 02:08:21 +08:00
|
|
|
|
};
|
|
|
|
|
|
2013-05-05 02:39:34 +08:00
|
|
|
|
static bool sgtl5000_volatile(struct device *dev, unsigned int reg)
|
2011-02-24 02:08:21 +08:00
|
|
|
|
{
|
|
|
|
|
switch (reg) {
|
|
|
|
|
case SGTL5000_CHIP_ID:
|
|
|
|
|
case SGTL5000_CHIP_ADCDAC_CTRL:
|
|
|
|
|
case SGTL5000_CHIP_ANA_STATUS:
|
2013-05-05 02:39:34 +08:00
|
|
|
|
return true;
|
2011-02-24 02:08:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-05 02:39:34 +08:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool sgtl5000_readable(struct device *dev, unsigned int reg)
|
|
|
|
|
{
|
|
|
|
|
switch (reg) {
|
|
|
|
|
case SGTL5000_CHIP_ID:
|
|
|
|
|
case SGTL5000_CHIP_DIG_POWER:
|
|
|
|
|
case SGTL5000_CHIP_CLK_CTRL:
|
|
|
|
|
case SGTL5000_CHIP_I2S_CTRL:
|
|
|
|
|
case SGTL5000_CHIP_SSS_CTRL:
|
|
|
|
|
case SGTL5000_CHIP_ADCDAC_CTRL:
|
|
|
|
|
case SGTL5000_CHIP_DAC_VOL:
|
|
|
|
|
case SGTL5000_CHIP_PAD_STRENGTH:
|
|
|
|
|
case SGTL5000_CHIP_ANA_ADC_CTRL:
|
|
|
|
|
case SGTL5000_CHIP_ANA_HP_CTRL:
|
|
|
|
|
case SGTL5000_CHIP_ANA_CTRL:
|
|
|
|
|
case SGTL5000_CHIP_LINREG_CTRL:
|
|
|
|
|
case SGTL5000_CHIP_REF_CTRL:
|
|
|
|
|
case SGTL5000_CHIP_MIC_CTRL:
|
|
|
|
|
case SGTL5000_CHIP_LINE_OUT_CTRL:
|
|
|
|
|
case SGTL5000_CHIP_LINE_OUT_VOL:
|
|
|
|
|
case SGTL5000_CHIP_ANA_POWER:
|
|
|
|
|
case SGTL5000_CHIP_PLL_CTRL:
|
|
|
|
|
case SGTL5000_CHIP_CLK_TOP_CTRL:
|
|
|
|
|
case SGTL5000_CHIP_ANA_STATUS:
|
|
|
|
|
case SGTL5000_CHIP_SHORT_CTRL:
|
|
|
|
|
case SGTL5000_CHIP_ANA_TEST2:
|
|
|
|
|
case SGTL5000_DAP_CTRL:
|
|
|
|
|
case SGTL5000_DAP_PEQ:
|
|
|
|
|
case SGTL5000_DAP_BASS_ENHANCE:
|
|
|
|
|
case SGTL5000_DAP_BASS_ENHANCE_CTRL:
|
|
|
|
|
case SGTL5000_DAP_AUDIO_EQ:
|
|
|
|
|
case SGTL5000_DAP_SURROUND:
|
|
|
|
|
case SGTL5000_DAP_FLT_COEF_ACCESS:
|
|
|
|
|
case SGTL5000_DAP_COEF_WR_B0_MSB:
|
|
|
|
|
case SGTL5000_DAP_COEF_WR_B0_LSB:
|
|
|
|
|
case SGTL5000_DAP_EQ_BASS_BAND0:
|
|
|
|
|
case SGTL5000_DAP_EQ_BASS_BAND1:
|
|
|
|
|
case SGTL5000_DAP_EQ_BASS_BAND2:
|
|
|
|
|
case SGTL5000_DAP_EQ_BASS_BAND3:
|
|
|
|
|
case SGTL5000_DAP_EQ_BASS_BAND4:
|
|
|
|
|
case SGTL5000_DAP_MAIN_CHAN:
|
|
|
|
|
case SGTL5000_DAP_MIX_CHAN:
|
|
|
|
|
case SGTL5000_DAP_AVC_CTRL:
|
|
|
|
|
case SGTL5000_DAP_AVC_THRESHOLD:
|
|
|
|
|
case SGTL5000_DAP_AVC_ATTACK:
|
|
|
|
|
case SGTL5000_DAP_AVC_DECAY:
|
|
|
|
|
case SGTL5000_DAP_COEF_WR_B1_MSB:
|
|
|
|
|
case SGTL5000_DAP_COEF_WR_B1_LSB:
|
|
|
|
|
case SGTL5000_DAP_COEF_WR_B2_MSB:
|
|
|
|
|
case SGTL5000_DAP_COEF_WR_B2_LSB:
|
|
|
|
|
case SGTL5000_DAP_COEF_WR_A1_MSB:
|
|
|
|
|
case SGTL5000_DAP_COEF_WR_A1_LSB:
|
|
|
|
|
case SGTL5000_DAP_COEF_WR_A2_MSB:
|
|
|
|
|
case SGTL5000_DAP_COEF_WR_A2_LSB:
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2011-02-24 02:08:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2015-04-16 20:51:57 +08:00
|
|
|
|
/*
|
|
|
|
|
* This precalculated table contains all (vag_val * 100 / lo_calcntrl) results
|
|
|
|
|
* to select an appropriate lo_vol_* in SGTL5000_CHIP_LINE_OUT_VOL
|
|
|
|
|
* The calculatation was done for all possible register values which
|
|
|
|
|
* is the array index and the following formula: 10^((idx−15)/40) * 100
|
|
|
|
|
*/
|
|
|
|
|
static const u8 vol_quot_table[] = {
|
|
|
|
|
42, 45, 47, 50, 53, 56, 60, 63,
|
|
|
|
|
67, 71, 75, 79, 84, 89, 94, 100,
|
|
|
|
|
106, 112, 119, 126, 133, 141, 150, 158,
|
|
|
|
|
168, 178, 188, 200, 211, 224, 237, 251
|
|
|
|
|
};
|
|
|
|
|
|
2011-02-24 02:08:21 +08:00
|
|
|
|
/*
|
|
|
|
|
* sgtl5000 has 3 internal power supplies:
|
|
|
|
|
* 1. VAG, normally set to vdda/2
|
2014-10-07 21:50:56 +08:00
|
|
|
|
* 2. charge pump, set to different value
|
2011-02-24 02:08:21 +08:00
|
|
|
|
* according to voltage of vdda and vddio
|
|
|
|
|
* 3. line out VAG, normally set to vddio/2
|
|
|
|
|
*
|
|
|
|
|
* and should be set according to:
|
|
|
|
|
* 1. vddd provided by external or not
|
|
|
|
|
* 2. vdda and vddio voltage value. > 3.1v or not
|
|
|
|
|
*/
|
2018-01-29 12:37:53 +08:00
|
|
|
|
static int sgtl5000_set_power_regs(struct snd_soc_component *component)
|
2011-02-24 02:08:21 +08:00
|
|
|
|
{
|
|
|
|
|
int vddd;
|
|
|
|
|
int vdda;
|
|
|
|
|
int vddio;
|
|
|
|
|
u16 ana_pwr;
|
|
|
|
|
u16 lreg_ctrl;
|
|
|
|
|
int vag;
|
2015-04-16 20:51:56 +08:00
|
|
|
|
int lo_vag;
|
2015-04-16 20:51:57 +08:00
|
|
|
|
int vol_quot;
|
|
|
|
|
int lo_vol;
|
|
|
|
|
size_t i;
|
2018-01-29 12:37:53 +08:00
|
|
|
|
struct sgtl5000_priv *sgtl5000 = snd_soc_component_get_drvdata(component);
|
2011-02-24 02:08:21 +08:00
|
|
|
|
|
|
|
|
|
vdda = regulator_get_voltage(sgtl5000->supplies[VDDA].consumer);
|
|
|
|
|
vddio = regulator_get_voltage(sgtl5000->supplies[VDDIO].consumer);
|
2016-06-07 07:14:48 +08:00
|
|
|
|
vddd = (sgtl5000->num_supplies > VDDD)
|
|
|
|
|
? regulator_get_voltage(sgtl5000->supplies[VDDD].consumer)
|
|
|
|
|
: LDO_VOLTAGE;
|
2011-02-24 02:08:21 +08:00
|
|
|
|
|
|
|
|
|
vdda = vdda / 1000;
|
|
|
|
|
vddio = vddio / 1000;
|
|
|
|
|
vddd = vddd / 1000;
|
|
|
|
|
|
|
|
|
|
if (vdda <= 0 || vddio <= 0 || vddd < 0) {
|
2018-01-29 12:37:53 +08:00
|
|
|
|
dev_err(component->dev, "regulator voltage not set correctly\n");
|
2011-02-24 02:08:21 +08:00
|
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* according to datasheet, maximum voltage of supplies */
|
|
|
|
|
if (vdda > 3600 || vddio > 3600 || vddd > 1980) {
|
2018-01-29 12:37:53 +08:00
|
|
|
|
dev_err(component->dev,
|
2011-12-28 19:55:15 +08:00
|
|
|
|
"exceed max voltage vdda %dmV vddio %dmV vddd %dmV\n",
|
2011-02-24 02:08:21 +08:00
|
|
|
|
vdda, vddio, vddd);
|
|
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* reset value */
|
2020-06-16 13:20:33 +08:00
|
|
|
|
ana_pwr = snd_soc_component_read(component, SGTL5000_CHIP_ANA_POWER);
|
2011-02-24 02:08:21 +08:00
|
|
|
|
ana_pwr |= SGTL5000_DAC_STEREO |
|
|
|
|
|
SGTL5000_ADC_STEREO |
|
|
|
|
|
SGTL5000_REFTOP_POWERUP;
|
2020-06-16 13:20:33 +08:00
|
|
|
|
lreg_ctrl = snd_soc_component_read(component, SGTL5000_CHIP_LINREG_CTRL);
|
2011-02-24 02:08:21 +08:00
|
|
|
|
|
|
|
|
|
if (vddio < 3100 && vdda < 3100) {
|
|
|
|
|
/* enable internal oscillator used for charge pump */
|
2018-01-29 12:37:53 +08:00
|
|
|
|
snd_soc_component_update_bits(component, SGTL5000_CHIP_CLK_TOP_CTRL,
|
2011-02-24 02:08:21 +08:00
|
|
|
|
SGTL5000_INT_OSC_EN,
|
|
|
|
|
SGTL5000_INT_OSC_EN);
|
|
|
|
|
/* Enable VDDC charge pump */
|
|
|
|
|
ana_pwr |= SGTL5000_VDDC_CHRGPMP_POWERUP;
|
2019-07-19 18:05:37 +08:00
|
|
|
|
} else {
|
2015-02-27 23:06:45 +08:00
|
|
|
|
ana_pwr &= ~SGTL5000_VDDC_CHRGPMP_POWERUP;
|
2019-07-19 18:05:37 +08:00
|
|
|
|
/*
|
|
|
|
|
* if vddio == vdda the source of charge pump should be
|
|
|
|
|
* assigned manually to VDDIO
|
|
|
|
|
*/
|
2019-12-21 00:44:50 +08:00
|
|
|
|
if (regulator_is_equal(sgtl5000->supplies[VDDA].consumer,
|
|
|
|
|
sgtl5000->supplies[VDDIO].consumer)) {
|
2019-07-19 18:05:37 +08:00
|
|
|
|
lreg_ctrl |= SGTL5000_VDDC_ASSN_OVRD;
|
|
|
|
|
lreg_ctrl |= SGTL5000_VDDC_MAN_ASSN_VDDIO <<
|
|
|
|
|
SGTL5000_VDDC_MAN_ASSN_SHIFT;
|
|
|
|
|
}
|
2011-02-24 02:08:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-29 12:37:53 +08:00
|
|
|
|
snd_soc_component_write(component, SGTL5000_CHIP_LINREG_CTRL, lreg_ctrl);
|
2011-02-24 02:08:21 +08:00
|
|
|
|
|
2018-01-29 12:37:53 +08:00
|
|
|
|
snd_soc_component_write(component, SGTL5000_CHIP_ANA_POWER, ana_pwr);
|
2011-02-24 02:08:21 +08:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* set ADC/DAC VAG to vdda / 2,
|
|
|
|
|
* should stay in range (0.8v, 1.575v)
|
|
|
|
|
*/
|
|
|
|
|
vag = vdda / 2;
|
|
|
|
|
if (vag <= SGTL5000_ANA_GND_BASE)
|
|
|
|
|
vag = 0;
|
|
|
|
|
else if (vag >= SGTL5000_ANA_GND_BASE + SGTL5000_ANA_GND_STP *
|
|
|
|
|
(SGTL5000_ANA_GND_MASK >> SGTL5000_ANA_GND_SHIFT))
|
|
|
|
|
vag = SGTL5000_ANA_GND_MASK >> SGTL5000_ANA_GND_SHIFT;
|
|
|
|
|
else
|
|
|
|
|
vag = (vag - SGTL5000_ANA_GND_BASE) / SGTL5000_ANA_GND_STP;
|
|
|
|
|
|
2018-01-29 12:37:53 +08:00
|
|
|
|
snd_soc_component_update_bits(component, SGTL5000_CHIP_REF_CTRL,
|
2011-10-21 09:54:43 +08:00
|
|
|
|
SGTL5000_ANA_GND_MASK, vag << SGTL5000_ANA_GND_SHIFT);
|
2011-02-24 02:08:21 +08:00
|
|
|
|
|
|
|
|
|
/* set line out VAG to vddio / 2, in range (0.8v, 1.675v) */
|
2015-04-16 20:51:56 +08:00
|
|
|
|
lo_vag = vddio / 2;
|
|
|
|
|
if (lo_vag <= SGTL5000_LINE_OUT_GND_BASE)
|
|
|
|
|
lo_vag = 0;
|
|
|
|
|
else if (lo_vag >= SGTL5000_LINE_OUT_GND_BASE +
|
2011-02-24 02:08:21 +08:00
|
|
|
|
SGTL5000_LINE_OUT_GND_STP * SGTL5000_LINE_OUT_GND_MAX)
|
2015-04-16 20:51:56 +08:00
|
|
|
|
lo_vag = SGTL5000_LINE_OUT_GND_MAX;
|
2011-02-24 02:08:21 +08:00
|
|
|
|
else
|
2015-04-16 20:51:56 +08:00
|
|
|
|
lo_vag = (lo_vag - SGTL5000_LINE_OUT_GND_BASE) /
|
2011-02-24 02:08:21 +08:00
|
|
|
|
SGTL5000_LINE_OUT_GND_STP;
|
|
|
|
|
|
2018-01-29 12:37:53 +08:00
|
|
|
|
snd_soc_component_update_bits(component, SGTL5000_CHIP_LINE_OUT_CTRL,
|
2011-10-21 09:54:43 +08:00
|
|
|
|
SGTL5000_LINE_OUT_CURRENT_MASK |
|
|
|
|
|
SGTL5000_LINE_OUT_GND_MASK,
|
2015-04-16 20:51:56 +08:00
|
|
|
|
lo_vag << SGTL5000_LINE_OUT_GND_SHIFT |
|
2011-02-24 02:08:21 +08:00
|
|
|
|
SGTL5000_LINE_OUT_CURRENT_360u <<
|
|
|
|
|
SGTL5000_LINE_OUT_CURRENT_SHIFT);
|
|
|
|
|
|
2015-04-16 20:51:57 +08:00
|
|
|
|
/*
|
|
|
|
|
* Set lineout output level in range (0..31)
|
|
|
|
|
* the same value is used for right and left channel
|
|
|
|
|
*
|
|
|
|
|
* Searching for a suitable index solving this formula:
|
|
|
|
|
* idx = 40 * log10(vag_val / lo_cagcntrl) + 15
|
|
|
|
|
*/
|
2018-09-06 18:41:52 +08:00
|
|
|
|
vol_quot = lo_vag ? (vag * 100) / lo_vag : 0;
|
2015-04-16 20:51:57 +08:00
|
|
|
|
lo_vol = 0;
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(vol_quot_table); i++) {
|
|
|
|
|
if (vol_quot >= vol_quot_table[i])
|
|
|
|
|
lo_vol = i;
|
|
|
|
|
else
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-29 12:37:53 +08:00
|
|
|
|
snd_soc_component_update_bits(component, SGTL5000_CHIP_LINE_OUT_VOL,
|
2015-04-16 20:51:57 +08:00
|
|
|
|
SGTL5000_LINE_OUT_VOL_RIGHT_MASK |
|
|
|
|
|
SGTL5000_LINE_OUT_VOL_LEFT_MASK,
|
|
|
|
|
lo_vol << SGTL5000_LINE_OUT_VOL_RIGHT_SHIFT |
|
|
|
|
|
lo_vol << SGTL5000_LINE_OUT_VOL_LEFT_SHIFT);
|
|
|
|
|
|
2011-02-24 02:08:21 +08:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-07 07:14:48 +08:00
|
|
|
|
static int sgtl5000_enable_regulators(struct i2c_client *client)
|
2011-02-24 02:08:21 +08:00
|
|
|
|
{
|
|
|
|
|
int ret;
|
|
|
|
|
int i;
|
|
|
|
|
int external_vddd = 0;
|
ASoC: sgtl5000: clean up sgtl5000_enable_regulators()
Function sgtl5000_enable_regulators() is somehow odd in handling the
optional external VDDD supply. The driver can only enable this supply
on SGTL5000 chip before revision 0x11, and of course when this external
VDDD is present. It currently does something like below.
1. Check if regulator_bulk_get() on VDDA, VDDIO and VDDD will fail. If
it fails, VDDD must be absent and it falls on internal LDO by calling
sgtl5000_replace_vddd_with_ldo(). Otherwise, VDDD is used. And in
either case, regulator_bulk_enable() will be called to enable
3 supplies.
2. In case that SGTL5000 revision is later than 0x11, even if external
VDDD is present, it has to roll back the 'enable' and 'get' calls
with regulator_bulk_disable() and regulator_bulk_free(), and starts
over again by calling sgtl5000_replace_vddd_with_ldo() and
regulator_bulk_enable().
Such back and forth calls sequence is complicated and unnecessary.
Also, since commit 4ddfebd (regulator: core: Provide a dummy regulator
with full constraints), regulator_bulk_get() will always succeeds
because of the dummy regulator. Thus the VDDD detection is broken.
The patch changes the flow to something like the following, which should
be more reasonable and clear, and also fix the VDDD detection breakage.
1. Check if we're running a chip before revision 0x11, on which an
external VDDD can possibly be an option.
2. If it is an early revision, call regulator_get_optional() to detect
whether an external VDDD supply is available.
3. If external VDDD is present, call sgtl5000_replace_vddd_with_ldo() to
update sgtl5000->supplies info.
4. Drop regulator_bulk_get() call in sgtl5000_replace_vddd_with_ldo(),
and call it in sgtl5000_enable_regulators() no matter it's an
external VDDD or internal LDO.
5. Call regulator_bulk_enable() to enable these 3 regulators.
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
Signed-off-by: Mark Brown <broonie@linaro.org>
2013-12-13 14:43:03 +08:00
|
|
|
|
struct regulator *vddd;
|
2016-06-07 07:14:48 +08:00
|
|
|
|
struct sgtl5000_priv *sgtl5000 = i2c_get_clientdata(client);
|
2011-02-24 02:08:21 +08:00
|
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(sgtl5000->supplies); i++)
|
|
|
|
|
sgtl5000->supplies[i].supply = supply_names[i];
|
|
|
|
|
|
2016-06-07 07:14:48 +08:00
|
|
|
|
vddd = regulator_get_optional(&client->dev, "VDDD");
|
|
|
|
|
if (IS_ERR(vddd)) {
|
|
|
|
|
/* See if it's just not registered yet */
|
|
|
|
|
if (PTR_ERR(vddd) == -EPROBE_DEFER)
|
|
|
|
|
return -EPROBE_DEFER;
|
|
|
|
|
} else {
|
|
|
|
|
external_vddd = 1;
|
|
|
|
|
regulator_put(vddd);
|
2011-02-24 02:08:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-07 07:14:48 +08:00
|
|
|
|
sgtl5000->num_supplies = ARRAY_SIZE(sgtl5000->supplies)
|
|
|
|
|
- 1 + external_vddd;
|
|
|
|
|
ret = regulator_bulk_get(&client->dev, sgtl5000->num_supplies,
|
ASoC: sgtl5000: clean up sgtl5000_enable_regulators()
Function sgtl5000_enable_regulators() is somehow odd in handling the
optional external VDDD supply. The driver can only enable this supply
on SGTL5000 chip before revision 0x11, and of course when this external
VDDD is present. It currently does something like below.
1. Check if regulator_bulk_get() on VDDA, VDDIO and VDDD will fail. If
it fails, VDDD must be absent and it falls on internal LDO by calling
sgtl5000_replace_vddd_with_ldo(). Otherwise, VDDD is used. And in
either case, regulator_bulk_enable() will be called to enable
3 supplies.
2. In case that SGTL5000 revision is later than 0x11, even if external
VDDD is present, it has to roll back the 'enable' and 'get' calls
with regulator_bulk_disable() and regulator_bulk_free(), and starts
over again by calling sgtl5000_replace_vddd_with_ldo() and
regulator_bulk_enable().
Such back and forth calls sequence is complicated and unnecessary.
Also, since commit 4ddfebd (regulator: core: Provide a dummy regulator
with full constraints), regulator_bulk_get() will always succeeds
because of the dummy regulator. Thus the VDDD detection is broken.
The patch changes the flow to something like the following, which should
be more reasonable and clear, and also fix the VDDD detection breakage.
1. Check if we're running a chip before revision 0x11, on which an
external VDDD can possibly be an option.
2. If it is an early revision, call regulator_get_optional() to detect
whether an external VDDD supply is available.
3. If external VDDD is present, call sgtl5000_replace_vddd_with_ldo() to
update sgtl5000->supplies info.
4. Drop regulator_bulk_get() call in sgtl5000_replace_vddd_with_ldo(),
and call it in sgtl5000_enable_regulators() no matter it's an
external VDDD or internal LDO.
5. Call regulator_bulk_enable() to enable these 3 regulators.
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
Signed-off-by: Mark Brown <broonie@linaro.org>
2013-12-13 14:43:03 +08:00
|
|
|
|
sgtl5000->supplies);
|
|
|
|
|
if (ret)
|
2016-06-07 07:14:48 +08:00
|
|
|
|
return ret;
|
2011-02-24 02:08:21 +08:00
|
|
|
|
|
2016-06-07 07:14:48 +08:00
|
|
|
|
ret = regulator_bulk_enable(sgtl5000->num_supplies,
|
|
|
|
|
sgtl5000->supplies);
|
|
|
|
|
if (!ret)
|
|
|
|
|
usleep_range(10, 20);
|
|
|
|
|
else
|
|
|
|
|
regulator_bulk_free(sgtl5000->num_supplies,
|
|
|
|
|
sgtl5000->supplies);
|
2011-02-24 02:08:21 +08:00
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-29 12:37:53 +08:00
|
|
|
|
static int sgtl5000_probe(struct snd_soc_component *component)
|
2011-02-24 02:08:21 +08:00
|
|
|
|
{
|
|
|
|
|
int ret;
|
2017-04-05 22:32:34 +08:00
|
|
|
|
u16 reg;
|
2018-01-29 12:37:53 +08:00
|
|
|
|
struct sgtl5000_priv *sgtl5000 = snd_soc_component_get_drvdata(component);
|
2019-07-19 18:05:35 +08:00
|
|
|
|
unsigned int zcd_mask = SGTL5000_HP_ZCD_EN | SGTL5000_ADC_ZCD_EN;
|
2011-02-24 02:08:21 +08:00
|
|
|
|
|
|
|
|
|
/* power up sgtl5000 */
|
2018-01-29 12:37:53 +08:00
|
|
|
|
ret = sgtl5000_set_power_regs(component);
|
2011-02-24 02:08:21 +08:00
|
|
|
|
if (ret)
|
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
|
|
/* enable small pop, introduce 400ms delay in turning off */
|
2018-01-29 12:37:53 +08:00
|
|
|
|
snd_soc_component_update_bits(component, SGTL5000_CHIP_REF_CTRL,
|
2019-07-19 18:05:33 +08:00
|
|
|
|
SGTL5000_SMALL_POP, SGTL5000_SMALL_POP);
|
2011-02-24 02:08:21 +08:00
|
|
|
|
|
|
|
|
|
/* disable short cut detector */
|
2018-01-29 12:37:53 +08:00
|
|
|
|
snd_soc_component_write(component, SGTL5000_CHIP_SHORT_CTRL, 0);
|
2011-02-24 02:08:21 +08:00
|
|
|
|
|
2018-01-29 12:37:53 +08:00
|
|
|
|
snd_soc_component_write(component, SGTL5000_CHIP_DIG_POWER,
|
2011-02-24 02:08:21 +08:00
|
|
|
|
SGTL5000_ADC_EN | SGTL5000_DAC_EN);
|
|
|
|
|
|
|
|
|
|
/* enable dac volume ramp by default */
|
2018-01-29 12:37:53 +08:00
|
|
|
|
snd_soc_component_write(component, SGTL5000_CHIP_ADCDAC_CTRL,
|
2011-02-24 02:08:21 +08:00
|
|
|
|
SGTL5000_DAC_VOL_RAMP_EN |
|
|
|
|
|
SGTL5000_DAC_MUTE_RIGHT |
|
|
|
|
|
SGTL5000_DAC_MUTE_LEFT);
|
|
|
|
|
|
2018-12-26 08:59:53 +08:00
|
|
|
|
reg = ((sgtl5000->lrclk_strength) << SGTL5000_PAD_I2S_LRCLK_SHIFT |
|
|
|
|
|
(sgtl5000->sclk_strength) << SGTL5000_PAD_I2S_SCLK_SHIFT |
|
|
|
|
|
0x1f);
|
2018-01-29 12:37:53 +08:00
|
|
|
|
snd_soc_component_write(component, SGTL5000_CHIP_PAD_STRENGTH, reg);
|
2011-02-24 02:08:21 +08:00
|
|
|
|
|
2019-07-19 18:05:35 +08:00
|
|
|
|
snd_soc_component_update_bits(component, SGTL5000_CHIP_ANA_CTRL,
|
|
|
|
|
zcd_mask, zcd_mask);
|
2011-02-24 02:08:21 +08:00
|
|
|
|
|
2018-01-29 12:37:53 +08:00
|
|
|
|
snd_soc_component_update_bits(component, SGTL5000_CHIP_MIC_CTRL,
|
2014-10-14 14:43:11 +08:00
|
|
|
|
SGTL5000_BIAS_R_MASK,
|
|
|
|
|
sgtl5000->micbias_resistor << SGTL5000_BIAS_R_SHIFT);
|
2011-02-24 02:08:21 +08:00
|
|
|
|
|
2018-01-29 12:37:53 +08:00
|
|
|
|
snd_soc_component_update_bits(component, SGTL5000_CHIP_MIC_CTRL,
|
2015-09-26 03:33:41 +08:00
|
|
|
|
SGTL5000_BIAS_VOLT_MASK,
|
|
|
|
|
sgtl5000->micbias_voltage << SGTL5000_BIAS_VOLT_SHIFT);
|
2011-02-24 02:08:21 +08:00
|
|
|
|
/*
|
2018-02-19 17:03:46 +08:00
|
|
|
|
* enable DAP Graphic EQ
|
2011-02-24 02:08:21 +08:00
|
|
|
|
* TODO:
|
2018-02-19 17:03:46 +08:00
|
|
|
|
* Add control for changing between PEQ/Tone Control/GEQ
|
2011-02-24 02:08:21 +08:00
|
|
|
|
*/
|
2018-02-19 17:03:46 +08:00
|
|
|
|
snd_soc_component_write(component, SGTL5000_DAP_AUDIO_EQ, SGTL5000_DAP_SEL_GEQ);
|
2011-02-24 02:08:21 +08:00
|
|
|
|
|
2018-02-02 20:10:29 +08:00
|
|
|
|
/* Unmute DAC after start */
|
2018-02-14 23:39:30 +08:00
|
|
|
|
snd_soc_component_update_bits(component, SGTL5000_CHIP_ADCDAC_CTRL,
|
2018-02-02 20:10:29 +08:00
|
|
|
|
SGTL5000_DAC_MUTE_LEFT | SGTL5000_DAC_MUTE_RIGHT, 0);
|
|
|
|
|
|
2011-02-24 02:08:21 +08:00
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
err:
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-20 05:32:19 +08:00
|
|
|
|
static int sgtl5000_of_xlate_dai_id(struct snd_soc_component *component,
|
|
|
|
|
struct device_node *endpoint)
|
|
|
|
|
{
|
|
|
|
|
/* return dai id 0, whatever the endpoint index */
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-29 12:37:53 +08:00
|
|
|
|
static const struct snd_soc_component_driver sgtl5000_driver = {
|
|
|
|
|
.probe = sgtl5000_probe,
|
|
|
|
|
.set_bias_level = sgtl5000_set_bias_level,
|
|
|
|
|
.controls = sgtl5000_snd_controls,
|
|
|
|
|
.num_controls = ARRAY_SIZE(sgtl5000_snd_controls),
|
|
|
|
|
.dapm_widgets = sgtl5000_dapm_widgets,
|
|
|
|
|
.num_dapm_widgets = ARRAY_SIZE(sgtl5000_dapm_widgets),
|
|
|
|
|
.dapm_routes = sgtl5000_dapm_routes,
|
|
|
|
|
.num_dapm_routes = ARRAY_SIZE(sgtl5000_dapm_routes),
|
2019-12-20 05:32:19 +08:00
|
|
|
|
.of_xlate_dai_id = sgtl5000_of_xlate_dai_id,
|
2018-01-29 12:37:53 +08:00
|
|
|
|
.suspend_bias_off = 1,
|
|
|
|
|
.idle_bias_on = 1,
|
|
|
|
|
.use_pmdown_time = 1,
|
|
|
|
|
.endianness = 1,
|
|
|
|
|
.non_legacy_dai_naming = 1,
|
2011-02-24 02:08:21 +08:00
|
|
|
|
};
|
|
|
|
|
|
2013-05-05 02:39:34 +08:00
|
|
|
|
static const struct regmap_config sgtl5000_regmap = {
|
|
|
|
|
.reg_bits = 16,
|
|
|
|
|
.val_bits = 16,
|
2013-07-05 07:01:01 +08:00
|
|
|
|
.reg_stride = 2,
|
2013-05-05 02:39:34 +08:00
|
|
|
|
|
|
|
|
|
.max_register = SGTL5000_MAX_REG_OFFSET,
|
|
|
|
|
.volatile_reg = sgtl5000_volatile,
|
|
|
|
|
.readable_reg = sgtl5000_readable,
|
|
|
|
|
|
|
|
|
|
.cache_type = REGCACHE_RBTREE,
|
|
|
|
|
.reg_defaults = sgtl5000_reg_defaults,
|
|
|
|
|
.num_reg_defaults = ARRAY_SIZE(sgtl5000_reg_defaults),
|
|
|
|
|
};
|
|
|
|
|
|
2013-05-10 08:15:47 +08:00
|
|
|
|
/*
|
|
|
|
|
* Write all the default values from sgtl5000_reg_defaults[] array into the
|
|
|
|
|
* sgtl5000 registers, to make sure we always start with the sane registers
|
|
|
|
|
* values as stated in the datasheet.
|
|
|
|
|
*
|
|
|
|
|
* Since sgtl5000 does not have a reset line, nor a reset command in software,
|
|
|
|
|
* we follow this approach to guarantee we always start from the default values
|
|
|
|
|
* and avoid problems like, not being able to probe after an audio playback
|
|
|
|
|
* followed by a system reset or a 'reboot' command in Linux
|
|
|
|
|
*/
|
2016-06-07 07:14:49 +08:00
|
|
|
|
static void sgtl5000_fill_defaults(struct i2c_client *client)
|
2013-05-10 08:15:47 +08:00
|
|
|
|
{
|
2016-06-07 07:14:49 +08:00
|
|
|
|
struct sgtl5000_priv *sgtl5000 = i2c_get_clientdata(client);
|
2013-05-10 08:15:47 +08:00
|
|
|
|
int i, ret, val, index;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(sgtl5000_reg_defaults); i++) {
|
|
|
|
|
val = sgtl5000_reg_defaults[i].def;
|
|
|
|
|
index = sgtl5000_reg_defaults[i].reg;
|
|
|
|
|
ret = regmap_write(sgtl5000->regmap, index, val);
|
|
|
|
|
if (ret)
|
2016-06-07 07:14:49 +08:00
|
|
|
|
dev_err(&client->dev,
|
|
|
|
|
"%s: error %d setting reg 0x%02x to 0x%04x\n",
|
|
|
|
|
__func__, ret, index, val);
|
2013-05-10 08:15:47 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-07 22:26:37 +08:00
|
|
|
|
static int sgtl5000_i2c_probe(struct i2c_client *client,
|
|
|
|
|
const struct i2c_device_id *id)
|
2011-02-24 02:08:21 +08:00
|
|
|
|
{
|
|
|
|
|
struct sgtl5000_priv *sgtl5000;
|
2013-05-10 08:15:46 +08:00
|
|
|
|
int ret, reg, rev;
|
2014-10-14 14:43:11 +08:00
|
|
|
|
struct device_node *np = client->dev.of_node;
|
|
|
|
|
u32 value;
|
2016-06-07 07:14:50 +08:00
|
|
|
|
u16 ana_pwr;
|
2011-02-24 02:08:21 +08:00
|
|
|
|
|
2014-10-24 23:01:25 +08:00
|
|
|
|
sgtl5000 = devm_kzalloc(&client->dev, sizeof(*sgtl5000), GFP_KERNEL);
|
2011-02-24 02:08:21 +08:00
|
|
|
|
if (!sgtl5000)
|
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
2016-06-07 07:14:48 +08:00
|
|
|
|
i2c_set_clientdata(client, sgtl5000);
|
|
|
|
|
|
|
|
|
|
ret = sgtl5000_enable_regulators(client);
|
|
|
|
|
if (ret)
|
|
|
|
|
return ret;
|
|
|
|
|
|
2013-05-05 02:39:34 +08:00
|
|
|
|
sgtl5000->regmap = devm_regmap_init_i2c(client, &sgtl5000_regmap);
|
|
|
|
|
if (IS_ERR(sgtl5000->regmap)) {
|
|
|
|
|
ret = PTR_ERR(sgtl5000->regmap);
|
|
|
|
|
dev_err(&client->dev, "Failed to allocate regmap: %d\n", ret);
|
2016-06-07 07:14:48 +08:00
|
|
|
|
goto disable_regs;
|
2013-05-05 02:39:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-10 09:07:46 +08:00
|
|
|
|
sgtl5000->mclk = devm_clk_get(&client->dev, NULL);
|
|
|
|
|
if (IS_ERR(sgtl5000->mclk)) {
|
|
|
|
|
ret = PTR_ERR(sgtl5000->mclk);
|
2013-07-16 09:17:27 +08:00
|
|
|
|
/* Defer the probe to see if the clk will be provided later */
|
|
|
|
|
if (ret == -ENOENT)
|
2016-06-07 07:14:48 +08:00
|
|
|
|
ret = -EPROBE_DEFER;
|
2018-01-17 23:48:54 +08:00
|
|
|
|
|
|
|
|
|
if (ret != -EPROBE_DEFER)
|
|
|
|
|
dev_err(&client->dev, "Failed to get mclock: %d\n",
|
|
|
|
|
ret);
|
2016-06-07 07:14:48 +08:00
|
|
|
|
goto disable_regs;
|
2013-06-10 09:07:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ret = clk_prepare_enable(sgtl5000->mclk);
|
2016-06-07 07:14:48 +08:00
|
|
|
|
if (ret) {
|
|
|
|
|
dev_err(&client->dev, "Error enabling clock %d\n", ret);
|
|
|
|
|
goto disable_regs;
|
|
|
|
|
}
|
2013-06-10 09:07:46 +08:00
|
|
|
|
|
2015-01-31 05:07:55 +08:00
|
|
|
|
/* Need 8 clocks before I2C accesses */
|
|
|
|
|
udelay(1);
|
|
|
|
|
|
2013-05-10 08:15:46 +08:00
|
|
|
|
/* read chip information */
|
|
|
|
|
ret = regmap_read(sgtl5000->regmap, SGTL5000_CHIP_ID, ®);
|
2016-06-07 07:14:48 +08:00
|
|
|
|
if (ret) {
|
|
|
|
|
dev_err(&client->dev, "Error reading chip id %d\n", ret);
|
2013-06-10 09:07:46 +08:00
|
|
|
|
goto disable_clk;
|
2016-06-07 07:14:48 +08:00
|
|
|
|
}
|
2013-05-10 08:15:46 +08:00
|
|
|
|
|
|
|
|
|
if (((reg & SGTL5000_PARTID_MASK) >> SGTL5000_PARTID_SHIFT) !=
|
|
|
|
|
SGTL5000_PARTID_PART_ID) {
|
|
|
|
|
dev_err(&client->dev,
|
|
|
|
|
"Device with ID register %x is not a sgtl5000\n", reg);
|
2013-06-10 09:07:46 +08:00
|
|
|
|
ret = -ENODEV;
|
|
|
|
|
goto disable_clk;
|
2013-05-10 08:15:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rev = (reg & SGTL5000_REVID_MASK) >> SGTL5000_REVID_SHIFT;
|
|
|
|
|
dev_info(&client->dev, "sgtl5000 revision 0x%x\n", rev);
|
2013-12-13 14:43:02 +08:00
|
|
|
|
sgtl5000->revision = rev;
|
2013-05-10 08:15:46 +08:00
|
|
|
|
|
2016-06-07 07:14:51 +08:00
|
|
|
|
/* reconfigure the clocks in case we're using the PLL */
|
|
|
|
|
ret = regmap_write(sgtl5000->regmap,
|
|
|
|
|
SGTL5000_CHIP_CLK_CTRL,
|
|
|
|
|
SGTL5000_CHIP_CLK_CTRL_DEFAULT);
|
|
|
|
|
if (ret)
|
|
|
|
|
dev_err(&client->dev,
|
|
|
|
|
"Error %d initializing CHIP_CLK_CTRL\n", ret);
|
|
|
|
|
|
2020-04-15 02:11:40 +08:00
|
|
|
|
/* Mute everything to avoid pop from the following power-up */
|
|
|
|
|
ret = regmap_write(sgtl5000->regmap, SGTL5000_CHIP_ANA_CTRL,
|
|
|
|
|
SGTL5000_CHIP_ANA_CTRL_DEFAULT);
|
|
|
|
|
if (ret) {
|
|
|
|
|
dev_err(&client->dev,
|
|
|
|
|
"Error %d muting outputs via CHIP_ANA_CTRL\n", ret);
|
|
|
|
|
goto disable_clk;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* If VAG is powered-on (e.g. from previous boot), it would be disabled
|
|
|
|
|
* by the write to ANA_POWER in later steps of the probe code. This
|
|
|
|
|
* may create a loud pop even with all outputs muted. The proper way
|
|
|
|
|
* to circumvent this is disabling the bit first and waiting the proper
|
|
|
|
|
* cool-down time.
|
|
|
|
|
*/
|
|
|
|
|
ret = regmap_read(sgtl5000->regmap, SGTL5000_CHIP_ANA_POWER, &value);
|
|
|
|
|
if (ret) {
|
|
|
|
|
dev_err(&client->dev, "Failed to read ANA_POWER: %d\n", ret);
|
|
|
|
|
goto disable_clk;
|
|
|
|
|
}
|
|
|
|
|
if (value & SGTL5000_VAG_POWERUP) {
|
|
|
|
|
ret = regmap_update_bits(sgtl5000->regmap,
|
|
|
|
|
SGTL5000_CHIP_ANA_POWER,
|
|
|
|
|
SGTL5000_VAG_POWERUP,
|
|
|
|
|
0);
|
|
|
|
|
if (ret) {
|
|
|
|
|
dev_err(&client->dev, "Error %d disabling VAG\n", ret);
|
|
|
|
|
goto disable_clk;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
msleep(SGTL5000_VAG_POWERDOWN_DELAY);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-07 07:14:48 +08:00
|
|
|
|
/* Follow section 2.2.1.1 of AN3663 */
|
2016-06-07 07:14:50 +08:00
|
|
|
|
ana_pwr = SGTL5000_ANA_POWER_DEFAULT;
|
2016-06-07 07:14:48 +08:00
|
|
|
|
if (sgtl5000->num_supplies <= VDDD) {
|
|
|
|
|
/* internal VDDD at 1.2V */
|
2016-06-07 07:14:50 +08:00
|
|
|
|
ret = regmap_update_bits(sgtl5000->regmap,
|
|
|
|
|
SGTL5000_CHIP_LINREG_CTRL,
|
|
|
|
|
SGTL5000_LINREG_VDDD_MASK,
|
|
|
|
|
LINREG_VDDD);
|
|
|
|
|
if (ret)
|
|
|
|
|
dev_err(&client->dev,
|
|
|
|
|
"Error %d setting LINREG_VDDD\n", ret);
|
|
|
|
|
|
|
|
|
|
ana_pwr |= SGTL5000_LINEREG_D_POWERUP;
|
|
|
|
|
dev_info(&client->dev,
|
2018-01-18 19:45:28 +08:00
|
|
|
|
"Using internal LDO instead of VDDD: check ER1 erratum\n");
|
2016-06-07 07:14:48 +08:00
|
|
|
|
} else {
|
|
|
|
|
/* using external LDO for VDDD
|
|
|
|
|
* Clear startup powerup and simple powerup
|
|
|
|
|
* bits to save power
|
|
|
|
|
*/
|
2016-06-07 07:14:50 +08:00
|
|
|
|
ana_pwr &= ~(SGTL5000_STARTUP_POWERUP
|
|
|
|
|
| SGTL5000_LINREG_SIMPLE_POWERUP);
|
2016-06-07 07:14:48 +08:00
|
|
|
|
dev_dbg(&client->dev, "Using external VDDD\n");
|
|
|
|
|
}
|
2016-06-07 07:14:50 +08:00
|
|
|
|
ret = regmap_write(sgtl5000->regmap, SGTL5000_CHIP_ANA_POWER, ana_pwr);
|
|
|
|
|
if (ret)
|
|
|
|
|
dev_err(&client->dev,
|
|
|
|
|
"Error %d setting CHIP_ANA_POWER to %04x\n",
|
|
|
|
|
ret, ana_pwr);
|
2016-06-07 07:14:48 +08:00
|
|
|
|
|
2014-10-14 14:43:11 +08:00
|
|
|
|
if (np) {
|
|
|
|
|
if (!of_property_read_u32(np,
|
|
|
|
|
"micbias-resistor-k-ohms", &value)) {
|
|
|
|
|
switch (value) {
|
|
|
|
|
case SGTL5000_MICBIAS_OFF:
|
|
|
|
|
sgtl5000->micbias_resistor = 0;
|
|
|
|
|
break;
|
|
|
|
|
case SGTL5000_MICBIAS_2K:
|
|
|
|
|
sgtl5000->micbias_resistor = 1;
|
|
|
|
|
break;
|
|
|
|
|
case SGTL5000_MICBIAS_4K:
|
|
|
|
|
sgtl5000->micbias_resistor = 2;
|
|
|
|
|
break;
|
|
|
|
|
case SGTL5000_MICBIAS_8K:
|
|
|
|
|
sgtl5000->micbias_resistor = 3;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
sgtl5000->micbias_resistor = 2;
|
|
|
|
|
dev_err(&client->dev,
|
|
|
|
|
"Unsuitable MicBias resistor\n");
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
/* default is 4Kohms */
|
|
|
|
|
sgtl5000->micbias_resistor = 2;
|
|
|
|
|
}
|
2014-10-14 14:43:12 +08:00
|
|
|
|
if (!of_property_read_u32(np,
|
|
|
|
|
"micbias-voltage-m-volts", &value)) {
|
|
|
|
|
/* 1250mV => 0 */
|
|
|
|
|
/* steps of 250mV */
|
|
|
|
|
if ((value >= 1250) && (value <= 3000))
|
|
|
|
|
sgtl5000->micbias_voltage = (value / 250) - 5;
|
|
|
|
|
else {
|
|
|
|
|
sgtl5000->micbias_voltage = 0;
|
2014-10-14 14:43:11 +08:00
|
|
|
|
dev_err(&client->dev,
|
2015-09-26 03:33:42 +08:00
|
|
|
|
"Unsuitable MicBias voltage\n");
|
2014-10-14 14:43:11 +08:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2014-10-14 14:43:12 +08:00
|
|
|
|
sgtl5000->micbias_voltage = 0;
|
2014-10-14 14:43:11 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-05 22:32:34 +08:00
|
|
|
|
sgtl5000->lrclk_strength = I2S_LRCLK_STRENGTH_LOW;
|
|
|
|
|
if (!of_property_read_u32(np, "lrclk-strength", &value)) {
|
|
|
|
|
if (value > I2S_LRCLK_STRENGTH_HIGH)
|
|
|
|
|
value = I2S_LRCLK_STRENGTH_LOW;
|
|
|
|
|
sgtl5000->lrclk_strength = value;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-26 08:59:53 +08:00
|
|
|
|
sgtl5000->sclk_strength = I2S_SCLK_STRENGTH_LOW;
|
|
|
|
|
if (!of_property_read_u32(np, "sclk-strength", &value)) {
|
|
|
|
|
if (value > I2S_SCLK_STRENGTH_HIGH)
|
|
|
|
|
value = I2S_SCLK_STRENGTH_LOW;
|
|
|
|
|
sgtl5000->sclk_strength = value;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-10 08:15:47 +08:00
|
|
|
|
/* Ensure sgtl5000 will start with sane register values */
|
2016-06-07 07:14:49 +08:00
|
|
|
|
sgtl5000_fill_defaults(client);
|
2013-05-10 08:15:47 +08:00
|
|
|
|
|
2018-01-29 12:37:53 +08:00
|
|
|
|
ret = devm_snd_soc_register_component(&client->dev,
|
2011-02-24 02:08:21 +08:00
|
|
|
|
&sgtl5000_driver, &sgtl5000_dai, 1);
|
2013-06-10 09:07:46 +08:00
|
|
|
|
if (ret)
|
|
|
|
|
goto disable_clk;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
disable_clk:
|
|
|
|
|
clk_disable_unprepare(sgtl5000->mclk);
|
2016-06-07 07:14:48 +08:00
|
|
|
|
|
|
|
|
|
disable_regs:
|
|
|
|
|
regulator_bulk_disable(sgtl5000->num_supplies, sgtl5000->supplies);
|
|
|
|
|
regulator_bulk_free(sgtl5000->num_supplies, sgtl5000->supplies);
|
|
|
|
|
|
2011-12-28 21:30:11 +08:00
|
|
|
|
return ret;
|
2011-02-24 02:08:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2012-12-07 22:26:37 +08:00
|
|
|
|
static int sgtl5000_i2c_remove(struct i2c_client *client)
|
2011-02-24 02:08:21 +08:00
|
|
|
|
{
|
2013-06-10 21:24:41 +08:00
|
|
|
|
struct sgtl5000_priv *sgtl5000 = i2c_get_clientdata(client);
|
2011-02-24 02:08:21 +08:00
|
|
|
|
|
2013-06-10 09:07:46 +08:00
|
|
|
|
clk_disable_unprepare(sgtl5000->mclk);
|
2016-06-07 07:14:48 +08:00
|
|
|
|
regulator_bulk_disable(sgtl5000->num_supplies, sgtl5000->supplies);
|
|
|
|
|
regulator_bulk_free(sgtl5000->num_supplies, sgtl5000->supplies);
|
|
|
|
|
|
2011-02-24 02:08:21 +08:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct i2c_device_id sgtl5000_id[] = {
|
|
|
|
|
{"sgtl5000", 0},
|
|
|
|
|
{},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE(i2c, sgtl5000_id);
|
|
|
|
|
|
2011-07-22 00:28:51 +08:00
|
|
|
|
static const struct of_device_id sgtl5000_dt_ids[] = {
|
|
|
|
|
{ .compatible = "fsl,sgtl5000", },
|
|
|
|
|
{ /* sentinel */ }
|
|
|
|
|
};
|
2011-08-11 22:19:16 +08:00
|
|
|
|
MODULE_DEVICE_TABLE(of, sgtl5000_dt_ids);
|
2011-07-22 00:28:51 +08:00
|
|
|
|
|
2011-02-24 02:08:21 +08:00
|
|
|
|
static struct i2c_driver sgtl5000_i2c_driver = {
|
|
|
|
|
.driver = {
|
|
|
|
|
.name = "sgtl5000",
|
2011-07-22 00:28:51 +08:00
|
|
|
|
.of_match_table = sgtl5000_dt_ids,
|
2011-02-24 02:08:21 +08:00
|
|
|
|
},
|
|
|
|
|
.probe = sgtl5000_i2c_probe,
|
2012-12-07 22:26:37 +08:00
|
|
|
|
.remove = sgtl5000_i2c_remove,
|
2011-02-24 02:08:21 +08:00
|
|
|
|
.id_table = sgtl5000_id,
|
|
|
|
|
};
|
|
|
|
|
|
2012-04-04 05:35:18 +08:00
|
|
|
|
module_i2c_driver(sgtl5000_i2c_driver);
|
2011-02-24 02:08:21 +08:00
|
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("Freescale SGTL5000 ALSA SoC Codec Driver");
|
2012-01-16 15:18:11 +08:00
|
|
|
|
MODULE_AUTHOR("Zeng Zhaoming <zengzm.kernel@gmail.com>");
|
2011-02-24 02:08:21 +08:00
|
|
|
|
MODULE_LICENSE("GPL");
|