saa5249.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. /*
  2. * Modified in order to keep it compatible both with new and old videotext IOCTLs by
  3. * Michael Geng <linux@MichaelGeng.de>
  4. *
  5. * Cleaned up to use existing videodev interface and allow the idea
  6. * of multiple teletext decoders on the video4linux iface. Changed i2c
  7. * to cover addressing clashes on device busses. It's also rebuilt so
  8. * you can add arbitary multiple teletext devices to Linux video4linux
  9. * now (well 32 anyway).
  10. *
  11. * Alan Cox <Alan.Cox@linux.org>
  12. *
  13. * The original driver was heavily modified to match the i2c interface
  14. * It was truncated to use the WinTV boards, too.
  15. *
  16. * Copyright (c) 1998 Richard Guenther <richard.guenther@student.uni-tuebingen.de>
  17. *
  18. * $Id: saa5249.c,v 1.1 1998/03/30 22:23:23 alan Exp $
  19. *
  20. * Derived From
  21. *
  22. * vtx.c:
  23. * This is a loadable character-device-driver for videotext-interfaces
  24. * (aka teletext). Please check the Makefile/README for a list of supported
  25. * interfaces.
  26. *
  27. * Copyright (c) 1994-97 Martin Buck <martin-2.buck@student.uni-ulm.de>
  28. *
  29. *
  30. * This program is free software; you can redistribute it and/or modify
  31. * it under the terms of the GNU General Public License as published by
  32. * the Free Software Foundation; either version 2 of the License, or
  33. * (at your option) any later version.
  34. *
  35. * This program is distributed in the hope that it will be useful,
  36. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  37. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  38. * GNU General Public License for more details.
  39. *
  40. * You should have received a copy of the GNU General Public License
  41. * along with this program; if not, write to the Free Software
  42. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  43. * USA.
  44. */
  45. #include <linux/module.h>
  46. #include <linux/kernel.h>
  47. #include <linux/sched.h>
  48. #include <linux/mm.h>
  49. #include <linux/errno.h>
  50. #include <linux/delay.h>
  51. #include <linux/ioport.h>
  52. #include <linux/slab.h>
  53. #include <linux/init.h>
  54. #include <stdarg.h>
  55. #include <linux/i2c.h>
  56. #include <linux/videotext.h>
  57. #include <linux/videodev.h>
  58. #include <asm/io.h>
  59. #include <asm/uaccess.h>
  60. #define VTX_VER_MAJ 1
  61. #define VTX_VER_MIN 8
  62. #define NUM_DAUS 4
  63. #define NUM_BUFS 8
  64. #define IF_NAME "SAA5249"
  65. static const int disp_modes[8][3] =
  66. {
  67. { 0x46, 0x03, 0x03 }, /* DISPOFF */
  68. { 0x46, 0xcc, 0xcc }, /* DISPNORM */
  69. { 0x44, 0x0f, 0x0f }, /* DISPTRANS */
  70. { 0x46, 0xcc, 0x46 }, /* DISPINS */
  71. { 0x44, 0x03, 0x03 }, /* DISPOFF, interlaced */
  72. { 0x44, 0xcc, 0xcc }, /* DISPNORM, interlaced */
  73. { 0x44, 0x0f, 0x0f }, /* DISPTRANS, interlaced */
  74. { 0x44, 0xcc, 0x46 } /* DISPINS, interlaced */
  75. };
  76. #define PAGE_WAIT (300*HZ/1000) /* Time between requesting page and */
  77. /* checking status bits */
  78. #define PGBUF_EXPIRE (15*HZ) /* Time to wait before retransmitting */
  79. /* page regardless of infobits */
  80. typedef struct {
  81. u8 pgbuf[VTX_VIRTUALSIZE]; /* Page-buffer */
  82. u8 laststat[10]; /* Last value of infobits for DAU */
  83. u8 sregs[7]; /* Page-request registers */
  84. unsigned long expire; /* Time when page will be expired */
  85. unsigned clrfound : 1; /* VTXIOCCLRFOUND has been called */
  86. unsigned stopped : 1; /* VTXIOCSTOPDAU has been called */
  87. } vdau_t;
  88. struct saa5249_device
  89. {
  90. vdau_t vdau[NUM_DAUS]; /* Data for virtual DAUs (the 5249 only has one */
  91. /* real DAU, so we have to simulate some more) */
  92. int vtx_use_count;
  93. int is_searching[NUM_DAUS];
  94. int disp_mode;
  95. int virtual_mode;
  96. struct i2c_client *client;
  97. struct semaphore lock;
  98. };
  99. #define CCTWR 34 /* I²C write/read-address of vtx-chip */
  100. #define CCTRD 35
  101. #define NOACK_REPEAT 10 /* Retry access this many times on failure */
  102. #define CLEAR_DELAY (HZ/20) /* Time required to clear a page */
  103. #define READY_TIMEOUT (30*HZ/1000) /* Time to wait for ready signal of I²C-bus interface */
  104. #define INIT_DELAY 500 /* Time in usec to wait at initialization of CEA interface */
  105. #define START_DELAY 10 /* Time in usec to wait before starting write-cycle (CEA) */
  106. #define VTX_DEV_MINOR 0
  107. /* General defines and debugging support */
  108. #ifndef FALSE
  109. #define FALSE 0
  110. #define TRUE 1
  111. #endif
  112. #define RESCHED do { cond_resched(); } while(0)
  113. static struct video_device saa_template; /* Declared near bottom */
  114. /* Addresses to scan */
  115. static unsigned short normal_i2c[] = {34>>1,I2C_CLIENT_END};
  116. I2C_CLIENT_INSMOD;
  117. static struct i2c_client client_template;
  118. static int saa5249_attach(struct i2c_adapter *adap, int addr, int kind)
  119. {
  120. int pgbuf;
  121. int err;
  122. struct i2c_client *client;
  123. struct video_device *vd;
  124. struct saa5249_device *t;
  125. printk(KERN_INFO "saa5249: teletext chip found.\n");
  126. client=kmalloc(sizeof(*client), GFP_KERNEL);
  127. if(client==NULL)
  128. return -ENOMEM;
  129. client_template.adapter = adap;
  130. client_template.addr = addr;
  131. memcpy(client, &client_template, sizeof(*client));
  132. t = kzalloc(sizeof(*t), GFP_KERNEL);
  133. if(t==NULL)
  134. {
  135. kfree(client);
  136. return -ENOMEM;
  137. }
  138. strlcpy(client->name, IF_NAME, I2C_NAME_SIZE);
  139. init_MUTEX(&t->lock);
  140. /*
  141. * Now create a video4linux device
  142. */
  143. vd = kmalloc(sizeof(struct video_device), GFP_KERNEL);
  144. if(vd==NULL)
  145. {
  146. kfree(t);
  147. kfree(client);
  148. return -ENOMEM;
  149. }
  150. i2c_set_clientdata(client, vd);
  151. memcpy(vd, &saa_template, sizeof(*vd));
  152. for (pgbuf = 0; pgbuf < NUM_DAUS; pgbuf++)
  153. {
  154. memset(t->vdau[pgbuf].pgbuf, ' ', sizeof(t->vdau[0].pgbuf));
  155. memset(t->vdau[pgbuf].sregs, 0, sizeof(t->vdau[0].sregs));
  156. memset(t->vdau[pgbuf].laststat, 0, sizeof(t->vdau[0].laststat));
  157. t->vdau[pgbuf].expire = 0;
  158. t->vdau[pgbuf].clrfound = TRUE;
  159. t->vdau[pgbuf].stopped = TRUE;
  160. t->is_searching[pgbuf] = FALSE;
  161. }
  162. vd->priv=t;
  163. /*
  164. * Register it
  165. */
  166. if((err=video_register_device(vd, VFL_TYPE_VTX,-1))<0)
  167. {
  168. kfree(t);
  169. kfree(vd);
  170. kfree(client);
  171. return err;
  172. }
  173. t->client = client;
  174. i2c_attach_client(client);
  175. return 0;
  176. }
  177. /*
  178. * We do most of the hard work when we become a device on the i2c.
  179. */
  180. static int saa5249_probe(struct i2c_adapter *adap)
  181. {
  182. if (adap->class & I2C_CLASS_TV_ANALOG)
  183. return i2c_probe(adap, &addr_data, saa5249_attach);
  184. return 0;
  185. }
  186. static int saa5249_detach(struct i2c_client *client)
  187. {
  188. struct video_device *vd = i2c_get_clientdata(client);
  189. i2c_detach_client(client);
  190. video_unregister_device(vd);
  191. kfree(vd->priv);
  192. kfree(vd);
  193. kfree(client);
  194. return 0;
  195. }
  196. /* new I2C driver support */
  197. static struct i2c_driver i2c_driver_videotext =
  198. {
  199. .driver = {
  200. .name = IF_NAME, /* name */
  201. },
  202. .id = I2C_DRIVERID_SAA5249, /* in i2c.h */
  203. .attach_adapter = saa5249_probe,
  204. .detach_client = saa5249_detach,
  205. };
  206. static struct i2c_client client_template = {
  207. .driver = &i2c_driver_videotext,
  208. .name = "(unset)",
  209. };
  210. /*
  211. * Wait the given number of jiffies (10ms). This calls the scheduler, so the actual
  212. * delay may be longer.
  213. */
  214. static void jdelay(unsigned long delay)
  215. {
  216. sigset_t oldblocked = current->blocked;
  217. spin_lock_irq(&current->sighand->siglock);
  218. sigfillset(&current->blocked);
  219. recalc_sigpending();
  220. spin_unlock_irq(&current->sighand->siglock);
  221. msleep_interruptible(jiffies_to_msecs(delay));
  222. spin_lock_irq(&current->sighand->siglock);
  223. current->blocked = oldblocked;
  224. recalc_sigpending();
  225. spin_unlock_irq(&current->sighand->siglock);
  226. }
  227. /*
  228. * I2C interfaces
  229. */
  230. static int i2c_sendbuf(struct saa5249_device *t, int reg, int count, u8 *data)
  231. {
  232. char buf[64];
  233. buf[0] = reg;
  234. memcpy(buf+1, data, count);
  235. if(i2c_master_send(t->client, buf, count+1)==count+1)
  236. return 0;
  237. return -1;
  238. }
  239. static int i2c_senddata(struct saa5249_device *t, ...)
  240. {
  241. unsigned char buf[64];
  242. int v;
  243. int ct=0;
  244. va_list argp;
  245. va_start(argp,t);
  246. while((v=va_arg(argp,int))!=-1)
  247. buf[ct++]=v;
  248. return i2c_sendbuf(t, buf[0], ct-1, buf+1);
  249. }
  250. /* Get count number of bytes from I²C-device at address adr, store them in buf. Start & stop
  251. * handshaking is done by this routine, ack will be sent after the last byte to inhibit further
  252. * sending of data. If uaccess is TRUE, data is written to user-space with put_user.
  253. * Returns -1 if I²C-device didn't send acknowledge, 0 otherwise
  254. */
  255. static int i2c_getdata(struct saa5249_device *t, int count, u8 *buf)
  256. {
  257. if(i2c_master_recv(t->client, buf, count)!=count)
  258. return -1;
  259. return 0;
  260. }
  261. /*
  262. * Standard character-device-driver functions
  263. */
  264. static int do_saa5249_ioctl(struct inode *inode, struct file *file,
  265. unsigned int cmd, void *arg)
  266. {
  267. static int virtual_mode = FALSE;
  268. struct video_device *vd = video_devdata(file);
  269. struct saa5249_device *t=vd->priv;
  270. switch(cmd)
  271. {
  272. case VTXIOCGETINFO:
  273. {
  274. vtx_info_t *info = arg;
  275. info->version_major = VTX_VER_MAJ;
  276. info->version_minor = VTX_VER_MIN;
  277. info->numpages = NUM_DAUS;
  278. /*info->cct_type = CCT_TYPE;*/
  279. return 0;
  280. }
  281. case VTXIOCCLRPAGE:
  282. {
  283. vtx_pagereq_t *req = arg;
  284. if (req->pgbuf < 0 || req->pgbuf >= NUM_DAUS)
  285. return -EINVAL;
  286. memset(t->vdau[req->pgbuf].pgbuf, ' ', sizeof(t->vdau[0].pgbuf));
  287. t->vdau[req->pgbuf].clrfound = TRUE;
  288. return 0;
  289. }
  290. case VTXIOCCLRFOUND:
  291. {
  292. vtx_pagereq_t *req = arg;
  293. if (req->pgbuf < 0 || req->pgbuf >= NUM_DAUS)
  294. return -EINVAL;
  295. t->vdau[req->pgbuf].clrfound = TRUE;
  296. return 0;
  297. }
  298. case VTXIOCPAGEREQ:
  299. {
  300. vtx_pagereq_t *req = arg;
  301. if (!(req->pagemask & PGMASK_PAGE))
  302. req->page = 0;
  303. if (!(req->pagemask & PGMASK_HOUR))
  304. req->hour = 0;
  305. if (!(req->pagemask & PGMASK_MINUTE))
  306. req->minute = 0;
  307. if (req->page < 0 || req->page > 0x8ff) /* 7FF ?? */
  308. return -EINVAL;
  309. req->page &= 0x7ff;
  310. if (req->hour < 0 || req->hour > 0x3f || req->minute < 0 || req->minute > 0x7f ||
  311. req->pagemask < 0 || req->pagemask >= PGMASK_MAX || req->pgbuf < 0 || req->pgbuf >= NUM_DAUS)
  312. return -EINVAL;
  313. t->vdau[req->pgbuf].sregs[0] = (req->pagemask & PG_HUND ? 0x10 : 0) | (req->page / 0x100);
  314. t->vdau[req->pgbuf].sregs[1] = (req->pagemask & PG_TEN ? 0x10 : 0) | ((req->page / 0x10) & 0xf);
  315. t->vdau[req->pgbuf].sregs[2] = (req->pagemask & PG_UNIT ? 0x10 : 0) | (req->page & 0xf);
  316. t->vdau[req->pgbuf].sregs[3] = (req->pagemask & HR_TEN ? 0x10 : 0) | (req->hour / 0x10);
  317. t->vdau[req->pgbuf].sregs[4] = (req->pagemask & HR_UNIT ? 0x10 : 0) | (req->hour & 0xf);
  318. t->vdau[req->pgbuf].sregs[5] = (req->pagemask & MIN_TEN ? 0x10 : 0) | (req->minute / 0x10);
  319. t->vdau[req->pgbuf].sregs[6] = (req->pagemask & MIN_UNIT ? 0x10 : 0) | (req->minute & 0xf);
  320. t->vdau[req->pgbuf].stopped = FALSE;
  321. t->vdau[req->pgbuf].clrfound = TRUE;
  322. t->is_searching[req->pgbuf] = TRUE;
  323. return 0;
  324. }
  325. case VTXIOCGETSTAT:
  326. {
  327. vtx_pagereq_t *req = arg;
  328. u8 infobits[10];
  329. vtx_pageinfo_t info;
  330. int a;
  331. if (req->pgbuf < 0 || req->pgbuf >= NUM_DAUS)
  332. return -EINVAL;
  333. if (!t->vdau[req->pgbuf].stopped)
  334. {
  335. if (i2c_senddata(t, 2, 0, -1) ||
  336. i2c_sendbuf(t, 3, sizeof(t->vdau[0].sregs), t->vdau[req->pgbuf].sregs) ||
  337. i2c_senddata(t, 8, 0, 25, 0, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', -1) ||
  338. i2c_senddata(t, 2, 0, t->vdau[req->pgbuf].sregs[0] | 8, -1) ||
  339. i2c_senddata(t, 8, 0, 25, 0, -1))
  340. return -EIO;
  341. jdelay(PAGE_WAIT);
  342. if (i2c_getdata(t, 10, infobits))
  343. return -EIO;
  344. if (!(infobits[8] & 0x10) && !(infobits[7] & 0xf0) && /* check FOUND-bit */
  345. (memcmp(infobits, t->vdau[req->pgbuf].laststat, sizeof(infobits)) ||
  346. time_after_eq(jiffies, t->vdau[req->pgbuf].expire)))
  347. { /* check if new page arrived */
  348. if (i2c_senddata(t, 8, 0, 0, 0, -1) ||
  349. i2c_getdata(t, VTX_PAGESIZE, t->vdau[req->pgbuf].pgbuf))
  350. return -EIO;
  351. t->vdau[req->pgbuf].expire = jiffies + PGBUF_EXPIRE;
  352. memset(t->vdau[req->pgbuf].pgbuf + VTX_PAGESIZE, ' ', VTX_VIRTUALSIZE - VTX_PAGESIZE);
  353. if (t->virtual_mode)
  354. {
  355. /* Packet X/24 */
  356. if (i2c_senddata(t, 8, 0, 0x20, 0, -1) ||
  357. i2c_getdata(t, 40, t->vdau[req->pgbuf].pgbuf + VTX_PAGESIZE + 20 * 40))
  358. return -EIO;
  359. /* Packet X/27/0 */
  360. if (i2c_senddata(t, 8, 0, 0x21, 0, -1) ||
  361. i2c_getdata(t, 40, t->vdau[req->pgbuf].pgbuf + VTX_PAGESIZE + 16 * 40))
  362. return -EIO;
  363. /* Packet 8/30/0...8/30/15
  364. * FIXME: AFAIK, the 5249 does hamming-decoding for some bytes in packet 8/30,
  365. * so we should undo this here.
  366. */
  367. if (i2c_senddata(t, 8, 0, 0x22, 0, -1) ||
  368. i2c_getdata(t, 40, t->vdau[req->pgbuf].pgbuf + VTX_PAGESIZE + 23 * 40))
  369. return -EIO;
  370. }
  371. t->vdau[req->pgbuf].clrfound = FALSE;
  372. memcpy(t->vdau[req->pgbuf].laststat, infobits, sizeof(infobits));
  373. }
  374. else
  375. {
  376. memcpy(infobits, t->vdau[req->pgbuf].laststat, sizeof(infobits));
  377. }
  378. }
  379. else
  380. {
  381. memcpy(infobits, t->vdau[req->pgbuf].laststat, sizeof(infobits));
  382. }
  383. info.pagenum = ((infobits[8] << 8) & 0x700) | ((infobits[1] << 4) & 0xf0) | (infobits[0] & 0x0f);
  384. if (info.pagenum < 0x100)
  385. info.pagenum += 0x800;
  386. info.hour = ((infobits[5] << 4) & 0x30) | (infobits[4] & 0x0f);
  387. info.minute = ((infobits[3] << 4) & 0x70) | (infobits[2] & 0x0f);
  388. info.charset = ((infobits[7] >> 1) & 7);
  389. info.delete = !!(infobits[3] & 8);
  390. info.headline = !!(infobits[5] & 4);
  391. info.subtitle = !!(infobits[5] & 8);
  392. info.supp_header = !!(infobits[6] & 1);
  393. info.update = !!(infobits[6] & 2);
  394. info.inter_seq = !!(infobits[6] & 4);
  395. info.dis_disp = !!(infobits[6] & 8);
  396. info.serial = !!(infobits[7] & 1);
  397. info.notfound = !!(infobits[8] & 0x10);
  398. info.pblf = !!(infobits[9] & 0x20);
  399. info.hamming = 0;
  400. for (a = 0; a <= 7; a++)
  401. {
  402. if (infobits[a] & 0xf0)
  403. {
  404. info.hamming = 1;
  405. break;
  406. }
  407. }
  408. if (t->vdau[req->pgbuf].clrfound)
  409. info.notfound = 1;
  410. if(copy_to_user(req->buffer, &info, sizeof(vtx_pageinfo_t)))
  411. return -EFAULT;
  412. if (!info.hamming && !info.notfound)
  413. {
  414. t->is_searching[req->pgbuf] = FALSE;
  415. }
  416. return 0;
  417. }
  418. case VTXIOCGETPAGE:
  419. {
  420. vtx_pagereq_t *req = arg;
  421. int start, end;
  422. if (req->pgbuf < 0 || req->pgbuf >= NUM_DAUS || req->start < 0 ||
  423. req->start > req->end || req->end >= (virtual_mode ? VTX_VIRTUALSIZE : VTX_PAGESIZE))
  424. return -EINVAL;
  425. if(copy_to_user(req->buffer, &t->vdau[req->pgbuf].pgbuf[req->start], req->end - req->start + 1))
  426. return -EFAULT;
  427. /*
  428. * Always read the time directly from SAA5249
  429. */
  430. if (req->start <= 39 && req->end >= 32)
  431. {
  432. int len;
  433. char buf[16];
  434. start = max(req->start, 32);
  435. end = min(req->end, 39);
  436. len=end-start+1;
  437. if (i2c_senddata(t, 8, 0, 0, start, -1) ||
  438. i2c_getdata(t, len, buf))
  439. return -EIO;
  440. if(copy_to_user(req->buffer+start-req->start, buf, len))
  441. return -EFAULT;
  442. }
  443. /* Insert the current header if DAU is still searching for a page */
  444. if (req->start <= 31 && req->end >= 7 && t->is_searching[req->pgbuf])
  445. {
  446. char buf[32];
  447. int len;
  448. start = max(req->start, 7);
  449. end = min(req->end, 31);
  450. len=end-start+1;
  451. if (i2c_senddata(t, 8, 0, 0, start, -1) ||
  452. i2c_getdata(t, len, buf))
  453. return -EIO;
  454. if(copy_to_user(req->buffer+start-req->start, buf, len))
  455. return -EFAULT;
  456. }
  457. return 0;
  458. }
  459. case VTXIOCSTOPDAU:
  460. {
  461. vtx_pagereq_t *req = arg;
  462. if (req->pgbuf < 0 || req->pgbuf >= NUM_DAUS)
  463. return -EINVAL;
  464. t->vdau[req->pgbuf].stopped = TRUE;
  465. t->is_searching[req->pgbuf] = FALSE;
  466. return 0;
  467. }
  468. case VTXIOCPUTPAGE:
  469. case VTXIOCSETDISP:
  470. case VTXIOCPUTSTAT:
  471. return 0;
  472. case VTXIOCCLRCACHE:
  473. {
  474. if (i2c_senddata(t, 0, NUM_DAUS, 0, 8, -1) || i2c_senddata(t, 11,
  475. ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
  476. ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', -1))
  477. return -EIO;
  478. if (i2c_senddata(t, 3, 0x20, -1))
  479. return -EIO;
  480. jdelay(10 * CLEAR_DELAY); /* I have no idea how long we have to wait here */
  481. return 0;
  482. }
  483. case VTXIOCSETVIRT:
  484. {
  485. /* The SAA5249 has virtual-row reception turned on always */
  486. t->virtual_mode = (int)(long)arg;
  487. return 0;
  488. }
  489. }
  490. return -EINVAL;
  491. }
  492. /*
  493. * Translates old vtx IOCTLs to new ones
  494. *
  495. * This keeps new kernel versions compatible with old userspace programs.
  496. */
  497. static inline unsigned int vtx_fix_command(unsigned int cmd)
  498. {
  499. switch (cmd) {
  500. case VTXIOCGETINFO_OLD:
  501. cmd = VTXIOCGETINFO;
  502. break;
  503. case VTXIOCCLRPAGE_OLD:
  504. cmd = VTXIOCCLRPAGE;
  505. break;
  506. case VTXIOCCLRFOUND_OLD:
  507. cmd = VTXIOCCLRFOUND;
  508. break;
  509. case VTXIOCPAGEREQ_OLD:
  510. cmd = VTXIOCPAGEREQ;
  511. break;
  512. case VTXIOCGETSTAT_OLD:
  513. cmd = VTXIOCGETSTAT;
  514. break;
  515. case VTXIOCGETPAGE_OLD:
  516. cmd = VTXIOCGETPAGE;
  517. break;
  518. case VTXIOCSTOPDAU_OLD:
  519. cmd = VTXIOCSTOPDAU;
  520. break;
  521. case VTXIOCPUTPAGE_OLD:
  522. cmd = VTXIOCPUTPAGE;
  523. break;
  524. case VTXIOCSETDISP_OLD:
  525. cmd = VTXIOCSETDISP;
  526. break;
  527. case VTXIOCPUTSTAT_OLD:
  528. cmd = VTXIOCPUTSTAT;
  529. break;
  530. case VTXIOCCLRCACHE_OLD:
  531. cmd = VTXIOCCLRCACHE;
  532. break;
  533. case VTXIOCSETVIRT_OLD:
  534. cmd = VTXIOCSETVIRT;
  535. break;
  536. }
  537. return cmd;
  538. }
  539. /*
  540. * Handle the locking
  541. */
  542. static int saa5249_ioctl(struct inode *inode, struct file *file,
  543. unsigned int cmd, unsigned long arg)
  544. {
  545. struct video_device *vd = video_devdata(file);
  546. struct saa5249_device *t=vd->priv;
  547. int err;
  548. cmd = vtx_fix_command(cmd);
  549. down(&t->lock);
  550. err = video_usercopy(inode,file,cmd,arg,do_saa5249_ioctl);
  551. up(&t->lock);
  552. return err;
  553. }
  554. static int saa5249_open(struct inode *inode, struct file *file)
  555. {
  556. struct video_device *vd = video_devdata(file);
  557. struct saa5249_device *t=vd->priv;
  558. int err,pgbuf;
  559. err = video_exclusive_open(inode,file);
  560. if (err < 0)
  561. return err;
  562. if (t->client==NULL) {
  563. err = -ENODEV;
  564. goto fail;
  565. }
  566. if (i2c_senddata(t, 0, 0, -1) || /* Select R11 */
  567. /* Turn off parity checks (we do this ourselves) */
  568. i2c_senddata(t, 1, disp_modes[t->disp_mode][0], 0, -1) ||
  569. /* Display TV-picture, no virtual rows */
  570. i2c_senddata(t, 4, NUM_DAUS, disp_modes[t->disp_mode][1], disp_modes[t->disp_mode][2], 7, -1)) /* Set display to page 4 */
  571. {
  572. err = -EIO;
  573. goto fail;
  574. }
  575. for (pgbuf = 0; pgbuf < NUM_DAUS; pgbuf++)
  576. {
  577. memset(t->vdau[pgbuf].pgbuf, ' ', sizeof(t->vdau[0].pgbuf));
  578. memset(t->vdau[pgbuf].sregs, 0, sizeof(t->vdau[0].sregs));
  579. memset(t->vdau[pgbuf].laststat, 0, sizeof(t->vdau[0].laststat));
  580. t->vdau[pgbuf].expire = 0;
  581. t->vdau[pgbuf].clrfound = TRUE;
  582. t->vdau[pgbuf].stopped = TRUE;
  583. t->is_searching[pgbuf] = FALSE;
  584. }
  585. t->virtual_mode=FALSE;
  586. return 0;
  587. fail:
  588. video_exclusive_release(inode,file);
  589. return err;
  590. }
  591. static int saa5249_release(struct inode *inode, struct file *file)
  592. {
  593. struct video_device *vd = video_devdata(file);
  594. struct saa5249_device *t=vd->priv;
  595. i2c_senddata(t, 1, 0x20, -1); /* Turn off CCT */
  596. i2c_senddata(t, 5, 3, 3, -1); /* Turn off TV-display */
  597. video_exclusive_release(inode,file);
  598. return 0;
  599. }
  600. static int __init init_saa_5249 (void)
  601. {
  602. printk(KERN_INFO "SAA5249 driver (" IF_NAME " interface) for VideoText version %d.%d\n",
  603. VTX_VER_MAJ, VTX_VER_MIN);
  604. return i2c_add_driver(&i2c_driver_videotext);
  605. }
  606. static void __exit cleanup_saa_5249 (void)
  607. {
  608. i2c_del_driver(&i2c_driver_videotext);
  609. }
  610. module_init(init_saa_5249);
  611. module_exit(cleanup_saa_5249);
  612. static struct file_operations saa_fops = {
  613. .owner = THIS_MODULE,
  614. .open = saa5249_open,
  615. .release = saa5249_release,
  616. .ioctl = saa5249_ioctl,
  617. .compat_ioctl = v4l_compat_ioctl32,
  618. .llseek = no_llseek,
  619. };
  620. static struct video_device saa_template =
  621. {
  622. .owner = THIS_MODULE,
  623. .name = IF_NAME,
  624. .type = VID_TYPE_TELETEXT, /*| VID_TYPE_TUNER ?? */
  625. .hardware = VID_HARDWARE_SAA5249,
  626. .fops = &saa_fops,
  627. };
  628. MODULE_LICENSE("GPL");