/* si4713_probe - probe for the device */ static int si4713_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct si4713_device *sdev; int rval; sdev = kzalloc(sizeof *sdev, GFP_KERNEL); if (!sdev) { dev_err(&client->dev, "Failed to alloc video device.\n"); rval = -ENOMEM; goto exit; } sdev->platform_data = client->dev.platform_data; if (!sdev->platform_data) { v4l2_err(&sdev->sd, "No platform data registered.\n"); rval = -ENODEV; goto free_sdev; } v4l2_i2c_subdev_init(&sdev->sd, client, &si4713_subdev_ops); mutex_init(&sdev->mutex); init_completion(&sdev->work); if (client->irq) { rval = request_irq(client->irq, si4713_handler, IRQF_TRIGGER_FALLING | IRQF_DISABLED, client->name, sdev); if (rval < 0) { v4l2_err(&sdev->sd, "Could not request IRQ\n"); goto free_sdev; } v4l2_dbg(1, debug, &sdev->sd, "IRQ requested.\n"); } else { v4l2_warn(&sdev->sd, "IRQ not configured. Using timeouts.\n"); } rval = si4713_initialize(sdev); if (rval < 0) { v4l2_err(&sdev->sd, "Failed to probe device information.\n"); goto free_irq; } return 0; free_irq: if (client->irq) free_irq(client->irq, sdev); free_sdev: kfree(sdev); exit: return rval; }
/* si4713_probe - probe for the device */ static int si4713_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct si4713_device *sdev; struct si4713_platform_data *pdata = client->dev.platform_data; struct v4l2_ctrl_handler *hdl; int rval, i; sdev = kzalloc(sizeof *sdev, GFP_KERNEL); if (!sdev) { dev_err(&client->dev, "Failed to alloc video device.\n"); rval = -ENOMEM; goto exit; } sdev->gpio_reset = -1; if (pdata && gpio_is_valid(pdata->gpio_reset)) { rval = gpio_request(pdata->gpio_reset, "si4713 reset"); if (rval) { dev_err(&client->dev, "Failed to request gpio: %d\n", rval); goto free_sdev; } sdev->gpio_reset = pdata->gpio_reset; gpio_direction_output(sdev->gpio_reset, 0); } for (i = 0; i < ARRAY_SIZE(sdev->supplies); i++) sdev->supplies[i].supply = si4713_supply_names[i]; rval = regulator_bulk_get(&client->dev, ARRAY_SIZE(sdev->supplies), sdev->supplies); if (rval) { dev_err(&client->dev, "Cannot get regulators: %d\n", rval); goto free_gpio; } v4l2_i2c_subdev_init(&sdev->sd, client, &si4713_subdev_ops); init_completion(&sdev->work); hdl = &sdev->ctrl_handler; v4l2_ctrl_handler_init(hdl, 20); sdev->mute = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, V4L2_CID_AUDIO_MUTE, 0, 1, 1, DEFAULT_MUTE); sdev->rds_pi = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, V4L2_CID_RDS_TX_PI, 0, 0xffff, 1, DEFAULT_RDS_PI); sdev->rds_pty = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, V4L2_CID_RDS_TX_PTY, 0, 31, 1, DEFAULT_RDS_PTY); sdev->rds_deviation = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, V4L2_CID_RDS_TX_DEVIATION, 0, MAX_RDS_DEVIATION, 10, DEFAULT_RDS_DEVIATION); /* * Report step as 8. From RDS spec, psname * should be 8. But there are receivers which scroll strings * sized as 8xN. */ sdev->rds_ps_name = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, V4L2_CID_RDS_TX_PS_NAME, 0, MAX_RDS_PS_NAME, 8, 0); /* * Report step as 32 (2A block). From RDS spec, * radio text should be 32 for 2A block. But there are receivers * which scroll strings sized as 32xN. Setting default to 32. */ sdev->rds_radio_text = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, V4L2_CID_RDS_TX_RADIO_TEXT, 0, MAX_RDS_RADIO_TEXT, 32, 0); sdev->limiter_enabled = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, V4L2_CID_AUDIO_LIMITER_ENABLED, 0, 1, 1, 1); sdev->limiter_release_time = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, V4L2_CID_AUDIO_LIMITER_RELEASE_TIME, 250, MAX_LIMITER_RELEASE_TIME, 10, DEFAULT_LIMITER_RTIME); sdev->limiter_deviation = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, V4L2_CID_AUDIO_LIMITER_DEVIATION, 0, MAX_LIMITER_DEVIATION, 10, DEFAULT_LIMITER_DEV); sdev->compression_enabled = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, V4L2_CID_AUDIO_COMPRESSION_ENABLED, 0, 1, 1, 1); sdev->compression_gain = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, V4L2_CID_AUDIO_COMPRESSION_GAIN, 0, MAX_ACOMP_GAIN, 1, DEFAULT_ACOMP_GAIN); sdev->compression_threshold = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, V4L2_CID_AUDIO_COMPRESSION_THRESHOLD, MIN_ACOMP_THRESHOLD, MAX_ACOMP_THRESHOLD, 1, DEFAULT_ACOMP_THRESHOLD); sdev->compression_attack_time = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME, 0, MAX_ACOMP_ATTACK_TIME, 500, DEFAULT_ACOMP_ATIME); sdev->compression_release_time = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME, 100000, MAX_ACOMP_RELEASE_TIME, 100000, DEFAULT_ACOMP_RTIME); sdev->pilot_tone_enabled = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, V4L2_CID_PILOT_TONE_ENABLED, 0, 1, 1, 1); sdev->pilot_tone_deviation = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, V4L2_CID_PILOT_TONE_DEVIATION, 0, MAX_PILOT_DEVIATION, 10, DEFAULT_PILOT_DEVIATION); sdev->pilot_tone_freq = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, V4L2_CID_PILOT_TONE_FREQUENCY, 0, MAX_PILOT_FREQUENCY, 1, DEFAULT_PILOT_FREQUENCY); sdev->tune_preemphasis = v4l2_ctrl_new_std_menu(hdl, &si4713_ctrl_ops, V4L2_CID_TUNE_PREEMPHASIS, V4L2_PREEMPHASIS_75_uS, 0, V4L2_PREEMPHASIS_50_uS); sdev->tune_pwr_level = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, V4L2_CID_TUNE_POWER_LEVEL, 0, 120, 1, DEFAULT_POWER_LEVEL); sdev->tune_ant_cap = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, V4L2_CID_TUNE_ANTENNA_CAPACITOR, 0, 191, 1, 0); if (hdl->error) { rval = hdl->error; goto free_ctrls; } v4l2_ctrl_cluster(20, &sdev->mute); sdev->sd.ctrl_handler = hdl; if (client->irq) { rval = request_irq(client->irq, si4713_handler, IRQF_TRIGGER_FALLING | IRQF_DISABLED, client->name, sdev); if (rval < 0) { v4l2_err(&sdev->sd, "Could not request IRQ\n"); goto put_reg; } v4l2_dbg(1, debug, &sdev->sd, "IRQ requested.\n"); } else { v4l2_warn(&sdev->sd, "IRQ not configured. Using timeouts.\n"); } rval = si4713_initialize(sdev); if (rval < 0) { v4l2_err(&sdev->sd, "Failed to probe device information.\n"); goto free_irq; } return 0; free_irq: if (client->irq) free_irq(client->irq, sdev); free_ctrls: v4l2_ctrl_handler_free(hdl); put_reg: regulator_bulk_free(ARRAY_SIZE(sdev->supplies), sdev->supplies); free_gpio: if (gpio_is_valid(sdev->gpio_reset)) gpio_free(sdev->gpio_reset); free_sdev: kfree(sdev); exit: return rval; }
/* si4713_probe - probe for the device */ static int si4713_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct si4713_device *sdev; struct v4l2_ctrl_handler *hdl; struct si4713_platform_data *pdata = client->dev.platform_data; struct device_node *np = client->dev.of_node; struct radio_si4713_platform_data si4713_pdev_pdata; struct platform_device *si4713_pdev; int rval; sdev = devm_kzalloc(&client->dev, sizeof(*sdev), GFP_KERNEL); if (!sdev) { dev_err(&client->dev, "Failed to alloc video device.\n"); rval = -ENOMEM; goto exit; } sdev->gpio_reset = devm_gpiod_get_optional(&client->dev, "reset", GPIOD_OUT_LOW); if (IS_ERR(sdev->gpio_reset)) { rval = PTR_ERR(sdev->gpio_reset); dev_err(&client->dev, "Failed to request gpio: %d\n", rval); goto exit; } sdev->vdd = devm_regulator_get_optional(&client->dev, "vdd"); if (IS_ERR(sdev->vdd)) { rval = PTR_ERR(sdev->vdd); if (rval == -EPROBE_DEFER) goto exit; dev_dbg(&client->dev, "no vdd regulator found: %d\n", rval); sdev->vdd = NULL; } sdev->vio = devm_regulator_get_optional(&client->dev, "vio"); if (IS_ERR(sdev->vio)) { rval = PTR_ERR(sdev->vio); if (rval == -EPROBE_DEFER) goto exit; dev_dbg(&client->dev, "no vio regulator found: %d\n", rval); sdev->vio = NULL; } v4l2_i2c_subdev_init(&sdev->sd, client, &si4713_subdev_ops); init_completion(&sdev->work); hdl = &sdev->ctrl_handler; v4l2_ctrl_handler_init(hdl, 20); sdev->mute = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, V4L2_CID_AUDIO_MUTE, 0, 1, 1, DEFAULT_MUTE); sdev->rds_pi = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, V4L2_CID_RDS_TX_PI, 0, 0xffff, 1, DEFAULT_RDS_PI); sdev->rds_pty = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, V4L2_CID_RDS_TX_PTY, 0, 31, 1, DEFAULT_RDS_PTY); sdev->rds_compressed = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, V4L2_CID_RDS_TX_COMPRESSED, 0, 1, 1, 0); sdev->rds_art_head = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, V4L2_CID_RDS_TX_ARTIFICIAL_HEAD, 0, 1, 1, 0); sdev->rds_stereo = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, V4L2_CID_RDS_TX_MONO_STEREO, 0, 1, 1, 1); sdev->rds_tp = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, V4L2_CID_RDS_TX_TRAFFIC_PROGRAM, 0, 1, 1, 0); sdev->rds_ta = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, V4L2_CID_RDS_TX_TRAFFIC_ANNOUNCEMENT, 0, 1, 1, 0); sdev->rds_ms = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, V4L2_CID_RDS_TX_MUSIC_SPEECH, 0, 1, 1, 1); sdev->rds_dyn_pty = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, V4L2_CID_RDS_TX_DYNAMIC_PTY, 0, 1, 1, 0); sdev->rds_alt_freqs_enable = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, V4L2_CID_RDS_TX_ALT_FREQS_ENABLE, 0, 1, 1, 0); sdev->rds_alt_freqs = v4l2_ctrl_new_custom(hdl, &si4713_alt_freqs_ctrl, NULL); sdev->rds_deviation = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, V4L2_CID_RDS_TX_DEVIATION, 0, MAX_RDS_DEVIATION, 10, DEFAULT_RDS_DEVIATION); /* * Report step as 8. From RDS spec, psname * should be 8. But there are receivers which scroll strings * sized as 8xN. */ sdev->rds_ps_name = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, V4L2_CID_RDS_TX_PS_NAME, 0, MAX_RDS_PS_NAME, 8, 0); /* * Report step as 32 (2A block). From RDS spec, * radio text should be 32 for 2A block. But there are receivers * which scroll strings sized as 32xN. Setting default to 32. */ sdev->rds_radio_text = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, V4L2_CID_RDS_TX_RADIO_TEXT, 0, MAX_RDS_RADIO_TEXT, 32, 0); sdev->limiter_enabled = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, V4L2_CID_AUDIO_LIMITER_ENABLED, 0, 1, 1, 1); sdev->limiter_release_time = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, V4L2_CID_AUDIO_LIMITER_RELEASE_TIME, 250, MAX_LIMITER_RELEASE_TIME, 10, DEFAULT_LIMITER_RTIME); sdev->limiter_deviation = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, V4L2_CID_AUDIO_LIMITER_DEVIATION, 0, MAX_LIMITER_DEVIATION, 10, DEFAULT_LIMITER_DEV); sdev->compression_enabled = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, V4L2_CID_AUDIO_COMPRESSION_ENABLED, 0, 1, 1, 1); sdev->compression_gain = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, V4L2_CID_AUDIO_COMPRESSION_GAIN, 0, MAX_ACOMP_GAIN, 1, DEFAULT_ACOMP_GAIN); sdev->compression_threshold = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, V4L2_CID_AUDIO_COMPRESSION_THRESHOLD, MIN_ACOMP_THRESHOLD, MAX_ACOMP_THRESHOLD, 1, DEFAULT_ACOMP_THRESHOLD); sdev->compression_attack_time = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME, 0, MAX_ACOMP_ATTACK_TIME, 500, DEFAULT_ACOMP_ATIME); sdev->compression_release_time = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME, 100000, MAX_ACOMP_RELEASE_TIME, 100000, DEFAULT_ACOMP_RTIME); sdev->pilot_tone_enabled = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, V4L2_CID_PILOT_TONE_ENABLED, 0, 1, 1, 1); sdev->pilot_tone_deviation = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, V4L2_CID_PILOT_TONE_DEVIATION, 0, MAX_PILOT_DEVIATION, 10, DEFAULT_PILOT_DEVIATION); sdev->pilot_tone_freq = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, V4L2_CID_PILOT_TONE_FREQUENCY, 0, MAX_PILOT_FREQUENCY, 1, DEFAULT_PILOT_FREQUENCY); sdev->tune_preemphasis = v4l2_ctrl_new_std_menu(hdl, &si4713_ctrl_ops, V4L2_CID_TUNE_PREEMPHASIS, V4L2_PREEMPHASIS_75_uS, 0, V4L2_PREEMPHASIS_50_uS); sdev->tune_pwr_level = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, V4L2_CID_TUNE_POWER_LEVEL, 0, SI4713_MAX_POWER, 1, DEFAULT_POWER_LEVEL); sdev->tune_ant_cap = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops, V4L2_CID_TUNE_ANTENNA_CAPACITOR, 0, SI4713_MAX_ANTCAP, 1, 0); if (hdl->error) { rval = hdl->error; goto free_ctrls; } v4l2_ctrl_cluster(29, &sdev->mute); sdev->sd.ctrl_handler = hdl; if (client->irq) { rval = devm_request_irq(&client->dev, client->irq, si4713_handler, IRQF_TRIGGER_FALLING, client->name, sdev); if (rval < 0) { v4l2_err(&sdev->sd, "Could not request IRQ\n"); goto free_ctrls; } v4l2_dbg(1, debug, &sdev->sd, "IRQ requested.\n"); } else { v4l2_warn(&sdev->sd, "IRQ not configured. Using timeouts.\n"); } rval = si4713_initialize(sdev); if (rval < 0) { v4l2_err(&sdev->sd, "Failed to probe device information.\n"); goto free_ctrls; } if (!np && (!pdata || !pdata->is_platform_device)) return 0; si4713_pdev = platform_device_alloc("radio-si4713", -1); if (!si4713_pdev) { rval = -ENOMEM; goto put_main_pdev; } si4713_pdev_pdata.subdev = client; rval = platform_device_add_data(si4713_pdev, &si4713_pdev_pdata, sizeof(si4713_pdev_pdata)); if (rval) goto put_main_pdev; rval = platform_device_add(si4713_pdev); if (rval) goto put_main_pdev; sdev->pd = si4713_pdev; return 0; put_main_pdev: platform_device_put(si4713_pdev); v4l2_device_unregister_subdev(&sdev->sd); free_ctrls: v4l2_ctrl_handler_free(hdl); exit: return rval; }