2 * Texas Instrumens TLV320AIC23 audio codec's i2c interface.
4 * Copyright (c) by Kai Svahn <kai.svahn@nokia.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <linux/config.h>
23 #include <linux/module.h>
24 #include <linux/init.h>
25 #include <linux/i2c.h>
26 #include <linux/slab.h>
28 #include <asm/arch/aic23.h>
30 #define TLV320AIC23_VERSION "0.1"
31 #define TLV320AIC23_DATE "12-Aug-2004"
33 /* I2C Addresses to scan */
34 static unsigned short normal_i2c[] = { TLV320AIC23ID1, TLV320AIC23ID2, I2C_CLIENT_END };
36 /* This makes all addr_data:s */
39 static struct i2c_driver tlv320aic23_driver;
40 static struct i2c_client *new_client;
41 //static struct i2c_client *client;
43 static int _tlv320aic23_write_value(struct i2c_client *client, u8 reg, u16 value)
47 /* TLV320AIC23 has 7 bit address and 9 bits of data
48 * so we need to switch one data bit into reg and rest
53 val = (0x01 & (value >> 8));
55 val = (0x00ff & value);
57 return i2c_smbus_write_byte_data(client, wreg, val);
60 int tlv320aic23_write_value(u8 reg, u16 value)
62 static struct i2c_client *client;
64 _tlv320aic23_write_value(client, reg, value);
69 static int tlv320aic23_detect_client(struct i2c_adapter *adapter, int address,
73 const char *client_name = "TLV320AIC23 Audio Codec";
75 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA |
76 I2C_FUNC_SMBUS_WRITE_BYTE)) {
77 printk(KERN_WARNING "%s functinality check failed\n", client_name);
81 if (!(new_client = kmalloc(sizeof(struct i2c_client),
84 printk(KERN_WARNING "Couldn't allocate memory for %s\n", client_name);
88 memset(new_client, 0x00, sizeof(struct i2c_client));
89 new_client->addr = address;
90 new_client->adapter = adapter;
91 new_client->driver = &tlv320aic23_driver;
92 new_client->flags = 0;
93 strlcpy(new_client->name, client_name, I2C_NAME_SIZE);
95 if ((err = i2c_attach_client(new_client))) {
96 printk(KERN_WARNING "Couldn't attach %s\n", client_name);
104 static int tlv320aic23_detach_client(struct i2c_client *client)
108 if ((err = i2c_detach_client(client))) {
109 printk("tlv320aic23.o: Client deregistration failed, client not detached.\n");
117 static int tlv320aic23_attach_adapter(struct i2c_adapter *adapter)
121 res = i2c_probe(adapter, &addr_data, &tlv320aic23_detect_client);
125 /*-----------------------------------------------------------------------*/
127 static struct i2c_driver tlv320aic23_driver = {
129 .name = "OMAP+TLV320AIC23 codec",
131 .id = I2C_DRIVERID_MISC, /* Experimental ID */
132 .attach_adapter = tlv320aic23_attach_adapter,
133 .detach_client = tlv320aic23_detach_client,
140 static int __init tlv320aic23_init(void)
143 struct i2c_client *client = client;
145 if ((res = i2c_add_driver(&tlv320aic23_driver))) {
146 printk("tlv320aic23 i2c: Driver registration failed, module not inserted.\n");
150 printk("TLV320AIC23 I2C version %s (%s)\n", TLV320AIC23_VERSION,
156 static void __exit tlv320aic23_exit(void)
160 if ((res = i2c_del_driver(&tlv320aic23_driver)))
161 printk("tlv320aic23 i2c: Driver remove failed, module not removed.\n");
164 MODULE_AUTHOR("Kai Svahn <kai.svahn@nokia.com>");
165 MODULE_DESCRIPTION("I2C interface for TLV320AIC23 codec.");
166 MODULE_LICENSE("GPL");
168 module_init(tlv320aic23_init)
169 module_exit(tlv320aic23_exit)
171 EXPORT_SYMBOL(tlv320aic23_write_value);