Lines Matching refs:state

64 static int reg_write(struct qm1d1c0042_state *state, u8 reg, u8 val)  in reg_write()  argument
69 ret = i2c_master_send(state->i2c, wbuf, sizeof(wbuf)); in reg_write()
75 static int reg_read(struct qm1d1c0042_state *state, u8 reg, u8 *val) in reg_read() argument
79 .addr = state->i2c->addr, in reg_read()
85 .addr = state->i2c->addr, in reg_read()
93 ret = i2c_transfer(state->i2c->adapter, msgs, ARRAY_SIZE(msgs)); in reg_read()
100 static int qm1d1c0042_set_srch_mode(struct qm1d1c0042_state *state, bool fast) in qm1d1c0042_set_srch_mode() argument
103 state->regs[0x03] |= 0x01; /* set fast search mode */ in qm1d1c0042_set_srch_mode()
105 state->regs[0x03] &= ~0x01 & 0xff; in qm1d1c0042_set_srch_mode()
107 return reg_write(state, 0x03, state->regs[0x03]); in qm1d1c0042_set_srch_mode()
110 static int qm1d1c0042_wakeup(struct qm1d1c0042_state *state) in qm1d1c0042_wakeup() argument
114 state->regs[0x01] |= 1 << 3; /* BB_Reg_enable */ in qm1d1c0042_wakeup()
115 state->regs[0x01] &= (~(1 << 0)) & 0xff; /* NORMAL (wake-up) */ in qm1d1c0042_wakeup()
116 state->regs[0x05] &= (~(1 << 3)) & 0xff; /* pfd_rst NORMAL */ in qm1d1c0042_wakeup()
117 ret = reg_write(state, 0x01, state->regs[0x01]); in qm1d1c0042_wakeup()
119 ret = reg_write(state, 0x05, state->regs[0x05]); in qm1d1c0042_wakeup()
122 dev_warn(&state->i2c->dev, "(%s) failed. [adap%d-fe%d]\n", in qm1d1c0042_wakeup()
123 __func__, state->cfg.fe->dvb->num, state->cfg.fe->id); in qm1d1c0042_wakeup()
131 struct qm1d1c0042_state *state; in qm1d1c0042_set_config() local
134 state = fe->tuner_priv; in qm1d1c0042_set_config()
138 state->cfg.fe = cfg->fe; in qm1d1c0042_set_config()
141 dev_warn(&state->i2c->dev, in qm1d1c0042_set_config()
143 state->cfg.xtal_freq = default_cfg.xtal_freq; in qm1d1c0042_set_config()
145 state->cfg.lpf = cfg->lpf; in qm1d1c0042_set_config()
146 state->cfg.fast_srch = cfg->fast_srch; in qm1d1c0042_set_config()
149 state->cfg.lpf_wait = cfg->lpf_wait; in qm1d1c0042_set_config()
151 state->cfg.lpf_wait = default_cfg.lpf_wait; in qm1d1c0042_set_config()
154 state->cfg.fast_srch_wait = cfg->fast_srch_wait; in qm1d1c0042_set_config()
156 state->cfg.fast_srch_wait = default_cfg.fast_srch_wait; in qm1d1c0042_set_config()
159 state->cfg.normal_srch_wait = cfg->normal_srch_wait; in qm1d1c0042_set_config()
161 state->cfg.normal_srch_wait = default_cfg.normal_srch_wait; in qm1d1c0042_set_config()
181 struct qm1d1c0042_state *state; in qm1d1c0042_set_params() local
188 state = fe->tuner_priv; in qm1d1c0042_set_params()
191 state->regs[0x08] &= 0xf0; in qm1d1c0042_set_params()
192 state->regs[0x08] |= 0x09; in qm1d1c0042_set_params()
194 state->regs[0x13] &= 0x9f; in qm1d1c0042_set_params()
195 state->regs[0x13] |= 0x20; in qm1d1c0042_set_params()
198 val = state->regs[0x02] & 0x0f; in qm1d1c0042_set_params()
205 ret = reg_write(state, 0x02, val); in qm1d1c0042_set_params()
209 a = DIV_ROUND_CLOSEST(freq, state->cfg.xtal_freq); in qm1d1c0042_set_params()
211 state->regs[0x06] &= 0x40; in qm1d1c0042_set_params()
212 state->regs[0x06] |= (a - 12) / 4; in qm1d1c0042_set_params()
213 ret = reg_write(state, 0x06, state->regs[0x06]); in qm1d1c0042_set_params()
217 state->regs[0x07] &= 0xf0; in qm1d1c0042_set_params()
218 state->regs[0x07] |= (a - 4 * ((a - 12) / 4 + 1) - 5) & 0x0f; in qm1d1c0042_set_params()
219 ret = reg_write(state, 0x07, state->regs[0x07]); in qm1d1c0042_set_params()
224 val = state->regs[0x08]; in qm1d1c0042_set_params()
225 if (state->cfg.lpf) { in qm1d1c0042_set_params()
230 ret = reg_write(state, 0x08, val); in qm1d1c0042_set_params()
239 b = (s32)div64_s64(((s64) freq) << 20, state->cfg.xtal_freq) in qm1d1c0042_set_params()
247 state->regs[0x09] &= 0xc0; in qm1d1c0042_set_params()
248 state->regs[0x09] |= (sd >> 16) & 0x3f; in qm1d1c0042_set_params()
249 state->regs[0x0a] = (sd >> 8) & 0xff; in qm1d1c0042_set_params()
250 state->regs[0x0b] = sd & 0xff; in qm1d1c0042_set_params()
251 ret = reg_write(state, 0x09, state->regs[0x09]); in qm1d1c0042_set_params()
253 ret = reg_write(state, 0x0a, state->regs[0x0a]); in qm1d1c0042_set_params()
255 ret = reg_write(state, 0x0b, state->regs[0x0b]); in qm1d1c0042_set_params()
259 if (!state->cfg.lpf) { in qm1d1c0042_set_params()
261 ret = reg_write(state, 0x13, state->regs[0x13]); in qm1d1c0042_set_params()
267 mask = state->cfg.lpf ? 0x3f : 0x7f; in qm1d1c0042_set_params()
268 val = state->regs[0x0c] & mask; in qm1d1c0042_set_params()
269 ret = reg_write(state, 0x0c, val); in qm1d1c0042_set_params()
273 val = state->regs[0x0c] | ~mask; in qm1d1c0042_set_params()
274 ret = reg_write(state, 0x0c, val); in qm1d1c0042_set_params()
278 if (state->cfg.lpf) in qm1d1c0042_set_params()
279 msleep(state->cfg.lpf_wait); in qm1d1c0042_set_params()
280 else if (state->regs[0x03] & 0x01) in qm1d1c0042_set_params()
281 msleep(state->cfg.fast_srch_wait); in qm1d1c0042_set_params()
283 msleep(state->cfg.normal_srch_wait); in qm1d1c0042_set_params()
285 if (state->cfg.lpf) { in qm1d1c0042_set_params()
287 ret = reg_write(state, 0x08, 0x09); in qm1d1c0042_set_params()
292 ret = reg_write(state, 0x13, state->regs[0x13]); in qm1d1c0042_set_params()
301 struct qm1d1c0042_state *state; in qm1d1c0042_sleep() local
304 state = fe->tuner_priv; in qm1d1c0042_sleep()
305 state->regs[0x01] &= (~(1 << 3)) & 0xff; /* BB_Reg_disable */ in qm1d1c0042_sleep()
306 state->regs[0x01] |= 1 << 0; /* STDBY */ in qm1d1c0042_sleep()
307 state->regs[0x05] |= 1 << 3; /* pfd_rst STANDBY */ in qm1d1c0042_sleep()
308 ret = reg_write(state, 0x05, state->regs[0x05]); in qm1d1c0042_sleep()
310 ret = reg_write(state, 0x01, state->regs[0x01]); in qm1d1c0042_sleep()
312 dev_warn(&state->i2c->dev, "(%s) failed. [adap%d-fe%d]\n", in qm1d1c0042_sleep()
319 struct qm1d1c0042_state *state; in qm1d1c0042_init() local
323 state = fe->tuner_priv; in qm1d1c0042_init()
325 reg_write(state, 0x01, 0x0c); in qm1d1c0042_init()
326 reg_write(state, 0x01, 0x0c); in qm1d1c0042_init()
328 ret = reg_write(state, 0x01, 0x0c); /* soft reset on */ in qm1d1c0042_init()
333 ret = reg_write(state, 0x01, 0x1c); /* soft reset off */ in qm1d1c0042_init()
338 ret = reg_read(state, 0x00, &val); in qm1d1c0042_init()
350 memcpy(state->regs, reg_initval[reg_index], QM1D1C0042_NUM_REGS); in qm1d1c0042_init()
353 state->regs[0x0c] |= 0x40; in qm1d1c0042_init()
354 ret = reg_write(state, 0x0c, state->regs[0x0c]); in qm1d1c0042_init()
357 msleep(state->cfg.lpf_wait); in qm1d1c0042_init()
361 ret = reg_write(state, i, state->regs[i]); in qm1d1c0042_init()
366 ret = reg_write(state, i, state->regs[i]); in qm1d1c0042_init()
371 ret = qm1d1c0042_wakeup(state); in qm1d1c0042_init()
375 ret = qm1d1c0042_set_srch_mode(state, state->cfg.fast_srch); in qm1d1c0042_init()
382 dev_warn(&state->i2c->dev, "(%s) failed. [adap%d-fe%d]\n", in qm1d1c0042_init()
406 struct qm1d1c0042_state *state; in qm1d1c0042_probe() local
410 state = kzalloc(sizeof(*state), GFP_KERNEL); in qm1d1c0042_probe()
411 if (!state) in qm1d1c0042_probe()
413 state->i2c = client; in qm1d1c0042_probe()
417 fe->tuner_priv = state; in qm1d1c0042_probe()
421 i2c_set_clientdata(client, &state->cfg); in qm1d1c0042_probe()
428 struct qm1d1c0042_state *state; in qm1d1c0042_remove() local
430 state = cfg_to_state(i2c_get_clientdata(client)); in qm1d1c0042_remove()
431 state->cfg.fe->tuner_priv = NULL; in qm1d1c0042_remove()
432 kfree(state); in qm1d1c0042_remove()