Linux v2.6.15-rc6
[pohmelfs.git] / include / sound / i2c.h
bloba665ddf9c14669f15c5e5a6225cd6a2f815bfa44
1 #ifndef __SOUND_I2C_H
2 #define __SOUND_I2C_H
4 /*
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.
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.
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
24 typedef struct _snd_i2c_device snd_i2c_device_t;
25 typedef struct _snd_i2c_bus snd_i2c_bus_t;
27 #define SND_I2C_DEVICE_ADDRTEN (1<<0) /* 10-bit I2C address */
29 struct _snd_i2c_device {
30 struct list_head list;
31 snd_i2c_bus_t *bus; /* I2C bus */
32 char name[32]; /* some useful device name */
33 unsigned short flags; /* device flags */
34 unsigned short addr; /* device address (might be 10-bit) */
35 unsigned long private_value;
36 void *private_data;
37 void (*private_free)(snd_i2c_device_t *device);
40 #define snd_i2c_device(n) list_entry(n, snd_i2c_device_t, list)
42 typedef struct _snd_i2c_bit_ops {
43 void (*start)(snd_i2c_bus_t *bus); /* transfer start */
44 void (*stop)(snd_i2c_bus_t *bus); /* transfer stop */
45 void (*direction)(snd_i2c_bus_t *bus, int clock, int data); /* set line direction (0 = write, 1 = read) */
46 void (*setlines)(snd_i2c_bus_t *bus, int clock, int data);
47 int (*getclock)(snd_i2c_bus_t *bus);
48 int (*getdata)(snd_i2c_bus_t *bus, int ack);
49 } snd_i2c_bit_ops_t;
51 typedef struct _snd_i2c_ops {
52 int (*sendbytes)(snd_i2c_device_t *device, unsigned char *bytes, int count);
53 int (*readbytes)(snd_i2c_device_t *device, unsigned char *bytes, int count);
54 int (*probeaddr)(snd_i2c_bus_t *bus, unsigned short addr);
55 } snd_i2c_ops_t;
57 struct _snd_i2c_bus {
58 snd_card_t *card; /* card which I2C belongs to */
59 char name[32]; /* some useful label */
61 struct semaphore lock_mutex;
63 snd_i2c_bus_t *master; /* master bus when SCK/SCL is shared */
64 struct list_head buses; /* master: slave buses sharing SCK/SCL, slave: link list */
66 struct list_head devices; /* attached devices to this bus */
68 union {
69 snd_i2c_bit_ops_t *bit;
70 void *ops;
71 } hw_ops; /* lowlevel operations */
72 snd_i2c_ops_t *ops; /* midlevel operations */
74 unsigned long private_value;
75 void *private_data;
76 void (*private_free)(snd_i2c_bus_t *bus);
79 #define snd_i2c_slave_bus(n) list_entry(n, snd_i2c_bus_t, buses)
81 int snd_i2c_bus_create(snd_card_t *card, const char *name, snd_i2c_bus_t *master, snd_i2c_bus_t **ri2c);
82 int snd_i2c_device_create(snd_i2c_bus_t *bus, const char *name, unsigned char addr, snd_i2c_device_t **rdevice);
83 int snd_i2c_device_free(snd_i2c_device_t *device);
85 static inline void snd_i2c_lock(snd_i2c_bus_t *bus) {
86 if (bus->master)
87 down(&bus->master->lock_mutex);
88 else
89 down(&bus->lock_mutex);
91 static inline void snd_i2c_unlock(snd_i2c_bus_t *bus) {
92 if (bus->master)
93 up(&bus->master->lock_mutex);
94 else
95 up(&bus->lock_mutex);
98 int snd_i2c_sendbytes(snd_i2c_device_t *device, unsigned char *bytes, int count);
99 int snd_i2c_readbytes(snd_i2c_device_t *device, unsigned char *bytes, int count);
100 int snd_i2c_probeaddr(snd_i2c_bus_t *bus, unsigned short addr);
102 #endif /* __SOUND_I2C_H */