Linux Audio

Check our new training course

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