Lines Matching refs:core

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