Lines Matching +full:preemphasis +full:- +full:level

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * drivers/media/radio/si4713-i2c.c
19 #include <media/v4l2-device.h>
20 #include <media/v4l2-ioctl.h>
21 #include <media/v4l2-common.h>
28 MODULE_PARM_DESC(debug, "Debug level (0 - 2)");
46 #define DEFAULT_ACOMP_THRESHOLD (-0x28)
146 * Values for preemphasis (sorted by second column)
147 * device preemphasis
160 int rval = -EINVAL; in usecs_to_dev()
176 v4l2_dbg(2, debug, &sdev->sd, in si4713_handler()
178 complete(&sdev->work); in si4713_handler()
184 * si4713_send_command - sends a command to si4713 and waits its response
197 struct i2c_client *client = v4l2_get_subdevdata(&sdev->sd); in si4713_send_command()
202 if (!client->adapter) in si4713_send_command()
203 return -ENODEV; in si4713_send_command()
208 DBG_BUFFER(&sdev->sd, "Parameters", data1, argn + 1); in si4713_send_command()
212 v4l2_err(&sdev->sd, "Error while sending command 0x%02x\n", in si4713_send_command()
214 return err < 0 ? err : -EIO; in si4713_send_command()
220 if (client->irq) { in si4713_send_command()
221 if (!wait_for_completion_timeout(&sdev->work, in si4713_send_command()
223 v4l2_warn(&sdev->sd, in si4713_send_command()
231 v4l2_err(&sdev->sd, in si4713_send_command()
234 return err < 0 ? err : -EIO; in si4713_send_command()
237 DBG_BUFFER(&sdev->sd, "Response", response, respn); in si4713_send_command()
241 if (client->irq) in si4713_send_command()
242 return -EBUSY; in si4713_send_command()
249 return -EBUSY; in si4713_send_command()
253 * si4713_read_property - reads a si4713 property
282 v4l2_dbg(1, debug, &sdev->sd, in si4713_read_property()
290 * si4713_write_property - modifies a si4713 property
322 v4l2_dbg(1, debug, &sdev->sd, in si4713_write_property()
337 * si4713_powerup - Powers the device up
342 struct i2c_client *client = v4l2_get_subdevdata(&sdev->sd); in si4713_powerup()
354 if (sdev->power_state) in si4713_powerup()
357 if (sdev->vdd) { in si4713_powerup()
358 err = regulator_enable(sdev->vdd); in si4713_powerup()
360 v4l2_err(&sdev->sd, "Failed to enable vdd: %d\n", err); in si4713_powerup()
365 if (sdev->vio) { in si4713_powerup()
366 err = regulator_enable(sdev->vio); in si4713_powerup()
368 v4l2_err(&sdev->sd, "Failed to enable vio: %d\n", err); in si4713_powerup()
373 if (sdev->gpio_reset) { in si4713_powerup()
375 gpiod_set_value(sdev->gpio_reset, 1); in si4713_powerup()
378 if (client->irq) in si4713_powerup()
387 v4l2_dbg(1, debug, &sdev->sd, "Powerup response: 0x%02x\n", in si4713_powerup()
389 v4l2_dbg(1, debug, &sdev->sd, "Device in power up mode\n"); in si4713_powerup()
390 sdev->power_state = POWER_ON; in si4713_powerup()
392 if (client->irq) in si4713_powerup()
397 gpiod_set_value(sdev->gpio_reset, 0); in si4713_powerup()
400 if (sdev->vdd) { in si4713_powerup()
401 err = regulator_disable(sdev->vdd); in si4713_powerup()
403 v4l2_err(&sdev->sd, "Failed to disable vdd: %d\n", err); in si4713_powerup()
406 if (sdev->vio) { in si4713_powerup()
407 err = regulator_disable(sdev->vio); in si4713_powerup()
409 v4l2_err(&sdev->sd, "Failed to disable vio: %d\n", err); in si4713_powerup()
416 * si4713_powerdown - Powers the device down
424 if (!sdev->power_state) in si4713_powerdown()
433 v4l2_dbg(1, debug, &sdev->sd, "Power down response: 0x%02x\n", in si4713_powerdown()
435 v4l2_dbg(1, debug, &sdev->sd, "Device in reset mode\n"); in si4713_powerdown()
436 if (sdev->gpio_reset) in si4713_powerdown()
437 gpiod_set_value(sdev->gpio_reset, 0); in si4713_powerdown()
439 if (sdev->vdd) { in si4713_powerdown()
440 err = regulator_disable(sdev->vdd); in si4713_powerdown()
442 v4l2_err(&sdev->sd, in si4713_powerdown()
447 if (sdev->vio) { in si4713_powerdown()
448 err = regulator_disable(sdev->vio); in si4713_powerdown()
450 v4l2_err(&sdev->sd, in si4713_powerdown()
454 sdev->power_state = POWER_OFF; in si4713_powerdown()
461 * si4713_checkrev - Checks if we are treating a device with the correct rev.
466 struct i2c_client *client = v4l2_get_subdevdata(&sdev->sd); in si4713_checkrev()
479 v4l2_info(&sdev->sd, "chip found @ 0x%02x (%s)\n", in si4713_checkrev()
480 client->addr << 1, client->adapter->name); in si4713_checkrev()
482 v4l2_err(&sdev->sd, "Invalid product number 0x%X\n", resp[1]); in si4713_checkrev()
483 rval = -EINVAL; in si4713_checkrev()
489 * si4713_wait_stc - Waits STC interrupt and clears status bits. Useful
496 struct i2c_client *client = v4l2_get_subdevdata(&sdev->sd); in si4713_wait_stc()
501 if (client->irq && in si4713_wait_stc()
502 !wait_for_completion_timeout(&sdev->work, usecs_to_jiffies(usecs) + 1)) in si4713_wait_stc()
503 v4l2_warn(&sdev->sd, in si4713_wait_stc()
515 v4l2_dbg(1, debug, &sdev->sd, in si4713_wait_stc()
521 if (jiffies_to_usecs(jiffies - start_jiffies) > usecs) in si4713_wait_stc()
522 return err < 0 ? err : -EIO; in si4713_wait_stc()
523 /* We sleep here for 3-4 ms in order to avoid flooding the device in si4713_wait_stc()
532 * si4713_tx_tune_freq - Sets the state of the RF carrier and sets the tuning
536 * @frequency: desired frequency (76 - 108 MHz, unit 10 KHz, step 50 kHz)
560 v4l2_dbg(1, debug, &sdev->sd, in si4713_tx_tune_freq()
572 * si4713_tx_tune_power - Sets the RF voltage level between 88 and 120 dBuV in
575 * indicates autotuning, and a value of 1 - 191 indicates
579 * @power: tuning power (88 - 120 dBuV, unit/step 1 dB)
580 * @antcap: value of antenna tuning capacitor (0 - 191)
600 /* Map power values 1-87 to MIN_POWER (88) */ in si4713_tx_tune_power()
611 v4l2_dbg(1, debug, &sdev->sd, in si4713_tx_tune_power()
619 * si4713_tx_tune_measure - Enters receive mode and measures the received noise
620 * level in units of dBuV on the selected frequency.
627 * @frequency: desired frequency (76 - 108 MHz, unit 10 KHz, step 50 kHz)
628 * @antcap: value of antenna tuning capacitor (0 - 191)
648 sdev->tune_rnl = DEFAULT_TUNE_RNL; in si4713_tx_tune_measure()
651 return -EDOM; in si4713_tx_tune_measure()
660 v4l2_dbg(1, debug, &sdev->sd, in si4713_tx_tune_measure()
668 * si4713_tx_tune_status- Returns the status of the tx_tune_freq, tx_tune_mea or
671 * capacitance value and the received noise level. The
679 * @noise: returned noise level
699 v4l2_dbg(1, debug, &sdev->sd, in si4713_tx_tune_status()
702 sdev->frequency = *frequency; in si4713_tx_tune_status()
706 v4l2_dbg(1, debug, &sdev->sd, in si4713_tx_tune_status()
715 * si4713_tx_rds_buff - Loads the RDS group buffer FIFO or circular buffer.
745 v4l2_dbg(1, debug, &sdev->sd, in si4713_tx_rds_buff()
747 *cbleft = (s8)val[2] - val[3]; in si4713_tx_rds_buff()
748 v4l2_dbg(1, debug, &sdev->sd, in si4713_tx_rds_buff()
757 * si4713_tx_rds_ps - Loads the program service buffer.
783 v4l2_dbg(1, debug, &sdev->sd, "%s: status=0x%02x\n", __func__, val[0]); in si4713_tx_rds_ps()
801 if (sdev->power_state) in si4713_set_mute()
817 if (sdev->power_state) { in si4713_set_rds_ps_name()
828 len = strlen(ps_name) - 1; in si4713_set_rds_ps_name()
856 if (!sdev->power_state) in si4713_set_rds_radio_text()
899 * si4713_update_tune_status - update properties from tx_tune_status
900 * command. Must be called with sdev->mutex held.
917 sdev->power_level = p; in si4713_update_tune_status()
918 sdev->antenna_capacitor = a;*/ in si4713_update_tune_status()
919 sdev->tune_rnl = n; in si4713_update_tune_status()
1039 rval = -EINVAL; in si4713_choose_econtrol_action()
1049 * si4713_setup - Sets the device up with current configuration.
1060 f.frequency = sdev->frequency ? sdev->frequency : DEFAULT_FREQUENCY; in si4713_setup()
1062 rval = si4713_s_frequency(&sdev->sd, &f); in si4713_setup()
1065 if (sdev->stereo) in si4713_setup()
1069 if (sdev->rds_enabled) in si4713_setup()
1071 si4713_s_modulator(&sdev->sd, &vm); in si4713_setup()
1077 * si4713_initialize - Sets the device up with default configuration.
1096 sdev->frequency = DEFAULT_FREQUENCY; in si4713_initialize()
1097 sdev->stereo = 1; in si4713_initialize()
1098 sdev->tune_rnl = DEFAULT_TUNE_RNL; in si4713_initialize()
1102 /* si4713_s_ctrl - set the value of a control */
1106 container_of(ctrl->handler, struct si4713_device, ctrl_handler); in si4713_s_ctrl()
1117 if (ctrl->id != V4L2_CID_AUDIO_MUTE) in si4713_s_ctrl()
1118 return -EINVAL; in si4713_s_ctrl()
1119 if (ctrl->is_new) { in si4713_s_ctrl()
1120 if (ctrl->val) { in si4713_s_ctrl()
1121 ret = si4713_set_mute(sdev, ctrl->val); in si4713_s_ctrl()
1128 ret = si4713_set_mute(sdev, ctrl->val); in si4713_s_ctrl()
1136 if (!sdev->power_state) in si4713_s_ctrl()
1139 for (c = 1; !ret && c < ctrl->ncontrols; c++) { in si4713_s_ctrl()
1140 ctrl = ctrl->cluster[c]; in si4713_s_ctrl()
1142 if (!force && !ctrl->is_new) in si4713_s_ctrl()
1145 switch (ctrl->id) { in si4713_s_ctrl()
1147 ret = si4713_set_rds_ps_name(sdev, ctrl->p_new.p_char); in si4713_s_ctrl()
1151 ret = si4713_set_rds_radio_text(sdev, ctrl->p_new.p_char); in si4713_s_ctrl()
1163 sdev->tune_pwr_level->val, sdev->tune_ant_cap->val); in si4713_s_ctrl()
1166 sdev->tune_ant_cap->is_new = false; in si4713_s_ctrl()
1167 sdev->tune_pwr_level->is_new = false; in si4713_s_ctrl()
1173 if (sdev->rds_alt_freqs_enable->val) { in si4713_s_ctrl()
1174 val = sdev->rds_alt_freqs->p_new.p_u32[0]; in si4713_s_ctrl()
1175 val = val / 100 - 876 + 0xe101; in si4713_s_ctrl()
1183 ret = si4713_choose_econtrol_action(sdev, ctrl->id, &bit, in si4713_s_ctrl()
1188 val = ctrl->val; in si4713_s_ctrl()
1203 val = set_bits(val, ctrl->val, bit, mask); in si4713_s_ctrl()
1210 val = ctrl->val; in si4713_s_ctrl()
1218 /* si4713_ioctl - deal with private ioctls (only rnl for now) */
1227 return -EINVAL; in si4713_ioctl()
1231 frequency = v4l2_to_si4713(rnl->frequency); in si4713_ioctl()
1233 if (sdev->power_state) { in si4713_ioctl()
1243 rnl->rnl = sdev->tune_rnl; in si4713_ioctl()
1248 rval = -ENOIOCTLCMD; in si4713_ioctl()
1254 /* si4713_g_modulator - get modulator attributes */
1261 return -ENODEV; in si4713_g_modulator()
1263 if (vm->index > 0) in si4713_g_modulator()
1264 return -EINVAL; in si4713_g_modulator()
1266 strscpy(vm->name, "FM Modulator", sizeof(vm->name)); in si4713_g_modulator()
1267 vm->capability = V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_LOW | in si4713_g_modulator()
1271 vm->rangelow = si4713_to_v4l2(FREQ_RANGE_LOW); in si4713_g_modulator()
1272 vm->rangehigh = si4713_to_v4l2(FREQ_RANGE_HIGH); in si4713_g_modulator()
1274 if (sdev->power_state) { in si4713_g_modulator()
1282 sdev->stereo = get_status_bit(comp_en, 1, 1 << 1); in si4713_g_modulator()
1286 if (sdev->stereo) in si4713_g_modulator()
1287 vm->txsubchans = V4L2_TUNER_SUB_STEREO; in si4713_g_modulator()
1289 vm->txsubchans = V4L2_TUNER_SUB_MONO; in si4713_g_modulator()
1292 if (sdev->rds_enabled) in si4713_g_modulator()
1293 vm->txsubchans |= V4L2_TUNER_SUB_RDS; in si4713_g_modulator()
1295 vm->txsubchans &= ~V4L2_TUNER_SUB_RDS; in si4713_g_modulator()
1300 /* si4713_s_modulator - set modulator attributes */
1309 return -ENODEV; in si4713_s_modulator()
1311 if (vm->index > 0) in si4713_s_modulator()
1312 return -EINVAL; in si4713_s_modulator()
1315 if (vm->txsubchans & V4L2_TUNER_SUB_STEREO) in si4713_s_modulator()
1317 else if (vm->txsubchans & V4L2_TUNER_SUB_MONO) in si4713_s_modulator()
1320 return -EINVAL; in si4713_s_modulator()
1322 rds = !!(vm->txsubchans & V4L2_TUNER_SUB_RDS); in si4713_s_modulator()
1324 if (sdev->power_state) { in si4713_s_modulator()
1339 sdev->stereo = stereo; in si4713_s_modulator()
1340 sdev->rds_enabled = rds; in si4713_s_modulator()
1345 /* si4713_g_frequency - get tuner or modulator radio frequency */
1351 if (f->tuner) in si4713_g_frequency()
1352 return -EINVAL; in si4713_g_frequency()
1354 if (sdev->power_state) { in si4713_g_frequency()
1362 sdev->frequency = freq; in si4713_g_frequency()
1365 f->frequency = si4713_to_v4l2(sdev->frequency); in si4713_g_frequency()
1370 /* si4713_s_frequency - set tuner or modulator radio frequency */
1375 u16 frequency = v4l2_to_si4713(f->frequency); in si4713_s_frequency()
1377 if (f->tuner) in si4713_s_frequency()
1378 return -EINVAL; in si4713_s_frequency()
1383 if (sdev->power_state) { in si4713_s_frequency()
1390 sdev->frequency = frequency; in si4713_s_frequency()
1429 /* si4713_probe - probe for the device */
1434 struct si4713_platform_data *pdata = client->dev.platform_data; in si4713_probe()
1435 struct device_node *np = client->dev.of_node; in si4713_probe()
1440 sdev = devm_kzalloc(&client->dev, sizeof(*sdev), GFP_KERNEL); in si4713_probe()
1442 dev_err(&client->dev, "Failed to alloc video device.\n"); in si4713_probe()
1443 rval = -ENOMEM; in si4713_probe()
1447 sdev->gpio_reset = devm_gpiod_get_optional(&client->dev, "reset", in si4713_probe()
1449 if (IS_ERR(sdev->gpio_reset)) { in si4713_probe()
1450 rval = PTR_ERR(sdev->gpio_reset); in si4713_probe()
1451 dev_err(&client->dev, "Failed to request gpio: %d\n", rval); in si4713_probe()
1455 sdev->vdd = devm_regulator_get_optional(&client->dev, "vdd"); in si4713_probe()
1456 if (IS_ERR(sdev->vdd)) { in si4713_probe()
1457 rval = PTR_ERR(sdev->vdd); in si4713_probe()
1458 if (rval == -EPROBE_DEFER) in si4713_probe()
1461 dev_dbg(&client->dev, "no vdd regulator found: %d\n", rval); in si4713_probe()
1462 sdev->vdd = NULL; in si4713_probe()
1465 sdev->vio = devm_regulator_get_optional(&client->dev, "vio"); in si4713_probe()
1466 if (IS_ERR(sdev->vio)) { in si4713_probe()
1467 rval = PTR_ERR(sdev->vio); in si4713_probe()
1468 if (rval == -EPROBE_DEFER) in si4713_probe()
1471 dev_dbg(&client->dev, "no vio regulator found: %d\n", rval); in si4713_probe()
1472 sdev->vio = NULL; in si4713_probe()
1475 v4l2_i2c_subdev_init(&sdev->sd, client, &si4713_subdev_ops); in si4713_probe()
1477 init_completion(&sdev->work); in si4713_probe()
1479 hdl = &sdev->ctrl_handler; in si4713_probe()
1481 sdev->mute = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, in si4713_probe()
1484 sdev->rds_pi = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, in si4713_probe()
1486 sdev->rds_pty = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, in si4713_probe()
1488 sdev->rds_compressed = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, in si4713_probe()
1490 sdev->rds_art_head = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, in si4713_probe()
1492 sdev->rds_stereo = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, in si4713_probe()
1494 sdev->rds_tp = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, in si4713_probe()
1496 sdev->rds_ta = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, in si4713_probe()
1498 sdev->rds_ms = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, in si4713_probe()
1500 sdev->rds_dyn_pty = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, in si4713_probe()
1502 sdev->rds_alt_freqs_enable = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, in si4713_probe()
1504 sdev->rds_alt_freqs = v4l2_ctrl_new_custom(hdl, &si4713_alt_freqs_ctrl, NULL); in si4713_probe()
1505 sdev->rds_deviation = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, in si4713_probe()
1513 sdev->rds_ps_name = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, in si4713_probe()
1520 sdev->rds_radio_text = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, in si4713_probe()
1523 sdev->limiter_enabled = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, in si4713_probe()
1525 sdev->limiter_release_time = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, in si4713_probe()
1528 sdev->limiter_deviation = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, in si4713_probe()
1532 sdev->compression_enabled = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, in si4713_probe()
1534 sdev->compression_gain = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, in si4713_probe()
1537 sdev->compression_threshold = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, in si4713_probe()
1541 sdev->compression_attack_time = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, in si4713_probe()
1544 sdev->compression_release_time = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, in si4713_probe()
1548 sdev->pilot_tone_enabled = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, in si4713_probe()
1550 sdev->pilot_tone_deviation = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, in si4713_probe()
1553 sdev->pilot_tone_freq = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, in si4713_probe()
1557 sdev->tune_preemphasis = v4l2_ctrl_new_std_menu(hdl, &si4713_ctrl_ops, in si4713_probe()
1560 sdev->tune_pwr_level = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, in si4713_probe()
1563 sdev->tune_ant_cap = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, in si4713_probe()
1567 if (hdl->error) { in si4713_probe()
1568 rval = hdl->error; in si4713_probe()
1571 v4l2_ctrl_cluster(29, &sdev->mute); in si4713_probe()
1572 sdev->sd.ctrl_handler = hdl; in si4713_probe()
1574 if (client->irq) { in si4713_probe()
1575 rval = devm_request_irq(&client->dev, client->irq, in si4713_probe()
1577 client->name, sdev); in si4713_probe()
1579 v4l2_err(&sdev->sd, "Could not request IRQ\n"); in si4713_probe()
1582 v4l2_dbg(1, debug, &sdev->sd, "IRQ requested.\n"); in si4713_probe()
1584 v4l2_warn(&sdev->sd, "IRQ not configured. Using timeouts.\n"); in si4713_probe()
1589 v4l2_err(&sdev->sd, "Failed to probe device information.\n"); in si4713_probe()
1593 if (!np && (!pdata || !pdata->is_platform_device)) in si4713_probe()
1596 si4713_pdev = platform_device_alloc("radio-si4713", -1); in si4713_probe()
1598 rval = -ENOMEM; in si4713_probe()
1612 sdev->pd = si4713_pdev; in si4713_probe()
1618 v4l2_device_unregister_subdev(&sdev->sd); in si4713_probe()
1625 /* si4713_remove - remove the device */
1631 platform_device_unregister(sdev->pd); in si4713_remove()
1633 if (sdev->power_state) in si4713_remove()
1637 v4l2_ctrl_handler_free(sd->ctrl_handler); in si4713_remove()
1640 /* si4713_i2c_driver - i2c driver interface */