ps3av_cmd.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020
  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. __func__, 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", __func__, 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", __func__, video_vid);
  445. break;
  446. }
  447. if (fs < PS3AV_CMD_AUDIO_FS_44K || fs > PS3AV_CMD_AUDIO_FS_192K)
  448. printk(KERN_ERR "%s failed, fs:%x\n", __func__, fs);
  449. else
  450. ns_val = ps3av_ns_table[PS3AV_CMD_AUDIO_FS_44K-BASE][d];
  451. *p++ = ns_val & 0x000000FF;
  452. *p++ = (ns_val & 0x0000FF00) >> 8;
  453. *p = (ns_val & 0x00FF0000) >> 16;
  454. }
  455. #undef BASE
  456. static u8 ps3av_cnv_enable(u32 source, const u8 *enable)
  457. {
  458. const u8 *p;
  459. u8 ret = 0;
  460. if (source == PS3AV_CMD_AUDIO_SOURCE_SPDIF) {
  461. ret = 0x03;
  462. } else if (source == PS3AV_CMD_AUDIO_SOURCE_SERIAL) {
  463. p = enable;
  464. ret = ((p[0] << 4) + (p[1] << 5) + (p[2] << 6) + (p[3] << 7)) |
  465. 0x01;
  466. } else
  467. printk(KERN_ERR "%s failed, source:%x\n", __func__, source);
  468. return ret;
  469. }
  470. static u8 ps3av_cnv_fifomap(const u8 *map)
  471. {
  472. const u8 *p;
  473. u8 ret = 0;
  474. p = map;
  475. ret = p[0] + (p[1] << 2) + (p[2] << 4) + (p[3] << 6);
  476. return ret;
  477. }
  478. static u8 ps3av_cnv_inputlen(u32 word_bits)
  479. {
  480. u8 ret = 0;
  481. switch (word_bits) {
  482. case PS3AV_CMD_AUDIO_WORD_BITS_16:
  483. ret = PS3AV_CMD_AV_INPUTLEN_16;
  484. break;
  485. case PS3AV_CMD_AUDIO_WORD_BITS_20:
  486. ret = PS3AV_CMD_AV_INPUTLEN_20;
  487. break;
  488. case PS3AV_CMD_AUDIO_WORD_BITS_24:
  489. ret = PS3AV_CMD_AV_INPUTLEN_24;
  490. break;
  491. default:
  492. printk(KERN_ERR "%s failed, word_bits:%x\n", __func__,
  493. word_bits);
  494. break;
  495. }
  496. return ret;
  497. }
  498. static u8 ps3av_cnv_layout(u32 num_of_ch)
  499. {
  500. if (num_of_ch > PS3AV_CMD_AUDIO_NUM_OF_CH_8) {
  501. printk(KERN_ERR "%s failed, num_of_ch:%x\n", __func__,
  502. num_of_ch);
  503. return 0;
  504. }
  505. return num_of_ch == PS3AV_CMD_AUDIO_NUM_OF_CH_2 ? 0x0 : 0x1;
  506. }
  507. static void ps3av_cnv_info(struct ps3av_audio_info_frame *info,
  508. const struct ps3av_pkt_audio_mode *mode)
  509. {
  510. info->pb1.cc = mode->audio_num_of_ch + 1; /* CH2:0x01 --- CH8:0x07 */
  511. info->pb1.ct = 0;
  512. info->pb2.sf = 0;
  513. info->pb2.ss = 0;
  514. info->pb3 = 0; /* check mode->audio_format ?? */
  515. info->pb4 = mode->audio_layout;
  516. info->pb5.dm = mode->audio_downmix;
  517. info->pb5.lsv = mode->audio_downmix_level;
  518. }
  519. static void ps3av_cnv_chstat(u8 *chstat, const u8 *cs_info)
  520. {
  521. memcpy(chstat, cs_info, 5);
  522. }
  523. u32 ps3av_cmd_set_av_audio_param(void *p, u32 port,
  524. const struct ps3av_pkt_audio_mode *audio_mode,
  525. u32 video_vid)
  526. {
  527. struct ps3av_pkt_av_audio_param *param;
  528. param = (struct ps3av_pkt_av_audio_param *)p;
  529. memset(param, 0, sizeof(*param));
  530. ps3av_set_hdr(PS3AV_CID_AV_AUDIO_PARAM, sizeof(*param),
  531. &param->send_hdr);
  532. param->avport = port;
  533. param->mclk = ps3av_cnv_mclk(audio_mode->audio_fs) | 0x80;
  534. ps3av_cnv_ns(param->ns, audio_mode->audio_fs, video_vid);
  535. param->enable = ps3av_cnv_enable(audio_mode->audio_source,
  536. audio_mode->audio_enable);
  537. param->swaplr = 0x09;
  538. param->fifomap = ps3av_cnv_fifomap(audio_mode->audio_map);
  539. param->inputctrl = 0x49;
  540. param->inputlen = ps3av_cnv_inputlen(audio_mode->audio_word_bits);
  541. param->layout = ps3av_cnv_layout(audio_mode->audio_num_of_ch);
  542. ps3av_cnv_info(&param->info, audio_mode);
  543. ps3av_cnv_chstat(param->chstat, audio_mode->audio_cs_info);
  544. return sizeof(*param);
  545. }
  546. /* default cs val */
  547. static const u8 ps3av_mode_cs_info[] = {
  548. 0x00, 0x09, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00
  549. };
  550. #define CS_44 0x00
  551. #define CS_48 0x02
  552. #define CS_88 0x08
  553. #define CS_96 0x0a
  554. #define CS_176 0x0c
  555. #define CS_192 0x0e
  556. #define CS_MASK 0x0f
  557. #define CS_BIT 0x40
  558. void ps3av_cmd_set_audio_mode(struct ps3av_pkt_audio_mode *audio, u32 avport,
  559. u32 ch, u32 fs, u32 word_bits, u32 format,
  560. u32 source)
  561. {
  562. int spdif_through, spdif_bitstream;
  563. int i;
  564. if (!(ch | fs | format | word_bits | source)) {
  565. ch = PS3AV_CMD_AUDIO_NUM_OF_CH_2;
  566. fs = PS3AV_CMD_AUDIO_FS_48K;
  567. word_bits = PS3AV_CMD_AUDIO_WORD_BITS_16;
  568. format = PS3AV_CMD_AUDIO_FORMAT_PCM;
  569. source = PS3AV_CMD_AUDIO_SOURCE_SERIAL;
  570. }
  571. spdif_through = spdif_bitstream = 0; /* XXX not supported */
  572. /* audio mode */
  573. memset(audio, 0, sizeof(*audio));
  574. ps3av_set_hdr(PS3AV_CID_AUDIO_MODE, sizeof(*audio), &audio->send_hdr);
  575. audio->avport = (u8) avport;
  576. audio->mask = 0x0FFF; /* XXX set all */
  577. audio->audio_num_of_ch = ch;
  578. audio->audio_fs = fs;
  579. audio->audio_word_bits = word_bits;
  580. audio->audio_format = format;
  581. audio->audio_source = source;
  582. switch (ch) {
  583. case PS3AV_CMD_AUDIO_NUM_OF_CH_8:
  584. audio->audio_enable[3] = 1;
  585. /* fall through */
  586. case PS3AV_CMD_AUDIO_NUM_OF_CH_6:
  587. audio->audio_enable[2] = 1;
  588. audio->audio_enable[1] = 1;
  589. /* fall through */
  590. case PS3AV_CMD_AUDIO_NUM_OF_CH_2:
  591. default:
  592. audio->audio_enable[0] = 1;
  593. }
  594. /* audio swap L/R */
  595. for (i = 0; i < 4; i++)
  596. audio->audio_swap[i] = PS3AV_CMD_AUDIO_SWAP_0; /* no swap */
  597. /* audio serial input mapping */
  598. audio->audio_map[0] = PS3AV_CMD_AUDIO_MAP_OUTPUT_0;
  599. audio->audio_map[1] = PS3AV_CMD_AUDIO_MAP_OUTPUT_1;
  600. audio->audio_map[2] = PS3AV_CMD_AUDIO_MAP_OUTPUT_2;
  601. audio->audio_map[3] = PS3AV_CMD_AUDIO_MAP_OUTPUT_3;
  602. /* audio speaker layout */
  603. if (avport == PS3AV_CMD_AVPORT_HDMI_0 ||
  604. avport == PS3AV_CMD_AVPORT_HDMI_1) {
  605. switch (ch) {
  606. case PS3AV_CMD_AUDIO_NUM_OF_CH_8:
  607. audio->audio_layout = PS3AV_CMD_AUDIO_LAYOUT_8CH;
  608. break;
  609. case PS3AV_CMD_AUDIO_NUM_OF_CH_6:
  610. audio->audio_layout = PS3AV_CMD_AUDIO_LAYOUT_6CH;
  611. break;
  612. case PS3AV_CMD_AUDIO_NUM_OF_CH_2:
  613. default:
  614. audio->audio_layout = PS3AV_CMD_AUDIO_LAYOUT_2CH;
  615. break;
  616. }
  617. } else {
  618. audio->audio_layout = PS3AV_CMD_AUDIO_LAYOUT_2CH;
  619. }
  620. /* audio downmix permission */
  621. audio->audio_downmix = PS3AV_CMD_AUDIO_DOWNMIX_PERMITTED;
  622. /* audio downmix level shift (0:0dB to 15:15dB) */
  623. audio->audio_downmix_level = 0; /* 0dB */
  624. /* set ch status */
  625. for (i = 0; i < 8; i++)
  626. audio->audio_cs_info[i] = ps3av_mode_cs_info[i];
  627. switch (fs) {
  628. case PS3AV_CMD_AUDIO_FS_44K:
  629. audio->audio_cs_info[3] &= ~CS_MASK;
  630. audio->audio_cs_info[3] |= CS_44;
  631. break;
  632. case PS3AV_CMD_AUDIO_FS_88K:
  633. audio->audio_cs_info[3] &= ~CS_MASK;
  634. audio->audio_cs_info[3] |= CS_88;
  635. break;
  636. case PS3AV_CMD_AUDIO_FS_96K:
  637. audio->audio_cs_info[3] &= ~CS_MASK;
  638. audio->audio_cs_info[3] |= CS_96;
  639. break;
  640. case PS3AV_CMD_AUDIO_FS_176K:
  641. audio->audio_cs_info[3] &= ~CS_MASK;
  642. audio->audio_cs_info[3] |= CS_176;
  643. break;
  644. case PS3AV_CMD_AUDIO_FS_192K:
  645. audio->audio_cs_info[3] &= ~CS_MASK;
  646. audio->audio_cs_info[3] |= CS_192;
  647. break;
  648. default:
  649. break;
  650. }
  651. /* pass through setting */
  652. if (spdif_through &&
  653. (avport == PS3AV_CMD_AVPORT_SPDIF_0 ||
  654. avport == PS3AV_CMD_AVPORT_SPDIF_1)) {
  655. audio->audio_word_bits = PS3AV_CMD_AUDIO_WORD_BITS_16;
  656. audio->audio_source = PS3AV_CMD_AUDIO_SOURCE_SPDIF;
  657. if (spdif_bitstream) {
  658. audio->audio_format = PS3AV_CMD_AUDIO_FORMAT_BITSTREAM;
  659. audio->audio_cs_info[0] |= CS_BIT;
  660. }
  661. }
  662. }
  663. int ps3av_cmd_audio_mode(struct ps3av_pkt_audio_mode *audio_mode)
  664. {
  665. int res;
  666. res = ps3av_do_pkt(PS3AV_CID_AUDIO_MODE, sizeof(*audio_mode),
  667. sizeof(*audio_mode), &audio_mode->send_hdr);
  668. if (res < 0)
  669. return res;
  670. res = get_status(audio_mode);
  671. if (res)
  672. printk(KERN_ERR "PS3AV_CID_AUDIO_MODE: failed %x\n", res);
  673. return res;
  674. }
  675. int ps3av_cmd_audio_mute(int num_of_port, u32 *port, u32 mute)
  676. {
  677. int i, res;
  678. struct ps3av_pkt_audio_mute audio_mute;
  679. if (num_of_port > PS3AV_OPT_PORT_MAX)
  680. return -EINVAL;
  681. /* audio mute */
  682. memset(&audio_mute, 0, sizeof(audio_mute));
  683. for (i = 0; i < num_of_port; i++) {
  684. audio_mute.mute[i].avport = port[i];
  685. audio_mute.mute[i].mute = mute;
  686. }
  687. res = ps3av_do_pkt(PS3AV_CID_AUDIO_MUTE,
  688. sizeof(audio_mute.send_hdr) +
  689. sizeof(struct ps3av_audio_mute) * num_of_port,
  690. sizeof(audio_mute), &audio_mute.send_hdr);
  691. if (res < 0)
  692. return res;
  693. res = get_status(&audio_mute);
  694. if (res)
  695. printk(KERN_ERR "PS3AV_CID_AUDIO_MUTE: failed %x\n", res);
  696. return res;
  697. }
  698. int ps3av_cmd_audio_active(int active, u32 port)
  699. {
  700. int res;
  701. struct ps3av_pkt_audio_active audio_active;
  702. u32 cid;
  703. /* audio active */
  704. memset(&audio_active, 0, sizeof(audio_active));
  705. audio_active.audio_port = port;
  706. cid = active ? PS3AV_CID_AUDIO_ACTIVE : PS3AV_CID_AUDIO_INACTIVE;
  707. res = ps3av_do_pkt(cid, sizeof(audio_active), sizeof(audio_active),
  708. &audio_active.send_hdr);
  709. if (res < 0)
  710. return res;
  711. res = get_status(&audio_active);
  712. if (res)
  713. printk(KERN_ERR "PS3AV_CID_AUDIO_ACTIVE:%x failed %x\n", cid,
  714. res);
  715. return res;
  716. }
  717. int ps3av_cmd_avb_param(struct ps3av_pkt_avb_param *avb, u32 send_len)
  718. {
  719. int res;
  720. ps3fb_flip_ctl(0); /* flip off */
  721. /* avb packet */
  722. res = ps3av_do_pkt(PS3AV_CID_AVB_PARAM, send_len, sizeof(*avb),
  723. &avb->send_hdr);
  724. if (res < 0)
  725. goto out;
  726. res = get_status(avb);
  727. if (res)
  728. pr_debug("%s: PS3AV_CID_AVB_PARAM: failed %x\n", __func__,
  729. res);
  730. out:
  731. ps3fb_flip_ctl(1); /* flip on */
  732. return res;
  733. }
  734. int ps3av_cmd_av_get_hw_conf(struct ps3av_pkt_av_get_hw_conf *hw_conf)
  735. {
  736. int res;
  737. memset(hw_conf, 0, sizeof(*hw_conf));
  738. res = ps3av_do_pkt(PS3AV_CID_AV_GET_HW_CONF, sizeof(hw_conf->send_hdr),
  739. sizeof(*hw_conf), &hw_conf->send_hdr);
  740. if (res < 0)
  741. return res;
  742. res = get_status(hw_conf);
  743. if (res)
  744. printk(KERN_ERR "PS3AV_CID_AV_GET_HW_CONF: failed %x\n", res);
  745. return res;
  746. }
  747. int ps3av_cmd_video_get_monitor_info(struct ps3av_pkt_av_get_monitor_info *info,
  748. u32 avport)
  749. {
  750. int res;
  751. memset(info, 0, sizeof(*info));
  752. info->avport = avport;
  753. res = ps3av_do_pkt(PS3AV_CID_AV_GET_MONITOR_INFO,
  754. sizeof(info->send_hdr) + sizeof(info->avport) +
  755. sizeof(info->reserved),
  756. sizeof(*info), &info->send_hdr);
  757. if (res < 0)
  758. return res;
  759. res = get_status(info);
  760. if (res)
  761. printk(KERN_ERR "PS3AV_CID_AV_GET_MONITOR_INFO: failed %x\n",
  762. res);
  763. return res;
  764. }
  765. #ifdef PS3AV_DEBUG
  766. void ps3av_cmd_av_hw_conf_dump(const struct ps3av_pkt_av_get_hw_conf *hw_conf)
  767. {
  768. printk("av_h_conf:num of hdmi:%d\n", hw_conf->num_of_hdmi);
  769. printk("av_h_conf:num of avmulti:%d\n", hw_conf->num_of_avmulti);
  770. printk("av_h_conf:num of spdif:%d\n", hw_conf->num_of_spdif);
  771. }
  772. void ps3av_cmd_av_monitor_info_dump(const struct ps3av_pkt_av_get_monitor_info *monitor_info)
  773. {
  774. const struct ps3av_info_monitor *info = &monitor_info->info;
  775. const struct ps3av_info_audio *audio = info->audio;
  776. int i;
  777. printk("Monitor Info: size%d\n", monitor_info->send_hdr.size);
  778. printk("avport:%02x\n", info->avport);
  779. printk("monitor_id:");
  780. for (i = 0; i < 10; i++)
  781. printk("%02x ", info->monitor_id[i]);
  782. printk("\nmonitor_type:%02x\n", info->monitor_type);
  783. printk("monitor_name:");
  784. for (i = 0; i < 16; i++)
  785. printk("%c", info->monitor_name[i]);
  786. /* resolution */
  787. printk("\nresolution_60: bits:%08x native:%08x\n",
  788. info->res_60.res_bits, info->res_60.native);
  789. printk("resolution_50: bits:%08x native:%08x\n",
  790. info->res_50.res_bits, info->res_50.native);
  791. printk("resolution_other: bits:%08x native:%08x\n",
  792. info->res_other.res_bits, info->res_other.native);
  793. printk("resolution_vesa: bits:%08x native:%08x\n",
  794. info->res_vesa.res_bits, info->res_vesa.native);
  795. /* color space */
  796. printk("color space rgb:%02x\n", info->cs.rgb);
  797. printk("color space yuv444:%02x\n", info->cs.yuv444);
  798. printk("color space yuv422:%02x\n", info->cs.yuv422);
  799. /* color info */
  800. printk("color info red:X %04x Y %04x\n",
  801. info->color.red_x, info->color.red_y);
  802. printk("color info green:X %04x Y %04x\n",
  803. info->color.green_x, info->color.green_y);
  804. printk("color info blue:X %04x Y %04x\n",
  805. info->color.blue_x, info->color.blue_y);
  806. printk("color info white:X %04x Y %04x\n",
  807. info->color.white_x, info->color.white_y);
  808. printk("color info gamma: %08x\n", info->color.gamma);
  809. /* other info */
  810. printk("supported_AI:%02x\n", info->supported_ai);
  811. printk("speaker_info:%02x\n", info->speaker_info);
  812. printk("num of audio:%02x\n", info->num_of_audio_block);
  813. /* audio block */
  814. for (i = 0; i < info->num_of_audio_block; i++) {
  815. printk("audio[%d] type:%02x max_ch:%02x fs:%02x sbit:%02x\n",
  816. i, audio->type, audio->max_num_of_ch, audio->fs,
  817. audio->sbit);
  818. audio++;
  819. }
  820. }
  821. #endif /* PS3AV_DEBUG */
  822. #define PS3AV_AV_LAYOUT_0 (PS3AV_CMD_AV_LAYOUT_32 \
  823. | PS3AV_CMD_AV_LAYOUT_44 \
  824. | PS3AV_CMD_AV_LAYOUT_48)
  825. #define PS3AV_AV_LAYOUT_1 (PS3AV_AV_LAYOUT_0 \
  826. | PS3AV_CMD_AV_LAYOUT_88 \
  827. | PS3AV_CMD_AV_LAYOUT_96 \
  828. | PS3AV_CMD_AV_LAYOUT_176 \
  829. | PS3AV_CMD_AV_LAYOUT_192)
  830. /************************* vuart ***************************/
  831. #define POLLING_INTERVAL 25 /* in msec */
  832. int ps3av_vuart_write(struct ps3_vuart_port_device *dev, const void *buf,
  833. unsigned long size)
  834. {
  835. int error = ps3_vuart_write(dev, buf, size);
  836. return error ? error : size;
  837. }
  838. int ps3av_vuart_read(struct ps3_vuart_port_device *dev, void *buf,
  839. unsigned long size, int timeout)
  840. {
  841. int error;
  842. int loopcnt = 0;
  843. timeout = (timeout + POLLING_INTERVAL - 1) / POLLING_INTERVAL;
  844. while (loopcnt++ <= timeout) {
  845. error = ps3_vuart_read(dev, buf, size);
  846. if (!error)
  847. return size;
  848. if (error != -EAGAIN) {
  849. printk(KERN_ERR "%s: ps3_vuart_read failed %d\n",
  850. __func__, error);
  851. return error;
  852. }
  853. msleep(POLLING_INTERVAL);
  854. }
  855. return -EWOULDBLOCK;
  856. }