1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2cb7a01acSMauro Carvalho Chehab /*
3cb7a01acSMauro Carvalho Chehab */
4cb7a01acSMauro Carvalho Chehab
5cb7a01acSMauro Carvalho Chehab #ifndef MSP3400_DRIVER_H
6cb7a01acSMauro Carvalho Chehab #define MSP3400_DRIVER_H
7cb7a01acSMauro Carvalho Chehab
8d647f0b7SMauro Carvalho Chehab #include <media/drv-intf/msp3400.h>
9cb7a01acSMauro Carvalho Chehab #include <media/v4l2-device.h>
10cb7a01acSMauro Carvalho Chehab #include <media/v4l2-ctrls.h>
11fb493282SMauro Carvalho Chehab #include <media/v4l2-mc.h>
12cb7a01acSMauro Carvalho Chehab
13cb7a01acSMauro Carvalho Chehab /* ---------------------------------------------------------------------- */
14cb7a01acSMauro Carvalho Chehab
15cb7a01acSMauro Carvalho Chehab /* This macro is allowed for *constants* only, gcc must calculate it
16cb7a01acSMauro Carvalho Chehab at compile time. Remember -- no floats in kernel mode */
17cb7a01acSMauro Carvalho Chehab #define MSP_CARRIER(freq) ((int)((float)(freq / 18.432) * (1 << 24)))
18cb7a01acSMauro Carvalho Chehab
19cb7a01acSMauro Carvalho Chehab #define MSP_MODE_AM_DETECT 0
20cb7a01acSMauro Carvalho Chehab #define MSP_MODE_FM_RADIO 2
21cb7a01acSMauro Carvalho Chehab #define MSP_MODE_FM_TERRA 3
22cb7a01acSMauro Carvalho Chehab #define MSP_MODE_FM_SAT 4
23cb7a01acSMauro Carvalho Chehab #define MSP_MODE_FM_NICAM1 5
24cb7a01acSMauro Carvalho Chehab #define MSP_MODE_FM_NICAM2 6
25cb7a01acSMauro Carvalho Chehab #define MSP_MODE_AM_NICAM 7
26cb7a01acSMauro Carvalho Chehab #define MSP_MODE_BTSC 8
27cb7a01acSMauro Carvalho Chehab #define MSP_MODE_EXTERN 9
28cb7a01acSMauro Carvalho Chehab
29cb7a01acSMauro Carvalho Chehab #define SCART_IN1 0
30cb7a01acSMauro Carvalho Chehab #define SCART_IN2 1
31cb7a01acSMauro Carvalho Chehab #define SCART_IN3 2
32cb7a01acSMauro Carvalho Chehab #define SCART_IN4 3
33cb7a01acSMauro Carvalho Chehab #define SCART_IN1_DA 4
34cb7a01acSMauro Carvalho Chehab #define SCART_IN2_DA 5
35cb7a01acSMauro Carvalho Chehab #define SCART_MONO 6
36cb7a01acSMauro Carvalho Chehab #define SCART_MUTE 7
37cb7a01acSMauro Carvalho Chehab
38cb7a01acSMauro Carvalho Chehab #define SCART_DSP_IN 0
39cb7a01acSMauro Carvalho Chehab #define SCART1_OUT 1
40cb7a01acSMauro Carvalho Chehab #define SCART2_OUT 2
41cb7a01acSMauro Carvalho Chehab
42cb7a01acSMauro Carvalho Chehab #define OPMODE_AUTO -1
43cb7a01acSMauro Carvalho Chehab #define OPMODE_MANUAL 0
44cb7a01acSMauro Carvalho Chehab #define OPMODE_AUTODETECT 1 /* use autodetect (>= msp3410 only) */
45cb7a01acSMauro Carvalho Chehab #define OPMODE_AUTOSELECT 2 /* use autodetect & autoselect (>= msp34xxG) */
46cb7a01acSMauro Carvalho Chehab
47cb7a01acSMauro Carvalho Chehab /* module parameters */
48cb7a01acSMauro Carvalho Chehab extern int msp_debug;
49cb7a01acSMauro Carvalho Chehab extern bool msp_once;
50cb7a01acSMauro Carvalho Chehab extern bool msp_amsound;
51cb7a01acSMauro Carvalho Chehab extern int msp_standard;
52cb7a01acSMauro Carvalho Chehab extern bool msp_dolby;
53cb7a01acSMauro Carvalho Chehab extern int msp_stereo_thresh;
54cb7a01acSMauro Carvalho Chehab
55fc9bd1ceSMauro Carvalho Chehab enum msp3400_pads {
56fc9bd1ceSMauro Carvalho Chehab MSP3400_PAD_IF_INPUT,
57fc9bd1ceSMauro Carvalho Chehab MSP3400_PAD_OUT,
58fc9bd1ceSMauro Carvalho Chehab MSP3400_NUM_PADS
59fc9bd1ceSMauro Carvalho Chehab };
60fc9bd1ceSMauro Carvalho Chehab
61cb7a01acSMauro Carvalho Chehab struct msp_state {
62cb7a01acSMauro Carvalho Chehab struct v4l2_subdev sd;
63cb7a01acSMauro Carvalho Chehab struct v4l2_ctrl_handler hdl;
64cb7a01acSMauro Carvalho Chehab int rev1, rev2;
65cb7a01acSMauro Carvalho Chehab int ident;
66cb7a01acSMauro Carvalho Chehab u8 has_nicam;
67cb7a01acSMauro Carvalho Chehab u8 has_radio;
68cb7a01acSMauro Carvalho Chehab u8 has_headphones;
69cb7a01acSMauro Carvalho Chehab u8 has_ntsc_jp_d_k3;
70cb7a01acSMauro Carvalho Chehab u8 has_scart2;
71cb7a01acSMauro Carvalho Chehab u8 has_scart3;
72cb7a01acSMauro Carvalho Chehab u8 has_scart4;
73cb7a01acSMauro Carvalho Chehab u8 has_scart2_out;
74cb7a01acSMauro Carvalho Chehab u8 has_scart2_out_volume;
75cb7a01acSMauro Carvalho Chehab u8 has_i2s_conf;
76cb7a01acSMauro Carvalho Chehab u8 has_subwoofer;
77cb7a01acSMauro Carvalho Chehab u8 has_sound_processing;
78cb7a01acSMauro Carvalho Chehab u8 has_virtual_dolby_surround;
79cb7a01acSMauro Carvalho Chehab u8 has_dolby_pro_logic;
80cb7a01acSMauro Carvalho Chehab u8 force_btsc;
81cb7a01acSMauro Carvalho Chehab
82cb7a01acSMauro Carvalho Chehab int radio;
83cb7a01acSMauro Carvalho Chehab int opmode;
84cb7a01acSMauro Carvalho Chehab int std;
85cb7a01acSMauro Carvalho Chehab int mode;
86cb7a01acSMauro Carvalho Chehab v4l2_std_id v4l2_std, detected_std;
87cb7a01acSMauro Carvalho Chehab int nicam_on;
88cb7a01acSMauro Carvalho Chehab int acb;
89cb7a01acSMauro Carvalho Chehab int in_scart;
90cb7a01acSMauro Carvalho Chehab int i2s_mode;
91cb7a01acSMauro Carvalho Chehab int main, second; /* sound carrier */
92cb7a01acSMauro Carvalho Chehab int input;
93cb7a01acSMauro Carvalho Chehab u32 route_in;
94cb7a01acSMauro Carvalho Chehab u32 route_out;
95cb7a01acSMauro Carvalho Chehab
96cb7a01acSMauro Carvalho Chehab /* v4l2 */
97cb7a01acSMauro Carvalho Chehab int audmode;
98cb7a01acSMauro Carvalho Chehab int rxsubchans;
99cb7a01acSMauro Carvalho Chehab
100cb7a01acSMauro Carvalho Chehab struct {
101cb7a01acSMauro Carvalho Chehab /* volume cluster */
102cb7a01acSMauro Carvalho Chehab struct v4l2_ctrl *volume;
103cb7a01acSMauro Carvalho Chehab struct v4l2_ctrl *muted;
104cb7a01acSMauro Carvalho Chehab };
105cb7a01acSMauro Carvalho Chehab
106cb7a01acSMauro Carvalho Chehab int scan_in_progress;
107cb7a01acSMauro Carvalho Chehab
108cb7a01acSMauro Carvalho Chehab /* thread */
109cb7a01acSMauro Carvalho Chehab struct task_struct *kthread;
110cb7a01acSMauro Carvalho Chehab wait_queue_head_t wq;
111cb7a01acSMauro Carvalho Chehab unsigned int restart:1;
112cb7a01acSMauro Carvalho Chehab unsigned int watch_stereo:1;
113fb493282SMauro Carvalho Chehab
11424095e76SArnd Bergmann #if IS_ENABLED(CONFIG_MEDIA_CONTROLLER)
115fc9bd1ceSMauro Carvalho Chehab struct media_pad pads[MSP3400_NUM_PADS];
116fb493282SMauro Carvalho Chehab #endif
117cb7a01acSMauro Carvalho Chehab };
118cb7a01acSMauro Carvalho Chehab
to_state(struct v4l2_subdev * sd)119cb7a01acSMauro Carvalho Chehab static inline struct msp_state *to_state(struct v4l2_subdev *sd)
120cb7a01acSMauro Carvalho Chehab {
121cb7a01acSMauro Carvalho Chehab return container_of(sd, struct msp_state, sd);
122cb7a01acSMauro Carvalho Chehab }
123cb7a01acSMauro Carvalho Chehab
ctrl_to_state(struct v4l2_ctrl * ctrl)124cb7a01acSMauro Carvalho Chehab static inline struct msp_state *ctrl_to_state(struct v4l2_ctrl *ctrl)
125cb7a01acSMauro Carvalho Chehab {
126cb7a01acSMauro Carvalho Chehab return container_of(ctrl->handler, struct msp_state, hdl);
127cb7a01acSMauro Carvalho Chehab }
128cb7a01acSMauro Carvalho Chehab
129cb7a01acSMauro Carvalho Chehab /* msp3400-driver.c */
130cb7a01acSMauro Carvalho Chehab int msp_write_dem(struct i2c_client *client, int addr, int val);
131cb7a01acSMauro Carvalho Chehab int msp_write_dsp(struct i2c_client *client, int addr, int val);
132cb7a01acSMauro Carvalho Chehab int msp_read_dem(struct i2c_client *client, int addr);
133cb7a01acSMauro Carvalho Chehab int msp_read_dsp(struct i2c_client *client, int addr);
134cb7a01acSMauro Carvalho Chehab int msp_reset(struct i2c_client *client);
135cb7a01acSMauro Carvalho Chehab void msp_set_scart(struct i2c_client *client, int in, int out);
136cb7a01acSMauro Carvalho Chehab void msp_update_volume(struct msp_state *state);
137*7c17c552SKevin Hao int msp_sleep(struct msp_state *state, int msec);
138cb7a01acSMauro Carvalho Chehab
139cb7a01acSMauro Carvalho Chehab /* msp3400-kthreads.c */
140cb7a01acSMauro Carvalho Chehab const char *msp_standard_std_name(int std);
141cb7a01acSMauro Carvalho Chehab void msp_set_audmode(struct i2c_client *client);
142cb7a01acSMauro Carvalho Chehab int msp_detect_stereo(struct i2c_client *client);
143cb7a01acSMauro Carvalho Chehab int msp3400c_thread(void *data);
144cb7a01acSMauro Carvalho Chehab int msp3410d_thread(void *data);
145cb7a01acSMauro Carvalho Chehab int msp34xxg_thread(void *data);
146cb7a01acSMauro Carvalho Chehab void msp3400c_set_mode(struct i2c_client *client, int mode);
147cb7a01acSMauro Carvalho Chehab void msp3400c_set_carrier(struct i2c_client *client, int cdo1, int cdo2);
148cb7a01acSMauro Carvalho Chehab
149cb7a01acSMauro Carvalho Chehab #endif /* MSP3400_DRIVER_H */
150