2 * ALSA SoC CX20709 Channel codec driver
4 * Copyright: (C) 2009/2010 Conexant Systems
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
13 *************************************************************************
14 * Modified Date: 12/01/11
15 * File Version: 2.26.35.11
16 *************************************************************************
19 #include <linux/module.h>
20 #include <linux/moduleparam.h>
21 #include <linux/module.h> /* Specifically, a module */
23 #include <asm/uaccess.h> /* for get_user and put_user */
24 //#include <sound/core.h>
25 //#include <sound/pcm.h>
26 //#include <sound/pcm_params.h>
27 #include <sound/soc.h>
28 //#include <sound/soc-dapm.h>
29 #include <linux/gpio.h>
30 #include <linux/slab.h>
36 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
37 #include <linux/i2c.h>
40 #if defined(CONFIG_SPI_MASTER)
41 #include <linux/spi/spi.h>
47 * Is the device open right now? Used to prevent
48 * concurent access into the same device
50 static int Device_Open = 0;
51 extern int CX_AUDDRV_VERSION;
52 struct snd_soc_codec *g_codec = NULL;
55 * This is called whenever a process attempts to open the device file
57 static int cxdbg_dev_open(struct inode *inode, struct file *file)
60 printk(KERN_INFO "cxdbg_dev: device_open(%p)\n", file);
64 * We don't want to talk to two processes at the same time
71 * Initialize the message
74 // try_module_get(THIS_MODULE);
79 * This is called whenever a process attempts to open the device file
81 static int cxdbg_dev_release(struct inode *inode, struct file *file)
84 printk(KERN_INFO "cxdbg_dev: device_release(%p)\n", file);
90 * Initialize the message
95 static int codec_reg_write(struct CXDBG_IODATA *reg)
100 BUG_ON(!g_codec->hw_write);
102 if(g_codec&& g_codec->hw_write)
104 if( g_codec->hw_write(g_codec,(char*)reg->data,reg->len)
108 printk(KERN_ERR "cxdbg_dev: codec_reg_write failed\n");
114 printk(KERN_ERR "cxdbg_dev: codec_reg_write failed, device is not ready.\n");
119 static unsigned int codec_reg_read(struct CXDBG_IODATA *reg)
122 unsigned int regaddr;
127 BUG_ON(!g_codec->hw_read);
131 regaddr = (((unsigned int)reg->data[0])<<8) + reg->data[1];
133 else if (reg->len == 1)
135 regaddr = (unsigned int)reg->data[0];
139 printk(KERN_ERR "cxdbg_dev: codec_reg_read failed, invalid parameter.\n");
142 memset(reg,0,sizeof(*reg));
143 if(g_codec && g_codec->hw_read)
145 data = g_codec->hw_read(g_codec,regaddr);
146 reg->data[0] = data & 0xFF;
152 printk(KERN_ERR "cxdbg_dev: codec_reg_read failed, device is not ready.\n");
158 long cxdbg_dev_ioctl(struct file * file, unsigned int cmd, unsigned long arg)
160 struct CXDBG_IODATA *reg=NULL ;
161 int __user *ip = (int __user*) arg;
164 printk(KERN_INFO "cxdbg_dev: ioctl, cmd=0x%02x, arg=0x%02lx\n", cmd, arg);
168 * Switch according to the ioctl called
171 case CXDBG_IOCTL_REG_SET:
172 reg = (struct CXDBG_IODATA*) kmalloc(sizeof(*reg),GFP_KERNEL);
173 err = copy_from_user((char*) reg, (char*)arg,sizeof(*reg));
176 codec_reg_write(reg);
180 case CXDBG_IOCTL_REG_GET:
181 reg = (struct CXDBG_IODATA*) kmalloc(sizeof(*reg),GFP_KERNEL);
182 err =copy_from_user((char*) reg, (char*)arg,sizeof(*reg));
186 err = copy_to_user((char*) arg, (char*)reg,sizeof(*reg));
189 case CXDBG_IOCTL_PDRIVER_VERSION:
190 err = put_user(CX_AUDDRV_VERSION,ip);
205 #if defined(_MSC_VER)
206 static const struct file_operations cxdbg_dev_fops =
208 /*.owner = */THIS_MODULE,
216 /*ioctl*/ NULL /*i2cdev_ioctl*/,
217 /*.unlocked_ioctl*/cxdbg_dev_ioctl,
218 /*.compat_ioctl*/NULL,
220 /*.open*/cxdbg_dev_open,
230 static const struct file_operations cxdbg_dev_fops = {
231 .owner = THIS_MODULE,
232 .unlocked_ioctl = cxdbg_dev_ioctl,
233 .open = cxdbg_dev_open,
234 .release = cxdbg_dev_release,
240 * Initialize the module - Register the character device
242 int cxdbg_dev_init(struct snd_soc_codec *socdev)
245 printk(KERN_INFO "cxdbg_dev: entries driver\n");
249 err = register_chrdev(CXDBG_MAJOR, CXDBG_DEVICE_NAME, &cxdbg_dev_fops);
252 printk(KERN_ERR "cxdbg_dev: Driver Initialisation failed\n");
257 void cxdbg_dev_exit(void)
259 unregister_chrdev(CXDBG_MAJOR,CXDBG_DEVICE_NAME);
263 MODULE_AUTHOR("Simon Ho<simon.ho@conexant.com");
264 MODULE_DESCRIPTION("debug driver");
265 MODULE_LICENSE("GPL");