diff options
author | Takashi Iwai <tiwai@suse.de> | 2009-05-19 06:50:04 -0400 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2009-05-19 06:54:55 -0400 |
commit | fa7979663190240b838ab8c8bad7f59e618bf77c (patch) | |
tree | e008dbd603562a54300ed8d189bd9bb59b5aa697 | |
parent | 4abc1cc2f9fe4b6bb3acc1d78e2c15af47b8133d (diff) |
ALSA: hda - Fix digital beep tone calculation
The digital beep tone is calculated in two different ways depending
on the codec chip. The standard one is using a divider, and another
one is a linear tone for IDT/STAC codecs. Currently, only the
latter type is used for all codecs, which resulted in a wrong tone
pitch.
This patch adds the calculation of the standard HD-audio type.
Also clean-up the fields in hda_beep struct.
Reference: bko#13162
http://bugzilla.kernel.org/show_bug.cgi?id=13162
Signed-off-by: Takashi Iwai <tiwai@suse.de>
-rw-r--r-- | sound/pci/hda/hda_beep.c | 55 | ||||
-rw-r--r-- | sound/pci/hda/hda_beep.h | 5 | ||||
-rw-r--r-- | sound/pci/hda/patch_sigmatel.c | 2 |
3 files changed, 49 insertions, 13 deletions
diff --git a/sound/pci/hda/hda_beep.c b/sound/pci/hda/hda_beep.c index 4de5bacd3929..29272f2e95a0 100644 --- a/sound/pci/hda/hda_beep.c +++ b/sound/pci/hda/hda_beep.c | |||
@@ -45,6 +45,46 @@ static void snd_hda_generate_beep(struct work_struct *work) | |||
45 | AC_VERB_SET_BEEP_CONTROL, beep->tone); | 45 | AC_VERB_SET_BEEP_CONTROL, beep->tone); |
46 | } | 46 | } |
47 | 47 | ||
48 | /* (non-standard) Linear beep tone calculation for IDT/STAC codecs | ||
49 | * | ||
50 | * The tone frequency of beep generator on IDT/STAC codecs is | ||
51 | * defined from the 8bit tone parameter, in Hz, | ||
52 | * freq = 48000 * (257 - tone) / 1024 | ||
53 | * that is from 12kHz to 93.75kHz in step of 46.875 hz | ||
54 | */ | ||
55 | static int beep_linear_tone(struct hda_beep *beep, int hz) | ||
56 | { | ||
57 | hz *= 1000; /* fixed point */ | ||
58 | hz = hz - DIGBEEP_HZ_MIN; | ||
59 | if (hz < 0) | ||
60 | hz = 0; /* turn off PC beep*/ | ||
61 | else if (hz >= (DIGBEEP_HZ_MAX - DIGBEEP_HZ_MIN)) | ||
62 | hz = 0xff; | ||
63 | else { | ||
64 | hz /= DIGBEEP_HZ_STEP; | ||
65 | hz++; | ||
66 | } | ||
67 | return hz; | ||
68 | } | ||
69 | |||
70 | /* HD-audio standard beep tone parameter calculation | ||
71 | * | ||
72 | * The tone frequency in Hz is calculated as | ||
73 | * freq = 48000 / (tone * 4) | ||
74 | * from 47Hz to 12kHz | ||
75 | */ | ||
76 | static int beep_standard_tone(struct hda_beep *beep, int hz) | ||
77 | { | ||
78 | if (hz <= 0) | ||
79 | return 0; /* disabled */ | ||
80 | hz = 12000 / hz; | ||
81 | if (hz > 0xff) | ||
82 | return 0xff; | ||
83 | if (hz <= 0) | ||
84 | return 1; | ||
85 | return hz; | ||
86 | } | ||
87 | |||
48 | static int snd_hda_beep_event(struct input_dev *dev, unsigned int type, | 88 | static int snd_hda_beep_event(struct input_dev *dev, unsigned int type, |
49 | unsigned int code, int hz) | 89 | unsigned int code, int hz) |
50 | { | 90 | { |
@@ -55,21 +95,14 @@ static int snd_hda_beep_event(struct input_dev *dev, unsigned int type, | |||
55 | if (hz) | 95 | if (hz) |
56 | hz = 1000; | 96 | hz = 1000; |
57 | case SND_TONE: | 97 | case SND_TONE: |
58 | hz *= 1000; /* fixed point */ | 98 | if (beep->linear_tone) |
59 | hz = hz - DIGBEEP_HZ_MIN; | 99 | beep->tone = beep_linear_tone(beep, hz); |
60 | if (hz < 0) | 100 | else |
61 | hz = 0; /* turn off PC beep*/ | 101 | beep->tone = beep_standard_tone(beep, hz); |
62 | else if (hz >= (DIGBEEP_HZ_MAX - DIGBEEP_HZ_MIN)) | ||
63 | hz = 0xff; | ||
64 | else { | ||
65 | hz /= DIGBEEP_HZ_STEP; | ||
66 | hz++; | ||
67 | } | ||
68 | break; | 102 | break; |
69 | default: | 103 | default: |
70 | return -1; | 104 | return -1; |
71 | } | 105 | } |
72 | beep->tone = hz; | ||
73 | 106 | ||
74 | /* schedule beep event */ | 107 | /* schedule beep event */ |
75 | schedule_work(&beep->beep_work); | 108 | schedule_work(&beep->beep_work); |
diff --git a/sound/pci/hda/hda_beep.h b/sound/pci/hda/hda_beep.h index 51bf6a5daf39..0c3de787c717 100644 --- a/sound/pci/hda/hda_beep.h +++ b/sound/pci/hda/hda_beep.h | |||
@@ -30,8 +30,9 @@ struct hda_beep { | |||
30 | struct hda_codec *codec; | 30 | struct hda_codec *codec; |
31 | char phys[32]; | 31 | char phys[32]; |
32 | int tone; | 32 | int tone; |
33 | int nid; | 33 | hda_nid_t nid; |
34 | int enabled; | 34 | unsigned int enabled:1; |
35 | unsigned int linear_tone:1; /* linear tone for IDT/STAC codec */ | ||
35 | struct work_struct beep_work; /* scheduled task for beep event */ | 36 | struct work_struct beep_work; /* scheduled task for beep event */ |
36 | }; | 37 | }; |
37 | 38 | ||
diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c index 02950980778e..17310814f121 100644 --- a/sound/pci/hda/patch_sigmatel.c +++ b/sound/pci/hda/patch_sigmatel.c | |||
@@ -3737,6 +3737,8 @@ static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out | |||
3737 | err = snd_hda_attach_beep_device(codec, nid); | 3737 | err = snd_hda_attach_beep_device(codec, nid); |
3738 | if (err < 0) | 3738 | if (err < 0) |
3739 | return err; | 3739 | return err; |
3740 | /* IDT/STAC codecs have linear beep tone parameter */ | ||
3741 | codec->beep->linear_tone = 1; | ||
3740 | /* if no beep switch is available, make its own one */ | 3742 | /* if no beep switch is available, make its own one */ |
3741 | caps = query_amp_caps(codec, nid, HDA_OUTPUT); | 3743 | caps = query_amp_caps(codec, nid, HDA_OUTPUT); |
3742 | if (codec->beep && | 3744 | if (codec->beep && |