av7110_hw.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224
  1. /*
  2. * av7110_hw.c: av7110 low level hardware access and firmware interface
  3. *
  4. * Copyright (C) 1999-2002 Ralph Metzler
  5. * & Marcus Metzler for convergence integrated media GmbH
  6. *
  7. * originally based on code by:
  8. * Copyright (C) 1998,1999 Christian Theiss <mistert@rz.fh-augsburg.de>
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License
  12. * as published by the Free Software Foundation; either version 2
  13. * of the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  23. * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
  24. *
  25. * the project's page is at https://linuxtv.org
  26. */
  27. /* for debugging ARM communication: */
  28. //#define COM_DEBUG
  29. #include <stdarg.h>
  30. #include <linux/types.h>
  31. #include <linux/kernel.h>
  32. #include <linux/string.h>
  33. #include <linux/delay.h>
  34. #include <linux/fs.h>
  35. #include "av7110.h"
  36. #include "av7110_hw.h"
  37. #define _NOHANDSHAKE
  38. /*
  39. * Max transfer size done by av7110_fw_cmd()
  40. *
  41. * The maximum size passed to this function is 6 bytes. The buffer also
  42. * uses two additional ones for type and size. So, 8 bytes is enough.
  43. */
  44. #define MAX_XFER_SIZE 8
  45. /****************************************************************************
  46. * DEBI functions
  47. ****************************************************************************/
  48. /* This DEBI code is based on the Stradis driver
  49. by Nathan Laredo <laredo@gnu.org> */
  50. int av7110_debiwrite(struct av7110 *av7110, u32 config,
  51. int addr, u32 val, unsigned int count)
  52. {
  53. struct saa7146_dev *dev = av7110->dev;
  54. if (count > 32764) {
  55. printk("%s: invalid count %d\n", __func__, count);
  56. return -1;
  57. }
  58. if (saa7146_wait_for_debi_done(av7110->dev, 0) < 0) {
  59. printk("%s: wait_for_debi_done failed\n", __func__);
  60. return -1;
  61. }
  62. saa7146_write(dev, DEBI_CONFIG, config);
  63. if (count <= 4) /* immediate transfer */
  64. saa7146_write(dev, DEBI_AD, val);
  65. else /* block transfer */
  66. saa7146_write(dev, DEBI_AD, av7110->debi_bus);
  67. saa7146_write(dev, DEBI_COMMAND, (count << 17) | (addr & 0xffff));
  68. saa7146_write(dev, MC2, (2 << 16) | 2);
  69. return 0;
  70. }
  71. u32 av7110_debiread(struct av7110 *av7110, u32 config, int addr, unsigned int count)
  72. {
  73. struct saa7146_dev *dev = av7110->dev;
  74. u32 result = 0;
  75. if (count > 32764) {
  76. printk("%s: invalid count %d\n", __func__, count);
  77. return 0;
  78. }
  79. if (saa7146_wait_for_debi_done(av7110->dev, 0) < 0) {
  80. printk("%s: wait_for_debi_done #1 failed\n", __func__);
  81. return 0;
  82. }
  83. saa7146_write(dev, DEBI_AD, av7110->debi_bus);
  84. saa7146_write(dev, DEBI_COMMAND, (count << 17) | 0x10000 | (addr & 0xffff));
  85. saa7146_write(dev, DEBI_CONFIG, config);
  86. saa7146_write(dev, MC2, (2 << 16) | 2);
  87. if (count > 4)
  88. return count;
  89. if (saa7146_wait_for_debi_done(av7110->dev, 0) < 0) {
  90. printk("%s: wait_for_debi_done #2 failed\n", __func__);
  91. return 0;
  92. }
  93. result = saa7146_read(dev, DEBI_AD);
  94. result &= (0xffffffffUL >> ((4 - count) * 8));
  95. return result;
  96. }
  97. /* av7110 ARM core boot stuff */
  98. #if 0
  99. void av7110_reset_arm(struct av7110 *av7110)
  100. {
  101. saa7146_setgpio(av7110->dev, RESET_LINE, SAA7146_GPIO_OUTLO);
  102. /* Disable DEBI and GPIO irq */
  103. SAA7146_IER_DISABLE(av7110->dev, MASK_19 | MASK_03);
  104. SAA7146_ISR_CLEAR(av7110->dev, MASK_19 | MASK_03);
  105. saa7146_setgpio(av7110->dev, RESET_LINE, SAA7146_GPIO_OUTHI);
  106. msleep(30); /* the firmware needs some time to initialize */
  107. ARM_ResetMailBox(av7110);
  108. SAA7146_ISR_CLEAR(av7110->dev, MASK_19 | MASK_03);
  109. SAA7146_IER_ENABLE(av7110->dev, MASK_03);
  110. av7110->arm_ready = 1;
  111. dprintk(1, "reset ARM\n");
  112. }
  113. #endif /* 0 */
  114. static int waitdebi(struct av7110 *av7110, int adr, int state)
  115. {
  116. int k;
  117. dprintk(4, "%p\n", av7110);
  118. for (k = 0; k < 100; k++) {
  119. if (irdebi(av7110, DEBINOSWAP, adr, 0, 2) == state)
  120. return 0;
  121. udelay(5);
  122. }
  123. return -ETIMEDOUT;
  124. }
  125. static int load_dram(struct av7110 *av7110, u32 *data, int len)
  126. {
  127. int i;
  128. int blocks, rest;
  129. u32 base, bootblock = AV7110_BOOT_BLOCK;
  130. dprintk(4, "%p\n", av7110);
  131. blocks = len / AV7110_BOOT_MAX_SIZE;
  132. rest = len % AV7110_BOOT_MAX_SIZE;
  133. base = DRAM_START_CODE;
  134. for (i = 0; i < blocks; i++) {
  135. if (waitdebi(av7110, AV7110_BOOT_STATE, BOOTSTATE_BUFFER_EMPTY) < 0) {
  136. printk(KERN_ERR "dvb-ttpci: load_dram(): timeout at block %d\n", i);
  137. return -ETIMEDOUT;
  138. }
  139. dprintk(4, "writing DRAM block %d\n", i);
  140. mwdebi(av7110, DEBISWAB, bootblock,
  141. ((u8 *)data) + i * AV7110_BOOT_MAX_SIZE, AV7110_BOOT_MAX_SIZE);
  142. bootblock ^= 0x1400;
  143. iwdebi(av7110, DEBISWAB, AV7110_BOOT_BASE, swab32(base), 4);
  144. iwdebi(av7110, DEBINOSWAP, AV7110_BOOT_SIZE, AV7110_BOOT_MAX_SIZE, 2);
  145. iwdebi(av7110, DEBINOSWAP, AV7110_BOOT_STATE, BOOTSTATE_BUFFER_FULL, 2);
  146. base += AV7110_BOOT_MAX_SIZE;
  147. }
  148. if (rest > 0) {
  149. if (waitdebi(av7110, AV7110_BOOT_STATE, BOOTSTATE_BUFFER_EMPTY) < 0) {
  150. printk(KERN_ERR "dvb-ttpci: load_dram(): timeout at last block\n");
  151. return -ETIMEDOUT;
  152. }
  153. if (rest > 4)
  154. mwdebi(av7110, DEBISWAB, bootblock,
  155. ((u8 *)data) + i * AV7110_BOOT_MAX_SIZE, rest);
  156. else
  157. mwdebi(av7110, DEBISWAB, bootblock,
  158. ((u8 *)data) + i * AV7110_BOOT_MAX_SIZE - 4, rest + 4);
  159. iwdebi(av7110, DEBISWAB, AV7110_BOOT_BASE, swab32(base), 4);
  160. iwdebi(av7110, DEBINOSWAP, AV7110_BOOT_SIZE, rest, 2);
  161. iwdebi(av7110, DEBINOSWAP, AV7110_BOOT_STATE, BOOTSTATE_BUFFER_FULL, 2);
  162. }
  163. if (waitdebi(av7110, AV7110_BOOT_STATE, BOOTSTATE_BUFFER_EMPTY) < 0) {
  164. printk(KERN_ERR "dvb-ttpci: load_dram(): timeout after last block\n");
  165. return -ETIMEDOUT;
  166. }
  167. iwdebi(av7110, DEBINOSWAP, AV7110_BOOT_SIZE, 0, 2);
  168. iwdebi(av7110, DEBINOSWAP, AV7110_BOOT_STATE, BOOTSTATE_BUFFER_FULL, 2);
  169. if (waitdebi(av7110, AV7110_BOOT_STATE, BOOTSTATE_AV7110_BOOT_COMPLETE) < 0) {
  170. printk(KERN_ERR "dvb-ttpci: load_dram(): final handshake timeout\n");
  171. return -ETIMEDOUT;
  172. }
  173. return 0;
  174. }
  175. /* we cannot write av7110 DRAM directly, so load a bootloader into
  176. * the DPRAM which implements a simple boot protocol */
  177. int av7110_bootarm(struct av7110 *av7110)
  178. {
  179. const struct firmware *fw;
  180. const char *fw_name = "av7110/bootcode.bin";
  181. struct saa7146_dev *dev = av7110->dev;
  182. u32 ret;
  183. int i;
  184. dprintk(4, "%p\n", av7110);
  185. av7110->arm_ready = 0;
  186. saa7146_setgpio(dev, RESET_LINE, SAA7146_GPIO_OUTLO);
  187. /* Disable DEBI and GPIO irq */
  188. SAA7146_IER_DISABLE(av7110->dev, MASK_03 | MASK_19);
  189. SAA7146_ISR_CLEAR(av7110->dev, MASK_19 | MASK_03);
  190. /* enable DEBI */
  191. saa7146_write(av7110->dev, MC1, 0x08800880);
  192. saa7146_write(av7110->dev, DD1_STREAM_B, 0x00000000);
  193. saa7146_write(av7110->dev, MC2, (MASK_09 | MASK_25 | MASK_10 | MASK_26));
  194. /* test DEBI */
  195. iwdebi(av7110, DEBISWAP, DPRAM_BASE, 0x76543210, 4);
  196. /* FIXME: Why does Nexus CA require 2x iwdebi for first init? */
  197. iwdebi(av7110, DEBISWAP, DPRAM_BASE, 0x76543210, 4);
  198. if ((ret=irdebi(av7110, DEBINOSWAP, DPRAM_BASE, 0, 4)) != 0x10325476) {
  199. printk(KERN_ERR "dvb-ttpci: debi test in av7110_bootarm() failed: "
  200. "%08x != %08x (check your BIOS 'Plug&Play OS' settings)\n",
  201. ret, 0x10325476);
  202. return -1;
  203. }
  204. for (i = 0; i < 8192; i += 4)
  205. iwdebi(av7110, DEBISWAP, DPRAM_BASE + i, 0x00, 4);
  206. dprintk(2, "debi test OK\n");
  207. /* boot */
  208. dprintk(1, "load boot code\n");
  209. saa7146_setgpio(dev, ARM_IRQ_LINE, SAA7146_GPIO_IRQLO);
  210. //saa7146_setgpio(dev, DEBI_DONE_LINE, SAA7146_GPIO_INPUT);
  211. //saa7146_setgpio(dev, 3, SAA7146_GPIO_INPUT);
  212. ret = request_firmware(&fw, fw_name, &dev->pci->dev);
  213. if (ret) {
  214. printk(KERN_ERR "dvb-ttpci: Failed to load firmware \"%s\"\n",
  215. fw_name);
  216. return ret;
  217. }
  218. mwdebi(av7110, DEBISWAB, DPRAM_BASE, fw->data, fw->size);
  219. release_firmware(fw);
  220. iwdebi(av7110, DEBINOSWAP, AV7110_BOOT_STATE, BOOTSTATE_BUFFER_FULL, 2);
  221. if (saa7146_wait_for_debi_done(av7110->dev, 1)) {
  222. printk(KERN_ERR "dvb-ttpci: av7110_bootarm(): "
  223. "saa7146_wait_for_debi_done() timed out\n");
  224. return -ETIMEDOUT;
  225. }
  226. saa7146_setgpio(dev, RESET_LINE, SAA7146_GPIO_OUTHI);
  227. mdelay(1);
  228. dprintk(1, "load dram code\n");
  229. if (load_dram(av7110, (u32 *)av7110->bin_root, av7110->size_root) < 0) {
  230. printk(KERN_ERR "dvb-ttpci: av7110_bootarm(): "
  231. "load_dram() failed\n");
  232. return -1;
  233. }
  234. saa7146_setgpio(dev, RESET_LINE, SAA7146_GPIO_OUTLO);
  235. mdelay(1);
  236. dprintk(1, "load dpram code\n");
  237. mwdebi(av7110, DEBISWAB, DPRAM_BASE, av7110->bin_dpram, av7110->size_dpram);
  238. if (saa7146_wait_for_debi_done(av7110->dev, 1)) {
  239. printk(KERN_ERR "dvb-ttpci: av7110_bootarm(): "
  240. "saa7146_wait_for_debi_done() timed out after loading DRAM\n");
  241. return -ETIMEDOUT;
  242. }
  243. saa7146_setgpio(dev, RESET_LINE, SAA7146_GPIO_OUTHI);
  244. msleep(30); /* the firmware needs some time to initialize */
  245. //ARM_ClearIrq(av7110);
  246. ARM_ResetMailBox(av7110);
  247. SAA7146_ISR_CLEAR(av7110->dev, MASK_19 | MASK_03);
  248. SAA7146_IER_ENABLE(av7110->dev, MASK_03);
  249. av7110->arm_errors = 0;
  250. av7110->arm_ready = 1;
  251. return 0;
  252. }
  253. MODULE_FIRMWARE("av7110/bootcode.bin");
  254. /****************************************************************************
  255. * DEBI command polling
  256. ****************************************************************************/
  257. int av7110_wait_msgstate(struct av7110 *av7110, u16 flags)
  258. {
  259. unsigned long start;
  260. u32 stat;
  261. int err;
  262. if (FW_VERSION(av7110->arm_app) <= 0x261c) {
  263. /* not supported by old firmware */
  264. msleep(50);
  265. return 0;
  266. }
  267. /* new firmware */
  268. start = jiffies;
  269. for (;;) {
  270. err = time_after(jiffies, start + ARM_WAIT_FREE);
  271. if (mutex_lock_interruptible(&av7110->dcomlock))
  272. return -ERESTARTSYS;
  273. stat = rdebi(av7110, DEBINOSWAP, MSGSTATE, 0, 2);
  274. mutex_unlock(&av7110->dcomlock);
  275. if ((stat & flags) == 0)
  276. break;
  277. if (err) {
  278. printk(KERN_ERR "%s: timeout waiting for MSGSTATE %04x\n",
  279. __func__, stat & flags);
  280. return -ETIMEDOUT;
  281. }
  282. msleep(1);
  283. }
  284. return 0;
  285. }
  286. static int __av7110_send_fw_cmd(struct av7110 *av7110, u16* buf, int length)
  287. {
  288. int i;
  289. unsigned long start;
  290. char *type = NULL;
  291. u16 flags[2] = {0, 0};
  292. u32 stat;
  293. int err;
  294. // dprintk(4, "%p\n", av7110);
  295. if (!av7110->arm_ready) {
  296. dprintk(1, "arm not ready.\n");
  297. return -ENXIO;
  298. }
  299. start = jiffies;
  300. while (1) {
  301. err = time_after(jiffies, start + ARM_WAIT_FREE);
  302. if (rdebi(av7110, DEBINOSWAP, COMMAND, 0, 2) == 0)
  303. break;
  304. if (err) {
  305. printk(KERN_ERR "dvb-ttpci: %s(): timeout waiting for COMMAND idle\n", __func__);
  306. av7110->arm_errors++;
  307. return -ETIMEDOUT;
  308. }
  309. msleep(1);
  310. }
  311. if (FW_VERSION(av7110->arm_app) <= 0x261f)
  312. wdebi(av7110, DEBINOSWAP, COM_IF_LOCK, 0xffff, 2);
  313. #ifndef _NOHANDSHAKE
  314. start = jiffies;
  315. while (1) {
  316. err = time_after(jiffies, start + ARM_WAIT_SHAKE);
  317. if (rdebi(av7110, DEBINOSWAP, HANDSHAKE_REG, 0, 2) == 0)
  318. break;
  319. if (err) {
  320. printk(KERN_ERR "dvb-ttpci: %s(): timeout waiting for HANDSHAKE_REG\n", __func__);
  321. return -ETIMEDOUT;
  322. }
  323. msleep(1);
  324. }
  325. #endif
  326. switch ((buf[0] >> 8) & 0xff) {
  327. case COMTYPE_PIDFILTER:
  328. case COMTYPE_ENCODER:
  329. case COMTYPE_REC_PLAY:
  330. case COMTYPE_MPEGDECODER:
  331. type = "MSG";
  332. flags[0] = GPMQOver;
  333. flags[1] = GPMQFull;
  334. break;
  335. case COMTYPE_OSD:
  336. type = "OSD";
  337. flags[0] = OSDQOver;
  338. flags[1] = OSDQFull;
  339. break;
  340. case COMTYPE_MISC:
  341. if (FW_VERSION(av7110->arm_app) >= 0x261d) {
  342. type = "MSG";
  343. flags[0] = GPMQOver;
  344. flags[1] = GPMQBusy;
  345. }
  346. break;
  347. default:
  348. break;
  349. }
  350. if (type != NULL) {
  351. /* non-immediate COMMAND type */
  352. start = jiffies;
  353. for (;;) {
  354. err = time_after(jiffies, start + ARM_WAIT_FREE);
  355. stat = rdebi(av7110, DEBINOSWAP, MSGSTATE, 0, 2);
  356. if (stat & flags[0]) {
  357. printk(KERN_ERR "%s: %s QUEUE overflow\n",
  358. __func__, type);
  359. return -1;
  360. }
  361. if ((stat & flags[1]) == 0)
  362. break;
  363. if (err) {
  364. printk(KERN_ERR "%s: timeout waiting on busy %s QUEUE\n",
  365. __func__, type);
  366. av7110->arm_errors++;
  367. return -ETIMEDOUT;
  368. }
  369. msleep(1);
  370. }
  371. }
  372. for (i = 2; i < length; i++)
  373. wdebi(av7110, DEBINOSWAP, COMMAND + 2 * i, (u32) buf[i], 2);
  374. if (length)
  375. wdebi(av7110, DEBINOSWAP, COMMAND + 2, (u32) buf[1], 2);
  376. else
  377. wdebi(av7110, DEBINOSWAP, COMMAND + 2, 0, 2);
  378. wdebi(av7110, DEBINOSWAP, COMMAND, (u32) buf[0], 2);
  379. if (FW_VERSION(av7110->arm_app) <= 0x261f)
  380. wdebi(av7110, DEBINOSWAP, COM_IF_LOCK, 0x0000, 2);
  381. #ifdef COM_DEBUG
  382. start = jiffies;
  383. while (1) {
  384. err = time_after(jiffies, start + ARM_WAIT_FREE);
  385. if (rdebi(av7110, DEBINOSWAP, COMMAND, 0, 2) == 0)
  386. break;
  387. if (err) {
  388. printk(KERN_ERR "dvb-ttpci: %s(): timeout waiting for COMMAND %d to complete\n",
  389. __func__, (buf[0] >> 8) & 0xff);
  390. return -ETIMEDOUT;
  391. }
  392. msleep(1);
  393. }
  394. stat = rdebi(av7110, DEBINOSWAP, MSGSTATE, 0, 2);
  395. if (stat & GPMQOver) {
  396. printk(KERN_ERR "dvb-ttpci: %s(): GPMQOver\n", __func__);
  397. return -ENOSPC;
  398. }
  399. else if (stat & OSDQOver) {
  400. printk(KERN_ERR "dvb-ttpci: %s(): OSDQOver\n", __func__);
  401. return -ENOSPC;
  402. }
  403. #endif
  404. return 0;
  405. }
  406. static int av7110_send_fw_cmd(struct av7110 *av7110, u16* buf, int length)
  407. {
  408. int ret;
  409. // dprintk(4, "%p\n", av7110);
  410. if (!av7110->arm_ready) {
  411. dprintk(1, "arm not ready.\n");
  412. return -1;
  413. }
  414. if (mutex_lock_interruptible(&av7110->dcomlock))
  415. return -ERESTARTSYS;
  416. ret = __av7110_send_fw_cmd(av7110, buf, length);
  417. mutex_unlock(&av7110->dcomlock);
  418. if (ret && ret!=-ERESTARTSYS)
  419. printk(KERN_ERR "dvb-ttpci: %s(): av7110_send_fw_cmd error %d\n",
  420. __func__, ret);
  421. return ret;
  422. }
  423. int av7110_fw_cmd(struct av7110 *av7110, int type, int com, int num, ...)
  424. {
  425. va_list args;
  426. u16 buf[MAX_XFER_SIZE];
  427. int i, ret;
  428. // dprintk(4, "%p\n", av7110);
  429. if (2 + num > ARRAY_SIZE(buf)) {
  430. printk(KERN_WARNING
  431. "%s: %s len=%d is too big!\n",
  432. KBUILD_MODNAME, __func__, num);
  433. return -EINVAL;
  434. }
  435. buf[0] = ((type << 8) | com);
  436. buf[1] = num;
  437. if (num) {
  438. va_start(args, num);
  439. for (i = 0; i < num; i++)
  440. buf[i + 2] = va_arg(args, u32);
  441. va_end(args);
  442. }
  443. ret = av7110_send_fw_cmd(av7110, buf, num + 2);
  444. if (ret && ret != -ERESTARTSYS)
  445. printk(KERN_ERR "dvb-ttpci: av7110_fw_cmd error %d\n", ret);
  446. return ret;
  447. }
  448. #if 0
  449. int av7110_send_ci_cmd(struct av7110 *av7110, u8 subcom, u8 *buf, u8 len)
  450. {
  451. int i, ret;
  452. u16 cmd[18] = { ((COMTYPE_COMMON_IF << 8) + subcom),
  453. 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  454. dprintk(4, "%p\n", av7110);
  455. for(i = 0; i < len && i < 32; i++)
  456. {
  457. if(i % 2 == 0)
  458. cmd[(i / 2) + 2] = (u16)(buf[i]) << 8;
  459. else
  460. cmd[(i / 2) + 2] |= buf[i];
  461. }
  462. ret = av7110_send_fw_cmd(av7110, cmd, 18);
  463. if (ret && ret != -ERESTARTSYS)
  464. printk(KERN_ERR "dvb-ttpci: av7110_send_ci_cmd error %d\n", ret);
  465. return ret;
  466. }
  467. #endif /* 0 */
  468. int av7110_fw_request(struct av7110 *av7110, u16 *request_buf,
  469. int request_buf_len, u16 *reply_buf, int reply_buf_len)
  470. {
  471. int err;
  472. s16 i;
  473. unsigned long start;
  474. #ifdef COM_DEBUG
  475. u32 stat;
  476. #endif
  477. dprintk(4, "%p\n", av7110);
  478. if (!av7110->arm_ready) {
  479. dprintk(1, "arm not ready.\n");
  480. return -1;
  481. }
  482. if (mutex_lock_interruptible(&av7110->dcomlock))
  483. return -ERESTARTSYS;
  484. if ((err = __av7110_send_fw_cmd(av7110, request_buf, request_buf_len)) < 0) {
  485. mutex_unlock(&av7110->dcomlock);
  486. printk(KERN_ERR "dvb-ttpci: av7110_fw_request error %d\n", err);
  487. return err;
  488. }
  489. start = jiffies;
  490. while (1) {
  491. err = time_after(jiffies, start + ARM_WAIT_FREE);
  492. if (rdebi(av7110, DEBINOSWAP, COMMAND, 0, 2) == 0)
  493. break;
  494. if (err) {
  495. printk(KERN_ERR "%s: timeout waiting for COMMAND to complete\n", __func__);
  496. mutex_unlock(&av7110->dcomlock);
  497. return -ETIMEDOUT;
  498. }
  499. #ifdef _NOHANDSHAKE
  500. msleep(1);
  501. #endif
  502. }
  503. #ifndef _NOHANDSHAKE
  504. start = jiffies;
  505. while (1) {
  506. err = time_after(jiffies, start + ARM_WAIT_SHAKE);
  507. if (rdebi(av7110, DEBINOSWAP, HANDSHAKE_REG, 0, 2) == 0)
  508. break;
  509. if (err) {
  510. printk(KERN_ERR "%s: timeout waiting for HANDSHAKE_REG\n", __func__);
  511. mutex_unlock(&av7110->dcomlock);
  512. return -ETIMEDOUT;
  513. }
  514. msleep(1);
  515. }
  516. #endif
  517. #ifdef COM_DEBUG
  518. stat = rdebi(av7110, DEBINOSWAP, MSGSTATE, 0, 2);
  519. if (stat & GPMQOver) {
  520. printk(KERN_ERR "%s: GPMQOver\n", __func__);
  521. mutex_unlock(&av7110->dcomlock);
  522. return -1;
  523. }
  524. else if (stat & OSDQOver) {
  525. printk(KERN_ERR "%s: OSDQOver\n", __func__);
  526. mutex_unlock(&av7110->dcomlock);
  527. return -1;
  528. }
  529. #endif
  530. for (i = 0; i < reply_buf_len; i++)
  531. reply_buf[i] = rdebi(av7110, DEBINOSWAP, COM_BUFF + 2 * i, 0, 2);
  532. mutex_unlock(&av7110->dcomlock);
  533. return 0;
  534. }
  535. static int av7110_fw_query(struct av7110 *av7110, u16 tag, u16* buf, s16 length)
  536. {
  537. int ret;
  538. ret = av7110_fw_request(av7110, &tag, 0, buf, length);
  539. if (ret)
  540. printk(KERN_ERR "dvb-ttpci: av7110_fw_query error %d\n", ret);
  541. return ret;
  542. }
  543. /****************************************************************************
  544. * Firmware commands
  545. ****************************************************************************/
  546. /* get version of the firmware ROM, RTSL, video ucode and ARM application */
  547. int av7110_firmversion(struct av7110 *av7110)
  548. {
  549. u16 buf[20];
  550. u16 tag = ((COMTYPE_REQUEST << 8) + ReqVersion);
  551. dprintk(4, "%p\n", av7110);
  552. if (av7110_fw_query(av7110, tag, buf, 16)) {
  553. printk("dvb-ttpci: failed to boot firmware @ card %d\n",
  554. av7110->dvb_adapter.num);
  555. return -EIO;
  556. }
  557. av7110->arm_fw = (buf[0] << 16) + buf[1];
  558. av7110->arm_rtsl = (buf[2] << 16) + buf[3];
  559. av7110->arm_vid = (buf[4] << 16) + buf[5];
  560. av7110->arm_app = (buf[6] << 16) + buf[7];
  561. av7110->avtype = (buf[8] << 16) + buf[9];
  562. printk("dvb-ttpci: info @ card %d: firm %08x, rtsl %08x, vid %08x, app %08x\n",
  563. av7110->dvb_adapter.num, av7110->arm_fw,
  564. av7110->arm_rtsl, av7110->arm_vid, av7110->arm_app);
  565. /* print firmware capabilities */
  566. if (FW_CI_LL_SUPPORT(av7110->arm_app))
  567. printk("dvb-ttpci: firmware @ card %d supports CI link layer interface\n",
  568. av7110->dvb_adapter.num);
  569. else
  570. printk("dvb-ttpci: no firmware support for CI link layer interface @ card %d\n",
  571. av7110->dvb_adapter.num);
  572. return 0;
  573. }
  574. int av7110_diseqc_send(struct av7110 *av7110, int len, u8 *msg, unsigned long burst)
  575. {
  576. int i, ret;
  577. u16 buf[18] = { ((COMTYPE_AUDIODAC << 8) + SendDiSEqC),
  578. 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  579. dprintk(4, "%p\n", av7110);
  580. if (len > 10)
  581. len = 10;
  582. buf[1] = len + 2;
  583. buf[2] = len;
  584. if (burst != -1)
  585. buf[3] = burst ? 0x01 : 0x00;
  586. else
  587. buf[3] = 0xffff;
  588. for (i = 0; i < len; i++)
  589. buf[i + 4] = msg[i];
  590. ret = av7110_send_fw_cmd(av7110, buf, 18);
  591. if (ret && ret!=-ERESTARTSYS)
  592. printk(KERN_ERR "dvb-ttpci: av7110_diseqc_send error %d\n", ret);
  593. return ret;
  594. }
  595. #ifdef CONFIG_DVB_AV7110_OSD
  596. static inline int SetColorBlend(struct av7110 *av7110, u8 windownr)
  597. {
  598. return av7110_fw_cmd(av7110, COMTYPE_OSD, SetCBlend, 1, windownr);
  599. }
  600. static inline int SetBlend_(struct av7110 *av7110, u8 windownr,
  601. enum av7110_osd_palette_type colordepth, u16 index, u8 blending)
  602. {
  603. return av7110_fw_cmd(av7110, COMTYPE_OSD, SetBlend, 4,
  604. windownr, colordepth, index, blending);
  605. }
  606. static inline int SetColor_(struct av7110 *av7110, u8 windownr,
  607. enum av7110_osd_palette_type colordepth, u16 index, u16 colorhi, u16 colorlo)
  608. {
  609. return av7110_fw_cmd(av7110, COMTYPE_OSD, SetColor, 5,
  610. windownr, colordepth, index, colorhi, colorlo);
  611. }
  612. static inline int SetFont(struct av7110 *av7110, u8 windownr, u8 fontsize,
  613. u16 colorfg, u16 colorbg)
  614. {
  615. return av7110_fw_cmd(av7110, COMTYPE_OSD, Set_Font, 4,
  616. windownr, fontsize, colorfg, colorbg);
  617. }
  618. static int FlushText(struct av7110 *av7110)
  619. {
  620. unsigned long start;
  621. int err;
  622. if (mutex_lock_interruptible(&av7110->dcomlock))
  623. return -ERESTARTSYS;
  624. start = jiffies;
  625. while (1) {
  626. err = time_after(jiffies, start + ARM_WAIT_OSD);
  627. if (rdebi(av7110, DEBINOSWAP, BUFF1_BASE, 0, 2) == 0)
  628. break;
  629. if (err) {
  630. printk(KERN_ERR "dvb-ttpci: %s(): timeout waiting for BUFF1_BASE == 0\n",
  631. __func__);
  632. mutex_unlock(&av7110->dcomlock);
  633. return -ETIMEDOUT;
  634. }
  635. msleep(1);
  636. }
  637. mutex_unlock(&av7110->dcomlock);
  638. return 0;
  639. }
  640. static int WriteText(struct av7110 *av7110, u8 win, u16 x, u16 y, char *buf)
  641. {
  642. int i, ret;
  643. unsigned long start;
  644. int length = strlen(buf) + 1;
  645. u16 cbuf[5] = { (COMTYPE_OSD << 8) + DText, 3, win, x, y };
  646. if (mutex_lock_interruptible(&av7110->dcomlock))
  647. return -ERESTARTSYS;
  648. start = jiffies;
  649. while (1) {
  650. ret = time_after(jiffies, start + ARM_WAIT_OSD);
  651. if (rdebi(av7110, DEBINOSWAP, BUFF1_BASE, 0, 2) == 0)
  652. break;
  653. if (ret) {
  654. printk(KERN_ERR "dvb-ttpci: %s: timeout waiting for BUFF1_BASE == 0\n",
  655. __func__);
  656. mutex_unlock(&av7110->dcomlock);
  657. return -ETIMEDOUT;
  658. }
  659. msleep(1);
  660. }
  661. #ifndef _NOHANDSHAKE
  662. start = jiffies;
  663. while (1) {
  664. ret = time_after(jiffies, start + ARM_WAIT_SHAKE);
  665. if (rdebi(av7110, DEBINOSWAP, HANDSHAKE_REG, 0, 2) == 0)
  666. break;
  667. if (ret) {
  668. printk(KERN_ERR "dvb-ttpci: %s: timeout waiting for HANDSHAKE_REG\n",
  669. __func__);
  670. mutex_unlock(&av7110->dcomlock);
  671. return -ETIMEDOUT;
  672. }
  673. msleep(1);
  674. }
  675. #endif
  676. for (i = 0; i < length / 2; i++)
  677. wdebi(av7110, DEBINOSWAP, BUFF1_BASE + i * 2,
  678. swab16(*(u16 *)(buf + 2 * i)), 2);
  679. if (length & 1)
  680. wdebi(av7110, DEBINOSWAP, BUFF1_BASE + i * 2, 0, 2);
  681. ret = __av7110_send_fw_cmd(av7110, cbuf, 5);
  682. mutex_unlock(&av7110->dcomlock);
  683. if (ret && ret!=-ERESTARTSYS)
  684. printk(KERN_ERR "dvb-ttpci: WriteText error %d\n", ret);
  685. return ret;
  686. }
  687. static inline int DrawLine(struct av7110 *av7110, u8 windownr,
  688. u16 x, u16 y, u16 dx, u16 dy, u16 color)
  689. {
  690. return av7110_fw_cmd(av7110, COMTYPE_OSD, DLine, 6,
  691. windownr, x, y, dx, dy, color);
  692. }
  693. static inline int DrawBlock(struct av7110 *av7110, u8 windownr,
  694. u16 x, u16 y, u16 dx, u16 dy, u16 color)
  695. {
  696. return av7110_fw_cmd(av7110, COMTYPE_OSD, DBox, 6,
  697. windownr, x, y, dx, dy, color);
  698. }
  699. static inline int HideWindow(struct av7110 *av7110, u8 windownr)
  700. {
  701. return av7110_fw_cmd(av7110, COMTYPE_OSD, WHide, 1, windownr);
  702. }
  703. static inline int MoveWindowRel(struct av7110 *av7110, u8 windownr, u16 x, u16 y)
  704. {
  705. return av7110_fw_cmd(av7110, COMTYPE_OSD, WMoveD, 3, windownr, x, y);
  706. }
  707. static inline int MoveWindowAbs(struct av7110 *av7110, u8 windownr, u16 x, u16 y)
  708. {
  709. return av7110_fw_cmd(av7110, COMTYPE_OSD, WMoveA, 3, windownr, x, y);
  710. }
  711. static inline int DestroyOSDWindow(struct av7110 *av7110, u8 windownr)
  712. {
  713. return av7110_fw_cmd(av7110, COMTYPE_OSD, WDestroy, 1, windownr);
  714. }
  715. static inline int CreateOSDWindow(struct av7110 *av7110, u8 windownr,
  716. osd_raw_window_t disptype,
  717. u16 width, u16 height)
  718. {
  719. return av7110_fw_cmd(av7110, COMTYPE_OSD, WCreate, 4,
  720. windownr, disptype, width, height);
  721. }
  722. static enum av7110_osd_palette_type bpp2pal[8] = {
  723. Pal1Bit, Pal2Bit, 0, Pal4Bit, 0, 0, 0, Pal8Bit
  724. };
  725. static osd_raw_window_t bpp2bit[8] = {
  726. OSD_BITMAP1, OSD_BITMAP2, 0, OSD_BITMAP4, 0, 0, 0, OSD_BITMAP8
  727. };
  728. static inline int WaitUntilBmpLoaded(struct av7110 *av7110)
  729. {
  730. int ret = wait_event_timeout(av7110->bmpq,
  731. av7110->bmp_state != BMP_LOADING, 10*HZ);
  732. if (ret == 0) {
  733. printk("dvb-ttpci: warning: timeout waiting in LoadBitmap: %d, %d\n",
  734. ret, av7110->bmp_state);
  735. av7110->bmp_state = BMP_NONE;
  736. return -ETIMEDOUT;
  737. }
  738. return 0;
  739. }
  740. static inline int LoadBitmap(struct av7110 *av7110,
  741. u16 dx, u16 dy, int inc, u8 __user * data)
  742. {
  743. u16 format;
  744. int bpp;
  745. int i;
  746. int d, delta;
  747. u8 c;
  748. int ret;
  749. dprintk(4, "%p\n", av7110);
  750. format = bpp2bit[av7110->osdbpp[av7110->osdwin]];
  751. av7110->bmp_state = BMP_LOADING;
  752. if (format == OSD_BITMAP8) {
  753. bpp=8; delta = 1;
  754. } else if (format == OSD_BITMAP4) {
  755. bpp=4; delta = 2;
  756. } else if (format == OSD_BITMAP2) {
  757. bpp=2; delta = 4;
  758. } else if (format == OSD_BITMAP1) {
  759. bpp=1; delta = 8;
  760. } else {
  761. av7110->bmp_state = BMP_NONE;
  762. return -EINVAL;
  763. }
  764. av7110->bmplen = ((dx * dy * bpp + 7) & ~7) / 8;
  765. av7110->bmpp = 0;
  766. if (av7110->bmplen > 32768) {
  767. av7110->bmp_state = BMP_NONE;
  768. return -EINVAL;
  769. }
  770. for (i = 0; i < dy; i++) {
  771. if (copy_from_user(av7110->bmpbuf + 1024 + i * dx, data + i * inc, dx)) {
  772. av7110->bmp_state = BMP_NONE;
  773. return -EINVAL;
  774. }
  775. }
  776. if (format != OSD_BITMAP8) {
  777. for (i = 0; i < dx * dy / delta; i++) {
  778. c = ((u8 *)av7110->bmpbuf)[1024 + i * delta + delta - 1];
  779. for (d = delta - 2; d >= 0; d--) {
  780. c |= (((u8 *)av7110->bmpbuf)[1024 + i * delta + d]
  781. << ((delta - d - 1) * bpp));
  782. ((u8 *)av7110->bmpbuf)[1024 + i] = c;
  783. }
  784. }
  785. }
  786. av7110->bmplen += 1024;
  787. dprintk(4, "av7110_fw_cmd: LoadBmp size %d\n", av7110->bmplen);
  788. ret = av7110_fw_cmd(av7110, COMTYPE_OSD, LoadBmp, 3, format, dx, dy);
  789. if (!ret)
  790. ret = WaitUntilBmpLoaded(av7110);
  791. return ret;
  792. }
  793. static int BlitBitmap(struct av7110 *av7110, u16 x, u16 y)
  794. {
  795. dprintk(4, "%p\n", av7110);
  796. return av7110_fw_cmd(av7110, COMTYPE_OSD, BlitBmp, 4, av7110->osdwin, x, y, 0);
  797. }
  798. static inline int ReleaseBitmap(struct av7110 *av7110)
  799. {
  800. dprintk(4, "%p\n", av7110);
  801. if (av7110->bmp_state != BMP_LOADED && FW_VERSION(av7110->arm_app) < 0x261e)
  802. return -1;
  803. if (av7110->bmp_state == BMP_LOADING)
  804. dprintk(1,"ReleaseBitmap called while BMP_LOADING\n");
  805. av7110->bmp_state = BMP_NONE;
  806. return av7110_fw_cmd(av7110, COMTYPE_OSD, ReleaseBmp, 0);
  807. }
  808. static u32 RGB2YUV(u16 R, u16 G, u16 B)
  809. {
  810. u16 y, u, v;
  811. u16 Y, Cr, Cb;
  812. y = R * 77 + G * 150 + B * 29; /* Luma=0.299R+0.587G+0.114B 0..65535 */
  813. u = 2048 + B * 8 -(y >> 5); /* Cr 0..4095 */
  814. v = 2048 + R * 8 -(y >> 5); /* Cb 0..4095 */
  815. Y = y / 256;
  816. Cb = u / 16;
  817. Cr = v / 16;
  818. return Cr | (Cb << 16) | (Y << 8);
  819. }
  820. static int OSDSetColor(struct av7110 *av7110, u8 color, u8 r, u8 g, u8 b, u8 blend)
  821. {
  822. int ret;
  823. u16 ch, cl;
  824. u32 yuv;
  825. yuv = blend ? RGB2YUV(r,g,b) : 0;
  826. cl = (yuv & 0xffff);
  827. ch = ((yuv >> 16) & 0xffff);
  828. ret = SetColor_(av7110, av7110->osdwin, bpp2pal[av7110->osdbpp[av7110->osdwin]],
  829. color, ch, cl);
  830. if (!ret)
  831. ret = SetBlend_(av7110, av7110->osdwin, bpp2pal[av7110->osdbpp[av7110->osdwin]],
  832. color, ((blend >> 4) & 0x0f));
  833. return ret;
  834. }
  835. static int OSDSetPalette(struct av7110 *av7110, u32 __user * colors, u8 first, u8 last)
  836. {
  837. int i;
  838. int length = last - first + 1;
  839. if (length * 4 > DATA_BUFF3_SIZE)
  840. return -EINVAL;
  841. for (i = 0; i < length; i++) {
  842. u32 color, blend, yuv;
  843. if (get_user(color, colors + i))
  844. return -EFAULT;
  845. blend = (color & 0xF0000000) >> 4;
  846. yuv = blend ? RGB2YUV(color & 0xFF, (color >> 8) & 0xFF,
  847. (color >> 16) & 0xFF) | blend : 0;
  848. yuv = ((yuv & 0xFFFF0000) >> 16) | ((yuv & 0x0000FFFF) << 16);
  849. wdebi(av7110, DEBINOSWAP, DATA_BUFF3_BASE + i * 4, yuv, 4);
  850. }
  851. return av7110_fw_cmd(av7110, COMTYPE_OSD, Set_Palette, 4,
  852. av7110->osdwin,
  853. bpp2pal[av7110->osdbpp[av7110->osdwin]],
  854. first, last);
  855. }
  856. static int OSDSetBlock(struct av7110 *av7110, int x0, int y0,
  857. int x1, int y1, int inc, u8 __user * data)
  858. {
  859. uint w, h, bpp, bpl, size, lpb, bnum, brest;
  860. int i;
  861. int rc,release_rc;
  862. w = x1 - x0 + 1;
  863. h = y1 - y0 + 1;
  864. if (inc <= 0)
  865. inc = w;
  866. if (w <= 0 || w > 720 || h <= 0 || h > 576)
  867. return -EINVAL;
  868. bpp = av7110->osdbpp[av7110->osdwin] + 1;
  869. bpl = ((w * bpp + 7) & ~7) / 8;
  870. size = h * bpl;
  871. lpb = (32 * 1024) / bpl;
  872. bnum = size / (lpb * bpl);
  873. brest = size - bnum * lpb * bpl;
  874. if (av7110->bmp_state == BMP_LOADING) {
  875. /* possible if syscall is repeated by -ERESTARTSYS and if firmware cannot abort */
  876. BUG_ON (FW_VERSION(av7110->arm_app) >= 0x261e);
  877. rc = WaitUntilBmpLoaded(av7110);
  878. if (rc)
  879. return rc;
  880. /* just continue. This should work for all fw versions
  881. * if bnum==1 && !brest && LoadBitmap was successful
  882. */
  883. }
  884. rc = 0;
  885. for (i = 0; i < bnum; i++) {
  886. rc = LoadBitmap(av7110, w, lpb, inc, data);
  887. if (rc)
  888. break;
  889. rc = BlitBitmap(av7110, x0, y0 + i * lpb);
  890. if (rc)
  891. break;
  892. data += lpb * inc;
  893. }
  894. if (!rc && brest) {
  895. rc = LoadBitmap(av7110, w, brest / bpl, inc, data);
  896. if (!rc)
  897. rc = BlitBitmap(av7110, x0, y0 + bnum * lpb);
  898. }
  899. release_rc = ReleaseBitmap(av7110);
  900. if (!rc)
  901. rc = release_rc;
  902. if (rc)
  903. dprintk(1,"returns %d\n",rc);
  904. return rc;
  905. }
  906. int av7110_osd_cmd(struct av7110 *av7110, osd_cmd_t *dc)
  907. {
  908. int ret;
  909. if (mutex_lock_interruptible(&av7110->osd_mutex))
  910. return -ERESTARTSYS;
  911. switch (dc->cmd) {
  912. case OSD_Close:
  913. ret = DestroyOSDWindow(av7110, av7110->osdwin);
  914. break;
  915. case OSD_Open:
  916. av7110->osdbpp[av7110->osdwin] = (dc->color - 1) & 7;
  917. ret = CreateOSDWindow(av7110, av7110->osdwin,
  918. bpp2bit[av7110->osdbpp[av7110->osdwin]],
  919. dc->x1 - dc->x0 + 1, dc->y1 - dc->y0 + 1);
  920. if (ret)
  921. break;
  922. if (!dc->data) {
  923. ret = MoveWindowAbs(av7110, av7110->osdwin, dc->x0, dc->y0);
  924. if (ret)
  925. break;
  926. ret = SetColorBlend(av7110, av7110->osdwin);
  927. }
  928. break;
  929. case OSD_Show:
  930. ret = MoveWindowRel(av7110, av7110->osdwin, 0, 0);
  931. break;
  932. case OSD_Hide:
  933. ret = HideWindow(av7110, av7110->osdwin);
  934. break;
  935. case OSD_Clear:
  936. ret = DrawBlock(av7110, av7110->osdwin, 0, 0, 720, 576, 0);
  937. break;
  938. case OSD_Fill:
  939. ret = DrawBlock(av7110, av7110->osdwin, 0, 0, 720, 576, dc->color);
  940. break;
  941. case OSD_SetColor:
  942. ret = OSDSetColor(av7110, dc->color, dc->x0, dc->y0, dc->x1, dc->y1);
  943. break;
  944. case OSD_SetPalette:
  945. if (FW_VERSION(av7110->arm_app) >= 0x2618)
  946. ret = OSDSetPalette(av7110, dc->data, dc->color, dc->x0);
  947. else {
  948. int i, len = dc->x0-dc->color+1;
  949. u8 __user *colors = (u8 __user *)dc->data;
  950. u8 r, g = 0, b = 0, blend = 0;
  951. ret = 0;
  952. for (i = 0; i<len; i++) {
  953. if (get_user(r, colors + i * 4) ||
  954. get_user(g, colors + i * 4 + 1) ||
  955. get_user(b, colors + i * 4 + 2) ||
  956. get_user(blend, colors + i * 4 + 3)) {
  957. ret = -EFAULT;
  958. break;
  959. }
  960. ret = OSDSetColor(av7110, dc->color + i, r, g, b, blend);
  961. if (ret)
  962. break;
  963. }
  964. }
  965. break;
  966. case OSD_SetPixel:
  967. ret = DrawLine(av7110, av7110->osdwin,
  968. dc->x0, dc->y0, 0, 0, dc->color);
  969. break;
  970. case OSD_SetRow:
  971. dc->y1 = dc->y0;
  972. /* fall through */
  973. case OSD_SetBlock:
  974. ret = OSDSetBlock(av7110, dc->x0, dc->y0, dc->x1, dc->y1, dc->color, dc->data);
  975. break;
  976. case OSD_FillRow:
  977. ret = DrawBlock(av7110, av7110->osdwin, dc->x0, dc->y0,
  978. dc->x1-dc->x0+1, dc->y1, dc->color);
  979. break;
  980. case OSD_FillBlock:
  981. ret = DrawBlock(av7110, av7110->osdwin, dc->x0, dc->y0,
  982. dc->x1 - dc->x0 + 1, dc->y1 - dc->y0 + 1, dc->color);
  983. break;
  984. case OSD_Line:
  985. ret = DrawLine(av7110, av7110->osdwin,
  986. dc->x0, dc->y0, dc->x1 - dc->x0, dc->y1 - dc->y0, dc->color);
  987. break;
  988. case OSD_Text:
  989. {
  990. char textbuf[240];
  991. if (strncpy_from_user(textbuf, dc->data, 240) < 0) {
  992. ret = -EFAULT;
  993. break;
  994. }
  995. textbuf[239] = 0;
  996. if (dc->x1 > 3)
  997. dc->x1 = 3;
  998. ret = SetFont(av7110, av7110->osdwin, dc->x1,
  999. (u16) (dc->color & 0xffff), (u16) (dc->color >> 16));
  1000. if (!ret)
  1001. ret = FlushText(av7110);
  1002. if (!ret)
  1003. ret = WriteText(av7110, av7110->osdwin, dc->x0, dc->y0, textbuf);
  1004. break;
  1005. }
  1006. case OSD_SetWindow:
  1007. if (dc->x0 < 1 || dc->x0 > 7)
  1008. ret = -EINVAL;
  1009. else {
  1010. av7110->osdwin = dc->x0;
  1011. ret = 0;
  1012. }
  1013. break;
  1014. case OSD_MoveWindow:
  1015. ret = MoveWindowAbs(av7110, av7110->osdwin, dc->x0, dc->y0);
  1016. if (!ret)
  1017. ret = SetColorBlend(av7110, av7110->osdwin);
  1018. break;
  1019. case OSD_OpenRaw:
  1020. if (dc->color < OSD_BITMAP1 || dc->color > OSD_CURSOR) {
  1021. ret = -EINVAL;
  1022. break;
  1023. }
  1024. if (dc->color >= OSD_BITMAP1 && dc->color <= OSD_BITMAP8HR)
  1025. av7110->osdbpp[av7110->osdwin] = (1 << (dc->color & 3)) - 1;
  1026. else
  1027. av7110->osdbpp[av7110->osdwin] = 0;
  1028. ret = CreateOSDWindow(av7110, av7110->osdwin, (osd_raw_window_t)dc->color,
  1029. dc->x1 - dc->x0 + 1, dc->y1 - dc->y0 + 1);
  1030. if (ret)
  1031. break;
  1032. if (!dc->data) {
  1033. ret = MoveWindowAbs(av7110, av7110->osdwin, dc->x0, dc->y0);
  1034. if (!ret)
  1035. ret = SetColorBlend(av7110, av7110->osdwin);
  1036. }
  1037. break;
  1038. default:
  1039. ret = -EINVAL;
  1040. break;
  1041. }
  1042. mutex_unlock(&av7110->osd_mutex);
  1043. if (ret==-ERESTARTSYS)
  1044. dprintk(1, "av7110_osd_cmd(%d) returns with -ERESTARTSYS\n",dc->cmd);
  1045. else if (ret)
  1046. dprintk(1, "av7110_osd_cmd(%d) returns with %d\n",dc->cmd,ret);
  1047. return ret;
  1048. }
  1049. int av7110_osd_capability(struct av7110 *av7110, osd_cap_t *cap)
  1050. {
  1051. switch (cap->cmd) {
  1052. case OSD_CAP_MEMSIZE:
  1053. if (FW_4M_SDRAM(av7110->arm_app))
  1054. cap->val = 1000000;
  1055. else
  1056. cap->val = 92000;
  1057. return 0;
  1058. default:
  1059. return -EINVAL;
  1060. }
  1061. }
  1062. #endif /* CONFIG_DVB_AV7110_OSD */