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/slab.h>
17 #include <linux/module.h>
18 #include <linux/kernel.h>
19 #include <linux/device.h>
20 #include <sound/core.h>
21 #include <sound/pcm.h>
22 #include <sound/ac97_codec.h>
23 #include <sound/initval.h>
24 #include <sound/soc.h>
28 * Note this is a simple chip with no configuration interface, sample rate is
29 * determined automatically by examining the Master clock and Bit clock ratios
31 #define WM8727_RATES (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 |\
32 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 |\
33 SNDRV_PCM_RATE_192000)
36 struct snd_soc_dai wm8727_dai
= {
39 .stream_name
= "Playback",
42 .rates
= WM8727_RATES
,
43 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S24_LE
,
46 EXPORT_SYMBOL_GPL(wm8727_dai
);
48 static struct snd_soc_codec
*wm8727_codec
;
50 static int wm8727_soc_probe(struct platform_device
*pdev
)
52 struct snd_soc_device
*socdev
= platform_get_drvdata(pdev
);
55 BUG_ON(!wm8727_codec
);
57 socdev
->card
->codec
= wm8727_codec
;
60 ret
= snd_soc_new_pcms(socdev
, SNDRV_DEFAULT_IDX1
, SNDRV_DEFAULT_STR1
);
62 printk(KERN_ERR
"wm8727: failed to create pcms\n");
69 kfree(socdev
->card
->codec
);
70 socdev
->card
->codec
= NULL
;
74 static int wm8727_soc_remove(struct platform_device
*pdev
)
76 struct snd_soc_device
*socdev
= platform_get_drvdata(pdev
);
78 snd_soc_free_pcms(socdev
);
83 struct snd_soc_codec_device soc_codec_dev_wm8727
= {
84 .probe
= wm8727_soc_probe
,
85 .remove
= wm8727_soc_remove
,
87 EXPORT_SYMBOL_GPL(soc_codec_dev_wm8727
);
90 static __devinit
int wm8727_platform_probe(struct platform_device
*pdev
)
92 struct snd_soc_codec
*codec
;
96 dev_err(&pdev
->dev
, "Another WM8727 is registered\n");
100 codec
= kzalloc(sizeof(struct snd_soc_codec
), GFP_KERNEL
);
103 wm8727_codec
= codec
;
105 platform_set_drvdata(pdev
, codec
);
107 mutex_init(&codec
->mutex
);
108 codec
->dev
= &pdev
->dev
;
109 codec
->name
= "WM8727";
110 codec
->owner
= THIS_MODULE
;
111 codec
->dai
= &wm8727_dai
;
113 INIT_LIST_HEAD(&codec
->dapm_widgets
);
114 INIT_LIST_HEAD(&codec
->dapm_paths
);
116 wm8727_dai
.dev
= &pdev
->dev
;
118 ret
= snd_soc_register_codec(codec
);
120 dev_err(&pdev
->dev
, "Failed to register CODEC: %d\n", ret
);
124 ret
= snd_soc_register_dai(&wm8727_dai
);
126 dev_err(&pdev
->dev
, "Failed to register DAI: %d\n", ret
);
131 snd_soc_unregister_codec(codec
);
137 static int __devexit
wm8727_platform_remove(struct platform_device
*pdev
)
139 snd_soc_unregister_dai(&wm8727_dai
);
140 snd_soc_unregister_codec(platform_get_drvdata(pdev
));
144 static struct platform_driver wm8727_codec_driver
= {
146 .name
= "wm8727-codec",
147 .owner
= THIS_MODULE
,
150 .probe
= wm8727_platform_probe
,
151 .remove
= __devexit_p(wm8727_platform_remove
),
154 static int __init
wm8727_init(void)
156 return platform_driver_register(&wm8727_codec_driver
);
158 module_init(wm8727_init
);
160 static void __exit
wm8727_exit(void)
162 platform_driver_unregister(&wm8727_codec_driver
);
164 module_exit(wm8727_exit
);
166 MODULE_DESCRIPTION("ASoC wm8727 driver");
167 MODULE_AUTHOR("Neil Jones");
168 MODULE_LICENSE("GPL");