~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
#include <sound/asoundef.h>
30
30
#include <sound/tlv.h>
31
31
#include <sound/initval.h>
 
32
#include <sound/jack.h>
32
33
#include "hda_local.h"
33
34
#include "hda_beep.h"
34
35
#include <sound/hda_hwdep.h>
306
307
}
307
308
EXPORT_SYMBOL_HDA(snd_hda_get_sub_nodes);
308
309
 
 
310
static int _hda_get_connections(struct hda_codec *codec, hda_nid_t nid,
 
311
                                hda_nid_t *conn_list, int max_conns);
 
312
static bool add_conn_list(struct snd_array *array, hda_nid_t nid);
 
313
static int copy_conn_list(hda_nid_t nid, hda_nid_t *dst, int max_dst,
 
314
                          hda_nid_t *src, int len);
 
315
 
309
316
/**
310
317
 * snd_hda_get_connections - get connection list
311
318
 * @codec: the HDA codec
319
326
 * Returns the number of connections, or a negative error code.
320
327
 */
321
328
int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid,
322
 
                            hda_nid_t *conn_list, int max_conns)
 
329
                             hda_nid_t *conn_list, int max_conns)
 
330
{
 
331
        struct snd_array *array = &codec->conn_lists;
 
332
        int i, len, old_used;
 
333
        hda_nid_t list[HDA_MAX_CONNECTIONS];
 
334
 
 
335
        /* look up the cached results */
 
336
        for (i = 0; i < array->used; ) {
 
337
                hda_nid_t *p = snd_array_elem(array, i);
 
338
                len = p[1];
 
339
                if (nid == *p)
 
340
                        return copy_conn_list(nid, conn_list, max_conns,
 
341
                                              p + 2, len);
 
342
                i += len + 2;
 
343
        }
 
344
 
 
345
        len = _hda_get_connections(codec, nid, list, HDA_MAX_CONNECTIONS);
 
346
        if (len < 0)
 
347
                return len;
 
348
 
 
349
        /* add to the cache */
 
350
        old_used = array->used;
 
351
        if (!add_conn_list(array, nid) || !add_conn_list(array, len))
 
352
                goto error_add;
 
353
        for (i = 0; i < len; i++)
 
354
                if (!add_conn_list(array, list[i]))
 
355
                        goto error_add;
 
356
 
 
357
        return copy_conn_list(nid, conn_list, max_conns, list, len);
 
358
                
 
359
 error_add:
 
360
        array->used = old_used;
 
361
        return -ENOMEM;
 
362
}
 
363
EXPORT_SYMBOL_HDA(snd_hda_get_connections);
 
364
 
 
365
static int _hda_get_connections(struct hda_codec *codec, hda_nid_t nid,
 
366
                             hda_nid_t *conn_list, int max_conns)
323
367
{
324
368
        unsigned int parm;
325
369
        int i, conn_len, conns;
416
460
        }
417
461
        return conns;
418
462
}
419
 
EXPORT_SYMBOL_HDA(snd_hda_get_connections);
420
 
 
 
463
 
 
464
static bool add_conn_list(struct snd_array *array, hda_nid_t nid)
 
465
{
 
466
        hda_nid_t *p = snd_array_new(array);
 
467
        if (!p)
 
468
                return false;
 
469
        *p = nid;
 
470
        return true;
 
471
}
 
472
 
 
473
static int copy_conn_list(hda_nid_t nid, hda_nid_t *dst, int max_dst,
 
474
                          hda_nid_t *src, int len)
 
475
{
 
476
        if (len > max_dst) {
 
477
                snd_printk(KERN_ERR "hda_codec: "
 
478
                           "Too many connections %d for NID 0x%x\n",
 
479
                           len, nid);
 
480
                return -EINVAL;
 
481
        }
 
482
        memcpy(dst, src, len * sizeof(hda_nid_t));
 
483
        return len;
 
484
}
421
485
 
422
486
/**
423
487
 * snd_hda_queue_unsol_event - add an unsolicited event to queue
936
1000
}
937
1001
EXPORT_SYMBOL_HDA(snd_hda_shutup_pins);
938
1002
 
 
1003
#ifdef SND_HDA_NEEDS_RESUME
939
1004
/* Restore the pin controls cleared previously via snd_hda_shutup_pins() */
940
1005
static void restore_shutup_pins(struct hda_codec *codec)
941
1006
{
952
1017
        }
953
1018
        codec->pins_shutup = 0;
954
1019
}
 
1020
#endif
955
1021
 
956
1022
static void init_hda_cache(struct hda_cache_rec *cache,
957
1023
                           unsigned int record_size);
1016
1082
        list_del(&codec->list);
1017
1083
        snd_array_free(&codec->mixers);
1018
1084
        snd_array_free(&codec->nids);
 
1085
        snd_array_free(&codec->conn_lists);
1019
1086
        codec->bus->caddr_tbl[codec->addr] = NULL;
1020
1087
        if (codec->patch_ops.free)
1021
1088
                codec->patch_ops.free(codec);
1076
1143
        snd_array_init(&codec->init_pins, sizeof(struct hda_pincfg), 16);
1077
1144
        snd_array_init(&codec->driver_pins, sizeof(struct hda_pincfg), 16);
1078
1145
        snd_array_init(&codec->cvt_setups, sizeof(struct hda_cvt_setup), 8);
 
1146
        snd_array_init(&codec->conn_lists, sizeof(hda_nid_t), 64);
1079
1147
        if (codec->bus->modelname) {
1080
1148
                codec->modelname = kstrdup(codec->bus->modelname, GFP_KERNEL);
1081
1149
                if (!codec->modelname) {
1328
1396
        }
1329
1397
}
1330
1398
 
 
1399
#ifdef SND_HDA_NEEDS_RESUME
1331
1400
/* clean up all streams; called from suspend */
1332
1401
static void hda_cleanup_all_streams(struct hda_codec *codec)
1333
1402
{
1339
1408
                        really_cleanup_stream(codec, p);
1340
1409
        }
1341
1410
}
 
1411
#endif
1342
1412
 
1343
1413
/*
1344
1414
 * amp access functions
2551
2621
static void set_dig_out(struct hda_codec *codec, hda_nid_t nid,
2552
2622
                        int verb, int val)
2553
2623
{
2554
 
        hda_nid_t *d;
 
2624
        const hda_nid_t *d;
2555
2625
 
2556
2626
        snd_hda_codec_write_cache(codec, nid, 0, verb, val);
2557
2627
        d = codec->slave_dig_outs;
3660
3730
 * with the proper parameters for set up.
3661
3731
 * ops.cleanup should be called in hw_free for clean up of streams.
3662
3732
 *
3663
 
 * This function returns 0 if successfull, or a negative error code.
 
3733
 * This function returns 0 if successful, or a negative error code.
3664
3734
 */
3665
3735
int __devinit snd_hda_build_pcms(struct hda_bus *bus)
3666
3736
{
3802
3872
 *
3803
3873
 * Returns 0 if successful, or a negative error code.
3804
3874
 */
3805
 
int snd_hda_add_new_ctls(struct hda_codec *codec, struct snd_kcontrol_new *knew)
 
3875
int snd_hda_add_new_ctls(struct hda_codec *codec,
 
3876
                         const struct snd_kcontrol_new *knew)
3806
3877
{
3807
3878
        int err;
3808
3879
 
3945
4016
                                 struct hda_loopback_check *check,
3946
4017
                                 hda_nid_t nid)
3947
4018
{
3948
 
        struct hda_amp_list *p;
 
4019
        const struct hda_amp_list *p;
3949
4020
        int ch, v;
3950
4021
 
3951
4022
        if (!check->amplist)
4113
4184
                                    -1);
4114
4185
        snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
4115
4186
        if (codec->slave_dig_outs) {
4116
 
                hda_nid_t *d;
 
4187
                const hda_nid_t *d;
4117
4188
                for (d = codec->slave_dig_outs; *d; d++)
4118
4189
                        snd_hda_codec_setup_stream(codec, *d, stream_tag, 0,
4119
4190
                                                   format);
4128
4199
{
4129
4200
        snd_hda_codec_cleanup_stream(codec, nid);
4130
4201
        if (codec->slave_dig_outs) {
4131
 
                hda_nid_t *d;
 
4202
                const hda_nid_t *d;
4132
4203
                for (d = codec->slave_dig_outs; *d; d++)
4133
4204
                        snd_hda_codec_cleanup_stream(codec, *d);
4134
4205
        }
4275
4346
                                     unsigned int format,
4276
4347
                                     struct snd_pcm_substream *substream)
4277
4348
{
4278
 
        hda_nid_t *nids = mout->dac_nids;
 
4349
        const hda_nid_t *nids = mout->dac_nids;
4279
4350
        int chs = substream->runtime->channels;
4280
4351
        int i;
4281
4352
 
4330
4401
int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec,
4331
4402
                                     struct hda_multi_out *mout)
4332
4403
{
4333
 
        hda_nid_t *nids = mout->dac_nids;
 
4404
        const hda_nid_t *nids = mout->dac_nids;
4334
4405
        int i;
4335
4406
 
4336
4407
        for (i = 0; i < mout->num_dacs; i++)
4355
4426
 * Helper for automatic pin configuration
4356
4427
 */
4357
4428
 
4358
 
static int is_in_nid_list(hda_nid_t nid, hda_nid_t *list)
 
4429
static int is_in_nid_list(hda_nid_t nid, const hda_nid_t *list)
4359
4430
{
4360
4431
        for (; *list; list++)
4361
4432
                if (*list == nid)
4436
4507
 */
4437
4508
int snd_hda_parse_pin_def_config(struct hda_codec *codec,
4438
4509
                                 struct auto_pin_cfg *cfg,
4439
 
                                 hda_nid_t *ignore_nids)
 
4510
                                 const hda_nid_t *ignore_nids)
4440
4511
{
4441
4512
        hda_nid_t nid, end_nid;
4442
4513
        short seq, assoc_line_out, assoc_speaker;
4627
4698
        /*
4628
4699
         * debug prints of the parsed results
4629
4700
         */
4630
 
        snd_printd("autoconfig: line_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
 
4701
        snd_printd("autoconfig: line_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x) type:%s\n",
4631
4702
                   cfg->line_outs, cfg->line_out_pins[0], cfg->line_out_pins[1],
4632
4703
                   cfg->line_out_pins[2], cfg->line_out_pins[3],
4633
 
                   cfg->line_out_pins[4]);
 
4704
                   cfg->line_out_pins[4],
 
4705
                   cfg->line_out_type == AUTO_PIN_HP_OUT ? "hp" :
 
4706
                   (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT ?
 
4707
                    "speaker" : "line"));
4634
4708
        snd_printd("   speaker_outs=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
4635
4709
                   cfg->speaker_outs, cfg->speaker_pins[0],
4636
4710
                   cfg->speaker_pins[1], cfg->speaker_pins[2],
4645
4719
                           cfg->dig_out_pins[0], cfg->dig_out_pins[1]);
4646
4720
        snd_printd("   inputs:");
4647
4721
        for (i = 0; i < cfg->num_inputs; i++) {
4648
 
                snd_printdd(" %s=0x%x",
 
4722
                snd_printd(" %s=0x%x",
4649
4723
                            hda_get_autocfg_input_label(codec, cfg, i),
4650
4724
                            cfg->inputs[i].pin);
4651
4725
        }
4850
4924
 *
4851
4925
 * Returns 0 if successful.
4852
4926
 *
4853
 
 * This fucntion is defined only when POWER_SAVE isn't set.
 
4927
 * This function is defined only when POWER_SAVE isn't set.
4854
4928
 * In the power-save mode, the codec is resumed dynamically.
4855
4929
 */
4856
4930
int snd_hda_resume(struct hda_bus *bus)
4959
5033
}
4960
5034
EXPORT_SYMBOL_HDA(snd_print_pcm_bits);
4961
5035
 
 
5036
#ifdef CONFIG_SND_HDA_INPUT_JACK
 
5037
/*
 
5038
 * Input-jack notification support
 
5039
 */
 
5040
struct hda_jack_item {
 
5041
        hda_nid_t nid;
 
5042
        int type;
 
5043
        struct snd_jack *jack;
 
5044
};
 
5045
 
 
5046
static const char *get_jack_default_name(struct hda_codec *codec, hda_nid_t nid,
 
5047
                                         int type)
 
5048
{
 
5049
        switch (type) {
 
5050
        case SND_JACK_HEADPHONE:
 
5051
                return "Headphone";
 
5052
        case SND_JACK_MICROPHONE:
 
5053
                return "Mic";
 
5054
        case SND_JACK_LINEOUT:
 
5055
                return "Line-out";
 
5056
        case SND_JACK_HEADSET:
 
5057
                return "Headset";
 
5058
        case SND_JACK_VIDEOOUT:
 
5059
                return "HDMI/DP";
 
5060
        default:
 
5061
                return "Misc";
 
5062
        }
 
5063
}
 
5064
 
 
5065
static void hda_free_jack_priv(struct snd_jack *jack)
 
5066
{
 
5067
        struct hda_jack_item *jacks = jack->private_data;
 
5068
        jacks->nid = 0;
 
5069
        jacks->jack = NULL;
 
5070
}
 
5071
 
 
5072
int snd_hda_input_jack_add(struct hda_codec *codec, hda_nid_t nid, int type,
 
5073
                           const char *name)
 
5074
{
 
5075
        struct hda_jack_item *jack;
 
5076
        int err;
 
5077
 
 
5078
        snd_array_init(&codec->jacks, sizeof(*jack), 32);
 
5079
        jack = snd_array_new(&codec->jacks);
 
5080
        if (!jack)
 
5081
                return -ENOMEM;
 
5082
 
 
5083
        jack->nid = nid;
 
5084
        jack->type = type;
 
5085
        if (!name)
 
5086
                name = get_jack_default_name(codec, nid, type);
 
5087
        err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
 
5088
        if (err < 0) {
 
5089
                jack->nid = 0;
 
5090
                return err;
 
5091
        }
 
5092
        jack->jack->private_data = jack;
 
5093
        jack->jack->private_free = hda_free_jack_priv;
 
5094
        return 0;
 
5095
}
 
5096
EXPORT_SYMBOL_HDA(snd_hda_input_jack_add);
 
5097
 
 
5098
void snd_hda_input_jack_report(struct hda_codec *codec, hda_nid_t nid)
 
5099
{
 
5100
        struct hda_jack_item *jacks = codec->jacks.list;
 
5101
        int i;
 
5102
 
 
5103
        if (!jacks)
 
5104
                return;
 
5105
 
 
5106
        for (i = 0; i < codec->jacks.used; i++, jacks++) {
 
5107
                unsigned int pin_ctl;
 
5108
                unsigned int present;
 
5109
                int type;
 
5110
 
 
5111
                if (jacks->nid != nid)
 
5112
                        continue;
 
5113
                present = snd_hda_jack_detect(codec, nid);
 
5114
                type = jacks->type;
 
5115
                if (type == (SND_JACK_HEADPHONE | SND_JACK_LINEOUT)) {
 
5116
                        pin_ctl = snd_hda_codec_read(codec, nid, 0,
 
5117
                                             AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
 
5118
                        type = (pin_ctl & AC_PINCTL_HP_EN) ?
 
5119
                                SND_JACK_HEADPHONE : SND_JACK_LINEOUT;
 
5120
                }
 
5121
                snd_jack_report(jacks->jack, present ? type : 0);
 
5122
        }
 
5123
}
 
5124
EXPORT_SYMBOL_HDA(snd_hda_input_jack_report);
 
5125
 
 
5126
/* free jack instances manually when clearing/reconfiguring */
 
5127
void snd_hda_input_jack_free(struct hda_codec *codec)
 
5128
{
 
5129
        if (!codec->bus->shutdown && codec->jacks.list) {
 
5130
                struct hda_jack_item *jacks = codec->jacks.list;
 
5131
                int i;
 
5132
                for (i = 0; i < codec->jacks.used; i++, jacks++) {
 
5133
                        if (jacks->jack)
 
5134
                                snd_device_free(codec->bus->card, jacks->jack);
 
5135
                }
 
5136
        }
 
5137
        snd_array_free(&codec->jacks);
 
5138
}
 
5139
EXPORT_SYMBOL_HDA(snd_hda_input_jack_free);
 
5140
#endif /* CONFIG_SND_HDA_INPUT_JACK */
 
5141
 
4962
5142
MODULE_DESCRIPTION("HDA codec core");
4963
5143
MODULE_LICENSE("GPL");