From d280289e799dcdf5913e8935bffe136d7594e26d Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Mon, 1 Sep 2008 17:44:05 +0200 Subject: sound: ASoC: Fix an error path in neo1973_wm8753 The error handling in neo1973_init is incorrect: * If platform_device_add fails, we go on with the rest of the initialization instead of bailing out. Things will break when the module is removed (platform_device_unregister called on a device that wasn't registered.) * If i2c_add_driver fails, we return an error so the module will not load, but we don't unregister neo1973_snd_device, so we are leaking resources. Add the missing error handling. Signed-off-by: Jean Delvare Cc: Tim Niemeyer Cc: Graeme Gregory Cc: Mark Brown Signed-off-by: Mark Brown Signed-off-by: Jaroslav Kysela --- sound/soc/s3c24xx/neo1973_wm8753.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'sound/soc/s3c24xx') diff --git a/sound/soc/s3c24xx/neo1973_wm8753.c b/sound/soc/s3c24xx/neo1973_wm8753.c index 8089f8ee05c..3aa441f19ae 100644 --- a/sound/soc/s3c24xx/neo1973_wm8753.c +++ b/sound/soc/s3c24xx/neo1973_wm8753.c @@ -717,12 +717,16 @@ static int __init neo1973_init(void) neo1973_snd_devdata.dev = &neo1973_snd_device->dev; ret = platform_device_add(neo1973_snd_device); - if (ret) + if (ret) { platform_device_put(neo1973_snd_device); + return ret; + } ret = i2c_add_driver(&lm4857_i2c_driver); - if (ret != 0) + if (ret != 0) { printk(KERN_ERR "can't add i2c driver"); + platform_device_unregister(neo1973_snd_device); + } return ret; } -- cgit v1.2.3-70-g09d2 From ad4503d8a0636ddae8175bd05b652264c4260e96 Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Mon, 1 Sep 2008 17:45:34 +0200 Subject: sound: ASoC: Convert wm8753 to a new-style i2c driver Convert the wm8753 codec driver to the new (standard) i2c device driver binding model. Signed-off-by: Jean Delvare Cc: Ville Syrjala Cc: Frank Mandarino Cc: Mark Brown Signed-off-by: Mark Brown Signed-off-by: Jaroslav Kysela --- sound/soc/codecs/wm8753.c | 106 ++++++++++++++++++------------------- sound/soc/codecs/wm8753.h | 1 + sound/soc/s3c24xx/neo1973_wm8753.c | 1 + 3 files changed, 55 insertions(+), 53 deletions(-) (limited to 'sound/soc/s3c24xx') diff --git a/sound/soc/codecs/wm8753.c b/sound/soc/codecs/wm8753.c index e873414840c..8c4df44f334 100644 --- a/sound/soc/codecs/wm8753.c +++ b/sound/soc/codecs/wm8753.c @@ -1637,84 +1637,86 @@ static struct snd_soc_device *wm8753_socdev; * low = 0x1a * high = 0x1b */ -static unsigned short normal_i2c[] = { 0, I2C_CLIENT_END }; -/* Magic definition of all other variables and things */ -I2C_CLIENT_INSMOD; - -static struct i2c_driver wm8753_i2c_driver; -static struct i2c_client client_template; - -static int wm8753_codec_probe(struct i2c_adapter *adap, int addr, int kind) +static int wm8753_i2c_probe(struct i2c_client *i2c, + const struct i2c_device_id *id) { struct snd_soc_device *socdev = wm8753_socdev; - struct wm8753_setup_data *setup = socdev->codec_data; struct snd_soc_codec *codec = socdev->codec; - struct i2c_client *i2c; int ret; - if (addr != setup->i2c_address) - return -ENODEV; - - client_template.adapter = adap; - client_template.addr = addr; - - i2c = kmemdup(&client_template, sizeof(client_template), GFP_KERNEL); - if (!i2c) - return -ENOMEM; - i2c_set_clientdata(i2c, codec); codec->control_data = i2c; - ret = i2c_attach_client(i2c); - if (ret < 0) { - pr_err("failed to attach codec at addr %x\n", addr); - goto err; - } - ret = wm8753_init(socdev); - if (ret < 0) { + if (ret < 0) pr_err("failed to initialise WM8753\n"); - goto err; - } - - return ret; -err: - kfree(i2c); return ret; } -static int wm8753_i2c_detach(struct i2c_client *client) +static int wm8753_i2c_remove(struct i2c_client *client) { struct snd_soc_codec *codec = i2c_get_clientdata(client); - i2c_detach_client(client); kfree(codec->reg_cache); - kfree(client); return 0; } -static int wm8753_i2c_attach(struct i2c_adapter *adap) -{ - return i2c_probe(adap, &addr_data, wm8753_codec_probe); -} +static const struct i2c_device_id wm8753_i2c_id[] = { + { "wm8753", 0 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, wm8753_i2c_id); -/* corgi i2c codec control layer */ static struct i2c_driver wm8753_i2c_driver = { .driver = { .name = "WM8753 I2C Codec", .owner = THIS_MODULE, }, - .id = I2C_DRIVERID_WM8753, - .attach_adapter = wm8753_i2c_attach, - .detach_client = wm8753_i2c_detach, - .command = NULL, + .probe = wm8753_i2c_probe, + .remove = wm8753_i2c_remove, + .id_table = wm8753_i2c_id, }; -static struct i2c_client client_template = { - .name = "WM8753", - .driver = &wm8753_i2c_driver, -}; +static int wm8753_add_i2c_device(struct platform_device *pdev, + const struct wm8753_setup_data *setup) +{ + struct i2c_board_info info; + struct i2c_adapter *adapter; + struct i2c_client *client; + int ret; + + ret = i2c_add_driver(&wm8753_i2c_driver); + if (ret != 0) { + dev_err(&pdev->dev, "can't add i2c driver\n"); + return ret; + } + + memset(&info, 0, sizeof(struct i2c_board_info)); + info.addr = setup->i2c_address; + strlcpy(info.type, "wm8753", I2C_NAME_SIZE); + + adapter = i2c_get_adapter(setup->i2c_bus); + if (!adapter) { + dev_err(&pdev->dev, "can't get i2c adapter %d\n", + setup->i2c_bus); + goto err_driver; + } + + client = i2c_new_device(adapter, &info); + i2c_put_adapter(adapter); + if (!client) { + dev_err(&pdev->dev, "can't add i2c device at 0x%x\n", + (unsigned int)info.addr); + goto err_driver; + } + + return 0; + +err_driver: + i2c_del_driver(&wm8753_i2c_driver); + return -ENODEV; +} #endif static int wm8753_probe(struct platform_device *pdev) @@ -1748,11 +1750,8 @@ static int wm8753_probe(struct platform_device *pdev) #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) if (setup->i2c_address) { - normal_i2c[0] = setup->i2c_address; codec->hw_write = (hw_write_t)i2c_master_send; - ret = i2c_add_driver(&wm8753_i2c_driver); - if (ret != 0) - printk(KERN_ERR "can't add i2c driver"); + ret = wm8753_add_i2c_device(pdev, setup); } #else /* Add other interfaces here */ @@ -1796,6 +1795,7 @@ static int wm8753_remove(struct platform_device *pdev) snd_soc_free_pcms(socdev); snd_soc_dapm_free(socdev); #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) + i2c_unregister_device(codec->control_data); i2c_del_driver(&wm8753_i2c_driver); #endif kfree(codec->private_data); diff --git a/sound/soc/codecs/wm8753.h b/sound/soc/codecs/wm8753.h index 44f5f1ff0cc..7defde069f1 100644 --- a/sound/soc/codecs/wm8753.h +++ b/sound/soc/codecs/wm8753.h @@ -79,6 +79,7 @@ #define WM8753_ADCTL2 0x3f struct wm8753_setup_data { + int i2c_bus; unsigned short i2c_address; }; diff --git a/sound/soc/s3c24xx/neo1973_wm8753.c b/sound/soc/s3c24xx/neo1973_wm8753.c index 3aa441f19ae..181d2999fb2 100644 --- a/sound/soc/s3c24xx/neo1973_wm8753.c +++ b/sound/soc/s3c24xx/neo1973_wm8753.c @@ -586,6 +586,7 @@ static struct snd_soc_machine neo1973 = { }; static struct wm8753_setup_data neo1973_wm8753_setup = { + .i2c_bus = 0, .i2c_address = 0x1a, }; -- cgit v1.2.3-70-g09d2 From b6471305bbda16fd0d8d96a5cfb01fa6aec87eb5 Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Mon, 1 Sep 2008 17:46:57 +0200 Subject: sound: ASoC: Convert neo1973/lm4857 to a new-style i2c driver Convert the lm4857 driver in neo1973_wm8753 to the new (standard) i2c device driver binding model. I assumed that the LM4857 was always on the same I2C bus as the WM8753 codec. Signed-off-by: Jean Delvare Cc: Tim Niemeyer Cc: Graeme Gregory Cc: Mark Brown Signed-off-by: Mark Brown Signed-off-by: Jaroslav Kysela --- sound/soc/s3c24xx/neo1973_wm8753.c | 110 +++++++++++++++++++------------------ 1 file changed, 58 insertions(+), 52 deletions(-) (limited to 'sound/soc/s3c24xx') diff --git a/sound/soc/s3c24xx/neo1973_wm8753.c b/sound/soc/s3c24xx/neo1973_wm8753.c index 181d2999fb2..47ddcdedc3a 100644 --- a/sound/soc/s3c24xx/neo1973_wm8753.c +++ b/sound/soc/s3c24xx/neo1973_wm8753.c @@ -597,54 +597,20 @@ static struct snd_soc_device neo1973_snd_devdata = { .codec_data = &neo1973_wm8753_setup, }; -static struct i2c_client client_template; - -static const unsigned short normal_i2c[] = { 0x7C, I2C_CLIENT_END }; - -/* Magic definition of all other variables and things */ -I2C_CLIENT_INSMOD; - -static int lm4857_amp_probe(struct i2c_adapter *adap, int addr, int kind) +static int lm4857_i2c_probe(struct i2c_client *client, + const struct i2c_device_id *id) { - int ret; - DBG("Entered %s\n", __func__); - client_template.adapter = adap; - client_template.addr = addr; - - i2c = kmemdup(&client_template, sizeof(client_template), GFP_KERNEL); - if (i2c == NULL) - return -ENOMEM; - - ret = i2c_attach_client(i2c); - if (ret < 0) { - printk(KERN_ERR "LM4857 failed to attach at addr %x\n", addr); - goto exit_err; - } - lm4857_write_regs(); - return ret; - -exit_err: - kfree(i2c); - return ret; -} - -static int lm4857_i2c_detach(struct i2c_client *client) -{ - DBG("Entered %s\n", __func__); - - i2c_detach_client(client); - kfree(client); return 0; } -static int lm4857_i2c_attach(struct i2c_adapter *adap) +static int lm4857_i2c_remove(struct i2c_client *client) { DBG("Entered %s\n", __func__); - return i2c_probe(adap, &addr_data, lm4857_amp_probe); + return 0; } static u8 lm4857_state; @@ -682,27 +648,67 @@ static void lm4857_shutdown(struct i2c_client *dev) lm4857_write_regs(); } -/* corgi i2c codec control layer */ +static const struct i2c_device_id lm4857_i2c_id[] = { + { "neo1973_lm4857", 0 } + { } +}; + static struct i2c_driver lm4857_i2c_driver = { .driver = { .name = "LM4857 I2C Amp", .owner = THIS_MODULE, }, - .id = I2C_DRIVERID_LM4857, .suspend = lm4857_suspend, .resume = lm4857_resume, .shutdown = lm4857_shutdown, - .attach_adapter = lm4857_i2c_attach, - .detach_client = lm4857_i2c_detach, - .command = NULL, -}; - -static struct i2c_client client_template = { - .name = "LM4857", - .driver = &lm4857_i2c_driver, + .probe = lm4857_i2c_probe, + .remove = lm4857_i2c_remove, + .id_table = lm4857_i2c_id, }; static struct platform_device *neo1973_snd_device; +static struct i2c_client *lm4857_client; + +static int __init neo1973_add_lm4857_device(struct platform_device *pdev, + int i2c_bus, + unsigned short i2c_address) +{ + struct i2c_board_info info; + struct i2c_adapter *adapter; + struct i2c_client *client; + int ret; + + ret = i2c_add_driver(&lm4857_i2c_driver); + if (ret != 0) { + dev_err(&pdev->dev, "can't add lm4857 driver\n"); + return ret; + } + + memset(&info, 0, sizeof(struct i2c_board_info)); + info.addr = i2c_address; + strlcpy(info.type, "neo1973_lm4857", I2C_NAME_SIZE); + + adapter = i2c_get_adapter(i2c_bus); + if (!adapter) { + dev_err(&pdev->dev, "can't get i2c adapter %d\n", i2c_bus); + goto err_driver; + } + + client = i2c_new_device(adapter, &info); + i2c_put_adapter(adapter); + if (!client) { + dev_err(&pdev->dev, "can't add lm4857 device at 0x%x\n", + (unsigned int)info.addr); + goto err_driver; + } + + lm4857_client = client; + return 0; + +err_driver: + i2c_del_driver(&lm4857_i2c_driver); + return -ENODEV; +} static int __init neo1973_init(void) { @@ -723,11 +729,10 @@ static int __init neo1973_init(void) return ret; } - ret = i2c_add_driver(&lm4857_i2c_driver); - if (ret != 0) { - printk(KERN_ERR "can't add i2c driver"); + ret = neo1973_add_lm4857_device(neo1973_snd_device, + neo1973_wm8753_setup, 0x7C); + if (ret != 0) platform_device_unregister(neo1973_snd_device); - } return ret; } @@ -736,6 +741,7 @@ static void __exit neo1973_exit(void) { DBG("Entered %s\n", __func__); + i2c_unregister_device(lm4857_client); i2c_del_driver(&lm4857_i2c_driver); platform_device_unregister(neo1973_snd_device); } -- cgit v1.2.3-70-g09d2 From fb2aa074d4eac4957f5717d261bc336f4a5f31c4 Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Wed, 8 Oct 2008 13:02:20 +0100 Subject: ALSA: ASoC: Check for machine type in GTA01 machine driver Since there are now multiple OpenMoko platforms it is more important to check that the machine driver is running on the correct system. This was orgininally generated as part of the initial GTA02 machine port. Signed-off-by: Mark Brown Signed-off-by: Takashi Iwai Signed-off-by: Jaroslav Kysela --- sound/soc/s3c24xx/neo1973_wm8753.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'sound/soc/s3c24xx') diff --git a/sound/soc/s3c24xx/neo1973_wm8753.c b/sound/soc/s3c24xx/neo1973_wm8753.c index 47ddcdedc3a..73a50e93a9a 100644 --- a/sound/soc/s3c24xx/neo1973_wm8753.c +++ b/sound/soc/s3c24xx/neo1973_wm8753.c @@ -24,6 +24,7 @@ #include #include +#include #include #include #include @@ -716,6 +717,12 @@ static int __init neo1973_init(void) DBG("Entered %s\n", __func__); + if (!machine_is_neo1973_gta01()) { + printk(KERN_INFO + "Only GTA01 hardware supported by ASoC driver\n"); + return -ENODEV; + } + neo1973_snd_device = platform_device_alloc("soc-audio", -1); if (!neo1973_snd_device) return -ENOMEM; -- cgit v1.2.3-70-g09d2 From b1cbc21c8e0cb9d253dc1388f24495b68261821a Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Wed, 24 Sep 2008 11:33:05 +0100 Subject: ALSA: ASoC: Use snd_soc_dapm_nc_pin() in GTA01 audio driver Signed-off-by: Mark Brown Signed-off-by: Takashi Iwai --- sound/soc/s3c24xx/neo1973_wm8753.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'sound/soc/s3c24xx') diff --git a/sound/soc/s3c24xx/neo1973_wm8753.c b/sound/soc/s3c24xx/neo1973_wm8753.c index 73a50e93a9a..006c36ded25 100644 --- a/sound/soc/s3c24xx/neo1973_wm8753.c +++ b/sound/soc/s3c24xx/neo1973_wm8753.c @@ -511,13 +511,12 @@ static int neo1973_wm8753_init(struct snd_soc_codec *codec) DBG("Entered %s\n", __func__); /* set up NC codec pins */ - snd_soc_dapm_disable_pin(codec, "LOUT2"); - snd_soc_dapm_disable_pin(codec, "ROUT2"); - snd_soc_dapm_disable_pin(codec, "OUT3"); - snd_soc_dapm_disable_pin(codec, "OUT4"); - snd_soc_dapm_disable_pin(codec, "LINE1"); - snd_soc_dapm_disable_pin(codec, "LINE2"); - + snd_soc_dapm_nc_pin(codec, "LOUT2"); + snd_soc_dapm_nc_pin(codec, "ROUT2"); + snd_soc_dapm_nc_pin(codec, "OUT3"); + snd_soc_dapm_nc_pin(codec, "OUT4"); + snd_soc_dapm_nc_pin(codec, "LINE1"); + snd_soc_dapm_nc_pin(codec, "LINE2"); /* set endpoints to default mode */ set_scenario_endpoints(codec, NEO_AUDIO_OFF); -- cgit v1.2.3-70-g09d2 From e8089948d65911c78bcd72960dd419ec636d6f0b Mon Sep 17 00:00:00 2001 From: Jonas Bonn Date: Wed, 1 Oct 2008 18:17:12 +0100 Subject: ALSA: ASoC: Add widgets before setting endpoints on GTA01 This prevents error messages at startup where the endpoints are being set before the widgets/controls have even been added. Signed-off-by: Jonas Bonn Signed-off-by: Mark Brown Signed-off-by: Takashi Iwai --- sound/soc/s3c24xx/neo1973_wm8753.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'sound/soc/s3c24xx') diff --git a/sound/soc/s3c24xx/neo1973_wm8753.c b/sound/soc/s3c24xx/neo1973_wm8753.c index 006c36ded25..9eda86259e6 100644 --- a/sound/soc/s3c24xx/neo1973_wm8753.c +++ b/sound/soc/s3c24xx/neo1973_wm8753.c @@ -518,13 +518,13 @@ static int neo1973_wm8753_init(struct snd_soc_codec *codec) snd_soc_dapm_nc_pin(codec, "LINE1"); snd_soc_dapm_nc_pin(codec, "LINE2"); - /* set endpoints to default mode */ - set_scenario_endpoints(codec, NEO_AUDIO_OFF); - /* Add neo1973 specific widgets */ snd_soc_dapm_new_controls(codec, wm8753_dapm_widgets, ARRAY_SIZE(wm8753_dapm_widgets)); + /* set endpoints to default mode */ + set_scenario_endpoints(codec, NEO_AUDIO_OFF); + /* add neo1973 specific controls */ for (i = 0; i < ARRAY_SIZE(wm8753_neo1973_controls); i++) { err = snd_ctl_add(codec->card, -- cgit v1.2.3-70-g09d2 From df20cf92cae5640568ee3d48bf7a32987c057413 Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Wed, 24 Sep 2008 11:57:27 +0100 Subject: ALSA: ASoC: Fix build of GTA01 audio driver Fix a couple of thinkos introduced during the I2C API update. Signed-off-by: Mark Brown Signed-off-by: Takashi Iwai --- sound/soc/s3c24xx/neo1973_wm8753.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sound/soc/s3c24xx') diff --git a/sound/soc/s3c24xx/neo1973_wm8753.c b/sound/soc/s3c24xx/neo1973_wm8753.c index 9eda86259e6..f7fc231e238 100644 --- a/sound/soc/s3c24xx/neo1973_wm8753.c +++ b/sound/soc/s3c24xx/neo1973_wm8753.c @@ -649,7 +649,7 @@ static void lm4857_shutdown(struct i2c_client *dev) } static const struct i2c_device_id lm4857_i2c_id[] = { - { "neo1973_lm4857", 0 } + { "neo1973_lm4857", 0 }, { } }; @@ -736,7 +736,7 @@ static int __init neo1973_init(void) } ret = neo1973_add_lm4857_device(neo1973_snd_device, - neo1973_wm8753_setup, 0x7C); + 0, 0x7C); if (ret != 0) platform_device_unregister(neo1973_snd_device); -- cgit v1.2.3-70-g09d2 From f9d1ab39e8c993f183c39a9724ca5ad29b6336e9 Mon Sep 17 00:00:00 2001 From: Jonas Bonn Date: Wed, 1 Oct 2008 21:47:19 +0200 Subject: ALSA: ASoC: Drop device registration from GTA01 lm4857 driver Device registration should be handled at the machine level and not in the driver code itself. This patch removes the device registration from the driver code in preparation for moving it to the machine definition. [Squashed down two parts to this patch for bisectability - there's also a third part adding registration of the device to the out of tree GTA01 machine driver -- broonie] Signed-off-by: Jonas Bonn Signed-off-by: Mark Brown Signed-off-by: Takashi Iwai --- sound/soc/s3c24xx/neo1973_wm8753.c | 51 +++++--------------------------------- 1 file changed, 6 insertions(+), 45 deletions(-) (limited to 'sound/soc/s3c24xx') diff --git a/sound/soc/s3c24xx/neo1973_wm8753.c b/sound/soc/s3c24xx/neo1973_wm8753.c index f7fc231e238..87ddfefcc2f 100644 --- a/sound/soc/s3c24xx/neo1973_wm8753.c +++ b/sound/soc/s3c24xx/neo1973_wm8753.c @@ -602,6 +602,8 @@ static int lm4857_i2c_probe(struct i2c_client *client, { DBG("Entered %s\n", __func__); + i2c = client; + lm4857_write_regs(); return 0; } @@ -610,6 +612,8 @@ static int lm4857_i2c_remove(struct i2c_client *client) { DBG("Entered %s\n", __func__); + i2c = NULL; + return 0; } @@ -667,48 +671,6 @@ static struct i2c_driver lm4857_i2c_driver = { }; static struct platform_device *neo1973_snd_device; -static struct i2c_client *lm4857_client; - -static int __init neo1973_add_lm4857_device(struct platform_device *pdev, - int i2c_bus, - unsigned short i2c_address) -{ - struct i2c_board_info info; - struct i2c_adapter *adapter; - struct i2c_client *client; - int ret; - - ret = i2c_add_driver(&lm4857_i2c_driver); - if (ret != 0) { - dev_err(&pdev->dev, "can't add lm4857 driver\n"); - return ret; - } - - memset(&info, 0, sizeof(struct i2c_board_info)); - info.addr = i2c_address; - strlcpy(info.type, "neo1973_lm4857", I2C_NAME_SIZE); - - adapter = i2c_get_adapter(i2c_bus); - if (!adapter) { - dev_err(&pdev->dev, "can't get i2c adapter %d\n", i2c_bus); - goto err_driver; - } - - client = i2c_new_device(adapter, &info); - i2c_put_adapter(adapter); - if (!client) { - dev_err(&pdev->dev, "can't add lm4857 device at 0x%x\n", - (unsigned int)info.addr); - goto err_driver; - } - - lm4857_client = client; - return 0; - -err_driver: - i2c_del_driver(&lm4857_i2c_driver); - return -ENODEV; -} static int __init neo1973_init(void) { @@ -735,8 +697,8 @@ static int __init neo1973_init(void) return ret; } - ret = neo1973_add_lm4857_device(neo1973_snd_device, - 0, 0x7C); + ret = i2c_add_driver(&lm4857_i2c_driver); + if (ret != 0) platform_device_unregister(neo1973_snd_device); @@ -747,7 +709,6 @@ static void __exit neo1973_exit(void) { DBG("Entered %s\n", __func__); - i2c_unregister_device(lm4857_client); i2c_del_driver(&lm4857_i2c_driver); platform_device_unregister(neo1973_snd_device); } -- cgit v1.2.3-70-g09d2