cec-funcs.h 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881
  1. /*
  2. * cec - HDMI Consumer Electronics Control message functions
  3. *
  4. * Copyright 2016 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
  5. *
  6. * This program is free software; you may redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; version 2 of the License.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  11. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  12. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  13. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  14. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  15. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  16. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  17. * SOFTWARE.
  18. */
  19. /*
  20. * Note: this framework is still in staging and it is likely the API
  21. * will change before it goes out of staging.
  22. *
  23. * Once it is moved out of staging this header will move to uapi.
  24. */
  25. #ifndef _CEC_UAPI_FUNCS_H
  26. #define _CEC_UAPI_FUNCS_H
  27. #include <linux/cec.h>
  28. /* One Touch Play Feature */
  29. static inline void cec_msg_active_source(struct cec_msg *msg, __u16 phys_addr)
  30. {
  31. msg->len = 4;
  32. msg->msg[0] |= 0xf; /* broadcast */
  33. msg->msg[1] = CEC_MSG_ACTIVE_SOURCE;
  34. msg->msg[2] = phys_addr >> 8;
  35. msg->msg[3] = phys_addr & 0xff;
  36. }
  37. static inline void cec_ops_active_source(const struct cec_msg *msg,
  38. __u16 *phys_addr)
  39. {
  40. *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
  41. }
  42. static inline void cec_msg_image_view_on(struct cec_msg *msg)
  43. {
  44. msg->len = 2;
  45. msg->msg[1] = CEC_MSG_IMAGE_VIEW_ON;
  46. }
  47. static inline void cec_msg_text_view_on(struct cec_msg *msg)
  48. {
  49. msg->len = 2;
  50. msg->msg[1] = CEC_MSG_TEXT_VIEW_ON;
  51. }
  52. /* Routing Control Feature */
  53. static inline void cec_msg_inactive_source(struct cec_msg *msg,
  54. __u16 phys_addr)
  55. {
  56. msg->len = 4;
  57. msg->msg[1] = CEC_MSG_INACTIVE_SOURCE;
  58. msg->msg[2] = phys_addr >> 8;
  59. msg->msg[3] = phys_addr & 0xff;
  60. }
  61. static inline void cec_ops_inactive_source(const struct cec_msg *msg,
  62. __u16 *phys_addr)
  63. {
  64. *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
  65. }
  66. static inline void cec_msg_request_active_source(struct cec_msg *msg,
  67. bool reply)
  68. {
  69. msg->len = 2;
  70. msg->msg[0] |= 0xf; /* broadcast */
  71. msg->msg[1] = CEC_MSG_REQUEST_ACTIVE_SOURCE;
  72. msg->reply = reply ? CEC_MSG_ACTIVE_SOURCE : 0;
  73. }
  74. static inline void cec_msg_routing_information(struct cec_msg *msg,
  75. __u16 phys_addr)
  76. {
  77. msg->len = 4;
  78. msg->msg[0] |= 0xf; /* broadcast */
  79. msg->msg[1] = CEC_MSG_ROUTING_INFORMATION;
  80. msg->msg[2] = phys_addr >> 8;
  81. msg->msg[3] = phys_addr & 0xff;
  82. }
  83. static inline void cec_ops_routing_information(const struct cec_msg *msg,
  84. __u16 *phys_addr)
  85. {
  86. *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
  87. }
  88. static inline void cec_msg_routing_change(struct cec_msg *msg,
  89. bool reply,
  90. __u16 orig_phys_addr,
  91. __u16 new_phys_addr)
  92. {
  93. msg->len = 6;
  94. msg->msg[0] |= 0xf; /* broadcast */
  95. msg->msg[1] = CEC_MSG_ROUTING_CHANGE;
  96. msg->msg[2] = orig_phys_addr >> 8;
  97. msg->msg[3] = orig_phys_addr & 0xff;
  98. msg->msg[4] = new_phys_addr >> 8;
  99. msg->msg[5] = new_phys_addr & 0xff;
  100. msg->reply = reply ? CEC_MSG_ROUTING_INFORMATION : 0;
  101. }
  102. static inline void cec_ops_routing_change(const struct cec_msg *msg,
  103. __u16 *orig_phys_addr,
  104. __u16 *new_phys_addr)
  105. {
  106. *orig_phys_addr = (msg->msg[2] << 8) | msg->msg[3];
  107. *new_phys_addr = (msg->msg[4] << 8) | msg->msg[5];
  108. }
  109. static inline void cec_msg_set_stream_path(struct cec_msg *msg, __u16 phys_addr)
  110. {
  111. msg->len = 4;
  112. msg->msg[0] |= 0xf; /* broadcast */
  113. msg->msg[1] = CEC_MSG_SET_STREAM_PATH;
  114. msg->msg[2] = phys_addr >> 8;
  115. msg->msg[3] = phys_addr & 0xff;
  116. }
  117. static inline void cec_ops_set_stream_path(const struct cec_msg *msg,
  118. __u16 *phys_addr)
  119. {
  120. *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
  121. }
  122. /* Standby Feature */
  123. static inline void cec_msg_standby(struct cec_msg *msg)
  124. {
  125. msg->len = 2;
  126. msg->msg[1] = CEC_MSG_STANDBY;
  127. }
  128. /* One Touch Record Feature */
  129. static inline void cec_msg_record_off(struct cec_msg *msg)
  130. {
  131. msg->len = 2;
  132. msg->msg[1] = CEC_MSG_RECORD_OFF;
  133. }
  134. struct cec_op_arib_data {
  135. __u16 transport_id;
  136. __u16 service_id;
  137. __u16 orig_network_id;
  138. };
  139. struct cec_op_atsc_data {
  140. __u16 transport_id;
  141. __u16 program_number;
  142. };
  143. struct cec_op_dvb_data {
  144. __u16 transport_id;
  145. __u16 service_id;
  146. __u16 orig_network_id;
  147. };
  148. struct cec_op_channel_data {
  149. __u8 channel_number_fmt;
  150. __u16 major;
  151. __u16 minor;
  152. };
  153. struct cec_op_digital_service_id {
  154. __u8 service_id_method;
  155. __u8 dig_bcast_system;
  156. union {
  157. struct cec_op_arib_data arib;
  158. struct cec_op_atsc_data atsc;
  159. struct cec_op_dvb_data dvb;
  160. struct cec_op_channel_data channel;
  161. };
  162. };
  163. struct cec_op_record_src {
  164. __u8 type;
  165. union {
  166. struct cec_op_digital_service_id digital;
  167. struct {
  168. __u8 ana_bcast_type;
  169. __u16 ana_freq;
  170. __u8 bcast_system;
  171. } analog;
  172. struct {
  173. __u8 plug;
  174. } ext_plug;
  175. struct {
  176. __u16 phys_addr;
  177. } ext_phys_addr;
  178. };
  179. };
  180. static inline void cec_set_digital_service_id(__u8 *msg,
  181. const struct cec_op_digital_service_id *digital)
  182. {
  183. *msg++ = (digital->service_id_method << 7) | digital->dig_bcast_system;
  184. if (digital->service_id_method == CEC_OP_SERVICE_ID_METHOD_BY_CHANNEL) {
  185. *msg++ = (digital->channel.channel_number_fmt << 2) |
  186. (digital->channel.major >> 8);
  187. *msg++ = digital->channel.major && 0xff;
  188. *msg++ = digital->channel.minor >> 8;
  189. *msg++ = digital->channel.minor & 0xff;
  190. *msg++ = 0;
  191. *msg++ = 0;
  192. return;
  193. }
  194. switch (digital->dig_bcast_system) {
  195. case CEC_OP_DIG_SERVICE_BCAST_SYSTEM_ATSC_GEN:
  196. case CEC_OP_DIG_SERVICE_BCAST_SYSTEM_ATSC_CABLE:
  197. case CEC_OP_DIG_SERVICE_BCAST_SYSTEM_ATSC_SAT:
  198. case CEC_OP_DIG_SERVICE_BCAST_SYSTEM_ATSC_T:
  199. *msg++ = digital->atsc.transport_id >> 8;
  200. *msg++ = digital->atsc.transport_id & 0xff;
  201. *msg++ = digital->atsc.program_number >> 8;
  202. *msg++ = digital->atsc.program_number & 0xff;
  203. *msg++ = 0;
  204. *msg++ = 0;
  205. break;
  206. default:
  207. *msg++ = digital->dvb.transport_id >> 8;
  208. *msg++ = digital->dvb.transport_id & 0xff;
  209. *msg++ = digital->dvb.service_id >> 8;
  210. *msg++ = digital->dvb.service_id & 0xff;
  211. *msg++ = digital->dvb.orig_network_id >> 8;
  212. *msg++ = digital->dvb.orig_network_id & 0xff;
  213. break;
  214. }
  215. }
  216. static inline void cec_get_digital_service_id(const __u8 *msg,
  217. struct cec_op_digital_service_id *digital)
  218. {
  219. digital->service_id_method = msg[0] >> 7;
  220. digital->dig_bcast_system = msg[0] & 0x7f;
  221. if (digital->service_id_method == CEC_OP_SERVICE_ID_METHOD_BY_CHANNEL) {
  222. digital->channel.channel_number_fmt = msg[1] >> 2;
  223. digital->channel.major = ((msg[1] & 3) << 6) | msg[2];
  224. digital->channel.minor = (msg[3] << 8) | msg[4];
  225. return;
  226. }
  227. digital->dvb.transport_id = (msg[1] << 8) | msg[2];
  228. digital->dvb.service_id = (msg[3] << 8) | msg[4];
  229. digital->dvb.orig_network_id = (msg[5] << 8) | msg[6];
  230. }
  231. static inline void cec_msg_record_on_own(struct cec_msg *msg)
  232. {
  233. msg->len = 3;
  234. msg->msg[1] = CEC_MSG_RECORD_ON;
  235. msg->msg[2] = CEC_OP_RECORD_SRC_OWN;
  236. }
  237. static inline void cec_msg_record_on_digital(struct cec_msg *msg,
  238. const struct cec_op_digital_service_id *digital)
  239. {
  240. msg->len = 10;
  241. msg->msg[1] = CEC_MSG_RECORD_ON;
  242. msg->msg[2] = CEC_OP_RECORD_SRC_DIGITAL;
  243. cec_set_digital_service_id(msg->msg + 3, digital);
  244. }
  245. static inline void cec_msg_record_on_analog(struct cec_msg *msg,
  246. __u8 ana_bcast_type,
  247. __u16 ana_freq,
  248. __u8 bcast_system)
  249. {
  250. msg->len = 7;
  251. msg->msg[1] = CEC_MSG_RECORD_ON;
  252. msg->msg[2] = CEC_OP_RECORD_SRC_ANALOG;
  253. msg->msg[3] = ana_bcast_type;
  254. msg->msg[4] = ana_freq >> 8;
  255. msg->msg[5] = ana_freq & 0xff;
  256. msg->msg[6] = bcast_system;
  257. }
  258. static inline void cec_msg_record_on_plug(struct cec_msg *msg,
  259. __u8 plug)
  260. {
  261. msg->len = 4;
  262. msg->msg[1] = CEC_MSG_RECORD_ON;
  263. msg->msg[2] = CEC_OP_RECORD_SRC_EXT_PLUG;
  264. msg->msg[3] = plug;
  265. }
  266. static inline void cec_msg_record_on_phys_addr(struct cec_msg *msg,
  267. __u16 phys_addr)
  268. {
  269. msg->len = 5;
  270. msg->msg[1] = CEC_MSG_RECORD_ON;
  271. msg->msg[2] = CEC_OP_RECORD_SRC_EXT_PHYS_ADDR;
  272. msg->msg[3] = phys_addr >> 8;
  273. msg->msg[4] = phys_addr & 0xff;
  274. }
  275. static inline void cec_msg_record_on(struct cec_msg *msg,
  276. const struct cec_op_record_src *rec_src)
  277. {
  278. switch (rec_src->type) {
  279. case CEC_OP_RECORD_SRC_OWN:
  280. cec_msg_record_on_own(msg);
  281. break;
  282. case CEC_OP_RECORD_SRC_DIGITAL:
  283. cec_msg_record_on_digital(msg, &rec_src->digital);
  284. break;
  285. case CEC_OP_RECORD_SRC_ANALOG:
  286. cec_msg_record_on_analog(msg,
  287. rec_src->analog.ana_bcast_type,
  288. rec_src->analog.ana_freq,
  289. rec_src->analog.bcast_system);
  290. break;
  291. case CEC_OP_RECORD_SRC_EXT_PLUG:
  292. cec_msg_record_on_plug(msg, rec_src->ext_plug.plug);
  293. break;
  294. case CEC_OP_RECORD_SRC_EXT_PHYS_ADDR:
  295. cec_msg_record_on_phys_addr(msg,
  296. rec_src->ext_phys_addr.phys_addr);
  297. break;
  298. }
  299. }
  300. static inline void cec_ops_record_on(const struct cec_msg *msg,
  301. struct cec_op_record_src *rec_src)
  302. {
  303. rec_src->type = msg->msg[2];
  304. switch (rec_src->type) {
  305. case CEC_OP_RECORD_SRC_OWN:
  306. break;
  307. case CEC_OP_RECORD_SRC_DIGITAL:
  308. cec_get_digital_service_id(msg->msg + 3, &rec_src->digital);
  309. break;
  310. case CEC_OP_RECORD_SRC_ANALOG:
  311. rec_src->analog.ana_bcast_type = msg->msg[3];
  312. rec_src->analog.ana_freq =
  313. (msg->msg[4] << 8) | msg->msg[5];
  314. rec_src->analog.bcast_system = msg->msg[6];
  315. break;
  316. case CEC_OP_RECORD_SRC_EXT_PLUG:
  317. rec_src->ext_plug.plug = msg->msg[3];
  318. break;
  319. case CEC_OP_RECORD_SRC_EXT_PHYS_ADDR:
  320. rec_src->ext_phys_addr.phys_addr =
  321. (msg->msg[3] << 8) | msg->msg[4];
  322. break;
  323. }
  324. }
  325. static inline void cec_msg_record_status(struct cec_msg *msg, __u8 rec_status)
  326. {
  327. msg->len = 3;
  328. msg->msg[1] = CEC_MSG_RECORD_STATUS;
  329. msg->msg[2] = rec_status;
  330. }
  331. static inline void cec_ops_record_status(const struct cec_msg *msg,
  332. __u8 *rec_status)
  333. {
  334. *rec_status = msg->msg[2];
  335. }
  336. static inline void cec_msg_record_tv_screen(struct cec_msg *msg,
  337. bool reply)
  338. {
  339. msg->len = 2;
  340. msg->msg[1] = CEC_MSG_RECORD_TV_SCREEN;
  341. msg->reply = reply ? CEC_MSG_RECORD_ON : 0;
  342. }
  343. /* Timer Programming Feature */
  344. static inline void cec_msg_timer_status(struct cec_msg *msg,
  345. __u8 timer_overlap_warning,
  346. __u8 media_info,
  347. __u8 prog_info,
  348. __u8 prog_error,
  349. __u8 duration_hr,
  350. __u8 duration_min)
  351. {
  352. msg->len = 3;
  353. msg->msg[1] = CEC_MSG_TIMER_STATUS;
  354. msg->msg[2] = (timer_overlap_warning << 7) |
  355. (media_info << 5) |
  356. (prog_info ? 0x10 : 0) |
  357. (prog_info ? prog_info : prog_error);
  358. if (prog_info == CEC_OP_PROG_INFO_NOT_ENOUGH_SPACE ||
  359. prog_info == CEC_OP_PROG_INFO_MIGHT_NOT_BE_ENOUGH_SPACE ||
  360. prog_error == CEC_OP_PROG_ERROR_DUPLICATE) {
  361. msg->len += 2;
  362. msg->msg[3] = ((duration_hr / 10) << 4) | (duration_hr % 10);
  363. msg->msg[4] = ((duration_min / 10) << 4) | (duration_min % 10);
  364. }
  365. }
  366. static inline void cec_ops_timer_status(struct cec_msg *msg,
  367. __u8 *timer_overlap_warning,
  368. __u8 *media_info,
  369. __u8 *prog_info,
  370. __u8 *prog_error,
  371. __u8 *duration_hr,
  372. __u8 *duration_min)
  373. {
  374. *timer_overlap_warning = msg->msg[2] >> 7;
  375. *media_info = (msg->msg[2] >> 5) & 3;
  376. if (msg->msg[2] & 0x10) {
  377. *prog_info = msg->msg[2] & 0xf;
  378. *prog_error = 0;
  379. } else {
  380. *prog_info = 0;
  381. *prog_error = msg->msg[2] & 0xf;
  382. }
  383. if (*prog_info == CEC_OP_PROG_INFO_NOT_ENOUGH_SPACE ||
  384. *prog_info == CEC_OP_PROG_INFO_MIGHT_NOT_BE_ENOUGH_SPACE ||
  385. *prog_error == CEC_OP_PROG_ERROR_DUPLICATE) {
  386. *duration_hr = (msg->msg[3] >> 4) * 10 + (msg->msg[3] & 0xf);
  387. *duration_min = (msg->msg[4] >> 4) * 10 + (msg->msg[4] & 0xf);
  388. } else {
  389. *duration_hr = *duration_min = 0;
  390. }
  391. }
  392. static inline void cec_msg_timer_cleared_status(struct cec_msg *msg,
  393. __u8 timer_cleared_status)
  394. {
  395. msg->len = 3;
  396. msg->msg[1] = CEC_MSG_TIMER_CLEARED_STATUS;
  397. msg->msg[2] = timer_cleared_status;
  398. }
  399. static inline void cec_ops_timer_cleared_status(struct cec_msg *msg,
  400. __u8 *timer_cleared_status)
  401. {
  402. *timer_cleared_status = msg->msg[2];
  403. }
  404. static inline void cec_msg_clear_analogue_timer(struct cec_msg *msg,
  405. bool reply,
  406. __u8 day,
  407. __u8 month,
  408. __u8 start_hr,
  409. __u8 start_min,
  410. __u8 duration_hr,
  411. __u8 duration_min,
  412. __u8 recording_seq,
  413. __u8 ana_bcast_type,
  414. __u16 ana_freq,
  415. __u8 bcast_system)
  416. {
  417. msg->len = 13;
  418. msg->msg[1] = CEC_MSG_CLEAR_ANALOGUE_TIMER;
  419. msg->msg[2] = day;
  420. msg->msg[3] = month;
  421. /* Hours and minutes are in BCD format */
  422. msg->msg[4] = ((start_hr / 10) << 4) | (start_hr % 10);
  423. msg->msg[5] = ((start_min / 10) << 4) | (start_min % 10);
  424. msg->msg[6] = ((duration_hr / 10) << 4) | (duration_hr % 10);
  425. msg->msg[7] = ((duration_min / 10) << 4) | (duration_min % 10);
  426. msg->msg[8] = recording_seq;
  427. msg->msg[9] = ana_bcast_type;
  428. msg->msg[10] = ana_freq >> 8;
  429. msg->msg[11] = ana_freq & 0xff;
  430. msg->msg[12] = bcast_system;
  431. msg->reply = reply ? CEC_MSG_TIMER_CLEARED_STATUS : 0;
  432. }
  433. static inline void cec_ops_clear_analogue_timer(struct cec_msg *msg,
  434. __u8 *day,
  435. __u8 *month,
  436. __u8 *start_hr,
  437. __u8 *start_min,
  438. __u8 *duration_hr,
  439. __u8 *duration_min,
  440. __u8 *recording_seq,
  441. __u8 *ana_bcast_type,
  442. __u16 *ana_freq,
  443. __u8 *bcast_system)
  444. {
  445. *day = msg->msg[2];
  446. *month = msg->msg[3];
  447. /* Hours and minutes are in BCD format */
  448. *start_hr = (msg->msg[4] >> 4) * 10 + (msg->msg[4] & 0xf);
  449. *start_min = (msg->msg[5] >> 4) * 10 + (msg->msg[5] & 0xf);
  450. *duration_hr = (msg->msg[6] >> 4) * 10 + (msg->msg[6] & 0xf);
  451. *duration_min = (msg->msg[7] >> 4) * 10 + (msg->msg[7] & 0xf);
  452. *recording_seq = msg->msg[8];
  453. *ana_bcast_type = msg->msg[9];
  454. *ana_freq = (msg->msg[10] << 8) | msg->msg[11];
  455. *bcast_system = msg->msg[12];
  456. }
  457. static inline void cec_msg_clear_digital_timer(struct cec_msg *msg,
  458. bool reply,
  459. __u8 day,
  460. __u8 month,
  461. __u8 start_hr,
  462. __u8 start_min,
  463. __u8 duration_hr,
  464. __u8 duration_min,
  465. __u8 recording_seq,
  466. const struct cec_op_digital_service_id *digital)
  467. {
  468. msg->len = 16;
  469. msg->reply = reply ? CEC_MSG_TIMER_CLEARED_STATUS : 0;
  470. msg->msg[1] = CEC_MSG_CLEAR_DIGITAL_TIMER;
  471. msg->msg[2] = day;
  472. msg->msg[3] = month;
  473. /* Hours and minutes are in BCD format */
  474. msg->msg[4] = ((start_hr / 10) << 4) | (start_hr % 10);
  475. msg->msg[5] = ((start_min / 10) << 4) | (start_min % 10);
  476. msg->msg[6] = ((duration_hr / 10) << 4) | (duration_hr % 10);
  477. msg->msg[7] = ((duration_min / 10) << 4) | (duration_min % 10);
  478. msg->msg[8] = recording_seq;
  479. cec_set_digital_service_id(msg->msg + 9, digital);
  480. }
  481. static inline void cec_ops_clear_digital_timer(struct cec_msg *msg,
  482. __u8 *day,
  483. __u8 *month,
  484. __u8 *start_hr,
  485. __u8 *start_min,
  486. __u8 *duration_hr,
  487. __u8 *duration_min,
  488. __u8 *recording_seq,
  489. struct cec_op_digital_service_id *digital)
  490. {
  491. *day = msg->msg[2];
  492. *month = msg->msg[3];
  493. /* Hours and minutes are in BCD format */
  494. *start_hr = (msg->msg[4] >> 4) * 10 + (msg->msg[4] & 0xf);
  495. *start_min = (msg->msg[5] >> 4) * 10 + (msg->msg[5] & 0xf);
  496. *duration_hr = (msg->msg[6] >> 4) * 10 + (msg->msg[6] & 0xf);
  497. *duration_min = (msg->msg[7] >> 4) * 10 + (msg->msg[7] & 0xf);
  498. *recording_seq = msg->msg[8];
  499. cec_get_digital_service_id(msg->msg + 9, digital);
  500. }
  501. static inline void cec_msg_clear_ext_timer(struct cec_msg *msg,
  502. bool reply,
  503. __u8 day,
  504. __u8 month,
  505. __u8 start_hr,
  506. __u8 start_min,
  507. __u8 duration_hr,
  508. __u8 duration_min,
  509. __u8 recording_seq,
  510. __u8 ext_src_spec,
  511. __u8 plug,
  512. __u16 phys_addr)
  513. {
  514. msg->len = 13;
  515. msg->msg[1] = CEC_MSG_CLEAR_EXT_TIMER;
  516. msg->msg[2] = day;
  517. msg->msg[3] = month;
  518. /* Hours and minutes are in BCD format */
  519. msg->msg[4] = ((start_hr / 10) << 4) | (start_hr % 10);
  520. msg->msg[5] = ((start_min / 10) << 4) | (start_min % 10);
  521. msg->msg[6] = ((duration_hr / 10) << 4) | (duration_hr % 10);
  522. msg->msg[7] = ((duration_min / 10) << 4) | (duration_min % 10);
  523. msg->msg[8] = recording_seq;
  524. msg->msg[9] = ext_src_spec;
  525. msg->msg[10] = plug;
  526. msg->msg[11] = phys_addr >> 8;
  527. msg->msg[12] = phys_addr & 0xff;
  528. msg->reply = reply ? CEC_MSG_TIMER_CLEARED_STATUS : 0;
  529. }
  530. static inline void cec_ops_clear_ext_timer(struct cec_msg *msg,
  531. __u8 *day,
  532. __u8 *month,
  533. __u8 *start_hr,
  534. __u8 *start_min,
  535. __u8 *duration_hr,
  536. __u8 *duration_min,
  537. __u8 *recording_seq,
  538. __u8 *ext_src_spec,
  539. __u8 *plug,
  540. __u16 *phys_addr)
  541. {
  542. *day = msg->msg[2];
  543. *month = msg->msg[3];
  544. /* Hours and minutes are in BCD format */
  545. *start_hr = (msg->msg[4] >> 4) * 10 + (msg->msg[4] & 0xf);
  546. *start_min = (msg->msg[5] >> 4) * 10 + (msg->msg[5] & 0xf);
  547. *duration_hr = (msg->msg[6] >> 4) * 10 + (msg->msg[6] & 0xf);
  548. *duration_min = (msg->msg[7] >> 4) * 10 + (msg->msg[7] & 0xf);
  549. *recording_seq = msg->msg[8];
  550. *ext_src_spec = msg->msg[9];
  551. *plug = msg->msg[10];
  552. *phys_addr = (msg->msg[11] << 8) | msg->msg[12];
  553. }
  554. static inline void cec_msg_set_analogue_timer(struct cec_msg *msg,
  555. bool reply,
  556. __u8 day,
  557. __u8 month,
  558. __u8 start_hr,
  559. __u8 start_min,
  560. __u8 duration_hr,
  561. __u8 duration_min,
  562. __u8 recording_seq,
  563. __u8 ana_bcast_type,
  564. __u16 ana_freq,
  565. __u8 bcast_system)
  566. {
  567. msg->len = 13;
  568. msg->msg[1] = CEC_MSG_SET_ANALOGUE_TIMER;
  569. msg->msg[2] = day;
  570. msg->msg[3] = month;
  571. /* Hours and minutes are in BCD format */
  572. msg->msg[4] = ((start_hr / 10) << 4) | (start_hr % 10);
  573. msg->msg[5] = ((start_min / 10) << 4) | (start_min % 10);
  574. msg->msg[6] = ((duration_hr / 10) << 4) | (duration_hr % 10);
  575. msg->msg[7] = ((duration_min / 10) << 4) | (duration_min % 10);
  576. msg->msg[8] = recording_seq;
  577. msg->msg[9] = ana_bcast_type;
  578. msg->msg[10] = ana_freq >> 8;
  579. msg->msg[11] = ana_freq & 0xff;
  580. msg->msg[12] = bcast_system;
  581. msg->reply = reply ? CEC_MSG_TIMER_STATUS : 0;
  582. }
  583. static inline void cec_ops_set_analogue_timer(struct cec_msg *msg,
  584. __u8 *day,
  585. __u8 *month,
  586. __u8 *start_hr,
  587. __u8 *start_min,
  588. __u8 *duration_hr,
  589. __u8 *duration_min,
  590. __u8 *recording_seq,
  591. __u8 *ana_bcast_type,
  592. __u16 *ana_freq,
  593. __u8 *bcast_system)
  594. {
  595. *day = msg->msg[2];
  596. *month = msg->msg[3];
  597. /* Hours and minutes are in BCD format */
  598. *start_hr = (msg->msg[4] >> 4) * 10 + (msg->msg[4] & 0xf);
  599. *start_min = (msg->msg[5] >> 4) * 10 + (msg->msg[5] & 0xf);
  600. *duration_hr = (msg->msg[6] >> 4) * 10 + (msg->msg[6] & 0xf);
  601. *duration_min = (msg->msg[7] >> 4) * 10 + (msg->msg[7] & 0xf);
  602. *recording_seq = msg->msg[8];
  603. *ana_bcast_type = msg->msg[9];
  604. *ana_freq = (msg->msg[10] << 8) | msg->msg[11];
  605. *bcast_system = msg->msg[12];
  606. }
  607. static inline void cec_msg_set_digital_timer(struct cec_msg *msg,
  608. bool reply,
  609. __u8 day,
  610. __u8 month,
  611. __u8 start_hr,
  612. __u8 start_min,
  613. __u8 duration_hr,
  614. __u8 duration_min,
  615. __u8 recording_seq,
  616. const struct cec_op_digital_service_id *digital)
  617. {
  618. msg->len = 16;
  619. msg->reply = reply ? CEC_MSG_TIMER_STATUS : 0;
  620. msg->msg[1] = CEC_MSG_SET_DIGITAL_TIMER;
  621. msg->msg[2] = day;
  622. msg->msg[3] = month;
  623. /* Hours and minutes are in BCD format */
  624. msg->msg[4] = ((start_hr / 10) << 4) | (start_hr % 10);
  625. msg->msg[5] = ((start_min / 10) << 4) | (start_min % 10);
  626. msg->msg[6] = ((duration_hr / 10) << 4) | (duration_hr % 10);
  627. msg->msg[7] = ((duration_min / 10) << 4) | (duration_min % 10);
  628. msg->msg[8] = recording_seq;
  629. cec_set_digital_service_id(msg->msg + 9, digital);
  630. }
  631. static inline void cec_ops_set_digital_timer(struct cec_msg *msg,
  632. __u8 *day,
  633. __u8 *month,
  634. __u8 *start_hr,
  635. __u8 *start_min,
  636. __u8 *duration_hr,
  637. __u8 *duration_min,
  638. __u8 *recording_seq,
  639. struct cec_op_digital_service_id *digital)
  640. {
  641. *day = msg->msg[2];
  642. *month = msg->msg[3];
  643. /* Hours and minutes are in BCD format */
  644. *start_hr = (msg->msg[4] >> 4) * 10 + (msg->msg[4] & 0xf);
  645. *start_min = (msg->msg[5] >> 4) * 10 + (msg->msg[5] & 0xf);
  646. *duration_hr = (msg->msg[6] >> 4) * 10 + (msg->msg[6] & 0xf);
  647. *duration_min = (msg->msg[7] >> 4) * 10 + (msg->msg[7] & 0xf);
  648. *recording_seq = msg->msg[8];
  649. cec_get_digital_service_id(msg->msg + 9, digital);
  650. }
  651. static inline void cec_msg_set_ext_timer(struct cec_msg *msg,
  652. bool reply,
  653. __u8 day,
  654. __u8 month,
  655. __u8 start_hr,
  656. __u8 start_min,
  657. __u8 duration_hr,
  658. __u8 duration_min,
  659. __u8 recording_seq,
  660. __u8 ext_src_spec,
  661. __u8 plug,
  662. __u16 phys_addr)
  663. {
  664. msg->len = 13;
  665. msg->msg[1] = CEC_MSG_SET_EXT_TIMER;
  666. msg->msg[2] = day;
  667. msg->msg[3] = month;
  668. /* Hours and minutes are in BCD format */
  669. msg->msg[4] = ((start_hr / 10) << 4) | (start_hr % 10);
  670. msg->msg[5] = ((start_min / 10) << 4) | (start_min % 10);
  671. msg->msg[6] = ((duration_hr / 10) << 4) | (duration_hr % 10);
  672. msg->msg[7] = ((duration_min / 10) << 4) | (duration_min % 10);
  673. msg->msg[8] = recording_seq;
  674. msg->msg[9] = ext_src_spec;
  675. msg->msg[10] = plug;
  676. msg->msg[11] = phys_addr >> 8;
  677. msg->msg[12] = phys_addr & 0xff;
  678. msg->reply = reply ? CEC_MSG_TIMER_STATUS : 0;
  679. }
  680. static inline void cec_ops_set_ext_timer(struct cec_msg *msg,
  681. __u8 *day,
  682. __u8 *month,
  683. __u8 *start_hr,
  684. __u8 *start_min,
  685. __u8 *duration_hr,
  686. __u8 *duration_min,
  687. __u8 *recording_seq,
  688. __u8 *ext_src_spec,
  689. __u8 *plug,
  690. __u16 *phys_addr)
  691. {
  692. *day = msg->msg[2];
  693. *month = msg->msg[3];
  694. /* Hours and minutes are in BCD format */
  695. *start_hr = (msg->msg[4] >> 4) * 10 + (msg->msg[4] & 0xf);
  696. *start_min = (msg->msg[5] >> 4) * 10 + (msg->msg[5] & 0xf);
  697. *duration_hr = (msg->msg[6] >> 4) * 10 + (msg->msg[6] & 0xf);
  698. *duration_min = (msg->msg[7] >> 4) * 10 + (msg->msg[7] & 0xf);
  699. *recording_seq = msg->msg[8];
  700. *ext_src_spec = msg->msg[9];
  701. *plug = msg->msg[10];
  702. *phys_addr = (msg->msg[11] << 8) | msg->msg[12];
  703. }
  704. static inline void cec_msg_set_timer_program_title(struct cec_msg *msg,
  705. const char *prog_title)
  706. {
  707. unsigned int len = strlen(prog_title);
  708. if (len > 14)
  709. len = 14;
  710. msg->len = 2 + len;
  711. msg->msg[1] = CEC_MSG_SET_TIMER_PROGRAM_TITLE;
  712. memcpy(msg->msg + 2, prog_title, len);
  713. }
  714. static inline void cec_ops_set_timer_program_title(const struct cec_msg *msg,
  715. char *prog_title)
  716. {
  717. unsigned int len = msg->len - 2;
  718. if (len > 14)
  719. len = 14;
  720. memcpy(prog_title, msg->msg + 2, len);
  721. prog_title[len] = '\0';
  722. }
  723. /* System Information Feature */
  724. static inline void cec_msg_cec_version(struct cec_msg *msg, __u8 cec_version)
  725. {
  726. msg->len = 3;
  727. msg->msg[1] = CEC_MSG_CEC_VERSION;
  728. msg->msg[2] = cec_version;
  729. }
  730. static inline void cec_ops_cec_version(const struct cec_msg *msg,
  731. __u8 *cec_version)
  732. {
  733. *cec_version = msg->msg[2];
  734. }
  735. static inline void cec_msg_get_cec_version(struct cec_msg *msg,
  736. bool reply)
  737. {
  738. msg->len = 2;
  739. msg->msg[1] = CEC_MSG_GET_CEC_VERSION;
  740. msg->reply = reply ? CEC_MSG_CEC_VERSION : 0;
  741. }
  742. static inline void cec_msg_report_physical_addr(struct cec_msg *msg,
  743. __u16 phys_addr, __u8 prim_devtype)
  744. {
  745. msg->len = 5;
  746. msg->msg[0] |= 0xf; /* broadcast */
  747. msg->msg[1] = CEC_MSG_REPORT_PHYSICAL_ADDR;
  748. msg->msg[2] = phys_addr >> 8;
  749. msg->msg[3] = phys_addr & 0xff;
  750. msg->msg[4] = prim_devtype;
  751. }
  752. static inline void cec_ops_report_physical_addr(const struct cec_msg *msg,
  753. __u16 *phys_addr, __u8 *prim_devtype)
  754. {
  755. *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
  756. *prim_devtype = msg->msg[4];
  757. }
  758. static inline void cec_msg_give_physical_addr(struct cec_msg *msg,
  759. bool reply)
  760. {
  761. msg->len = 2;
  762. msg->msg[1] = CEC_MSG_GIVE_PHYSICAL_ADDR;
  763. msg->reply = reply ? CEC_MSG_REPORT_PHYSICAL_ADDR : 0;
  764. }
  765. static inline void cec_msg_set_menu_language(struct cec_msg *msg,
  766. const char *language)
  767. {
  768. msg->len = 5;
  769. msg->msg[0] |= 0xf; /* broadcast */
  770. msg->msg[1] = CEC_MSG_SET_MENU_LANGUAGE;
  771. memcpy(msg->msg + 2, language, 3);
  772. }
  773. static inline void cec_ops_set_menu_language(struct cec_msg *msg,
  774. char *language)
  775. {
  776. memcpy(language, msg->msg + 2, 3);
  777. language[3] = '\0';
  778. }
  779. static inline void cec_msg_get_menu_language(struct cec_msg *msg,
  780. bool reply)
  781. {
  782. msg->len = 2;
  783. msg->msg[1] = CEC_MSG_GET_MENU_LANGUAGE;
  784. msg->reply = reply ? CEC_MSG_SET_MENU_LANGUAGE : 0;
  785. }
  786. /*
  787. * Assumes a single RC Profile byte and a single Device Features byte,
  788. * i.e. no extended features are supported by this helper function.
  789. *
  790. * As of CEC 2.0 no extended features are defined, should those be added
  791. * in the future, then this function needs to be adapted or a new function
  792. * should be added.
  793. */
  794. static inline void cec_msg_report_features(struct cec_msg *msg,
  795. __u8 cec_version, __u8 all_device_types,
  796. __u8 rc_profile, __u8 dev_features)
  797. {
  798. msg->len = 6;
  799. msg->msg[0] |= 0xf; /* broadcast */
  800. msg->msg[1] = CEC_MSG_REPORT_FEATURES;
  801. msg->msg[2] = cec_version;
  802. msg->msg[3] = all_device_types;
  803. msg->msg[4] = rc_profile;
  804. msg->msg[5] = dev_features;
  805. }
  806. static inline void cec_ops_report_features(const struct cec_msg *msg,
  807. __u8 *cec_version, __u8 *all_device_types,
  808. const __u8 **rc_profile, const __u8 **dev_features)
  809. {
  810. const __u8 *p = &msg->msg[4];
  811. *cec_version = msg->msg[2];
  812. *all_device_types = msg->msg[3];
  813. *rc_profile = p;
  814. while (p < &msg->msg[14] && (*p & CEC_OP_FEAT_EXT))
  815. p++;
  816. if (!(*p & CEC_OP_FEAT_EXT)) {
  817. *dev_features = p + 1;
  818. while (p < &msg->msg[15] && (*p & CEC_OP_FEAT_EXT))
  819. p++;
  820. }
  821. if (*p & CEC_OP_FEAT_EXT)
  822. *rc_profile = *dev_features = NULL;
  823. }
  824. static inline void cec_msg_give_features(struct cec_msg *msg,
  825. bool reply)
  826. {
  827. msg->len = 2;
  828. msg->msg[1] = CEC_MSG_GIVE_FEATURES;
  829. msg->reply = reply ? CEC_MSG_REPORT_FEATURES : 0;
  830. }
  831. /* Deck Control Feature */
  832. static inline void cec_msg_deck_control(struct cec_msg *msg,
  833. __u8 deck_control_mode)
  834. {
  835. msg->len = 3;
  836. msg->msg[1] = CEC_MSG_DECK_CONTROL;
  837. msg->msg[2] = deck_control_mode;
  838. }
  839. static inline void cec_ops_deck_control(struct cec_msg *msg,
  840. __u8 *deck_control_mode)
  841. {
  842. *deck_control_mode = msg->msg[2];
  843. }
  844. static inline void cec_msg_deck_status(struct cec_msg *msg,
  845. __u8 deck_info)
  846. {
  847. msg->len = 3;
  848. msg->msg[1] = CEC_MSG_DECK_STATUS;
  849. msg->msg[2] = deck_info;
  850. }
  851. static inline void cec_ops_deck_status(struct cec_msg *msg,
  852. __u8 *deck_info)
  853. {
  854. *deck_info = msg->msg[2];
  855. }
  856. static inline void cec_msg_give_deck_status(struct cec_msg *msg,
  857. bool reply,
  858. __u8 status_req)
  859. {
  860. msg->len = 3;
  861. msg->msg[1] = CEC_MSG_GIVE_DECK_STATUS;
  862. msg->msg[2] = status_req;
  863. msg->reply = reply ? CEC_MSG_DECK_STATUS : 0;
  864. }
  865. static inline void cec_ops_give_deck_status(struct cec_msg *msg,
  866. __u8 *status_req)
  867. {
  868. *status_req = msg->msg[2];
  869. }
  870. static inline void cec_msg_play(struct cec_msg *msg,
  871. __u8 play_mode)
  872. {
  873. msg->len = 3;
  874. msg->msg[1] = CEC_MSG_PLAY;
  875. msg->msg[2] = play_mode;
  876. }
  877. static inline void cec_ops_play(struct cec_msg *msg,
  878. __u8 *play_mode)
  879. {
  880. *play_mode = msg->msg[2];
  881. }
  882. /* Tuner Control Feature */
  883. struct cec_op_tuner_device_info {
  884. __u8 rec_flag;
  885. __u8 tuner_display_info;
  886. bool is_analog;
  887. union {
  888. struct cec_op_digital_service_id digital;
  889. struct {
  890. __u8 ana_bcast_type;
  891. __u16 ana_freq;
  892. __u8 bcast_system;
  893. } analog;
  894. };
  895. };
  896. static inline void cec_msg_tuner_device_status_analog(struct cec_msg *msg,
  897. __u8 rec_flag,
  898. __u8 tuner_display_info,
  899. __u8 ana_bcast_type,
  900. __u16 ana_freq,
  901. __u8 bcast_system)
  902. {
  903. msg->len = 7;
  904. msg->msg[1] = CEC_MSG_TUNER_DEVICE_STATUS;
  905. msg->msg[2] = (rec_flag << 7) | tuner_display_info;
  906. msg->msg[3] = ana_bcast_type;
  907. msg->msg[4] = ana_freq >> 8;
  908. msg->msg[5] = ana_freq & 0xff;
  909. msg->msg[6] = bcast_system;
  910. }
  911. static inline void cec_msg_tuner_device_status_digital(struct cec_msg *msg,
  912. __u8 rec_flag, __u8 tuner_display_info,
  913. const struct cec_op_digital_service_id *digital)
  914. {
  915. msg->len = 10;
  916. msg->msg[1] = CEC_MSG_TUNER_DEVICE_STATUS;
  917. msg->msg[2] = (rec_flag << 7) | tuner_display_info;
  918. cec_set_digital_service_id(msg->msg + 3, digital);
  919. }
  920. static inline void cec_msg_tuner_device_status(struct cec_msg *msg,
  921. const struct cec_op_tuner_device_info *tuner_dev_info)
  922. {
  923. if (tuner_dev_info->is_analog)
  924. cec_msg_tuner_device_status_analog(msg,
  925. tuner_dev_info->rec_flag,
  926. tuner_dev_info->tuner_display_info,
  927. tuner_dev_info->analog.ana_bcast_type,
  928. tuner_dev_info->analog.ana_freq,
  929. tuner_dev_info->analog.bcast_system);
  930. else
  931. cec_msg_tuner_device_status_digital(msg,
  932. tuner_dev_info->rec_flag,
  933. tuner_dev_info->tuner_display_info,
  934. &tuner_dev_info->digital);
  935. }
  936. static inline void cec_ops_tuner_device_status(struct cec_msg *msg,
  937. struct cec_op_tuner_device_info *tuner_dev_info)
  938. {
  939. tuner_dev_info->is_analog = msg->len < 10;
  940. tuner_dev_info->rec_flag = msg->msg[2] >> 7;
  941. tuner_dev_info->tuner_display_info = msg->msg[2] & 0x7f;
  942. if (tuner_dev_info->is_analog) {
  943. tuner_dev_info->analog.ana_bcast_type = msg->msg[3];
  944. tuner_dev_info->analog.ana_freq = (msg->msg[4] << 8) | msg->msg[5];
  945. tuner_dev_info->analog.bcast_system = msg->msg[6];
  946. return;
  947. }
  948. cec_get_digital_service_id(msg->msg + 3, &tuner_dev_info->digital);
  949. }
  950. static inline void cec_msg_give_tuner_device_status(struct cec_msg *msg,
  951. bool reply,
  952. __u8 status_req)
  953. {
  954. msg->len = 3;
  955. msg->msg[1] = CEC_MSG_GIVE_TUNER_DEVICE_STATUS;
  956. msg->msg[2] = status_req;
  957. msg->reply = reply ? CEC_MSG_TUNER_DEVICE_STATUS : 0;
  958. }
  959. static inline void cec_ops_give_tuner_device_status(struct cec_msg *msg,
  960. __u8 *status_req)
  961. {
  962. *status_req = msg->msg[2];
  963. }
  964. static inline void cec_msg_select_analogue_service(struct cec_msg *msg,
  965. __u8 ana_bcast_type,
  966. __u16 ana_freq,
  967. __u8 bcast_system)
  968. {
  969. msg->len = 6;
  970. msg->msg[1] = CEC_MSG_SELECT_ANALOGUE_SERVICE;
  971. msg->msg[2] = ana_bcast_type;
  972. msg->msg[3] = ana_freq >> 8;
  973. msg->msg[4] = ana_freq & 0xff;
  974. msg->msg[5] = bcast_system;
  975. }
  976. static inline void cec_ops_select_analogue_service(struct cec_msg *msg,
  977. __u8 *ana_bcast_type,
  978. __u16 *ana_freq,
  979. __u8 *bcast_system)
  980. {
  981. *ana_bcast_type = msg->msg[2];
  982. *ana_freq = (msg->msg[3] << 8) | msg->msg[4];
  983. *bcast_system = msg->msg[5];
  984. }
  985. static inline void cec_msg_select_digital_service(struct cec_msg *msg,
  986. const struct cec_op_digital_service_id *digital)
  987. {
  988. msg->len = 9;
  989. msg->msg[1] = CEC_MSG_SELECT_DIGITAL_SERVICE;
  990. cec_set_digital_service_id(msg->msg + 2, digital);
  991. }
  992. static inline void cec_ops_select_digital_service(struct cec_msg *msg,
  993. struct cec_op_digital_service_id *digital)
  994. {
  995. cec_get_digital_service_id(msg->msg + 2, digital);
  996. }
  997. static inline void cec_msg_tuner_step_decrement(struct cec_msg *msg)
  998. {
  999. msg->len = 2;
  1000. msg->msg[1] = CEC_MSG_TUNER_STEP_DECREMENT;
  1001. }
  1002. static inline void cec_msg_tuner_step_increment(struct cec_msg *msg)
  1003. {
  1004. msg->len = 2;
  1005. msg->msg[1] = CEC_MSG_TUNER_STEP_INCREMENT;
  1006. }
  1007. /* Vendor Specific Commands Feature */
  1008. static inline void cec_msg_device_vendor_id(struct cec_msg *msg, __u32 vendor_id)
  1009. {
  1010. msg->len = 5;
  1011. msg->msg[0] |= 0xf; /* broadcast */
  1012. msg->msg[1] = CEC_MSG_DEVICE_VENDOR_ID;
  1013. msg->msg[2] = vendor_id >> 16;
  1014. msg->msg[3] = (vendor_id >> 8) & 0xff;
  1015. msg->msg[4] = vendor_id & 0xff;
  1016. }
  1017. static inline void cec_ops_device_vendor_id(const struct cec_msg *msg,
  1018. __u32 *vendor_id)
  1019. {
  1020. *vendor_id = (msg->msg[2] << 16) | (msg->msg[3] << 8) | msg->msg[4];
  1021. }
  1022. static inline void cec_msg_give_device_vendor_id(struct cec_msg *msg,
  1023. bool reply)
  1024. {
  1025. msg->len = 2;
  1026. msg->msg[1] = CEC_MSG_GIVE_DEVICE_VENDOR_ID;
  1027. msg->reply = reply ? CEC_MSG_DEVICE_VENDOR_ID : 0;
  1028. }
  1029. static inline void cec_msg_vendor_remote_button_up(struct cec_msg *msg)
  1030. {
  1031. msg->len = 2;
  1032. msg->msg[1] = CEC_MSG_VENDOR_REMOTE_BUTTON_UP;
  1033. }
  1034. /* OSD Display Feature */
  1035. static inline void cec_msg_set_osd_string(struct cec_msg *msg,
  1036. __u8 disp_ctl,
  1037. const char *osd)
  1038. {
  1039. unsigned int len = strlen(osd);
  1040. if (len > 13)
  1041. len = 13;
  1042. msg->len = 3 + len;
  1043. msg->msg[1] = CEC_MSG_SET_OSD_STRING;
  1044. msg->msg[2] = disp_ctl;
  1045. memcpy(msg->msg + 3, osd, len);
  1046. }
  1047. static inline void cec_ops_set_osd_string(const struct cec_msg *msg,
  1048. __u8 *disp_ctl,
  1049. char *osd)
  1050. {
  1051. unsigned int len = msg->len - 3;
  1052. *disp_ctl = msg->msg[2];
  1053. if (len > 13)
  1054. len = 13;
  1055. memcpy(osd, msg->msg + 3, len);
  1056. osd[len] = '\0';
  1057. }
  1058. /* Device OSD Transfer Feature */
  1059. static inline void cec_msg_set_osd_name(struct cec_msg *msg, const char *name)
  1060. {
  1061. unsigned int len = strlen(name);
  1062. if (len > 14)
  1063. len = 14;
  1064. msg->len = 2 + len;
  1065. msg->msg[1] = CEC_MSG_SET_OSD_NAME;
  1066. memcpy(msg->msg + 2, name, len);
  1067. }
  1068. static inline void cec_ops_set_osd_name(const struct cec_msg *msg,
  1069. char *name)
  1070. {
  1071. unsigned int len = msg->len - 2;
  1072. if (len > 14)
  1073. len = 14;
  1074. memcpy(name, msg->msg + 2, len);
  1075. name[len] = '\0';
  1076. }
  1077. static inline void cec_msg_give_osd_name(struct cec_msg *msg,
  1078. bool reply)
  1079. {
  1080. msg->len = 2;
  1081. msg->msg[1] = CEC_MSG_GIVE_OSD_NAME;
  1082. msg->reply = reply ? CEC_MSG_SET_OSD_NAME : 0;
  1083. }
  1084. /* Device Menu Control Feature */
  1085. static inline void cec_msg_menu_status(struct cec_msg *msg,
  1086. __u8 menu_state)
  1087. {
  1088. msg->len = 3;
  1089. msg->msg[1] = CEC_MSG_MENU_STATUS;
  1090. msg->msg[2] = menu_state;
  1091. }
  1092. static inline void cec_ops_menu_status(struct cec_msg *msg,
  1093. __u8 *menu_state)
  1094. {
  1095. *menu_state = msg->msg[2];
  1096. }
  1097. static inline void cec_msg_menu_request(struct cec_msg *msg,
  1098. bool reply,
  1099. __u8 menu_req)
  1100. {
  1101. msg->len = 3;
  1102. msg->msg[1] = CEC_MSG_MENU_REQUEST;
  1103. msg->msg[2] = menu_req;
  1104. msg->reply = reply ? CEC_MSG_MENU_STATUS : 0;
  1105. }
  1106. static inline void cec_ops_menu_request(struct cec_msg *msg,
  1107. __u8 *menu_req)
  1108. {
  1109. *menu_req = msg->msg[2];
  1110. }
  1111. struct cec_op_ui_command {
  1112. __u8 ui_cmd;
  1113. bool has_opt_arg;
  1114. union {
  1115. struct cec_op_channel_data channel_identifier;
  1116. __u8 ui_broadcast_type;
  1117. __u8 ui_sound_presentation_control;
  1118. __u8 play_mode;
  1119. __u8 ui_function_media;
  1120. __u8 ui_function_select_av_input;
  1121. __u8 ui_function_select_audio_input;
  1122. };
  1123. };
  1124. static inline void cec_msg_user_control_pressed(struct cec_msg *msg,
  1125. const struct cec_op_ui_command *ui_cmd)
  1126. {
  1127. msg->len = 3;
  1128. msg->msg[1] = CEC_MSG_USER_CONTROL_PRESSED;
  1129. msg->msg[2] = ui_cmd->ui_cmd;
  1130. if (!ui_cmd->has_opt_arg)
  1131. return;
  1132. switch (ui_cmd->ui_cmd) {
  1133. case 0x56:
  1134. case 0x57:
  1135. case 0x60:
  1136. case 0x68:
  1137. case 0x69:
  1138. case 0x6a:
  1139. /* The optional operand is one byte for all these ui commands */
  1140. msg->len++;
  1141. msg->msg[3] = ui_cmd->play_mode;
  1142. break;
  1143. case 0x67:
  1144. msg->len += 4;
  1145. msg->msg[3] = (ui_cmd->channel_identifier.channel_number_fmt << 2) |
  1146. (ui_cmd->channel_identifier.major >> 8);
  1147. msg->msg[4] = ui_cmd->channel_identifier.major && 0xff;
  1148. msg->msg[5] = ui_cmd->channel_identifier.minor >> 8;
  1149. msg->msg[6] = ui_cmd->channel_identifier.minor & 0xff;
  1150. break;
  1151. }
  1152. }
  1153. static inline void cec_ops_user_control_pressed(struct cec_msg *msg,
  1154. struct cec_op_ui_command *ui_cmd)
  1155. {
  1156. ui_cmd->ui_cmd = msg->msg[2];
  1157. ui_cmd->has_opt_arg = false;
  1158. if (msg->len == 3)
  1159. return;
  1160. switch (ui_cmd->ui_cmd) {
  1161. case 0x56:
  1162. case 0x57:
  1163. case 0x60:
  1164. case 0x68:
  1165. case 0x69:
  1166. case 0x6a:
  1167. /* The optional operand is one byte for all these ui commands */
  1168. ui_cmd->play_mode = msg->msg[3];
  1169. ui_cmd->has_opt_arg = true;
  1170. break;
  1171. case 0x67:
  1172. if (msg->len < 7)
  1173. break;
  1174. ui_cmd->has_opt_arg = true;
  1175. ui_cmd->channel_identifier.channel_number_fmt = msg->msg[3] >> 2;
  1176. ui_cmd->channel_identifier.major = ((msg->msg[3] & 3) << 6) | msg->msg[4];
  1177. ui_cmd->channel_identifier.minor = (msg->msg[5] << 8) | msg->msg[6];
  1178. break;
  1179. }
  1180. }
  1181. static inline void cec_msg_user_control_released(struct cec_msg *msg)
  1182. {
  1183. msg->len = 2;
  1184. msg->msg[1] = CEC_MSG_USER_CONTROL_RELEASED;
  1185. }
  1186. /* Remote Control Passthrough Feature */
  1187. /* Power Status Feature */
  1188. static inline void cec_msg_report_power_status(struct cec_msg *msg,
  1189. __u8 pwr_state)
  1190. {
  1191. msg->len = 3;
  1192. msg->msg[1] = CEC_MSG_REPORT_POWER_STATUS;
  1193. msg->msg[2] = pwr_state;
  1194. }
  1195. static inline void cec_ops_report_power_status(const struct cec_msg *msg,
  1196. __u8 *pwr_state)
  1197. {
  1198. *pwr_state = msg->msg[2];
  1199. }
  1200. static inline void cec_msg_give_device_power_status(struct cec_msg *msg,
  1201. bool reply)
  1202. {
  1203. msg->len = 2;
  1204. msg->msg[1] = CEC_MSG_GIVE_DEVICE_POWER_STATUS;
  1205. msg->reply = reply ? CEC_MSG_REPORT_POWER_STATUS : 0;
  1206. }
  1207. /* General Protocol Messages */
  1208. static inline void cec_msg_feature_abort(struct cec_msg *msg,
  1209. __u8 abort_msg, __u8 reason)
  1210. {
  1211. msg->len = 4;
  1212. msg->msg[1] = CEC_MSG_FEATURE_ABORT;
  1213. msg->msg[2] = abort_msg;
  1214. msg->msg[3] = reason;
  1215. }
  1216. static inline void cec_ops_feature_abort(const struct cec_msg *msg,
  1217. __u8 *abort_msg, __u8 *reason)
  1218. {
  1219. *abort_msg = msg->msg[2];
  1220. *reason = msg->msg[3];
  1221. }
  1222. /* This changes the current message into a feature abort message */
  1223. static inline void cec_msg_reply_feature_abort(struct cec_msg *msg, __u8 reason)
  1224. {
  1225. cec_msg_set_reply_to(msg, msg);
  1226. msg->len = 4;
  1227. msg->msg[2] = msg->msg[1];
  1228. msg->msg[3] = reason;
  1229. msg->msg[1] = CEC_MSG_FEATURE_ABORT;
  1230. }
  1231. static inline void cec_msg_abort(struct cec_msg *msg)
  1232. {
  1233. msg->len = 2;
  1234. msg->msg[1] = CEC_MSG_ABORT;
  1235. }
  1236. /* System Audio Control Feature */
  1237. static inline void cec_msg_report_audio_status(struct cec_msg *msg,
  1238. __u8 aud_mute_status,
  1239. __u8 aud_vol_status)
  1240. {
  1241. msg->len = 3;
  1242. msg->msg[1] = CEC_MSG_REPORT_AUDIO_STATUS;
  1243. msg->msg[2] = (aud_mute_status << 7) | (aud_vol_status & 0x7f);
  1244. }
  1245. static inline void cec_ops_report_audio_status(const struct cec_msg *msg,
  1246. __u8 *aud_mute_status,
  1247. __u8 *aud_vol_status)
  1248. {
  1249. *aud_mute_status = msg->msg[2] >> 7;
  1250. *aud_vol_status = msg->msg[2] & 0x7f;
  1251. }
  1252. static inline void cec_msg_give_audio_status(struct cec_msg *msg,
  1253. bool reply)
  1254. {
  1255. msg->len = 2;
  1256. msg->msg[1] = CEC_MSG_GIVE_AUDIO_STATUS;
  1257. msg->reply = reply ? CEC_MSG_REPORT_AUDIO_STATUS : 0;
  1258. }
  1259. static inline void cec_msg_set_system_audio_mode(struct cec_msg *msg,
  1260. __u8 sys_aud_status)
  1261. {
  1262. msg->len = 3;
  1263. msg->msg[1] = CEC_MSG_SET_SYSTEM_AUDIO_MODE;
  1264. msg->msg[2] = sys_aud_status;
  1265. }
  1266. static inline void cec_ops_set_system_audio_mode(const struct cec_msg *msg,
  1267. __u8 *sys_aud_status)
  1268. {
  1269. *sys_aud_status = msg->msg[2];
  1270. }
  1271. static inline void cec_msg_system_audio_mode_request(struct cec_msg *msg,
  1272. bool reply,
  1273. __u16 phys_addr)
  1274. {
  1275. msg->len = phys_addr == 0xffff ? 2 : 4;
  1276. msg->msg[1] = CEC_MSG_SYSTEM_AUDIO_MODE_REQUEST;
  1277. msg->msg[2] = phys_addr >> 8;
  1278. msg->msg[3] = phys_addr & 0xff;
  1279. msg->reply = reply ? CEC_MSG_SET_SYSTEM_AUDIO_MODE : 0;
  1280. }
  1281. static inline void cec_ops_system_audio_mode_request(const struct cec_msg *msg,
  1282. __u16 *phys_addr)
  1283. {
  1284. if (msg->len < 4)
  1285. *phys_addr = 0xffff;
  1286. else
  1287. *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
  1288. }
  1289. static inline void cec_msg_system_audio_mode_status(struct cec_msg *msg,
  1290. __u8 sys_aud_status)
  1291. {
  1292. msg->len = 3;
  1293. msg->msg[1] = CEC_MSG_SYSTEM_AUDIO_MODE_STATUS;
  1294. msg->msg[2] = sys_aud_status;
  1295. }
  1296. static inline void cec_ops_system_audio_mode_status(const struct cec_msg *msg,
  1297. __u8 *sys_aud_status)
  1298. {
  1299. *sys_aud_status = msg->msg[2];
  1300. }
  1301. static inline void cec_msg_give_system_audio_mode_status(struct cec_msg *msg,
  1302. bool reply)
  1303. {
  1304. msg->len = 2;
  1305. msg->msg[1] = CEC_MSG_GIVE_SYSTEM_AUDIO_MODE_STATUS;
  1306. msg->reply = reply ? CEC_MSG_SYSTEM_AUDIO_MODE_STATUS : 0;
  1307. }
  1308. static inline void cec_msg_report_short_audio_descriptor(struct cec_msg *msg,
  1309. __u8 num_descriptors,
  1310. const __u32 *descriptors)
  1311. {
  1312. unsigned int i;
  1313. if (num_descriptors > 4)
  1314. num_descriptors = 4;
  1315. msg->len = 2 + num_descriptors * 3;
  1316. msg->msg[1] = CEC_MSG_REPORT_SHORT_AUDIO_DESCRIPTOR;
  1317. for (i = 0; i < num_descriptors; i++) {
  1318. msg->msg[2 + i * 3] = (descriptors[i] >> 16) & 0xff;
  1319. msg->msg[3 + i * 3] = (descriptors[i] >> 8) & 0xff;
  1320. msg->msg[4 + i * 3] = descriptors[i] & 0xff;
  1321. }
  1322. }
  1323. static inline void cec_ops_report_short_audio_descriptor(const struct cec_msg *msg,
  1324. __u8 *num_descriptors,
  1325. __u32 *descriptors)
  1326. {
  1327. unsigned int i;
  1328. *num_descriptors = (msg->len - 2) / 3;
  1329. if (*num_descriptors > 4)
  1330. *num_descriptors = 4;
  1331. for (i = 0; i < *num_descriptors; i++)
  1332. descriptors[i] = (msg->msg[2 + i * 3] << 16) |
  1333. (msg->msg[3 + i * 3] << 8) |
  1334. msg->msg[4 + i * 3];
  1335. }
  1336. static inline void cec_msg_request_short_audio_descriptor(struct cec_msg *msg,
  1337. __u8 num_descriptors,
  1338. const __u8 *audio_format_id,
  1339. const __u8 *audio_format_code)
  1340. {
  1341. unsigned int i;
  1342. if (num_descriptors > 4)
  1343. num_descriptors = 4;
  1344. msg->len = 2 + num_descriptors;
  1345. msg->msg[1] = CEC_MSG_REQUEST_SHORT_AUDIO_DESCRIPTOR;
  1346. for (i = 0; i < num_descriptors; i++)
  1347. msg->msg[2 + i] = (audio_format_id[i] << 6) |
  1348. (audio_format_code[i] & 0x3f);
  1349. }
  1350. static inline void cec_ops_request_short_audio_descriptor(const struct cec_msg *msg,
  1351. __u8 *num_descriptors,
  1352. __u8 *audio_format_id,
  1353. __u8 *audio_format_code)
  1354. {
  1355. unsigned int i;
  1356. *num_descriptors = msg->len - 2;
  1357. if (*num_descriptors > 4)
  1358. *num_descriptors = 4;
  1359. for (i = 0; i < *num_descriptors; i++) {
  1360. audio_format_id[i] = msg->msg[2 + i] >> 6;
  1361. audio_format_code[i] = msg->msg[2 + i] & 0x3f;
  1362. }
  1363. }
  1364. /* Audio Rate Control Feature */
  1365. static inline void cec_msg_set_audio_rate(struct cec_msg *msg,
  1366. __u8 audio_rate)
  1367. {
  1368. msg->len = 3;
  1369. msg->msg[1] = CEC_MSG_SET_AUDIO_RATE;
  1370. msg->msg[2] = audio_rate;
  1371. }
  1372. static inline void cec_ops_set_audio_rate(const struct cec_msg *msg,
  1373. __u8 *audio_rate)
  1374. {
  1375. *audio_rate = msg->msg[2];
  1376. }
  1377. /* Audio Return Channel Control Feature */
  1378. static inline void cec_msg_report_arc_initiated(struct cec_msg *msg)
  1379. {
  1380. msg->len = 2;
  1381. msg->msg[1] = CEC_MSG_REPORT_ARC_INITIATED;
  1382. }
  1383. static inline void cec_msg_initiate_arc(struct cec_msg *msg,
  1384. bool reply)
  1385. {
  1386. msg->len = 2;
  1387. msg->msg[1] = CEC_MSG_INITIATE_ARC;
  1388. msg->reply = reply ? CEC_MSG_REPORT_ARC_INITIATED : 0;
  1389. }
  1390. static inline void cec_msg_request_arc_initiation(struct cec_msg *msg,
  1391. bool reply)
  1392. {
  1393. msg->len = 2;
  1394. msg->msg[1] = CEC_MSG_REQUEST_ARC_INITIATION;
  1395. msg->reply = reply ? CEC_MSG_INITIATE_ARC : 0;
  1396. }
  1397. static inline void cec_msg_report_arc_terminated(struct cec_msg *msg)
  1398. {
  1399. msg->len = 2;
  1400. msg->msg[1] = CEC_MSG_REPORT_ARC_TERMINATED;
  1401. }
  1402. static inline void cec_msg_terminate_arc(struct cec_msg *msg,
  1403. bool reply)
  1404. {
  1405. msg->len = 2;
  1406. msg->msg[1] = CEC_MSG_TERMINATE_ARC;
  1407. msg->reply = reply ? CEC_MSG_REPORT_ARC_TERMINATED : 0;
  1408. }
  1409. static inline void cec_msg_request_arc_termination(struct cec_msg *msg,
  1410. bool reply)
  1411. {
  1412. msg->len = 2;
  1413. msg->msg[1] = CEC_MSG_REQUEST_ARC_TERMINATION;
  1414. msg->reply = reply ? CEC_MSG_TERMINATE_ARC : 0;
  1415. }
  1416. /* Dynamic Audio Lipsync Feature */
  1417. /* Only for CEC 2.0 and up */
  1418. static inline void cec_msg_report_current_latency(struct cec_msg *msg,
  1419. __u16 phys_addr,
  1420. __u8 video_latency,
  1421. __u8 low_latency_mode,
  1422. __u8 audio_out_compensated,
  1423. __u8 audio_out_delay)
  1424. {
  1425. msg->len = 7;
  1426. msg->msg[0] |= 0xf; /* broadcast */
  1427. msg->msg[1] = CEC_MSG_REPORT_CURRENT_LATENCY;
  1428. msg->msg[2] = phys_addr >> 8;
  1429. msg->msg[3] = phys_addr & 0xff;
  1430. msg->msg[4] = video_latency;
  1431. msg->msg[5] = (low_latency_mode << 2) | audio_out_compensated;
  1432. msg->msg[6] = audio_out_delay;
  1433. }
  1434. static inline void cec_ops_report_current_latency(const struct cec_msg *msg,
  1435. __u16 *phys_addr,
  1436. __u8 *video_latency,
  1437. __u8 *low_latency_mode,
  1438. __u8 *audio_out_compensated,
  1439. __u8 *audio_out_delay)
  1440. {
  1441. *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
  1442. *video_latency = msg->msg[4];
  1443. *low_latency_mode = (msg->msg[5] >> 2) & 1;
  1444. *audio_out_compensated = msg->msg[5] & 3;
  1445. *audio_out_delay = msg->msg[6];
  1446. }
  1447. static inline void cec_msg_request_current_latency(struct cec_msg *msg,
  1448. bool reply,
  1449. __u16 phys_addr)
  1450. {
  1451. msg->len = 4;
  1452. msg->msg[0] |= 0xf; /* broadcast */
  1453. msg->msg[1] = CEC_MSG_REQUEST_CURRENT_LATENCY;
  1454. msg->msg[2] = phys_addr >> 8;
  1455. msg->msg[3] = phys_addr & 0xff;
  1456. msg->reply = reply ? CEC_MSG_REPORT_CURRENT_LATENCY : 0;
  1457. }
  1458. static inline void cec_ops_request_current_latency(const struct cec_msg *msg,
  1459. __u16 *phys_addr)
  1460. {
  1461. *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
  1462. }
  1463. /* Capability Discovery and Control Feature */
  1464. static inline void cec_msg_cdc_hec_inquire_state(struct cec_msg *msg,
  1465. __u16 phys_addr1,
  1466. __u16 phys_addr2)
  1467. {
  1468. msg->len = 9;
  1469. msg->msg[0] |= 0xf; /* broadcast */
  1470. msg->msg[1] = CEC_MSG_CDC_MESSAGE;
  1471. /* msg[2] and msg[3] (phys_addr) are filled in by the CEC framework */
  1472. msg->msg[4] = CEC_MSG_CDC_HEC_INQUIRE_STATE;
  1473. msg->msg[5] = phys_addr1 >> 8;
  1474. msg->msg[6] = phys_addr1 & 0xff;
  1475. msg->msg[7] = phys_addr2 >> 8;
  1476. msg->msg[8] = phys_addr2 & 0xff;
  1477. }
  1478. static inline void cec_ops_cdc_hec_inquire_state(const struct cec_msg *msg,
  1479. __u16 *phys_addr,
  1480. __u16 *phys_addr1,
  1481. __u16 *phys_addr2)
  1482. {
  1483. *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
  1484. *phys_addr1 = (msg->msg[5] << 8) | msg->msg[6];
  1485. *phys_addr2 = (msg->msg[7] << 8) | msg->msg[8];
  1486. }
  1487. static inline void cec_msg_cdc_hec_report_state(struct cec_msg *msg,
  1488. __u16 target_phys_addr,
  1489. __u8 hec_func_state,
  1490. __u8 host_func_state,
  1491. __u8 enc_func_state,
  1492. __u8 cdc_errcode,
  1493. __u8 has_field,
  1494. __u16 hec_field)
  1495. {
  1496. msg->len = has_field ? 10 : 8;
  1497. msg->msg[0] |= 0xf; /* broadcast */
  1498. msg->msg[1] = CEC_MSG_CDC_MESSAGE;
  1499. /* msg[2] and msg[3] (phys_addr) are filled in by the CEC framework */
  1500. msg->msg[4] = CEC_MSG_CDC_HEC_REPORT_STATE;
  1501. msg->msg[5] = target_phys_addr >> 8;
  1502. msg->msg[6] = target_phys_addr & 0xff;
  1503. msg->msg[7] = (hec_func_state << 6) |
  1504. (host_func_state << 4) |
  1505. (enc_func_state << 2) |
  1506. cdc_errcode;
  1507. if (has_field) {
  1508. msg->msg[8] = hec_field >> 8;
  1509. msg->msg[9] = hec_field & 0xff;
  1510. }
  1511. }
  1512. static inline void cec_ops_cdc_hec_report_state(const struct cec_msg *msg,
  1513. __u16 *phys_addr,
  1514. __u16 *target_phys_addr,
  1515. __u8 *hec_func_state,
  1516. __u8 *host_func_state,
  1517. __u8 *enc_func_state,
  1518. __u8 *cdc_errcode,
  1519. __u8 *has_field,
  1520. __u16 *hec_field)
  1521. {
  1522. *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
  1523. *target_phys_addr = (msg->msg[5] << 8) | msg->msg[6];
  1524. *hec_func_state = msg->msg[7] >> 6;
  1525. *host_func_state = (msg->msg[7] >> 4) & 3;
  1526. *enc_func_state = (msg->msg[7] >> 4) & 3;
  1527. *cdc_errcode = msg->msg[7] & 3;
  1528. *has_field = msg->len >= 10;
  1529. *hec_field = *has_field ? ((msg->msg[8] << 8) | msg->msg[9]) : 0;
  1530. }
  1531. static inline void cec_msg_cdc_hec_set_state(struct cec_msg *msg,
  1532. __u16 phys_addr1,
  1533. __u16 phys_addr2,
  1534. __u8 hec_set_state,
  1535. __u16 phys_addr3,
  1536. __u16 phys_addr4,
  1537. __u16 phys_addr5)
  1538. {
  1539. msg->len = 10;
  1540. msg->msg[0] |= 0xf; /* broadcast */
  1541. msg->msg[1] = CEC_MSG_CDC_MESSAGE;
  1542. /* msg[2] and msg[3] (phys_addr) are filled in by the CEC framework */
  1543. msg->msg[4] = CEC_MSG_CDC_HEC_INQUIRE_STATE;
  1544. msg->msg[5] = phys_addr1 >> 8;
  1545. msg->msg[6] = phys_addr1 & 0xff;
  1546. msg->msg[7] = phys_addr2 >> 8;
  1547. msg->msg[8] = phys_addr2 & 0xff;
  1548. msg->msg[9] = hec_set_state;
  1549. if (phys_addr3 != CEC_PHYS_ADDR_INVALID) {
  1550. msg->msg[msg->len++] = phys_addr3 >> 8;
  1551. msg->msg[msg->len++] = phys_addr3 & 0xff;
  1552. if (phys_addr4 != CEC_PHYS_ADDR_INVALID) {
  1553. msg->msg[msg->len++] = phys_addr4 >> 8;
  1554. msg->msg[msg->len++] = phys_addr4 & 0xff;
  1555. if (phys_addr5 != CEC_PHYS_ADDR_INVALID) {
  1556. msg->msg[msg->len++] = phys_addr5 >> 8;
  1557. msg->msg[msg->len++] = phys_addr5 & 0xff;
  1558. }
  1559. }
  1560. }
  1561. }
  1562. static inline void cec_ops_cdc_hec_set_state(const struct cec_msg *msg,
  1563. __u16 *phys_addr,
  1564. __u16 *phys_addr1,
  1565. __u16 *phys_addr2,
  1566. __u8 *hec_set_state,
  1567. __u16 *phys_addr3,
  1568. __u16 *phys_addr4,
  1569. __u16 *phys_addr5)
  1570. {
  1571. *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
  1572. *phys_addr1 = (msg->msg[5] << 8) | msg->msg[6];
  1573. *phys_addr2 = (msg->msg[7] << 8) | msg->msg[8];
  1574. *hec_set_state = msg->msg[9];
  1575. *phys_addr3 = *phys_addr4 = *phys_addr5 = CEC_PHYS_ADDR_INVALID;
  1576. if (msg->len >= 12)
  1577. *phys_addr3 = (msg->msg[10] << 8) | msg->msg[11];
  1578. if (msg->len >= 14)
  1579. *phys_addr4 = (msg->msg[12] << 8) | msg->msg[13];
  1580. if (msg->len >= 16)
  1581. *phys_addr5 = (msg->msg[14] << 8) | msg->msg[15];
  1582. }
  1583. static inline void cec_msg_cdc_hec_set_state_adjacent(struct cec_msg *msg,
  1584. __u16 phys_addr1,
  1585. __u8 hec_set_state)
  1586. {
  1587. msg->len = 8;
  1588. msg->msg[0] |= 0xf; /* broadcast */
  1589. msg->msg[1] = CEC_MSG_CDC_MESSAGE;
  1590. /* msg[2] and msg[3] (phys_addr) are filled in by the CEC framework */
  1591. msg->msg[4] = CEC_MSG_CDC_HEC_SET_STATE_ADJACENT;
  1592. msg->msg[5] = phys_addr1 >> 8;
  1593. msg->msg[6] = phys_addr1 & 0xff;
  1594. msg->msg[7] = hec_set_state;
  1595. }
  1596. static inline void cec_ops_cdc_hec_set_state_adjacent(const struct cec_msg *msg,
  1597. __u16 *phys_addr,
  1598. __u16 *phys_addr1,
  1599. __u8 *hec_set_state)
  1600. {
  1601. *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
  1602. *phys_addr1 = (msg->msg[5] << 8) | msg->msg[6];
  1603. *hec_set_state = msg->msg[7];
  1604. }
  1605. static inline void cec_msg_cdc_hec_request_deactivation(struct cec_msg *msg,
  1606. __u16 phys_addr1,
  1607. __u16 phys_addr2,
  1608. __u16 phys_addr3)
  1609. {
  1610. msg->len = 11;
  1611. msg->msg[0] |= 0xf; /* broadcast */
  1612. msg->msg[1] = CEC_MSG_CDC_MESSAGE;
  1613. /* msg[2] and msg[3] (phys_addr) are filled in by the CEC framework */
  1614. msg->msg[4] = CEC_MSG_CDC_HEC_REQUEST_DEACTIVATION;
  1615. msg->msg[5] = phys_addr1 >> 8;
  1616. msg->msg[6] = phys_addr1 & 0xff;
  1617. msg->msg[7] = phys_addr2 >> 8;
  1618. msg->msg[8] = phys_addr2 & 0xff;
  1619. msg->msg[9] = phys_addr3 >> 8;
  1620. msg->msg[10] = phys_addr3 & 0xff;
  1621. }
  1622. static inline void cec_ops_cdc_hec_request_deactivation(const struct cec_msg *msg,
  1623. __u16 *phys_addr,
  1624. __u16 *phys_addr1,
  1625. __u16 *phys_addr2,
  1626. __u16 *phys_addr3)
  1627. {
  1628. *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
  1629. *phys_addr1 = (msg->msg[5] << 8) | msg->msg[6];
  1630. *phys_addr2 = (msg->msg[7] << 8) | msg->msg[8];
  1631. *phys_addr3 = (msg->msg[9] << 8) | msg->msg[10];
  1632. }
  1633. static inline void cec_msg_cdc_hec_notify_alive(struct cec_msg *msg)
  1634. {
  1635. msg->len = 5;
  1636. msg->msg[0] |= 0xf; /* broadcast */
  1637. msg->msg[1] = CEC_MSG_CDC_MESSAGE;
  1638. /* msg[2] and msg[3] (phys_addr) are filled in by the CEC framework */
  1639. msg->msg[4] = CEC_MSG_CDC_HEC_NOTIFY_ALIVE;
  1640. }
  1641. static inline void cec_ops_cdc_hec_notify_alive(const struct cec_msg *msg,
  1642. __u16 *phys_addr)
  1643. {
  1644. *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
  1645. }
  1646. static inline void cec_msg_cdc_hec_discover(struct cec_msg *msg)
  1647. {
  1648. msg->len = 5;
  1649. msg->msg[0] |= 0xf; /* broadcast */
  1650. msg->msg[1] = CEC_MSG_CDC_MESSAGE;
  1651. /* msg[2] and msg[3] (phys_addr) are filled in by the CEC framework */
  1652. msg->msg[4] = CEC_MSG_CDC_HEC_DISCOVER;
  1653. }
  1654. static inline void cec_ops_cdc_hec_discover(const struct cec_msg *msg,
  1655. __u16 *phys_addr)
  1656. {
  1657. *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
  1658. }
  1659. static inline void cec_msg_cdc_hpd_set_state(struct cec_msg *msg,
  1660. __u8 input_port,
  1661. __u8 hpd_state)
  1662. {
  1663. msg->len = 6;
  1664. msg->msg[0] |= 0xf; /* broadcast */
  1665. msg->msg[1] = CEC_MSG_CDC_MESSAGE;
  1666. /* msg[2] and msg[3] (phys_addr) are filled in by the CEC framework */
  1667. msg->msg[4] = CEC_MSG_CDC_HPD_SET_STATE;
  1668. msg->msg[5] = (input_port << 4) | hpd_state;
  1669. }
  1670. static inline void cec_ops_cdc_hpd_set_state(const struct cec_msg *msg,
  1671. __u16 *phys_addr,
  1672. __u8 *input_port,
  1673. __u8 *hpd_state)
  1674. {
  1675. *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
  1676. *input_port = msg->msg[5] >> 4;
  1677. *hpd_state = msg->msg[5] & 0xf;
  1678. }
  1679. static inline void cec_msg_cdc_hpd_report_state(struct cec_msg *msg,
  1680. __u8 hpd_state,
  1681. __u8 hpd_error)
  1682. {
  1683. msg->len = 6;
  1684. msg->msg[0] |= 0xf; /* broadcast */
  1685. msg->msg[1] = CEC_MSG_CDC_MESSAGE;
  1686. /* msg[2] and msg[3] (phys_addr) are filled in by the CEC framework */
  1687. msg->msg[4] = CEC_MSG_CDC_HPD_REPORT_STATE;
  1688. msg->msg[5] = (hpd_state << 4) | hpd_error;
  1689. }
  1690. static inline void cec_ops_cdc_hpd_report_state(const struct cec_msg *msg,
  1691. __u16 *phys_addr,
  1692. __u8 *hpd_state,
  1693. __u8 *hpd_error)
  1694. {
  1695. *phys_addr = (msg->msg[2] << 8) | msg->msg[3];
  1696. *hpd_state = msg->msg[5] >> 4;
  1697. *hpd_error = msg->msg[5] & 0xf;
  1698. }
  1699. #endif