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