18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * NXP TDA18218HN silicon tuner driver
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2010 Antti Palosaari <crope@iki.fi>
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#include "tda18218_priv.h"
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci/* Max transfer size done by I2C transfer functions */
118c2ecf20Sopenharmony_ci#define MAX_XFER_SIZE  64
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci/* write multiple registers */
148c2ecf20Sopenharmony_cistatic int tda18218_wr_regs(struct tda18218_priv *priv, u8 reg, u8 *val, u8 len)
158c2ecf20Sopenharmony_ci{
168c2ecf20Sopenharmony_ci	int ret = 0, len2, remaining;
178c2ecf20Sopenharmony_ci	u8 buf[MAX_XFER_SIZE];
188c2ecf20Sopenharmony_ci	struct i2c_msg msg[1] = {
198c2ecf20Sopenharmony_ci		{
208c2ecf20Sopenharmony_ci			.addr = priv->cfg->i2c_address,
218c2ecf20Sopenharmony_ci			.flags = 0,
228c2ecf20Sopenharmony_ci			.buf = buf,
238c2ecf20Sopenharmony_ci		}
248c2ecf20Sopenharmony_ci	};
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci	if (1 + len > sizeof(buf)) {
278c2ecf20Sopenharmony_ci		dev_warn(&priv->i2c->dev,
288c2ecf20Sopenharmony_ci			 "%s: i2c wr reg=%04x: len=%d is too big!\n",
298c2ecf20Sopenharmony_ci			 KBUILD_MODNAME, reg, len);
308c2ecf20Sopenharmony_ci		return -EINVAL;
318c2ecf20Sopenharmony_ci	}
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci	for (remaining = len; remaining > 0;
348c2ecf20Sopenharmony_ci			remaining -= (priv->cfg->i2c_wr_max - 1)) {
358c2ecf20Sopenharmony_ci		len2 = remaining;
368c2ecf20Sopenharmony_ci		if (len2 > (priv->cfg->i2c_wr_max - 1))
378c2ecf20Sopenharmony_ci			len2 = (priv->cfg->i2c_wr_max - 1);
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci		msg[0].len = 1 + len2;
408c2ecf20Sopenharmony_ci		buf[0] = reg + len - remaining;
418c2ecf20Sopenharmony_ci		memcpy(&buf[1], &val[len - remaining], len2);
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci		ret = i2c_transfer(priv->i2c, msg, 1);
448c2ecf20Sopenharmony_ci		if (ret != 1)
458c2ecf20Sopenharmony_ci			break;
468c2ecf20Sopenharmony_ci	}
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci	if (ret == 1) {
498c2ecf20Sopenharmony_ci		ret = 0;
508c2ecf20Sopenharmony_ci	} else {
518c2ecf20Sopenharmony_ci		dev_warn(&priv->i2c->dev, "%s: i2c wr failed=%d reg=%02x " \
528c2ecf20Sopenharmony_ci				"len=%d\n", KBUILD_MODNAME, ret, reg, len);
538c2ecf20Sopenharmony_ci		ret = -EREMOTEIO;
548c2ecf20Sopenharmony_ci	}
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci	return ret;
578c2ecf20Sopenharmony_ci}
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci/* read multiple registers */
608c2ecf20Sopenharmony_cistatic int tda18218_rd_regs(struct tda18218_priv *priv, u8 reg, u8 *val, u8 len)
618c2ecf20Sopenharmony_ci{
628c2ecf20Sopenharmony_ci	int ret;
638c2ecf20Sopenharmony_ci	u8 buf[MAX_XFER_SIZE]; /* we must start read always from reg 0x00 */
648c2ecf20Sopenharmony_ci	struct i2c_msg msg[2] = {
658c2ecf20Sopenharmony_ci		{
668c2ecf20Sopenharmony_ci			.addr = priv->cfg->i2c_address,
678c2ecf20Sopenharmony_ci			.flags = 0,
688c2ecf20Sopenharmony_ci			.len = 1,
698c2ecf20Sopenharmony_ci			.buf = "\x00",
708c2ecf20Sopenharmony_ci		}, {
718c2ecf20Sopenharmony_ci			.addr = priv->cfg->i2c_address,
728c2ecf20Sopenharmony_ci			.flags = I2C_M_RD,
738c2ecf20Sopenharmony_ci			.len = reg + len,
748c2ecf20Sopenharmony_ci			.buf = buf,
758c2ecf20Sopenharmony_ci		}
768c2ecf20Sopenharmony_ci	};
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci	if (reg + len > sizeof(buf)) {
798c2ecf20Sopenharmony_ci		dev_warn(&priv->i2c->dev,
808c2ecf20Sopenharmony_ci			 "%s: i2c wr reg=%04x: len=%d is too big!\n",
818c2ecf20Sopenharmony_ci			 KBUILD_MODNAME, reg, len);
828c2ecf20Sopenharmony_ci		return -EINVAL;
838c2ecf20Sopenharmony_ci	}
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci	ret = i2c_transfer(priv->i2c, msg, 2);
868c2ecf20Sopenharmony_ci	if (ret == 2) {
878c2ecf20Sopenharmony_ci		memcpy(val, &buf[reg], len);
888c2ecf20Sopenharmony_ci		ret = 0;
898c2ecf20Sopenharmony_ci	} else {
908c2ecf20Sopenharmony_ci		dev_warn(&priv->i2c->dev, "%s: i2c rd failed=%d reg=%02x " \
918c2ecf20Sopenharmony_ci				"len=%d\n", KBUILD_MODNAME, ret, reg, len);
928c2ecf20Sopenharmony_ci		ret = -EREMOTEIO;
938c2ecf20Sopenharmony_ci	}
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci	return ret;
968c2ecf20Sopenharmony_ci}
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci/* write single register */
998c2ecf20Sopenharmony_cistatic int tda18218_wr_reg(struct tda18218_priv *priv, u8 reg, u8 val)
1008c2ecf20Sopenharmony_ci{
1018c2ecf20Sopenharmony_ci	return tda18218_wr_regs(priv, reg, &val, 1);
1028c2ecf20Sopenharmony_ci}
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci/* read single register */
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_cistatic int tda18218_rd_reg(struct tda18218_priv *priv, u8 reg, u8 *val)
1078c2ecf20Sopenharmony_ci{
1088c2ecf20Sopenharmony_ci	return tda18218_rd_regs(priv, reg, val, 1);
1098c2ecf20Sopenharmony_ci}
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_cistatic int tda18218_set_params(struct dvb_frontend *fe)
1128c2ecf20Sopenharmony_ci{
1138c2ecf20Sopenharmony_ci	struct tda18218_priv *priv = fe->tuner_priv;
1148c2ecf20Sopenharmony_ci	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1158c2ecf20Sopenharmony_ci	u32 bw = c->bandwidth_hz;
1168c2ecf20Sopenharmony_ci	int ret;
1178c2ecf20Sopenharmony_ci	u8 buf[3], i, BP_Filter, LP_Fc;
1188c2ecf20Sopenharmony_ci	u32 LO_Frac;
1198c2ecf20Sopenharmony_ci	/* TODO: find out correct AGC algorithm */
1208c2ecf20Sopenharmony_ci	u8 agc[][2] = {
1218c2ecf20Sopenharmony_ci		{ R20_AGC11, 0x60 },
1228c2ecf20Sopenharmony_ci		{ R23_AGC21, 0x02 },
1238c2ecf20Sopenharmony_ci		{ R20_AGC11, 0xa0 },
1248c2ecf20Sopenharmony_ci		{ R23_AGC21, 0x09 },
1258c2ecf20Sopenharmony_ci		{ R20_AGC11, 0xe0 },
1268c2ecf20Sopenharmony_ci		{ R23_AGC21, 0x0c },
1278c2ecf20Sopenharmony_ci		{ R20_AGC11, 0x40 },
1288c2ecf20Sopenharmony_ci		{ R23_AGC21, 0x01 },
1298c2ecf20Sopenharmony_ci		{ R20_AGC11, 0x80 },
1308c2ecf20Sopenharmony_ci		{ R23_AGC21, 0x08 },
1318c2ecf20Sopenharmony_ci		{ R20_AGC11, 0xc0 },
1328c2ecf20Sopenharmony_ci		{ R23_AGC21, 0x0b },
1338c2ecf20Sopenharmony_ci		{ R24_AGC22, 0x1c },
1348c2ecf20Sopenharmony_ci		{ R24_AGC22, 0x0c },
1358c2ecf20Sopenharmony_ci	};
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci	if (fe->ops.i2c_gate_ctrl)
1388c2ecf20Sopenharmony_ci		fe->ops.i2c_gate_ctrl(fe, 1); /* open I2C-gate */
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_ci	/* low-pass filter cut-off frequency */
1418c2ecf20Sopenharmony_ci	if (bw <= 6000000) {
1428c2ecf20Sopenharmony_ci		LP_Fc = 0;
1438c2ecf20Sopenharmony_ci		priv->if_frequency = 3000000;
1448c2ecf20Sopenharmony_ci	} else if (bw <= 7000000) {
1458c2ecf20Sopenharmony_ci		LP_Fc = 1;
1468c2ecf20Sopenharmony_ci		priv->if_frequency = 3500000;
1478c2ecf20Sopenharmony_ci	} else {
1488c2ecf20Sopenharmony_ci		LP_Fc = 2;
1498c2ecf20Sopenharmony_ci		priv->if_frequency = 4000000;
1508c2ecf20Sopenharmony_ci	}
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci	LO_Frac = c->frequency + priv->if_frequency;
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ci	/* band-pass filter */
1558c2ecf20Sopenharmony_ci	if (LO_Frac < 188000000)
1568c2ecf20Sopenharmony_ci		BP_Filter = 3;
1578c2ecf20Sopenharmony_ci	else if (LO_Frac < 253000000)
1588c2ecf20Sopenharmony_ci		BP_Filter = 4;
1598c2ecf20Sopenharmony_ci	else if (LO_Frac < 343000000)
1608c2ecf20Sopenharmony_ci		BP_Filter = 5;
1618c2ecf20Sopenharmony_ci	else
1628c2ecf20Sopenharmony_ci		BP_Filter = 6;
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ci	buf[0] = (priv->regs[R1A_IF1] & ~7) | BP_Filter; /* BP_Filter */
1658c2ecf20Sopenharmony_ci	buf[1] = (priv->regs[R1B_IF2] & ~3) | LP_Fc; /* LP_Fc */
1668c2ecf20Sopenharmony_ci	buf[2] = priv->regs[R1C_AGC2B];
1678c2ecf20Sopenharmony_ci	ret = tda18218_wr_regs(priv, R1A_IF1, buf, 3);
1688c2ecf20Sopenharmony_ci	if (ret)
1698c2ecf20Sopenharmony_ci		goto error;
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_ci	buf[0] = (LO_Frac / 1000) >> 12; /* LO_Frac_0 */
1728c2ecf20Sopenharmony_ci	buf[1] = (LO_Frac / 1000) >> 4; /* LO_Frac_1 */
1738c2ecf20Sopenharmony_ci	buf[2] = (LO_Frac / 1000) << 4 |
1748c2ecf20Sopenharmony_ci		(priv->regs[R0C_MD5] & 0x0f); /* LO_Frac_2 */
1758c2ecf20Sopenharmony_ci	ret = tda18218_wr_regs(priv, R0A_MD3, buf, 3);
1768c2ecf20Sopenharmony_ci	if (ret)
1778c2ecf20Sopenharmony_ci		goto error;
1788c2ecf20Sopenharmony_ci
1798c2ecf20Sopenharmony_ci	buf[0] = priv->regs[R0F_MD8] | (1 << 6); /* Freq_prog_Start */
1808c2ecf20Sopenharmony_ci	ret = tda18218_wr_regs(priv, R0F_MD8, buf, 1);
1818c2ecf20Sopenharmony_ci	if (ret)
1828c2ecf20Sopenharmony_ci		goto error;
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_ci	buf[0] = priv->regs[R0F_MD8] & ~(1 << 6); /* Freq_prog_Start */
1858c2ecf20Sopenharmony_ci	ret = tda18218_wr_regs(priv, R0F_MD8, buf, 1);
1868c2ecf20Sopenharmony_ci	if (ret)
1878c2ecf20Sopenharmony_ci		goto error;
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_ci	/* trigger AGC */
1908c2ecf20Sopenharmony_ci	for (i = 0; i < ARRAY_SIZE(agc); i++) {
1918c2ecf20Sopenharmony_ci		ret = tda18218_wr_reg(priv, agc[i][0], agc[i][1]);
1928c2ecf20Sopenharmony_ci		if (ret)
1938c2ecf20Sopenharmony_ci			goto error;
1948c2ecf20Sopenharmony_ci	}
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_cierror:
1978c2ecf20Sopenharmony_ci	if (fe->ops.i2c_gate_ctrl)
1988c2ecf20Sopenharmony_ci		fe->ops.i2c_gate_ctrl(fe, 0); /* close I2C-gate */
1998c2ecf20Sopenharmony_ci
2008c2ecf20Sopenharmony_ci	if (ret)
2018c2ecf20Sopenharmony_ci		dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret);
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_ci	return ret;
2048c2ecf20Sopenharmony_ci}
2058c2ecf20Sopenharmony_ci
2068c2ecf20Sopenharmony_cistatic int tda18218_get_if_frequency(struct dvb_frontend *fe, u32 *frequency)
2078c2ecf20Sopenharmony_ci{
2088c2ecf20Sopenharmony_ci	struct tda18218_priv *priv = fe->tuner_priv;
2098c2ecf20Sopenharmony_ci	*frequency = priv->if_frequency;
2108c2ecf20Sopenharmony_ci	dev_dbg(&priv->i2c->dev, "%s: if_frequency=%d\n", __func__, *frequency);
2118c2ecf20Sopenharmony_ci	return 0;
2128c2ecf20Sopenharmony_ci}
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_cistatic int tda18218_sleep(struct dvb_frontend *fe)
2158c2ecf20Sopenharmony_ci{
2168c2ecf20Sopenharmony_ci	struct tda18218_priv *priv = fe->tuner_priv;
2178c2ecf20Sopenharmony_ci	int ret;
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_ci	if (fe->ops.i2c_gate_ctrl)
2208c2ecf20Sopenharmony_ci		fe->ops.i2c_gate_ctrl(fe, 1); /* open I2C-gate */
2218c2ecf20Sopenharmony_ci
2228c2ecf20Sopenharmony_ci	/* standby */
2238c2ecf20Sopenharmony_ci	ret = tda18218_wr_reg(priv, R17_PD1, priv->regs[R17_PD1] | (1 << 0));
2248c2ecf20Sopenharmony_ci
2258c2ecf20Sopenharmony_ci	if (fe->ops.i2c_gate_ctrl)
2268c2ecf20Sopenharmony_ci		fe->ops.i2c_gate_ctrl(fe, 0); /* close I2C-gate */
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_ci	if (ret)
2298c2ecf20Sopenharmony_ci		dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret);
2308c2ecf20Sopenharmony_ci
2318c2ecf20Sopenharmony_ci	return ret;
2328c2ecf20Sopenharmony_ci}
2338c2ecf20Sopenharmony_ci
2348c2ecf20Sopenharmony_cistatic int tda18218_init(struct dvb_frontend *fe)
2358c2ecf20Sopenharmony_ci{
2368c2ecf20Sopenharmony_ci	struct tda18218_priv *priv = fe->tuner_priv;
2378c2ecf20Sopenharmony_ci	int ret;
2388c2ecf20Sopenharmony_ci
2398c2ecf20Sopenharmony_ci	/* TODO: calibrations */
2408c2ecf20Sopenharmony_ci
2418c2ecf20Sopenharmony_ci	if (fe->ops.i2c_gate_ctrl)
2428c2ecf20Sopenharmony_ci		fe->ops.i2c_gate_ctrl(fe, 1); /* open I2C-gate */
2438c2ecf20Sopenharmony_ci
2448c2ecf20Sopenharmony_ci	ret = tda18218_wr_regs(priv, R00_ID, priv->regs, TDA18218_NUM_REGS);
2458c2ecf20Sopenharmony_ci
2468c2ecf20Sopenharmony_ci	if (fe->ops.i2c_gate_ctrl)
2478c2ecf20Sopenharmony_ci		fe->ops.i2c_gate_ctrl(fe, 0); /* close I2C-gate */
2488c2ecf20Sopenharmony_ci
2498c2ecf20Sopenharmony_ci	if (ret)
2508c2ecf20Sopenharmony_ci		dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret);
2518c2ecf20Sopenharmony_ci
2528c2ecf20Sopenharmony_ci	return ret;
2538c2ecf20Sopenharmony_ci}
2548c2ecf20Sopenharmony_ci
2558c2ecf20Sopenharmony_cistatic void tda18218_release(struct dvb_frontend *fe)
2568c2ecf20Sopenharmony_ci{
2578c2ecf20Sopenharmony_ci	kfree(fe->tuner_priv);
2588c2ecf20Sopenharmony_ci	fe->tuner_priv = NULL;
2598c2ecf20Sopenharmony_ci}
2608c2ecf20Sopenharmony_ci
2618c2ecf20Sopenharmony_cistatic const struct dvb_tuner_ops tda18218_tuner_ops = {
2628c2ecf20Sopenharmony_ci	.info = {
2638c2ecf20Sopenharmony_ci		.name              = "NXP TDA18218",
2648c2ecf20Sopenharmony_ci
2658c2ecf20Sopenharmony_ci		.frequency_min_hz  = 174 * MHz,
2668c2ecf20Sopenharmony_ci		.frequency_max_hz  = 864 * MHz,
2678c2ecf20Sopenharmony_ci		.frequency_step_hz =   1 * kHz,
2688c2ecf20Sopenharmony_ci	},
2698c2ecf20Sopenharmony_ci
2708c2ecf20Sopenharmony_ci	.release       = tda18218_release,
2718c2ecf20Sopenharmony_ci	.init          = tda18218_init,
2728c2ecf20Sopenharmony_ci	.sleep         = tda18218_sleep,
2738c2ecf20Sopenharmony_ci
2748c2ecf20Sopenharmony_ci	.set_params    = tda18218_set_params,
2758c2ecf20Sopenharmony_ci
2768c2ecf20Sopenharmony_ci	.get_if_frequency = tda18218_get_if_frequency,
2778c2ecf20Sopenharmony_ci};
2788c2ecf20Sopenharmony_ci
2798c2ecf20Sopenharmony_cistruct dvb_frontend *tda18218_attach(struct dvb_frontend *fe,
2808c2ecf20Sopenharmony_ci	struct i2c_adapter *i2c, struct tda18218_config *cfg)
2818c2ecf20Sopenharmony_ci{
2828c2ecf20Sopenharmony_ci	struct tda18218_priv *priv = NULL;
2838c2ecf20Sopenharmony_ci	u8 val;
2848c2ecf20Sopenharmony_ci	int ret;
2858c2ecf20Sopenharmony_ci	/* chip default registers values */
2868c2ecf20Sopenharmony_ci	static u8 def_regs[] = {
2878c2ecf20Sopenharmony_ci		0xc0, 0x88, 0x00, 0x8e, 0x03, 0x00, 0x00, 0xd0, 0x00, 0x40,
2888c2ecf20Sopenharmony_ci		0x00, 0x00, 0x07, 0xff, 0x84, 0x09, 0x00, 0x13, 0x00, 0x00,
2898c2ecf20Sopenharmony_ci		0x01, 0x84, 0x09, 0xf0, 0x19, 0x0a, 0x8e, 0x69, 0x98, 0x01,
2908c2ecf20Sopenharmony_ci		0x00, 0x58, 0x10, 0x40, 0x8c, 0x00, 0x0c, 0x48, 0x85, 0xc9,
2918c2ecf20Sopenharmony_ci		0xa7, 0x00, 0x00, 0x00, 0x30, 0x81, 0x80, 0x00, 0x39, 0x00,
2928c2ecf20Sopenharmony_ci		0x8a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf6, 0xf6
2938c2ecf20Sopenharmony_ci	};
2948c2ecf20Sopenharmony_ci
2958c2ecf20Sopenharmony_ci	priv = kzalloc(sizeof(struct tda18218_priv), GFP_KERNEL);
2968c2ecf20Sopenharmony_ci	if (priv == NULL)
2978c2ecf20Sopenharmony_ci		return NULL;
2988c2ecf20Sopenharmony_ci
2998c2ecf20Sopenharmony_ci	priv->cfg = cfg;
3008c2ecf20Sopenharmony_ci	priv->i2c = i2c;
3018c2ecf20Sopenharmony_ci	fe->tuner_priv = priv;
3028c2ecf20Sopenharmony_ci
3038c2ecf20Sopenharmony_ci	if (fe->ops.i2c_gate_ctrl)
3048c2ecf20Sopenharmony_ci		fe->ops.i2c_gate_ctrl(fe, 1); /* open I2C-gate */
3058c2ecf20Sopenharmony_ci
3068c2ecf20Sopenharmony_ci	/* check if the tuner is there */
3078c2ecf20Sopenharmony_ci	ret = tda18218_rd_reg(priv, R00_ID, &val);
3088c2ecf20Sopenharmony_ci	if (!ret)
3098c2ecf20Sopenharmony_ci		dev_dbg(&priv->i2c->dev, "%s: chip id=%02x\n", __func__, val);
3108c2ecf20Sopenharmony_ci	if (ret || val != def_regs[R00_ID]) {
3118c2ecf20Sopenharmony_ci		kfree(priv);
3128c2ecf20Sopenharmony_ci		return NULL;
3138c2ecf20Sopenharmony_ci	}
3148c2ecf20Sopenharmony_ci
3158c2ecf20Sopenharmony_ci	dev_info(&priv->i2c->dev,
3168c2ecf20Sopenharmony_ci			"%s: NXP TDA18218HN successfully identified\n",
3178c2ecf20Sopenharmony_ci			KBUILD_MODNAME);
3188c2ecf20Sopenharmony_ci
3198c2ecf20Sopenharmony_ci	memcpy(&fe->ops.tuner_ops, &tda18218_tuner_ops,
3208c2ecf20Sopenharmony_ci		sizeof(struct dvb_tuner_ops));
3218c2ecf20Sopenharmony_ci	memcpy(priv->regs, def_regs, sizeof(def_regs));
3228c2ecf20Sopenharmony_ci
3238c2ecf20Sopenharmony_ci	/* loop-through enabled chip default register values */
3248c2ecf20Sopenharmony_ci	if (priv->cfg->loop_through) {
3258c2ecf20Sopenharmony_ci		priv->regs[R17_PD1] = 0xb0;
3268c2ecf20Sopenharmony_ci		priv->regs[R18_PD2] = 0x59;
3278c2ecf20Sopenharmony_ci	}
3288c2ecf20Sopenharmony_ci
3298c2ecf20Sopenharmony_ci	/* standby */
3308c2ecf20Sopenharmony_ci	ret = tda18218_wr_reg(priv, R17_PD1, priv->regs[R17_PD1] | (1 << 0));
3318c2ecf20Sopenharmony_ci	if (ret)
3328c2ecf20Sopenharmony_ci		dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret);
3338c2ecf20Sopenharmony_ci
3348c2ecf20Sopenharmony_ci	if (fe->ops.i2c_gate_ctrl)
3358c2ecf20Sopenharmony_ci		fe->ops.i2c_gate_ctrl(fe, 0); /* close I2C-gate */
3368c2ecf20Sopenharmony_ci
3378c2ecf20Sopenharmony_ci	return fe;
3388c2ecf20Sopenharmony_ci}
3398c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(tda18218_attach);
3408c2ecf20Sopenharmony_ci
3418c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("NXP TDA18218HN silicon tuner driver");
3428c2ecf20Sopenharmony_ciMODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
3438c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL");
344