~ubuntu-branches/ubuntu/quantal/linux-lowlatency/quantal

« back to all changes in this revision

Viewing changes to sound/pci/hda/hda_codec.c

  • Committer: Package Import Robot
  • Author(s): Alessio Igor Bogani
  • Date: 2011-10-26 11:13:05 UTC
  • Revision ID: package-import@ubuntu.com-20111026111305-04kado7d1u2er2rl
Tags: 3.2.0-16.25
Add new lowlatency kernel flavour

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
#include <sound/jack.h>
34
34
#include "hda_local.h"
35
35
#include "hda_beep.h"
 
36
#include "hda_jack.h"
36
37
#include <sound/hda_hwdep.h>
37
38
 
38
39
#define CREATE_TRACE_POINTS
1446
1447
                for (i = 0; i < c->cvt_setups.used; i++) {
1447
1448
                        p = snd_array_elem(&c->cvt_setups, i);
1448
1449
                        if (!p->active && p->stream_tag == stream_tag &&
1449
 
                            get_wcaps_type(get_wcaps(codec, p->nid)) == type)
 
1450
                            get_wcaps_type(get_wcaps(c, p->nid)) == type)
1450
1451
                                p->dirty = 1;
1451
1452
                }
1452
1453
        }
1723
1724
}
1724
1725
EXPORT_SYMBOL_HDA(snd_hda_override_pin_caps);
1725
1726
 
1726
 
/**
1727
 
 * snd_hda_pin_sense - execute pin sense measurement
1728
 
 * @codec: the CODEC to sense
1729
 
 * @nid: the pin NID to sense
1730
 
 *
1731
 
 * Execute necessary pin sense measurement and return its Presence Detect,
1732
 
 * Impedance, ELD Valid etc. status bits.
1733
 
 */
1734
 
u32 snd_hda_pin_sense(struct hda_codec *codec, hda_nid_t nid)
1735
 
{
1736
 
        u32 pincap;
1737
 
 
1738
 
        if (!codec->no_trigger_sense) {
1739
 
                pincap = snd_hda_query_pin_caps(codec, nid);
1740
 
                if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */
1741
 
                        snd_hda_codec_read(codec, nid, 0,
1742
 
                                        AC_VERB_SET_PIN_SENSE, 0);
1743
 
        }
1744
 
        return snd_hda_codec_read(codec, nid, 0,
1745
 
                                  AC_VERB_GET_PIN_SENSE, 0);
1746
 
}
1747
 
EXPORT_SYMBOL_HDA(snd_hda_pin_sense);
1748
 
 
1749
 
/**
1750
 
 * snd_hda_jack_detect - query pin Presence Detect status
1751
 
 * @codec: the CODEC to sense
1752
 
 * @nid: the pin NID to sense
1753
 
 *
1754
 
 * Query and return the pin's Presence Detect status.
1755
 
 */
1756
 
int snd_hda_jack_detect(struct hda_codec *codec, hda_nid_t nid)
1757
 
{
1758
 
        u32 sense = snd_hda_pin_sense(codec, nid);
1759
 
        return !!(sense & AC_PINSENSE_PRESENCE);
1760
 
}
1761
 
EXPORT_SYMBOL_HDA(snd_hda_jack_detect);
1762
 
 
1763
1727
/*
1764
1728
 * read the current volume to info
1765
1729
 * if the cache exists, read the cache value.
2308
2272
        }
2309
2273
        if (codec->patch_ops.free)
2310
2274
                codec->patch_ops.free(codec);
 
2275
        snd_hda_jack_tbl_clear(codec);
2311
2276
        codec->proc_widget_hook = NULL;
2312
2277
        codec->spec = NULL;
2313
2278
        free_hda_cache(&codec->amp_cache);
3364
3329
        restore_pincfgs(codec); /* restore all current pin configs */
3365
3330
        restore_shutup_pins(codec);
3366
3331
        hda_exec_init_verbs(codec);
 
3332
        snd_hda_jack_set_dirty_all(codec);
3367
3333
        if (codec->patch_ops.resume)
3368
3334
                codec->patch_ops.resume(codec);
3369
3335
        else {
5004
4970
 * "Rear", "Internal".
5005
4971
 */
5006
4972
 
5007
 
const char *hda_get_input_pin_label(struct hda_codec *codec, hda_nid_t pin,
5008
 
                                        int check_location)
 
4973
static const char *hda_get_input_pin_label(struct hda_codec *codec,
 
4974
                                           hda_nid_t pin, bool check_location)
5009
4975
{
5010
4976
        unsigned int def_conf;
5011
4977
        static const char * const mic_names[] = {
5044
5010
                return "Misc";
5045
5011
        }
5046
5012
}
5047
 
EXPORT_SYMBOL_HDA(hda_get_input_pin_label);
5048
5013
 
5049
5014
/* Check whether the location prefix needs to be added to the label.
5050
5015
 * If all mic-jacks are in the same location (e.g. rear panel), we don't
5101
5066
}
5102
5067
EXPORT_SYMBOL_HDA(hda_get_autocfg_input_label);
5103
5068
 
 
5069
/* return the position of NID in the list, or -1 if not found */
 
5070
static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
 
5071
{
 
5072
        int i;
 
5073
        for (i = 0; i < nums; i++)
 
5074
                if (list[i] == nid)
 
5075
                        return i;
 
5076
        return -1;
 
5077
}
 
5078
 
 
5079
/* get a unique suffix or an index number */
 
5080
static const char *check_output_sfx(hda_nid_t nid, const hda_nid_t *pins,
 
5081
                                    int num_pins, int *indexp)
 
5082
{
 
5083
        static const char * const channel_sfx[] = {
 
5084
                " Front", " Surround", " CLFE", " Side"
 
5085
        };
 
5086
        int i;
 
5087
 
 
5088
        i = find_idx_in_nid_list(nid, pins, num_pins);
 
5089
        if (i < 0)
 
5090
                return NULL;
 
5091
        if (num_pins == 1)
 
5092
                return "";
 
5093
        if (num_pins > ARRAY_SIZE(channel_sfx)) {
 
5094
                if (indexp)
 
5095
                        *indexp = i;
 
5096
                return "";
 
5097
        }
 
5098
        return channel_sfx[i];
 
5099
}
 
5100
 
 
5101
static int fill_audio_out_name(struct hda_codec *codec, hda_nid_t nid,
 
5102
                               const struct auto_pin_cfg *cfg,
 
5103
                               const char *name, char *label, int maxlen,
 
5104
                               int *indexp)
 
5105
{
 
5106
        unsigned int def_conf = snd_hda_codec_get_pincfg(codec, nid);
 
5107
        int attr = snd_hda_get_input_pin_attr(def_conf);
 
5108
        const char *pfx = "", *sfx = "";
 
5109
 
 
5110
        /* handle as a speaker if it's a fixed line-out */
 
5111
        if (!strcmp(name, "Line-Out") && attr == INPUT_PIN_ATTR_INT)
 
5112
                name = "Speaker";
 
5113
        /* check the location */
 
5114
        switch (attr) {
 
5115
        case INPUT_PIN_ATTR_DOCK:
 
5116
                pfx = "Dock ";
 
5117
                break;
 
5118
        case INPUT_PIN_ATTR_FRONT:
 
5119
                pfx = "Front ";
 
5120
                break;
 
5121
        }
 
5122
        if (cfg) {
 
5123
                /* try to give a unique suffix if needed */
 
5124
                sfx = check_output_sfx(nid, cfg->line_out_pins, cfg->line_outs,
 
5125
                                       indexp);
 
5126
                if (!sfx)
 
5127
                        sfx = check_output_sfx(nid, cfg->speaker_pins, cfg->speaker_outs,
 
5128
                                               indexp);
 
5129
                if (!sfx) {
 
5130
                        /* don't add channel suffix for Headphone controls */
 
5131
                        int idx = find_idx_in_nid_list(nid, cfg->hp_pins,
 
5132
                                                       cfg->hp_outs);
 
5133
                        if (idx >= 0)
 
5134
                                *indexp = idx;
 
5135
                        sfx = "";
 
5136
                }
 
5137
        }
 
5138
        snprintf(label, maxlen, "%s%s%s", pfx, name, sfx);
 
5139
        return 1;
 
5140
}
 
5141
 
 
5142
/**
 
5143
 * snd_hda_get_pin_label - Get a label for the given I/O pin
 
5144
 *
 
5145
 * Get a label for the given pin.  This function works for both input and
 
5146
 * output pins.  When @cfg is given as non-NULL, the function tries to get
 
5147
 * an optimized label using hda_get_autocfg_input_label().
 
5148
 *
 
5149
 * This function tries to give a unique label string for the pin as much as
 
5150
 * possible.  For example, when the multiple line-outs are present, it adds
 
5151
 * the channel suffix like "Front", "Surround", etc (only when @cfg is given).
 
5152
 * If no unique name with a suffix is available and @indexp is non-NULL, the
 
5153
 * index number is stored in the pointer.
 
5154
 */
 
5155
int snd_hda_get_pin_label(struct hda_codec *codec, hda_nid_t nid,
 
5156
                          const struct auto_pin_cfg *cfg,
 
5157
                          char *label, int maxlen, int *indexp)
 
5158
{
 
5159
        unsigned int def_conf = snd_hda_codec_get_pincfg(codec, nid);
 
5160
        const char *name = NULL;
 
5161
        int i;
 
5162
 
 
5163
        if (indexp)
 
5164
                *indexp = 0;
 
5165
        if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
 
5166
                return 0;
 
5167
 
 
5168
        switch (get_defcfg_device(def_conf)) {
 
5169
        case AC_JACK_LINE_OUT:
 
5170
                return fill_audio_out_name(codec, nid, cfg, "Line-Out",
 
5171
                                           label, maxlen, indexp);
 
5172
        case AC_JACK_SPEAKER:
 
5173
                return fill_audio_out_name(codec, nid, cfg, "Speaker",
 
5174
                                           label, maxlen, indexp);
 
5175
        case AC_JACK_HP_OUT:
 
5176
                return fill_audio_out_name(codec, nid, cfg, "Headphone",
 
5177
                                           label, maxlen, indexp);
 
5178
        case AC_JACK_SPDIF_OUT:
 
5179
        case AC_JACK_DIG_OTHER_OUT:
 
5180
                if (get_defcfg_location(def_conf) == AC_JACK_LOC_HDMI)
 
5181
                        name = "HDMI";
 
5182
                else
 
5183
                        name = "SPDIF";
 
5184
                if (cfg && indexp) {
 
5185
                        i = find_idx_in_nid_list(nid, cfg->dig_out_pins,
 
5186
                                                 cfg->dig_outs);
 
5187
                        if (i >= 0)
 
5188
                                *indexp = i;
 
5189
                }
 
5190
                break;
 
5191
        default:
 
5192
                if (cfg) {
 
5193
                        for (i = 0; i < cfg->num_inputs; i++) {
 
5194
                                if (cfg->inputs[i].pin != nid)
 
5195
                                        continue;
 
5196
                                name = hda_get_autocfg_input_label(codec, cfg, i);
 
5197
                                if (name)
 
5198
                                        break;
 
5199
                        }
 
5200
                }
 
5201
                if (!name)
 
5202
                        name = hda_get_input_pin_label(codec, nid, true);
 
5203
                break;
 
5204
        }
 
5205
        if (!name)
 
5206
                return 0;
 
5207
        strlcpy(label, name, maxlen);
 
5208
        return 1;
 
5209
}
 
5210
EXPORT_SYMBOL_HDA(snd_hda_get_pin_label);
 
5211
 
5104
5212
/**
5105
5213
 * snd_hda_add_imux_item - Add an item to input_mux
5106
5214
 *
5252
5360
}
5253
5361
EXPORT_SYMBOL_HDA(snd_print_pcm_bits);
5254
5362
 
5255
 
#ifdef CONFIG_SND_HDA_INPUT_JACK
5256
 
/*
5257
 
 * Input-jack notification support
5258
 
 */
5259
 
struct hda_jack_item {
5260
 
        hda_nid_t nid;
5261
 
        int type;
5262
 
        struct snd_jack *jack;
5263
 
};
5264
 
 
5265
 
static const char *get_jack_default_name(struct hda_codec *codec, hda_nid_t nid,
5266
 
                                         int type)
5267
 
{
5268
 
        switch (type) {
5269
 
        case SND_JACK_HEADPHONE:
5270
 
                return "Headphone";
5271
 
        case SND_JACK_MICROPHONE:
5272
 
                return "Mic";
5273
 
        case SND_JACK_LINEOUT:
5274
 
                return "Line-out";
5275
 
        case SND_JACK_LINEIN:
5276
 
                return "Line-in";
5277
 
        case SND_JACK_HEADSET:
5278
 
                return "Headset";
5279
 
        case SND_JACK_VIDEOOUT:
5280
 
                return "HDMI/DP";
5281
 
        default:
5282
 
                return "Misc";
5283
 
        }
5284
 
}
5285
 
 
5286
 
static void hda_free_jack_priv(struct snd_jack *jack)
5287
 
{
5288
 
        struct hda_jack_item *jacks = jack->private_data;
5289
 
        jacks->nid = 0;
5290
 
        jacks->jack = NULL;
5291
 
}
5292
 
 
5293
 
int snd_hda_input_jack_add(struct hda_codec *codec, hda_nid_t nid, int type,
5294
 
                           const char *name)
5295
 
{
5296
 
        struct hda_jack_item *jack;
5297
 
        int err;
5298
 
 
5299
 
        snd_array_init(&codec->jacks, sizeof(*jack), 32);
5300
 
        jack = snd_array_new(&codec->jacks);
5301
 
        if (!jack)
5302
 
                return -ENOMEM;
5303
 
 
5304
 
        jack->nid = nid;
5305
 
        jack->type = type;
5306
 
        if (!name)
5307
 
                name = get_jack_default_name(codec, nid, type);
5308
 
        err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
5309
 
        if (err < 0) {
5310
 
                jack->nid = 0;
5311
 
                return err;
5312
 
        }
5313
 
        jack->jack->private_data = jack;
5314
 
        jack->jack->private_free = hda_free_jack_priv;
5315
 
        return 0;
5316
 
}
5317
 
EXPORT_SYMBOL_HDA(snd_hda_input_jack_add);
5318
 
 
5319
 
void snd_hda_input_jack_report(struct hda_codec *codec, hda_nid_t nid)
5320
 
{
5321
 
        struct hda_jack_item *jacks = codec->jacks.list;
5322
 
        int i;
5323
 
 
5324
 
        if (!jacks)
5325
 
                return;
5326
 
 
5327
 
        for (i = 0; i < codec->jacks.used; i++, jacks++) {
5328
 
                unsigned int pin_ctl;
5329
 
                unsigned int present;
5330
 
                int type;
5331
 
 
5332
 
                if (jacks->nid != nid)
5333
 
                        continue;
5334
 
                present = snd_hda_jack_detect(codec, nid);
5335
 
                type = jacks->type;
5336
 
                if (type == (SND_JACK_HEADPHONE | SND_JACK_LINEOUT)) {
5337
 
                        pin_ctl = snd_hda_codec_read(codec, nid, 0,
5338
 
                                             AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5339
 
                        type = (pin_ctl & AC_PINCTL_HP_EN) ?
5340
 
                                SND_JACK_HEADPHONE : SND_JACK_LINEOUT;
5341
 
                }
5342
 
                snd_jack_report(jacks->jack, present ? type : 0);
5343
 
        }
5344
 
}
5345
 
EXPORT_SYMBOL_HDA(snd_hda_input_jack_report);
5346
 
 
5347
 
/* free jack instances manually when clearing/reconfiguring */
5348
 
void snd_hda_input_jack_free(struct hda_codec *codec)
5349
 
{
5350
 
        if (!codec->bus->shutdown && codec->jacks.list) {
5351
 
                struct hda_jack_item *jacks = codec->jacks.list;
5352
 
                int i;
5353
 
                for (i = 0; i < codec->jacks.used; i++, jacks++) {
5354
 
                        if (jacks->jack)
5355
 
                                snd_device_free(codec->bus->card, jacks->jack);
5356
 
                }
5357
 
        }
5358
 
        snd_array_free(&codec->jacks);
5359
 
}
5360
 
EXPORT_SYMBOL_HDA(snd_hda_input_jack_free);
5361
 
#endif /* CONFIG_SND_HDA_INPUT_JACK */
5362
 
 
5363
5363
MODULE_DESCRIPTION("HDA codec core");
5364
5364
MODULE_LICENSE("GPL");