saa7164-api.c 44 KB

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