saa7164-api.c 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525
  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/wait.h>
  18. #include <linux/slab.h>
  19. #include "saa7164.h"
  20. int saa7164_api_get_load_info(struct saa7164_dev *dev, struct tmFwInfoStruct *i)
  21. {
  22. int ret;
  23. if (!(saa_debug & DBGLVL_CPU))
  24. return 0;
  25. dprintk(DBGLVL_API, "%s()\n", __func__);
  26. i->deviceinst = 0;
  27. i->devicespec = 0;
  28. i->mode = 0;
  29. i->status = 0;
  30. ret = saa7164_cmd_send(dev, 0, GET_CUR,
  31. GET_FW_STATUS_CONTROL, sizeof(struct tmFwInfoStruct), i);
  32. if (ret != SAA_OK)
  33. printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
  34. printk(KERN_INFO "saa7164[%d]-CPU: %d percent", dev->nr, i->CPULoad);
  35. return ret;
  36. }
  37. int saa7164_api_collect_debug(struct saa7164_dev *dev)
  38. {
  39. struct tmComResDebugGetData d;
  40. u8 more = 255;
  41. int ret;
  42. dprintk(DBGLVL_API, "%s()\n", __func__);
  43. while (more--) {
  44. memset(&d, 0, sizeof(d));
  45. ret = saa7164_cmd_send(dev, 0, GET_CUR,
  46. GET_DEBUG_DATA_CONTROL, sizeof(d), &d);
  47. if (ret != SAA_OK)
  48. printk(KERN_ERR "%s() error, ret = 0x%x\n",
  49. __func__, ret);
  50. if (d.dwResult != SAA_OK)
  51. break;
  52. printk(KERN_INFO "saa7164[%d]-FWMSG: %s", dev->nr,
  53. d.ucDebugData);
  54. }
  55. return 0;
  56. }
  57. int saa7164_api_set_debug(struct saa7164_dev *dev, u8 level)
  58. {
  59. struct tmComResDebugSetLevel lvl;
  60. int ret;
  61. dprintk(DBGLVL_API, "%s(level=%d)\n", __func__, level);
  62. /* Retrieve current state */
  63. ret = saa7164_cmd_send(dev, 0, GET_CUR,
  64. SET_DEBUG_LEVEL_CONTROL, sizeof(lvl), &lvl);
  65. if (ret != SAA_OK)
  66. printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
  67. dprintk(DBGLVL_API, "%s() Was %d\n", __func__, lvl.dwDebugLevel);
  68. lvl.dwDebugLevel = level;
  69. /* set new state */
  70. ret = saa7164_cmd_send(dev, 0, SET_CUR,
  71. SET_DEBUG_LEVEL_CONTROL, sizeof(lvl), &lvl);
  72. if (ret != SAA_OK)
  73. printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
  74. return ret;
  75. }
  76. int saa7164_api_set_vbi_format(struct saa7164_port *port)
  77. {
  78. struct saa7164_dev *dev = port->dev;
  79. struct tmComResProbeCommit fmt, rsp;
  80. int ret;
  81. dprintk(DBGLVL_API, "%s(nr=%d, unitid=0x%x)\n", __func__,
  82. port->nr, port->hwcfg.unitid);
  83. fmt.bmHint = 0;
  84. fmt.bFormatIndex = 1;
  85. fmt.bFrameIndex = 1;
  86. /* Probe, see if it can support this format */
  87. ret = saa7164_cmd_send(port->dev, port->hwcfg.unitid,
  88. SET_CUR, SAA_PROBE_CONTROL, sizeof(fmt), &fmt);
  89. if (ret != SAA_OK)
  90. printk(KERN_ERR "%s() set error, ret = 0x%x\n", __func__, ret);
  91. /* See of the format change was successful */
  92. ret = saa7164_cmd_send(port->dev, port->hwcfg.unitid,
  93. GET_CUR, SAA_PROBE_CONTROL, sizeof(rsp), &rsp);
  94. if (ret != SAA_OK) {
  95. printk(KERN_ERR "%s() get error, ret = 0x%x\n", __func__, ret);
  96. } else {
  97. /* Compare requested vs received, should be same */
  98. if (memcmp(&fmt, &rsp, sizeof(rsp)) == 0) {
  99. dprintk(DBGLVL_API, "SET/PROBE Verified\n");
  100. /* Ask the device to select the negotiated format */
  101. ret = saa7164_cmd_send(port->dev, port->hwcfg.unitid,
  102. SET_CUR, SAA_COMMIT_CONTROL, sizeof(fmt), &fmt);
  103. if (ret != SAA_OK)
  104. printk(KERN_ERR "%s() commit error, ret = 0x%x\n",
  105. __func__, ret);
  106. ret = saa7164_cmd_send(port->dev, port->hwcfg.unitid,
  107. GET_CUR, SAA_COMMIT_CONTROL, sizeof(rsp), &rsp);
  108. if (ret != SAA_OK)
  109. printk(KERN_ERR "%s() GET commit error, ret = 0x%x\n",
  110. __func__, ret);
  111. if (memcmp(&fmt, &rsp, sizeof(rsp)) != 0) {
  112. printk(KERN_ERR "%s() memcmp error, ret = 0x%x\n",
  113. __func__, ret);
  114. } else
  115. dprintk(DBGLVL_API, "SET/COMMIT Verified\n");
  116. dprintk(DBGLVL_API, "rsp.bmHint = 0x%x\n", rsp.bmHint);
  117. dprintk(DBGLVL_API, "rsp.bFormatIndex = 0x%x\n",
  118. rsp.bFormatIndex);
  119. dprintk(DBGLVL_API, "rsp.bFrameIndex = 0x%x\n",
  120. rsp.bFrameIndex);
  121. } else
  122. printk(KERN_ERR "%s() compare failed\n", __func__);
  123. }
  124. if (ret == SAA_OK)
  125. dprintk(DBGLVL_API, "%s(nr=%d) Success\n", __func__, port->nr);
  126. return ret;
  127. }
  128. static int saa7164_api_set_gop_size(struct saa7164_port *port)
  129. {
  130. struct saa7164_dev *dev = port->dev;
  131. struct tmComResEncVideoGopStructure gs;
  132. int ret;
  133. dprintk(DBGLVL_ENC, "%s()\n", __func__);
  134. gs.ucRefFrameDist = port->encoder_params.refdist;
  135. gs.ucGOPSize = port->encoder_params.gop_size;
  136. ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, SET_CUR,
  137. EU_VIDEO_GOP_STRUCTURE_CONTROL,
  138. sizeof(gs), &gs);
  139. if (ret != SAA_OK)
  140. printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
  141. return ret;
  142. }
  143. int saa7164_api_set_encoder(struct saa7164_port *port)
  144. {
  145. struct saa7164_dev *dev = port->dev;
  146. struct tmComResEncVideoBitRate vb;
  147. struct tmComResEncAudioBitRate ab;
  148. int ret;
  149. dprintk(DBGLVL_ENC, "%s() unitid=0x%x\n", __func__,
  150. port->hwcfg.sourceid);
  151. if (port->encoder_params.stream_type == V4L2_MPEG_STREAM_TYPE_MPEG2_PS)
  152. port->encoder_profile = EU_PROFILE_PS_DVD;
  153. else
  154. port->encoder_profile = EU_PROFILE_TS_HQ;
  155. ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, SET_CUR,
  156. EU_PROFILE_CONTROL, sizeof(u8), &port->encoder_profile);
  157. if (ret != SAA_OK)
  158. printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
  159. /* Resolution */
  160. ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, SET_CUR,
  161. EU_PROFILE_CONTROL, sizeof(u8), &port->encoder_profile);
  162. if (ret != SAA_OK)
  163. printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
  164. /* Establish video bitrates */
  165. if (port->encoder_params.bitrate_mode ==
  166. V4L2_MPEG_VIDEO_BITRATE_MODE_CBR)
  167. vb.ucVideoBitRateMode = EU_VIDEO_BIT_RATE_MODE_CONSTANT;
  168. else
  169. vb.ucVideoBitRateMode = EU_VIDEO_BIT_RATE_MODE_VARIABLE_PEAK;
  170. vb.dwVideoBitRate = port->encoder_params.bitrate;
  171. vb.dwVideoBitRatePeak = port->encoder_params.bitrate_peak;
  172. ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, SET_CUR,
  173. EU_VIDEO_BIT_RATE_CONTROL,
  174. sizeof(struct tmComResEncVideoBitRate),
  175. &vb);
  176. if (ret != SAA_OK)
  177. printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
  178. /* Establish audio bitrates */
  179. ab.ucAudioBitRateMode = 0;
  180. ab.dwAudioBitRate = 384000;
  181. ab.dwAudioBitRatePeak = ab.dwAudioBitRate;
  182. ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, SET_CUR,
  183. EU_AUDIO_BIT_RATE_CONTROL,
  184. sizeof(struct tmComResEncAudioBitRate),
  185. &ab);
  186. if (ret != SAA_OK)
  187. printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__,
  188. ret);
  189. saa7164_api_set_aspect_ratio(port);
  190. saa7164_api_set_gop_size(port);
  191. return ret;
  192. }
  193. int saa7164_api_get_encoder(struct saa7164_port *port)
  194. {
  195. struct saa7164_dev *dev = port->dev;
  196. struct tmComResEncVideoBitRate v;
  197. struct tmComResEncAudioBitRate a;
  198. struct tmComResEncVideoInputAspectRatio ar;
  199. int ret;
  200. dprintk(DBGLVL_ENC, "%s() unitid=0x%x\n", __func__,
  201. port->hwcfg.sourceid);
  202. port->encoder_profile = 0;
  203. port->video_format = 0;
  204. port->video_resolution = 0;
  205. port->audio_format = 0;
  206. ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, GET_CUR,
  207. EU_PROFILE_CONTROL, sizeof(u8), &port->encoder_profile);
  208. if (ret != SAA_OK)
  209. printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
  210. ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, GET_CUR,
  211. EU_VIDEO_RESOLUTION_CONTROL, sizeof(u8),
  212. &port->video_resolution);
  213. if (ret != SAA_OK)
  214. printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
  215. ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, GET_CUR,
  216. EU_VIDEO_FORMAT_CONTROL, sizeof(u8), &port->video_format);
  217. if (ret != SAA_OK)
  218. printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
  219. ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, GET_CUR,
  220. EU_VIDEO_BIT_RATE_CONTROL, sizeof(v), &v);
  221. if (ret != SAA_OK)
  222. printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
  223. ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, GET_CUR,
  224. EU_AUDIO_FORMAT_CONTROL, sizeof(u8), &port->audio_format);
  225. if (ret != SAA_OK)
  226. printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
  227. ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, GET_CUR,
  228. EU_AUDIO_BIT_RATE_CONTROL, sizeof(a), &a);
  229. if (ret != SAA_OK)
  230. printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
  231. /* Aspect Ratio */
  232. ar.width = 0;
  233. ar.height = 0;
  234. ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, GET_CUR,
  235. EU_VIDEO_INPUT_ASPECT_CONTROL,
  236. sizeof(struct tmComResEncVideoInputAspectRatio), &ar);
  237. if (ret != SAA_OK)
  238. printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
  239. dprintk(DBGLVL_ENC, "encoder_profile = %d\n", port->encoder_profile);
  240. dprintk(DBGLVL_ENC, "video_format = %d\n", port->video_format);
  241. dprintk(DBGLVL_ENC, "audio_format = %d\n", port->audio_format);
  242. dprintk(DBGLVL_ENC, "video_resolution= %d\n", port->video_resolution);
  243. dprintk(DBGLVL_ENC, "v.ucVideoBitRateMode = %d\n",
  244. v.ucVideoBitRateMode);
  245. dprintk(DBGLVL_ENC, "v.dwVideoBitRate = %d\n",
  246. v.dwVideoBitRate);
  247. dprintk(DBGLVL_ENC, "v.dwVideoBitRatePeak = %d\n",
  248. v.dwVideoBitRatePeak);
  249. dprintk(DBGLVL_ENC, "a.ucVideoBitRateMode = %d\n",
  250. a.ucAudioBitRateMode);
  251. dprintk(DBGLVL_ENC, "a.dwVideoBitRate = %d\n",
  252. a.dwAudioBitRate);
  253. dprintk(DBGLVL_ENC, "a.dwVideoBitRatePeak = %d\n",
  254. a.dwAudioBitRatePeak);
  255. dprintk(DBGLVL_ENC, "aspect.width / height = %d:%d\n",
  256. ar.width, ar.height);
  257. return ret;
  258. }
  259. int saa7164_api_set_aspect_ratio(struct saa7164_port *port)
  260. {
  261. struct saa7164_dev *dev = port->dev;
  262. struct tmComResEncVideoInputAspectRatio ar;
  263. int ret;
  264. dprintk(DBGLVL_ENC, "%s(%d)\n", __func__,
  265. port->encoder_params.ctl_aspect);
  266. switch (port->encoder_params.ctl_aspect) {
  267. case V4L2_MPEG_VIDEO_ASPECT_1x1:
  268. ar.width = 1;
  269. ar.height = 1;
  270. break;
  271. case V4L2_MPEG_VIDEO_ASPECT_4x3:
  272. ar.width = 4;
  273. ar.height = 3;
  274. break;
  275. case V4L2_MPEG_VIDEO_ASPECT_16x9:
  276. ar.width = 16;
  277. ar.height = 9;
  278. break;
  279. case V4L2_MPEG_VIDEO_ASPECT_221x100:
  280. ar.width = 221;
  281. ar.height = 100;
  282. break;
  283. default:
  284. BUG();
  285. }
  286. dprintk(DBGLVL_ENC, "%s(%d) now %d:%d\n", __func__,
  287. port->encoder_params.ctl_aspect,
  288. ar.width, ar.height);
  289. /* Aspect Ratio */
  290. ret = saa7164_cmd_send(port->dev, port->hwcfg.sourceid, SET_CUR,
  291. EU_VIDEO_INPUT_ASPECT_CONTROL,
  292. sizeof(struct tmComResEncVideoInputAspectRatio), &ar);
  293. if (ret != SAA_OK)
  294. printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
  295. return ret;
  296. }
  297. int saa7164_api_set_usercontrol(struct saa7164_port *port, u8 ctl)
  298. {
  299. struct saa7164_dev *dev = port->dev;
  300. int ret;
  301. u16 val;
  302. if (ctl == PU_BRIGHTNESS_CONTROL)
  303. val = port->ctl_brightness;
  304. else
  305. if (ctl == PU_CONTRAST_CONTROL)
  306. val = port->ctl_contrast;
  307. else
  308. if (ctl == PU_HUE_CONTROL)
  309. val = port->ctl_hue;
  310. else
  311. if (ctl == PU_SATURATION_CONTROL)
  312. val = port->ctl_saturation;
  313. else
  314. if (ctl == PU_SHARPNESS_CONTROL)
  315. val = port->ctl_sharpness;
  316. else
  317. return -EINVAL;
  318. dprintk(DBGLVL_ENC, "%s() unitid=0x%x ctl=%d, val=%d\n",
  319. __func__, port->encunit.vsourceid, ctl, val);
  320. ret = saa7164_cmd_send(port->dev, port->encunit.vsourceid, SET_CUR,
  321. ctl, sizeof(u16), &val);
  322. if (ret != SAA_OK)
  323. printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
  324. return ret;
  325. }
  326. int saa7164_api_get_usercontrol(struct saa7164_port *port, u8 ctl)
  327. {
  328. struct saa7164_dev *dev = port->dev;
  329. int ret;
  330. u16 val;
  331. ret = saa7164_cmd_send(port->dev, port->encunit.vsourceid, GET_CUR,
  332. ctl, sizeof(u16), &val);
  333. if (ret != SAA_OK) {
  334. printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
  335. return ret;
  336. }
  337. dprintk(DBGLVL_ENC, "%s() ctl=%d, val=%d\n",
  338. __func__, ctl, val);
  339. if (ctl == PU_BRIGHTNESS_CONTROL)
  340. port->ctl_brightness = val;
  341. else
  342. if (ctl == PU_CONTRAST_CONTROL)
  343. port->ctl_contrast = val;
  344. else
  345. if (ctl == PU_HUE_CONTROL)
  346. port->ctl_hue = val;
  347. else
  348. if (ctl == PU_SATURATION_CONTROL)
  349. port->ctl_saturation = val;
  350. else
  351. if (ctl == PU_SHARPNESS_CONTROL)
  352. port->ctl_sharpness = val;
  353. return ret;
  354. }
  355. int saa7164_api_set_videomux(struct saa7164_port *port)
  356. {
  357. struct saa7164_dev *dev = port->dev;
  358. u8 inputs[] = { 1, 2, 2, 2, 5, 5, 5 };
  359. int ret;
  360. dprintk(DBGLVL_ENC, "%s() v_mux=%d a_mux=%d\n",
  361. __func__, port->mux_input, inputs[port->mux_input - 1]);
  362. /* Audio Mute */
  363. ret = saa7164_api_audio_mute(port, 1);
  364. if (ret != SAA_OK)
  365. printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
  366. /* Video Mux */
  367. ret = saa7164_cmd_send(port->dev, port->vidproc.sourceid, SET_CUR,
  368. SU_INPUT_SELECT_CONTROL, sizeof(u8), &port->mux_input);
  369. if (ret != SAA_OK)
  370. printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
  371. /* Audio Mux */
  372. ret = saa7164_cmd_send(port->dev, port->audfeat.sourceid, SET_CUR,
  373. SU_INPUT_SELECT_CONTROL, sizeof(u8),
  374. &inputs[port->mux_input - 1]);
  375. if (ret != SAA_OK)
  376. printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
  377. /* Audio UnMute */
  378. ret = saa7164_api_audio_mute(port, 0);
  379. if (ret != SAA_OK)
  380. printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
  381. return ret;
  382. }
  383. int saa7164_api_audio_mute(struct saa7164_port *port, int mute)
  384. {
  385. struct saa7164_dev *dev = port->dev;
  386. u8 v = mute;
  387. int ret;
  388. dprintk(DBGLVL_API, "%s(%d)\n", __func__, mute);
  389. ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, SET_CUR,
  390. MUTE_CONTROL, sizeof(u8), &v);
  391. if (ret != SAA_OK)
  392. printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
  393. return ret;
  394. }
  395. /* 0 = silence, 0xff = full */
  396. int saa7164_api_set_audio_volume(struct saa7164_port *port, s8 level)
  397. {
  398. struct saa7164_dev *dev = port->dev;
  399. s16 v, min, max;
  400. int ret;
  401. dprintk(DBGLVL_API, "%s(%d)\n", __func__, level);
  402. /* Obtain the min/max ranges */
  403. ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, GET_MIN,
  404. VOLUME_CONTROL, sizeof(u16), &min);
  405. if (ret != SAA_OK)
  406. printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
  407. ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, GET_MAX,
  408. VOLUME_CONTROL, sizeof(u16), &max);
  409. if (ret != SAA_OK)
  410. printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
  411. ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, GET_CUR,
  412. (0x01 << 8) | VOLUME_CONTROL, sizeof(u16), &v);
  413. if (ret != SAA_OK)
  414. printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
  415. dprintk(DBGLVL_API, "%s(%d) min=%d max=%d cur=%d\n", __func__,
  416. level, min, max, v);
  417. v = level;
  418. if (v < min)
  419. v = min;
  420. if (v > max)
  421. v = max;
  422. /* Left */
  423. ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, SET_CUR,
  424. (0x01 << 8) | VOLUME_CONTROL, sizeof(s16), &v);
  425. if (ret != SAA_OK)
  426. printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
  427. /* Right */
  428. ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, SET_CUR,
  429. (0x02 << 8) | VOLUME_CONTROL, sizeof(s16), &v);
  430. if (ret != SAA_OK)
  431. printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
  432. ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, GET_CUR,
  433. (0x01 << 8) | VOLUME_CONTROL, sizeof(u16), &v);
  434. if (ret != SAA_OK)
  435. printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
  436. dprintk(DBGLVL_API, "%s(%d) min=%d max=%d cur=%d\n", __func__,
  437. level, min, max, v);
  438. return ret;
  439. }
  440. int saa7164_api_set_audio_std(struct saa7164_port *port)
  441. {
  442. struct saa7164_dev *dev = port->dev;
  443. struct tmComResAudioDefaults lvl;
  444. struct tmComResTunerStandard tvaudio;
  445. int ret;
  446. dprintk(DBGLVL_API, "%s()\n", __func__);
  447. /* Establish default levels */
  448. lvl.ucDecoderLevel = TMHW_LEV_ADJ_DECLEV_DEFAULT;
  449. lvl.ucDecoderFM_Level = TMHW_LEV_ADJ_DECLEV_DEFAULT;
  450. lvl.ucMonoLevel = TMHW_LEV_ADJ_MONOLEV_DEFAULT;
  451. lvl.ucNICAM_Level = TMHW_LEV_ADJ_NICLEV_DEFAULT;
  452. lvl.ucSAP_Level = TMHW_LEV_ADJ_SAPLEV_DEFAULT;
  453. lvl.ucADC_Level = TMHW_LEV_ADJ_ADCLEV_DEFAULT;
  454. ret = saa7164_cmd_send(port->dev, port->audfeat.unitid, SET_CUR,
  455. AUDIO_DEFAULT_CONTROL, sizeof(struct tmComResAudioDefaults),
  456. &lvl);
  457. if (ret != SAA_OK)
  458. printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
  459. /* Manually select the appropriate TV audio standard */
  460. if (port->encodernorm.id & V4L2_STD_NTSC) {
  461. tvaudio.std = TU_STANDARD_NTSC_M;
  462. tvaudio.country = 1;
  463. } else {
  464. tvaudio.std = TU_STANDARD_PAL_I;
  465. tvaudio.country = 44;
  466. }
  467. ret = saa7164_cmd_send(port->dev, port->tunerunit.unitid, SET_CUR,
  468. TU_STANDARD_CONTROL, sizeof(tvaudio), &tvaudio);
  469. if (ret != SAA_OK)
  470. printk(KERN_ERR "%s() TU_STANDARD_CONTROL error, ret = 0x%x\n",
  471. __func__, ret);
  472. return ret;
  473. }
  474. int saa7164_api_set_audio_detection(struct saa7164_port *port, int autodetect)
  475. {
  476. struct saa7164_dev *dev = port->dev;
  477. struct tmComResTunerStandardAuto p;
  478. int ret;
  479. dprintk(DBGLVL_API, "%s(%d)\n", __func__, autodetect);
  480. /* Disable TV Audio autodetect if not already set (buggy) */
  481. if (autodetect)
  482. p.mode = TU_STANDARD_AUTO;
  483. else
  484. p.mode = TU_STANDARD_MANUAL;
  485. ret = saa7164_cmd_send(port->dev, port->tunerunit.unitid, SET_CUR,
  486. TU_STANDARD_AUTO_CONTROL, sizeof(p), &p);
  487. if (ret != SAA_OK)
  488. printk(KERN_ERR
  489. "%s() TU_STANDARD_AUTO_CONTROL error, ret = 0x%x\n",
  490. __func__, ret);
  491. return ret;
  492. }
  493. int saa7164_api_get_videomux(struct saa7164_port *port)
  494. {
  495. struct saa7164_dev *dev = port->dev;
  496. int ret;
  497. ret = saa7164_cmd_send(port->dev, port->vidproc.sourceid, GET_CUR,
  498. SU_INPUT_SELECT_CONTROL, sizeof(u8), &port->mux_input);
  499. if (ret != SAA_OK)
  500. printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
  501. dprintk(DBGLVL_ENC, "%s() v_mux=%d\n",
  502. __func__, port->mux_input);
  503. return ret;
  504. }
  505. static int saa7164_api_set_dif(struct saa7164_port *port, u8 reg, u8 val)
  506. {
  507. struct saa7164_dev *dev = port->dev;
  508. u16 len = 0;
  509. u8 buf[256];
  510. int ret;
  511. u8 mas;
  512. dprintk(DBGLVL_API, "%s(nr=%d type=%d val=%x)\n", __func__,
  513. port->nr, port->type, val);
  514. if (port->nr == 0)
  515. mas = 0xd0;
  516. else
  517. mas = 0xe0;
  518. memset(buf, 0, sizeof(buf));
  519. buf[0x00] = 0x04;
  520. buf[0x01] = 0x00;
  521. buf[0x02] = 0x00;
  522. buf[0x03] = 0x00;
  523. buf[0x04] = 0x04;
  524. buf[0x05] = 0x00;
  525. buf[0x06] = 0x00;
  526. buf[0x07] = 0x00;
  527. buf[0x08] = reg;
  528. buf[0x09] = 0x26;
  529. buf[0x0a] = mas;
  530. buf[0x0b] = 0xb0;
  531. buf[0x0c] = val;
  532. buf[0x0d] = 0x00;
  533. buf[0x0e] = 0x00;
  534. buf[0x0f] = 0x00;
  535. ret = saa7164_cmd_send(dev, port->ifunit.unitid, GET_LEN,
  536. EXU_REGISTER_ACCESS_CONTROL, sizeof(len), &len);
  537. if (ret != SAA_OK) {
  538. printk(KERN_ERR "%s() error, ret(1) = 0x%x\n", __func__, ret);
  539. return -EIO;
  540. }
  541. ret = saa7164_cmd_send(dev, port->ifunit.unitid, SET_CUR,
  542. EXU_REGISTER_ACCESS_CONTROL, len, &buf);
  543. if (ret != SAA_OK)
  544. printk(KERN_ERR "%s() error, ret(2) = 0x%x\n", __func__, ret);
  545. #if 0
  546. print_hex_dump(KERN_INFO, "", DUMP_PREFIX_OFFSET, 16, 1, buf, 16,
  547. false);
  548. #endif
  549. return ret == SAA_OK ? 0 : -EIO;
  550. }
  551. /* Disable the IF block AGC controls */
  552. int saa7164_api_configure_dif(struct saa7164_port *port, u32 std)
  553. {
  554. struct saa7164_dev *dev = port->dev;
  555. u8 agc_disable;
  556. dprintk(DBGLVL_API, "%s(nr=%d, 0x%x)\n", __func__, port->nr, std);
  557. if (std & V4L2_STD_NTSC) {
  558. dprintk(DBGLVL_API, " NTSC\n");
  559. saa7164_api_set_dif(port, 0x00, 0x01); /* Video Standard */
  560. agc_disable = 0;
  561. } else if (std & V4L2_STD_PAL_I) {
  562. dprintk(DBGLVL_API, " PAL-I\n");
  563. saa7164_api_set_dif(port, 0x00, 0x08); /* Video Standard */
  564. agc_disable = 0;
  565. } else if (std & V4L2_STD_PAL_M) {
  566. dprintk(DBGLVL_API, " PAL-M\n");
  567. saa7164_api_set_dif(port, 0x00, 0x01); /* Video Standard */
  568. agc_disable = 0;
  569. } else if (std & V4L2_STD_PAL_N) {
  570. dprintk(DBGLVL_API, " PAL-N\n");
  571. saa7164_api_set_dif(port, 0x00, 0x01); /* Video Standard */
  572. agc_disable = 0;
  573. } else if (std & V4L2_STD_PAL_Nc) {
  574. dprintk(DBGLVL_API, " PAL-Nc\n");
  575. saa7164_api_set_dif(port, 0x00, 0x01); /* Video Standard */
  576. agc_disable = 0;
  577. } else if (std & V4L2_STD_PAL_B) {
  578. dprintk(DBGLVL_API, " PAL-B\n");
  579. saa7164_api_set_dif(port, 0x00, 0x02); /* Video Standard */
  580. agc_disable = 0;
  581. } else if (std & V4L2_STD_PAL_DK) {
  582. dprintk(DBGLVL_API, " PAL-DK\n");
  583. saa7164_api_set_dif(port, 0x00, 0x10); /* Video Standard */
  584. agc_disable = 0;
  585. } else if (std & V4L2_STD_SECAM_L) {
  586. dprintk(DBGLVL_API, " SECAM-L\n");
  587. saa7164_api_set_dif(port, 0x00, 0x20); /* Video Standard */
  588. agc_disable = 0;
  589. } else {
  590. /* Unknown standard, assume DTV */
  591. dprintk(DBGLVL_API, " Unknown (assuming DTV)\n");
  592. /* Undefinded Video Standard */
  593. saa7164_api_set_dif(port, 0x00, 0x80);
  594. agc_disable = 1;
  595. }
  596. saa7164_api_set_dif(port, 0x48, 0xa0); /* AGC Functions 1 */
  597. saa7164_api_set_dif(port, 0xc0, agc_disable); /* AGC Output Disable */
  598. saa7164_api_set_dif(port, 0x7c, 0x04); /* CVBS EQ */
  599. saa7164_api_set_dif(port, 0x04, 0x01); /* Active */
  600. msleep(100);
  601. saa7164_api_set_dif(port, 0x04, 0x00); /* Active (again) */
  602. msleep(100);
  603. return 0;
  604. }
  605. /* Ensure the dif is in the correct state for the operating mode
  606. * (analog / dtv). We only configure the diff through the analog encoder
  607. * so when we're in digital mode we need to find the appropriate encoder
  608. * and use it to configure the DIF.
  609. */
  610. int saa7164_api_initialize_dif(struct saa7164_port *port)
  611. {
  612. struct saa7164_dev *dev = port->dev;
  613. struct saa7164_port *p = NULL;
  614. int ret = -EINVAL;
  615. u32 std = 0;
  616. dprintk(DBGLVL_API, "%s(nr=%d type=%d)\n", __func__,
  617. port->nr, port->type);
  618. if (port->type == SAA7164_MPEG_ENCODER) {
  619. /* Pick any analog standard to init the diff.
  620. * we'll come back during encoder_init'
  621. * and set the correct standard if requried.
  622. */
  623. std = V4L2_STD_NTSC;
  624. } else
  625. if (port->type == SAA7164_MPEG_DVB) {
  626. if (port->nr == SAA7164_PORT_TS1)
  627. p = &dev->ports[SAA7164_PORT_ENC1];
  628. else
  629. p = &dev->ports[SAA7164_PORT_ENC2];
  630. } else
  631. if (port->type == SAA7164_MPEG_VBI) {
  632. std = V4L2_STD_NTSC;
  633. if (port->nr == SAA7164_PORT_VBI1)
  634. p = &dev->ports[SAA7164_PORT_ENC1];
  635. else
  636. p = &dev->ports[SAA7164_PORT_ENC2];
  637. } else
  638. BUG();
  639. if (p)
  640. ret = saa7164_api_configure_dif(p, std);
  641. return ret;
  642. }
  643. int saa7164_api_transition_port(struct saa7164_port *port, u8 mode)
  644. {
  645. struct saa7164_dev *dev = port->dev;
  646. int ret;
  647. dprintk(DBGLVL_API, "%s(nr=%d unitid=0x%x,%d)\n",
  648. __func__, port->nr, port->hwcfg.unitid, mode);
  649. ret = saa7164_cmd_send(port->dev, port->hwcfg.unitid, SET_CUR,
  650. SAA_STATE_CONTROL, sizeof(mode), &mode);
  651. if (ret != SAA_OK)
  652. printk(KERN_ERR "%s(portnr %d unitid 0x%x) error, ret = 0x%x\n",
  653. __func__, port->nr, port->hwcfg.unitid, ret);
  654. return ret;
  655. }
  656. int saa7164_api_get_fw_version(struct saa7164_dev *dev, u32 *version)
  657. {
  658. int ret;
  659. ret = saa7164_cmd_send(dev, 0, GET_CUR,
  660. GET_FW_VERSION_CONTROL, sizeof(u32), version);
  661. if (ret != SAA_OK)
  662. printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
  663. return ret;
  664. }
  665. int saa7164_api_read_eeprom(struct saa7164_dev *dev, u8 *buf, int buflen)
  666. {
  667. u8 reg[] = { 0x0f, 0x00 };
  668. if (buflen < 128)
  669. return -ENOMEM;
  670. /* Assumption: Hauppauge eeprom is at 0xa0 on on bus 0 */
  671. /* TODO: Pull the details from the boards struct */
  672. return saa7164_api_i2c_read(&dev->i2c_bus[0], 0xa0 >> 1, sizeof(reg),
  673. &reg[0], 128, buf);
  674. }
  675. static int saa7164_api_configure_port_vbi(struct saa7164_dev *dev,
  676. struct saa7164_port *port)
  677. {
  678. struct tmComResVBIFormatDescrHeader *fmt = &port->vbi_fmt_ntsc;
  679. dprintk(DBGLVL_API, " bFormatIndex = 0x%x\n", fmt->bFormatIndex);
  680. dprintk(DBGLVL_API, " VideoStandard = 0x%x\n", fmt->VideoStandard);
  681. dprintk(DBGLVL_API, " StartLine = %d\n", fmt->StartLine);
  682. dprintk(DBGLVL_API, " EndLine = %d\n", fmt->EndLine);
  683. dprintk(DBGLVL_API, " FieldRate = %d\n", fmt->FieldRate);
  684. dprintk(DBGLVL_API, " bNumLines = %d\n", fmt->bNumLines);
  685. /* Cache the hardware configuration in the port */
  686. port->bufcounter = port->hwcfg.BARLocation;
  687. port->pitch = port->hwcfg.BARLocation + (2 * sizeof(u32));
  688. port->bufsize = port->hwcfg.BARLocation + (3 * sizeof(u32));
  689. port->bufoffset = port->hwcfg.BARLocation + (4 * sizeof(u32));
  690. port->bufptr32l = port->hwcfg.BARLocation +
  691. (4 * sizeof(u32)) +
  692. (sizeof(u32) * port->hwcfg.buffercount) + sizeof(u32);
  693. port->bufptr32h = port->hwcfg.BARLocation +
  694. (4 * sizeof(u32)) +
  695. (sizeof(u32) * port->hwcfg.buffercount);
  696. port->bufptr64 = port->hwcfg.BARLocation +
  697. (4 * sizeof(u32)) +
  698. (sizeof(u32) * port->hwcfg.buffercount);
  699. dprintk(DBGLVL_API, " = port->hwcfg.BARLocation = 0x%x\n",
  700. port->hwcfg.BARLocation);
  701. dprintk(DBGLVL_API, " = VS_FORMAT_VBI (becomes dev->en[%d])\n",
  702. port->nr);
  703. return 0;
  704. }
  705. static int
  706. saa7164_api_configure_port_mpeg2ts(struct saa7164_dev *dev,
  707. struct saa7164_port *port,
  708. struct tmComResTSFormatDescrHeader *tsfmt)
  709. {
  710. dprintk(DBGLVL_API, " bFormatIndex = 0x%x\n", tsfmt->bFormatIndex);
  711. dprintk(DBGLVL_API, " bDataOffset = 0x%x\n", tsfmt->bDataOffset);
  712. dprintk(DBGLVL_API, " bPacketLength= 0x%x\n", tsfmt->bPacketLength);
  713. dprintk(DBGLVL_API, " bStrideLength= 0x%x\n", tsfmt->bStrideLength);
  714. dprintk(DBGLVL_API, " bguid = (....)\n");
  715. /* Cache the hardware configuration in the port */
  716. port->bufcounter = port->hwcfg.BARLocation;
  717. port->pitch = port->hwcfg.BARLocation + (2 * sizeof(u32));
  718. port->bufsize = port->hwcfg.BARLocation + (3 * sizeof(u32));
  719. port->bufoffset = port->hwcfg.BARLocation + (4 * sizeof(u32));
  720. port->bufptr32l = port->hwcfg.BARLocation +
  721. (4 * sizeof(u32)) +
  722. (sizeof(u32) * port->hwcfg.buffercount) + sizeof(u32);
  723. port->bufptr32h = port->hwcfg.BARLocation +
  724. (4 * sizeof(u32)) +
  725. (sizeof(u32) * port->hwcfg.buffercount);
  726. port->bufptr64 = port->hwcfg.BARLocation +
  727. (4 * sizeof(u32)) +
  728. (sizeof(u32) * port->hwcfg.buffercount);
  729. dprintk(DBGLVL_API, " = port->hwcfg.BARLocation = 0x%x\n",
  730. port->hwcfg.BARLocation);
  731. dprintk(DBGLVL_API, " = VS_FORMAT_MPEGTS (becomes dev->ts[%d])\n",
  732. port->nr);
  733. return 0;
  734. }
  735. static int
  736. saa7164_api_configure_port_mpeg2ps(struct saa7164_dev *dev,
  737. struct saa7164_port *port,
  738. struct tmComResPSFormatDescrHeader *fmt)
  739. {
  740. dprintk(DBGLVL_API, " bFormatIndex = 0x%x\n", fmt->bFormatIndex);
  741. dprintk(DBGLVL_API, " wPacketLength= 0x%x\n", fmt->wPacketLength);
  742. dprintk(DBGLVL_API, " wPackLength= 0x%x\n", fmt->wPackLength);
  743. dprintk(DBGLVL_API, " bPackDataType= 0x%x\n", fmt->bPackDataType);
  744. /* Cache the hardware configuration in the port */
  745. /* TODO: CHECK THIS in the port config */
  746. port->bufcounter = port->hwcfg.BARLocation;
  747. port->pitch = port->hwcfg.BARLocation + (2 * sizeof(u32));
  748. port->bufsize = port->hwcfg.BARLocation + (3 * sizeof(u32));
  749. port->bufoffset = port->hwcfg.BARLocation + (4 * sizeof(u32));
  750. port->bufptr32l = port->hwcfg.BARLocation +
  751. (4 * sizeof(u32)) +
  752. (sizeof(u32) * port->hwcfg.buffercount) + sizeof(u32);
  753. port->bufptr32h = port->hwcfg.BARLocation +
  754. (4 * sizeof(u32)) +
  755. (sizeof(u32) * port->hwcfg.buffercount);
  756. port->bufptr64 = port->hwcfg.BARLocation +
  757. (4 * sizeof(u32)) +
  758. (sizeof(u32) * port->hwcfg.buffercount);
  759. dprintk(DBGLVL_API, " = port->hwcfg.BARLocation = 0x%x\n",
  760. port->hwcfg.BARLocation);
  761. dprintk(DBGLVL_API, " = VS_FORMAT_MPEGPS (becomes dev->enc[%d])\n",
  762. port->nr);
  763. return 0;
  764. }
  765. static int saa7164_api_dump_subdevs(struct saa7164_dev *dev, u8 *buf, int len)
  766. {
  767. struct saa7164_port *tsport = NULL;
  768. struct saa7164_port *encport = NULL;
  769. struct saa7164_port *vbiport = NULL;
  770. u32 idx, next_offset;
  771. int i;
  772. struct tmComResDescrHeader *hdr, *t;
  773. struct tmComResExtDevDescrHeader *exthdr;
  774. struct tmComResPathDescrHeader *pathhdr;
  775. struct tmComResAntTermDescrHeader *anttermhdr;
  776. struct tmComResTunerDescrHeader *tunerunithdr;
  777. struct tmComResDMATermDescrHeader *vcoutputtermhdr;
  778. struct tmComResTSFormatDescrHeader *tsfmt;
  779. struct tmComResPSFormatDescrHeader *psfmt;
  780. struct tmComResSelDescrHeader *psel;
  781. struct tmComResProcDescrHeader *pdh;
  782. struct tmComResAFeatureDescrHeader *afd;
  783. struct tmComResEncoderDescrHeader *edh;
  784. struct tmComResVBIFormatDescrHeader *vbifmt;
  785. u32 currpath = 0;
  786. dprintk(DBGLVL_API,
  787. "%s(?,?,%d) sizeof(struct tmComResDescrHeader) = %d bytes\n",
  788. __func__, len, (u32)sizeof(struct tmComResDescrHeader));
  789. for (idx = 0; idx < (len - sizeof(struct tmComResDescrHeader));) {
  790. hdr = (struct tmComResDescrHeader *)(buf + idx);
  791. if (hdr->type != CS_INTERFACE)
  792. return SAA_ERR_NOT_SUPPORTED;
  793. dprintk(DBGLVL_API, "@ 0x%x =\n", idx);
  794. switch (hdr->subtype) {
  795. case GENERAL_REQUEST:
  796. dprintk(DBGLVL_API, " GENERAL_REQUEST\n");
  797. break;
  798. case VC_TUNER_PATH:
  799. dprintk(DBGLVL_API, " VC_TUNER_PATH\n");
  800. pathhdr = (struct tmComResPathDescrHeader *)(buf + idx);
  801. dprintk(DBGLVL_API, " pathid = 0x%x\n",
  802. pathhdr->pathid);
  803. currpath = pathhdr->pathid;
  804. break;
  805. case VC_INPUT_TERMINAL:
  806. dprintk(DBGLVL_API, " VC_INPUT_TERMINAL\n");
  807. anttermhdr =
  808. (struct tmComResAntTermDescrHeader *)(buf + idx);
  809. dprintk(DBGLVL_API, " terminalid = 0x%x\n",
  810. anttermhdr->terminalid);
  811. dprintk(DBGLVL_API, " terminaltype = 0x%x\n",
  812. anttermhdr->terminaltype);
  813. switch (anttermhdr->terminaltype) {
  814. case ITT_ANTENNA:
  815. dprintk(DBGLVL_API, " = ITT_ANTENNA\n");
  816. break;
  817. case LINE_CONNECTOR:
  818. dprintk(DBGLVL_API, " = LINE_CONNECTOR\n");
  819. break;
  820. case SPDIF_CONNECTOR:
  821. dprintk(DBGLVL_API, " = SPDIF_CONNECTOR\n");
  822. break;
  823. case COMPOSITE_CONNECTOR:
  824. dprintk(DBGLVL_API,
  825. " = COMPOSITE_CONNECTOR\n");
  826. break;
  827. case SVIDEO_CONNECTOR:
  828. dprintk(DBGLVL_API, " = SVIDEO_CONNECTOR\n");
  829. break;
  830. case COMPONENT_CONNECTOR:
  831. dprintk(DBGLVL_API,
  832. " = COMPONENT_CONNECTOR\n");
  833. break;
  834. case STANDARD_DMA:
  835. dprintk(DBGLVL_API, " = STANDARD_DMA\n");
  836. break;
  837. default:
  838. dprintk(DBGLVL_API, " = undefined (0x%x)\n",
  839. anttermhdr->terminaltype);
  840. }
  841. dprintk(DBGLVL_API, " assocterminal= 0x%x\n",
  842. anttermhdr->assocterminal);
  843. dprintk(DBGLVL_API, " iterminal = 0x%x\n",
  844. anttermhdr->iterminal);
  845. dprintk(DBGLVL_API, " controlsize = 0x%x\n",
  846. anttermhdr->controlsize);
  847. break;
  848. case VC_OUTPUT_TERMINAL:
  849. dprintk(DBGLVL_API, " VC_OUTPUT_TERMINAL\n");
  850. vcoutputtermhdr =
  851. (struct tmComResDMATermDescrHeader *)(buf + idx);
  852. dprintk(DBGLVL_API, " unitid = 0x%x\n",
  853. vcoutputtermhdr->unitid);
  854. dprintk(DBGLVL_API, " terminaltype = 0x%x\n",
  855. vcoutputtermhdr->terminaltype);
  856. switch (vcoutputtermhdr->terminaltype) {
  857. case ITT_ANTENNA:
  858. dprintk(DBGLVL_API, " = ITT_ANTENNA\n");
  859. break;
  860. case LINE_CONNECTOR:
  861. dprintk(DBGLVL_API, " = LINE_CONNECTOR\n");
  862. break;
  863. case SPDIF_CONNECTOR:
  864. dprintk(DBGLVL_API, " = SPDIF_CONNECTOR\n");
  865. break;
  866. case COMPOSITE_CONNECTOR:
  867. dprintk(DBGLVL_API,
  868. " = COMPOSITE_CONNECTOR\n");
  869. break;
  870. case SVIDEO_CONNECTOR:
  871. dprintk(DBGLVL_API, " = SVIDEO_CONNECTOR\n");
  872. break;
  873. case COMPONENT_CONNECTOR:
  874. dprintk(DBGLVL_API,
  875. " = COMPONENT_CONNECTOR\n");
  876. break;
  877. case STANDARD_DMA:
  878. dprintk(DBGLVL_API, " = STANDARD_DMA\n");
  879. break;
  880. default:
  881. dprintk(DBGLVL_API, " = undefined (0x%x)\n",
  882. vcoutputtermhdr->terminaltype);
  883. }
  884. dprintk(DBGLVL_API, " assocterminal= 0x%x\n",
  885. vcoutputtermhdr->assocterminal);
  886. dprintk(DBGLVL_API, " sourceid = 0x%x\n",
  887. vcoutputtermhdr->sourceid);
  888. dprintk(DBGLVL_API, " iterminal = 0x%x\n",
  889. vcoutputtermhdr->iterminal);
  890. dprintk(DBGLVL_API, " BARLocation = 0x%x\n",
  891. vcoutputtermhdr->BARLocation);
  892. dprintk(DBGLVL_API, " flags = 0x%x\n",
  893. vcoutputtermhdr->flags);
  894. dprintk(DBGLVL_API, " interruptid = 0x%x\n",
  895. vcoutputtermhdr->interruptid);
  896. dprintk(DBGLVL_API, " buffercount = 0x%x\n",
  897. vcoutputtermhdr->buffercount);
  898. dprintk(DBGLVL_API, " metadatasize = 0x%x\n",
  899. vcoutputtermhdr->metadatasize);
  900. dprintk(DBGLVL_API, " controlsize = 0x%x\n",
  901. vcoutputtermhdr->controlsize);
  902. dprintk(DBGLVL_API, " numformats = 0x%x\n",
  903. vcoutputtermhdr->numformats);
  904. t = (struct tmComResDescrHeader *)
  905. ((struct tmComResDMATermDescrHeader *)(buf + idx));
  906. next_offset = idx + (vcoutputtermhdr->len);
  907. for (i = 0; i < vcoutputtermhdr->numformats; i++) {
  908. t = (struct tmComResDescrHeader *)
  909. (buf + next_offset);
  910. switch (t->subtype) {
  911. case VS_FORMAT_MPEG2TS:
  912. tsfmt =
  913. (struct tmComResTSFormatDescrHeader *)t;
  914. if (currpath == 1)
  915. tsport = &dev->ports[SAA7164_PORT_TS1];
  916. else
  917. tsport = &dev->ports[SAA7164_PORT_TS2];
  918. memcpy(&tsport->hwcfg, vcoutputtermhdr,
  919. sizeof(*vcoutputtermhdr));
  920. saa7164_api_configure_port_mpeg2ts(dev,
  921. tsport, tsfmt);
  922. break;
  923. case VS_FORMAT_MPEG2PS:
  924. psfmt =
  925. (struct tmComResPSFormatDescrHeader *)t;
  926. if (currpath == 1)
  927. encport = &dev->ports[SAA7164_PORT_ENC1];
  928. else
  929. encport = &dev->ports[SAA7164_PORT_ENC2];
  930. memcpy(&encport->hwcfg, vcoutputtermhdr,
  931. sizeof(*vcoutputtermhdr));
  932. saa7164_api_configure_port_mpeg2ps(dev,
  933. encport, psfmt);
  934. break;
  935. case VS_FORMAT_VBI:
  936. vbifmt =
  937. (struct tmComResVBIFormatDescrHeader *)t;
  938. if (currpath == 1)
  939. vbiport = &dev->ports[SAA7164_PORT_VBI1];
  940. else
  941. vbiport = &dev->ports[SAA7164_PORT_VBI2];
  942. memcpy(&vbiport->hwcfg, vcoutputtermhdr,
  943. sizeof(*vcoutputtermhdr));
  944. memcpy(&vbiport->vbi_fmt_ntsc, vbifmt,
  945. sizeof(*vbifmt));
  946. saa7164_api_configure_port_vbi(dev,
  947. vbiport);
  948. break;
  949. case VS_FORMAT_RDS:
  950. dprintk(DBGLVL_API,
  951. " = VS_FORMAT_RDS\n");
  952. break;
  953. case VS_FORMAT_UNCOMPRESSED:
  954. dprintk(DBGLVL_API,
  955. " = VS_FORMAT_UNCOMPRESSED\n");
  956. break;
  957. case VS_FORMAT_TYPE:
  958. dprintk(DBGLVL_API,
  959. " = VS_FORMAT_TYPE\n");
  960. break;
  961. default:
  962. dprintk(DBGLVL_API,
  963. " = undefined (0x%x)\n",
  964. t->subtype);
  965. }
  966. next_offset += t->len;
  967. }
  968. break;
  969. case TUNER_UNIT:
  970. dprintk(DBGLVL_API, " TUNER_UNIT\n");
  971. tunerunithdr =
  972. (struct tmComResTunerDescrHeader *)(buf + idx);
  973. dprintk(DBGLVL_API, " unitid = 0x%x\n",
  974. tunerunithdr->unitid);
  975. dprintk(DBGLVL_API, " sourceid = 0x%x\n",
  976. tunerunithdr->sourceid);
  977. dprintk(DBGLVL_API, " iunit = 0x%x\n",
  978. tunerunithdr->iunit);
  979. dprintk(DBGLVL_API, " tuningstandards = 0x%x\n",
  980. tunerunithdr->tuningstandards);
  981. dprintk(DBGLVL_API, " controlsize = 0x%x\n",
  982. tunerunithdr->controlsize);
  983. dprintk(DBGLVL_API, " controls = 0x%x\n",
  984. tunerunithdr->controls);
  985. if (tunerunithdr->unitid == tunerunithdr->iunit) {
  986. if (currpath == 1)
  987. encport = &dev->ports[SAA7164_PORT_ENC1];
  988. else
  989. encport = &dev->ports[SAA7164_PORT_ENC2];
  990. memcpy(&encport->tunerunit, tunerunithdr,
  991. sizeof(struct tmComResTunerDescrHeader));
  992. dprintk(DBGLVL_API,
  993. " (becomes dev->enc[%d] tuner)\n",
  994. encport->nr);
  995. }
  996. break;
  997. case VC_SELECTOR_UNIT:
  998. psel = (struct tmComResSelDescrHeader *)(buf + idx);
  999. dprintk(DBGLVL_API, " VC_SELECTOR_UNIT\n");
  1000. dprintk(DBGLVL_API, " unitid = 0x%x\n",
  1001. psel->unitid);
  1002. dprintk(DBGLVL_API, " nrinpins = 0x%x\n",
  1003. psel->nrinpins);
  1004. dprintk(DBGLVL_API, " sourceid = 0x%x\n",
  1005. psel->sourceid);
  1006. break;
  1007. case VC_PROCESSING_UNIT:
  1008. pdh = (struct tmComResProcDescrHeader *)(buf + idx);
  1009. dprintk(DBGLVL_API, " VC_PROCESSING_UNIT\n");
  1010. dprintk(DBGLVL_API, " unitid = 0x%x\n",
  1011. pdh->unitid);
  1012. dprintk(DBGLVL_API, " sourceid = 0x%x\n",
  1013. pdh->sourceid);
  1014. dprintk(DBGLVL_API, " controlsize = 0x%x\n",
  1015. pdh->controlsize);
  1016. if (pdh->controlsize == 0x04) {
  1017. if (currpath == 1)
  1018. encport = &dev->ports[SAA7164_PORT_ENC1];
  1019. else
  1020. encport = &dev->ports[SAA7164_PORT_ENC2];
  1021. memcpy(&encport->vidproc, pdh,
  1022. sizeof(struct tmComResProcDescrHeader));
  1023. dprintk(DBGLVL_API, " (becomes dev->enc[%d])\n",
  1024. encport->nr);
  1025. }
  1026. break;
  1027. case FEATURE_UNIT:
  1028. afd = (struct tmComResAFeatureDescrHeader *)(buf + idx);
  1029. dprintk(DBGLVL_API, " FEATURE_UNIT\n");
  1030. dprintk(DBGLVL_API, " unitid = 0x%x\n",
  1031. afd->unitid);
  1032. dprintk(DBGLVL_API, " sourceid = 0x%x\n",
  1033. afd->sourceid);
  1034. dprintk(DBGLVL_API, " controlsize = 0x%x\n",
  1035. afd->controlsize);
  1036. if (currpath == 1)
  1037. encport = &dev->ports[SAA7164_PORT_ENC1];
  1038. else
  1039. encport = &dev->ports[SAA7164_PORT_ENC2];
  1040. memcpy(&encport->audfeat, afd,
  1041. sizeof(struct tmComResAFeatureDescrHeader));
  1042. dprintk(DBGLVL_API, " (becomes dev->enc[%d])\n",
  1043. encport->nr);
  1044. break;
  1045. case ENCODER_UNIT:
  1046. edh = (struct tmComResEncoderDescrHeader *)(buf + idx);
  1047. dprintk(DBGLVL_API, " ENCODER_UNIT\n");
  1048. dprintk(DBGLVL_API, " subtype = 0x%x\n", edh->subtype);
  1049. dprintk(DBGLVL_API, " unitid = 0x%x\n", edh->unitid);
  1050. dprintk(DBGLVL_API, " vsourceid = 0x%x\n",
  1051. edh->vsourceid);
  1052. dprintk(DBGLVL_API, " asourceid = 0x%x\n",
  1053. edh->asourceid);
  1054. dprintk(DBGLVL_API, " iunit = 0x%x\n", edh->iunit);
  1055. if (edh->iunit == edh->unitid) {
  1056. if (currpath == 1)
  1057. encport = &dev->ports[SAA7164_PORT_ENC1];
  1058. else
  1059. encport = &dev->ports[SAA7164_PORT_ENC2];
  1060. memcpy(&encport->encunit, edh,
  1061. sizeof(struct tmComResEncoderDescrHeader));
  1062. dprintk(DBGLVL_API,
  1063. " (becomes dev->enc[%d])\n",
  1064. encport->nr);
  1065. }
  1066. break;
  1067. case EXTENSION_UNIT:
  1068. dprintk(DBGLVL_API, " EXTENSION_UNIT\n");
  1069. exthdr = (struct tmComResExtDevDescrHeader *)(buf + idx);
  1070. dprintk(DBGLVL_API, " unitid = 0x%x\n",
  1071. exthdr->unitid);
  1072. dprintk(DBGLVL_API, " deviceid = 0x%x\n",
  1073. exthdr->deviceid);
  1074. dprintk(DBGLVL_API, " devicetype = 0x%x\n",
  1075. exthdr->devicetype);
  1076. if (exthdr->devicetype & 0x1)
  1077. dprintk(DBGLVL_API, " = Decoder Device\n");
  1078. if (exthdr->devicetype & 0x2)
  1079. dprintk(DBGLVL_API, " = GPIO Source\n");
  1080. if (exthdr->devicetype & 0x4)
  1081. dprintk(DBGLVL_API, " = Video Decoder\n");
  1082. if (exthdr->devicetype & 0x8)
  1083. dprintk(DBGLVL_API, " = Audio Decoder\n");
  1084. if (exthdr->devicetype & 0x20)
  1085. dprintk(DBGLVL_API, " = Crossbar\n");
  1086. if (exthdr->devicetype & 0x40)
  1087. dprintk(DBGLVL_API, " = Tuner\n");
  1088. if (exthdr->devicetype & 0x80)
  1089. dprintk(DBGLVL_API, " = IF PLL\n");
  1090. if (exthdr->devicetype & 0x100)
  1091. dprintk(DBGLVL_API, " = Demodulator\n");
  1092. if (exthdr->devicetype & 0x200)
  1093. dprintk(DBGLVL_API, " = RDS Decoder\n");
  1094. if (exthdr->devicetype & 0x400)
  1095. dprintk(DBGLVL_API, " = Encoder\n");
  1096. if (exthdr->devicetype & 0x800)
  1097. dprintk(DBGLVL_API, " = IR Decoder\n");
  1098. if (exthdr->devicetype & 0x1000)
  1099. dprintk(DBGLVL_API, " = EEPROM\n");
  1100. if (exthdr->devicetype & 0x2000)
  1101. dprintk(DBGLVL_API,
  1102. " = VBI Decoder\n");
  1103. if (exthdr->devicetype & 0x10000)
  1104. dprintk(DBGLVL_API,
  1105. " = Streaming Device\n");
  1106. if (exthdr->devicetype & 0x20000)
  1107. dprintk(DBGLVL_API,
  1108. " = DRM Device\n");
  1109. if (exthdr->devicetype & 0x40000000)
  1110. dprintk(DBGLVL_API,
  1111. " = Generic Device\n");
  1112. if (exthdr->devicetype & 0x80000000)
  1113. dprintk(DBGLVL_API,
  1114. " = Config Space Device\n");
  1115. dprintk(DBGLVL_API, " numgpiopins = 0x%x\n",
  1116. exthdr->numgpiopins);
  1117. dprintk(DBGLVL_API, " numgpiogroups = 0x%x\n",
  1118. exthdr->numgpiogroups);
  1119. dprintk(DBGLVL_API, " controlsize = 0x%x\n",
  1120. exthdr->controlsize);
  1121. if (exthdr->devicetype & 0x80) {
  1122. if (currpath == 1)
  1123. encport = &dev->ports[SAA7164_PORT_ENC1];
  1124. else
  1125. encport = &dev->ports[SAA7164_PORT_ENC2];
  1126. memcpy(&encport->ifunit, exthdr,
  1127. sizeof(struct tmComResExtDevDescrHeader));
  1128. dprintk(DBGLVL_API,
  1129. " (becomes dev->enc[%d])\n",
  1130. encport->nr);
  1131. }
  1132. break;
  1133. case PVC_INFRARED_UNIT:
  1134. dprintk(DBGLVL_API, " PVC_INFRARED_UNIT\n");
  1135. break;
  1136. case DRM_UNIT:
  1137. dprintk(DBGLVL_API, " DRM_UNIT\n");
  1138. break;
  1139. default:
  1140. dprintk(DBGLVL_API, "default %d\n", hdr->subtype);
  1141. }
  1142. dprintk(DBGLVL_API, " 1.%x\n", hdr->len);
  1143. dprintk(DBGLVL_API, " 2.%x\n", hdr->type);
  1144. dprintk(DBGLVL_API, " 3.%x\n", hdr->subtype);
  1145. dprintk(DBGLVL_API, " 4.%x\n", hdr->unitid);
  1146. idx += hdr->len;
  1147. }
  1148. return 0;
  1149. }
  1150. int saa7164_api_enum_subdevs(struct saa7164_dev *dev)
  1151. {
  1152. int ret;
  1153. u32 buflen = 0;
  1154. u8 *buf;
  1155. dprintk(DBGLVL_API, "%s()\n", __func__);
  1156. /* Get the total descriptor length */
  1157. ret = saa7164_cmd_send(dev, 0, GET_LEN,
  1158. GET_DESCRIPTORS_CONTROL, sizeof(buflen), &buflen);
  1159. if (ret != SAA_OK)
  1160. printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
  1161. dprintk(DBGLVL_API, "%s() total descriptor size = %d bytes.\n",
  1162. __func__, buflen);
  1163. /* Allocate enough storage for all of the descs */
  1164. buf = kzalloc(buflen, GFP_KERNEL);
  1165. if (!buf)
  1166. return SAA_ERR_NO_RESOURCES;
  1167. /* Retrieve them */
  1168. ret = saa7164_cmd_send(dev, 0, GET_CUR,
  1169. GET_DESCRIPTORS_CONTROL, buflen, buf);
  1170. if (ret != SAA_OK) {
  1171. printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
  1172. goto out;
  1173. }
  1174. if (saa_debug & DBGLVL_API)
  1175. print_hex_dump(KERN_INFO, "", DUMP_PREFIX_OFFSET, 16, 1, buf,
  1176. buflen & ~15, false);
  1177. saa7164_api_dump_subdevs(dev, buf, buflen);
  1178. out:
  1179. kfree(buf);
  1180. return ret;
  1181. }
  1182. int saa7164_api_i2c_read(struct saa7164_i2c *bus, u8 addr, u32 reglen, u8 *reg,
  1183. u32 datalen, u8 *data)
  1184. {
  1185. struct saa7164_dev *dev = bus->dev;
  1186. u16 len = 0;
  1187. int unitid;
  1188. u8 buf[256];
  1189. int ret;
  1190. dprintk(DBGLVL_API, "%s() addr=%x reglen=%d datalen=%d\n",
  1191. __func__, addr, reglen, datalen);
  1192. if (reglen > 4)
  1193. return -EIO;
  1194. /* Prepare the send buffer */
  1195. /* Bytes 00-03 source register length
  1196. * 04-07 source bytes to read
  1197. * 08... register address
  1198. */
  1199. memset(buf, 0, sizeof(buf));
  1200. memcpy((buf + 2 * sizeof(u32) + 0), reg, reglen);
  1201. *((u32 *)(buf + 0 * sizeof(u32))) = reglen;
  1202. *((u32 *)(buf + 1 * sizeof(u32))) = datalen;
  1203. unitid = saa7164_i2caddr_to_unitid(bus, addr);
  1204. if (unitid < 0) {
  1205. printk(KERN_ERR
  1206. "%s() error, cannot translate regaddr 0x%x to unitid\n",
  1207. __func__, addr);
  1208. return -EIO;
  1209. }
  1210. ret = saa7164_cmd_send(bus->dev, unitid, GET_LEN,
  1211. EXU_REGISTER_ACCESS_CONTROL, sizeof(len), &len);
  1212. if (ret != SAA_OK) {
  1213. printk(KERN_ERR "%s() error, ret(1) = 0x%x\n", __func__, ret);
  1214. return -EIO;
  1215. }
  1216. dprintk(DBGLVL_API, "%s() len = %d bytes\n", __func__, len);
  1217. if (saa_debug & DBGLVL_I2C)
  1218. print_hex_dump(KERN_INFO, "", DUMP_PREFIX_OFFSET, 16, 1, buf,
  1219. 32, false);
  1220. ret = saa7164_cmd_send(bus->dev, unitid, GET_CUR,
  1221. EXU_REGISTER_ACCESS_CONTROL, len, &buf);
  1222. if (ret != SAA_OK)
  1223. printk(KERN_ERR "%s() error, ret(2) = 0x%x\n", __func__, ret);
  1224. else {
  1225. if (saa_debug & DBGLVL_I2C)
  1226. print_hex_dump(KERN_INFO, "", DUMP_PREFIX_OFFSET, 16, 1,
  1227. buf, sizeof(buf), false);
  1228. memcpy(data, (buf + 2 * sizeof(u32) + reglen), datalen);
  1229. }
  1230. return ret == SAA_OK ? 0 : -EIO;
  1231. }
  1232. /* For a given 8 bit i2c address device, write the buffer */
  1233. int saa7164_api_i2c_write(struct saa7164_i2c *bus, u8 addr, u32 datalen,
  1234. u8 *data)
  1235. {
  1236. struct saa7164_dev *dev = bus->dev;
  1237. u16 len = 0;
  1238. int unitid;
  1239. int reglen;
  1240. u8 buf[256];
  1241. int ret;
  1242. dprintk(DBGLVL_API, "%s() addr=0x%2x len=0x%x\n",
  1243. __func__, addr, datalen);
  1244. if ((datalen == 0) || (datalen > 232))
  1245. return -EIO;
  1246. memset(buf, 0, sizeof(buf));
  1247. unitid = saa7164_i2caddr_to_unitid(bus, addr);
  1248. if (unitid < 0) {
  1249. printk(KERN_ERR
  1250. "%s() error, cannot translate regaddr 0x%x to unitid\n",
  1251. __func__, addr);
  1252. return -EIO;
  1253. }
  1254. reglen = saa7164_i2caddr_to_reglen(bus, addr);
  1255. if (reglen < 0) {
  1256. printk(KERN_ERR
  1257. "%s() error, cannot translate regaddr to reglen\n",
  1258. __func__);
  1259. return -EIO;
  1260. }
  1261. ret = saa7164_cmd_send(bus->dev, unitid, GET_LEN,
  1262. EXU_REGISTER_ACCESS_CONTROL, sizeof(len), &len);
  1263. if (ret != SAA_OK) {
  1264. printk(KERN_ERR "%s() error, ret(1) = 0x%x\n", __func__, ret);
  1265. return -EIO;
  1266. }
  1267. dprintk(DBGLVL_API, "%s() len = %d bytes unitid=0x%x\n", __func__,
  1268. len, unitid);
  1269. /* Prepare the send buffer */
  1270. /* Bytes 00-03 dest register length
  1271. * 04-07 dest bytes to write
  1272. * 08... register address
  1273. */
  1274. *((u32 *)(buf + 0 * sizeof(u32))) = reglen;
  1275. *((u32 *)(buf + 1 * sizeof(u32))) = datalen - reglen;
  1276. memcpy((buf + 2 * sizeof(u32)), data, datalen);
  1277. if (saa_debug & DBGLVL_I2C)
  1278. print_hex_dump(KERN_INFO, "", DUMP_PREFIX_OFFSET, 16, 1,
  1279. buf, sizeof(buf), false);
  1280. ret = saa7164_cmd_send(bus->dev, unitid, SET_CUR,
  1281. EXU_REGISTER_ACCESS_CONTROL, len, &buf);
  1282. if (ret != SAA_OK)
  1283. printk(KERN_ERR "%s() error, ret(2) = 0x%x\n", __func__, ret);
  1284. return ret == SAA_OK ? 0 : -EIO;
  1285. }
  1286. static int saa7164_api_modify_gpio(struct saa7164_dev *dev, u8 unitid,
  1287. u8 pin, u8 state)
  1288. {
  1289. int ret;
  1290. struct tmComResGPIO t;
  1291. dprintk(DBGLVL_API, "%s(0x%x, %d, %d)\n",
  1292. __func__, unitid, pin, state);
  1293. if ((pin > 7) || (state > 2))
  1294. return SAA_ERR_BAD_PARAMETER;
  1295. t.pin = pin;
  1296. t.state = state;
  1297. ret = saa7164_cmd_send(dev, unitid, SET_CUR,
  1298. EXU_GPIO_CONTROL, sizeof(t), &t);
  1299. if (ret != SAA_OK)
  1300. printk(KERN_ERR "%s() error, ret = 0x%x\n",
  1301. __func__, ret);
  1302. return ret;
  1303. }
  1304. int saa7164_api_set_gpiobit(struct saa7164_dev *dev, u8 unitid,
  1305. u8 pin)
  1306. {
  1307. return saa7164_api_modify_gpio(dev, unitid, pin, 1);
  1308. }
  1309. int saa7164_api_clear_gpiobit(struct saa7164_dev *dev, u8 unitid,
  1310. u8 pin)
  1311. {
  1312. return saa7164_api_modify_gpio(dev, unitid, pin, 0);
  1313. }