saa7164-api.c 43 KB

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