saa7164-api.c 44 KB

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