Release 4.7 sound/i2c/i2c.c
/*
* Generic i2c interface for ALSA
*
* (c) 1998 Gerd Knorr <kraxel@cs.tu-berlin.de>
* Modified for the ALSA driver by Jaroslav Kysela <perex@perex.cz>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/module.h>
#include <linux/string.h>
#include <linux/errno.h>
#include <sound/core.h>
#include <sound/i2c.h>
MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
MODULE_DESCRIPTION("Generic i2c interface for ALSA");
MODULE_LICENSE("GPL");
static int snd_i2c_bit_sendbytes(struct snd_i2c_device *device,
unsigned char *bytes, int count);
static int snd_i2c_bit_readbytes(struct snd_i2c_device *device,
unsigned char *bytes, int count);
static int snd_i2c_bit_probeaddr(struct snd_i2c_bus *bus,
unsigned short addr);
static const struct snd_i2c_ops snd_i2c_bit_ops = {
.sendbytes = snd_i2c_bit_sendbytes,
.readbytes = snd_i2c_bit_readbytes,
.probeaddr = snd_i2c_bit_probeaddr,
};
static int snd_i2c_bus_free(struct snd_i2c_bus *bus)
{
struct snd_i2c_bus *slave;
struct snd_i2c_device *device;
if (snd_BUG_ON(!bus))
return -EINVAL;
while (!list_empty(&bus->devices)) {
device = snd_i2c_device(bus->devices.next);
snd_i2c_device_free(device);
}
if (bus->master)
list_del(&bus->buses);
else {
while (!list_empty(&bus->buses)) {
slave = snd_i2c_slave_bus(bus->buses.next);
snd_device_free(bus->card, slave);
}
}
if (bus->private_free)
bus->private_free(bus);
kfree(bus);
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
jaroslav kysela | jaroslav kysela | 117 | 87.97% | 2 | 50.00% |
takashi iwai | takashi iwai | 16 | 12.03% | 2 | 50.00% |
| Total | 133 | 100.00% | 4 | 100.00% |
static int snd_i2c_bus_dev_free(struct snd_device *device)
{
struct snd_i2c_bus *bus = device->device_data;
return snd_i2c_bus_free(bus);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
jaroslav kysela | jaroslav kysela | 22 | 84.62% | 2 | 66.67% |
takashi iwai | takashi iwai | 4 | 15.38% | 1 | 33.33% |
| Total | 26 | 100.00% | 3 | 100.00% |
int snd_i2c_bus_create(struct snd_card *card, const char *name,
struct snd_i2c_bus *master, struct snd_i2c_bus **ri2c)
{
struct snd_i2c_bus *bus;
int err;
static struct snd_device_ops ops = {
.dev_free = snd_i2c_bus_dev_free,
};
*ri2c = NULL;
bus = kzalloc(sizeof(*bus), GFP_KERNEL);
if (bus == NULL)
return -ENOMEM;
mutex_init(&bus->lock_mutex);
INIT_LIST_HEAD(&bus->devices);
INIT_LIST_HEAD(&bus->buses);
bus->card = card;
bus->ops = &snd_i2c_bit_ops;
if (master) {
list_add_tail(&bus->buses, &master->buses);
bus->master = master;
}
strlcpy(bus->name, name, sizeof(bus->name));
err = snd_device_new(card, SNDRV_DEV_BUS, bus, &ops);
if (err < 0) {
snd_i2c_bus_free(bus);
return err;
}
*ri2c = bus;
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
jaroslav kysela | jaroslav kysela | 173 | 91.05% | 5 | 50.00% |
takashi iwai | takashi iwai | 11 | 5.79% | 2 | 20.00% |
brian waters | brian waters | 4 | 2.11% | 1 | 10.00% |
ben collins | ben collins | 1 | 0.53% | 1 | 10.00% |
ingo molnar | ingo molnar | 1 | 0.53% | 1 | 10.00% |
| Total | 190 | 100.00% | 10 | 100.00% |
EXPORT_SYMBOL(snd_i2c_bus_create);
int snd_i2c_device_create(struct snd_i2c_bus *bus, const char *name,
unsigned char addr, struct snd_i2c_device **rdevice)
{
struct snd_i2c_device *device;
*rdevice = NULL;
if (snd_BUG_ON(!bus))
return -EINVAL;
device = kzalloc(sizeof(*device), GFP_KERNEL);
if (device == NULL)
return -ENOMEM;
device->addr = addr;
strlcpy(device->name, name, sizeof(device->name));
list_add_tail(&device->list, &bus->devices);
device->bus = bus;
*rdevice = device;
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
jaroslav kysela | jaroslav kysela | 101 | 84.87% | 2 | 33.33% |
takashi iwai | takashi iwai | 17 | 14.29% | 3 | 50.00% |
ben collins | ben collins | 1 | 0.84% | 1 | 16.67% |
| Total | 119 | 100.00% | 6 | 100.00% |
EXPORT_SYMBOL(snd_i2c_device_create);
int snd_i2c_device_free(struct snd_i2c_device *device)
{
if (device->bus)
list_del(&device->list);
if (device->private_free)
device->private_free(device);
kfree(device);
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
jaroslav kysela | jaroslav kysela | 43 | 95.56% | 2 | 66.67% |
takashi iwai | takashi iwai | 2 | 4.44% | 1 | 33.33% |
| Total | 45 | 100.00% | 3 | 100.00% |
EXPORT_SYMBOL(snd_i2c_device_free);
int snd_i2c_sendbytes(struct snd_i2c_device *device, unsigned char *bytes, int count)
{
return device->bus->ops->sendbytes(device, bytes, count);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
jaroslav kysela | jaroslav kysela | 32 | 94.12% | 1 | 50.00% |
takashi iwai | takashi iwai | 2 | 5.88% | 1 | 50.00% |
| Total | 34 | 100.00% | 2 | 100.00% |
EXPORT_SYMBOL(snd_i2c_sendbytes);
int snd_i2c_readbytes(struct snd_i2c_device *device, unsigned char *bytes, int count)
{
return device->bus->ops->readbytes(device, bytes, count);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
jaroslav kysela | jaroslav kysela | 32 | 94.12% | 1 | 50.00% |
takashi iwai | takashi iwai | 2 | 5.88% | 1 | 50.00% |
| Total | 34 | 100.00% | 2 | 100.00% |
EXPORT_SYMBOL(snd_i2c_readbytes);
int snd_i2c_probeaddr(struct snd_i2c_bus *bus, unsigned short addr)
{
return bus->ops->probeaddr(bus, addr);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
jaroslav kysela | jaroslav kysela | 24 | 92.31% | 1 | 50.00% |
takashi iwai | takashi iwai | 2 | 7.69% | 1 | 50.00% |
| Total | 26 | 100.00% | 2 | 100.00% |
EXPORT_SYMBOL(snd_i2c_probeaddr);
/*
* bit-operations
*/
static inline void snd_i2c_bit_hw_start(struct snd_i2c_bus *bus)
{
if (bus->hw_ops.bit->start)
bus->hw_ops.bit->start(bus);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
jaroslav kysela | jaroslav kysela | 31 | 93.94% | 1 | 50.00% |
takashi iwai | takashi iwai | 2 | 6.06% | 1 | 50.00% |
| Total | 33 | 100.00% | 2 | 100.00% |
static inline void snd_i2c_bit_hw_stop(struct snd_i2c_bus *bus)
{
if (bus->hw_ops.bit->stop)
bus->hw_ops.bit->stop(bus);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
jaroslav kysela | jaroslav kysela | 31 | 93.94% | 1 | 50.00% |
takashi iwai | takashi iwai | 2 | 6.06% | 1 | 50.00% |
| Total | 33 | 100.00% | 2 | 100.00% |
static void snd_i2c_bit_direction(struct snd_i2c_bus *bus, int clock, int data)
{
if (bus->hw_ops.bit->direction)
bus->hw_ops.bit->direction(bus, clock, data);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
jaroslav kysela | jaroslav kysela | 40 | 95.24% | 1 | 50.00% |
takashi iwai | takashi iwai | 2 | 4.76% | 1 | 50.00% |
| Total | 42 | 100.00% | 2 | 100.00% |
static void snd_i2c_bit_set(struct snd_i2c_bus *bus, int clock, int data)
{
bus->hw_ops.bit->setlines(bus, clock, data);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
jaroslav kysela | jaroslav kysela | 30 | 93.75% | 1 | 50.00% |
takashi iwai | takashi iwai | 2 | 6.25% | 1 | 50.00% |
| Total | 32 | 100.00% | 2 | 100.00% |
#if 0
static int snd_i2c_bit_clock(struct snd_i2c_bus *bus)
{
if (bus->hw_ops.bit->getclock)
return bus->hw_ops.bit->getclock(bus);
return -ENXIO;
}
#endif
static int snd_i2c_bit_data(struct snd_i2c_bus *bus, int ack)
{
return bus->hw_ops.bit->getdata(bus, ack);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
jaroslav kysela | jaroslav kysela | 26 | 92.86% | 1 | 50.00% |
takashi iwai | takashi iwai | 2 | 7.14% | 1 | 50.00% |
| Total | 28 | 100.00% | 2 | 100.00% |
static void snd_i2c_bit_start(struct snd_i2c_bus *bus)
{
snd_i2c_bit_hw_start(bus);
snd_i2c_bit_direction(bus, 1, 1); /* SCL - wr, SDA - wr */
snd_i2c_bit_set(bus, 1, 1);
snd_i2c_bit_set(bus, 1, 0);
snd_i2c_bit_set(bus, 0, 0);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
jaroslav kysela | jaroslav kysela | 51 | 96.23% | 1 | 50.00% |
takashi iwai | takashi iwai | 2 | 3.77% | 1 | 50.00% |
| Total | 53 | 100.00% | 2 | 100.00% |
static void snd_i2c_bit_stop(struct snd_i2c_bus *bus)
{
snd_i2c_bit_set(bus, 0, 0);
snd_i2c_bit_set(bus, 1, 0);
snd_i2c_bit_set(bus, 1, 1);
snd_i2c_bit_hw_stop(bus);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
jaroslav kysela | jaroslav kysela | 41 | 95.35% | 1 | 50.00% |
takashi iwai | takashi iwai | 2 | 4.65% | 1 | 50.00% |
| Total | 43 | 100.00% | 2 | 100.00% |
static void snd_i2c_bit_send(struct snd_i2c_bus *bus, int data)
{
snd_i2c_bit_set(bus, 0, data);
snd_i2c_bit_set(bus, 1, data);
snd_i2c_bit_set(bus, 0, data);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
jaroslav kysela | jaroslav kysela | 39 | 95.12% | 1 | 50.00% |
takashi iwai | takashi iwai | 2 | 4.88% | 1 | 50.00% |
| Total | 41 | 100.00% | 2 | 100.00% |
static int snd_i2c_bit_ack(struct snd_i2c_bus *bus)
{
int ack;
snd_i2c_bit_set(bus, 0, 1);
snd_i2c_bit_set(bus, 1, 1);
snd_i2c_bit_direction(bus, 1, 0); /* SCL - wr, SDA - rd */
ack = snd_i2c_bit_data(bus, 1);
snd_i2c_bit_direction(bus, 1, 1); /* SCL - wr, SDA - wr */
snd_i2c_bit_set(bus, 0, 1);
return ack ? -EIO : 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
jaroslav kysela | jaroslav kysela | 76 | 97.44% | 2 | 66.67% |
takashi iwai | takashi iwai | 2 | 2.56% | 1 | 33.33% |
| Total | 78 | 100.00% | 3 | 100.00% |
static int snd_i2c_bit_sendbyte(struct snd_i2c_bus *bus, unsigned char data)
{
int i, err;
for (i = 7; i >= 0; i--)
snd_i2c_bit_send(bus, !!(data & (1 << i)));
err = snd_i2c_bit_ack(bus);
if (err < 0)
return err;
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
jaroslav kysela | jaroslav kysela | 63 | 91.30% | 1 | 33.33% |
brian waters | brian waters | 4 | 5.80% | 1 | 33.33% |
takashi iwai | takashi iwai | 2 | 2.90% | 1 | 33.33% |
| Total | 69 | 100.00% | 3 | 100.00% |
static int snd_i2c_bit_readbyte(struct snd_i2c_bus *bus, int last)
{
int i;
unsigned char data = 0;
snd_i2c_bit_set(bus, 0, 1);
snd_i2c_bit_direction(bus, 1, 0); /* SCL - wr, SDA - rd */
for (i = 7; i >= 0; i--) {
snd_i2c_bit_set(bus, 1, 1);
if (snd_i2c_bit_data(bus, 0))
data |= (1 << i);
snd_i2c_bit_set(bus, 0, 1);
}
snd_i2c_bit_direction(bus, 1, 1); /* SCL - wr, SDA - wr */
snd_i2c_bit_send(bus, !!last);
return data;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
jaroslav kysela | jaroslav kysela | 112 | 98.25% | 1 | 50.00% |
takashi iwai | takashi iwai | 2 | 1.75% | 1 | 50.00% |
| Total | 114 | 100.00% | 2 | 100.00% |
static int snd_i2c_bit_sendbytes(struct snd_i2c_device *device,
unsigned char *bytes, int count)
{
struct snd_i2c_bus *bus = device->bus;
int err, res = 0;
if (device->flags & SND_I2C_DEVICE_ADDRTEN)
return -EIO; /* not yet implemented */
snd_i2c_bit_start(bus);
err = snd_i2c_bit_sendbyte(bus, device->addr << 1);
if (err < 0) {
snd_i2c_bit_hw_stop(bus);
return err;
}
while (count-- > 0) {
err = snd_i2c_bit_sendbyte(bus, *bytes++);
if (err < 0) {
snd_i2c_bit_hw_stop(bus);
return err;
}
res++;
}
snd_i2c_bit_stop(bus);
return res;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
jaroslav kysela | jaroslav kysela | 117 | 90.70% | 2 | 50.00% |
brian waters | brian waters | 8 | 6.20% | 1 | 25.00% |
takashi iwai | takashi iwai | 4 | 3.10% | 1 | 25.00% |
| Total | 129 | 100.00% | 4 | 100.00% |
static int snd_i2c_bit_readbytes(struct snd_i2c_device *device,
unsigned char *bytes, int count)
{
struct snd_i2c_bus *bus = device->bus;
int err, res = 0;
if (device->flags & SND_I2C_DEVICE_ADDRTEN)
return -EIO; /* not yet implemented */
snd_i2c_bit_start(bus);
err = snd_i2c_bit_sendbyte(bus, (device->addr << 1) | 1);
if (err < 0) {
snd_i2c_bit_hw_stop(bus);
return err;
}
while (count-- > 0) {
err = snd_i2c_bit_readbyte(bus, count == 0);
if (err < 0) {
snd_i2c_bit_hw_stop(bus);
return err;
}
*bytes++ = (unsigned char)err;
res++;
}
snd_i2c_bit_stop(bus);
return res;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
jaroslav kysela | jaroslav kysela | 131 | 91.61% | 2 | 50.00% |
brian waters | brian waters | 8 | 5.59% | 1 | 25.00% |
takashi iwai | takashi iwai | 4 | 2.80% | 1 | 25.00% |
| Total | 143 | 100.00% | 4 | 100.00% |
static int snd_i2c_bit_probeaddr(struct snd_i2c_bus *bus, unsigned short addr)
{
int err;
if (addr & 0x8000) /* 10-bit address */
return -EIO; /* not yet implemented */
if (addr & 0x7f80) /* invalid address */
return -EINVAL;
snd_i2c_bit_start(bus);
err = snd_i2c_bit_sendbyte(bus, addr << 1);
snd_i2c_bit_stop(bus);
return err;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
jaroslav kysela | jaroslav kysela | 63 | 96.92% | 2 | 66.67% |
takashi iwai | takashi iwai | 2 | 3.08% | 1 | 33.33% |
| Total | 65 | 100.00% | 3 | 100.00% |
static int __init alsa_i2c_init(void)
{
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
jaroslav kysela | jaroslav kysela | 12 | 100.00% | 1 | 100.00% |
| Total | 12 | 100.00% | 1 | 100.00% |
static void __exit alsa_i2c_exit(void)
{
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
jaroslav kysela | jaroslav kysela | 8 | 100.00% | 1 | 100.00% |
| Total | 8 | 100.00% | 1 | 100.00% |
module_init(alsa_i2c_init)
module_exit(alsa_i2c_exit)
Overall Contributors
| Person | Tokens | Prop | Commits | CommitProp |
jaroslav kysela | jaroslav kysela | 1521 | 90.27% | 8 | 42.11% |
takashi iwai | takashi iwai | 127 | 7.54% | 4 | 21.05% |
brian waters | brian waters | 24 | 1.42% | 1 | 5.26% |
david s. miller | david s. miller | 6 | 0.36% | 2 | 10.53% |
paul gortmaker | paul gortmaker | 3 | 0.18% | 1 | 5.26% |
ben collins | ben collins | 2 | 0.12% | 1 | 5.26% |
julia lawall | julia lawall | 1 | 0.06% | 1 | 5.26% |
ingo molnar | ingo molnar | 1 | 0.06% | 1 | 5.26% |
| Total | 1685 | 100.00% | 19 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.