Re: [Device-drivers-devel] [PATCH] Add driver for Analog DevicesADAU1701 SigmaDSP

From: Mike Frysinger
Date: Sun Mar 06 2011 - 21:45:16 EST


On Sun, Mar 6, 2011 at 20:11, <cliff.cai@xxxxxxxxxx> wrote:
> +#define ADAU1701_FIRMWARE "SigmaDSP_fw.bin"

this probably needs to be more specific. like "adau1701.bin".
otherwise it makes it a pain to work with diff codecs in the same
system.

> +static int adau1701_write_register(struct snd_soc_codec *codec,
> + Â Â Â u16 reg_address, u8 length, u32 value)
> +{
> + Â Â Â int ret;
> + Â Â Â int count = length + 2; /*data plus 16bit register address*/
> + Â Â Â u8 buf[8] = {0, 0, 0, 0, 0, 0, 0, 0};
> +
> + Â Â Â if (length == 0)
> + Â Â Â Â Â Â Â return -1;
> + Â Â Â buf[0] = (reg_address >> 8) & 0xFF;

should be a blank line after that return

> + Â Â Â buf[1] = reg_address & 0xFF;
> + Â Â Â if (length == 1)
> + Â Â Â Â Â Â Â buf[2] = value & 0xFF;
> + Â Â Â else if (length == 2) {
> + Â Â Â Â Â Â Â buf[2] = (value >> 8) & 0xFF;
> + Â Â Â Â Â Â Â buf[3] = value & 0xFF;
> + Â Â Â } else if (length == 3) {
> + Â Â Â Â Â Â Â buf[2] = (value >> 16) & 0xFF;
> + Â Â Â Â Â Â Â buf[3] = (value >> 8) & 0xFF;
> + Â Â Â Â Â Â Â buf[4] = value & 0xFF;
> + Â Â Â }

i think the buf[8] init forces gcc to generate bad code, and seems to
be useless. shouldnt the code have an "else" brace to return -1 if
length is greater than 3, and then change the decl to "u8 buf[5];" ?

also, all these 0xFF masks are useless -- you're assigning it to a u8
which implies bit truncation

> + ret = i2c_master_send(codec->control_data, buf, count);
> +
> + Â Â Â return ret;
> +
> +}

the whole "int ret" seems kind of useless in this func. just return
the i2c_master_send and drop the ret var completely. and drop the
blank link after the return.

> +/*
> + * read ADAU1701 hw register
> + */
> +static u32 adau1701_read_register(struct snd_soc_codec *codec,
> + Â Â Â u16 reg_address, u8 length)
> +{
> + Â Â Â u8 addr[2];
> + Â Â Â u8 buf[2];
> + Â Â Â u32 value = 0;
> + Â Â Â int ret;
> +
> + Â Â Â if (reg_address < ADAU1701_FIRSTREG)
> + Â Â Â Â Â Â Â reg_address = reg_address + ADAU1701_FIRSTREG;
> +
> + Â Â Â if ((reg_address < ADAU1701_FIRSTREG) || (reg_address > ADAU1701_LASTREG))
> + Â Â Â Â Â Â Â return -EIO;

this func has "u32" for ret, and you return the raw register value
below. but here you try returning -EIO. shouldnt it be "int" so the
caller can check for "< 0" ?

> + Â Â Â addr[0] = (reg_address >> 8) & 0xFF;
> + Â Â Â addr[1] = reg_address & 0xFF;
> +
> + Â Â Â /* write the 2byte read address */
> + Â Â Â ret = i2c_master_send(codec->control_data, addr, 2);
> + Â Â Â if (ret)
> + Â Â Â Â Â Â Â return ret;
> +
> + Â Â Â if (length == 1) {
> + Â Â Â Â Â Â Â if (i2c_master_recv(codec->control_data, buf, 1) != 1)
> + Â Â Â Â Â Â Â Â Â Â Â return -EIO;
> + Â Â Â Â Â Â Â value = buf[0];
> + Â Â Â } else if (length == 2) {
> + Â Â Â Â Â Â Â if (i2c_master_recv(codec->control_data, buf, 2) != 2)
> + Â Â Â Â Â Â Â Â Â Â Â return -EIO;

seems like this can be combined into one simple code block where you
replace "1" and '2" with "length"

> +static int adau1701_setprogram(struct snd_soc_codec *codec)
> +{
> + Â Â Â int ret = 0;
> +
> + Â Â Â ret = process_sigma_firmware(codec->control_data, ADAU1701_FIRMWARE);
> +
> + Â Â Â return ret;
> +}

seems like this should be one statement -- a simple return

> +static int adau1701_set_bias_level(struct snd_soc_codec *codec,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âenum snd_soc_bias_level level)
> +{
> + Â Â Â u16 reg;
> + Â Â Â switch (level) {
> + Â Â Â case SND_SOC_BIAS_ON:
> + Â Â Â Â Â Â Â reg = adau1701_read_register(codec, ADAU1701_AUXNPOW, 2);
> + Â Â Â Â Â Â Â reg &= ~(AUXNPOW_AAPD | AUXNPOW_D0PD | AUXNPOW_D1PD | ÂAUXNPOW_D2PD |
> + Â Â Â Â Â Â Â Â Â Â Â ÂAUXNPOW_D3PD | AUXNPOW_VBPD | AUXNPOW_VRPD);
> + Â Â Â Â Â Â Â adau1701_write_register(codec, ADAU1701_AUXNPOW, 2, reg);
> + Â Â Â Â Â Â Â break;
> + Â Â Â case SND_SOC_BIAS_PREPARE:
> + Â Â Â Â Â Â Â break;
> + Â Â Â case SND_SOC_BIAS_STANDBY:
> + Â Â Â Â Â Â Â break;
> + Â Â Â case SND_SOC_BIAS_OFF:
> + Â Â Â Â Â Â Â /* everything off, dac mute, inactive */
> + Â Â Â Â Â Â Â reg = adau1701_read_register(codec, ADAU1701_AUXNPOW, 2);
> + Â Â Â Â Â Â Â reg |= AUXNPOW_AAPD | AUXNPOW_D0PD | AUXNPOW_D1PD | ÂAUXNPOW_D2PD |
> + Â Â Â Â Â Â Â Â Â Â Â ÂAUXNPOW_D3PD | AUXNPOW_VBPD | AUXNPOW_VRPD;
> + Â Â Â Â Â Â Â adau1701_write_register(codec, ADAU1701_AUXNPOW, 2, reg);

error checking missing on the read_register() call

> + Â Â Â Â Â Â Â break;
> +
> + Â Â Â }

drop the blank line before the brace

> +struct snd_soc_dai_driver adau1701_dai = {
> + Â Â Â .name = "ADAU1701",

i think the standard is to use all lower case

> +static int adau1701_suspend(struct snd_soc_codec *codec, pm_message_t state)
> +{
> + Â Â Â adau1701_set_bias_level(codec, SND_SOC_BIAS_OFF);
> + Â Â Â return 0;
> +}
> +
> +static int adau1701_resume(struct snd_soc_codec *codec)
> +{
> + Â Â Â adau1701_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
> + Â Â Â return 0;
> +}
> ...
> +static int adau1701_remove(struct snd_soc_codec *codec)
> +{
> + adau1701_set_bias_level(codec, SND_SOC_BIAS_OFF);
> + return 0;
> +}

why not return set_bias_level ?

> +static int adau1701_reg_init(struct snd_soc_codec *codec)
> ...
> + Â Â Â Â Â Â Â printk(KERN_ERR "Loading program data failed\n");

dev_err

> +struct snd_soc_codec_driver soc_codec_dev_adau1701 = {

static

> +static __devinit int adau1701_i2c_probe(struct i2c_client *i2c,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â const struct i2c_device_id *id)
> +{
> + Â Â Â struct adau1701_priv *adau1701;
> + Â Â Â int ret = 0;
> +
> + Â Â Â adau1701 = kzalloc(sizeof(struct adau1701_priv), GFP_KERNEL);

sizeof(*adau1701)

> +static int __init adau1701_modinit(void)
> +{
> + Â Â Â int ret;
> +
> + Â Â Â ret = i2c_add_driver(&adau1701_i2c_driver);
> + Â Â Â if (ret != 0) {
> + Â Â Â Â Â Â Â printk(KERN_ERR "Failed to register adau1701 I2C driver: %d\n",
> + Â Â Â Â Â Â Â Â Â Â Âret);
> + Â Â Â }

uesless braces, and should be pr_err

> +MODULE_DESCRIPTION("ASoC ADAU1701 SigmaDSP driver");
> +MODULE_AUTHOR("Cliff Cai");
> +MODULE_LICENSE("GPL");

MODULE_ALIAS() ?

> +++ b/sound/soc/codecs/adau1701.h
> ...
> +#define    ÂAUXADCE_AAEN      Â(1 << 15)
> +#define OSCIPOW_OPD Â Â Â Â Â Â(0x04)
> +#define    ÂDACSET_DACEN      Â(1)

looks like you got "#define<tab>" junk in here
-mike
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/