xref: /openbmc/linux/include/sound/i2c.h (revision 5df29bca)
11da177e4SLinus Torvalds #ifndef __SOUND_I2C_H
21da177e4SLinus Torvalds #define __SOUND_I2C_H
31da177e4SLinus Torvalds 
41da177e4SLinus Torvalds /*
51da177e4SLinus Torvalds  *
61da177e4SLinus Torvalds  *
71da177e4SLinus Torvalds  *   This program is free software; you can redistribute it and/or modify
81da177e4SLinus Torvalds  *   it under the terms of the GNU General Public License as published by
91da177e4SLinus Torvalds  *   the Free Software Foundation; either version 2 of the License, or
101da177e4SLinus Torvalds  *   (at your option) any later version.
111da177e4SLinus Torvalds  *
121da177e4SLinus Torvalds  *   This program is distributed in the hope that it will be useful,
131da177e4SLinus Torvalds  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
141da177e4SLinus Torvalds  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
151da177e4SLinus Torvalds  *   GNU General Public License for more details.
161da177e4SLinus Torvalds  *
171da177e4SLinus Torvalds  *   You should have received a copy of the GNU General Public License
181da177e4SLinus Torvalds  *   along with this program; if not, write to the Free Software
191da177e4SLinus Torvalds  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
201da177e4SLinus Torvalds  *
211da177e4SLinus Torvalds  *
221da177e4SLinus Torvalds  */
231da177e4SLinus Torvalds 
241da177e4SLinus Torvalds #define SND_I2C_DEVICE_ADDRTEN	(1<<0)	/* 10-bit I2C address */
251da177e4SLinus Torvalds 
2697f02e05STakashi Iwai struct snd_i2c_device {
271da177e4SLinus Torvalds 	struct list_head list;
2897f02e05STakashi Iwai 	struct snd_i2c_bus *bus;	/* I2C bus */
291da177e4SLinus Torvalds 	char name[32];		/* some useful device name */
301da177e4SLinus Torvalds 	unsigned short flags;	/* device flags */
311da177e4SLinus Torvalds 	unsigned short addr;	/* device address (might be 10-bit) */
321da177e4SLinus Torvalds 	unsigned long private_value;
331da177e4SLinus Torvalds 	void *private_data;
3497f02e05STakashi Iwai 	void (*private_free)(struct snd_i2c_device *device);
351da177e4SLinus Torvalds };
361da177e4SLinus Torvalds 
3797f02e05STakashi Iwai #define snd_i2c_device(n) list_entry(n, struct snd_i2c_device, list)
381da177e4SLinus Torvalds 
3997f02e05STakashi Iwai struct snd_i2c_bit_ops {
4097f02e05STakashi Iwai 	void (*start)(struct snd_i2c_bus *bus);	/* transfer start */
4197f02e05STakashi Iwai 	void (*stop)(struct snd_i2c_bus *bus);	/* transfer stop */
4297f02e05STakashi Iwai 	void (*direction)(struct snd_i2c_bus *bus, int clock, int data);  /* set line direction (0 = write, 1 = read) */
4397f02e05STakashi Iwai 	void (*setlines)(struct snd_i2c_bus *bus, int clock, int data);
4497f02e05STakashi Iwai 	int (*getclock)(struct snd_i2c_bus *bus);
4597f02e05STakashi Iwai 	int (*getdata)(struct snd_i2c_bus *bus, int ack);
4697f02e05STakashi Iwai };
471da177e4SLinus Torvalds 
4897f02e05STakashi Iwai struct snd_i2c_ops {
4997f02e05STakashi Iwai 	int (*sendbytes)(struct snd_i2c_device *device, unsigned char *bytes, int count);
5097f02e05STakashi Iwai 	int (*readbytes)(struct snd_i2c_device *device, unsigned char *bytes, int count);
5197f02e05STakashi Iwai 	int (*probeaddr)(struct snd_i2c_bus *bus, unsigned short addr);
5297f02e05STakashi Iwai };
531da177e4SLinus Torvalds 
5497f02e05STakashi Iwai struct snd_i2c_bus {
5597f02e05STakashi Iwai 	struct snd_card *card;	/* card which I2C belongs to */
561da177e4SLinus Torvalds 	char name[32];		/* some useful label */
571da177e4SLinus Torvalds 
58ef9f0a42SIngo Molnar 	struct mutex lock_mutex;
591da177e4SLinus Torvalds 
6097f02e05STakashi Iwai 	struct snd_i2c_bus *master;	/* master bus when SCK/SCL is shared */
611da177e4SLinus Torvalds 	struct list_head buses;	/* master: slave buses sharing SCK/SCL, slave: link list */
621da177e4SLinus Torvalds 
631da177e4SLinus Torvalds 	struct list_head devices; /* attached devices to this bus */
641da177e4SLinus Torvalds 
651da177e4SLinus Torvalds 	union {
6697f02e05STakashi Iwai 		struct snd_i2c_bit_ops *bit;
671da177e4SLinus Torvalds 		void *ops;
681da177e4SLinus Torvalds 	} hw_ops;		/* lowlevel operations */
695df29bcaSJulia Lawall 	const struct snd_i2c_ops *ops;	/* midlevel operations */
701da177e4SLinus Torvalds 
711da177e4SLinus Torvalds 	unsigned long private_value;
721da177e4SLinus Torvalds 	void *private_data;
7397f02e05STakashi Iwai 	void (*private_free)(struct snd_i2c_bus *bus);
741da177e4SLinus Torvalds };
751da177e4SLinus Torvalds 
7697f02e05STakashi Iwai #define snd_i2c_slave_bus(n) list_entry(n, struct snd_i2c_bus, buses)
771da177e4SLinus Torvalds 
7897f02e05STakashi Iwai int snd_i2c_bus_create(struct snd_card *card, const char *name,
7997f02e05STakashi Iwai 		       struct snd_i2c_bus *master, struct snd_i2c_bus **ri2c);
8097f02e05STakashi Iwai int snd_i2c_device_create(struct snd_i2c_bus *bus, const char *name,
8197f02e05STakashi Iwai 			  unsigned char addr, struct snd_i2c_device **rdevice);
8297f02e05STakashi Iwai int snd_i2c_device_free(struct snd_i2c_device *device);
831da177e4SLinus Torvalds 
8497f02e05STakashi Iwai static inline void snd_i2c_lock(struct snd_i2c_bus *bus)
8597f02e05STakashi Iwai {
861da177e4SLinus Torvalds 	if (bus->master)
87ef9f0a42SIngo Molnar 		mutex_lock(&bus->master->lock_mutex);
881da177e4SLinus Torvalds 	else
89ef9f0a42SIngo Molnar 		mutex_lock(&bus->lock_mutex);
901da177e4SLinus Torvalds }
9197f02e05STakashi Iwai 
9297f02e05STakashi Iwai static inline void snd_i2c_unlock(struct snd_i2c_bus *bus)
9397f02e05STakashi Iwai {
941da177e4SLinus Torvalds 	if (bus->master)
95ef9f0a42SIngo Molnar 		mutex_unlock(&bus->master->lock_mutex);
961da177e4SLinus Torvalds 	else
97ef9f0a42SIngo Molnar 		mutex_unlock(&bus->lock_mutex);
981da177e4SLinus Torvalds }
991da177e4SLinus Torvalds 
10097f02e05STakashi Iwai int snd_i2c_sendbytes(struct snd_i2c_device *device, unsigned char *bytes, int count);
10197f02e05STakashi Iwai int snd_i2c_readbytes(struct snd_i2c_device *device, unsigned char *bytes, int count);
10297f02e05STakashi Iwai int snd_i2c_probeaddr(struct snd_i2c_bus *bus, unsigned short addr);
1031da177e4SLinus Torvalds 
1041da177e4SLinus Torvalds #endif /* __SOUND_I2C_H */
105