2 * Driver for the i2c/i2s based DAC3550a sound chip used
3 * on some Apple iBooks. Also known as "DACA".
5 * This file is subject to the terms and conditions of the GNU General Public
6 * License. See the file COPYING in the main directory of this archive
10 #include <linux/module.h>
11 #include <linux/slab.h>
12 #include <linux/proc_fs.h>
13 #include <linux/ioport.h>
14 #include <linux/sysctl.h>
15 #include <linux/types.h>
16 #include <linux/i2c.h>
17 #include <linux/init.h>
18 #include <asm/uaccess.h>
19 #include <asm/errno.h>
24 /* FYI: This code was derived from the tas3001c.c Texas/Tumbler mixer
25 * control code, as well as info derived from the AppleDACAAudio driver
26 * from Darwin CVS (main thing I derived being register numbers and
27 * values, as well as when to make the calls). */
29 #define I2C_DRIVERID_DACA (0xFDCB)
31 #define DACA_VERSION "0.1"
32 #define DACA_DATE "20010930"
34 static int cur_left_vol;
35 static int cur_right_vol;
36 static struct i2c_client *daca_client;
38 static int daca_attach_adapter(struct i2c_adapter *adapter);
39 static int daca_detect_client(struct i2c_adapter *adapter, int address);
40 static int daca_detach_client(struct i2c_client *client);
42 /* Unique ID allocation */
45 struct i2c_driver daca_driver = {
47 .name = "DAC3550A driver V " DACA_VERSION,
48 .id = I2C_DRIVERID_DACA,
49 .flags = I2C_DF_NOTIFY,
50 .attach_adapter = daca_attach_adapter,
51 .detach_client = daca_detach_client,
54 #define VOL_MAX ((1<<20) - 1)
56 void daca_get_volume(uint * left_vol, uint *right_vol)
58 *left_vol = cur_left_vol >> 5;
59 *right_vol = cur_right_vol >> 5;
62 int daca_set_volume(uint left_vol, uint right_vol)
64 unsigned short voldata;
69 /* Derived from experience, not from any specific values */
73 if (left_vol > VOL_MAX)
75 if (right_vol > VOL_MAX)
78 voldata = ((left_vol >> 14) & 0x3f) << 8;
79 voldata |= (right_vol >> 14) & 0x3f;
81 if (i2c_smbus_write_word_data(daca_client, 2, voldata) < 0) {
82 printk("daca: failed to set volume \n");
86 cur_left_vol = left_vol;
87 cur_right_vol = right_vol;
92 int daca_leave_sleep(void)
97 /* Do a short sleep, just to make sure I2C bus is awake and paying
101 /* Write the sample rate reg the value it needs */
102 i2c_smbus_write_byte_data(daca_client, 1, 8);
103 daca_set_volume(cur_left_vol >> 5, cur_right_vol >> 5);
104 /* Another short delay, just to make sure the other I2C bus writes
108 /* Write the global config reg - invert right power amp,
109 * DAC on, use 5-volt mode */
110 i2c_smbus_write_byte_data(daca_client, 3, 0x45);
115 int daca_enter_sleep(void)
120 i2c_smbus_write_byte_data(daca_client, 1, 8);
121 daca_set_volume(cur_left_vol >> 5, cur_right_vol >> 5);
123 /* Write the global config reg - invert right power amp,
124 * DAC on, enter low-power mode, use 5-volt mode
126 i2c_smbus_write_byte_data(daca_client, 3, 0x65);
131 static int daca_attach_adapter(struct i2c_adapter *adapter)
133 if (!strncmp(adapter->name, "mac-io", 6))
134 daca_detect_client(adapter, 0x4d);
138 static int daca_init_client(struct i2c_client * new_client)
141 * Probe is not working with the current i2c-keywest
142 * driver. We try to use addr 0x4d on each adapters
143 * instead, by setting the format register.
145 * FIXME: I'm sure that can be obtained from the
146 * device-tree. --BenH.
149 /* Write the global config reg - invert right power amp,
150 * DAC on, use 5-volt mode
152 if (i2c_smbus_write_byte_data(new_client, 3, 0x45))
155 i2c_smbus_write_byte_data(new_client, 1, 8);
156 daca_client = new_client;
157 daca_set_volume(15000, 15000);
162 static int daca_detect_client(struct i2c_adapter *adapter, int address)
164 const char *client_name = "DAC 3550A Digital Equalizer";
165 struct i2c_client *new_client;
168 new_client = kmalloc(sizeof(*new_client), GFP_KERNEL);
171 memset(new_client, 0, sizeof(*new_client));
173 new_client->addr = address;
174 new_client->adapter = adapter;
175 new_client->driver = &daca_driver;
176 new_client->flags = 0;
177 strcpy(new_client->name, client_name);
178 new_client->id = daca_id++; /* racy... */
180 if (daca_init_client(new_client))
183 /* Tell the i2c layer a new client has arrived */
184 if (i2c_attach_client(new_client))
194 static int daca_detach_client(struct i2c_client *client)
196 if (client == daca_client)
199 i2c_detach_client(client);
204 void daca_cleanup(void)
206 i2c_del_driver(&daca_driver);
211 printk("dac3550a driver version %s (%s)\n",DACA_VERSION,DACA_DATE);
212 return i2c_add_driver(&daca_driver);