1*a0c7056fSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
29a0bf528SMauro Carvalho Chehab /*
39a0bf528SMauro Carvalho Chehab * tdhd1.h - ALPS TDHD1-204A tuner support
49a0bf528SMauro Carvalho Chehab *
59a0bf528SMauro Carvalho Chehab * Copyright (C) 2008 Oliver Endriss <o.endriss@gmx.de>
69a0bf528SMauro Carvalho Chehab *
7991ce92fSMauro Carvalho Chehab * The project's page is at https://linuxtv.org
89a0bf528SMauro Carvalho Chehab */
99a0bf528SMauro Carvalho Chehab
109a0bf528SMauro Carvalho Chehab #ifndef TDHD1_H
119a0bf528SMauro Carvalho Chehab #define TDHD1_H
129a0bf528SMauro Carvalho Chehab
139a0bf528SMauro Carvalho Chehab #include "tda1004x.h"
149a0bf528SMauro Carvalho Chehab
159a0bf528SMauro Carvalho Chehab static int alps_tdhd1_204_request_firmware(struct dvb_frontend *fe, const struct firmware **fw, char *name);
169a0bf528SMauro Carvalho Chehab
179a0bf528SMauro Carvalho Chehab static struct tda1004x_config alps_tdhd1_204a_config = {
189a0bf528SMauro Carvalho Chehab .demod_address = 0x8,
199a0bf528SMauro Carvalho Chehab .invert = 1,
209a0bf528SMauro Carvalho Chehab .invert_oclk = 0,
219a0bf528SMauro Carvalho Chehab .xtal_freq = TDA10046_XTAL_4M,
229a0bf528SMauro Carvalho Chehab .agc_config = TDA10046_AGC_DEFAULT,
239a0bf528SMauro Carvalho Chehab .if_freq = TDA10046_FREQ_3617,
249a0bf528SMauro Carvalho Chehab .request_firmware = alps_tdhd1_204_request_firmware
259a0bf528SMauro Carvalho Chehab };
269a0bf528SMauro Carvalho Chehab
alps_tdhd1_204a_tuner_set_params(struct dvb_frontend * fe)279a0bf528SMauro Carvalho Chehab static int alps_tdhd1_204a_tuner_set_params(struct dvb_frontend *fe)
289a0bf528SMauro Carvalho Chehab {
299a0bf528SMauro Carvalho Chehab struct dtv_frontend_properties *p = &fe->dtv_property_cache;
309a0bf528SMauro Carvalho Chehab struct i2c_adapter *i2c = fe->tuner_priv;
319a0bf528SMauro Carvalho Chehab u8 data[4];
329a0bf528SMauro Carvalho Chehab struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = data, .len = sizeof(data) };
339a0bf528SMauro Carvalho Chehab u32 div;
349a0bf528SMauro Carvalho Chehab
359a0bf528SMauro Carvalho Chehab div = (p->frequency + 36166666) / 166666;
369a0bf528SMauro Carvalho Chehab
379a0bf528SMauro Carvalho Chehab data[0] = (div >> 8) & 0x7f;
389a0bf528SMauro Carvalho Chehab data[1] = div & 0xff;
399a0bf528SMauro Carvalho Chehab data[2] = 0x85;
409a0bf528SMauro Carvalho Chehab
419a0bf528SMauro Carvalho Chehab if (p->frequency >= 174000000 && p->frequency <= 230000000)
429a0bf528SMauro Carvalho Chehab data[3] = 0x02;
439a0bf528SMauro Carvalho Chehab else if (p->frequency >= 470000000 && p->frequency <= 823000000)
449a0bf528SMauro Carvalho Chehab data[3] = 0x0C;
459a0bf528SMauro Carvalho Chehab else if (p->frequency > 823000000 && p->frequency <= 862000000)
469a0bf528SMauro Carvalho Chehab data[3] = 0x8C;
479a0bf528SMauro Carvalho Chehab else
489a0bf528SMauro Carvalho Chehab return -EINVAL;
499a0bf528SMauro Carvalho Chehab
509a0bf528SMauro Carvalho Chehab if (fe->ops.i2c_gate_ctrl)
519a0bf528SMauro Carvalho Chehab fe->ops.i2c_gate_ctrl(fe, 1);
529a0bf528SMauro Carvalho Chehab if (i2c_transfer(i2c, &msg, 1) != 1)
539a0bf528SMauro Carvalho Chehab return -EIO;
549a0bf528SMauro Carvalho Chehab
559a0bf528SMauro Carvalho Chehab return 0;
569a0bf528SMauro Carvalho Chehab }
579a0bf528SMauro Carvalho Chehab
589a0bf528SMauro Carvalho Chehab #endif /* TDHD1_H */
59