axehelper: rename i2c commands, add proper support for STV0610 tuners
This commit is contained in:
parent
ae897833ea
commit
e86bc1fc87
@ -66,17 +66,44 @@ demod)
|
|||||||
echo ">>> $n"
|
echo ">>> $n"
|
||||||
echo "********************************************************"
|
echo "********************************************************"
|
||||||
echo
|
echo
|
||||||
axehelper i2c_demod_reg_read --decode $d 0x${a1}12 2
|
axehelper i2c_reg_read --decode $d 0x${a1}12 2
|
||||||
axehelper i2c_demod_reg_read --decode $d 0x${a1}16 1
|
axehelper i2c_reg_read --decode $d 0x${a1}16 1
|
||||||
axehelper i2c_demod_reg_read --decode $d 0x${a2}69 2
|
axehelper i2c_reg_read --decode $d 0x${a2}69 2
|
||||||
axehelper i2c_demod_reg_read --decode $d 0x${a2}70 1
|
axehelper i2c_reg_read --decode $d 0x${a2}70 1
|
||||||
axehelper i2c_demod_reg_read --decode $d 0x${a2}80 5
|
axehelper i2c_reg_read --decode $d 0x${a2}80 5
|
||||||
axehelper i2c_demod_reg_read --decode $d 0x${a2}99 3
|
axehelper i2c_reg_read --decode $d 0x${a2}99 3
|
||||||
axehelper i2c_demod_reg_read --decode $d 0x${a2}9d 3
|
axehelper i2c_reg_read --decode $d 0x${a2}9d 3
|
||||||
axehelper i2c_demod_reg_read --decode $d 0x${a2}a4 1
|
axehelper i2c_reg_read --decode $d 0x${a2}a4 1
|
||||||
axehelper i2c_demod_reg_read --decode $d 0x${a2}ad 3
|
axehelper i2c_reg_read --decode $d 0x${a2}ad 3
|
||||||
done
|
done
|
||||||
;;
|
;;
|
||||||
|
gain)
|
||||||
|
val1="$2"
|
||||||
|
test -z "$val1" && val1="3"
|
||||||
|
echo "Tuner gain set to 0x5${val1}"
|
||||||
|
axehelper i2c_reg_write 0xc0 0x01 0x5${val1}
|
||||||
|
axehelper i2c_reg_write 0xc0 0x0b 0x5${val1}
|
||||||
|
axehelper i2c_reg_write 0xc6 0x01 0x5${val1}
|
||||||
|
axehelper i2c_reg_write 0xc6 0x0b 0x5${val1}
|
||||||
|
;;
|
||||||
|
gain2)
|
||||||
|
val1="$2"
|
||||||
|
test -z "$val1" && val1="9"
|
||||||
|
echo "Demod gain set to 0x4${val1}"
|
||||||
|
axehelper i2c_reg_write 0xd0 0xf2e8 0x4${val1}
|
||||||
|
axehelper i2c_reg_write 0xd0 0xf4e8 0x4${val1}
|
||||||
|
axehelper i2c_reg_write 0xd2 0xf2e8 0x4${val1}
|
||||||
|
axehelper i2c_reg_write 0xd2 0xf4e8 0x4${val1}
|
||||||
|
;;
|
||||||
|
agc2)
|
||||||
|
val1="$2"
|
||||||
|
test -z "$val1" && val1="38"
|
||||||
|
echo "Demod gain set to 0x${val1}"
|
||||||
|
axehelper i2c_reg_write 0xd0 0xf22d 0x${val1}
|
||||||
|
axehelper i2c_reg_write 0xd0 0xf42d 0x${val1}
|
||||||
|
axehelper i2c_reg_write 0xd2 0xf22d 0x${val1}
|
||||||
|
axehelper i2c_reg_write 0xd2 0xf42d 0x${val1}
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
show_help
|
show_help
|
||||||
esac
|
esac
|
||||||
|
@ -1103,6 +1103,15 @@ int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
|
|||||||
(msgs[ret].flags & I2C_M_RECV_LEN) ? "+" : "");
|
(msgs[ret].flags & I2C_M_RECV_LEN) ? "+" : "");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#if 0
|
||||||
|
for (ret = 0; ret < num; ret++) {
|
||||||
|
printk("i2c master_xfer[%d] %c, addr=0x%02x, "
|
||||||
|
"len=%d%s, flags=0x%x\n", ret, (msgs[ret].flags & I2C_M_RD)
|
||||||
|
? 'R' : 'W', msgs[ret].addr, msgs[ret].len,
|
||||||
|
(msgs[ret].flags & I2C_M_RECV_LEN) ? "+" : "",
|
||||||
|
msgs[ret].flags);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (in_atomic() || irqs_disabled()) {
|
if (in_atomic() || irqs_disabled()) {
|
||||||
ret = mutex_trylock(&adap->bus_lock);
|
ret = mutex_trylock(&adap->bus_lock);
|
||||||
|
@ -930,12 +930,15 @@ i2c_open_check(void)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static u8 i2c_repeater[3] = { 0xf1, 0x2a, 0xbc };
|
||||||
|
|
||||||
static int
|
static int
|
||||||
i2c_demod_reg_read(int addr, int reg, u8 *buf, int cnt)
|
i2c_reg_read(int addr, int reg, u8 *buf, int cnt)
|
||||||
{
|
{
|
||||||
u8 buf1[3];
|
u8 buf1[3];
|
||||||
struct i2c_rdwr_ioctl_data d;
|
struct i2c_rdwr_ioctl_data d;
|
||||||
struct i2c_msg m[2];
|
struct i2c_msg m[4];
|
||||||
|
int mi = 0, fmask = 0;
|
||||||
|
|
||||||
if (i2c_open_check())
|
if (i2c_open_check())
|
||||||
return -1;
|
return -1;
|
||||||
@ -945,20 +948,45 @@ i2c_demod_reg_read(int addr, int reg, u8 *buf, int cnt)
|
|||||||
memset(buf1, 0, sizeof(buf1));
|
memset(buf1, 0, sizeof(buf1));
|
||||||
memset(buf, 0, cnt);
|
memset(buf, 0, cnt);
|
||||||
|
|
||||||
|
/* STV0610 */
|
||||||
|
if (addr == 0xc0 || addr == 0xc6) {
|
||||||
|
fmask = I2C_M_NOREPSTART;
|
||||||
|
m[mi].addr = (addr == 0xc0 ? 0xd0 : 0xd2) >> 1;
|
||||||
|
m[mi].len = sizeof(i2c_repeater);
|
||||||
|
m[mi].flags = fmask;
|
||||||
|
m[mi].buf = i2c_repeater;
|
||||||
|
mi++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reg < 256) {
|
||||||
|
buf1[0] = reg;
|
||||||
|
} else {
|
||||||
buf1[0] = reg >> 8;
|
buf1[0] = reg >> 8;
|
||||||
buf1[1] = reg;
|
buf1[1] = reg;
|
||||||
|
}
|
||||||
|
|
||||||
m[0].addr = addr >> 1;
|
m[mi].addr = addr >> 1;
|
||||||
m[0].len = 2;
|
m[mi].len = reg < 256 ? 1 : 2;
|
||||||
m[0].flags = 0;
|
m[mi].flags = fmask;
|
||||||
m[0].buf = buf1;
|
m[mi].buf = buf1;
|
||||||
|
mi++;
|
||||||
|
|
||||||
m[1].addr = addr >> 1;
|
/* STV0610 */
|
||||||
m[1].len = cnt;
|
if (addr == 0xc0 || addr == 0xc6) {
|
||||||
m[1].flags = I2C_M_RD;
|
m[mi].addr = (addr == 0xc0 ? 0xd0 : 0xd2) >> 1;
|
||||||
m[1].buf = buf;
|
m[mi].len = sizeof(i2c_repeater);
|
||||||
|
m[mi].flags = fmask;
|
||||||
|
m[mi].buf = i2c_repeater;
|
||||||
|
mi++;
|
||||||
|
}
|
||||||
|
|
||||||
d.nmsgs = 2;
|
m[mi].addr = addr >> 1;
|
||||||
|
m[mi].len = cnt;
|
||||||
|
m[mi].flags = fmask | I2C_M_RD;
|
||||||
|
m[mi].buf = buf;
|
||||||
|
mi++;
|
||||||
|
|
||||||
|
d.nmsgs = mi;
|
||||||
d.msgs = m;
|
d.msgs = m;
|
||||||
if (ioctl(i2c_fd, I2C_RDWR, &d) < 0) {
|
if (ioctl(i2c_fd, I2C_RDWR, &d) < 0) {
|
||||||
printf("I2C RDWR failed for addr 0x%x\n", addr);
|
printf("I2C RDWR failed for addr 0x%x\n", addr);
|
||||||
@ -968,11 +996,12 @@ i2c_demod_reg_read(int addr, int reg, u8 *buf, int cnt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
i2c_demod_reg_write(int addr, int reg, u8 *buf, int cnt)
|
i2c_reg_write(int addr, int reg, u8 *buf, int cnt)
|
||||||
{
|
{
|
||||||
u8 buf1[32];
|
u8 buf1[32];
|
||||||
struct i2c_rdwr_ioctl_data d;
|
struct i2c_rdwr_ioctl_data d;
|
||||||
struct i2c_msg m[2];
|
struct i2c_msg m[2];
|
||||||
|
int mi = 0, fmask = 0;
|
||||||
|
|
||||||
if (i2c_open_check())
|
if (i2c_open_check())
|
||||||
return -1;
|
return -1;
|
||||||
@ -981,16 +1010,32 @@ i2c_demod_reg_write(int addr, int reg, u8 *buf, int cnt)
|
|||||||
memset(&m, 0, sizeof(m));
|
memset(&m, 0, sizeof(m));
|
||||||
memset(buf1, 0, sizeof(buf1));
|
memset(buf1, 0, sizeof(buf1));
|
||||||
|
|
||||||
|
/* STV0610 */
|
||||||
|
if (addr == 0xc0 || addr == 0xc6) {
|
||||||
|
fmask = I2C_M_NOREPSTART;
|
||||||
|
m[mi].addr = (addr == 0xc0 ? 0xd0 : 0xd2) >> 1;
|
||||||
|
m[mi].len = sizeof(i2c_repeater);
|
||||||
|
m[mi].flags = fmask;
|
||||||
|
m[mi].buf = i2c_repeater;
|
||||||
|
mi++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reg < 256) {
|
||||||
|
buf1[0] = reg;
|
||||||
|
memcpy(buf1 + 1, buf, cnt);
|
||||||
|
} else {
|
||||||
buf1[0] = reg >> 8;
|
buf1[0] = reg >> 8;
|
||||||
buf1[1] = reg;
|
buf1[1] = reg;
|
||||||
memcpy(buf1 + 2, buf, cnt);
|
memcpy(buf1 + 2, buf, cnt);
|
||||||
|
}
|
||||||
|
|
||||||
m[0].addr = addr >> 1;
|
m[mi].addr = addr >> 1;
|
||||||
m[0].len = 2 + cnt;
|
m[mi].len = (reg < 256 ? 1 : 2) + cnt;
|
||||||
m[0].flags = 0;
|
m[mi].flags = fmask;
|
||||||
m[0].buf = buf1;
|
m[mi].buf = buf1;
|
||||||
|
mi++;
|
||||||
|
|
||||||
d.nmsgs = 1;
|
d.nmsgs = mi;
|
||||||
d.msgs = m;
|
d.msgs = m;
|
||||||
if (ioctl(i2c_fd, I2C_RDWR, &d) < 0) {
|
if (ioctl(i2c_fd, I2C_RDWR, &d) < 0) {
|
||||||
printf("I2C RDWR failed for addr 0x%x\n", addr);
|
printf("I2C RDWR failed for addr 0x%x\n", addr);
|
||||||
@ -1010,7 +1055,7 @@ i2c_scan(void)
|
|||||||
if (i2c_open(i, path))
|
if (i2c_open(i, path))
|
||||||
continue;
|
continue;
|
||||||
a = 0xd0;
|
a = 0xd0;
|
||||||
r = i2c_demod_reg_read(a, 0xf000, &v, 1);
|
r = i2c_reg_read(a, 0xf000, &v, 1);
|
||||||
if (r >= 0)
|
if (r >= 0)
|
||||||
printf("I2C read succeed for %s, addr 0x%02x: 0x%02x\n", path, a, v);
|
printf("I2C read succeed for %s, addr 0x%02x: 0x%02x\n", path, a, v);
|
||||||
close(i2c_fd);
|
close(i2c_fd);
|
||||||
@ -1083,20 +1128,26 @@ main(int _argc, char *_argv[])
|
|||||||
if (argc > 1 && !strcmp(argv[1], "i2c_scan")) {
|
if (argc > 1 && !strcmp(argv[1], "i2c_scan")) {
|
||||||
i2c_scan();
|
i2c_scan();
|
||||||
}
|
}
|
||||||
if (argc > 1 && !strcmp(argv[1], "i2c_demod_reg_read")) {
|
if (argc > 1 && !strcmp(argv[1], "i2c_reg_read")) {
|
||||||
if (argc > 3) {
|
if (argc <= 3)
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
int i, j;
|
int i, j;
|
||||||
int a = strtol(argv[2], NULL, 0);
|
int a = strtol(argv[2], NULL, 0);
|
||||||
int r = strtol(argv[3], NULL, 0);
|
int r = strtol(argv[3], NULL, 0);
|
||||||
int c = argc > 4 ? strtol(argv[4], NULL, 0) : 1;
|
int c = argc > 4 ? strtol(argv[4], NULL, 0) : 1;
|
||||||
u8 buf[16];
|
u8 buf[16];
|
||||||
char buf2[256];
|
char buf2[256];
|
||||||
if (a > 0 && r > 0) {
|
if (a <= 0 || r < 0 || c < 0)
|
||||||
i = i2c_demod_reg_read(a, r, buf, c > sizeof(buf) ? sizeof(buf) : c);
|
exit(EXIT_FAILURE);
|
||||||
if (i < 0)
|
i = i2c_reg_read(a, r, buf, c > sizeof(buf) ? sizeof(buf) : c);
|
||||||
|
if (i < 0) {
|
||||||
printf("Unable to read register 0x%x from addr 0x%x\n", r, a);
|
printf("Unable to read register 0x%x from addr 0x%x\n", r, a);
|
||||||
else {
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
if (find_opt("decode")) {
|
if (find_opt("decode")) {
|
||||||
|
if (r < 256)
|
||||||
|
sprintf(buf2, " > (%x, %d) %02x", a & ~1, 2, r & 0xff);
|
||||||
|
else
|
||||||
sprintf(buf2, " > (%x, %d) %02x.%02x", a & ~1, 2, (r >> 8) & 0xff, r & 0xff);
|
sprintf(buf2, " > (%x, %d) %02x.%02x", a & ~1, 2, (r >> 8) & 0xff, r & 0xff);
|
||||||
if (i2c_line(0, 0, 5, buf2) >= 0) {
|
if (i2c_line(0, 0, 5, buf2) >= 0) {
|
||||||
sprintf(buf2, " < (%x, %d) ", a | 1, i);
|
sprintf(buf2, " < (%x, %d) ", a | 1, i);
|
||||||
@ -1113,27 +1164,23 @@ main(int _argc, char *_argv[])
|
|||||||
}
|
}
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
}
|
if (argc > 1 && !strcmp(argv[1], "i2c_reg_write")) {
|
||||||
}
|
if (argc <= 4)
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
|
||||||
if (argc > 1 && !strcmp(argv[1], "i2c_demod_reg_write")) {
|
|
||||||
if (argc > 4) {
|
|
||||||
int i, j;
|
int i, j;
|
||||||
int a = strtol(argv[2], NULL, 0);
|
int a = strtol(argv[2], NULL, 0);
|
||||||
int r = strtol(argv[3], NULL, 0);
|
int r = strtol(argv[3], NULL, 0);
|
||||||
u8 buf[16];
|
u8 buf[16];
|
||||||
for (j = 4; j < argc && j < sizeof(buf) + 4; j++)
|
for (j = 4; j < argc && j < sizeof(buf) + 4; j++)
|
||||||
buf[j-4] = strtol(argv[j], NULL, 0);
|
buf[j-4] = strtol(argv[j], NULL, 0);
|
||||||
if (a > 0 && r > 0) {
|
if (a <= 0 && r < 0)
|
||||||
i = i2c_demod_reg_write(a, r, buf, j);
|
|
||||||
if (i < 0)
|
|
||||||
printf("Unable to write register 0x%x to addr 0x%x\n", r, a);
|
|
||||||
else
|
|
||||||
exit(EXIT_SUCCESS);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
i = i2c_reg_write(a, r, buf, j);
|
||||||
|
if (i < 0) {
|
||||||
|
printf("Unable to write register 0x%x to addr 0x%x\n", r, a);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user