]> Pileus Git - ~andy/linux/blobdiff - sound/soc/codecs/wm1250-ev1.c
Merge tag 'hda-switcheroo' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai...
[~andy/linux] / sound / soc / codecs / wm1250-ev1.c
index cd0ec0fd1dbab536579b296884275cc14828326a..e0b51e9f8b121c8a146e9582665cc413a94b7ae1 100644 (file)
@@ -79,22 +79,65 @@ static const struct snd_soc_dapm_route wm1250_ev1_dapm_routes[] = {
        { "WM1250 Output", NULL, "DAC" },
 };
 
+static int wm1250_ev1_hw_params(struct snd_pcm_substream *substream,
+                               struct snd_pcm_hw_params *params,
+                               struct snd_soc_dai *dai)
+{
+       struct wm1250_priv *wm1250 = snd_soc_codec_get_drvdata(dai->codec);
+
+       switch (params_rate(params)) {
+       case 8000:
+               gpio_set_value(wm1250->gpios[WM1250_EV1_GPIO_CLK_SEL0].gpio,
+                              1);
+               gpio_set_value(wm1250->gpios[WM1250_EV1_GPIO_CLK_SEL1].gpio,
+                              1);
+               break;
+       case 16000:
+               gpio_set_value(wm1250->gpios[WM1250_EV1_GPIO_CLK_SEL0].gpio,
+                              0);
+               gpio_set_value(wm1250->gpios[WM1250_EV1_GPIO_CLK_SEL1].gpio,
+                              1);
+               break;
+       case 32000:
+               gpio_set_value(wm1250->gpios[WM1250_EV1_GPIO_CLK_SEL0].gpio,
+                              1);
+               gpio_set_value(wm1250->gpios[WM1250_EV1_GPIO_CLK_SEL1].gpio,
+                              0);
+               break;
+       case 64000:
+               gpio_set_value(wm1250->gpios[WM1250_EV1_GPIO_CLK_SEL0].gpio,
+                              0);
+               gpio_set_value(wm1250->gpios[WM1250_EV1_GPIO_CLK_SEL1].gpio,
+                              0);
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static const struct snd_soc_dai_ops wm1250_ev1_ops = {
+       .hw_params = wm1250_ev1_hw_params,
+};
+
 static struct snd_soc_dai_driver wm1250_ev1_dai = {
        .name = "wm1250-ev1",
        .playback = {
                .stream_name = "Playback",
                .channels_min = 1,
-               .channels_max = 1,
+               .channels_max = 2,
                .rates = SNDRV_PCM_RATE_8000,
                .formats = SNDRV_PCM_FMTBIT_S16_LE,
        },
        .capture = {
                .stream_name = "Capture",
                .channels_min = 1,
-               .channels_max = 1,
+               .channels_max = 2,
                .rates = SNDRV_PCM_RATE_8000,
                .formats = SNDRV_PCM_FMTBIT_S16_LE,
        },
+       .ops = &wm1250_ev1_ops,
 };
 
 static struct snd_soc_codec_driver soc_codec_dev_wm1250_ev1 = {
@@ -116,7 +159,7 @@ static int __devinit wm1250_ev1_pdata(struct i2c_client *i2c)
        if (!pdata)
                return 0;
 
-       wm1250 = kzalloc(sizeof(*wm1250), GFP_KERNEL);
+       wm1250 = devm_kzalloc(&i2c->dev, sizeof(*wm1250), GFP_KERNEL);
        if (!wm1250) {
                dev_err(&i2c->dev, "Unable to allocate private data\n");
                ret = -ENOMEM;
@@ -134,15 +177,13 @@ static int __devinit wm1250_ev1_pdata(struct i2c_client *i2c)
        ret = gpio_request_array(wm1250->gpios, ARRAY_SIZE(wm1250->gpios));
        if (ret != 0) {
                dev_err(&i2c->dev, "Failed to get GPIOs: %d\n", ret);
-               goto err_alloc;
+               goto err;
        }
 
        dev_set_drvdata(&i2c->dev, wm1250);
 
        return ret;
 
-err_alloc:
-       kfree(wm1250);
 err:
        return ret;
 }
@@ -151,10 +192,8 @@ static void wm1250_ev1_free(struct i2c_client *i2c)
 {
        struct wm1250_priv *wm1250 = dev_get_drvdata(&i2c->dev);
 
-       if (wm1250) {
+       if (wm1250)
                gpio_free_array(wm1250->gpios, ARRAY_SIZE(wm1250->gpios));
-               kfree(wm1250);
-       }
 }
 
 static int __devinit wm1250_ev1_probe(struct i2c_client *i2c,
@@ -219,23 +258,7 @@ static struct i2c_driver wm1250_ev1_i2c_driver = {
        .id_table = wm1250_ev1_i2c_id,
 };
 
-static int __init wm1250_ev1_modinit(void)
-{
-       int ret = 0;
-
-       ret = i2c_add_driver(&wm1250_ev1_i2c_driver);
-       if (ret != 0)
-               pr_err("Failed to register WM1250-EV1 I2C driver: %d\n", ret);
-
-       return ret;
-}
-module_init(wm1250_ev1_modinit);
-
-static void __exit wm1250_ev1_exit(void)
-{
-       i2c_del_driver(&wm1250_ev1_i2c_driver);
-}
-module_exit(wm1250_ev1_exit);
+module_i2c_driver(wm1250_ev1_i2c_driver);
 
 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
 MODULE_DESCRIPTION("WM1250-EV1 audio I/O module driver");