📄 wm8782.c
字号:
/* ========================================================================== *//* *//* wm8782.c *//* (c) 2007 Author *//* *//* Description *//* *//* ========================================================================== */#include <linux/module.h>#include <linux/moduleparam.h>#include <linux/init.h>#include <linux/delay.h>#include <linux/pm.h>#include <linux/i2c.h>#include <linux/platform_device.h>#include <sound/driver.h>#include <sound/core.h>#include <sound/pcm.h>#include <sound/pcm_params.h>#include <sound/initval.h>#include <sound/control.h>#include <linux/miscdevice.h>#include "wm8782.h"#include "mxc-pcm.h"#include "wm8782-mixer.h"#define AUDIO_NAME "wm8782"#define WM8782_VERSION "0.1"#define __WM8782_PM__#define WM8782_READ_REG 0x1#define WM8782_WRITE_REG 0x2mx27_codec_t * mx27_codec = NULL;extern int mx27_codec_pcm_init (mx27_codec_t* codec, int device);#define WM8782_DEBUG 0#ifdef WM8782_DEBUG#define dbg(format, arg...) \ printk(KERN_DEBUG AUDIO_NAME ": " format "\n" , ## arg)#else#define dbg(format, arg...) do {} while (0)#endif#define err(format, arg...) \ printk(KERN_ERR AUDIO_NAME ": " format "\n" , ## arg)#define info(format, arg...) \ printk(KERN_INFO AUDIO_NAME ": " format "\n" , ## arg)#define warn(format, arg...) \ printk(KERN_WARNING AUDIO_NAME ": " format "\n" , ## arg)static struct wm8782_platform_data wm8782_data ={};static int wm8782_open(struct inode * node ,struct file *file){ printk("%s successful\n",__FUNCTION__); return 0;}static int wm8782_close(struct inode * node ,struct file *file){ printk("%s successful\n",__FUNCTION__); return 0;}static int wm8782_ioctl(struct inode *inode, struct file *file,unsigned int cmd, unsigned long arg){ return 0;}static const struct file_operations wm8782_fops = { .owner = THIS_MODULE, .open = wm8782_open, .release = wm8782_close, .ioctl = wm8782_ioctl,};#define WM8782_MINOR 100static struct miscdevice wm8782_codec = { WM8782_MINOR , "wm8782_codec", &wm8782_fops,};#ifdef CONFIG_PMstatic int wm8782_suspend(struct platform_device *pdev, pm_message_t state){ return 0;}static int wm8782_resume(struct platform_device *pdev){ return 0;}#else#define wm8782_suspend NULL#define wm8782_resume NULL#endifstatic void wm8782_codec_free (struct snd_card *card){ card->private_data = NULL;}static int wm8782_card_new(void){ int result; struct snd_card * card; printk("zd: wm8782_card_new start!\n"); card = snd_card_new (-1, "mxc-wm8782", THIS_MODULE, sizeof (mx27_codec_t*)); if (card == NULL) return -ENOMEM; card->private_data = mx27_codec; card->private_free = wm8782_codec_free; mx27_codec->card = card; mx27_codec->pdata = &wm8782_data; result = mx27_codec_pcm_init (mx27_codec, 0); if (result < 0) goto fail; strcpy(card->driver, "MXC"); strcpy(card->shortname, "WM8782 codec"); sprintf(card->longname, "WM8782 codec ALSA driver for freescale i.mx27"); result = snd_card_register(card); if (result < 0) goto fail; return 0; fail: snd_card_free (card); return result;}static int wm8782_probe(struct platform_device *pdev){ struct wm8782_platform_data * pdata = pdev->dev.platform_data; int ret; info("WM8782 Audio Codec %s", WM8782_VERSION); mx27_codec = kcalloc (1, sizeof (mx27_codec_t), GFP_KERNEL); if (mx27_codec == NULL) return -ENOMEM; pdata->private_data=mx27_codec; ret=wm8782_card_new(); if(ret<0) { err("failed to initialise WM8782\n"); return -1; } return 0;}/* power down chip */static int wm8782_remove(struct platform_device *pdev){ struct wm8782_platform_data * pdata =(struct wm8782_platform_data *)pdev->dev.platform_data; mx27_codec_t * codec = (mx27_codec_t *)pdata->private_data; struct snd_card * card = codec->card; printk(KERN_INFO "%s\n",__FUNCTION__); snd_card_free(card); pdata->private_data=NULL; kfree(codec); return 0;}/*Device Definition for WM8782*/static void pdevice_release(struct device * dev){ return ;}static struct platform_device mxc_wm8782_device={ .name = "mxc_wm8782", .id = 0, .dev={ .platform_data =& wm8782_data, .release = pdevice_release, },};/*Driver Definition for WM8782*/static struct platform_driver mxc_wm8782_driver = { .driver = { .name = "mxc_wm8782", }, .probe = wm8782_probe, .remove = wm8782_remove, .suspend = wm8782_suspend, .resume = wm8782_resume,};static int __init mxc_wm8782_init(void){ int ret; if((ret=platform_device_register(&mxc_wm8782_device))< 0) { printk(KERN_ERR "Registering the wm8782 device failed \n"); return ret; } if((ret = platform_driver_register(&mxc_wm8782_driver))<0) { printk(KERN_ERR "Registering the wm8782 driver failed \n"); platform_device_unregister(&mxc_wm8782_device); return ret; } ret = misc_register(&wm8782_codec); if (ret) { printk("\tWM8782_ERROR: could not register wm8782 devices. \n"); return ret; } return 0;}static void __exit mxc_wm8782_exit(void){ platform_driver_unregister(&mxc_wm8782_driver); platform_device_unregister(&mxc_wm8782_device); misc_deregister(&wm8782_codec);}module_init(mxc_wm8782_init);module_exit(mxc_wm8782_exit);MODULE_DESCRIPTION("ASoC WM8782 driver");MODULE_AUTHOR("Richard Purdie");MODULE_LICENSE("GPL");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -