summaryrefslogtreecommitdiff
path: root/sound/soc/codecs/aic326x_tiload.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/soc/codecs/aic326x_tiload.c')
-rw-r--r--sound/soc/codecs/aic326x_tiload.c231
1 files changed, 122 insertions, 109 deletions
diff --git a/sound/soc/codecs/aic326x_tiload.c b/sound/soc/codecs/aic326x_tiload.c
index 07615dc5ebd7..781a6cb3456e 100644
--- a/sound/soc/codecs/aic326x_tiload.c
+++ b/sound/soc/codecs/aic326x_tiload.c
@@ -16,9 +16,9 @@
*
* History:
*
- * Rev 0.1 Tiload support 16-09-2010
+ * Rev 0.1 Tiload support TI 16-09-2010
*
- * The Tiload programming support is added to AIC3262.
+ * The Tiload programming support is added to AIC3262.
*
*/
@@ -37,16 +37,21 @@
#include <linux/platform_device.h>
#include <sound/soc.h>
#include <sound/control.h>
+#include <linux/switch.h>
+#include <sound/jack.h>
+#include <linux/irq.h>
+#include <linux/interrupt.h>
+#include <linux/mfd/tlv320aic3262-core.h>
#include "tlv320aic326x.h"
#include "aic326x_tiload.h"
/* enable debug prints in the driver */
-#define DEBUG
-//#undef DEBUG
+/*#define DEBUG */
+#undef DEBUG
#ifdef DEBUG
-#define dprintk(x...) printk(x)
+#define dprintk(x...) printk(x)
#else
#define dprintk(x...)
#endif
@@ -58,17 +63,12 @@
static void aic3262_dump_page(struct i2c_client *i2c, u8 page);
#endif
-/* externs */
-extern int aic3262_change_page(struct snd_soc_codec *codec, u8 new_page);
-extern int aic3262_change_book(struct snd_soc_codec *codec, u8 new_book);
-extern int aic3262_write(struct snd_soc_codec *codec, unsigned int reg,
- unsigned int value);
-int aic3262_driver_init(struct snd_soc_codec *codec);
/************** Dynamic aic3262 driver, TI LOAD support ***************/
static struct cdev *aic3262_cdev;
-static int aic3262_major = 0; /* Dynamic allocation of Mjr No. */
-static int aic3262_opened = 0; /* Dynamic allocation of Mjr No. */
+static union aic326x_reg_union aic_reg;
+static int aic3262_major; /* Dynamic allocation of Mjr No. */
+static int aic3262_opened; /* Dynamic allocation of Mjr No. */
static struct snd_soc_codec *aic3262_codec;
struct class *tiload_class;
static unsigned int magic_num = 0xE0;
@@ -77,10 +77,12 @@ static unsigned int magic_num = 0xE0;
#ifdef REG_DUMP_aic3262
/*
- *----------------------------------------------------------------------------
- * Function : aic3262_dump_page
- * Purpose : Read and display one codec register page, for debugging purpose
- *----------------------------------------------------------------------------
+ * aic3262_dump_page: Read and display one codec register page, for
+ debugging purpose
+ * @i2c; i2c_client identifies a single device (i.e. aic3262) connected
+ to an i2c bus.
+ * @page: page number
+ *
*/
static void aic3262_dump_page(struct i2c_client *i2c, u8 page)
{
@@ -88,103 +90,99 @@ static void aic3262_dump_page(struct i2c_client *i2c, u8 page)
u8 data;
u8 test_page_array[8];
- dprintk("TiLoad DRIVER : %s\n", __FUNCTION__);
- aic3262_change_page(codec, page);
+ dprintk("TiLoad DRIVER : %s\n", __func__);
data = 0x0;
-
i2c_master_send(i2c, data, 1);
i2c_master_recv(i2c, test_page_array, 8);
- printk("\n------- aic3262 PAGE %d DUMP --------\n", page);
- for (i = 0; i < 8; i++) {
- printk(" [ %d ] = 0x%x\n", i, test_page_array[i]);
- }
+ dprintk("\n------- aic3262 PAGE %d DUMP --------\n", page);
+ for (i = 0; i < 8; i++)
+ dprintk(" [ %d ] = 0x%x\n", i, test_page_array[i]);
}
#endif
-/*
- *----------------------------------------------------------------------------
- * Function : tiload_open
+/**
+ * tiload_open: open method for aic3262-tiload programming interface
+ * @in: Pointer to inode
+ * @filp: pointer to file
*
- * Purpose : open method for aic3262-tiload programming interface
- *----------------------------------------------------------------------------
+ * Return: Return 0 if success.
*/
static int tiload_open(struct inode *in, struct file *filp)
{
- dprintk("TiLoad DRIVER : %s\n", __FUNCTION__);
+ dprintk("TiLoad DRIVER : %s\n", __func__);
if (aic3262_opened) {
- printk("%s device is already opened\n", "aic3262");
- printk("%s: only one instance of driver is allowed\n",
- "aic3262");
+ dprintk("%s device is already opened\n", "aic3262");
+ dprintk("%s: only one instance of driver is allowed\n",
+ "aic3262");
return -1;
}
aic3262_opened++;
return 0;
}
-/*
- *----------------------------------------------------------------------------
- * Function : tiload_release
+/**
+ * tiload_release close method for aic3262_tilaod programming interface
+ * @in: Pointer to inode
+ * @filp: pointer to file
*
- * Purpose : close method for aic3262_tilaod programming interface
- *----------------------------------------------------------------------------
+ * Return: Return 0 if success.
*/
static int tiload_release(struct inode *in, struct file *filp)
{
- dprintk("TiLoad DRIVER : %s\n", __FUNCTION__);
+ dprintk("TiLoad DRIVER : %s\n", __func__);
aic3262_opened--;
return 0;
}
-/*
- *----------------------------------------------------------------------------
- * Function : tiload_read
+/**
+ * tiload_read: read method for mini dsp programming interface
+ * @file: pointer to file
+ * @buf: pointer to user
+ * @count: number of byte to be read
+ * @offset: offset address
*
- * Purpose : read method for mini dsp programming interface
- *----------------------------------------------------------------------------
+ * Return: return value read
*/
-static ssize_t tiload_read(struct file *file, char __user * buf,
- size_t count, loff_t * offset)
+static ssize_t tiload_read(struct file *file, char __user *buf,
+ size_t count, loff_t *offset)
{
- static char rd_data[8];
+ static char rd_data[128];
char reg_addr;
size_t size;
- #ifdef DEBUG
+#ifdef DEBUG
int i;
- #endif
- struct i2c_client *i2c = aic3262_codec->control_data;
+#endif
+ struct aic3262 *control = aic3262_codec->control_data;
- dprintk("TiLoad DRIVER : %s\n", __FUNCTION__);
+ dprintk("TiLoad DRIVER : %s\n", __func__);
if (count > 128) {
- printk("Max 128 bytes can be read\n");
+ dprintk("Max 128 bytes can be read\n");
count = 128;
}
/* copy register address from user space */
size = copy_from_user(&reg_addr, buf, 1);
if (size != 0) {
- printk("read: copy_from_user failure\n");
+ dprintk("read: copy_from_user failure\n");
return -1;
}
/* Send the address to device thats is to be read */
- if (i2c_master_send(i2c, &reg_addr, 1) != 1) {
- dprintk("Can not write register address\n");
- return -1;
- }
- /* read the codec device registers */
- size = i2c_master_recv(i2c, rd_data, count);
+ aic_reg.aic326x_register.offset = reg_addr;
+ size =
+ aic3262_bulk_read(control, aic_reg.aic326x_register_int, count,
+ rd_data);
+
#ifdef DEBUG
- printk(KERN_ERR "read size = %d, reg_addr= %x , count = %d\n",
- (int)size, reg_addr, (int)count);
- for (i = 0; i < (int)size; i++) {
- printk(KERN_ERR "rd_data[%d]=%x\n", i, rd_data[i]);
- }
+ pr_err(KERN_ERR "read size = %d, reg_addr= %x , count = %d\n",
+ (int)size, reg_addr, (int)count);
+ for (i = 0; i < (int)size; i++)
+ dprintk("rd_data[%d]=%x\n", i, rd_data[i]);
#endif
- if (size != count) {
- printk("read %d registers from the codec\n", size);
- }
+ if (size != count)
+ dprintk("read %d registers from the codec\n", size);
if (copy_to_user(buf, rd_data, size) != 0) {
dprintk("copy_to_user failed\n");
@@ -194,58 +192,71 @@ static ssize_t tiload_read(struct file *file, char __user * buf,
return size;
}
-/*
- *----------------------------------------------------------------------------
- * Function : tiload_write
+/**
+ * tiload_write: write method for aic3262_tiload programming interface
+ * @file: pointer to file
+ * @buf: pointer to user
+ * @count: number of byte to be read
+ * @offset: offset address
*
- * Purpose : write method for aic3262_tiload programming interface
- *----------------------------------------------------------------------------
+ * Return: return byte written
*/
-static ssize_t tiload_write(struct file *file, const char __user * buf,
- size_t count, loff_t * offset)
+static ssize_t tiload_write(struct file *file, const char __user *buf,
+ size_t count, loff_t *offset)
{
- static char wr_data[8];
- u8 pg_no;
- #ifdef DEBUG
+ static char wr_data[128];
+#ifdef DEBUG
int i;
- #endif
- struct i2c_client *i2c = aic3262_codec->control_data;
- struct aic3262_priv *aic3262_private = snd_soc_codec_get_drvdata(aic3262_codec);
+#endif
+ struct aic3262 *control = aic3262_codec->control_data;
- dprintk("TiLoad DRIVER : %s\n", __FUNCTION__);
+ dprintk("TiLoad DRIVER : %s\n", __func__);
/* copy buffer from user space */
if (copy_from_user(wr_data, buf, count)) {
- printk("copy_from_user failure\n");
+ dprintk("copy_from_user failure\n");
return -1;
}
#ifdef DEBUG
- printk(KERN_ERR "write size = %d\n", (int)count);
- for (i = 0; i < (int)count; i++) {
- printk(KERN_INFO "\nwr_data[%d]=%x\n", i, wr_data[i]);
- }
+ dprintk("write size = %d\n", (int)count);
+ for (i = 0; i < (int)count; i++)
+ dprintk("\nwr_data[%d]=%x\n", i, wr_data[i]);
#endif
if (wr_data[0] == 0) {
- aic3262_change_page(aic3262_codec, wr_data[1]);
+ /*change of page seen, but will only be registered */
+ aic_reg.aic326x_register.page = wr_data[1];
+ return count;
+
+ } else
+ if (wr_data[0] == 127) {
+ /* change of book seen, but will not be sent for I2C write */
+ aic_reg.aic326x_register.book = wr_data[1];
return count;
- }
- pg_no = aic3262_private->page_no;
- if ((wr_data[0] == 127) && (pg_no == 0)) {
- aic3262_change_book(aic3262_codec, wr_data[1]);
+ } else {
+ aic_reg.aic326x_register.offset = wr_data[0];
+ aic3262_bulk_write(control, aic_reg.aic326x_register_int,
+ count - 1, &wr_data[1]);
return count;
}
- return i2c_master_send(i2c, wr_data, count);
}
-static long tiload_ioctl(struct file *filp,
- unsigned int cmd, unsigned long arg)
+/**
+ * tiload_ioctl: copy data to user and from user
+ * @filp: pointer to file
+ * @cmd: integer of type command
+ * @arg: argument type
+ *
+ * Return: Return 0 on success
+ */
+static long tiload_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
{
int num = 0;
void __user *argp = (void __user *)arg;
+
if (_IOC_TYPE(cmd) != aic3262_IOC_MAGIC)
return -ENOTTY;
- dprintk("TiLoad DRIVER : %s\n", __FUNCTION__);
+ dprintk("TiLoad DRIVER : %s\n", __func__);
switch (cmd) {
case aic3262_IOMAGICNUM_GET:
num = copy_to_user(argp, &magic_num, sizeof(int));
@@ -257,7 +268,7 @@ static long tiload_ioctl(struct file *filp,
return num;
}
-/*********** File operations structure for aic3262-tiload programming *************/
+/******* File operations structure for aic3262-tiload programming *********/
static struct file_operations aic3262_fops = {
.owner = THIS_MODULE,
.open = tiload_open,
@@ -267,46 +278,48 @@ static struct file_operations aic3262_fops = {
.unlocked_ioctl = tiload_ioctl,
};
-/*
- *----------------------------------------------------------------------------
- * Function : aic3262_driver_init
+/**
+ * aic3262_driver_init: Register a char driver for dynamic aic3262-tiload programming
+ * @codec: pointer variable to codec having codec information
*
- * Purpose : Register a char driver for dynamic aic3262-tiload programming
- *----------------------------------------------------------------------------
+ * Return: Return 0 on seccess
*/
int aic3262_driver_init(struct snd_soc_codec *codec)
{
int result;
dev_t dev = MKDEV(aic3262_major, 0);
- printk("TiLoad DRIVER : %s\n", __FUNCTION__);
+ dprintk("TiLoad DRIVER : %s\n", __func__);
aic3262_codec = codec;
- printk("allocating dynamic major number\n");
+ dprintk("allocating dynamic major number\n");
result = alloc_chrdev_region(&dev, 0, 1, DEVICE_NAME);
if (result < 0) {
- printk("cannot allocate major number %d\n", aic3262_major);
+ dprintk("cannot allocate major number %d\n", aic3262_major);
return result;
}
+
tiload_class = class_create(THIS_MODULE, DEVICE_NAME);
aic3262_major = MAJOR(dev);
- printk("allocated Major Number: %d\n", aic3262_major);
+ dprintk("allocated Major Number: %d\n", aic3262_major);
aic3262_cdev = cdev_alloc();
cdev_init(aic3262_cdev, &aic3262_fops);
aic3262_cdev->owner = THIS_MODULE;
aic3262_cdev->ops = &aic3262_fops;
+ aic_reg.aic326x_register.page = 0;
+ aic_reg.aic326x_register.book = 0;
+
if (cdev_add(aic3262_cdev, dev, 1) < 0) {
- dprintk("aic3262_driver: cdev_add failed \n");
+ dprintk("aic3262_driver: cdev_add failed\n");
unregister_chrdev_region(dev, 1);
aic3262_cdev = NULL;
return 1;
}
- printk("Registered aic3262 TiLoad driver, Major number: %d \n",
- aic3262_major);
- //class_device_create(tiload_class, NULL, dev, NULL, DEVICE_NAME, 0);
+ dprintk("Registered aic3262 TiLoad driver, Major number: %d\n",
+ aic3262_major);
return 0;
}