saa7164-api.c 43 KB

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