AC97 powersave patch
Hi,
the below is an experimental patch to reduce slighly the power consumption of AC97 codecs at idle time. The DAC/ADC are turned on/off automatically on demand. With my laptop, it extended about 5 minutes of battery run time. It's not a big gain, but a few minutes may become critical in some situation ;)
If you have a laptop with intel8x0, via82xx or atiixp, please give it a try. (In theory, it may work with other drivers using ac97, too.) After applying the patch and reloading the driver, set
# echo 1 > /proc/asound/card0/codec97#0/ac97#0-0+power
The proc file name might be different depending on the codec id.
The drawback of this patch is that it may produce a pop noise at opening a sound device onsome machines.
Takashi
Index: alsa-kernel/include/ac97_codec.h
===================================================================
RCS file: /home/iwai/cvs/alsa/alsa-kernel/include/ac97_codec.h,v retrieving revision 1.74
include/ac97_codec.h +25 -0
@@ -27,6 +27,7 @@#include <linux/bitops.h> #include <linux/device.h> +#include <linux/workqueue.h> #include "pcm.h" #include "control.h" #include "info.h"
@@ -140,6 +141,20 @@#define AC97_GP_DRSS_1011 0x0000/* LR(C) 10+11(+12) */ #define AC97_GP_DRSS_78 0x0400/* LR 7+8 */ +/* powerdown bits */ +#define AC97_PD_ADC_STATUS 0x0001/* ADC status (RO) */ +#define AC97_PD_DAC_STATUS 0x0002/* DAC status (RO) */ +#define AC97_PD_MIXER_STATUS 0x0004/* Analog mixer status (RO) */ +#define AC97_PD_VREF_STATUS 0x0008/* Vref status (RO) */ +#define AC97_PD_PR0 0x0100/* Power down PCM ADCs and input MUX */ +#define AC97_PD_PR1 0x0200/* Power down PCM front DAC */ +#define AC97_PD_PR2 0x0400/* Power down Mixer (Vref still on) */ +#define AC97_PD_PR3 0x0800/* Power down Mixer (Vref off) */ +#define AC97_PD_PR4 0x1000/* Power down AC-Link */ +#define AC97_PD_PR5 0x2000/* Disable internal clock usage */ +#define AC97_PD_PR6 0x4000/* Headphone amplifier */ +#define AC97_PD_EAPD 0x8000/* External Amplifer Power Down (EAPD) */ +/* extended audio ID bit defines */ #define AC97_EI_VRA 0x0001/* Variable bit rate supported */ #define AC97_EI_DRA 0x0002/* Double rate supported */
@@ -358,6 +373,7 @@#define AC97_SCAP_INV_EAPD (1<<7)/* inverted EAPD */ #define AC97_SCAP_DETECT_BY_VENDOR (1<<8)/* use vendor registers for read tests */ #define AC97_SCAP_NO_SPDIF (1<<9)/* don't build SPDIF controls */ +#define AC97_SCAP_EAPD_LED (1<<10)/* EAPD as mute LED */ /* ac97->flags */ #define AC97_HAS_PC_BEEP (1<<0)/* force PC Speaker usage */
@@ -454,6 +470,7 @@struct pci_dev *pci;/* assigned PCI device - used for quirks */ struct snd_info_entry *proc;struct snd_info_entry *proc_regs; +struct snd_info_entry *proc_power;unsigned short subsystem_vendor;unsigned short subsystem_device;struct mutex reg_mutex;
@@ -484,6 +501,12 @@/* jack-sharing info */ unsigned char indep_surround;unsigned char channel_mode; + +unsigned char do_powersave;/* power-save mode flag */ +unsigned int power_up;/* power states */ +struct workqueue_struct *power_workq; +struct work_struct power_work; +struct device dev; };
@@ -525,6 +548,7 @@void snd_ac97_write_cache (struct snd_ac97 *ac97,unsigned short reg,unsigned short value);int snd_ac97_update (struct snd_ac97 *ac97,unsigned short reg,unsigned short value);int snd_ac97_update_bits (struct snd_ac97 *ac97,unsigned short reg,unsigned short mask,unsigned short value); +int snd_ac97_update_power (struct snd_ac97 *ac97,int reg,int powerup);#ifdef CONFIG_PM void snd_ac97_suspend (struct snd_ac97 *ac97);void snd_ac97_resume (struct snd_ac97 *ac97);
@@ -576,6 +600,7 @@ copy_flag:1 ,/* lowlevel driver must fill all entries */ spdif: 1; /* spdif pcm */unsigned short aslots;/* active slots */ +unsigned short cur_dbl;/* current double-rate state */ unsigned int rates;/* available rates */ struct {unsigned short slots;/* driver input: requested AC97 slot numbers */
Index: alsa-kernel/pci/intel8x0.c
===================================================================
RCS file: /home/iwai/cvs/alsa/alsa-kernel/pci/intel8x0.c,v retrieving revision 1.235
pci/intel8x0.c +1 -0
@@ -2593,6 +2593,7 @@/* not 48000Hz, tuning the clock.. */ chip->ac97_bus->clock = (chip->ac97_bus->clock *48000 ) / pos;printk (KERN_INFO "intel8x0: clocking to %d\n" , chip->ac97_bus->clock); +snd_ac97_update_power (chip->ac97[0 ],AC97_PCM_FRONT_DAC_RATE ,0 ); }#ifdef CONFIG_PROC_FS
Index: alsa-kernel/pci/via82xx.c
===================================================================
RCS file: /home/iwai/cvs/alsa/alsa-kernel/pci/via82xx.c,v retrieving revision 1.200
pci/via82xx.c +12 -1
@@ -1271,7 +1271,18 @@if (! ratep->used) ratep->rate =0 ;spin_unlock_irq (&ratep->lock); - +if (! ratep->rate) { +if (! viadev->direction) { +snd_ac97_update_power (chip->ac97, +AC97_PCM_FRONT_DAC_RATE ,0 ); +snd_ac97_update_power (chip->ac97, +AC97_PCM_SURR_DAC_RATE ,0 ); +snd_ac97_update_power (chip->ac97, +AC97_PCM_LFE_DAC_RATE ,0 ); + }else +snd_ac97_update_power (chip->ac97, +AC97_PCM_LR_ADC_RATE ,0 ); + } viadev->substream =NULL ;return 0 ; }
Index: alsa-kernel/pci/ac97/ac97_codec.c
===================================================================
RCS file: /home/iwai/cvs/alsa/alsa-kernel/pci/ac97/ac97_codec.c,v retrieving revision 1.200
pci/ac97/ac97_codec.c +160 -34
364 lines not on this page · raw message
Index: alsa-kernel/pci/ac97/ac97_pcm.c
===================================================================
RCS file: /home/iwai/cvs/alsa/alsa-kernel/pci/ac97/ac97_pcm.c,v retrieving revision 1.23
pci/ac97/ac97_pcm.c +16 -1
@@ -269,6 +269,7 @@return -EINVAL ; } +snd_ac97_update_power (ac97, reg,1 );switch (reg) {case AC97_PCM_MIC_ADC_RATE :if ((ac97->regs[AC97_EXTENDED_STATUS ] &AC97_EA_VRM ) ==0 )/* MIC VRA */
@@ -602,6 +603,7 @@ goto error; } } + pcm->cur_dbl = r;spin_unlock_irq (&pcm->bus->bus_lock);for (i =3 ; i <12 ; i++) {if (!(slots & (1 << i)))
@@ -643,7 +645,19 @@ {struct snd_ac97_bus *bus;unsigned short slots = pcm->aslots; -int i, cidx; +int i, r, cidx, reg; + + r = pcm->cur_dbl; +for (i =3 ; i <12 ; i++) { +if (!(slots & (1 << i))) +continue ; +for (cidx =0 ; cidx <4 ; cidx++) { +if (pcm->r[r].rslots[cidx] & (1 << i)) { + reg =get_slot_reg (pcm, cidx, i, r); +snd_ac97_update_power (pcm->r[r].codec[cidx], reg,0 ); + } + } + } bus = pcm->bus;spin_lock_irq (&pcm->bus->bus_lock);
@@ -654,6 +668,7 @@ bus->used_slots[pcm->stream][cidx] &= ~(1 << i); } pcm->aslots =0 ; + pcm->cur_dbl =0 ;spin_unlock_irq (&pcm->bus->bus_lock);return 0 ; }
Index: alsa-kernel/pci/ac97/ac97_proc.c
===================================================================
RCS file: /home/iwai/cvs/alsa/alsa-kernel/pci/ac97/ac97_proc.c,v retrieving revision 1.17
pci/ac97/ac97_proc.c +39 -0
@@ -422,6 +422,29 @@mutex_unlock (&ac97->page_mutex); } +static void snd_ac97_proc_power_read (struct snd_info_entry *entry, +struct snd_info_buffer *buffer) +{ +struct snd_ac97 *ac97 = entry->private_data; +snd_iprintf (buffer,"%d\n" , ac97->do_powersave); +} + +static void snd_ac97_proc_power_write (struct snd_info_entry *entry, +struct snd_info_buffer *buffer) +{ +struct snd_ac97 *ac97 = entry->private_data; +char line[16 ]; +int val; +if (snd_info_get_line (buffer, line,sizeof (line)) || +sscanf (line,"%d" , &val) !=1 ) +return ; + val = !!val; +if (val != ac97->do_powersave) { + ac97->do_powersave = val; +snd_ac97_update_power (ac97,0 ,0 ); + } +} +void snd_ac97_proc_init (struct snd_ac97 * ac97) {struct snd_info_entry *entry;
@@ -454,10 +477,26 @@ } } ac97->proc_regs = entry; +sprintf (name,"%s#%d-%d+power" , prefix, ac97->addr, ac97->num); +if ((entry =snd_info_create_card_entry (ac97->bus->card, name, ac97->bus->proc)) !=NULL ) { +snd_info_set_text_ops (entry, ac97,1024 , snd_ac97_proc_power_read); + entry->mode |=S_IWUSR ; + entry->c.text.write_size =1024 ; + entry->c.text.write = snd_ac97_proc_power_write; +if (snd_info_register (entry) <0 ) { +snd_info_free_entry (entry); + entry =NULL ; + } + } + ac97->proc_power = entry; }void snd_ac97_proc_done (struct snd_ac97 * ac97) { +if (ac97->proc_power) { +snd_info_unregister (ac97->proc_power); + ac97->proc_power =NULL ; + }if (ac97->proc_regs) {snd_info_unregister (ac97->proc_regs); ac97->proc_regs =NULL ;
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642