add dependency of CONFIG_SGI_XP upon CONFIG_NET
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / media / video / saa5246a.c
blob6ee63e69b36c4d7106fd0b2bcafb0433df47d64b
1 /*
2 * Driver for the SAA5246A or SAA5281 Teletext (=Videotext) decoder chips from
3 * Philips.
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.
9 * Copyright (C) 2004 Michael Geng <linux@MichaelGeng.de>
11 * Derived from
13 * saa5249 driver
14 * Copyright (C) 1998 Richard Guenther
15 * <richard.guenther@student.uni-tuebingen.de>
17 * with changes by
18 * Alan Cox <Alan.Cox@linux.org>
20 * and
22 * vtx.c
23 * Copyright (C) 1994-97 Martin Buck <martin-2.buck@student.uni-ulm.de>
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.
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.
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.
41 #include <linux/module.h>
42 #include <linux/kernel.h>
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>
48 #include <media/v4l2-common.h>
49 #include <media/v4l2-ioctl.h>
50 #include <linux/mutex.h>
52 #include "saa5246a.h"
54 MODULE_AUTHOR("Michael Geng <linux@MichaelGeng.de>");
55 MODULE_DESCRIPTION("Philips SAA5246A, SAA5281 Teletext decoder driver");
56 MODULE_LICENSE("GPL");
58 struct saa5246a_device
60 u8 pgbuf[NUM_DAUS][VTX_VIRTUALSIZE];
61 int is_searching[NUM_DAUS];
62 struct i2c_client *client;
63 struct mutex lock;
66 static struct video_device saa_template; /* Declared near bottom */
68 /* Addresses to scan */
69 static unsigned short normal_i2c[] = { I2C_ADDRESS, I2C_CLIENT_END };
71 I2C_CLIENT_INSMOD;
73 static struct i2c_client client_template;
75 static int saa5246a_attach(struct i2c_adapter *adap, int addr, int kind)
77 int pgbuf;
78 int err;
79 struct i2c_client *client;
80 struct video_device *vd;
81 struct saa5246a_device *t;
83 printk(KERN_INFO "saa5246a: teletext chip found.\n");
84 client=kmalloc(sizeof(*client), GFP_KERNEL);
85 if(client==NULL)
86 return -ENOMEM;
87 client_template.adapter = adap;
88 client_template.addr = addr;
89 memcpy(client, &client_template, sizeof(*client));
90 t = kzalloc(sizeof(*t), GFP_KERNEL);
91 if(t==NULL)
93 kfree(client);
94 return -ENOMEM;
96 strlcpy(client->name, IF_NAME, I2C_NAME_SIZE);
97 mutex_init(&t->lock);
100 * Now create a video4linux device
103 vd = video_device_alloc();
104 if(vd==NULL)
106 kfree(t);
107 kfree(client);
108 return -ENOMEM;
110 i2c_set_clientdata(client, vd);
111 memcpy(vd, &saa_template, sizeof(*vd));
113 for (pgbuf = 0; pgbuf < NUM_DAUS; pgbuf++)
115 memset(t->pgbuf[pgbuf], ' ', sizeof(t->pgbuf[0]));
116 t->is_searching[pgbuf] = false;
118 vd->priv=t;
122 * Register it
125 if((err=video_register_device(vd, VFL_TYPE_VTX,-1))<0)
127 kfree(t);
128 kfree(client);
129 video_device_release(vd);
130 return err;
132 t->client = client;
133 i2c_attach_client(client);
134 return 0;
138 * We do most of the hard work when we become a device on the i2c.
140 static int saa5246a_probe(struct i2c_adapter *adap)
142 if (adap->class & I2C_CLASS_TV_ANALOG)
143 return i2c_probe(adap, &addr_data, saa5246a_attach);
144 return 0;
147 static int saa5246a_detach(struct i2c_client *client)
149 struct video_device *vd = i2c_get_clientdata(client);
150 i2c_detach_client(client);
151 video_unregister_device(vd);
152 kfree(vd->priv);
153 kfree(client);
154 return 0;
158 * I2C interfaces
161 static struct i2c_driver i2c_driver_videotext =
163 .driver = {
164 .name = IF_NAME, /* name */
166 .id = I2C_DRIVERID_SAA5249, /* in i2c.h */
167 .attach_adapter = saa5246a_probe,
168 .detach_client = saa5246a_detach,
171 static struct i2c_client client_template = {
172 .driver = &i2c_driver_videotext,
173 .name = "(unset)",
176 static int i2c_sendbuf(struct saa5246a_device *t, int reg, int count, u8 *data)
178 char buf[64];
180 buf[0] = reg;
181 memcpy(buf+1, data, count);
183 if(i2c_master_send(t->client, buf, count+1)==count+1)
184 return 0;
185 return -1;
188 static int i2c_senddata(struct saa5246a_device *t, ...)
190 unsigned char buf[64];
191 int v;
192 int ct = 0;
193 va_list argp;
194 va_start(argp, t);
196 while ((v = va_arg(argp, int)) != -1)
197 buf[ct++] = v;
199 va_end(argp);
200 return i2c_sendbuf(t, buf[0], ct-1, buf+1);
203 /* Get count number of bytes from I²C-device at address adr, store them in buf.
204 * Start & stop handshaking is done by this routine, ack will be sent after the
205 * last byte to inhibit further sending of data. If uaccess is 'true', data is
206 * written to user-space with put_user. Returns -1 if I²C-device didn't send
207 * acknowledge, 0 otherwise
209 static int i2c_getdata(struct saa5246a_device *t, int count, u8 *buf)
211 if(i2c_master_recv(t->client, buf, count)!=count)
212 return -1;
213 return 0;
216 /* When a page is found then the not FOUND bit in one of the status registers
217 * of the SAA5264A chip is cleared. Unfortunately this bit is not set
218 * automatically when a new page is requested. Instead this function must be
219 * called after a page has been requested.
221 * Return value: 0 if successful
223 static int saa5246a_clear_found_bit(struct saa5246a_device *t,
224 unsigned char dau_no)
226 unsigned char row_25_column_8;
228 if (i2c_senddata(t, SAA5246A_REGISTER_R8,
230 dau_no |
231 R8_DO_NOT_CLEAR_MEMORY,
233 R9_CURSER_ROW_25,
235 R10_CURSER_COLUMN_8,
237 COMMAND_END) ||
238 i2c_getdata(t, 1, &row_25_column_8))
240 return -EIO;
242 row_25_column_8 |= ROW25_COLUMN8_PAGE_NOT_FOUND;
243 if (i2c_senddata(t, SAA5246A_REGISTER_R8,
245 dau_no |
246 R8_DO_NOT_CLEAR_MEMORY,
248 R9_CURSER_ROW_25,
250 R10_CURSER_COLUMN_8,
252 row_25_column_8,
254 COMMAND_END))
256 return -EIO;
259 return 0;
262 /* Requests one videotext page as described in req. The fields of req are
263 * checked and an error is returned if something is invalid.
265 * Return value: 0 if successful
267 static int saa5246a_request_page(struct saa5246a_device *t,
268 vtx_pagereq_t *req)
270 if (req->pagemask < 0 || req->pagemask >= PGMASK_MAX)
271 return -EINVAL;
272 if (req->pagemask & PGMASK_PAGE)
273 if (req->page < 0 || req->page > PAGE_MAX)
274 return -EINVAL;
275 if (req->pagemask & PGMASK_HOUR)
276 if (req->hour < 0 || req->hour > HOUR_MAX)
277 return -EINVAL;
278 if (req->pagemask & PGMASK_MINUTE)
279 if (req->minute < 0 || req->minute > MINUTE_MAX)
280 return -EINVAL;
281 if (req->pgbuf < 0 || req->pgbuf >= NUM_DAUS)
282 return -EINVAL;
284 if (i2c_senddata(t, SAA5246A_REGISTER_R2,
286 R2_IN_R3_SELECT_PAGE_HUNDREDS |
287 req->pgbuf << 4 |
288 R2_BANK_0 |
289 R2_HAMMING_CHECK_OFF,
291 HUNDREDS_OF_PAGE(req->page) |
292 R3_HOLD_PAGE |
293 (req->pagemask & PG_HUND ?
294 R3_PAGE_HUNDREDS_DO_CARE :
295 R3_PAGE_HUNDREDS_DO_NOT_CARE),
297 TENS_OF_PAGE(req->page) |
298 (req->pagemask & PG_TEN ?
299 R3_PAGE_TENS_DO_CARE :
300 R3_PAGE_TENS_DO_NOT_CARE),
302 UNITS_OF_PAGE(req->page) |
303 (req->pagemask & PG_UNIT ?
304 R3_PAGE_UNITS_DO_CARE :
305 R3_PAGE_UNITS_DO_NOT_CARE),
307 TENS_OF_HOUR(req->hour) |
308 (req->pagemask & HR_TEN ?
309 R3_HOURS_TENS_DO_CARE :
310 R3_HOURS_TENS_DO_NOT_CARE),
312 UNITS_OF_HOUR(req->hour) |
313 (req->pagemask & HR_UNIT ?
314 R3_HOURS_UNITS_DO_CARE :
315 R3_HOURS_UNITS_DO_NOT_CARE),
317 TENS_OF_MINUTE(req->minute) |
318 (req->pagemask & MIN_TEN ?
319 R3_MINUTES_TENS_DO_CARE :
320 R3_MINUTES_TENS_DO_NOT_CARE),
322 UNITS_OF_MINUTE(req->minute) |
323 (req->pagemask & MIN_UNIT ?
324 R3_MINUTES_UNITS_DO_CARE :
325 R3_MINUTES_UNITS_DO_NOT_CARE),
327 COMMAND_END) || i2c_senddata(t, SAA5246A_REGISTER_R2,
329 R2_IN_R3_SELECT_PAGE_HUNDREDS |
330 req->pgbuf << 4 |
331 R2_BANK_0 |
332 R2_HAMMING_CHECK_OFF,
334 HUNDREDS_OF_PAGE(req->page) |
335 R3_UPDATE_PAGE |
336 (req->pagemask & PG_HUND ?
337 R3_PAGE_HUNDREDS_DO_CARE :
338 R3_PAGE_HUNDREDS_DO_NOT_CARE),
340 COMMAND_END))
342 return -EIO;
345 t->is_searching[req->pgbuf] = true;
346 return 0;
349 /* This routine decodes the page number from the infobits contained in line 25.
351 * Parameters:
352 * infobits: must be bits 0 to 9 of column 25
354 * Return value: page number coded in hexadecimal, i. e. page 123 is coded 0x123
356 static inline int saa5246a_extract_pagenum_from_infobits(
357 unsigned char infobits[10])
359 int page_hundreds, page_tens, page_units;
361 page_units = infobits[0] & ROW25_COLUMN0_PAGE_UNITS;
362 page_tens = infobits[1] & ROW25_COLUMN1_PAGE_TENS;
363 page_hundreds = infobits[8] & ROW25_COLUMN8_PAGE_HUNDREDS;
365 /* page 0x.. means page 8.. */
366 if (page_hundreds == 0)
367 page_hundreds = 8;
369 return((page_hundreds << 8) | (page_tens << 4) | page_units);
372 /* Decodes the hour from the infobits contained in line 25.
374 * Parameters:
375 * infobits: must be bits 0 to 9 of column 25
377 * Return: hour coded in hexadecimal, i. e. 12h is coded 0x12
379 static inline int saa5246a_extract_hour_from_infobits(
380 unsigned char infobits[10])
382 int hour_tens, hour_units;
384 hour_units = infobits[4] & ROW25_COLUMN4_HOUR_UNITS;
385 hour_tens = infobits[5] & ROW25_COLUMN5_HOUR_TENS;
387 return((hour_tens << 4) | hour_units);
390 /* Decodes the minutes from the infobits contained in line 25.
392 * Parameters:
393 * infobits: must be bits 0 to 9 of column 25
395 * Return: minutes coded in hexadecimal, i. e. 10min is coded 0x10
397 static inline int saa5246a_extract_minutes_from_infobits(
398 unsigned char infobits[10])
400 int minutes_tens, minutes_units;
402 minutes_units = infobits[2] & ROW25_COLUMN2_MINUTES_UNITS;
403 minutes_tens = infobits[3] & ROW25_COLUMN3_MINUTES_TENS;
405 return((minutes_tens << 4) | minutes_units);
408 /* Reads the status bits contained in the first 10 columns of the first line
409 * and extracts the information into info.
411 * Return value: 0 if successful
413 static inline int saa5246a_get_status(struct saa5246a_device *t,
414 vtx_pageinfo_t *info, unsigned char dau_no)
416 unsigned char infobits[10];
417 int column;
419 if (dau_no >= NUM_DAUS)
420 return -EINVAL;
422 if (i2c_senddata(t, SAA5246A_REGISTER_R8,
424 dau_no |
425 R8_DO_NOT_CLEAR_MEMORY,
427 R9_CURSER_ROW_25,
429 R10_CURSER_COLUMN_0,
431 COMMAND_END) ||
432 i2c_getdata(t, 10, infobits))
434 return -EIO;
437 info->pagenum = saa5246a_extract_pagenum_from_infobits(infobits);
438 info->hour = saa5246a_extract_hour_from_infobits(infobits);
439 info->minute = saa5246a_extract_minutes_from_infobits(infobits);
440 info->charset = ((infobits[7] & ROW25_COLUMN7_CHARACTER_SET) >> 1);
441 info->delete = !!(infobits[3] & ROW25_COLUMN3_DELETE_PAGE);
442 info->headline = !!(infobits[5] & ROW25_COLUMN5_INSERT_HEADLINE);
443 info->subtitle = !!(infobits[5] & ROW25_COLUMN5_INSERT_SUBTITLE);
444 info->supp_header = !!(infobits[6] & ROW25_COLUMN6_SUPPRESS_HEADER);
445 info->update = !!(infobits[6] & ROW25_COLUMN6_UPDATE_PAGE);
446 info->inter_seq = !!(infobits[6] & ROW25_COLUMN6_INTERRUPTED_SEQUENCE);
447 info->dis_disp = !!(infobits[6] & ROW25_COLUMN6_SUPPRESS_DISPLAY);
448 info->serial = !!(infobits[7] & ROW25_COLUMN7_SERIAL_MODE);
449 info->notfound = !!(infobits[8] & ROW25_COLUMN8_PAGE_NOT_FOUND);
450 info->pblf = !!(infobits[9] & ROW25_COLUMN9_PAGE_BEING_LOOKED_FOR);
451 info->hamming = 0;
452 for (column = 0; column <= 7; column++) {
453 if (infobits[column] & ROW25_COLUMN0_TO_7_HAMMING_ERROR) {
454 info->hamming = 1;
455 break;
458 if (!info->hamming && !info->notfound)
459 t->is_searching[dau_no] = false;
460 return 0;
463 /* Reads 1 videotext page buffer of the SAA5246A.
465 * req is used both as input and as output. It contains information which part
466 * must be read. The videotext page is copied into req->buffer.
468 * Return value: 0 if successful
470 static inline int saa5246a_get_page(struct saa5246a_device *t,
471 vtx_pagereq_t *req)
473 int start, end, size;
474 char *buf;
475 int err;
477 if (req->pgbuf < 0 || req->pgbuf >= NUM_DAUS ||
478 req->start < 0 || req->start > req->end || req->end >= VTX_PAGESIZE)
479 return -EINVAL;
481 buf = kmalloc(VTX_PAGESIZE, GFP_KERNEL);
482 if (!buf)
483 return -ENOMEM;
485 /* Read "normal" part of page */
486 err = -EIO;
488 end = min(req->end, VTX_PAGESIZE - 1);
489 if (i2c_senddata(t, SAA5246A_REGISTER_R8,
490 req->pgbuf | R8_DO_NOT_CLEAR_MEMORY,
491 ROW(req->start), COLUMN(req->start), COMMAND_END))
492 goto out;
493 if (i2c_getdata(t, end - req->start + 1, buf))
494 goto out;
495 err = -EFAULT;
496 if (copy_to_user(req->buffer, buf, end - req->start + 1))
497 goto out;
499 /* Always get the time from buffer 4, since this stupid SAA5246A only
500 * updates the currently displayed buffer...
502 if (REQ_CONTAINS_TIME(req)) {
503 start = max(req->start, POS_TIME_START);
504 end = min(req->end, POS_TIME_END);
505 size = end - start + 1;
506 err = -EINVAL;
507 if (size < 0)
508 goto out;
509 err = -EIO;
510 if (i2c_senddata(t, SAA5246A_REGISTER_R8,
511 R8_ACTIVE_CHAPTER_4 | R8_DO_NOT_CLEAR_MEMORY,
512 R9_CURSER_ROW_0, start, COMMAND_END))
513 goto out;
514 if (i2c_getdata(t, size, buf))
515 goto out;
516 err = -EFAULT;
517 if (copy_to_user(req->buffer + start - req->start, buf, size))
518 goto out;
520 /* Insert the header from buffer 4 only, if acquisition circuit is still searching for a page */
521 if (REQ_CONTAINS_HEADER(req) && t->is_searching[req->pgbuf]) {
522 start = max(req->start, POS_HEADER_START);
523 end = min(req->end, POS_HEADER_END);
524 size = end - start + 1;
525 err = -EINVAL;
526 if (size < 0)
527 goto out;
528 err = -EIO;
529 if (i2c_senddata(t, SAA5246A_REGISTER_R8,
530 R8_ACTIVE_CHAPTER_4 | R8_DO_NOT_CLEAR_MEMORY,
531 R9_CURSER_ROW_0, start, COMMAND_END))
532 goto out;
533 if (i2c_getdata(t, end - start + 1, buf))
534 goto out;
535 err = -EFAULT;
536 if (copy_to_user(req->buffer + start - req->start, buf, size))
537 goto out;
539 err = 0;
540 out:
541 kfree(buf);
542 return err;
545 /* Stops the acquisition circuit given in dau_no. The page buffer associated
546 * with this acquisition circuit will no more be updated. The other daus are
547 * not affected.
549 * Return value: 0 if successful
551 static inline int saa5246a_stop_dau(struct saa5246a_device *t,
552 unsigned char dau_no)
554 if (dau_no >= NUM_DAUS)
555 return -EINVAL;
556 if (i2c_senddata(t, SAA5246A_REGISTER_R2,
558 R2_IN_R3_SELECT_PAGE_HUNDREDS |
559 dau_no << 4 |
560 R2_BANK_0 |
561 R2_HAMMING_CHECK_OFF,
563 R3_PAGE_HUNDREDS_0 |
564 R3_HOLD_PAGE |
565 R3_PAGE_HUNDREDS_DO_NOT_CARE,
567 COMMAND_END))
569 return -EIO;
571 t->is_searching[dau_no] = false;
572 return 0;
575 /* Handles ioctls defined in videotext.h
577 * Returns 0 if successful
579 static int do_saa5246a_ioctl(struct inode *inode, struct file *file,
580 unsigned int cmd, void *arg)
582 struct video_device *vd = video_devdata(file);
583 struct saa5246a_device *t=vd->priv;
584 switch(cmd)
586 case VTXIOCGETINFO:
588 vtx_info_t *info = arg;
590 info->version_major = MAJOR_VERSION;
591 info->version_minor = MINOR_VERSION;
592 info->numpages = NUM_DAUS;
593 return 0;
596 case VTXIOCCLRPAGE:
598 vtx_pagereq_t *req = arg;
600 if (req->pgbuf < 0 || req->pgbuf >= NUM_DAUS)
601 return -EINVAL;
602 memset(t->pgbuf[req->pgbuf], ' ', sizeof(t->pgbuf[0]));
603 return 0;
606 case VTXIOCCLRFOUND:
608 vtx_pagereq_t *req = arg;
610 if (req->pgbuf < 0 || req->pgbuf >= NUM_DAUS)
611 return -EINVAL;
612 return(saa5246a_clear_found_bit(t, req->pgbuf));
615 case VTXIOCPAGEREQ:
617 vtx_pagereq_t *req = arg;
619 return(saa5246a_request_page(t, req));
622 case VTXIOCGETSTAT:
624 vtx_pagereq_t *req = arg;
625 vtx_pageinfo_t info;
626 int rval;
628 if ((rval = saa5246a_get_status(t, &info, req->pgbuf)))
629 return rval;
630 if(copy_to_user(req->buffer, &info,
631 sizeof(vtx_pageinfo_t)))
632 return -EFAULT;
633 return 0;
636 case VTXIOCGETPAGE:
638 vtx_pagereq_t *req = arg;
640 return(saa5246a_get_page(t, req));
643 case VTXIOCSTOPDAU:
645 vtx_pagereq_t *req = arg;
647 return(saa5246a_stop_dau(t, req->pgbuf));
650 case VTXIOCPUTPAGE:
651 case VTXIOCSETDISP:
652 case VTXIOCPUTSTAT:
653 return 0;
655 case VTXIOCCLRCACHE:
657 return 0;
660 case VTXIOCSETVIRT:
662 /* I do not know what "virtual mode" means */
663 return 0;
666 return -EINVAL;
670 * Translates old vtx IOCTLs to new ones
672 * This keeps new kernel versions compatible with old userspace programs.
674 static inline unsigned int vtx_fix_command(unsigned int cmd)
676 switch (cmd) {
677 case VTXIOCGETINFO_OLD:
678 cmd = VTXIOCGETINFO;
679 break;
680 case VTXIOCCLRPAGE_OLD:
681 cmd = VTXIOCCLRPAGE;
682 break;
683 case VTXIOCCLRFOUND_OLD:
684 cmd = VTXIOCCLRFOUND;
685 break;
686 case VTXIOCPAGEREQ_OLD:
687 cmd = VTXIOCPAGEREQ;
688 break;
689 case VTXIOCGETSTAT_OLD:
690 cmd = VTXIOCGETSTAT;
691 break;
692 case VTXIOCGETPAGE_OLD:
693 cmd = VTXIOCGETPAGE;
694 break;
695 case VTXIOCSTOPDAU_OLD:
696 cmd = VTXIOCSTOPDAU;
697 break;
698 case VTXIOCPUTPAGE_OLD:
699 cmd = VTXIOCPUTPAGE;
700 break;
701 case VTXIOCSETDISP_OLD:
702 cmd = VTXIOCSETDISP;
703 break;
704 case VTXIOCPUTSTAT_OLD:
705 cmd = VTXIOCPUTSTAT;
706 break;
707 case VTXIOCCLRCACHE_OLD:
708 cmd = VTXIOCCLRCACHE;
709 break;
710 case VTXIOCSETVIRT_OLD:
711 cmd = VTXIOCSETVIRT;
712 break;
714 return cmd;
718 * Handle the locking
720 static int saa5246a_ioctl(struct inode *inode, struct file *file,
721 unsigned int cmd, unsigned long arg)
723 struct video_device *vd = video_devdata(file);
724 struct saa5246a_device *t = vd->priv;
725 int err;
727 cmd = vtx_fix_command(cmd);
728 mutex_lock(&t->lock);
729 err = video_usercopy(inode, file, cmd, arg, do_saa5246a_ioctl);
730 mutex_unlock(&t->lock);
731 return err;
734 static int saa5246a_open(struct inode *inode, struct file *file)
736 struct video_device *vd = video_devdata(file);
737 struct saa5246a_device *t = vd->priv;
738 int err;
740 err = video_exclusive_open(inode,file);
741 if (err < 0)
742 return err;
744 if (t->client==NULL) {
745 err = -ENODEV;
746 goto fail;
749 if (i2c_senddata(t, SAA5246A_REGISTER_R0,
751 R0_SELECT_R11 |
752 R0_PLL_TIME_CONSTANT_LONG |
753 R0_ENABLE_nODD_EVEN_OUTPUT |
754 R0_ENABLE_HDR_POLL |
755 R0_DO_NOT_FORCE_nODD_EVEN_LOW_IF_PICTURE_DISPLAYED |
756 R0_NO_FREE_RUN_PLL |
757 R0_NO_AUTOMATIC_FASTEXT_PROMPT,
759 R1_NON_INTERLACED_312_312_LINES |
760 R1_DEW |
761 R1_EXTENDED_PACKET_DISABLE |
762 R1_DAUS_ALL_ON |
763 R1_8_BITS_NO_PARITY |
764 R1_VCS_TO_SCS,
766 COMMAND_END) ||
767 i2c_senddata(t, SAA5246A_REGISTER_R4,
769 /* We do not care much for the TV display but nevertheless we
770 * need the currently displayed page later because only on that
771 * page the time is updated. */
772 R4_DISPLAY_PAGE_4,
774 COMMAND_END))
776 err = -EIO;
777 goto fail;
780 return 0;
782 fail:
783 video_exclusive_release(inode,file);
784 return err;
787 static int saa5246a_release(struct inode *inode, struct file *file)
789 struct video_device *vd = video_devdata(file);
790 struct saa5246a_device *t = vd->priv;
792 /* Stop all acquisition circuits. */
793 i2c_senddata(t, SAA5246A_REGISTER_R1,
795 R1_INTERLACED_312_AND_HALF_312_AND_HALF_LINES |
796 R1_DEW |
797 R1_EXTENDED_PACKET_DISABLE |
798 R1_DAUS_ALL_OFF |
799 R1_8_BITS_NO_PARITY |
800 R1_VCS_TO_SCS,
802 COMMAND_END);
803 video_exclusive_release(inode,file);
804 return 0;
807 static int __init init_saa_5246a (void)
809 printk(KERN_INFO
810 "SAA5246A (or compatible) Teletext decoder driver version %d.%d\n",
811 MAJOR_VERSION, MINOR_VERSION);
812 return i2c_add_driver(&i2c_driver_videotext);
815 static void __exit cleanup_saa_5246a (void)
817 i2c_del_driver(&i2c_driver_videotext);
820 module_init(init_saa_5246a);
821 module_exit(cleanup_saa_5246a);
823 static const struct file_operations saa_fops = {
824 .owner = THIS_MODULE,
825 .open = saa5246a_open,
826 .release = saa5246a_release,
827 .ioctl = saa5246a_ioctl,
828 .llseek = no_llseek,
831 static struct video_device saa_template =
833 .name = IF_NAME,
834 .fops = &saa_fops,
835 .release = video_device_release,
836 .minor = -1,