Lines Matching full:core
3 * drivers/mfd/si476x-i2c.c -- Core device driver for si476x MFD
21 #include <linux/mfd/si476x-core.h>
29 * @core: Core device structure
36 static int si476x_core_config_pinmux(struct si476x_core *core) in si476x_core_config_pinmux() argument
39 dev_dbg(&core->client->dev, "Configuring pinmux\n"); in si476x_core_config_pinmux()
40 err = si476x_core_cmd_dig_audio_pin_cfg(core, in si476x_core_config_pinmux()
41 core->pinmux.dclk, in si476x_core_config_pinmux()
42 core->pinmux.dfs, in si476x_core_config_pinmux()
43 core->pinmux.dout, in si476x_core_config_pinmux()
44 core->pinmux.xout); in si476x_core_config_pinmux()
46 dev_err(&core->client->dev, in si476x_core_config_pinmux()
52 err = si476x_core_cmd_zif_pin_cfg(core, in si476x_core_config_pinmux()
53 core->pinmux.iqclk, in si476x_core_config_pinmux()
54 core->pinmux.iqfs, in si476x_core_config_pinmux()
55 core->pinmux.iout, in si476x_core_config_pinmux()
56 core->pinmux.qout); in si476x_core_config_pinmux()
58 dev_err(&core->client->dev, in si476x_core_config_pinmux()
64 err = si476x_core_cmd_ic_link_gpo_ctl_pin_cfg(core, in si476x_core_config_pinmux()
65 core->pinmux.icin, in si476x_core_config_pinmux()
66 core->pinmux.icip, in si476x_core_config_pinmux()
67 core->pinmux.icon, in si476x_core_config_pinmux()
68 core->pinmux.icop); in si476x_core_config_pinmux()
70 dev_err(&core->client->dev, in si476x_core_config_pinmux()
76 err = si476x_core_cmd_ana_audio_pin_cfg(core, in si476x_core_config_pinmux()
77 core->pinmux.lrout); in si476x_core_config_pinmux()
79 dev_err(&core->client->dev, in si476x_core_config_pinmux()
85 err = si476x_core_cmd_intb_pin_cfg(core, in si476x_core_config_pinmux()
86 core->pinmux.intb, in si476x_core_config_pinmux()
87 core->pinmux.a1); in si476x_core_config_pinmux()
89 dev_err(&core->client->dev, in si476x_core_config_pinmux()
98 static inline void si476x_core_schedule_polling_work(struct si476x_core *core) in si476x_core_schedule_polling_work() argument
100 schedule_delayed_work(&core->status_monitor, in si476x_core_schedule_polling_work()
106 * @core: Core device structure
127 int si476x_core_start(struct si476x_core *core, bool soft) in si476x_core_start() argument
129 struct i2c_client *client = core->client; in si476x_core_start()
133 if (gpio_is_valid(core->gpio_reset)) in si476x_core_start()
134 gpio_set_value_cansleep(core->gpio_reset, 1); in si476x_core_start()
142 atomic_set(&core->is_alive, 1); in si476x_core_start()
143 si476x_core_schedule_polling_work(core); in si476x_core_start()
149 atomic_set(&core->is_alive, 1); in si476x_core_start()
150 si476x_core_schedule_polling_work(core); in si476x_core_start()
154 err = si476x_core_cmd_power_up(core, in si476x_core_start()
155 &core->power_up_parameters); in si476x_core_start()
158 dev_err(&core->client->dev, in si476x_core_start()
165 atomic_set(&core->is_alive, 1); in si476x_core_start()
167 err = si476x_core_config_pinmux(core); in si476x_core_start()
169 dev_err(&core->client->dev, in si476x_core_start()
176 err = regmap_write(core->regmap, in si476x_core_start()
182 dev_err(&core->client->dev, in si476x_core_start()
193 atomic_set(&core->is_alive, 0); in si476x_core_start()
198 cancel_delayed_work_sync(&core->status_monitor); in si476x_core_start()
200 if (gpio_is_valid(core->gpio_reset)) in si476x_core_start()
201 gpio_set_value_cansleep(core->gpio_reset, 0); in si476x_core_start()
209 * @core: Core device structure
221 int si476x_core_stop(struct si476x_core *core, bool soft) in si476x_core_stop() argument
224 atomic_set(&core->is_alive, 0); in si476x_core_stop()
234 err = si476x_core_cmd_power_down(core, &args); in si476x_core_stop()
240 if (core->client->irq) in si476x_core_stop()
241 disable_irq(core->client->irq); in si476x_core_stop()
243 cancel_delayed_work_sync(&core->status_monitor); in si476x_core_stop()
246 if (gpio_is_valid(core->gpio_reset)) in si476x_core_stop()
247 gpio_set_value_cansleep(core->gpio_reset, 0); in si476x_core_stop()
256 * @core: Core device structure
265 int si476x_core_set_power_state(struct si476x_core *core, in si476x_core_set_power_state() argument
275 if (core->power_state == SI476X_POWER_INCONSISTENT) { in si476x_core_set_power_state()
276 dev_err(&core->client->dev, in si476x_core_set_power_state()
281 if (next_state != core->power_state) { in si476x_core_set_power_state()
284 err = regulator_bulk_enable(ARRAY_SIZE(core->supplies), in si476x_core_set_power_state()
285 core->supplies); in si476x_core_set_power_state()
287 core->power_state = SI476X_POWER_INCONSISTENT; in si476x_core_set_power_state()
297 err = si476x_core_start(core, false); in si476x_core_set_power_state()
301 core->power_state = next_state; in si476x_core_set_power_state()
305 core->power_state = next_state; in si476x_core_set_power_state()
306 err = si476x_core_stop(core, false); in si476x_core_set_power_state()
308 core->power_state = SI476X_POWER_INCONSISTENT; in si476x_core_set_power_state()
310 err = regulator_bulk_disable(ARRAY_SIZE(core->supplies), in si476x_core_set_power_state()
311 core->supplies); in si476x_core_set_power_state()
313 core->power_state = SI476X_POWER_INCONSISTENT; in si476x_core_set_power_state()
328 * @core: Core device structure
330 static inline void si476x_core_report_drainer_stop(struct si476x_core *core) in si476x_core_report_drainer_stop() argument
332 mutex_lock(&core->rds_drainer_status_lock); in si476x_core_report_drainer_stop()
333 core->rds_drainer_is_working = false; in si476x_core_report_drainer_stop()
334 mutex_unlock(&core->rds_drainer_status_lock); in si476x_core_report_drainer_stop()
341 * @core: Datastructure corresponding to the chip.
343 static inline void si476x_core_start_rds_drainer_once(struct si476x_core *core) in si476x_core_start_rds_drainer_once() argument
345 mutex_lock(&core->rds_drainer_status_lock); in si476x_core_start_rds_drainer_once()
346 if (!core->rds_drainer_is_working) { in si476x_core_start_rds_drainer_once()
347 core->rds_drainer_is_working = true; in si476x_core_start_rds_drainer_once()
348 schedule_work(&core->rds_fifo_drainer); in si476x_core_start_rds_drainer_once()
350 mutex_unlock(&core->rds_drainer_status_lock); in si476x_core_start_rds_drainer_once()
363 struct si476x_core *core = container_of(work, struct si476x_core, in si476x_core_drain_rds_fifo() local
368 si476x_core_lock(core); in si476x_core_drain_rds_fifo()
369 err = si476x_core_cmd_fm_rds_status(core, true, false, false, &report); in si476x_core_drain_rds_fifo()
372 dev_dbg(&core->client->dev, in si476x_core_drain_rds_fifo()
375 err = si476x_core_cmd_fm_rds_status(core, false, false, in si476x_core_drain_rds_fifo()
380 kfifo_in(&core->rds_fifo, report.rds, in si476x_core_drain_rds_fifo()
382 dev_dbg(&core->client->dev, "RDS data:\n %*ph\n", in si476x_core_drain_rds_fifo()
385 dev_dbg(&core->client->dev, "Drrrrained!\n"); in si476x_core_drain_rds_fifo()
386 wake_up_interruptible(&core->rds_read_queue); in si476x_core_drain_rds_fifo()
390 si476x_core_unlock(core); in si476x_core_drain_rds_fifo()
391 si476x_core_report_drainer_stop(core); in si476x_core_drain_rds_fifo()
397 * @core: Core device structure
403 static void si476x_core_pronounce_dead(struct si476x_core *core) in si476x_core_pronounce_dead() argument
405 dev_info(&core->client->dev, "Core device is dead.\n"); in si476x_core_pronounce_dead()
407 atomic_set(&core->is_alive, 0); in si476x_core_pronounce_dead()
410 wake_up_interruptible(&core->rds_read_queue); in si476x_core_pronounce_dead()
412 atomic_set(&core->cts, 1); in si476x_core_pronounce_dead()
413 wake_up(&core->command); in si476x_core_pronounce_dead()
415 atomic_set(&core->stc, 1); in si476x_core_pronounce_dead()
416 wake_up(&core->tuning); in si476x_core_pronounce_dead()
422 * @core: Core device structure
434 int si476x_core_i2c_xfer(struct si476x_core *core, in si476x_core_i2c_xfer() argument
441 err = i2c_master_send(core->client, buf, count); in si476x_core_i2c_xfer()
443 err = i2c_master_recv(core->client, buf, count); in si476x_core_i2c_xfer()
447 si476x_core_pronounce_dead(core); in si476x_core_i2c_xfer()
458 * @core: Core device structure
460 * Get the status byte of the core device by berforming one byte I2C
466 static int si476x_core_get_status(struct si476x_core *core) in si476x_core_get_status() argument
469 int err = si476x_core_i2c_xfer(core, SI476X_I2C_RECV, in si476x_core_get_status()
477 * @core: Core device structure
483 static void si476x_core_get_and_signal_status(struct si476x_core *core) in si476x_core_get_and_signal_status() argument
485 int status = si476x_core_get_status(core); in si476x_core_get_and_signal_status()
487 dev_err(&core->client->dev, "Failed to get status\n"); in si476x_core_get_and_signal_status()
498 dev_dbg(&core->client->dev, "[interrupt] CTSINT\n"); in si476x_core_get_and_signal_status()
499 atomic_set(&core->cts, 1); in si476x_core_get_and_signal_status()
500 wake_up(&core->command); in si476x_core_get_and_signal_status()
504 dev_dbg(&core->client->dev, "[interrupt] RDSINT\n"); in si476x_core_get_and_signal_status()
505 si476x_core_start_rds_drainer_once(core); in si476x_core_get_and_signal_status()
509 dev_dbg(&core->client->dev, "[interrupt] STCINT\n"); in si476x_core_get_and_signal_status()
510 atomic_set(&core->stc, 1); in si476x_core_get_and_signal_status()
511 wake_up(&core->tuning); in si476x_core_get_and_signal_status()
517 struct si476x_core *core = SI476X_WORK_TO_CORE(work); in si476x_core_poll_loop() local
519 si476x_core_get_and_signal_status(core); in si476x_core_poll_loop()
521 if (atomic_read(&core->is_alive)) in si476x_core_poll_loop()
522 si476x_core_schedule_polling_work(core); in si476x_core_poll_loop()
527 struct si476x_core *core = dev; in si476x_core_interrupt() local
529 si476x_core_get_and_signal_status(core); in si476x_core_interrupt()
536 * @core: Core device structure
552 static int si476x_core_fwver_to_revision(struct si476x_core *core, in si476x_core_fwver_to_revision() argument
597 dev_err(&core->client->dev, in si476x_core_fwver_to_revision()
607 * @core: Core device structure
618 static int si476x_core_get_revision_info(struct si476x_core *core) in si476x_core_get_revision_info() argument
623 si476x_core_lock(core); in si476x_core_get_revision_info()
624 rval = si476x_core_set_power_state(core, SI476X_POWER_UP_FULL); in si476x_core_get_revision_info()
628 rval = si476x_core_cmd_func_info(core, &info); in si476x_core_get_revision_info()
632 core->revision = si476x_core_fwver_to_revision(core, info.func, in si476x_core_get_revision_info()
637 si476x_core_set_power_state(core, SI476X_POWER_DOWN); in si476x_core_get_revision_info()
639 si476x_core_unlock(core); in si476x_core_get_revision_info()
644 bool si476x_core_has_am(struct si476x_core *core) in si476x_core_has_am() argument
646 return core->chip_id == SI476X_CHIP_SI4761 || in si476x_core_has_am()
647 core->chip_id == SI476X_CHIP_SI4764; in si476x_core_has_am()
651 bool si476x_core_has_diversity(struct si476x_core *core) in si476x_core_has_diversity() argument
653 return core->chip_id == SI476X_CHIP_SI4764; in si476x_core_has_diversity()
657 bool si476x_core_is_a_secondary_tuner(struct si476x_core *core) in si476x_core_is_a_secondary_tuner() argument
659 return si476x_core_has_diversity(core) && in si476x_core_is_a_secondary_tuner()
660 (core->diversity_mode == SI476X_PHDIV_SECONDARY_ANTENNA || in si476x_core_is_a_secondary_tuner()
661 core->diversity_mode == SI476X_PHDIV_SECONDARY_COMBINING); in si476x_core_is_a_secondary_tuner()
665 bool si476x_core_is_a_primary_tuner(struct si476x_core *core) in si476x_core_is_a_primary_tuner() argument
667 return si476x_core_has_diversity(core) && in si476x_core_is_a_primary_tuner()
668 (core->diversity_mode == SI476X_PHDIV_PRIMARY_ANTENNA || in si476x_core_is_a_primary_tuner()
669 core->diversity_mode == SI476X_PHDIV_PRIMARY_COMBINING); in si476x_core_is_a_primary_tuner()
673 bool si476x_core_is_in_am_receiver_mode(struct si476x_core *core) in si476x_core_is_in_am_receiver_mode() argument
675 return si476x_core_has_am(core) && in si476x_core_is_in_am_receiver_mode()
676 (core->power_up_parameters.func == SI476X_FUNC_AM_RECEIVER); in si476x_core_is_in_am_receiver_mode()
680 bool si476x_core_is_powered_up(struct si476x_core *core) in si476x_core_is_powered_up() argument
682 return core->power_state == SI476X_POWER_UP_FULL; in si476x_core_is_powered_up()
690 struct si476x_core *core; in si476x_core_probe() local
695 core = devm_kzalloc(&client->dev, sizeof(*core), GFP_KERNEL); in si476x_core_probe()
696 if (!core) in si476x_core_probe()
699 core->client = client; in si476x_core_probe()
701 core->regmap = devm_regmap_init_si476x(core); in si476x_core_probe()
702 if (IS_ERR(core->regmap)) { in si476x_core_probe()
703 rval = PTR_ERR(core->regmap); in si476x_core_probe()
710 i2c_set_clientdata(client, core); in si476x_core_probe()
712 atomic_set(&core->is_alive, 0); in si476x_core_probe()
713 core->power_state = SI476X_POWER_DOWN; in si476x_core_probe()
717 memcpy(&core->power_up_parameters, in si476x_core_probe()
719 sizeof(core->power_up_parameters)); in si476x_core_probe()
721 core->gpio_reset = -1; in si476x_core_probe()
729 core->gpio_reset = pdata->gpio_reset; in si476x_core_probe()
730 gpio_direction_output(core->gpio_reset, 0); in si476x_core_probe()
733 core->diversity_mode = pdata->diversity_mode; in si476x_core_probe()
734 memcpy(&core->pinmux, &pdata->pinmux, in si476x_core_probe()
741 core->supplies[0].supply = "vd"; in si476x_core_probe()
742 core->supplies[1].supply = "va"; in si476x_core_probe()
743 core->supplies[2].supply = "vio1"; in si476x_core_probe()
744 core->supplies[3].supply = "vio2"; in si476x_core_probe()
747 ARRAY_SIZE(core->supplies), in si476x_core_probe()
748 core->supplies); in si476x_core_probe()
754 mutex_init(&core->cmd_lock); in si476x_core_probe()
755 init_waitqueue_head(&core->command); in si476x_core_probe()
756 init_waitqueue_head(&core->tuning); in si476x_core_probe()
758 rval = kfifo_alloc(&core->rds_fifo, in si476x_core_probe()
766 mutex_init(&core->rds_drainer_status_lock); in si476x_core_probe()
767 init_waitqueue_head(&core->rds_read_queue); in si476x_core_probe()
768 INIT_WORK(&core->rds_fifo_drainer, si476x_core_drain_rds_fifo); in si476x_core_probe()
776 client->name, core); in si476x_core_probe()
785 core->rds_fifo_depth = 20; in si476x_core_probe()
787 INIT_DELAYED_WORK(&core->status_monitor, in si476x_core_probe()
792 core->rds_fifo_depth = 5; in si476x_core_probe()
795 core->chip_id = id->driver_data; in si476x_core_probe()
797 rval = si476x_core_get_revision_info(core); in si476x_core_probe()
805 cell = &core->cells[SI476X_RADIO_CELL]; in si476x_core_probe()
810 if ((core->chip_id == SI476X_CHIP_SI4761 || in si476x_core_probe()
811 core->chip_id == SI476X_CHIP_SI4764) && in si476x_core_probe()
812 core->pinmux.dclk == SI476X_DCLK_DAUDIO && in si476x_core_probe()
813 core->pinmux.dfs == SI476X_DFS_DAUDIO && in si476x_core_probe()
814 core->pinmux.dout == SI476X_DOUT_I2S_OUTPUT && in si476x_core_probe()
815 core->pinmux.xout == SI476X_XOUT_TRISTATE) { in si476x_core_probe()
816 cell = &core->cells[SI476X_CODEC_CELL]; in si476x_core_probe()
823 core->cells, cell_num, in si476x_core_probe()
829 kfifo_free(&core->rds_fifo); in si476x_core_probe()
832 if (gpio_is_valid(core->gpio_reset)) in si476x_core_probe()
833 gpio_free(core->gpio_reset); in si476x_core_probe()
840 struct si476x_core *core = i2c_get_clientdata(client); in si476x_core_remove() local
842 si476x_core_pronounce_dead(core); in si476x_core_remove()
848 cancel_delayed_work_sync(&core->status_monitor); in si476x_core_remove()
850 kfifo_free(&core->rds_fifo); in si476x_core_remove()
852 if (gpio_is_valid(core->gpio_reset)) in si476x_core_remove()
853 gpio_free(core->gpio_reset); in si476x_core_remove()
867 .name = "si476x-core",
877 MODULE_DESCRIPTION("Si4761/64/68 AM/FM MFD core device driver");