snd-aoa: add snd-aoa
Subsystems (2)
Johannes Berg
maintainercover snd-aoa: add snd-aoa
The following patches would add snd-aoa to the Linux source tree. I'm posting them here in the spirit of getting review fairly early, it works fine for those machines it handles but has some rough edges like not providing headphone detection at the moment.
There are plans to fix this, but they might be influenced by your comments so I'm holding off there a bit. One thing that will probably be done is moving all the alsa controls for various inputs from the codecs to the fabric, the fabric needs to know these anyway and code can be simplified and prepared for headphone/... detection if the codecs simply provide hooks to turn on/off the various in- and outputs.
Any comments are appreciated.
Thanks,
johannes
Johannes Berg
maintainerRFC 1/7 snd-aoa: add aoa header files
This patch adds header files to use for communication between the various parts of aoa.
sound/aoa/aoa-gpio.h new file +44 -0
@@ -0,0 +1,44 @@ +/* +* Apple Onboard Audio GPIO definitions +* +* Copyright 2006 Johannes Berg <[email protected]> +* +* GPL v2, can be found in COPYING. +*/ + +#ifndef __AOA_GPIO_H +#define __AOA_GPIO_H +#include <asm/prom.h> + +struct gpio_runtime ; +struct gpio_methods { +/* for initialisation/de-initialisation of the GPIO layer */ +void (*init)(struct gpio_runtime *rt); +void (*exit)(struct gpio_runtime *rt); + +/* turn off headphone, speakers, lineout */ +void (*all_amps_off)(struct gpio_runtime *rt); +/* turn headphone, speakers, lineout back to previous setting */ +void (*all_amps_restore)(struct gpio_runtime *rt); + +void (*set_headphone)(struct gpio_runtime *rt,int on); +void (*set_speakers)(struct gpio_runtime *rt,int on); +void (*set_lineout)(struct gpio_runtime *rt,int on); + +int (*get_headphone)(struct gpio_runtime *rt); +int (*get_speakers)(struct gpio_runtime *rt); +int (*get_lineout)(struct gpio_runtime *rt); + +void (*set_hw_reset)(struct gpio_runtime *rt,int on); +}; + +struct gpio_runtime { +/* to be assigned by fabric */ +struct device_node *node; +/* since everyone needs this pointer anyway... */ +struct gpio_methods *methods; +/* to be used by the gpio implementation */ +int implementation_private; +}; + +#endif /* __AOA_GPIO_H */
sound/aoa/aoa.h new file +130 -0
130 lines not on this page · raw message
--
Johannes Berg
maintainerRFC 2/7 snd-aoa: add aoa core
In reply to Johannes BergThis patch adds the core of aoa, in itself pretty useless, but providing useful functions to other modules.
sound/aoa/core/Makefile new file +4 -0
@@ -0,0 +1,4 @@ +obj-$(CONFIG_SND_AOA) += snd-aoa.o +snd-aoa-objs := snd-aoa-core.o \ + snd-aoa-alsa.o \ + snd-aoa-gpio-pmf.o
sound/aoa/core/snd-aoa-alsa.c new file +91 -0
91 lines not on this page · raw message
sound/aoa/core/snd-aoa-alsa.h new file +17 -0
@@ -0,0 +1,17 @@ +/* +* Apple Onboard Audio Alsa private helpers +* +* Copyright 2006 Johannes Berg <[email protected]> +* +* GPL v2, can be found in COPYING. +*/ + +#ifndef __SND_AOA_ALSA_H +#define __SND_AOA_ALSA_H +/* FIXME */ +#include "../aoa.h" + +extern int aoa_alsa_init (char *name,struct module *mod); +extern void aoa_alsa_cleanup (void ); + +#endif /* __SND_AOA_ALSA_H */
sound/aoa/core/snd-aoa-core.c new file +153 -0
153 lines not on this page · raw message
sound/aoa/core/snd-aoa-gpio-pmf.c new file +91 -0
91 lines not on this page · raw message
--
Re: [RFC 2/7] snd-aoa: add aoa core
At Sun, 28 May 2006 21:00:28 +0200,
Quoted 15 lines · Johannes Berg
sound/aoa/core/snd-aoa-alsa.c new file +12
-0@@ -0,0 +1,91 @@ +/* +* Apple Onboard Audio Alsa helpers +* +* Copyright 2006 Johannes Berg <[email protected]> +* +* GPL v2, can be found in COPYING. +*/ +#include <linux/module.h> +#include "snd-aoa-alsa.h" + +static struct aoa_card *aoa_card; +
sound/aoa/core/snd-aoa-alsa.c line 22
Quoted 10 lines
sound/aoa/core/snd-aoa-alsa.c new file +10
-0+int aoa_alsa_init (char *name,struct module *mod) +{ +struct snd_card *alsa_card; +int err; + +if (aoa_card) +/* cannot be EEXIST due to usage in aoa_fabric_register */ +return -EBUSY ; + + alsa_card =snd_card_new (-1 , name, mod,sizeof (struct aoa_card ));
Usually the first argument here is the index module option so that user may specify the card order (e.g. secondary card) independent from the order of module loading.
sound/aoa/core/snd-aoa-alsa.c line 30
Quoted 8 lines
sound/aoa/core/snd-aoa-alsa.c new file +8
-0+if (!alsa_card) +return -ENOMEM ; + aoa_card = alsa_card->private_data; + aoa_card->alsa_card = alsa_card; +strncpy (alsa_card->driver,"AppleOnbdAudio" ,sizeof (alsa_card->driver)); +strncpy (alsa_card->shortname, name,sizeof (alsa_card->shortname)); +strncpy (alsa_card->longname, name,sizeof (alsa_card->longname)); +strncpy (alsa_card->mixername, name,sizeof (alsa_card->mixername));
strlcpy is safer. Also, longname usually contains more verbose info.
Quoted 2 lines
sound/aoa/core/snd-aoa-core.c new file +0
-0
(snip)
sound/aoa/core/snd-aoa-core.c line 96
Quoted 4 lines
sound/aoa/core/snd-aoa-core.c new file +4
-0+ err =aoa_alsa_init (new_fabric->name, new_fabric->owner); +if (err) { +return err; + }
Remove braces.
Takashi
Johannes Berg
maintainerRe: [RFC 2/7] snd-aoa: add aoa core
Quoted 5 lines · Takashi Iwai
sound/aoa/core/snd-aoa-alsa.c line 22
Quoted 1 line
sound/aoa/core/snd-aoa-alsa.c new file +1
-0+ alsa_card =snd_card_new (-1 , name, mod,sizeof (struct aoa_card ));Usually the first argument here is the index module option so that user may specify the card order (e.g. secondary card) independent from the order of module loading.
Are you saying I should add an index module option and pass that?
johannes
_______________________________________________
Alsa-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/alsa-devel
Johannes Berg
maintainerRe: [Alsa-devel] [RFC 2/7] snd-aoa: add aoa core
In reply to Takashi IwaiQuoted 5 lines · Takashi Iwai
sound/aoa/core/snd-aoa-alsa.c line 22
Quoted 1 line
sound/aoa/core/snd-aoa-alsa.c new file +1
-0+ alsa_card =snd_card_new (-1 , name, mod,sizeof (struct aoa_card ));Usually the first argument here is the index module option so that user may specify the card order (e.g. secondary card) independent from the order of module loading.
Are you saying I should add an index module option and pass that?
johannes
Re: [RFC 2/7] snd-aoa: add aoa core
At Tue, 30 May 2006 14:44:31 +0200,
Quoted 9 lines · Johannes Berg
Quoted 5 lines · Takashi Iwai
sound/aoa/core/snd-aoa-alsa.c line 22
Quoted 1 line
sound/aoa/core/snd-aoa-alsa.c new file +1
-0+ alsa_card =snd_card_new (-1 , name, mod,sizeof (struct aoa_card ));Usually the first argument here is the index module option so that user may specify the card order (e.g. secondary card) independent from the order of module loading.
Are you saying I should add an index module option and pass that?
Yep, all other drivers do so.
Takashi
Johannes Berg
maintainerRFC 3/7 snd-aoa: add soundbus and i2sbus
In reply to Johannes BergThis patch adds the mostly generic soundbus that will be used for older things (davbus comes to mind) as well as adding i2sbus, the module handling the i2s bus on Apple mac-io chips.
sound/aoa/soundbus/Kconfig new file +14 -0
@@ -0,0 +1,14 @@ +config SND_AOA_SOUNDBUS + tristate "Apple Soundbus support" + depends on SOUND && SND_PCM && EXPERIMENTAL + ---help--- + This option enables the generic driver for the soundbus + support on Apple machines. + + It is required for the sound bus implementations. + +config SND_AOA_SOUNDBUS_I2S + tristate "I2S bus support" + depends on SND_AOA_SOUNDBUS && PCI + ---help--- + This option enables support for Apple I2S busses.
sound/aoa/soundbus/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +obj-$(CONFIG_SND_AOA_SOUNDBUS) += snd-aoa-soundbus.o +snd-aoa-soundbus-objs := core.o sysfs.o +obj-$(CONFIG_SND_AOA_SOUNDBUS_I2S) += i2sbus/
sound/aoa/soundbus/core.c new file +250 -0
250 lines not on this page · raw message
sound/aoa/soundbus/i2sbus/Makefile new file +2 -0
@@ -0,0 +1,2 @@ +obj-$(CONFIG_SND_AOA_SOUNDBUS_I2S) += snd-aoa-i2sbus.o +snd-aoa-i2sbus-objs := i2sbus-core.o i2sbus-pcm.o i2sbus-control.o
sound/aoa/soundbus/i2sbus/i2sbus-control.c new file +213 -0
213 lines not on this page · raw message
sound/aoa/soundbus/i2sbus/i2sbus-control.h new file +37 -0
@@ -0,0 +1,37 @@ +/* +* i2sbus driver -- bus register definitions +* +* Copyright 2006 Johannes Berg <[email protected]> +* +* GPL v2, can be found in COPYING. +*/ +#ifndef __I2SBUS_CONTROLREGS_H +#define __I2SBUS_CONTROLREGS_H + +/* i2s control registers, at least what we know about them */ + +#define __PAD (m,n) u8 __pad##m[n] +#define _PAD (line, n) __PAD(line, n) +#define PAD (n) _PAD(__LINE__, (n)) +struct i2s_control_regs { + PAD(0x38); +__le32 fcr0;/* 0x38 (unknown) */ +__le32 cell_control;/* 0x3c (fcr1) */ +__le32 fcr2;/* 0x40 (unknown) */ +__le32 fcr3;/* 0x44 (fcr3) */ +__le32 clock_control;/* 0x48 (unknown) */ + PAD(4); +/* total size: 0x50 bytes */ +} __attribute__((__packed__ )); + +#define CTRL_CLOCK_CELL_0_ENABLE (1<<10) +#define CTRL_CLOCK_CLOCK_0_ENABLE (1<<12) +#define CTRL_CLOCK_SWRESET_0 (1<<11) +#define CTRL_CLOCK_INTF_0_ENABLE (1<<13) + +#define CTRL_CLOCK_CELL_1_ENABLE (1<<17) +#define CTRL_CLOCK_CLOCK_1_ENABLE (1<<18) +#define CTRL_CLOCK_SWRESET_1 (1<<19) +#define CTRL_CLOCK_INTF_1_ENABLE (1<<20) + +#endif /* __I2SBUS_CONTROLREGS_H */
sound/aoa/soundbus/i2sbus/i2sbus-core.c new file +370 -0
370 lines not on this page · raw message
sound/aoa/soundbus/i2sbus/i2sbus-interface.h new file +187 -0
187 lines not on this page · raw message
sound/aoa/soundbus/i2sbus/i2sbus-pcm.c new file +1008 -0
1,008 lines not on this page · raw message
sound/aoa/soundbus/i2sbus/i2sbus.h new file +115 -0
115 lines not on this page · raw message
sound/aoa/soundbus/soundbus.h new file +202 -0
202 lines not on this page · raw message
sound/aoa/soundbus/sysfs.c new file +67 -0
67 lines not on this page · raw message
--
Johannes Berg
maintainerRFC 4/7 snd-aoa: add codecs
In reply to Johannes BergThis patch adds two of the most important codecs Apple uses in newer machines, namely the Onyx and the tas3004.
sound/aoa/codecs/Kconfig new file +24 -0
@@ -0,0 +1,24 @@ +config SND_AOA_ONYX + tristate "support Onyx chip" + depends on SND_AOA + ---help--- + This option enables support for the Onyx (pcm3052) + codec chip found in the latest Apple machines + (most of those with digital audio output). + +#config SND_AOA_TOPAZ +# tristate "support Topaz chips" +# depends on SND_AOA +# ---help--- +# This option enables support for the Topaz (CS84xx) +# codec chips found in the latest Apple machines, +# these chips do the digital input and output on +# some PowerMacs. + +config SND_AOA_TAS + tristate "support TAS chips" + depends on SND_AOA + ---help--- + This option enables support for the tas chips + found in a lot of Apple Machines, especially + iBooks and PowerBooks without digital.
sound/aoa/codecs/Makefile new file +2 -0
@@ -0,0 +1,2 @@ +obj-$(CONFIG_SND_AOA_ONYX) += snd-aoa-codec-onyx.o +obj-$(CONFIG_SND_AOA_TAS) += snd-aoa-codec-tas.o
sound/aoa/codecs/snd-aoa-codec-onyx.c new file +1069 -0
1,069 lines not on this page · raw message
sound/aoa/codecs/snd-aoa-codec-onyx.h new file +76 -0
76 lines not on this page · raw message
sound/aoa/codecs/snd-aoa-codec-tas-gain-table.h new file +209 -0
209 lines not on this page · raw message
sound/aoa/codecs/snd-aoa-codec-tas.c new file +669 -0
669 lines not on this page · raw message
sound/aoa/codecs/snd-aoa-codec-tas.h new file +47 -0
47 lines not on this page · raw message
--
Re: [RFC 4/7] snd-aoa: add codecs
At Sun, 28 May 2006 21:00:30 +0200,
Quoted 6 lines · Johannes Berg
sound/aoa/codecs/snd-aoa-codec-onyx.c new file +4
-0+/* both return 0 if all ok, else on error */ +static int onyx_read_register (struct onyx *onyx,u8 reg,u8 *value) +{ +s32 v;
sound/aoa/codecs/snd-aoa-codec-onyx.c line 80
Quoted 10 lines
sound/aoa/codecs/snd-aoa-codec-onyx.c new file +10
-0+ +if (reg !=ONYX_REG_CONTROL ) { + *value = onyx->cache[reg-FIRSTREGISTER ]; +return 0 ; + } + v =i2c_smbus_read_byte_data (&onyx->i2c, reg); +if (v <0 ) +return -1 ; + *value = (u8 )v; + onyx->cache[ONYX_REG_CONTROL -FIRSTREGISTER ] = *value;
Isn't it "reg - FIRSTREGISTER" ?
Quoted 21 lines
sound/aoa/codecs/snd-aoa-codec-onyx.c new file +21
-0+return 0 ; +} + +static int onyx_write_register (struct onyx *onyx,u8 reg,u8 value) +{ +int result; + + result =i2c_smbus_write_byte_data (&onyx->i2c, reg, value); +if (!result) + onyx->cache[reg-FIRSTREGISTER ] = value; +return result; +} + +/* alsa stuff */ + +static int onyx_dev_register (struct snd_device *dev) +{ +return 0 ; +} + +static struct snd_device_ops ops = {
sound/aoa/codecs/snd-aoa-codec-onyx.c line 111
Quoted 10 lines
sound/aoa/codecs/snd-aoa-codec-onyx.c new file +10
-0+ .dev_register = onyx_dev_register, +}; + +static int onyx_snd_vol_info (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_info *uinfo) +{ + uinfo->type =SNDRV_CTL_ELEM_TYPE_INTEGER ; + uinfo->count =2 ; + uinfo->value.integer.min =-128 +128 ; + uinfo->value.integer.max =-1 +128 ;
I'd define a constant for 128.
Quoted 18 lines
sound/aoa/codecs/snd-aoa-codec-onyx.c new file +18
-0+return 0 ; +} + +static int onyx_snd_vol_get (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol) +{ +struct onyx *onyx =snd_kcontrol_chip (kcontrol); +s8 l,r; + +mutex_lock (&onyx->mutex); +onyx_read_register (onyx,ONYX_REG_DAC_ATTEN_LEFT , &l); +onyx_read_register (onyx,ONYX_REG_DAC_ATTEN_RIGHT , &r); +mutex_unlock (&onyx->mutex); + + ucontrol->value.integer.value[0 ] = l+128 ; + ucontrol->value.integer.value[1 ] = r+128 ; + +return 0 ;
sound/aoa/codecs/snd-aoa-codec-onyx.c line 139
Quoted 10 lines
sound/aoa/codecs/snd-aoa-codec-onyx.c new file +10
-0+} + +static int onyx_snd_vol_put (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol) +{ +struct onyx *onyx =snd_kcontrol_chip (kcontrol); + +mutex_lock (&onyx->mutex); +onyx_write_register (onyx,ONYX_REG_DAC_ATTEN_LEFT , ucontrol->value.integer.value[0 ]-128 ); +onyx_write_register (onyx,ONYX_REG_DAC_ATTEN_RIGHT , ucontrol->value.integer.value[1 ]-128 );
Fold lines to fit with 80 columns (heh, blaming other one's code is easy :)
sound/aoa/codecs/snd-aoa-codec-onyx.c line 143
Quoted 4 lines
sound/aoa/codecs/snd-aoa-codec-onyx.c new file +4
-0+/* FIXME: we could be checking if anything changed */ +mutex_unlock (&onyx->mutex); + +return 1 ;
The put callback is supposed to return 0 if the values are unchanged (although most apps ignore the return value).
(snip)
Quoted 7 lines
sound/aoa/codecs/snd-aoa-codec-onyx.c new file +7
-0+static u8 register_map[] = { +ONYX_REG_DAC_ATTEN_LEFT , +ONYX_REG_DAC_ATTEN_RIGHT , +ONYX_REG_CONTROL , +ONYX_REG_DAC_CONTROL , +ONYX_REG_DAC_DEEMPH , +ONYX_REG_DAC_FILTER ,
sound/aoa/codecs/snd-aoa-codec-onyx.c line 549
Quoted 10 lines
sound/aoa/codecs/snd-aoa-codec-onyx.c new file +10
-0+ONYX_REG_DAC_OUTPHASE , +ONYX_REG_ADC_CONTROL , +ONYX_REG_ADC_HPF_BYPASS , +ONYX_REG_DIG_INFO1 , +ONYX_REG_DIG_INFO2 , +ONYX_REG_DIG_INFO3 , +ONYX_REG_DIG_INFO4 +}; + +static u8 initial_values[] = {
Should have ARRAY_SIZE(register_map) since this size must be identical with register_map.
Quoted 38 lines
sound/aoa/codecs/snd-aoa-codec-onyx.c new file +38
-0+0x80 ,0x80 ,/* muted */ +ONYX_MRST |ONYX_SRST ,/* but handled specially! */ +ONYX_MUTE_LEFT |ONYX_MUTE_RIGHT , +0 ,/* no deemphasis */ +ONYX_DAC_FILTER_ALWAYS , +ONYX_OUTPHASE_INVERTED , + (-1 /*dB*/ +8 ) &0xF ,/* line in selected, -1 dB gain*/ +ONYX_ADC_HPF_ALWAYS , + (1 <<2 ),/* pcm audio */ +2 ,/* category: pcm coder */ +0 ,/* sampling frequency 44.1 kHz, clock accuracy level II */ +1 /* 24 bit depth */ +}; + +/* reset registers of chip, either to initial or to previous values */ +static int onyx_register_init (struct onyx *onyx) +{ +int i; +u8 val; +u8 regs[sizeof (initial_values)]; + +if (!onyx->initialised) { +memcpy (regs, initial_values,sizeof (initial_values)); +if (onyx_read_register (onyx,ONYX_REG_CONTROL , &val)) +return -1 ; + val &= ~ONYX_SILICONVERSION ; + val |= initial_values[3 ]; + regs[3 ] = val; + }else { +for (i=0 ; i<sizeof (register_map); i++) + regs[i] = onyx->cache[register_map[i]-FIRSTREGISTER ]; + } + +for (i=0 ; i<sizeof (register_map); i++) { +if (onyx_write_register (onyx, register_map[i], regs[i])) +return -1 ; + } + onyx->initialised =1 ;
sound/aoa/codecs/snd-aoa-codec-onyx.c line 597
Quoted 10 lines
sound/aoa/codecs/snd-aoa-codec-onyx.c new file +10
-0+return 0 ; +} + +static struct transfer_info onyx_transfers[] = { +/* this is first so we can skip it if no input is present... +* No hardware exists with that, but it's here as an example +* of what to do :) */ + { +/* analog input */ + .formats =SNDRV_PCM_FMTBIT_S8 |SNDRV_PCM_FMTBIT_S16_BE |SNDRV_PCM_FMTBIT_S24_BE ,
Too long lines ;)
(snip)
sound/aoa/codecs/snd-aoa-codec-onyx.c line 893
Quoted 13 lines
sound/aoa/codecs/snd-aoa-codec-onyx.c new file +13
-0+if (onyx->codec.soundbus_dev->attach_codec (onyx->codec.soundbus_dev, +aoa_get_card (), + ci, onyx)) { + printk(KERN_ERR PFX "error creating onyx pcm\n"); +return -ENODEV ; + } +#define ADDCTL (n) \ + do { \ + ctl = snd_ctl_new1(&n, onyx); \ + if (ctl) { \ + ctl->id.device = \ + onyx->codec.soundbus_dev->pcm->device; \ + aoa_snd_ctl_add(ctl); \
No error check?
sound/aoa/codecs/snd-aoa-codec-onyx.c line 983
Quoted 9 lines
sound/aoa/codecs/snd-aoa-codec-onyx.c new file +9
-0+/* we try to read from register ONYX_REG_CONTROL +* to check if the codec is present */ +if (onyx_read_register (onyx,ONYX_REG_CONTROL , &dummy) !=0 ) { +i2c_detach_client (&onyx->i2c); + printk(KERN_ERR PFX "failed to read control register\n"); + goto fail; + } + +strncpy (onyx->codec.name,"onyx" ,MAX_CODEC_NAME_LEN );
Use strlcpy, or MAX_CODEC_NAME_LEN-1. Similar lines are found in tas driver too.
Quoted 3 lines
sound/aoa/codecs/snd-aoa-codec-tas.c new file +0
-0@@ -0,0 +1,669 @@
(snip)
Quoted 16 lines
sound/aoa/codecs/snd-aoa-codec-tas.c new file +16
-0+struct tas { +u32 primary_magic; +struct aoa_codec codec; +/* see comment at top of file */ +u32 secondary_magic; +struct aoa_codec secondary; +struct i2c_client i2c; +u32 muted_l:1 , muted_r:1 , + controls_created:1 ; +u8 cached_volume_l, cached_volume_r; +u8 mixer_l[3 ], mixer_r[3 ]; +u8 acr; +}; + +static struct tas *codec_to_tas (struct aoa_codec *codec) +{
sound/aoa/codecs/snd-aoa-codec-tas.c line 112
Quoted 10 lines
sound/aoa/codecs/snd-aoa-codec-tas.c new file +10
-0+u32 *tmp = (u32 *)codec; +switch (*(tmp-1 )) { +case TAS_PRIMARY_MAGIC : + return container_of(codec, struct tas, codec); +case TAS_SECONDARY_MAGIC : + return container_of(codec, struct tas, secondary); +default : +return NULL ; + } +}
Looks a bit too hacky. IMO, it's better to define a struct
struct tas_codec {
struct aoa_codec codec;
struct tas *tas;
}to make the above simpler like:
static struct tas *codec_to_tas(struct aoa_codec *codec)
{
return ((struct tas_codec *)codec)->tas;
}The tas struct becomes:
struct as {
struct tas_codec primary;
struct tas_codec secondary;
...
}and is initialized like:
tas->primary.tas = tas; tas->secondary.tas = tas;
sound/aoa/codecs/snd-aoa-codec-tas.c line 325
Quoted 4 lines
sound/aoa/codecs/snd-aoa-codec-tas.c new file +4
-0+static int tas_snd_capture_source_info (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_info *uinfo) +{ +static char * texts[] = {"Line-In" ,"Microphone" };
char *texts[]
Quoted 18 lines
sound/aoa/codecs/snd-aoa-codec-tas.c new file +18
-0+static int tas_reset_init (struct tas *tas) +{ +u8 tmp; +/* +char write[8]; +union i2c_smbus_data read = { 0 }; +int r1, r2; +*/ + tas->codec.gpio->methods->set_hw_reset (tas->codec.gpio,0 ); +msleep (1 ); + tas->codec.gpio->methods->set_hw_reset (tas->codec.gpio,1 ); +msleep (1 ); + tas->codec.gpio->methods->set_hw_reset (tas->codec.gpio,0 ); +msleep (1 ); + + tas->acr &= ~TAS_ACR_ANALOG_PDOWN ; + tas->acr |=TAS_ACR_B_MONAUREAL |TAS_ACR_B_MON_SEL_RIGHT ; +if (tas_write_reg (tas,TAS_REG_ACR ,1 , &tas->acr))
sound/aoa/codecs/snd-aoa-codec-tas.c line 430
Quoted 10 lines
sound/aoa/codecs/snd-aoa-codec-tas.c new file +10
-0+return -ENODEV ; + + tmp =TAS_MCS_SCLK64 |TAS_MCS_SPORT_MODE_I2S |TAS_MCS_SPORT_WL_24BIT ; +if (tas_write_reg (tas,TAS_REG_MCS ,1 , &tmp)) +return -ENODEV ; + + tmp =0 ; +if (tas_write_reg (tas,TAS_REG_MCS2 ,1 , &tmp)) +return -ENODEV ; +/* I need help here!
Use ifdef. Nested comments are bad.
Quoted 31 lines
sound/aoa/codecs/snd-aoa-codec-tas.c new file +31
-0+/* This is a bit tricky, but serves to detect if there really +* is a tas codec present. +* First, we set the volume register to 00,00,01 (on both channels). +* This is almost muted. Then, we read back the last 6 bytes we +* wrote to the chip, and check if they are the same. +* +write[0] = 7; +write[1] = TAS_REG_VOL; +write[2] = write[3] = 0; +write[4] = 1; +write[5] = write[6] = 0; +write[7] = 1; +r1 = tas_write_reg(tas, TAS_REG_VOL, 6, &write[1]); +/* Hmm, how am I supposed to do the i2c sequence that +* is mentioned on page 45 of the tas3004 datasheet? +* This doesn't cut it: * +read.block[0] = 7; +r2 = i2c_smbus_xfer(tas->i2c.adapter, tas->i2c.addr, tas->i2c.flags, +I2C_SMBUS_READ, TAS_REG_VOL, +I2C_SMBUS_BLOCK_DATA, &read); + +printk(KERN_DEBUG "r1 = %d, r2 = %d, read=%x %x %x %x %x %x %x %x\n", r1, r2, read.block[0], read.block[1], read.block[2], read.block[3], read.block[4], read.block[5], read.block[6], read.block[7]); + +if (r1 || r2 || memcmp(write, read.block, 8)) +return -ENODEV; +*/ + +return 0 ; +} +static int tas_init_codec (struct aoa_codec *codec) +{
(snip)
sound/aoa/codecs/snd-aoa-codec-tas.c line 534
Quoted 1 line
sound/aoa/codecs/snd-aoa-codec-tas.c new file +1
-0+aoa_snd_ctl_add (snd_ctl_new1 (&volume_control, tas));
Error checks please.
Takashi
Johannes Berg
maintainerRe: [RFC 4/7] snd-aoa: add codecs
Quoted 11 lines · Takashi Iwai
sound/aoa/codecs/snd-aoa-codec-onyx.c line 80
Quoted 9 lines
sound/aoa/codecs/snd-aoa-codec-onyx.c new file +9
-0+if (reg !=ONYX_REG_CONTROL ) { + *value = onyx->cache[reg-FIRSTREGISTER ]; +return 0 ; + } + v =i2c_smbus_read_byte_data (&onyx->i2c, reg); +if (v <0 ) +return -1 ; + *value = (u8 )v; + onyx->cache[ONYX_REG_CONTROL -FIRSTREGISTER ] = *value;Isn't it "reg - FIRSTREGISTER" ?
Nah, look at the first line I quoted :)
Quoted 1 line
I'd define a constant for 128.
#define OFFSET_BECAUSE_ALSA_USERSPACE_PROGRAMS_SUCK 128 ;)
Just kidding, will do.
Quoted 2 lines
Fold lines to fit with 80 columns (heh, blaming other one's code is easy :)
Heh. I thought I'd Lindent'ed most of it.
Quoted 7 lines
sound/aoa/codecs/snd-aoa-codec-onyx.c line 143
Quoted 4 lines
sound/aoa/codecs/snd-aoa-codec-onyx.c new file +4
-0+/* FIXME: we could be checking if anything changed */ +mutex_unlock (&onyx->mutex); + +return 1 ;The put callback is supposed to return 0 if the values are unchanged (although most apps ignore the return value).
Does it have to? This way there's an event, but...
Quoted 4 lines
Quoted 1 line
+static u8 initial_values[] = {
Should have
ARRAY_SIZE(register_map)since this size must be identical withregister_map.
Good point.
Quoted 9 lines
sound/aoa/codecs/snd-aoa-codec-onyx.c line 893
Quoted 7 lines
sound/aoa/codecs/snd-aoa-codec-onyx.c new file +7
-0+#define ADDCTL (n) \ + do { \ + ctl = snd_ctl_new1(&n, onyx); \ + if (ctl) { \ + ctl->id.device = \ + onyx->codec.soundbus_dev->pcm->device; \ + aoa_snd_ctl_add(ctl); \No error check?
Hmm, yeah, I guess it should have error checks. Will revisit that.
Quoted 2 lines
Use strlcpy, or MAX_CODEC_NAME_LEN-1. Similar lines are found in tas driver too.
Right.
Quoted 1 line
Looks a bit too hacky. IMO, it's better to define a struct
Maybe I'll just get rid of it completely, it's never hooked up as far as I know. But yeah, I guess you're right.
Quoted 6 lines
sound/aoa/codecs/snd-aoa-codec-tas.c line 325
Quoted 4 lines
sound/aoa/codecs/snd-aoa-codec-tas.c new file +4
-0+static int tas_snd_capture_source_info (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_info *uinfo) +{ +static char * texts[] = {"Line-In" ,"Microphone" };char *texts[]
Any particular reason?
Quoted 3 lines
Quoted 1 line
+/* I need help here!
Use ifdef. Nested comments are bad.
I know. Temporary code, probably going away completely.
Quoted 3 lines
sound/aoa/codecs/snd-aoa-codec-tas.c line 534
Quoted 1 line
sound/aoa/codecs/snd-aoa-codec-tas.c new file +1
-0+aoa_snd_ctl_add (snd_ctl_new1 (&volume_control, tas));Error checks please.
What should it do on such errors?
Thanks,
johannes
_______________________________________________
Alsa-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/alsa-devel
Johannes Berg
maintainerRe: [Alsa-devel] [RFC 4/7] snd-aoa: add codecs
In reply to Takashi IwaiQuoted 11 lines · Takashi Iwai
sound/aoa/codecs/snd-aoa-codec-onyx.c line 80
Quoted 9 lines
sound/aoa/codecs/snd-aoa-codec-onyx.c new file +9
-0+if (reg !=ONYX_REG_CONTROL ) { + *value = onyx->cache[reg-FIRSTREGISTER ]; +return 0 ; + } + v =i2c_smbus_read_byte_data (&onyx->i2c, reg); +if (v <0 ) +return -1 ; + *value = (u8 )v; + onyx->cache[ONYX_REG_CONTROL -FIRSTREGISTER ] = *value;Isn't it "reg - FIRSTREGISTER" ?
Nah, look at the first line I quoted :)
Quoted 1 line
I'd define a constant for 128.
#define OFFSET_BECAUSE_ALSA_USERSPACE_PROGRAMS_SUCK 128 ;)
Just kidding, will do.
Quoted 2 lines
Fold lines to fit with 80 columns (heh, blaming other one's code is easy :)
Heh. I thought I'd Lindent'ed most of it.
Quoted 7 lines
sound/aoa/codecs/snd-aoa-codec-onyx.c line 143
Quoted 4 lines
sound/aoa/codecs/snd-aoa-codec-onyx.c new file +4
-0+/* FIXME: we could be checking if anything changed */ +mutex_unlock (&onyx->mutex); + +return 1 ;The put callback is supposed to return 0 if the values are unchanged (although most apps ignore the return value).
Does it have to? This way there's an event, but...
Quoted 4 lines
Quoted 1 line
+static u8 initial_values[] = {
Should have
ARRAY_SIZE(register_map)since this size must be identical withregister_map.
Good point.
Quoted 9 lines
sound/aoa/codecs/snd-aoa-codec-onyx.c line 893
Quoted 7 lines
sound/aoa/codecs/snd-aoa-codec-onyx.c new file +7
-0+#define ADDCTL (n) \ + do { \ + ctl = snd_ctl_new1(&n, onyx); \ + if (ctl) { \ + ctl->id.device = \ + onyx->codec.soundbus_dev->pcm->device; \ + aoa_snd_ctl_add(ctl); \No error check?
Hmm, yeah, I guess it should have error checks. Will revisit that.
Quoted 2 lines
Use strlcpy, or MAX_CODEC_NAME_LEN-1. Similar lines are found in tas driver too.
Right.
Quoted 1 line
Looks a bit too hacky. IMO, it's better to define a struct
Maybe I'll just get rid of it completely, it's never hooked up as far as I know. But yeah, I guess you're right.
Quoted 6 lines
sound/aoa/codecs/snd-aoa-codec-tas.c line 325
Quoted 4 lines
sound/aoa/codecs/snd-aoa-codec-tas.c new file +4
-0+static int tas_snd_capture_source_info (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_info *uinfo) +{ +static char * texts[] = {"Line-In" ,"Microphone" };char *texts[]
Any particular reason?
Quoted 3 lines
Quoted 1 line
+/* I need help here!
Use ifdef. Nested comments are bad.
I know. Temporary code, probably going away completely.
Quoted 3 lines
sound/aoa/codecs/snd-aoa-codec-tas.c line 534
Quoted 1 line
sound/aoa/codecs/snd-aoa-codec-tas.c new file +1
-0+aoa_snd_ctl_add (snd_ctl_new1 (&volume_control, tas));Error checks please.
What should it do on such errors?
Thanks,
johannes
Re: [RFC 4/7] snd-aoa: add codecs
At Tue, 30 May 2006 14:43:16 +0200,
Quoted 14 lines · Johannes Berg
Quoted 11 lines · Takashi Iwai
sound/aoa/codecs/snd-aoa-codec-onyx.c line 80
Quoted 9 lines
sound/aoa/codecs/snd-aoa-codec-onyx.c new file +9
-0+if (reg !=ONYX_REG_CONTROL ) { + *value = onyx->cache[reg-FIRSTREGISTER ]; +return 0 ; + } + v =i2c_smbus_read_byte_data (&onyx->i2c, reg); +if (v <0 ) +return -1 ; + *value = (u8 )v; + onyx->cache[ONYX_REG_CONTROL -FIRSTREGISTER ] = *value;Isn't it "reg - FIRSTREGISTER" ?
Quoted 1 line
Nah, look at the first line I quoted :)
Ah, OK it's anyway same...
Quoted 9 lines
Quoted 7 lines
sound/aoa/codecs/snd-aoa-codec-onyx.c line 143
Quoted 4 lines
sound/aoa/codecs/snd-aoa-codec-onyx.c new file +4
-0+/* FIXME: we could be checking if anything changed */ +mutex_unlock (&onyx->mutex); + +return 1 ;The put callback is supposed to return 0 if the values are unchanged (although most apps ignore the return value).
Does it have to? This way there's an event, but...
Yes, in principle. As mentioned, it works even without the check, though.
Quoted 8 lines
Quoted 6 lines
sound/aoa/codecs/snd-aoa-codec-tas.c line 325
Quoted 4 lines
sound/aoa/codecs/snd-aoa-codec-tas.c new file +4
-0+static int tas_snd_capture_source_info (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_info *uinfo) +{ +static char * texts[] = {"Line-In" ,"Microphone" };char *texts[]
Any particular reason?
Well, I meant the position of asterisk to follow the conventional C coding style. Of course it should be static.
Quoted 5 lines
Quoted 3 lines
sound/aoa/codecs/snd-aoa-codec-tas.c line 534
Quoted 1 line
sound/aoa/codecs/snd-aoa-codec-tas.c new file +1
-0+aoa_snd_ctl_add (snd_ctl_new1 (&volume_control, tas));Error checks please.
What should it do on such errors?
The driver should give up the initialization and fail to load. Usually the error from snd_ctl_add() is critical, either no memory or a duplicated control element is found.
Takashi
Johannes Berg
maintainerRe: [RFC 4/7] snd-aoa: add codecs
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ return 1;The put callback is supposed to return 0 if the values are unchanged (although most apps ignore the return value).
Does it have to? This way there's an event, but...
Yes, in principle. As mentioned, it works even without the check, though.
Hmm. I thought it worked like this:
0 -> no change 1 -> change applied, and other apps are notified, 0 returned to the app -err -> error returned to app
Is that wrong?
Quoted 2 lines
Well, I meant the position of asterisk to follow the conventional C coding style. Of course it should be static.
Ah. Yeah, I'll see to that and probably just Lindent the files (cleaning up after it...)
Quoted 3 lines
The driver should give up the initialization and fail to load. Usually the error from
snd_ctl_add()is critical, either no memory or a duplicated control element is found.
Hmm, that's a bit hard to do since the driver here consists of more than one module, but I suppose I can do something about it.
johannes
_______________________________________________
Alsa-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/alsa-devel
Re: [RFC 4/7] snd-aoa: add codecs
At Tue, 30 May 2006 15:26:10 +0200,
Quoted 11 lines · Johannes Berg
Quoted 10 lines
Quoted 7 lines
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +1
-0+ return 1;The put callback is supposed to return 0 if the values are unchanged (although most apps ignore the return value).
Does it have to? This way there's an event, but...
Yes, in principle. As mentioned, it works even without the check, though.
Quoted 6 lines
Hmm. I thought it worked like this:
0 -> no change 1 -> change applied, and other apps are notified, 0 returned to the app -err -> error returned to appIs that wrong?
It's correct.
And I thought the put callbacks in your code always return either 1 or -err?
Takashi
Re: [Alsa-devel] [RFC 4/7] snd-aoa: add codecs
In reply to Johannes BergAt Tue, 30 May 2006 15:26:10 +0200,
Quoted 11 lines · Johannes Berg
Quoted 10 lines
Quoted 7 lines
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +1
-0+ return 1;The put callback is supposed to return 0 if the values are unchanged (although most apps ignore the return value).
Does it have to? This way there's an event, but...
Yes, in principle. As mentioned, it works even without the check, though.
Quoted 6 lines
Hmm. I thought it worked like this:
0 -> no change 1 -> change applied, and other apps are notified, 0 returned to the app -err -> error returned to appIs that wrong?
It's correct.
And I thought the put callbacks in your code always return either 1 or -err?
Takashi
Johannes Berg
maintainerRe: [RFC 4/7] snd-aoa: add codecs
Quoted 2 lines · Takashi Iwai
And I thought the put callbacks in your code always return either 1 or -err?
Yeah, they return 1 if the change was applied (or no change) and -err if there's an error about the change (only in very few cases).
I figured the extra notification wouldn't hurt, and to the application there wouldn't be a problem.
johannes
_______________________________________________
Alsa-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/alsa-devel
Re: [RFC 4/7] snd-aoa: add codecs
At Tue, 30 May 2006 15:39:09 +0200,
Quoted 11 lines · Johannes Berg
Quoted 2 lines · Takashi Iwai
And I thought the put callbacks in your code always return either 1 or -err?
Yeah, they return 1 if the change was applied (or no change) and -err if there's an error about the change (only in very few cases).
I figured the extra notification wouldn't hurt, and to the application there wouldn't be a problem.
Actually the extra notification won't hurt much in practice. I've seen that some drivers also don't check the unchanged case and return always 1, so apparently the apps work. But, it's of course better to check the state on the driver side.
Takashi
Johannes Berg
maintainerRe: [RFC 4/7] snd-aoa: add codecs
Quoted 4 lines · Takashi Iwai
Actually the extra notification won't hurt much in practice. I've seen that some drivers also don't check the unchanged case and return always 1, so apparently the apps work. But, it's of course better to check the state on the driver side.
Yeah, agreed. I'll fix it.
How about making alsamixer actually handle the error cases? In the onyx codec, there's some things that prohibit changing the s/pdif output if you dno't use a bitrate that can handle, but alsamixer 'changes' it anyway...
johannes
_______________________________________________
Alsa-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/alsa-devel
Re: [RFC 4/7] snd-aoa: add codecs
At Tue, 30 May 2006 15:53:25 +0200,
Quoted 8 lines · Johannes Berg
Quoted 4 lines · Takashi Iwai
Actually the extra notification won't hurt much in practice. I've seen that some drivers also don't check the unchanged case and return always 1, so apparently the apps work. But, it's of course better to check the state on the driver side.
Quoted 6 lines
Yeah, agreed. I'll fix it.
How about making alsamixer actually handle the error cases? In the onyx codec, there's some things that prohibit changing the s/pdif output if you dno't use a bitrate that can handle, but alsamixer 'changes' it anyway...
Oh, it should be called as a "bug"... ;)
Takashi
Johannes Berg
maintainerRFC 5/7 snd-aoa: add layout-id fabric
In reply to Johannes BergThe 'fabric' is the thing that pulls all of snd-aoa together, this patch adds the 'layout' or 'layout-id' fabric that keys off the 'layout-id' property in the device-tree to pull in the proper modules. It itself loads if an i2sbus is present with a layout-id (exported in modalias) that it can use.
sound/aoa/fabrics/Kconfig new file +12 -0
@@ -0,0 +1,12 @@ +config SND_AOA_FABRIC_LAYOUT + tristate "layout-id fabric" + depends SND_AOA + select SND_AOA_SOUNDBUS + select SND_AOA_SOUNDBUS_I2S + ---help--- + This enables the layout-id fabric for the Apple Onboard + Audio driver, the module holding it all together + based on the device-tree's layout-id property. + + If you are unsure and have a later Apple machine, + compile it as a module.
sound/aoa/fabrics/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-$(CONFIG_SND_AOA_FABRIC_LAYOUT) += snd-aoa-fabric-layout.o
sound/aoa/fabrics/snd-aoa-fabric-layout.c new file +605 -0
605 lines not on this page · raw message
--
Re: [RFC 5/7] snd-aoa: add layout-id fabric
At Sun, 28 May 2006 21:00:31 +0200,
Quoted 6 lines · Johannes Berg
The 'fabric' is the thing that pulls all of snd-aoa together, this patch adds the 'layout' or 'layout-id' fabric that keys off the 'layout-id' property in the device-tree to pull in the proper modules. It itself loads if an i2sbus is present with a layout-id (exported in modalias) that it can use.
(snip)
sound/aoa/fabrics/snd-aoa-fabric-layout.c line 290
Quoted 7 lines
sound/aoa/fabrics/snd-aoa-fabric-layout.c new file +7
-0+static void use_layout (struct layout *l) +{ +int i; + +for (i=0 ; i<MAX_CODECS_PER_BUS ; i++) { +if (l->codecs[i].name) { +request_module ("snd-aoa-codec-%s" , l->codecs[i].name);
Just from curiosity: Does this work properly?
I remember that there was a deadlock when you call request_module() during module probe.
Takashi
Johannes Berg
maintainerRe: [RFC 5/7] snd-aoa: add layout-id fabric
Quoted 3 lines · Takashi Iwai
Just from curiosity: Does this work properly?
I remember that there was a deadlock when you callrequest_module()during module probe.
Yes, it works, but I don't think this is actually done during module probe (would have to check though)
johannes
_______________________________________________
Alsa-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/alsa-devel
Johannes Berg
maintainerRFC 6/7 snd-aoa: add Kconfig and Makefile
In reply to Johannes BergThis patch adds the simple Kconfig and Makefile files for aoa.
sound/aoa/Kconfig new file +17 -0
@@ -0,0 +1,17 @@ +menu "Apple Onboard Audio driver" + depends on SND != n && PPC + +config SND_AOA + tristate "Apple Onboard Audio driver" + depends on SOUND && SND_PCM && EXPERIMENTAL + ---help--- + This option enables the new driver for the various + Apple Onboard Audio components. + +source "sound/aoa/fabrics/Kconfig" + +source "sound/aoa/codecs/Kconfig" + +source "sound/aoa/soundbus/Kconfig" + +endmenu
sound/aoa/Makefile new file +4 -0
@@ -0,0 +1,4 @@ +obj-$(CONFIG_SND_AOA) += core/ +obj-$(CONFIG_SND_AOA) += codecs/ +obj-$(CONFIG_SND_AOA) += fabrics/ +obj-$(CONFIG_SND_AOA_SOUNDBUS) += soundbus/
--
Johannes Berg
maintainerRFC 7/7 snd-aoa: wire up aoa in sound/
In reply to Johannes BergThis patch adds the necessary Kconfig and Makefile hooks to make aoa buildable inside the kernel tree.
sound/Kconfig +2 -0
@@ -58,6 +58,8 @@ source "sound/pci/Kconfig" source "sound/ppc/Kconfig" +source "sound/aoa/Kconfig" + source "sound/arm/Kconfig" source "sound/mips/Kconfig"
sound/Makefile +1 -1
@@ -4,7 +4,7 @@ # obj-$(CONFIG_SOUND) += soundcore.o obj-$(CONFIG_SOUND_PRIME) += oss/ obj-$(CONFIG_DMASOUND) += oss/ -obj-$(CONFIG_SND) += core/ i2c/ drivers/ isa/ pci/ ppc/ arm/ synth/ usb/ sparc/ parisc/ pcmcia/ mips/ +obj-$(CONFIG_SND) += core/ i2c/ drivers/ isa/ pci/ ppc/ arm/ synth/ usb/ sparc/ parisc/ pcmcia/ mips/ aoa/ ifeq ($(CONFIG_SND),y) obj-y += last.o
--
Johannes Berg
maintainerHmm. The most interesting, #3, was held for being too large. Can someone free it please?
johannes
_______________________________________________
Alsa-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/alsa-devel
At Sun, 28 May 2006 21:10:08 +0200,
Quoted 3 lines · Johannes Berg
Hmm. The most interesting, #3, was held for being too large. Can someone free it please?
Not sure which filtered the post (sourceforge server?)...
Could you repost with a gzipped attachment?
thanks,
Takashi
Johannes Berg
maintainerQuoted 1 line · Takashi Iwai
Not sure which filtered the post (sourceforge server?)...
Yeah, sf.net, you can look at it on their mailman interface.
Quoted 1 line
Could you repost with a gzipped attachment?
I'll instead split it up into two which are both smaller, can be done.
johannes
_______________________________________________
Alsa-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/alsa-devel