Commit | Line | Data |
---|---|---|
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> | |
43 | #include <linux/sched.h> | |
44 | #include <linux/mm.h> | |
45 | #include <linux/init.h> | |
46 | #include <linux/i2c.h> | |
47 | #include <linux/videotext.h> | |
48 | #include <linux/videodev.h> | |
49 | #include "saa5246a.h" | |
50 | ||
51 | MODULE_AUTHOR("Michael Geng <linux@MichaelGeng.de>"); | |
52 | MODULE_DESCRIPTION("Philips SAA5246A, SAA5281 Teletext decoder driver"); | |
53 | MODULE_LICENSE("GPL"); | |
54 | ||
55 | struct saa5246a_device | |
56 | { | |
57 | u8 pgbuf[NUM_DAUS][VTX_VIRTUALSIZE]; | |
58 | int is_searching[NUM_DAUS]; | |
59 | struct i2c_client *client; | |
60 | struct semaphore lock; | |
61 | }; | |
62 | ||
63 | static struct video_device saa_template; /* Declared near bottom */ | |
64 | ||
65 | /* Addresses to scan */ | |
66 | static unsigned short normal_i2c[] = { I2C_ADDRESS, I2C_CLIENT_END }; | |
1da177e4 LT |
67 | I2C_CLIENT_INSMOD; |
68 | ||
69 | static struct i2c_client client_template; | |
70 | ||
71 | static int saa5246a_attach(struct i2c_adapter *adap, int addr, int kind) | |
72 | { | |
73 | int pgbuf; | |
74 | int err; | |
75 | struct i2c_client *client; | |
76 | struct video_device *vd; | |
77 | struct saa5246a_device *t; | |
78 | ||
79 | printk(KERN_INFO "saa5246a: teletext chip found.\n"); | |
80 | client=kmalloc(sizeof(*client), GFP_KERNEL); | |
81 | if(client==NULL) | |
82 | return -ENOMEM; | |
83 | client_template.adapter = adap; | |
84 | client_template.addr = addr; | |
85 | memcpy(client, &client_template, sizeof(*client)); | |
86 | t = kmalloc(sizeof(*t), GFP_KERNEL); | |
87 | if(t==NULL) | |
88 | { | |
89 | kfree(client); | |
90 | return -ENOMEM; | |
91 | } | |
92 | memset(t, 0, sizeof(*t)); | |
93 | strlcpy(client->name, IF_NAME, I2C_NAME_SIZE); | |
94 | init_MUTEX(&t->lock); | |
95 | ||
96 | /* | |
97 | * Now create a video4linux device | |
98 | */ | |
99 | ||
100 | vd = video_device_alloc(); | |
101 | if(vd==NULL) | |
102 | { | |
103 | kfree(t); | |
104 | kfree(client); | |
105 | return -ENOMEM; | |
106 | } | |
107 | i2c_set_clientdata(client, vd); | |
108 | memcpy(vd, &saa_template, sizeof(*vd)); | |
109 | ||
110 | for (pgbuf = 0; pgbuf < NUM_DAUS; pgbuf++) | |
111 | { | |
112 | memset(t->pgbuf[pgbuf], ' ', sizeof(t->pgbuf[0])); | |
113 | t->is_searching[pgbuf] = FALSE; | |
114 | } | |
115 | vd->priv=t; | |
116 | ||
117 | ||
118 | /* | |
119 | * Register it | |
120 | */ | |
121 | ||
122 | if((err=video_register_device(vd, VFL_TYPE_VTX,-1))<0) | |
123 | { | |
124 | kfree(t); | |
125 | kfree(client); | |
126 | video_device_release(vd); | |
127 | return err; | |
128 | } | |
129 | t->client = client; | |
130 | i2c_attach_client(client); | |
131 | return 0; | |
132 | } | |
133 | ||
134 | /* | |
135 | * We do most of the hard work when we become a device on the i2c. | |
136 | */ | |
137 | static int saa5246a_probe(struct i2c_adapter *adap) | |
138 | { | |
139 | if (adap->class & I2C_CLASS_TV_ANALOG) | |
140 | return i2c_probe(adap, &addr_data, saa5246a_attach); | |
141 | return 0; | |
142 | } | |
143 | ||
144 | static int saa5246a_detach(struct i2c_client *client) | |
145 | { | |
146 | struct video_device *vd = i2c_get_clientdata(client); | |
147 | i2c_detach_client(client); | |
148 | video_unregister_device(vd); | |
149 | kfree(vd->priv); | |
150 | kfree(client); | |
151 | return 0; | |
152 | } | |
153 | ||
154 | static int saa5246a_command(struct i2c_client *device, unsigned int cmd, | |
155 | void *arg) | |
156 | { | |
157 | return -EINVAL; | |
158 | } | |
159 | ||
160 | /* | |
161 | * I2C interfaces | |
162 | */ | |
163 | ||
164 | static struct i2c_driver i2c_driver_videotext = | |
165 | { | |
604f28e2 LR |
166 | .driver = { |
167 | .owner = THIS_MODULE, | |
168 | .name = IF_NAME, /* name */ | |
169 | }, | |
1da177e4 | 170 | .id = I2C_DRIVERID_SAA5249, /* in i2c.h */ |
1da177e4 LT |
171 | .attach_adapter = saa5246a_probe, |
172 | .detach_client = saa5246a_detach, | |
173 | .command = saa5246a_command | |
174 | }; | |
175 | ||
176 | static struct i2c_client client_template = { | |
177 | .driver = &i2c_driver_videotext, | |
178 | .name = "(unset)", | |
179 | }; | |
180 | ||
181 | static int i2c_sendbuf(struct saa5246a_device *t, int reg, int count, u8 *data) | |
182 | { | |
183 | char buf[64]; | |
184 | ||
185 | buf[0] = reg; | |
186 | memcpy(buf+1, data, count); | |
187 | ||
188 | if(i2c_master_send(t->client, buf, count+1)==count+1) | |
189 | return 0; | |
190 | return -1; | |
191 | } | |
192 | ||
193 | static int i2c_senddata(struct saa5246a_device *t, ...) | |
194 | { | |
195 | unsigned char buf[64]; | |
196 | int v; | |
197 | int ct=0; | |
198 | va_list argp; | |
199 | va_start(argp,t); | |
200 | ||
201 | while((v=va_arg(argp,int))!=-1) | |
202 | buf[ct++]=v; | |
203 | return i2c_sendbuf(t, buf[0], ct-1, buf+1); | |
204 | } | |
205 |