Commit 95e475c9 authored by Gabriel Paubert's avatar Gabriel Paubert Committed by Greg Kroah-Hartman

[PATCH] I2C: Recent I2C "dead code removal" breaks pmac sound.

> Put the function back, and change the pmac.h file to delete the #define,
> and replace the snd_pmac_keywest_write function with a real call to
> i2c_smbus_write_block_data so things like this don't happen again.
>
> Care to write a patch to do this?

It follows, along with an update of the include/linux/i2c.h to only
declare functions that actually exist, but grepping the whole sound
subtree shows that at least sound/oss/dmasound/tas_common.h defines
a few inline functions that call i2c_smbus_write_{byte,block}_data.


[I2C part]
Ressuscitate i2c_smbus_write_block_data since it's actually
used. Update include/linux/i2c.h to reflect the existing
functions.

[Sound part]
Remove snd_pmac_keywest_write* wrapper macros and directly
call the i2c_smbus_* functions instead.
Signed-off-by: default avatarGabriel Paubert <paubert@iram.es>
Signed-off-by: default avatarGreg Kroah-Hartman <greg@kroah.com>


===== include/linux/i2c.h 1.41 vs edited =====
parent bc2c7815
...@@ -1021,6 +1021,22 @@ s32 i2c_smbus_write_word_data(struct i2c_client *client, u8 command, u16 value) ...@@ -1021,6 +1021,22 @@ s32 i2c_smbus_write_word_data(struct i2c_client *client, u8 command, u16 value)
I2C_SMBUS_WORD_DATA,&data); I2C_SMBUS_WORD_DATA,&data);
} }
/* Returns the number of bytes transferred */
s32 i2c_smbus_write_block_data(struct i2c_client *client, u8 command,
u8 length, u8 *values)
{
union i2c_smbus_data data;
int i;
if (length > I2C_SMBUS_BLOCK_MAX)
length = I2C_SMBUS_BLOCK_MAX;
for (i = 1; i <= length; i++)
data.block[i] = values[i-1];
data.block[0] = length;
return i2c_smbus_xfer(client->adapter,client->addr,client->flags,
I2C_SMBUS_WRITE,command,
I2C_SMBUS_BLOCK_DATA,&data);
}
/* Returns the number of read bytes */ /* Returns the number of read bytes */
s32 i2c_smbus_block_process_call(struct i2c_client *client, u8 command, u8 length, u8 *values) s32 i2c_smbus_block_process_call(struct i2c_client *client, u8 command, u8 length, u8 *values)
{ {
...@@ -1279,6 +1295,7 @@ EXPORT_SYMBOL(i2c_smbus_read_byte_data); ...@@ -1279,6 +1295,7 @@ EXPORT_SYMBOL(i2c_smbus_read_byte_data);
EXPORT_SYMBOL(i2c_smbus_write_byte_data); EXPORT_SYMBOL(i2c_smbus_write_byte_data);
EXPORT_SYMBOL(i2c_smbus_read_word_data); EXPORT_SYMBOL(i2c_smbus_read_word_data);
EXPORT_SYMBOL(i2c_smbus_write_word_data); EXPORT_SYMBOL(i2c_smbus_write_word_data);
EXPORT_SYMBOL(i2c_smbus_write_block_data);
EXPORT_SYMBOL(i2c_smbus_read_i2c_block_data); EXPORT_SYMBOL(i2c_smbus_read_i2c_block_data);
EXPORT_SYMBOL(i2c_get_functionality); EXPORT_SYMBOL(i2c_get_functionality);
......
...@@ -88,20 +88,12 @@ extern s32 i2c_smbus_write_byte_data(struct i2c_client * client, ...@@ -88,20 +88,12 @@ extern s32 i2c_smbus_write_byte_data(struct i2c_client * client,
extern s32 i2c_smbus_read_word_data(struct i2c_client * client, u8 command); extern s32 i2c_smbus_read_word_data(struct i2c_client * client, u8 command);
extern s32 i2c_smbus_write_word_data(struct i2c_client * client, extern s32 i2c_smbus_write_word_data(struct i2c_client * client,
u8 command, u16 value); u8 command, u16 value);
extern s32 i2c_smbus_process_call(struct i2c_client * client, /* Returns the number of bytes transferred */
u8 command, u16 value);
/* Returns the number of read bytes */
extern s32 i2c_smbus_read_block_data(struct i2c_client * client,
u8 command, u8 *values);
extern s32 i2c_smbus_write_block_data(struct i2c_client * client, extern s32 i2c_smbus_write_block_data(struct i2c_client * client,
u8 command, u8 length, u8 command, u8 length,
u8 *values); u8 *values);
extern s32 i2c_smbus_read_i2c_block_data(struct i2c_client * client, extern s32 i2c_smbus_read_i2c_block_data(struct i2c_client * client,
u8 command, u8 *values); u8 command, u8 *values);
extern s32 i2c_smbus_write_i2c_block_data(struct i2c_client * client,
u8 command, u8 length,
u8 *values);
/* /*
* A driver is capable of handling one or more physical devices present on * A driver is capable of handling one or more physical devices present on
......
...@@ -56,10 +56,11 @@ static int daca_init_client(pmac_keywest_t *i2c) ...@@ -56,10 +56,11 @@ static int daca_init_client(pmac_keywest_t *i2c)
unsigned short wdata = 0x00; unsigned short wdata = 0x00;
/* SR: no swap, 1bit delay, 32-48kHz */ /* SR: no swap, 1bit delay, 32-48kHz */
/* GCFG: power amp inverted, DAC on */ /* GCFG: power amp inverted, DAC on */
if (snd_pmac_keywest_write_byte(i2c, DACA_REG_SR, 0x08) < 0 || if (i2c_smbus_write_byte_data(i2c->client, DACA_REG_SR, 0x08) < 0 ||
snd_pmac_keywest_write_byte(i2c, DACA_REG_GCFG, 0x05) < 0) i2c_smbus_write_byte_data(i2c->client, DACA_REG_GCFG, 0x05) < 0)
return -EINVAL; return -EINVAL;
return snd_pmac_keywest_write(i2c, DACA_REG_AVOL, 2, (unsigned char*)&wdata); return i2c_smbus_write_block_data(i2c->client, DACA_REG_AVOL,
2, (unsigned char*)&wdata);
} }
/* /*
...@@ -81,7 +82,8 @@ static int daca_set_volume(pmac_daca_t *mix) ...@@ -81,7 +82,8 @@ static int daca_set_volume(pmac_daca_t *mix)
else else
data[1] = mix->right_vol; data[1] = mix->right_vol;
data[1] |= mix->deemphasis ? 0x40 : 0; data[1] |= mix->deemphasis ? 0x40 : 0;
if (snd_pmac_keywest_write(&mix->i2c, DACA_REG_AVOL, 2, data) < 0) { if (i2c_smbus_write_block_data(mix->i2c.client, DACA_REG_AVOL,
2, data) < 0) {
snd_printk("failed to set volume \n"); snd_printk("failed to set volume \n");
return -EINVAL; return -EINVAL;
} }
...@@ -188,7 +190,7 @@ static int daca_put_amp(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol ...@@ -188,7 +190,7 @@ static int daca_put_amp(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol
change = mix->amp_on != ucontrol->value.integer.value[0]; change = mix->amp_on != ucontrol->value.integer.value[0];
if (change) { if (change) {
mix->amp_on = ucontrol->value.integer.value[0]; mix->amp_on = ucontrol->value.integer.value[0];
snd_pmac_keywest_write_byte(&mix->i2c, DACA_REG_GCFG, i2c_smbus_write_byte_data(mix->i2c.client, DACA_REG_GCFG,
mix->amp_on ? 0x05 : 0x04); mix->amp_on ? 0x05 : 0x04);
} }
return change; return change;
...@@ -220,8 +222,8 @@ static snd_kcontrol_new_t daca_mixers[] = { ...@@ -220,8 +222,8 @@ static snd_kcontrol_new_t daca_mixers[] = {
static void daca_resume(pmac_t *chip) static void daca_resume(pmac_t *chip)
{ {
pmac_daca_t *mix = chip->mixer_data; pmac_daca_t *mix = chip->mixer_data;
snd_pmac_keywest_write_byte(&mix->i2c, DACA_REG_SR, 0x08); i2c_smbus_write_byte_data(mix->i2c.client, DACA_REG_SR, 0x08);
snd_pmac_keywest_write_byte(&mix->i2c, DACA_REG_GCFG, i2c_smbus_write_byte_data(mix->i2c.client, DACA_REG_GCFG,
mix->amp_on ? 0x05 : 0x04); mix->amp_on ? 0x05 : 0x04);
daca_set_volume(mix); daca_set_volume(mix);
} }
......
...@@ -199,8 +199,6 @@ typedef struct snd_pmac_keywest { ...@@ -199,8 +199,6 @@ typedef struct snd_pmac_keywest {
int snd_pmac_keywest_init(pmac_keywest_t *i2c); int snd_pmac_keywest_init(pmac_keywest_t *i2c);
void snd_pmac_keywest_cleanup(pmac_keywest_t *i2c); void snd_pmac_keywest_cleanup(pmac_keywest_t *i2c);
#define snd_pmac_keywest_write(i2c,cmd,len,data) i2c_smbus_write_block_data((i2c)->client, cmd, len, data)
#define snd_pmac_keywest_write_byte(i2c,cmd,data) i2c_smbus_write_byte_data((i2c)->client, cmd, data)
/* misc */ /* misc */
int snd_pmac_boolean_stereo_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo); int snd_pmac_boolean_stereo_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo);
......
...@@ -109,7 +109,8 @@ static int send_init_client(pmac_keywest_t *i2c, unsigned int *regs) ...@@ -109,7 +109,8 @@ static int send_init_client(pmac_keywest_t *i2c, unsigned int *regs)
while (*regs > 0) { while (*regs > 0) {
int err, count = 10; int err, count = 10;
do { do {
err = snd_pmac_keywest_write_byte(i2c, regs[0], regs[1]); err = i2c_smbus_write_byte_data(i2c->client,
regs[0], regs[1]);
if (err >= 0) if (err >= 0)
break; break;
mdelay(10); mdelay(10);
...@@ -220,7 +221,8 @@ static int tumbler_set_master_volume(pmac_tumbler_t *mix) ...@@ -220,7 +221,8 @@ static int tumbler_set_master_volume(pmac_tumbler_t *mix)
block[4] = (right_vol >> 8) & 0xff; block[4] = (right_vol >> 8) & 0xff;
block[5] = (right_vol >> 0) & 0xff; block[5] = (right_vol >> 0) & 0xff;
if (snd_pmac_keywest_write(&mix->i2c, TAS_REG_VOL, 6, block) < 0) { if (i2c_smbus_write_block_data(mix->i2c.client, TAS_REG_VOL,
6, block) < 0) {
snd_printk("failed to set volume \n"); snd_printk("failed to set volume \n");
return -EINVAL; return -EINVAL;
} }
...@@ -320,7 +322,8 @@ static int tumbler_set_drc(pmac_tumbler_t *mix) ...@@ -320,7 +322,8 @@ static int tumbler_set_drc(pmac_tumbler_t *mix)
val[1] = 0; val[1] = 0;
} }
if (snd_pmac_keywest_write(&mix->i2c, TAS_REG_DRC, 2, val) < 0) { if (i2c_smbus_write_block_data(mix->i2c.client, TAS_REG_DRC,
2, val) < 0) {
snd_printk("failed to set DRC\n"); snd_printk("failed to set DRC\n");
return -EINVAL; return -EINVAL;
} }
...@@ -355,7 +358,8 @@ static int snapper_set_drc(pmac_tumbler_t *mix) ...@@ -355,7 +358,8 @@ static int snapper_set_drc(pmac_tumbler_t *mix)
val[4] = 0x60; val[4] = 0x60;
val[5] = 0xa0; val[5] = 0xa0;
if (snd_pmac_keywest_write(&mix->i2c, TAS_REG_DRC, 6, val) < 0) { if (i2c_smbus_write_block_data(mix->i2c.client, TAS_REG_DRC,
6, val) < 0) {
snd_printk("failed to set DRC\n"); snd_printk("failed to set DRC\n");
return -EINVAL; return -EINVAL;
} }
...@@ -459,7 +463,8 @@ static int tumbler_set_mono_volume(pmac_tumbler_t *mix, struct tumbler_mono_vol ...@@ -459,7 +463,8 @@ static int tumbler_set_mono_volume(pmac_tumbler_t *mix, struct tumbler_mono_vol
vol = info->table[vol]; vol = info->table[vol];
for (i = 0; i < info->bytes; i++) for (i = 0; i < info->bytes; i++)
block[i] = (vol >> ((info->bytes - i - 1) * 8)) & 0xff; block[i] = (vol >> ((info->bytes - i - 1) * 8)) & 0xff;
if (snd_pmac_keywest_write(&mix->i2c, info->reg, info->bytes, block) < 0) { if (i2c_smbus_write_block_data(mix->i2c.client, info->reg,
info->bytes, block) < 0) {
snd_printk("failed to set mono volume %d\n", info->index); snd_printk("failed to set mono volume %d\n", info->index);
return -EINVAL; return -EINVAL;
} }
...@@ -588,7 +593,7 @@ static int snapper_set_mix_vol1(pmac_tumbler_t *mix, int idx, int ch, int reg) ...@@ -588,7 +593,7 @@ static int snapper_set_mix_vol1(pmac_tumbler_t *mix, int idx, int ch, int reg)
for (j = 0; j < 3; j++) for (j = 0; j < 3; j++)
block[i * 3 + j] = (vol >> ((2 - j) * 8)) & 0xff; block[i * 3 + j] = (vol >> ((2 - j) * 8)) & 0xff;
} }
if (snd_pmac_keywest_write(&mix->i2c, reg, 9, block) < 0) { if (i2c_smbus_write_block_data(mix->i2c.client, reg, 9, block) < 0) {
snd_printk("failed to set mono volume %d\n", reg); snd_printk("failed to set mono volume %d\n", reg);
return -EINVAL; return -EINVAL;
} }
...@@ -689,7 +694,7 @@ static int snapper_set_capture_source(pmac_tumbler_t *mix) ...@@ -689,7 +694,7 @@ static int snapper_set_capture_source(pmac_tumbler_t *mix)
{ {
if (! mix->i2c.client) if (! mix->i2c.client)
return -ENODEV; return -ENODEV;
return snd_pmac_keywest_write_byte(&mix->i2c, TAS_REG_ACS, return i2c_smbus_write_byte_data(mix->i2c.client, TAS_REG_ACS,
mix->capture_source ? 2 : 0); mix->capture_source ? 2 : 0);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment