blob: 55973a5fce9e0f142fe14c0f8513d37e8e1fce9e [file] [log] [blame]
Thomas Gleixnera0c70562019-05-23 11:14:50 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Oliver Endriss81ae9532008-09-03 18:16:09 -03002/*
3 * tdhd1.h - ALPS TDHD1-204A tuner support
4 *
5 * Copyright (C) 2008 Oliver Endriss <o.endriss@gmx.de>
6 *
Mauro Carvalho Chehab991ce922015-12-04 10:38:59 -02007 * The project's page is at https://linuxtv.org
Oliver Endriss81ae9532008-09-03 18:16:09 -03008 */
9
10#ifndef TDHD1_H
11#define TDHD1_H
12
13#include "tda1004x.h"
14
Oliver Endriss83512e22008-09-04 20:35:19 -030015static int alps_tdhd1_204_request_firmware(struct dvb_frontend *fe, const struct firmware **fw, char *name);
16
Oliver Endriss81ae9532008-09-03 18:16:09 -030017static struct tda1004x_config alps_tdhd1_204a_config = {
18 .demod_address = 0x8,
19 .invert = 1,
20 .invert_oclk = 0,
21 .xtal_freq = TDA10046_XTAL_4M,
22 .agc_config = TDA10046_AGC_DEFAULT,
23 .if_freq = TDA10046_FREQ_3617,
Oliver Endriss83512e22008-09-04 20:35:19 -030024 .request_firmware = alps_tdhd1_204_request_firmware
Oliver Endriss81ae9532008-09-03 18:16:09 -030025};
26
Mauro Carvalho Chehab14d24d12011-12-24 12:24:33 -030027static int alps_tdhd1_204a_tuner_set_params(struct dvb_frontend *fe)
Oliver Endriss81ae9532008-09-03 18:16:09 -030028{
Mauro Carvalho Chehabe7e10de2011-12-23 18:27:35 -030029 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
Oliver Endriss81ae9532008-09-03 18:16:09 -030030 struct i2c_adapter *i2c = fe->tuner_priv;
31 u8 data[4];
32 struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = data, .len = sizeof(data) };
33 u32 div;
34
Mauro Carvalho Chehabe7e10de2011-12-23 18:27:35 -030035 div = (p->frequency + 36166666) / 166666;
Oliver Endriss81ae9532008-09-03 18:16:09 -030036
37 data[0] = (div >> 8) & 0x7f;
38 data[1] = div & 0xff;
39 data[2] = 0x85;
40
Mauro Carvalho Chehabe7e10de2011-12-23 18:27:35 -030041 if (p->frequency >= 174000000 && p->frequency <= 230000000)
Oliver Endriss81ae9532008-09-03 18:16:09 -030042 data[3] = 0x02;
Mauro Carvalho Chehabe7e10de2011-12-23 18:27:35 -030043 else if (p->frequency >= 470000000 && p->frequency <= 823000000)
Oliver Endriss81ae9532008-09-03 18:16:09 -030044 data[3] = 0x0C;
Mauro Carvalho Chehabe7e10de2011-12-23 18:27:35 -030045 else if (p->frequency > 823000000 && p->frequency <= 862000000)
Oliver Endriss81ae9532008-09-03 18:16:09 -030046 data[3] = 0x8C;
47 else
48 return -EINVAL;
49
50 if (fe->ops.i2c_gate_ctrl)
51 fe->ops.i2c_gate_ctrl(fe, 1);
52 if (i2c_transfer(i2c, &msg, 1) != 1)
53 return -EIO;
54
55 return 0;
56}
57
58#endif /* TDHD1_H */