saa5249.c 19 KB

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