saa7164-fw.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. /*
  2. * Driver for the NXP SAA7164 PCIe bridge
  3. *
  4. * Copyright (c) 2010-2015 Steven Toth <stoth@kernellabs.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. *
  15. * GNU General Public License for more details.
  16. */
  17. #include <linux/firmware.h>
  18. #include <linux/slab.h>
  19. #include "saa7164.h"
  20. #define SAA7164_REV2_FIRMWARE "NXP7164-2010-03-10.1.fw"
  21. #define SAA7164_REV2_FIRMWARE_SIZE 4019072
  22. #define SAA7164_REV3_FIRMWARE "NXP7164-2010-03-10.1.fw"
  23. #define SAA7164_REV3_FIRMWARE_SIZE 4019072
  24. struct fw_header {
  25. u32 firmwaresize;
  26. u32 bslsize;
  27. u32 reserved;
  28. u32 version;
  29. };
  30. static int saa7164_dl_wait_ack(struct saa7164_dev *dev, u32 reg)
  31. {
  32. u32 timeout = SAA_DEVICE_TIMEOUT;
  33. while ((saa7164_readl(reg) & 0x01) == 0) {
  34. timeout -= 10;
  35. if (timeout == 0) {
  36. printk(KERN_ERR "%s() timeout (no d/l ack)\n",
  37. __func__);
  38. return -EBUSY;
  39. }
  40. msleep(100);
  41. }
  42. return 0;
  43. }
  44. static int saa7164_dl_wait_clr(struct saa7164_dev *dev, u32 reg)
  45. {
  46. u32 timeout = SAA_DEVICE_TIMEOUT;
  47. while (saa7164_readl(reg) & 0x01) {
  48. timeout -= 10;
  49. if (timeout == 0) {
  50. printk(KERN_ERR "%s() timeout (no d/l clr)\n",
  51. __func__);
  52. return -EBUSY;
  53. }
  54. msleep(100);
  55. }
  56. return 0;
  57. }
  58. /* TODO: move dlflags into dev-> and change to write/readl/b */
  59. /* TODO: Excessive levels of debug */
  60. static int saa7164_downloadimage(struct saa7164_dev *dev, u8 *src, u32 srcsize,
  61. u32 dlflags, u8 __iomem *dst, u32 dstsize)
  62. {
  63. u32 reg, timeout, offset;
  64. u8 *srcbuf = NULL;
  65. int ret;
  66. u32 dlflag = dlflags;
  67. u32 dlflag_ack = dlflag + 4;
  68. u32 drflag = dlflag_ack + 4;
  69. u32 drflag_ack = drflag + 4;
  70. u32 bleflag = drflag_ack + 4;
  71. dprintk(DBGLVL_FW,
  72. "%s(image=%p, size=%d, flags=0x%x, dst=%p, dstsize=0x%x)\n",
  73. __func__, src, srcsize, dlflags, dst, dstsize);
  74. if ((src == NULL) || (dst == NULL)) {
  75. ret = -EIO;
  76. goto out;
  77. }
  78. srcbuf = kzalloc(4 * 1048576, GFP_KERNEL);
  79. if (NULL == srcbuf) {
  80. ret = -ENOMEM;
  81. goto out;
  82. }
  83. if (srcsize > (4*1048576)) {
  84. ret = -ENOMEM;
  85. goto out;
  86. }
  87. memcpy(srcbuf, src, srcsize);
  88. dprintk(DBGLVL_FW, "%s() dlflag = 0x%x\n", __func__, dlflag);
  89. dprintk(DBGLVL_FW, "%s() dlflag_ack = 0x%x\n", __func__, dlflag_ack);
  90. dprintk(DBGLVL_FW, "%s() drflag = 0x%x\n", __func__, drflag);
  91. dprintk(DBGLVL_FW, "%s() drflag_ack = 0x%x\n", __func__, drflag_ack);
  92. dprintk(DBGLVL_FW, "%s() bleflag = 0x%x\n", __func__, bleflag);
  93. reg = saa7164_readl(dlflag);
  94. dprintk(DBGLVL_FW, "%s() dlflag (0x%x)= 0x%x\n", __func__, dlflag, reg);
  95. if (reg == 1)
  96. dprintk(DBGLVL_FW,
  97. "%s() Download flag already set, please reboot\n",
  98. __func__);
  99. /* Indicate download start */
  100. saa7164_writel(dlflag, 1);
  101. ret = saa7164_dl_wait_ack(dev, dlflag_ack);
  102. if (ret < 0)
  103. goto out;
  104. /* Ack download start, then wait for wait */
  105. saa7164_writel(dlflag, 0);
  106. ret = saa7164_dl_wait_clr(dev, dlflag_ack);
  107. if (ret < 0)
  108. goto out;
  109. /* Deal with the raw firmware, in the appropriate chunk size */
  110. for (offset = 0; srcsize > dstsize;
  111. srcsize -= dstsize, offset += dstsize) {
  112. dprintk(DBGLVL_FW, "%s() memcpy %d\n", __func__, dstsize);
  113. memcpy_toio(dst, srcbuf + offset, dstsize);
  114. /* Flag the data as ready */
  115. saa7164_writel(drflag, 1);
  116. ret = saa7164_dl_wait_ack(dev, drflag_ack);
  117. if (ret < 0)
  118. goto out;
  119. /* Wait for indication data was received */
  120. saa7164_writel(drflag, 0);
  121. ret = saa7164_dl_wait_clr(dev, drflag_ack);
  122. if (ret < 0)
  123. goto out;
  124. }
  125. dprintk(DBGLVL_FW, "%s() memcpy(l) %d\n", __func__, dstsize);
  126. /* Write last block to the device */
  127. memcpy_toio(dst, srcbuf+offset, srcsize);
  128. /* Flag the data as ready */
  129. saa7164_writel(drflag, 1);
  130. ret = saa7164_dl_wait_ack(dev, drflag_ack);
  131. if (ret < 0)
  132. goto out;
  133. saa7164_writel(drflag, 0);
  134. timeout = 0;
  135. while (saa7164_readl(bleflag) != SAA_DEVICE_IMAGE_BOOTING) {
  136. if (saa7164_readl(bleflag) & SAA_DEVICE_IMAGE_CORRUPT) {
  137. printk(KERN_ERR "%s() image corrupt\n", __func__);
  138. ret = -EBUSY;
  139. goto out;
  140. }
  141. if (saa7164_readl(bleflag) & SAA_DEVICE_MEMORY_CORRUPT) {
  142. printk(KERN_ERR "%s() device memory corrupt\n",
  143. __func__);
  144. ret = -EBUSY;
  145. goto out;
  146. }
  147. msleep(10); /* Checkpatch throws a < 20ms warning */
  148. if (timeout++ > 60)
  149. break;
  150. }
  151. printk(KERN_INFO "%s() Image downloaded, booting...\n", __func__);
  152. ret = saa7164_dl_wait_clr(dev, drflag_ack);
  153. if (ret < 0)
  154. goto out;
  155. printk(KERN_INFO "%s() Image booted successfully.\n", __func__);
  156. ret = 0;
  157. out:
  158. kfree(srcbuf);
  159. return ret;
  160. }
  161. /* TODO: Excessive debug */
  162. /* Load the firmware. Optionally it can be in ROM or newer versions
  163. * can be on disk, saving the expense of the ROM hardware. */
  164. int saa7164_downloadfirmware(struct saa7164_dev *dev)
  165. {
  166. /* u32 second_timeout = 60 * SAA_DEVICE_TIMEOUT; */
  167. u32 tmp, filesize, version, err_flags, first_timeout, fwlength;
  168. u32 second_timeout, updatebootloader = 1, bootloadersize = 0;
  169. const struct firmware *fw = NULL;
  170. struct fw_header *hdr, *boothdr = NULL, *fwhdr;
  171. u32 bootloaderversion = 0, fwloadersize;
  172. u8 *bootloaderoffset = NULL, *fwloaderoffset;
  173. char *fwname;
  174. int ret;
  175. dprintk(DBGLVL_FW, "%s()\n", __func__);
  176. if (saa7164_boards[dev->board].chiprev == SAA7164_CHIP_REV2) {
  177. fwname = SAA7164_REV2_FIRMWARE;
  178. fwlength = SAA7164_REV2_FIRMWARE_SIZE;
  179. } else {
  180. fwname = SAA7164_REV3_FIRMWARE;
  181. fwlength = SAA7164_REV3_FIRMWARE_SIZE;
  182. }
  183. version = saa7164_getcurrentfirmwareversion(dev);
  184. if (version == 0x00) {
  185. second_timeout = 100;
  186. first_timeout = 100;
  187. err_flags = saa7164_readl(SAA_BOOTLOADERERROR_FLAGS);
  188. dprintk(DBGLVL_FW, "%s() err_flags = %x\n",
  189. __func__, err_flags);
  190. while (err_flags != SAA_DEVICE_IMAGE_BOOTING) {
  191. dprintk(DBGLVL_FW, "%s() err_flags = %x\n",
  192. __func__, err_flags);
  193. msleep(10); /* Checkpatch throws a < 20ms warning */
  194. if (err_flags & SAA_DEVICE_IMAGE_CORRUPT) {
  195. printk(KERN_ERR "%s() firmware corrupt\n",
  196. __func__);
  197. break;
  198. }
  199. if (err_flags & SAA_DEVICE_MEMORY_CORRUPT) {
  200. printk(KERN_ERR "%s() device memory corrupt\n",
  201. __func__);
  202. break;
  203. }
  204. if (err_flags & SAA_DEVICE_NO_IMAGE) {
  205. printk(KERN_ERR "%s() no first image\n",
  206. __func__);
  207. break;
  208. }
  209. if (err_flags & SAA_DEVICE_IMAGE_SEARCHING) {
  210. first_timeout -= 10;
  211. if (first_timeout == 0) {
  212. printk(KERN_ERR
  213. "%s() no first image\n",
  214. __func__);
  215. break;
  216. }
  217. } else if (err_flags & SAA_DEVICE_IMAGE_LOADING) {
  218. second_timeout -= 10;
  219. if (second_timeout == 0) {
  220. printk(KERN_ERR
  221. "%s() FW load time exceeded\n",
  222. __func__);
  223. break;
  224. }
  225. } else {
  226. second_timeout -= 10;
  227. if (second_timeout == 0) {
  228. printk(KERN_ERR
  229. "%s() Unknown bootloader flags 0x%x\n",
  230. __func__, err_flags);
  231. break;
  232. }
  233. }
  234. err_flags = saa7164_readl(SAA_BOOTLOADERERROR_FLAGS);
  235. } /* While != Booting */
  236. if (err_flags == SAA_DEVICE_IMAGE_BOOTING) {
  237. dprintk(DBGLVL_FW, "%s() Loader 1 has loaded.\n",
  238. __func__);
  239. first_timeout = SAA_DEVICE_TIMEOUT;
  240. second_timeout = 60 * SAA_DEVICE_TIMEOUT;
  241. second_timeout = 100;
  242. err_flags = saa7164_readl(SAA_SECONDSTAGEERROR_FLAGS);
  243. dprintk(DBGLVL_FW, "%s() err_flags2 = %x\n",
  244. __func__, err_flags);
  245. while (err_flags != SAA_DEVICE_IMAGE_BOOTING) {
  246. dprintk(DBGLVL_FW, "%s() err_flags2 = %x\n",
  247. __func__, err_flags);
  248. msleep(10); /* Checkpatch throws a < 20ms warning */
  249. if (err_flags & SAA_DEVICE_IMAGE_CORRUPT) {
  250. printk(KERN_ERR
  251. "%s() firmware corrupt\n",
  252. __func__);
  253. break;
  254. }
  255. if (err_flags & SAA_DEVICE_MEMORY_CORRUPT) {
  256. printk(KERN_ERR
  257. "%s() device memory corrupt\n",
  258. __func__);
  259. break;
  260. }
  261. if (err_flags & SAA_DEVICE_NO_IMAGE) {
  262. printk(KERN_ERR "%s() no second image\n",
  263. __func__);
  264. break;
  265. }
  266. if (err_flags & SAA_DEVICE_IMAGE_SEARCHING) {
  267. first_timeout -= 10;
  268. if (first_timeout == 0) {
  269. printk(KERN_ERR
  270. "%s() no second image\n",
  271. __func__);
  272. break;
  273. }
  274. } else if (err_flags &
  275. SAA_DEVICE_IMAGE_LOADING) {
  276. second_timeout -= 10;
  277. if (second_timeout == 0) {
  278. printk(KERN_ERR
  279. "%s() FW load time exceeded\n",
  280. __func__);
  281. break;
  282. }
  283. } else {
  284. second_timeout -= 10;
  285. if (second_timeout == 0) {
  286. printk(KERN_ERR
  287. "%s() Unknown bootloader flags 0x%x\n",
  288. __func__, err_flags);
  289. break;
  290. }
  291. }
  292. err_flags =
  293. saa7164_readl(SAA_SECONDSTAGEERROR_FLAGS);
  294. } /* err_flags != SAA_DEVICE_IMAGE_BOOTING */
  295. dprintk(DBGLVL_FW, "%s() Loader flags 1:0x%x 2:0x%x.\n",
  296. __func__,
  297. saa7164_readl(SAA_BOOTLOADERERROR_FLAGS),
  298. saa7164_readl(SAA_SECONDSTAGEERROR_FLAGS));
  299. } /* err_flags == SAA_DEVICE_IMAGE_BOOTING */
  300. /* It's possible for both firmwares to have booted,
  301. * but that doesn't mean they've finished booting yet.
  302. */
  303. if ((saa7164_readl(SAA_BOOTLOADERERROR_FLAGS) ==
  304. SAA_DEVICE_IMAGE_BOOTING) &&
  305. (saa7164_readl(SAA_SECONDSTAGEERROR_FLAGS) ==
  306. SAA_DEVICE_IMAGE_BOOTING)) {
  307. dprintk(DBGLVL_FW, "%s() Loader 2 has loaded.\n",
  308. __func__);
  309. first_timeout = SAA_DEVICE_TIMEOUT;
  310. while (first_timeout) {
  311. msleep(10); /* Checkpatch throws a < 20ms warning */
  312. version =
  313. saa7164_getcurrentfirmwareversion(dev);
  314. if (version) {
  315. dprintk(DBGLVL_FW,
  316. "%s() All f/w loaded successfully\n",
  317. __func__);
  318. break;
  319. } else {
  320. first_timeout -= 10;
  321. if (first_timeout == 0) {
  322. printk(KERN_ERR
  323. "%s() FW did not boot\n",
  324. __func__);
  325. break;
  326. }
  327. }
  328. }
  329. }
  330. version = saa7164_getcurrentfirmwareversion(dev);
  331. } /* version == 0 */
  332. /* Has the firmware really booted? */
  333. if ((saa7164_readl(SAA_BOOTLOADERERROR_FLAGS) ==
  334. SAA_DEVICE_IMAGE_BOOTING) &&
  335. (saa7164_readl(SAA_SECONDSTAGEERROR_FLAGS) ==
  336. SAA_DEVICE_IMAGE_BOOTING) && (version == 0)) {
  337. printk(KERN_ERR
  338. "%s() The firmware hung, probably bad firmware\n",
  339. __func__);
  340. /* Tell the second stage loader we have a deadlock */
  341. saa7164_writel(SAA_DEVICE_DEADLOCK_DETECTED_OFFSET,
  342. SAA_DEVICE_DEADLOCK_DETECTED);
  343. saa7164_getfirmwarestatus(dev);
  344. return -ENOMEM;
  345. }
  346. dprintk(DBGLVL_FW, "Device has Firmware Version %d.%d.%d.%d\n",
  347. (version & 0x0000fc00) >> 10,
  348. (version & 0x000003e0) >> 5,
  349. (version & 0x0000001f),
  350. (version & 0xffff0000) >> 16);
  351. /* Load the firmwware from the disk if required */
  352. if (version == 0) {
  353. printk(KERN_INFO "%s() Waiting for firmware upload (%s)\n",
  354. __func__, fwname);
  355. ret = request_firmware(&fw, fwname, &dev->pci->dev);
  356. if (ret)
  357. return -ENOMEM;
  358. printk(KERN_INFO "%s() firmware read %zu bytes.\n",
  359. __func__, fw->size);
  360. if (fw->size != fwlength) {
  361. printk(KERN_ERR "saa7164: firmware incorrect size %zu != %u\n",
  362. fw->size, fwlength);
  363. ret = -ENOMEM;
  364. goto out;
  365. }
  366. printk(KERN_INFO "%s() firmware loaded.\n", __func__);
  367. hdr = (struct fw_header *)fw->data;
  368. printk(KERN_INFO "Firmware file header part 1:\n");
  369. printk(KERN_INFO " .FirmwareSize = 0x%x\n", hdr->firmwaresize);
  370. printk(KERN_INFO " .BSLSize = 0x%x\n", hdr->bslsize);
  371. printk(KERN_INFO " .Reserved = 0x%x\n", hdr->reserved);
  372. printk(KERN_INFO " .Version = 0x%x\n", hdr->version);
  373. /* Retrieve bootloader if reqd */
  374. if ((hdr->firmwaresize == 0) && (hdr->bslsize == 0))
  375. /* Second bootloader in the firmware file */
  376. filesize = hdr->reserved * 16;
  377. else
  378. filesize = (hdr->firmwaresize + hdr->bslsize) *
  379. 16 + sizeof(struct fw_header);
  380. printk(KERN_INFO "%s() SecBootLoader.FileSize = %d\n",
  381. __func__, filesize);
  382. /* Get bootloader (if reqd) and firmware header */
  383. if ((hdr->firmwaresize == 0) && (hdr->bslsize == 0)) {
  384. /* Second boot loader is required */
  385. /* Get the loader header */
  386. boothdr = (struct fw_header *)(fw->data +
  387. sizeof(struct fw_header));
  388. bootloaderversion =
  389. saa7164_readl(SAA_DEVICE_2ND_VERSION);
  390. dprintk(DBGLVL_FW, "Onboard BootLoader:\n");
  391. dprintk(DBGLVL_FW, "->Flag 0x%x\n",
  392. saa7164_readl(SAA_BOOTLOADERERROR_FLAGS));
  393. dprintk(DBGLVL_FW, "->Ack 0x%x\n",
  394. saa7164_readl(SAA_DATAREADY_FLAG_ACK));
  395. dprintk(DBGLVL_FW, "->FW Version 0x%x\n", version);
  396. dprintk(DBGLVL_FW, "->Loader Version 0x%x\n",
  397. bootloaderversion);
  398. if ((saa7164_readl(SAA_BOOTLOADERERROR_FLAGS) ==
  399. 0x03) && (saa7164_readl(SAA_DATAREADY_FLAG_ACK)
  400. == 0x00) && (version == 0x00)) {
  401. dprintk(DBGLVL_FW, "BootLoader version in rom %d.%d.%d.%d\n",
  402. (bootloaderversion & 0x0000fc00) >> 10,
  403. (bootloaderversion & 0x000003e0) >> 5,
  404. (bootloaderversion & 0x0000001f),
  405. (bootloaderversion & 0xffff0000) >> 16
  406. );
  407. dprintk(DBGLVL_FW, "BootLoader version in file %d.%d.%d.%d\n",
  408. (boothdr->version & 0x0000fc00) >> 10,
  409. (boothdr->version & 0x000003e0) >> 5,
  410. (boothdr->version & 0x0000001f),
  411. (boothdr->version & 0xffff0000) >> 16
  412. );
  413. if (bootloaderversion == boothdr->version)
  414. updatebootloader = 0;
  415. }
  416. /* Calculate offset to firmware header */
  417. tmp = (boothdr->firmwaresize + boothdr->bslsize) * 16 +
  418. (sizeof(struct fw_header) +
  419. sizeof(struct fw_header));
  420. fwhdr = (struct fw_header *)(fw->data+tmp);
  421. } else {
  422. /* No second boot loader */
  423. fwhdr = hdr;
  424. }
  425. dprintk(DBGLVL_FW, "Firmware version in file %d.%d.%d.%d\n",
  426. (fwhdr->version & 0x0000fc00) >> 10,
  427. (fwhdr->version & 0x000003e0) >> 5,
  428. (fwhdr->version & 0x0000001f),
  429. (fwhdr->version & 0xffff0000) >> 16
  430. );
  431. if (version == fwhdr->version) {
  432. /* No download, firmware already on board */
  433. ret = 0;
  434. goto out;
  435. }
  436. if ((hdr->firmwaresize == 0) && (hdr->bslsize == 0)) {
  437. if (updatebootloader) {
  438. /* Get ready to upload the bootloader */
  439. bootloadersize = (boothdr->firmwaresize +
  440. boothdr->bslsize) * 16 +
  441. sizeof(struct fw_header);
  442. bootloaderoffset = (u8 *)(fw->data +
  443. sizeof(struct fw_header));
  444. dprintk(DBGLVL_FW, "bootloader d/l starts.\n");
  445. printk(KERN_INFO "%s() FirmwareSize = 0x%x\n",
  446. __func__, boothdr->firmwaresize);
  447. printk(KERN_INFO "%s() BSLSize = 0x%x\n",
  448. __func__, boothdr->bslsize);
  449. printk(KERN_INFO "%s() Reserved = 0x%x\n",
  450. __func__, boothdr->reserved);
  451. printk(KERN_INFO "%s() Version = 0x%x\n",
  452. __func__, boothdr->version);
  453. ret = saa7164_downloadimage(
  454. dev,
  455. bootloaderoffset,
  456. bootloadersize,
  457. SAA_DOWNLOAD_FLAGS,
  458. dev->bmmio + SAA_DEVICE_DOWNLOAD_OFFSET,
  459. SAA_DEVICE_BUFFERBLOCKSIZE);
  460. if (ret < 0) {
  461. printk(KERN_ERR
  462. "bootloader d/l has failed\n");
  463. goto out;
  464. }
  465. dprintk(DBGLVL_FW,
  466. "bootloader download complete.\n");
  467. }
  468. printk(KERN_ERR "starting firmware download(2)\n");
  469. bootloadersize = (boothdr->firmwaresize +
  470. boothdr->bslsize) * 16 +
  471. sizeof(struct fw_header);
  472. bootloaderoffset =
  473. (u8 *)(fw->data + sizeof(struct fw_header));
  474. fwloaderoffset = bootloaderoffset + bootloadersize;
  475. /* TODO: fix this bounds overrun here with old f/ws */
  476. fwloadersize = (fwhdr->firmwaresize + fwhdr->bslsize) *
  477. 16 + sizeof(struct fw_header);
  478. ret = saa7164_downloadimage(
  479. dev,
  480. fwloaderoffset,
  481. fwloadersize,
  482. SAA_DEVICE_2ND_DOWNLOADFLAG_OFFSET,
  483. dev->bmmio + SAA_DEVICE_2ND_DOWNLOAD_OFFSET,
  484. SAA_DEVICE_2ND_BUFFERBLOCKSIZE);
  485. if (ret < 0) {
  486. printk(KERN_ERR "firmware download failed\n");
  487. goto out;
  488. }
  489. printk(KERN_ERR "firmware download complete.\n");
  490. } else {
  491. /* No bootloader update reqd, download firmware only */
  492. printk(KERN_ERR "starting firmware download(3)\n");
  493. ret = saa7164_downloadimage(
  494. dev,
  495. (u8 *)fw->data,
  496. fw->size,
  497. SAA_DOWNLOAD_FLAGS,
  498. dev->bmmio + SAA_DEVICE_DOWNLOAD_OFFSET,
  499. SAA_DEVICE_BUFFERBLOCKSIZE);
  500. if (ret < 0) {
  501. printk(KERN_ERR "firmware download failed\n");
  502. goto out;
  503. }
  504. printk(KERN_ERR "firmware download complete.\n");
  505. }
  506. }
  507. dev->firmwareloaded = 1;
  508. ret = 0;
  509. out:
  510. release_firmware(fw);
  511. return ret;
  512. }