| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | *   Generic i2c interface for ALSA | 
|  | 3 | * | 
|  | 4 | *   (c) 1998 Gerd Knorr <kraxel@cs.tu-berlin.de> | 
| Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 5 | *   Modified for the ALSA driver by Jaroslav Kysela <perex@perex.cz> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * | 
|  | 7 | *   This program is free software; you can redistribute it and/or modify | 
|  | 8 | *   it under the terms of the GNU General Public License as published by | 
|  | 9 | *   the Free Software Foundation; either version 2 of the License, or | 
|  | 10 | *   (at your option) any later version. | 
|  | 11 | * | 
|  | 12 | *   This program is distributed in the hope that it will be useful, | 
|  | 13 | *   but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|  | 14 | *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|  | 15 | *   GNU General Public License for more details. | 
|  | 16 | * | 
|  | 17 | *   You should have received a copy of the GNU General Public License | 
|  | 18 | *   along with this program; if not, write to the Free Software | 
|  | 19 | *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA | 
|  | 20 | * | 
|  | 21 | */ | 
|  | 22 |  | 
|  | 23 | #include <sound/driver.h> | 
|  | 24 | #include <linux/init.h> | 
|  | 25 | #include <linux/slab.h> | 
|  | 26 | #include <linux/string.h> | 
|  | 27 | #include <linux/errno.h> | 
|  | 28 | #include <sound/core.h> | 
|  | 29 | #include <sound/i2c.h> | 
|  | 30 |  | 
| Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 31 | MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | MODULE_DESCRIPTION("Generic i2c interface for ALSA"); | 
|  | 33 | MODULE_LICENSE("GPL"); | 
|  | 34 |  | 
| Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 35 | static int snd_i2c_bit_sendbytes(struct snd_i2c_device *device, | 
|  | 36 | unsigned char *bytes, int count); | 
|  | 37 | static int snd_i2c_bit_readbytes(struct snd_i2c_device *device, | 
|  | 38 | unsigned char *bytes, int count); | 
|  | 39 | static int snd_i2c_bit_probeaddr(struct snd_i2c_bus *bus, | 
|  | 40 | unsigned short addr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 |  | 
| Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 42 | static struct snd_i2c_ops snd_i2c_bit_ops = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | .sendbytes = snd_i2c_bit_sendbytes, | 
|  | 44 | .readbytes = snd_i2c_bit_readbytes, | 
|  | 45 | .probeaddr = snd_i2c_bit_probeaddr, | 
|  | 46 | }; | 
|  | 47 |  | 
| Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 48 | static int snd_i2c_bus_free(struct snd_i2c_bus *bus) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | { | 
| Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 50 | struct snd_i2c_bus *slave; | 
|  | 51 | struct snd_i2c_device *device; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 |  | 
|  | 53 | snd_assert(bus != NULL, return -EINVAL); | 
|  | 54 | while (!list_empty(&bus->devices)) { | 
|  | 55 | device = snd_i2c_device(bus->devices.next); | 
|  | 56 | snd_i2c_device_free(device); | 
|  | 57 | } | 
|  | 58 | if (bus->master) | 
|  | 59 | list_del(&bus->buses); | 
|  | 60 | else { | 
|  | 61 | while (!list_empty(&bus->buses)) { | 
|  | 62 | slave = snd_i2c_slave_bus(bus->buses.next); | 
|  | 63 | snd_device_free(bus->card, slave); | 
|  | 64 | } | 
|  | 65 | } | 
|  | 66 | if (bus->private_free) | 
|  | 67 | bus->private_free(bus); | 
|  | 68 | kfree(bus); | 
|  | 69 | return 0; | 
|  | 70 | } | 
|  | 71 |  | 
| Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 72 | static int snd_i2c_bus_dev_free(struct snd_device *device) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | { | 
| Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 74 | struct snd_i2c_bus *bus = device->device_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | return snd_i2c_bus_free(bus); | 
|  | 76 | } | 
|  | 77 |  | 
| Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 78 | int snd_i2c_bus_create(struct snd_card *card, const char *name, | 
|  | 79 | struct snd_i2c_bus *master, struct snd_i2c_bus **ri2c) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | { | 
| Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 81 | struct snd_i2c_bus *bus; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | int err; | 
| Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 83 | static struct snd_device_ops ops = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | .dev_free =	snd_i2c_bus_dev_free, | 
|  | 85 | }; | 
|  | 86 |  | 
|  | 87 | *ri2c = NULL; | 
| Takashi Iwai | 561b220 | 2005-09-09 14:22:34 +0200 | [diff] [blame] | 88 | bus = kzalloc(sizeof(*bus), GFP_KERNEL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | if (bus == NULL) | 
|  | 90 | return -ENOMEM; | 
| Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 91 | mutex_init(&bus->lock_mutex); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | INIT_LIST_HEAD(&bus->devices); | 
|  | 93 | INIT_LIST_HEAD(&bus->buses); | 
|  | 94 | bus->card = card; | 
|  | 95 | bus->ops = &snd_i2c_bit_ops; | 
|  | 96 | if (master) { | 
|  | 97 | list_add_tail(&bus->buses, &master->buses); | 
|  | 98 | bus->master = master; | 
|  | 99 | } | 
|  | 100 | strlcpy(bus->name, name, sizeof(bus->name)); | 
|  | 101 | if ((err = snd_device_new(card, SNDRV_DEV_BUS, bus, &ops)) < 0) { | 
|  | 102 | snd_i2c_bus_free(bus); | 
|  | 103 | return err; | 
|  | 104 | } | 
|  | 105 | *ri2c = bus; | 
|  | 106 | return 0; | 
|  | 107 | } | 
|  | 108 |  | 
| Takashi Iwai | 57c65c1 | 2006-04-28 15:13:40 +0200 | [diff] [blame] | 109 | EXPORT_SYMBOL(snd_i2c_bus_create); | 
|  | 110 |  | 
| Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 111 | int snd_i2c_device_create(struct snd_i2c_bus *bus, const char *name, | 
|  | 112 | unsigned char addr, struct snd_i2c_device **rdevice) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | { | 
| Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 114 | struct snd_i2c_device *device; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 |  | 
|  | 116 | *rdevice = NULL; | 
|  | 117 | snd_assert(bus != NULL, return -EINVAL); | 
| Takashi Iwai | 561b220 | 2005-09-09 14:22:34 +0200 | [diff] [blame] | 118 | device = kzalloc(sizeof(*device), GFP_KERNEL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | if (device == NULL) | 
|  | 120 | return -ENOMEM; | 
|  | 121 | device->addr = addr; | 
|  | 122 | strlcpy(device->name, name, sizeof(device->name)); | 
|  | 123 | list_add_tail(&device->list, &bus->devices); | 
|  | 124 | device->bus = bus; | 
|  | 125 | *rdevice = device; | 
|  | 126 | return 0; | 
|  | 127 | } | 
|  | 128 |  | 
| Takashi Iwai | 57c65c1 | 2006-04-28 15:13:40 +0200 | [diff] [blame] | 129 | EXPORT_SYMBOL(snd_i2c_device_create); | 
|  | 130 |  | 
| Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 131 | int snd_i2c_device_free(struct snd_i2c_device *device) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | { | 
|  | 133 | if (device->bus) | 
|  | 134 | list_del(&device->list); | 
|  | 135 | if (device->private_free) | 
|  | 136 | device->private_free(device); | 
|  | 137 | kfree(device); | 
|  | 138 | return 0; | 
|  | 139 | } | 
|  | 140 |  | 
| Takashi Iwai | 57c65c1 | 2006-04-28 15:13:40 +0200 | [diff] [blame] | 141 | EXPORT_SYMBOL(snd_i2c_device_free); | 
|  | 142 |  | 
| Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 143 | int snd_i2c_sendbytes(struct snd_i2c_device *device, unsigned char *bytes, int count) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | { | 
|  | 145 | return device->bus->ops->sendbytes(device, bytes, count); | 
|  | 146 | } | 
|  | 147 |  | 
| Takashi Iwai | 57c65c1 | 2006-04-28 15:13:40 +0200 | [diff] [blame] | 148 | EXPORT_SYMBOL(snd_i2c_sendbytes); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 |  | 
| Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 150 | int snd_i2c_readbytes(struct snd_i2c_device *device, unsigned char *bytes, int count) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | { | 
|  | 152 | return device->bus->ops->readbytes(device, bytes, count); | 
|  | 153 | } | 
|  | 154 |  | 
| Takashi Iwai | 57c65c1 | 2006-04-28 15:13:40 +0200 | [diff] [blame] | 155 | EXPORT_SYMBOL(snd_i2c_readbytes); | 
|  | 156 |  | 
| Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 157 | int snd_i2c_probeaddr(struct snd_i2c_bus *bus, unsigned short addr) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | { | 
|  | 159 | return bus->ops->probeaddr(bus, addr); | 
|  | 160 | } | 
|  | 161 |  | 
| Takashi Iwai | 57c65c1 | 2006-04-28 15:13:40 +0200 | [diff] [blame] | 162 | EXPORT_SYMBOL(snd_i2c_probeaddr); | 
|  | 163 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | /* | 
|  | 165 | *  bit-operations | 
|  | 166 | */ | 
|  | 167 |  | 
| Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 168 | static inline void snd_i2c_bit_hw_start(struct snd_i2c_bus *bus) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | { | 
|  | 170 | if (bus->hw_ops.bit->start) | 
|  | 171 | bus->hw_ops.bit->start(bus); | 
|  | 172 | } | 
|  | 173 |  | 
| Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 174 | static inline void snd_i2c_bit_hw_stop(struct snd_i2c_bus *bus) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | { | 
|  | 176 | if (bus->hw_ops.bit->stop) | 
|  | 177 | bus->hw_ops.bit->stop(bus); | 
|  | 178 | } | 
|  | 179 |  | 
| Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 180 | static void snd_i2c_bit_direction(struct snd_i2c_bus *bus, int clock, int data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | { | 
|  | 182 | if (bus->hw_ops.bit->direction) | 
|  | 183 | bus->hw_ops.bit->direction(bus, clock, data); | 
|  | 184 | } | 
|  | 185 |  | 
| Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 186 | static void snd_i2c_bit_set(struct snd_i2c_bus *bus, int clock, int data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | { | 
|  | 188 | bus->hw_ops.bit->setlines(bus, clock, data); | 
|  | 189 | } | 
|  | 190 |  | 
|  | 191 | #if 0 | 
| Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 192 | static int snd_i2c_bit_clock(struct snd_i2c_bus *bus) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | { | 
|  | 194 | if (bus->hw_ops.bit->getclock) | 
|  | 195 | return bus->hw_ops.bit->getclock(bus); | 
|  | 196 | return -ENXIO; | 
|  | 197 | } | 
|  | 198 | #endif | 
|  | 199 |  | 
| Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 200 | static int snd_i2c_bit_data(struct snd_i2c_bus *bus, int ack) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | { | 
|  | 202 | return bus->hw_ops.bit->getdata(bus, ack); | 
|  | 203 | } | 
|  | 204 |  | 
| Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 205 | static void snd_i2c_bit_start(struct snd_i2c_bus *bus) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | { | 
|  | 207 | snd_i2c_bit_hw_start(bus); | 
|  | 208 | snd_i2c_bit_direction(bus, 1, 1);	/* SCL - wr, SDA - wr */ | 
|  | 209 | snd_i2c_bit_set(bus, 1, 1); | 
|  | 210 | snd_i2c_bit_set(bus, 1, 0); | 
|  | 211 | snd_i2c_bit_set(bus, 0, 0); | 
|  | 212 | } | 
|  | 213 |  | 
| Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 214 | static void snd_i2c_bit_stop(struct snd_i2c_bus *bus) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | { | 
|  | 216 | snd_i2c_bit_set(bus, 0, 0); | 
|  | 217 | snd_i2c_bit_set(bus, 1, 0); | 
|  | 218 | snd_i2c_bit_set(bus, 1, 1); | 
|  | 219 | snd_i2c_bit_hw_stop(bus); | 
|  | 220 | } | 
|  | 221 |  | 
| Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 222 | static void snd_i2c_bit_send(struct snd_i2c_bus *bus, int data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | { | 
|  | 224 | snd_i2c_bit_set(bus, 0, data); | 
|  | 225 | snd_i2c_bit_set(bus, 1, data); | 
|  | 226 | snd_i2c_bit_set(bus, 0, data); | 
|  | 227 | } | 
|  | 228 |  | 
| Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 229 | static int snd_i2c_bit_ack(struct snd_i2c_bus *bus) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | { | 
|  | 231 | int ack; | 
|  | 232 |  | 
|  | 233 | snd_i2c_bit_set(bus, 0, 1); | 
|  | 234 | snd_i2c_bit_set(bus, 1, 1); | 
|  | 235 | snd_i2c_bit_direction(bus, 1, 0);	/* SCL - wr, SDA - rd */ | 
|  | 236 | ack = snd_i2c_bit_data(bus, 1); | 
|  | 237 | snd_i2c_bit_direction(bus, 1, 1);	/* SCL - wr, SDA - wr */ | 
|  | 238 | snd_i2c_bit_set(bus, 0, 1); | 
|  | 239 | return ack ? -EIO : 0; | 
|  | 240 | } | 
|  | 241 |  | 
| Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 242 | static int snd_i2c_bit_sendbyte(struct snd_i2c_bus *bus, unsigned char data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | { | 
|  | 244 | int i, err; | 
|  | 245 |  | 
|  | 246 | for (i = 7; i >= 0; i--) | 
|  | 247 | snd_i2c_bit_send(bus, !!(data & (1 << i))); | 
|  | 248 | if ((err = snd_i2c_bit_ack(bus)) < 0) | 
|  | 249 | return err; | 
|  | 250 | return 0; | 
|  | 251 | } | 
|  | 252 |  | 
| Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 253 | static int snd_i2c_bit_readbyte(struct snd_i2c_bus *bus, int last) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | { | 
|  | 255 | int i; | 
|  | 256 | unsigned char data = 0; | 
|  | 257 |  | 
|  | 258 | snd_i2c_bit_set(bus, 0, 1); | 
|  | 259 | snd_i2c_bit_direction(bus, 1, 0);	/* SCL - wr, SDA - rd */ | 
|  | 260 | for (i = 7; i >= 0; i--) { | 
|  | 261 | snd_i2c_bit_set(bus, 1, 1); | 
|  | 262 | if (snd_i2c_bit_data(bus, 0)) | 
|  | 263 | data |= (1 << i); | 
|  | 264 | snd_i2c_bit_set(bus, 0, 1); | 
|  | 265 | } | 
|  | 266 | snd_i2c_bit_direction(bus, 1, 1);	/* SCL - wr, SDA - wr */ | 
|  | 267 | snd_i2c_bit_send(bus, !!last); | 
|  | 268 | return data; | 
|  | 269 | } | 
|  | 270 |  | 
| Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 271 | static int snd_i2c_bit_sendbytes(struct snd_i2c_device *device, | 
|  | 272 | unsigned char *bytes, int count) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | { | 
| Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 274 | struct snd_i2c_bus *bus = device->bus; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | int err, res = 0; | 
|  | 276 |  | 
|  | 277 | if (device->flags & SND_I2C_DEVICE_ADDRTEN) | 
|  | 278 | return -EIO;		/* not yet implemented */ | 
|  | 279 | snd_i2c_bit_start(bus); | 
|  | 280 | if ((err = snd_i2c_bit_sendbyte(bus, device->addr << 1)) < 0) { | 
|  | 281 | snd_i2c_bit_hw_stop(bus); | 
|  | 282 | return err; | 
|  | 283 | } | 
|  | 284 | while (count-- > 0) { | 
|  | 285 | if ((err = snd_i2c_bit_sendbyte(bus, *bytes++)) < 0) { | 
|  | 286 | snd_i2c_bit_hw_stop(bus); | 
|  | 287 | return err; | 
|  | 288 | } | 
|  | 289 | res++; | 
|  | 290 | } | 
|  | 291 | snd_i2c_bit_stop(bus); | 
|  | 292 | return res; | 
|  | 293 | } | 
|  | 294 |  | 
| Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 295 | static int snd_i2c_bit_readbytes(struct snd_i2c_device *device, | 
|  | 296 | unsigned char *bytes, int count) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | { | 
| Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 298 | struct snd_i2c_bus *bus = device->bus; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | int err, res = 0; | 
|  | 300 |  | 
|  | 301 | if (device->flags & SND_I2C_DEVICE_ADDRTEN) | 
|  | 302 | return -EIO;		/* not yet implemented */ | 
|  | 303 | snd_i2c_bit_start(bus); | 
|  | 304 | if ((err = snd_i2c_bit_sendbyte(bus, (device->addr << 1) | 1)) < 0) { | 
|  | 305 | snd_i2c_bit_hw_stop(bus); | 
|  | 306 | return err; | 
|  | 307 | } | 
|  | 308 | while (count-- > 0) { | 
|  | 309 | if ((err = snd_i2c_bit_readbyte(bus, count == 0)) < 0) { | 
|  | 310 | snd_i2c_bit_hw_stop(bus); | 
|  | 311 | return err; | 
|  | 312 | } | 
|  | 313 | *bytes++ = (unsigned char)err; | 
|  | 314 | res++; | 
|  | 315 | } | 
|  | 316 | snd_i2c_bit_stop(bus); | 
|  | 317 | return res; | 
|  | 318 | } | 
|  | 319 |  | 
| Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 320 | static int snd_i2c_bit_probeaddr(struct snd_i2c_bus *bus, unsigned short addr) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | { | 
|  | 322 | int err; | 
|  | 323 |  | 
|  | 324 | if (addr & 0x8000)	/* 10-bit address */ | 
|  | 325 | return -EIO;	/* not yet implemented */ | 
|  | 326 | if (addr & 0x7f80)	/* invalid address */ | 
|  | 327 | return -EINVAL; | 
|  | 328 | snd_i2c_bit_start(bus); | 
|  | 329 | err = snd_i2c_bit_sendbyte(bus, addr << 1); | 
|  | 330 | snd_i2c_bit_stop(bus); | 
|  | 331 | return err; | 
|  | 332 | } | 
|  | 333 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 |  | 
|  | 335 | static int __init alsa_i2c_init(void) | 
|  | 336 | { | 
|  | 337 | return 0; | 
|  | 338 | } | 
|  | 339 |  | 
|  | 340 | static void __exit alsa_i2c_exit(void) | 
|  | 341 | { | 
|  | 342 | } | 
|  | 343 |  | 
|  | 344 | module_init(alsa_i2c_init) | 
|  | 345 | module_exit(alsa_i2c_exit) |