av7110_hw.c 32 KB

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