Lines Matching refs:core

45 static int si476x_core_config_pinmux(struct si476x_core *core)  in si476x_core_config_pinmux()  argument
48 dev_dbg(&core->client->dev, "Configuring pinmux\n"); in si476x_core_config_pinmux()
49 err = si476x_core_cmd_dig_audio_pin_cfg(core, in si476x_core_config_pinmux()
50 core->pinmux.dclk, in si476x_core_config_pinmux()
51 core->pinmux.dfs, in si476x_core_config_pinmux()
52 core->pinmux.dout, in si476x_core_config_pinmux()
53 core->pinmux.xout); in si476x_core_config_pinmux()
55 dev_err(&core->client->dev, in si476x_core_config_pinmux()
61 err = si476x_core_cmd_zif_pin_cfg(core, in si476x_core_config_pinmux()
62 core->pinmux.iqclk, in si476x_core_config_pinmux()
63 core->pinmux.iqfs, in si476x_core_config_pinmux()
64 core->pinmux.iout, in si476x_core_config_pinmux()
65 core->pinmux.qout); in si476x_core_config_pinmux()
67 dev_err(&core->client->dev, in si476x_core_config_pinmux()
73 err = si476x_core_cmd_ic_link_gpo_ctl_pin_cfg(core, in si476x_core_config_pinmux()
74 core->pinmux.icin, in si476x_core_config_pinmux()
75 core->pinmux.icip, in si476x_core_config_pinmux()
76 core->pinmux.icon, in si476x_core_config_pinmux()
77 core->pinmux.icop); in si476x_core_config_pinmux()
79 dev_err(&core->client->dev, in si476x_core_config_pinmux()
85 err = si476x_core_cmd_ana_audio_pin_cfg(core, in si476x_core_config_pinmux()
86 core->pinmux.lrout); in si476x_core_config_pinmux()
88 dev_err(&core->client->dev, in si476x_core_config_pinmux()
94 err = si476x_core_cmd_intb_pin_cfg(core, in si476x_core_config_pinmux()
95 core->pinmux.intb, in si476x_core_config_pinmux()
96 core->pinmux.a1); in si476x_core_config_pinmux()
98 dev_err(&core->client->dev, in si476x_core_config_pinmux()
107 static inline void si476x_core_schedule_polling_work(struct si476x_core *core) in si476x_core_schedule_polling_work() argument
109 schedule_delayed_work(&core->status_monitor, in si476x_core_schedule_polling_work()
136 int si476x_core_start(struct si476x_core *core, bool soft) in si476x_core_start() argument
138 struct i2c_client *client = core->client; in si476x_core_start()
142 if (gpio_is_valid(core->gpio_reset)) in si476x_core_start()
143 gpio_set_value_cansleep(core->gpio_reset, 1); in si476x_core_start()
151 atomic_set(&core->is_alive, 1); in si476x_core_start()
152 si476x_core_schedule_polling_work(core); in si476x_core_start()
158 atomic_set(&core->is_alive, 1); in si476x_core_start()
159 si476x_core_schedule_polling_work(core); in si476x_core_start()
163 err = si476x_core_cmd_power_up(core, in si476x_core_start()
164 &core->power_up_parameters); in si476x_core_start()
167 dev_err(&core->client->dev, in si476x_core_start()
174 atomic_set(&core->is_alive, 1); in si476x_core_start()
176 err = si476x_core_config_pinmux(core); in si476x_core_start()
178 dev_err(&core->client->dev, in si476x_core_start()
185 err = regmap_write(core->regmap, in si476x_core_start()
191 dev_err(&core->client->dev, in si476x_core_start()
202 atomic_set(&core->is_alive, 0); in si476x_core_start()
207 cancel_delayed_work_sync(&core->status_monitor); in si476x_core_start()
209 if (gpio_is_valid(core->gpio_reset)) in si476x_core_start()
210 gpio_set_value_cansleep(core->gpio_reset, 0); in si476x_core_start()
230 int si476x_core_stop(struct si476x_core *core, bool soft) in si476x_core_stop() argument
233 atomic_set(&core->is_alive, 0); in si476x_core_stop()
243 err = si476x_core_cmd_power_down(core, &args); in si476x_core_stop()
249 if (core->client->irq) in si476x_core_stop()
250 disable_irq(core->client->irq); in si476x_core_stop()
252 cancel_delayed_work_sync(&core->status_monitor); in si476x_core_stop()
255 if (gpio_is_valid(core->gpio_reset)) in si476x_core_stop()
256 gpio_set_value_cansleep(core->gpio_reset, 0); in si476x_core_stop()
274 int si476x_core_set_power_state(struct si476x_core *core, in si476x_core_set_power_state() argument
284 if (core->power_state == SI476X_POWER_INCONSISTENT) { in si476x_core_set_power_state()
285 dev_err(&core->client->dev, in si476x_core_set_power_state()
290 if (next_state != core->power_state) { in si476x_core_set_power_state()
293 err = regulator_bulk_enable(ARRAY_SIZE(core->supplies), in si476x_core_set_power_state()
294 core->supplies); in si476x_core_set_power_state()
296 core->power_state = SI476X_POWER_INCONSISTENT; in si476x_core_set_power_state()
306 err = si476x_core_start(core, false); in si476x_core_set_power_state()
310 core->power_state = next_state; in si476x_core_set_power_state()
314 core->power_state = next_state; in si476x_core_set_power_state()
315 err = si476x_core_stop(core, false); in si476x_core_set_power_state()
317 core->power_state = SI476X_POWER_INCONSISTENT; in si476x_core_set_power_state()
319 err = regulator_bulk_disable(ARRAY_SIZE(core->supplies), in si476x_core_set_power_state()
320 core->supplies); in si476x_core_set_power_state()
322 core->power_state = SI476X_POWER_INCONSISTENT; in si476x_core_set_power_state()
339 static inline void si476x_core_report_drainer_stop(struct si476x_core *core) in si476x_core_report_drainer_stop() argument
341 mutex_lock(&core->rds_drainer_status_lock); in si476x_core_report_drainer_stop()
342 core->rds_drainer_is_working = false; in si476x_core_report_drainer_stop()
343 mutex_unlock(&core->rds_drainer_status_lock); in si476x_core_report_drainer_stop()
352 static inline void si476x_core_start_rds_drainer_once(struct si476x_core *core) in si476x_core_start_rds_drainer_once() argument
354 mutex_lock(&core->rds_drainer_status_lock); in si476x_core_start_rds_drainer_once()
355 if (!core->rds_drainer_is_working) { in si476x_core_start_rds_drainer_once()
356 core->rds_drainer_is_working = true; in si476x_core_start_rds_drainer_once()
357 schedule_work(&core->rds_fifo_drainer); in si476x_core_start_rds_drainer_once()
359 mutex_unlock(&core->rds_drainer_status_lock); in si476x_core_start_rds_drainer_once()
372 struct si476x_core *core = container_of(work, struct si476x_core, in si476x_core_drain_rds_fifo() local
377 si476x_core_lock(core); in si476x_core_drain_rds_fifo()
378 err = si476x_core_cmd_fm_rds_status(core, true, false, false, &report); in si476x_core_drain_rds_fifo()
381 dev_dbg(&core->client->dev, in si476x_core_drain_rds_fifo()
384 err = si476x_core_cmd_fm_rds_status(core, false, false, in si476x_core_drain_rds_fifo()
389 kfifo_in(&core->rds_fifo, report.rds, in si476x_core_drain_rds_fifo()
391 dev_dbg(&core->client->dev, "RDS data:\n %*ph\n", in si476x_core_drain_rds_fifo()
394 dev_dbg(&core->client->dev, "Drrrrained!\n"); in si476x_core_drain_rds_fifo()
395 wake_up_interruptible(&core->rds_read_queue); in si476x_core_drain_rds_fifo()
399 si476x_core_unlock(core); in si476x_core_drain_rds_fifo()
400 si476x_core_report_drainer_stop(core); in si476x_core_drain_rds_fifo()
412 static void si476x_core_pronounce_dead(struct si476x_core *core) in si476x_core_pronounce_dead() argument
414 dev_info(&core->client->dev, "Core device is dead.\n"); in si476x_core_pronounce_dead()
416 atomic_set(&core->is_alive, 0); in si476x_core_pronounce_dead()
419 wake_up_interruptible(&core->rds_read_queue); in si476x_core_pronounce_dead()
421 atomic_set(&core->cts, 1); in si476x_core_pronounce_dead()
422 wake_up(&core->command); in si476x_core_pronounce_dead()
424 atomic_set(&core->stc, 1); in si476x_core_pronounce_dead()
425 wake_up(&core->tuning); in si476x_core_pronounce_dead()
443 int si476x_core_i2c_xfer(struct si476x_core *core, in si476x_core_i2c_xfer() argument
450 err = i2c_master_send(core->client, buf, count); in si476x_core_i2c_xfer()
452 err = i2c_master_recv(core->client, buf, count); in si476x_core_i2c_xfer()
456 si476x_core_pronounce_dead(core); in si476x_core_i2c_xfer()
475 static int si476x_core_get_status(struct si476x_core *core) in si476x_core_get_status() argument
478 int err = si476x_core_i2c_xfer(core, SI476X_I2C_RECV, in si476x_core_get_status()
492 static void si476x_core_get_and_signal_status(struct si476x_core *core) in si476x_core_get_and_signal_status() argument
494 int status = si476x_core_get_status(core); in si476x_core_get_and_signal_status()
496 dev_err(&core->client->dev, "Failed to get status\n"); in si476x_core_get_and_signal_status()
507 dev_dbg(&core->client->dev, "[interrupt] CTSINT\n"); in si476x_core_get_and_signal_status()
508 atomic_set(&core->cts, 1); in si476x_core_get_and_signal_status()
509 wake_up(&core->command); in si476x_core_get_and_signal_status()
513 dev_dbg(&core->client->dev, "[interrupt] RDSINT\n"); in si476x_core_get_and_signal_status()
514 si476x_core_start_rds_drainer_once(core); in si476x_core_get_and_signal_status()
518 dev_dbg(&core->client->dev, "[interrupt] STCINT\n"); in si476x_core_get_and_signal_status()
519 atomic_set(&core->stc, 1); in si476x_core_get_and_signal_status()
520 wake_up(&core->tuning); in si476x_core_get_and_signal_status()
526 struct si476x_core *core = SI476X_WORK_TO_CORE(work); in si476x_core_poll_loop() local
528 si476x_core_get_and_signal_status(core); in si476x_core_poll_loop()
530 if (atomic_read(&core->is_alive)) in si476x_core_poll_loop()
531 si476x_core_schedule_polling_work(core); in si476x_core_poll_loop()
536 struct si476x_core *core = dev; in si476x_core_interrupt() local
538 si476x_core_get_and_signal_status(core); in si476x_core_interrupt()
556 static int si476x_core_fwver_to_revision(struct si476x_core *core, in si476x_core_fwver_to_revision() argument
601 dev_err(&core->client->dev, in si476x_core_fwver_to_revision()
622 static int si476x_core_get_revision_info(struct si476x_core *core) in si476x_core_get_revision_info() argument
627 si476x_core_lock(core); in si476x_core_get_revision_info()
628 rval = si476x_core_set_power_state(core, SI476X_POWER_UP_FULL); in si476x_core_get_revision_info()
632 rval = si476x_core_cmd_func_info(core, &info); in si476x_core_get_revision_info()
636 core->revision = si476x_core_fwver_to_revision(core, info.func, in si476x_core_get_revision_info()
641 si476x_core_set_power_state(core, SI476X_POWER_DOWN); in si476x_core_get_revision_info()
643 si476x_core_unlock(core); in si476x_core_get_revision_info()
648 bool si476x_core_has_am(struct si476x_core *core) in si476x_core_has_am() argument
650 return core->chip_id == SI476X_CHIP_SI4761 || in si476x_core_has_am()
651 core->chip_id == SI476X_CHIP_SI4764; in si476x_core_has_am()
655 bool si476x_core_has_diversity(struct si476x_core *core) in si476x_core_has_diversity() argument
657 return core->chip_id == SI476X_CHIP_SI4764; in si476x_core_has_diversity()
661 bool si476x_core_is_a_secondary_tuner(struct si476x_core *core) in si476x_core_is_a_secondary_tuner() argument
663 return si476x_core_has_diversity(core) && in si476x_core_is_a_secondary_tuner()
664 (core->diversity_mode == SI476X_PHDIV_SECONDARY_ANTENNA || in si476x_core_is_a_secondary_tuner()
665 core->diversity_mode == SI476X_PHDIV_SECONDARY_COMBINING); in si476x_core_is_a_secondary_tuner()
669 bool si476x_core_is_a_primary_tuner(struct si476x_core *core) in si476x_core_is_a_primary_tuner() argument
671 return si476x_core_has_diversity(core) && in si476x_core_is_a_primary_tuner()
672 (core->diversity_mode == SI476X_PHDIV_PRIMARY_ANTENNA || in si476x_core_is_a_primary_tuner()
673 core->diversity_mode == SI476X_PHDIV_PRIMARY_COMBINING); in si476x_core_is_a_primary_tuner()
677 bool si476x_core_is_in_am_receiver_mode(struct si476x_core *core) in si476x_core_is_in_am_receiver_mode() argument
679 return si476x_core_has_am(core) && in si476x_core_is_in_am_receiver_mode()
680 (core->power_up_parameters.func == SI476X_FUNC_AM_RECEIVER); in si476x_core_is_in_am_receiver_mode()
684 bool si476x_core_is_powered_up(struct si476x_core *core) in si476x_core_is_powered_up() argument
686 return core->power_state == SI476X_POWER_UP_FULL; in si476x_core_is_powered_up()
694 struct si476x_core *core; in si476x_core_probe() local
699 core = devm_kzalloc(&client->dev, sizeof(*core), GFP_KERNEL); in si476x_core_probe()
700 if (!core) { in si476x_core_probe()
705 core->client = client; in si476x_core_probe()
707 core->regmap = devm_regmap_init_si476x(core); in si476x_core_probe()
708 if (IS_ERR(core->regmap)) { in si476x_core_probe()
709 rval = PTR_ERR(core->regmap); in si476x_core_probe()
716 i2c_set_clientdata(client, core); in si476x_core_probe()
718 atomic_set(&core->is_alive, 0); in si476x_core_probe()
719 core->power_state = SI476X_POWER_DOWN; in si476x_core_probe()
723 memcpy(&core->power_up_parameters, in si476x_core_probe()
725 sizeof(core->power_up_parameters)); in si476x_core_probe()
727 core->gpio_reset = -1; in si476x_core_probe()
735 core->gpio_reset = pdata->gpio_reset; in si476x_core_probe()
736 gpio_direction_output(core->gpio_reset, 0); in si476x_core_probe()
739 core->diversity_mode = pdata->diversity_mode; in si476x_core_probe()
740 memcpy(&core->pinmux, &pdata->pinmux, in si476x_core_probe()
747 core->supplies[0].supply = "vd"; in si476x_core_probe()
748 core->supplies[1].supply = "va"; in si476x_core_probe()
749 core->supplies[2].supply = "vio1"; in si476x_core_probe()
750 core->supplies[3].supply = "vio2"; in si476x_core_probe()
753 ARRAY_SIZE(core->supplies), in si476x_core_probe()
754 core->supplies); in si476x_core_probe()
760 mutex_init(&core->cmd_lock); in si476x_core_probe()
761 init_waitqueue_head(&core->command); in si476x_core_probe()
762 init_waitqueue_head(&core->tuning); in si476x_core_probe()
764 rval = kfifo_alloc(&core->rds_fifo, in si476x_core_probe()
772 mutex_init(&core->rds_drainer_status_lock); in si476x_core_probe()
773 init_waitqueue_head(&core->rds_read_queue); in si476x_core_probe()
774 INIT_WORK(&core->rds_fifo_drainer, si476x_core_drain_rds_fifo); in si476x_core_probe()
781 client->name, core); in si476x_core_probe()
790 core->rds_fifo_depth = 20; in si476x_core_probe()
792 INIT_DELAYED_WORK(&core->status_monitor, in si476x_core_probe()
797 core->rds_fifo_depth = 5; in si476x_core_probe()
800 core->chip_id = id->driver_data; in si476x_core_probe()
802 rval = si476x_core_get_revision_info(core); in si476x_core_probe()
810 cell = &core->cells[SI476X_RADIO_CELL]; in si476x_core_probe()
815 if ((core->chip_id == SI476X_CHIP_SI4761 || in si476x_core_probe()
816 core->chip_id == SI476X_CHIP_SI4764) && in si476x_core_probe()
817 core->pinmux.dclk == SI476X_DCLK_DAUDIO && in si476x_core_probe()
818 core->pinmux.dfs == SI476X_DFS_DAUDIO && in si476x_core_probe()
819 core->pinmux.dout == SI476X_DOUT_I2S_OUTPUT && in si476x_core_probe()
820 core->pinmux.xout == SI476X_XOUT_TRISTATE) { in si476x_core_probe()
821 cell = &core->cells[SI476X_CODEC_CELL]; in si476x_core_probe()
828 core->cells, cell_num, in si476x_core_probe()
834 kfifo_free(&core->rds_fifo); in si476x_core_probe()
837 if (gpio_is_valid(core->gpio_reset)) in si476x_core_probe()
838 gpio_free(core->gpio_reset); in si476x_core_probe()
845 struct si476x_core *core = i2c_get_clientdata(client); in si476x_core_remove() local
847 si476x_core_pronounce_dead(core); in si476x_core_remove()
853 cancel_delayed_work_sync(&core->status_monitor); in si476x_core_remove()
855 kfifo_free(&core->rds_fifo); in si476x_core_remove()
857 if (gpio_is_valid(core->gpio_reset)) in si476x_core_remove()
858 gpio_free(core->gpio_reset); in si476x_core_remove()