4 * Created on: 15-Oct-2009
5 * Author: neil.jones@imgtec.com
7 * Copyright (C) 2009 Imagination Technologies Ltd.
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
15 #include <linux/init.h>
16 #include <linux/module.h>
17 #include <linux/kernel.h>
18 #include <linux/device.h>
19 #include <sound/core.h>
20 #include <sound/pcm.h>
21 #include <sound/ac97_codec.h>
22 #include <sound/initval.h>
23 #include <sound/soc.h>
27 * Note this is a simple chip with no configuration interface, sample rate is
28 * determined automatically by examining the Master clock and Bit clock ratios
30 #define WM8727_RATES (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 |\
31 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 |\
32 SNDRV_PCM_RATE_192000)
35 struct snd_soc_dai wm8727_dai
= {
38 .stream_name
= "Playback",
41 .rates
= WM8727_RATES
,
42 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S24_LE
,
45 EXPORT_SYMBOL_GPL(wm8727_dai
);
47 static struct snd_soc_codec
*wm8727_codec
;
49 static int wm8727_soc_probe(struct platform_device
*pdev
)
51 struct snd_soc_device
*socdev
= platform_get_drvdata(pdev
);
54 BUG_ON(!wm8727_codec
);
56 socdev
->card
->codec
= wm8727_codec
;
59 ret
= snd_soc_new_pcms(socdev
, SNDRV_DEFAULT_IDX1
, SNDRV_DEFAULT_STR1
);
61 printk(KERN_ERR
"wm8727: failed to create pcms\n");
68 kfree(socdev
->card
->codec
);
69 socdev
->card
->codec
= NULL
;
73 static int wm8727_soc_remove(struct platform_device
*pdev
)
75 struct snd_soc_device
*socdev
= platform_get_drvdata(pdev
);
77 snd_soc_free_pcms(socdev
);
82 struct snd_soc_codec_device soc_codec_dev_wm8727
= {
83 .probe
= wm8727_soc_probe
,
84 .remove
= wm8727_soc_remove
,
86 EXPORT_SYMBOL_GPL(soc_codec_dev_wm8727
);
89 static __devinit
int wm8727_platform_probe(struct platform_device
*pdev
)
91 struct snd_soc_codec
*codec
;
95 dev_err(&pdev
->dev
, "Another WM8727 is registered\n");
99 codec
= kzalloc(sizeof(struct snd_soc_codec
), GFP_KERNEL
);
102 wm8727_codec
= codec
;
104 platform_set_drvdata(pdev
, codec
);
106 mutex_init(&codec
->mutex
);
107 codec
->dev
= &pdev
->dev
;
108 codec
->name
= "WM8727";
109 codec
->owner
= THIS_MODULE
;
110 codec
->dai
= &wm8727_dai
;
112 INIT_LIST_HEAD(&codec
->dapm_widgets
);
113 INIT_LIST_HEAD(&codec
->dapm_paths
);
115 wm8727_dai
.dev
= &pdev
->dev
;
117 ret
= snd_soc_register_codec(codec
);
119 dev_err(&pdev
->dev
, "Failed to register CODEC: %d\n", ret
);
123 ret
= snd_soc_register_dai(&wm8727_dai
);
125 dev_err(&pdev
->dev
, "Failed to register DAI: %d\n", ret
);
130 snd_soc_unregister_codec(codec
);
136 static int __devexit
wm8727_platform_remove(struct platform_device
*pdev
)
138 snd_soc_unregister_dai(&wm8727_dai
);
139 snd_soc_unregister_codec(platform_get_drvdata(pdev
));
143 static struct platform_driver wm8727_codec_driver
= {
145 .name
= "wm8727-codec",
146 .owner
= THIS_MODULE
,
149 .probe
= wm8727_platform_probe
,
150 .remove
= __devexit_p(wm8727_platform_remove
),
153 static int __init
wm8727_init(void)
155 return platform_driver_register(&wm8727_codec_driver
);
157 module_init(wm8727_init
);
159 static void __exit
wm8727_exit(void)
161 platform_driver_unregister(&wm8727_codec_driver
);
163 module_exit(wm8727_exit
);
165 MODULE_DESCRIPTION("ASoC wm8727 driver");
166 MODULE_AUTHOR("Neil Jones");
167 MODULE_LICENSE("GPL");