saa7164-api.c 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524
  1. /*
  2. * Driver for the NXP SAA7164 PCIe bridge
  3. *
  4. * Copyright (c) 2010 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. 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. 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. int ret = 0;
  560. u8 agc_disable;
  561. dprintk(DBGLVL_API, "%s(nr=%d, 0x%x)\n", __func__, port->nr, std);
  562. if (std & V4L2_STD_NTSC) {
  563. dprintk(DBGLVL_API, " NTSC\n");
  564. saa7164_api_set_dif(port, 0x00, 0x01); /* Video Standard */
  565. agc_disable = 0;
  566. } else if (std & V4L2_STD_PAL_I) {
  567. dprintk(DBGLVL_API, " PAL-I\n");
  568. saa7164_api_set_dif(port, 0x00, 0x08); /* Video Standard */
  569. agc_disable = 0;
  570. } else if (std & V4L2_STD_PAL_M) {
  571. dprintk(DBGLVL_API, " PAL-M\n");
  572. saa7164_api_set_dif(port, 0x00, 0x01); /* Video Standard */
  573. agc_disable = 0;
  574. } else if (std & V4L2_STD_PAL_N) {
  575. dprintk(DBGLVL_API, " PAL-N\n");
  576. saa7164_api_set_dif(port, 0x00, 0x01); /* Video Standard */
  577. agc_disable = 0;
  578. } else if (std & V4L2_STD_PAL_Nc) {
  579. dprintk(DBGLVL_API, " PAL-Nc\n");
  580. saa7164_api_set_dif(port, 0x00, 0x01); /* Video Standard */
  581. agc_disable = 0;
  582. } else if (std & V4L2_STD_PAL_B) {
  583. dprintk(DBGLVL_API, " PAL-B\n");
  584. saa7164_api_set_dif(port, 0x00, 0x02); /* Video Standard */
  585. agc_disable = 0;
  586. } else if (std & V4L2_STD_PAL_DK) {
  587. dprintk(DBGLVL_API, " PAL-DK\n");
  588. saa7164_api_set_dif(port, 0x00, 0x10); /* Video Standard */
  589. agc_disable = 0;
  590. } else if (std & V4L2_STD_SECAM_L) {
  591. dprintk(DBGLVL_API, " SECAM-L\n");
  592. saa7164_api_set_dif(port, 0x00, 0x20); /* Video Standard */
  593. agc_disable = 0;
  594. } else {
  595. /* Unknown standard, assume DTV */
  596. dprintk(DBGLVL_API, " Unknown (assuming DTV)\n");
  597. /* Undefinded Video Standard */
  598. saa7164_api_set_dif(port, 0x00, 0x80);
  599. agc_disable = 1;
  600. }
  601. saa7164_api_set_dif(port, 0x48, 0xa0); /* AGC Functions 1 */
  602. saa7164_api_set_dif(port, 0xc0, agc_disable); /* AGC Output Disable */
  603. saa7164_api_set_dif(port, 0x7c, 0x04); /* CVBS EQ */
  604. saa7164_api_set_dif(port, 0x04, 0x01); /* Active */
  605. msleep(100);
  606. saa7164_api_set_dif(port, 0x04, 0x00); /* Active (again) */
  607. msleep(100);
  608. return ret;
  609. }
  610. /* Ensure the dif is in the correct state for the operating mode
  611. * (analog / dtv). We only configure the diff through the analog encoder
  612. * so when we're in digital mode we need to find the appropriate encoder
  613. * and use it to configure the DIF.
  614. */
  615. int saa7164_api_initialize_dif(struct saa7164_port *port)
  616. {
  617. struct saa7164_dev *dev = port->dev;
  618. struct saa7164_port *p = NULL;
  619. int ret = -EINVAL;
  620. u32 std = 0;
  621. dprintk(DBGLVL_API, "%s(nr=%d type=%d)\n", __func__,
  622. port->nr, port->type);
  623. if (port->type == SAA7164_MPEG_ENCODER) {
  624. /* Pick any analog standard to init the diff.
  625. * we'll come back during encoder_init'
  626. * and set the correct standard if requried.
  627. */
  628. std = V4L2_STD_NTSC;
  629. } else
  630. if (port->type == SAA7164_MPEG_DVB) {
  631. if (port->nr == SAA7164_PORT_TS1)
  632. p = &dev->ports[SAA7164_PORT_ENC1];
  633. else
  634. p = &dev->ports[SAA7164_PORT_ENC2];
  635. } else
  636. if (port->type == SAA7164_MPEG_VBI) {
  637. std = V4L2_STD_NTSC;
  638. if (port->nr == SAA7164_PORT_VBI1)
  639. p = &dev->ports[SAA7164_PORT_ENC1];
  640. else
  641. p = &dev->ports[SAA7164_PORT_ENC2];
  642. } else
  643. BUG();
  644. if (p)
  645. ret = saa7164_api_configure_dif(p, std);
  646. return ret;
  647. }
  648. int saa7164_api_transition_port(struct saa7164_port *port, u8 mode)
  649. {
  650. struct saa7164_dev *dev = port->dev;
  651. int ret;
  652. dprintk(DBGLVL_API, "%s(nr=%d unitid=0x%x,%d)\n",
  653. __func__, port->nr, port->hwcfg.unitid, mode);
  654. ret = saa7164_cmd_send(port->dev, port->hwcfg.unitid, SET_CUR,
  655. SAA_STATE_CONTROL, sizeof(mode), &mode);
  656. if (ret != SAA_OK)
  657. printk(KERN_ERR "%s(portnr %d unitid 0x%x) error, ret = 0x%x\n",
  658. __func__, port->nr, port->hwcfg.unitid, ret);
  659. return ret;
  660. }
  661. int saa7164_api_get_fw_version(struct saa7164_dev *dev, u32 *version)
  662. {
  663. int ret;
  664. ret = saa7164_cmd_send(dev, 0, GET_CUR,
  665. GET_FW_VERSION_CONTROL, sizeof(u32), version);
  666. if (ret != SAA_OK)
  667. printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
  668. return ret;
  669. }
  670. int saa7164_api_read_eeprom(struct saa7164_dev *dev, u8 *buf, int buflen)
  671. {
  672. u8 reg[] = { 0x0f, 0x00 };
  673. if (buflen < 128)
  674. return -ENOMEM;
  675. /* Assumption: Hauppauge eeprom is at 0xa0 on on bus 0 */
  676. /* TODO: Pull the details from the boards struct */
  677. return saa7164_api_i2c_read(&dev->i2c_bus[0], 0xa0 >> 1, sizeof(reg),
  678. &reg[0], 128, buf);
  679. }
  680. int saa7164_api_configure_port_vbi(struct saa7164_dev *dev,
  681. struct saa7164_port *port)
  682. {
  683. struct tmComResVBIFormatDescrHeader *fmt = &port->vbi_fmt_ntsc;
  684. dprintk(DBGLVL_API, " bFormatIndex = 0x%x\n", fmt->bFormatIndex);
  685. dprintk(DBGLVL_API, " VideoStandard = 0x%x\n", fmt->VideoStandard);
  686. dprintk(DBGLVL_API, " StartLine = %d\n", fmt->StartLine);
  687. dprintk(DBGLVL_API, " EndLine = %d\n", fmt->EndLine);
  688. dprintk(DBGLVL_API, " FieldRate = %d\n", fmt->FieldRate);
  689. dprintk(DBGLVL_API, " bNumLines = %d\n", fmt->bNumLines);
  690. /* Cache the hardware configuration in the port */
  691. port->bufcounter = port->hwcfg.BARLocation;
  692. port->pitch = port->hwcfg.BARLocation + (2 * sizeof(u32));
  693. port->bufsize = port->hwcfg.BARLocation + (3 * sizeof(u32));
  694. port->bufoffset = port->hwcfg.BARLocation + (4 * sizeof(u32));
  695. port->bufptr32l = port->hwcfg.BARLocation +
  696. (4 * sizeof(u32)) +
  697. (sizeof(u32) * port->hwcfg.buffercount) + sizeof(u32);
  698. port->bufptr32h = port->hwcfg.BARLocation +
  699. (4 * sizeof(u32)) +
  700. (sizeof(u32) * port->hwcfg.buffercount);
  701. port->bufptr64 = port->hwcfg.BARLocation +
  702. (4 * sizeof(u32)) +
  703. (sizeof(u32) * port->hwcfg.buffercount);
  704. dprintk(DBGLVL_API, " = port->hwcfg.BARLocation = 0x%x\n",
  705. port->hwcfg.BARLocation);
  706. dprintk(DBGLVL_API, " = VS_FORMAT_VBI (becomes dev->en[%d])\n",
  707. port->nr);
  708. return 0;
  709. }
  710. int 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. int saa7164_api_configure_port_mpeg2ps(struct saa7164_dev *dev,
  740. struct saa7164_port *port,
  741. struct tmComResPSFormatDescrHeader *fmt)
  742. {
  743. dprintk(DBGLVL_API, " bFormatIndex = 0x%x\n", fmt->bFormatIndex);
  744. dprintk(DBGLVL_API, " wPacketLength= 0x%x\n", fmt->wPacketLength);
  745. dprintk(DBGLVL_API, " wPackLength= 0x%x\n", fmt->wPackLength);
  746. dprintk(DBGLVL_API, " bPackDataType= 0x%x\n", fmt->bPackDataType);
  747. /* Cache the hardware configuration in the port */
  748. /* TODO: CHECK THIS in the port config */
  749. port->bufcounter = port->hwcfg.BARLocation;
  750. port->pitch = port->hwcfg.BARLocation + (2 * sizeof(u32));
  751. port->bufsize = port->hwcfg.BARLocation + (3 * sizeof(u32));
  752. port->bufoffset = port->hwcfg.BARLocation + (4 * sizeof(u32));
  753. port->bufptr32l = port->hwcfg.BARLocation +
  754. (4 * sizeof(u32)) +
  755. (sizeof(u32) * port->hwcfg.buffercount) + sizeof(u32);
  756. port->bufptr32h = port->hwcfg.BARLocation +
  757. (4 * sizeof(u32)) +
  758. (sizeof(u32) * port->hwcfg.buffercount);
  759. port->bufptr64 = port->hwcfg.BARLocation +
  760. (4 * sizeof(u32)) +
  761. (sizeof(u32) * port->hwcfg.buffercount);
  762. dprintk(DBGLVL_API, " = port->hwcfg.BARLocation = 0x%x\n",
  763. port->hwcfg.BARLocation);
  764. dprintk(DBGLVL_API, " = VS_FORMAT_MPEGPS (becomes dev->enc[%d])\n",
  765. port->nr);
  766. return 0;
  767. }
  768. int saa7164_api_dump_subdevs(struct saa7164_dev *dev, u8 *buf, int len)
  769. {
  770. struct saa7164_port *tsport = NULL;
  771. struct saa7164_port *encport = NULL;
  772. struct saa7164_port *vbiport = NULL;
  773. u32 idx, next_offset;
  774. int i;
  775. struct tmComResDescrHeader *hdr, *t;
  776. struct tmComResExtDevDescrHeader *exthdr;
  777. struct tmComResPathDescrHeader *pathhdr;
  778. struct tmComResAntTermDescrHeader *anttermhdr;
  779. struct tmComResTunerDescrHeader *tunerunithdr;
  780. struct tmComResDMATermDescrHeader *vcoutputtermhdr;
  781. struct tmComResTSFormatDescrHeader *tsfmt;
  782. struct tmComResPSFormatDescrHeader *psfmt;
  783. struct tmComResSelDescrHeader *psel;
  784. struct tmComResProcDescrHeader *pdh;
  785. struct tmComResAFeatureDescrHeader *afd;
  786. struct tmComResEncoderDescrHeader *edh;
  787. struct tmComResVBIFormatDescrHeader *vbifmt;
  788. u32 currpath = 0;
  789. dprintk(DBGLVL_API,
  790. "%s(?,?,%d) sizeof(struct tmComResDescrHeader) = %d bytes\n",
  791. __func__, len, (u32)sizeof(struct tmComResDescrHeader));
  792. for (idx = 0; idx < (len - sizeof(struct tmComResDescrHeader));) {
  793. hdr = (struct tmComResDescrHeader *)(buf + idx);
  794. if (hdr->type != CS_INTERFACE)
  795. return SAA_ERR_NOT_SUPPORTED;
  796. dprintk(DBGLVL_API, "@ 0x%x =\n", idx);
  797. switch (hdr->subtype) {
  798. case GENERAL_REQUEST:
  799. dprintk(DBGLVL_API, " GENERAL_REQUEST\n");
  800. break;
  801. case VC_TUNER_PATH:
  802. dprintk(DBGLVL_API, " VC_TUNER_PATH\n");
  803. pathhdr = (struct tmComResPathDescrHeader *)(buf + idx);
  804. dprintk(DBGLVL_API, " pathid = 0x%x\n",
  805. pathhdr->pathid);
  806. currpath = pathhdr->pathid;
  807. break;
  808. case VC_INPUT_TERMINAL:
  809. dprintk(DBGLVL_API, " VC_INPUT_TERMINAL\n");
  810. anttermhdr =
  811. (struct tmComResAntTermDescrHeader *)(buf + idx);
  812. dprintk(DBGLVL_API, " terminalid = 0x%x\n",
  813. anttermhdr->terminalid);
  814. dprintk(DBGLVL_API, " terminaltype = 0x%x\n",
  815. anttermhdr->terminaltype);
  816. switch (anttermhdr->terminaltype) {
  817. case ITT_ANTENNA:
  818. dprintk(DBGLVL_API, " = ITT_ANTENNA\n");
  819. break;
  820. case LINE_CONNECTOR:
  821. dprintk(DBGLVL_API, " = LINE_CONNECTOR\n");
  822. break;
  823. case SPDIF_CONNECTOR:
  824. dprintk(DBGLVL_API, " = SPDIF_CONNECTOR\n");
  825. break;
  826. case COMPOSITE_CONNECTOR:
  827. dprintk(DBGLVL_API,
  828. " = COMPOSITE_CONNECTOR\n");
  829. break;
  830. case SVIDEO_CONNECTOR:
  831. dprintk(DBGLVL_API, " = SVIDEO_CONNECTOR\n");
  832. break;
  833. case COMPONENT_CONNECTOR:
  834. dprintk(DBGLVL_API,
  835. " = COMPONENT_CONNECTOR\n");
  836. break;
  837. case STANDARD_DMA:
  838. dprintk(DBGLVL_API, " = STANDARD_DMA\n");
  839. break;
  840. default:
  841. dprintk(DBGLVL_API, " = undefined (0x%x)\n",
  842. anttermhdr->terminaltype);
  843. }
  844. dprintk(DBGLVL_API, " assocterminal= 0x%x\n",
  845. anttermhdr->assocterminal);
  846. dprintk(DBGLVL_API, " iterminal = 0x%x\n",
  847. anttermhdr->iterminal);
  848. dprintk(DBGLVL_API, " controlsize = 0x%x\n",
  849. anttermhdr->controlsize);
  850. break;
  851. case VC_OUTPUT_TERMINAL:
  852. dprintk(DBGLVL_API, " VC_OUTPUT_TERMINAL\n");
  853. vcoutputtermhdr =
  854. (struct tmComResDMATermDescrHeader *)(buf + idx);
  855. dprintk(DBGLVL_API, " unitid = 0x%x\n",
  856. vcoutputtermhdr->unitid);
  857. dprintk(DBGLVL_API, " terminaltype = 0x%x\n",
  858. vcoutputtermhdr->terminaltype);
  859. switch (vcoutputtermhdr->terminaltype) {
  860. case ITT_ANTENNA:
  861. dprintk(DBGLVL_API, " = ITT_ANTENNA\n");
  862. break;
  863. case LINE_CONNECTOR:
  864. dprintk(DBGLVL_API, " = LINE_CONNECTOR\n");
  865. break;
  866. case SPDIF_CONNECTOR:
  867. dprintk(DBGLVL_API, " = SPDIF_CONNECTOR\n");
  868. break;
  869. case COMPOSITE_CONNECTOR:
  870. dprintk(DBGLVL_API,
  871. " = COMPOSITE_CONNECTOR\n");
  872. break;
  873. case SVIDEO_CONNECTOR:
  874. dprintk(DBGLVL_API, " = SVIDEO_CONNECTOR\n");
  875. break;
  876. case COMPONENT_CONNECTOR:
  877. dprintk(DBGLVL_API,
  878. " = COMPONENT_CONNECTOR\n");
  879. break;
  880. case STANDARD_DMA:
  881. dprintk(DBGLVL_API, " = STANDARD_DMA\n");
  882. break;
  883. default:
  884. dprintk(DBGLVL_API, " = undefined (0x%x)\n",
  885. vcoutputtermhdr->terminaltype);
  886. }
  887. dprintk(DBGLVL_API, " assocterminal= 0x%x\n",
  888. vcoutputtermhdr->assocterminal);
  889. dprintk(DBGLVL_API, " sourceid = 0x%x\n",
  890. vcoutputtermhdr->sourceid);
  891. dprintk(DBGLVL_API, " iterminal = 0x%x\n",
  892. vcoutputtermhdr->iterminal);
  893. dprintk(DBGLVL_API, " BARLocation = 0x%x\n",
  894. vcoutputtermhdr->BARLocation);
  895. dprintk(DBGLVL_API, " flags = 0x%x\n",
  896. vcoutputtermhdr->flags);
  897. dprintk(DBGLVL_API, " interruptid = 0x%x\n",
  898. vcoutputtermhdr->interruptid);
  899. dprintk(DBGLVL_API, " buffercount = 0x%x\n",
  900. vcoutputtermhdr->buffercount);
  901. dprintk(DBGLVL_API, " metadatasize = 0x%x\n",
  902. vcoutputtermhdr->metadatasize);
  903. dprintk(DBGLVL_API, " controlsize = 0x%x\n",
  904. vcoutputtermhdr->controlsize);
  905. dprintk(DBGLVL_API, " numformats = 0x%x\n",
  906. vcoutputtermhdr->numformats);
  907. t = (struct tmComResDescrHeader *)
  908. ((struct tmComResDMATermDescrHeader *)(buf + idx));
  909. next_offset = idx + (vcoutputtermhdr->len);
  910. for (i = 0; i < vcoutputtermhdr->numformats; i++) {
  911. t = (struct tmComResDescrHeader *)
  912. (buf + next_offset);
  913. switch (t->subtype) {
  914. case VS_FORMAT_MPEG2TS:
  915. tsfmt =
  916. (struct tmComResTSFormatDescrHeader *)t;
  917. if (currpath == 1)
  918. tsport = &dev->ports[SAA7164_PORT_TS1];
  919. else
  920. tsport = &dev->ports[SAA7164_PORT_TS2];
  921. memcpy(&tsport->hwcfg, vcoutputtermhdr,
  922. sizeof(*vcoutputtermhdr));
  923. saa7164_api_configure_port_mpeg2ts(dev,
  924. tsport, tsfmt);
  925. break;
  926. case VS_FORMAT_MPEG2PS:
  927. psfmt =
  928. (struct tmComResPSFormatDescrHeader *)t;
  929. if (currpath == 1)
  930. encport = &dev->ports[SAA7164_PORT_ENC1];
  931. else
  932. encport = &dev->ports[SAA7164_PORT_ENC2];
  933. memcpy(&encport->hwcfg, vcoutputtermhdr,
  934. sizeof(*vcoutputtermhdr));
  935. saa7164_api_configure_port_mpeg2ps(dev,
  936. encport, psfmt);
  937. break;
  938. case VS_FORMAT_VBI:
  939. vbifmt =
  940. (struct tmComResVBIFormatDescrHeader *)t;
  941. if (currpath == 1)
  942. vbiport = &dev->ports[SAA7164_PORT_VBI1];
  943. else
  944. vbiport = &dev->ports[SAA7164_PORT_VBI2];
  945. memcpy(&vbiport->hwcfg, vcoutputtermhdr,
  946. sizeof(*vcoutputtermhdr));
  947. memcpy(&vbiport->vbi_fmt_ntsc, vbifmt,
  948. sizeof(*vbifmt));
  949. saa7164_api_configure_port_vbi(dev,
  950. vbiport);
  951. break;
  952. case VS_FORMAT_RDS:
  953. dprintk(DBGLVL_API,
  954. " = VS_FORMAT_RDS\n");
  955. break;
  956. case VS_FORMAT_UNCOMPRESSED:
  957. dprintk(DBGLVL_API,
  958. " = VS_FORMAT_UNCOMPRESSED\n");
  959. break;
  960. case VS_FORMAT_TYPE:
  961. dprintk(DBGLVL_API,
  962. " = VS_FORMAT_TYPE\n");
  963. break;
  964. default:
  965. dprintk(DBGLVL_API,
  966. " = undefined (0x%x)\n",
  967. t->subtype);
  968. }
  969. next_offset += t->len;
  970. }
  971. break;
  972. case TUNER_UNIT:
  973. dprintk(DBGLVL_API, " TUNER_UNIT\n");
  974. tunerunithdr =
  975. (struct tmComResTunerDescrHeader *)(buf + idx);
  976. dprintk(DBGLVL_API, " unitid = 0x%x\n",
  977. tunerunithdr->unitid);
  978. dprintk(DBGLVL_API, " sourceid = 0x%x\n",
  979. tunerunithdr->sourceid);
  980. dprintk(DBGLVL_API, " iunit = 0x%x\n",
  981. tunerunithdr->iunit);
  982. dprintk(DBGLVL_API, " tuningstandards = 0x%x\n",
  983. tunerunithdr->tuningstandards);
  984. dprintk(DBGLVL_API, " controlsize = 0x%x\n",
  985. tunerunithdr->controlsize);
  986. dprintk(DBGLVL_API, " controls = 0x%x\n",
  987. tunerunithdr->controls);
  988. if (tunerunithdr->unitid == tunerunithdr->iunit) {
  989. if (currpath == 1)
  990. encport = &dev->ports[SAA7164_PORT_ENC1];
  991. else
  992. encport = &dev->ports[SAA7164_PORT_ENC2];
  993. memcpy(&encport->tunerunit, tunerunithdr,
  994. sizeof(struct tmComResTunerDescrHeader));
  995. dprintk(DBGLVL_API,
  996. " (becomes dev->enc[%d] tuner)\n",
  997. encport->nr);
  998. }
  999. break;
  1000. case VC_SELECTOR_UNIT:
  1001. psel = (struct tmComResSelDescrHeader *)(buf + idx);
  1002. dprintk(DBGLVL_API, " VC_SELECTOR_UNIT\n");
  1003. dprintk(DBGLVL_API, " unitid = 0x%x\n",
  1004. psel->unitid);
  1005. dprintk(DBGLVL_API, " nrinpins = 0x%x\n",
  1006. psel->nrinpins);
  1007. dprintk(DBGLVL_API, " sourceid = 0x%x\n",
  1008. psel->sourceid);
  1009. break;
  1010. case VC_PROCESSING_UNIT:
  1011. pdh = (struct tmComResProcDescrHeader *)(buf + idx);
  1012. dprintk(DBGLVL_API, " VC_PROCESSING_UNIT\n");
  1013. dprintk(DBGLVL_API, " unitid = 0x%x\n",
  1014. pdh->unitid);
  1015. dprintk(DBGLVL_API, " sourceid = 0x%x\n",
  1016. pdh->sourceid);
  1017. dprintk(DBGLVL_API, " controlsize = 0x%x\n",
  1018. pdh->controlsize);
  1019. if (pdh->controlsize == 0x04) {
  1020. if (currpath == 1)
  1021. encport = &dev->ports[SAA7164_PORT_ENC1];
  1022. else
  1023. encport = &dev->ports[SAA7164_PORT_ENC2];
  1024. memcpy(&encport->vidproc, pdh,
  1025. sizeof(struct tmComResProcDescrHeader));
  1026. dprintk(DBGLVL_API, " (becomes dev->enc[%d])\n",
  1027. encport->nr);
  1028. }
  1029. break;
  1030. case FEATURE_UNIT:
  1031. afd = (struct tmComResAFeatureDescrHeader *)(buf + idx);
  1032. dprintk(DBGLVL_API, " FEATURE_UNIT\n");
  1033. dprintk(DBGLVL_API, " unitid = 0x%x\n",
  1034. afd->unitid);
  1035. dprintk(DBGLVL_API, " sourceid = 0x%x\n",
  1036. afd->sourceid);
  1037. dprintk(DBGLVL_API, " controlsize = 0x%x\n",
  1038. afd->controlsize);
  1039. if (currpath == 1)
  1040. encport = &dev->ports[SAA7164_PORT_ENC1];
  1041. else
  1042. encport = &dev->ports[SAA7164_PORT_ENC2];
  1043. memcpy(&encport->audfeat, afd,
  1044. sizeof(struct tmComResAFeatureDescrHeader));
  1045. dprintk(DBGLVL_API, " (becomes dev->enc[%d])\n",
  1046. encport->nr);
  1047. break;
  1048. case ENCODER_UNIT:
  1049. edh = (struct tmComResEncoderDescrHeader *)(buf + idx);
  1050. dprintk(DBGLVL_API, " ENCODER_UNIT\n");
  1051. dprintk(DBGLVL_API, " subtype = 0x%x\n", edh->subtype);
  1052. dprintk(DBGLVL_API, " unitid = 0x%x\n", edh->unitid);
  1053. dprintk(DBGLVL_API, " vsourceid = 0x%x\n",
  1054. edh->vsourceid);
  1055. dprintk(DBGLVL_API, " asourceid = 0x%x\n",
  1056. edh->asourceid);
  1057. dprintk(DBGLVL_API, " iunit = 0x%x\n", edh->iunit);
  1058. if (edh->iunit == edh->unitid) {
  1059. if (currpath == 1)
  1060. encport = &dev->ports[SAA7164_PORT_ENC1];
  1061. else
  1062. encport = &dev->ports[SAA7164_PORT_ENC2];
  1063. memcpy(&encport->encunit, edh,
  1064. sizeof(struct tmComResEncoderDescrHeader));
  1065. dprintk(DBGLVL_API,
  1066. " (becomes dev->enc[%d])\n",
  1067. encport->nr);
  1068. }
  1069. break;
  1070. case EXTENSION_UNIT:
  1071. dprintk(DBGLVL_API, " EXTENSION_UNIT\n");
  1072. exthdr = (struct tmComResExtDevDescrHeader *)(buf + idx);
  1073. dprintk(DBGLVL_API, " unitid = 0x%x\n",
  1074. exthdr->unitid);
  1075. dprintk(DBGLVL_API, " deviceid = 0x%x\n",
  1076. exthdr->deviceid);
  1077. dprintk(DBGLVL_API, " devicetype = 0x%x\n",
  1078. exthdr->devicetype);
  1079. if (exthdr->devicetype & 0x1)
  1080. dprintk(DBGLVL_API, " = Decoder Device\n");
  1081. if (exthdr->devicetype & 0x2)
  1082. dprintk(DBGLVL_API, " = GPIO Source\n");
  1083. if (exthdr->devicetype & 0x4)
  1084. dprintk(DBGLVL_API, " = Video Decoder\n");
  1085. if (exthdr->devicetype & 0x8)
  1086. dprintk(DBGLVL_API, " = Audio Decoder\n");
  1087. if (exthdr->devicetype & 0x20)
  1088. dprintk(DBGLVL_API, " = Crossbar\n");
  1089. if (exthdr->devicetype & 0x40)
  1090. dprintk(DBGLVL_API, " = Tuner\n");
  1091. if (exthdr->devicetype & 0x80)
  1092. dprintk(DBGLVL_API, " = IF PLL\n");
  1093. if (exthdr->devicetype & 0x100)
  1094. dprintk(DBGLVL_API, " = Demodulator\n");
  1095. if (exthdr->devicetype & 0x200)
  1096. dprintk(DBGLVL_API, " = RDS Decoder\n");
  1097. if (exthdr->devicetype & 0x400)
  1098. dprintk(DBGLVL_API, " = Encoder\n");
  1099. if (exthdr->devicetype & 0x800)
  1100. dprintk(DBGLVL_API, " = IR Decoder\n");
  1101. if (exthdr->devicetype & 0x1000)
  1102. dprintk(DBGLVL_API, " = EEPROM\n");
  1103. if (exthdr->devicetype & 0x2000)
  1104. dprintk(DBGLVL_API,
  1105. " = VBI Decoder\n");
  1106. if (exthdr->devicetype & 0x10000)
  1107. dprintk(DBGLVL_API,
  1108. " = Streaming Device\n");
  1109. if (exthdr->devicetype & 0x20000)
  1110. dprintk(DBGLVL_API,
  1111. " = DRM Device\n");
  1112. if (exthdr->devicetype & 0x40000000)
  1113. dprintk(DBGLVL_API,
  1114. " = Generic Device\n");
  1115. if (exthdr->devicetype & 0x80000000)
  1116. dprintk(DBGLVL_API,
  1117. " = Config Space Device\n");
  1118. dprintk(DBGLVL_API, " numgpiopins = 0x%x\n",
  1119. exthdr->numgpiopins);
  1120. dprintk(DBGLVL_API, " numgpiogroups = 0x%x\n",
  1121. exthdr->numgpiogroups);
  1122. dprintk(DBGLVL_API, " controlsize = 0x%x\n",
  1123. exthdr->controlsize);
  1124. if (exthdr->devicetype & 0x80) {
  1125. if (currpath == 1)
  1126. encport = &dev->ports[SAA7164_PORT_ENC1];
  1127. else
  1128. encport = &dev->ports[SAA7164_PORT_ENC2];
  1129. memcpy(&encport->ifunit, exthdr,
  1130. sizeof(struct tmComResExtDevDescrHeader));
  1131. dprintk(DBGLVL_API,
  1132. " (becomes dev->enc[%d])\n",
  1133. encport->nr);
  1134. }
  1135. break;
  1136. case PVC_INFRARED_UNIT:
  1137. dprintk(DBGLVL_API, " PVC_INFRARED_UNIT\n");
  1138. break;
  1139. case DRM_UNIT:
  1140. dprintk(DBGLVL_API, " DRM_UNIT\n");
  1141. break;
  1142. default:
  1143. dprintk(DBGLVL_API, "default %d\n", hdr->subtype);
  1144. }
  1145. dprintk(DBGLVL_API, " 1.%x\n", hdr->len);
  1146. dprintk(DBGLVL_API, " 2.%x\n", hdr->type);
  1147. dprintk(DBGLVL_API, " 3.%x\n", hdr->subtype);
  1148. dprintk(DBGLVL_API, " 4.%x\n", hdr->unitid);
  1149. idx += hdr->len;
  1150. }
  1151. return 0;
  1152. }
  1153. int saa7164_api_enum_subdevs(struct saa7164_dev *dev)
  1154. {
  1155. int ret;
  1156. u32 buflen = 0;
  1157. u8 *buf;
  1158. dprintk(DBGLVL_API, "%s()\n", __func__);
  1159. /* Get the total descriptor length */
  1160. ret = saa7164_cmd_send(dev, 0, GET_LEN,
  1161. GET_DESCRIPTORS_CONTROL, sizeof(buflen), &buflen);
  1162. if (ret != SAA_OK)
  1163. printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
  1164. dprintk(DBGLVL_API, "%s() total descriptor size = %d bytes.\n",
  1165. __func__, buflen);
  1166. /* Allocate enough storage for all of the descs */
  1167. buf = kzalloc(buflen, GFP_KERNEL);
  1168. if (!buf)
  1169. return SAA_ERR_NO_RESOURCES;
  1170. /* Retrieve them */
  1171. ret = saa7164_cmd_send(dev, 0, GET_CUR,
  1172. GET_DESCRIPTORS_CONTROL, buflen, buf);
  1173. if (ret != SAA_OK) {
  1174. printk(KERN_ERR "%s() error, ret = 0x%x\n", __func__, ret);
  1175. goto out;
  1176. }
  1177. if (saa_debug & DBGLVL_API)
  1178. print_hex_dump(KERN_INFO, "", DUMP_PREFIX_OFFSET, 16, 1, buf,
  1179. buflen & ~15, false);
  1180. saa7164_api_dump_subdevs(dev, buf, buflen);
  1181. out:
  1182. kfree(buf);
  1183. return ret;
  1184. }
  1185. int saa7164_api_i2c_read(struct saa7164_i2c *bus, u8 addr, u32 reglen, u8 *reg,
  1186. u32 datalen, u8 *data)
  1187. {
  1188. struct saa7164_dev *dev = bus->dev;
  1189. u16 len = 0;
  1190. int unitid;
  1191. u8 buf[256];
  1192. int ret;
  1193. dprintk(DBGLVL_API, "%s()\n", __func__);
  1194. if (reglen > 4)
  1195. return -EIO;
  1196. /* Prepare the send buffer */
  1197. /* Bytes 00-03 source register length
  1198. * 04-07 source bytes to read
  1199. * 08... register address
  1200. */
  1201. memset(buf, 0, sizeof(buf));
  1202. memcpy((buf + 2 * sizeof(u32) + 0), reg, reglen);
  1203. *((u32 *)(buf + 0 * sizeof(u32))) = reglen;
  1204. *((u32 *)(buf + 1 * sizeof(u32))) = datalen;
  1205. unitid = saa7164_i2caddr_to_unitid(bus, addr);
  1206. if (unitid < 0) {
  1207. printk(KERN_ERR
  1208. "%s() error, cannot translate regaddr 0x%x to unitid\n",
  1209. __func__, addr);
  1210. return -EIO;
  1211. }
  1212. ret = saa7164_cmd_send(bus->dev, unitid, GET_LEN,
  1213. EXU_REGISTER_ACCESS_CONTROL, sizeof(len), &len);
  1214. if (ret != SAA_OK) {
  1215. printk(KERN_ERR "%s() error, ret(1) = 0x%x\n", __func__, ret);
  1216. return -EIO;
  1217. }
  1218. dprintk(DBGLVL_API, "%s() len = %d bytes\n", __func__, len);
  1219. if (saa_debug & DBGLVL_I2C)
  1220. print_hex_dump(KERN_INFO, "", DUMP_PREFIX_OFFSET, 16, 1, buf,
  1221. 32, false);
  1222. ret = saa7164_cmd_send(bus->dev, unitid, GET_CUR,
  1223. EXU_REGISTER_ACCESS_CONTROL, len, &buf);
  1224. if (ret != SAA_OK)
  1225. printk(KERN_ERR "%s() error, ret(2) = 0x%x\n", __func__, ret);
  1226. else {
  1227. if (saa_debug & DBGLVL_I2C)
  1228. print_hex_dump(KERN_INFO, "", DUMP_PREFIX_OFFSET, 16, 1,
  1229. buf, sizeof(buf), false);
  1230. memcpy(data, (buf + 2 * sizeof(u32) + reglen), datalen);
  1231. }
  1232. return ret == SAA_OK ? 0 : -EIO;
  1233. }
  1234. /* For a given 8 bit i2c address device, write the buffer */
  1235. int saa7164_api_i2c_write(struct saa7164_i2c *bus, u8 addr, u32 datalen,
  1236. u8 *data)
  1237. {
  1238. struct saa7164_dev *dev = bus->dev;
  1239. u16 len = 0;
  1240. int unitid;
  1241. int reglen;
  1242. u8 buf[256];
  1243. int ret;
  1244. dprintk(DBGLVL_API, "%s()\n", __func__);
  1245. if ((datalen == 0) || (datalen > 232))
  1246. return -EIO;
  1247. memset(buf, 0, sizeof(buf));
  1248. unitid = saa7164_i2caddr_to_unitid(bus, addr);
  1249. if (unitid < 0) {
  1250. printk(KERN_ERR
  1251. "%s() error, cannot translate regaddr 0x%x to unitid\n",
  1252. __func__, addr);
  1253. return -EIO;
  1254. }
  1255. reglen = saa7164_i2caddr_to_reglen(bus, addr);
  1256. if (reglen < 0) {
  1257. printk(KERN_ERR
  1258. "%s() error, cannot translate regaddr to reglen\n",
  1259. __func__);
  1260. return -EIO;
  1261. }
  1262. ret = saa7164_cmd_send(bus->dev, unitid, GET_LEN,
  1263. EXU_REGISTER_ACCESS_CONTROL, sizeof(len), &len);
  1264. if (ret != SAA_OK) {
  1265. printk(KERN_ERR "%s() error, ret(1) = 0x%x\n", __func__, ret);
  1266. return -EIO;
  1267. }
  1268. dprintk(DBGLVL_API, "%s() len = %d bytes\n", __func__, len);
  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. 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. }