2019-05-20 17:07:57 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2005-08-11 09:18:38 +00:00
|
|
|
/*
|
|
|
|
* Universal Interface for Intel High Definition Audio Codec
|
|
|
|
*
|
|
|
|
* HD audio interface patch for Silicon Labs 3054/5 modem codec
|
|
|
|
*
|
2005-10-10 09:45:31 +00:00
|
|
|
* Copyright (c) 2005 Sasha Khapyorsky <sashak@alsa-project.org>
|
2005-08-11 09:18:38 +00:00
|
|
|
* Takashi Iwai <tiwai@suse.de>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/slab.h>
|
2011-07-15 16:38:28 +00:00
|
|
|
#include <linux/module.h>
|
2005-08-11 09:18:38 +00:00
|
|
|
#include <sound/core.h>
|
2018-08-22 20:24:57 +00:00
|
|
|
#include <sound/hda_codec.h>
|
2005-08-11 09:18:38 +00:00
|
|
|
#include "hda_local.h"
|
|
|
|
|
|
|
|
/* si3054 verbs */
|
|
|
|
#define SI3054_VERB_READ_NODE 0x900
|
|
|
|
#define SI3054_VERB_WRITE_NODE 0x100
|
|
|
|
|
|
|
|
/* si3054 nodes (registers) */
|
|
|
|
#define SI3054_EXTENDED_MID 2
|
|
|
|
#define SI3054_LINE_RATE 3
|
|
|
|
#define SI3054_LINE_LEVEL 4
|
|
|
|
#define SI3054_GPIO_CFG 5
|
|
|
|
#define SI3054_GPIO_POLARITY 6
|
|
|
|
#define SI3054_GPIO_STICKY 7
|
|
|
|
#define SI3054_GPIO_WAKEUP 8
|
|
|
|
#define SI3054_GPIO_STATUS 9
|
|
|
|
#define SI3054_GPIO_CONTROL 10
|
|
|
|
#define SI3054_MISC_AFE 11
|
|
|
|
#define SI3054_CHIPID 12
|
|
|
|
#define SI3054_LINE_CFG1 13
|
|
|
|
#define SI3054_LINE_STATUS 14
|
|
|
|
#define SI3054_DC_TERMINATION 15
|
|
|
|
#define SI3054_LINE_CONFIG 16
|
|
|
|
#define SI3054_CALLPROG_ATT 17
|
|
|
|
#define SI3054_SQ_CONTROL 18
|
|
|
|
#define SI3054_MISC_CONTROL 19
|
|
|
|
#define SI3054_RING_CTRL1 20
|
|
|
|
#define SI3054_RING_CTRL2 21
|
|
|
|
|
|
|
|
/* extended MID */
|
|
|
|
#define SI3054_MEI_READY 0xf
|
|
|
|
|
|
|
|
/* line level */
|
|
|
|
#define SI3054_ATAG_MASK 0x00f0
|
|
|
|
#define SI3054_DTAG_MASK 0xf000
|
|
|
|
|
|
|
|
/* GPIO bits */
|
|
|
|
#define SI3054_GPIO_OH 0x0001
|
|
|
|
#define SI3054_GPIO_CID 0x0002
|
|
|
|
|
|
|
|
/* chipid and revisions */
|
|
|
|
#define SI3054_CHIPID_CODEC_REV_MASK 0x000f
|
|
|
|
#define SI3054_CHIPID_DAA_REV_MASK 0x00f0
|
|
|
|
#define SI3054_CHIPID_INTERNATIONAL 0x0100
|
|
|
|
#define SI3054_CHIPID_DAA_ID 0x0f00
|
|
|
|
#define SI3054_CHIPID_CODEC_ID (1<<12)
|
|
|
|
|
|
|
|
/* si3054 codec registers (nodes) access macros */
|
|
|
|
#define GET_REG(codec,reg) (snd_hda_codec_read(codec,reg,0,SI3054_VERB_READ_NODE,0))
|
|
|
|
#define SET_REG(codec,reg,val) (snd_hda_codec_write(codec,reg,0,SI3054_VERB_WRITE_NODE,val))
|
2007-08-10 15:09:26 +00:00
|
|
|
#define SET_REG_CACHE(codec,reg,val) \
|
|
|
|
snd_hda_codec_write_cache(codec,reg,0,SI3054_VERB_WRITE_NODE,val)
|
2005-08-11 09:18:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
struct si3054_spec {
|
|
|
|
unsigned international;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Modem mixer
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define PRIVATE_VALUE(reg,mask) ((reg<<16)|(mask&0xffff))
|
|
|
|
#define PRIVATE_REG(val) ((val>>16)&0xffff)
|
|
|
|
#define PRIVATE_MASK(val) (val&0xffff)
|
|
|
|
|
2007-07-23 13:42:26 +00:00
|
|
|
#define si3054_switch_info snd_ctl_boolean_mono_info
|
2005-08-11 09:18:38 +00:00
|
|
|
|
2005-11-17 13:57:47 +00:00
|
|
|
static int si3054_switch_get(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *uvalue)
|
2005-08-11 09:18:38 +00:00
|
|
|
{
|
|
|
|
struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
|
|
|
|
u16 reg = PRIVATE_REG(kcontrol->private_value);
|
|
|
|
u16 mask = PRIVATE_MASK(kcontrol->private_value);
|
|
|
|
uvalue->value.integer.value[0] = (GET_REG(codec, reg)) & mask ? 1 : 0 ;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 13:57:47 +00:00
|
|
|
static int si3054_switch_put(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *uvalue)
|
2005-08-11 09:18:38 +00:00
|
|
|
{
|
|
|
|
struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
|
|
|
|
u16 reg = PRIVATE_REG(kcontrol->private_value);
|
|
|
|
u16 mask = PRIVATE_MASK(kcontrol->private_value);
|
|
|
|
if (uvalue->value.integer.value[0])
|
2007-08-10 15:09:26 +00:00
|
|
|
SET_REG_CACHE(codec, reg, (GET_REG(codec, reg)) | mask);
|
2005-08-11 09:18:38 +00:00
|
|
|
else
|
2007-08-10 15:09:26 +00:00
|
|
|
SET_REG_CACHE(codec, reg, (GET_REG(codec, reg)) & ~mask);
|
2005-08-11 09:18:38 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define SI3054_KCONTROL(kname,reg,mask) { \
|
|
|
|
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
|
|
|
|
.name = kname, \
|
2009-12-08 15:13:32 +00:00
|
|
|
.subdevice = HDA_SUBDEV_NID_FLAG | reg, \
|
2005-08-11 09:18:38 +00:00
|
|
|
.info = si3054_switch_info, \
|
|
|
|
.get = si3054_switch_get, \
|
|
|
|
.put = si3054_switch_put, \
|
|
|
|
.private_value = PRIVATE_VALUE(reg,mask), \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-02 10:22:39 +00:00
|
|
|
static const struct snd_kcontrol_new si3054_modem_mixer[] = {
|
2005-08-11 09:18:38 +00:00
|
|
|
SI3054_KCONTROL("Off-hook Switch", SI3054_GPIO_CONTROL, SI3054_GPIO_OH),
|
|
|
|
SI3054_KCONTROL("Caller ID Switch", SI3054_GPIO_CONTROL, SI3054_GPIO_CID),
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
static int si3054_build_controls(struct hda_codec *codec)
|
|
|
|
{
|
|
|
|
return snd_hda_add_new_ctls(codec, si3054_modem_mixer);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PCM callbacks
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int si3054_pcm_prepare(struct hda_pcm_stream *hinfo,
|
|
|
|
struct hda_codec *codec,
|
|
|
|
unsigned int stream_tag,
|
|
|
|
unsigned int format,
|
2005-11-17 13:57:47 +00:00
|
|
|
struct snd_pcm_substream *substream)
|
2005-08-11 09:18:38 +00:00
|
|
|
{
|
|
|
|
u16 val;
|
|
|
|
|
|
|
|
SET_REG(codec, SI3054_LINE_RATE, substream->runtime->rate);
|
|
|
|
val = GET_REG(codec, SI3054_LINE_LEVEL);
|
|
|
|
val &= 0xff << (8 * (substream->stream != SNDRV_PCM_STREAM_PLAYBACK));
|
|
|
|
val |= ((stream_tag & 0xf) << 4) << (8 * (substream->stream == SNDRV_PCM_STREAM_PLAYBACK));
|
|
|
|
SET_REG(codec, SI3054_LINE_LEVEL, val);
|
|
|
|
|
|
|
|
snd_hda_codec_setup_stream(codec, hinfo->nid,
|
|
|
|
stream_tag, 0, format);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int si3054_pcm_open(struct hda_pcm_stream *hinfo,
|
|
|
|
struct hda_codec *codec,
|
2005-11-17 13:57:47 +00:00
|
|
|
struct snd_pcm_substream *substream)
|
2005-08-11 09:18:38 +00:00
|
|
|
{
|
2017-06-07 12:20:07 +00:00
|
|
|
static const unsigned int rates[] = { 8000, 9600, 16000 };
|
|
|
|
static const struct snd_pcm_hw_constraint_list hw_constraints_rates = {
|
2005-08-11 09:18:38 +00:00
|
|
|
.count = ARRAY_SIZE(rates),
|
|
|
|
.list = rates,
|
|
|
|
.mask = 0,
|
|
|
|
};
|
|
|
|
substream->runtime->hw.period_bytes_min = 80;
|
|
|
|
return snd_pcm_hw_constraint_list(substream->runtime, 0,
|
|
|
|
SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-02 10:22:39 +00:00
|
|
|
static const struct hda_pcm_stream si3054_pcm = {
|
2005-08-11 09:18:38 +00:00
|
|
|
.substreams = 1,
|
|
|
|
.channels_min = 1,
|
|
|
|
.channels_max = 1,
|
|
|
|
.nid = 0x1,
|
|
|
|
.rates = SNDRV_PCM_RATE_8000|SNDRV_PCM_RATE_16000|SNDRV_PCM_RATE_KNOT,
|
|
|
|
.formats = SNDRV_PCM_FMTBIT_S16_LE,
|
|
|
|
.maxbps = 16,
|
|
|
|
.ops = {
|
|
|
|
.open = si3054_pcm_open,
|
|
|
|
.prepare = si3054_pcm_prepare,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static int si3054_build_pcms(struct hda_codec *codec)
|
|
|
|
{
|
2015-02-27 16:43:19 +00:00
|
|
|
struct hda_pcm *info;
|
|
|
|
|
|
|
|
info = snd_hda_codec_pcm_new(codec, "Si3054 Modem");
|
|
|
|
if (!info)
|
|
|
|
return -ENOMEM;
|
2005-08-11 09:18:38 +00:00
|
|
|
info->stream[SNDRV_PCM_STREAM_PLAYBACK] = si3054_pcm;
|
|
|
|
info->stream[SNDRV_PCM_STREAM_CAPTURE] = si3054_pcm;
|
2015-03-03 09:07:24 +00:00
|
|
|
info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = codec->core.mfg;
|
|
|
|
info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = codec->core.mfg;
|
[ALSA] hda-intel - Fix PCM device number assignment
In the current scheme, PCM device numbers are assigned incrementally
in the order of codecs. This causes problems when the codec number
is irregular, e.g. codec #0 for HDMI and codec #1 for analog. Then
the HDMI becomes the first PCM, which is picked up as the default
output device. Unfortuantely this doesn't work well with normal
setups.
This patch introduced the fixed device numbers for the PCM types,
namely, analog, SPDIF, HDMI and modem. The PCM devices are assigned
according to the corresponding PCM type. After this patch, HDMI will
be always assigned to PCM #3, SPDIF to PCM #1, and the first analog
to PCM #0, etc.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2008-02-06 13:03:20 +00:00
|
|
|
info->pcm_type = HDA_PCM_TYPE_MODEM;
|
2005-08-11 09:18:38 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Init part
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int si3054_init(struct hda_codec *codec)
|
|
|
|
{
|
|
|
|
struct si3054_spec *spec = codec->spec;
|
|
|
|
unsigned wait_count;
|
|
|
|
u16 val;
|
|
|
|
|
ALSA: hda - Use regmap for command verb caches, too
Like the previous patches, this patch converts also to the regmap, at
this time, the cached verb writes are the target. But this conversion
needs a bit more caution than before.
- In the old code, we just record any verbs as is, and restore them at
resume. For the regmap scheme, this doesn't work, since a few verbs
like AMP or DIGI_CONVERT are asymmetrical. Such verbs are converted
either to the dedicated function (snd_hda_regmap_xxx_amp()) or
changed to the unified verb.
- Some verbs have to be declared as vendor-specific ones before
accessing via regmap.
Also, the minor optimization with codec->cached_write flag is dropped
in a few places, as this would confuse the operation. Further
optimizations will be brought in the later patches, if any.
This conversion ends up with a drop of significant amount of codes,
mostly the helper codes that are no longer used.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-02-26 11:34:49 +00:00
|
|
|
if (snd_hdac_regmap_add_vendor_verb(&codec->core,
|
|
|
|
SI3054_VERB_WRITE_NODE))
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2005-08-11 09:18:38 +00:00
|
|
|
snd_hda_codec_write(codec, AC_NODE_ROOT, 0, AC_VERB_SET_CODEC_RESET, 0);
|
2015-03-03 09:07:24 +00:00
|
|
|
snd_hda_codec_write(codec, codec->core.mfg, 0, AC_VERB_SET_STREAM_FORMAT, 0);
|
2005-08-11 09:18:38 +00:00
|
|
|
SET_REG(codec, SI3054_LINE_RATE, 9600);
|
|
|
|
SET_REG(codec, SI3054_LINE_LEVEL, SI3054_DTAG_MASK|SI3054_ATAG_MASK);
|
|
|
|
SET_REG(codec, SI3054_EXTENDED_MID, 0);
|
|
|
|
|
|
|
|
wait_count = 10;
|
|
|
|
do {
|
|
|
|
msleep(2);
|
|
|
|
val = GET_REG(codec, SI3054_EXTENDED_MID);
|
|
|
|
} while ((val & SI3054_MEI_READY) != SI3054_MEI_READY && wait_count--);
|
|
|
|
|
|
|
|
if((val&SI3054_MEI_READY) != SI3054_MEI_READY) {
|
2014-02-25 11:21:03 +00:00
|
|
|
codec_err(codec, "si3054: cannot initialize. EXT MID = %04x\n", val);
|
2006-10-10 18:01:01 +00:00
|
|
|
/* let's pray that this is no fatal error */
|
|
|
|
/* return -EACCES; */
|
2005-08-11 09:18:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SET_REG(codec, SI3054_GPIO_POLARITY, 0xffff);
|
|
|
|
SET_REG(codec, SI3054_GPIO_CFG, 0x0);
|
|
|
|
SET_REG(codec, SI3054_MISC_AFE, 0);
|
|
|
|
SET_REG(codec, SI3054_LINE_CFG1,0x200);
|
|
|
|
|
|
|
|
if((GET_REG(codec,SI3054_LINE_STATUS) & (1<<6)) == 0) {
|
2014-02-25 11:21:03 +00:00
|
|
|
codec_dbg(codec,
|
|
|
|
"Link Frame Detect(FDT) is not ready (line status: %04x)\n",
|
2005-08-11 09:18:38 +00:00
|
|
|
GET_REG(codec,SI3054_LINE_STATUS));
|
|
|
|
}
|
|
|
|
|
|
|
|
spec->international = GET_REG(codec, SI3054_CHIPID) & SI3054_CHIPID_INTERNATIONAL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void si3054_free(struct hda_codec *codec)
|
|
|
|
{
|
|
|
|
kfree(codec->spec);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
*/
|
|
|
|
|
2011-05-02 10:22:39 +00:00
|
|
|
static const struct hda_codec_ops si3054_patch_ops = {
|
2005-08-11 09:18:38 +00:00
|
|
|
.build_controls = si3054_build_controls,
|
|
|
|
.build_pcms = si3054_build_pcms,
|
|
|
|
.init = si3054_init,
|
|
|
|
.free = si3054_free,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int patch_si3054(struct hda_codec *codec)
|
|
|
|
{
|
[ALSA] Replace with kzalloc() - pci stuff
AD1889 driver,ATIIXP driver,ATIIXP-modem driver,AZT3328 driver
BT87x driver,CMIPCI driver,CS4281 driver,ENS1370/1+ driver
ES1938 driver,ES1968 driver,FM801 driver,Intel8x0 driver
Intel8x0-modem driver,Maestro3 driver,SonicVibes driver,VIA82xx driver
VIA82xx-modem driver,AC97 Codec,AK4531 codec,au88x0 driver
CA0106 driver,CS46xx driver,EMU10K1/EMU10K2 driver,HDA Codec driver
HDA generic driver,HDA Intel driver,ICE1712 driver,ICE1724 driver
KORG1212 driver,MIXART driver,NM256 driver,Trident driver,YMFPCI driver
Replace kcalloc(1,..) with kzalloc().
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2005-09-09 12:21:46 +00:00
|
|
|
struct si3054_spec *spec = kzalloc(sizeof(*spec), GFP_KERNEL);
|
2005-08-11 09:18:38 +00:00
|
|
|
if (spec == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
codec->spec = spec;
|
|
|
|
codec->patch_ops = si3054_patch_ops;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* patch entries
|
|
|
|
*/
|
2015-10-01 14:20:04 +00:00
|
|
|
static const struct hda_device_id snd_hda_id_si3054[] = {
|
|
|
|
HDA_CODEC_ENTRY(0x163c3055, "Si3054", patch_si3054),
|
|
|
|
HDA_CODEC_ENTRY(0x163c3155, "Si3054", patch_si3054),
|
|
|
|
HDA_CODEC_ENTRY(0x11c13026, "Si3054", patch_si3054),
|
|
|
|
HDA_CODEC_ENTRY(0x11c13055, "Si3054", patch_si3054),
|
|
|
|
HDA_CODEC_ENTRY(0x11c13155, "Si3054", patch_si3054),
|
|
|
|
HDA_CODEC_ENTRY(0x10573055, "Si3054", patch_si3054),
|
|
|
|
HDA_CODEC_ENTRY(0x10573057, "Si3054", patch_si3054),
|
|
|
|
HDA_CODEC_ENTRY(0x10573155, "Si3054", patch_si3054),
|
2007-07-11 08:31:08 +00:00
|
|
|
/* VIA HDA on Clevo m540 */
|
2015-10-01 14:20:04 +00:00
|
|
|
HDA_CODEC_ENTRY(0x11063288, "Si3054", patch_si3054),
|
2007-05-18 14:55:26 +00:00
|
|
|
/* Asus A8J Modem (SM56) */
|
2015-10-01 14:20:04 +00:00
|
|
|
HDA_CODEC_ENTRY(0x15433155, "Si3054", patch_si3054),
|
2007-07-12 09:27:37 +00:00
|
|
|
/* LG LW20 modem */
|
2015-10-01 14:20:04 +00:00
|
|
|
HDA_CODEC_ENTRY(0x18540018, "Si3054", patch_si3054),
|
2005-08-11 09:18:38 +00:00
|
|
|
{}
|
|
|
|
};
|
2015-10-01 14:20:04 +00:00
|
|
|
MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_si3054);
|
2008-11-27 14:47:11 +00:00
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_DESCRIPTION("Si3054 HD-audio modem codec");
|
|
|
|
|
2015-02-17 14:25:37 +00:00
|
|
|
static struct hda_codec_driver si3054_driver = {
|
2015-10-01 14:20:04 +00:00
|
|
|
.id = snd_hda_id_si3054,
|
2008-11-27 14:47:11 +00:00
|
|
|
};
|
|
|
|
|
2015-02-17 14:25:37 +00:00
|
|
|
module_hda_codec_driver(si3054_driver);
|