aboutsummaryrefslogtreecommitdiffstats
path: root/sound
diff options
context:
space:
mode:
authorMatthew Ranostay <mranostay@embeddedalley.com>2008-07-18 12:20:52 -0400
committerJaroslav Kysela <perex@perex.cz>2008-07-20 13:17:49 -0400
commit1cd2224cd01898a13138f4ab476932cfb689839e (patch)
treeb482e8f8e6e51fd5143ac9ef7edc88194b031d9c /sound
parent68c072388d2339af504c033a51886ea7c6b8d806 (diff)
ALSA: hda: digital pc-beep support hd-audio codecs
Added digital pc-beep support using linear tone generation for hd-codecs along with initial support for several IDT codecs. Signed-off-by: Matthew Ranostay <mranostay@embeddedalley.com> Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Diffstat (limited to 'sound')
-rw-r--r--sound/pci/Kconfig8
-rw-r--r--sound/pci/hda/Makefile1
-rw-r--r--sound/pci/hda/hda_beep.c134
-rw-r--r--sound/pci/hda/hda_beep.h44
-rw-r--r--sound/pci/hda/hda_codec.h4
-rw-r--r--sound/pci/hda/patch_sigmatel.c63
6 files changed, 254 insertions, 0 deletions
diff --git a/sound/pci/Kconfig b/sound/pci/Kconfig
index 31f52d3fc21f..db9e31fd0612 100644
--- a/sound/pci/Kconfig
+++ b/sound/pci/Kconfig
@@ -517,6 +517,14 @@ config SND_HDA_HWDEP
517 This interface can be used for out-of-band communication 517 This interface can be used for out-of-band communication
518 with codecs for debugging purposes. 518 with codecs for debugging purposes.
519 519
520config SND_HDA_INPUT_BEEP
521 bool "Support digital beep via input layer"
522 depends on SND_HDA_INTEL
523 depends on INPUT=y || INPUT=SND_HDA_INTEL
524 help
525 Say Y here to build a digital beep interface for HD-audio
526 driver. This interface is used to generate digital beeps.
527
520config SND_HDA_CODEC_REALTEK 528config SND_HDA_CODEC_REALTEK
521 bool "Build Realtek HD-audio codec support" 529 bool "Build Realtek HD-audio codec support"
522 depends on SND_HDA_INTEL 530 depends on SND_HDA_INTEL
diff --git a/sound/pci/hda/Makefile b/sound/pci/hda/Makefile
index ab0c726d648e..6db92fd954d9 100644
--- a/sound/pci/hda/Makefile
+++ b/sound/pci/hda/Makefile
@@ -5,6 +5,7 @@ snd-hda-intel-y := hda_intel.o
5snd-hda-intel-y += hda_codec.o 5snd-hda-intel-y += hda_codec.o
6snd-hda-intel-$(CONFIG_PROC_FS) += hda_proc.o 6snd-hda-intel-$(CONFIG_PROC_FS) += hda_proc.o
7snd-hda-intel-$(CONFIG_SND_HDA_HWDEP) += hda_hwdep.o 7snd-hda-intel-$(CONFIG_SND_HDA_HWDEP) += hda_hwdep.o
8snd-hda-intel-$(CONFIG_SND_HDA_INPUT_BEEP) += hda_beep.o
8snd-hda-intel-$(CONFIG_SND_HDA_GENERIC) += hda_generic.o 9snd-hda-intel-$(CONFIG_SND_HDA_GENERIC) += hda_generic.o
9snd-hda-intel-$(CONFIG_SND_HDA_CODEC_REALTEK) += patch_realtek.o 10snd-hda-intel-$(CONFIG_SND_HDA_CODEC_REALTEK) += patch_realtek.o
10snd-hda-intel-$(CONFIG_SND_HDA_CODEC_CMEDIA) += patch_cmedia.o 11snd-hda-intel-$(CONFIG_SND_HDA_CODEC_CMEDIA) += patch_cmedia.o
diff --git a/sound/pci/hda/hda_beep.c b/sound/pci/hda/hda_beep.c
new file mode 100644
index 000000000000..5a764c481391
--- /dev/null
+++ b/sound/pci/hda/hda_beep.c
@@ -0,0 +1,134 @@
1/*
2 * Digital Beep Input Interface for HD-audio codec
3 *
4 * Author: Matthew Ranostay <mranostay@embeddedalley.com>
5 * Copyright (c) 2008 Embedded Alley Solutions Inc
6 *
7 * This driver is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This driver is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22#include <linux/input.h>
23#include <linux/pci.h>
24#include <linux/workqueue.h>
25#include <sound/core.h>
26#include "hda_beep.h"
27
28enum {
29 DIGBEEP_HZ_STEP = 46875, /* 46.875 Hz */
30 DIGBEEP_HZ_MIN = 93750, /* 93.750 Hz */
31 DIGBEEP_HZ_MAX = 12000000, /* 12 KHz */
32};
33
34static void snd_hda_generate_beep(struct work_struct *work)
35{
36 struct hda_beep *beep =
37 container_of(work, struct hda_beep, beep_work);
38 struct hda_codec *codec = beep->codec;
39
40 /* generate tone */
41 snd_hda_codec_write_cache(codec, beep->nid, 0,
42 AC_VERB_SET_BEEP_CONTROL, beep->tone);
43}
44
45static int snd_hda_beep_event(struct input_dev *dev, unsigned int type,
46 unsigned int code, int hz)
47{
48 struct hda_beep *beep = input_get_drvdata(dev);
49
50 switch (code) {
51 case SND_BELL:
52 if (hz)
53 hz = 1000;
54 case SND_TONE:
55 hz *= 1000; /* fixed point */
56 hz = hz - DIGBEEP_HZ_MIN;
57 if (hz < 0)
58 hz = 0; /* turn off PC beep*/
59 else if (hz >= (DIGBEEP_HZ_MAX - DIGBEEP_HZ_MIN))
60 hz = 0xff;
61 else {
62 hz /= DIGBEEP_HZ_STEP;
63 hz++;
64 }
65 break;
66 default:
67 return -1;
68 }
69 beep->tone = hz;
70
71 /* schedule beep event */
72 schedule_work(&beep->beep_work);
73 return 0;
74}
75
76int snd_hda_attach_beep_device(struct hda_codec *codec, int nid)
77{
78 struct input_dev *input_dev;
79 struct hda_beep *beep;
80 int err;
81
82 beep = kzalloc(sizeof(*beep), GFP_KERNEL);
83 if (beep == NULL)
84 return -ENOMEM;
85 snprintf(beep->phys, sizeof(beep->phys),
86 "card%d/codec#%d/beep0", codec->bus->card->number, codec->addr);
87 input_dev = input_allocate_device();
88
89 /* setup digital beep device */
90 input_dev->name = "HDA Digital PCBeep";
91 input_dev->phys = beep->phys;
92 input_dev->id.bustype = BUS_PCI;
93
94 input_dev->id.vendor = codec->vendor_id >> 16;
95 input_dev->id.product = codec->vendor_id & 0xffff;
96 input_dev->id.version = 0x01;
97
98 input_dev->evbit[0] = BIT_MASK(EV_SND);
99 input_dev->sndbit[0] = BIT_MASK(SND_BELL) | BIT_MASK(SND_TONE);
100 input_dev->event = snd_hda_beep_event;
101 input_dev->dev.parent = &codec->bus->pci->dev;
102 input_set_drvdata(input_dev, beep);
103
104 err = input_register_device(input_dev);
105 if (err < 0) {
106 kfree(input_dev);
107 kfree(beep);
108 return err;
109 }
110
111 /* enable linear scale */
112 snd_hda_codec_write(codec, nid, 0,
113 AC_VERB_SET_DIGI_CONVERT_2, 0x01);
114
115 beep->nid = nid;
116 beep->dev = input_dev;
117 beep->codec = codec;
118 codec->beep = beep;
119
120 INIT_WORK(&beep->beep_work, &snd_hda_generate_beep);
121 return 0;
122}
123
124void snd_hda_detach_beep_device(struct hda_codec *codec)
125{
126 struct hda_beep *beep = codec->beep;
127 if (beep) {
128 cancel_work_sync(&beep->beep_work);
129 flush_scheduled_work();
130
131 input_unregister_device(beep->dev);
132 kfree(beep);
133 }
134}
diff --git a/sound/pci/hda/hda_beep.h b/sound/pci/hda/hda_beep.h
new file mode 100644
index 000000000000..de4036e6e710
--- /dev/null
+++ b/sound/pci/hda/hda_beep.h
@@ -0,0 +1,44 @@
1/*
2 * Digital Beep Input Interface for HD-audio codec
3 *
4 * Author: Matthew Ranostay <mranostay@embeddedalley.com>
5 * Copyright (c) 2008 Embedded Alley Solutions Inc
6 *
7 * This driver is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This driver is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22#ifndef __SOUND_HDA_BEEP_H
23#define __SOUND_HDA_BEEP_H
24
25#include "hda_codec.h"
26
27/* beep information */
28struct hda_beep {
29 struct input_dev *dev;
30 struct hda_codec *codec;
31 char phys[32];
32 int tone;
33 int nid;
34 struct work_struct beep_work; /* scheduled task for beep event */
35};
36
37#ifdef CONFIG_SND_HDA_INPUT_BEEP
38int snd_hda_attach_beep_device(struct hda_codec *codec, int nid);
39void snd_hda_detach_beep_device(struct hda_codec *codec);
40#else
41#define snd_hda_attach_beep_device(...)
42#define snd_hda_detach_beep_device(...)
43#endif
44#endif
diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
index efc682888b31..3a63c445d36b 100644
--- a/sound/pci/hda/hda_codec.h
+++ b/sound/pci/hda/hda_codec.h
@@ -449,6 +449,7 @@ enum {
449 */ 449 */
450 450
451struct hda_bus; 451struct hda_bus;
452struct hda_beep;
452struct hda_codec; 453struct hda_codec;
453struct hda_pcm; 454struct hda_pcm;
454struct hda_pcm_stream; 455struct hda_pcm_stream;
@@ -634,6 +635,9 @@ struct hda_codec {
634 /* codec specific info */ 635 /* codec specific info */
635 void *spec; 636 void *spec;
636 637
638 /* beep device */
639 struct hda_beep *beep;
640
637 /* widget capabilities cache */ 641 /* widget capabilities cache */
638 unsigned int num_nodes; 642 unsigned int num_nodes;
639 hda_nid_t start_nid; 643 hda_nid_t start_nid;
diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c
index f3da621f25c5..6ee73ed23ddd 100644
--- a/sound/pci/hda/patch_sigmatel.c
+++ b/sound/pci/hda/patch_sigmatel.c
@@ -33,6 +33,7 @@
33#include "hda_codec.h" 33#include "hda_codec.h"
34#include "hda_local.h" 34#include "hda_local.h"
35#include "hda_patch.h" 35#include "hda_patch.h"
36#include "hda_beep.h"
36 37
37#define NUM_CONTROL_ALLOC 32 38#define NUM_CONTROL_ALLOC 32
38#define STAC_PWR_EVENT 0x20 39#define STAC_PWR_EVENT 0x20
@@ -164,6 +165,8 @@ struct sigmatel_spec {
164 unsigned int num_dmuxes; 165 unsigned int num_dmuxes;
165 hda_nid_t dig_in_nid; 166 hda_nid_t dig_in_nid;
166 hda_nid_t mono_nid; 167 hda_nid_t mono_nid;
168 hda_nid_t anabeep_nid;
169 hda_nid_t digbeep_nid;
167 170
168 /* pin widgets */ 171 /* pin widgets */
169 hda_nid_t *pin_nids; 172 hda_nid_t *pin_nids;
@@ -690,6 +693,8 @@ static struct hda_verb d965_core_init[] = {
690static struct hda_verb stac927x_core_init[] = { 693static struct hda_verb stac927x_core_init[] = {
691 /* set master volume and direct control */ 694 /* set master volume and direct control */
692 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff}, 695 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
696 /* enable analog pc beep path */
697 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
693 {} 698 {}
694}; 699};
695 700
@@ -829,8 +834,11 @@ static struct snd_kcontrol_new stac92hd71bxx_analog_mixer[] = {
829 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT), 834 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT),
830 HDA_CODEC_VOLUME_IDX("Capture Mux Volume", 0x1, 0x1b, 0x0, HDA_OUTPUT), 835 HDA_CODEC_VOLUME_IDX("Capture Mux Volume", 0x1, 0x1b, 0x0, HDA_OUTPUT),
831 836
837 /* analog pc-beep replaced with digital beep support */
838 /*
832 HDA_CODEC_VOLUME("PC Beep Volume", 0x17, 0x2, HDA_INPUT), 839 HDA_CODEC_VOLUME("PC Beep Volume", 0x17, 0x2, HDA_INPUT),
833 HDA_CODEC_MUTE("PC Beep Switch", 0x17, 0x2, HDA_INPUT), 840 HDA_CODEC_MUTE("PC Beep Switch", 0x17, 0x2, HDA_INPUT),
841 */
834 842
835 HDA_CODEC_MUTE("Analog Loopback 1", 0x17, 0x3, HDA_INPUT), 843 HDA_CODEC_MUTE("Analog Loopback 1", 0x17, 0x3, HDA_INPUT),
836 HDA_CODEC_MUTE("Analog Loopback 2", 0x17, 0x4, HDA_INPUT), 844 HDA_CODEC_MUTE("Analog Loopback 2", 0x17, 0x4, HDA_INPUT),
@@ -2609,6 +2617,34 @@ static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
2609 "Mono Mux", spec->mono_nid); 2617 "Mono Mux", spec->mono_nid);
2610} 2618}
2611 2619
2620/* create PC beep volume controls */
2621static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
2622 hda_nid_t nid)
2623{
2624 struct sigmatel_spec *spec = codec->spec;
2625 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
2626 int err;
2627
2628 /* check for mute support for the the amp */
2629 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
2630 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
2631 "PC Beep Playback Switch",
2632 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
2633 if (err < 0)
2634 return err;
2635 }
2636
2637 /* check to see if there is volume support for the amp */
2638 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
2639 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
2640 "PC Beep Playback Volume",
2641 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
2642 if (err < 0)
2643 return err;
2644 }
2645 return 0;
2646}
2647
2612/* labels for dmic mux inputs */ 2648/* labels for dmic mux inputs */
2613static const char *stac92xx_dmic_labels[5] = { 2649static const char *stac92xx_dmic_labels[5] = {
2614 "Analog Inputs", "Digital Mic 1", "Digital Mic 2", 2650 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
@@ -2844,6 +2880,28 @@ static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out
2844 if (err < 0) 2880 if (err < 0)
2845 return err; 2881 return err;
2846 2882
2883 /* setup analog beep controls */
2884 if (spec->anabeep_nid > 0) {
2885 err = stac92xx_auto_create_beep_ctls(codec,
2886 spec->anabeep_nid);
2887 if (err < 0)
2888 return err;
2889 }
2890
2891 /* setup digital beep controls and input device */
2892#ifdef CONFIG_SND_HDA_INPUT_BEEP
2893 if (spec->digbeep_nid > 0) {
2894 hda_nid_t nid = spec->digbeep_nid;
2895
2896 err = stac92xx_auto_create_beep_ctls(codec, nid);
2897 if (err < 0)
2898 return err;
2899 err = snd_hda_attach_beep_device(codec, nid);
2900 if (err < 0)
2901 return err;
2902 }
2903#endif
2904
2847 if (hp_speaker_swap == 1) { 2905 if (hp_speaker_swap == 1) {
2848 /* Restore the hp_outs and line_outs */ 2906 /* Restore the hp_outs and line_outs */
2849 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins, 2907 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
@@ -3158,6 +3216,7 @@ static void stac92xx_free(struct hda_codec *codec)
3158 kfree(spec->bios_pin_configs); 3216 kfree(spec->bios_pin_configs);
3159 3217
3160 kfree(spec); 3218 kfree(spec);
3219 snd_hda_detach_beep_device(codec);
3161} 3220}
3162 3221
3163static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid, 3222static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
@@ -3546,6 +3605,7 @@ again:
3546 spec->aloopback_mask = 0x01; 3605 spec->aloopback_mask = 0x01;
3547 spec->aloopback_shift = 8; 3606 spec->aloopback_shift = 8;
3548 3607
3608 spec->digbeep_nid = 0x1c;
3549 spec->mux_nids = stac92hd73xx_mux_nids; 3609 spec->mux_nids = stac92hd73xx_mux_nids;
3550 spec->adc_nids = stac92hd73xx_adc_nids; 3610 spec->adc_nids = stac92hd73xx_adc_nids;
3551 spec->dmic_nids = stac92hd73xx_dmic_nids; 3611 spec->dmic_nids = stac92hd73xx_dmic_nids;
@@ -3680,6 +3740,7 @@ again:
3680 spec->gpio_dir = 0x01; 3740 spec->gpio_dir = 0x01;
3681 spec->gpio_data = 0x01; 3741 spec->gpio_data = 0x01;
3682 3742
3743 spec->digbeep_nid = 0x26;
3683 spec->mux_nids = stac92hd71bxx_mux_nids; 3744 spec->mux_nids = stac92hd71bxx_mux_nids;
3684 spec->adc_nids = stac92hd71bxx_adc_nids; 3745 spec->adc_nids = stac92hd71bxx_adc_nids;
3685 spec->dmic_nids = stac92hd71bxx_dmic_nids; 3746 spec->dmic_nids = stac92hd71bxx_dmic_nids;
@@ -3854,6 +3915,7 @@ static int patch_stac927x(struct hda_codec *codec)
3854 stac92xx_set_config_regs(codec); 3915 stac92xx_set_config_regs(codec);
3855 } 3916 }
3856 3917
3918 spec->digbeep_nid = 0x23;
3857 spec->adc_nids = stac927x_adc_nids; 3919 spec->adc_nids = stac927x_adc_nids;
3858 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids); 3920 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
3859 spec->mux_nids = stac927x_mux_nids; 3921 spec->mux_nids = stac927x_mux_nids;
@@ -3974,6 +4036,7 @@ static int patch_stac9205(struct hda_codec *codec)
3974 stac92xx_set_config_regs(codec); 4036 stac92xx_set_config_regs(codec);
3975 } 4037 }
3976 4038
4039 spec->digbeep_nid = 0x23;
3977 spec->adc_nids = stac9205_adc_nids; 4040 spec->adc_nids = stac9205_adc_nids;
3978 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids); 4041 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
3979 spec->mux_nids = stac9205_mux_nids; 4042 spec->mux_nids = stac9205_mux_nids;