ps3av_cmd.c 26 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022
  1. /*
  2. * Copyright (C) 2006 Sony Computer Entertainment Inc.
  3. * Copyright 2006, 2007 Sony Corporation
  4. *
  5. * AV backend support for PS3
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published
  9. * by the Free Software Foundation; version 2 of the License.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. */
  20. #include <linux/module.h>
  21. #include <linux/kernel.h>
  22. #include <linux/delay.h>
  23. #include <asm/ps3av.h>
  24. #include <asm/ps3fb.h>
  25. #include <asm/ps3.h>
  26. #include "vuart.h"
  27. static const struct video_fmt {
  28. u32 format;
  29. u32 order;
  30. } ps3av_video_fmt_table[] = {
  31. { PS3AV_CMD_VIDEO_FORMAT_ARGB_8BIT, PS3AV_CMD_VIDEO_ORDER_RGB },
  32. { PS3AV_CMD_VIDEO_FORMAT_ARGB_8BIT, PS3AV_CMD_VIDEO_ORDER_BGR },
  33. };
  34. static const struct {
  35. int cs;
  36. u32 av;
  37. u32 bl;
  38. } ps3av_cs_video2av_table[] = {
  39. {
  40. .cs = PS3AV_CMD_VIDEO_CS_RGB_8,
  41. .av = PS3AV_CMD_AV_CS_RGB_8,
  42. .bl = PS3AV_CMD_AV_CS_8
  43. }, {
  44. .cs = PS3AV_CMD_VIDEO_CS_RGB_10,
  45. .av = PS3AV_CMD_AV_CS_RGB_8,
  46. .bl = PS3AV_CMD_AV_CS_8
  47. }, {
  48. .cs = PS3AV_CMD_VIDEO_CS_RGB_12,
  49. .av = PS3AV_CMD_AV_CS_RGB_8,
  50. .bl = PS3AV_CMD_AV_CS_8
  51. }, {
  52. .cs = PS3AV_CMD_VIDEO_CS_YUV444_8,
  53. .av = PS3AV_CMD_AV_CS_YUV444_8,
  54. .bl = PS3AV_CMD_AV_CS_8
  55. }, {
  56. .cs = PS3AV_CMD_VIDEO_CS_YUV444_10,
  57. .av = PS3AV_CMD_AV_CS_YUV444_8,
  58. .bl = PS3AV_CMD_AV_CS_10
  59. }, {
  60. .cs = PS3AV_CMD_VIDEO_CS_YUV444_12,
  61. .av = PS3AV_CMD_AV_CS_YUV444_8,
  62. .bl = PS3AV_CMD_AV_CS_10
  63. }, {
  64. .cs = PS3AV_CMD_VIDEO_CS_YUV422_8,
  65. .av = PS3AV_CMD_AV_CS_YUV422_8,
  66. .bl = PS3AV_CMD_AV_CS_10
  67. }, {
  68. .cs = PS3AV_CMD_VIDEO_CS_YUV422_10,
  69. .av = PS3AV_CMD_AV_CS_YUV422_8,
  70. .bl = PS3AV_CMD_AV_CS_10
  71. }, {
  72. .cs = PS3AV_CMD_VIDEO_CS_YUV422_12,
  73. .av = PS3AV_CMD_AV_CS_YUV422_8,
  74. .bl = PS3AV_CMD_AV_CS_12
  75. }, {
  76. .cs = PS3AV_CMD_VIDEO_CS_XVYCC_8,
  77. .av = PS3AV_CMD_AV_CS_XVYCC_8,
  78. .bl = PS3AV_CMD_AV_CS_12
  79. }, {
  80. .cs = PS3AV_CMD_VIDEO_CS_XVYCC_10,
  81. .av = PS3AV_CMD_AV_CS_XVYCC_8,
  82. .bl = PS3AV_CMD_AV_CS_12
  83. }, {
  84. .cs = PS3AV_CMD_VIDEO_CS_XVYCC_12,
  85. .av = PS3AV_CMD_AV_CS_XVYCC_8,
  86. .bl = PS3AV_CMD_AV_CS_12
  87. }
  88. };
  89. static u32 ps3av_cs_video2av(int cs)
  90. {
  91. unsigned int i;
  92. for (i = 0; i < ARRAY_SIZE(ps3av_cs_video2av_table); i++)
  93. if (ps3av_cs_video2av_table[i].cs == cs)
  94. return ps3av_cs_video2av_table[i].av;
  95. return PS3AV_CMD_AV_CS_RGB_8;
  96. }
  97. static u32 ps3av_cs_video2av_bitlen(int cs)
  98. {
  99. unsigned int i;
  100. for (i = 0; i < ARRAY_SIZE(ps3av_cs_video2av_table); i++)
  101. if (ps3av_cs_video2av_table[i].cs == cs)
  102. return ps3av_cs_video2av_table[i].bl;
  103. return PS3AV_CMD_AV_CS_8;
  104. }
  105. static const struct {
  106. int vid;
  107. u32 av;
  108. } ps3av_vid_video2av_table[] = {
  109. { PS3AV_CMD_VIDEO_VID_480I, PS3AV_CMD_AV_VID_480I },
  110. { PS3AV_CMD_VIDEO_VID_480P, PS3AV_CMD_AV_VID_480P },
  111. { PS3AV_CMD_VIDEO_VID_576I, PS3AV_CMD_AV_VID_576I },
  112. { PS3AV_CMD_VIDEO_VID_576P, PS3AV_CMD_AV_VID_576P },
  113. { PS3AV_CMD_VIDEO_VID_1080I_60HZ, PS3AV_CMD_AV_VID_1080I_60HZ },
  114. { PS3AV_CMD_VIDEO_VID_720P_60HZ, PS3AV_CMD_AV_VID_720P_60HZ },
  115. { PS3AV_CMD_VIDEO_VID_1080P_60HZ, PS3AV_CMD_AV_VID_1080P_60HZ },
  116. { PS3AV_CMD_VIDEO_VID_1080I_50HZ, PS3AV_CMD_AV_VID_1080I_50HZ },
  117. { PS3AV_CMD_VIDEO_VID_720P_50HZ, PS3AV_CMD_AV_VID_720P_50HZ },
  118. { PS3AV_CMD_VIDEO_VID_1080P_50HZ, PS3AV_CMD_AV_VID_1080P_50HZ },
  119. { PS3AV_CMD_VIDEO_VID_WXGA, PS3AV_CMD_AV_VID_WXGA },
  120. { PS3AV_CMD_VIDEO_VID_SXGA, PS3AV_CMD_AV_VID_SXGA },
  121. { PS3AV_CMD_VIDEO_VID_WUXGA, PS3AV_CMD_AV_VID_WUXGA }
  122. };
  123. static u32 ps3av_vid_video2av(int vid)
  124. {
  125. unsigned int i;
  126. for (i = 0; i < ARRAY_SIZE(ps3av_vid_video2av_table); i++)
  127. if (ps3av_vid_video2av_table[i].vid == vid)
  128. return ps3av_vid_video2av_table[i].av;
  129. return PS3AV_CMD_AV_VID_480P;
  130. }
  131. int ps3av_cmd_init(void)
  132. {
  133. int res;
  134. struct ps3av_pkt_av_init av_init;
  135. struct ps3av_pkt_video_init video_init;
  136. struct ps3av_pkt_audio_init audio_init;
  137. /* video init */
  138. memset(&video_init, 0, sizeof(video_init));
  139. res = ps3av_do_pkt(PS3AV_CID_VIDEO_INIT, sizeof(video_init.send_hdr),
  140. sizeof(video_init), &video_init.send_hdr);
  141. if (res < 0)
  142. return res;
  143. res = get_status(&video_init);
  144. if (res) {
  145. printk(KERN_ERR "PS3AV_CID_VIDEO_INIT: failed %x\n", res);
  146. return res;
  147. }
  148. /* audio init */
  149. memset(&audio_init, 0, sizeof(audio_init));
  150. res = ps3av_do_pkt(PS3AV_CID_AUDIO_INIT, sizeof(audio_init.send_hdr),
  151. sizeof(audio_init), &audio_init.send_hdr);
  152. if (res < 0)
  153. return res;
  154. res = get_status(&audio_init);
  155. if (res) {
  156. printk(KERN_ERR "PS3AV_CID_AUDIO_INIT: failed %x\n", res);
  157. return res;
  158. }
  159. /* av init */
  160. memset(&av_init, 0, sizeof(av_init));
  161. av_init.event_bit = 0;
  162. res = ps3av_do_pkt(PS3AV_CID_AV_INIT, sizeof(av_init), sizeof(av_init),
  163. &av_init.send_hdr);
  164. if (res < 0)
  165. return res;
  166. res = get_status(&av_init);
  167. if (res)
  168. printk(KERN_ERR "PS3AV_CID_AV_INIT: failed %x\n", res);
  169. return res;
  170. }
  171. int ps3av_cmd_fin(void)
  172. {
  173. int res;
  174. struct ps3av_pkt_av_fin av_fin;
  175. memset(&av_fin, 0, sizeof(av_fin));
  176. res = ps3av_do_pkt(PS3AV_CID_AV_FIN, sizeof(av_fin.send_hdr),
  177. sizeof(av_fin), &av_fin.send_hdr);
  178. if (res < 0)
  179. return res;
  180. res = get_status(&av_fin);
  181. if (res)
  182. printk(KERN_ERR "PS3AV_CID_AV_FIN: failed %x\n", res);
  183. return res;
  184. }
  185. int ps3av_cmd_av_video_mute(int num_of_port, u32 *port, u32 mute)
  186. {
  187. int i, send_len, res;
  188. struct ps3av_pkt_av_video_mute av_video_mute;
  189. if (num_of_port > PS3AV_MUTE_PORT_MAX)
  190. return -EINVAL;
  191. memset(&av_video_mute, 0, sizeof(av_video_mute));
  192. for (i = 0; i < num_of_port; i++) {
  193. av_video_mute.mute[i].avport = port[i];
  194. av_video_mute.mute[i].mute = mute;
  195. }
  196. send_len = sizeof(av_video_mute.send_hdr) +
  197. sizeof(struct ps3av_av_mute) * num_of_port;
  198. res = ps3av_do_pkt(PS3AV_CID_AV_VIDEO_MUTE, send_len,
  199. sizeof(av_video_mute), &av_video_mute.send_hdr);
  200. if (res < 0)
  201. return res;
  202. res = get_status(&av_video_mute);
  203. if (res)
  204. printk(KERN_ERR "PS3AV_CID_AV_VIDEO_MUTE: failed %x\n", res);
  205. return res;
  206. }
  207. int ps3av_cmd_av_video_disable_sig(u32 port)
  208. {
  209. int res;
  210. struct ps3av_pkt_av_video_disable_sig av_video_sig;
  211. memset(&av_video_sig, 0, sizeof(av_video_sig));
  212. av_video_sig.avport = port;
  213. res = ps3av_do_pkt(PS3AV_CID_AV_VIDEO_DISABLE_SIG,
  214. sizeof(av_video_sig), sizeof(av_video_sig),
  215. &av_video_sig.send_hdr);
  216. if (res < 0)
  217. return res;
  218. res = get_status(&av_video_sig);
  219. if (res)
  220. printk(KERN_ERR
  221. "PS3AV_CID_AV_VIDEO_DISABLE_SIG: failed %x port:%x\n",
  222. res, port);
  223. return res;
  224. }
  225. int ps3av_cmd_av_tv_mute(u32 avport, u32 mute)
  226. {
  227. int res;
  228. struct ps3av_pkt_av_tv_mute tv_mute;
  229. memset(&tv_mute, 0, sizeof(tv_mute));
  230. tv_mute.avport = avport;
  231. tv_mute.mute = mute;
  232. res = ps3av_do_pkt(PS3AV_CID_AV_TV_MUTE, sizeof(tv_mute),
  233. sizeof(tv_mute), &tv_mute.send_hdr);
  234. if (res < 0)
  235. return res;
  236. res = get_status(&tv_mute);
  237. if (res)
  238. printk(KERN_ERR "PS3AV_CID_AV_TV_MUTE: failed %x port:%x\n",
  239. res, avport);
  240. return res;
  241. }
  242. int ps3av_cmd_enable_event(void)
  243. {
  244. int res;
  245. struct ps3av_pkt_av_event av_event;
  246. memset(&av_event, 0, sizeof(av_event));
  247. av_event.event_bit = PS3AV_CMD_EVENT_BIT_UNPLUGGED |
  248. PS3AV_CMD_EVENT_BIT_PLUGGED | PS3AV_CMD_EVENT_BIT_HDCP_DONE;
  249. res = ps3av_do_pkt(PS3AV_CID_AV_ENABLE_EVENT, sizeof(av_event),
  250. sizeof(av_event), &av_event.send_hdr);
  251. if (res < 0)
  252. return res;
  253. res = get_status(&av_event);
  254. if (res)
  255. printk(KERN_ERR "PS3AV_CID_AV_ENABLE_EVENT: failed %x\n", res);
  256. return res;
  257. }
  258. int ps3av_cmd_av_hdmi_mode(u8 mode)
  259. {
  260. int res;
  261. struct ps3av_pkt_av_hdmi_mode hdmi_mode;
  262. memset(&hdmi_mode, 0, sizeof(hdmi_mode));
  263. hdmi_mode.mode = mode;
  264. res = ps3av_do_pkt(PS3AV_CID_AV_HDMI_MODE, sizeof(hdmi_mode),
  265. sizeof(hdmi_mode), &hdmi_mode.send_hdr);
  266. if (res < 0)
  267. return res;
  268. res = get_status(&hdmi_mode);
  269. if (res && res != PS3AV_STATUS_UNSUPPORTED_HDMI_MODE)
  270. printk(KERN_ERR "PS3AV_CID_AV_HDMI_MODE: failed %x\n", res);
  271. return res;
  272. }
  273. u32 ps3av_cmd_set_av_video_cs(void *p, u32 avport, int video_vid, int cs_out,
  274. int aspect, u32 id)
  275. {
  276. struct ps3av_pkt_av_video_cs *av_video_cs;
  277. av_video_cs = (struct ps3av_pkt_av_video_cs *)p;
  278. if (video_vid == -1)
  279. video_vid = PS3AV_CMD_VIDEO_VID_720P_60HZ;
  280. if (cs_out == -1)
  281. cs_out = PS3AV_CMD_VIDEO_CS_YUV444_8;
  282. if (aspect == -1)
  283. aspect = 0;
  284. memset(av_video_cs, 0, sizeof(*av_video_cs));
  285. ps3av_set_hdr(PS3AV_CID_AV_VIDEO_CS, sizeof(*av_video_cs),
  286. &av_video_cs->send_hdr);
  287. av_video_cs->avport = avport;
  288. /* should be same as video_mode.resolution */
  289. av_video_cs->av_vid = ps3av_vid_video2av(video_vid);
  290. av_video_cs->av_cs_out = ps3av_cs_video2av(cs_out);
  291. /* should be same as video_mode.video_cs_out */
  292. av_video_cs->av_cs_in = ps3av_cs_video2av(PS3AV_CMD_VIDEO_CS_RGB_8);
  293. av_video_cs->bitlen_out = ps3av_cs_video2av_bitlen(cs_out);
  294. av_video_cs->aspect = aspect;
  295. if (id & PS3AV_MODE_DITHER) {
  296. av_video_cs->dither = PS3AV_CMD_AV_DITHER_ON
  297. | PS3AV_CMD_AV_DITHER_8BIT;
  298. } else {
  299. /* default off */
  300. av_video_cs->dither = PS3AV_CMD_AV_DITHER_OFF;
  301. }
  302. return sizeof(*av_video_cs);
  303. }
  304. u32 ps3av_cmd_set_video_mode(void *p, u32 head, int video_vid, int video_fmt,
  305. u32 id)
  306. {
  307. struct ps3av_pkt_video_mode *video_mode;
  308. u32 x, y;
  309. video_mode = (struct ps3av_pkt_video_mode *)p;
  310. if (video_vid == -1)
  311. video_vid = PS3AV_CMD_VIDEO_VID_720P_60HZ;
  312. if (video_fmt == -1)
  313. video_fmt = PS3AV_CMD_VIDEO_FMT_X8R8G8B8;
  314. if (ps3av_video_mode2res(id, &x, &y))
  315. return 0;
  316. /* video mode */
  317. memset(video_mode, 0, sizeof(*video_mode));
  318. ps3av_set_hdr(PS3AV_CID_VIDEO_MODE, sizeof(*video_mode),
  319. &video_mode->send_hdr);
  320. video_mode->video_head = head;
  321. if (video_vid == PS3AV_CMD_VIDEO_VID_480I
  322. && head == PS3AV_CMD_VIDEO_HEAD_B)
  323. video_mode->video_vid = PS3AV_CMD_VIDEO_VID_480I_A;
  324. else
  325. video_mode->video_vid = video_vid;
  326. video_mode->width = (u16) x;
  327. video_mode->height = (u16) y;
  328. video_mode->pitch = video_mode->width * 4; /* line_length */
  329. video_mode->video_out_format = PS3AV_CMD_VIDEO_OUT_FORMAT_RGB_12BIT;
  330. video_mode->video_format = ps3av_video_fmt_table[video_fmt].format;
  331. video_mode->video_order = ps3av_video_fmt_table[video_fmt].order;
  332. pr_debug("%s: video_mode:vid:%x width:%d height:%d pitch:%d out_format:%d format:%x order:%x\n",
  333. __FUNCTION__, video_vid, video_mode->width, video_mode->height,
  334. video_mode->pitch, video_mode->video_out_format,
  335. video_mode->video_format, video_mode->video_order);
  336. return sizeof(*video_mode);
  337. }
  338. int ps3av_cmd_video_format_black(u32 head, u32 video_fmt, u32 mute)
  339. {
  340. int res;
  341. struct ps3av_pkt_video_format video_format;
  342. memset(&video_format, 0, sizeof(video_format));
  343. video_format.video_head = head;
  344. if (mute != PS3AV_CMD_MUTE_OFF)
  345. video_format.video_format = PS3AV_CMD_VIDEO_FORMAT_BLACK;
  346. else
  347. video_format.video_format =
  348. ps3av_video_fmt_table[video_fmt].format;
  349. video_format.video_order = ps3av_video_fmt_table[video_fmt].order;
  350. res = ps3av_do_pkt(PS3AV_CID_VIDEO_FORMAT, sizeof(video_format),
  351. sizeof(video_format), &video_format.send_hdr);
  352. if (res < 0)
  353. return res;
  354. res = get_status(&video_format);
  355. if (res)
  356. printk(KERN_ERR "PS3AV_CID_VIDEO_FORMAT: failed %x\n", res);
  357. return res;
  358. }
  359. int ps3av_cmd_av_audio_mute(int num_of_port, u32 *port, u32 mute)
  360. {
  361. int i, res;
  362. struct ps3av_pkt_av_audio_mute av_audio_mute;
  363. if (num_of_port > PS3AV_MUTE_PORT_MAX)
  364. return -EINVAL;
  365. /* audio mute */
  366. memset(&av_audio_mute, 0, sizeof(av_audio_mute));
  367. for (i = 0; i < num_of_port; i++) {
  368. av_audio_mute.mute[i].avport = port[i];
  369. av_audio_mute.mute[i].mute = mute;
  370. }
  371. res = ps3av_do_pkt(PS3AV_CID_AV_AUDIO_MUTE,
  372. sizeof(av_audio_mute.send_hdr) +
  373. sizeof(struct ps3av_av_mute) * num_of_port,
  374. sizeof(av_audio_mute), &av_audio_mute.send_hdr);
  375. if (res < 0)
  376. return res;
  377. res = get_status(&av_audio_mute);
  378. if (res)
  379. printk(KERN_ERR "PS3AV_CID_AV_AUDIO_MUTE: failed %x\n", res);
  380. return res;
  381. }
  382. static const struct {
  383. u32 fs;
  384. u8 mclk;
  385. } ps3av_cnv_mclk_table[] = {
  386. { PS3AV_CMD_AUDIO_FS_44K, PS3AV_CMD_AV_MCLK_512 },
  387. { PS3AV_CMD_AUDIO_FS_48K, PS3AV_CMD_AV_MCLK_512 },
  388. { PS3AV_CMD_AUDIO_FS_88K, PS3AV_CMD_AV_MCLK_256 },
  389. { PS3AV_CMD_AUDIO_FS_96K, PS3AV_CMD_AV_MCLK_256 },
  390. { PS3AV_CMD_AUDIO_FS_176K, PS3AV_CMD_AV_MCLK_128 },
  391. { PS3AV_CMD_AUDIO_FS_192K, PS3AV_CMD_AV_MCLK_128 }
  392. };
  393. static u8 ps3av_cnv_mclk(u32 fs)
  394. {
  395. unsigned int i;
  396. for (i = 0; i < ARRAY_SIZE(ps3av_cnv_mclk_table); i++)
  397. if (ps3av_cnv_mclk_table[i].fs == fs)
  398. return ps3av_cnv_mclk_table[i].mclk;
  399. printk(KERN_ERR "%s failed, fs:%x\n", __FUNCTION__, fs);
  400. return 0;
  401. }
  402. #define BASE PS3AV_CMD_AUDIO_FS_44K
  403. static const u32 ps3av_ns_table[][5] = {
  404. /* D1, D2, D3, D4, D5 */
  405. [PS3AV_CMD_AUDIO_FS_44K-BASE] = { 6272, 6272, 17836, 17836, 8918 },
  406. [PS3AV_CMD_AUDIO_FS_48K-BASE] = { 6144, 6144, 11648, 11648, 5824 },
  407. [PS3AV_CMD_AUDIO_FS_88K-BASE] = { 12544, 12544, 35672, 35672, 17836 },
  408. [PS3AV_CMD_AUDIO_FS_96K-BASE] = { 12288, 12288, 23296, 23296, 11648 },
  409. [PS3AV_CMD_AUDIO_FS_176K-BASE] = { 25088, 25088, 71344, 71344, 35672 },
  410. [PS3AV_CMD_AUDIO_FS_192K-BASE] = { 24576, 24576, 46592, 46592, 23296 }
  411. };
  412. static void ps3av_cnv_ns(u8 *ns, u32 fs, u32 video_vid)
  413. {
  414. u32 av_vid, ns_val;
  415. u8 *p = ns;
  416. int d;
  417. d = ns_val = 0;
  418. av_vid = ps3av_vid_video2av(video_vid);
  419. switch (av_vid) {
  420. case PS3AV_CMD_AV_VID_480I:
  421. case PS3AV_CMD_AV_VID_576I:
  422. d = 0;
  423. break;
  424. case PS3AV_CMD_AV_VID_480P:
  425. case PS3AV_CMD_AV_VID_576P:
  426. d = 1;
  427. break;
  428. case PS3AV_CMD_AV_VID_1080I_60HZ:
  429. case PS3AV_CMD_AV_VID_1080I_50HZ:
  430. d = 2;
  431. break;
  432. case PS3AV_CMD_AV_VID_720P_60HZ:
  433. case PS3AV_CMD_AV_VID_720P_50HZ:
  434. d = 3;
  435. break;
  436. case PS3AV_CMD_AV_VID_1080P_60HZ:
  437. case PS3AV_CMD_AV_VID_1080P_50HZ:
  438. case PS3AV_CMD_AV_VID_WXGA:
  439. case PS3AV_CMD_AV_VID_SXGA:
  440. case PS3AV_CMD_AV_VID_WUXGA:
  441. d = 4;
  442. break;
  443. default:
  444. printk(KERN_ERR "%s failed, vid:%x\n", __FUNCTION__,
  445. video_vid);
  446. break;
  447. }
  448. if (fs < PS3AV_CMD_AUDIO_FS_44K || fs > PS3AV_CMD_AUDIO_FS_192K)
  449. printk(KERN_ERR "%s failed, fs:%x\n", __FUNCTION__, fs);
  450. else
  451. ns_val = ps3av_ns_table[PS3AV_CMD_AUDIO_FS_44K-BASE][d];
  452. *p++ = ns_val & 0x000000FF;
  453. *p++ = (ns_val & 0x0000FF00) >> 8;
  454. *p = (ns_val & 0x00FF0000) >> 16;
  455. }
  456. #undef BASE
  457. static u8 ps3av_cnv_enable(u32 source, const u8 *enable)
  458. {
  459. const u8 *p;
  460. u8 ret = 0;
  461. if (source == PS3AV_CMD_AUDIO_SOURCE_SPDIF) {
  462. ret = 0x03;
  463. } else if (source == PS3AV_CMD_AUDIO_SOURCE_SERIAL) {
  464. p = enable;
  465. ret = ((p[0] << 4) + (p[1] << 5) + (p[2] << 6) + (p[3] << 7)) |
  466. 0x01;
  467. } else
  468. printk(KERN_ERR "%s failed, source:%x\n", __FUNCTION__,
  469. source);
  470. return ret;
  471. }
  472. static u8 ps3av_cnv_fifomap(const u8 *map)
  473. {
  474. const u8 *p;
  475. u8 ret = 0;
  476. p = map;
  477. ret = p[0] + (p[1] << 2) + (p[2] << 4) + (p[3] << 6);
  478. return ret;
  479. }
  480. static u8 ps3av_cnv_inputlen(u32 word_bits)
  481. {
  482. u8 ret = 0;
  483. switch (word_bits) {
  484. case PS3AV_CMD_AUDIO_WORD_BITS_16:
  485. ret = PS3AV_CMD_AV_INPUTLEN_16;
  486. break;
  487. case PS3AV_CMD_AUDIO_WORD_BITS_20:
  488. ret = PS3AV_CMD_AV_INPUTLEN_20;
  489. break;
  490. case PS3AV_CMD_AUDIO_WORD_BITS_24:
  491. ret = PS3AV_CMD_AV_INPUTLEN_24;
  492. break;
  493. default:
  494. printk(KERN_ERR "%s failed, word_bits:%x\n", __FUNCTION__,
  495. word_bits);
  496. break;
  497. }
  498. return ret;
  499. }
  500. static u8 ps3av_cnv_layout(u32 num_of_ch)
  501. {
  502. if (num_of_ch > PS3AV_CMD_AUDIO_NUM_OF_CH_8) {
  503. printk(KERN_ERR "%s failed, num_of_ch:%x\n", __FUNCTION__,
  504. num_of_ch);
  505. return 0;
  506. }
  507. return num_of_ch == PS3AV_CMD_AUDIO_NUM_OF_CH_2 ? 0x0 : 0x1;
  508. }
  509. static void ps3av_cnv_info(struct ps3av_audio_info_frame *info,
  510. const struct ps3av_pkt_audio_mode *mode)
  511. {
  512. info->pb1.cc = mode->audio_num_of_ch + 1; /* CH2:0x01 --- CH8:0x07 */
  513. info->pb1.ct = 0;
  514. info->pb2.sf = 0;
  515. info->pb2.ss = 0;
  516. info->pb3 = 0; /* check mode->audio_format ?? */
  517. info->pb4 = mode->audio_layout;
  518. info->pb5.dm = mode->audio_downmix;
  519. info->pb5.lsv = mode->audio_downmix_level;
  520. }
  521. static void ps3av_cnv_chstat(u8 *chstat, const u8 *cs_info)
  522. {
  523. memcpy(chstat, cs_info, 5);
  524. }
  525. u32 ps3av_cmd_set_av_audio_param(void *p, u32 port,
  526. const struct ps3av_pkt_audio_mode *audio_mode,
  527. u32 video_vid)
  528. {
  529. struct ps3av_pkt_av_audio_param *param;
  530. param = (struct ps3av_pkt_av_audio_param *)p;
  531. memset(param, 0, sizeof(*param));
  532. ps3av_set_hdr(PS3AV_CID_AV_AUDIO_PARAM, sizeof(*param),
  533. &param->send_hdr);
  534. param->avport = port;
  535. param->mclk = ps3av_cnv_mclk(audio_mode->audio_fs) | 0x80;
  536. ps3av_cnv_ns(param->ns, audio_mode->audio_fs, video_vid);
  537. param->enable = ps3av_cnv_enable(audio_mode->audio_source,
  538. audio_mode->audio_enable);
  539. param->swaplr = 0x09;
  540. param->fifomap = ps3av_cnv_fifomap(audio_mode->audio_map);
  541. param->inputctrl = 0x49;
  542. param->inputlen = ps3av_cnv_inputlen(audio_mode->audio_word_bits);
  543. param->layout = ps3av_cnv_layout(audio_mode->audio_num_of_ch);
  544. ps3av_cnv_info(&param->info, audio_mode);
  545. ps3av_cnv_chstat(param->chstat, audio_mode->audio_cs_info);
  546. return sizeof(*param);
  547. }
  548. /* default cs val */
  549. static const u8 ps3av_mode_cs_info[] = {
  550. 0x00, 0x09, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00
  551. };
  552. #define CS_44 0x00
  553. #define CS_48 0x02
  554. #define CS_88 0x08
  555. #define CS_96 0x0a
  556. #define CS_176 0x0c
  557. #define CS_192 0x0e
  558. #define CS_MASK 0x0f
  559. #define CS_BIT 0x40
  560. void ps3av_cmd_set_audio_mode(struct ps3av_pkt_audio_mode *audio, u32 avport,
  561. u32 ch, u32 fs, u32 word_bits, u32 format,
  562. u32 source)
  563. {
  564. int spdif_through, spdif_bitstream;
  565. int i;
  566. if (!(ch | fs | format | word_bits | source)) {
  567. ch = PS3AV_CMD_AUDIO_NUM_OF_CH_2;
  568. fs = PS3AV_CMD_AUDIO_FS_48K;
  569. word_bits = PS3AV_CMD_AUDIO_WORD_BITS_16;
  570. format = PS3AV_CMD_AUDIO_FORMAT_PCM;
  571. source = PS3AV_CMD_AUDIO_SOURCE_SERIAL;
  572. }
  573. spdif_through = spdif_bitstream = 0; /* XXX not supported */
  574. /* audio mode */
  575. memset(audio, 0, sizeof(*audio));
  576. ps3av_set_hdr(PS3AV_CID_AUDIO_MODE, sizeof(*audio), &audio->send_hdr);
  577. audio->avport = (u8) avport;
  578. audio->mask = 0x0FFF; /* XXX set all */
  579. audio->audio_num_of_ch = ch;
  580. audio->audio_fs = fs;
  581. audio->audio_word_bits = word_bits;
  582. audio->audio_format = format;
  583. audio->audio_source = source;
  584. switch (ch) {
  585. case PS3AV_CMD_AUDIO_NUM_OF_CH_8:
  586. audio->audio_enable[3] = 1;
  587. /* fall through */
  588. case PS3AV_CMD_AUDIO_NUM_OF_CH_6:
  589. audio->audio_enable[2] = 1;
  590. audio->audio_enable[1] = 1;
  591. /* fall through */
  592. case PS3AV_CMD_AUDIO_NUM_OF_CH_2:
  593. default:
  594. audio->audio_enable[0] = 1;
  595. }
  596. /* audio swap L/R */
  597. for (i = 0; i < 4; i++)
  598. audio->audio_swap[i] = PS3AV_CMD_AUDIO_SWAP_0; /* no swap */
  599. /* audio serial input mapping */
  600. audio->audio_map[0] = PS3AV_CMD_AUDIO_MAP_OUTPUT_0;
  601. audio->audio_map[1] = PS3AV_CMD_AUDIO_MAP_OUTPUT_1;
  602. audio->audio_map[2] = PS3AV_CMD_AUDIO_MAP_OUTPUT_2;
  603. audio->audio_map[3] = PS3AV_CMD_AUDIO_MAP_OUTPUT_3;
  604. /* audio speaker layout */
  605. if (avport == PS3AV_CMD_AVPORT_HDMI_0 ||
  606. avport == PS3AV_CMD_AVPORT_HDMI_1) {
  607. switch (ch) {
  608. case PS3AV_CMD_AUDIO_NUM_OF_CH_8:
  609. audio->audio_layout = PS3AV_CMD_AUDIO_LAYOUT_8CH;
  610. break;
  611. case PS3AV_CMD_AUDIO_NUM_OF_CH_6:
  612. audio->audio_layout = PS3AV_CMD_AUDIO_LAYOUT_6CH;
  613. break;
  614. case PS3AV_CMD_AUDIO_NUM_OF_CH_2:
  615. default:
  616. audio->audio_layout = PS3AV_CMD_AUDIO_LAYOUT_2CH;
  617. break;
  618. }
  619. } else {
  620. audio->audio_layout = PS3AV_CMD_AUDIO_LAYOUT_2CH;
  621. }
  622. /* audio downmix permission */
  623. audio->audio_downmix = PS3AV_CMD_AUDIO_DOWNMIX_PERMITTED;
  624. /* audio downmix level shift (0:0dB to 15:15dB) */
  625. audio->audio_downmix_level = 0; /* 0dB */
  626. /* set ch status */
  627. for (i = 0; i < 8; i++)
  628. audio->audio_cs_info[i] = ps3av_mode_cs_info[i];
  629. switch (fs) {
  630. case PS3AV_CMD_AUDIO_FS_44K:
  631. audio->audio_cs_info[3] &= ~CS_MASK;
  632. audio->audio_cs_info[3] |= CS_44;
  633. break;
  634. case PS3AV_CMD_AUDIO_FS_88K:
  635. audio->audio_cs_info[3] &= ~CS_MASK;
  636. audio->audio_cs_info[3] |= CS_88;
  637. break;
  638. case PS3AV_CMD_AUDIO_FS_96K:
  639. audio->audio_cs_info[3] &= ~CS_MASK;
  640. audio->audio_cs_info[3] |= CS_96;
  641. break;
  642. case PS3AV_CMD_AUDIO_FS_176K:
  643. audio->audio_cs_info[3] &= ~CS_MASK;
  644. audio->audio_cs_info[3] |= CS_176;
  645. break;
  646. case PS3AV_CMD_AUDIO_FS_192K:
  647. audio->audio_cs_info[3] &= ~CS_MASK;
  648. audio->audio_cs_info[3] |= CS_192;
  649. break;
  650. default:
  651. break;
  652. }
  653. /* pass through setting */
  654. if (spdif_through &&
  655. (avport == PS3AV_CMD_AVPORT_SPDIF_0 ||
  656. avport == PS3AV_CMD_AVPORT_SPDIF_1)) {
  657. audio->audio_word_bits = PS3AV_CMD_AUDIO_WORD_BITS_16;
  658. audio->audio_source = PS3AV_CMD_AUDIO_SOURCE_SPDIF;
  659. if (spdif_bitstream) {
  660. audio->audio_format = PS3AV_CMD_AUDIO_FORMAT_BITSTREAM;
  661. audio->audio_cs_info[0] |= CS_BIT;
  662. }
  663. }
  664. }
  665. int ps3av_cmd_audio_mode(struct ps3av_pkt_audio_mode *audio_mode)
  666. {
  667. int res;
  668. res = ps3av_do_pkt(PS3AV_CID_AUDIO_MODE, sizeof(*audio_mode),
  669. sizeof(*audio_mode), &audio_mode->send_hdr);
  670. if (res < 0)
  671. return res;
  672. res = get_status(audio_mode);
  673. if (res)
  674. printk(KERN_ERR "PS3AV_CID_AUDIO_MODE: failed %x\n", res);
  675. return res;
  676. }
  677. int ps3av_cmd_audio_mute(int num_of_port, u32 *port, u32 mute)
  678. {
  679. int i, res;
  680. struct ps3av_pkt_audio_mute audio_mute;
  681. if (num_of_port > PS3AV_OPT_PORT_MAX)
  682. return -EINVAL;
  683. /* audio mute */
  684. memset(&audio_mute, 0, sizeof(audio_mute));
  685. for (i = 0; i < num_of_port; i++) {
  686. audio_mute.mute[i].avport = port[i];
  687. audio_mute.mute[i].mute = mute;
  688. }
  689. res = ps3av_do_pkt(PS3AV_CID_AUDIO_MUTE,
  690. sizeof(audio_mute.send_hdr) +
  691. sizeof(struct ps3av_audio_mute) * num_of_port,
  692. sizeof(audio_mute), &audio_mute.send_hdr);
  693. if (res < 0)
  694. return res;
  695. res = get_status(&audio_mute);
  696. if (res)
  697. printk(KERN_ERR "PS3AV_CID_AUDIO_MUTE: failed %x\n", res);
  698. return res;
  699. }
  700. int ps3av_cmd_audio_active(int active, u32 port)
  701. {
  702. int res;
  703. struct ps3av_pkt_audio_active audio_active;
  704. u32 cid;
  705. /* audio active */
  706. memset(&audio_active, 0, sizeof(audio_active));
  707. audio_active.audio_port = port;
  708. cid = active ? PS3AV_CID_AUDIO_ACTIVE : PS3AV_CID_AUDIO_INACTIVE;
  709. res = ps3av_do_pkt(cid, sizeof(audio_active), sizeof(audio_active),
  710. &audio_active.send_hdr);
  711. if (res < 0)
  712. return res;
  713. res = get_status(&audio_active);
  714. if (res)
  715. printk(KERN_ERR "PS3AV_CID_AUDIO_ACTIVE:%x failed %x\n", cid,
  716. res);
  717. return res;
  718. }
  719. int ps3av_cmd_avb_param(struct ps3av_pkt_avb_param *avb, u32 send_len)
  720. {
  721. int res;
  722. ps3fb_flip_ctl(0); /* flip off */
  723. /* avb packet */
  724. res = ps3av_do_pkt(PS3AV_CID_AVB_PARAM, send_len, sizeof(*avb),
  725. &avb->send_hdr);
  726. if (res < 0)
  727. goto out;
  728. res = get_status(avb);
  729. if (res)
  730. pr_debug("%s: PS3AV_CID_AVB_PARAM: failed %x\n", __FUNCTION__,
  731. res);
  732. out:
  733. ps3fb_flip_ctl(1); /* flip on */
  734. return res;
  735. }
  736. int ps3av_cmd_av_get_hw_conf(struct ps3av_pkt_av_get_hw_conf *hw_conf)
  737. {
  738. int res;
  739. memset(hw_conf, 0, sizeof(*hw_conf));
  740. res = ps3av_do_pkt(PS3AV_CID_AV_GET_HW_CONF, sizeof(hw_conf->send_hdr),
  741. sizeof(*hw_conf), &hw_conf->send_hdr);
  742. if (res < 0)
  743. return res;
  744. res = get_status(hw_conf);
  745. if (res)
  746. printk(KERN_ERR "PS3AV_CID_AV_GET_HW_CONF: failed %x\n", res);
  747. return res;
  748. }
  749. int ps3av_cmd_video_get_monitor_info(struct ps3av_pkt_av_get_monitor_info *info,
  750. u32 avport)
  751. {
  752. int res;
  753. memset(info, 0, sizeof(*info));
  754. info->avport = avport;
  755. res = ps3av_do_pkt(PS3AV_CID_AV_GET_MONITOR_INFO,
  756. sizeof(info->send_hdr) + sizeof(info->avport) +
  757. sizeof(info->reserved),
  758. sizeof(*info), &info->send_hdr);
  759. if (res < 0)
  760. return res;
  761. res = get_status(info);
  762. if (res)
  763. printk(KERN_ERR "PS3AV_CID_AV_GET_MONITOR_INFO: failed %x\n",
  764. res);
  765. return res;
  766. }
  767. #ifdef PS3AV_DEBUG
  768. void ps3av_cmd_av_hw_conf_dump(const struct ps3av_pkt_av_get_hw_conf *hw_conf)
  769. {
  770. printk("av_h_conf:num of hdmi:%d\n", hw_conf->num_of_hdmi);
  771. printk("av_h_conf:num of avmulti:%d\n", hw_conf->num_of_avmulti);
  772. printk("av_h_conf:num of spdif:%d\n", hw_conf->num_of_spdif);
  773. }
  774. void ps3av_cmd_av_monitor_info_dump(const struct ps3av_pkt_av_get_monitor_info *monitor_info)
  775. {
  776. const struct ps3av_info_monitor *info = &monitor_info->info;
  777. const struct ps3av_info_audio *audio = info->audio;
  778. int i;
  779. printk("Monitor Info: size%d\n", monitor_info->send_hdr.size);
  780. printk("avport:%02x\n", info->avport);
  781. printk("monitor_id:");
  782. for (i = 0; i < 10; i++)
  783. printk("%02x ", info->monitor_id[i]);
  784. printk("\nmonitor_type:%02x\n", info->monitor_type);
  785. printk("monitor_name:");
  786. for (i = 0; i < 16; i++)
  787. printk("%c", info->monitor_name[i]);
  788. /* resolution */
  789. printk("\nresolution_60: bits:%08x native:%08x\n",
  790. info->res_60.res_bits, info->res_60.native);
  791. printk("resolution_50: bits:%08x native:%08x\n",
  792. info->res_50.res_bits, info->res_50.native);
  793. printk("resolution_other: bits:%08x native:%08x\n",
  794. info->res_other.res_bits, info->res_other.native);
  795. printk("resolution_vesa: bits:%08x native:%08x\n",
  796. info->res_vesa.res_bits, info->res_vesa.native);
  797. /* color space */
  798. printk("color space rgb:%02x\n", info->cs.rgb);
  799. printk("color space yuv444:%02x\n", info->cs.yuv444);
  800. printk("color space yuv422:%02x\n", info->cs.yuv422);
  801. /* color info */
  802. printk("color info red:X %04x Y %04x\n",
  803. info->color.red_x, info->color.red_y);
  804. printk("color info green:X %04x Y %04x\n",
  805. info->color.green_x, info->color.green_y);
  806. printk("color info blue:X %04x Y %04x\n",
  807. info->color.blue_x, info->color.blue_y);
  808. printk("color info white:X %04x Y %04x\n",
  809. info->color.white_x, info->color.white_y);
  810. printk("color info gamma: %08x\n", info->color.gamma);
  811. /* other info */
  812. printk("supported_AI:%02x\n", info->supported_ai);
  813. printk("speaker_info:%02x\n", info->speaker_info);
  814. printk("num of audio:%02x\n", info->num_of_audio_block);
  815. /* audio block */
  816. for (i = 0; i < info->num_of_audio_block; i++) {
  817. printk("audio[%d] type:%02x max_ch:%02x fs:%02x sbit:%02x\n",
  818. i, audio->type, audio->max_num_of_ch, audio->fs,
  819. audio->sbit);
  820. audio++;
  821. }
  822. }
  823. #endif /* PS3AV_DEBUG */
  824. #define PS3AV_AV_LAYOUT_0 (PS3AV_CMD_AV_LAYOUT_32 \
  825. | PS3AV_CMD_AV_LAYOUT_44 \
  826. | PS3AV_CMD_AV_LAYOUT_48)
  827. #define PS3AV_AV_LAYOUT_1 (PS3AV_AV_LAYOUT_0 \
  828. | PS3AV_CMD_AV_LAYOUT_88 \
  829. | PS3AV_CMD_AV_LAYOUT_96 \
  830. | PS3AV_CMD_AV_LAYOUT_176 \
  831. | PS3AV_CMD_AV_LAYOUT_192)
  832. /************************* vuart ***************************/
  833. #define POLLING_INTERVAL 25 /* in msec */
  834. int ps3av_vuart_write(struct ps3_vuart_port_device *dev, const void *buf,
  835. unsigned long size)
  836. {
  837. int error = ps3_vuart_write(dev, buf, size);
  838. return error ? error : size;
  839. }
  840. int ps3av_vuart_read(struct ps3_vuart_port_device *dev, void *buf,
  841. unsigned long size, int timeout)
  842. {
  843. int error;
  844. int loopcnt = 0;
  845. timeout = (timeout + POLLING_INTERVAL - 1) / POLLING_INTERVAL;
  846. while (loopcnt++ <= timeout) {
  847. error = ps3_vuart_read(dev, buf, size);
  848. if (!error)
  849. return size;
  850. if (error != -EAGAIN) {
  851. printk(KERN_ERR "%s: ps3_vuart_read failed %d\n",
  852. __FUNCTION__, error);
  853. return error;
  854. }
  855. msleep(POLLING_INTERVAL);
  856. }
  857. return -EWOULDBLOCK;
  858. }