162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * drivers/media/radio/si4713-i2c.h
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * Property and commands definitions for Si4713 radio transmitter chip.
562306a36Sopenharmony_ci *
662306a36Sopenharmony_ci * Copyright (c) 2008 Instituto Nokia de Tecnologia - INdT
762306a36Sopenharmony_ci * Contact: Eduardo Valentin <eduardo.valentin@nokia.com>
862306a36Sopenharmony_ci *
962306a36Sopenharmony_ci * This file is licensed under the terms of the GNU General Public License
1062306a36Sopenharmony_ci * version 2. This program is licensed "as is" without any warranty of any
1162306a36Sopenharmony_ci * kind, whether express or implied.
1262306a36Sopenharmony_ci *
1362306a36Sopenharmony_ci */
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci#ifndef SI4713_I2C_H
1662306a36Sopenharmony_ci#define SI4713_I2C_H
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci#include <linux/platform_device.h>
1962306a36Sopenharmony_ci#include <linux/regulator/consumer.h>
2062306a36Sopenharmony_ci#include <linux/gpio/consumer.h>
2162306a36Sopenharmony_ci#include <media/v4l2-subdev.h>
2262306a36Sopenharmony_ci#include <media/v4l2-ctrls.h>
2362306a36Sopenharmony_ci#include <linux/platform_data/media/si4713.h>
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ci#define SI4713_PRODUCT_NUMBER		0x0D
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_ci/* Command Timeouts */
2862306a36Sopenharmony_ci#define DEFAULT_TIMEOUT			500
2962306a36Sopenharmony_ci#define TIMEOUT_SET_PROPERTY		20
3062306a36Sopenharmony_ci#define TIMEOUT_TX_TUNE_POWER		30000
3162306a36Sopenharmony_ci#define TIMEOUT_TX_TUNE			110000
3262306a36Sopenharmony_ci#define TIMEOUT_POWER_UP		200000
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ci/*
3562306a36Sopenharmony_ci * Command and its arguments definitions
3662306a36Sopenharmony_ci */
3762306a36Sopenharmony_ci#define SI4713_PWUP_CTSIEN		(1<<7)
3862306a36Sopenharmony_ci#define SI4713_PWUP_GPO2OEN		(1<<6)
3962306a36Sopenharmony_ci#define SI4713_PWUP_PATCH		(1<<5)
4062306a36Sopenharmony_ci#define SI4713_PWUP_XOSCEN		(1<<4)
4162306a36Sopenharmony_ci#define SI4713_PWUP_FUNC_TX		0x02
4262306a36Sopenharmony_ci#define SI4713_PWUP_FUNC_PATCH		0x0F
4362306a36Sopenharmony_ci#define SI4713_PWUP_OPMOD_ANALOG	0x50
4462306a36Sopenharmony_ci#define SI4713_PWUP_OPMOD_DIGITAL	0x0F
4562306a36Sopenharmony_ci#define SI4713_PWUP_NARGS		2
4662306a36Sopenharmony_ci#define SI4713_PWUP_NRESP		1
4762306a36Sopenharmony_ci#define SI4713_CMD_POWER_UP		0x01
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_ci#define SI4713_GETREV_NRESP		9
5062306a36Sopenharmony_ci#define SI4713_CMD_GET_REV		0x10
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ci#define SI4713_PWDN_NRESP		1
5362306a36Sopenharmony_ci#define SI4713_CMD_POWER_DOWN		0x11
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ci#define SI4713_SET_PROP_NARGS		5
5662306a36Sopenharmony_ci#define SI4713_SET_PROP_NRESP		1
5762306a36Sopenharmony_ci#define SI4713_CMD_SET_PROPERTY		0x12
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_ci#define SI4713_GET_PROP_NARGS		3
6062306a36Sopenharmony_ci#define SI4713_GET_PROP_NRESP		4
6162306a36Sopenharmony_ci#define SI4713_CMD_GET_PROPERTY		0x13
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_ci#define SI4713_GET_STATUS_NRESP		1
6462306a36Sopenharmony_ci#define SI4713_CMD_GET_INT_STATUS	0x14
6562306a36Sopenharmony_ci
6662306a36Sopenharmony_ci#define SI4713_CMD_PATCH_ARGS		0x15
6762306a36Sopenharmony_ci#define SI4713_CMD_PATCH_DATA		0x16
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_ci#define SI4713_MAX_FREQ			10800
7062306a36Sopenharmony_ci#define SI4713_MIN_FREQ			7600
7162306a36Sopenharmony_ci#define SI4713_TXFREQ_NARGS		3
7262306a36Sopenharmony_ci#define SI4713_TXFREQ_NRESP		1
7362306a36Sopenharmony_ci#define SI4713_CMD_TX_TUNE_FREQ		0x30
7462306a36Sopenharmony_ci
7562306a36Sopenharmony_ci#define SI4713_MAX_POWER		120
7662306a36Sopenharmony_ci#define SI4713_MIN_POWER		88
7762306a36Sopenharmony_ci#define SI4713_MAX_ANTCAP		191
7862306a36Sopenharmony_ci#define SI4713_MIN_ANTCAP		0
7962306a36Sopenharmony_ci#define SI4713_TXPWR_NARGS		4
8062306a36Sopenharmony_ci#define SI4713_TXPWR_NRESP		1
8162306a36Sopenharmony_ci#define SI4713_CMD_TX_TUNE_POWER	0x31
8262306a36Sopenharmony_ci
8362306a36Sopenharmony_ci#define SI4713_TXMEA_NARGS		4
8462306a36Sopenharmony_ci#define SI4713_TXMEA_NRESP		1
8562306a36Sopenharmony_ci#define SI4713_CMD_TX_TUNE_MEASURE	0x32
8662306a36Sopenharmony_ci
8762306a36Sopenharmony_ci#define SI4713_INTACK_MASK		0x01
8862306a36Sopenharmony_ci#define SI4713_TXSTATUS_NARGS		1
8962306a36Sopenharmony_ci#define SI4713_TXSTATUS_NRESP		8
9062306a36Sopenharmony_ci#define SI4713_CMD_TX_TUNE_STATUS	0x33
9162306a36Sopenharmony_ci
9262306a36Sopenharmony_ci#define SI4713_OVERMOD_BIT		(1 << 2)
9362306a36Sopenharmony_ci#define SI4713_IALH_BIT			(1 << 1)
9462306a36Sopenharmony_ci#define SI4713_IALL_BIT			(1 << 0)
9562306a36Sopenharmony_ci#define SI4713_ASQSTATUS_NARGS		1
9662306a36Sopenharmony_ci#define SI4713_ASQSTATUS_NRESP		5
9762306a36Sopenharmony_ci#define SI4713_CMD_TX_ASQ_STATUS	0x34
9862306a36Sopenharmony_ci
9962306a36Sopenharmony_ci#define SI4713_RDSBUFF_MODE_MASK	0x87
10062306a36Sopenharmony_ci#define SI4713_RDSBUFF_NARGS		7
10162306a36Sopenharmony_ci#define SI4713_RDSBUFF_NRESP		6
10262306a36Sopenharmony_ci#define SI4713_CMD_TX_RDS_BUFF		0x35
10362306a36Sopenharmony_ci
10462306a36Sopenharmony_ci#define SI4713_RDSPS_PSID_MASK		0x1F
10562306a36Sopenharmony_ci#define SI4713_RDSPS_NARGS		5
10662306a36Sopenharmony_ci#define SI4713_RDSPS_NRESP		1
10762306a36Sopenharmony_ci#define SI4713_CMD_TX_RDS_PS		0x36
10862306a36Sopenharmony_ci
10962306a36Sopenharmony_ci#define SI4713_CMD_GPO_CTL		0x80
11062306a36Sopenharmony_ci#define SI4713_CMD_GPO_SET		0x81
11162306a36Sopenharmony_ci
11262306a36Sopenharmony_ci/*
11362306a36Sopenharmony_ci * Bits from status response
11462306a36Sopenharmony_ci */
11562306a36Sopenharmony_ci#define SI4713_CTS			(1<<7)
11662306a36Sopenharmony_ci#define SI4713_ERR			(1<<6)
11762306a36Sopenharmony_ci#define SI4713_RDS_INT			(1<<2)
11862306a36Sopenharmony_ci#define SI4713_ASQ_INT			(1<<1)
11962306a36Sopenharmony_ci#define SI4713_STC_INT			(1<<0)
12062306a36Sopenharmony_ci
12162306a36Sopenharmony_ci/*
12262306a36Sopenharmony_ci * Property definitions
12362306a36Sopenharmony_ci */
12462306a36Sopenharmony_ci#define SI4713_GPO_IEN			0x0001
12562306a36Sopenharmony_ci#define SI4713_DIG_INPUT_FORMAT		0x0101
12662306a36Sopenharmony_ci#define SI4713_DIG_INPUT_SAMPLE_RATE	0x0103
12762306a36Sopenharmony_ci#define SI4713_REFCLK_FREQ		0x0201
12862306a36Sopenharmony_ci#define SI4713_REFCLK_PRESCALE		0x0202
12962306a36Sopenharmony_ci#define SI4713_TX_COMPONENT_ENABLE	0x2100
13062306a36Sopenharmony_ci#define SI4713_TX_AUDIO_DEVIATION	0x2101
13162306a36Sopenharmony_ci#define SI4713_TX_PILOT_DEVIATION	0x2102
13262306a36Sopenharmony_ci#define SI4713_TX_RDS_DEVIATION		0x2103
13362306a36Sopenharmony_ci#define SI4713_TX_LINE_INPUT_LEVEL	0x2104
13462306a36Sopenharmony_ci#define SI4713_TX_LINE_INPUT_MUTE	0x2105
13562306a36Sopenharmony_ci#define SI4713_TX_PREEMPHASIS		0x2106
13662306a36Sopenharmony_ci#define SI4713_TX_PILOT_FREQUENCY	0x2107
13762306a36Sopenharmony_ci#define SI4713_TX_ACOMP_ENABLE		0x2200
13862306a36Sopenharmony_ci#define SI4713_TX_ACOMP_THRESHOLD	0x2201
13962306a36Sopenharmony_ci#define SI4713_TX_ACOMP_ATTACK_TIME	0x2202
14062306a36Sopenharmony_ci#define SI4713_TX_ACOMP_RELEASE_TIME	0x2203
14162306a36Sopenharmony_ci#define SI4713_TX_ACOMP_GAIN		0x2204
14262306a36Sopenharmony_ci#define SI4713_TX_LIMITER_RELEASE_TIME	0x2205
14362306a36Sopenharmony_ci#define SI4713_TX_ASQ_INTERRUPT_SOURCE	0x2300
14462306a36Sopenharmony_ci#define SI4713_TX_ASQ_LEVEL_LOW		0x2301
14562306a36Sopenharmony_ci#define SI4713_TX_ASQ_DURATION_LOW	0x2302
14662306a36Sopenharmony_ci#define SI4713_TX_ASQ_LEVEL_HIGH	0x2303
14762306a36Sopenharmony_ci#define SI4713_TX_ASQ_DURATION_HIGH	0x2304
14862306a36Sopenharmony_ci#define SI4713_TX_RDS_INTERRUPT_SOURCE	0x2C00
14962306a36Sopenharmony_ci#define SI4713_TX_RDS_PI		0x2C01
15062306a36Sopenharmony_ci#define SI4713_TX_RDS_PS_MIX		0x2C02
15162306a36Sopenharmony_ci#define SI4713_TX_RDS_PS_MISC		0x2C03
15262306a36Sopenharmony_ci#define SI4713_TX_RDS_PS_REPEAT_COUNT	0x2C04
15362306a36Sopenharmony_ci#define SI4713_TX_RDS_PS_MESSAGE_COUNT	0x2C05
15462306a36Sopenharmony_ci#define SI4713_TX_RDS_PS_AF		0x2C06
15562306a36Sopenharmony_ci#define SI4713_TX_RDS_FIFO_SIZE		0x2C07
15662306a36Sopenharmony_ci
15762306a36Sopenharmony_ci#define PREEMPHASIS_USA			75
15862306a36Sopenharmony_ci#define PREEMPHASIS_EU			50
15962306a36Sopenharmony_ci#define PREEMPHASIS_DISABLED		0
16062306a36Sopenharmony_ci#define FMPE_USA			0x00
16162306a36Sopenharmony_ci#define FMPE_EU				0x01
16262306a36Sopenharmony_ci#define FMPE_DISABLED			0x02
16362306a36Sopenharmony_ci
16462306a36Sopenharmony_ci#define POWER_UP			0x01
16562306a36Sopenharmony_ci#define POWER_DOWN			0x00
16662306a36Sopenharmony_ci
16762306a36Sopenharmony_ci#define MAX_RDS_PTY			31
16862306a36Sopenharmony_ci#define MAX_RDS_DEVIATION		90000
16962306a36Sopenharmony_ci
17062306a36Sopenharmony_ci/*
17162306a36Sopenharmony_ci * PSNAME is known to be defined as 8 character sized (RDS Spec).
17262306a36Sopenharmony_ci * However, there is receivers which scroll PSNAME 8xN sized.
17362306a36Sopenharmony_ci */
17462306a36Sopenharmony_ci#define MAX_RDS_PS_NAME			96
17562306a36Sopenharmony_ci
17662306a36Sopenharmony_ci/*
17762306a36Sopenharmony_ci * MAX_RDS_RADIO_TEXT is known to be defined as 32 (2A group) or 64 (2B group)
17862306a36Sopenharmony_ci * character sized (RDS Spec).
17962306a36Sopenharmony_ci * However, there is receivers which scroll them as well.
18062306a36Sopenharmony_ci */
18162306a36Sopenharmony_ci#define MAX_RDS_RADIO_TEXT		384
18262306a36Sopenharmony_ci
18362306a36Sopenharmony_ci#define MAX_LIMITER_RELEASE_TIME	102390
18462306a36Sopenharmony_ci#define MAX_LIMITER_DEVIATION		90000
18562306a36Sopenharmony_ci
18662306a36Sopenharmony_ci#define MAX_PILOT_DEVIATION		90000
18762306a36Sopenharmony_ci#define MAX_PILOT_FREQUENCY		19000
18862306a36Sopenharmony_ci
18962306a36Sopenharmony_ci#define MAX_ACOMP_RELEASE_TIME		1000000
19062306a36Sopenharmony_ci#define MAX_ACOMP_ATTACK_TIME		5000
19162306a36Sopenharmony_ci#define MAX_ACOMP_THRESHOLD		0
19262306a36Sopenharmony_ci#define MIN_ACOMP_THRESHOLD		(-40)
19362306a36Sopenharmony_ci#define MAX_ACOMP_GAIN			20
19462306a36Sopenharmony_ci
19562306a36Sopenharmony_ci/*
19662306a36Sopenharmony_ci * si4713_device - private data
19762306a36Sopenharmony_ci */
19862306a36Sopenharmony_cistruct si4713_device {
19962306a36Sopenharmony_ci	/* v4l2_subdev and i2c reference (v4l2_subdev priv data) */
20062306a36Sopenharmony_ci	struct v4l2_subdev sd;
20162306a36Sopenharmony_ci	struct v4l2_ctrl_handler ctrl_handler;
20262306a36Sopenharmony_ci	/* private data structures */
20362306a36Sopenharmony_ci	struct { /* si4713 control cluster */
20462306a36Sopenharmony_ci		/* This is one big cluster since the mute control
20562306a36Sopenharmony_ci		 * powers off the device and after unmuting again all
20662306a36Sopenharmony_ci		 * controls need to be set at once. The only way of doing
20762306a36Sopenharmony_ci		 * that is by making it one big cluster. */
20862306a36Sopenharmony_ci		struct v4l2_ctrl *mute;
20962306a36Sopenharmony_ci		struct v4l2_ctrl *rds_ps_name;
21062306a36Sopenharmony_ci		struct v4l2_ctrl *rds_radio_text;
21162306a36Sopenharmony_ci		struct v4l2_ctrl *rds_pi;
21262306a36Sopenharmony_ci		struct v4l2_ctrl *rds_deviation;
21362306a36Sopenharmony_ci		struct v4l2_ctrl *rds_pty;
21462306a36Sopenharmony_ci		struct v4l2_ctrl *rds_compressed;
21562306a36Sopenharmony_ci		struct v4l2_ctrl *rds_art_head;
21662306a36Sopenharmony_ci		struct v4l2_ctrl *rds_stereo;
21762306a36Sopenharmony_ci		struct v4l2_ctrl *rds_ta;
21862306a36Sopenharmony_ci		struct v4l2_ctrl *rds_tp;
21962306a36Sopenharmony_ci		struct v4l2_ctrl *rds_ms;
22062306a36Sopenharmony_ci		struct v4l2_ctrl *rds_dyn_pty;
22162306a36Sopenharmony_ci		struct v4l2_ctrl *rds_alt_freqs_enable;
22262306a36Sopenharmony_ci		struct v4l2_ctrl *rds_alt_freqs;
22362306a36Sopenharmony_ci		struct v4l2_ctrl *compression_enabled;
22462306a36Sopenharmony_ci		struct v4l2_ctrl *compression_threshold;
22562306a36Sopenharmony_ci		struct v4l2_ctrl *compression_gain;
22662306a36Sopenharmony_ci		struct v4l2_ctrl *compression_attack_time;
22762306a36Sopenharmony_ci		struct v4l2_ctrl *compression_release_time;
22862306a36Sopenharmony_ci		struct v4l2_ctrl *pilot_tone_enabled;
22962306a36Sopenharmony_ci		struct v4l2_ctrl *pilot_tone_freq;
23062306a36Sopenharmony_ci		struct v4l2_ctrl *pilot_tone_deviation;
23162306a36Sopenharmony_ci		struct v4l2_ctrl *limiter_enabled;
23262306a36Sopenharmony_ci		struct v4l2_ctrl *limiter_deviation;
23362306a36Sopenharmony_ci		struct v4l2_ctrl *limiter_release_time;
23462306a36Sopenharmony_ci		struct v4l2_ctrl *tune_preemphasis;
23562306a36Sopenharmony_ci		struct v4l2_ctrl *tune_pwr_level;
23662306a36Sopenharmony_ci		struct v4l2_ctrl *tune_ant_cap;
23762306a36Sopenharmony_ci	};
23862306a36Sopenharmony_ci	struct completion work;
23962306a36Sopenharmony_ci	struct regulator *vdd;
24062306a36Sopenharmony_ci	struct regulator *vio;
24162306a36Sopenharmony_ci	struct gpio_desc *gpio_reset;
24262306a36Sopenharmony_ci	struct platform_device *pd;
24362306a36Sopenharmony_ci	u32 power_state;
24462306a36Sopenharmony_ci	u32 rds_enabled;
24562306a36Sopenharmony_ci	u32 frequency;
24662306a36Sopenharmony_ci	u32 preemphasis;
24762306a36Sopenharmony_ci	u32 stereo;
24862306a36Sopenharmony_ci	u32 tune_rnl;
24962306a36Sopenharmony_ci};
25062306a36Sopenharmony_ci
25162306a36Sopenharmony_cistruct radio_si4713_platform_data {
25262306a36Sopenharmony_ci	struct i2c_client *subdev;
25362306a36Sopenharmony_ci};
25462306a36Sopenharmony_ci#endif /* ifndef SI4713_I2C_H */
255