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 	CX25840_PAD_VBI_OUT,
44 
45 	CX25840_NUM_PADS
46 };
47 
48 /**
49  * struct cx25840_state - a device instance private data
50  * @c:			i2c_client struct representing this device
51  * @sd:		our V4L2 sub-device
52  * @hdl:		our V4L2 control handler
53  * @volume:		audio volume V4L2 control (non-cx2583x devices only)
54  * @mute:		audio mute V4L2 control (non-cx2583x devices only)
55  * @pvr150_workaround:	whether we enable workaround for Hauppauge PVR150
56  *			hardware bug (audio dropping out)
57  * @radio:		set if we are currently in the radio mode, otherwise
58  *			the current mode is non-radio (that is, video)
59  * @std:		currently set video standard
60  * @vid_input:		currently set video input
61  * @aud_input:		currently set audio input
62  * @audclk_freq:	currently set audio sample rate
63  * @audmode:		currently set audio mode (when in non-radio mode)
64  * @vbi_line_offset:	vbi line number offset
65  * @id:		exact device model
66  * @rev:		raw device id read from the chip
67  * @is_initialized:	whether we have already loaded firmware into the chip
68  *			and initialized it
69  * @vbi_regs_offset:	offset of vbi regs
70  * @fw_wait:		wait queue to wake an initalization function up when
71  *			firmware loading (on a separate workqueue) finishes
72  * @fw_work:		a work that actually loads the firmware on a separate
73  *			workqueue
74  * @ir_state:		a pointer to chip IR controller private data
75  * @pads:		array of supported chip pads (currently only a stub)
76  */
77 struct cx25840_state {
78 	struct i2c_client *c;
79 	struct v4l2_subdev sd;
80 	struct v4l2_ctrl_handler hdl;
81 	struct {
82 		/* volume cluster */
83 		struct v4l2_ctrl *volume;
84 		struct v4l2_ctrl *mute;
85 	};
86 	int pvr150_workaround;
87 	int radio;
88 	v4l2_std_id std;
89 	enum cx25840_video_input vid_input;
90 	enum cx25840_audio_input aud_input;
91 	u32 audclk_freq;
92 	int audmode;
93 	int vbi_line_offset;
94 	enum cx25840_model id;
95 	u32 rev;
96 	int is_initialized;
97 	unsigned vbi_regs_offset;
98 	wait_queue_head_t fw_wait;
99 	struct work_struct fw_work;
100 	struct cx25840_ir_state *ir_state;
101 #if defined(CONFIG_MEDIA_CONTROLLER)
102 	struct media_pad	pads[CX25840_NUM_PADS];
103 #endif
104 };
105 
106 static inline struct cx25840_state *to_state(struct v4l2_subdev *sd)
107 {
108 	return container_of(sd, struct cx25840_state, sd);
109 }
110 
111 static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl)
112 {
113 	return &container_of(ctrl->handler, struct cx25840_state, hdl)->sd;
114 }
115 
116 static inline bool is_cx2583x(struct cx25840_state *state)
117 {
118 	return state->id == CX25836 ||
119 	       state->id == CX25837;
120 }
121 
122 static inline bool is_cx231xx(struct cx25840_state *state)
123 {
124 	return state->id == CX2310X_AV;
125 }
126 
127 static inline bool is_cx2388x(struct cx25840_state *state)
128 {
129 	return state->id == CX23885_AV ||
130 	       state->id == CX23887_AV ||
131 	       state->id == CX23888_AV;
132 }
133 
134 static inline bool is_cx23885(struct cx25840_state *state)
135 {
136 	return state->id == CX23885_AV;
137 }
138 
139 static inline bool is_cx23887(struct cx25840_state *state)
140 {
141 	return state->id == CX23887_AV;
142 }
143 
144 static inline bool is_cx23888(struct cx25840_state *state)
145 {
146 	return state->id == CX23888_AV;
147 }
148 
149 /* ----------------------------------------------------------------------- */
150 /* cx25850-core.c							   */
151 int cx25840_write(struct i2c_client *client, u16 addr, u8 value);
152 int cx25840_write4(struct i2c_client *client, u16 addr, u32 value);
153 u8 cx25840_read(struct i2c_client *client, u16 addr);
154 u32 cx25840_read4(struct i2c_client *client, u16 addr);
155 int cx25840_and_or(struct i2c_client *client, u16 addr, unsigned mask, u8 value);
156 int cx25840_and_or4(struct i2c_client *client, u16 addr, u32 and_mask,
157 		    u32 or_value);
158 void cx25840_std_setup(struct i2c_client *client);
159 
160 /* ----------------------------------------------------------------------- */
161 /* cx25850-firmware.c                                                      */
162 int cx25840_loadfw(struct i2c_client *client);
163 
164 /* ----------------------------------------------------------------------- */
165 /* cx25850-audio.c                                                         */
166 void cx25840_audio_set_path(struct i2c_client *client);
167 int cx25840_s_clock_freq(struct v4l2_subdev *sd, u32 freq);
168 
169 extern const struct v4l2_ctrl_ops cx25840_audio_ctrl_ops;
170 
171 /* ----------------------------------------------------------------------- */
172 /* cx25850-vbi.c                                                           */
173 int cx25840_s_raw_fmt(struct v4l2_subdev *sd, struct v4l2_vbi_format *fmt);
174 int cx25840_s_sliced_fmt(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *fmt);
175 int cx25840_g_sliced_fmt(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *fmt);
176 int cx25840_decode_vbi_line(struct v4l2_subdev *sd, struct v4l2_decode_vbi_line *vbi);
177 
178 /* ----------------------------------------------------------------------- */
179 /* cx25850-ir.c                                                            */
180 extern const struct v4l2_subdev_ir_ops cx25840_ir_ops;
181 int cx25840_ir_log_status(struct v4l2_subdev *sd);
182 int cx25840_ir_irq_handler(struct v4l2_subdev *sd, u32 status, bool *handled);
183 int cx25840_ir_probe(struct v4l2_subdev *sd);
184 int cx25840_ir_remove(struct v4l2_subdev *sd);
185 
186 #endif
187