xref: /linux/drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd.c (revision 9a87ffc99ec8eb8d35eed7c4f816d75f5cc9662e)
1e5835488SYasunari Takiguchi // SPDX-License-Identifier: GPL-2.0
2e5835488SYasunari Takiguchi /*
3e5835488SYasunari Takiguchi  * cxd2880_tnrdmd.c
4e5835488SYasunari Takiguchi  * Sony CXD2880 DVB-T2/T tuner + demodulator driver
5e5835488SYasunari Takiguchi  * common control functions
6e5835488SYasunari Takiguchi  *
7e5835488SYasunari Takiguchi  * Copyright (C) 2016, 2017, 2018 Sony Semiconductor Solutions Corporation
8e5835488SYasunari Takiguchi  */
9e5835488SYasunari Takiguchi 
107cbc3013SMauro Carvalho Chehab #include <media/dvb_frontend.h>
11e5835488SYasunari Takiguchi #include "cxd2880_common.h"
12e5835488SYasunari Takiguchi #include "cxd2880_tnrdmd.h"
13e5835488SYasunari Takiguchi #include "cxd2880_tnrdmd_mon.h"
14e5835488SYasunari Takiguchi #include "cxd2880_tnrdmd_dvbt.h"
15e5835488SYasunari Takiguchi #include "cxd2880_tnrdmd_dvbt2.h"
16e5835488SYasunari Takiguchi 
17e5835488SYasunari Takiguchi static const struct cxd2880_reg_value p_init1_seq[] = {
18e5835488SYasunari Takiguchi 	{0x11, 0x16}, {0x00, 0x10},
19e5835488SYasunari Takiguchi };
20e5835488SYasunari Takiguchi 
21e5835488SYasunari Takiguchi static const struct cxd2880_reg_value rf_init1_seq1[] = {
22e5835488SYasunari Takiguchi 	{0x4f, 0x18}, {0x61, 0x00}, {0x71, 0x00}, {0x9d, 0x01},
23e5835488SYasunari Takiguchi 	{0x7d, 0x02}, {0x8f, 0x01}, {0x8b, 0xc6}, {0x9a, 0x03},
24e5835488SYasunari Takiguchi 	{0x1c, 0x00},
25e5835488SYasunari Takiguchi };
26e5835488SYasunari Takiguchi 
27e5835488SYasunari Takiguchi static const struct cxd2880_reg_value rf_init1_seq2[] = {
28e5835488SYasunari Takiguchi 	{0xb9, 0x07}, {0x33, 0x01}, {0xc1, 0x01}, {0xc4, 0x1e},
29e5835488SYasunari Takiguchi };
30e5835488SYasunari Takiguchi 
31e5835488SYasunari Takiguchi static const struct cxd2880_reg_value rf_init1_seq3[] = {
32e5835488SYasunari Takiguchi 	{0x00, 0x10}, {0x51, 0x01}, {0xc5, 0x07}, {0x00, 0x11},
33e5835488SYasunari Takiguchi 	{0x70, 0xe9}, {0x76, 0x0a}, {0x78, 0x32}, {0x7a, 0x46},
34e5835488SYasunari Takiguchi 	{0x7c, 0x86}, {0x7e, 0xa4}, {0x00, 0x10}, {0xe1, 0x01},
35e5835488SYasunari Takiguchi };
36e5835488SYasunari Takiguchi 
37e5835488SYasunari Takiguchi static const struct cxd2880_reg_value rf_init1_seq4[] = {
38e5835488SYasunari Takiguchi 	{0x15, 0x00}, {0x00, 0x16}
39e5835488SYasunari Takiguchi };
40e5835488SYasunari Takiguchi 
41e5835488SYasunari Takiguchi static const struct cxd2880_reg_value rf_init1_seq5[] = {
42e5835488SYasunari Takiguchi 	{0x00, 0x00}, {0x25, 0x00}
43e5835488SYasunari Takiguchi };
44e5835488SYasunari Takiguchi 
45e5835488SYasunari Takiguchi static const struct cxd2880_reg_value rf_init1_seq6[] = {
46e5835488SYasunari Takiguchi 	{0x02, 0x00}, {0x00, 0x00}, {0x21, 0x01}, {0x00, 0xe1},
47e5835488SYasunari Takiguchi 	{0x8f, 0x16}, {0x67, 0x60}, {0x6a, 0x0f}, {0x6c, 0x17}
48e5835488SYasunari Takiguchi };
49e5835488SYasunari Takiguchi 
50e5835488SYasunari Takiguchi static const struct cxd2880_reg_value rf_init1_seq7[] = {
51e5835488SYasunari Takiguchi 	{0x00, 0xe2}, {0x41, 0xa0}, {0x4b, 0x68}, {0x00, 0x00},
52e5835488SYasunari Takiguchi 	{0x21, 0x00}, {0x10, 0x01},
53e5835488SYasunari Takiguchi };
54e5835488SYasunari Takiguchi 
55e5835488SYasunari Takiguchi static const struct cxd2880_reg_value rf_init1_seq8[] = {
56e5835488SYasunari Takiguchi 	{0x00, 0x10}, {0x25, 0x01},
57e5835488SYasunari Takiguchi };
58e5835488SYasunari Takiguchi 
59e5835488SYasunari Takiguchi static const struct cxd2880_reg_value rf_init1_seq9[] = {
60e5835488SYasunari Takiguchi 	{0x00, 0x10}, {0x14, 0x01}, {0x00, 0x00}, {0x26, 0x00},
61e5835488SYasunari Takiguchi };
62e5835488SYasunari Takiguchi 
63e5835488SYasunari Takiguchi static const struct cxd2880_reg_value rf_init2_seq1[] = {
64e5835488SYasunari Takiguchi 	{0x00, 0x14}, {0x1b, 0x01},
65e5835488SYasunari Takiguchi };
66e5835488SYasunari Takiguchi 
67e5835488SYasunari Takiguchi static const struct cxd2880_reg_value rf_init2_seq2[] = {
68e5835488SYasunari Takiguchi 	{0x00, 0x00}, {0x21, 0x01}, {0x00, 0xe1}, {0xd3, 0x00},
69e5835488SYasunari Takiguchi 	{0x00, 0x00}, {0x21, 0x00},
70e5835488SYasunari Takiguchi };
71e5835488SYasunari Takiguchi 
72e5835488SYasunari Takiguchi static const struct cxd2880_reg_value x_tune1_seq1[] = {
73e5835488SYasunari Takiguchi 	{0x00, 0x00}, {0x10, 0x01},
74e5835488SYasunari Takiguchi };
75e5835488SYasunari Takiguchi 
76e5835488SYasunari Takiguchi static const struct cxd2880_reg_value x_tune1_seq2[] = {
77e5835488SYasunari Takiguchi 	{0x62, 0x00}, {0x00, 0x15},
78e5835488SYasunari Takiguchi };
79e5835488SYasunari Takiguchi 
80e5835488SYasunari Takiguchi static const struct cxd2880_reg_value x_tune2_seq1[] = {
81e5835488SYasunari Takiguchi 	{0x00, 0x1a}, {0x29, 0x01},
82e5835488SYasunari Takiguchi };
83e5835488SYasunari Takiguchi 
84e5835488SYasunari Takiguchi static const struct cxd2880_reg_value x_tune2_seq2[] = {
85e5835488SYasunari Takiguchi 	{0x62, 0x01}, {0x00, 0x11}, {0x2d, 0x00}, {0x2f, 0x00},
86e5835488SYasunari Takiguchi };
87e5835488SYasunari Takiguchi 
88e5835488SYasunari Takiguchi static const struct cxd2880_reg_value x_tune2_seq3[] = {
89e5835488SYasunari Takiguchi 	{0x00, 0x00}, {0x10, 0x00}, {0x21, 0x01},
90e5835488SYasunari Takiguchi };
91e5835488SYasunari Takiguchi 
92e5835488SYasunari Takiguchi static const struct cxd2880_reg_value x_tune2_seq4[] = {
93e5835488SYasunari Takiguchi 	{0x00, 0xe1}, {0x8a, 0x87},
94e5835488SYasunari Takiguchi };
95e5835488SYasunari Takiguchi 
96e5835488SYasunari Takiguchi static const struct cxd2880_reg_value x_tune2_seq5[] = {
97e5835488SYasunari Takiguchi 	{0x00, 0x00}, {0x21, 0x00},
98e5835488SYasunari Takiguchi };
99e5835488SYasunari Takiguchi 
100e5835488SYasunari Takiguchi static const struct cxd2880_reg_value x_tune3_seq[] = {
101e5835488SYasunari Takiguchi 	{0x00, 0x00}, {0x21, 0x01}, {0x00, 0xe2}, {0x41, 0xa0},
102e5835488SYasunari Takiguchi 	{0x00, 0x00}, {0x21, 0x00}, {0xfe, 0x01},
103e5835488SYasunari Takiguchi };
104e5835488SYasunari Takiguchi 
105e5835488SYasunari Takiguchi static const struct cxd2880_reg_value x_tune4_seq[] = {
106e5835488SYasunari Takiguchi 	{0x00, 0x00}, {0xfe, 0x01},
107e5835488SYasunari Takiguchi };
108e5835488SYasunari Takiguchi 
109e5835488SYasunari Takiguchi static const struct cxd2880_reg_value x_sleep1_seq[] = {
110e5835488SYasunari Takiguchi 	{0x00, 0x00}, {0x57, 0x03},
111e5835488SYasunari Takiguchi };
112e5835488SYasunari Takiguchi 
113e5835488SYasunari Takiguchi static const struct cxd2880_reg_value x_sleep2_seq1[] = {
114e5835488SYasunari Takiguchi 	{0x00, 0x2d}, {0xb1, 0x01},
115e5835488SYasunari Takiguchi };
116e5835488SYasunari Takiguchi 
117e5835488SYasunari Takiguchi static const struct cxd2880_reg_value x_sleep2_seq2[] = {
118e5835488SYasunari Takiguchi 	{0x00, 0x10}, {0xf4, 0x00}, {0xf3, 0x00}, {0xf2, 0x00},
119e5835488SYasunari Takiguchi 	{0xf1, 0x00}, {0xf0, 0x00}, {0xef, 0x00},
120e5835488SYasunari Takiguchi };
121e5835488SYasunari Takiguchi 
122e5835488SYasunari Takiguchi static const struct cxd2880_reg_value x_sleep3_seq[] = {
123e5835488SYasunari Takiguchi 	{0x00, 0x00}, {0xfd, 0x00},
124e5835488SYasunari Takiguchi };
125e5835488SYasunari Takiguchi 
126e5835488SYasunari Takiguchi static const struct cxd2880_reg_value x_sleep4_seq[] = {
127e5835488SYasunari Takiguchi 	{0x00, 0x00}, {0x21, 0x01}, {0x00, 0xe2}, {0x41, 0x00},
128e5835488SYasunari Takiguchi 	{0x00, 0x00}, {0x21, 0x00},
129e5835488SYasunari Takiguchi };
130e5835488SYasunari Takiguchi 
131e5835488SYasunari Takiguchi static const struct cxd2880_reg_value spll_reset_seq1[] = {
132e5835488SYasunari Takiguchi 	{0x00, 0x10}, {0x29, 0x01}, {0x28, 0x01}, {0x27, 0x01},
133e5835488SYasunari Takiguchi 	{0x26, 0x01},
134e5835488SYasunari Takiguchi };
135e5835488SYasunari Takiguchi 
136e5835488SYasunari Takiguchi static const struct cxd2880_reg_value spll_reset_seq2[] = {
137e5835488SYasunari Takiguchi 	{0x00, 0x00}, {0x10, 0x00},
138e5835488SYasunari Takiguchi };
139e5835488SYasunari Takiguchi 
140e5835488SYasunari Takiguchi static const struct cxd2880_reg_value spll_reset_seq3[] = {
141e5835488SYasunari Takiguchi 	{0x00, 0x00}, {0x27, 0x00}, {0x22, 0x01},
142e5835488SYasunari Takiguchi };
143e5835488SYasunari Takiguchi 
144e5835488SYasunari Takiguchi static const struct cxd2880_reg_value spll_reset_seq4[] = {
145e5835488SYasunari Takiguchi 	{0x00, 0x00}, {0x27, 0x01},
146e5835488SYasunari Takiguchi };
147e5835488SYasunari Takiguchi 
148e5835488SYasunari Takiguchi static const struct cxd2880_reg_value spll_reset_seq5[] = {
149e5835488SYasunari Takiguchi 	{0x00, 0x00}, {0x10, 0x01},
150e5835488SYasunari Takiguchi };
151e5835488SYasunari Takiguchi 
152e5835488SYasunari Takiguchi static const struct cxd2880_reg_value t_power_x_seq1[] = {
153e5835488SYasunari Takiguchi 	{0x00, 0x10}, {0x29, 0x01}, {0x28, 0x01}, {0x27, 0x01},
154e5835488SYasunari Takiguchi };
155e5835488SYasunari Takiguchi 
156e5835488SYasunari Takiguchi static const struct cxd2880_reg_value t_power_x_seq2[] = {
157e5835488SYasunari Takiguchi 	{0x00, 0x00}, {0x10, 0x00},
158e5835488SYasunari Takiguchi };
159e5835488SYasunari Takiguchi 
160e5835488SYasunari Takiguchi static const struct cxd2880_reg_value t_power_x_seq3[] = {
161e5835488SYasunari Takiguchi 	{0x00, 0x00}, {0x27, 0x00}, {0x25, 0x01},
162e5835488SYasunari Takiguchi };
163e5835488SYasunari Takiguchi 
164e5835488SYasunari Takiguchi static const struct cxd2880_reg_value t_power_x_seq4[] = {
165e5835488SYasunari Takiguchi 	{0x00, 0x00}, {0x2a, 0x00},
166e5835488SYasunari Takiguchi };
167e5835488SYasunari Takiguchi 
168e5835488SYasunari Takiguchi static const struct cxd2880_reg_value t_power_x_seq5[] = {
169e5835488SYasunari Takiguchi 	{0x00, 0x00}, {0x25, 0x00},
170e5835488SYasunari Takiguchi };
171e5835488SYasunari Takiguchi 
172e5835488SYasunari Takiguchi static const struct cxd2880_reg_value t_power_x_seq6[] = {
173e5835488SYasunari Takiguchi 	{0x00, 0x00}, {0x27, 0x01},
174e5835488SYasunari Takiguchi };
175e5835488SYasunari Takiguchi 
176e5835488SYasunari Takiguchi static const struct cxd2880_reg_value t_power_x_seq7[] = {
177e5835488SYasunari Takiguchi 	{0x00, 0x00}, {0x10, 0x01},
178e5835488SYasunari Takiguchi };
179e5835488SYasunari Takiguchi 
180e5835488SYasunari Takiguchi static const struct cxd2880_reg_value set_ts_pin_seq[] = {
181e5835488SYasunari Takiguchi 	{0x50, 0x3f}, {0x52, 0x1f},
182e5835488SYasunari Takiguchi 
183e5835488SYasunari Takiguchi };
184e5835488SYasunari Takiguchi 
185e5835488SYasunari Takiguchi static const struct cxd2880_reg_value set_ts_output_seq1[] = {
186e5835488SYasunari Takiguchi 	{0x00, 0x00}, {0x52, 0x00},
187e5835488SYasunari Takiguchi };
188e5835488SYasunari Takiguchi 
189e5835488SYasunari Takiguchi static const struct cxd2880_reg_value set_ts_output_seq2[] = {
190e5835488SYasunari Takiguchi 	{0x00, 0x00}, {0xc3, 0x00},
191e5835488SYasunari Takiguchi 
192e5835488SYasunari Takiguchi };
193e5835488SYasunari Takiguchi 
194e5835488SYasunari Takiguchi static const struct cxd2880_reg_value set_ts_output_seq3[] = {
195e5835488SYasunari Takiguchi 	{0x00, 0x00}, {0xc3, 0x01},
196e5835488SYasunari Takiguchi 
197e5835488SYasunari Takiguchi };
198e5835488SYasunari Takiguchi 
199e5835488SYasunari Takiguchi static const struct cxd2880_reg_value set_ts_output_seq4[] = {
200e5835488SYasunari Takiguchi 	{0x00, 0x00}, {0x52, 0x1f},
201e5835488SYasunari Takiguchi 
202e5835488SYasunari Takiguchi };
203e5835488SYasunari Takiguchi 
p_init1(struct cxd2880_tnrdmd * tnr_dmd)204e5835488SYasunari Takiguchi static int p_init1(struct cxd2880_tnrdmd *tnr_dmd)
205e5835488SYasunari Takiguchi {
206e5835488SYasunari Takiguchi 	u8 data = 0;
207e5835488SYasunari Takiguchi 	int ret;
208e5835488SYasunari Takiguchi 
209e5835488SYasunari Takiguchi 	if (!tnr_dmd)
210e5835488SYasunari Takiguchi 		return -EINVAL;
211e5835488SYasunari Takiguchi 
212e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io,
213e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
214e5835488SYasunari Takiguchi 				     0x00, 0x00);
215e5835488SYasunari Takiguchi 	if (ret)
216e5835488SYasunari Takiguchi 		return ret;
217e5835488SYasunari Takiguchi 
218e5835488SYasunari Takiguchi 	if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_SINGLE ||
219e5835488SYasunari Takiguchi 	    tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_MAIN) {
220e5835488SYasunari Takiguchi 		switch (tnr_dmd->create_param.ts_output_if) {
221e5835488SYasunari Takiguchi 		case CXD2880_TNRDMD_TSOUT_IF_TS:
222e5835488SYasunari Takiguchi 			data = 0x00;
223e5835488SYasunari Takiguchi 			break;
224e5835488SYasunari Takiguchi 		case CXD2880_TNRDMD_TSOUT_IF_SPI:
225e5835488SYasunari Takiguchi 			data = 0x01;
226e5835488SYasunari Takiguchi 			break;
227e5835488SYasunari Takiguchi 		case CXD2880_TNRDMD_TSOUT_IF_SDIO:
228e5835488SYasunari Takiguchi 			data = 0x02;
229e5835488SYasunari Takiguchi 			break;
230e5835488SYasunari Takiguchi 		default:
231e5835488SYasunari Takiguchi 			return -EINVAL;
232e5835488SYasunari Takiguchi 		}
233e5835488SYasunari Takiguchi 		ret = tnr_dmd->io->write_reg(tnr_dmd->io,
234e5835488SYasunari Takiguchi 					     CXD2880_IO_TGT_SYS,
235e5835488SYasunari Takiguchi 					     0x10, data);
236e5835488SYasunari Takiguchi 		if (ret)
237e5835488SYasunari Takiguchi 			return ret;
238e5835488SYasunari Takiguchi 	}
239e5835488SYasunari Takiguchi 
240e5835488SYasunari Takiguchi 	ret = cxd2880_io_write_multi_regs(tnr_dmd->io,
241e5835488SYasunari Takiguchi 					  CXD2880_IO_TGT_SYS,
242e5835488SYasunari Takiguchi 					  p_init1_seq,
243e5835488SYasunari Takiguchi 					  ARRAY_SIZE(p_init1_seq));
244e5835488SYasunari Takiguchi 	if (ret)
245e5835488SYasunari Takiguchi 		return ret;
246e5835488SYasunari Takiguchi 
247e5835488SYasunari Takiguchi 	switch (tnr_dmd->chip_id) {
248e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_CHIP_ID_CXD2880_ES1_0X:
249e5835488SYasunari Takiguchi 		data = 0x1a;
250e5835488SYasunari Takiguchi 		break;
251e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_CHIP_ID_CXD2880_ES1_11:
252e5835488SYasunari Takiguchi 		data = 0x16;
253e5835488SYasunari Takiguchi 		break;
254e5835488SYasunari Takiguchi 	default:
255e5835488SYasunari Takiguchi 		return -ENOTTY;
256e5835488SYasunari Takiguchi 	}
257e5835488SYasunari Takiguchi 
258e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io,
259e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
260e5835488SYasunari Takiguchi 				     0x10, data);
261e5835488SYasunari Takiguchi 	if (ret)
262e5835488SYasunari Takiguchi 		return ret;
263e5835488SYasunari Takiguchi 
264e5835488SYasunari Takiguchi 	if (tnr_dmd->create_param.en_internal_ldo)
265e5835488SYasunari Takiguchi 		data = 0x01;
266e5835488SYasunari Takiguchi 	else
267e5835488SYasunari Takiguchi 		data = 0x00;
268e5835488SYasunari Takiguchi 
269e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io,
270e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
271e5835488SYasunari Takiguchi 				     0x11, data);
272e5835488SYasunari Takiguchi 	if (ret)
273e5835488SYasunari Takiguchi 		return ret;
274e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io,
275e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
276e5835488SYasunari Takiguchi 				     0x13, data);
277e5835488SYasunari Takiguchi 	if (ret)
278e5835488SYasunari Takiguchi 		return ret;
279e5835488SYasunari Takiguchi 
280e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io,
281e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
282e5835488SYasunari Takiguchi 				     0x00, 0x00);
283e5835488SYasunari Takiguchi 	if (ret)
284e5835488SYasunari Takiguchi 		return ret;
285e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io,
286e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
287e5835488SYasunari Takiguchi 				     0x12, data);
288e5835488SYasunari Takiguchi 	if (ret)
289e5835488SYasunari Takiguchi 		return ret;
290e5835488SYasunari Takiguchi 
291e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io,
292e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
293e5835488SYasunari Takiguchi 				     0x00, 0x10);
294e5835488SYasunari Takiguchi 	if (ret)
295e5835488SYasunari Takiguchi 		return ret;
296e5835488SYasunari Takiguchi 
297e5835488SYasunari Takiguchi 	switch (tnr_dmd->chip_id) {
298e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_CHIP_ID_CXD2880_ES1_0X:
299e5835488SYasunari Takiguchi 		data = 0x01;
300e5835488SYasunari Takiguchi 		break;
301e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_CHIP_ID_CXD2880_ES1_11:
302e5835488SYasunari Takiguchi 		data = 0x00;
303e5835488SYasunari Takiguchi 		break;
304e5835488SYasunari Takiguchi 	default:
305e5835488SYasunari Takiguchi 		return -ENOTTY;
306e5835488SYasunari Takiguchi 	}
307e5835488SYasunari Takiguchi 
308e5835488SYasunari Takiguchi 	return tnr_dmd->io->write_reg(tnr_dmd->io,
309e5835488SYasunari Takiguchi 				      CXD2880_IO_TGT_SYS,
310e5835488SYasunari Takiguchi 				      0x69, data);
311e5835488SYasunari Takiguchi }
312e5835488SYasunari Takiguchi 
p_init2(struct cxd2880_tnrdmd * tnr_dmd)313e5835488SYasunari Takiguchi static int p_init2(struct cxd2880_tnrdmd *tnr_dmd)
314e5835488SYasunari Takiguchi {
315e5835488SYasunari Takiguchi 	u8 data[6] = { 0 };
316e5835488SYasunari Takiguchi 	int ret;
317e5835488SYasunari Takiguchi 
318e5835488SYasunari Takiguchi 	if (!tnr_dmd)
319e5835488SYasunari Takiguchi 		return -EINVAL;
320e5835488SYasunari Takiguchi 
321e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io,
322e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
323e5835488SYasunari Takiguchi 				     0x00, 0x00);
324e5835488SYasunari Takiguchi 	if (ret)
325e5835488SYasunari Takiguchi 		return ret;
326e5835488SYasunari Takiguchi 	data[0] = tnr_dmd->create_param.xosc_cap;
327e5835488SYasunari Takiguchi 	data[1] = tnr_dmd->create_param.xosc_i;
328e5835488SYasunari Takiguchi 	switch (tnr_dmd->create_param.xtal_share_type) {
329e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_XTAL_SHARE_NONE:
330e5835488SYasunari Takiguchi 		data[2] = 0x01;
331e5835488SYasunari Takiguchi 		data[3] = 0x00;
332e5835488SYasunari Takiguchi 		break;
333e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_XTAL_SHARE_EXTREF:
334e5835488SYasunari Takiguchi 		data[2] = 0x00;
335e5835488SYasunari Takiguchi 		data[3] = 0x00;
336e5835488SYasunari Takiguchi 		break;
337e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_XTAL_SHARE_MASTER:
338e5835488SYasunari Takiguchi 		data[2] = 0x01;
339e5835488SYasunari Takiguchi 		data[3] = 0x01;
340e5835488SYasunari Takiguchi 		break;
341e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_XTAL_SHARE_SLAVE:
342e5835488SYasunari Takiguchi 		data[2] = 0x00;
343e5835488SYasunari Takiguchi 		data[3] = 0x01;
344e5835488SYasunari Takiguchi 		break;
345e5835488SYasunari Takiguchi 	default:
346e5835488SYasunari Takiguchi 		return -EINVAL;
347e5835488SYasunari Takiguchi 	}
348e5835488SYasunari Takiguchi 	data[4] = 0x06;
349e5835488SYasunari Takiguchi 	data[5] = 0x00;
350e5835488SYasunari Takiguchi 
351e5835488SYasunari Takiguchi 	return tnr_dmd->io->write_regs(tnr_dmd->io,
352e5835488SYasunari Takiguchi 				       CXD2880_IO_TGT_SYS,
353e5835488SYasunari Takiguchi 				       0x13, data, 6);
354e5835488SYasunari Takiguchi }
355e5835488SYasunari Takiguchi 
p_init3(struct cxd2880_tnrdmd * tnr_dmd)356e5835488SYasunari Takiguchi static int p_init3(struct cxd2880_tnrdmd *tnr_dmd)
357e5835488SYasunari Takiguchi {
358e5835488SYasunari Takiguchi 	u8 data[2] = { 0 };
359e5835488SYasunari Takiguchi 	int ret;
360e5835488SYasunari Takiguchi 
361e5835488SYasunari Takiguchi 	if (!tnr_dmd)
362e5835488SYasunari Takiguchi 		return -EINVAL;
363e5835488SYasunari Takiguchi 
364e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io,
365e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
366e5835488SYasunari Takiguchi 				     0x00, 0x00);
367e5835488SYasunari Takiguchi 	if (ret)
368e5835488SYasunari Takiguchi 		return ret;
369e5835488SYasunari Takiguchi 
370e5835488SYasunari Takiguchi 	switch (tnr_dmd->diver_mode) {
371e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_DIVERMODE_SINGLE:
372e5835488SYasunari Takiguchi 		data[0] = 0x00;
373e5835488SYasunari Takiguchi 		break;
374e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_DIVERMODE_MAIN:
375e5835488SYasunari Takiguchi 		data[0] = 0x03;
376e5835488SYasunari Takiguchi 		break;
377e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_DIVERMODE_SUB:
378e5835488SYasunari Takiguchi 		data[0] = 0x02;
379e5835488SYasunari Takiguchi 		break;
380e5835488SYasunari Takiguchi 	default:
381e5835488SYasunari Takiguchi 		return -EINVAL;
382e5835488SYasunari Takiguchi 	}
383e5835488SYasunari Takiguchi 
384e5835488SYasunari Takiguchi 	data[1] = 0x01;
385e5835488SYasunari Takiguchi 
386e5835488SYasunari Takiguchi 	return tnr_dmd->io->write_regs(tnr_dmd->io,
387e5835488SYasunari Takiguchi 				       CXD2880_IO_TGT_SYS,
388e5835488SYasunari Takiguchi 				       0x1f, data, 2);
389e5835488SYasunari Takiguchi }
390e5835488SYasunari Takiguchi 
rf_init1(struct cxd2880_tnrdmd * tnr_dmd)391e5835488SYasunari Takiguchi static int rf_init1(struct cxd2880_tnrdmd *tnr_dmd)
392e5835488SYasunari Takiguchi {
393e5835488SYasunari Takiguchi 	u8 data[8] = { 0 };
394e5835488SYasunari Takiguchi 	static const u8 rf_init1_cdata1[40] = {
395e5835488SYasunari Takiguchi 		0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
396e5835488SYasunari Takiguchi 		0x05, 0x05, 0x04, 0x04, 0x04, 0x03, 0x03,
397e5835488SYasunari Takiguchi 		0x03, 0x04, 0x04, 0x05, 0x05, 0x05, 0x02,
398e5835488SYasunari Takiguchi 		0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
399e5835488SYasunari Takiguchi 		0x02, 0x03, 0x02, 0x01, 0x01, 0x01, 0x02,
400e5835488SYasunari Takiguchi 		0x02, 0x03, 0x04, 0x04, 0x04
401e5835488SYasunari Takiguchi 	};
402e5835488SYasunari Takiguchi 
403e5835488SYasunari Takiguchi 	static const u8 rf_init1_cdata2[5] = {0xff, 0x00, 0x00, 0x00, 0x00};
404e5835488SYasunari Takiguchi 	static const u8 rf_init1_cdata3[80] = {
405e5835488SYasunari Takiguchi 		0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
406e5835488SYasunari Takiguchi 		0x01, 0x00, 0x02, 0x00, 0x63, 0x00, 0x00,
407e5835488SYasunari Takiguchi 		0x00, 0x03, 0x00, 0x04, 0x00, 0x04, 0x00,
408e5835488SYasunari Takiguchi 		0x06, 0x00, 0x06, 0x00, 0x08, 0x00, 0x09,
409e5835488SYasunari Takiguchi 		0x00, 0x0b, 0x00, 0x0b, 0x00, 0x0d, 0x00,
410e5835488SYasunari Takiguchi 		0x0d, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f,
411e5835488SYasunari Takiguchi 		0x00, 0x10, 0x00, 0x79, 0x00, 0x00, 0x00,
412e5835488SYasunari Takiguchi 		0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x01,
413e5835488SYasunari Takiguchi 		0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00,
414e5835488SYasunari Takiguchi 		0x04, 0x00, 0x04, 0x00, 0x06, 0x00, 0x05,
415e5835488SYasunari Takiguchi 		0x00, 0x07, 0x00, 0x07, 0x00, 0x08, 0x00,
416e5835488SYasunari Takiguchi 		0x0a, 0x03, 0xe0
417e5835488SYasunari Takiguchi 	};
418e5835488SYasunari Takiguchi 
419e5835488SYasunari Takiguchi 	static const u8 rf_init1_cdata4[8] = {
420e5835488SYasunari Takiguchi 		0x20, 0x20, 0x30, 0x41, 0x50, 0x5f, 0x6f, 0x80
421e5835488SYasunari Takiguchi 	};
422e5835488SYasunari Takiguchi 
423e5835488SYasunari Takiguchi 	static const u8 rf_init1_cdata5[50] = {
424e5835488SYasunari Takiguchi 		0x00, 0x09, 0x00, 0x08, 0x00, 0x07, 0x00,
425e5835488SYasunari Takiguchi 		0x06, 0x00, 0x05, 0x00, 0x03, 0x00, 0x02,
426e5835488SYasunari Takiguchi 		0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00,
427e5835488SYasunari Takiguchi 		0x06, 0x00, 0x08, 0x00, 0x08, 0x00, 0x0c,
428e5835488SYasunari Takiguchi 		0x00, 0x0c, 0x00, 0x0d, 0x00, 0x0f, 0x00,
429e5835488SYasunari Takiguchi 		0x0e, 0x00, 0x0e, 0x00, 0x10, 0x00, 0x0f,
430e5835488SYasunari Takiguchi 		0x00, 0x0e, 0x00, 0x10, 0x00, 0x0f, 0x00,
431e5835488SYasunari Takiguchi 		0x0e
432e5835488SYasunari Takiguchi 	};
433e5835488SYasunari Takiguchi 
434e5835488SYasunari Takiguchi 	u8 addr = 0;
435e5835488SYasunari Takiguchi 	int ret;
436e5835488SYasunari Takiguchi 
437e5835488SYasunari Takiguchi 	if (!tnr_dmd)
438e5835488SYasunari Takiguchi 		return -EINVAL;
439e5835488SYasunari Takiguchi 
440e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io,
441e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
442e5835488SYasunari Takiguchi 				     0x00, 0x00);
443e5835488SYasunari Takiguchi 	if (ret)
444e5835488SYasunari Takiguchi 		return ret;
445e5835488SYasunari Takiguchi 	data[0] = 0x01;
446e5835488SYasunari Takiguchi 	data[1] = 0x00;
447e5835488SYasunari Takiguchi 	data[2] = 0x01;
448e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_regs(tnr_dmd->io,
449e5835488SYasunari Takiguchi 				      CXD2880_IO_TGT_SYS,
450e5835488SYasunari Takiguchi 				      0x21, data, 3);
451e5835488SYasunari Takiguchi 	if (ret)
452e5835488SYasunari Takiguchi 		return ret;
453e5835488SYasunari Takiguchi 
454e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io,
455e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
456e5835488SYasunari Takiguchi 				     0x00, 0x10);
457e5835488SYasunari Takiguchi 	if (ret)
458e5835488SYasunari Takiguchi 		return ret;
459e5835488SYasunari Takiguchi 	data[0] = 0x01;
460e5835488SYasunari Takiguchi 	data[1] = 0x01;
461e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_regs(tnr_dmd->io,
462e5835488SYasunari Takiguchi 				      CXD2880_IO_TGT_SYS,
463e5835488SYasunari Takiguchi 				      0x17, data, 2);
464e5835488SYasunari Takiguchi 	if (ret)
465e5835488SYasunari Takiguchi 		return ret;
466e5835488SYasunari Takiguchi 
467e5835488SYasunari Takiguchi 	if (tnr_dmd->create_param.stationary_use) {
468e5835488SYasunari Takiguchi 		ret = tnr_dmd->io->write_reg(tnr_dmd->io,
469e5835488SYasunari Takiguchi 					     CXD2880_IO_TGT_SYS,
470e5835488SYasunari Takiguchi 					     0x1a, 0x06);
471e5835488SYasunari Takiguchi 		if (ret)
472e5835488SYasunari Takiguchi 			return ret;
473e5835488SYasunari Takiguchi 	}
474e5835488SYasunari Takiguchi 
475e5835488SYasunari Takiguchi 	ret = cxd2880_io_write_multi_regs(tnr_dmd->io,
476e5835488SYasunari Takiguchi 					  CXD2880_IO_TGT_SYS,
477e5835488SYasunari Takiguchi 					  rf_init1_seq1,
478e5835488SYasunari Takiguchi 					  ARRAY_SIZE(rf_init1_seq1));
479e5835488SYasunari Takiguchi 	if (ret)
480e5835488SYasunari Takiguchi 		return ret;
481e5835488SYasunari Takiguchi 
482e5835488SYasunari Takiguchi 	data[0] = 0x00;
483e5835488SYasunari Takiguchi 	if (tnr_dmd->create_param.is_cxd2881gg &&
484e5835488SYasunari Takiguchi 	    tnr_dmd->create_param.xtal_share_type ==
485e5835488SYasunari Takiguchi 		CXD2880_TNRDMD_XTAL_SHARE_SLAVE)
486e5835488SYasunari Takiguchi 		data[1] = 0x00;
487e5835488SYasunari Takiguchi 	else
488e5835488SYasunari Takiguchi 		data[1] = 0x1f;
489e5835488SYasunari Takiguchi 	data[2] = 0x0a;
490e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_regs(tnr_dmd->io,
491e5835488SYasunari Takiguchi 				      CXD2880_IO_TGT_SYS,
492e5835488SYasunari Takiguchi 				      0xb5, data, 3);
493e5835488SYasunari Takiguchi 	if (ret)
494e5835488SYasunari Takiguchi 		return ret;
495e5835488SYasunari Takiguchi 
496e5835488SYasunari Takiguchi 	ret = cxd2880_io_write_multi_regs(tnr_dmd->io,
497e5835488SYasunari Takiguchi 					  CXD2880_IO_TGT_SYS,
498e5835488SYasunari Takiguchi 					  rf_init1_seq2,
499e5835488SYasunari Takiguchi 					  ARRAY_SIZE(rf_init1_seq2));
500e5835488SYasunari Takiguchi 	if (ret)
501e5835488SYasunari Takiguchi 		return ret;
502e5835488SYasunari Takiguchi 
503e5835488SYasunari Takiguchi 	if (tnr_dmd->chip_id == CXD2880_TNRDMD_CHIP_ID_CXD2880_ES1_0X) {
504e5835488SYasunari Takiguchi 		data[0] = 0x34;
505e5835488SYasunari Takiguchi 		data[1] = 0x2c;
506e5835488SYasunari Takiguchi 	} else {
507e5835488SYasunari Takiguchi 		data[0] = 0x2f;
508e5835488SYasunari Takiguchi 		data[1] = 0x25;
509e5835488SYasunari Takiguchi 	}
510e5835488SYasunari Takiguchi 	data[2] = 0x15;
511e5835488SYasunari Takiguchi 	data[3] = 0x19;
512e5835488SYasunari Takiguchi 	data[4] = 0x1b;
513e5835488SYasunari Takiguchi 	data[5] = 0x15;
514e5835488SYasunari Takiguchi 	data[6] = 0x19;
515e5835488SYasunari Takiguchi 	data[7] = 0x1b;
516e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_regs(tnr_dmd->io,
517e5835488SYasunari Takiguchi 				      CXD2880_IO_TGT_SYS,
518e5835488SYasunari Takiguchi 				      0xd9, data, 8);
519e5835488SYasunari Takiguchi 	if (ret)
520e5835488SYasunari Takiguchi 		return ret;
521e5835488SYasunari Takiguchi 
522e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io,
523e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
524e5835488SYasunari Takiguchi 				     0x00, 0x11);
525e5835488SYasunari Takiguchi 	if (ret)
526e5835488SYasunari Takiguchi 		return ret;
527e5835488SYasunari Takiguchi 	data[0] = 0x6c;
528e5835488SYasunari Takiguchi 	data[1] = 0x10;
529e5835488SYasunari Takiguchi 	data[2] = 0xa6;
530e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_regs(tnr_dmd->io,
531e5835488SYasunari Takiguchi 				      CXD2880_IO_TGT_SYS,
532e5835488SYasunari Takiguchi 				      0x44, data, 3);
533e5835488SYasunari Takiguchi 	if (ret)
534e5835488SYasunari Takiguchi 		return ret;
535e5835488SYasunari Takiguchi 	data[0] = 0x16;
536e5835488SYasunari Takiguchi 	data[1] = 0xa8;
537e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_regs(tnr_dmd->io,
538e5835488SYasunari Takiguchi 				      CXD2880_IO_TGT_SYS,
539e5835488SYasunari Takiguchi 				      0x50, data, 2);
540e5835488SYasunari Takiguchi 	if (ret)
541e5835488SYasunari Takiguchi 		return ret;
542e5835488SYasunari Takiguchi 	data[0] = 0x00;
543e5835488SYasunari Takiguchi 	data[1] = 0x22;
544e5835488SYasunari Takiguchi 	data[2] = 0x00;
545e5835488SYasunari Takiguchi 	data[3] = 0x88;
546e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_regs(tnr_dmd->io,
547e5835488SYasunari Takiguchi 				      CXD2880_IO_TGT_SYS,
548e5835488SYasunari Takiguchi 				      0x62, data, 4);
549e5835488SYasunari Takiguchi 	if (ret)
550e5835488SYasunari Takiguchi 		return ret;
551e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io,
552e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
553e5835488SYasunari Takiguchi 				     0x74, 0x75);
554e5835488SYasunari Takiguchi 	if (ret)
555e5835488SYasunari Takiguchi 		return ret;
556e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_regs(tnr_dmd->io,
557e5835488SYasunari Takiguchi 				      CXD2880_IO_TGT_SYS,
558e5835488SYasunari Takiguchi 				      0x7f, rf_init1_cdata1, 40);
559e5835488SYasunari Takiguchi 	if (ret)
560e5835488SYasunari Takiguchi 		return ret;
561e5835488SYasunari Takiguchi 
562e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io,
563e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
564e5835488SYasunari Takiguchi 				     0x00, 0x16);
565e5835488SYasunari Takiguchi 	if (ret)
566e5835488SYasunari Takiguchi 		return ret;
567e5835488SYasunari Takiguchi 	data[0] = 0x00;
568e5835488SYasunari Takiguchi 	data[1] = 0x71;
569e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_regs(tnr_dmd->io,
570e5835488SYasunari Takiguchi 				      CXD2880_IO_TGT_SYS,
571e5835488SYasunari Takiguchi 				      0x10, data, 2);
572e5835488SYasunari Takiguchi 	if (ret)
573e5835488SYasunari Takiguchi 		return ret;
574e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io,
575e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
576e5835488SYasunari Takiguchi 				     0x23, 0x89);
577e5835488SYasunari Takiguchi 	if (ret)
578e5835488SYasunari Takiguchi 		return ret;
579e5835488SYasunari Takiguchi 
580e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_regs(tnr_dmd->io,
581e5835488SYasunari Takiguchi 				      CXD2880_IO_TGT_SYS,
582e5835488SYasunari Takiguchi 				      0x27, rf_init1_cdata2, 5);
583e5835488SYasunari Takiguchi 	if (ret)
584e5835488SYasunari Takiguchi 		return ret;
585e5835488SYasunari Takiguchi 
586e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_regs(tnr_dmd->io,
587e5835488SYasunari Takiguchi 				      CXD2880_IO_TGT_SYS,
588e5835488SYasunari Takiguchi 				      0x3a, rf_init1_cdata3, 80);
589e5835488SYasunari Takiguchi 	if (ret)
590e5835488SYasunari Takiguchi 		return ret;
591e5835488SYasunari Takiguchi 
592e5835488SYasunari Takiguchi 	data[0] = 0x03;
593e5835488SYasunari Takiguchi 	data[1] = 0xe0;
594e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_regs(tnr_dmd->io,
595e5835488SYasunari Takiguchi 				      CXD2880_IO_TGT_SYS,
596e5835488SYasunari Takiguchi 				      0xbc, data, 2);
597e5835488SYasunari Takiguchi 	if (ret)
598e5835488SYasunari Takiguchi 		return ret;
599e5835488SYasunari Takiguchi 
600e5835488SYasunari Takiguchi 	ret = cxd2880_io_write_multi_regs(tnr_dmd->io,
601e5835488SYasunari Takiguchi 					  CXD2880_IO_TGT_SYS,
602e5835488SYasunari Takiguchi 					  rf_init1_seq3,
603e5835488SYasunari Takiguchi 					  ARRAY_SIZE(rf_init1_seq3));
604e5835488SYasunari Takiguchi 	if (ret)
605e5835488SYasunari Takiguchi 		return ret;
606e5835488SYasunari Takiguchi 
607e5835488SYasunari Takiguchi 	if (tnr_dmd->create_param.stationary_use) {
608e5835488SYasunari Takiguchi 		data[0] = 0x06;
609e5835488SYasunari Takiguchi 		data[1] = 0x07;
610e5835488SYasunari Takiguchi 		data[2] = 0x1a;
611e5835488SYasunari Takiguchi 	} else {
612e5835488SYasunari Takiguchi 		data[0] = 0x00;
613e5835488SYasunari Takiguchi 		data[1] = 0x08;
614e5835488SYasunari Takiguchi 		data[2] = 0x19;
615e5835488SYasunari Takiguchi 	}
616e5835488SYasunari Takiguchi 	data[3] = 0x0e;
617e5835488SYasunari Takiguchi 	data[4] = 0x09;
618e5835488SYasunari Takiguchi 	data[5] = 0x0e;
619e5835488SYasunari Takiguchi 
620e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io,
621e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
622e5835488SYasunari Takiguchi 				     0x00, 0x12);
623e5835488SYasunari Takiguchi 	if (ret)
624e5835488SYasunari Takiguchi 		return ret;
625e5835488SYasunari Takiguchi 	for (addr = 0x10; addr < 0x9f; addr += 6) {
626e5835488SYasunari Takiguchi 		if (tnr_dmd->lna_thrs_tbl_air) {
627e5835488SYasunari Takiguchi 			u8 idx = 0;
628e5835488SYasunari Takiguchi 
629e5835488SYasunari Takiguchi 			idx = (addr - 0x10) / 6;
630e5835488SYasunari Takiguchi 			data[0] =
631e5835488SYasunari Takiguchi 			    tnr_dmd->lna_thrs_tbl_air->thrs[idx].off_on;
632e5835488SYasunari Takiguchi 			data[1] =
633e5835488SYasunari Takiguchi 			    tnr_dmd->lna_thrs_tbl_air->thrs[idx].on_off;
634e5835488SYasunari Takiguchi 		}
635e5835488SYasunari Takiguchi 		ret = tnr_dmd->io->write_regs(tnr_dmd->io,
636e5835488SYasunari Takiguchi 					      CXD2880_IO_TGT_SYS,
637e5835488SYasunari Takiguchi 					      addr, data, 6);
638e5835488SYasunari Takiguchi 		if (ret)
639e5835488SYasunari Takiguchi 			return ret;
640e5835488SYasunari Takiguchi 	}
641e5835488SYasunari Takiguchi 
642e5835488SYasunari Takiguchi 	data[0] = 0x00;
643e5835488SYasunari Takiguchi 	data[1] = 0x08;
644e5835488SYasunari Takiguchi 	if (tnr_dmd->create_param.stationary_use)
645e5835488SYasunari Takiguchi 		data[2] = 0x1a;
646e5835488SYasunari Takiguchi 	else
647e5835488SYasunari Takiguchi 		data[2] = 0x19;
648e5835488SYasunari Takiguchi 	data[3] = 0x0e;
649e5835488SYasunari Takiguchi 	data[4] = 0x09;
650e5835488SYasunari Takiguchi 	data[5] = 0x0e;
651e5835488SYasunari Takiguchi 
652e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io,
653e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
654e5835488SYasunari Takiguchi 				     0x00, 0x13);
655e5835488SYasunari Takiguchi 	if (ret)
656e5835488SYasunari Takiguchi 		return ret;
657e5835488SYasunari Takiguchi 	for (addr = 0x10; addr < 0xcf; addr += 6) {
658e5835488SYasunari Takiguchi 		if (tnr_dmd->lna_thrs_tbl_cable) {
659e5835488SYasunari Takiguchi 			u8 idx = 0;
660e5835488SYasunari Takiguchi 
661e5835488SYasunari Takiguchi 			idx = (addr - 0x10) / 6;
662e5835488SYasunari Takiguchi 			data[0] =
663e5835488SYasunari Takiguchi 			    tnr_dmd->lna_thrs_tbl_cable->thrs[idx].off_on;
664e5835488SYasunari Takiguchi 			data[1] =
665e5835488SYasunari Takiguchi 			    tnr_dmd->lna_thrs_tbl_cable->thrs[idx].on_off;
666e5835488SYasunari Takiguchi 		}
667e5835488SYasunari Takiguchi 		ret = tnr_dmd->io->write_regs(tnr_dmd->io,
668e5835488SYasunari Takiguchi 					      CXD2880_IO_TGT_SYS,
669e5835488SYasunari Takiguchi 					      addr, data, 6);
670e5835488SYasunari Takiguchi 		if (ret)
671e5835488SYasunari Takiguchi 			return ret;
672e5835488SYasunari Takiguchi 	}
673e5835488SYasunari Takiguchi 
674e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io,
675e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
676e5835488SYasunari Takiguchi 				     0x00, 0x11);
677e5835488SYasunari Takiguchi 	if (ret)
678e5835488SYasunari Takiguchi 		return ret;
679e5835488SYasunari Takiguchi 	data[0] = 0x08;
680e5835488SYasunari Takiguchi 	data[1] = 0x09;
681e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_regs(tnr_dmd->io,
682e5835488SYasunari Takiguchi 				      CXD2880_IO_TGT_SYS,
683e5835488SYasunari Takiguchi 				      0xbd, data, 2);
684e5835488SYasunari Takiguchi 	if (ret)
685e5835488SYasunari Takiguchi 		return ret;
686e5835488SYasunari Takiguchi 	data[0] = 0x08;
687e5835488SYasunari Takiguchi 	data[1] = 0x09;
688e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_regs(tnr_dmd->io,
689e5835488SYasunari Takiguchi 				      CXD2880_IO_TGT_SYS,
690e5835488SYasunari Takiguchi 				      0xc4, data, 2);
691e5835488SYasunari Takiguchi 	if (ret)
692e5835488SYasunari Takiguchi 		return ret;
693e5835488SYasunari Takiguchi 
694e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_regs(tnr_dmd->io,
695e5835488SYasunari Takiguchi 				      CXD2880_IO_TGT_SYS,
696e5835488SYasunari Takiguchi 				      0xc9, rf_init1_cdata4, 8);
697e5835488SYasunari Takiguchi 	if (ret)
698e5835488SYasunari Takiguchi 		return ret;
699e5835488SYasunari Takiguchi 
700e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io,
701e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
702e5835488SYasunari Takiguchi 				     0x00, 0x14);
703e5835488SYasunari Takiguchi 	if (ret)
704e5835488SYasunari Takiguchi 		return ret;
705e5835488SYasunari Takiguchi 	data[0] = 0x15;
706e5835488SYasunari Takiguchi 	data[1] = 0x18;
707e5835488SYasunari Takiguchi 	data[2] = 0x00;
708e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_regs(tnr_dmd->io,
709e5835488SYasunari Takiguchi 				      CXD2880_IO_TGT_SYS,
710e5835488SYasunari Takiguchi 				      0x10, data, 3);
711e5835488SYasunari Takiguchi 	if (ret)
712e5835488SYasunari Takiguchi 		return ret;
713e5835488SYasunari Takiguchi 
714e5835488SYasunari Takiguchi 	ret = cxd2880_io_write_multi_regs(tnr_dmd->io,
715e5835488SYasunari Takiguchi 					  CXD2880_IO_TGT_SYS,
716e5835488SYasunari Takiguchi 					  rf_init1_seq4,
717e5835488SYasunari Takiguchi 					  ARRAY_SIZE(rf_init1_seq4));
718e5835488SYasunari Takiguchi 	if (ret)
719e5835488SYasunari Takiguchi 		return ret;
720e5835488SYasunari Takiguchi 
721e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_regs(tnr_dmd->io,
722e5835488SYasunari Takiguchi 				      CXD2880_IO_TGT_SYS,
723e5835488SYasunari Takiguchi 				      0x12, rf_init1_cdata5, 50);
724e5835488SYasunari Takiguchi 	if (ret)
725e5835488SYasunari Takiguchi 		return ret;
726e5835488SYasunari Takiguchi 
727e5835488SYasunari Takiguchi 	usleep_range(1000, 2000);
728e5835488SYasunari Takiguchi 
729e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io,
730e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
731e5835488SYasunari Takiguchi 				     0x00, 0x0a);
732e5835488SYasunari Takiguchi 	if (ret)
733e5835488SYasunari Takiguchi 		return ret;
734e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->read_regs(tnr_dmd->io,
735e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
736e5835488SYasunari Takiguchi 				     0x10, data, 1);
737e5835488SYasunari Takiguchi 	if (ret)
738e5835488SYasunari Takiguchi 		return ret;
739e5835488SYasunari Takiguchi 	if ((data[0] & 0x01) == 0x00)
740e5835488SYasunari Takiguchi 		return -EINVAL;
741e5835488SYasunari Takiguchi 
742e5835488SYasunari Takiguchi 	ret = cxd2880_io_write_multi_regs(tnr_dmd->io,
743e5835488SYasunari Takiguchi 					  CXD2880_IO_TGT_SYS,
744e5835488SYasunari Takiguchi 					  rf_init1_seq5,
745e5835488SYasunari Takiguchi 					  ARRAY_SIZE(rf_init1_seq5));
746e5835488SYasunari Takiguchi 	if (ret)
747e5835488SYasunari Takiguchi 		return ret;
748e5835488SYasunari Takiguchi 
749e5835488SYasunari Takiguchi 	usleep_range(1000, 2000);
750e5835488SYasunari Takiguchi 
751e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io,
752e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
753e5835488SYasunari Takiguchi 				     0x00, 0x0a);
754e5835488SYasunari Takiguchi 	if (ret)
755e5835488SYasunari Takiguchi 		return ret;
756e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->read_regs(tnr_dmd->io,
757e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
758e5835488SYasunari Takiguchi 				     0x11, data, 1);
759e5835488SYasunari Takiguchi 	if (ret)
760e5835488SYasunari Takiguchi 		return ret;
761e5835488SYasunari Takiguchi 	if ((data[0] & 0x01) == 0x00)
762e5835488SYasunari Takiguchi 		return -EINVAL;
763e5835488SYasunari Takiguchi 
764e5835488SYasunari Takiguchi 	ret = cxd2880_io_write_multi_regs(tnr_dmd->io,
765e5835488SYasunari Takiguchi 					  CXD2880_IO_TGT_DMD,
766e5835488SYasunari Takiguchi 					  rf_init1_seq6,
767e5835488SYasunari Takiguchi 					  ARRAY_SIZE(rf_init1_seq6));
768e5835488SYasunari Takiguchi 	if (ret)
769e5835488SYasunari Takiguchi 		return ret;
770e5835488SYasunari Takiguchi 
771e5835488SYasunari Takiguchi 	data[0] = 0x00;
772e5835488SYasunari Takiguchi 	data[1] = 0xfe;
773e5835488SYasunari Takiguchi 	data[2] = 0xee;
774e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_regs(tnr_dmd->io,
775e5835488SYasunari Takiguchi 				      CXD2880_IO_TGT_DMD,
776e5835488SYasunari Takiguchi 				      0x6e, data, 3);
777e5835488SYasunari Takiguchi 	if (ret)
778e5835488SYasunari Takiguchi 		return ret;
779e5835488SYasunari Takiguchi 	data[0] = 0xa1;
780e5835488SYasunari Takiguchi 	data[1] = 0x8b;
781e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_regs(tnr_dmd->io,
782e5835488SYasunari Takiguchi 				      CXD2880_IO_TGT_DMD,
783e5835488SYasunari Takiguchi 				      0x8d, data, 2);
784e5835488SYasunari Takiguchi 	if (ret)
785e5835488SYasunari Takiguchi 		return ret;
786e5835488SYasunari Takiguchi 	data[0] = 0x08;
787e5835488SYasunari Takiguchi 	data[1] = 0x09;
788e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_regs(tnr_dmd->io,
789e5835488SYasunari Takiguchi 				      CXD2880_IO_TGT_DMD,
790e5835488SYasunari Takiguchi 				      0x77, data, 2);
791e5835488SYasunari Takiguchi 	if (ret)
792e5835488SYasunari Takiguchi 		return ret;
793e5835488SYasunari Takiguchi 
794e5835488SYasunari Takiguchi 	if (tnr_dmd->create_param.stationary_use) {
795e5835488SYasunari Takiguchi 		ret = tnr_dmd->io->write_reg(tnr_dmd->io,
796e5835488SYasunari Takiguchi 					     CXD2880_IO_TGT_DMD,
797e5835488SYasunari Takiguchi 					     0x80, 0xaa);
798e5835488SYasunari Takiguchi 		if (ret)
799e5835488SYasunari Takiguchi 			return ret;
800e5835488SYasunari Takiguchi 	}
801e5835488SYasunari Takiguchi 
802e5835488SYasunari Takiguchi 	ret = cxd2880_io_write_multi_regs(tnr_dmd->io,
803e5835488SYasunari Takiguchi 					  CXD2880_IO_TGT_DMD,
804e5835488SYasunari Takiguchi 					  rf_init1_seq7,
805e5835488SYasunari Takiguchi 					  ARRAY_SIZE(rf_init1_seq7));
806e5835488SYasunari Takiguchi 	if (ret)
807e5835488SYasunari Takiguchi 		return ret;
808e5835488SYasunari Takiguchi 
809e5835488SYasunari Takiguchi 	ret = cxd2880_io_write_multi_regs(tnr_dmd->io,
810e5835488SYasunari Takiguchi 					  CXD2880_IO_TGT_SYS,
811e5835488SYasunari Takiguchi 					  rf_init1_seq8,
812e5835488SYasunari Takiguchi 					  ARRAY_SIZE(rf_init1_seq8));
813e5835488SYasunari Takiguchi 	if (ret)
814e5835488SYasunari Takiguchi 		return ret;
815e5835488SYasunari Takiguchi 
816e5835488SYasunari Takiguchi 	usleep_range(1000, 2000);
817e5835488SYasunari Takiguchi 
818e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io,
819e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
820e5835488SYasunari Takiguchi 				     0x00, 0x1a);
821e5835488SYasunari Takiguchi 	if (ret)
822e5835488SYasunari Takiguchi 		return ret;
823e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->read_regs(tnr_dmd->io,
824e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
825e5835488SYasunari Takiguchi 				     0x10, data, 1);
826e5835488SYasunari Takiguchi 	if (ret)
827e5835488SYasunari Takiguchi 		return ret;
828e5835488SYasunari Takiguchi 	if ((data[0] & 0x01) == 0x00)
829e5835488SYasunari Takiguchi 		return -EINVAL;
830e5835488SYasunari Takiguchi 
831e5835488SYasunari Takiguchi 	return cxd2880_io_write_multi_regs(tnr_dmd->io,
832e5835488SYasunari Takiguchi 					   CXD2880_IO_TGT_SYS,
833e5835488SYasunari Takiguchi 					   rf_init1_seq9,
834e5835488SYasunari Takiguchi 					   ARRAY_SIZE(rf_init1_seq9));
835e5835488SYasunari Takiguchi }
836e5835488SYasunari Takiguchi 
rf_init2(struct cxd2880_tnrdmd * tnr_dmd)837e5835488SYasunari Takiguchi static int rf_init2(struct cxd2880_tnrdmd *tnr_dmd)
838e5835488SYasunari Takiguchi {
839e5835488SYasunari Takiguchi 	u8 data[5] = { 0 };
840e5835488SYasunari Takiguchi 	int ret;
841e5835488SYasunari Takiguchi 
842e5835488SYasunari Takiguchi 	if (!tnr_dmd)
843e5835488SYasunari Takiguchi 		return -EINVAL;
844e5835488SYasunari Takiguchi 
845e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io,
846e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
847e5835488SYasunari Takiguchi 				     0x00, 0x10);
848e5835488SYasunari Takiguchi 	if (ret)
849e5835488SYasunari Takiguchi 		return ret;
850e5835488SYasunari Takiguchi 	data[0] = 0x40;
851e5835488SYasunari Takiguchi 	data[1] = 0x40;
852e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_regs(tnr_dmd->io,
853e5835488SYasunari Takiguchi 				      CXD2880_IO_TGT_SYS,
854e5835488SYasunari Takiguchi 				      0xea, data, 2);
855e5835488SYasunari Takiguchi 	if (ret)
856e5835488SYasunari Takiguchi 		return ret;
857e5835488SYasunari Takiguchi 
858e5835488SYasunari Takiguchi 	usleep_range(1000, 2000);
859e5835488SYasunari Takiguchi 
860e5835488SYasunari Takiguchi 	data[0] = 0x00;
861e5835488SYasunari Takiguchi 	if (tnr_dmd->chip_id == CXD2880_TNRDMD_CHIP_ID_CXD2880_ES1_0X)
862e5835488SYasunari Takiguchi 		data[1] = 0x00;
863e5835488SYasunari Takiguchi 	else
864e5835488SYasunari Takiguchi 		data[1] = 0x01;
865e5835488SYasunari Takiguchi 	data[2] = 0x01;
866e5835488SYasunari Takiguchi 	data[3] = 0x03;
867e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_regs(tnr_dmd->io,
868e5835488SYasunari Takiguchi 				      CXD2880_IO_TGT_SYS,
869e5835488SYasunari Takiguchi 				      0x30, data, 4);
870e5835488SYasunari Takiguchi 	if (ret)
871e5835488SYasunari Takiguchi 		return ret;
872e5835488SYasunari Takiguchi 
873e5835488SYasunari Takiguchi 	ret = cxd2880_io_write_multi_regs(tnr_dmd->io,
874e5835488SYasunari Takiguchi 					  CXD2880_IO_TGT_SYS,
875e5835488SYasunari Takiguchi 					  rf_init2_seq1,
876e5835488SYasunari Takiguchi 					  ARRAY_SIZE(rf_init2_seq1));
877e5835488SYasunari Takiguchi 	if (ret)
878e5835488SYasunari Takiguchi 		return ret;
879e5835488SYasunari Takiguchi 
880e5835488SYasunari Takiguchi 	return cxd2880_io_write_multi_regs(tnr_dmd->io,
881e5835488SYasunari Takiguchi 					   CXD2880_IO_TGT_DMD,
882e5835488SYasunari Takiguchi 					   rf_init2_seq2,
883e5835488SYasunari Takiguchi 					   ARRAY_SIZE(rf_init2_seq2));
884e5835488SYasunari Takiguchi }
885e5835488SYasunari Takiguchi 
x_tune1(struct cxd2880_tnrdmd * tnr_dmd,enum cxd2880_dtv_sys sys,u32 freq_khz,enum cxd2880_dtv_bandwidth bandwidth,u8 is_cable,int shift_frequency_khz)886e5835488SYasunari Takiguchi static int x_tune1(struct cxd2880_tnrdmd *tnr_dmd,
887e5835488SYasunari Takiguchi 		   enum cxd2880_dtv_sys sys, u32 freq_khz,
888e5835488SYasunari Takiguchi 		   enum cxd2880_dtv_bandwidth bandwidth,
889e5835488SYasunari Takiguchi 		   u8 is_cable, int shift_frequency_khz)
890e5835488SYasunari Takiguchi {
891e5835488SYasunari Takiguchi 	u8 data[11] = { 0 };
892e5835488SYasunari Takiguchi 	int ret;
893e5835488SYasunari Takiguchi 
894e5835488SYasunari Takiguchi 	if (!tnr_dmd)
895e5835488SYasunari Takiguchi 		return -EINVAL;
896e5835488SYasunari Takiguchi 
897e5835488SYasunari Takiguchi 	ret = cxd2880_io_write_multi_regs(tnr_dmd->io,
898e5835488SYasunari Takiguchi 					  CXD2880_IO_TGT_DMD,
899e5835488SYasunari Takiguchi 					  x_tune1_seq1,
900e5835488SYasunari Takiguchi 					  ARRAY_SIZE(x_tune1_seq1));
901e5835488SYasunari Takiguchi 	if (ret)
902e5835488SYasunari Takiguchi 		return ret;
903e5835488SYasunari Takiguchi 
904e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io,
905e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
906e5835488SYasunari Takiguchi 				     0x00, 0x10);
907e5835488SYasunari Takiguchi 	if (ret)
908e5835488SYasunari Takiguchi 		return ret;
909e5835488SYasunari Takiguchi 
910e5835488SYasunari Takiguchi 	data[2] = 0x0e;
911e5835488SYasunari Takiguchi 	data[4] = 0x03;
912e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_regs(tnr_dmd->io,
913e5835488SYasunari Takiguchi 				      CXD2880_IO_TGT_SYS,
914e5835488SYasunari Takiguchi 				      0xe7, data, 5);
915e5835488SYasunari Takiguchi 	if (ret)
916e5835488SYasunari Takiguchi 		return ret;
917e5835488SYasunari Takiguchi 
918e5835488SYasunari Takiguchi 	data[0] = 0x1f;
919e5835488SYasunari Takiguchi 	data[1] = 0x80;
920e5835488SYasunari Takiguchi 	data[2] = 0x18;
921e5835488SYasunari Takiguchi 	data[3] = 0x00;
922e5835488SYasunari Takiguchi 	data[4] = 0x07;
923e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_regs(tnr_dmd->io,
924e5835488SYasunari Takiguchi 				      CXD2880_IO_TGT_SYS,
925e5835488SYasunari Takiguchi 				      0xe7, data, 5);
926e5835488SYasunari Takiguchi 	if (ret)
927e5835488SYasunari Takiguchi 		return ret;
928e5835488SYasunari Takiguchi 
929e5835488SYasunari Takiguchi 	usleep_range(1000, 2000);
930e5835488SYasunari Takiguchi 
931e5835488SYasunari Takiguchi 	data[0] = 0x72;
932e5835488SYasunari Takiguchi 	data[1] = 0x81;
933e5835488SYasunari Takiguchi 	data[3] = 0x1d;
934e5835488SYasunari Takiguchi 	data[4] = 0x6f;
935e5835488SYasunari Takiguchi 	data[5] = 0x7e;
936e5835488SYasunari Takiguchi 	data[7] = 0x1c;
937e5835488SYasunari Takiguchi 	switch (sys) {
938e5835488SYasunari Takiguchi 	case CXD2880_DTV_SYS_DVBT:
939e5835488SYasunari Takiguchi 		data[2] = 0x94;
940e5835488SYasunari Takiguchi 		data[6] = 0x91;
941e5835488SYasunari Takiguchi 		break;
942e5835488SYasunari Takiguchi 	case CXD2880_DTV_SYS_DVBT2:
943e5835488SYasunari Takiguchi 		data[2] = 0x96;
944e5835488SYasunari Takiguchi 		data[6] = 0x93;
945e5835488SYasunari Takiguchi 		break;
946e5835488SYasunari Takiguchi 	default:
947e5835488SYasunari Takiguchi 		return -EINVAL;
948e5835488SYasunari Takiguchi 	}
949e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_regs(tnr_dmd->io,
950e5835488SYasunari Takiguchi 				      CXD2880_IO_TGT_SYS,
951e5835488SYasunari Takiguchi 				      0x44, data, 8);
952e5835488SYasunari Takiguchi 	if (ret)
953e5835488SYasunari Takiguchi 		return ret;
954e5835488SYasunari Takiguchi 
955e5835488SYasunari Takiguchi 	ret = cxd2880_io_write_multi_regs(tnr_dmd->io,
956e5835488SYasunari Takiguchi 					  CXD2880_IO_TGT_SYS,
957e5835488SYasunari Takiguchi 					  x_tune1_seq2,
958e5835488SYasunari Takiguchi 					  ARRAY_SIZE(x_tune1_seq2));
959e5835488SYasunari Takiguchi 	if (ret)
960e5835488SYasunari Takiguchi 		return ret;
961e5835488SYasunari Takiguchi 
962e5835488SYasunari Takiguchi 	data[0] = 0x03;
963e5835488SYasunari Takiguchi 	data[1] = 0xe2;
964e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_regs(tnr_dmd->io,
965e5835488SYasunari Takiguchi 				      CXD2880_IO_TGT_SYS,
966e5835488SYasunari Takiguchi 				      0x1e, data, 2);
967e5835488SYasunari Takiguchi 	if (ret)
968e5835488SYasunari Takiguchi 		return ret;
969e5835488SYasunari Takiguchi 
970e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io,
971e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
972e5835488SYasunari Takiguchi 				     0x00, 0x10);
973e5835488SYasunari Takiguchi 	if (ret)
974e5835488SYasunari Takiguchi 		return ret;
975e5835488SYasunari Takiguchi 
976e5835488SYasunari Takiguchi 	data[0] = is_cable ? 0x01 : 0x00;
977e5835488SYasunari Takiguchi 	data[1] = 0x00;
978e5835488SYasunari Takiguchi 	data[2] = 0x6b;
979e5835488SYasunari Takiguchi 	data[3] = 0x4d;
980e5835488SYasunari Takiguchi 
981e5835488SYasunari Takiguchi 	switch (bandwidth) {
982e5835488SYasunari Takiguchi 	case CXD2880_DTV_BW_1_7_MHZ:
983e5835488SYasunari Takiguchi 		data[4] = 0x03;
984e5835488SYasunari Takiguchi 		break;
985e5835488SYasunari Takiguchi 	case CXD2880_DTV_BW_5_MHZ:
986e5835488SYasunari Takiguchi 	case CXD2880_DTV_BW_6_MHZ:
987e5835488SYasunari Takiguchi 		data[4] = 0x00;
988e5835488SYasunari Takiguchi 		break;
989e5835488SYasunari Takiguchi 	case CXD2880_DTV_BW_7_MHZ:
990e5835488SYasunari Takiguchi 		data[4] = 0x01;
991e5835488SYasunari Takiguchi 		break;
992e5835488SYasunari Takiguchi 	case CXD2880_DTV_BW_8_MHZ:
993e5835488SYasunari Takiguchi 		data[4] = 0x02;
994e5835488SYasunari Takiguchi 		break;
995e5835488SYasunari Takiguchi 	default:
996e5835488SYasunari Takiguchi 		return -EINVAL;
997e5835488SYasunari Takiguchi 	}
998e5835488SYasunari Takiguchi 
999e5835488SYasunari Takiguchi 	data[5] = 0x00;
1000e5835488SYasunari Takiguchi 
1001e5835488SYasunari Takiguchi 	freq_khz += shift_frequency_khz;
1002e5835488SYasunari Takiguchi 
1003e5835488SYasunari Takiguchi 	data[6] = (freq_khz >> 16) & 0x0f;
1004e5835488SYasunari Takiguchi 	data[7] = (freq_khz >> 8) & 0xff;
1005e5835488SYasunari Takiguchi 	data[8] = freq_khz & 0xff;
1006e5835488SYasunari Takiguchi 	data[9] = 0xff;
1007e5835488SYasunari Takiguchi 	data[10] = 0xfe;
1008e5835488SYasunari Takiguchi 
1009e5835488SYasunari Takiguchi 	return tnr_dmd->io->write_regs(tnr_dmd->io,
1010e5835488SYasunari Takiguchi 				       CXD2880_IO_TGT_SYS,
1011e5835488SYasunari Takiguchi 				       0x52, data, 11);
1012e5835488SYasunari Takiguchi }
1013e5835488SYasunari Takiguchi 
x_tune2(struct cxd2880_tnrdmd * tnr_dmd,enum cxd2880_dtv_bandwidth bandwidth,enum cxd2880_tnrdmd_clockmode clk_mode,int shift_frequency_khz)1014e5835488SYasunari Takiguchi static int x_tune2(struct cxd2880_tnrdmd *tnr_dmd,
1015e5835488SYasunari Takiguchi 		   enum cxd2880_dtv_bandwidth bandwidth,
1016e5835488SYasunari Takiguchi 		   enum cxd2880_tnrdmd_clockmode clk_mode,
1017e5835488SYasunari Takiguchi 		   int shift_frequency_khz)
1018e5835488SYasunari Takiguchi {
1019e5835488SYasunari Takiguchi 	u8 data[3] = { 0 };
1020e5835488SYasunari Takiguchi 	int ret;
1021e5835488SYasunari Takiguchi 
1022e5835488SYasunari Takiguchi 	if (!tnr_dmd)
1023e5835488SYasunari Takiguchi 		return -EINVAL;
1024e5835488SYasunari Takiguchi 
1025e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io,
1026e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
1027e5835488SYasunari Takiguchi 				     0x00, 0x11);
1028e5835488SYasunari Takiguchi 	if (ret)
1029e5835488SYasunari Takiguchi 		return ret;
1030e5835488SYasunari Takiguchi 
1031e5835488SYasunari Takiguchi 	data[0] = 0x01;
1032e5835488SYasunari Takiguchi 	data[1] = 0x0e;
1033e5835488SYasunari Takiguchi 	data[2] = 0x01;
1034e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_regs(tnr_dmd->io,
1035e5835488SYasunari Takiguchi 				      CXD2880_IO_TGT_SYS,
1036e5835488SYasunari Takiguchi 				      0x2d, data, 3);
1037e5835488SYasunari Takiguchi 	if (ret)
1038e5835488SYasunari Takiguchi 		return ret;
1039e5835488SYasunari Takiguchi 
1040e5835488SYasunari Takiguchi 	ret = cxd2880_io_write_multi_regs(tnr_dmd->io,
1041e5835488SYasunari Takiguchi 					  CXD2880_IO_TGT_SYS,
1042e5835488SYasunari Takiguchi 					  x_tune2_seq1,
1043e5835488SYasunari Takiguchi 					  ARRAY_SIZE(x_tune2_seq1));
1044e5835488SYasunari Takiguchi 	if (ret)
1045e5835488SYasunari Takiguchi 		return ret;
1046e5835488SYasunari Takiguchi 
1047e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->read_regs(tnr_dmd->io,
1048e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
1049e5835488SYasunari Takiguchi 				     0x2c, data, 1);
1050e5835488SYasunari Takiguchi 	if (ret)
1051e5835488SYasunari Takiguchi 		return ret;
1052e5835488SYasunari Takiguchi 
1053e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io,
1054e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
1055e5835488SYasunari Takiguchi 				     0x00, 0x10);
1056e5835488SYasunari Takiguchi 	if (ret)
1057e5835488SYasunari Takiguchi 		return ret;
1058e5835488SYasunari Takiguchi 
1059e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io,
1060e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
1061e5835488SYasunari Takiguchi 				     0x60, data[0]);
1062e5835488SYasunari Takiguchi 	if (ret)
1063e5835488SYasunari Takiguchi 		return ret;
1064e5835488SYasunari Takiguchi 
1065e5835488SYasunari Takiguchi 	ret = cxd2880_io_write_multi_regs(tnr_dmd->io,
1066e5835488SYasunari Takiguchi 					  CXD2880_IO_TGT_SYS,
1067e5835488SYasunari Takiguchi 					  x_tune2_seq2,
1068e5835488SYasunari Takiguchi 					  ARRAY_SIZE(x_tune2_seq2));
1069e5835488SYasunari Takiguchi 	if (ret)
1070e5835488SYasunari Takiguchi 		return ret;
1071e5835488SYasunari Takiguchi 
1072e5835488SYasunari Takiguchi 	ret = cxd2880_io_write_multi_regs(tnr_dmd->io,
1073e5835488SYasunari Takiguchi 					  CXD2880_IO_TGT_DMD,
1074e5835488SYasunari Takiguchi 					  x_tune2_seq3,
1075e5835488SYasunari Takiguchi 					  ARRAY_SIZE(x_tune2_seq3));
1076e5835488SYasunari Takiguchi 	if (ret)
1077e5835488SYasunari Takiguchi 		return ret;
1078e5835488SYasunari Takiguchi 
1079e5835488SYasunari Takiguchi 	if (shift_frequency_khz != 0) {
1080e5835488SYasunari Takiguchi 		int shift_freq = 0;
1081e5835488SYasunari Takiguchi 
1082e5835488SYasunari Takiguchi 		ret = tnr_dmd->io->write_reg(tnr_dmd->io,
1083e5835488SYasunari Takiguchi 					     CXD2880_IO_TGT_DMD,
1084e5835488SYasunari Takiguchi 					     0x00, 0xe1);
1085e5835488SYasunari Takiguchi 		if (ret)
1086e5835488SYasunari Takiguchi 			return ret;
1087e5835488SYasunari Takiguchi 
1088e5835488SYasunari Takiguchi 		ret = tnr_dmd->io->read_regs(tnr_dmd->io,
1089e5835488SYasunari Takiguchi 					     CXD2880_IO_TGT_DMD,
1090e5835488SYasunari Takiguchi 					     0x60, data, 2);
1091e5835488SYasunari Takiguchi 		if (ret)
1092e5835488SYasunari Takiguchi 			return ret;
1093e5835488SYasunari Takiguchi 
1094e5835488SYasunari Takiguchi 		shift_freq = shift_frequency_khz * 1000;
1095e5835488SYasunari Takiguchi 
1096e5835488SYasunari Takiguchi 		switch (clk_mode) {
1097e5835488SYasunari Takiguchi 		case CXD2880_TNRDMD_CLOCKMODE_A:
1098e5835488SYasunari Takiguchi 		case CXD2880_TNRDMD_CLOCKMODE_C:
1099e5835488SYasunari Takiguchi 		default:
1100e5835488SYasunari Takiguchi 			if (shift_freq >= 0)
1101e5835488SYasunari Takiguchi 				shift_freq = (shift_freq + 183 / 2) / 183;
1102e5835488SYasunari Takiguchi 			else
1103e5835488SYasunari Takiguchi 				shift_freq = (shift_freq - 183 / 2) / 183;
1104e5835488SYasunari Takiguchi 			break;
1105e5835488SYasunari Takiguchi 		case CXD2880_TNRDMD_CLOCKMODE_B:
1106e5835488SYasunari Takiguchi 			if (shift_freq >= 0)
1107e5835488SYasunari Takiguchi 				shift_freq = (shift_freq + 178 / 2) / 178;
1108e5835488SYasunari Takiguchi 			else
1109e5835488SYasunari Takiguchi 				shift_freq = (shift_freq - 178 / 2) / 178;
1110e5835488SYasunari Takiguchi 			break;
1111e5835488SYasunari Takiguchi 		}
1112e5835488SYasunari Takiguchi 
1113e5835488SYasunari Takiguchi 		shift_freq +=
1114e5835488SYasunari Takiguchi 		    cxd2880_convert2s_complement((data[0] << 8) | data[1], 16);
1115e5835488SYasunari Takiguchi 
1116e5835488SYasunari Takiguchi 		if (shift_freq > 32767)
1117e5835488SYasunari Takiguchi 			shift_freq = 32767;
1118e5835488SYasunari Takiguchi 		else if (shift_freq < -32768)
1119e5835488SYasunari Takiguchi 			shift_freq = -32768;
1120e5835488SYasunari Takiguchi 
1121e5835488SYasunari Takiguchi 		data[0] = (shift_freq >> 8) & 0xff;
1122e5835488SYasunari Takiguchi 		data[1] = shift_freq & 0xff;
1123e5835488SYasunari Takiguchi 
1124e5835488SYasunari Takiguchi 		ret = tnr_dmd->io->write_regs(tnr_dmd->io,
1125e5835488SYasunari Takiguchi 					      CXD2880_IO_TGT_DMD,
1126e5835488SYasunari Takiguchi 					      0x60, data, 2);
1127e5835488SYasunari Takiguchi 		if (ret)
1128e5835488SYasunari Takiguchi 			return ret;
1129e5835488SYasunari Takiguchi 
1130e5835488SYasunari Takiguchi 		ret = tnr_dmd->io->read_regs(tnr_dmd->io,
1131e5835488SYasunari Takiguchi 					     CXD2880_IO_TGT_DMD,
1132e5835488SYasunari Takiguchi 					     0x69, data, 1);
1133e5835488SYasunari Takiguchi 		if (ret)
1134e5835488SYasunari Takiguchi 			return ret;
1135e5835488SYasunari Takiguchi 
1136e5835488SYasunari Takiguchi 		shift_freq = -shift_frequency_khz;
1137e5835488SYasunari Takiguchi 
1138e5835488SYasunari Takiguchi 		if (bandwidth == CXD2880_DTV_BW_1_7_MHZ) {
1139e5835488SYasunari Takiguchi 			switch (clk_mode) {
1140e5835488SYasunari Takiguchi 			case CXD2880_TNRDMD_CLOCKMODE_A:
1141e5835488SYasunari Takiguchi 			case CXD2880_TNRDMD_CLOCKMODE_C:
1142e5835488SYasunari Takiguchi 			default:
1143e5835488SYasunari Takiguchi 				if (shift_freq >= 0)
1144e5835488SYasunari Takiguchi 					shift_freq =
1145e5835488SYasunari Takiguchi 					    (shift_freq * 1000 +
1146e5835488SYasunari Takiguchi 					     17578 / 2) / 17578;
1147e5835488SYasunari Takiguchi 				else
1148e5835488SYasunari Takiguchi 					shift_freq =
1149e5835488SYasunari Takiguchi 					    (shift_freq * 1000 -
1150e5835488SYasunari Takiguchi 					     17578 / 2) / 17578;
1151e5835488SYasunari Takiguchi 				break;
1152e5835488SYasunari Takiguchi 			case CXD2880_TNRDMD_CLOCKMODE_B:
1153e5835488SYasunari Takiguchi 				if (shift_freq >= 0)
1154e5835488SYasunari Takiguchi 					shift_freq =
1155e5835488SYasunari Takiguchi 					    (shift_freq * 1000 +
1156e5835488SYasunari Takiguchi 					     17090 / 2) / 17090;
1157e5835488SYasunari Takiguchi 				else
1158e5835488SYasunari Takiguchi 					shift_freq =
1159e5835488SYasunari Takiguchi 					    (shift_freq * 1000 -
1160e5835488SYasunari Takiguchi 					     17090 / 2) / 17090;
1161e5835488SYasunari Takiguchi 				break;
1162e5835488SYasunari Takiguchi 			}
1163e5835488SYasunari Takiguchi 		} else {
1164e5835488SYasunari Takiguchi 			switch (clk_mode) {
1165e5835488SYasunari Takiguchi 			case CXD2880_TNRDMD_CLOCKMODE_A:
1166e5835488SYasunari Takiguchi 			case CXD2880_TNRDMD_CLOCKMODE_C:
1167e5835488SYasunari Takiguchi 			default:
1168e5835488SYasunari Takiguchi 				if (shift_freq >= 0)
1169e5835488SYasunari Takiguchi 					shift_freq =
1170e5835488SYasunari Takiguchi 					    (shift_freq * 1000 +
1171e5835488SYasunari Takiguchi 					     35156 / 2) / 35156;
1172e5835488SYasunari Takiguchi 				else
1173e5835488SYasunari Takiguchi 					shift_freq =
1174e5835488SYasunari Takiguchi 					    (shift_freq * 1000 -
1175e5835488SYasunari Takiguchi 					     35156 / 2) / 35156;
1176e5835488SYasunari Takiguchi 				break;
1177e5835488SYasunari Takiguchi 			case CXD2880_TNRDMD_CLOCKMODE_B:
1178e5835488SYasunari Takiguchi 				if (shift_freq >= 0)
1179e5835488SYasunari Takiguchi 					shift_freq =
1180e5835488SYasunari Takiguchi 					    (shift_freq * 1000 +
1181e5835488SYasunari Takiguchi 					     34180 / 2) / 34180;
1182e5835488SYasunari Takiguchi 				else
1183e5835488SYasunari Takiguchi 					shift_freq =
1184e5835488SYasunari Takiguchi 					    (shift_freq * 1000 -
1185e5835488SYasunari Takiguchi 					     34180 / 2) / 34180;
1186e5835488SYasunari Takiguchi 				break;
1187e5835488SYasunari Takiguchi 			}
1188e5835488SYasunari Takiguchi 		}
1189e5835488SYasunari Takiguchi 
1190e5835488SYasunari Takiguchi 		shift_freq += cxd2880_convert2s_complement(data[0], 8);
1191e5835488SYasunari Takiguchi 
1192e5835488SYasunari Takiguchi 		if (shift_freq > 127)
1193e5835488SYasunari Takiguchi 			shift_freq = 127;
1194e5835488SYasunari Takiguchi 		else if (shift_freq < -128)
1195e5835488SYasunari Takiguchi 			shift_freq = -128;
1196e5835488SYasunari Takiguchi 
1197e5835488SYasunari Takiguchi 		data[0] = shift_freq & 0xff;
1198e5835488SYasunari Takiguchi 
1199e5835488SYasunari Takiguchi 		ret = tnr_dmd->io->write_reg(tnr_dmd->io,
1200e5835488SYasunari Takiguchi 					     CXD2880_IO_TGT_DMD,
1201e5835488SYasunari Takiguchi 					     0x69, data[0]);
1202e5835488SYasunari Takiguchi 		if (ret)
1203e5835488SYasunari Takiguchi 			return ret;
1204e5835488SYasunari Takiguchi 	}
1205e5835488SYasunari Takiguchi 
1206e5835488SYasunari Takiguchi 	if (tnr_dmd->create_param.stationary_use) {
1207e5835488SYasunari Takiguchi 		ret = cxd2880_io_write_multi_regs(tnr_dmd->io,
1208e5835488SYasunari Takiguchi 						  CXD2880_IO_TGT_DMD,
1209e5835488SYasunari Takiguchi 						  x_tune2_seq4,
1210e5835488SYasunari Takiguchi 						  ARRAY_SIZE(x_tune2_seq4));
1211e5835488SYasunari Takiguchi 		if (ret)
1212e5835488SYasunari Takiguchi 			return ret;
1213e5835488SYasunari Takiguchi 	}
1214e5835488SYasunari Takiguchi 
1215e5835488SYasunari Takiguchi 	return cxd2880_io_write_multi_regs(tnr_dmd->io,
1216e5835488SYasunari Takiguchi 					   CXD2880_IO_TGT_DMD,
1217e5835488SYasunari Takiguchi 					   x_tune2_seq5,
1218e5835488SYasunari Takiguchi 					   ARRAY_SIZE(x_tune2_seq5));
1219e5835488SYasunari Takiguchi }
1220e5835488SYasunari Takiguchi 
x_tune3(struct cxd2880_tnrdmd * tnr_dmd,enum cxd2880_dtv_sys sys,u8 en_fef_intmtnt_ctrl)1221e5835488SYasunari Takiguchi static int x_tune3(struct cxd2880_tnrdmd *tnr_dmd,
1222e5835488SYasunari Takiguchi 		   enum cxd2880_dtv_sys sys,
1223e5835488SYasunari Takiguchi 		   u8 en_fef_intmtnt_ctrl)
1224e5835488SYasunari Takiguchi {
1225e5835488SYasunari Takiguchi 	u8 data[6] = { 0 };
1226e5835488SYasunari Takiguchi 	int ret;
1227e5835488SYasunari Takiguchi 
1228e5835488SYasunari Takiguchi 	if (!tnr_dmd)
1229e5835488SYasunari Takiguchi 		return -EINVAL;
1230e5835488SYasunari Takiguchi 
1231e5835488SYasunari Takiguchi 	ret = cxd2880_io_write_multi_regs(tnr_dmd->io,
1232e5835488SYasunari Takiguchi 					  CXD2880_IO_TGT_DMD,
1233e5835488SYasunari Takiguchi 					  x_tune3_seq,
1234e5835488SYasunari Takiguchi 					  ARRAY_SIZE(x_tune3_seq));
1235e5835488SYasunari Takiguchi 	if (ret)
1236e5835488SYasunari Takiguchi 		return ret;
1237e5835488SYasunari Takiguchi 
1238e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io,
1239e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
1240e5835488SYasunari Takiguchi 				     0x00, 0x10);
1241e5835488SYasunari Takiguchi 	if (ret)
1242e5835488SYasunari Takiguchi 		return ret;
1243e5835488SYasunari Takiguchi 
1244e5835488SYasunari Takiguchi 	if (sys == CXD2880_DTV_SYS_DVBT2 && en_fef_intmtnt_ctrl)
1245e5835488SYasunari Takiguchi 		memset(data, 0x01, sizeof(data));
1246e5835488SYasunari Takiguchi 	else
1247e5835488SYasunari Takiguchi 		memset(data, 0x00, sizeof(data));
1248e5835488SYasunari Takiguchi 
1249e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_regs(tnr_dmd->io,
1250e5835488SYasunari Takiguchi 				      CXD2880_IO_TGT_SYS,
1251e5835488SYasunari Takiguchi 				      0xef, data, 6);
1252e5835488SYasunari Takiguchi 	if (ret)
1253e5835488SYasunari Takiguchi 		return ret;
1254e5835488SYasunari Takiguchi 
1255e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io,
1256e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_DMD,
1257e5835488SYasunari Takiguchi 				     0x00, 0x2d);
1258e5835488SYasunari Takiguchi 	if (ret)
1259e5835488SYasunari Takiguchi 		return ret;
1260e5835488SYasunari Takiguchi 	if (sys == CXD2880_DTV_SYS_DVBT2 && en_fef_intmtnt_ctrl)
1261e5835488SYasunari Takiguchi 		data[0] = 0x00;
1262e5835488SYasunari Takiguchi 	else
1263e5835488SYasunari Takiguchi 		data[0] = 0x01;
1264e5835488SYasunari Takiguchi 
1265e5835488SYasunari Takiguchi 	return tnr_dmd->io->write_reg(tnr_dmd->io,
1266e5835488SYasunari Takiguchi 				      CXD2880_IO_TGT_DMD,
1267e5835488SYasunari Takiguchi 				      0xb1, data[0]);
1268e5835488SYasunari Takiguchi }
1269e5835488SYasunari Takiguchi 
x_tune4(struct cxd2880_tnrdmd * tnr_dmd)1270e5835488SYasunari Takiguchi static int x_tune4(struct cxd2880_tnrdmd *tnr_dmd)
1271e5835488SYasunari Takiguchi {
1272e5835488SYasunari Takiguchi 	u8 data[2] = { 0 };
1273e5835488SYasunari Takiguchi 	int ret;
1274e5835488SYasunari Takiguchi 
1275e5835488SYasunari Takiguchi 	if (!tnr_dmd)
1276e5835488SYasunari Takiguchi 		return -EINVAL;
1277e5835488SYasunari Takiguchi 
1278e5835488SYasunari Takiguchi 	if (tnr_dmd->diver_mode != CXD2880_TNRDMD_DIVERMODE_MAIN)
1279e5835488SYasunari Takiguchi 		return -EINVAL;
1280e5835488SYasunari Takiguchi 
1281e5835488SYasunari Takiguchi 	ret = tnr_dmd->diver_sub->io->write_reg(tnr_dmd->diver_sub->io,
1282e5835488SYasunari Takiguchi 						CXD2880_IO_TGT_SYS,
1283e5835488SYasunari Takiguchi 						0x00, 0x00);
1284e5835488SYasunari Takiguchi 	if (ret)
1285e5835488SYasunari Takiguchi 		return ret;
1286e5835488SYasunari Takiguchi 	data[0] = 0x14;
1287e5835488SYasunari Takiguchi 	data[1] = 0x00;
1288e5835488SYasunari Takiguchi 	ret = tnr_dmd->diver_sub->io->write_regs(tnr_dmd->diver_sub->io,
1289e5835488SYasunari Takiguchi 						CXD2880_IO_TGT_SYS,
1290e5835488SYasunari Takiguchi 						0x55, data, 2);
1291e5835488SYasunari Takiguchi 	if (ret)
1292e5835488SYasunari Takiguchi 		return ret;
1293e5835488SYasunari Takiguchi 
1294e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io,
1295e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
1296e5835488SYasunari Takiguchi 				     0x00, 0x00);
1297e5835488SYasunari Takiguchi 	if (ret)
1298e5835488SYasunari Takiguchi 		return ret;
1299e5835488SYasunari Takiguchi 	data[0] = 0x0b;
1300e5835488SYasunari Takiguchi 	data[1] = 0xff;
1301e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_regs(tnr_dmd->io,
1302e5835488SYasunari Takiguchi 				      CXD2880_IO_TGT_SYS,
1303e5835488SYasunari Takiguchi 				      0x53, data, 2);
1304e5835488SYasunari Takiguchi 	if (ret)
1305e5835488SYasunari Takiguchi 		return ret;
1306e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io,
1307e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
1308e5835488SYasunari Takiguchi 				     0x57, 0x01);
1309e5835488SYasunari Takiguchi 	if (ret)
1310e5835488SYasunari Takiguchi 		return ret;
1311e5835488SYasunari Takiguchi 	data[0] = 0x0b;
1312e5835488SYasunari Takiguchi 	data[1] = 0xff;
1313e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_regs(tnr_dmd->io,
1314e5835488SYasunari Takiguchi 				      CXD2880_IO_TGT_SYS,
1315e5835488SYasunari Takiguchi 				      0x55, data, 2);
1316e5835488SYasunari Takiguchi 	if (ret)
1317e5835488SYasunari Takiguchi 		return ret;
1318e5835488SYasunari Takiguchi 
1319e5835488SYasunari Takiguchi 	ret = tnr_dmd->diver_sub->io->write_reg(tnr_dmd->diver_sub->io,
1320e5835488SYasunari Takiguchi 						CXD2880_IO_TGT_SYS,
1321e5835488SYasunari Takiguchi 						0x00, 0x00);
1322e5835488SYasunari Takiguchi 	if (ret)
1323e5835488SYasunari Takiguchi 		return ret;
1324e5835488SYasunari Takiguchi 	data[0] = 0x14;
1325e5835488SYasunari Takiguchi 	data[1] = 0x00;
1326e5835488SYasunari Takiguchi 	ret = tnr_dmd->diver_sub->io->write_regs(tnr_dmd->diver_sub->io,
1327e5835488SYasunari Takiguchi 						 CXD2880_IO_TGT_SYS,
1328e5835488SYasunari Takiguchi 						 0x53, data, 2);
1329e5835488SYasunari Takiguchi 	if (ret)
1330e5835488SYasunari Takiguchi 		return ret;
1331e5835488SYasunari Takiguchi 	ret = tnr_dmd->diver_sub->io->write_reg(tnr_dmd->diver_sub->io,
1332e5835488SYasunari Takiguchi 						CXD2880_IO_TGT_SYS,
1333e5835488SYasunari Takiguchi 						0x57, 0x02);
1334e5835488SYasunari Takiguchi 	if (ret)
1335e5835488SYasunari Takiguchi 		return ret;
1336e5835488SYasunari Takiguchi 
1337e5835488SYasunari Takiguchi 	ret = cxd2880_io_write_multi_regs(tnr_dmd->io,
1338e5835488SYasunari Takiguchi 					  CXD2880_IO_TGT_DMD,
1339e5835488SYasunari Takiguchi 					  x_tune4_seq,
1340e5835488SYasunari Takiguchi 					  ARRAY_SIZE(x_tune4_seq));
1341e5835488SYasunari Takiguchi 	if (ret)
1342e5835488SYasunari Takiguchi 		return ret;
1343e5835488SYasunari Takiguchi 
1344e5835488SYasunari Takiguchi 	return cxd2880_io_write_multi_regs(tnr_dmd->diver_sub->io,
1345e5835488SYasunari Takiguchi 					   CXD2880_IO_TGT_DMD,
1346e5835488SYasunari Takiguchi 					   x_tune4_seq,
1347e5835488SYasunari Takiguchi 					   ARRAY_SIZE(x_tune4_seq));
1348e5835488SYasunari Takiguchi }
1349e5835488SYasunari Takiguchi 
x_sleep1(struct cxd2880_tnrdmd * tnr_dmd)1350e5835488SYasunari Takiguchi static int x_sleep1(struct cxd2880_tnrdmd *tnr_dmd)
1351e5835488SYasunari Takiguchi {
1352e5835488SYasunari Takiguchi 	u8 data[3] = { 0 };
1353e5835488SYasunari Takiguchi 	int ret;
1354e5835488SYasunari Takiguchi 
1355e5835488SYasunari Takiguchi 	if (!tnr_dmd)
1356e5835488SYasunari Takiguchi 		return -EINVAL;
1357e5835488SYasunari Takiguchi 
1358e5835488SYasunari Takiguchi 	if (tnr_dmd->diver_mode != CXD2880_TNRDMD_DIVERMODE_MAIN)
1359e5835488SYasunari Takiguchi 		return -EINVAL;
1360e5835488SYasunari Takiguchi 
1361e5835488SYasunari Takiguchi 	ret = cxd2880_io_write_multi_regs(tnr_dmd->io,
1362e5835488SYasunari Takiguchi 					  CXD2880_IO_TGT_SYS,
1363e5835488SYasunari Takiguchi 					  x_sleep1_seq,
1364e5835488SYasunari Takiguchi 					  ARRAY_SIZE(x_sleep1_seq));
1365e5835488SYasunari Takiguchi 	if (ret)
1366e5835488SYasunari Takiguchi 		return ret;
1367e5835488SYasunari Takiguchi 
1368e5835488SYasunari Takiguchi 	data[0] = 0x00;
1369e5835488SYasunari Takiguchi 	data[1] = 0x00;
1370e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_regs(tnr_dmd->io,
1371e5835488SYasunari Takiguchi 				      CXD2880_IO_TGT_SYS,
1372e5835488SYasunari Takiguchi 				      0x53, data, 2);
1373e5835488SYasunari Takiguchi 	if (ret)
1374e5835488SYasunari Takiguchi 		return ret;
1375e5835488SYasunari Takiguchi 
1376e5835488SYasunari Takiguchi 	ret = tnr_dmd->diver_sub->io->write_reg(tnr_dmd->diver_sub->io,
1377e5835488SYasunari Takiguchi 						CXD2880_IO_TGT_SYS,
1378e5835488SYasunari Takiguchi 						0x00, 0x00);
1379e5835488SYasunari Takiguchi 	if (ret)
1380e5835488SYasunari Takiguchi 		return ret;
1381e5835488SYasunari Takiguchi 	data[0] = 0x1f;
1382e5835488SYasunari Takiguchi 	data[1] = 0xff;
1383e5835488SYasunari Takiguchi 	data[2] = 0x03;
1384e5835488SYasunari Takiguchi 	ret = tnr_dmd->diver_sub->io->write_regs(tnr_dmd->diver_sub->io,
1385e5835488SYasunari Takiguchi 						 CXD2880_IO_TGT_SYS,
1386e5835488SYasunari Takiguchi 						 0x55, data, 3);
1387e5835488SYasunari Takiguchi 	if (ret)
1388e5835488SYasunari Takiguchi 		return ret;
1389e5835488SYasunari Takiguchi 	data[0] = 0x00;
1390e5835488SYasunari Takiguchi 	data[1] = 0x00;
1391e5835488SYasunari Takiguchi 	ret = tnr_dmd->diver_sub->io->write_regs(tnr_dmd->diver_sub->io,
1392e5835488SYasunari Takiguchi 						 CXD2880_IO_TGT_SYS,
1393e5835488SYasunari Takiguchi 						 0x53, data, 2);
1394e5835488SYasunari Takiguchi 	if (ret)
1395e5835488SYasunari Takiguchi 		return ret;
1396e5835488SYasunari Takiguchi 
1397e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io,
1398e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
1399e5835488SYasunari Takiguchi 				     0x00, 0x00);
1400e5835488SYasunari Takiguchi 	if (ret)
1401e5835488SYasunari Takiguchi 		return ret;
1402e5835488SYasunari Takiguchi 	data[0] = 0x1f;
1403e5835488SYasunari Takiguchi 	data[1] = 0xff;
1404e5835488SYasunari Takiguchi 
1405e5835488SYasunari Takiguchi 	return tnr_dmd->io->write_regs(tnr_dmd->io,
1406e5835488SYasunari Takiguchi 				       CXD2880_IO_TGT_SYS,
1407e5835488SYasunari Takiguchi 				       0x55, data, 2);
1408e5835488SYasunari Takiguchi }
1409e5835488SYasunari Takiguchi 
x_sleep2(struct cxd2880_tnrdmd * tnr_dmd)1410e5835488SYasunari Takiguchi static int x_sleep2(struct cxd2880_tnrdmd *tnr_dmd)
1411e5835488SYasunari Takiguchi {
1412e5835488SYasunari Takiguchi 	u8 data = 0;
1413e5835488SYasunari Takiguchi 	int ret;
1414e5835488SYasunari Takiguchi 
1415e5835488SYasunari Takiguchi 	if (!tnr_dmd)
1416e5835488SYasunari Takiguchi 		return -EINVAL;
1417e5835488SYasunari Takiguchi 
1418e5835488SYasunari Takiguchi 	ret = cxd2880_io_write_multi_regs(tnr_dmd->io,
1419e5835488SYasunari Takiguchi 					  CXD2880_IO_TGT_DMD,
1420e5835488SYasunari Takiguchi 					  x_sleep2_seq1,
1421e5835488SYasunari Takiguchi 					  ARRAY_SIZE(x_sleep2_seq1));
1422e5835488SYasunari Takiguchi 	if (ret)
1423e5835488SYasunari Takiguchi 		return ret;
1424e5835488SYasunari Takiguchi 
1425e5835488SYasunari Takiguchi 	usleep_range(1000, 2000);
1426e5835488SYasunari Takiguchi 
1427e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->read_regs(tnr_dmd->io,
1428e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_DMD,
1429e5835488SYasunari Takiguchi 				     0xb2, &data, 1);
1430e5835488SYasunari Takiguchi 	if (ret)
1431e5835488SYasunari Takiguchi 		return ret;
1432e5835488SYasunari Takiguchi 
1433e5835488SYasunari Takiguchi 	if ((data & 0x01) == 0x00)
1434e5835488SYasunari Takiguchi 		return -EINVAL;
1435e5835488SYasunari Takiguchi 
1436e5835488SYasunari Takiguchi 	return cxd2880_io_write_multi_regs(tnr_dmd->io,
1437e5835488SYasunari Takiguchi 					   CXD2880_IO_TGT_SYS,
1438e5835488SYasunari Takiguchi 					   x_sleep2_seq2,
1439e5835488SYasunari Takiguchi 					   ARRAY_SIZE(x_sleep2_seq2));
1440e5835488SYasunari Takiguchi }
1441e5835488SYasunari Takiguchi 
x_sleep3(struct cxd2880_tnrdmd * tnr_dmd)1442e5835488SYasunari Takiguchi static int x_sleep3(struct cxd2880_tnrdmd *tnr_dmd)
1443e5835488SYasunari Takiguchi {
1444e5835488SYasunari Takiguchi 	if (!tnr_dmd)
1445e5835488SYasunari Takiguchi 		return -EINVAL;
1446e5835488SYasunari Takiguchi 
1447e5835488SYasunari Takiguchi 	return cxd2880_io_write_multi_regs(tnr_dmd->io,
1448e5835488SYasunari Takiguchi 					   CXD2880_IO_TGT_DMD,
1449e5835488SYasunari Takiguchi 					   x_sleep3_seq,
1450e5835488SYasunari Takiguchi 					   ARRAY_SIZE(x_sleep3_seq));
1451e5835488SYasunari Takiguchi }
1452e5835488SYasunari Takiguchi 
x_sleep4(struct cxd2880_tnrdmd * tnr_dmd)1453e5835488SYasunari Takiguchi static int x_sleep4(struct cxd2880_tnrdmd *tnr_dmd)
1454e5835488SYasunari Takiguchi {
1455e5835488SYasunari Takiguchi 	if (!tnr_dmd)
1456e5835488SYasunari Takiguchi 		return -EINVAL;
1457e5835488SYasunari Takiguchi 
1458e5835488SYasunari Takiguchi 	return cxd2880_io_write_multi_regs(tnr_dmd->io,
1459e5835488SYasunari Takiguchi 					   CXD2880_IO_TGT_DMD,
1460e5835488SYasunari Takiguchi 					   x_sleep4_seq,
1461e5835488SYasunari Takiguchi 					   ARRAY_SIZE(x_sleep4_seq));
1462e5835488SYasunari Takiguchi }
1463e5835488SYasunari Takiguchi 
spll_reset(struct cxd2880_tnrdmd * tnr_dmd,enum cxd2880_tnrdmd_clockmode clockmode)1464e5835488SYasunari Takiguchi static int spll_reset(struct cxd2880_tnrdmd *tnr_dmd,
1465e5835488SYasunari Takiguchi 		      enum cxd2880_tnrdmd_clockmode clockmode)
1466e5835488SYasunari Takiguchi {
1467e5835488SYasunari Takiguchi 	u8 data[4] = { 0 };
1468e5835488SYasunari Takiguchi 	int ret;
1469e5835488SYasunari Takiguchi 
1470e5835488SYasunari Takiguchi 	if (!tnr_dmd)
1471e5835488SYasunari Takiguchi 		return -EINVAL;
1472e5835488SYasunari Takiguchi 
1473e5835488SYasunari Takiguchi 	ret = cxd2880_io_write_multi_regs(tnr_dmd->io,
1474e5835488SYasunari Takiguchi 					  CXD2880_IO_TGT_SYS,
1475e5835488SYasunari Takiguchi 					  spll_reset_seq1,
1476e5835488SYasunari Takiguchi 					  ARRAY_SIZE(spll_reset_seq1));
1477e5835488SYasunari Takiguchi 	if (ret)
1478e5835488SYasunari Takiguchi 		return ret;
1479e5835488SYasunari Takiguchi 
1480e5835488SYasunari Takiguchi 	ret = cxd2880_io_write_multi_regs(tnr_dmd->io,
1481e5835488SYasunari Takiguchi 					  CXD2880_IO_TGT_DMD,
1482e5835488SYasunari Takiguchi 					  spll_reset_seq2,
1483e5835488SYasunari Takiguchi 					  ARRAY_SIZE(spll_reset_seq2));
1484e5835488SYasunari Takiguchi 	if (ret)
1485e5835488SYasunari Takiguchi 		return ret;
1486e5835488SYasunari Takiguchi 
1487e5835488SYasunari Takiguchi 	ret = cxd2880_io_write_multi_regs(tnr_dmd->io,
1488e5835488SYasunari Takiguchi 					  CXD2880_IO_TGT_SYS,
1489e5835488SYasunari Takiguchi 					  spll_reset_seq3,
1490e5835488SYasunari Takiguchi 					  ARRAY_SIZE(spll_reset_seq3));
1491e5835488SYasunari Takiguchi 	if (ret)
1492e5835488SYasunari Takiguchi 		return ret;
1493e5835488SYasunari Takiguchi 
1494e5835488SYasunari Takiguchi 	switch (clockmode) {
1495e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_CLOCKMODE_A:
1496e5835488SYasunari Takiguchi 		data[0] = 0x00;
1497e5835488SYasunari Takiguchi 		break;
1498e5835488SYasunari Takiguchi 
1499e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_CLOCKMODE_B:
1500e5835488SYasunari Takiguchi 		data[0] = 0x01;
1501e5835488SYasunari Takiguchi 		break;
1502e5835488SYasunari Takiguchi 
1503e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_CLOCKMODE_C:
1504e5835488SYasunari Takiguchi 		data[0] = 0x02;
1505e5835488SYasunari Takiguchi 		break;
1506e5835488SYasunari Takiguchi 
1507e5835488SYasunari Takiguchi 	default:
1508e5835488SYasunari Takiguchi 		return -EINVAL;
1509e5835488SYasunari Takiguchi 	}
1510e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io,
1511e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
1512e5835488SYasunari Takiguchi 				     0x30, data[0]);
1513e5835488SYasunari Takiguchi 	if (ret)
1514e5835488SYasunari Takiguchi 		return ret;
1515e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io,
1516e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
1517e5835488SYasunari Takiguchi 				     0x22, 0x00);
1518e5835488SYasunari Takiguchi 	if (ret)
1519e5835488SYasunari Takiguchi 		return ret;
1520e5835488SYasunari Takiguchi 
1521e5835488SYasunari Takiguchi 	usleep_range(2000, 3000);
1522e5835488SYasunari Takiguchi 
1523e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io,
1524e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
1525e5835488SYasunari Takiguchi 				     0x00, 0x0a);
1526e5835488SYasunari Takiguchi 	if (ret)
1527e5835488SYasunari Takiguchi 		return ret;
1528e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->read_regs(tnr_dmd->io,
1529e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
1530e5835488SYasunari Takiguchi 				     0x10, data, 1);
1531e5835488SYasunari Takiguchi 	if (ret)
1532e5835488SYasunari Takiguchi 		return ret;
1533e5835488SYasunari Takiguchi 	if ((data[0] & 0x01) == 0x00)
1534e5835488SYasunari Takiguchi 		return -EINVAL;
1535e5835488SYasunari Takiguchi 
1536e5835488SYasunari Takiguchi 	ret = cxd2880_io_write_multi_regs(tnr_dmd->io,
1537e5835488SYasunari Takiguchi 					  CXD2880_IO_TGT_SYS,
1538e5835488SYasunari Takiguchi 					  spll_reset_seq4,
1539e5835488SYasunari Takiguchi 					  ARRAY_SIZE(spll_reset_seq4));
1540e5835488SYasunari Takiguchi 	if (ret)
1541e5835488SYasunari Takiguchi 		return ret;
1542e5835488SYasunari Takiguchi 
1543e5835488SYasunari Takiguchi 	usleep_range(1000, 2000);
1544e5835488SYasunari Takiguchi 
1545e5835488SYasunari Takiguchi 	ret = cxd2880_io_write_multi_regs(tnr_dmd->io,
1546e5835488SYasunari Takiguchi 					  CXD2880_IO_TGT_DMD,
1547e5835488SYasunari Takiguchi 					  spll_reset_seq5,
1548e5835488SYasunari Takiguchi 					  ARRAY_SIZE(spll_reset_seq5));
1549e5835488SYasunari Takiguchi 	if (ret)
1550e5835488SYasunari Takiguchi 		return ret;
1551e5835488SYasunari Takiguchi 
1552e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io,
1553e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
1554e5835488SYasunari Takiguchi 				     0x00, 0x10);
1555e5835488SYasunari Takiguchi 	if (ret)
1556e5835488SYasunari Takiguchi 		return ret;
1557e5835488SYasunari Takiguchi 
1558e5835488SYasunari Takiguchi 	memset(data, 0x00, sizeof(data));
1559e5835488SYasunari Takiguchi 
1560e5835488SYasunari Takiguchi 	return tnr_dmd->io->write_regs(tnr_dmd->io,
1561e5835488SYasunari Takiguchi 				       CXD2880_IO_TGT_SYS,
1562e5835488SYasunari Takiguchi 				       0x26, data, 4);
1563e5835488SYasunari Takiguchi }
1564e5835488SYasunari Takiguchi 
t_power_x(struct cxd2880_tnrdmd * tnr_dmd,u8 on)1565e5835488SYasunari Takiguchi static int t_power_x(struct cxd2880_tnrdmd *tnr_dmd, u8 on)
1566e5835488SYasunari Takiguchi {
1567e5835488SYasunari Takiguchi 	u8 data[3] = { 0 };
1568e5835488SYasunari Takiguchi 	int ret;
1569e5835488SYasunari Takiguchi 
1570e5835488SYasunari Takiguchi 	if (!tnr_dmd)
1571e5835488SYasunari Takiguchi 		return -EINVAL;
1572e5835488SYasunari Takiguchi 
1573e5835488SYasunari Takiguchi 	ret = cxd2880_io_write_multi_regs(tnr_dmd->io,
1574e5835488SYasunari Takiguchi 					  CXD2880_IO_TGT_SYS,
1575e5835488SYasunari Takiguchi 					  t_power_x_seq1,
1576e5835488SYasunari Takiguchi 					  ARRAY_SIZE(t_power_x_seq1));
1577e5835488SYasunari Takiguchi 	if (ret)
1578e5835488SYasunari Takiguchi 		return ret;
1579e5835488SYasunari Takiguchi 
1580e5835488SYasunari Takiguchi 	ret = cxd2880_io_write_multi_regs(tnr_dmd->io,
1581e5835488SYasunari Takiguchi 					  CXD2880_IO_TGT_DMD,
1582e5835488SYasunari Takiguchi 					  t_power_x_seq2,
1583e5835488SYasunari Takiguchi 					  ARRAY_SIZE(t_power_x_seq2));
1584e5835488SYasunari Takiguchi 	if (ret)
1585e5835488SYasunari Takiguchi 		return ret;
1586e5835488SYasunari Takiguchi 
1587e5835488SYasunari Takiguchi 	ret = cxd2880_io_write_multi_regs(tnr_dmd->io,
1588e5835488SYasunari Takiguchi 					  CXD2880_IO_TGT_SYS,
1589e5835488SYasunari Takiguchi 					  t_power_x_seq3,
1590e5835488SYasunari Takiguchi 					  ARRAY_SIZE(t_power_x_seq3));
1591e5835488SYasunari Takiguchi 	if (ret)
1592e5835488SYasunari Takiguchi 		return ret;
1593e5835488SYasunari Takiguchi 
1594e5835488SYasunari Takiguchi 	if (on) {
1595e5835488SYasunari Takiguchi 		ret = tnr_dmd->io->write_reg(tnr_dmd->io,
1596e5835488SYasunari Takiguchi 					     CXD2880_IO_TGT_SYS,
1597e5835488SYasunari Takiguchi 					     0x2b, 0x01);
1598e5835488SYasunari Takiguchi 		if (ret)
1599e5835488SYasunari Takiguchi 			return ret;
1600e5835488SYasunari Takiguchi 
1601e5835488SYasunari Takiguchi 		usleep_range(1000, 2000);
1602e5835488SYasunari Takiguchi 
1603e5835488SYasunari Takiguchi 		ret = tnr_dmd->io->write_reg(tnr_dmd->io,
1604e5835488SYasunari Takiguchi 					     CXD2880_IO_TGT_SYS,
1605e5835488SYasunari Takiguchi 					     0x00, 0x0a);
1606e5835488SYasunari Takiguchi 		if (ret)
1607e5835488SYasunari Takiguchi 			return ret;
1608e5835488SYasunari Takiguchi 		ret = tnr_dmd->io->read_regs(tnr_dmd->io,
1609e5835488SYasunari Takiguchi 					     CXD2880_IO_TGT_SYS,
1610e5835488SYasunari Takiguchi 					     0x12, data, 1);
1611e5835488SYasunari Takiguchi 		if (ret)
1612e5835488SYasunari Takiguchi 			return ret;
1613e5835488SYasunari Takiguchi 		if ((data[0] & 0x01) == 0)
1614e5835488SYasunari Takiguchi 			return -EINVAL;
1615e5835488SYasunari Takiguchi 
1616e5835488SYasunari Takiguchi 		ret = cxd2880_io_write_multi_regs(tnr_dmd->io,
1617e5835488SYasunari Takiguchi 						  CXD2880_IO_TGT_SYS,
1618e5835488SYasunari Takiguchi 						  t_power_x_seq4,
1619e5835488SYasunari Takiguchi 						  ARRAY_SIZE(t_power_x_seq4));
1620e5835488SYasunari Takiguchi 		if (ret)
1621e5835488SYasunari Takiguchi 			return ret;
1622e5835488SYasunari Takiguchi 	} else {
1623e5835488SYasunari Takiguchi 		data[0] = 0x03;
1624e5835488SYasunari Takiguchi 		data[1] = 0x00;
1625e5835488SYasunari Takiguchi 		ret = tnr_dmd->io->write_regs(tnr_dmd->io,
1626e5835488SYasunari Takiguchi 					      CXD2880_IO_TGT_SYS,
1627e5835488SYasunari Takiguchi 					      0x2a, data, 2);
1628e5835488SYasunari Takiguchi 		if (ret)
1629e5835488SYasunari Takiguchi 			return ret;
1630e5835488SYasunari Takiguchi 
1631e5835488SYasunari Takiguchi 		usleep_range(1000, 2000);
1632e5835488SYasunari Takiguchi 
1633e5835488SYasunari Takiguchi 		ret = tnr_dmd->io->write_reg(tnr_dmd->io,
1634e5835488SYasunari Takiguchi 					     CXD2880_IO_TGT_SYS,
1635e5835488SYasunari Takiguchi 					     0x00, 0x0a);
1636e5835488SYasunari Takiguchi 		if (ret)
1637e5835488SYasunari Takiguchi 			return ret;
1638e5835488SYasunari Takiguchi 		ret = tnr_dmd->io->read_regs(tnr_dmd->io,
1639e5835488SYasunari Takiguchi 					     CXD2880_IO_TGT_SYS,
1640e5835488SYasunari Takiguchi 					     0x13, data, 1);
1641e5835488SYasunari Takiguchi 		if (ret)
1642e5835488SYasunari Takiguchi 			return ret;
1643e5835488SYasunari Takiguchi 		if ((data[0] & 0x01) == 0)
1644e5835488SYasunari Takiguchi 			return -EINVAL;
1645e5835488SYasunari Takiguchi 	}
1646e5835488SYasunari Takiguchi 
1647e5835488SYasunari Takiguchi 	ret = cxd2880_io_write_multi_regs(tnr_dmd->io,
1648e5835488SYasunari Takiguchi 					  CXD2880_IO_TGT_SYS,
1649e5835488SYasunari Takiguchi 					  t_power_x_seq5,
1650e5835488SYasunari Takiguchi 					  ARRAY_SIZE(t_power_x_seq5));
1651e5835488SYasunari Takiguchi 	if (ret)
1652e5835488SYasunari Takiguchi 		return ret;
1653e5835488SYasunari Takiguchi 
1654e5835488SYasunari Takiguchi 	usleep_range(1000, 2000);
1655e5835488SYasunari Takiguchi 
1656e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io,
1657e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
1658e5835488SYasunari Takiguchi 				     0x00, 0x0a);
1659e5835488SYasunari Takiguchi 	if (ret)
1660e5835488SYasunari Takiguchi 		return ret;
1661e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->read_regs(tnr_dmd->io,
1662e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
1663e5835488SYasunari Takiguchi 				     0x11, data, 1);
1664e5835488SYasunari Takiguchi 	if (ret)
1665e5835488SYasunari Takiguchi 		return ret;
1666e5835488SYasunari Takiguchi 	if ((data[0] & 0x01) == 0)
1667e5835488SYasunari Takiguchi 		return -EINVAL;
1668e5835488SYasunari Takiguchi 
1669e5835488SYasunari Takiguchi 	ret = cxd2880_io_write_multi_regs(tnr_dmd->io,
1670e5835488SYasunari Takiguchi 					  CXD2880_IO_TGT_SYS,
1671e5835488SYasunari Takiguchi 					  t_power_x_seq6,
1672e5835488SYasunari Takiguchi 					  ARRAY_SIZE(t_power_x_seq6));
1673e5835488SYasunari Takiguchi 	if (ret)
1674e5835488SYasunari Takiguchi 		return ret;
1675e5835488SYasunari Takiguchi 
1676e5835488SYasunari Takiguchi 	usleep_range(1000, 2000);
1677e5835488SYasunari Takiguchi 
1678e5835488SYasunari Takiguchi 	ret = cxd2880_io_write_multi_regs(tnr_dmd->io,
1679e5835488SYasunari Takiguchi 					  CXD2880_IO_TGT_DMD,
1680e5835488SYasunari Takiguchi 					  t_power_x_seq7,
1681e5835488SYasunari Takiguchi 					  ARRAY_SIZE(t_power_x_seq7));
1682e5835488SYasunari Takiguchi 	if (ret)
1683e5835488SYasunari Takiguchi 		return ret;
1684e5835488SYasunari Takiguchi 
1685e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io,
1686e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
1687e5835488SYasunari Takiguchi 				     0x00, 0x10);
1688e5835488SYasunari Takiguchi 	if (ret)
1689e5835488SYasunari Takiguchi 		return ret;
1690e5835488SYasunari Takiguchi 
1691e5835488SYasunari Takiguchi 	memset(data, 0x00, sizeof(data));
1692e5835488SYasunari Takiguchi 
1693e5835488SYasunari Takiguchi 	return tnr_dmd->io->write_regs(tnr_dmd->io,
1694e5835488SYasunari Takiguchi 				       CXD2880_IO_TGT_SYS,
1695e5835488SYasunari Takiguchi 				       0x27, data, 3);
1696e5835488SYasunari Takiguchi }
1697e5835488SYasunari Takiguchi 
1698e5835488SYasunari Takiguchi struct cxd2880_tnrdmd_ts_clk_cfg {
1699e5835488SYasunari Takiguchi 	u8 srl_clk_mode;
1700e5835488SYasunari Takiguchi 	u8 srl_duty_mode;
1701e5835488SYasunari Takiguchi 	u8 ts_clk_period;
1702e5835488SYasunari Takiguchi };
1703e5835488SYasunari Takiguchi 
set_ts_clk_mode_and_freq(struct cxd2880_tnrdmd * tnr_dmd,enum cxd2880_dtv_sys sys)1704e5835488SYasunari Takiguchi static int set_ts_clk_mode_and_freq(struct cxd2880_tnrdmd *tnr_dmd,
1705e5835488SYasunari Takiguchi 				    enum cxd2880_dtv_sys sys)
1706e5835488SYasunari Takiguchi {
1707e5835488SYasunari Takiguchi 	int ret;
1708e5835488SYasunari Takiguchi 	u8 backwards_compatible = 0;
1709e5835488SYasunari Takiguchi 	struct cxd2880_tnrdmd_ts_clk_cfg ts_clk_cfg;
1710e5835488SYasunari Takiguchi 	u8 ts_rate_ctrl_off = 0;
1711e5835488SYasunari Takiguchi 	u8 ts_in_off = 0;
1712e5835488SYasunari Takiguchi 	u8 ts_clk_manaul_on = 0;
1713e5835488SYasunari Takiguchi 	u8 data = 0;
1714e5835488SYasunari Takiguchi 
1715e5835488SYasunari Takiguchi 	static const struct cxd2880_tnrdmd_ts_clk_cfg srl_ts_clk_stgs[2][2] = {
1716e5835488SYasunari Takiguchi 		{
1717e5835488SYasunari Takiguchi 			{3, 1, 8,},
1718e5835488SYasunari Takiguchi 			{0, 2, 16,}
1719e5835488SYasunari Takiguchi 		}, {
1720e5835488SYasunari Takiguchi 			{1, 1, 8,},
1721e5835488SYasunari Takiguchi 			{2, 2, 16,}
1722e5835488SYasunari Takiguchi 		}
1723e5835488SYasunari Takiguchi 	};
1724e5835488SYasunari Takiguchi 
1725e5835488SYasunari Takiguchi 	if (!tnr_dmd)
1726e5835488SYasunari Takiguchi 		return -EINVAL;
1727e5835488SYasunari Takiguchi 
1728e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io,
1729e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_DMD,
1730e5835488SYasunari Takiguchi 				     0x00, 0x00);
1731e5835488SYasunari Takiguchi 	if (ret)
1732e5835488SYasunari Takiguchi 		return ret;
1733e5835488SYasunari Takiguchi 
1734e5835488SYasunari Takiguchi 	if (tnr_dmd->is_ts_backwards_compatible_mode) {
1735e5835488SYasunari Takiguchi 		backwards_compatible = 1;
1736e5835488SYasunari Takiguchi 		ts_rate_ctrl_off = 1;
1737e5835488SYasunari Takiguchi 		ts_in_off = 1;
1738e5835488SYasunari Takiguchi 	} else {
1739e5835488SYasunari Takiguchi 		backwards_compatible = 0;
1740e5835488SYasunari Takiguchi 		ts_rate_ctrl_off = 0;
1741e5835488SYasunari Takiguchi 		ts_in_off = 0;
1742e5835488SYasunari Takiguchi 	}
1743e5835488SYasunari Takiguchi 
1744e5835488SYasunari Takiguchi 	if (tnr_dmd->ts_byte_clk_manual_setting) {
1745e5835488SYasunari Takiguchi 		ts_clk_manaul_on = 1;
1746e5835488SYasunari Takiguchi 		ts_rate_ctrl_off = 0;
1747e5835488SYasunari Takiguchi 	}
1748e5835488SYasunari Takiguchi 
1749e5835488SYasunari Takiguchi 	ret = cxd2880_io_set_reg_bits(tnr_dmd->io,
1750e5835488SYasunari Takiguchi 				      CXD2880_IO_TGT_DMD,
1751e5835488SYasunari Takiguchi 				      0xd3, ts_rate_ctrl_off, 0x01);
1752e5835488SYasunari Takiguchi 	if (ret)
1753e5835488SYasunari Takiguchi 		return ret;
1754e5835488SYasunari Takiguchi 
1755e5835488SYasunari Takiguchi 	ret = cxd2880_io_set_reg_bits(tnr_dmd->io,
1756e5835488SYasunari Takiguchi 				      CXD2880_IO_TGT_DMD,
1757e5835488SYasunari Takiguchi 				      0xde, ts_in_off, 0x01);
1758e5835488SYasunari Takiguchi 	if (ret)
1759e5835488SYasunari Takiguchi 		return ret;
1760e5835488SYasunari Takiguchi 
1761e5835488SYasunari Takiguchi 	ret = cxd2880_io_set_reg_bits(tnr_dmd->io,
1762e5835488SYasunari Takiguchi 				      CXD2880_IO_TGT_DMD,
1763e5835488SYasunari Takiguchi 				      0xda, ts_clk_manaul_on, 0x01);
1764e5835488SYasunari Takiguchi 	if (ret)
1765e5835488SYasunari Takiguchi 		return ret;
1766e5835488SYasunari Takiguchi 
1767e5835488SYasunari Takiguchi 	ts_clk_cfg = srl_ts_clk_stgs[tnr_dmd->srl_ts_clk_mod_cnts]
1768e5835488SYasunari Takiguchi 				    [tnr_dmd->srl_ts_clk_frq];
1769e5835488SYasunari Takiguchi 
1770e5835488SYasunari Takiguchi 	if (tnr_dmd->ts_byte_clk_manual_setting)
1771e5835488SYasunari Takiguchi 		ts_clk_cfg.ts_clk_period = tnr_dmd->ts_byte_clk_manual_setting;
1772e5835488SYasunari Takiguchi 
1773e5835488SYasunari Takiguchi 	ret = cxd2880_io_set_reg_bits(tnr_dmd->io,
1774e5835488SYasunari Takiguchi 				      CXD2880_IO_TGT_DMD,
1775e5835488SYasunari Takiguchi 				      0xc4, ts_clk_cfg.srl_clk_mode, 0x03);
1776e5835488SYasunari Takiguchi 	if (ret)
1777e5835488SYasunari Takiguchi 		return ret;
1778e5835488SYasunari Takiguchi 
1779e5835488SYasunari Takiguchi 	ret = cxd2880_io_set_reg_bits(tnr_dmd->io,
1780e5835488SYasunari Takiguchi 				      CXD2880_IO_TGT_DMD,
1781e5835488SYasunari Takiguchi 				      0xd1, ts_clk_cfg.srl_duty_mode, 0x03);
1782e5835488SYasunari Takiguchi 	if (ret)
1783e5835488SYasunari Takiguchi 		return ret;
1784e5835488SYasunari Takiguchi 
1785e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io,
1786e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_DMD, 0xd9,
1787e5835488SYasunari Takiguchi 				     ts_clk_cfg.ts_clk_period);
1788e5835488SYasunari Takiguchi 	if (ret)
1789e5835488SYasunari Takiguchi 		return ret;
1790e5835488SYasunari Takiguchi 
1791e5835488SYasunari Takiguchi 	data = backwards_compatible ? 0x00 : 0x01;
1792e5835488SYasunari Takiguchi 
1793e5835488SYasunari Takiguchi 	if (sys == CXD2880_DTV_SYS_DVBT) {
1794e5835488SYasunari Takiguchi 		ret = tnr_dmd->io->write_reg(tnr_dmd->io,
1795e5835488SYasunari Takiguchi 					     CXD2880_IO_TGT_DMD,
1796e5835488SYasunari Takiguchi 					     0x00, 0x10);
1797e5835488SYasunari Takiguchi 		if (ret)
1798e5835488SYasunari Takiguchi 			return ret;
1799e5835488SYasunari Takiguchi 
1800e5835488SYasunari Takiguchi 		ret =
1801e5835488SYasunari Takiguchi 		    cxd2880_io_set_reg_bits(tnr_dmd->io,
1802e5835488SYasunari Takiguchi 					    CXD2880_IO_TGT_DMD,
1803e5835488SYasunari Takiguchi 					    0x66, data, 0x01);
1804e5835488SYasunari Takiguchi 	}
1805e5835488SYasunari Takiguchi 
1806e5835488SYasunari Takiguchi 	return ret;
1807e5835488SYasunari Takiguchi }
1808e5835488SYasunari Takiguchi 
pid_ftr_setting(struct cxd2880_tnrdmd * tnr_dmd,struct cxd2880_tnrdmd_pid_ftr_cfg * pid_ftr_cfg)1809e5835488SYasunari Takiguchi static int pid_ftr_setting(struct cxd2880_tnrdmd *tnr_dmd,
1810e5835488SYasunari Takiguchi 			   struct cxd2880_tnrdmd_pid_ftr_cfg
1811e5835488SYasunari Takiguchi 			   *pid_ftr_cfg)
1812e5835488SYasunari Takiguchi {
1813e5835488SYasunari Takiguchi 	int i;
1814e5835488SYasunari Takiguchi 	int ret;
1815e5835488SYasunari Takiguchi 	u8 data[65];
1816e5835488SYasunari Takiguchi 
1817e5835488SYasunari Takiguchi 	if (!tnr_dmd)
1818e5835488SYasunari Takiguchi 		return -EINVAL;
1819e5835488SYasunari Takiguchi 
1820e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io,
1821e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_DMD,
1822e5835488SYasunari Takiguchi 				     0x00, 0x00);
1823e5835488SYasunari Takiguchi 	if (ret)
1824e5835488SYasunari Takiguchi 		return ret;
1825e5835488SYasunari Takiguchi 
1826e5835488SYasunari Takiguchi 	if (!pid_ftr_cfg)
1827e5835488SYasunari Takiguchi 		return tnr_dmd->io->write_reg(tnr_dmd->io,
1828e5835488SYasunari Takiguchi 					      CXD2880_IO_TGT_DMD,
1829e5835488SYasunari Takiguchi 					      0x50, 0x02);
1830e5835488SYasunari Takiguchi 
1831e5835488SYasunari Takiguchi 	data[0] = pid_ftr_cfg->is_negative ? 0x01 : 0x00;
1832e5835488SYasunari Takiguchi 
1833e5835488SYasunari Takiguchi 	for (i = 0; i < 32; i++) {
1834e5835488SYasunari Takiguchi 		if (pid_ftr_cfg->pid_cfg[i].is_en) {
1835e5835488SYasunari Takiguchi 			data[1 + (i * 2)] = (pid_ftr_cfg->pid_cfg[i].pid >> 8) | 0x20;
1836e5835488SYasunari Takiguchi 			data[2 + (i * 2)] =  pid_ftr_cfg->pid_cfg[i].pid & 0xff;
1837e5835488SYasunari Takiguchi 		} else {
1838e5835488SYasunari Takiguchi 			data[1 + (i * 2)] = 0x00;
1839e5835488SYasunari Takiguchi 			data[2 + (i * 2)] = 0x00;
1840e5835488SYasunari Takiguchi 		}
1841e5835488SYasunari Takiguchi 	}
1842e5835488SYasunari Takiguchi 
1843e5835488SYasunari Takiguchi 	return tnr_dmd->io->write_regs(tnr_dmd->io,
1844e5835488SYasunari Takiguchi 				       CXD2880_IO_TGT_DMD,
1845e5835488SYasunari Takiguchi 				       0x50, data, 65);
1846e5835488SYasunari Takiguchi }
1847e5835488SYasunari Takiguchi 
load_cfg_mem(struct cxd2880_tnrdmd * tnr_dmd)1848e5835488SYasunari Takiguchi static int load_cfg_mem(struct cxd2880_tnrdmd *tnr_dmd)
1849e5835488SYasunari Takiguchi {
1850e5835488SYasunari Takiguchi 	int ret;
1851e5835488SYasunari Takiguchi 	u8 i;
1852e5835488SYasunari Takiguchi 
1853e5835488SYasunari Takiguchi 	if (!tnr_dmd)
1854e5835488SYasunari Takiguchi 		return -EINVAL;
1855e5835488SYasunari Takiguchi 
1856e5835488SYasunari Takiguchi 	for (i = 0; i < tnr_dmd->cfg_mem_last_entry; i++) {
1857e5835488SYasunari Takiguchi 		ret = tnr_dmd->io->write_reg(tnr_dmd->io,
1858e5835488SYasunari Takiguchi 					     tnr_dmd->cfg_mem[i].tgt,
1859e5835488SYasunari Takiguchi 					     0x00, tnr_dmd->cfg_mem[i].bank);
1860e5835488SYasunari Takiguchi 		if (ret)
1861e5835488SYasunari Takiguchi 			return ret;
1862e5835488SYasunari Takiguchi 
1863e5835488SYasunari Takiguchi 		ret = cxd2880_io_set_reg_bits(tnr_dmd->io,
1864e5835488SYasunari Takiguchi 					      tnr_dmd->cfg_mem[i].tgt,
1865e5835488SYasunari Takiguchi 					      tnr_dmd->cfg_mem[i].address,
1866e5835488SYasunari Takiguchi 					      tnr_dmd->cfg_mem[i].value,
1867e5835488SYasunari Takiguchi 					      tnr_dmd->cfg_mem[i].bit_mask);
1868e5835488SYasunari Takiguchi 		if (ret)
1869e5835488SYasunari Takiguchi 			return ret;
1870e5835488SYasunari Takiguchi 	}
1871e5835488SYasunari Takiguchi 
1872e5835488SYasunari Takiguchi 	return 0;
1873e5835488SYasunari Takiguchi }
1874e5835488SYasunari Takiguchi 
set_cfg_mem(struct cxd2880_tnrdmd * tnr_dmd,enum cxd2880_io_tgt tgt,u8 bank,u8 address,u8 value,u8 bit_mask)1875e5835488SYasunari Takiguchi static int set_cfg_mem(struct cxd2880_tnrdmd *tnr_dmd,
1876e5835488SYasunari Takiguchi 		       enum cxd2880_io_tgt tgt,
1877e5835488SYasunari Takiguchi 		       u8 bank, u8 address, u8 value, u8 bit_mask)
1878e5835488SYasunari Takiguchi {
1879e5835488SYasunari Takiguchi 	u8 i;
1880e5835488SYasunari Takiguchi 	u8 value_stored = 0;
1881e5835488SYasunari Takiguchi 
1882e5835488SYasunari Takiguchi 	if (!tnr_dmd)
1883e5835488SYasunari Takiguchi 		return -EINVAL;
1884e5835488SYasunari Takiguchi 
1885e5835488SYasunari Takiguchi 	for (i = 0; i < tnr_dmd->cfg_mem_last_entry; i++) {
1886e5835488SYasunari Takiguchi 		if (value_stored == 0 &&
1887e5835488SYasunari Takiguchi 		    tnr_dmd->cfg_mem[i].tgt == tgt &&
1888e5835488SYasunari Takiguchi 		    tnr_dmd->cfg_mem[i].bank == bank &&
1889e5835488SYasunari Takiguchi 		    tnr_dmd->cfg_mem[i].address == address) {
1890e5835488SYasunari Takiguchi 			tnr_dmd->cfg_mem[i].value &= ~bit_mask;
1891e5835488SYasunari Takiguchi 			tnr_dmd->cfg_mem[i].value |= (value & bit_mask);
1892e5835488SYasunari Takiguchi 
1893e5835488SYasunari Takiguchi 			tnr_dmd->cfg_mem[i].bit_mask |= bit_mask;
1894e5835488SYasunari Takiguchi 
1895e5835488SYasunari Takiguchi 			value_stored = 1;
1896e5835488SYasunari Takiguchi 		}
1897e5835488SYasunari Takiguchi 	}
1898e5835488SYasunari Takiguchi 
1899e5835488SYasunari Takiguchi 	if (value_stored)
1900e5835488SYasunari Takiguchi 		return 0;
1901e5835488SYasunari Takiguchi 
1902e5835488SYasunari Takiguchi 	if (tnr_dmd->cfg_mem_last_entry < CXD2880_TNRDMD_MAX_CFG_MEM_COUNT) {
1903e5835488SYasunari Takiguchi 		tnr_dmd->cfg_mem[tnr_dmd->cfg_mem_last_entry].tgt = tgt;
1904e5835488SYasunari Takiguchi 		tnr_dmd->cfg_mem[tnr_dmd->cfg_mem_last_entry].bank = bank;
1905e5835488SYasunari Takiguchi 		tnr_dmd->cfg_mem[tnr_dmd->cfg_mem_last_entry].address = address;
1906e5835488SYasunari Takiguchi 		tnr_dmd->cfg_mem[tnr_dmd->cfg_mem_last_entry].value = (value & bit_mask);
1907e5835488SYasunari Takiguchi 		tnr_dmd->cfg_mem[tnr_dmd->cfg_mem_last_entry].bit_mask = bit_mask;
1908e5835488SYasunari Takiguchi 		tnr_dmd->cfg_mem_last_entry++;
1909e5835488SYasunari Takiguchi 	} else {
1910e5835488SYasunari Takiguchi 		return -ENOMEM;
1911e5835488SYasunari Takiguchi 	}
1912e5835488SYasunari Takiguchi 
1913e5835488SYasunari Takiguchi 	return 0;
1914e5835488SYasunari Takiguchi }
1915e5835488SYasunari Takiguchi 
cxd2880_tnrdmd_create(struct cxd2880_tnrdmd * tnr_dmd,struct cxd2880_io * io,struct cxd2880_tnrdmd_create_param * create_param)1916e5835488SYasunari Takiguchi int cxd2880_tnrdmd_create(struct cxd2880_tnrdmd *tnr_dmd,
1917e5835488SYasunari Takiguchi 			  struct cxd2880_io *io,
1918e5835488SYasunari Takiguchi 			  struct cxd2880_tnrdmd_create_param
1919e5835488SYasunari Takiguchi 			  *create_param)
1920e5835488SYasunari Takiguchi {
1921e5835488SYasunari Takiguchi 	if (!tnr_dmd || !io || !create_param)
1922e5835488SYasunari Takiguchi 		return -EINVAL;
1923e5835488SYasunari Takiguchi 
1924e5835488SYasunari Takiguchi 	memset(tnr_dmd, 0, sizeof(struct cxd2880_tnrdmd));
1925e5835488SYasunari Takiguchi 
1926e5835488SYasunari Takiguchi 	tnr_dmd->io = io;
1927e5835488SYasunari Takiguchi 	tnr_dmd->create_param = *create_param;
1928e5835488SYasunari Takiguchi 
1929e5835488SYasunari Takiguchi 	tnr_dmd->diver_mode = CXD2880_TNRDMD_DIVERMODE_SINGLE;
1930e5835488SYasunari Takiguchi 	tnr_dmd->diver_sub = NULL;
1931e5835488SYasunari Takiguchi 
1932e5835488SYasunari Takiguchi 	tnr_dmd->srl_ts_clk_mod_cnts = 1;
1933e5835488SYasunari Takiguchi 	tnr_dmd->en_fef_intmtnt_base = 1;
1934e5835488SYasunari Takiguchi 	tnr_dmd->en_fef_intmtnt_lite = 1;
1935e5835488SYasunari Takiguchi 	tnr_dmd->rf_lvl_cmpstn = NULL;
1936e5835488SYasunari Takiguchi 	tnr_dmd->lna_thrs_tbl_air = NULL;
1937e5835488SYasunari Takiguchi 	tnr_dmd->lna_thrs_tbl_cable = NULL;
1938e5835488SYasunari Takiguchi 	atomic_set(&tnr_dmd->cancel, 0);
1939e5835488SYasunari Takiguchi 
1940e5835488SYasunari Takiguchi 	return 0;
1941e5835488SYasunari Takiguchi }
1942e5835488SYasunari Takiguchi 
cxd2880_tnrdmd_diver_create(struct cxd2880_tnrdmd * tnr_dmd_main,struct cxd2880_io * io_main,struct cxd2880_tnrdmd * tnr_dmd_sub,struct cxd2880_io * io_sub,struct cxd2880_tnrdmd_diver_create_param * create_param)1943e5835488SYasunari Takiguchi int cxd2880_tnrdmd_diver_create(struct cxd2880_tnrdmd
1944e5835488SYasunari Takiguchi 				*tnr_dmd_main,
1945e5835488SYasunari Takiguchi 				struct cxd2880_io *io_main,
1946e5835488SYasunari Takiguchi 				struct cxd2880_tnrdmd *tnr_dmd_sub,
1947e5835488SYasunari Takiguchi 				struct cxd2880_io *io_sub,
1948e5835488SYasunari Takiguchi 				struct
1949e5835488SYasunari Takiguchi 				cxd2880_tnrdmd_diver_create_param
1950e5835488SYasunari Takiguchi 				*create_param)
1951e5835488SYasunari Takiguchi {
1952e5835488SYasunari Takiguchi 	struct cxd2880_tnrdmd_create_param *main_param, *sub_param;
1953e5835488SYasunari Takiguchi 
1954e5835488SYasunari Takiguchi 	if (!tnr_dmd_main || !io_main || !tnr_dmd_sub || !io_sub ||
1955e5835488SYasunari Takiguchi 	    !create_param)
1956e5835488SYasunari Takiguchi 		return -EINVAL;
1957e5835488SYasunari Takiguchi 
1958e5835488SYasunari Takiguchi 	memset(tnr_dmd_main, 0, sizeof(struct cxd2880_tnrdmd));
1959e5835488SYasunari Takiguchi 	memset(tnr_dmd_sub, 0, sizeof(struct cxd2880_tnrdmd));
1960e5835488SYasunari Takiguchi 
1961e5835488SYasunari Takiguchi 	main_param = &tnr_dmd_main->create_param;
1962e5835488SYasunari Takiguchi 	sub_param = &tnr_dmd_sub->create_param;
1963e5835488SYasunari Takiguchi 
1964e5835488SYasunari Takiguchi 	tnr_dmd_main->io = io_main;
1965e5835488SYasunari Takiguchi 	tnr_dmd_main->diver_mode = CXD2880_TNRDMD_DIVERMODE_MAIN;
1966e5835488SYasunari Takiguchi 	tnr_dmd_main->diver_sub = tnr_dmd_sub;
1967e5835488SYasunari Takiguchi 	tnr_dmd_main->create_param.en_internal_ldo =
1968e5835488SYasunari Takiguchi 	    create_param->en_internal_ldo;
1969e5835488SYasunari Takiguchi 
1970e5835488SYasunari Takiguchi 	main_param->ts_output_if = create_param->ts_output_if;
1971e5835488SYasunari Takiguchi 	main_param->xtal_share_type = CXD2880_TNRDMD_XTAL_SHARE_MASTER;
1972e5835488SYasunari Takiguchi 	main_param->xosc_cap = create_param->xosc_cap_main;
1973e5835488SYasunari Takiguchi 	main_param->xosc_i = create_param->xosc_i_main;
1974e5835488SYasunari Takiguchi 	main_param->is_cxd2881gg = create_param->is_cxd2881gg;
1975e5835488SYasunari Takiguchi 	main_param->stationary_use = create_param->stationary_use;
1976e5835488SYasunari Takiguchi 
1977e5835488SYasunari Takiguchi 	tnr_dmd_sub->io = io_sub;
1978e5835488SYasunari Takiguchi 	tnr_dmd_sub->diver_mode = CXD2880_TNRDMD_DIVERMODE_SUB;
1979e5835488SYasunari Takiguchi 	tnr_dmd_sub->diver_sub = NULL;
1980e5835488SYasunari Takiguchi 
1981e5835488SYasunari Takiguchi 	sub_param->en_internal_ldo = create_param->en_internal_ldo;
1982e5835488SYasunari Takiguchi 	sub_param->ts_output_if = create_param->ts_output_if;
1983e5835488SYasunari Takiguchi 	sub_param->xtal_share_type = CXD2880_TNRDMD_XTAL_SHARE_SLAVE;
1984e5835488SYasunari Takiguchi 	sub_param->xosc_cap = 0;
1985e5835488SYasunari Takiguchi 	sub_param->xosc_i = create_param->xosc_i_sub;
1986e5835488SYasunari Takiguchi 	sub_param->is_cxd2881gg = create_param->is_cxd2881gg;
1987e5835488SYasunari Takiguchi 	sub_param->stationary_use = create_param->stationary_use;
1988e5835488SYasunari Takiguchi 
1989e5835488SYasunari Takiguchi 	tnr_dmd_main->srl_ts_clk_mod_cnts = 1;
1990e5835488SYasunari Takiguchi 	tnr_dmd_main->en_fef_intmtnt_base = 1;
1991e5835488SYasunari Takiguchi 	tnr_dmd_main->en_fef_intmtnt_lite = 1;
1992e5835488SYasunari Takiguchi 	tnr_dmd_main->rf_lvl_cmpstn = NULL;
1993e5835488SYasunari Takiguchi 	tnr_dmd_main->lna_thrs_tbl_air = NULL;
1994e5835488SYasunari Takiguchi 	tnr_dmd_main->lna_thrs_tbl_cable = NULL;
1995e5835488SYasunari Takiguchi 
1996e5835488SYasunari Takiguchi 	tnr_dmd_sub->srl_ts_clk_mod_cnts = 1;
1997e5835488SYasunari Takiguchi 	tnr_dmd_sub->en_fef_intmtnt_base = 1;
1998e5835488SYasunari Takiguchi 	tnr_dmd_sub->en_fef_intmtnt_lite = 1;
1999e5835488SYasunari Takiguchi 	tnr_dmd_sub->rf_lvl_cmpstn = NULL;
2000e5835488SYasunari Takiguchi 	tnr_dmd_sub->lna_thrs_tbl_air = NULL;
2001e5835488SYasunari Takiguchi 	tnr_dmd_sub->lna_thrs_tbl_cable = NULL;
2002e5835488SYasunari Takiguchi 
2003e5835488SYasunari Takiguchi 	return 0;
2004e5835488SYasunari Takiguchi }
2005e5835488SYasunari Takiguchi 
cxd2880_tnrdmd_init1(struct cxd2880_tnrdmd * tnr_dmd)2006e5835488SYasunari Takiguchi int cxd2880_tnrdmd_init1(struct cxd2880_tnrdmd *tnr_dmd)
2007e5835488SYasunari Takiguchi {
2008e5835488SYasunari Takiguchi 	int ret;
2009e5835488SYasunari Takiguchi 
2010e5835488SYasunari Takiguchi 	if (!tnr_dmd || tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_SUB)
2011e5835488SYasunari Takiguchi 		return -EINVAL;
2012e5835488SYasunari Takiguchi 
2013e5835488SYasunari Takiguchi 	tnr_dmd->chip_id = CXD2880_TNRDMD_CHIP_ID_UNKNOWN;
2014e5835488SYasunari Takiguchi 	tnr_dmd->state = CXD2880_TNRDMD_STATE_UNKNOWN;
2015e5835488SYasunari Takiguchi 	tnr_dmd->clk_mode = CXD2880_TNRDMD_CLOCKMODE_UNKNOWN;
2016e5835488SYasunari Takiguchi 	tnr_dmd->frequency_khz = 0;
2017e5835488SYasunari Takiguchi 	tnr_dmd->sys = CXD2880_DTV_SYS_UNKNOWN;
2018e5835488SYasunari Takiguchi 	tnr_dmd->bandwidth = CXD2880_DTV_BW_UNKNOWN;
2019e5835488SYasunari Takiguchi 	tnr_dmd->scan_mode = 0;
2020e5835488SYasunari Takiguchi 	atomic_set(&tnr_dmd->cancel, 0);
2021e5835488SYasunari Takiguchi 
2022e5835488SYasunari Takiguchi 	if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_MAIN) {
2023e5835488SYasunari Takiguchi 		tnr_dmd->diver_sub->chip_id = CXD2880_TNRDMD_CHIP_ID_UNKNOWN;
2024e5835488SYasunari Takiguchi 		tnr_dmd->diver_sub->state = CXD2880_TNRDMD_STATE_UNKNOWN;
2025e5835488SYasunari Takiguchi 		tnr_dmd->diver_sub->clk_mode = CXD2880_TNRDMD_CLOCKMODE_UNKNOWN;
2026e5835488SYasunari Takiguchi 		tnr_dmd->diver_sub->frequency_khz = 0;
2027e5835488SYasunari Takiguchi 		tnr_dmd->diver_sub->sys = CXD2880_DTV_SYS_UNKNOWN;
2028e5835488SYasunari Takiguchi 		tnr_dmd->diver_sub->bandwidth = CXD2880_DTV_BW_UNKNOWN;
2029e5835488SYasunari Takiguchi 		tnr_dmd->diver_sub->scan_mode = 0;
2030e5835488SYasunari Takiguchi 		atomic_set(&tnr_dmd->diver_sub->cancel, 0);
2031e5835488SYasunari Takiguchi 	}
2032e5835488SYasunari Takiguchi 
2033e5835488SYasunari Takiguchi 	ret = cxd2880_tnrdmd_chip_id(tnr_dmd, &tnr_dmd->chip_id);
2034e5835488SYasunari Takiguchi 	if (ret)
2035e5835488SYasunari Takiguchi 		return ret;
2036e5835488SYasunari Takiguchi 
2037e5835488SYasunari Takiguchi 	if (!CXD2880_TNRDMD_CHIP_ID_VALID(tnr_dmd->chip_id))
2038e5835488SYasunari Takiguchi 		return -ENOTTY;
2039e5835488SYasunari Takiguchi 
2040e5835488SYasunari Takiguchi 	if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_MAIN) {
2041e5835488SYasunari Takiguchi 		ret =
2042e5835488SYasunari Takiguchi 		    cxd2880_tnrdmd_chip_id(tnr_dmd->diver_sub,
2043e5835488SYasunari Takiguchi 					   &tnr_dmd->diver_sub->chip_id);
2044e5835488SYasunari Takiguchi 		if (ret)
2045e5835488SYasunari Takiguchi 			return ret;
2046e5835488SYasunari Takiguchi 
2047e5835488SYasunari Takiguchi 		if (!CXD2880_TNRDMD_CHIP_ID_VALID(tnr_dmd->diver_sub->chip_id))
2048e5835488SYasunari Takiguchi 			return -ENOTTY;
2049e5835488SYasunari Takiguchi 	}
2050e5835488SYasunari Takiguchi 
2051e5835488SYasunari Takiguchi 	ret = p_init1(tnr_dmd);
2052e5835488SYasunari Takiguchi 	if (ret)
2053e5835488SYasunari Takiguchi 		return ret;
2054e5835488SYasunari Takiguchi 
2055e5835488SYasunari Takiguchi 	if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_MAIN) {
2056e5835488SYasunari Takiguchi 		ret = p_init1(tnr_dmd->diver_sub);
2057e5835488SYasunari Takiguchi 		if (ret)
2058e5835488SYasunari Takiguchi 			return ret;
2059e5835488SYasunari Takiguchi 	}
2060e5835488SYasunari Takiguchi 
2061e5835488SYasunari Takiguchi 	usleep_range(1000, 2000);
2062e5835488SYasunari Takiguchi 
2063e5835488SYasunari Takiguchi 	if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_MAIN) {
2064e5835488SYasunari Takiguchi 		ret = p_init2(tnr_dmd->diver_sub);
2065e5835488SYasunari Takiguchi 		if (ret)
2066e5835488SYasunari Takiguchi 			return ret;
2067e5835488SYasunari Takiguchi 	}
2068e5835488SYasunari Takiguchi 
2069e5835488SYasunari Takiguchi 	ret = p_init2(tnr_dmd);
2070e5835488SYasunari Takiguchi 	if (ret)
2071e5835488SYasunari Takiguchi 		return ret;
2072e5835488SYasunari Takiguchi 
2073e5835488SYasunari Takiguchi 	usleep_range(5000, 6000);
2074e5835488SYasunari Takiguchi 
2075e5835488SYasunari Takiguchi 	ret = p_init3(tnr_dmd);
2076e5835488SYasunari Takiguchi 	if (ret)
2077e5835488SYasunari Takiguchi 		return ret;
2078e5835488SYasunari Takiguchi 
2079e5835488SYasunari Takiguchi 	if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_MAIN) {
2080e5835488SYasunari Takiguchi 		ret = p_init3(tnr_dmd->diver_sub);
2081e5835488SYasunari Takiguchi 		if (ret)
2082e5835488SYasunari Takiguchi 			return ret;
2083e5835488SYasunari Takiguchi 	}
2084e5835488SYasunari Takiguchi 
2085e5835488SYasunari Takiguchi 	ret = rf_init1(tnr_dmd);
2086e5835488SYasunari Takiguchi 	if (ret)
2087e5835488SYasunari Takiguchi 		return ret;
2088e5835488SYasunari Takiguchi 
2089e5835488SYasunari Takiguchi 	if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_MAIN)
2090e5835488SYasunari Takiguchi 		ret = rf_init1(tnr_dmd->diver_sub);
2091e5835488SYasunari Takiguchi 
2092e5835488SYasunari Takiguchi 	return ret;
2093e5835488SYasunari Takiguchi }
2094e5835488SYasunari Takiguchi 
cxd2880_tnrdmd_init2(struct cxd2880_tnrdmd * tnr_dmd)2095e5835488SYasunari Takiguchi int cxd2880_tnrdmd_init2(struct cxd2880_tnrdmd *tnr_dmd)
2096e5835488SYasunari Takiguchi {
2097e5835488SYasunari Takiguchi 	u8 cpu_task_completed;
2098e5835488SYasunari Takiguchi 	int ret;
2099e5835488SYasunari Takiguchi 
2100e5835488SYasunari Takiguchi 	if (!tnr_dmd)
2101e5835488SYasunari Takiguchi 		return -EINVAL;
2102e5835488SYasunari Takiguchi 
2103e5835488SYasunari Takiguchi 	if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_SUB)
2104e5835488SYasunari Takiguchi 		return -EINVAL;
2105e5835488SYasunari Takiguchi 
2106e5835488SYasunari Takiguchi 	ret = cxd2880_tnrdmd_check_internal_cpu_status(tnr_dmd,
2107e5835488SYasunari Takiguchi 						     &cpu_task_completed);
2108e5835488SYasunari Takiguchi 	if (ret)
2109e5835488SYasunari Takiguchi 		return ret;
2110e5835488SYasunari Takiguchi 
2111e5835488SYasunari Takiguchi 	if (!cpu_task_completed)
2112e5835488SYasunari Takiguchi 		return -EINVAL;
2113e5835488SYasunari Takiguchi 
2114e5835488SYasunari Takiguchi 	ret = rf_init2(tnr_dmd);
2115e5835488SYasunari Takiguchi 	if (ret)
2116e5835488SYasunari Takiguchi 		return ret;
2117e5835488SYasunari Takiguchi 
2118e5835488SYasunari Takiguchi 	if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_MAIN) {
2119e5835488SYasunari Takiguchi 		ret = rf_init2(tnr_dmd->diver_sub);
2120e5835488SYasunari Takiguchi 		if (ret)
2121e5835488SYasunari Takiguchi 			return ret;
2122e5835488SYasunari Takiguchi 	}
2123e5835488SYasunari Takiguchi 
2124e5835488SYasunari Takiguchi 	ret = load_cfg_mem(tnr_dmd);
2125e5835488SYasunari Takiguchi 	if (ret)
2126e5835488SYasunari Takiguchi 		return ret;
2127e5835488SYasunari Takiguchi 
2128e5835488SYasunari Takiguchi 	if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_MAIN) {
2129e5835488SYasunari Takiguchi 		ret = load_cfg_mem(tnr_dmd->diver_sub);
2130e5835488SYasunari Takiguchi 		if (ret)
2131e5835488SYasunari Takiguchi 			return ret;
2132e5835488SYasunari Takiguchi 	}
2133e5835488SYasunari Takiguchi 
2134e5835488SYasunari Takiguchi 	tnr_dmd->state = CXD2880_TNRDMD_STATE_SLEEP;
2135e5835488SYasunari Takiguchi 
2136e5835488SYasunari Takiguchi 	if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_MAIN)
2137e5835488SYasunari Takiguchi 		tnr_dmd->diver_sub->state = CXD2880_TNRDMD_STATE_SLEEP;
2138e5835488SYasunari Takiguchi 
2139e5835488SYasunari Takiguchi 	return ret;
2140e5835488SYasunari Takiguchi }
2141e5835488SYasunari Takiguchi 
cxd2880_tnrdmd_check_internal_cpu_status(struct cxd2880_tnrdmd * tnr_dmd,u8 * task_completed)2142e5835488SYasunari Takiguchi int cxd2880_tnrdmd_check_internal_cpu_status(struct cxd2880_tnrdmd
2143e5835488SYasunari Takiguchi 					     *tnr_dmd,
2144e5835488SYasunari Takiguchi 					     u8 *task_completed)
2145e5835488SYasunari Takiguchi {
2146e5835488SYasunari Takiguchi 	u16 cpu_status = 0;
2147e5835488SYasunari Takiguchi 	int ret;
2148e5835488SYasunari Takiguchi 
2149e5835488SYasunari Takiguchi 	if (!tnr_dmd || !task_completed)
2150e5835488SYasunari Takiguchi 		return -EINVAL;
2151e5835488SYasunari Takiguchi 
2152e5835488SYasunari Takiguchi 	if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_SUB)
2153e5835488SYasunari Takiguchi 		return -EINVAL;
2154e5835488SYasunari Takiguchi 
2155e5835488SYasunari Takiguchi 	ret = cxd2880_tnrdmd_mon_internal_cpu_status(tnr_dmd, &cpu_status);
2156e5835488SYasunari Takiguchi 	if (ret)
2157e5835488SYasunari Takiguchi 		return ret;
2158e5835488SYasunari Takiguchi 
2159e5835488SYasunari Takiguchi 	if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_SINGLE) {
2160e5835488SYasunari Takiguchi 		if (cpu_status == 0)
2161e5835488SYasunari Takiguchi 			*task_completed = 1;
2162e5835488SYasunari Takiguchi 		else
2163e5835488SYasunari Takiguchi 			*task_completed = 0;
2164e5835488SYasunari Takiguchi 
2165*8963c119SHans Verkuil 		return 0;
2166e5835488SYasunari Takiguchi 	}
2167e5835488SYasunari Takiguchi 	if (cpu_status != 0) {
2168e5835488SYasunari Takiguchi 		*task_completed = 0;
2169*8963c119SHans Verkuil 		return 0;
2170e5835488SYasunari Takiguchi 	}
2171e5835488SYasunari Takiguchi 
2172e5835488SYasunari Takiguchi 	ret = cxd2880_tnrdmd_mon_internal_cpu_status_sub(tnr_dmd, &cpu_status);
2173e5835488SYasunari Takiguchi 	if (ret)
2174e5835488SYasunari Takiguchi 		return ret;
2175e5835488SYasunari Takiguchi 
2176e5835488SYasunari Takiguchi 	if (cpu_status == 0)
2177e5835488SYasunari Takiguchi 		*task_completed = 1;
2178e5835488SYasunari Takiguchi 	else
2179e5835488SYasunari Takiguchi 		*task_completed = 0;
2180e5835488SYasunari Takiguchi 
2181e5835488SYasunari Takiguchi 	return ret;
2182e5835488SYasunari Takiguchi }
2183e5835488SYasunari Takiguchi 
cxd2880_tnrdmd_common_tune_setting1(struct cxd2880_tnrdmd * tnr_dmd,enum cxd2880_dtv_sys sys,u32 frequency_khz,enum cxd2880_dtv_bandwidth bandwidth,u8 one_seg_opt,u8 one_seg_opt_shft_dir)2184e5835488SYasunari Takiguchi int cxd2880_tnrdmd_common_tune_setting1(struct cxd2880_tnrdmd *tnr_dmd,
2185e5835488SYasunari Takiguchi 					enum cxd2880_dtv_sys sys,
2186e5835488SYasunari Takiguchi 					u32 frequency_khz,
2187e5835488SYasunari Takiguchi 					enum cxd2880_dtv_bandwidth
2188e5835488SYasunari Takiguchi 					bandwidth, u8 one_seg_opt,
2189e5835488SYasunari Takiguchi 					u8 one_seg_opt_shft_dir)
2190e5835488SYasunari Takiguchi {
2191e5835488SYasunari Takiguchi 	u8 data;
2192e5835488SYasunari Takiguchi 	enum cxd2880_tnrdmd_clockmode new_clk_mode =
2193e5835488SYasunari Takiguchi 				CXD2880_TNRDMD_CLOCKMODE_A;
2194e5835488SYasunari Takiguchi 	int shift_frequency_khz;
2195e5835488SYasunari Takiguchi 	u8 cpu_task_completed;
2196e5835488SYasunari Takiguchi 	int ret;
2197e5835488SYasunari Takiguchi 
2198e5835488SYasunari Takiguchi 	if (!tnr_dmd)
2199e5835488SYasunari Takiguchi 		return -EINVAL;
2200e5835488SYasunari Takiguchi 
2201e5835488SYasunari Takiguchi 	if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_SUB)
2202e5835488SYasunari Takiguchi 		return -EINVAL;
2203e5835488SYasunari Takiguchi 
2204e5835488SYasunari Takiguchi 	if (tnr_dmd->state != CXD2880_TNRDMD_STATE_SLEEP &&
2205e5835488SYasunari Takiguchi 	    tnr_dmd->state != CXD2880_TNRDMD_STATE_ACTIVE)
2206e5835488SYasunari Takiguchi 		return -EINVAL;
2207e5835488SYasunari Takiguchi 
2208e5835488SYasunari Takiguchi 	if (frequency_khz < 4000)
2209e5835488SYasunari Takiguchi 		return -EINVAL;
2210e5835488SYasunari Takiguchi 
2211e5835488SYasunari Takiguchi 	ret = cxd2880_tnrdmd_sleep(tnr_dmd);
2212e5835488SYasunari Takiguchi 	if (ret)
2213e5835488SYasunari Takiguchi 		return ret;
2214e5835488SYasunari Takiguchi 
2215e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io,
2216e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
2217e5835488SYasunari Takiguchi 				     0x00,
2218e5835488SYasunari Takiguchi 				     0x00);
2219e5835488SYasunari Takiguchi 	if (ret)
2220e5835488SYasunari Takiguchi 		return ret;
2221e5835488SYasunari Takiguchi 
2222e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->read_regs(tnr_dmd->io,
2223e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
2224e5835488SYasunari Takiguchi 				     0x2b,
2225e5835488SYasunari Takiguchi 				     &data,
2226e5835488SYasunari Takiguchi 				     1);
2227e5835488SYasunari Takiguchi 	if (ret)
2228e5835488SYasunari Takiguchi 		return ret;
2229e5835488SYasunari Takiguchi 
2230e5835488SYasunari Takiguchi 	switch (sys) {
2231e5835488SYasunari Takiguchi 	case CXD2880_DTV_SYS_DVBT:
2232e5835488SYasunari Takiguchi 		if (data == 0x00) {
2233e5835488SYasunari Takiguchi 			ret = t_power_x(tnr_dmd, 1);
2234e5835488SYasunari Takiguchi 			if (ret)
2235e5835488SYasunari Takiguchi 				return ret;
2236e5835488SYasunari Takiguchi 
2237e5835488SYasunari Takiguchi 			if (tnr_dmd->diver_mode ==
2238e5835488SYasunari Takiguchi 			    CXD2880_TNRDMD_DIVERMODE_MAIN) {
2239e5835488SYasunari Takiguchi 				ret = t_power_x(tnr_dmd->diver_sub, 1);
2240e5835488SYasunari Takiguchi 				if (ret)
2241e5835488SYasunari Takiguchi 					return ret;
2242e5835488SYasunari Takiguchi 			}
2243e5835488SYasunari Takiguchi 		}
2244e5835488SYasunari Takiguchi 		break;
2245e5835488SYasunari Takiguchi 
2246e5835488SYasunari Takiguchi 	case CXD2880_DTV_SYS_DVBT2:
2247e5835488SYasunari Takiguchi 		if (data == 0x01) {
2248e5835488SYasunari Takiguchi 			ret = t_power_x(tnr_dmd, 0);
2249e5835488SYasunari Takiguchi 			if (ret)
2250e5835488SYasunari Takiguchi 				return ret;
2251e5835488SYasunari Takiguchi 
2252e5835488SYasunari Takiguchi 			if (tnr_dmd->diver_mode ==
2253e5835488SYasunari Takiguchi 			    CXD2880_TNRDMD_DIVERMODE_MAIN) {
2254e5835488SYasunari Takiguchi 				ret = t_power_x(tnr_dmd->diver_sub, 0);
2255e5835488SYasunari Takiguchi 				if (ret)
2256e5835488SYasunari Takiguchi 					return ret;
2257e5835488SYasunari Takiguchi 			}
2258e5835488SYasunari Takiguchi 		}
2259e5835488SYasunari Takiguchi 		break;
2260e5835488SYasunari Takiguchi 
2261e5835488SYasunari Takiguchi 	default:
2262e5835488SYasunari Takiguchi 		return -EINVAL;
2263e5835488SYasunari Takiguchi 	}
2264e5835488SYasunari Takiguchi 
2265e5835488SYasunari Takiguchi 	ret = spll_reset(tnr_dmd, new_clk_mode);
2266e5835488SYasunari Takiguchi 	if (ret)
2267e5835488SYasunari Takiguchi 		return ret;
2268e5835488SYasunari Takiguchi 
2269e5835488SYasunari Takiguchi 	tnr_dmd->clk_mode = new_clk_mode;
2270e5835488SYasunari Takiguchi 
2271e5835488SYasunari Takiguchi 	if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_MAIN) {
2272e5835488SYasunari Takiguchi 		ret = spll_reset(tnr_dmd->diver_sub, new_clk_mode);
2273e5835488SYasunari Takiguchi 		if (ret)
2274e5835488SYasunari Takiguchi 			return ret;
2275e5835488SYasunari Takiguchi 
2276e5835488SYasunari Takiguchi 		tnr_dmd->diver_sub->clk_mode = new_clk_mode;
2277e5835488SYasunari Takiguchi 	}
2278e5835488SYasunari Takiguchi 
2279e5835488SYasunari Takiguchi 	ret = load_cfg_mem(tnr_dmd);
2280e5835488SYasunari Takiguchi 	if (ret)
2281e5835488SYasunari Takiguchi 		return ret;
2282e5835488SYasunari Takiguchi 
2283e5835488SYasunari Takiguchi 	if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_MAIN) {
2284e5835488SYasunari Takiguchi 		ret = load_cfg_mem(tnr_dmd->diver_sub);
2285e5835488SYasunari Takiguchi 		if (ret)
2286e5835488SYasunari Takiguchi 			return ret;
2287e5835488SYasunari Takiguchi 	}
2288e5835488SYasunari Takiguchi 
2289e5835488SYasunari Takiguchi 	if (one_seg_opt) {
2290e5835488SYasunari Takiguchi 		if (tnr_dmd->diver_mode ==
2291e5835488SYasunari Takiguchi 		    CXD2880_TNRDMD_DIVERMODE_MAIN) {
2292e5835488SYasunari Takiguchi 			shift_frequency_khz = 350;
2293e5835488SYasunari Takiguchi 		} else {
2294e5835488SYasunari Takiguchi 			if (one_seg_opt_shft_dir)
2295e5835488SYasunari Takiguchi 				shift_frequency_khz = 350;
2296e5835488SYasunari Takiguchi 			else
2297e5835488SYasunari Takiguchi 				shift_frequency_khz = -350;
2298e5835488SYasunari Takiguchi 
2299e5835488SYasunari Takiguchi 			if (tnr_dmd->create_param.xtal_share_type ==
2300e5835488SYasunari Takiguchi 			    CXD2880_TNRDMD_XTAL_SHARE_SLAVE)
2301e5835488SYasunari Takiguchi 				shift_frequency_khz *= -1;
2302e5835488SYasunari Takiguchi 		}
2303e5835488SYasunari Takiguchi 	} else {
2304e5835488SYasunari Takiguchi 		if (tnr_dmd->diver_mode ==
2305e5835488SYasunari Takiguchi 		    CXD2880_TNRDMD_DIVERMODE_MAIN) {
2306e5835488SYasunari Takiguchi 			shift_frequency_khz = 150;
2307e5835488SYasunari Takiguchi 		} else {
2308e5835488SYasunari Takiguchi 			switch (tnr_dmd->create_param.xtal_share_type) {
2309e5835488SYasunari Takiguchi 			case CXD2880_TNRDMD_XTAL_SHARE_NONE:
2310e5835488SYasunari Takiguchi 			case CXD2880_TNRDMD_XTAL_SHARE_EXTREF:
2311e5835488SYasunari Takiguchi 			default:
2312e5835488SYasunari Takiguchi 				shift_frequency_khz = 0;
2313e5835488SYasunari Takiguchi 				break;
2314e5835488SYasunari Takiguchi 			case CXD2880_TNRDMD_XTAL_SHARE_MASTER:
2315e5835488SYasunari Takiguchi 				shift_frequency_khz = 150;
2316e5835488SYasunari Takiguchi 				break;
2317e5835488SYasunari Takiguchi 			case CXD2880_TNRDMD_XTAL_SHARE_SLAVE:
2318e5835488SYasunari Takiguchi 				shift_frequency_khz = -150;
2319e5835488SYasunari Takiguchi 				break;
2320e5835488SYasunari Takiguchi 			}
2321e5835488SYasunari Takiguchi 		}
2322e5835488SYasunari Takiguchi 	}
2323e5835488SYasunari Takiguchi 
2324e5835488SYasunari Takiguchi 	ret =
2325e5835488SYasunari Takiguchi 	    x_tune1(tnr_dmd, sys, frequency_khz, bandwidth,
2326e5835488SYasunari Takiguchi 		    tnr_dmd->is_cable_input, shift_frequency_khz);
2327e5835488SYasunari Takiguchi 	if (ret)
2328e5835488SYasunari Takiguchi 		return ret;
2329e5835488SYasunari Takiguchi 
2330e5835488SYasunari Takiguchi 	if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_MAIN) {
2331e5835488SYasunari Takiguchi 		ret =
2332e5835488SYasunari Takiguchi 		    x_tune1(tnr_dmd->diver_sub, sys, frequency_khz,
2333e5835488SYasunari Takiguchi 			    bandwidth, tnr_dmd->is_cable_input,
2334e5835488SYasunari Takiguchi 			    -shift_frequency_khz);
2335e5835488SYasunari Takiguchi 		if (ret)
2336e5835488SYasunari Takiguchi 			return ret;
2337e5835488SYasunari Takiguchi 	}
2338e5835488SYasunari Takiguchi 
2339e5835488SYasunari Takiguchi 	usleep_range(10000, 11000);
2340e5835488SYasunari Takiguchi 
2341e5835488SYasunari Takiguchi 	ret =
2342e5835488SYasunari Takiguchi 	    cxd2880_tnrdmd_check_internal_cpu_status(tnr_dmd,
2343e5835488SYasunari Takiguchi 					     &cpu_task_completed);
2344e5835488SYasunari Takiguchi 	if (ret)
2345e5835488SYasunari Takiguchi 		return ret;
2346e5835488SYasunari Takiguchi 
2347e5835488SYasunari Takiguchi 	if (!cpu_task_completed)
2348e5835488SYasunari Takiguchi 		return -EINVAL;
2349e5835488SYasunari Takiguchi 
2350e5835488SYasunari Takiguchi 	ret =
2351e5835488SYasunari Takiguchi 	    x_tune2(tnr_dmd, bandwidth, tnr_dmd->clk_mode,
2352e5835488SYasunari Takiguchi 		    shift_frequency_khz);
2353e5835488SYasunari Takiguchi 	if (ret)
2354e5835488SYasunari Takiguchi 		return ret;
2355e5835488SYasunari Takiguchi 
2356e5835488SYasunari Takiguchi 	if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_MAIN) {
2357e5835488SYasunari Takiguchi 		ret =
2358e5835488SYasunari Takiguchi 		    x_tune2(tnr_dmd->diver_sub, bandwidth,
2359e5835488SYasunari Takiguchi 			    tnr_dmd->diver_sub->clk_mode,
2360e5835488SYasunari Takiguchi 			    -shift_frequency_khz);
2361e5835488SYasunari Takiguchi 		if (ret)
2362e5835488SYasunari Takiguchi 			return ret;
2363e5835488SYasunari Takiguchi 	}
2364e5835488SYasunari Takiguchi 
2365e5835488SYasunari Takiguchi 	if (tnr_dmd->create_param.ts_output_if == CXD2880_TNRDMD_TSOUT_IF_TS) {
2366e5835488SYasunari Takiguchi 		ret = set_ts_clk_mode_and_freq(tnr_dmd, sys);
2367e5835488SYasunari Takiguchi 	} else {
2368e5835488SYasunari Takiguchi 		struct cxd2880_tnrdmd_pid_ftr_cfg *pid_ftr_cfg;
2369e5835488SYasunari Takiguchi 
2370e5835488SYasunari Takiguchi 		if (tnr_dmd->pid_ftr_cfg_en)
2371e5835488SYasunari Takiguchi 			pid_ftr_cfg = &tnr_dmd->pid_ftr_cfg;
2372e5835488SYasunari Takiguchi 		else
2373e5835488SYasunari Takiguchi 			pid_ftr_cfg = NULL;
2374e5835488SYasunari Takiguchi 
2375e5835488SYasunari Takiguchi 		ret = pid_ftr_setting(tnr_dmd, pid_ftr_cfg);
2376e5835488SYasunari Takiguchi 	}
2377e5835488SYasunari Takiguchi 
2378e5835488SYasunari Takiguchi 	return ret;
2379e5835488SYasunari Takiguchi }
2380e5835488SYasunari Takiguchi 
cxd2880_tnrdmd_common_tune_setting2(struct cxd2880_tnrdmd * tnr_dmd,enum cxd2880_dtv_sys sys,u8 en_fef_intmtnt_ctrl)2381e5835488SYasunari Takiguchi int cxd2880_tnrdmd_common_tune_setting2(struct cxd2880_tnrdmd
2382e5835488SYasunari Takiguchi 					*tnr_dmd,
2383e5835488SYasunari Takiguchi 					enum cxd2880_dtv_sys sys,
2384e5835488SYasunari Takiguchi 					u8 en_fef_intmtnt_ctrl)
2385e5835488SYasunari Takiguchi {
2386e5835488SYasunari Takiguchi 	int ret;
2387e5835488SYasunari Takiguchi 
2388e5835488SYasunari Takiguchi 	if (!tnr_dmd)
2389e5835488SYasunari Takiguchi 		return -EINVAL;
2390e5835488SYasunari Takiguchi 
2391e5835488SYasunari Takiguchi 	if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_SUB)
2392e5835488SYasunari Takiguchi 		return -EINVAL;
2393e5835488SYasunari Takiguchi 
2394e5835488SYasunari Takiguchi 	if (tnr_dmd->state != CXD2880_TNRDMD_STATE_SLEEP &&
2395e5835488SYasunari Takiguchi 	    tnr_dmd->state != CXD2880_TNRDMD_STATE_ACTIVE)
2396e5835488SYasunari Takiguchi 		return -EINVAL;
2397e5835488SYasunari Takiguchi 
2398e5835488SYasunari Takiguchi 	ret = x_tune3(tnr_dmd, sys, en_fef_intmtnt_ctrl);
2399e5835488SYasunari Takiguchi 	if (ret)
2400e5835488SYasunari Takiguchi 		return ret;
2401e5835488SYasunari Takiguchi 
2402e5835488SYasunari Takiguchi 	if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_MAIN) {
2403e5835488SYasunari Takiguchi 		ret = x_tune3(tnr_dmd->diver_sub, sys, en_fef_intmtnt_ctrl);
2404e5835488SYasunari Takiguchi 		if (ret)
2405e5835488SYasunari Takiguchi 			return ret;
2406e5835488SYasunari Takiguchi 		ret = x_tune4(tnr_dmd);
2407e5835488SYasunari Takiguchi 		if (ret)
2408e5835488SYasunari Takiguchi 			return ret;
2409e5835488SYasunari Takiguchi 	}
2410e5835488SYasunari Takiguchi 
2411e5835488SYasunari Takiguchi 	return cxd2880_tnrdmd_set_ts_output(tnr_dmd, 1);
2412e5835488SYasunari Takiguchi }
2413e5835488SYasunari Takiguchi 
cxd2880_tnrdmd_sleep(struct cxd2880_tnrdmd * tnr_dmd)2414e5835488SYasunari Takiguchi int cxd2880_tnrdmd_sleep(struct cxd2880_tnrdmd *tnr_dmd)
2415e5835488SYasunari Takiguchi {
2416e5835488SYasunari Takiguchi 	int ret;
2417e5835488SYasunari Takiguchi 
2418e5835488SYasunari Takiguchi 	if (!tnr_dmd)
2419e5835488SYasunari Takiguchi 		return -EINVAL;
2420e5835488SYasunari Takiguchi 
2421e5835488SYasunari Takiguchi 	if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_SUB)
2422e5835488SYasunari Takiguchi 		return -EINVAL;
2423e5835488SYasunari Takiguchi 
2424e5835488SYasunari Takiguchi 	if (tnr_dmd->state == CXD2880_TNRDMD_STATE_SLEEP)
2425e5835488SYasunari Takiguchi 		return 0;
2426e5835488SYasunari Takiguchi 
2427e5835488SYasunari Takiguchi 	if (tnr_dmd->state != CXD2880_TNRDMD_STATE_ACTIVE)
2428e5835488SYasunari Takiguchi 		return -EINVAL;
2429e5835488SYasunari Takiguchi 
2430e5835488SYasunari Takiguchi 	ret = cxd2880_tnrdmd_set_ts_output(tnr_dmd, 0);
2431e5835488SYasunari Takiguchi 	if (ret)
2432e5835488SYasunari Takiguchi 		return ret;
2433e5835488SYasunari Takiguchi 
2434e5835488SYasunari Takiguchi 	if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_MAIN) {
2435e5835488SYasunari Takiguchi 		ret = x_sleep1(tnr_dmd);
2436e5835488SYasunari Takiguchi 		if (ret)
2437e5835488SYasunari Takiguchi 			return ret;
2438e5835488SYasunari Takiguchi 	}
2439e5835488SYasunari Takiguchi 
2440e5835488SYasunari Takiguchi 	ret = x_sleep2(tnr_dmd);
2441e5835488SYasunari Takiguchi 	if (ret)
2442e5835488SYasunari Takiguchi 		return ret;
2443e5835488SYasunari Takiguchi 
2444e5835488SYasunari Takiguchi 	if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_MAIN) {
2445e5835488SYasunari Takiguchi 		ret = x_sleep2(tnr_dmd->diver_sub);
2446e5835488SYasunari Takiguchi 		if (ret)
2447e5835488SYasunari Takiguchi 			return ret;
2448e5835488SYasunari Takiguchi 	}
2449e5835488SYasunari Takiguchi 
2450e5835488SYasunari Takiguchi 	switch (tnr_dmd->sys) {
2451e5835488SYasunari Takiguchi 	case CXD2880_DTV_SYS_DVBT:
2452e5835488SYasunari Takiguchi 		ret = cxd2880_tnrdmd_dvbt_sleep_setting(tnr_dmd);
2453e5835488SYasunari Takiguchi 		if (ret)
2454e5835488SYasunari Takiguchi 			return ret;
2455e5835488SYasunari Takiguchi 		break;
2456e5835488SYasunari Takiguchi 
2457e5835488SYasunari Takiguchi 	case CXD2880_DTV_SYS_DVBT2:
2458e5835488SYasunari Takiguchi 		ret = cxd2880_tnrdmd_dvbt2_sleep_setting(tnr_dmd);
2459e5835488SYasunari Takiguchi 		if (ret)
2460e5835488SYasunari Takiguchi 			return ret;
2461e5835488SYasunari Takiguchi 		break;
2462e5835488SYasunari Takiguchi 
2463e5835488SYasunari Takiguchi 	default:
2464e5835488SYasunari Takiguchi 		return -EINVAL;
2465e5835488SYasunari Takiguchi 	}
2466e5835488SYasunari Takiguchi 
2467e5835488SYasunari Takiguchi 	ret = x_sleep3(tnr_dmd);
2468e5835488SYasunari Takiguchi 	if (ret)
2469e5835488SYasunari Takiguchi 		return ret;
2470e5835488SYasunari Takiguchi 
2471e5835488SYasunari Takiguchi 	if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_MAIN) {
2472e5835488SYasunari Takiguchi 		ret = x_sleep3(tnr_dmd->diver_sub);
2473e5835488SYasunari Takiguchi 		if (ret)
2474e5835488SYasunari Takiguchi 			return ret;
2475e5835488SYasunari Takiguchi 	}
2476e5835488SYasunari Takiguchi 
2477e5835488SYasunari Takiguchi 	ret = x_sleep4(tnr_dmd);
2478e5835488SYasunari Takiguchi 	if (ret)
2479e5835488SYasunari Takiguchi 		return ret;
2480e5835488SYasunari Takiguchi 
2481e5835488SYasunari Takiguchi 	if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_MAIN) {
2482e5835488SYasunari Takiguchi 		ret = x_sleep4(tnr_dmd->diver_sub);
2483e5835488SYasunari Takiguchi 		if (ret)
2484e5835488SYasunari Takiguchi 			return ret;
2485e5835488SYasunari Takiguchi 	}
2486e5835488SYasunari Takiguchi 
2487e5835488SYasunari Takiguchi 	tnr_dmd->state = CXD2880_TNRDMD_STATE_SLEEP;
2488e5835488SYasunari Takiguchi 	tnr_dmd->frequency_khz = 0;
2489e5835488SYasunari Takiguchi 	tnr_dmd->sys = CXD2880_DTV_SYS_UNKNOWN;
2490e5835488SYasunari Takiguchi 	tnr_dmd->bandwidth = CXD2880_DTV_BW_UNKNOWN;
2491e5835488SYasunari Takiguchi 
2492e5835488SYasunari Takiguchi 	if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_MAIN) {
2493e5835488SYasunari Takiguchi 		tnr_dmd->diver_sub->state = CXD2880_TNRDMD_STATE_SLEEP;
2494e5835488SYasunari Takiguchi 		tnr_dmd->diver_sub->frequency_khz = 0;
2495e5835488SYasunari Takiguchi 		tnr_dmd->diver_sub->sys = CXD2880_DTV_SYS_UNKNOWN;
2496e5835488SYasunari Takiguchi 		tnr_dmd->diver_sub->bandwidth = CXD2880_DTV_BW_UNKNOWN;
2497e5835488SYasunari Takiguchi 	}
2498e5835488SYasunari Takiguchi 
2499e5835488SYasunari Takiguchi 	return 0;
2500e5835488SYasunari Takiguchi }
2501e5835488SYasunari Takiguchi 
cxd2880_tnrdmd_set_cfg(struct cxd2880_tnrdmd * tnr_dmd,enum cxd2880_tnrdmd_cfg_id id,int value)2502e5835488SYasunari Takiguchi int cxd2880_tnrdmd_set_cfg(struct cxd2880_tnrdmd *tnr_dmd,
2503e5835488SYasunari Takiguchi 			   enum cxd2880_tnrdmd_cfg_id id,
2504e5835488SYasunari Takiguchi 			   int value)
2505e5835488SYasunari Takiguchi {
25069ca4897bSMauro Carvalho Chehab 	int ret = 0;
2507e5835488SYasunari Takiguchi 	u8 data[2] = { 0 };
2508e5835488SYasunari Takiguchi 	u8 need_sub_setting = 0;
2509e5835488SYasunari Takiguchi 
2510e5835488SYasunari Takiguchi 	if (!tnr_dmd)
2511e5835488SYasunari Takiguchi 		return -EINVAL;
2512e5835488SYasunari Takiguchi 
2513e5835488SYasunari Takiguchi 	if (tnr_dmd->state != CXD2880_TNRDMD_STATE_SLEEP &&
2514e5835488SYasunari Takiguchi 	    tnr_dmd->state != CXD2880_TNRDMD_STATE_ACTIVE)
2515e5835488SYasunari Takiguchi 		return -EINVAL;
2516e5835488SYasunari Takiguchi 
2517e5835488SYasunari Takiguchi 	switch (id) {
2518e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_CFG_OUTPUT_SEL_MSB:
2519e5835488SYasunari Takiguchi 		if (tnr_dmd->state != CXD2880_TNRDMD_STATE_SLEEP)
2520e5835488SYasunari Takiguchi 			return -EINVAL;
2521e5835488SYasunari Takiguchi 
2522e5835488SYasunari Takiguchi 		ret =
2523e5835488SYasunari Takiguchi 		    cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd,
2524e5835488SYasunari Takiguchi 							 CXD2880_IO_TGT_DMD,
2525e5835488SYasunari Takiguchi 							 0x00, 0xc4,
2526e5835488SYasunari Takiguchi 							 value ? 0x00 : 0x10,
2527e5835488SYasunari Takiguchi 							 0x10);
2528e5835488SYasunari Takiguchi 		if (ret)
2529e5835488SYasunari Takiguchi 			return ret;
2530e5835488SYasunari Takiguchi 		break;
2531e5835488SYasunari Takiguchi 
2532e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_CFG_TSVALID_ACTIVE_HI:
2533e5835488SYasunari Takiguchi 		if (tnr_dmd->state != CXD2880_TNRDMD_STATE_SLEEP)
2534e5835488SYasunari Takiguchi 			return -EINVAL;
2535e5835488SYasunari Takiguchi 
2536e5835488SYasunari Takiguchi 		ret =
2537e5835488SYasunari Takiguchi 		    cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd,
2538e5835488SYasunari Takiguchi 							 CXD2880_IO_TGT_DMD,
2539e5835488SYasunari Takiguchi 							 0x00, 0xc5,
2540e5835488SYasunari Takiguchi 							 value ? 0x00 : 0x02,
2541e5835488SYasunari Takiguchi 							 0x02);
2542e5835488SYasunari Takiguchi 		if (ret)
2543e5835488SYasunari Takiguchi 			return ret;
2544e5835488SYasunari Takiguchi 		break;
2545e5835488SYasunari Takiguchi 
2546e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_CFG_TSSYNC_ACTIVE_HI:
2547e5835488SYasunari Takiguchi 		if (tnr_dmd->state != CXD2880_TNRDMD_STATE_SLEEP)
2548e5835488SYasunari Takiguchi 			return -EINVAL;
2549e5835488SYasunari Takiguchi 
2550e5835488SYasunari Takiguchi 		ret =
2551e5835488SYasunari Takiguchi 		    cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd,
2552e5835488SYasunari Takiguchi 							 CXD2880_IO_TGT_DMD,
2553e5835488SYasunari Takiguchi 							 0x00, 0xc5,
2554e5835488SYasunari Takiguchi 							 value ? 0x00 : 0x04,
2555e5835488SYasunari Takiguchi 							 0x04);
2556e5835488SYasunari Takiguchi 		if (ret)
2557e5835488SYasunari Takiguchi 			return ret;
2558e5835488SYasunari Takiguchi 		break;
2559e5835488SYasunari Takiguchi 
2560e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_CFG_TSERR_ACTIVE_HI:
2561e5835488SYasunari Takiguchi 		if (tnr_dmd->state != CXD2880_TNRDMD_STATE_SLEEP)
2562e5835488SYasunari Takiguchi 			return -EINVAL;
2563e5835488SYasunari Takiguchi 
2564e5835488SYasunari Takiguchi 		ret =
2565e5835488SYasunari Takiguchi 		    cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd,
2566e5835488SYasunari Takiguchi 							 CXD2880_IO_TGT_DMD,
2567e5835488SYasunari Takiguchi 							 0x00, 0xcb,
2568e5835488SYasunari Takiguchi 							 value ? 0x00 : 0x01,
2569e5835488SYasunari Takiguchi 							 0x01);
2570e5835488SYasunari Takiguchi 		if (ret)
2571e5835488SYasunari Takiguchi 			return ret;
2572e5835488SYasunari Takiguchi 		break;
2573e5835488SYasunari Takiguchi 
2574e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_CFG_LATCH_ON_POSEDGE:
2575e5835488SYasunari Takiguchi 		if (tnr_dmd->state != CXD2880_TNRDMD_STATE_SLEEP)
2576e5835488SYasunari Takiguchi 			return -EINVAL;
2577e5835488SYasunari Takiguchi 
2578e5835488SYasunari Takiguchi 		ret =
2579e5835488SYasunari Takiguchi 		    cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd,
2580e5835488SYasunari Takiguchi 							 CXD2880_IO_TGT_DMD,
2581e5835488SYasunari Takiguchi 							 0x00, 0xc5,
2582e5835488SYasunari Takiguchi 							 value ? 0x01 : 0x00,
2583e5835488SYasunari Takiguchi 							 0x01);
2584e5835488SYasunari Takiguchi 		if (ret)
2585e5835488SYasunari Takiguchi 			return ret;
2586e5835488SYasunari Takiguchi 		break;
2587e5835488SYasunari Takiguchi 
2588e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_CFG_TSCLK_CONT:
2589e5835488SYasunari Takiguchi 		if (tnr_dmd->state != CXD2880_TNRDMD_STATE_SLEEP)
2590e5835488SYasunari Takiguchi 			return -EINVAL;
2591e5835488SYasunari Takiguchi 
2592e5835488SYasunari Takiguchi 		tnr_dmd->srl_ts_clk_mod_cnts = value ? 0x01 : 0x00;
2593e5835488SYasunari Takiguchi 		break;
2594e5835488SYasunari Takiguchi 
2595e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_CFG_TSCLK_MASK:
2596e5835488SYasunari Takiguchi 		if (tnr_dmd->state != CXD2880_TNRDMD_STATE_SLEEP)
2597e5835488SYasunari Takiguchi 			return -EINVAL;
2598e5835488SYasunari Takiguchi 
2599e5835488SYasunari Takiguchi 		if (value < 0 || value > 0x1f)
2600e5835488SYasunari Takiguchi 			return -EINVAL;
2601e5835488SYasunari Takiguchi 
2602e5835488SYasunari Takiguchi 		ret =
2603e5835488SYasunari Takiguchi 		    cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd,
2604e5835488SYasunari Takiguchi 							 CXD2880_IO_TGT_DMD,
2605e5835488SYasunari Takiguchi 							 0x00, 0xc6, value,
2606e5835488SYasunari Takiguchi 							 0x1f);
2607e5835488SYasunari Takiguchi 		if (ret)
2608e5835488SYasunari Takiguchi 			return ret;
2609e5835488SYasunari Takiguchi 		break;
2610e5835488SYasunari Takiguchi 
2611e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_CFG_TSVALID_MASK:
2612e5835488SYasunari Takiguchi 		if (tnr_dmd->state != CXD2880_TNRDMD_STATE_SLEEP)
2613e5835488SYasunari Takiguchi 			return -EINVAL;
2614e5835488SYasunari Takiguchi 
2615e5835488SYasunari Takiguchi 		if (value < 0 || value > 0x1f)
2616e5835488SYasunari Takiguchi 			return -EINVAL;
2617e5835488SYasunari Takiguchi 
2618e5835488SYasunari Takiguchi 		ret =
2619e5835488SYasunari Takiguchi 		    cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd,
2620e5835488SYasunari Takiguchi 							 CXD2880_IO_TGT_DMD,
2621e5835488SYasunari Takiguchi 							 0x00, 0xc8, value,
2622e5835488SYasunari Takiguchi 							 0x1f);
2623e5835488SYasunari Takiguchi 		if (ret)
2624e5835488SYasunari Takiguchi 			return ret;
2625e5835488SYasunari Takiguchi 		break;
2626e5835488SYasunari Takiguchi 
2627e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_CFG_TSERR_MASK:
2628e5835488SYasunari Takiguchi 		if (tnr_dmd->state != CXD2880_TNRDMD_STATE_SLEEP)
2629e5835488SYasunari Takiguchi 			return -EINVAL;
2630e5835488SYasunari Takiguchi 
2631e5835488SYasunari Takiguchi 		if (value < 0 || value > 0x1f)
2632e5835488SYasunari Takiguchi 			return -EINVAL;
2633e5835488SYasunari Takiguchi 
2634e5835488SYasunari Takiguchi 		ret =
2635e5835488SYasunari Takiguchi 		    cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd,
2636e5835488SYasunari Takiguchi 							 CXD2880_IO_TGT_DMD,
2637e5835488SYasunari Takiguchi 							 0x00, 0xc9, value,
2638e5835488SYasunari Takiguchi 							 0x1f);
2639e5835488SYasunari Takiguchi 		if (ret)
2640e5835488SYasunari Takiguchi 			return ret;
2641e5835488SYasunari Takiguchi 		break;
2642e5835488SYasunari Takiguchi 
2643e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_CFG_TSERR_VALID_DIS:
2644e5835488SYasunari Takiguchi 		if (tnr_dmd->state != CXD2880_TNRDMD_STATE_SLEEP)
2645e5835488SYasunari Takiguchi 			return -EINVAL;
2646e5835488SYasunari Takiguchi 
2647e5835488SYasunari Takiguchi 		ret =
2648e5835488SYasunari Takiguchi 		    cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd,
2649e5835488SYasunari Takiguchi 							 CXD2880_IO_TGT_DMD,
2650e5835488SYasunari Takiguchi 							 0x00, 0x91,
2651e5835488SYasunari Takiguchi 							 value ? 0x01 : 0x00,
2652e5835488SYasunari Takiguchi 							 0x01);
2653e5835488SYasunari Takiguchi 		if (ret)
2654e5835488SYasunari Takiguchi 			return ret;
2655e5835488SYasunari Takiguchi 		break;
2656e5835488SYasunari Takiguchi 
2657e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_CFG_TSPIN_CURRENT:
2658e5835488SYasunari Takiguchi 		if (tnr_dmd->state != CXD2880_TNRDMD_STATE_SLEEP)
2659e5835488SYasunari Takiguchi 			return -EINVAL;
2660e5835488SYasunari Takiguchi 
2661e5835488SYasunari Takiguchi 		ret =
2662e5835488SYasunari Takiguchi 		    cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd,
2663e5835488SYasunari Takiguchi 							 CXD2880_IO_TGT_SYS,
2664e5835488SYasunari Takiguchi 							 0x00, 0x51, value,
2665e5835488SYasunari Takiguchi 							 0x3f);
2666e5835488SYasunari Takiguchi 		if (ret)
2667e5835488SYasunari Takiguchi 			return ret;
2668e5835488SYasunari Takiguchi 		break;
2669e5835488SYasunari Takiguchi 
2670e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_CFG_TSPIN_PULLUP_MANUAL:
2671e5835488SYasunari Takiguchi 		if (tnr_dmd->state != CXD2880_TNRDMD_STATE_SLEEP)
2672e5835488SYasunari Takiguchi 			return -EINVAL;
2673e5835488SYasunari Takiguchi 
2674e5835488SYasunari Takiguchi 		ret =
2675e5835488SYasunari Takiguchi 		    cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd,
2676e5835488SYasunari Takiguchi 							 CXD2880_IO_TGT_SYS,
2677e5835488SYasunari Takiguchi 							 0x00, 0x50,
2678e5835488SYasunari Takiguchi 							 value ? 0x80 : 0x00,
2679e5835488SYasunari Takiguchi 							 0x80);
2680e5835488SYasunari Takiguchi 		if (ret)
2681e5835488SYasunari Takiguchi 			return ret;
2682e5835488SYasunari Takiguchi 		break;
2683e5835488SYasunari Takiguchi 
2684e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_CFG_TSPIN_PULLUP:
2685e5835488SYasunari Takiguchi 		if (tnr_dmd->state != CXD2880_TNRDMD_STATE_SLEEP)
2686e5835488SYasunari Takiguchi 			return -EINVAL;
2687e5835488SYasunari Takiguchi 
2688e5835488SYasunari Takiguchi 		ret =
2689e5835488SYasunari Takiguchi 		    cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd,
2690e5835488SYasunari Takiguchi 							 CXD2880_IO_TGT_SYS,
2691e5835488SYasunari Takiguchi 							 0x00, 0x50, value,
2692e5835488SYasunari Takiguchi 							 0x3f);
2693e5835488SYasunari Takiguchi 		if (ret)
2694e5835488SYasunari Takiguchi 			return ret;
2695e5835488SYasunari Takiguchi 		break;
2696e5835488SYasunari Takiguchi 
2697e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_CFG_TSCLK_FREQ:
2698e5835488SYasunari Takiguchi 		if (tnr_dmd->state != CXD2880_TNRDMD_STATE_SLEEP)
2699e5835488SYasunari Takiguchi 			return -EINVAL;
2700e5835488SYasunari Takiguchi 
2701e5835488SYasunari Takiguchi 		if (value < 0 || value > 1)
2702e5835488SYasunari Takiguchi 			return -EINVAL;
2703e5835488SYasunari Takiguchi 
2704e5835488SYasunari Takiguchi 		tnr_dmd->srl_ts_clk_frq =
2705e5835488SYasunari Takiguchi 		    (enum cxd2880_tnrdmd_serial_ts_clk)value;
2706e5835488SYasunari Takiguchi 		break;
2707e5835488SYasunari Takiguchi 
2708e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_CFG_TSBYTECLK_MANUAL:
2709e5835488SYasunari Takiguchi 		if (tnr_dmd->state != CXD2880_TNRDMD_STATE_SLEEP)
2710e5835488SYasunari Takiguchi 			return -EINVAL;
2711e5835488SYasunari Takiguchi 
2712e5835488SYasunari Takiguchi 		if (value < 0 || value > 0xff)
2713e5835488SYasunari Takiguchi 			return -EINVAL;
2714e5835488SYasunari Takiguchi 
2715e5835488SYasunari Takiguchi 		tnr_dmd->ts_byte_clk_manual_setting = value;
2716e5835488SYasunari Takiguchi 
2717e5835488SYasunari Takiguchi 		break;
2718e5835488SYasunari Takiguchi 
2719e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_CFG_TS_PACKET_GAP:
2720e5835488SYasunari Takiguchi 		if (tnr_dmd->state != CXD2880_TNRDMD_STATE_SLEEP)
2721e5835488SYasunari Takiguchi 			return -EINVAL;
2722e5835488SYasunari Takiguchi 
2723e5835488SYasunari Takiguchi 		if (value < 0 || value > 7)
2724e5835488SYasunari Takiguchi 			return -EINVAL;
2725e5835488SYasunari Takiguchi 
2726e5835488SYasunari Takiguchi 		ret =
2727e5835488SYasunari Takiguchi 		    cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd,
2728e5835488SYasunari Takiguchi 							 CXD2880_IO_TGT_DMD,
2729e5835488SYasunari Takiguchi 							 0x00, 0xd6, value,
2730e5835488SYasunari Takiguchi 							 0x07);
2731e5835488SYasunari Takiguchi 		if (ret)
2732e5835488SYasunari Takiguchi 			return ret;
2733e5835488SYasunari Takiguchi 
2734e5835488SYasunari Takiguchi 		break;
2735e5835488SYasunari Takiguchi 
2736e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_CFG_TS_BACKWARDS_COMPATIBLE:
2737e5835488SYasunari Takiguchi 		if (tnr_dmd->state != CXD2880_TNRDMD_STATE_SLEEP)
2738e5835488SYasunari Takiguchi 			return -EINVAL;
2739e5835488SYasunari Takiguchi 
2740e5835488SYasunari Takiguchi 		tnr_dmd->is_ts_backwards_compatible_mode = value ? 1 : 0;
2741e5835488SYasunari Takiguchi 
2742e5835488SYasunari Takiguchi 		break;
2743e5835488SYasunari Takiguchi 
2744e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_CFG_PWM_VALUE:
2745e5835488SYasunari Takiguchi 		if (value < 0 || value > 0x1000)
2746e5835488SYasunari Takiguchi 			return -EINVAL;
2747e5835488SYasunari Takiguchi 
2748e5835488SYasunari Takiguchi 		ret =
2749e5835488SYasunari Takiguchi 		    cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd,
2750e5835488SYasunari Takiguchi 							 CXD2880_IO_TGT_DMD,
2751e5835488SYasunari Takiguchi 							 0x00, 0x22,
2752e5835488SYasunari Takiguchi 							 value ? 0x01 : 0x00,
2753e5835488SYasunari Takiguchi 							 0x01);
2754e5835488SYasunari Takiguchi 		if (ret)
2755e5835488SYasunari Takiguchi 			return ret;
2756e5835488SYasunari Takiguchi 
2757e5835488SYasunari Takiguchi 		data[0] = (value >> 8) & 0x1f;
2758e5835488SYasunari Takiguchi 		data[1] = value & 0xff;
2759e5835488SYasunari Takiguchi 
2760e5835488SYasunari Takiguchi 		ret =
2761e5835488SYasunari Takiguchi 		    cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd,
2762e5835488SYasunari Takiguchi 							 CXD2880_IO_TGT_DMD,
2763e5835488SYasunari Takiguchi 							 0x00, 0x23,
2764e5835488SYasunari Takiguchi 							 data[0], 0x1f);
2765e5835488SYasunari Takiguchi 		if (ret)
2766e5835488SYasunari Takiguchi 			return ret;
2767e5835488SYasunari Takiguchi 
2768e5835488SYasunari Takiguchi 		ret =
2769e5835488SYasunari Takiguchi 		    cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd,
2770e5835488SYasunari Takiguchi 							 CXD2880_IO_TGT_DMD,
2771e5835488SYasunari Takiguchi 							 0x00, 0x24,
2772e5835488SYasunari Takiguchi 							 data[1], 0xff);
2773e5835488SYasunari Takiguchi 		if (ret)
2774e5835488SYasunari Takiguchi 			return ret;
2775e5835488SYasunari Takiguchi 
2776e5835488SYasunari Takiguchi 		break;
2777e5835488SYasunari Takiguchi 
2778e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_CFG_INTERRUPT:
2779e5835488SYasunari Takiguchi 		data[0] = (value >> 8) & 0xff;
2780e5835488SYasunari Takiguchi 		data[1] = value & 0xff;
2781e5835488SYasunari Takiguchi 		ret =
2782e5835488SYasunari Takiguchi 		    cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd,
2783e5835488SYasunari Takiguchi 							 CXD2880_IO_TGT_SYS,
2784e5835488SYasunari Takiguchi 							 0x00, 0x48, data[0],
2785e5835488SYasunari Takiguchi 							 0xff);
2786e5835488SYasunari Takiguchi 		if (ret)
2787e5835488SYasunari Takiguchi 			return ret;
2788e5835488SYasunari Takiguchi 		ret =
2789e5835488SYasunari Takiguchi 		    cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd,
2790e5835488SYasunari Takiguchi 							 CXD2880_IO_TGT_SYS,
2791e5835488SYasunari Takiguchi 							 0x00, 0x49, data[1],
2792e5835488SYasunari Takiguchi 							 0xff);
2793e5835488SYasunari Takiguchi 		if (ret)
2794e5835488SYasunari Takiguchi 			return ret;
2795e5835488SYasunari Takiguchi 		break;
2796e5835488SYasunari Takiguchi 
2797e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_CFG_INTERRUPT_LOCK_SEL:
2798e5835488SYasunari Takiguchi 		data[0] = value & 0x07;
2799e5835488SYasunari Takiguchi 		ret =
2800e5835488SYasunari Takiguchi 		    cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd,
2801e5835488SYasunari Takiguchi 							 CXD2880_IO_TGT_SYS,
2802e5835488SYasunari Takiguchi 							 0x00, 0x4a, data[0],
2803e5835488SYasunari Takiguchi 							 0x07);
2804e5835488SYasunari Takiguchi 		if (ret)
2805e5835488SYasunari Takiguchi 			return ret;
2806e5835488SYasunari Takiguchi 		break;
2807e5835488SYasunari Takiguchi 
2808e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_CFG_INTERRUPT_INV_LOCK_SEL:
2809e5835488SYasunari Takiguchi 		data[0] = (value & 0x07) << 3;
2810e5835488SYasunari Takiguchi 		ret =
2811e5835488SYasunari Takiguchi 		    cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd,
2812e5835488SYasunari Takiguchi 							 CXD2880_IO_TGT_SYS,
2813e5835488SYasunari Takiguchi 							 0x00, 0x4a, data[0],
2814e5835488SYasunari Takiguchi 							 0x38);
2815e5835488SYasunari Takiguchi 		if (ret)
2816e5835488SYasunari Takiguchi 			return ret;
2817e5835488SYasunari Takiguchi 		break;
2818e5835488SYasunari Takiguchi 
2819e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_CFG_FIXED_CLOCKMODE:
2820e5835488SYasunari Takiguchi 		if (value < CXD2880_TNRDMD_CLOCKMODE_UNKNOWN ||
2821e5835488SYasunari Takiguchi 		    value > CXD2880_TNRDMD_CLOCKMODE_C)
2822e5835488SYasunari Takiguchi 			return -EINVAL;
2823e5835488SYasunari Takiguchi 		tnr_dmd->fixed_clk_mode = (enum cxd2880_tnrdmd_clockmode)value;
2824e5835488SYasunari Takiguchi 		break;
2825e5835488SYasunari Takiguchi 
2826e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_CFG_CABLE_INPUT:
2827e5835488SYasunari Takiguchi 		tnr_dmd->is_cable_input = value ? 1 : 0;
2828e5835488SYasunari Takiguchi 		break;
2829e5835488SYasunari Takiguchi 
2830e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_CFG_DVBT2_FEF_INTERMITTENT_BASE:
2831e5835488SYasunari Takiguchi 		tnr_dmd->en_fef_intmtnt_base = value ? 1 : 0;
2832e5835488SYasunari Takiguchi 		break;
2833e5835488SYasunari Takiguchi 
2834e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_CFG_DVBT2_FEF_INTERMITTENT_LITE:
2835e5835488SYasunari Takiguchi 		tnr_dmd->en_fef_intmtnt_lite = value ? 1 : 0;
2836e5835488SYasunari Takiguchi 		break;
2837e5835488SYasunari Takiguchi 
2838e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_CFG_TS_BUF_ALMOST_EMPTY_THRS:
2839e5835488SYasunari Takiguchi 		data[0] = (value >> 8) & 0x07;
2840e5835488SYasunari Takiguchi 		data[1] = value & 0xff;
2841e5835488SYasunari Takiguchi 		ret =
2842e5835488SYasunari Takiguchi 		    cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd,
2843e5835488SYasunari Takiguchi 							 CXD2880_IO_TGT_DMD,
2844e5835488SYasunari Takiguchi 							 0x00, 0x99, data[0],
2845e5835488SYasunari Takiguchi 							 0x07);
2846e5835488SYasunari Takiguchi 		if (ret)
2847e5835488SYasunari Takiguchi 			return ret;
2848e5835488SYasunari Takiguchi 		ret =
2849e5835488SYasunari Takiguchi 		    cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd,
2850e5835488SYasunari Takiguchi 							 CXD2880_IO_TGT_DMD,
2851e5835488SYasunari Takiguchi 							 0x00, 0x9a, data[1],
2852e5835488SYasunari Takiguchi 							 0xff);
2853e5835488SYasunari Takiguchi 		if (ret)
2854e5835488SYasunari Takiguchi 			return ret;
2855e5835488SYasunari Takiguchi 		break;
2856e5835488SYasunari Takiguchi 
2857e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_CFG_TS_BUF_ALMOST_FULL_THRS:
2858e5835488SYasunari Takiguchi 		data[0] = (value >> 8) & 0x07;
2859e5835488SYasunari Takiguchi 		data[1] = value & 0xff;
2860e5835488SYasunari Takiguchi 		ret =
2861e5835488SYasunari Takiguchi 		    cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd,
2862e5835488SYasunari Takiguchi 							 CXD2880_IO_TGT_DMD,
2863e5835488SYasunari Takiguchi 							 0x00, 0x9b, data[0],
2864e5835488SYasunari Takiguchi 							 0x07);
2865e5835488SYasunari Takiguchi 		if (ret)
2866e5835488SYasunari Takiguchi 			return ret;
2867e5835488SYasunari Takiguchi 		ret =
2868e5835488SYasunari Takiguchi 		    cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd,
2869e5835488SYasunari Takiguchi 							 CXD2880_IO_TGT_DMD,
2870e5835488SYasunari Takiguchi 							 0x00, 0x9c, data[1],
2871e5835488SYasunari Takiguchi 							 0xff);
2872e5835488SYasunari Takiguchi 		if (ret)
2873e5835488SYasunari Takiguchi 			return ret;
2874e5835488SYasunari Takiguchi 		break;
2875e5835488SYasunari Takiguchi 
2876e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_CFG_TS_BUF_RRDY_THRS:
2877e5835488SYasunari Takiguchi 		data[0] = (value >> 8) & 0x07;
2878e5835488SYasunari Takiguchi 		data[1] = value & 0xff;
2879e5835488SYasunari Takiguchi 		ret =
2880e5835488SYasunari Takiguchi 		    cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd,
2881e5835488SYasunari Takiguchi 							 CXD2880_IO_TGT_DMD,
2882e5835488SYasunari Takiguchi 							 0x00, 0x9d, data[0],
2883e5835488SYasunari Takiguchi 							 0x07);
2884e5835488SYasunari Takiguchi 		if (ret)
2885e5835488SYasunari Takiguchi 			return ret;
2886e5835488SYasunari Takiguchi 		ret =
2887e5835488SYasunari Takiguchi 		    cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd,
2888e5835488SYasunari Takiguchi 							 CXD2880_IO_TGT_DMD,
2889e5835488SYasunari Takiguchi 							 0x00, 0x9e, data[1],
2890e5835488SYasunari Takiguchi 							 0xff);
2891e5835488SYasunari Takiguchi 		if (ret)
2892e5835488SYasunari Takiguchi 			return ret;
2893e5835488SYasunari Takiguchi 		break;
2894e5835488SYasunari Takiguchi 
2895e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_CFG_BLINDTUNE_DVBT2_FIRST:
2896e5835488SYasunari Takiguchi 		tnr_dmd->blind_tune_dvbt2_first = value ? 1 : 0;
2897e5835488SYasunari Takiguchi 		break;
2898e5835488SYasunari Takiguchi 
2899e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_CFG_DVBT_BERN_PERIOD:
2900e5835488SYasunari Takiguchi 		if (value < 0 || value > 31)
2901e5835488SYasunari Takiguchi 			return -EINVAL;
2902e5835488SYasunari Takiguchi 
2903e5835488SYasunari Takiguchi 		ret =
2904e5835488SYasunari Takiguchi 		    cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd,
2905e5835488SYasunari Takiguchi 							 CXD2880_IO_TGT_DMD,
2906e5835488SYasunari Takiguchi 							 0x10, 0x60,
2907e5835488SYasunari Takiguchi 							 value & 0x1f, 0x1f);
2908e5835488SYasunari Takiguchi 		if (ret)
2909e5835488SYasunari Takiguchi 			return ret;
2910e5835488SYasunari Takiguchi 		break;
2911e5835488SYasunari Takiguchi 
2912e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_CFG_DVBT_VBER_PERIOD:
2913e5835488SYasunari Takiguchi 		if (value < 0 || value > 7)
2914e5835488SYasunari Takiguchi 			return -EINVAL;
2915e5835488SYasunari Takiguchi 
2916e5835488SYasunari Takiguchi 		ret =
2917e5835488SYasunari Takiguchi 		    cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd,
2918e5835488SYasunari Takiguchi 							 CXD2880_IO_TGT_DMD,
2919e5835488SYasunari Takiguchi 							 0x10, 0x6f,
2920e5835488SYasunari Takiguchi 							 value & 0x07, 0x07);
2921e5835488SYasunari Takiguchi 		if (ret)
2922e5835488SYasunari Takiguchi 			return ret;
2923e5835488SYasunari Takiguchi 		break;
2924e5835488SYasunari Takiguchi 
2925e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_CFG_DVBT2_BBER_MES:
2926e5835488SYasunari Takiguchi 		if (value < 0 || value > 15)
2927e5835488SYasunari Takiguchi 			return -EINVAL;
2928e5835488SYasunari Takiguchi 
2929e5835488SYasunari Takiguchi 		ret =
2930e5835488SYasunari Takiguchi 		    cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd,
2931e5835488SYasunari Takiguchi 							 CXD2880_IO_TGT_DMD,
2932e5835488SYasunari Takiguchi 							 0x20, 0x72,
2933e5835488SYasunari Takiguchi 							 value & 0x0f, 0x0f);
2934e5835488SYasunari Takiguchi 		if (ret)
2935e5835488SYasunari Takiguchi 			return ret;
2936e5835488SYasunari Takiguchi 		break;
2937e5835488SYasunari Takiguchi 
2938e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_CFG_DVBT2_LBER_MES:
2939e5835488SYasunari Takiguchi 		if (value < 0 || value > 15)
2940e5835488SYasunari Takiguchi 			return -EINVAL;
2941e5835488SYasunari Takiguchi 
2942e5835488SYasunari Takiguchi 		ret =
2943e5835488SYasunari Takiguchi 		    cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd,
2944e5835488SYasunari Takiguchi 							 CXD2880_IO_TGT_DMD,
2945e5835488SYasunari Takiguchi 							 0x20, 0x6f,
2946e5835488SYasunari Takiguchi 							 value & 0x0f, 0x0f);
2947e5835488SYasunari Takiguchi 		if (ret)
2948e5835488SYasunari Takiguchi 			return ret;
2949e5835488SYasunari Takiguchi 		break;
2950e5835488SYasunari Takiguchi 
2951e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_CFG_DVBT_PER_MES:
2952e5835488SYasunari Takiguchi 		if (value < 0 || value > 15)
2953e5835488SYasunari Takiguchi 			return -EINVAL;
2954e5835488SYasunari Takiguchi 
2955e5835488SYasunari Takiguchi 		ret =
2956e5835488SYasunari Takiguchi 		    cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd,
2957e5835488SYasunari Takiguchi 							 CXD2880_IO_TGT_DMD,
2958e5835488SYasunari Takiguchi 							 0x10, 0x5c,
2959e5835488SYasunari Takiguchi 							 value & 0x0f, 0x0f);
2960e5835488SYasunari Takiguchi 		if (ret)
2961e5835488SYasunari Takiguchi 			return ret;
2962e5835488SYasunari Takiguchi 		break;
2963e5835488SYasunari Takiguchi 
2964e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_CFG_DVBT2_PER_MES:
2965e5835488SYasunari Takiguchi 		if (value < 0 || value > 15)
2966e5835488SYasunari Takiguchi 			return -EINVAL;
2967e5835488SYasunari Takiguchi 
2968e5835488SYasunari Takiguchi 		ret =
2969e5835488SYasunari Takiguchi 		    cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd,
2970e5835488SYasunari Takiguchi 							 CXD2880_IO_TGT_DMD,
2971e5835488SYasunari Takiguchi 							 0x24, 0xdc,
2972e5835488SYasunari Takiguchi 							 value & 0x0f, 0x0f);
2973e5835488SYasunari Takiguchi 		if (ret)
2974e5835488SYasunari Takiguchi 			return ret;
2975e5835488SYasunari Takiguchi 		break;
2976e5835488SYasunari Takiguchi 
2977e5835488SYasunari Takiguchi 	default:
2978e5835488SYasunari Takiguchi 		return -EINVAL;
2979e5835488SYasunari Takiguchi 	}
2980e5835488SYasunari Takiguchi 
2981e5835488SYasunari Takiguchi 	if (need_sub_setting &&
2982e5835488SYasunari Takiguchi 	    tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_MAIN)
2983e5835488SYasunari Takiguchi 		ret = cxd2880_tnrdmd_set_cfg(tnr_dmd->diver_sub, id, value);
2984e5835488SYasunari Takiguchi 
2985e5835488SYasunari Takiguchi 	return ret;
2986e5835488SYasunari Takiguchi }
2987e5835488SYasunari Takiguchi 
cxd2880_tnrdmd_gpio_set_cfg(struct cxd2880_tnrdmd * tnr_dmd,u8 id,u8 en,enum cxd2880_tnrdmd_gpio_mode mode,u8 open_drain,u8 invert)2988e5835488SYasunari Takiguchi int cxd2880_tnrdmd_gpio_set_cfg(struct cxd2880_tnrdmd *tnr_dmd,
2989e5835488SYasunari Takiguchi 				u8 id,
2990e5835488SYasunari Takiguchi 				u8 en,
2991e5835488SYasunari Takiguchi 				enum cxd2880_tnrdmd_gpio_mode mode,
2992e5835488SYasunari Takiguchi 				u8 open_drain, u8 invert)
2993e5835488SYasunari Takiguchi {
2994e5835488SYasunari Takiguchi 	int ret;
2995e5835488SYasunari Takiguchi 
2996e5835488SYasunari Takiguchi 	if (!tnr_dmd)
2997e5835488SYasunari Takiguchi 		return -EINVAL;
2998e5835488SYasunari Takiguchi 
2999e5835488SYasunari Takiguchi 	if (id > 2)
3000e5835488SYasunari Takiguchi 		return -EINVAL;
3001e5835488SYasunari Takiguchi 
3002e5835488SYasunari Takiguchi 	if (mode > CXD2880_TNRDMD_GPIO_MODE_EEW)
3003e5835488SYasunari Takiguchi 		return -EINVAL;
3004e5835488SYasunari Takiguchi 
3005e5835488SYasunari Takiguchi 	if (tnr_dmd->state != CXD2880_TNRDMD_STATE_SLEEP &&
3006e5835488SYasunari Takiguchi 	    tnr_dmd->state != CXD2880_TNRDMD_STATE_ACTIVE)
3007e5835488SYasunari Takiguchi 		return -EINVAL;
3008e5835488SYasunari Takiguchi 
3009e5835488SYasunari Takiguchi 	ret =
3010e5835488SYasunari Takiguchi 	    cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd, CXD2880_IO_TGT_SYS,
3011e5835488SYasunari Takiguchi 						 0x00, 0x40 + id, mode,
3012e5835488SYasunari Takiguchi 						 0x0f);
3013e5835488SYasunari Takiguchi 	if (ret)
3014e5835488SYasunari Takiguchi 		return ret;
3015e5835488SYasunari Takiguchi 
3016e5835488SYasunari Takiguchi 	ret =
3017e5835488SYasunari Takiguchi 	    cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd, CXD2880_IO_TGT_SYS,
3018e5835488SYasunari Takiguchi 						 0x00, 0x43,
3019e5835488SYasunari Takiguchi 						 open_drain ? (1 << id) : 0,
3020e5835488SYasunari Takiguchi 						 1 << id);
3021e5835488SYasunari Takiguchi 	if (ret)
3022e5835488SYasunari Takiguchi 		return ret;
3023e5835488SYasunari Takiguchi 
3024e5835488SYasunari Takiguchi 	ret =
3025e5835488SYasunari Takiguchi 	    cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd, CXD2880_IO_TGT_SYS,
3026e5835488SYasunari Takiguchi 						 0x00, 0x44,
3027e5835488SYasunari Takiguchi 						 invert ? (1 << id) : 0,
3028e5835488SYasunari Takiguchi 						 1 << id);
3029e5835488SYasunari Takiguchi 	if (ret)
3030e5835488SYasunari Takiguchi 		return ret;
3031e5835488SYasunari Takiguchi 
3032e5835488SYasunari Takiguchi 	return cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd,
3033e5835488SYasunari Takiguchi 						    CXD2880_IO_TGT_SYS,
3034e5835488SYasunari Takiguchi 						    0x00, 0x45,
3035e5835488SYasunari Takiguchi 						    en ? 0 : (1 << id),
3036e5835488SYasunari Takiguchi 						    1 << id);
3037e5835488SYasunari Takiguchi }
3038e5835488SYasunari Takiguchi 
cxd2880_tnrdmd_gpio_set_cfg_sub(struct cxd2880_tnrdmd * tnr_dmd,u8 id,u8 en,enum cxd2880_tnrdmd_gpio_mode mode,u8 open_drain,u8 invert)3039e5835488SYasunari Takiguchi int cxd2880_tnrdmd_gpio_set_cfg_sub(struct cxd2880_tnrdmd *tnr_dmd,
3040e5835488SYasunari Takiguchi 				    u8 id,
3041e5835488SYasunari Takiguchi 				    u8 en,
3042e5835488SYasunari Takiguchi 				    enum cxd2880_tnrdmd_gpio_mode
3043e5835488SYasunari Takiguchi 				    mode, u8 open_drain, u8 invert)
3044e5835488SYasunari Takiguchi {
3045e5835488SYasunari Takiguchi 	if (!tnr_dmd)
3046e5835488SYasunari Takiguchi 		return -EINVAL;
3047e5835488SYasunari Takiguchi 
3048e5835488SYasunari Takiguchi 	if (tnr_dmd->diver_mode != CXD2880_TNRDMD_DIVERMODE_MAIN)
3049e5835488SYasunari Takiguchi 		return -EINVAL;
3050e5835488SYasunari Takiguchi 
3051e5835488SYasunari Takiguchi 	return cxd2880_tnrdmd_gpio_set_cfg(tnr_dmd->diver_sub, id, en, mode,
3052e5835488SYasunari Takiguchi 					   open_drain, invert);
3053e5835488SYasunari Takiguchi }
3054e5835488SYasunari Takiguchi 
cxd2880_tnrdmd_gpio_read(struct cxd2880_tnrdmd * tnr_dmd,u8 id,u8 * value)3055e5835488SYasunari Takiguchi int cxd2880_tnrdmd_gpio_read(struct cxd2880_tnrdmd *tnr_dmd,
3056e5835488SYasunari Takiguchi 			     u8 id, u8 *value)
3057e5835488SYasunari Takiguchi {
3058e5835488SYasunari Takiguchi 	u8 data = 0;
3059e5835488SYasunari Takiguchi 	int ret;
3060e5835488SYasunari Takiguchi 
3061e5835488SYasunari Takiguchi 	if (!tnr_dmd || !value)
3062e5835488SYasunari Takiguchi 		return -EINVAL;
3063e5835488SYasunari Takiguchi 
3064e5835488SYasunari Takiguchi 	if (id > 2)
3065e5835488SYasunari Takiguchi 		return -EINVAL;
3066e5835488SYasunari Takiguchi 
3067e5835488SYasunari Takiguchi 	if (tnr_dmd->state != CXD2880_TNRDMD_STATE_SLEEP &&
3068e5835488SYasunari Takiguchi 	    tnr_dmd->state != CXD2880_TNRDMD_STATE_ACTIVE)
3069e5835488SYasunari Takiguchi 		return -EINVAL;
3070e5835488SYasunari Takiguchi 
3071e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io,
3072e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
3073e5835488SYasunari Takiguchi 				     0x00, 0x0a);
3074e5835488SYasunari Takiguchi 	if (ret)
3075e5835488SYasunari Takiguchi 		return ret;
3076e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->read_regs(tnr_dmd->io,
3077e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
3078e5835488SYasunari Takiguchi 				     0x20, &data, 1);
3079e5835488SYasunari Takiguchi 	if (ret)
3080e5835488SYasunari Takiguchi 		return ret;
3081e5835488SYasunari Takiguchi 
3082e5835488SYasunari Takiguchi 	*value = (data >> id) & 0x01;
3083e5835488SYasunari Takiguchi 
3084e5835488SYasunari Takiguchi 	return 0;
3085e5835488SYasunari Takiguchi }
3086e5835488SYasunari Takiguchi 
cxd2880_tnrdmd_gpio_read_sub(struct cxd2880_tnrdmd * tnr_dmd,u8 id,u8 * value)3087e5835488SYasunari Takiguchi int cxd2880_tnrdmd_gpio_read_sub(struct cxd2880_tnrdmd *tnr_dmd,
3088e5835488SYasunari Takiguchi 				 u8 id, u8 *value)
3089e5835488SYasunari Takiguchi {
3090e5835488SYasunari Takiguchi 	if (!tnr_dmd)
3091e5835488SYasunari Takiguchi 		return -EINVAL;
3092e5835488SYasunari Takiguchi 
3093e5835488SYasunari Takiguchi 	if (tnr_dmd->diver_mode != CXD2880_TNRDMD_DIVERMODE_MAIN)
3094e5835488SYasunari Takiguchi 		return -EINVAL;
3095e5835488SYasunari Takiguchi 
3096e5835488SYasunari Takiguchi 	return cxd2880_tnrdmd_gpio_read(tnr_dmd->diver_sub, id, value);
3097e5835488SYasunari Takiguchi }
3098e5835488SYasunari Takiguchi 
cxd2880_tnrdmd_gpio_write(struct cxd2880_tnrdmd * tnr_dmd,u8 id,u8 value)3099e5835488SYasunari Takiguchi int cxd2880_tnrdmd_gpio_write(struct cxd2880_tnrdmd *tnr_dmd,
3100e5835488SYasunari Takiguchi 			      u8 id, u8 value)
3101e5835488SYasunari Takiguchi {
3102e5835488SYasunari Takiguchi 	if (!tnr_dmd)
3103e5835488SYasunari Takiguchi 		return -EINVAL;
3104e5835488SYasunari Takiguchi 
3105e5835488SYasunari Takiguchi 	if (id > 2)
3106e5835488SYasunari Takiguchi 		return -EINVAL;
3107e5835488SYasunari Takiguchi 
3108e5835488SYasunari Takiguchi 	if (tnr_dmd->state != CXD2880_TNRDMD_STATE_SLEEP &&
3109e5835488SYasunari Takiguchi 	    tnr_dmd->state != CXD2880_TNRDMD_STATE_ACTIVE)
3110e5835488SYasunari Takiguchi 		return -EINVAL;
3111e5835488SYasunari Takiguchi 
3112e5835488SYasunari Takiguchi 	return cxd2880_tnrdmd_set_and_save_reg_bits(tnr_dmd,
3113e5835488SYasunari Takiguchi 						    CXD2880_IO_TGT_SYS,
3114e5835488SYasunari Takiguchi 						    0x00, 0x46,
3115e5835488SYasunari Takiguchi 						    value ? (1 << id) : 0,
3116e5835488SYasunari Takiguchi 						    1 << id);
3117e5835488SYasunari Takiguchi }
3118e5835488SYasunari Takiguchi 
cxd2880_tnrdmd_gpio_write_sub(struct cxd2880_tnrdmd * tnr_dmd,u8 id,u8 value)3119e5835488SYasunari Takiguchi int cxd2880_tnrdmd_gpio_write_sub(struct cxd2880_tnrdmd *tnr_dmd,
3120e5835488SYasunari Takiguchi 				  u8 id, u8 value)
3121e5835488SYasunari Takiguchi {
3122e5835488SYasunari Takiguchi 	if (!tnr_dmd)
3123e5835488SYasunari Takiguchi 		return -EINVAL;
3124e5835488SYasunari Takiguchi 
3125e5835488SYasunari Takiguchi 	if (tnr_dmd->diver_mode != CXD2880_TNRDMD_DIVERMODE_MAIN)
3126e5835488SYasunari Takiguchi 		return -EINVAL;
3127e5835488SYasunari Takiguchi 
3128e5835488SYasunari Takiguchi 	return cxd2880_tnrdmd_gpio_write(tnr_dmd->diver_sub, id, value);
3129e5835488SYasunari Takiguchi }
3130e5835488SYasunari Takiguchi 
cxd2880_tnrdmd_interrupt_read(struct cxd2880_tnrdmd * tnr_dmd,u16 * value)3131e5835488SYasunari Takiguchi int cxd2880_tnrdmd_interrupt_read(struct cxd2880_tnrdmd *tnr_dmd,
3132e5835488SYasunari Takiguchi 				  u16 *value)
3133e5835488SYasunari Takiguchi {
3134e5835488SYasunari Takiguchi 	int ret;
3135e5835488SYasunari Takiguchi 	u8 data[2] = { 0 };
3136e5835488SYasunari Takiguchi 
3137e5835488SYasunari Takiguchi 	if (!tnr_dmd || !value)
3138e5835488SYasunari Takiguchi 		return -EINVAL;
3139e5835488SYasunari Takiguchi 
3140e5835488SYasunari Takiguchi 	if (tnr_dmd->state != CXD2880_TNRDMD_STATE_SLEEP &&
3141e5835488SYasunari Takiguchi 	    tnr_dmd->state != CXD2880_TNRDMD_STATE_ACTIVE)
3142e5835488SYasunari Takiguchi 		return -EINVAL;
3143e5835488SYasunari Takiguchi 
3144e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io,
3145e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
3146e5835488SYasunari Takiguchi 				     0x00, 0x0a);
3147e5835488SYasunari Takiguchi 	if (ret)
3148e5835488SYasunari Takiguchi 		return ret;
3149e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->read_regs(tnr_dmd->io,
3150e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
3151e5835488SYasunari Takiguchi 				     0x15, data, 2);
3152e5835488SYasunari Takiguchi 	if (ret)
3153e5835488SYasunari Takiguchi 		return ret;
3154e5835488SYasunari Takiguchi 
3155e5835488SYasunari Takiguchi 	*value = (data[0] << 8) | data[1];
3156e5835488SYasunari Takiguchi 
3157e5835488SYasunari Takiguchi 	return 0;
3158e5835488SYasunari Takiguchi }
3159e5835488SYasunari Takiguchi 
cxd2880_tnrdmd_interrupt_clear(struct cxd2880_tnrdmd * tnr_dmd,u16 value)3160e5835488SYasunari Takiguchi int cxd2880_tnrdmd_interrupt_clear(struct cxd2880_tnrdmd *tnr_dmd,
3161e5835488SYasunari Takiguchi 				   u16 value)
3162e5835488SYasunari Takiguchi {
3163e5835488SYasunari Takiguchi 	int ret;
3164e5835488SYasunari Takiguchi 	u8 data[2] = { 0 };
3165e5835488SYasunari Takiguchi 
3166e5835488SYasunari Takiguchi 	if (!tnr_dmd)
3167e5835488SYasunari Takiguchi 		return -EINVAL;
3168e5835488SYasunari Takiguchi 
3169e5835488SYasunari Takiguchi 	if (tnr_dmd->state != CXD2880_TNRDMD_STATE_SLEEP &&
3170e5835488SYasunari Takiguchi 	    tnr_dmd->state != CXD2880_TNRDMD_STATE_ACTIVE)
3171e5835488SYasunari Takiguchi 		return -EINVAL;
3172e5835488SYasunari Takiguchi 
3173e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io,
3174e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
3175e5835488SYasunari Takiguchi 				     0x00, 0x00);
3176e5835488SYasunari Takiguchi 	if (ret)
3177e5835488SYasunari Takiguchi 		return ret;
3178e5835488SYasunari Takiguchi 
3179e5835488SYasunari Takiguchi 	data[0] = (value >> 8) & 0xff;
3180e5835488SYasunari Takiguchi 	data[1] = value & 0xff;
3181e5835488SYasunari Takiguchi 
3182e5835488SYasunari Takiguchi 	return tnr_dmd->io->write_regs(tnr_dmd->io,
3183e5835488SYasunari Takiguchi 				       CXD2880_IO_TGT_SYS,
3184e5835488SYasunari Takiguchi 				       0x3c, data, 2);
3185e5835488SYasunari Takiguchi }
3186e5835488SYasunari Takiguchi 
cxd2880_tnrdmd_ts_buf_clear(struct cxd2880_tnrdmd * tnr_dmd,u8 clear_overflow_flag,u8 clear_underflow_flag,u8 clear_buf)3187e5835488SYasunari Takiguchi int cxd2880_tnrdmd_ts_buf_clear(struct cxd2880_tnrdmd *tnr_dmd,
3188e5835488SYasunari Takiguchi 				u8 clear_overflow_flag,
3189e5835488SYasunari Takiguchi 				u8 clear_underflow_flag,
3190e5835488SYasunari Takiguchi 				u8 clear_buf)
3191e5835488SYasunari Takiguchi {
3192e5835488SYasunari Takiguchi 	int ret;
3193e5835488SYasunari Takiguchi 	u8 data[2] = { 0 };
3194e5835488SYasunari Takiguchi 
3195e5835488SYasunari Takiguchi 	if (!tnr_dmd)
3196e5835488SYasunari Takiguchi 		return -EINVAL;
3197e5835488SYasunari Takiguchi 
3198e5835488SYasunari Takiguchi 	if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_SUB)
3199e5835488SYasunari Takiguchi 		return -EINVAL;
3200e5835488SYasunari Takiguchi 
3201e5835488SYasunari Takiguchi 	if (tnr_dmd->state != CXD2880_TNRDMD_STATE_SLEEP &&
3202e5835488SYasunari Takiguchi 	    tnr_dmd->state != CXD2880_TNRDMD_STATE_ACTIVE)
3203e5835488SYasunari Takiguchi 		return -EINVAL;
3204e5835488SYasunari Takiguchi 
3205e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io,
3206e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_DMD,
3207e5835488SYasunari Takiguchi 				     0x00, 0x00);
3208e5835488SYasunari Takiguchi 	if (ret)
3209e5835488SYasunari Takiguchi 		return ret;
3210e5835488SYasunari Takiguchi 
3211e5835488SYasunari Takiguchi 	data[0] = clear_overflow_flag ? 0x02 : 0x00;
3212e5835488SYasunari Takiguchi 	data[0] |= clear_underflow_flag ? 0x01 : 0x00;
3213e5835488SYasunari Takiguchi 	data[1] = clear_buf ? 0x01 : 0x00;
3214e5835488SYasunari Takiguchi 
3215e5835488SYasunari Takiguchi 	return tnr_dmd->io->write_regs(tnr_dmd->io,
3216e5835488SYasunari Takiguchi 				       CXD2880_IO_TGT_DMD,
3217e5835488SYasunari Takiguchi 				       0x9f, data, 2);
3218e5835488SYasunari Takiguchi }
3219e5835488SYasunari Takiguchi 
cxd2880_tnrdmd_chip_id(struct cxd2880_tnrdmd * tnr_dmd,enum cxd2880_tnrdmd_chip_id * chip_id)3220e5835488SYasunari Takiguchi int cxd2880_tnrdmd_chip_id(struct cxd2880_tnrdmd *tnr_dmd,
3221e5835488SYasunari Takiguchi 			   enum cxd2880_tnrdmd_chip_id *chip_id)
3222e5835488SYasunari Takiguchi {
3223e5835488SYasunari Takiguchi 	int ret;
3224e5835488SYasunari Takiguchi 	u8 data = 0;
3225e5835488SYasunari Takiguchi 
3226e5835488SYasunari Takiguchi 	if (!tnr_dmd || !chip_id)
3227e5835488SYasunari Takiguchi 		return -EINVAL;
3228e5835488SYasunari Takiguchi 
3229e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io,
3230e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
3231e5835488SYasunari Takiguchi 				     0x00, 0x00);
3232e5835488SYasunari Takiguchi 	if (ret)
3233e5835488SYasunari Takiguchi 		return ret;
3234e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->read_regs(tnr_dmd->io,
3235e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
3236e5835488SYasunari Takiguchi 				     0xfd, &data, 1);
3237e5835488SYasunari Takiguchi 	if (ret)
3238e5835488SYasunari Takiguchi 		return ret;
3239e5835488SYasunari Takiguchi 
3240e5835488SYasunari Takiguchi 	*chip_id = (enum cxd2880_tnrdmd_chip_id)data;
3241e5835488SYasunari Takiguchi 
3242e5835488SYasunari Takiguchi 	return 0;
3243e5835488SYasunari Takiguchi }
3244e5835488SYasunari Takiguchi 
cxd2880_tnrdmd_set_and_save_reg_bits(struct cxd2880_tnrdmd * tnr_dmd,enum cxd2880_io_tgt tgt,u8 bank,u8 address,u8 value,u8 bit_mask)3245e5835488SYasunari Takiguchi int cxd2880_tnrdmd_set_and_save_reg_bits(struct cxd2880_tnrdmd
3246e5835488SYasunari Takiguchi 					 *tnr_dmd,
3247e5835488SYasunari Takiguchi 					 enum cxd2880_io_tgt tgt,
3248e5835488SYasunari Takiguchi 					 u8 bank, u8 address,
3249e5835488SYasunari Takiguchi 					 u8 value, u8 bit_mask)
3250e5835488SYasunari Takiguchi {
3251e5835488SYasunari Takiguchi 	int ret;
3252e5835488SYasunari Takiguchi 
3253e5835488SYasunari Takiguchi 	if (!tnr_dmd)
3254e5835488SYasunari Takiguchi 		return -EINVAL;
3255e5835488SYasunari Takiguchi 
3256e5835488SYasunari Takiguchi 	if (tnr_dmd->state != CXD2880_TNRDMD_STATE_SLEEP &&
3257e5835488SYasunari Takiguchi 	    tnr_dmd->state != CXD2880_TNRDMD_STATE_ACTIVE)
3258e5835488SYasunari Takiguchi 		return -EINVAL;
3259e5835488SYasunari Takiguchi 
3260e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io, tgt, 0x00, bank);
3261e5835488SYasunari Takiguchi 	if (ret)
3262e5835488SYasunari Takiguchi 		return ret;
3263e5835488SYasunari Takiguchi 
3264e5835488SYasunari Takiguchi 	ret = cxd2880_io_set_reg_bits(tnr_dmd->io,
3265e5835488SYasunari Takiguchi 				      tgt, address, value, bit_mask);
3266e5835488SYasunari Takiguchi 	if (ret)
3267e5835488SYasunari Takiguchi 		return ret;
3268e5835488SYasunari Takiguchi 
3269e5835488SYasunari Takiguchi 	return set_cfg_mem(tnr_dmd, tgt, bank, address, value, bit_mask);
3270e5835488SYasunari Takiguchi }
3271e5835488SYasunari Takiguchi 
cxd2880_tnrdmd_set_scan_mode(struct cxd2880_tnrdmd * tnr_dmd,enum cxd2880_dtv_sys sys,u8 scan_mode_end)3272e5835488SYasunari Takiguchi int cxd2880_tnrdmd_set_scan_mode(struct cxd2880_tnrdmd *tnr_dmd,
3273e5835488SYasunari Takiguchi 				 enum cxd2880_dtv_sys sys,
3274e5835488SYasunari Takiguchi 				 u8 scan_mode_end)
3275e5835488SYasunari Takiguchi {
3276e5835488SYasunari Takiguchi 	if (!tnr_dmd)
3277e5835488SYasunari Takiguchi 		return -EINVAL;
3278e5835488SYasunari Takiguchi 
3279e5835488SYasunari Takiguchi 	if (tnr_dmd->state != CXD2880_TNRDMD_STATE_SLEEP &&
3280e5835488SYasunari Takiguchi 	    tnr_dmd->state != CXD2880_TNRDMD_STATE_ACTIVE)
3281e5835488SYasunari Takiguchi 		return -EINVAL;
3282e5835488SYasunari Takiguchi 
3283e5835488SYasunari Takiguchi 	tnr_dmd->scan_mode = scan_mode_end;
3284e5835488SYasunari Takiguchi 
3285e5835488SYasunari Takiguchi 	if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_MAIN)
3286e5835488SYasunari Takiguchi 		return cxd2880_tnrdmd_set_scan_mode(tnr_dmd->diver_sub, sys,
3287e5835488SYasunari Takiguchi 						    scan_mode_end);
3288e5835488SYasunari Takiguchi 	else
3289e5835488SYasunari Takiguchi 		return 0;
3290e5835488SYasunari Takiguchi }
3291e5835488SYasunari Takiguchi 
cxd2880_tnrdmd_set_pid_ftr(struct cxd2880_tnrdmd * tnr_dmd,struct cxd2880_tnrdmd_pid_ftr_cfg * pid_ftr_cfg)3292e5835488SYasunari Takiguchi int cxd2880_tnrdmd_set_pid_ftr(struct cxd2880_tnrdmd *tnr_dmd,
3293e5835488SYasunari Takiguchi 			       struct cxd2880_tnrdmd_pid_ftr_cfg
3294e5835488SYasunari Takiguchi 			       *pid_ftr_cfg)
3295e5835488SYasunari Takiguchi {
3296e5835488SYasunari Takiguchi 	if (!tnr_dmd)
3297e5835488SYasunari Takiguchi 		return -EINVAL;
3298e5835488SYasunari Takiguchi 
3299e5835488SYasunari Takiguchi 	if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_SUB)
3300e5835488SYasunari Takiguchi 		return -EINVAL;
3301e5835488SYasunari Takiguchi 
3302e5835488SYasunari Takiguchi 	if (tnr_dmd->state != CXD2880_TNRDMD_STATE_SLEEP &&
3303e5835488SYasunari Takiguchi 	    tnr_dmd->state != CXD2880_TNRDMD_STATE_ACTIVE)
3304e5835488SYasunari Takiguchi 		return -EINVAL;
3305e5835488SYasunari Takiguchi 
3306e5835488SYasunari Takiguchi 	if (tnr_dmd->create_param.ts_output_if == CXD2880_TNRDMD_TSOUT_IF_TS)
3307e5835488SYasunari Takiguchi 		return -ENOTTY;
3308e5835488SYasunari Takiguchi 
3309e5835488SYasunari Takiguchi 	if (pid_ftr_cfg) {
3310e5835488SYasunari Takiguchi 		tnr_dmd->pid_ftr_cfg = *pid_ftr_cfg;
3311e5835488SYasunari Takiguchi 		tnr_dmd->pid_ftr_cfg_en = 1;
3312e5835488SYasunari Takiguchi 	} else {
3313e5835488SYasunari Takiguchi 		tnr_dmd->pid_ftr_cfg_en = 0;
3314e5835488SYasunari Takiguchi 	}
3315e5835488SYasunari Takiguchi 
3316e5835488SYasunari Takiguchi 	if (tnr_dmd->state == CXD2880_TNRDMD_STATE_ACTIVE)
3317e5835488SYasunari Takiguchi 		return pid_ftr_setting(tnr_dmd, pid_ftr_cfg);
3318e5835488SYasunari Takiguchi 	else
3319e5835488SYasunari Takiguchi 		return 0;
3320e5835488SYasunari Takiguchi }
3321e5835488SYasunari Takiguchi 
cxd2880_tnrdmd_set_rf_lvl_cmpstn(struct cxd2880_tnrdmd * tnr_dmd,int (* rf_lvl_cmpstn)(struct cxd2880_tnrdmd *,int *))3322e5835488SYasunari Takiguchi int cxd2880_tnrdmd_set_rf_lvl_cmpstn(struct cxd2880_tnrdmd
3323e5835488SYasunari Takiguchi 				     *tnr_dmd,
3324e5835488SYasunari Takiguchi 				     int (*rf_lvl_cmpstn)
3325e5835488SYasunari Takiguchi 				     (struct cxd2880_tnrdmd *,
3326e5835488SYasunari Takiguchi 				     int *))
3327e5835488SYasunari Takiguchi {
3328e5835488SYasunari Takiguchi 	if (!tnr_dmd)
3329e5835488SYasunari Takiguchi 		return -EINVAL;
3330e5835488SYasunari Takiguchi 
3331e5835488SYasunari Takiguchi 	tnr_dmd->rf_lvl_cmpstn = rf_lvl_cmpstn;
3332e5835488SYasunari Takiguchi 
3333e5835488SYasunari Takiguchi 	return 0;
3334e5835488SYasunari Takiguchi }
3335e5835488SYasunari Takiguchi 
cxd2880_tnrdmd_set_rf_lvl_cmpstn_sub(struct cxd2880_tnrdmd * tnr_dmd,int (* rf_lvl_cmpstn)(struct cxd2880_tnrdmd *,int *))3336e5835488SYasunari Takiguchi int cxd2880_tnrdmd_set_rf_lvl_cmpstn_sub(struct cxd2880_tnrdmd
3337e5835488SYasunari Takiguchi 					 *tnr_dmd,
3338e5835488SYasunari Takiguchi 					 int (*rf_lvl_cmpstn)
3339e5835488SYasunari Takiguchi 					 (struct cxd2880_tnrdmd *,
3340e5835488SYasunari Takiguchi 					 int *))
3341e5835488SYasunari Takiguchi {
3342e5835488SYasunari Takiguchi 	if (!tnr_dmd)
3343e5835488SYasunari Takiguchi 		return -EINVAL;
3344e5835488SYasunari Takiguchi 
3345e5835488SYasunari Takiguchi 	if (tnr_dmd->diver_mode != CXD2880_TNRDMD_DIVERMODE_MAIN)
3346e5835488SYasunari Takiguchi 		return -EINVAL;
3347e5835488SYasunari Takiguchi 
3348e5835488SYasunari Takiguchi 	return cxd2880_tnrdmd_set_rf_lvl_cmpstn(tnr_dmd->diver_sub,
3349e5835488SYasunari Takiguchi 						rf_lvl_cmpstn);
3350e5835488SYasunari Takiguchi }
3351e5835488SYasunari Takiguchi 
cxd2880_tnrdmd_set_lna_thrs(struct cxd2880_tnrdmd * tnr_dmd,struct cxd2880_tnrdmd_lna_thrs_tbl_air * tbl_air,struct cxd2880_tnrdmd_lna_thrs_tbl_cable * tbl_cable)3352e5835488SYasunari Takiguchi int cxd2880_tnrdmd_set_lna_thrs(struct cxd2880_tnrdmd *tnr_dmd,
3353e5835488SYasunari Takiguchi 				struct cxd2880_tnrdmd_lna_thrs_tbl_air
3354e5835488SYasunari Takiguchi 				*tbl_air,
3355e5835488SYasunari Takiguchi 				struct cxd2880_tnrdmd_lna_thrs_tbl_cable
3356e5835488SYasunari Takiguchi 				*tbl_cable)
3357e5835488SYasunari Takiguchi {
3358e5835488SYasunari Takiguchi 	if (!tnr_dmd)
3359e5835488SYasunari Takiguchi 		return -EINVAL;
3360e5835488SYasunari Takiguchi 
3361e5835488SYasunari Takiguchi 	tnr_dmd->lna_thrs_tbl_air = tbl_air;
3362e5835488SYasunari Takiguchi 	tnr_dmd->lna_thrs_tbl_cable = tbl_cable;
3363e5835488SYasunari Takiguchi 
3364e5835488SYasunari Takiguchi 	return 0;
3365e5835488SYasunari Takiguchi }
3366e5835488SYasunari Takiguchi 
cxd2880_tnrdmd_set_lna_thrs_sub(struct cxd2880_tnrdmd * tnr_dmd,struct cxd2880_tnrdmd_lna_thrs_tbl_air * tbl_air,struct cxd2880_tnrdmd_lna_thrs_tbl_cable * tbl_cable)3367e5835488SYasunari Takiguchi int cxd2880_tnrdmd_set_lna_thrs_sub(struct cxd2880_tnrdmd *tnr_dmd,
3368e5835488SYasunari Takiguchi 				    struct
3369e5835488SYasunari Takiguchi 				    cxd2880_tnrdmd_lna_thrs_tbl_air
3370e5835488SYasunari Takiguchi 				    *tbl_air,
3371e5835488SYasunari Takiguchi 				    struct cxd2880_tnrdmd_lna_thrs_tbl_cable
3372e5835488SYasunari Takiguchi 				    *tbl_cable)
3373e5835488SYasunari Takiguchi {
3374e5835488SYasunari Takiguchi 	if (!tnr_dmd)
3375e5835488SYasunari Takiguchi 		return -EINVAL;
3376e5835488SYasunari Takiguchi 
3377e5835488SYasunari Takiguchi 	if (tnr_dmd->diver_mode != CXD2880_TNRDMD_DIVERMODE_MAIN)
3378e5835488SYasunari Takiguchi 		return -EINVAL;
3379e5835488SYasunari Takiguchi 
3380e5835488SYasunari Takiguchi 	return cxd2880_tnrdmd_set_lna_thrs(tnr_dmd->diver_sub,
3381e5835488SYasunari Takiguchi 					   tbl_air, tbl_cable);
3382e5835488SYasunari Takiguchi }
3383e5835488SYasunari Takiguchi 
cxd2880_tnrdmd_set_ts_pin_high_low(struct cxd2880_tnrdmd * tnr_dmd,u8 en,u8 value)3384e5835488SYasunari Takiguchi int cxd2880_tnrdmd_set_ts_pin_high_low(struct cxd2880_tnrdmd
3385e5835488SYasunari Takiguchi 				       *tnr_dmd, u8 en, u8 value)
3386e5835488SYasunari Takiguchi {
3387e5835488SYasunari Takiguchi 	int ret;
3388e5835488SYasunari Takiguchi 
3389e5835488SYasunari Takiguchi 	if (!tnr_dmd)
3390e5835488SYasunari Takiguchi 		return -EINVAL;
3391e5835488SYasunari Takiguchi 
3392e5835488SYasunari Takiguchi 	if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_SUB)
3393e5835488SYasunari Takiguchi 		return -EINVAL;
3394e5835488SYasunari Takiguchi 
3395e5835488SYasunari Takiguchi 	if (tnr_dmd->state != CXD2880_TNRDMD_STATE_SLEEP)
3396e5835488SYasunari Takiguchi 		return -EINVAL;
3397e5835488SYasunari Takiguchi 
3398e5835488SYasunari Takiguchi 	if (tnr_dmd->create_param.ts_output_if != CXD2880_TNRDMD_TSOUT_IF_TS)
3399e5835488SYasunari Takiguchi 		return -ENOTTY;
3400e5835488SYasunari Takiguchi 
3401e5835488SYasunari Takiguchi 	ret = tnr_dmd->io->write_reg(tnr_dmd->io,
3402e5835488SYasunari Takiguchi 				     CXD2880_IO_TGT_SYS,
3403e5835488SYasunari Takiguchi 				     0x00, 0x00);
3404e5835488SYasunari Takiguchi 	if (ret)
3405e5835488SYasunari Takiguchi 		return ret;
3406e5835488SYasunari Takiguchi 
3407e5835488SYasunari Takiguchi 	if (en) {
3408e5835488SYasunari Takiguchi 		ret = tnr_dmd->io->write_reg(tnr_dmd->io,
3409e5835488SYasunari Takiguchi 					     CXD2880_IO_TGT_SYS,
3410e5835488SYasunari Takiguchi 					     0x50, ((value & 0x1f) | 0x80));
3411e5835488SYasunari Takiguchi 		if (ret)
3412e5835488SYasunari Takiguchi 			return ret;
3413e5835488SYasunari Takiguchi 
3414e5835488SYasunari Takiguchi 		ret = tnr_dmd->io->write_reg(tnr_dmd->io,
3415e5835488SYasunari Takiguchi 					     CXD2880_IO_TGT_SYS,
3416e5835488SYasunari Takiguchi 					     0x52, (value & 0x1f));
3417e5835488SYasunari Takiguchi 	} else {
3418e5835488SYasunari Takiguchi 		ret = cxd2880_io_write_multi_regs(tnr_dmd->io,
3419e5835488SYasunari Takiguchi 						  CXD2880_IO_TGT_SYS,
3420e5835488SYasunari Takiguchi 						  set_ts_pin_seq,
3421e5835488SYasunari Takiguchi 						  ARRAY_SIZE(set_ts_pin_seq));
3422e5835488SYasunari Takiguchi 		if (ret)
3423e5835488SYasunari Takiguchi 			return ret;
3424e5835488SYasunari Takiguchi 
3425e5835488SYasunari Takiguchi 		ret = load_cfg_mem(tnr_dmd);
3426e5835488SYasunari Takiguchi 	}
3427e5835488SYasunari Takiguchi 
3428e5835488SYasunari Takiguchi 	return ret;
3429e5835488SYasunari Takiguchi }
3430e5835488SYasunari Takiguchi 
cxd2880_tnrdmd_set_ts_output(struct cxd2880_tnrdmd * tnr_dmd,u8 en)3431e5835488SYasunari Takiguchi int cxd2880_tnrdmd_set_ts_output(struct cxd2880_tnrdmd *tnr_dmd,
3432e5835488SYasunari Takiguchi 				 u8 en)
3433e5835488SYasunari Takiguchi {
3434e5835488SYasunari Takiguchi 	int ret;
3435e5835488SYasunari Takiguchi 
3436e5835488SYasunari Takiguchi 	if (!tnr_dmd)
3437e5835488SYasunari Takiguchi 		return -EINVAL;
3438e5835488SYasunari Takiguchi 
3439e5835488SYasunari Takiguchi 	if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_SUB)
3440e5835488SYasunari Takiguchi 		return -EINVAL;
3441e5835488SYasunari Takiguchi 
3442e5835488SYasunari Takiguchi 	if (tnr_dmd->state != CXD2880_TNRDMD_STATE_SLEEP &&
3443e5835488SYasunari Takiguchi 	    tnr_dmd->state != CXD2880_TNRDMD_STATE_ACTIVE)
3444e5835488SYasunari Takiguchi 		return -EINVAL;
3445e5835488SYasunari Takiguchi 
3446e5835488SYasunari Takiguchi 	switch (tnr_dmd->create_param.ts_output_if) {
3447e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_TSOUT_IF_TS:
3448e5835488SYasunari Takiguchi 		if (en) {
3449e5835488SYasunari Takiguchi 			ret = cxd2880_io_write_multi_regs(tnr_dmd->io,
3450e5835488SYasunari Takiguchi 							  CXD2880_IO_TGT_SYS,
3451e5835488SYasunari Takiguchi 							  set_ts_output_seq1,
3452e5835488SYasunari Takiguchi 							  ARRAY_SIZE(set_ts_output_seq1));
3453e5835488SYasunari Takiguchi 			if (ret)
3454e5835488SYasunari Takiguchi 				return ret;
3455e5835488SYasunari Takiguchi 
3456e5835488SYasunari Takiguchi 			ret = cxd2880_io_write_multi_regs(tnr_dmd->io,
3457e5835488SYasunari Takiguchi 							  CXD2880_IO_TGT_DMD,
3458e5835488SYasunari Takiguchi 							  set_ts_output_seq2,
3459e5835488SYasunari Takiguchi 							  ARRAY_SIZE(set_ts_output_seq2));
3460e5835488SYasunari Takiguchi 			if (ret)
3461e5835488SYasunari Takiguchi 				return ret;
3462e5835488SYasunari Takiguchi 		} else {
3463e5835488SYasunari Takiguchi 			ret = cxd2880_io_write_multi_regs(tnr_dmd->io,
3464e5835488SYasunari Takiguchi 							  CXD2880_IO_TGT_DMD,
3465e5835488SYasunari Takiguchi 							  set_ts_output_seq3,
3466e5835488SYasunari Takiguchi 							  ARRAY_SIZE(set_ts_output_seq3));
3467e5835488SYasunari Takiguchi 			if (ret)
3468e5835488SYasunari Takiguchi 				return ret;
3469e5835488SYasunari Takiguchi 
3470e5835488SYasunari Takiguchi 			ret = cxd2880_io_write_multi_regs(tnr_dmd->io,
3471e5835488SYasunari Takiguchi 							  CXD2880_IO_TGT_SYS,
3472e5835488SYasunari Takiguchi 							  set_ts_output_seq4,
3473e5835488SYasunari Takiguchi 							  ARRAY_SIZE(set_ts_output_seq4));
3474e5835488SYasunari Takiguchi 			if (ret)
3475e5835488SYasunari Takiguchi 				return ret;
3476e5835488SYasunari Takiguchi 		}
3477e5835488SYasunari Takiguchi 		break;
3478e5835488SYasunari Takiguchi 
3479e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_TSOUT_IF_SPI:
3480e5835488SYasunari Takiguchi 		break;
3481e5835488SYasunari Takiguchi 
3482e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_TSOUT_IF_SDIO:
3483e5835488SYasunari Takiguchi 		break;
3484e5835488SYasunari Takiguchi 
3485e5835488SYasunari Takiguchi 	default:
3486e5835488SYasunari Takiguchi 		return -EINVAL;
3487e5835488SYasunari Takiguchi 	}
3488e5835488SYasunari Takiguchi 
3489e5835488SYasunari Takiguchi 	return 0;
3490e5835488SYasunari Takiguchi }
3491e5835488SYasunari Takiguchi 
slvt_freeze_reg(struct cxd2880_tnrdmd * tnr_dmd)3492e5835488SYasunari Takiguchi int slvt_freeze_reg(struct cxd2880_tnrdmd *tnr_dmd)
3493e5835488SYasunari Takiguchi {
3494e5835488SYasunari Takiguchi 	u8 data;
3495e5835488SYasunari Takiguchi 	int ret;
3496e5835488SYasunari Takiguchi 
3497e5835488SYasunari Takiguchi 	if (!tnr_dmd)
3498e5835488SYasunari Takiguchi 		return -EINVAL;
3499e5835488SYasunari Takiguchi 
3500e5835488SYasunari Takiguchi 	switch (tnr_dmd->create_param.ts_output_if) {
3501e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_TSOUT_IF_SPI:
3502e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_TSOUT_IF_SDIO:
3503e5835488SYasunari Takiguchi 
3504e5835488SYasunari Takiguchi 		ret = tnr_dmd->io->read_regs(tnr_dmd->io,
3505e5835488SYasunari Takiguchi 					     CXD2880_IO_TGT_DMD,
3506e5835488SYasunari Takiguchi 					     0x00, &data, 1);
3507e5835488SYasunari Takiguchi 		if (ret)
3508e5835488SYasunari Takiguchi 			return ret;
3509e5835488SYasunari Takiguchi 
3510e5835488SYasunari Takiguchi 		break;
3511e5835488SYasunari Takiguchi 	case CXD2880_TNRDMD_TSOUT_IF_TS:
3512e5835488SYasunari Takiguchi 	default:
3513e5835488SYasunari Takiguchi 		break;
3514e5835488SYasunari Takiguchi 	}
3515e5835488SYasunari Takiguchi 
3516e5835488SYasunari Takiguchi 	return tnr_dmd->io->write_reg(tnr_dmd->io,
3517e5835488SYasunari Takiguchi 				      CXD2880_IO_TGT_DMD,
3518e5835488SYasunari Takiguchi 				      0x01, 0x01);
3519e5835488SYasunari Takiguchi }
3520