aboutsummaryrefslogtreecommitdiffstats
path: root/include/sound/i2c.h
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /include/sound/i2c.h
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'include/sound/i2c.h')
-rw-r--r--include/sound/i2c.h102
1 files changed, 102 insertions, 0 deletions
diff --git a/include/sound/i2c.h b/include/sound/i2c.h
new file mode 100644
index 000000000000..a665ddf9c146
--- /dev/null
+++ b/include/sound/i2c.h
@@ -0,0 +1,102 @@
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
24typedef struct _snd_i2c_device snd_i2c_device_t;
25typedef struct _snd_i2c_bus snd_i2c_bus_t;
26
27#define SND_I2C_DEVICE_ADDRTEN (1<<0) /* 10-bit I2C address */
28
29struct _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);
38};
39
40#define snd_i2c_device(n) list_entry(n, snd_i2c_device_t, list)
41
42typedef 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;
50
51typedef 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;
56
57struct _snd_i2c_bus {
58 snd_card_t *card; /* card which I2C belongs to */
59 char name[32]; /* some useful label */
60
61 struct semaphore lock_mutex;
62
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 */
65
66 struct list_head devices; /* attached devices to this bus */
67
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 */
73
74 unsigned long private_value;
75 void *private_data;
76 void (*private_free)(snd_i2c_bus_t *bus);
77};
78
79#define snd_i2c_slave_bus(n) list_entry(n, snd_i2c_bus_t, buses)
80
81int snd_i2c_bus_create(snd_card_t *card, const char *name, snd_i2c_bus_t *master, snd_i2c_bus_t **ri2c);
82int snd_i2c_device_create(snd_i2c_bus_t *bus, const char *name, unsigned char addr, snd_i2c_device_t **rdevice);
83int snd_i2c_device_free(snd_i2c_device_t *device);
84
85static 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);
90}
91static 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);
96}
97
98int snd_i2c_sendbytes(snd_i2c_device_t *device, unsigned char *bytes, int count);
99int snd_i2c_readbytes(snd_i2c_device_t *device, unsigned char *bytes, int count);
100int snd_i2c_probeaddr(snd_i2c_bus_t *bus, unsigned short addr);
101
102#endif /* __SOUND_I2C_H */