aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/zr36120_i2c.c
blob: 21fde43a6aed7fc26c4fb0a34125edcc6b14e8ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
    zr36120_i2c.c - Zoran 36120/36125 based framegrabbers

    Copyright (C) 1998-1999 Pauline Middelink <middelin@polyware.nl>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include <linux/types.h>
#include <linux/delay.h>
#include <asm/io.h>

#include <linux/video_decoder.h>
#include <asm/uaccess.h>

#include "tuner.h"
#include "zr36120.h"

/* ----------------------------------------------------------------------- */
/* I2C functions							   */
/* ----------------------------------------------------------------------- */

/* software I2C functions */

#define I2C_DELAY   10

static void i2c_setlines(struct i2c_bus *bus,int ctrl,int data)
{
	struct zoran *ztv = (struct zoran*)bus->data;
	unsigned int b = 0;
	if (data) b |= ztv->card->swapi2c ? ZORAN_I2C_SCL : ZORAN_I2C_SDA;
	if (ctrl) b |= ztv->card->swapi2c ? ZORAN_I2C_SDA : ZORAN_I2C_SCL;
	zrwrite(b, ZORAN_I2C);
	udelay(I2C_DELAY);
}

static int i2c_getdataline(struct i2c_bus *bus)
{
	struct zoran *ztv = (struct zoran*)bus->data;
	if (ztv->card->swapi2c)
		return zrread(ZORAN_I2C) & ZORAN_I2C_SCL;
	return zrread(ZORAN_I2C) & ZORAN_I2C_SDA;
}

static
void attach_inform(struct i2c_bus *bus, int id)
{
	struct zoran *ztv = (struct zoran*)bus->data;
	struct video_decoder_capability dc;
	int rv;

	switch (id) {
	 case I2C_DRIVERID_VIDEODECODER:
		DEBUG(printk(CARD_INFO "decoder attached\n",CARD));

		/* fetch the capabilities of the decoder */
		rv = i2c_control_device(&ztv->i2c, I2C_DRIVERID_VIDEODECODER, DECODER_GET_CAPABILITIES, &dc);
		if (rv) {
			DEBUG(printk(CARD_DEBUG "decoder is not V4L aware!\n",CARD));
			break;
		}
		DEBUG(printk(CARD_DEBUG "capabilities %d %d %d\n",CARD,dc.flags,dc.inputs,dc.outputs));

		/* Test if the decoder can de VBI transfers */
		if (dc.flags & 16 /*VIDEO_DECODER_VBI*/)
			ztv->have_decoder = 2;
		else
			ztv->have_decoder = 1;
		break;
	 case I2C_DRIVERID_TUNER:
		ztv->have_tuner = 1;
		DEBUG(printk(CARD_INFO "tuner attached\n",CARD));
		if (ztv->tuner_type >= 0)
		{
			if (i2c_control_device(&ztv->i2c,I2C_DRIVERID_TUNER,TUNER_SET_TYPE,&ztv->tuner_type)<0)
			DEBUG(printk(CARD_INFO "attach_inform; tuner won't be set to type %d\n",CARD,ztv->tuner_type));
		}
		break;
	 default:
		DEBUG(printk(CARD_INFO "attach_inform; unknown device id=%d\n",CARD,id));
		break;
	}
}

static
void detach_inform(struct i2c_bus *bus, int id)
{
	struct zoran *ztv = (struct zoran*)bus->data;

	switch (id) {
	 case I2C_DRIVERID_VIDEODECODER:
		ztv->have_decoder = 0;
		DEBUG(printk(CARD_INFO "decoder detached\n",CARD));
		break;
	 case I2C_DRIVERID_TUNER:
		ztv->have_tuner = 0;
		DEBUG(printk(CARD_INFO "tuner detached\n",CARD));
		break;
	 default:
		DEBUG(printk(CARD_INFO "detach_inform; unknown device id=%d\n",CARD,id));
		break;
	}
}

struct i2c_bus zoran_i2c_bus_template =
{
	"ZR36120",
	I2C_BUSID_ZORAN,
	NULL,

	SPIN_LOCK_UNLOCKED,

	attach_inform,
	detach_inform,

	i2c_setlines,
	i2c_getdataline,
	NULL,
	NULL
};