Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 1 | /* |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 2 | */ |
| 3 | |
Hans Verkuil | 49965a8 | 2006-03-19 08:45:38 -0300 | [diff] [blame] | 4 | #ifndef MSP3400_DRIVER_H |
| 5 | #define MSP3400_DRIVER_H |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | |
Mauro Carvalho Chehab | d647f0b | 2015-11-13 19:40:07 -0200 | [diff] [blame] | 7 | #include <media/drv-intf/msp3400.h> |
Hans Verkuil | 76efd62 | 2008-11-24 18:16:46 -0300 | [diff] [blame] | 8 | #include <media/v4l2-device.h> |
Hans Verkuil | ebc3bba | 2010-05-24 10:01:58 -0300 | [diff] [blame] | 9 | #include <media/v4l2-ctrls.h> |
Mauro Carvalho Chehab | fb49328 | 2016-01-28 08:51:01 -0200 | [diff] [blame] | 10 | #include <media/v4l2-mc.h> |
Hans Verkuil | 2474ed4 | 2006-03-19 12:35:57 -0300 | [diff] [blame] | 11 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | /* ---------------------------------------------------------------------- */ |
| 13 | |
Hans Verkuil | 53b0a1c | 2006-01-09 15:32:39 -0200 | [diff] [blame] | 14 | /* This macro is allowed for *constants* only, gcc must calculate it |
| 15 | at compile time. Remember -- no floats in kernel mode */ |
| 16 | #define MSP_CARRIER(freq) ((int)((float)(freq / 18.432) * (1 << 24))) |
| 17 | |
| 18 | #define MSP_MODE_AM_DETECT 0 |
| 19 | #define MSP_MODE_FM_RADIO 2 |
| 20 | #define MSP_MODE_FM_TERRA 3 |
| 21 | #define MSP_MODE_FM_SAT 4 |
| 22 | #define MSP_MODE_FM_NICAM1 5 |
| 23 | #define MSP_MODE_FM_NICAM2 6 |
| 24 | #define MSP_MODE_AM_NICAM 7 |
| 25 | #define MSP_MODE_BTSC 8 |
| 26 | #define MSP_MODE_EXTERN 9 |
| 27 | |
Hans Verkuil | 4277257 | 2006-03-19 06:48:51 -0300 | [diff] [blame] | 28 | #define SCART_IN1 0 |
| 29 | #define SCART_IN2 1 |
| 30 | #define SCART_IN3 2 |
| 31 | #define SCART_IN4 3 |
| 32 | #define SCART_IN1_DA 4 |
| 33 | #define SCART_IN2_DA 5 |
| 34 | #define SCART_MONO 6 |
| 35 | #define SCART_MUTE 7 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
| 37 | #define SCART_DSP_IN 0 |
| 38 | #define SCART1_OUT 1 |
| 39 | #define SCART2_OUT 2 |
| 40 | |
Hans Verkuil | 53b0a1c | 2006-01-09 15:32:39 -0200 | [diff] [blame] | 41 | #define OPMODE_AUTO -1 |
| 42 | #define OPMODE_MANUAL 0 |
| 43 | #define OPMODE_AUTODETECT 1 /* use autodetect (>= msp3410 only) */ |
| 44 | #define OPMODE_AUTOSELECT 2 /* use autodetect & autoselect (>= msp34xxG) */ |
| 45 | |
| 46 | /* module parameters */ |
Mauro Carvalho Chehab | f167cb4e | 2006-01-11 19:41:49 -0200 | [diff] [blame] | 47 | extern int msp_debug; |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 48 | extern bool msp_once; |
| 49 | extern bool msp_amsound; |
Mauro Carvalho Chehab | f167cb4e | 2006-01-11 19:41:49 -0200 | [diff] [blame] | 50 | extern int msp_standard; |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 51 | extern bool msp_dolby; |
Mauro Carvalho Chehab | f167cb4e | 2006-01-11 19:41:49 -0200 | [diff] [blame] | 52 | extern int msp_stereo_thresh; |
Hans Verkuil | 53b0a1c | 2006-01-09 15:32:39 -0200 | [diff] [blame] | 53 | |
| 54 | struct msp_state { |
Hans Verkuil | 76efd62 | 2008-11-24 18:16:46 -0300 | [diff] [blame] | 55 | struct v4l2_subdev sd; |
Hans Verkuil | ebc3bba | 2010-05-24 10:01:58 -0300 | [diff] [blame] | 56 | struct v4l2_ctrl_handler hdl; |
Hans Verkuil | 53b0a1c | 2006-01-09 15:32:39 -0200 | [diff] [blame] | 57 | int rev1, rev2; |
Hans Verkuil | 74cab31 | 2007-04-27 12:31:26 -0300 | [diff] [blame] | 58 | int ident; |
Hans Verkuil | 5af0c8f | 2006-01-09 18:21:37 -0200 | [diff] [blame] | 59 | u8 has_nicam; |
| 60 | u8 has_radio; |
| 61 | u8 has_headphones; |
| 62 | u8 has_ntsc_jp_d_k3; |
Hans Verkuil | 0020d3e | 2006-03-30 19:50:34 -0300 | [diff] [blame] | 63 | u8 has_scart2; |
| 64 | u8 has_scart3; |
Hans Verkuil | 5af0c8f | 2006-01-09 18:21:37 -0200 | [diff] [blame] | 65 | u8 has_scart4; |
Hans Verkuil | 0020d3e | 2006-03-30 19:50:34 -0300 | [diff] [blame] | 66 | u8 has_scart2_out; |
Hans Verkuil | 5af0c8f | 2006-01-09 18:21:37 -0200 | [diff] [blame] | 67 | u8 has_scart2_out_volume; |
| 68 | u8 has_i2s_conf; |
| 69 | u8 has_subwoofer; |
| 70 | u8 has_sound_processing; |
| 71 | u8 has_virtual_dolby_surround; |
| 72 | u8 has_dolby_pro_logic; |
Hans Verkuil | de98cda | 2006-10-01 17:56:32 -0300 | [diff] [blame] | 73 | u8 force_btsc; |
Hans Verkuil | 53b0a1c | 2006-01-09 15:32:39 -0200 | [diff] [blame] | 74 | |
Hans Verkuil | 7560d7a | 2006-01-09 18:21:32 -0200 | [diff] [blame] | 75 | int radio; |
Hans Verkuil | 53b0a1c | 2006-01-09 15:32:39 -0200 | [diff] [blame] | 76 | int opmode; |
Hans Verkuil | 5af0c8f | 2006-01-09 18:21:37 -0200 | [diff] [blame] | 77 | int std; |
Hans Verkuil | 53b0a1c | 2006-01-09 15:32:39 -0200 | [diff] [blame] | 78 | int mode; |
Mauro Carvalho Chehab | 5d1ed98 | 2011-10-04 09:44:02 -0300 | [diff] [blame] | 79 | v4l2_std_id v4l2_std, detected_std; |
Hans Verkuil | 53b0a1c | 2006-01-09 15:32:39 -0200 | [diff] [blame] | 80 | int nicam_on; |
| 81 | int acb; |
| 82 | int in_scart; |
| 83 | int i2s_mode; |
| 84 | int main, second; /* sound carrier */ |
| 85 | int input; |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 86 | u32 route_in; |
| 87 | u32 route_out; |
Hans Verkuil | 53b0a1c | 2006-01-09 15:32:39 -0200 | [diff] [blame] | 88 | |
| 89 | /* v4l2 */ |
| 90 | int audmode; |
| 91 | int rxsubchans; |
| 92 | |
Hans Verkuil | ebc3bba | 2010-05-24 10:01:58 -0300 | [diff] [blame] | 93 | struct { |
| 94 | /* volume cluster */ |
| 95 | struct v4l2_ctrl *volume; |
| 96 | struct v4l2_ctrl *muted; |
| 97 | }; |
| 98 | |
Hans Verkuil | 3bbe5a8 | 2006-04-01 15:27:52 -0300 | [diff] [blame] | 99 | int scan_in_progress; |
Hans Verkuil | 53b0a1c | 2006-01-09 15:32:39 -0200 | [diff] [blame] | 100 | |
| 101 | /* thread */ |
| 102 | struct task_struct *kthread; |
| 103 | wait_queue_head_t wq; |
Randy Dunlap | 0a11537 | 2006-06-28 15:05:11 -0300 | [diff] [blame] | 104 | unsigned int restart:1; |
| 105 | unsigned int watch_stereo:1; |
Mauro Carvalho Chehab | fb49328 | 2016-01-28 08:51:01 -0200 | [diff] [blame] | 106 | |
Arnd Bergmann | 24095e7 | 2016-02-02 13:47:58 -0200 | [diff] [blame] | 107 | #if IS_ENABLED(CONFIG_MEDIA_CONTROLLER) |
Mauro Carvalho Chehab | fb49328 | 2016-01-28 08:51:01 -0200 | [diff] [blame] | 108 | struct media_pad pads[IF_AUD_DEC_PAD_NUM_PADS]; |
| 109 | #endif |
Hans Verkuil | 53b0a1c | 2006-01-09 15:32:39 -0200 | [diff] [blame] | 110 | }; |
| 111 | |
Hans Verkuil | 76efd62 | 2008-11-24 18:16:46 -0300 | [diff] [blame] | 112 | static inline struct msp_state *to_state(struct v4l2_subdev *sd) |
| 113 | { |
| 114 | return container_of(sd, struct msp_state, sd); |
| 115 | } |
| 116 | |
Hans Verkuil | ebc3bba | 2010-05-24 10:01:58 -0300 | [diff] [blame] | 117 | static inline struct msp_state *ctrl_to_state(struct v4l2_ctrl *ctrl) |
| 118 | { |
| 119 | return container_of(ctrl->handler, struct msp_state, hdl); |
| 120 | } |
| 121 | |
Hans Verkuil | 53b0a1c | 2006-01-09 15:32:39 -0200 | [diff] [blame] | 122 | /* msp3400-driver.c */ |
| 123 | int msp_write_dem(struct i2c_client *client, int addr, int val); |
| 124 | int msp_write_dsp(struct i2c_client *client, int addr, int val); |
| 125 | int msp_read_dem(struct i2c_client *client, int addr); |
| 126 | int msp_read_dsp(struct i2c_client *client, int addr); |
| 127 | int msp_reset(struct i2c_client *client); |
| 128 | void msp_set_scart(struct i2c_client *client, int in, int out); |
Hans Verkuil | ebc3bba | 2010-05-24 10:01:58 -0300 | [diff] [blame] | 129 | void msp_update_volume(struct msp_state *state); |
Hans Verkuil | 53b0a1c | 2006-01-09 15:32:39 -0200 | [diff] [blame] | 130 | int msp_sleep(struct msp_state *state, int timeout); |
| 131 | |
| 132 | /* msp3400-kthreads.c */ |
Hans Verkuil | 5af0c8f | 2006-01-09 18:21:37 -0200 | [diff] [blame] | 133 | const char *msp_standard_std_name(int std); |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 134 | void msp_set_audmode(struct i2c_client *client); |
Hans Verkuil | de533cc | 2006-03-19 08:21:56 -0300 | [diff] [blame] | 135 | int msp_detect_stereo(struct i2c_client *client); |
Hans Verkuil | 53b0a1c | 2006-01-09 15:32:39 -0200 | [diff] [blame] | 136 | int msp3400c_thread(void *data); |
| 137 | int msp3410d_thread(void *data); |
| 138 | int msp34xxg_thread(void *data); |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 139 | void msp3400c_set_mode(struct i2c_client *client, int mode); |
| 140 | void msp3400c_set_carrier(struct i2c_client *client, int cdo1, int cdo2); |
Hans Verkuil | 53b0a1c | 2006-01-09 15:32:39 -0200 | [diff] [blame] | 141 | |
Hans Verkuil | 49965a8 | 2006-03-19 08:45:38 -0300 | [diff] [blame] | 142 | #endif /* MSP3400_DRIVER_H */ |