1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * drivers/media/radio/si4713-i2c.c
5 * Silicon Labs Si4713 FM Radio Transmitter I2C commands.
7 * Copyright (c) 2009 Nokia Corporation
8 * Contact: Eduardo Valentin <eduardo.valentin@nokia.com>
11 #include <linux/completion.h>
12 #include <linux/delay.h>
13 #include <linux/err.h>
14 #include <linux/interrupt.h>
15 #include <linux/i2c.h>
16 #include <linux/slab.h>
17 #include <linux/gpio.h>
18 #include <linux/module.h>
19 #include <media/v4l2-device.h>
20 #include <media/v4l2-ioctl.h>
21 #include <media/v4l2-common.h>
25 /* module parameters */
27 module_param(debug, int, S_IRUGO | S_IWUSR);
28 MODULE_PARM_DESC(debug, "Debug level (0 - 2)");
30 MODULE_LICENSE("GPL");
31 MODULE_AUTHOR("Eduardo Valentin <eduardo.valentin@nokia.com>");
32 MODULE_DESCRIPTION("I2C driver for Si4713 FM Radio Transmitter");
33 MODULE_VERSION("0.0.1");
35 #define DEFAULT_RDS_PI 0x00
36 #define DEFAULT_RDS_PTY 0x00
37 #define DEFAULT_RDS_DEVIATION 0x00C8
38 #define DEFAULT_RDS_PS_REPEAT_COUNT 0x0003
39 #define DEFAULT_LIMITER_RTIME 0x1392
40 #define DEFAULT_LIMITER_DEV 0x102CA
41 #define DEFAULT_PILOT_FREQUENCY 0x4A38
42 #define DEFAULT_PILOT_DEVIATION 0x1A5E
43 #define DEFAULT_ACOMP_ATIME 0x0000
44 #define DEFAULT_ACOMP_RTIME 0xF4240L
45 #define DEFAULT_ACOMP_GAIN 0x0F
46 #define DEFAULT_ACOMP_THRESHOLD (-0x28)
47 #define DEFAULT_MUTE 0x01
48 #define DEFAULT_POWER_LEVEL 88
49 #define DEFAULT_FREQUENCY 8800
50 #define DEFAULT_PREEMPHASIS FMPE_EU
51 #define DEFAULT_TUNE_RNL 0xFF
53 #define to_si4713_device(sd) container_of(sd, struct si4713_device, sd)
55 /* frequency domain transformation (using times 10 to avoid floats) */
56 #define FREQDEV_UNIT 100000
57 #define FREQV4L2_MULTI 625
58 #define si4713_to_v4l2(f) ((f * FREQDEV_UNIT) / FREQV4L2_MULTI)
59 #define v4l2_to_si4713(f) ((f * FREQV4L2_MULTI) / FREQDEV_UNIT)
60 #define FREQ_RANGE_LOW 7600
61 #define FREQ_RANGE_HIGH 10800
66 #define RDS_BLOCK_CLEAR 0x03
67 #define RDS_BLOCK_LOAD 0x04
68 #define RDS_RADIOTEXT_2A 0x20
69 #define RDS_RADIOTEXT_BLK_SIZE 4
70 #define RDS_RADIOTEXT_INDEX_MAX 0x0F
71 #define RDS_CARRIAGE_RETURN 0x0D
73 #define rds_ps_nblocks(len) ((len / RDS_BLOCK) + (len % RDS_BLOCK ? 1 : 0))
75 #define get_status_bit(p, b, m) (((p) & (m)) >> (b))
76 #define set_bits(p, v, b, m) (((p) & ~(m)) | ((v) << (b)))
78 #define ATTACK_TIME_UNIT 500
80 #define POWER_OFF 0x00
83 #define msb(x) ((u8)((u16) x >> 8))
84 #define lsb(x) ((u8)((u16) x & 0x00FF))
85 #define compose_u16(msb, lsb) (((u16)msb << 8) | lsb)
86 #define check_command_failed(status) (!(status & SI4713_CTS) || \
87 (status & SI4713_ERR))
89 #define set_mute(p) ((p & 1) | ((p & 1) << 1));
92 #define DBG_BUFFER(device, message, buffer, size) \
96 for (i = 0; i < size; i++) \
97 sprintf(str + i * 5, " 0x%02x", buffer[i]); \
98 v4l2_dbg(2, debug, device, "%s:%s\n", message, str); \
101 #define DBG_BUFFER(device, message, buffer, size)
105 * Values for limiter release time (sorted by second column)
109 static long limiter_times[] = {
133 * Values for audio compression release time (sorted by second column)
137 static unsigned long acomp_rtimes[] = {
146 * Values for preemphasis (sorted by second column)
150 static unsigned long preemphasis_values[] = {
151 FMPE_DISABLED, V4L2_PREEMPHASIS_DISABLED,
152 FMPE_EU, V4L2_PREEMPHASIS_50_uS,
153 FMPE_USA, V4L2_PREEMPHASIS_75_uS,
156 static int usecs_to_dev(unsigned long usecs, unsigned long const array[],
162 for (i = 0; i < size / 2; i++)
163 if (array[(i * 2) + 1] >= usecs) {
171 /* si4713_handler: IRQ handler, just complete work */
172 static irqreturn_t si4713_handler(int irq, void *dev)
174 struct si4713_device *sdev = dev;
176 v4l2_dbg(2, debug, &sdev->sd,
177 "%s: sending signal to completion work.\n", __func__);
178 complete(&sdev->work);
184 * si4713_send_command - sends a command to si4713 and waits its response
185 * @sdev: si4713_device structure for the device we are communicating
186 * @command: command id
187 * @args: command arguments we are sending (up to 7)
188 * @argn: actual size of @args
189 * @response: buffer to place the expected response from the device (up to 15)
190 * @respn: actual size of @response
191 * @usecs: amount of time to wait before reading the response (in usecs)
193 static int si4713_send_command(struct si4713_device *sdev, const u8 command,
194 const u8 args[], const int argn,
195 u8 response[], const int respn, const int usecs)
197 struct i2c_client *client = v4l2_get_subdevdata(&sdev->sd);
198 unsigned long until_jiffies;
199 u8 data1[MAX_ARGS + 1];
202 if (!client->adapter)
205 /* First send the command and its arguments */
207 memcpy(data1 + 1, args, argn);
208 DBG_BUFFER(&sdev->sd, "Parameters", data1, argn + 1);
210 err = i2c_master_send(client, data1, argn + 1);
211 if (err != argn + 1) {
212 v4l2_err(&sdev->sd, "Error while sending command 0x%02x\n",
214 return err < 0 ? err : -EIO;
217 until_jiffies = jiffies + usecs_to_jiffies(usecs) + 1;
219 /* Wait response from interrupt */
221 if (!wait_for_completion_timeout(&sdev->work,
222 usecs_to_jiffies(usecs) + 1))
224 "(%s) Device took too much time to answer.\n",
229 err = i2c_master_recv(client, response, respn);
232 "Error %d while reading response for command 0x%02x\n",
234 return err < 0 ? err : -EIO;
237 DBG_BUFFER(&sdev->sd, "Response", response, respn);
238 if (!check_command_failed(response[0]))
244 usleep_range(usecs, 1000);
246 usleep_range(1000, 2000);
247 } while (time_is_after_jiffies(until_jiffies));
253 * si4713_read_property - reads a si4713 property
254 * @sdev: si4713_device structure for the device we are communicating
255 * @prop: property identification number
256 * @pv: property value to be returned on success
258 static int si4713_read_property(struct si4713_device *sdev, u16 prop, u32 *pv)
261 u8 val[SI4713_GET_PROP_NRESP];
264 * .Second byte = property's MSB
265 * .Third byte = property's LSB
267 const u8 args[SI4713_GET_PROP_NARGS] = {
273 err = si4713_send_command(sdev, SI4713_CMD_GET_PROPERTY,
274 args, ARRAY_SIZE(args), val,
275 ARRAY_SIZE(val), DEFAULT_TIMEOUT);
280 *pv = compose_u16(val[2], val[3]);
282 v4l2_dbg(1, debug, &sdev->sd,
283 "%s: property=0x%02x value=0x%02x status=0x%02x\n",
284 __func__, prop, *pv, val[0]);
290 * si4713_write_property - modifies a si4713 property
291 * @sdev: si4713_device structure for the device we are communicating
292 * @prop: property identification number
293 * @val: new value for that property
295 static int si4713_write_property(struct si4713_device *sdev, u16 prop, u16 val)
298 u8 resp[SI4713_SET_PROP_NRESP];
301 * .Second byte = property's MSB
302 * .Third byte = property's LSB
303 * .Fourth byte = value's MSB
304 * .Fifth byte = value's LSB
306 const u8 args[SI4713_SET_PROP_NARGS] = {
314 rval = si4713_send_command(sdev, SI4713_CMD_SET_PROPERTY,
315 args, ARRAY_SIZE(args),
316 resp, ARRAY_SIZE(resp),
322 v4l2_dbg(1, debug, &sdev->sd,
323 "%s: property=0x%02x value=0x%02x status=0x%02x\n",
324 __func__, prop, val, resp[0]);
327 * As there is no command response for SET_PROPERTY,
328 * wait Tcomp time to finish before proceed, in order
329 * to have property properly set.
331 msleep(TIMEOUT_SET_PROPERTY);
337 * si4713_powerup - Powers the device up
338 * @sdev: si4713_device structure for the device we are communicating
340 static int si4713_powerup(struct si4713_device *sdev)
342 struct i2c_client *client = v4l2_get_subdevdata(&sdev->sd);
344 u8 resp[SI4713_PWUP_NRESP];
346 * .First byte = Enabled interrupts and boot function
347 * .Second byte = Input operation mode
349 u8 args[SI4713_PWUP_NARGS] = {
350 SI4713_PWUP_GPO2OEN | SI4713_PWUP_FUNC_TX,
351 SI4713_PWUP_OPMOD_ANALOG,
354 if (sdev->power_state)
358 err = regulator_enable(sdev->vdd);
360 v4l2_err(&sdev->sd, "Failed to enable vdd: %d\n", err);
366 err = regulator_enable(sdev->vio);
368 v4l2_err(&sdev->sd, "Failed to enable vio: %d\n", err);
373 if (sdev->gpio_reset) {
375 gpiod_set_value(sdev->gpio_reset, 1);
379 args[0] |= SI4713_PWUP_CTSIEN;
381 err = si4713_send_command(sdev, SI4713_CMD_POWER_UP,
382 args, ARRAY_SIZE(args),
383 resp, ARRAY_SIZE(resp),
387 v4l2_dbg(1, debug, &sdev->sd, "Powerup response: 0x%02x\n",
389 v4l2_dbg(1, debug, &sdev->sd, "Device in power up mode\n");
390 sdev->power_state = POWER_ON;
393 err = si4713_write_property(sdev, SI4713_GPO_IEN,
394 SI4713_STC_INT | SI4713_CTS);
397 gpiod_set_value(sdev->gpio_reset, 0);
401 err = regulator_disable(sdev->vdd);
403 v4l2_err(&sdev->sd, "Failed to disable vdd: %d\n", err);
407 err = regulator_disable(sdev->vio);
409 v4l2_err(&sdev->sd, "Failed to disable vio: %d\n", err);
416 * si4713_powerdown - Powers the device down
417 * @sdev: si4713_device structure for the device we are communicating
419 static int si4713_powerdown(struct si4713_device *sdev)
422 u8 resp[SI4713_PWDN_NRESP];
424 if (!sdev->power_state)
427 err = si4713_send_command(sdev, SI4713_CMD_POWER_DOWN,
429 resp, ARRAY_SIZE(resp),
433 v4l2_dbg(1, debug, &sdev->sd, "Power down response: 0x%02x\n",
435 v4l2_dbg(1, debug, &sdev->sd, "Device in reset mode\n");
436 if (sdev->gpio_reset)
437 gpiod_set_value(sdev->gpio_reset, 0);
440 err = regulator_disable(sdev->vdd);
443 "Failed to disable vdd: %d\n", err);
448 err = regulator_disable(sdev->vio);
451 "Failed to disable vio: %d\n", err);
454 sdev->power_state = POWER_OFF;
461 * si4713_checkrev - Checks if we are treating a device with the correct rev.
462 * @sdev: si4713_device structure for the device we are communicating
464 static int si4713_checkrev(struct si4713_device *sdev)
466 struct i2c_client *client = v4l2_get_subdevdata(&sdev->sd);
468 u8 resp[SI4713_GETREV_NRESP];
470 rval = si4713_send_command(sdev, SI4713_CMD_GET_REV,
472 resp, ARRAY_SIZE(resp),
478 if (resp[1] == SI4713_PRODUCT_NUMBER) {
479 v4l2_info(&sdev->sd, "chip found @ 0x%02x (%s)\n",
480 client->addr << 1, client->adapter->name);
482 v4l2_err(&sdev->sd, "Invalid product number 0x%X\n", resp[1]);
489 * si4713_wait_stc - Waits STC interrupt and clears status bits. Useful
490 * for TX_TUNE_POWER, TX_TUNE_FREQ and TX_TUNE_MEAS
491 * @sdev: si4713_device structure for the device we are communicating
492 * @usecs: timeout to wait for STC interrupt signal
494 static int si4713_wait_stc(struct si4713_device *sdev, const int usecs)
496 struct i2c_client *client = v4l2_get_subdevdata(&sdev->sd);
497 u8 resp[SI4713_GET_STATUS_NRESP];
498 unsigned long start_jiffies = jiffies;
502 !wait_for_completion_timeout(&sdev->work, usecs_to_jiffies(usecs) + 1))
504 "(%s) Device took too much time to answer.\n", __func__);
507 /* Clear status bits */
508 err = si4713_send_command(sdev, SI4713_CMD_GET_INT_STATUS,
510 resp, ARRAY_SIZE(resp),
512 /* The USB device returns errors when it waits for the
513 * STC bit to be set. Hence polling */
515 v4l2_dbg(1, debug, &sdev->sd,
516 "%s: status bits: 0x%02x\n", __func__, resp[0]);
518 if (resp[0] & SI4713_STC_INT)
521 if (jiffies_to_usecs(jiffies - start_jiffies) > usecs)
522 return err < 0 ? err : -EIO;
523 /* We sleep here for 3-4 ms in order to avoid flooding the device
524 * with USB requests. The si4713 USB driver was developed
525 * by reverse engineering the Windows USB driver. The windows
526 * driver also has a ~2.5 ms delay between responses. */
527 usleep_range(3000, 4000);
532 * si4713_tx_tune_freq - Sets the state of the RF carrier and sets the tuning
533 * frequency between 76 and 108 MHz in 10 kHz units and
535 * @sdev: si4713_device structure for the device we are communicating
536 * @frequency: desired frequency (76 - 108 MHz, unit 10 KHz, step 50 kHz)
538 static int si4713_tx_tune_freq(struct si4713_device *sdev, u16 frequency)
541 u8 val[SI4713_TXFREQ_NRESP];
544 * .Second byte = frequency's MSB
545 * .Third byte = frequency's LSB
547 const u8 args[SI4713_TXFREQ_NARGS] = {
553 err = si4713_send_command(sdev, SI4713_CMD_TX_TUNE_FREQ,
554 args, ARRAY_SIZE(args), val,
555 ARRAY_SIZE(val), DEFAULT_TIMEOUT);
560 v4l2_dbg(1, debug, &sdev->sd,
561 "%s: frequency=0x%02x status=0x%02x\n", __func__,
564 err = si4713_wait_stc(sdev, TIMEOUT_TX_TUNE);
568 return compose_u16(args[1], args[2]);
572 * si4713_tx_tune_power - Sets the RF voltage level between 88 and 120 dBuV in
573 * 1 dB units. A value of 0x00 indicates off. The command
574 * also sets the antenna tuning capacitance. A value of 0
575 * indicates autotuning, and a value of 1 - 191 indicates
576 * a manual override, which results in a tuning
577 * capacitance of 0.25 pF x @antcap.
578 * @sdev: si4713_device structure for the device we are communicating
579 * @power: tuning power (88 - 120 dBuV, unit/step 1 dB)
580 * @antcap: value of antenna tuning capacitor (0 - 191)
582 static int si4713_tx_tune_power(struct si4713_device *sdev, u8 power,
586 u8 val[SI4713_TXPWR_NRESP];
590 * .Third byte = power
591 * .Fourth byte = antcap
593 u8 args[SI4713_TXPWR_NARGS] = {
600 /* Map power values 1-87 to MIN_POWER (88) */
601 if (power > 0 && power < SI4713_MIN_POWER)
602 args[2] = power = SI4713_MIN_POWER;
604 err = si4713_send_command(sdev, SI4713_CMD_TX_TUNE_POWER,
605 args, ARRAY_SIZE(args), val,
606 ARRAY_SIZE(val), DEFAULT_TIMEOUT);
611 v4l2_dbg(1, debug, &sdev->sd,
612 "%s: power=0x%02x antcap=0x%02x status=0x%02x\n",
613 __func__, power, antcap, val[0]);
615 return si4713_wait_stc(sdev, TIMEOUT_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.
621 * The Frequency must be between 76 and 108 MHz in 10 kHz
622 * units and steps of 50 kHz. The command also sets the
623 * antenna tuning capacitance. A value of 0 means
624 * autotuning, and a value of 1 to 191 indicates manual
626 * @sdev: si4713_device structure for the device we are communicating
627 * @frequency: desired frequency (76 - 108 MHz, unit 10 KHz, step 50 kHz)
628 * @antcap: value of antenna tuning capacitor (0 - 191)
630 static int si4713_tx_tune_measure(struct si4713_device *sdev, u16 frequency,
634 u8 val[SI4713_TXMEA_NRESP];
637 * .Second byte = frequency's MSB
638 * .Third byte = frequency's LSB
639 * .Fourth byte = antcap
641 const u8 args[SI4713_TXMEA_NARGS] = {
648 sdev->tune_rnl = DEFAULT_TUNE_RNL;
650 if (antcap > SI4713_MAX_ANTCAP)
653 err = si4713_send_command(sdev, SI4713_CMD_TX_TUNE_MEASURE,
654 args, ARRAY_SIZE(args), val,
655 ARRAY_SIZE(val), DEFAULT_TIMEOUT);
660 v4l2_dbg(1, debug, &sdev->sd,
661 "%s: frequency=0x%02x antcap=0x%02x status=0x%02x\n",
662 __func__, frequency, antcap, val[0]);
664 return si4713_wait_stc(sdev, TIMEOUT_TX_TUNE);
668 * si4713_tx_tune_status- Returns the status of the tx_tune_freq, tx_tune_mea or
669 * tx_tune_power commands. This command return the current
670 * frequency, output voltage in dBuV, the antenna tunning
671 * capacitance value and the received noise level. The
672 * command also clears the stcint interrupt bit when the
673 * first bit of its arguments is high.
674 * @sdev: si4713_device structure for the device we are communicating
675 * @intack: 0x01 to clear the seek/tune complete interrupt status indicator.
676 * @frequency: returned frequency
677 * @power: returned power
678 * @antcap: returned antenna capacitance
679 * @noise: returned noise level
681 static int si4713_tx_tune_status(struct si4713_device *sdev, u8 intack,
682 u16 *frequency, u8 *power,
683 u8 *antcap, u8 *noise)
686 u8 val[SI4713_TXSTATUS_NRESP];
688 * .First byte = intack bit
690 const u8 args[SI4713_TXSTATUS_NARGS] = {
691 intack & SI4713_INTACK_MASK,
694 err = si4713_send_command(sdev, SI4713_CMD_TX_TUNE_STATUS,
695 args, ARRAY_SIZE(args), val,
696 ARRAY_SIZE(val), DEFAULT_TIMEOUT);
699 v4l2_dbg(1, debug, &sdev->sd,
700 "%s: status=0x%02x\n", __func__, val[0]);
701 *frequency = compose_u16(val[2], val[3]);
702 sdev->frequency = *frequency;
706 v4l2_dbg(1, debug, &sdev->sd,
707 "%s: response: %d x 10 kHz (power %d, antcap %d, rnl %d)\n",
708 __func__, *frequency, *power, *antcap, *noise);
715 * si4713_tx_rds_buff - Loads the RDS group buffer FIFO or circular buffer.
716 * @sdev: si4713_device structure for the device we are communicating
717 * @mode: the buffer operation mode.
721 * @cbleft: returns the number of available circular buffer blocks minus the
722 * number of used circular buffer blocks.
724 static int si4713_tx_rds_buff(struct si4713_device *sdev, u8 mode, u16 rdsb,
725 u16 rdsc, u16 rdsd, s8 *cbleft)
728 u8 val[SI4713_RDSBUFF_NRESP];
730 const u8 args[SI4713_RDSBUFF_NARGS] = {
731 mode & SI4713_RDSBUFF_MODE_MASK,
740 err = si4713_send_command(sdev, SI4713_CMD_TX_RDS_BUFF,
741 args, ARRAY_SIZE(args), val,
742 ARRAY_SIZE(val), DEFAULT_TIMEOUT);
745 v4l2_dbg(1, debug, &sdev->sd,
746 "%s: status=0x%02x\n", __func__, val[0]);
747 *cbleft = (s8)val[2] - val[3];
748 v4l2_dbg(1, debug, &sdev->sd,
749 "%s: response: interrupts 0x%02x cb avail: %d cb used %d fifo avail %d fifo used %d\n",
750 __func__, val[1], val[2], val[3], val[4], val[5]);
757 * si4713_tx_rds_ps - Loads the program service buffer.
758 * @sdev: si4713_device structure for the device we are communicating
759 * @psid: program service id to be loaded.
760 * @pschar: assumed 4 size char array to be loaded into the program service
762 static int si4713_tx_rds_ps(struct si4713_device *sdev, u8 psid,
763 unsigned char *pschar)
766 u8 val[SI4713_RDSPS_NRESP];
768 const u8 args[SI4713_RDSPS_NARGS] = {
769 psid & SI4713_RDSPS_PSID_MASK,
776 err = si4713_send_command(sdev, SI4713_CMD_TX_RDS_PS,
777 args, ARRAY_SIZE(args), val,
778 ARRAY_SIZE(val), DEFAULT_TIMEOUT);
783 v4l2_dbg(1, debug, &sdev->sd, "%s: status=0x%02x\n", __func__, val[0]);
788 static int si4713_set_power_state(struct si4713_device *sdev, u8 value)
791 return si4713_powerup(sdev);
792 return si4713_powerdown(sdev);
795 static int si4713_set_mute(struct si4713_device *sdev, u16 mute)
799 mute = set_mute(mute);
801 if (sdev->power_state)
802 rval = si4713_write_property(sdev,
803 SI4713_TX_LINE_INPUT_MUTE, mute);
808 static int si4713_set_rds_ps_name(struct si4713_device *sdev, char *ps_name)
813 /* We want to clear the whole thing */
814 if (!strlen(ps_name))
815 memset(ps_name, 0, MAX_RDS_PS_NAME + 1);
817 if (sdev->power_state) {
818 /* Write the new ps name and clear the padding */
819 for (i = 0; i < MAX_RDS_PS_NAME; i += (RDS_BLOCK / 2)) {
820 rval = si4713_tx_rds_ps(sdev, (i / (RDS_BLOCK / 2)),
826 /* Setup the size to be sent */
828 len = strlen(ps_name) - 1;
832 rval = si4713_write_property(sdev,
833 SI4713_TX_RDS_PS_MESSAGE_COUNT,
834 rds_ps_nblocks(len));
838 rval = si4713_write_property(sdev,
839 SI4713_TX_RDS_PS_REPEAT_COUNT,
840 DEFAULT_RDS_PS_REPEAT_COUNT * 2);
848 static int si4713_set_rds_radio_text(struct si4713_device *sdev, const char *rt)
850 static const char cr[RDS_RADIOTEXT_BLK_SIZE] = { RDS_CARRIAGE_RETURN, 0 };
853 u8 b_index = 0, cr_inserted = 0;
856 if (!sdev->power_state)
859 rval = si4713_tx_rds_buff(sdev, RDS_BLOCK_CLEAR, 0, 0, 0, &left);
867 /* RDS spec says that if the last block isn't used,
868 * then apply a carriage return
870 if (t_index < (RDS_RADIOTEXT_INDEX_MAX * RDS_RADIOTEXT_BLK_SIZE)) {
871 for (i = 0; i < RDS_RADIOTEXT_BLK_SIZE; i++) {
872 if (!rt[t_index + i] ||
873 rt[t_index + i] == RDS_CARRIAGE_RETURN) {
881 rval = si4713_tx_rds_buff(sdev, RDS_BLOCK_LOAD,
882 compose_u16(RDS_RADIOTEXT_2A, b_index++),
883 compose_u16(rt[t_index], rt[t_index + 1]),
884 compose_u16(rt[t_index + 2], rt[t_index + 3]),
889 t_index += RDS_RADIOTEXT_BLK_SIZE;
899 * si4713_update_tune_status - update properties from tx_tune_status
900 * command. Must be called with sdev->mutex held.
901 * @sdev: si4713_device structure for the device we are communicating
903 static int si4713_update_tune_status(struct si4713_device *sdev)
907 u8 p = 0, a = 0, n = 0;
909 rval = si4713_tx_tune_status(sdev, 0x00, &f, &p, &a, &n);
914 /* TODO: check that power_level and antenna_capacitor really are not
915 changed by the hardware. If they are, then these controls should become
917 sdev->power_level = p;
918 sdev->antenna_capacitor = a;*/
925 static int si4713_choose_econtrol_action(struct si4713_device *sdev, u32 id,
926 s32 *bit, s32 *mask, u16 *property, int *mul,
927 unsigned long **table, int *size)
932 /* FM_TX class controls */
933 case V4L2_CID_RDS_TX_PI:
934 *property = SI4713_TX_RDS_PI;
937 case V4L2_CID_AUDIO_COMPRESSION_THRESHOLD:
938 *property = SI4713_TX_ACOMP_THRESHOLD;
941 case V4L2_CID_AUDIO_COMPRESSION_GAIN:
942 *property = SI4713_TX_ACOMP_GAIN;
945 case V4L2_CID_PILOT_TONE_FREQUENCY:
946 *property = SI4713_TX_PILOT_FREQUENCY;
949 case V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME:
950 *property = SI4713_TX_ACOMP_ATTACK_TIME;
951 *mul = ATTACK_TIME_UNIT;
953 case V4L2_CID_PILOT_TONE_DEVIATION:
954 *property = SI4713_TX_PILOT_DEVIATION;
957 case V4L2_CID_AUDIO_LIMITER_DEVIATION:
958 *property = SI4713_TX_AUDIO_DEVIATION;
961 case V4L2_CID_RDS_TX_DEVIATION:
962 *property = SI4713_TX_RDS_DEVIATION;
966 case V4L2_CID_RDS_TX_PTY:
967 *property = SI4713_TX_RDS_PS_MISC;
971 case V4L2_CID_RDS_TX_DYNAMIC_PTY:
972 *property = SI4713_TX_RDS_PS_MISC;
976 case V4L2_CID_RDS_TX_COMPRESSED:
977 *property = SI4713_TX_RDS_PS_MISC;
981 case V4L2_CID_RDS_TX_ARTIFICIAL_HEAD:
982 *property = SI4713_TX_RDS_PS_MISC;
986 case V4L2_CID_RDS_TX_MONO_STEREO:
987 *property = SI4713_TX_RDS_PS_MISC;
991 case V4L2_CID_RDS_TX_TRAFFIC_PROGRAM:
992 *property = SI4713_TX_RDS_PS_MISC;
996 case V4L2_CID_RDS_TX_TRAFFIC_ANNOUNCEMENT:
997 *property = SI4713_TX_RDS_PS_MISC;
1001 case V4L2_CID_RDS_TX_MUSIC_SPEECH:
1002 *property = SI4713_TX_RDS_PS_MISC;
1006 case V4L2_CID_AUDIO_LIMITER_ENABLED:
1007 *property = SI4713_TX_ACOMP_ENABLE;
1011 case V4L2_CID_AUDIO_COMPRESSION_ENABLED:
1012 *property = SI4713_TX_ACOMP_ENABLE;
1016 case V4L2_CID_PILOT_TONE_ENABLED:
1017 *property = SI4713_TX_COMPONENT_ENABLE;
1022 case V4L2_CID_AUDIO_LIMITER_RELEASE_TIME:
1023 *property = SI4713_TX_LIMITER_RELEASE_TIME;
1024 *table = limiter_times;
1025 *size = ARRAY_SIZE(limiter_times);
1027 case V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME:
1028 *property = SI4713_TX_ACOMP_RELEASE_TIME;
1029 *table = acomp_rtimes;
1030 *size = ARRAY_SIZE(acomp_rtimes);
1032 case V4L2_CID_TUNE_PREEMPHASIS:
1033 *property = SI4713_TX_PREEMPHASIS;
1034 *table = preemphasis_values;
1035 *size = ARRAY_SIZE(preemphasis_values);
1046 static int si4713_s_frequency(struct v4l2_subdev *sd, const struct v4l2_frequency *f);
1047 static int si4713_s_modulator(struct v4l2_subdev *sd, const struct v4l2_modulator *);
1049 * si4713_setup - Sets the device up with current configuration.
1050 * @sdev: si4713_device structure for the device we are communicating
1052 static int si4713_setup(struct si4713_device *sdev)
1054 struct v4l2_frequency f;
1055 struct v4l2_modulator vm;
1058 /* Device procedure needs to set frequency first */
1060 f.frequency = sdev->frequency ? sdev->frequency : DEFAULT_FREQUENCY;
1061 f.frequency = si4713_to_v4l2(f.frequency);
1062 rval = si4713_s_frequency(&sdev->sd, &f);
1066 vm.txsubchans = V4L2_TUNER_SUB_STEREO;
1068 vm.txsubchans = V4L2_TUNER_SUB_MONO;
1069 if (sdev->rds_enabled)
1070 vm.txsubchans |= V4L2_TUNER_SUB_RDS;
1071 si4713_s_modulator(&sdev->sd, &vm);
1077 * si4713_initialize - Sets the device up with default configuration.
1078 * @sdev: si4713_device structure for the device we are communicating
1080 static int si4713_initialize(struct si4713_device *sdev)
1084 rval = si4713_set_power_state(sdev, POWER_ON);
1088 rval = si4713_checkrev(sdev);
1092 rval = si4713_set_power_state(sdev, POWER_OFF);
1096 sdev->frequency = DEFAULT_FREQUENCY;
1098 sdev->tune_rnl = DEFAULT_TUNE_RNL;
1102 /* si4713_s_ctrl - set the value of a control */
1103 static int si4713_s_ctrl(struct v4l2_ctrl *ctrl)
1105 struct si4713_device *sdev =
1106 container_of(ctrl->handler, struct si4713_device, ctrl_handler);
1108 s32 bit = 0, mask = 0;
1111 unsigned long *table = NULL;
1117 if (ctrl->id != V4L2_CID_AUDIO_MUTE)
1121 ret = si4713_set_mute(sdev, ctrl->val);
1123 ret = si4713_set_power_state(sdev, POWER_DOWN);
1126 ret = si4713_set_power_state(sdev, POWER_UP);
1128 ret = si4713_set_mute(sdev, ctrl->val);
1130 ret = si4713_setup(sdev);
1136 if (!sdev->power_state)
1139 for (c = 1; !ret && c < ctrl->ncontrols; c++) {
1140 ctrl = ctrl->cluster[c];
1142 if (!force && !ctrl->is_new)
1146 case V4L2_CID_RDS_TX_PS_NAME:
1147 ret = si4713_set_rds_ps_name(sdev, ctrl->p_new.p_char);
1150 case V4L2_CID_RDS_TX_RADIO_TEXT:
1151 ret = si4713_set_rds_radio_text(sdev, ctrl->p_new.p_char);
1154 case V4L2_CID_TUNE_ANTENNA_CAPACITOR:
1155 /* don't handle this control if we force setting all
1156 * controls since in that case it will be handled by
1157 * V4L2_CID_TUNE_POWER_LEVEL. */
1161 case V4L2_CID_TUNE_POWER_LEVEL:
1162 ret = si4713_tx_tune_power(sdev,
1163 sdev->tune_pwr_level->val, sdev->tune_ant_cap->val);
1165 /* Make sure we don't set this twice */
1166 sdev->tune_ant_cap->is_new = false;
1167 sdev->tune_pwr_level->is_new = false;
1171 case V4L2_CID_RDS_TX_ALT_FREQS_ENABLE:
1172 case V4L2_CID_RDS_TX_ALT_FREQS:
1173 if (sdev->rds_alt_freqs_enable->val) {
1174 val = sdev->rds_alt_freqs->p_new.p_u32[0];
1175 val = val / 100 - 876 + 0xe101;
1179 ret = si4713_write_property(sdev, SI4713_TX_RDS_PS_AF, val);
1183 ret = si4713_choose_econtrol_action(sdev, ctrl->id, &bit,
1184 &mask, &property, &mul, &table, &size);
1192 ret = usecs_to_dev(val, table, size);
1200 ret = si4713_read_property(sdev, property, &val);
1203 val = set_bits(val, ctrl->val, bit, mask);
1206 ret = si4713_write_property(sdev, property, val);
1218 /* si4713_ioctl - deal with private ioctls (only rnl for now) */
1219 static long si4713_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
1221 struct si4713_device *sdev = to_si4713_device(sd);
1222 struct si4713_rnl *rnl = arg;
1230 case SI4713_IOC_MEASURE_RNL:
1231 frequency = v4l2_to_si4713(rnl->frequency);
1233 if (sdev->power_state) {
1234 /* Set desired measurement frequency */
1235 rval = si4713_tx_tune_measure(sdev, frequency, 0);
1238 /* get results from tune status */
1239 rval = si4713_update_tune_status(sdev);
1243 rnl->rnl = sdev->tune_rnl;
1248 rval = -ENOIOCTLCMD;
1254 /* si4713_g_modulator - get modulator attributes */
1255 static int si4713_g_modulator(struct v4l2_subdev *sd, struct v4l2_modulator *vm)
1257 struct si4713_device *sdev = to_si4713_device(sd);
1266 strscpy(vm->name, "FM Modulator", sizeof(vm->name));
1267 vm->capability = V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_LOW |
1268 V4L2_TUNER_CAP_RDS | V4L2_TUNER_CAP_RDS_CONTROLS;
1270 /* Report current frequency range limits */
1271 vm->rangelow = si4713_to_v4l2(FREQ_RANGE_LOW);
1272 vm->rangehigh = si4713_to_v4l2(FREQ_RANGE_HIGH);
1274 if (sdev->power_state) {
1277 rval = si4713_read_property(sdev, SI4713_TX_COMPONENT_ENABLE,
1282 sdev->stereo = get_status_bit(comp_en, 1, 1 << 1);
1285 /* Report current audio mode: mono or stereo */
1287 vm->txsubchans = V4L2_TUNER_SUB_STEREO;
1289 vm->txsubchans = V4L2_TUNER_SUB_MONO;
1291 /* Report rds feature status */
1292 if (sdev->rds_enabled)
1293 vm->txsubchans |= V4L2_TUNER_SUB_RDS;
1295 vm->txsubchans &= ~V4L2_TUNER_SUB_RDS;
1300 /* si4713_s_modulator - set modulator attributes */
1301 static int si4713_s_modulator(struct v4l2_subdev *sd, const struct v4l2_modulator *vm)
1303 struct si4713_device *sdev = to_si4713_device(sd);
1314 /* Set audio mode: mono or stereo */
1315 if (vm->txsubchans & V4L2_TUNER_SUB_STEREO)
1317 else if (vm->txsubchans & V4L2_TUNER_SUB_MONO)
1322 rds = !!(vm->txsubchans & V4L2_TUNER_SUB_RDS);
1324 if (sdev->power_state) {
1325 rval = si4713_read_property(sdev,
1326 SI4713_TX_COMPONENT_ENABLE, &p);
1330 p = set_bits(p, stereo, 1, 1 << 1);
1331 p = set_bits(p, rds, 2, 1 << 2);
1333 rval = si4713_write_property(sdev,
1334 SI4713_TX_COMPONENT_ENABLE, p);
1339 sdev->stereo = stereo;
1340 sdev->rds_enabled = rds;
1345 /* si4713_g_frequency - get tuner or modulator radio frequency */
1346 static int si4713_g_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *f)
1348 struct si4713_device *sdev = to_si4713_device(sd);
1354 if (sdev->power_state) {
1358 rval = si4713_tx_tune_status(sdev, 0x00, &freq, &p, &a, &n);
1362 sdev->frequency = freq;
1365 f->frequency = si4713_to_v4l2(sdev->frequency);
1370 /* si4713_s_frequency - set tuner or modulator radio frequency */
1371 static int si4713_s_frequency(struct v4l2_subdev *sd, const struct v4l2_frequency *f)
1373 struct si4713_device *sdev = to_si4713_device(sd);
1375 u16 frequency = v4l2_to_si4713(f->frequency);
1380 /* Check frequency range */
1381 frequency = clamp_t(u16, frequency, FREQ_RANGE_LOW, FREQ_RANGE_HIGH);
1383 if (sdev->power_state) {
1384 rval = si4713_tx_tune_freq(sdev, frequency);
1390 sdev->frequency = frequency;
1395 static const struct v4l2_ctrl_ops si4713_ctrl_ops = {
1396 .s_ctrl = si4713_s_ctrl,
1399 static const struct v4l2_subdev_core_ops si4713_subdev_core_ops = {
1400 .ioctl = si4713_ioctl,
1403 static const struct v4l2_subdev_tuner_ops si4713_subdev_tuner_ops = {
1404 .g_frequency = si4713_g_frequency,
1405 .s_frequency = si4713_s_frequency,
1406 .g_modulator = si4713_g_modulator,
1407 .s_modulator = si4713_s_modulator,
1410 static const struct v4l2_subdev_ops si4713_subdev_ops = {
1411 .core = &si4713_subdev_core_ops,
1412 .tuner = &si4713_subdev_tuner_ops,
1415 static const struct v4l2_ctrl_config si4713_alt_freqs_ctrl = {
1416 .id = V4L2_CID_RDS_TX_ALT_FREQS,
1417 .type = V4L2_CTRL_TYPE_U32,
1423 .elem_size = sizeof(u32),
1427 * I2C driver interface
1429 /* si4713_probe - probe for the device */
1430 static int si4713_probe(struct i2c_client *client)
1432 struct si4713_device *sdev;
1433 struct v4l2_ctrl_handler *hdl;
1434 struct si4713_platform_data *pdata = client->dev.platform_data;
1435 struct device_node *np = client->dev.of_node;
1436 struct radio_si4713_platform_data si4713_pdev_pdata;
1437 struct platform_device *si4713_pdev;
1440 sdev = devm_kzalloc(&client->dev, sizeof(*sdev), GFP_KERNEL);
1442 dev_err(&client->dev, "Failed to alloc video device.\n");
1447 sdev->gpio_reset = devm_gpiod_get_optional(&client->dev, "reset",
1449 if (IS_ERR(sdev->gpio_reset)) {
1450 rval = PTR_ERR(sdev->gpio_reset);
1451 dev_err(&client->dev, "Failed to request gpio: %d\n", rval);
1455 sdev->vdd = devm_regulator_get_optional(&client->dev, "vdd");
1456 if (IS_ERR(sdev->vdd)) {
1457 rval = PTR_ERR(sdev->vdd);
1458 if (rval == -EPROBE_DEFER)
1461 dev_dbg(&client->dev, "no vdd regulator found: %d\n", rval);
1465 sdev->vio = devm_regulator_get_optional(&client->dev, "vio");
1466 if (IS_ERR(sdev->vio)) {
1467 rval = PTR_ERR(sdev->vio);
1468 if (rval == -EPROBE_DEFER)
1471 dev_dbg(&client->dev, "no vio regulator found: %d\n", rval);
1475 v4l2_i2c_subdev_init(&sdev->sd, client, &si4713_subdev_ops);
1477 init_completion(&sdev->work);
1479 hdl = &sdev->ctrl_handler;
1480 v4l2_ctrl_handler_init(hdl, 20);
1481 sdev->mute = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
1482 V4L2_CID_AUDIO_MUTE, 0, 1, 1, DEFAULT_MUTE);
1484 sdev->rds_pi = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
1485 V4L2_CID_RDS_TX_PI, 0, 0xffff, 1, DEFAULT_RDS_PI);
1486 sdev->rds_pty = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
1487 V4L2_CID_RDS_TX_PTY, 0, 31, 1, DEFAULT_RDS_PTY);
1488 sdev->rds_compressed = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
1489 V4L2_CID_RDS_TX_COMPRESSED, 0, 1, 1, 0);
1490 sdev->rds_art_head = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
1491 V4L2_CID_RDS_TX_ARTIFICIAL_HEAD, 0, 1, 1, 0);
1492 sdev->rds_stereo = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
1493 V4L2_CID_RDS_TX_MONO_STEREO, 0, 1, 1, 1);
1494 sdev->rds_tp = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
1495 V4L2_CID_RDS_TX_TRAFFIC_PROGRAM, 0, 1, 1, 0);
1496 sdev->rds_ta = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
1497 V4L2_CID_RDS_TX_TRAFFIC_ANNOUNCEMENT, 0, 1, 1, 0);
1498 sdev->rds_ms = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
1499 V4L2_CID_RDS_TX_MUSIC_SPEECH, 0, 1, 1, 1);
1500 sdev->rds_dyn_pty = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
1501 V4L2_CID_RDS_TX_DYNAMIC_PTY, 0, 1, 1, 0);
1502 sdev->rds_alt_freqs_enable = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
1503 V4L2_CID_RDS_TX_ALT_FREQS_ENABLE, 0, 1, 1, 0);
1504 sdev->rds_alt_freqs = v4l2_ctrl_new_custom(hdl, &si4713_alt_freqs_ctrl, NULL);
1505 sdev->rds_deviation = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
1506 V4L2_CID_RDS_TX_DEVIATION, 0, MAX_RDS_DEVIATION,
1507 10, DEFAULT_RDS_DEVIATION);
1509 * Report step as 8. From RDS spec, psname
1510 * should be 8. But there are receivers which scroll strings
1513 sdev->rds_ps_name = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
1514 V4L2_CID_RDS_TX_PS_NAME, 0, MAX_RDS_PS_NAME, 8, 0);
1516 * Report step as 32 (2A block). From RDS spec,
1517 * radio text should be 32 for 2A block. But there are receivers
1518 * which scroll strings sized as 32xN. Setting default to 32.
1520 sdev->rds_radio_text = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
1521 V4L2_CID_RDS_TX_RADIO_TEXT, 0, MAX_RDS_RADIO_TEXT, 32, 0);
1523 sdev->limiter_enabled = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
1524 V4L2_CID_AUDIO_LIMITER_ENABLED, 0, 1, 1, 1);
1525 sdev->limiter_release_time = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
1526 V4L2_CID_AUDIO_LIMITER_RELEASE_TIME, 250,
1527 MAX_LIMITER_RELEASE_TIME, 10, DEFAULT_LIMITER_RTIME);
1528 sdev->limiter_deviation = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
1529 V4L2_CID_AUDIO_LIMITER_DEVIATION, 0,
1530 MAX_LIMITER_DEVIATION, 10, DEFAULT_LIMITER_DEV);
1532 sdev->compression_enabled = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
1533 V4L2_CID_AUDIO_COMPRESSION_ENABLED, 0, 1, 1, 1);
1534 sdev->compression_gain = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
1535 V4L2_CID_AUDIO_COMPRESSION_GAIN, 0, MAX_ACOMP_GAIN, 1,
1536 DEFAULT_ACOMP_GAIN);
1537 sdev->compression_threshold = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
1538 V4L2_CID_AUDIO_COMPRESSION_THRESHOLD,
1539 MIN_ACOMP_THRESHOLD, MAX_ACOMP_THRESHOLD, 1,
1540 DEFAULT_ACOMP_THRESHOLD);
1541 sdev->compression_attack_time = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
1542 V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME, 0,
1543 MAX_ACOMP_ATTACK_TIME, 500, DEFAULT_ACOMP_ATIME);
1544 sdev->compression_release_time = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
1545 V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME, 100000,
1546 MAX_ACOMP_RELEASE_TIME, 100000, DEFAULT_ACOMP_RTIME);
1548 sdev->pilot_tone_enabled = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
1549 V4L2_CID_PILOT_TONE_ENABLED, 0, 1, 1, 1);
1550 sdev->pilot_tone_deviation = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
1551 V4L2_CID_PILOT_TONE_DEVIATION, 0, MAX_PILOT_DEVIATION,
1552 10, DEFAULT_PILOT_DEVIATION);
1553 sdev->pilot_tone_freq = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
1554 V4L2_CID_PILOT_TONE_FREQUENCY, 0, MAX_PILOT_FREQUENCY,
1555 1, DEFAULT_PILOT_FREQUENCY);
1557 sdev->tune_preemphasis = v4l2_ctrl_new_std_menu(hdl, &si4713_ctrl_ops,
1558 V4L2_CID_TUNE_PREEMPHASIS,
1559 V4L2_PREEMPHASIS_75_uS, 0, V4L2_PREEMPHASIS_50_uS);
1560 sdev->tune_pwr_level = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
1561 V4L2_CID_TUNE_POWER_LEVEL, 0, SI4713_MAX_POWER,
1562 1, DEFAULT_POWER_LEVEL);
1563 sdev->tune_ant_cap = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
1564 V4L2_CID_TUNE_ANTENNA_CAPACITOR, 0, SI4713_MAX_ANTCAP,
1571 v4l2_ctrl_cluster(29, &sdev->mute);
1572 sdev->sd.ctrl_handler = hdl;
1575 rval = devm_request_irq(&client->dev, client->irq,
1576 si4713_handler, IRQF_TRIGGER_FALLING,
1577 client->name, sdev);
1579 v4l2_err(&sdev->sd, "Could not request IRQ\n");
1582 v4l2_dbg(1, debug, &sdev->sd, "IRQ requested.\n");
1584 v4l2_warn(&sdev->sd, "IRQ not configured. Using timeouts.\n");
1587 rval = si4713_initialize(sdev);
1589 v4l2_err(&sdev->sd, "Failed to probe device information.\n");
1593 if (!np && (!pdata || !pdata->is_platform_device))
1596 si4713_pdev = platform_device_alloc("radio-si4713", -1);
1602 si4713_pdev_pdata.subdev = client;
1603 rval = platform_device_add_data(si4713_pdev, &si4713_pdev_pdata,
1604 sizeof(si4713_pdev_pdata));
1608 rval = platform_device_add(si4713_pdev);
1612 sdev->pd = si4713_pdev;
1617 platform_device_put(si4713_pdev);
1618 v4l2_device_unregister_subdev(&sdev->sd);
1620 v4l2_ctrl_handler_free(hdl);
1625 /* si4713_remove - remove the device */
1626 static int si4713_remove(struct i2c_client *client)
1628 struct v4l2_subdev *sd = i2c_get_clientdata(client);
1629 struct si4713_device *sdev = to_si4713_device(sd);
1631 platform_device_unregister(sdev->pd);
1633 if (sdev->power_state)
1634 si4713_set_power_state(sdev, POWER_DOWN);
1636 v4l2_device_unregister_subdev(sd);
1637 v4l2_ctrl_handler_free(sd->ctrl_handler);
1642 /* si4713_i2c_driver - i2c driver interface */
1643 static const struct i2c_device_id si4713_id[] = {
1647 MODULE_DEVICE_TABLE(i2c, si4713_id);
1649 #if IS_ENABLED(CONFIG_OF)
1650 static const struct of_device_id si4713_of_match[] = {
1651 { .compatible = "silabs,si4713" },
1654 MODULE_DEVICE_TABLE(of, si4713_of_match);
1657 static struct i2c_driver si4713_i2c_driver = {
1660 .of_match_table = of_match_ptr(si4713_of_match),
1662 .probe_new = si4713_probe,
1663 .remove = si4713_remove,
1664 .id_table = si4713_id,
1667 module_i2c_driver(si4713_i2c_driver);