]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/media/video/saa5246a.c
[PATCH] remove many unneeded #includes of sched.h
[net-next-2.6.git] / drivers / media / video / saa5246a.c
CommitLineData
1da177e4
LT
1/*
2 * Driver for the SAA5246A or SAA5281 Teletext (=Videotext) decoder chips from
3 * Philips.
4 *
5 * Only capturing of Teletext pages is tested. The videotext chips also have a
6 * TV output but my hardware doesn't use it. For this reason this driver does
7 * not support changing any TV display settings.
8 *
9 * Copyright (C) 2004 Michael Geng <linux@MichaelGeng.de>
10 *
11 * Derived from
12 *
13 * saa5249 driver
14 * Copyright (C) 1998 Richard Guenther
15 * <richard.guenther@student.uni-tuebingen.de>
16 *
17 * with changes by
18 * Alan Cox <Alan.Cox@linux.org>
19 *
20 * and
21 *
22 * vtx.c
23 * Copyright (C) 1994-97 Martin Buck <martin-2.buck@student.uni-ulm.de>
24 *
25 * This program is free software; you can redistribute it and/or modify
26 * it under the terms of the GNU General Public License as published by
27 * the Free Software Foundation; either version 2 of the License, or
28 * (at your option) any later version.
29 *
30 * This program is distributed in the hope that it will be useful,
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 * GNU General Public License for more details.
34 *
35 * You should have received a copy of the GNU General Public License
36 * along with this program; if not, write to the Free Software
37 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
38 * USA.
39 */
40
41#include <linux/module.h>
42#include <linux/kernel.h>
1da177e4
LT
43#include <linux/mm.h>
44#include <linux/init.h>
45#include <linux/i2c.h>
46#include <linux/videotext.h>
47#include <linux/videodev.h>
5e87efa3 48#include <media/v4l2-common.h>
3593cab5
IM
49#include <linux/mutex.h>
50
1da177e4
LT
51#include "saa5246a.h"
52
53MODULE_AUTHOR("Michael Geng <linux@MichaelGeng.de>");
54MODULE_DESCRIPTION("Philips SAA5246A, SAA5281 Teletext decoder driver");
55MODULE_LICENSE("GPL");
56
57struct saa5246a_device
58{
59 u8 pgbuf[NUM_DAUS][VTX_VIRTUALSIZE];
60 int is_searching[NUM_DAUS];
61 struct i2c_client *client;
3593cab5 62 struct mutex lock;
1da177e4
LT
63};
64
65static struct video_device saa_template; /* Declared near bottom */
66
67/* Addresses to scan */
68static unsigned short normal_i2c[] = { I2C_ADDRESS, I2C_CLIENT_END };
1da177e4
LT
69I2C_CLIENT_INSMOD;
70
71static struct i2c_client client_template;
72
73static int saa5246a_attach(struct i2c_adapter *adap, int addr, int kind)
74{
75 int pgbuf;
76 int err;
77 struct i2c_client *client;
78 struct video_device *vd;
79 struct saa5246a_device *t;
80
81 printk(KERN_INFO "saa5246a: teletext chip found.\n");
82 client=kmalloc(sizeof(*client), GFP_KERNEL);
83 if(client==NULL)
84 return -ENOMEM;
85 client_template.adapter = adap;
86 client_template.addr = addr;
87 memcpy(client, &client_template, sizeof(*client));
7408187d 88 t = kzalloc(sizeof(*t), GFP_KERNEL);
1da177e4
LT
89 if(t==NULL)
90 {
91 kfree(client);
92 return -ENOMEM;
93 }
1da177e4 94 strlcpy(client->name, IF_NAME, I2C_NAME_SIZE);
3593cab5 95 mutex_init(&t->lock);
1da177e4
LT
96
97 /*
98 * Now create a video4linux device
99 */
100
101 vd = video_device_alloc();
102 if(vd==NULL)
103 {
104 kfree(t);
105 kfree(client);
106 return -ENOMEM;
107 }
108 i2c_set_clientdata(client, vd);
109 memcpy(vd, &saa_template, sizeof(*vd));
110
111 for (pgbuf = 0; pgbuf < NUM_DAUS; pgbuf++)
112 {
113 memset(t->pgbuf[pgbuf], ' ', sizeof(t->pgbuf[0]));
114 t->is_searching[pgbuf] = FALSE;
115 }
116 vd->priv=t;
117
118
119 /*
120 * Register it
121 */
122
123 if((err=video_register_device(vd, VFL_TYPE_VTX,-1))<0)
124 {
125 kfree(t);
126 kfree(client);
127 video_device_release(vd);
128 return err;
129 }
130 t->client = client;
131 i2c_attach_client(client);
132 return 0;
133}
134
135/*
136 * We do most of the hard work when we become a device on the i2c.
137 */
138static int saa5246a_probe(struct i2c_adapter *adap)
139{
140 if (adap->class & I2C_CLASS_TV_ANALOG)
141 return i2c_probe(adap, &addr_data, saa5246a_attach);
142 return 0;
143}
144
145static int saa5246a_detach(struct i2c_client *client)
146{
147 struct video_device *vd = i2c_get_clientdata(client);
148 i2c_detach_client(client);
149 video_unregister_device(vd);
150 kfree(vd->priv);
151 kfree(client);
152 return 0;
153}
154
1da177e4
LT
155/*
156 * I2C interfaces
157 */
158
159static struct i2c_driver i2c_driver_videotext =
160{
604f28e2 161 .driver = {
604f28e2
LR
162 .name = IF_NAME, /* name */
163 },
1da177e4 164 .id = I2C_DRIVERID_SAA5249, /* in i2c.h */
1da177e4
LT
165 .attach_adapter = saa5246a_probe,
166 .detach_client = saa5246a_detach,
1da177e4
LT
167};
168
169static struct i2c_client client_template = {
170 .driver = &i2c_driver_videotext,
171 .name = "(unset)",
172};
173
174static int i2c_sendbuf(struct saa5246a_device *t, int reg, int count, u8 *data)
175{
176 char buf[64];
177
178 buf[0] = reg;
179 memcpy(buf+1, data, count);
180
181 if(i2c_master_send(t->client, buf, count+1)==count+1)
182 return 0;
183 return -1;
184}
185
186static int i2c_senddata(struct saa5246a_device *t, ...)
187{
188 unsigned char buf[64];
189 int v;
190 int ct=0;
191 va_list argp;
192 va_start(argp,t);
193
194 while((v=va_arg(argp,int))!=-1)
195 buf[ct++]=v;
196 return i2c_sendbuf(t, buf[0], ct-1, buf+1);
197}
198
199