From 26247018be1ca7ca464f5f32e8ca7c897ded5393 Mon Sep 17 00:00:00 2001 From: Aapo Tahkola Date: Mon, 5 Mar 2007 18:23:19 -0300 Subject: [PATCH] V4L/DVB (5423): M920x: i2c cleanups - Implement m920x i2c as suggested by Pierre Willenbrock - remove "magic" hack - r/w bit is not part of the i2c address - move hardware remarks to header file Signed-off-by: Aapo Tahkola Signed-off-by: Michael Krufky Signed-off-by: Mauro Carvalho Chehab --- drivers/media/dvb/dvb-usb/m920x.c | 69 ++++++++++++------------------- drivers/media/dvb/dvb-usb/m920x.h | 32 ++++++++++---- 2 files changed, 51 insertions(+), 50 deletions(-) diff --git a/drivers/media/dvb/dvb-usb/m920x.c b/drivers/media/dvb/dvb-usb/m920x.c index d48b24d9abf4..92f76c918c79 100644 --- a/drivers/media/dvb/dvb-usb/m920x.c +++ b/drivers/media/dvb/dvb-usb/m920x.c @@ -137,52 +137,45 @@ static int m9206_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num) { struct dvb_usb_device *d = i2c_get_adapdata(adap); - struct m9206_state *m = d->priv; - int i; + int i, j; int ret = 0; if (mutex_lock_interruptible(&d->i2c_mutex) < 0) return -EAGAIN; - if (num > 2) - return -EINVAL; - for (i = 0; i < num; i++) { - if ((ret = m9206_write(d->udev, M9206_I2C, msg[i].addr, 0x80)) != 0) - goto unlock; - - if ((ret = m9206_write(d->udev, M9206_I2C, msg[i].buf[0], 0x0)) != 0) - goto unlock; - - if (i + 1 < num && msg[i + 1].flags & I2C_M_RD) { - int i2c_i; - - for (i2c_i = 0; i2c_i < M9206_I2C_MAX; i2c_i++) - if (msg[i].addr == m->i2c_r[i2c_i].addr) - break; + if (msg[i].flags & I2C_M_RD) { - if (i2c_i >= M9206_I2C_MAX) { - deb_rc("No magic for i2c addr!\n"); - ret = -EINVAL; + if ((ret = m9206_write(d->udev, M9206_I2C, (msg[i].addr << 1) | 0x01, 0x80)) != 0) goto unlock; + + for(j = 0; j < msg[i].len; j++) { + if (j + 1 == msg[i].len && i + 1== num) { + if ((ret = m9206_read(d->udev, M9206_I2C, 0x0, 0x60, &msg[i].buf[j], msg[i].len)) != 0) + goto unlock; + } else { + if ((ret = m9206_read(d->udev, M9206_I2C, 0x0, 0x21, &msg[i].buf[j], msg[i].len)) != 0) + goto unlock; + } } - if ((ret = m9206_write(d->udev, M9206_I2C, m->i2c_r[i2c_i].magic, 0x80)) != 0) + } else { + if ((ret = m9206_write(d->udev, M9206_I2C, msg[i].addr << 1, 0x80)) != 0) goto unlock; - if ((ret = m9206_read(d->udev, M9206_I2C, 0x0, 0x60, msg[i + 1].buf, msg[i + 1].len)) != 0) - goto unlock; + for(j = 0; j < msg[i].len; j++) { + if (j + 1 == msg[i].len && i + 1== num) { + if ((ret = m9206_write(d->udev, M9206_I2C, msg[i].buf[j], 0x40)) != 0) + goto unlock; - i++; - } else { - if (msg[i].len != 2) - return -EINVAL; - - if ((ret = m9206_write(d->udev, M9206_I2C, msg[i].buf[1], 0x40)) != 0) - goto unlock; + } else { + if ((ret = m9206_write(d->udev, M9206_I2C, msg[i].buf[j], 0x0)) != 0) + goto unlock; + } + } } } - ret = i; + ret = num; unlock: mutex_unlock(&d->i2c_mutex); @@ -381,20 +374,15 @@ static int megasky_mt352_demod_init(struct dvb_frontend *fe) } static struct mt352_config megasky_mt352_config = { - .demod_address = 0x1e, + .demod_address = 0x0f, .no_tuner = 1, .demod_init = megasky_mt352_demod_init, }; static int megasky_mt352_frontend_attach(struct dvb_usb_adapter *adap) { - struct m9206_state *m = adap->dev->priv; - deb_rc("megasky_frontend_attach!\n"); - m->i2c_r[M9206_I2C_DEMOD].addr = megasky_mt352_config.demod_address; - m->i2c_r[M9206_I2C_DEMOD].magic = 0x1f; - if ((adap->fe = dvb_attach(mt352_attach, &megasky_mt352_config, &adap->dev->i2c_adap)) == NULL) return -EIO; @@ -402,16 +390,11 @@ static int megasky_mt352_frontend_attach(struct dvb_usb_adapter *adap) } static struct qt1010_config megasky_qt1010_config = { - .i2c_address = 0xc4 + .i2c_address = 0x62 }; static int megasky_qt1010_tuner_attach(struct dvb_usb_adapter *adap) { - struct m9206_state *m = adap->dev->priv; - - m->i2c_r[M9206_I2C_TUNER].addr = megasky_qt1010_config.i2c_address; - m->i2c_r[M9206_I2C_TUNER].magic = 0xc5; - if (dvb_attach(qt1010_attach, adap->fe, &adap->dev->i2c_adap, &megasky_qt1010_config) == NULL) return -ENODEV; diff --git a/drivers/media/dvb/dvb-usb/m920x.h b/drivers/media/dvb/dvb-usb/m920x.h index c354196ffe5d..c5ef592cbfee 100644 --- a/drivers/media/dvb/dvb-usb/m920x.h +++ b/drivers/media/dvb/dvb-usb/m920x.h @@ -19,17 +19,35 @@ #define M9206_MAX_FILTERS 8 -#define M9206_I2C_TUNER 0 -#define M9206_I2C_DEMOD 1 -#define M9206_I2C_MAX 2 +/* +sequences found in logs: +[index value] +0x80 write addr +(0x00 out byte)* +0x40 out byte + +0x80 write addr +(0x00 out byte)* +0x80 read addr +(0x21 in byte)* +0x60 in byte + +this sequence works: +0x80 read addr +(0x21 in byte)* +0x60 in byte + +_my guess_: +0x80: begin i2c transfer using address. value=address<<1|(reading?1:0) +0x00: write byte +0x21: read byte, more to follow +0x40: write last byte of message sequence +0x60: read last byte of message sequence + */ struct m9206_state { u16 filters[M9206_MAX_FILTERS]; int filtering_enabled; int rep_count; - struct { - unsigned char addr; - unsigned char magic; - }i2c_r[M9206_I2C_MAX]; }; #endif -- GitLab