blob: b3b60dd7bc14d8958beaaaea663f0b3689ea7b7c [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>
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>
24
25#include "wm8727.h"
26/*
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
29 */
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)
33
34
35struct snd_soc_dai wm8727_dai = {
36 .name = "WM8727",
37 .playback = {
38 .stream_name = "Playback",
39 .channels_min = 2,
40 .channels_max = 2,
41 .rates = WM8727_RATES,
42 .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE,
43 },
44};
45EXPORT_SYMBOL_GPL(wm8727_dai);
46
47static int wm8727_soc_probe(struct platform_device *pdev)
48{
49 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
50 struct snd_soc_codec *codec;
51 int ret = 0;
52
53 codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
54 if (codec == NULL)
55 return -ENOMEM;
56 mutex_init(&codec->mutex);
57 codec->name = "WM8727";
58 codec->owner = THIS_MODULE;
59 codec->dai = &wm8727_dai;
60 codec->num_dai = 1;
61 socdev->card->codec = codec;
62 INIT_LIST_HEAD(&codec->dapm_widgets);
63 INIT_LIST_HEAD(&codec->dapm_paths);
64
65 /* register pcms */
66 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
67 if (ret < 0) {
68 printk(KERN_ERR "wm8727: failed to create pcms\n");
69 goto pcm_err;
70 }
71 /* register card */
72 ret = snd_soc_init_card(socdev);
73 if (ret < 0) {
74 printk(KERN_ERR "wm8727: failed to register card\n");
75 goto register_err;
76 }
77
78 return ret;
79
80register_err:
81 snd_soc_free_pcms(socdev);
82pcm_err:
83 kfree(socdev->card->codec);
84 socdev->card->codec = NULL;
85 return ret;
86}
87
88static int wm8727_soc_remove(struct platform_device *pdev)
89{
90 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
91 struct snd_soc_codec *codec = socdev->card->codec;
92
93 if (codec == NULL)
94 return 0;
95 snd_soc_free_pcms(socdev);
96 kfree(codec);
97 return 0;
98}
99
100struct snd_soc_codec_device soc_codec_dev_wm8727 = {
101 .probe = wm8727_soc_probe,
102 .remove = wm8727_soc_remove,
103};
104EXPORT_SYMBOL_GPL(soc_codec_dev_wm8727);
105
106
107static __devinit int wm8727_platform_probe(struct platform_device *pdev)
108{
109 wm8727_dai.dev = &pdev->dev;
110 return snd_soc_register_dai(&wm8727_dai);
111}
112
113static int __devexit wm8727_platform_remove(struct platform_device *pdev)
114{
115 snd_soc_unregister_dai(&wm8727_dai);
116 return 0;
117}
118
119struct platform_driver wm8727_codec_driver = {
120 .driver = {
121 .name = "wm8727-codec",
122 .owner = THIS_MODULE,
123 },
124
125 .probe = wm8727_platform_probe,
126 .remove = __devexit_p(wm8727_platform_remove),
127};
128
129static int __init wm8727_init(void)
130{
131 return platform_driver_register(&wm8727_codec_driver);
132}
133module_init(wm8727_init);
134
135static void __exit wm8727_exit(void)
136{
137 platform_driver_unregister(&wm8727_codec_driver);
138}
139module_exit(wm8727_exit);
140
141MODULE_DESCRIPTION("ASoC wm8727 driver");
142MODULE_AUTHOR("Neil Jones");
143MODULE_LICENSE("GPL");