4 * Sony HELENE DVB-S/S2 DVB-T/T2 DVB-C/C2 ISDB-T/S tuner driver (CXD2858ER)
6 * Copyright 2012 Sony Corporation
7 * Copyright (C) 2014 NetUP Inc.
8 * Copyright (C) 2014 Abylay Ospan <aospan@netup.ru>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #include <linux/slab.h>
22 #include <linux/module.h>
23 #include <linux/dvb/frontend.h>
24 #include <linux/types.h>
26 #include "dvb_frontend.h"
28 #define MAX_WRITE_REGSIZE 20
39 struct i2c_adapter
*i2c
;
40 enum helene_state state
;
42 int (*set_tuner
)(void *, int);
43 enum helene_xtal xtal
;
46 #define TERR_INTERNAL_LOOPFILTER_AVAILABLE(tv_system) \
47 (((tv_system) != SONY_HELENE_DTV_DVBC_6) && \
48 ((tv_system) != SONY_HELENE_DTV_DVBC_8)\
49 && ((tv_system) != SONY_HELENE_DTV_DVBC2_6) && \
50 ((tv_system) != SONY_HELENE_DTV_DVBC2_8))
52 #define HELENE_AUTO 0xff
53 #define HELENE_OFFSET(ofs) ((u8)(ofs) & 0x1F)
54 #define HELENE_BW_6 0x00
55 #define HELENE_BW_7 0x01
56 #define HELENE_BW_8 0x02
57 #define HELENE_BW_1_7 0x03
59 enum helene_tv_system_t
{
60 SONY_HELENE_TV_SYSTEM_UNKNOWN
,
61 /* Terrestrial Analog */
62 SONY_HELENE_ATV_MN_EIAJ
,
63 /**< System-M (Japan) (IF: Fp=5.75MHz in default) */
64 SONY_HELENE_ATV_MN_SAP
,
65 /**< System-M (US) (IF: Fp=5.75MHz in default) */
66 SONY_HELENE_ATV_MN_A2
,
67 /**< System-M (Korea) (IF: Fp=5.9MHz in default) */
69 /**< System-B/G (IF: Fp=7.3MHz in default) */
71 /**< System-I (IF: Fp=7.85MHz in default) */
73 /**< System-D/K (IF: Fp=7.85MHz in default) */
75 /**< System-L (IF: Fp=7.85MHz in default) */
76 SONY_HELENE_ATV_L_DASH
,
77 /**< System-L DASH (IF: Fp=2.2MHz in default) */
78 /* Terrestrial/Cable Digital */
80 /**< ATSC 8VSB (IF: Fc=3.7MHz in default) */
82 /**< US QAM (IF: Fc=3.7MHz in default) */
83 SONY_HELENE_DTV_ISDBT_6
,
84 /**< ISDB-T 6MHzBW (IF: Fc=3.55MHz in default) */
85 SONY_HELENE_DTV_ISDBT_7
,
86 /**< ISDB-T 7MHzBW (IF: Fc=4.15MHz in default) */
87 SONY_HELENE_DTV_ISDBT_8
,
88 /**< ISDB-T 8MHzBW (IF: Fc=4.75MHz in default) */
89 SONY_HELENE_DTV_DVBT_5
,
90 /**< DVB-T 5MHzBW (IF: Fc=3.6MHz in default) */
91 SONY_HELENE_DTV_DVBT_6
,
92 /**< DVB-T 6MHzBW (IF: Fc=3.6MHz in default) */
93 SONY_HELENE_DTV_DVBT_7
,
94 /**< DVB-T 7MHzBW (IF: Fc=4.2MHz in default) */
95 SONY_HELENE_DTV_DVBT_8
,
96 /**< DVB-T 8MHzBW (IF: Fc=4.8MHz in default) */
97 SONY_HELENE_DTV_DVBT2_1_7
,
98 /**< DVB-T2 1.7MHzBW (IF: Fc=3.5MHz in default) */
99 SONY_HELENE_DTV_DVBT2_5
,
100 /**< DVB-T2 5MHzBW (IF: Fc=3.6MHz in default) */
101 SONY_HELENE_DTV_DVBT2_6
,
102 /**< DVB-T2 6MHzBW (IF: Fc=3.6MHz in default) */
103 SONY_HELENE_DTV_DVBT2_7
,
104 /**< DVB-T2 7MHzBW (IF: Fc=4.2MHz in default) */
105 SONY_HELENE_DTV_DVBT2_8
,
106 /**< DVB-T2 8MHzBW (IF: Fc=4.8MHz in default) */
107 SONY_HELENE_DTV_DVBC_6
,
108 /**< DVB-C 6MHzBW (IF: Fc=3.7MHz in default) */
109 SONY_HELENE_DTV_DVBC_8
,
110 /**< DVB-C 8MHzBW (IF: Fc=4.9MHz in default) */
111 SONY_HELENE_DTV_DVBC2_6
,
112 /**< DVB-C2 6MHzBW (IF: Fc=3.7MHz in default) */
113 SONY_HELENE_DTV_DVBC2_8
,
114 /**< DVB-C2 8MHzBW (IF: Fc=4.9MHz in default) */
115 SONY_HELENE_DTV_DTMB
,
116 /**< DTMB (IF: Fc=5.1MHz in default) */
118 SONY_HELENE_STV_ISDBS
,
120 SONY_HELENE_STV_DVBS
,
122 SONY_HELENE_STV_DVBS2
,
125 SONY_HELENE_ATV_MIN
= SONY_HELENE_ATV_MN_EIAJ
,
126 /**< Minimum analog terrestrial system */
127 SONY_HELENE_ATV_MAX
= SONY_HELENE_ATV_L_DASH
,
128 /**< Maximum analog terrestrial system */
129 SONY_HELENE_DTV_MIN
= SONY_HELENE_DTV_8VSB
,
130 /**< Minimum digital terrestrial system */
131 SONY_HELENE_DTV_MAX
= SONY_HELENE_DTV_DTMB
,
132 /**< Maximum digital terrestrial system */
133 SONY_HELENE_TERR_TV_SYSTEM_NUM
,
134 /**< Number of supported terrestrial broadcasting system */
135 SONY_HELENE_STV_MIN
= SONY_HELENE_STV_ISDBS
,
136 /**< Minimum satellite system */
137 SONY_HELENE_STV_MAX
= SONY_HELENE_STV_DVBS2
138 /**< Maximum satellite system */
141 struct helene_terr_adjust_param_t
{
142 /* < Addr:0x69 Bit[6:4] : RFVGA gain.
143 * 0xFF means Auto. (RF_GAIN_SEL = 1)
146 /* < Addr:0x69 Bit[3:0] : IF_BPF gain.
149 /* < Addr:0x6B Bit[3:0] : RF overload
150 * RF input detect level. (FRF <= 172MHz)
152 uint8_t RFOVLD_DET_LV1_VL
;
153 /* < Addr:0x6B Bit[3:0] : RF overload
154 * RF input detect level. (172MHz < FRF <= 464MHz)
156 uint8_t RFOVLD_DET_LV1_VH
;
157 /* < Addr:0x6B Bit[3:0] : RF overload
158 * RF input detect level. (FRF > 464MHz)
160 uint8_t RFOVLD_DET_LV1_U
;
161 /* < Addr:0x6C Bit[2:0] :
162 * Internal RFAGC detect level. (FRF <= 172MHz)
164 uint8_t IFOVLD_DET_LV_VL
;
165 /* < Addr:0x6C Bit[2:0] :
166 * Internal RFAGC detect level. (172MHz < FRF <= 464MHz)
168 uint8_t IFOVLD_DET_LV_VH
;
169 /* < Addr:0x6C Bit[2:0] :
170 * Internal RFAGC detect level. (FRF > 464MHz)
172 uint8_t IFOVLD_DET_LV_U
;
173 /* < Addr:0x6D Bit[5:4] :
174 * IF filter center offset.
177 /* < Addr:0x6D Bit[1:0] :
178 * 6MHzBW(0x00) or 7MHzBW(0x01)
179 * or 8MHzBW(0x02) or 1.7MHzBW(0x03)
182 /* < Addr:0x6E Bit[4:0] :
183 * 5bit signed. IF offset (kHz) = FIF_OFFSET x 50
186 /* < Addr:0x6F Bit[4:0] :
187 * 5bit signed. BW offset (kHz) =
188 * BW_OFFSET x 50 (BW_OFFSET x 10 in 1.7MHzBW)
191 /* < Addr:0x9C Bit[0] :
192 * Local polarity. (0: Upper Local, 1: Lower Local)
194 uint8_t IS_LOWERLOCAL
;
197 static const struct helene_terr_adjust_param_t
198 terr_params
[SONY_HELENE_TERR_TV_SYSTEM_NUM
] = {
199 /*< SONY_HELENE_TV_SYSTEM_UNKNOWN */
200 {HELENE_AUTO
, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
201 HELENE_BW_6
, HELENE_OFFSET(0), HELENE_OFFSET(0), 0x00},
203 /**< SONY_HELENE_ATV_MN_EIAJ (System-M (Japan)) */
204 {HELENE_AUTO
, 0x05, 0x03, 0x06, 0x03, 0x01, 0x01, 0x01, 0x00,
205 HELENE_BW_6
, HELENE_OFFSET(0), HELENE_OFFSET(1), 0x00},
206 /**< SONY_HELENE_ATV_MN_SAP (System-M (US)) */
207 {HELENE_AUTO
, 0x05, 0x03, 0x06, 0x03, 0x01, 0x01, 0x01, 0x00,
208 HELENE_BW_6
, HELENE_OFFSET(0), HELENE_OFFSET(1), 0x00},
209 {HELENE_AUTO
, 0x05, 0x03, 0x06, 0x03, 0x01, 0x01, 0x01, 0x00,
210 HELENE_BW_6
, HELENE_OFFSET(3), HELENE_OFFSET(1), 0x00},
211 /**< SONY_HELENE_ATV_MN_A2 (System-M (Korea)) */
212 {HELENE_AUTO
, 0x05, 0x03, 0x06, 0x03, 0x01, 0x01, 0x01, 0x00,
213 HELENE_BW_7
, HELENE_OFFSET(11), HELENE_OFFSET(5), 0x00},
214 /**< SONY_HELENE_ATV_BG (System-B/G) */
215 {HELENE_AUTO
, 0x05, 0x03, 0x06, 0x03, 0x01, 0x01, 0x01, 0x00,
216 HELENE_BW_8
, HELENE_OFFSET(2), HELENE_OFFSET(-3), 0x00},
217 /**< SONY_HELENE_ATV_I (System-I) */
218 {HELENE_AUTO
, 0x05, 0x03, 0x06, 0x03, 0x01, 0x01, 0x01, 0x00,
219 HELENE_BW_8
, HELENE_OFFSET(2), HELENE_OFFSET(-3), 0x00},
220 /**< SONY_HELENE_ATV_DK (System-D/K) */
221 {HELENE_AUTO
, 0x03, 0x04, 0x0A, 0x04, 0x04, 0x04, 0x04, 0x00,
222 HELENE_BW_8
, HELENE_OFFSET(2), HELENE_OFFSET(-3), 0x00},
223 /**< SONY_HELENE_ATV_L (System-L) */
224 {HELENE_AUTO
, 0x03, 0x04, 0x0A, 0x04, 0x04, 0x04, 0x04, 0x00,
225 HELENE_BW_8
, HELENE_OFFSET(-1), HELENE_OFFSET(4), 0x00},
226 /**< SONY_HELENE_ATV_L_DASH (System-L DASH) */
228 {HELENE_AUTO
, 0x09, 0x0B, 0x0B, 0x0B, 0x03, 0x03, 0x03, 0x00,
229 HELENE_BW_6
, HELENE_OFFSET(-6), HELENE_OFFSET(-3), 0x00},
230 /**< SONY_HELENE_DTV_8VSB (ATSC 8VSB) */
231 {HELENE_AUTO
, 0x09, 0x0B, 0x0B, 0x0B, 0x02, 0x02, 0x02, 0x00,
232 HELENE_BW_6
, HELENE_OFFSET(-6), HELENE_OFFSET(-3), 0x00},
233 /**< SONY_HELENE_DTV_QAM (US QAM) */
234 {HELENE_AUTO
, 0x09, 0x0B, 0x0B, 0x0B, 0x02, 0x02, 0x02, 0x00,
235 HELENE_BW_6
, HELENE_OFFSET(-9), HELENE_OFFSET(-5), 0x00},
236 /**< SONY_HELENE_DTV_ISDBT_6 (ISDB-T 6MHzBW) */
237 {HELENE_AUTO
, 0x09, 0x0B, 0x0B, 0x0B, 0x02, 0x02, 0x02, 0x00,
238 HELENE_BW_7
, HELENE_OFFSET(-7), HELENE_OFFSET(-6), 0x00},
239 /**< SONY_HELENE_DTV_ISDBT_7 (ISDB-T 7MHzBW) */
240 {HELENE_AUTO
, 0x09, 0x0B, 0x0B, 0x0B, 0x02, 0x02, 0x02, 0x00,
241 HELENE_BW_8
, HELENE_OFFSET(-5), HELENE_OFFSET(-7), 0x00},
242 /**< SONY_HELENE_DTV_ISDBT_8 (ISDB-T 8MHzBW) */
243 {HELENE_AUTO
, 0x09, 0x0B, 0x0B, 0x0B, 0x02, 0x02, 0x02, 0x00,
244 HELENE_BW_6
, HELENE_OFFSET(-8), HELENE_OFFSET(-3), 0x00},
245 /**< SONY_HELENE_DTV_DVBT_5 (DVB-T 5MHzBW) */
246 {HELENE_AUTO
, 0x09, 0x0B, 0x0B, 0x0B, 0x02, 0x02, 0x02, 0x00,
247 HELENE_BW_6
, HELENE_OFFSET(-8), HELENE_OFFSET(-3), 0x00},
248 /**< SONY_HELENE_DTV_DVBT_6 (DVB-T 6MHzBW) */
249 {HELENE_AUTO
, 0x09, 0x0B, 0x0B, 0x0B, 0x02, 0x02, 0x02, 0x00,
250 HELENE_BW_7
, HELENE_OFFSET(-6), HELENE_OFFSET(-5), 0x00},
251 /**< SONY_HELENE_DTV_DVBT_7 (DVB-T 7MHzBW) */
252 {HELENE_AUTO
, 0x09, 0x0B, 0x0B, 0x0B, 0x02, 0x02, 0x02, 0x00,
253 HELENE_BW_8
, HELENE_OFFSET(-4), HELENE_OFFSET(-6), 0x00},
254 /**< SONY_HELENE_DTV_DVBT_8 (DVB-T 8MHzBW) */
255 {HELENE_AUTO
, 0x09, 0x0B, 0x0B, 0x0B, 0x02, 0x02, 0x02, 0x00,
256 HELENE_BW_1_7
, HELENE_OFFSET(-10), HELENE_OFFSET(-10), 0x00},
257 /**< SONY_HELENE_DTV_DVBT2_1_7 (DVB-T2 1.7MHzBW) */
258 {HELENE_AUTO
, 0x09, 0x0B, 0x0B, 0x0B, 0x02, 0x02, 0x02, 0x00,
259 HELENE_BW_6
, HELENE_OFFSET(-8), HELENE_OFFSET(-3), 0x00},
260 /**< SONY_HELENE_DTV_DVBT2_5 (DVB-T2 5MHzBW) */
261 {HELENE_AUTO
, 0x09, 0x0B, 0x0B, 0x0B, 0x02, 0x02, 0x02, 0x00,
262 HELENE_BW_6
, HELENE_OFFSET(-8), HELENE_OFFSET(-3), 0x00},
263 /**< SONY_HELENE_DTV_DVBT2_6 (DVB-T2 6MHzBW) */
264 {HELENE_AUTO
, 0x09, 0x0B, 0x0B, 0x0B, 0x02, 0x02, 0x02, 0x00,
265 HELENE_BW_7
, HELENE_OFFSET(-6), HELENE_OFFSET(-5), 0x00},
266 /**< SONY_HELENE_DTV_DVBT2_7 (DVB-T2 7MHzBW) */
267 {HELENE_AUTO
, 0x09, 0x0B, 0x0B, 0x0B, 0x02, 0x02, 0x02, 0x00,
268 HELENE_BW_8
, HELENE_OFFSET(-4), HELENE_OFFSET(-6), 0x00},
269 /**< SONY_HELENE_DTV_DVBT2_8 (DVB-T2 8MHzBW) */
270 {HELENE_AUTO
, 0x05, 0x02, 0x02, 0x02, 0x01, 0x01, 0x01, 0x00,
271 HELENE_BW_6
, HELENE_OFFSET(-6), HELENE_OFFSET(-4), 0x00},
272 /**< SONY_HELENE_DTV_DVBC_6 (DVB-C 6MHzBW) */
273 {HELENE_AUTO
, 0x05, 0x02, 0x02, 0x02, 0x01, 0x01, 0x01, 0x00,
274 HELENE_BW_8
, HELENE_OFFSET(-2), HELENE_OFFSET(-3), 0x00},
275 /**< SONY_HELENE_DTV_DVBC_8 (DVB-C 8MHzBW) */
276 {HELENE_AUTO
, 0x03, 0x09, 0x09, 0x09, 0x02, 0x02, 0x02, 0x00,
277 HELENE_BW_6
, HELENE_OFFSET(-6), HELENE_OFFSET(-2), 0x00},
278 /**< SONY_HELENE_DTV_DVBC2_6 (DVB-C2 6MHzBW) */
279 {HELENE_AUTO
, 0x03, 0x09, 0x09, 0x09, 0x02, 0x02, 0x02, 0x00,
280 HELENE_BW_8
, HELENE_OFFSET(-2), HELENE_OFFSET(0), 0x00},
281 /**< SONY_HELENE_DTV_DVBC2_8 (DVB-C2 8MHzBW) */
282 {HELENE_AUTO
, 0x04, 0x0B, 0x0B, 0x0B, 0x02, 0x02, 0x02, 0x00,
283 HELENE_BW_8
, HELENE_OFFSET(2), HELENE_OFFSET(1), 0x00}
284 /**< SONY_HELENE_DTV_DTMB (DTMB) */
287 static void helene_i2c_debug(struct helene_priv
*priv
,
288 u8 reg
, u8 write
, const u8
*data
, u32 len
)
290 dev_dbg(&priv
->i2c
->dev
, "helene: I2C %s reg 0x%02x size %d\n",
291 (write
== 0 ? "read" : "write"), reg
, len
);
292 print_hex_dump_bytes("helene: I2C data: ",
293 DUMP_PREFIX_OFFSET
, data
, len
);
296 static int helene_write_regs(struct helene_priv
*priv
,
297 u8 reg
, const u8
*data
, u32 len
)
300 u8 buf
[MAX_WRITE_REGSIZE
+ 1];
301 struct i2c_msg msg
[1] = {
303 .addr
= priv
->i2c_address
,
310 if (len
+ 1 > sizeof(buf
)) {
311 dev_warn(&priv
->i2c
->dev
,
312 "wr reg=%04x: len=%d vs %Zu is too big!\n",
313 reg
, len
+ 1, sizeof(buf
));
317 helene_i2c_debug(priv
, reg
, 1, data
, len
);
319 memcpy(&buf
[1], data
, len
);
320 ret
= i2c_transfer(priv
->i2c
, msg
, 1);
321 if (ret
>= 0 && ret
!= 1)
324 dev_warn(&priv
->i2c
->dev
,
325 "%s: i2c wr failed=%d reg=%02x len=%d\n",
326 KBUILD_MODNAME
, ret
, reg
, len
);
332 static int helene_write_reg(struct helene_priv
*priv
, u8 reg
, u8 val
)
334 return helene_write_regs(priv
, reg
, &val
, 1);
337 static int helene_read_regs(struct helene_priv
*priv
,
338 u8 reg
, u8
*val
, u32 len
)
341 struct i2c_msg msg
[2] = {
343 .addr
= priv
->i2c_address
,
348 .addr
= priv
->i2c_address
,
355 ret
= i2c_transfer(priv
->i2c
, &msg
[0], 1);
356 if (ret
>= 0 && ret
!= 1)
359 dev_warn(&priv
->i2c
->dev
,
360 "%s: I2C rw failed=%d addr=%02x reg=%02x\n",
361 KBUILD_MODNAME
, ret
, priv
->i2c_address
, reg
);
364 ret
= i2c_transfer(priv
->i2c
, &msg
[1], 1);
365 if (ret
>= 0 && ret
!= 1)
368 dev_warn(&priv
->i2c
->dev
,
369 "%s: i2c rd failed=%d addr=%02x reg=%02x\n",
370 KBUILD_MODNAME
, ret
, priv
->i2c_address
, reg
);
373 helene_i2c_debug(priv
, reg
, 0, val
, len
);
377 static int helene_read_reg(struct helene_priv
*priv
, u8 reg
, u8
*val
)
379 return helene_read_regs(priv
, reg
, val
, 1);
382 static int helene_set_reg_bits(struct helene_priv
*priv
,
383 u8 reg
, u8 data
, u8 mask
)
389 res
= helene_read_reg(priv
, reg
, &rdata
);
392 data
= ((data
& mask
) | (rdata
& (mask
^ 0xFF)));
394 return helene_write_reg(priv
, reg
, data
);
397 static int helene_enter_power_save(struct helene_priv
*priv
)
399 dev_dbg(&priv
->i2c
->dev
, "%s()\n", __func__
);
400 if (priv
->state
== STATE_SLEEP
)
403 /* Standby setting for CPU */
404 helene_write_reg(priv
, 0x88, 0x0);
406 /* Standby setting for internal logic block */
407 helene_write_reg(priv
, 0x87, 0xC0);
409 priv
->state
= STATE_SLEEP
;
413 static int helene_leave_power_save(struct helene_priv
*priv
)
415 dev_dbg(&priv
->i2c
->dev
, "%s()\n", __func__
);
416 if (priv
->state
== STATE_ACTIVE
)
419 /* Standby setting for internal logic block */
420 helene_write_reg(priv
, 0x87, 0xC4);
422 /* Standby setting for CPU */
423 helene_write_reg(priv
, 0x88, 0x40);
425 priv
->state
= STATE_ACTIVE
;
429 static int helene_init(struct dvb_frontend
*fe
)
431 struct helene_priv
*priv
= fe
->tuner_priv
;
433 dev_dbg(&priv
->i2c
->dev
, "%s()\n", __func__
);
434 return helene_leave_power_save(priv
);
437 static int helene_release(struct dvb_frontend
*fe
)
439 struct helene_priv
*priv
= fe
->tuner_priv
;
441 dev_dbg(&priv
->i2c
->dev
, "%s()\n", __func__
);
442 kfree(fe
->tuner_priv
);
443 fe
->tuner_priv
= NULL
;
447 static int helene_sleep(struct dvb_frontend
*fe
)
449 struct helene_priv
*priv
= fe
->tuner_priv
;
451 dev_dbg(&priv
->i2c
->dev
, "%s()\n", __func__
);
452 helene_enter_power_save(priv
);
456 static enum helene_tv_system_t
helene_get_tv_system(struct dvb_frontend
*fe
)
458 enum helene_tv_system_t system
= SONY_HELENE_TV_SYSTEM_UNKNOWN
;
459 struct dtv_frontend_properties
*p
= &fe
->dtv_property_cache
;
460 struct helene_priv
*priv
= fe
->tuner_priv
;
462 if (p
->delivery_system
== SYS_DVBT
) {
463 if (p
->bandwidth_hz
<= 5000000)
464 system
= SONY_HELENE_DTV_DVBT_5
;
465 else if (p
->bandwidth_hz
<= 6000000)
466 system
= SONY_HELENE_DTV_DVBT_6
;
467 else if (p
->bandwidth_hz
<= 7000000)
468 system
= SONY_HELENE_DTV_DVBT_7
;
469 else if (p
->bandwidth_hz
<= 8000000)
470 system
= SONY_HELENE_DTV_DVBT_8
;
472 system
= SONY_HELENE_DTV_DVBT_8
;
473 p
->bandwidth_hz
= 8000000;
475 } else if (p
->delivery_system
== SYS_DVBT2
) {
476 if (p
->bandwidth_hz
<= 5000000)
477 system
= SONY_HELENE_DTV_DVBT2_5
;
478 else if (p
->bandwidth_hz
<= 6000000)
479 system
= SONY_HELENE_DTV_DVBT2_6
;
480 else if (p
->bandwidth_hz
<= 7000000)
481 system
= SONY_HELENE_DTV_DVBT2_7
;
482 else if (p
->bandwidth_hz
<= 8000000)
483 system
= SONY_HELENE_DTV_DVBT2_8
;
485 system
= SONY_HELENE_DTV_DVBT2_8
;
486 p
->bandwidth_hz
= 8000000;
488 } else if (p
->delivery_system
== SYS_DVBS
) {
489 system
= SONY_HELENE_STV_DVBS
;
490 } else if (p
->delivery_system
== SYS_DVBS2
) {
491 system
= SONY_HELENE_STV_DVBS2
;
492 } else if (p
->delivery_system
== SYS_ISDBS
) {
493 system
= SONY_HELENE_STV_ISDBS
;
494 } else if (p
->delivery_system
== SYS_ISDBT
) {
495 if (p
->bandwidth_hz
<= 6000000)
496 system
= SONY_HELENE_DTV_ISDBT_6
;
497 else if (p
->bandwidth_hz
<= 7000000)
498 system
= SONY_HELENE_DTV_ISDBT_7
;
499 else if (p
->bandwidth_hz
<= 8000000)
500 system
= SONY_HELENE_DTV_ISDBT_8
;
502 system
= SONY_HELENE_DTV_ISDBT_8
;
503 p
->bandwidth_hz
= 8000000;
505 } else if (p
->delivery_system
== SYS_DVBC_ANNEX_A
) {
506 if (p
->bandwidth_hz
<= 6000000)
507 system
= SONY_HELENE_DTV_DVBC_6
;
508 else if (p
->bandwidth_hz
<= 8000000)
509 system
= SONY_HELENE_DTV_DVBC_8
;
511 dev_dbg(&priv
->i2c
->dev
,
512 "%s(): HELENE DTV system %d (delsys %d, bandwidth %d)\n",
513 __func__
, (int)system
, p
->delivery_system
,
518 static int helene_set_params_s(struct dvb_frontend
*fe
)
520 u8 data
[MAX_WRITE_REGSIZE
];
522 enum helene_tv_system_t tv_system
;
523 struct dtv_frontend_properties
*p
= &fe
->dtv_property_cache
;
524 struct helene_priv
*priv
= fe
->tuner_priv
;
525 int frequencykHz
= p
->frequency
;
526 uint32_t frequency4kHz
= 0;
527 u32 symbol_rate
= p
->symbol_rate
/1000;
529 dev_dbg(&priv
->i2c
->dev
, "%s(): tune frequency %dkHz sr=%uKsps\n",
530 __func__
, frequencykHz
, symbol_rate
);
531 tv_system
= helene_get_tv_system(fe
);
533 if (tv_system
== SONY_HELENE_TV_SYSTEM_UNKNOWN
) {
534 dev_err(&priv
->i2c
->dev
, "%s(): unknown DTV system\n",
538 /* RF switch turn to satellite */
540 priv
->set_tuner(priv
->set_tuner_data
, 0);
541 frequency
= roundup(p
->frequency
/ 1000, 1);
543 /* Disable IF signal output */
544 helene_write_reg(priv
, 0x15, 0x02);
546 /* RFIN matching in power save (Sat) reset */
547 helene_write_reg(priv
, 0x43, 0x06);
549 /* Analog block setting (0x6A, 0x6B) */
552 helene_write_regs(priv
, 0x6A, data
, 2);
553 helene_write_reg(priv
, 0x75, 0x99);
554 helene_write_reg(priv
, 0x9D, 0x00);
556 /* Tuning setting for CPU (0x61) */
557 helene_write_reg(priv
, 0x61, 0x07);
559 /* Satellite mode select (0x01) */
560 helene_write_reg(priv
, 0x01, 0x01);
562 /* Clock enable for internal logic block, CPU wake-up (0x04, 0x05) */
566 switch (priv
->xtal
) {
567 case SONY_HELENE_XTAL_16000
:
570 case SONY_HELENE_XTAL_20500
:
573 case SONY_HELENE_XTAL_24000
:
576 case SONY_HELENE_XTAL_41000
:
580 dev_err(&priv
->i2c
->dev
, "%s(): unknown xtal %d\n",
581 __func__
, priv
->xtal
);
585 /* Setting for analog block (0x07). LOOPFILTER INTERNAL */
588 /* Tuning setting for analog block
589 * (0x08, 0x09, 0x0A, 0x0B). LOOPFILTER INTERNAL
591 if (priv
->xtal
== SONY_HELENE_XTAL_20500
)
600 /* Enable for analog block (0x0C, 0x0D, 0x0E). SAT LNA ON */
602 data
[8] |= 0xE0; /* POWERSAVE_TERR_RF_ACTIVE */
606 /* Setting for LPF cutoff frequency (0x0F) */
608 case SONY_HELENE_STV_ISDBS
:
609 data
[11] = 0x22; /* 22MHz */
611 case SONY_HELENE_STV_DVBS
:
612 if (symbol_rate
<= 4000)
614 else if (symbol_rate
<= 10000)
615 data
[11] = (uint8_t)((symbol_rate
* 47
616 + (40000-1)) / 40000);
618 data
[11] = (uint8_t)((symbol_rate
* 27
619 + (40000-1)) / 40000 + 5);
622 data
[11] = 36; /* 5 <= lpf_cutoff <= 36 is valid */
624 case SONY_HELENE_STV_DVBS2
:
625 if (symbol_rate
<= 4000)
627 else if (symbol_rate
<= 10000)
628 data
[11] = (uint8_t)((symbol_rate
* 11
629 + (10000-1)) / 10000);
631 data
[11] = (uint8_t)((symbol_rate
* 3
632 + (5000-1)) / 5000 + 5);
635 data
[11] = 36; /* 5 <= lpf_cutoff <= 36 is valid */
638 dev_err(&priv
->i2c
->dev
, "%s(): unknown standard %d\n",
639 __func__
, tv_system
);
643 /* RF tuning frequency setting (0x10, 0x11, 0x12) */
644 frequency4kHz
= (frequencykHz
+ 2) / 4;
645 data
[12] = (uint8_t)(frequency4kHz
& 0xFF); /* FRF_L */
646 data
[13] = (uint8_t)((frequency4kHz
>> 8) & 0xFF); /* FRF_M */
647 /* FRF_H (bit[3:0]) */
648 data
[14] = (uint8_t)((frequency4kHz
>> 16) & 0x0F);
650 /* Tuning command (0x13) */
653 /* Setting for IQOUT_LIMIT (0x14) 0.75Vpp */
656 /* Enable IQ output (0x15) */
659 helene_write_regs(priv
, 0x04, data
, 18);
661 dev_dbg(&priv
->i2c
->dev
, "%s(): tune done\n",
664 priv
->frequency
= frequency
;
668 static int helene_set_params(struct dvb_frontend
*fe
)
670 u8 data
[MAX_WRITE_REGSIZE
];
672 enum helene_tv_system_t tv_system
;
673 struct dtv_frontend_properties
*p
= &fe
->dtv_property_cache
;
674 struct helene_priv
*priv
= fe
->tuner_priv
;
675 int frequencykHz
= p
->frequency
/ 1000;
677 dev_dbg(&priv
->i2c
->dev
, "%s(): tune frequency %dkHz\n",
678 __func__
, frequencykHz
);
679 tv_system
= helene_get_tv_system(fe
);
681 if (tv_system
== SONY_HELENE_TV_SYSTEM_UNKNOWN
) {
682 dev_dbg(&priv
->i2c
->dev
, "%s(): unknown DTV system\n",
687 priv
->set_tuner(priv
->set_tuner_data
, 1);
688 frequency
= roundup(p
->frequency
/ 1000, 25);
691 helene_write_reg(priv
, 0x01, 0x00);
693 /* Disable IF signal output */
694 helene_write_reg(priv
, 0x74, 0x02);
696 if (priv
->state
== STATE_SLEEP
)
697 helene_leave_power_save(priv
);
699 /* Initial setting for internal analog block (0x91, 0x92) */
700 if ((tv_system
== SONY_HELENE_DTV_DVBC_6
) ||
701 (tv_system
== SONY_HELENE_DTV_DVBC_8
)) {
708 helene_write_regs(priv
, 0x91, data
, 2);
710 /* Setting for analog block */
711 if (TERR_INTERNAL_LOOPFILTER_AVAILABLE(tv_system
))
716 /* Setting for local polarity (0x9D) */
717 data
[1] = (uint8_t)(terr_params
[tv_system
].IS_LOWERLOCAL
& 0x01);
718 helene_write_regs(priv
, 0x9C, data
, 2);
720 /* Enable for analog block */
724 data
[3] = 0x67; /* Tuning setting for CPU */
726 /* Setting for PLL reference divider for xtal=24MHz */
727 if ((tv_system
== SONY_HELENE_DTV_DVBC_6
) ||
728 (tv_system
== SONY_HELENE_DTV_DVBC_8
))
733 /* Tuning setting for analog block */
734 if (TERR_INTERNAL_LOOPFILTER_AVAILABLE(tv_system
)) {
739 } else if ((tv_system
== SONY_HELENE_DTV_DVBC_6
) ||
740 (tv_system
== SONY_HELENE_DTV_DVBC_8
)) {
751 helene_write_regs(priv
, 0x5E, data
, 9);
753 /* LT_AMP_EN should be 0 */
754 helene_set_reg_bits(priv
, 0x67, 0x0, 0x02);
756 /* Setting for IFOUT_LIMIT */
757 data
[0] = 0x00; /* 1.5Vpp */
759 /* RF_GAIN setting */
760 if (terr_params
[tv_system
].RF_GAIN
== HELENE_AUTO
)
761 data
[1] = 0x80; /* RF_GAIN_SEL = 1 */
763 data
[1] = (uint8_t)((terr_params
[tv_system
].RF_GAIN
766 /* IF_BPF_GC setting */
767 data
[1] |= (uint8_t)(terr_params
[tv_system
].IF_BPF_GC
& 0x0F);
769 /* Setting for internal RFAGC (0x6A, 0x6B, 0x6C) */
771 if (frequencykHz
<= 172000) {
772 data
[3] = (uint8_t)(terr_params
[tv_system
].RFOVLD_DET_LV1_VL
774 data
[4] = (uint8_t)(terr_params
[tv_system
].IFOVLD_DET_LV_VL
776 } else if (frequencykHz
<= 464000) {
777 data
[3] = (uint8_t)(terr_params
[tv_system
].RFOVLD_DET_LV1_VH
779 data
[4] = (uint8_t)(terr_params
[tv_system
].IFOVLD_DET_LV_VH
782 data
[3] = (uint8_t)(terr_params
[tv_system
].RFOVLD_DET_LV1_U
784 data
[4] = (uint8_t)(terr_params
[tv_system
].IFOVLD_DET_LV_U
789 /* Setting for IF frequency and bandwidth */
791 /* IF filter center frequency offset (IF_BPF_F0) (0x6D) */
792 data
[5] = (uint8_t)((terr_params
[tv_system
].IF_BPF_F0
<< 4) & 0x30);
794 /* IF filter band width (BW) (0x6D) */
795 data
[5] |= (uint8_t)(terr_params
[tv_system
].BW
& 0x03);
797 /* IF frequency offset value (FIF_OFFSET) (0x6E) */
798 data
[6] = (uint8_t)(terr_params
[tv_system
].FIF_OFFSET
& 0x1F);
800 /* IF band width offset value (BW_OFFSET) (0x6F) */
801 data
[7] = (uint8_t)(terr_params
[tv_system
].BW_OFFSET
& 0x1F);
803 /* RF tuning frequency setting (0x70, 0x71, 0x72) */
804 data
[8] = (uint8_t)(frequencykHz
& 0xFF); /* FRF_L */
805 data
[9] = (uint8_t)((frequencykHz
>> 8) & 0xFF); /* FRF_M */
806 data
[10] = (uint8_t)((frequencykHz
>> 16)
807 & 0x0F); /* FRF_H (bit[3:0]) */
812 /* Enable IF output, AGC and IFOUT pin selection (0x74) */
815 if ((tv_system
== SONY_HELENE_DTV_DVBC_6
) ||
816 (tv_system
== SONY_HELENE_DTV_DVBC_8
)) {
828 helene_write_regs(priv
, 0x68, data
, 17);
830 dev_dbg(&priv
->i2c
->dev
, "%s(): tune done\n",
833 priv
->frequency
= frequency
;
837 static int helene_get_frequency(struct dvb_frontend
*fe
, u32
*frequency
)
839 struct helene_priv
*priv
= fe
->tuner_priv
;
841 *frequency
= priv
->frequency
* 1000;
845 static struct dvb_tuner_ops helene_tuner_ops
= {
847 .name
= "Sony HELENE Ter tuner",
848 .frequency_min
= 1000000,
849 .frequency_max
= 1200000000,
850 .frequency_step
= 25000,
853 .release
= helene_release
,
854 .sleep
= helene_sleep
,
855 .set_params
= helene_set_params
,
856 .get_frequency
= helene_get_frequency
,
859 static struct dvb_tuner_ops helene_tuner_ops_s
= {
861 .name
= "Sony HELENE Sat tuner",
862 .frequency_min
= 500000,
863 .frequency_max
= 2500000,
864 .frequency_step
= 1000,
867 .release
= helene_release
,
868 .sleep
= helene_sleep
,
869 .set_params
= helene_set_params_s
,
870 .get_frequency
= helene_get_frequency
,
874 * call once after reset
876 static int helene_x_pon(struct helene_priv
*priv
)
878 /* RFIN matching in power save (terrestrial) = ACTIVE */
879 /* RFIN matching in power save (satellite) = ACTIVE */
880 u8 dataT
[] = { 0x06, 0x00, 0x02, 0x00 };
881 /* SAT_RF_ACTIVE = true, lnaOff = false, terrRfActive = true */
882 u8 dataS
[] = { 0x05, 0x06 };
883 u8 cdata
[] = {0x7A, 0x01};
888 helene_write_reg(priv
, 0x01, 0x00);
890 helene_write_reg(priv
, 0x67, dataT
[3]);
891 helene_write_reg(priv
, 0x43, dataS
[1]);
892 helene_write_regs(priv
, 0x5E, dataT
, 3);
893 helene_write_reg(priv
, 0x0C, dataS
[0]);
895 /* Initial setting for internal logic block */
896 helene_write_regs(priv
, 0x99, cdata
, sizeof(cdata
));
899 data
[0] = 0x18; /* xtal 24 MHz */
900 data
[1] = (uint8_t)(0x80 | (0x04 & 0x1F)); /* 4 x 25 = 100uA */
901 data
[2] = (uint8_t)(0x80 | (0x26 & 0x7F)); /* 38 x 0.25 = 9.5pF */
902 data
[3] = 0x80; /* REFOUT signal output 500mVpp */
903 data
[4] = 0x00; /* GPIO settings */
904 data
[5] = 0x00; /* GPIO settings */
905 data
[6] = 0xC4; /* Clock enable for internal logic block */
906 data
[7] = 0x40; /* Start CPU boot-up */
907 data
[8] = 0x10; /* For burst-write */
909 /* Setting for internal RFAGC */
914 data
[12] = 0x07; /* Setting for analog block */
916 /* Initial setting for internal analog block */
925 helene_write_regs(priv
, 0x81, data
, sizeof(data
));
927 /* Setting for internal RFAGC */
928 helene_write_reg(priv
, 0x9B, 0x00);
932 /* Check CPU_STT/CPU_ERR */
933 helene_read_regs(priv
, 0x1A, rdata
, sizeof(rdata
));
935 if (rdata
[0] != 0x00) {
936 dev_err(&priv
->i2c
->dev
,
937 "HELENE tuner CPU error 0x%x\n", rdata
[0]);
941 /* VCO current setting */
944 helene_write_regs(priv
, 0x17, cdata
, sizeof(cdata
));
946 helene_read_reg(priv
, 0x19, data
);
947 helene_write_reg(priv
, 0x95, (uint8_t)((data
[0] >> 4) & 0x0F));
949 /* Disable IF signal output */
950 helene_write_reg(priv
, 0x74, 0x02);
952 /* Standby setting for CPU */
953 helene_write_reg(priv
, 0x88, 0x00);
955 /* Standby setting for internal logic block */
956 helene_write_reg(priv
, 0x87, 0xC0);
958 /* Load capacitance control setting for crystal oscillator */
959 helene_write_reg(priv
, 0x80, 0x01);
961 /* Satellite initial setting */
964 helene_write_regs(priv
, 0x41, cdata
, sizeof(cdata
));
966 dev_info(&priv
->i2c
->dev
,
967 "HELENE tuner x_pon done\n");
972 struct dvb_frontend
*helene_attach_s(struct dvb_frontend
*fe
,
973 const struct helene_config
*config
,
974 struct i2c_adapter
*i2c
)
976 struct helene_priv
*priv
= NULL
;
978 priv
= kzalloc(sizeof(struct helene_priv
), GFP_KERNEL
);
981 priv
->i2c_address
= (config
->i2c_address
>> 1);
983 priv
->set_tuner_data
= config
->set_tuner_priv
;
984 priv
->set_tuner
= config
->set_tuner_callback
;
985 priv
->xtal
= config
->xtal
;
987 if (fe
->ops
.i2c_gate_ctrl
)
988 fe
->ops
.i2c_gate_ctrl(fe
, 1);
990 if (helene_x_pon(priv
) != 0)
993 if (fe
->ops
.i2c_gate_ctrl
)
994 fe
->ops
.i2c_gate_ctrl(fe
, 0);
996 memcpy(&fe
->ops
.tuner_ops
, &helene_tuner_ops_s
,
997 sizeof(struct dvb_tuner_ops
));
998 fe
->tuner_priv
= priv
;
999 dev_info(&priv
->i2c
->dev
,
1000 "Sony HELENE Sat attached on addr=%x at I2C adapter %p\n",
1001 priv
->i2c_address
, priv
->i2c
);
1004 EXPORT_SYMBOL(helene_attach_s
);
1006 struct dvb_frontend
*helene_attach(struct dvb_frontend
*fe
,
1007 const struct helene_config
*config
,
1008 struct i2c_adapter
*i2c
)
1010 struct helene_priv
*priv
= NULL
;
1012 priv
= kzalloc(sizeof(struct helene_priv
), GFP_KERNEL
);
1015 priv
->i2c_address
= (config
->i2c_address
>> 1);
1017 priv
->set_tuner_data
= config
->set_tuner_priv
;
1018 priv
->set_tuner
= config
->set_tuner_callback
;
1019 priv
->xtal
= config
->xtal
;
1021 if (fe
->ops
.i2c_gate_ctrl
)
1022 fe
->ops
.i2c_gate_ctrl(fe
, 1);
1024 if (helene_x_pon(priv
) != 0)
1027 if (fe
->ops
.i2c_gate_ctrl
)
1028 fe
->ops
.i2c_gate_ctrl(fe
, 0);
1030 memcpy(&fe
->ops
.tuner_ops
, &helene_tuner_ops
,
1031 sizeof(struct dvb_tuner_ops
));
1032 fe
->tuner_priv
= priv
;
1033 dev_info(&priv
->i2c
->dev
,
1034 "Sony HELENE Ter attached on addr=%x at I2C adapter %p\n",
1035 priv
->i2c_address
, priv
->i2c
);
1038 EXPORT_SYMBOL(helene_attach
);
1040 MODULE_DESCRIPTION("Sony HELENE Sat/Ter tuner driver");
1041 MODULE_AUTHOR("Abylay Ospan <aospan@netup.ru>");
1042 MODULE_LICENSE("GPL");