av7110_hw.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172
  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 -1;
  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 -1;
  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 -1;
  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 -1;
  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 -1;
  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 -1;
  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 -1;
  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 -1;
  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 -1;
  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 to complete\n",
  376. __FUNCTION__);
  377. return -ETIMEDOUT;
  378. }
  379. }
  380. stat = rdebi(av7110, DEBINOSWAP, MSGSTATE, 0, 2);
  381. if (stat & GPMQOver) {
  382. printk(KERN_ERR "dvb-ttpci: %s(): GPMQOver\n", __FUNCTION__);
  383. return -ENOSPC;
  384. }
  385. else if (stat & OSDQOver) {
  386. printk(KERN_ERR "dvb-ttpci: %s(): OSDQOver\n", __FUNCTION__);
  387. return -ENOSPC;
  388. }
  389. #endif
  390. return 0;
  391. }
  392. static int av7110_send_fw_cmd(struct av7110 *av7110, u16* buf, int length)
  393. {
  394. int ret;
  395. // dprintk(4, "%p\n", av7110);
  396. if (!av7110->arm_ready) {
  397. dprintk(1, "arm not ready.\n");
  398. return -1;
  399. }
  400. if (down_interruptible(&av7110->dcomlock))
  401. return -ERESTARTSYS;
  402. ret = __av7110_send_fw_cmd(av7110, buf, length);
  403. up(&av7110->dcomlock);
  404. if (ret)
  405. printk(KERN_ERR "dvb-ttpci: %s(): av7110_send_fw_cmd error %d\n",
  406. __FUNCTION__, ret);
  407. return ret;
  408. }
  409. int av7110_fw_cmd(struct av7110 *av7110, int type, int com, int num, ...)
  410. {
  411. va_list args;
  412. u16 buf[num + 2];
  413. int i, ret;
  414. // dprintk(4, "%p\n", av7110);
  415. buf[0] = ((type << 8) | com);
  416. buf[1] = num;
  417. if (num) {
  418. va_start(args, num);
  419. for (i = 0; i < num; i++)
  420. buf[i + 2] = va_arg(args, u32);
  421. va_end(args);
  422. }
  423. ret = av7110_send_fw_cmd(av7110, buf, num + 2);
  424. if (ret)
  425. printk(KERN_ERR "dvb-ttpci: av7110_fw_cmd error %d\n", ret);
  426. return ret;
  427. }
  428. #if 0
  429. int av7110_send_ci_cmd(struct av7110 *av7110, u8 subcom, u8 *buf, u8 len)
  430. {
  431. int i, ret;
  432. u16 cmd[18] = { ((COMTYPE_COMMON_IF << 8) + subcom),
  433. 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  434. dprintk(4, "%p\n", av7110);
  435. for(i = 0; i < len && i < 32; i++)
  436. {
  437. if(i % 2 == 0)
  438. cmd[(i / 2) + 2] = (u16)(buf[i]) << 8;
  439. else
  440. cmd[(i / 2) + 2] |= buf[i];
  441. }
  442. ret = av7110_send_fw_cmd(av7110, cmd, 18);
  443. if (ret)
  444. printk(KERN_ERR "dvb-ttpci: av7110_send_ci_cmd error %d\n", ret);
  445. return ret;
  446. }
  447. #endif /* 0 */
  448. int av7110_fw_request(struct av7110 *av7110, u16 *request_buf,
  449. int request_buf_len, u16 *reply_buf, int reply_buf_len)
  450. {
  451. int err;
  452. s16 i;
  453. unsigned long start;
  454. #ifdef COM_DEBUG
  455. u32 stat;
  456. #endif
  457. dprintk(4, "%p\n", av7110);
  458. if (!av7110->arm_ready) {
  459. dprintk(1, "arm not ready.\n");
  460. return -1;
  461. }
  462. if (down_interruptible(&av7110->dcomlock))
  463. return -ERESTARTSYS;
  464. if ((err = __av7110_send_fw_cmd(av7110, request_buf, request_buf_len)) < 0) {
  465. up(&av7110->dcomlock);
  466. printk(KERN_ERR "dvb-ttpci: av7110_fw_request error %d\n", err);
  467. return err;
  468. }
  469. start = jiffies;
  470. while (rdebi(av7110, DEBINOSWAP, COMMAND, 0, 2)) {
  471. #ifdef _NOHANDSHAKE
  472. msleep(1);
  473. #endif
  474. if (time_after(jiffies, start + ARM_WAIT_FREE)) {
  475. printk(KERN_ERR "%s: timeout waiting for COMMAND to complete\n", __FUNCTION__);
  476. up(&av7110->dcomlock);
  477. return -1;
  478. }
  479. }
  480. #ifndef _NOHANDSHAKE
  481. start = jiffies;
  482. while (rdebi(av7110, DEBINOSWAP, HANDSHAKE_REG, 0, 2 )) {
  483. msleep(1);
  484. if (time_after(jiffies, start + ARM_WAIT_SHAKE)) {
  485. printk(KERN_ERR "%s: timeout waiting for HANDSHAKE_REG\n", __FUNCTION__);
  486. up(&av7110->dcomlock);
  487. return -1;
  488. }
  489. }
  490. #endif
  491. #ifdef COM_DEBUG
  492. stat = rdebi(av7110, DEBINOSWAP, MSGSTATE, 0, 2);
  493. if (stat & GPMQOver) {
  494. printk(KERN_ERR "%s: GPMQOver\n", __FUNCTION__);
  495. up(&av7110->dcomlock);
  496. return -1;
  497. }
  498. else if (stat & OSDQOver) {
  499. printk(KERN_ERR "%s: OSDQOver\n", __FUNCTION__);
  500. up(&av7110->dcomlock);
  501. return -1;
  502. }
  503. #endif
  504. for (i = 0; i < reply_buf_len; i++)
  505. reply_buf[i] = rdebi(av7110, DEBINOSWAP, COM_BUFF + 2 * i, 0, 2);
  506. up(&av7110->dcomlock);
  507. return 0;
  508. }
  509. static int av7110_fw_query(struct av7110 *av7110, u16 tag, u16* buf, s16 length)
  510. {
  511. int ret;
  512. ret = av7110_fw_request(av7110, &tag, 0, buf, length);
  513. if (ret)
  514. printk(KERN_ERR "dvb-ttpci: av7110_fw_query error %d\n", ret);
  515. return ret;
  516. }
  517. /****************************************************************************
  518. * Firmware commands
  519. ****************************************************************************/
  520. /* get version of the firmware ROM, RTSL, video ucode and ARM application */
  521. int av7110_firmversion(struct av7110 *av7110)
  522. {
  523. u16 buf[20];
  524. u16 tag = ((COMTYPE_REQUEST << 8) + ReqVersion);
  525. dprintk(4, "%p\n", av7110);
  526. if (av7110_fw_query(av7110, tag, buf, 16)) {
  527. printk("dvb-ttpci: failed to boot firmware @ card %d\n",
  528. av7110->dvb_adapter.num);
  529. return -EIO;
  530. }
  531. av7110->arm_fw = (buf[0] << 16) + buf[1];
  532. av7110->arm_rtsl = (buf[2] << 16) + buf[3];
  533. av7110->arm_vid = (buf[4] << 16) + buf[5];
  534. av7110->arm_app = (buf[6] << 16) + buf[7];
  535. av7110->avtype = (buf[8] << 16) + buf[9];
  536. printk("dvb-ttpci: info @ card %d: firm %08x, rtsl %08x, vid %08x, app %08x\n",
  537. av7110->dvb_adapter.num, av7110->arm_fw,
  538. av7110->arm_rtsl, av7110->arm_vid, av7110->arm_app);
  539. /* print firmware capabilities */
  540. if (FW_CI_LL_SUPPORT(av7110->arm_app))
  541. printk("dvb-ttpci: firmware @ card %d supports CI link layer interface\n",
  542. av7110->dvb_adapter.num);
  543. else
  544. printk("dvb-ttpci: no firmware support for CI link layer interface @ card %d\n",
  545. av7110->dvb_adapter.num);
  546. return 0;
  547. }
  548. int av7110_diseqc_send(struct av7110 *av7110, int len, u8 *msg, unsigned long burst)
  549. {
  550. int i, ret;
  551. u16 buf[18] = { ((COMTYPE_AUDIODAC << 8) + SendDiSEqC),
  552. 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  553. dprintk(4, "%p\n", av7110);
  554. if (len > 10)
  555. len = 10;
  556. buf[1] = len + 2;
  557. buf[2] = len;
  558. if (burst != -1)
  559. buf[3] = burst ? 0x01 : 0x00;
  560. else
  561. buf[3] = 0xffff;
  562. for (i = 0; i < len; i++)
  563. buf[i + 4] = msg[i];
  564. if ((ret = av7110_send_fw_cmd(av7110, buf, 18)))
  565. printk(KERN_ERR "dvb-ttpci: av7110_diseqc_send error %d\n", ret);
  566. return 0;
  567. }
  568. #ifdef CONFIG_DVB_AV7110_OSD
  569. static inline int SetColorBlend(struct av7110 *av7110, u8 windownr)
  570. {
  571. return av7110_fw_cmd(av7110, COMTYPE_OSD, SetCBlend, 1, windownr);
  572. }
  573. static inline int SetBlend_(struct av7110 *av7110, u8 windownr,
  574. enum av7110_osd_palette_type colordepth, u16 index, u8 blending)
  575. {
  576. return av7110_fw_cmd(av7110, COMTYPE_OSD, SetBlend, 4,
  577. windownr, colordepth, index, blending);
  578. }
  579. static inline int SetColor_(struct av7110 *av7110, u8 windownr,
  580. enum av7110_osd_palette_type colordepth, u16 index, u16 colorhi, u16 colorlo)
  581. {
  582. return av7110_fw_cmd(av7110, COMTYPE_OSD, SetColor, 5,
  583. windownr, colordepth, index, colorhi, colorlo);
  584. }
  585. static inline int SetFont(struct av7110 *av7110, u8 windownr, u8 fontsize,
  586. u16 colorfg, u16 colorbg)
  587. {
  588. return av7110_fw_cmd(av7110, COMTYPE_OSD, Set_Font, 4,
  589. windownr, fontsize, colorfg, colorbg);
  590. }
  591. static int FlushText(struct av7110 *av7110)
  592. {
  593. unsigned long start;
  594. if (down_interruptible(&av7110->dcomlock))
  595. return -ERESTARTSYS;
  596. start = jiffies;
  597. while (rdebi(av7110, DEBINOSWAP, BUFF1_BASE, 0, 2)) {
  598. msleep(1);
  599. if (time_after(jiffies, start + ARM_WAIT_OSD)) {
  600. printk(KERN_ERR "dvb-ttpci: %s(): timeout waiting for BUFF1_BASE == 0\n",
  601. __FUNCTION__);
  602. up(&av7110->dcomlock);
  603. return -1;
  604. }
  605. }
  606. up(&av7110->dcomlock);
  607. return 0;
  608. }
  609. static int WriteText(struct av7110 *av7110, u8 win, u16 x, u16 y, u8* buf)
  610. {
  611. int i, ret;
  612. unsigned long start;
  613. int length = strlen(buf) + 1;
  614. u16 cbuf[5] = { (COMTYPE_OSD << 8) + DText, 3, win, x, y };
  615. if (down_interruptible(&av7110->dcomlock))
  616. return -ERESTARTSYS;
  617. start = jiffies;
  618. while (rdebi(av7110, DEBINOSWAP, BUFF1_BASE, 0, 2)) {
  619. msleep(1);
  620. if (time_after(jiffies, start + ARM_WAIT_OSD)) {
  621. printk(KERN_ERR "dvb-ttpci: %s: timeout waiting for BUFF1_BASE == 0\n",
  622. __FUNCTION__);
  623. up(&av7110->dcomlock);
  624. return -1;
  625. }
  626. }
  627. #ifndef _NOHANDSHAKE
  628. start = jiffies;
  629. while (rdebi(av7110, DEBINOSWAP, HANDSHAKE_REG, 0, 2)) {
  630. msleep(1);
  631. if (time_after(jiffies, start + ARM_WAIT_SHAKE)) {
  632. printk(KERN_ERR "dvb-ttpci: %s: timeout waiting for HANDSHAKE_REG\n",
  633. __FUNCTION__);
  634. up(&av7110->dcomlock);
  635. return -1;
  636. }
  637. }
  638. #endif
  639. for (i = 0; i < length / 2; i++)
  640. wdebi(av7110, DEBINOSWAP, BUFF1_BASE + i * 2,
  641. swab16(*(u16 *)(buf + 2 * i)), 2);
  642. if (length & 1)
  643. wdebi(av7110, DEBINOSWAP, BUFF1_BASE + i * 2, 0, 2);
  644. ret = __av7110_send_fw_cmd(av7110, cbuf, 5);
  645. up(&av7110->dcomlock);
  646. if (ret)
  647. printk(KERN_ERR "dvb-ttpci: WriteText error %d\n", ret);
  648. return ret;
  649. }
  650. static inline int DrawLine(struct av7110 *av7110, u8 windownr,
  651. u16 x, u16 y, u16 dx, u16 dy, u16 color)
  652. {
  653. return av7110_fw_cmd(av7110, COMTYPE_OSD, DLine, 6,
  654. windownr, x, y, dx, dy, color);
  655. }
  656. static inline int DrawBlock(struct av7110 *av7110, u8 windownr,
  657. u16 x, u16 y, u16 dx, u16 dy, u16 color)
  658. {
  659. return av7110_fw_cmd(av7110, COMTYPE_OSD, DBox, 6,
  660. windownr, x, y, dx, dy, color);
  661. }
  662. static inline int HideWindow(struct av7110 *av7110, u8 windownr)
  663. {
  664. return av7110_fw_cmd(av7110, COMTYPE_OSD, WHide, 1, windownr);
  665. }
  666. static inline int MoveWindowRel(struct av7110 *av7110, u8 windownr, u16 x, u16 y)
  667. {
  668. return av7110_fw_cmd(av7110, COMTYPE_OSD, WMoveD, 3, windownr, x, y);
  669. }
  670. static inline int MoveWindowAbs(struct av7110 *av7110, u8 windownr, u16 x, u16 y)
  671. {
  672. return av7110_fw_cmd(av7110, COMTYPE_OSD, WMoveA, 3, windownr, x, y);
  673. }
  674. static inline int DestroyOSDWindow(struct av7110 *av7110, u8 windownr)
  675. {
  676. return av7110_fw_cmd(av7110, COMTYPE_OSD, WDestroy, 1, windownr);
  677. }
  678. static inline int CreateOSDWindow(struct av7110 *av7110, u8 windownr,
  679. osd_raw_window_t disptype,
  680. u16 width, u16 height)
  681. {
  682. return av7110_fw_cmd(av7110, COMTYPE_OSD, WCreate, 4,
  683. windownr, disptype, width, height);
  684. }
  685. static enum av7110_osd_palette_type bpp2pal[8] = {
  686. Pal1Bit, Pal2Bit, 0, Pal4Bit, 0, 0, 0, Pal8Bit
  687. };
  688. static osd_raw_window_t bpp2bit[8] = {
  689. OSD_BITMAP1, OSD_BITMAP2, 0, OSD_BITMAP4, 0, 0, 0, OSD_BITMAP8
  690. };
  691. static inline int LoadBitmap(struct av7110 *av7110, u16 format,
  692. u16 dx, u16 dy, int inc, u8 __user * data)
  693. {
  694. int bpp;
  695. int i;
  696. int d, delta;
  697. u8 c;
  698. int ret;
  699. dprintk(4, "%p\n", av7110);
  700. ret = wait_event_interruptible_timeout(av7110->bmpq, av7110->bmp_state != BMP_LOADING, HZ);
  701. if (ret == -ERESTARTSYS || ret == 0) {
  702. printk("dvb-ttpci: warning: timeout waiting in LoadBitmap: %d, %d\n",
  703. ret, av7110->bmp_state);
  704. av7110->bmp_state = BMP_NONE;
  705. return -1;
  706. }
  707. BUG_ON (av7110->bmp_state == BMP_LOADING);
  708. av7110->bmp_state = BMP_LOADING;
  709. if (format == OSD_BITMAP8) {
  710. bpp=8; delta = 1;
  711. } else if (format == OSD_BITMAP4) {
  712. bpp=4; delta = 2;
  713. } else if (format == OSD_BITMAP2) {
  714. bpp=2; delta = 4;
  715. } else if (format == OSD_BITMAP1) {
  716. bpp=1; delta = 8;
  717. } else {
  718. av7110->bmp_state = BMP_NONE;
  719. return -1;
  720. }
  721. av7110->bmplen = ((dx * dy * bpp + 7) & ~7) / 8;
  722. av7110->bmpp = 0;
  723. if (av7110->bmplen > 32768) {
  724. av7110->bmp_state = BMP_NONE;
  725. return -1;
  726. }
  727. for (i = 0; i < dy; i++) {
  728. if (copy_from_user(av7110->bmpbuf + 1024 + i * dx, data + i * inc, dx)) {
  729. av7110->bmp_state = BMP_NONE;
  730. return -1;
  731. }
  732. }
  733. if (format != OSD_BITMAP8) {
  734. for (i = 0; i < dx * dy / delta; i++) {
  735. c = ((u8 *)av7110->bmpbuf)[1024 + i * delta + delta - 1];
  736. for (d = delta - 2; d >= 0; d--) {
  737. c |= (((u8 *)av7110->bmpbuf)[1024 + i * delta + d]
  738. << ((delta - d - 1) * bpp));
  739. ((u8 *)av7110->bmpbuf)[1024 + i] = c;
  740. }
  741. }
  742. }
  743. av7110->bmplen += 1024;
  744. dprintk(4, "av7110_fw_cmd: LoadBmp size %d\n", av7110->bmplen);
  745. return av7110_fw_cmd(av7110, COMTYPE_OSD, LoadBmp, 3, format, dx, dy);
  746. }
  747. static int BlitBitmap(struct av7110 *av7110, u16 win, u16 x, u16 y, u16 trans)
  748. {
  749. int ret;
  750. dprintk(4, "%p\n", av7110);
  751. BUG_ON (av7110->bmp_state == BMP_NONE);
  752. ret = wait_event_interruptible_timeout(av7110->bmpq,
  753. av7110->bmp_state != BMP_LOADING, 10*HZ);
  754. if (ret == -ERESTARTSYS || ret == 0) {
  755. printk("dvb-ttpci: warning: timeout waiting in BlitBitmap: %d, %d\n",
  756. ret, av7110->bmp_state);
  757. av7110->bmp_state = BMP_NONE;
  758. return (ret == 0) ? -ETIMEDOUT : ret;
  759. }
  760. BUG_ON (av7110->bmp_state != BMP_LOADED);
  761. return av7110_fw_cmd(av7110, COMTYPE_OSD, BlitBmp, 4, win, x, y, trans);
  762. }
  763. static inline int ReleaseBitmap(struct av7110 *av7110)
  764. {
  765. dprintk(4, "%p\n", av7110);
  766. if (av7110->bmp_state != BMP_LOADED)
  767. return -1;
  768. av7110->bmp_state = BMP_NONE;
  769. return av7110_fw_cmd(av7110, COMTYPE_OSD, ReleaseBmp, 0);
  770. }
  771. static u32 RGB2YUV(u16 R, u16 G, u16 B)
  772. {
  773. u16 y, u, v;
  774. u16 Y, Cr, Cb;
  775. y = R * 77 + G * 150 + B * 29; /* Luma=0.299R+0.587G+0.114B 0..65535 */
  776. u = 2048 + B * 8 -(y >> 5); /* Cr 0..4095 */
  777. v = 2048 + R * 8 -(y >> 5); /* Cb 0..4095 */
  778. Y = y / 256;
  779. Cb = u / 16;
  780. Cr = v / 16;
  781. return Cr | (Cb << 16) | (Y << 8);
  782. }
  783. static void OSDSetColor(struct av7110 *av7110, u8 color, u8 r, u8 g, u8 b, u8 blend)
  784. {
  785. u16 ch, cl;
  786. u32 yuv;
  787. yuv = blend ? RGB2YUV(r,g,b) : 0;
  788. cl = (yuv & 0xffff);
  789. ch = ((yuv >> 16) & 0xffff);
  790. SetColor_(av7110, av7110->osdwin, bpp2pal[av7110->osdbpp[av7110->osdwin]],
  791. color, ch, cl);
  792. SetBlend_(av7110, av7110->osdwin, bpp2pal[av7110->osdbpp[av7110->osdwin]],
  793. color, ((blend >> 4) & 0x0f));
  794. }
  795. static int OSDSetPalette(struct av7110 *av7110, u32 __user * colors, u8 first, u8 last)
  796. {
  797. int i;
  798. int length = last - first + 1;
  799. if (length * 4 > DATA_BUFF3_SIZE)
  800. return -EINVAL;
  801. for (i = 0; i < length; i++) {
  802. u32 color, blend, yuv;
  803. if (get_user(color, colors + i))
  804. return -EFAULT;
  805. blend = (color & 0xF0000000) >> 4;
  806. yuv = blend ? RGB2YUV(color & 0xFF, (color >> 8) & 0xFF,
  807. (color >> 16) & 0xFF) | blend : 0;
  808. yuv = ((yuv & 0xFFFF0000) >> 16) | ((yuv & 0x0000FFFF) << 16);
  809. wdebi(av7110, DEBINOSWAP, DATA_BUFF3_BASE + i * 4, yuv, 4);
  810. }
  811. return av7110_fw_cmd(av7110, COMTYPE_OSD, Set_Palette, 4,
  812. av7110->osdwin,
  813. bpp2pal[av7110->osdbpp[av7110->osdwin]],
  814. first, last);
  815. }
  816. static int OSDSetBlock(struct av7110 *av7110, int x0, int y0,
  817. int x1, int y1, int inc, u8 __user * data)
  818. {
  819. uint w, h, bpp, bpl, size, lpb, bnum, brest;
  820. int i;
  821. int rc;
  822. w = x1 - x0 + 1;
  823. h = y1 - y0 + 1;
  824. if (inc <= 0)
  825. inc = w;
  826. if (w <= 0 || w > 720 || h <= 0 || h > 576)
  827. return -1;
  828. bpp = av7110->osdbpp[av7110->osdwin] + 1;
  829. bpl = ((w * bpp + 7) & ~7) / 8;
  830. size = h * bpl;
  831. lpb = (32 * 1024) / bpl;
  832. bnum = size / (lpb * bpl);
  833. brest = size - bnum * lpb * bpl;
  834. for (i = 0; i < bnum; i++) {
  835. rc = LoadBitmap(av7110, bpp2bit[av7110->osdbpp[av7110->osdwin]],
  836. w, lpb, inc, data);
  837. if (rc)
  838. return rc;
  839. rc = BlitBitmap(av7110, av7110->osdwin, x0, y0 + i * lpb, 0);
  840. if (rc)
  841. return rc;
  842. data += lpb * inc;
  843. }
  844. if (brest) {
  845. rc = LoadBitmap(av7110, bpp2bit[av7110->osdbpp[av7110->osdwin]],
  846. w, brest / bpl, inc, data);
  847. if (rc)
  848. return rc;
  849. rc = BlitBitmap(av7110, av7110->osdwin, x0, y0 + bnum * lpb, 0);
  850. if (rc)
  851. return rc;
  852. }
  853. ReleaseBitmap(av7110);
  854. return 0;
  855. }
  856. int av7110_osd_cmd(struct av7110 *av7110, osd_cmd_t *dc)
  857. {
  858. int ret;
  859. ret = down_interruptible(&av7110->osd_sema);
  860. if (ret)
  861. return -ERESTARTSYS;
  862. /* stupid, but OSD functions don't provide a return code anyway */
  863. ret = 0;
  864. switch (dc->cmd) {
  865. case OSD_Close:
  866. DestroyOSDWindow(av7110, av7110->osdwin);
  867. goto out;
  868. case OSD_Open:
  869. av7110->osdbpp[av7110->osdwin] = (dc->color - 1) & 7;
  870. CreateOSDWindow(av7110, av7110->osdwin,
  871. bpp2bit[av7110->osdbpp[av7110->osdwin]],
  872. dc->x1 - dc->x0 + 1, dc->y1 - dc->y0 + 1);
  873. if (!dc->data) {
  874. MoveWindowAbs(av7110, av7110->osdwin, dc->x0, dc->y0);
  875. SetColorBlend(av7110, av7110->osdwin);
  876. }
  877. goto out;
  878. case OSD_Show:
  879. MoveWindowRel(av7110, av7110->osdwin, 0, 0);
  880. goto out;
  881. case OSD_Hide:
  882. HideWindow(av7110, av7110->osdwin);
  883. goto out;
  884. case OSD_Clear:
  885. DrawBlock(av7110, av7110->osdwin, 0, 0, 720, 576, 0);
  886. goto out;
  887. case OSD_Fill:
  888. DrawBlock(av7110, av7110->osdwin, 0, 0, 720, 576, dc->color);
  889. goto out;
  890. case OSD_SetColor:
  891. OSDSetColor(av7110, dc->color, dc->x0, dc->y0, dc->x1, dc->y1);
  892. goto out;
  893. case OSD_SetPalette:
  894. {
  895. if (FW_VERSION(av7110->arm_app) >= 0x2618) {
  896. ret = OSDSetPalette(av7110, dc->data, dc->color, dc->x0);
  897. goto out;
  898. } else {
  899. int i, len = dc->x0-dc->color+1;
  900. u8 __user *colors = (u8 __user *)dc->data;
  901. u8 r, g, b, blend;
  902. for (i = 0; i<len; i++) {
  903. if (get_user(r, colors + i * 4) ||
  904. get_user(g, colors + i * 4 + 1) ||
  905. get_user(b, colors + i * 4 + 2) ||
  906. get_user(blend, colors + i * 4 + 3)) {
  907. ret = -EFAULT;
  908. goto out;
  909. }
  910. OSDSetColor(av7110, dc->color + i, r, g, b, blend);
  911. }
  912. }
  913. ret = 0;
  914. goto out;
  915. }
  916. case OSD_SetTrans:
  917. goto out;
  918. case OSD_SetPixel:
  919. DrawLine(av7110, av7110->osdwin,
  920. dc->x0, dc->y0, 0, 0, dc->color);
  921. goto out;
  922. case OSD_GetPixel:
  923. goto out;
  924. case OSD_SetRow:
  925. dc->y1 = dc->y0;
  926. /* fall through */
  927. case OSD_SetBlock:
  928. ret = OSDSetBlock(av7110, dc->x0, dc->y0, dc->x1, dc->y1, dc->color, dc->data);
  929. goto out;
  930. case OSD_FillRow:
  931. DrawBlock(av7110, av7110->osdwin, dc->x0, dc->y0,
  932. dc->x1-dc->x0+1, dc->y1, dc->color);
  933. goto out;
  934. case OSD_FillBlock:
  935. DrawBlock(av7110, av7110->osdwin, dc->x0, dc->y0,
  936. dc->x1 - dc->x0 + 1, dc->y1 - dc->y0 + 1, dc->color);
  937. goto out;
  938. case OSD_Line:
  939. DrawLine(av7110, av7110->osdwin,
  940. dc->x0, dc->y0, dc->x1 - dc->x0, dc->y1 - dc->y0, dc->color);
  941. goto out;
  942. case OSD_Query:
  943. goto out;
  944. case OSD_Test:
  945. goto out;
  946. case OSD_Text:
  947. {
  948. char textbuf[240];
  949. if (strncpy_from_user(textbuf, dc->data, 240) < 0) {
  950. ret = -EFAULT;
  951. goto out;
  952. }
  953. textbuf[239] = 0;
  954. if (dc->x1 > 3)
  955. dc->x1 = 3;
  956. SetFont(av7110, av7110->osdwin, dc->x1,
  957. (u16) (dc->color & 0xffff), (u16) (dc->color >> 16));
  958. FlushText(av7110);
  959. WriteText(av7110, av7110->osdwin, dc->x0, dc->y0, textbuf);
  960. goto out;
  961. }
  962. case OSD_SetWindow:
  963. if (dc->x0 < 1 || dc->x0 > 7) {
  964. ret = -EINVAL;
  965. goto out;
  966. }
  967. av7110->osdwin = dc->x0;
  968. goto out;
  969. case OSD_MoveWindow:
  970. MoveWindowAbs(av7110, av7110->osdwin, dc->x0, dc->y0);
  971. SetColorBlend(av7110, av7110->osdwin);
  972. goto out;
  973. case OSD_OpenRaw:
  974. if (dc->color < OSD_BITMAP1 || dc->color > OSD_CURSOR) {
  975. ret = -EINVAL;
  976. goto out;
  977. }
  978. if (dc->color >= OSD_BITMAP1 && dc->color <= OSD_BITMAP8HR) {
  979. av7110->osdbpp[av7110->osdwin] = (1 << (dc->color & 3)) - 1;
  980. }
  981. else {
  982. av7110->osdbpp[av7110->osdwin] = 0;
  983. }
  984. CreateOSDWindow(av7110, av7110->osdwin, (osd_raw_window_t)dc->color,
  985. dc->x1 - dc->x0 + 1, dc->y1 - dc->y0 + 1);
  986. if (!dc->data) {
  987. MoveWindowAbs(av7110, av7110->osdwin, dc->x0, dc->y0);
  988. SetColorBlend(av7110, av7110->osdwin);
  989. }
  990. goto out;
  991. default:
  992. ret = -EINVAL;
  993. goto out;
  994. }
  995. out:
  996. up(&av7110->osd_sema);
  997. return ret;
  998. }
  999. int av7110_osd_capability(struct av7110 *av7110, osd_cap_t *cap)
  1000. {
  1001. switch (cap->cmd) {
  1002. case OSD_CAP_MEMSIZE:
  1003. if (FW_4M_SDRAM(av7110->arm_app))
  1004. cap->val = 1000000;
  1005. else
  1006. cap->val = 92000;
  1007. return 0;
  1008. default:
  1009. return -EINVAL;
  1010. }
  1011. }
  1012. #endif /* CONFIG_DVB_AV7110_OSD */