blob: 9d1df26281361ef9ed569e0b87a39d9a934f9254 [file] [log] [blame]
Neil Jones89933de2009-11-02 15:14:17 +00001/*
2 * wm8727.c
3 *
4 * Created on: 15-Oct-2009
5 * Author: neil.jones@imgtec.com
6 *
7 * Copyright (C) 2009 Imagination Technologies Ltd.
8 *
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.
13 */
14
15#include <linux/init.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090016#include <linux/slab.h>
Neil Jones89933de2009-11-02 15:14:17 +000017#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>
25
26#include "wm8727.h"
27/*
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
30 */
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)
34
35
36struct snd_soc_dai wm8727_dai = {
37 .name = "WM8727",
38 .playback = {
39 .stream_name = "Playback",
40 .channels_min = 2,
41 .channels_max = 2,
42 .rates = WM8727_RATES,
43 .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE,
44 },
45};
46EXPORT_SYMBOL_GPL(wm8727_dai);
47
Mark Browncce2e9d2009-12-08 21:50:01 +000048static struct snd_soc_codec *wm8727_codec;
49
Neil Jones89933de2009-11-02 15:14:17 +000050static int wm8727_soc_probe(struct platform_device *pdev)
51{
52 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
Neil Jones89933de2009-11-02 15:14:17 +000053 int ret = 0;
54
Mark Browncce2e9d2009-12-08 21:50:01 +000055 BUG_ON(!wm8727_codec);
56
57 socdev->card->codec = wm8727_codec;
Neil Jones89933de2009-11-02 15:14:17 +000058
59 /* register pcms */
60 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
61 if (ret < 0) {
62 printk(KERN_ERR "wm8727: failed to create pcms\n");
63 goto pcm_err;
64 }
Neil Jones89933de2009-11-02 15:14:17 +000065
66 return ret;
67
Neil Jones89933de2009-11-02 15:14:17 +000068pcm_err:
69 kfree(socdev->card->codec);
70 socdev->card->codec = NULL;
71 return ret;
72}
73
74static int wm8727_soc_remove(struct platform_device *pdev)
75{
76 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
Neil Jones89933de2009-11-02 15:14:17 +000077
Neil Jones89933de2009-11-02 15:14:17 +000078 snd_soc_free_pcms(socdev);
Mark Browncce2e9d2009-12-08 21:50:01 +000079
Neil Jones89933de2009-11-02 15:14:17 +000080 return 0;
81}
82
83struct snd_soc_codec_device soc_codec_dev_wm8727 = {
84 .probe = wm8727_soc_probe,
85 .remove = wm8727_soc_remove,
86};
87EXPORT_SYMBOL_GPL(soc_codec_dev_wm8727);
88
89
90static __devinit int wm8727_platform_probe(struct platform_device *pdev)
91{
Mark Browncce2e9d2009-12-08 21:50:01 +000092 struct snd_soc_codec *codec;
93 int ret;
94
95 if (wm8727_codec) {
96 dev_err(&pdev->dev, "Another WM8727 is registered\n");
97 return -EBUSY;
98 }
99
100 codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
101 if (codec == NULL)
102 return -ENOMEM;
103 wm8727_codec = codec;
104
105 platform_set_drvdata(pdev, codec);
106
107 mutex_init(&codec->mutex);
108 codec->dev = &pdev->dev;
109 codec->name = "WM8727";
110 codec->owner = THIS_MODULE;
111 codec->dai = &wm8727_dai;
112 codec->num_dai = 1;
113 INIT_LIST_HEAD(&codec->dapm_widgets);
114 INIT_LIST_HEAD(&codec->dapm_paths);
115
Neil Jones89933de2009-11-02 15:14:17 +0000116 wm8727_dai.dev = &pdev->dev;
Mark Browncce2e9d2009-12-08 21:50:01 +0000117
118 ret = snd_soc_register_codec(codec);
119 if (ret != 0) {
120 dev_err(&pdev->dev, "Failed to register CODEC: %d\n", ret);
121 goto err;
122 }
123
124 ret = snd_soc_register_dai(&wm8727_dai);
125 if (ret != 0) {
126 dev_err(&pdev->dev, "Failed to register DAI: %d\n", ret);
127 goto err_codec;
128 }
129
Axel Linc555b022010-07-14 18:57:31 +0800130 return 0;
131
Mark Browncce2e9d2009-12-08 21:50:01 +0000132err_codec:
133 snd_soc_unregister_codec(codec);
134err:
135 kfree(codec);
136 return ret;
Neil Jones89933de2009-11-02 15:14:17 +0000137}
138
139static int __devexit wm8727_platform_remove(struct platform_device *pdev)
140{
141 snd_soc_unregister_dai(&wm8727_dai);
Mark Browncce2e9d2009-12-08 21:50:01 +0000142 snd_soc_unregister_codec(platform_get_drvdata(pdev));
Neil Jones89933de2009-11-02 15:14:17 +0000143 return 0;
144}
145
Mark Brown529697c2009-11-03 22:13:30 +0000146static struct platform_driver wm8727_codec_driver = {
Neil Jones89933de2009-11-02 15:14:17 +0000147 .driver = {
148 .name = "wm8727-codec",
149 .owner = THIS_MODULE,
150 },
151
152 .probe = wm8727_platform_probe,
153 .remove = __devexit_p(wm8727_platform_remove),
154};
155
156static int __init wm8727_init(void)
157{
158 return platform_driver_register(&wm8727_codec_driver);
159}
160module_init(wm8727_init);
161
162static void __exit wm8727_exit(void)
163{
164 platform_driver_unregister(&wm8727_codec_driver);
165}
166module_exit(wm8727_exit);
167
168MODULE_DESCRIPTION("ASoC wm8727 driver");
169MODULE_AUTHOR("Neil Jones");
170MODULE_LICENSE("GPL");