Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef __SOUND_I2C_H |
| 2 | #define __SOUND_I2C_H |
| 3 | |
| 4 | /* |
| 5 | * |
| 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #define SND_I2C_DEVICE_ADDRTEN (1<<0) /* 10-bit I2C address */ |
| 25 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 26 | struct snd_i2c_device { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | struct list_head list; |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 28 | struct snd_i2c_bus *bus; /* I2C bus */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | char name[32]; /* some useful device name */ |
| 30 | unsigned short flags; /* device flags */ |
| 31 | unsigned short addr; /* device address (might be 10-bit) */ |
| 32 | unsigned long private_value; |
| 33 | void *private_data; |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 34 | void (*private_free)(struct snd_i2c_device *device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | }; |
| 36 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 37 | #define snd_i2c_device(n) list_entry(n, struct snd_i2c_device, list) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 39 | struct snd_i2c_bit_ops { |
| 40 | void (*start)(struct snd_i2c_bus *bus); /* transfer start */ |
| 41 | void (*stop)(struct snd_i2c_bus *bus); /* transfer stop */ |
| 42 | void (*direction)(struct snd_i2c_bus *bus, int clock, int data); /* set line direction (0 = write, 1 = read) */ |
| 43 | void (*setlines)(struct snd_i2c_bus *bus, int clock, int data); |
| 44 | int (*getclock)(struct snd_i2c_bus *bus); |
| 45 | int (*getdata)(struct snd_i2c_bus *bus, int ack); |
| 46 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 48 | struct snd_i2c_ops { |
| 49 | int (*sendbytes)(struct snd_i2c_device *device, unsigned char *bytes, int count); |
| 50 | int (*readbytes)(struct snd_i2c_device *device, unsigned char *bytes, int count); |
| 51 | int (*probeaddr)(struct snd_i2c_bus *bus, unsigned short addr); |
| 52 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 54 | struct snd_i2c_bus { |
| 55 | struct snd_card *card; /* card which I2C belongs to */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | char name[32]; /* some useful label */ |
| 57 | |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 58 | struct mutex lock_mutex; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 60 | struct snd_i2c_bus *master; /* master bus when SCK/SCL is shared */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | struct list_head buses; /* master: slave buses sharing SCK/SCL, slave: link list */ |
| 62 | |
| 63 | struct list_head devices; /* attached devices to this bus */ |
| 64 | |
| 65 | union { |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 66 | struct snd_i2c_bit_ops *bit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | void *ops; |
| 68 | } hw_ops; /* lowlevel operations */ |
Julia Lawall | 5df29bc | 2015-11-29 18:25:24 +0100 | [diff] [blame] | 69 | const struct snd_i2c_ops *ops; /* midlevel operations */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | |
| 71 | unsigned long private_value; |
| 72 | void *private_data; |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 73 | void (*private_free)(struct snd_i2c_bus *bus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | }; |
| 75 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 76 | #define snd_i2c_slave_bus(n) list_entry(n, struct snd_i2c_bus, buses) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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); |
| 80 | int snd_i2c_device_create(struct snd_i2c_bus *bus, const char *name, |
| 81 | unsigned char addr, struct snd_i2c_device **rdevice); |
| 82 | int snd_i2c_device_free(struct snd_i2c_device *device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 84 | static inline void snd_i2c_lock(struct snd_i2c_bus *bus) |
| 85 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | if (bus->master) |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 87 | mutex_lock(&bus->master->lock_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | else |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 89 | mutex_lock(&bus->lock_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | } |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 91 | |
| 92 | static inline void snd_i2c_unlock(struct snd_i2c_bus *bus) |
| 93 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | if (bus->master) |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 95 | mutex_unlock(&bus->master->lock_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | else |
Ingo Molnar | ef9f0a4 | 2006-01-16 16:31:42 +0100 | [diff] [blame] | 97 | mutex_unlock(&bus->lock_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | } |
| 99 | |
Takashi Iwai | 97f02e0 | 2005-11-17 14:17:19 +0100 | [diff] [blame] | 100 | int snd_i2c_sendbytes(struct snd_i2c_device *device, unsigned char *bytes, int count); |
| 101 | int snd_i2c_readbytes(struct snd_i2c_device *device, unsigned char *bytes, int count); |
| 102 | int snd_i2c_probeaddr(struct snd_i2c_bus *bus, unsigned short addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | |
| 104 | #endif /* __SOUND_I2C_H */ |