Lines Matching +full:pinmux +full:- +full:id

1 // SPDX-License-Identifier: GPL-2.0-only
3 * drivers/mfd/si476x-i2c.c -- Core device driver for si476x MFD
21 #include <linux/mfd/si476x-core.h>
27 * si476x_core_config_pinmux() - pin function configuration function
39 dev_dbg(&core->client->dev, "Configuring pinmux\n"); 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()
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()
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()
71 "Failed to configure IC-Link/GPO pins(err = %d)\n", 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()
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()
100 schedule_delayed_work(&core->status_monitor, in si476x_core_schedule_polling_work()
105 * si476x_core_start() - early chip startup function
120 * information about power-up parameters.
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()
136 if (client->irq) in si476x_core_start()
137 enable_irq(client->irq); in si476x_core_start()
141 if (!client->irq) { in si476x_core_start()
142 atomic_set(&core->is_alive, 1); in si476x_core_start()
146 if (client->irq) in si476x_core_start()
147 enable_irq(client->irq); in si476x_core_start()
149 atomic_set(&core->is_alive, 1); in si476x_core_start()
155 &core->power_up_parameters); in si476x_core_start()
158 dev_err(&core->client->dev, in si476x_core_start()
164 if (client->irq) in si476x_core_start()
165 atomic_set(&core->is_alive, 1); in si476x_core_start()
169 dev_err(&core->client->dev, in si476x_core_start()
170 "Failed to configure pinmux(err = %d)\n", in si476x_core_start()
175 if (client->irq) { in si476x_core_start()
176 err = regmap_write(core->regmap, in si476x_core_start()
182 dev_err(&core->client->dev, in si476x_core_start()
192 if (err == -ENODEV) in si476x_core_start()
193 atomic_set(&core->is_alive, 0); in si476x_core_start()
195 if (client->irq) in si476x_core_start()
196 disable_irq(client->irq); 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()
208 * si476x_core_stop() - chip power-down function
224 atomic_set(&core->is_alive, 0); 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()
254 * si476x_core_set_power_state() - set the level at which the power is
271 So for now the power-up policy is "power-up all the things!" in si476x_core_set_power_state()
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()
278 return -EINVAL; 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()
301 core->power_state = next_state; in si476x_core_set_power_state()
305 core->power_state = next_state; 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()
325 * si476x_core_report_drainer_stop() - mark the completion of the RDS
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()
338 * si476x_core_start_rds_drainer_once() - start RDS drainer worker if
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()
353 * si476x_drain_rds_fifo() - RDS buffer drainer.
372 dev_dbg(&core->client->dev, in si476x_core_drain_rds_fifo()
374 for (; i > 0; --i) { 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()
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()
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()
476 * si476x_get_and_signal_status() - IRQ dispatcher
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()
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()
521 if (atomic_read(&core->is_alive)) in si476x_core_poll_loop()
538 * *_BOOTLOADER - Boot loader
539 * *_FM_RECEIVER - FM receiver
540 * *_AM_RECEIVER - AM receiver
541 * *_WB_RECEIVER - Weatherband receiver
549 * This function returns a positive offset in case of success and a -1
593 return -1; in si476x_core_fwver_to_revision()
597 dev_err(&core->client->dev, in si476x_core_fwver_to_revision()
611 * 1. Power-up the device
632 core->revision = si476x_core_fwver_to_revision(core, info.func, in si476x_core_get_revision_info()
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()
653 return core->chip_id == SI476X_CHIP_SI4764; in si476x_core_has_diversity()
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()
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()
676 (core->power_up_parameters.func == SI476X_FUNC_AM_RECEIVER); in si476x_core_is_in_am_receiver_mode()
682 return core->power_state == SI476X_POWER_UP_FULL; in si476x_core_is_powered_up()
687 const struct i2c_device_id *id) in si476x_core_probe() argument
695 core = devm_kzalloc(&client->dev, sizeof(*core), GFP_KERNEL); in si476x_core_probe()
697 return -ENOMEM; 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()
704 dev_err(&client->dev, 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()
715 pdata = dev_get_platdata(&client->dev); in si476x_core_probe()
717 memcpy(&core->power_up_parameters, in si476x_core_probe()
718 &pdata->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()
722 if (gpio_is_valid(pdata->gpio_reset)) { in si476x_core_probe()
723 rval = gpio_request(pdata->gpio_reset, "si476x reset"); in si476x_core_probe()
725 dev_err(&client->dev, 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()
737 dev_err(&client->dev, "No platform data provided\n"); in si476x_core_probe()
738 return -EINVAL; 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()
746 rval = devm_regulator_bulk_get(&client->dev, in si476x_core_probe()
747 ARRAY_SIZE(core->supplies), in si476x_core_probe()
748 core->supplies); in si476x_core_probe()
750 dev_err(&client->dev, "Failed to get all of the regulators\n"); 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()
763 dev_err(&client->dev, "Could not allocate the FIFO\n"); 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()
770 if (client->irq) { in si476x_core_probe()
771 rval = devm_request_threaded_irq(&client->dev, in si476x_core_probe()
772 client->irq, NULL, in si476x_core_probe()
776 client->name, core); in si476x_core_probe()
778 dev_err(&client->dev, "Could not request IRQ %d\n", in si476x_core_probe()
779 client->irq); in si476x_core_probe()
782 disable_irq(client->irq); in si476x_core_probe()
783 dev_dbg(&client->dev, "IRQ requested.\n"); 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()
789 dev_info(&client->dev, 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()
799 rval = -ENODEV; in si476x_core_probe()
805 cell = &core->cells[SI476X_RADIO_CELL]; in si476x_core_probe()
806 cell->name = "si476x-radio"; 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()
817 cell->name = "si476x-codec"; in si476x_core_probe()
821 rval = mfd_add_devices(&client->dev, in si476x_core_probe()
822 (client->adapter->nr << 8) + client->addr, 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()
843 mfd_remove_devices(&client->dev); in si476x_core_remove()
845 if (client->irq) in si476x_core_remove()
846 disable_irq(client->irq); 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()
869 .name = "si476x-core",