Skip to contentSkip to conversation

pmac mixer update from shadow register on resume and switching DRC on headphone plug

PATCH In review Rene Rebe 2 participants 2 messages Jul 30, 2004 – Aug 2, 2004

lore
Share & tools
lore

Rene Rebe

author
#0 lore raw

PATCH 1/1 pmac mixer update from shadow register on resume and switching DRC on headphone plug

Hi all,

the attached patch improved the pmac driver by implementing updating the mixer from the shadow register after a resume or headphone interrupt, as well as automatically selecting DRC on headphone plug.

For normal line-out one does not want the DRC, but it should automatically be reenabled after the headphone is unplugged: Otherwise the power to the internal speakers is high enought to destroy them (happend once to my iBook - when it still had warrenty ... ;-)

I needed a work-queue / task-queue since it can not be done in the interrupt context - this is done in the way the OSS driver does it, too. I hope this is acceptable.

Have fun,
René Rebe

tumbler.c renamed from tumbler.c~ +66 -13
@@ -16,6 +16,11 @@
  *   You should have received a copy of the GNU General Public License
  *   along with this program; if not, write to the Free Software
  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ *
+ *   Rene Rebe <[email protected]>:
+ *     * update from shadow registers on wakeup and headphone plug
+ *     * automatically toggle DRC on headphone plug
+ *	
  */
 
 
@@ -759,12 +764,6 @@
 	DEFINE_MONO("Tone Control - Treble", treble),
 	DEFINE_MONO("PCM Playback Volume", pcm),
 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
-	  .name = "DRC Switch",
-	  .info = snd_pmac_boolean_mono_info,
-	  .get = tumbler_get_drc_switch,
-	  .put = tumbler_put_drc_switch
-	},
-	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
 	  .name = "DRC Range",
 	  .info = tumbler_info_drc_value,
 	  .get = tumbler_get_drc_value,
@@ -791,12 +790,6 @@
 	DEFINE_SNAPPER_MONO("Tone Control - Bass", bass),
 	DEFINE_SNAPPER_MONO("Tone Control - Treble", treble),
 	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
-	  .name = "DRC Switch",
-	  .info = snd_pmac_boolean_mono_info,
-	  .get = tumbler_get_drc_switch,
-	  .put = tumbler_put_drc_switch
-	},
-	{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
 	  .name = "DRC Range",
 	  .info = tumbler_info_drc_value,
 	  .get = tumbler_get_drc_value,
@@ -826,6 +819,14 @@
 	.put = tumbler_put_mute_switch,
 	.private_value = TUMBLER_MUTE_AMP,
 };
+static snd_kcontrol_new_t tumbler_drc_sw __initdata = {
+	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+	.name = "DRC Switch",
+	.info = snd_pmac_boolean_mono_info,
+	.get = tumbler_get_drc_switch,
+	.put = tumbler_put_drc_switch
+};
+
 
 #ifdef PMAC_SUPPORT_AUTOMUTE
 /*
@@ -847,6 +848,33 @@
 	}
 }
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+static struct tq_struct device_change;
+#else
+static struct work_struct device_change;
+#endif
+
+static void
+device_change_handler(void *self)
+{
+	pmac_t *chip = (pmac_t*) self;
+	pmac_tumbler_t *mix;
+
+	if (!chip)
+		return;
+
+	mix = chip->mixer_data;
+
+	/* first set the DRC so the speaker do not explode */
+	if (chip->model == PMAC_TUMBLER)
+		tumbler_set_drc(mix);
+	else
+		snapper_set_drc(mix);
+
+	/* reset the master volume so the correct amplification is applied */
+	tumbler_set_master_volume(mix);
+}
+
 static void tumbler_update_automute(pmac_t *chip, int do_notify)
 {
 	if (chip->auto_mute) {
@@ -856,14 +889,29 @@
 			/* mute speaker */
 			check_mute(chip, &mix->amp_mute, 1, do_notify, chip->speaker_sw_ctl);
 			check_mute(chip, &mix->hp_mute, 0, do_notify, chip->master_sw_ctl);
+			mix->drc_enable = 0;
+
 		} else {
 			/* unmute speaker */
 			check_mute(chip, &mix->amp_mute, 0, do_notify, chip->speaker_sw_ctl);
 			check_mute(chip, &mix->hp_mute, 1, do_notify, chip->master_sw_ctl);
+			mix->drc_enable = 1;
 		}
-		if (do_notify)
+		if (do_notify) {
 			snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
 				       &chip->hp_detect_ctl->id);
+			snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
+			               &chip->drc_sw_ctl->id);
+		}
+
+		/* finally we need to schedule an update of the mixer values
+		   (master and DRC are enough for now) -ReneR */
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+		schedule_task(&device_change);
+#else
+		schedule_work(&device_change);
+#endif
+
 	}
 }
 #endif /* PMAC_SUPPORT_AUTOMUTE */
@@ -1114,11 +1163,21 @@
 	chip->speaker_sw_ctl = snd_ctl_new1(&tumbler_speaker_sw, chip);
 	if ((err = snd_ctl_add(chip->card, chip->speaker_sw_ctl)) < 0)
 		return err;
+	chip->drc_sw_ctl = snd_ctl_new1(&tumbler_drc_sw, chip);
+	if ((err = snd_ctl_add(chip->card, chip->drc_sw_ctl)) < 0)
+		return err;
+
 
 #ifdef CONFIG_PMAC_PBOOK
 	chip->resume = tumbler_resume;
 #endif
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
+	INIT_TQUEUE(&device_change, device_change_handler, (void *)chip);
+#else
+	INIT_WORK(&device_change, device_change_handler, (void *)chip);
+#endif
+
 #ifdef PMAC_SUPPORT_AUTOMUTE
 	if (mix->headphone_irq >=0 && (err = snd_pmac_add_automute(chip)) < 0)
 		return err;
#1 lore raw

At Fri, 30 Jul 2004 16:56:16 +0200,

Quoted 7 lines · Rene Rebe

Hi all,

the attached patch improved the pmac driver by implementing updating the mixer from the shadow register after a resume or headphone interrupt, as well as automatically selecting DRC on headphone plug.

Quoted 8 lines

For normal line-out one does not want the DRC, but it should automatically be reenabled after the headphone is unplugged: Otherwise the power to the internal speakers is high enought to destroy them (happend once to my iBook - when it still had warrenty ... ;-)

I needed a work-queue / task-queue since it can not be done in the interrupt context - this is done in the way the OSS driver does it, too. I hope this is acceptable.

That's fine, but we keep 2.6 clean from older kernel codes. The mixed code is the result after patch, which you can find in alsa-driver tree as *.patch file.

Could you make them separate, and send the patch to tumbler.c and the new tumber.patch?
i.e. alsa-kernel/ppc/tumbler.c contains 2.6-only code and the stuff within "#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)" is added by alsa-driver/ppc/tumbler.patch.

Takashi

-------------------------------------------------------
This SF.Net email is sponsored by OSTG. Have you noticed the changes on Linux.com, ITManagersJournal and NewsForge in the past few weeks? Now, one more big change to announce. We are now OSTG- Open Source Technology Group. Come see the changes on the new OSTG site. www.ostg.com