1 /* cx25840 internal API header 2 * 3 * Copyright (C) 2003-2004 Chris Kennedy 4 * 5 * This program is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU General Public License 7 * as published by the Free Software Foundation; either version 2 8 * of the License, or (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 */ 15 16 #ifndef _CX25840_CORE_H_ 17 #define _CX25840_CORE_H_ 18 19 20 #include <linux/videodev2.h> 21 #include <media/v4l2-device.h> 22 #include <media/v4l2-ctrls.h> 23 #include <linux/i2c.h> 24 25 struct cx25840_ir_state; 26 27 enum cx25840_model { 28 CX23885_AV, 29 CX23887_AV, 30 CX23888_AV, 31 CX2310X_AV, 32 CX25840, 33 CX25841, 34 CX25842, 35 CX25843, 36 CX25836, 37 CX25837, 38 }; 39 40 enum cx25840_media_pads { 41 CX25840_PAD_INPUT, 42 CX25840_PAD_VID_OUT, 43 44 CX25840_NUM_PADS 45 }; 46 47 /** 48 * struct cx25840_state - a device instance private data 49 * @c: i2c_client struct representing this device 50 * @sd: our V4L2 sub-device 51 * @hdl: our V4L2 control handler 52 * @volume: audio volume V4L2 control (non-cx2583x devices only) 53 * @mute: audio mute V4L2 control (non-cx2583x devices only) 54 * @pvr150_workaround: whether we enable workaround for Hauppauge PVR150 55 * hardware bug (audio dropping out) 56 * @radio: set if we are currently in the radio mode, otherwise 57 * the current mode is non-radio (that is, video) 58 * @std: currently set video standard 59 * @vid_input: currently set video input 60 * @aud_input: currently set audio input 61 * @audclk_freq: currently set audio sample rate 62 * @audmode: currently set audio mode (when in non-radio mode) 63 * @vbi_line_offset: vbi line number offset 64 * @id: exact device model 65 * @rev: raw device id read from the chip 66 * @is_initialized: whether we have already loaded firmware into the chip 67 * and initialized it 68 * @vbi_regs_offset: offset of vbi regs 69 * @fw_wait: wait queue to wake an initialization function up when 70 * firmware loading (on a separate workqueue) finishes 71 * @fw_work: a work that actually loads the firmware on a separate 72 * workqueue 73 * @ir_state: a pointer to chip IR controller private data 74 * @pads: array of supported chip pads (currently only a stub) 75 */ 76 struct cx25840_state { 77 struct i2c_client *c; 78 struct v4l2_subdev sd; 79 struct v4l2_ctrl_handler hdl; 80 struct { 81 /* volume cluster */ 82 struct v4l2_ctrl *volume; 83 struct v4l2_ctrl *mute; 84 }; 85 int pvr150_workaround; 86 int radio; 87 v4l2_std_id std; 88 enum cx25840_video_input vid_input; 89 enum cx25840_audio_input aud_input; 90 u32 audclk_freq; 91 int audmode; 92 int vbi_line_offset; 93 enum cx25840_model id; 94 u32 rev; 95 int is_initialized; 96 unsigned vbi_regs_offset; 97 wait_queue_head_t fw_wait; 98 struct work_struct fw_work; 99 struct cx25840_ir_state *ir_state; 100 #if defined(CONFIG_MEDIA_CONTROLLER) 101 struct media_pad pads[CX25840_NUM_PADS]; 102 #endif 103 }; 104 105 static inline struct cx25840_state *to_state(struct v4l2_subdev *sd) 106 { 107 return container_of(sd, struct cx25840_state, sd); 108 } 109 110 static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl) 111 { 112 return &container_of(ctrl->handler, struct cx25840_state, hdl)->sd; 113 } 114 115 static inline bool is_cx2583x(struct cx25840_state *state) 116 { 117 return state->id == CX25836 || 118 state->id == CX25837; 119 } 120 121 static inline bool is_cx231xx(struct cx25840_state *state) 122 { 123 return state->id == CX2310X_AV; 124 } 125 126 static inline bool is_cx2388x(struct cx25840_state *state) 127 { 128 return state->id == CX23885_AV || 129 state->id == CX23887_AV || 130 state->id == CX23888_AV; 131 } 132 133 static inline bool is_cx23885(struct cx25840_state *state) 134 { 135 return state->id == CX23885_AV; 136 } 137 138 static inline bool is_cx23887(struct cx25840_state *state) 139 { 140 return state->id == CX23887_AV; 141 } 142 143 static inline bool is_cx23888(struct cx25840_state *state) 144 { 145 return state->id == CX23888_AV; 146 } 147 148 /* ----------------------------------------------------------------------- */ 149 /* cx25850-core.c */ 150 int cx25840_write(struct i2c_client *client, u16 addr, u8 value); 151 int cx25840_write4(struct i2c_client *client, u16 addr, u32 value); 152 u8 cx25840_read(struct i2c_client *client, u16 addr); 153 u32 cx25840_read4(struct i2c_client *client, u16 addr); 154 int cx25840_and_or(struct i2c_client *client, u16 addr, unsigned mask, u8 value); 155 int cx25840_and_or4(struct i2c_client *client, u16 addr, u32 and_mask, 156 u32 or_value); 157 void cx25840_std_setup(struct i2c_client *client); 158 159 /* ----------------------------------------------------------------------- */ 160 /* cx25850-firmware.c */ 161 int cx25840_loadfw(struct i2c_client *client); 162 163 /* ----------------------------------------------------------------------- */ 164 /* cx25850-audio.c */ 165 void cx25840_audio_set_path(struct i2c_client *client); 166 int cx25840_s_clock_freq(struct v4l2_subdev *sd, u32 freq); 167 168 extern const struct v4l2_ctrl_ops cx25840_audio_ctrl_ops; 169 170 /* ----------------------------------------------------------------------- */ 171 /* cx25850-vbi.c */ 172 int cx25840_s_raw_fmt(struct v4l2_subdev *sd, struct v4l2_vbi_format *fmt); 173 int cx25840_s_sliced_fmt(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *fmt); 174 int cx25840_g_sliced_fmt(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *fmt); 175 int cx25840_decode_vbi_line(struct v4l2_subdev *sd, struct v4l2_decode_vbi_line *vbi); 176 177 /* ----------------------------------------------------------------------- */ 178 /* cx25850-ir.c */ 179 extern const struct v4l2_subdev_ir_ops cx25840_ir_ops; 180 int cx25840_ir_log_status(struct v4l2_subdev *sd); 181 int cx25840_ir_irq_handler(struct v4l2_subdev *sd, u32 status, bool *handled); 182 int cx25840_ir_probe(struct v4l2_subdev *sd); 183 int cx25840_ir_remove(struct v4l2_subdev *sd); 184 185 #endif 186