av7110_hw.c 31 KB

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