18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci    mxb - v4l2 driver for the Multimedia eXtension Board
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci    Copyright (C) 1998-2006 Michael Hunold <michael@mihu.de>
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci    Visit http://www.themm.net/~mihu/linux/saa7146/mxb.html
88c2ecf20Sopenharmony_ci    for further details about this card.
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci*/
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#define DEBUG_VARIABLE debug
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#include <media/drv-intf/saa7146_vv.h>
178c2ecf20Sopenharmony_ci#include <media/tuner.h>
188c2ecf20Sopenharmony_ci#include <media/v4l2-common.h>
198c2ecf20Sopenharmony_ci#include <media/i2c/saa7115.h>
208c2ecf20Sopenharmony_ci#include <linux/module.h>
218c2ecf20Sopenharmony_ci#include <linux/kernel.h>
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci#include "tea6415c.h"
248c2ecf20Sopenharmony_ci#include "tea6420.h"
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#define MXB_AUDIOS	6
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci#define I2C_SAA7111A  0x24
298c2ecf20Sopenharmony_ci#define	I2C_TDA9840   0x42
308c2ecf20Sopenharmony_ci#define	I2C_TEA6415C  0x43
318c2ecf20Sopenharmony_ci#define	I2C_TEA6420_1 0x4c
328c2ecf20Sopenharmony_ci#define	I2C_TEA6420_2 0x4d
338c2ecf20Sopenharmony_ci#define	I2C_TUNER     0x60
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci#define MXB_BOARD_CAN_DO_VBI(dev)   (dev->revision != 0)
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci/* global variable */
388c2ecf20Sopenharmony_cistatic int mxb_num;
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci/* initial frequence the tuner will be tuned to.
418c2ecf20Sopenharmony_ci   in verden (lower saxony, germany) 4148 is a
428c2ecf20Sopenharmony_ci   channel called "phoenix" */
438c2ecf20Sopenharmony_cistatic int freq = 4148;
448c2ecf20Sopenharmony_cimodule_param(freq, int, 0644);
458c2ecf20Sopenharmony_ciMODULE_PARM_DESC(freq, "initial frequency the tuner will be tuned to while setup");
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_cistatic int debug;
488c2ecf20Sopenharmony_cimodule_param(debug, int, 0644);
498c2ecf20Sopenharmony_ciMODULE_PARM_DESC(debug, "Turn on/off device debugging (default:off).");
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci#define MXB_INPUTS 4
528c2ecf20Sopenharmony_cienum { TUNER, AUX1, AUX3, AUX3_YC };
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_cistatic struct v4l2_input mxb_inputs[MXB_INPUTS] = {
558c2ecf20Sopenharmony_ci	{ TUNER,   "Tuner",          V4L2_INPUT_TYPE_TUNER,  0x3f, 0,
568c2ecf20Sopenharmony_ci		V4L2_STD_PAL_BG | V4L2_STD_PAL_I, 0, V4L2_IN_CAP_STD },
578c2ecf20Sopenharmony_ci	{ AUX1,	   "AUX1",           V4L2_INPUT_TYPE_CAMERA, 0x3f, 0,
588c2ecf20Sopenharmony_ci		V4L2_STD_ALL, 0, V4L2_IN_CAP_STD },
598c2ecf20Sopenharmony_ci	{ AUX3,	   "AUX3 Composite", V4L2_INPUT_TYPE_CAMERA, 0x3f, 0,
608c2ecf20Sopenharmony_ci		V4L2_STD_ALL, 0, V4L2_IN_CAP_STD },
618c2ecf20Sopenharmony_ci	{ AUX3_YC, "AUX3 S-Video",   V4L2_INPUT_TYPE_CAMERA, 0x3f, 0,
628c2ecf20Sopenharmony_ci		V4L2_STD_ALL, 0, V4L2_IN_CAP_STD },
638c2ecf20Sopenharmony_ci};
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci/* this array holds the information, which port of the saa7146 each
668c2ecf20Sopenharmony_ci   input actually uses. the mxb uses port 0 for every input */
678c2ecf20Sopenharmony_cistatic struct {
688c2ecf20Sopenharmony_ci	int hps_source;
698c2ecf20Sopenharmony_ci	int hps_sync;
708c2ecf20Sopenharmony_ci} input_port_selection[MXB_INPUTS] = {
718c2ecf20Sopenharmony_ci	{ SAA7146_HPS_SOURCE_PORT_A, SAA7146_HPS_SYNC_PORT_A },
728c2ecf20Sopenharmony_ci	{ SAA7146_HPS_SOURCE_PORT_A, SAA7146_HPS_SYNC_PORT_A },
738c2ecf20Sopenharmony_ci	{ SAA7146_HPS_SOURCE_PORT_A, SAA7146_HPS_SYNC_PORT_A },
748c2ecf20Sopenharmony_ci	{ SAA7146_HPS_SOURCE_PORT_A, SAA7146_HPS_SYNC_PORT_A },
758c2ecf20Sopenharmony_ci};
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci/* this array holds the information of the audio source (mxb_audios),
788c2ecf20Sopenharmony_ci   which has to be switched corresponding to the video source (mxb_channels) */
798c2ecf20Sopenharmony_cistatic int video_audio_connect[MXB_INPUTS] =
808c2ecf20Sopenharmony_ci	{ 0, 1, 3, 3 };
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_cistruct mxb_routing {
838c2ecf20Sopenharmony_ci	u32 input;
848c2ecf20Sopenharmony_ci	u32 output;
858c2ecf20Sopenharmony_ci};
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci/* these are the available audio sources, which can switched
888c2ecf20Sopenharmony_ci   to the line- and cd-output individually */
898c2ecf20Sopenharmony_cistatic struct v4l2_audio mxb_audios[MXB_AUDIOS] = {
908c2ecf20Sopenharmony_ci	    {
918c2ecf20Sopenharmony_ci		.index	= 0,
928c2ecf20Sopenharmony_ci		.name	= "Tuner",
938c2ecf20Sopenharmony_ci		.capability = V4L2_AUDCAP_STEREO,
948c2ecf20Sopenharmony_ci	} , {
958c2ecf20Sopenharmony_ci		.index	= 1,
968c2ecf20Sopenharmony_ci		.name	= "AUX1",
978c2ecf20Sopenharmony_ci		.capability = V4L2_AUDCAP_STEREO,
988c2ecf20Sopenharmony_ci	} , {
998c2ecf20Sopenharmony_ci		.index	= 2,
1008c2ecf20Sopenharmony_ci		.name	= "AUX2",
1018c2ecf20Sopenharmony_ci		.capability = V4L2_AUDCAP_STEREO,
1028c2ecf20Sopenharmony_ci	} , {
1038c2ecf20Sopenharmony_ci		.index	= 3,
1048c2ecf20Sopenharmony_ci		.name	= "AUX3",
1058c2ecf20Sopenharmony_ci		.capability = V4L2_AUDCAP_STEREO,
1068c2ecf20Sopenharmony_ci	} , {
1078c2ecf20Sopenharmony_ci		.index	= 4,
1088c2ecf20Sopenharmony_ci		.name	= "Radio (X9)",
1098c2ecf20Sopenharmony_ci		.capability = V4L2_AUDCAP_STEREO,
1108c2ecf20Sopenharmony_ci	} , {
1118c2ecf20Sopenharmony_ci		.index	= 5,
1128c2ecf20Sopenharmony_ci		.name	= "CD-ROM (X10)",
1138c2ecf20Sopenharmony_ci		.capability = V4L2_AUDCAP_STEREO,
1148c2ecf20Sopenharmony_ci	}
1158c2ecf20Sopenharmony_ci};
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci/* These are the necessary input-output-pins for bringing one audio source
1188c2ecf20Sopenharmony_ci   (see above) to the CD-output. Note that gain is set to 0 in this table. */
1198c2ecf20Sopenharmony_cistatic struct mxb_routing TEA6420_cd[MXB_AUDIOS + 1][2] = {
1208c2ecf20Sopenharmony_ci	{ { 1, 1 }, { 1, 1 } },	/* Tuner */
1218c2ecf20Sopenharmony_ci	{ { 5, 1 }, { 6, 1 } },	/* AUX 1 */
1228c2ecf20Sopenharmony_ci	{ { 4, 1 }, { 6, 1 } },	/* AUX 2 */
1238c2ecf20Sopenharmony_ci	{ { 3, 1 }, { 6, 1 } },	/* AUX 3 */
1248c2ecf20Sopenharmony_ci	{ { 1, 1 }, { 3, 1 } },	/* Radio */
1258c2ecf20Sopenharmony_ci	{ { 1, 1 }, { 2, 1 } },	/* CD-Rom */
1268c2ecf20Sopenharmony_ci	{ { 6, 1 }, { 6, 1 } }	/* Mute */
1278c2ecf20Sopenharmony_ci};
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ci/* These are the necessary input-output-pins for bringing one audio source
1308c2ecf20Sopenharmony_ci   (see above) to the line-output. Note that gain is set to 0 in this table. */
1318c2ecf20Sopenharmony_cistatic struct mxb_routing TEA6420_line[MXB_AUDIOS + 1][2] = {
1328c2ecf20Sopenharmony_ci	{ { 2, 3 }, { 1, 2 } },
1338c2ecf20Sopenharmony_ci	{ { 5, 3 }, { 6, 2 } },
1348c2ecf20Sopenharmony_ci	{ { 4, 3 }, { 6, 2 } },
1358c2ecf20Sopenharmony_ci	{ { 3, 3 }, { 6, 2 } },
1368c2ecf20Sopenharmony_ci	{ { 2, 3 }, { 3, 2 } },
1378c2ecf20Sopenharmony_ci	{ { 2, 3 }, { 2, 2 } },
1388c2ecf20Sopenharmony_ci	{ { 6, 3 }, { 6, 2 } }	/* Mute */
1398c2ecf20Sopenharmony_ci};
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_cistruct mxb
1428c2ecf20Sopenharmony_ci{
1438c2ecf20Sopenharmony_ci	struct video_device	video_dev;
1448c2ecf20Sopenharmony_ci	struct video_device	vbi_dev;
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ci	struct i2c_adapter	i2c_adapter;
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ci	struct v4l2_subdev	*saa7111a;
1498c2ecf20Sopenharmony_ci	struct v4l2_subdev	*tda9840;
1508c2ecf20Sopenharmony_ci	struct v4l2_subdev	*tea6415c;
1518c2ecf20Sopenharmony_ci	struct v4l2_subdev	*tuner;
1528c2ecf20Sopenharmony_ci	struct v4l2_subdev	*tea6420_1;
1538c2ecf20Sopenharmony_ci	struct v4l2_subdev	*tea6420_2;
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_ci	int	cur_mode;	/* current audio mode (mono, stereo, ...) */
1568c2ecf20Sopenharmony_ci	int	cur_input;	/* current input */
1578c2ecf20Sopenharmony_ci	int	cur_audinput;	/* current audio input */
1588c2ecf20Sopenharmony_ci	int	cur_mute;	/* current mute status */
1598c2ecf20Sopenharmony_ci	struct v4l2_frequency	cur_freq;	/* current frequency the tuner is tuned to */
1608c2ecf20Sopenharmony_ci};
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_ci#define saa7111a_call(mxb, o, f, args...) \
1638c2ecf20Sopenharmony_ci	v4l2_subdev_call(mxb->saa7111a, o, f, ##args)
1648c2ecf20Sopenharmony_ci#define tda9840_call(mxb, o, f, args...) \
1658c2ecf20Sopenharmony_ci	v4l2_subdev_call(mxb->tda9840, o, f, ##args)
1668c2ecf20Sopenharmony_ci#define tea6415c_call(mxb, o, f, args...) \
1678c2ecf20Sopenharmony_ci	v4l2_subdev_call(mxb->tea6415c, o, f, ##args)
1688c2ecf20Sopenharmony_ci#define tuner_call(mxb, o, f, args...) \
1698c2ecf20Sopenharmony_ci	v4l2_subdev_call(mxb->tuner, o, f, ##args)
1708c2ecf20Sopenharmony_ci#define call_all(dev, o, f, args...) \
1718c2ecf20Sopenharmony_ci	v4l2_device_call_until_err(&dev->v4l2_dev, 0, o, f, ##args)
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_cistatic void mxb_update_audmode(struct mxb *mxb)
1748c2ecf20Sopenharmony_ci{
1758c2ecf20Sopenharmony_ci	struct v4l2_tuner t = {
1768c2ecf20Sopenharmony_ci		.audmode = mxb->cur_mode,
1778c2ecf20Sopenharmony_ci	};
1788c2ecf20Sopenharmony_ci
1798c2ecf20Sopenharmony_ci	tda9840_call(mxb, tuner, s_tuner, &t);
1808c2ecf20Sopenharmony_ci}
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_cistatic inline void tea6420_route(struct mxb *mxb, int idx)
1838c2ecf20Sopenharmony_ci{
1848c2ecf20Sopenharmony_ci	v4l2_subdev_call(mxb->tea6420_1, audio, s_routing,
1858c2ecf20Sopenharmony_ci		TEA6420_cd[idx][0].input, TEA6420_cd[idx][0].output, 0);
1868c2ecf20Sopenharmony_ci	v4l2_subdev_call(mxb->tea6420_2, audio, s_routing,
1878c2ecf20Sopenharmony_ci		TEA6420_cd[idx][1].input, TEA6420_cd[idx][1].output, 0);
1888c2ecf20Sopenharmony_ci	v4l2_subdev_call(mxb->tea6420_1, audio, s_routing,
1898c2ecf20Sopenharmony_ci		TEA6420_line[idx][0].input, TEA6420_line[idx][0].output, 0);
1908c2ecf20Sopenharmony_ci	v4l2_subdev_call(mxb->tea6420_2, audio, s_routing,
1918c2ecf20Sopenharmony_ci		TEA6420_line[idx][1].input, TEA6420_line[idx][1].output, 0);
1928c2ecf20Sopenharmony_ci}
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_cistatic struct saa7146_extension extension;
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_cistatic int mxb_s_ctrl(struct v4l2_ctrl *ctrl)
1978c2ecf20Sopenharmony_ci{
1988c2ecf20Sopenharmony_ci	struct saa7146_dev *dev = container_of(ctrl->handler,
1998c2ecf20Sopenharmony_ci				struct saa7146_dev, ctrl_handler);
2008c2ecf20Sopenharmony_ci	struct mxb *mxb = dev->ext_priv;
2018c2ecf20Sopenharmony_ci
2028c2ecf20Sopenharmony_ci	switch (ctrl->id) {
2038c2ecf20Sopenharmony_ci	case V4L2_CID_AUDIO_MUTE:
2048c2ecf20Sopenharmony_ci		mxb->cur_mute = ctrl->val;
2058c2ecf20Sopenharmony_ci		/* switch the audio-source */
2068c2ecf20Sopenharmony_ci		tea6420_route(mxb, ctrl->val ? 6 :
2078c2ecf20Sopenharmony_ci				video_audio_connect[mxb->cur_input]);
2088c2ecf20Sopenharmony_ci		break;
2098c2ecf20Sopenharmony_ci	default:
2108c2ecf20Sopenharmony_ci		return -EINVAL;
2118c2ecf20Sopenharmony_ci	}
2128c2ecf20Sopenharmony_ci	return 0;
2138c2ecf20Sopenharmony_ci}
2148c2ecf20Sopenharmony_ci
2158c2ecf20Sopenharmony_cistatic const struct v4l2_ctrl_ops mxb_ctrl_ops = {
2168c2ecf20Sopenharmony_ci	.s_ctrl = mxb_s_ctrl,
2178c2ecf20Sopenharmony_ci};
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_cistatic int mxb_probe(struct saa7146_dev *dev)
2208c2ecf20Sopenharmony_ci{
2218c2ecf20Sopenharmony_ci	struct v4l2_ctrl_handler *hdl = &dev->ctrl_handler;
2228c2ecf20Sopenharmony_ci	struct mxb *mxb = NULL;
2238c2ecf20Sopenharmony_ci
2248c2ecf20Sopenharmony_ci	v4l2_ctrl_new_std(hdl, &mxb_ctrl_ops,
2258c2ecf20Sopenharmony_ci			V4L2_CID_AUDIO_MUTE, 0, 1, 1, 1);
2268c2ecf20Sopenharmony_ci	if (hdl->error)
2278c2ecf20Sopenharmony_ci		return hdl->error;
2288c2ecf20Sopenharmony_ci	mxb = kzalloc(sizeof(struct mxb), GFP_KERNEL);
2298c2ecf20Sopenharmony_ci	if (mxb == NULL) {
2308c2ecf20Sopenharmony_ci		DEB_D("not enough kernel memory\n");
2318c2ecf20Sopenharmony_ci		return -ENOMEM;
2328c2ecf20Sopenharmony_ci	}
2338c2ecf20Sopenharmony_ci
2348c2ecf20Sopenharmony_ci
2358c2ecf20Sopenharmony_ci	snprintf(mxb->i2c_adapter.name, sizeof(mxb->i2c_adapter.name), "mxb%d", mxb_num);
2368c2ecf20Sopenharmony_ci
2378c2ecf20Sopenharmony_ci	saa7146_i2c_adapter_prepare(dev, &mxb->i2c_adapter, SAA7146_I2C_BUS_BIT_RATE_480);
2388c2ecf20Sopenharmony_ci	if (i2c_add_adapter(&mxb->i2c_adapter) < 0) {
2398c2ecf20Sopenharmony_ci		DEB_S("cannot register i2c-device. skipping.\n");
2408c2ecf20Sopenharmony_ci		kfree(mxb);
2418c2ecf20Sopenharmony_ci		return -EFAULT;
2428c2ecf20Sopenharmony_ci	}
2438c2ecf20Sopenharmony_ci
2448c2ecf20Sopenharmony_ci	mxb->saa7111a = v4l2_i2c_new_subdev(&dev->v4l2_dev, &mxb->i2c_adapter,
2458c2ecf20Sopenharmony_ci			"saa7111", I2C_SAA7111A, NULL);
2468c2ecf20Sopenharmony_ci	mxb->tea6420_1 = v4l2_i2c_new_subdev(&dev->v4l2_dev, &mxb->i2c_adapter,
2478c2ecf20Sopenharmony_ci			"tea6420", I2C_TEA6420_1, NULL);
2488c2ecf20Sopenharmony_ci	mxb->tea6420_2 = v4l2_i2c_new_subdev(&dev->v4l2_dev, &mxb->i2c_adapter,
2498c2ecf20Sopenharmony_ci			"tea6420", I2C_TEA6420_2, NULL);
2508c2ecf20Sopenharmony_ci	mxb->tea6415c = v4l2_i2c_new_subdev(&dev->v4l2_dev, &mxb->i2c_adapter,
2518c2ecf20Sopenharmony_ci			"tea6415c", I2C_TEA6415C, NULL);
2528c2ecf20Sopenharmony_ci	mxb->tda9840 = v4l2_i2c_new_subdev(&dev->v4l2_dev, &mxb->i2c_adapter,
2538c2ecf20Sopenharmony_ci			"tda9840", I2C_TDA9840, NULL);
2548c2ecf20Sopenharmony_ci	mxb->tuner = v4l2_i2c_new_subdev(&dev->v4l2_dev, &mxb->i2c_adapter,
2558c2ecf20Sopenharmony_ci			"tuner", I2C_TUNER, NULL);
2568c2ecf20Sopenharmony_ci
2578c2ecf20Sopenharmony_ci	/* check if all devices are present */
2588c2ecf20Sopenharmony_ci	if (!mxb->tea6420_1 || !mxb->tea6420_2 || !mxb->tea6415c ||
2598c2ecf20Sopenharmony_ci	    !mxb->tda9840 || !mxb->saa7111a || !mxb->tuner) {
2608c2ecf20Sopenharmony_ci		pr_err("did not find all i2c devices. aborting\n");
2618c2ecf20Sopenharmony_ci		i2c_del_adapter(&mxb->i2c_adapter);
2628c2ecf20Sopenharmony_ci		kfree(mxb);
2638c2ecf20Sopenharmony_ci		return -ENODEV;
2648c2ecf20Sopenharmony_ci	}
2658c2ecf20Sopenharmony_ci
2668c2ecf20Sopenharmony_ci	/* all devices are present, probe was successful */
2678c2ecf20Sopenharmony_ci
2688c2ecf20Sopenharmony_ci	/* we store the pointer in our private data field */
2698c2ecf20Sopenharmony_ci	dev->ext_priv = mxb;
2708c2ecf20Sopenharmony_ci
2718c2ecf20Sopenharmony_ci	v4l2_ctrl_handler_setup(hdl);
2728c2ecf20Sopenharmony_ci
2738c2ecf20Sopenharmony_ci	return 0;
2748c2ecf20Sopenharmony_ci}
2758c2ecf20Sopenharmony_ci
2768c2ecf20Sopenharmony_ci/* some init data for the saa7740, the so-called 'sound arena module'.
2778c2ecf20Sopenharmony_ci   there are no specs available, so we simply use some init values */
2788c2ecf20Sopenharmony_cistatic struct {
2798c2ecf20Sopenharmony_ci	int	length;
2808c2ecf20Sopenharmony_ci	char	data[9];
2818c2ecf20Sopenharmony_ci} mxb_saa7740_init[] = {
2828c2ecf20Sopenharmony_ci	{ 3, { 0x80, 0x00, 0x00 } },{ 3, { 0x80, 0x89, 0x00 } },
2838c2ecf20Sopenharmony_ci	{ 3, { 0x80, 0xb0, 0x0a } },{ 3, { 0x00, 0x00, 0x00 } },
2848c2ecf20Sopenharmony_ci	{ 3, { 0x49, 0x00, 0x00 } },{ 3, { 0x4a, 0x00, 0x00 } },
2858c2ecf20Sopenharmony_ci	{ 3, { 0x4b, 0x00, 0x00 } },{ 3, { 0x4c, 0x00, 0x00 } },
2868c2ecf20Sopenharmony_ci	{ 3, { 0x4d, 0x00, 0x00 } },{ 3, { 0x4e, 0x00, 0x00 } },
2878c2ecf20Sopenharmony_ci	{ 3, { 0x4f, 0x00, 0x00 } },{ 3, { 0x50, 0x00, 0x00 } },
2888c2ecf20Sopenharmony_ci	{ 3, { 0x51, 0x00, 0x00 } },{ 3, { 0x52, 0x00, 0x00 } },
2898c2ecf20Sopenharmony_ci	{ 3, { 0x53, 0x00, 0x00 } },{ 3, { 0x54, 0x00, 0x00 } },
2908c2ecf20Sopenharmony_ci	{ 3, { 0x55, 0x00, 0x00 } },{ 3, { 0x56, 0x00, 0x00 } },
2918c2ecf20Sopenharmony_ci	{ 3, { 0x57, 0x00, 0x00 } },{ 3, { 0x58, 0x00, 0x00 } },
2928c2ecf20Sopenharmony_ci	{ 3, { 0x59, 0x00, 0x00 } },{ 3, { 0x5a, 0x00, 0x00 } },
2938c2ecf20Sopenharmony_ci	{ 3, { 0x5b, 0x00, 0x00 } },{ 3, { 0x5c, 0x00, 0x00 } },
2948c2ecf20Sopenharmony_ci	{ 3, { 0x5d, 0x00, 0x00 } },{ 3, { 0x5e, 0x00, 0x00 } },
2958c2ecf20Sopenharmony_ci	{ 3, { 0x5f, 0x00, 0x00 } },{ 3, { 0x60, 0x00, 0x00 } },
2968c2ecf20Sopenharmony_ci	{ 3, { 0x61, 0x00, 0x00 } },{ 3, { 0x62, 0x00, 0x00 } },
2978c2ecf20Sopenharmony_ci	{ 3, { 0x63, 0x00, 0x00 } },{ 3, { 0x64, 0x00, 0x00 } },
2988c2ecf20Sopenharmony_ci	{ 3, { 0x65, 0x00, 0x00 } },{ 3, { 0x66, 0x00, 0x00 } },
2998c2ecf20Sopenharmony_ci	{ 3, { 0x67, 0x00, 0x00 } },{ 3, { 0x68, 0x00, 0x00 } },
3008c2ecf20Sopenharmony_ci	{ 3, { 0x69, 0x00, 0x00 } },{ 3, { 0x6a, 0x00, 0x00 } },
3018c2ecf20Sopenharmony_ci	{ 3, { 0x6b, 0x00, 0x00 } },{ 3, { 0x6c, 0x00, 0x00 } },
3028c2ecf20Sopenharmony_ci	{ 3, { 0x6d, 0x00, 0x00 } },{ 3, { 0x6e, 0x00, 0x00 } },
3038c2ecf20Sopenharmony_ci	{ 3, { 0x6f, 0x00, 0x00 } },{ 3, { 0x70, 0x00, 0x00 } },
3048c2ecf20Sopenharmony_ci	{ 3, { 0x71, 0x00, 0x00 } },{ 3, { 0x72, 0x00, 0x00 } },
3058c2ecf20Sopenharmony_ci	{ 3, { 0x73, 0x00, 0x00 } },{ 3, { 0x74, 0x00, 0x00 } },
3068c2ecf20Sopenharmony_ci	{ 3, { 0x75, 0x00, 0x00 } },{ 3, { 0x76, 0x00, 0x00 } },
3078c2ecf20Sopenharmony_ci	{ 3, { 0x77, 0x00, 0x00 } },{ 3, { 0x41, 0x00, 0x42 } },
3088c2ecf20Sopenharmony_ci	{ 3, { 0x42, 0x10, 0x42 } },{ 3, { 0x43, 0x20, 0x42 } },
3098c2ecf20Sopenharmony_ci	{ 3, { 0x44, 0x30, 0x42 } },{ 3, { 0x45, 0x00, 0x01 } },
3108c2ecf20Sopenharmony_ci	{ 3, { 0x46, 0x00, 0x01 } },{ 3, { 0x47, 0x00, 0x01 } },
3118c2ecf20Sopenharmony_ci	{ 3, { 0x48, 0x00, 0x01 } },
3128c2ecf20Sopenharmony_ci	{ 9, { 0x01, 0x03, 0xc5, 0x5c, 0x7a, 0x85, 0x01, 0x00, 0x54 } },
3138c2ecf20Sopenharmony_ci	{ 9, { 0x21, 0x03, 0xc5, 0x5c, 0x7a, 0x85, 0x01, 0x00, 0x54 } },
3148c2ecf20Sopenharmony_ci	{ 9, { 0x09, 0x0b, 0xb4, 0x6b, 0x74, 0x85, 0x95, 0x00, 0x34 } },
3158c2ecf20Sopenharmony_ci	{ 9, { 0x29, 0x0b, 0xb4, 0x6b, 0x74, 0x85, 0x95, 0x00, 0x34 } },
3168c2ecf20Sopenharmony_ci	{ 9, { 0x11, 0x17, 0x43, 0x62, 0x68, 0x89, 0xd1, 0xff, 0xb0 } },
3178c2ecf20Sopenharmony_ci	{ 9, { 0x31, 0x17, 0x43, 0x62, 0x68, 0x89, 0xd1, 0xff, 0xb0 } },
3188c2ecf20Sopenharmony_ci	{ 9, { 0x19, 0x20, 0x62, 0x51, 0x5a, 0x95, 0x19, 0x01, 0x50 } },
3198c2ecf20Sopenharmony_ci	{ 9, { 0x39, 0x20, 0x62, 0x51, 0x5a, 0x95, 0x19, 0x01, 0x50 } },
3208c2ecf20Sopenharmony_ci	{ 9, { 0x05, 0x3e, 0xd2, 0x69, 0x4e, 0x9a, 0x51, 0x00, 0xf0 } },
3218c2ecf20Sopenharmony_ci	{ 9, { 0x25, 0x3e, 0xd2, 0x69, 0x4e, 0x9a, 0x51, 0x00, 0xf0 } },
3228c2ecf20Sopenharmony_ci	{ 9, { 0x0d, 0x3d, 0xa1, 0x40, 0x7d, 0x9f, 0x29, 0xfe, 0x14 } },
3238c2ecf20Sopenharmony_ci	{ 9, { 0x2d, 0x3d, 0xa1, 0x40, 0x7d, 0x9f, 0x29, 0xfe, 0x14 } },
3248c2ecf20Sopenharmony_ci	{ 9, { 0x15, 0x73, 0xa1, 0x50, 0x5d, 0xa6, 0xf5, 0xfe, 0x38 } },
3258c2ecf20Sopenharmony_ci	{ 9, { 0x35, 0x73, 0xa1, 0x50, 0x5d, 0xa6, 0xf5, 0xfe, 0x38 } },
3268c2ecf20Sopenharmony_ci	{ 9, { 0x1d, 0xed, 0xd0, 0x68, 0x29, 0xb4, 0xe1, 0x00, 0xb8 } },
3278c2ecf20Sopenharmony_ci	{ 9, { 0x3d, 0xed, 0xd0, 0x68, 0x29, 0xb4, 0xe1, 0x00, 0xb8 } },
3288c2ecf20Sopenharmony_ci	{ 3, { 0x80, 0xb3, 0x0a } },
3298c2ecf20Sopenharmony_ci	{-1, { 0 } }
3308c2ecf20Sopenharmony_ci};
3318c2ecf20Sopenharmony_ci
3328c2ecf20Sopenharmony_ci/* bring hardware to a sane state. this has to be done, just in case someone
3338c2ecf20Sopenharmony_ci   wants to capture from this device before it has been properly initialized.
3348c2ecf20Sopenharmony_ci   the capture engine would badly fail, because no valid signal arrives on the
3358c2ecf20Sopenharmony_ci   saa7146, thus leading to timeouts and stuff. */
3368c2ecf20Sopenharmony_cistatic int mxb_init_done(struct saa7146_dev* dev)
3378c2ecf20Sopenharmony_ci{
3388c2ecf20Sopenharmony_ci	struct mxb* mxb = (struct mxb*)dev->ext_priv;
3398c2ecf20Sopenharmony_ci	struct i2c_msg msg;
3408c2ecf20Sopenharmony_ci	struct tuner_setup tun_setup;
3418c2ecf20Sopenharmony_ci	v4l2_std_id std = V4L2_STD_PAL_BG;
3428c2ecf20Sopenharmony_ci
3438c2ecf20Sopenharmony_ci	int i = 0, err = 0;
3448c2ecf20Sopenharmony_ci
3458c2ecf20Sopenharmony_ci	/* mute audio on tea6420s */
3468c2ecf20Sopenharmony_ci	tea6420_route(mxb, 6);
3478c2ecf20Sopenharmony_ci
3488c2ecf20Sopenharmony_ci	/* select video mode in saa7111a */
3498c2ecf20Sopenharmony_ci	saa7111a_call(mxb, video, s_std, std);
3508c2ecf20Sopenharmony_ci
3518c2ecf20Sopenharmony_ci	/* select tuner-output on saa7111a */
3528c2ecf20Sopenharmony_ci	i = 0;
3538c2ecf20Sopenharmony_ci	saa7111a_call(mxb, video, s_routing, SAA7115_COMPOSITE0,
3548c2ecf20Sopenharmony_ci		SAA7111_FMT_CCIR, 0);
3558c2ecf20Sopenharmony_ci
3568c2ecf20Sopenharmony_ci	/* select a tuner type */
3578c2ecf20Sopenharmony_ci	tun_setup.mode_mask = T_ANALOG_TV;
3588c2ecf20Sopenharmony_ci	tun_setup.addr = ADDR_UNSET;
3598c2ecf20Sopenharmony_ci	tun_setup.type = TUNER_PHILIPS_PAL;
3608c2ecf20Sopenharmony_ci	tuner_call(mxb, tuner, s_type_addr, &tun_setup);
3618c2ecf20Sopenharmony_ci	/* tune in some frequency on tuner */
3628c2ecf20Sopenharmony_ci	mxb->cur_freq.tuner = 0;
3638c2ecf20Sopenharmony_ci	mxb->cur_freq.type = V4L2_TUNER_ANALOG_TV;
3648c2ecf20Sopenharmony_ci	mxb->cur_freq.frequency = freq;
3658c2ecf20Sopenharmony_ci	tuner_call(mxb, tuner, s_frequency, &mxb->cur_freq);
3668c2ecf20Sopenharmony_ci
3678c2ecf20Sopenharmony_ci	/* set a default video standard */
3688c2ecf20Sopenharmony_ci	/* These two gpio calls set the GPIO pins that control the tda9820 */
3698c2ecf20Sopenharmony_ci	saa7146_write(dev, GPIO_CTRL, 0x00404050);
3708c2ecf20Sopenharmony_ci	saa7111a_call(mxb, core, s_gpio, 1);
3718c2ecf20Sopenharmony_ci	saa7111a_call(mxb, video, s_std, std);
3728c2ecf20Sopenharmony_ci	tuner_call(mxb, video, s_std, std);
3738c2ecf20Sopenharmony_ci
3748c2ecf20Sopenharmony_ci	/* switch to tuner-channel on tea6415c */
3758c2ecf20Sopenharmony_ci	tea6415c_call(mxb, video, s_routing, 3, 17, 0);
3768c2ecf20Sopenharmony_ci
3778c2ecf20Sopenharmony_ci	/* select tuner-output on multicable on tea6415c */
3788c2ecf20Sopenharmony_ci	tea6415c_call(mxb, video, s_routing, 3, 13, 0);
3798c2ecf20Sopenharmony_ci
3808c2ecf20Sopenharmony_ci	/* the rest for mxb */
3818c2ecf20Sopenharmony_ci	mxb->cur_input = 0;
3828c2ecf20Sopenharmony_ci	mxb->cur_audinput = video_audio_connect[mxb->cur_input];
3838c2ecf20Sopenharmony_ci	mxb->cur_mute = 1;
3848c2ecf20Sopenharmony_ci
3858c2ecf20Sopenharmony_ci	mxb->cur_mode = V4L2_TUNER_MODE_STEREO;
3868c2ecf20Sopenharmony_ci	mxb_update_audmode(mxb);
3878c2ecf20Sopenharmony_ci
3888c2ecf20Sopenharmony_ci	/* check if the saa7740 (aka 'sound arena module') is present
3898c2ecf20Sopenharmony_ci	   on the mxb. if so, we must initialize it. due to lack of
3908c2ecf20Sopenharmony_ci	   information about the saa7740, the values were reverse
3918c2ecf20Sopenharmony_ci	   engineered. */
3928c2ecf20Sopenharmony_ci	msg.addr = 0x1b;
3938c2ecf20Sopenharmony_ci	msg.flags = 0;
3948c2ecf20Sopenharmony_ci	msg.len = mxb_saa7740_init[0].length;
3958c2ecf20Sopenharmony_ci	msg.buf = &mxb_saa7740_init[0].data[0];
3968c2ecf20Sopenharmony_ci
3978c2ecf20Sopenharmony_ci	err = i2c_transfer(&mxb->i2c_adapter, &msg, 1);
3988c2ecf20Sopenharmony_ci	if (err == 1) {
3998c2ecf20Sopenharmony_ci		/* the sound arena module is a pos, that's probably the reason
4008c2ecf20Sopenharmony_ci		   philips refuses to hand out a datasheet for the saa7740...
4018c2ecf20Sopenharmony_ci		   it seems to screw up the i2c bus, so we disable fast irq
4028c2ecf20Sopenharmony_ci		   based i2c transactions here and rely on the slow and safe
4038c2ecf20Sopenharmony_ci		   polling method ... */
4048c2ecf20Sopenharmony_ci		extension.flags &= ~SAA7146_USE_I2C_IRQ;
4058c2ecf20Sopenharmony_ci		for (i = 1; ; i++) {
4068c2ecf20Sopenharmony_ci			if (-1 == mxb_saa7740_init[i].length)
4078c2ecf20Sopenharmony_ci				break;
4088c2ecf20Sopenharmony_ci
4098c2ecf20Sopenharmony_ci			msg.len = mxb_saa7740_init[i].length;
4108c2ecf20Sopenharmony_ci			msg.buf = &mxb_saa7740_init[i].data[0];
4118c2ecf20Sopenharmony_ci			err = i2c_transfer(&mxb->i2c_adapter, &msg, 1);
4128c2ecf20Sopenharmony_ci			if (err != 1) {
4138c2ecf20Sopenharmony_ci				DEB_D("failed to initialize 'sound arena module'\n");
4148c2ecf20Sopenharmony_ci				goto err;
4158c2ecf20Sopenharmony_ci			}
4168c2ecf20Sopenharmony_ci		}
4178c2ecf20Sopenharmony_ci		pr_info("'sound arena module' detected\n");
4188c2ecf20Sopenharmony_ci	}
4198c2ecf20Sopenharmony_cierr:
4208c2ecf20Sopenharmony_ci	/* the rest for saa7146: you should definitely set some basic values
4218c2ecf20Sopenharmony_ci	   for the input-port handling of the saa7146. */
4228c2ecf20Sopenharmony_ci
4238c2ecf20Sopenharmony_ci	/* ext->saa has been filled by the core driver */
4248c2ecf20Sopenharmony_ci
4258c2ecf20Sopenharmony_ci	/* some stuff is done via variables */
4268c2ecf20Sopenharmony_ci	saa7146_set_hps_source_and_sync(dev, input_port_selection[mxb->cur_input].hps_source,
4278c2ecf20Sopenharmony_ci			input_port_selection[mxb->cur_input].hps_sync);
4288c2ecf20Sopenharmony_ci
4298c2ecf20Sopenharmony_ci	/* some stuff is done via direct write to the registers */
4308c2ecf20Sopenharmony_ci
4318c2ecf20Sopenharmony_ci	/* this is ugly, but because of the fact that this is completely
4328c2ecf20Sopenharmony_ci	   hardware dependend, it should be done directly... */
4338c2ecf20Sopenharmony_ci	saa7146_write(dev, DD1_STREAM_B,	0x00000000);
4348c2ecf20Sopenharmony_ci	saa7146_write(dev, DD1_INIT,		0x02000200);
4358c2ecf20Sopenharmony_ci	saa7146_write(dev, MC2, (MASK_09 | MASK_25 | MASK_10 | MASK_26));
4368c2ecf20Sopenharmony_ci
4378c2ecf20Sopenharmony_ci	return 0;
4388c2ecf20Sopenharmony_ci}
4398c2ecf20Sopenharmony_ci
4408c2ecf20Sopenharmony_ci/* interrupt-handler. this gets called when irq_mask is != 0.
4418c2ecf20Sopenharmony_ci   it must clear the interrupt-bits in irq_mask it has handled */
4428c2ecf20Sopenharmony_ci/*
4438c2ecf20Sopenharmony_civoid mxb_irq_bh(struct saa7146_dev* dev, u32* irq_mask)
4448c2ecf20Sopenharmony_ci{
4458c2ecf20Sopenharmony_ci	struct mxb* mxb = (struct mxb*)dev->ext_priv;
4468c2ecf20Sopenharmony_ci}
4478c2ecf20Sopenharmony_ci*/
4488c2ecf20Sopenharmony_ci
4498c2ecf20Sopenharmony_cistatic int vidioc_enum_input(struct file *file, void *fh, struct v4l2_input *i)
4508c2ecf20Sopenharmony_ci{
4518c2ecf20Sopenharmony_ci	DEB_EE("VIDIOC_ENUMINPUT %d\n", i->index);
4528c2ecf20Sopenharmony_ci	if (i->index >= MXB_INPUTS)
4538c2ecf20Sopenharmony_ci		return -EINVAL;
4548c2ecf20Sopenharmony_ci	memcpy(i, &mxb_inputs[i->index], sizeof(struct v4l2_input));
4558c2ecf20Sopenharmony_ci	return 0;
4568c2ecf20Sopenharmony_ci}
4578c2ecf20Sopenharmony_ci
4588c2ecf20Sopenharmony_cistatic int vidioc_g_input(struct file *file, void *fh, unsigned int *i)
4598c2ecf20Sopenharmony_ci{
4608c2ecf20Sopenharmony_ci	struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
4618c2ecf20Sopenharmony_ci	struct mxb *mxb = (struct mxb *)dev->ext_priv;
4628c2ecf20Sopenharmony_ci	*i = mxb->cur_input;
4638c2ecf20Sopenharmony_ci
4648c2ecf20Sopenharmony_ci	DEB_EE("VIDIOC_G_INPUT %d\n", *i);
4658c2ecf20Sopenharmony_ci	return 0;
4668c2ecf20Sopenharmony_ci}
4678c2ecf20Sopenharmony_ci
4688c2ecf20Sopenharmony_cistatic int vidioc_s_input(struct file *file, void *fh, unsigned int input)
4698c2ecf20Sopenharmony_ci{
4708c2ecf20Sopenharmony_ci	struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
4718c2ecf20Sopenharmony_ci	struct mxb *mxb = (struct mxb *)dev->ext_priv;
4728c2ecf20Sopenharmony_ci	int err = 0;
4738c2ecf20Sopenharmony_ci	int i = 0;
4748c2ecf20Sopenharmony_ci
4758c2ecf20Sopenharmony_ci	DEB_EE("VIDIOC_S_INPUT %d\n", input);
4768c2ecf20Sopenharmony_ci
4778c2ecf20Sopenharmony_ci	if (input >= MXB_INPUTS)
4788c2ecf20Sopenharmony_ci		return -EINVAL;
4798c2ecf20Sopenharmony_ci
4808c2ecf20Sopenharmony_ci	mxb->cur_input = input;
4818c2ecf20Sopenharmony_ci
4828c2ecf20Sopenharmony_ci	saa7146_set_hps_source_and_sync(dev, input_port_selection[input].hps_source,
4838c2ecf20Sopenharmony_ci			input_port_selection[input].hps_sync);
4848c2ecf20Sopenharmony_ci
4858c2ecf20Sopenharmony_ci	/* prepare switching of tea6415c and saa7111a;
4868c2ecf20Sopenharmony_ci	   have a look at the 'background'-file for further information  */
4878c2ecf20Sopenharmony_ci	switch (input) {
4888c2ecf20Sopenharmony_ci	case TUNER:
4898c2ecf20Sopenharmony_ci		i = SAA7115_COMPOSITE0;
4908c2ecf20Sopenharmony_ci
4918c2ecf20Sopenharmony_ci		err = tea6415c_call(mxb, video, s_routing, 3, 17, 0);
4928c2ecf20Sopenharmony_ci
4938c2ecf20Sopenharmony_ci		/* connect tuner-output always to multicable */
4948c2ecf20Sopenharmony_ci		if (!err)
4958c2ecf20Sopenharmony_ci			err = tea6415c_call(mxb, video, s_routing, 3, 13, 0);
4968c2ecf20Sopenharmony_ci		break;
4978c2ecf20Sopenharmony_ci	case AUX3_YC:
4988c2ecf20Sopenharmony_ci		/* nothing to be done here. aux3_yc is
4998c2ecf20Sopenharmony_ci		   directly connected to the saa711a */
5008c2ecf20Sopenharmony_ci		i = SAA7115_SVIDEO1;
5018c2ecf20Sopenharmony_ci		break;
5028c2ecf20Sopenharmony_ci	case AUX3:
5038c2ecf20Sopenharmony_ci		/* nothing to be done here. aux3 is
5048c2ecf20Sopenharmony_ci		   directly connected to the saa711a */
5058c2ecf20Sopenharmony_ci		i = SAA7115_COMPOSITE1;
5068c2ecf20Sopenharmony_ci		break;
5078c2ecf20Sopenharmony_ci	case AUX1:
5088c2ecf20Sopenharmony_ci		i = SAA7115_COMPOSITE0;
5098c2ecf20Sopenharmony_ci		err = tea6415c_call(mxb, video, s_routing, 1, 17, 0);
5108c2ecf20Sopenharmony_ci		break;
5118c2ecf20Sopenharmony_ci	}
5128c2ecf20Sopenharmony_ci
5138c2ecf20Sopenharmony_ci	if (err)
5148c2ecf20Sopenharmony_ci		return err;
5158c2ecf20Sopenharmony_ci
5168c2ecf20Sopenharmony_ci	/* switch video in saa7111a */
5178c2ecf20Sopenharmony_ci	if (saa7111a_call(mxb, video, s_routing, i, SAA7111_FMT_CCIR, 0))
5188c2ecf20Sopenharmony_ci		pr_err("VIDIOC_S_INPUT: could not address saa7111a\n");
5198c2ecf20Sopenharmony_ci
5208c2ecf20Sopenharmony_ci	mxb->cur_audinput = video_audio_connect[input];
5218c2ecf20Sopenharmony_ci	/* switch the audio-source only if necessary */
5228c2ecf20Sopenharmony_ci	if (0 == mxb->cur_mute)
5238c2ecf20Sopenharmony_ci		tea6420_route(mxb, mxb->cur_audinput);
5248c2ecf20Sopenharmony_ci	if (mxb->cur_audinput == 0)
5258c2ecf20Sopenharmony_ci		mxb_update_audmode(mxb);
5268c2ecf20Sopenharmony_ci
5278c2ecf20Sopenharmony_ci	return 0;
5288c2ecf20Sopenharmony_ci}
5298c2ecf20Sopenharmony_ci
5308c2ecf20Sopenharmony_cistatic int vidioc_g_tuner(struct file *file, void *fh, struct v4l2_tuner *t)
5318c2ecf20Sopenharmony_ci{
5328c2ecf20Sopenharmony_ci	struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
5338c2ecf20Sopenharmony_ci	struct mxb *mxb = (struct mxb *)dev->ext_priv;
5348c2ecf20Sopenharmony_ci
5358c2ecf20Sopenharmony_ci	if (t->index) {
5368c2ecf20Sopenharmony_ci		DEB_D("VIDIOC_G_TUNER: channel %d does not have a tuner attached\n",
5378c2ecf20Sopenharmony_ci		      t->index);
5388c2ecf20Sopenharmony_ci		return -EINVAL;
5398c2ecf20Sopenharmony_ci	}
5408c2ecf20Sopenharmony_ci
5418c2ecf20Sopenharmony_ci	DEB_EE("VIDIOC_G_TUNER: %d\n", t->index);
5428c2ecf20Sopenharmony_ci
5438c2ecf20Sopenharmony_ci	memset(t, 0, sizeof(*t));
5448c2ecf20Sopenharmony_ci	strscpy(t->name, "TV Tuner", sizeof(t->name));
5458c2ecf20Sopenharmony_ci	t->type = V4L2_TUNER_ANALOG_TV;
5468c2ecf20Sopenharmony_ci	t->capability = V4L2_TUNER_CAP_NORM | V4L2_TUNER_CAP_STEREO |
5478c2ecf20Sopenharmony_ci			V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2 | V4L2_TUNER_CAP_SAP;
5488c2ecf20Sopenharmony_ci	t->audmode = mxb->cur_mode;
5498c2ecf20Sopenharmony_ci	return call_all(dev, tuner, g_tuner, t);
5508c2ecf20Sopenharmony_ci}
5518c2ecf20Sopenharmony_ci
5528c2ecf20Sopenharmony_cistatic int vidioc_s_tuner(struct file *file, void *fh, const struct v4l2_tuner *t)
5538c2ecf20Sopenharmony_ci{
5548c2ecf20Sopenharmony_ci	struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
5558c2ecf20Sopenharmony_ci	struct mxb *mxb = (struct mxb *)dev->ext_priv;
5568c2ecf20Sopenharmony_ci
5578c2ecf20Sopenharmony_ci	if (t->index) {
5588c2ecf20Sopenharmony_ci		DEB_D("VIDIOC_S_TUNER: channel %d does not have a tuner attached\n",
5598c2ecf20Sopenharmony_ci		      t->index);
5608c2ecf20Sopenharmony_ci		return -EINVAL;
5618c2ecf20Sopenharmony_ci	}
5628c2ecf20Sopenharmony_ci
5638c2ecf20Sopenharmony_ci	mxb->cur_mode = t->audmode;
5648c2ecf20Sopenharmony_ci	return call_all(dev, tuner, s_tuner, t);
5658c2ecf20Sopenharmony_ci}
5668c2ecf20Sopenharmony_ci
5678c2ecf20Sopenharmony_cistatic int vidioc_querystd(struct file *file, void *fh, v4l2_std_id *norm)
5688c2ecf20Sopenharmony_ci{
5698c2ecf20Sopenharmony_ci	struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
5708c2ecf20Sopenharmony_ci
5718c2ecf20Sopenharmony_ci	return call_all(dev, video, querystd, norm);
5728c2ecf20Sopenharmony_ci}
5738c2ecf20Sopenharmony_ci
5748c2ecf20Sopenharmony_cistatic int vidioc_g_frequency(struct file *file, void *fh, struct v4l2_frequency *f)
5758c2ecf20Sopenharmony_ci{
5768c2ecf20Sopenharmony_ci	struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
5778c2ecf20Sopenharmony_ci	struct mxb *mxb = (struct mxb *)dev->ext_priv;
5788c2ecf20Sopenharmony_ci
5798c2ecf20Sopenharmony_ci	if (f->tuner)
5808c2ecf20Sopenharmony_ci		return -EINVAL;
5818c2ecf20Sopenharmony_ci	*f = mxb->cur_freq;
5828c2ecf20Sopenharmony_ci
5838c2ecf20Sopenharmony_ci	DEB_EE("VIDIOC_G_FREQ: freq:0x%08x\n", mxb->cur_freq.frequency);
5848c2ecf20Sopenharmony_ci	return 0;
5858c2ecf20Sopenharmony_ci}
5868c2ecf20Sopenharmony_ci
5878c2ecf20Sopenharmony_cistatic int vidioc_s_frequency(struct file *file, void *fh, const struct v4l2_frequency *f)
5888c2ecf20Sopenharmony_ci{
5898c2ecf20Sopenharmony_ci	struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
5908c2ecf20Sopenharmony_ci	struct mxb *mxb = (struct mxb *)dev->ext_priv;
5918c2ecf20Sopenharmony_ci	struct saa7146_vv *vv = dev->vv_data;
5928c2ecf20Sopenharmony_ci
5938c2ecf20Sopenharmony_ci	if (f->tuner)
5948c2ecf20Sopenharmony_ci		return -EINVAL;
5958c2ecf20Sopenharmony_ci
5968c2ecf20Sopenharmony_ci	if (V4L2_TUNER_ANALOG_TV != f->type)
5978c2ecf20Sopenharmony_ci		return -EINVAL;
5988c2ecf20Sopenharmony_ci
5998c2ecf20Sopenharmony_ci	DEB_EE("VIDIOC_S_FREQUENCY: freq:0x%08x\n", mxb->cur_freq.frequency);
6008c2ecf20Sopenharmony_ci
6018c2ecf20Sopenharmony_ci	/* tune in desired frequency */
6028c2ecf20Sopenharmony_ci	tuner_call(mxb, tuner, s_frequency, f);
6038c2ecf20Sopenharmony_ci	/* let the tuner subdev clamp the frequency to the tuner range */
6048c2ecf20Sopenharmony_ci	mxb->cur_freq = *f;
6058c2ecf20Sopenharmony_ci	tuner_call(mxb, tuner, g_frequency, &mxb->cur_freq);
6068c2ecf20Sopenharmony_ci	if (mxb->cur_audinput == 0)
6078c2ecf20Sopenharmony_ci		mxb_update_audmode(mxb);
6088c2ecf20Sopenharmony_ci
6098c2ecf20Sopenharmony_ci	if (mxb->cur_input)
6108c2ecf20Sopenharmony_ci		return 0;
6118c2ecf20Sopenharmony_ci
6128c2ecf20Sopenharmony_ci	/* hack: changing the frequency should invalidate the vbi-counter (=> alevt) */
6138c2ecf20Sopenharmony_ci	spin_lock(&dev->slock);
6148c2ecf20Sopenharmony_ci	vv->vbi_fieldcount = 0;
6158c2ecf20Sopenharmony_ci	spin_unlock(&dev->slock);
6168c2ecf20Sopenharmony_ci
6178c2ecf20Sopenharmony_ci	return 0;
6188c2ecf20Sopenharmony_ci}
6198c2ecf20Sopenharmony_ci
6208c2ecf20Sopenharmony_cistatic int vidioc_enumaudio(struct file *file, void *fh, struct v4l2_audio *a)
6218c2ecf20Sopenharmony_ci{
6228c2ecf20Sopenharmony_ci	if (a->index >= MXB_AUDIOS)
6238c2ecf20Sopenharmony_ci		return -EINVAL;
6248c2ecf20Sopenharmony_ci	*a = mxb_audios[a->index];
6258c2ecf20Sopenharmony_ci	return 0;
6268c2ecf20Sopenharmony_ci}
6278c2ecf20Sopenharmony_ci
6288c2ecf20Sopenharmony_cistatic int vidioc_g_audio(struct file *file, void *fh, struct v4l2_audio *a)
6298c2ecf20Sopenharmony_ci{
6308c2ecf20Sopenharmony_ci	struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
6318c2ecf20Sopenharmony_ci	struct mxb *mxb = (struct mxb *)dev->ext_priv;
6328c2ecf20Sopenharmony_ci
6338c2ecf20Sopenharmony_ci	DEB_EE("VIDIOC_G_AUDIO\n");
6348c2ecf20Sopenharmony_ci	*a = mxb_audios[mxb->cur_audinput];
6358c2ecf20Sopenharmony_ci	return 0;
6368c2ecf20Sopenharmony_ci}
6378c2ecf20Sopenharmony_ci
6388c2ecf20Sopenharmony_cistatic int vidioc_s_audio(struct file *file, void *fh, const struct v4l2_audio *a)
6398c2ecf20Sopenharmony_ci{
6408c2ecf20Sopenharmony_ci	struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
6418c2ecf20Sopenharmony_ci	struct mxb *mxb = (struct mxb *)dev->ext_priv;
6428c2ecf20Sopenharmony_ci
6438c2ecf20Sopenharmony_ci	DEB_D("VIDIOC_S_AUDIO %d\n", a->index);
6448c2ecf20Sopenharmony_ci	if (a->index >= 32 ||
6458c2ecf20Sopenharmony_ci	    !(mxb_inputs[mxb->cur_input].audioset & (1 << a->index)))
6468c2ecf20Sopenharmony_ci		return -EINVAL;
6478c2ecf20Sopenharmony_ci
6488c2ecf20Sopenharmony_ci	if (mxb->cur_audinput != a->index) {
6498c2ecf20Sopenharmony_ci		mxb->cur_audinput = a->index;
6508c2ecf20Sopenharmony_ci		tea6420_route(mxb, a->index);
6518c2ecf20Sopenharmony_ci		if (mxb->cur_audinput == 0)
6528c2ecf20Sopenharmony_ci			mxb_update_audmode(mxb);
6538c2ecf20Sopenharmony_ci	}
6548c2ecf20Sopenharmony_ci	return 0;
6558c2ecf20Sopenharmony_ci}
6568c2ecf20Sopenharmony_ci
6578c2ecf20Sopenharmony_ci#ifdef CONFIG_VIDEO_ADV_DEBUG
6588c2ecf20Sopenharmony_cistatic int vidioc_g_register(struct file *file, void *fh, struct v4l2_dbg_register *reg)
6598c2ecf20Sopenharmony_ci{
6608c2ecf20Sopenharmony_ci	struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
6618c2ecf20Sopenharmony_ci
6628c2ecf20Sopenharmony_ci	if (reg->reg > pci_resource_len(dev->pci, 0) - 4)
6638c2ecf20Sopenharmony_ci		return -EINVAL;
6648c2ecf20Sopenharmony_ci	reg->val = saa7146_read(dev, reg->reg);
6658c2ecf20Sopenharmony_ci	reg->size = 4;
6668c2ecf20Sopenharmony_ci	return 0;
6678c2ecf20Sopenharmony_ci}
6688c2ecf20Sopenharmony_ci
6698c2ecf20Sopenharmony_cistatic int vidioc_s_register(struct file *file, void *fh, const struct v4l2_dbg_register *reg)
6708c2ecf20Sopenharmony_ci{
6718c2ecf20Sopenharmony_ci	struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
6728c2ecf20Sopenharmony_ci
6738c2ecf20Sopenharmony_ci	if (reg->reg > pci_resource_len(dev->pci, 0) - 4)
6748c2ecf20Sopenharmony_ci		return -EINVAL;
6758c2ecf20Sopenharmony_ci	saa7146_write(dev, reg->reg, reg->val);
6768c2ecf20Sopenharmony_ci	return 0;
6778c2ecf20Sopenharmony_ci}
6788c2ecf20Sopenharmony_ci#endif
6798c2ecf20Sopenharmony_ci
6808c2ecf20Sopenharmony_cistatic struct saa7146_ext_vv vv_data;
6818c2ecf20Sopenharmony_ci
6828c2ecf20Sopenharmony_ci/* this function only gets called when the probing was successful */
6838c2ecf20Sopenharmony_cistatic int mxb_attach(struct saa7146_dev *dev, struct saa7146_pci_extension_data *info)
6848c2ecf20Sopenharmony_ci{
6858c2ecf20Sopenharmony_ci	struct mxb *mxb;
6868c2ecf20Sopenharmony_ci	int ret;
6878c2ecf20Sopenharmony_ci
6888c2ecf20Sopenharmony_ci	DEB_EE("dev:%p\n", dev);
6898c2ecf20Sopenharmony_ci
6908c2ecf20Sopenharmony_ci	ret = saa7146_vv_init(dev, &vv_data);
6918c2ecf20Sopenharmony_ci	if (ret) {
6928c2ecf20Sopenharmony_ci		ERR("Error in saa7146_vv_init()");
6938c2ecf20Sopenharmony_ci		return ret;
6948c2ecf20Sopenharmony_ci	}
6958c2ecf20Sopenharmony_ci
6968c2ecf20Sopenharmony_ci	if (mxb_probe(dev)) {
6978c2ecf20Sopenharmony_ci		saa7146_vv_release(dev);
6988c2ecf20Sopenharmony_ci		return -1;
6998c2ecf20Sopenharmony_ci	}
7008c2ecf20Sopenharmony_ci	mxb = (struct mxb *)dev->ext_priv;
7018c2ecf20Sopenharmony_ci
7028c2ecf20Sopenharmony_ci	vv_data.vid_ops.vidioc_enum_input = vidioc_enum_input;
7038c2ecf20Sopenharmony_ci	vv_data.vid_ops.vidioc_g_input = vidioc_g_input;
7048c2ecf20Sopenharmony_ci	vv_data.vid_ops.vidioc_s_input = vidioc_s_input;
7058c2ecf20Sopenharmony_ci	vv_data.vid_ops.vidioc_querystd = vidioc_querystd;
7068c2ecf20Sopenharmony_ci	vv_data.vid_ops.vidioc_g_tuner = vidioc_g_tuner;
7078c2ecf20Sopenharmony_ci	vv_data.vid_ops.vidioc_s_tuner = vidioc_s_tuner;
7088c2ecf20Sopenharmony_ci	vv_data.vid_ops.vidioc_g_frequency = vidioc_g_frequency;
7098c2ecf20Sopenharmony_ci	vv_data.vid_ops.vidioc_s_frequency = vidioc_s_frequency;
7108c2ecf20Sopenharmony_ci	vv_data.vid_ops.vidioc_enumaudio = vidioc_enumaudio;
7118c2ecf20Sopenharmony_ci	vv_data.vid_ops.vidioc_g_audio = vidioc_g_audio;
7128c2ecf20Sopenharmony_ci	vv_data.vid_ops.vidioc_s_audio = vidioc_s_audio;
7138c2ecf20Sopenharmony_ci#ifdef CONFIG_VIDEO_ADV_DEBUG
7148c2ecf20Sopenharmony_ci	vv_data.vid_ops.vidioc_g_register = vidioc_g_register;
7158c2ecf20Sopenharmony_ci	vv_data.vid_ops.vidioc_s_register = vidioc_s_register;
7168c2ecf20Sopenharmony_ci#endif
7178c2ecf20Sopenharmony_ci	if (saa7146_register_device(&mxb->video_dev, dev, "mxb", VFL_TYPE_VIDEO)) {
7188c2ecf20Sopenharmony_ci		ERR("cannot register capture v4l2 device. skipping.\n");
7198c2ecf20Sopenharmony_ci		saa7146_vv_release(dev);
7208c2ecf20Sopenharmony_ci		return -1;
7218c2ecf20Sopenharmony_ci	}
7228c2ecf20Sopenharmony_ci
7238c2ecf20Sopenharmony_ci	/* initialization stuff (vbi) (only for revision > 0 and for extensions which want it)*/
7248c2ecf20Sopenharmony_ci	if (MXB_BOARD_CAN_DO_VBI(dev)) {
7258c2ecf20Sopenharmony_ci		if (saa7146_register_device(&mxb->vbi_dev, dev, "mxb", VFL_TYPE_VBI)) {
7268c2ecf20Sopenharmony_ci			ERR("cannot register vbi v4l2 device. skipping.\n");
7278c2ecf20Sopenharmony_ci		}
7288c2ecf20Sopenharmony_ci	}
7298c2ecf20Sopenharmony_ci
7308c2ecf20Sopenharmony_ci	pr_info("found Multimedia eXtension Board #%d\n", mxb_num);
7318c2ecf20Sopenharmony_ci
7328c2ecf20Sopenharmony_ci	mxb_num++;
7338c2ecf20Sopenharmony_ci	mxb_init_done(dev);
7348c2ecf20Sopenharmony_ci	return 0;
7358c2ecf20Sopenharmony_ci}
7368c2ecf20Sopenharmony_ci
7378c2ecf20Sopenharmony_cistatic int mxb_detach(struct saa7146_dev *dev)
7388c2ecf20Sopenharmony_ci{
7398c2ecf20Sopenharmony_ci	struct mxb *mxb = (struct mxb *)dev->ext_priv;
7408c2ecf20Sopenharmony_ci
7418c2ecf20Sopenharmony_ci	DEB_EE("dev:%p\n", dev);
7428c2ecf20Sopenharmony_ci
7438c2ecf20Sopenharmony_ci	/* mute audio on tea6420s */
7448c2ecf20Sopenharmony_ci	tea6420_route(mxb, 6);
7458c2ecf20Sopenharmony_ci
7468c2ecf20Sopenharmony_ci	saa7146_unregister_device(&mxb->video_dev,dev);
7478c2ecf20Sopenharmony_ci	if (MXB_BOARD_CAN_DO_VBI(dev))
7488c2ecf20Sopenharmony_ci		saa7146_unregister_device(&mxb->vbi_dev, dev);
7498c2ecf20Sopenharmony_ci	saa7146_vv_release(dev);
7508c2ecf20Sopenharmony_ci
7518c2ecf20Sopenharmony_ci	mxb_num--;
7528c2ecf20Sopenharmony_ci
7538c2ecf20Sopenharmony_ci	i2c_del_adapter(&mxb->i2c_adapter);
7548c2ecf20Sopenharmony_ci	kfree(mxb);
7558c2ecf20Sopenharmony_ci
7568c2ecf20Sopenharmony_ci	return 0;
7578c2ecf20Sopenharmony_ci}
7588c2ecf20Sopenharmony_ci
7598c2ecf20Sopenharmony_cistatic int std_callback(struct saa7146_dev *dev, struct saa7146_standard *standard)
7608c2ecf20Sopenharmony_ci{
7618c2ecf20Sopenharmony_ci	struct mxb *mxb = (struct mxb *)dev->ext_priv;
7628c2ecf20Sopenharmony_ci
7638c2ecf20Sopenharmony_ci	if (V4L2_STD_PAL_I == standard->id) {
7648c2ecf20Sopenharmony_ci		v4l2_std_id std = V4L2_STD_PAL_I;
7658c2ecf20Sopenharmony_ci
7668c2ecf20Sopenharmony_ci		DEB_D("VIDIOC_S_STD: setting mxb for PAL_I\n");
7678c2ecf20Sopenharmony_ci		/* These two gpio calls set the GPIO pins that control the tda9820 */
7688c2ecf20Sopenharmony_ci		saa7146_write(dev, GPIO_CTRL, 0x00404050);
7698c2ecf20Sopenharmony_ci		saa7111a_call(mxb, core, s_gpio, 0);
7708c2ecf20Sopenharmony_ci		saa7111a_call(mxb, video, s_std, std);
7718c2ecf20Sopenharmony_ci		if (mxb->cur_input == 0)
7728c2ecf20Sopenharmony_ci			tuner_call(mxb, video, s_std, std);
7738c2ecf20Sopenharmony_ci	} else {
7748c2ecf20Sopenharmony_ci		v4l2_std_id std = V4L2_STD_PAL_BG;
7758c2ecf20Sopenharmony_ci
7768c2ecf20Sopenharmony_ci		if (mxb->cur_input)
7778c2ecf20Sopenharmony_ci			std = standard->id;
7788c2ecf20Sopenharmony_ci		DEB_D("VIDIOC_S_STD: setting mxb for PAL/NTSC/SECAM\n");
7798c2ecf20Sopenharmony_ci		/* These two gpio calls set the GPIO pins that control the tda9820 */
7808c2ecf20Sopenharmony_ci		saa7146_write(dev, GPIO_CTRL, 0x00404050);
7818c2ecf20Sopenharmony_ci		saa7111a_call(mxb, core, s_gpio, 1);
7828c2ecf20Sopenharmony_ci		saa7111a_call(mxb, video, s_std, std);
7838c2ecf20Sopenharmony_ci		if (mxb->cur_input == 0)
7848c2ecf20Sopenharmony_ci			tuner_call(mxb, video, s_std, std);
7858c2ecf20Sopenharmony_ci	}
7868c2ecf20Sopenharmony_ci	return 0;
7878c2ecf20Sopenharmony_ci}
7888c2ecf20Sopenharmony_ci
7898c2ecf20Sopenharmony_cistatic struct saa7146_standard standard[] = {
7908c2ecf20Sopenharmony_ci	{
7918c2ecf20Sopenharmony_ci		.name	= "PAL-BG",	.id	= V4L2_STD_PAL_BG,
7928c2ecf20Sopenharmony_ci		.v_offset	= 0x17,	.v_field	= 288,
7938c2ecf20Sopenharmony_ci		.h_offset	= 0x14,	.h_pixels	= 680,
7948c2ecf20Sopenharmony_ci		.v_max_out	= 576,	.h_max_out	= 768,
7958c2ecf20Sopenharmony_ci	}, {
7968c2ecf20Sopenharmony_ci		.name	= "PAL-I",	.id	= V4L2_STD_PAL_I,
7978c2ecf20Sopenharmony_ci		.v_offset	= 0x17,	.v_field	= 288,
7988c2ecf20Sopenharmony_ci		.h_offset	= 0x14,	.h_pixels	= 680,
7998c2ecf20Sopenharmony_ci		.v_max_out	= 576,	.h_max_out	= 768,
8008c2ecf20Sopenharmony_ci	}, {
8018c2ecf20Sopenharmony_ci		.name	= "NTSC",	.id	= V4L2_STD_NTSC,
8028c2ecf20Sopenharmony_ci		.v_offset	= 0x16,	.v_field	= 240,
8038c2ecf20Sopenharmony_ci		.h_offset	= 0x06,	.h_pixels	= 708,
8048c2ecf20Sopenharmony_ci		.v_max_out	= 480,	.h_max_out	= 640,
8058c2ecf20Sopenharmony_ci	}, {
8068c2ecf20Sopenharmony_ci		.name	= "SECAM",	.id	= V4L2_STD_SECAM,
8078c2ecf20Sopenharmony_ci		.v_offset	= 0x14,	.v_field	= 288,
8088c2ecf20Sopenharmony_ci		.h_offset	= 0x14,	.h_pixels	= 720,
8098c2ecf20Sopenharmony_ci		.v_max_out	= 576,	.h_max_out	= 768,
8108c2ecf20Sopenharmony_ci	}
8118c2ecf20Sopenharmony_ci};
8128c2ecf20Sopenharmony_ci
8138c2ecf20Sopenharmony_cistatic struct saa7146_pci_extension_data mxb = {
8148c2ecf20Sopenharmony_ci	.ext_priv = "Multimedia eXtension Board",
8158c2ecf20Sopenharmony_ci	.ext = &extension,
8168c2ecf20Sopenharmony_ci};
8178c2ecf20Sopenharmony_ci
8188c2ecf20Sopenharmony_cistatic const struct pci_device_id pci_tbl[] = {
8198c2ecf20Sopenharmony_ci	{
8208c2ecf20Sopenharmony_ci		.vendor    = PCI_VENDOR_ID_PHILIPS,
8218c2ecf20Sopenharmony_ci		.device	   = PCI_DEVICE_ID_PHILIPS_SAA7146,
8228c2ecf20Sopenharmony_ci		.subvendor = 0x0000,
8238c2ecf20Sopenharmony_ci		.subdevice = 0x0000,
8248c2ecf20Sopenharmony_ci		.driver_data = (unsigned long)&mxb,
8258c2ecf20Sopenharmony_ci	}, {
8268c2ecf20Sopenharmony_ci		.vendor	= 0,
8278c2ecf20Sopenharmony_ci	}
8288c2ecf20Sopenharmony_ci};
8298c2ecf20Sopenharmony_ci
8308c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(pci, pci_tbl);
8318c2ecf20Sopenharmony_ci
8328c2ecf20Sopenharmony_cistatic struct saa7146_ext_vv vv_data = {
8338c2ecf20Sopenharmony_ci	.inputs		= MXB_INPUTS,
8348c2ecf20Sopenharmony_ci	.capabilities	= V4L2_CAP_TUNER | V4L2_CAP_VBI_CAPTURE | V4L2_CAP_AUDIO,
8358c2ecf20Sopenharmony_ci	.stds		= &standard[0],
8368c2ecf20Sopenharmony_ci	.num_stds	= ARRAY_SIZE(standard),
8378c2ecf20Sopenharmony_ci	.std_callback	= &std_callback,
8388c2ecf20Sopenharmony_ci};
8398c2ecf20Sopenharmony_ci
8408c2ecf20Sopenharmony_cistatic struct saa7146_extension extension = {
8418c2ecf20Sopenharmony_ci	.name		= "Multimedia eXtension Board",
8428c2ecf20Sopenharmony_ci	.flags		= SAA7146_USE_I2C_IRQ,
8438c2ecf20Sopenharmony_ci
8448c2ecf20Sopenharmony_ci	.pci_tbl	= &pci_tbl[0],
8458c2ecf20Sopenharmony_ci	.module		= THIS_MODULE,
8468c2ecf20Sopenharmony_ci
8478c2ecf20Sopenharmony_ci	.attach		= mxb_attach,
8488c2ecf20Sopenharmony_ci	.detach		= mxb_detach,
8498c2ecf20Sopenharmony_ci
8508c2ecf20Sopenharmony_ci	.irq_mask	= 0,
8518c2ecf20Sopenharmony_ci	.irq_func	= NULL,
8528c2ecf20Sopenharmony_ci};
8538c2ecf20Sopenharmony_ci
8548c2ecf20Sopenharmony_cistatic int __init mxb_init_module(void)
8558c2ecf20Sopenharmony_ci{
8568c2ecf20Sopenharmony_ci	if (saa7146_register_extension(&extension)) {
8578c2ecf20Sopenharmony_ci		DEB_S("failed to register extension\n");
8588c2ecf20Sopenharmony_ci		return -ENODEV;
8598c2ecf20Sopenharmony_ci	}
8608c2ecf20Sopenharmony_ci
8618c2ecf20Sopenharmony_ci	return 0;
8628c2ecf20Sopenharmony_ci}
8638c2ecf20Sopenharmony_ci
8648c2ecf20Sopenharmony_cistatic void __exit mxb_cleanup_module(void)
8658c2ecf20Sopenharmony_ci{
8668c2ecf20Sopenharmony_ci	saa7146_unregister_extension(&extension);
8678c2ecf20Sopenharmony_ci}
8688c2ecf20Sopenharmony_ci
8698c2ecf20Sopenharmony_cimodule_init(mxb_init_module);
8708c2ecf20Sopenharmony_cimodule_exit(mxb_cleanup_module);
8718c2ecf20Sopenharmony_ci
8728c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("video4linux-2 driver for the Siemens-Nixdorf 'Multimedia eXtension board'");
8738c2ecf20Sopenharmony_ciMODULE_AUTHOR("Michael Hunold <michael@mihu.de>");
8748c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL");
875