webkitgtk: update to 2.18.0
[openadk.git] / package / libcec / patches / libcec-00-imx6-support.patch
blob2c24635c460fa7edff3f82bab329399774a4f4c2
1 From a7f3315333c1a79259a763c6542a6cd71855b357 Mon Sep 17 00:00:00 2001
2 From: Stefan Saraev <stefan@saraev.ca>
3 Date: Thu, 7 May 2015 11:35:04 +0300
4 Subject: [PATCH] imx support
6 note. I am NOT the author of the patch. just rebased it
7 ---
8 include/cectypes.h | 14 +-
9 src/libcec/CECTypeUtils.h | 2 +
10 src/libcec/adapter/AdapterFactory.cpp | 29 +-
11 src/libcec/adapter/IMX/AdapterMessageQueue.h | 134 +++++++++
12 .../adapter/IMX/IMXCECAdapterCommunication.cpp | 328 +++++++++++++++++++++
13 .../adapter/IMX/IMXCECAdapterCommunication.h | 119 ++++++++
14 src/libcec/adapter/IMX/IMXCECAdapterDetection.cpp | 42 +++
15 src/libcec/adapter/IMX/IMXCECAdapterDetection.h | 36 +++
16 src/libcec/cmake/CheckPlatformSupport.cmake | 10 +
17 src/libcec/cmake/DisplayPlatformSupport.cmake | 6 +
18 src/libcec/env.h.in | 3 +
19 11 files changed, 720 insertions(+), 3 deletions(-)
20 create mode 100644 src/libcec/adapter/IMX/AdapterMessageQueue.h
21 create mode 100644 src/libcec/adapter/IMX/IMXCECAdapterCommunication.cpp
22 create mode 100644 src/libcec/adapter/IMX/IMXCECAdapterCommunication.h
23 create mode 100644 src/libcec/adapter/IMX/IMXCECAdapterDetection.cpp
24 create mode 100644 src/libcec/adapter/IMX/IMXCECAdapterDetection.h
26 diff --git a/include/cectypes.h b/include/cectypes.h
27 index acff259..0cfee8c 100644
28 --- a/include/cectypes.h
29 +++ b/include/cectypes.h
30 @@ -309,6 +309,17 @@ namespace CEC {
31 #define CEC_EXYNOS_VIRTUAL_COM "Exynos"
33 /*!
34 + * the path to use for the i.MX CEC wire
35 + */
36 +#define CEC_IMX_PATH "/dev/mxc_hdmi_cec"
38 +/*!
39 + * the name of the virtual COM port to use for the i.MX CEC wire
40 + */
41 +#define CEC_IMX_VIRTUAL_COM "i.MX"
44 +/*!
45 * Mimimum client version
47 #define CEC_MIN_LIB_VERSION 3
48 @@ -876,7 +887,8 @@ typedef enum cec_adapter_type
49 ADAPTERTYPE_P8_DAUGHTERBOARD = 0x2,
50 ADAPTERTYPE_RPI = 0x100,
51 ADAPTERTYPE_TDA995x = 0x200,
52 - ADAPTERTYPE_EXYNOS = 0x300
53 + ADAPTERTYPE_EXYNOS = 0x300,
54 + ADAPTERTYPE_IMX = 0x400
55 } cec_adapter_type;
57 /** force exporting through swig */
58 diff --git a/src/libcec/CECTypeUtils.h b/src/libcec/CECTypeUtils.h
59 index fd8046a..48cb215 100644
60 --- a/src/libcec/CECTypeUtils.h
61 +++ b/src/libcec/CECTypeUtils.h
62 @@ -765,6 +765,8 @@ namespace CEC
63 return "Raspberry Pi";
64 case ADAPTERTYPE_TDA995x:
65 return "TDA995x";
66 + case ADAPTERTYPE_IMX:
67 + return "i.MX";
68 default:
69 return "unknown";
71 diff --git a/src/libcec/adapter/AdapterFactory.cpp b/src/libcec/adapter/AdapterFactory.cpp
72 index da05725..92e378b 100644
73 --- a/src/libcec/adapter/AdapterFactory.cpp
74 +++ b/src/libcec/adapter/AdapterFactory.cpp
75 @@ -58,6 +58,11 @@
76 #include "Exynos/ExynosCECAdapterCommunication.h"
77 #endif
79 +#if defined(HAVE_IMX_API)
80 +#include "IMX/IMXCECAdapterDetection.h"
81 +#include "IMX/IMXCECAdapterCommunication.h"
82 +#endif
84 using namespace CEC;
86 int8_t CAdapterFactory::FindAdapters(cec_adapter *deviceList, uint8_t iBufSize, const char *strDevicePath /* = NULL */)
87 @@ -127,7 +132,22 @@ int8_t CAdapterFactory::DetectAdapters(cec_adapter_descriptor *deviceList, uint8
88 #endif
91 -#if !defined(HAVE_RPI_API) && !defined(HAVE_P8_USB) && !defined(HAVE_TDA995X_API)
93 +#if defined(HAVE_IMX_API)
94 + if (iAdaptersFound < iBufSize && CIMXCECAdapterDetection::FindAdapter() &&
95 + (!strDevicePath || !strcmp(strDevicePath, CEC_IMX_VIRTUAL_COM)))
96 + {
97 + snprintf(deviceList[iAdaptersFound].strComPath, sizeof(deviceList[iAdaptersFound].strComPath), CEC_IMX_PATH);
98 + snprintf(deviceList[iAdaptersFound].strComName, sizeof(deviceList[iAdaptersFound].strComName), CEC_IMX_VIRTUAL_COM);
99 + deviceList[iAdaptersFound].iVendorId = IMX_ADAPTER_VID;
100 + deviceList[iAdaptersFound].iProductId = IMX_ADAPTER_PID;
101 + deviceList[iAdaptersFound].adapterType = ADAPTERTYPE_IMX;
102 + iAdaptersFound++;
104 +#endif
107 +#if !defined(HAVE_RPI_API) && !defined(HAVE_P8_USB) && !defined(HAVE_TDA995X_API) && !defined(HAVE_IMX_API)
108 #error "libCEC doesn't have support for any type of adapter. please check your build system or configuration"
109 #endif
111 @@ -151,11 +171,16 @@ IAdapterCommunication *CAdapterFactory::GetInstance(const char *strPort, uint16_
112 return new CRPiCECAdapterCommunication(m_lib->m_cec);
113 #endif
115 +#if defined(HAVE_IMX_API)
116 + if (!strcmp(strPort, CEC_IMX_VIRTUAL_COM))
117 + return new CIMXCECAdapterCommunication(m_lib->m_cec);
118 +#endif
120 #if defined(HAVE_P8_USB)
121 return new CUSBCECAdapterCommunication(m_lib->m_cec, strPort, iBaudRate);
122 #endif
124 -#if !defined(HAVE_RPI_API) && !defined(HAVE_P8_USB) && !defined(HAVE_TDA995X_API) && !defined(HAVE_EXYNOS_API)
125 +#if !defined(HAVE_RPI_API) && !defined(HAVE_P8_USB) && !defined(HAVE_TDA995X_API) && !defined(HAVE_EXYNOS_API) && !defined(HAVE_IMX_API)
126 return NULL;
127 #endif
129 diff --git a/src/libcec/adapter/IMX/AdapterMessageQueue.h b/src/libcec/adapter/IMX/AdapterMessageQueue.h
130 new file mode 100644
131 index 0000000..af6742c
132 --- /dev/null
133 +++ b/src/libcec/adapter/IMX/AdapterMessageQueue.h
134 @@ -0,0 +1,134 @@
135 +#pragma once
137 + * This file is part of the libCEC(R) library.
139 + * libCEC(R) is Copyright (C) 2011-2013 Pulse-Eight Limited. All rights reserved.
140 + * libCEC(R) is an original work, containing original code.
142 + * libCEC(R) is a trademark of Pulse-Eight Limited.
144 + * This program is dual-licensed; you can redistribute it and/or modify
145 + * it under the terms of the GNU General Public License as published by
146 + * the Free Software Foundation; either version 2 of the License, or
147 + * (at your option) any later version.
149 + * This program is distributed in the hope that it will be useful,
150 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
151 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
152 + * GNU General Public License for more details.
154 + * You should have received a copy of the GNU General Public License
155 + * along with this program; if not, write to the Free Software
156 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
159 + * Alternatively, you can license this library under a commercial license,
160 + * please contact Pulse-Eight Licensing for more information.
162 + * For more information contact:
163 + * Pulse-Eight Licensing <license@pulse-eight.com>
164 + * http://www.pulse-eight.com/
165 + * http://www.pulse-eight.net/
166 + */
168 +#include "platform/threads/mutex.h"
170 +namespace CEC
172 + using namespace PLATFORM;
174 + class CAdapterMessageQueueEntry
176 + public:
177 + CAdapterMessageQueueEntry(const cec_command &command)
178 + : m_bWaiting(true), m_retval((uint32_t)-1), m_bSucceeded(false)
180 + m_hash = hashValue(
181 + uint32_t(command.opcode_set ? command.opcode : CEC_OPCODE_NONE),
182 + command.initiator, command.destination);
185 + virtual ~CAdapterMessageQueueEntry(void) {}
187 + /*!
188 + * @brief Query result from worker thread
189 + */
190 + uint32_t Result() const
192 + return m_retval;
195 + /*!
196 + * @brief Signal waiting threads
197 + */
198 + void Broadcast(void)
200 + CLockObject lock(m_mutex);
201 + m_condition.Broadcast();
204 + /*!
205 + * @brief Signal waiting thread(s) when message matches this entry
206 + */
207 + bool CheckMatch(uint32_t opcode, cec_logical_address initiator,
208 + cec_logical_address destination, uint32_t response)
210 + uint32_t hash = hashValue(opcode, initiator, destination);
212 + if (hash == m_hash)
214 + CLockObject lock(m_mutex);
216 + m_retval = response;
217 + m_bSucceeded = true;
218 + m_condition.Signal();
219 + return true;
222 + return false;
225 + /*!
226 + * @brief Wait for a response to this command.
227 + * @param iTimeout The timeout to use while waiting.
228 + * @return True when a response was received before the timeout passed, false otherwise.
229 + */
230 + bool Wait(uint32_t iTimeout)
232 + CLockObject lock(m_mutex);
234 + bool bReturn = m_bSucceeded ? true : m_condition.Wait(m_mutex, m_bSucceeded, iTimeout);
235 + m_bWaiting = false;
236 + return bReturn;
239 + /*!
240 + * @return True while a thread is waiting for a signal or isn't waiting yet, false otherwise.
241 + */
242 + bool IsWaiting(void)
244 + CLockObject lock(m_mutex);
245 + return m_bWaiting;
248 + /*!
249 + * @return Hash value for given cec_command
250 + */
251 + static uint32_t hashValue(uint32_t opcode,
252 + cec_logical_address initiator,
253 + cec_logical_address destination)
255 + return 1 | ((uint32_t)initiator << 8) |
256 + ((uint32_t)destination << 16) | ((uint32_t)opcode << 16);
259 + private:
260 + bool m_bWaiting; /**< true while a thread is waiting or when it hasn't started waiting yet */
261 + PLATFORM::CCondition<bool> m_condition; /**< the condition to wait on */
262 + PLATFORM::CMutex m_mutex; /**< mutex for changes to this class */
263 + uint32_t m_hash;
264 + uint32_t m_retval;
265 + bool m_bSucceeded;
266 + };
269 diff --git a/src/libcec/adapter/IMX/IMXCECAdapterCommunication.cpp b/src/libcec/adapter/IMX/IMXCECAdapterCommunication.cpp
270 new file mode 100644
271 index 0000000..2daa8cb
272 --- /dev/null
273 +++ b/src/libcec/adapter/IMX/IMXCECAdapterCommunication.cpp
274 @@ -0,0 +1,328 @@
276 + * This file is part of the libCEC(R) library.
278 + * libCEC(R) is Copyright (C) 2011-2013 Pulse-Eight Limited. All rights reserved.
279 + * libCEC(R) is an original work, containing original code.
281 + * libCEC(R) is a trademark of Pulse-Eight Limited.
282 + *
283 + * IMX adpater port is Copyright (C) 2013 by Stephan Rafin
284 + *
285 + * You can redistribute this file and/or modify
286 + * it under the terms of the GNU General Public License as published by
287 + * the Free Software Foundation; either version 2 of the License, or
288 + * (at your option) any later version.
290 + * This program is distributed in the hope that it will be useful,
291 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
292 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
293 + * GNU General Public License for more details.
295 + * You should have received a copy of the GNU General Public License
296 + * along with this program; if not, write to the Free Software
297 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
300 + */
302 +#include "env.h"
304 +#if defined(HAVE_IMX_API)
305 +#include "IMXCECAdapterCommunication.h"
307 +#include "CECTypeUtils.h"
308 +#include "LibCEC.h"
309 +#include "platform/sockets/cdevsocket.h"
310 +#include "platform/util/StdString.h"
311 +#include "platform/util/buffer.h"
314 + * Ioctl definitions from kernel header
315 + */
316 +#define HDMICEC_IOC_MAGIC 'H'
317 +#define HDMICEC_IOC_SETLOGICALADDRESS _IOW(HDMICEC_IOC_MAGIC, 1, unsigned char)
318 +#define HDMICEC_IOC_STARTDEVICE _IO(HDMICEC_IOC_MAGIC, 2)
319 +#define HDMICEC_IOC_STOPDEVICE _IO(HDMICEC_IOC_MAGIC, 3)
320 +#define HDMICEC_IOC_GETPHYADDRESS _IOR(HDMICEC_IOC_MAGIC, 4, unsigned char[4])
322 +#define MAX_CEC_MESSAGE_LEN 17
324 +#define MESSAGE_TYPE_RECEIVE_SUCCESS 1
325 +#define MESSAGE_TYPE_NOACK 2
326 +#define MESSAGE_TYPE_DISCONNECTED 3
327 +#define MESSAGE_TYPE_CONNECTED 4
328 +#define MESSAGE_TYPE_SEND_SUCCESS 5
330 +typedef struct hdmi_cec_event{
331 + int event_type;
332 + int msg_len;
333 + unsigned char msg[MAX_CEC_MESSAGE_LEN];
334 +}hdmi_cec_event;
337 +using namespace std;
338 +using namespace CEC;
339 +using namespace PLATFORM;
341 +#include "AdapterMessageQueue.h"
343 +#define LIB_CEC m_callback->GetLib()
345 +// these are defined in nxp private header file
346 +#define CEC_MSG_SUCCESS 0x00 /*Message transmisson Succeed*/
347 +#define CEC_CSP_OFF_STATE 0x80 /*CSP in Off State*/
348 +#define CEC_BAD_REQ_SERVICE 0x81 /*Bad .req service*/
349 +#define CEC_MSG_FAIL_UNABLE_TO_ACCESS 0x82 /*Message transmisson failed: Unable to access CEC line*/
350 +#define CEC_MSG_FAIL_ARBITRATION_ERROR 0x83 /*Message transmisson failed: Arbitration error*/
351 +#define CEC_MSG_FAIL_BIT_TIMMING_ERROR 0x84 /*Message transmisson failed: Bit timming error*/
352 +#define CEC_MSG_FAIL_DEST_NOT_ACK 0x85 /*Message transmisson failed: Destination Address not aknowledged*/
353 +#define CEC_MSG_FAIL_DATA_NOT_ACK 0x86 /*Message transmisson failed: Databyte not acknowledged*/
356 +CIMXCECAdapterCommunication::CIMXCECAdapterCommunication(IAdapterCommunicationCallback *callback) :
357 + IAdapterCommunication(callback)/*,
358 + m_bLogicalAddressChanged(false)*/
360 + CLockObject lock(m_mutex);
362 + m_iNextMessage = 0;
363 + //m_logicalAddresses.Clear();
364 + m_logicalAddress = CECDEVICE_UNKNOWN;
365 + m_bLogicalAddressRegistered = false;
366 + m_bInitialised = false;
367 + m_dev = new CCDevSocket(CEC_IMX_PATH);
370 +CIMXCECAdapterCommunication::~CIMXCECAdapterCommunication(void)
372 + Close();
374 + CLockObject lock(m_mutex);
375 + delete m_dev;
376 + m_dev = 0;
379 +bool CIMXCECAdapterCommunication::IsOpen(void)
381 + return IsInitialised() && m_dev->IsOpen();
384 +bool CIMXCECAdapterCommunication::Open(uint32_t iTimeoutMs, bool UNUSED(bSkipChecks), bool bStartListening)
386 + if (m_dev->Open(iTimeoutMs))
388 + if (!bStartListening || CreateThread()) {
389 + if (m_dev->Ioctl(HDMICEC_IOC_STARTDEVICE, NULL) == 0) {
390 + m_bInitialised = true;
391 + return true;
393 + LIB_CEC->AddLog(CEC_LOG_ERROR, "%s: Unable to start device\n", __func__);
395 + m_dev->Close();
398 + return false;
402 +void CIMXCECAdapterCommunication::Close(void)
404 + StopThread(0);
406 + CLockObject lock(m_mutex);
407 + if (!m_bInitialised) {
408 + return;
410 + if (m_dev->Ioctl(HDMICEC_IOC_STOPDEVICE, NULL) != 0) {
411 + LIB_CEC->AddLog(CEC_LOG_ERROR, "%s: Unable to stop device\n", __func__);
413 + m_dev->Close();
414 + m_bInitialised = false;
418 +std::string CIMXCECAdapterCommunication::GetError(void) const
420 + std::string strError(m_strError);
421 + return strError;
425 +cec_adapter_message_state CIMXCECAdapterCommunication::Write(
426 + const cec_command &data, bool &UNUSED(bRetry), uint8_t UNUSED(iLineTimeout), bool UNUSED(bIsReply))
428 + //cec_frame frame;
429 + unsigned char message[MAX_CEC_MESSAGE_LEN];
430 + int msg_len = 1;
431 + cec_adapter_message_state rc = ADAPTER_MESSAGE_STATE_ERROR;
433 + if ((size_t)data.parameters.size + data.opcode_set + 1 > sizeof(message))
435 + LIB_CEC->AddLog(CEC_LOG_ERROR, "%s: data size too large !", __func__);
436 + return ADAPTER_MESSAGE_STATE_ERROR;
439 + message[0] = (data.initiator << 4) | (data.destination & 0x0f);
440 + if (data.opcode_set)
442 + message[1] = data.opcode;
443 + msg_len++;
444 + memcpy(&message[2], data.parameters.data, data.parameters.size);
445 + msg_len+=data.parameters.size;
448 + if (m_dev->Write(message, msg_len) == msg_len)
450 + rc = ADAPTER_MESSAGE_STATE_SENT_ACKED;
452 + else
453 + LIB_CEC->AddLog(CEC_LOG_ERROR, "%s: sent command error !", __func__);
455 + return rc;
459 +uint16_t CIMXCECAdapterCommunication::GetFirmwareVersion(void)
461 + /* FIXME add ioctl ? */
462 + return 0;
466 +cec_vendor_id CIMXCECAdapterCommunication::GetVendorId(void)
468 + return CEC_VENDOR_UNKNOWN;
472 +uint16_t CIMXCECAdapterCommunication::GetPhysicalAddress(void)
474 + uint32_t info;
475 + uint16_t phy_addr;
477 + if (m_dev->Ioctl(HDMICEC_IOC_GETPHYADDRESS, &info) != 0)
479 + LIB_CEC->AddLog(CEC_LOG_ERROR, "%s: HDMICEC_IOC_GETPHYADDRESS failed !", __func__);
480 + return CEC_INVALID_PHYSICAL_ADDRESS;
482 + /* Rebuild 16 bit raw value from fsl 32 bits value */
483 + phy_addr = ((info & 0x0f) << 12) | (info & 0x0f00) |
484 + ((info & 0x0f0000) >> 12) | ((info & 0x0f000000) >> 24);
486 + return phy_addr;
490 +cec_logical_addresses CIMXCECAdapterCommunication::GetLogicalAddresses(void)
492 + cec_logical_addresses addresses;
493 + addresses.Clear();
495 + CLockObject lock(m_mutex);
496 + if ((m_logicalAddress & (CECDEVICE_UNKNOWN | CECDEVICE_UNREGISTERED)) == 0)
497 + addresses.Set(m_logicalAddress);
499 + return addresses;
502 +void CIMXCECAdapterCommunication::HandleLogicalAddressLost(cec_logical_address UNUSED(oldAddress))
504 + UnregisterLogicalAddress();
507 +bool CIMXCECAdapterCommunication::UnregisterLogicalAddress(void)
509 + CLockObject lock(m_mutex);
510 + if (!m_bLogicalAddressRegistered)
511 + return true;
513 + if (m_dev->Ioctl(HDMICEC_IOC_SETLOGICALADDRESS, (void *)CECDEVICE_BROADCAST) != 0)
515 + LIB_CEC->AddLog(CEC_LOG_ERROR, "%s: HDMICEC_IOC_SETLOGICALADDRESS failed !", __func__);
516 + return false;
519 + m_logicalAddress = CECDEVICE_UNKNOWN;
520 + m_bLogicalAddressRegistered = false;
521 + return true;
524 +bool CIMXCECAdapterCommunication::RegisterLogicalAddress(const cec_logical_address address)
526 + CLockObject lock(m_mutex);
528 + if (m_logicalAddress == address && m_bLogicalAddressRegistered)
530 + return true;
533 + if (m_dev->Ioctl(HDMICEC_IOC_SETLOGICALADDRESS, (void *)address) != 0)
535 + LIB_CEC->AddLog(CEC_LOG_ERROR, "%s: HDMICEC_IOC_SETLOGICALADDRESS failed !", __func__);
536 + return false;
539 + m_logicalAddress = address;
540 + m_bLogicalAddressRegistered = true;
541 + return true;
544 +bool CIMXCECAdapterCommunication::SetLogicalAddresses(const cec_logical_addresses &addresses)
546 + int log_addr = addresses.primary;
548 + return RegisterLogicalAddress((cec_logical_address)log_addr);
551 +void *CIMXCECAdapterCommunication::Process(void)
553 + bool bHandled;
554 + hdmi_cec_event event;
555 + int ret;
557 + uint32_t opcode, status;
558 + cec_logical_address initiator, destination;
560 + while (!IsStopped())
562 + ret = m_dev->Read((char *)&event, sizeof(event), 5000);
563 + if (ret > 0)
566 + initiator = cec_logical_address(event.msg[0] >> 4);
567 + destination = cec_logical_address(event.msg[0] & 0x0f);
569 + //LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s: Read data : type : %d initiator %d dest %d", __func__, event.event_type, initiator, destination);
570 + if (event.event_type == MESSAGE_TYPE_RECEIVE_SUCCESS)
571 + /* Message received */
573 + cec_command cmd;
575 + cec_command::Format(
576 + cmd, initiator, destination,
577 + ( event.msg_len > 1 ) ? cec_opcode(event.msg[1]) : CEC_OPCODE_NONE);
579 + for( uint8_t i = 2; i < event.msg_len; i++ )
580 + cmd.parameters.PushBack(event.msg[i]);
582 + if (!IsStopped())
583 + m_callback->OnCommandReceived(cmd);
586 + if (event.event_type == MESSAGE_TYPE_CONNECTED)
587 + /* HDMI has just been reconnected - Notify phy address*/
589 + uint16_t iNewAddress = GetPhysicalAddress();
590 + m_callback->HandlePhysicalAddressChanged(iNewAddress);
592 + /* We are not interested in other events */
593 + } /*else {
594 + LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s: Read returned %d", __func__, ret);
595 + }*/
599 + return 0;
602 +#endif // HAVE_IMX_API
603 diff --git a/src/libcec/adapter/IMX/IMXCECAdapterCommunication.h b/src/libcec/adapter/IMX/IMXCECAdapterCommunication.h
604 new file mode 100644
605 index 0000000..9e899a3
606 --- /dev/null
607 +++ b/src/libcec/adapter/IMX/IMXCECAdapterCommunication.h
608 @@ -0,0 +1,119 @@
609 +#pragma once
611 + * This file is part of the libCEC(R) library.
613 + * libCEC(R) is Copyright (C) 2011-2013 Pulse-Eight Limited. All rights reserved.
614 + * libCEC(R) is an original work, containing original code.
616 + * libCEC(R) is a trademark of Pulse-Eight Limited.
618 + * IMX adpater port is Copyright (C) 2013 by Stephan Rafin
619 + *
620 + * You can redistribute this file and/or modify
621 + * it under the terms of the GNU General Public License as published by
622 + * the Free Software Foundation; either version 2 of the License, or
623 + * (at your option) any later version.
625 + * This program is distributed in the hope that it will be useful,
626 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
627 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
628 + * GNU General Public License for more details.
630 + * You should have received a copy of the GNU General Public License
631 + * along with this program; if not, write to the Free Software
632 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
635 + */
637 +#if defined(HAVE_IMX_API)
639 +#include "platform/threads/mutex.h"
640 +#include "platform/threads/threads.h"
641 +#include "platform/sockets/socket.h"
642 +#include "adapter/AdapterCommunication.h"
643 +#include <map>
645 +#define IMX_ADAPTER_VID 0x0471 /*FIXME TBD*/
646 +#define IMX_ADAPTER_PID 0x1001
650 +namespace PLATFORM
652 + class CCDevSocket;
656 +namespace CEC
658 + class CAdapterMessageQueueEntry;
660 + class CIMXCECAdapterCommunication : public IAdapterCommunication, public PLATFORM::CThread
662 + public:
663 + /*!
664 + * @brief Create a new USB-CEC communication handler.
665 + * @param callback The callback to use for incoming CEC commands.
666 + */
667 + CIMXCECAdapterCommunication(IAdapterCommunicationCallback *callback);
668 + virtual ~CIMXCECAdapterCommunication(void);
670 + /** @name IAdapterCommunication implementation */
671 + ///{
672 + bool Open(uint32_t iTimeoutMs = CEC_DEFAULT_CONNECT_TIMEOUT, bool bSkipChecks = false, bool bStartListening = true);
673 + void Close(void);
674 + bool IsOpen(void);
675 + std::string GetError(void) const;
676 + cec_adapter_message_state Write(const cec_command &data, bool &bRetry, uint8_t iLineTimeout, bool bIsReply);
678 + bool SetLineTimeout(uint8_t UNUSED(iTimeout)) { return true; }
679 + bool StartBootloader(void) { return false; }
680 + bool SetLogicalAddresses(const cec_logical_addresses &addresses);
681 + cec_logical_addresses GetLogicalAddresses(void);
682 + bool PingAdapter(void) { return IsInitialised(); }
683 + uint16_t GetFirmwareVersion(void);
684 + uint32_t GetFirmwareBuildDate(void) { return 0; }
685 + bool IsRunningLatestFirmware(void) { return true; }
686 + bool PersistConfiguration(const libcec_configuration & UNUSED(configuration)) { return false; }
687 + bool GetConfiguration(libcec_configuration & UNUSED(configuration)) { return false; }
688 + std::string GetPortName(void) { return std::string("IMX"); }
689 + uint16_t GetPhysicalAddress(void);
690 + bool SetControlledMode(bool UNUSED(controlled)) { return true; }
691 + cec_vendor_id GetVendorId(void);
692 + bool SupportsSourceLogicalAddress(const cec_logical_address address) { return address > CECDEVICE_TV && address <= CECDEVICE_BROADCAST; }
693 + cec_adapter_type GetAdapterType(void) { return ADAPTERTYPE_IMX; }
694 + uint16_t GetAdapterVendorId(void) const { return IMX_ADAPTER_VID; }
695 + uint16_t GetAdapterProductId(void) const { return IMX_ADAPTER_PID; }
696 + void HandleLogicalAddressLost(cec_logical_address UNUSED(oldAddress));
697 + void SetActiveSource(bool UNUSED(bSetTo), bool UNUSED(bClientUnregistered)) {}
698 + bool RegisterLogicalAddress(const cec_logical_address address);
699 + ///}
701 + /** @name PLATFORM::CThread implementation */
702 + ///{
703 + void *Process(void);
704 + ///}
706 + private:
707 + bool IsInitialised(void) const { return m_bInitialised; };
708 + bool UnregisterLogicalAddress(void);
710 + std::string m_strError; /**< current error message */
712 + //cec_logical_addresses m_logicalAddresses;
713 + cec_logical_address m_logicalAddress;
715 + PLATFORM::CMutex m_mutex;
716 + PLATFORM::CCDevSocket *m_dev; /**< the device connection */
717 + bool m_bLogicalAddressRegistered;
718 + bool m_bInitialised;
720 + PLATFORM::CMutex m_messageMutex;
721 + uint32_t m_iNextMessage;
722 + std::map<uint32_t, CAdapterMessageQueueEntry *> m_messages;
723 + };
727 +#endif
728 diff --git a/src/libcec/adapter/IMX/IMXCECAdapterDetection.cpp b/src/libcec/adapter/IMX/IMXCECAdapterDetection.cpp
729 new file mode 100644
730 index 0000000..6c93c45
731 --- /dev/null
732 +++ b/src/libcec/adapter/IMX/IMXCECAdapterDetection.cpp
733 @@ -0,0 +1,42 @@
735 + * This file is part of the libCEC(R) library.
737 + * libCEC(R) is Copyright (C) 2011-2013 Pulse-Eight Limited. All rights reserved.
738 + * libCEC(R) is an original work, containing original code.
740 + * libCEC(R) is a trademark of Pulse-Eight Limited.
741 + *
742 + * IMX adpater port is Copyright (C) 2013 by Stephan Rafin
743 + *
744 + * You can redistribute this file and/or modify
745 + * it under the terms of the GNU General Public License as published by
746 + * the Free Software Foundation; either version 2 of the License, or
747 + * (at your option) any later version.
749 + * This program is distributed in the hope that it will be useful,
750 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
751 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
752 + * GNU General Public License for more details.
754 + * You should have received a copy of the GNU General Public License
755 + * along with this program; if not, write to the Free Software
756 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
759 + */
761 +#include "env.h"
762 +#include <stdio.h>
764 +#if defined(HAVE_IMX_API)
765 +#include "IMXCECAdapterDetection.h"
768 +using namespace CEC;
770 +bool CIMXCECAdapterDetection::FindAdapter(void)
772 + return access(CEC_IMX_PATH, 0) == 0;
775 +#endif
776 diff --git a/src/libcec/adapter/IMX/IMXCECAdapterDetection.h b/src/libcec/adapter/IMX/IMXCECAdapterDetection.h
777 new file mode 100644
778 index 0000000..d54891d
779 --- /dev/null
780 +++ b/src/libcec/adapter/IMX/IMXCECAdapterDetection.h
781 @@ -0,0 +1,36 @@
782 +#pragma once
784 + * This file is part of the libCEC(R) library.
786 + * libCEC(R) is Copyright (C) 2011-2013 Pulse-Eight Limited. All rights reserved.
787 + * libCEC(R) is an original work, containing original code.
789 + * libCEC(R) is a trademark of Pulse-Eight Limited.
790 + *
791 + * IMX adpater port is Copyright (C) 2013 by Stephan Rafin
792 + *
793 + * You can redistribute this file and/or modify
794 + * it under the terms of the GNU General Public License as published by
795 + * the Free Software Foundation; either version 2 of the License, or
796 + * (at your option) any later version.
798 + * This program is distributed in the hope that it will be useful,
799 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
800 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
801 + * GNU General Public License for more details.
803 + * You should have received a copy of the GNU General Public License
804 + * along with this program; if not, write to the Free Software
805 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
808 + */
810 +namespace CEC
812 + class CIMXCECAdapterDetection
814 + public:
815 + static bool FindAdapter(void);
816 + };
818 diff --git a/src/libcec/cmake/CheckPlatformSupport.cmake b/src/libcec/cmake/CheckPlatformSupport.cmake
819 index 828cdb2..8b47795 100644
820 --- a/src/libcec/cmake/CheckPlatformSupport.cmake
821 +++ b/src/libcec/cmake/CheckPlatformSupport.cmake
822 @@ -8,6 +8,7 @@
823 # HAVE_RANDR 1 if xrandr is supported
824 # HAVE_LIBUDEV 1 if udev is supported
825 # HAVE_RPI_API 1 if Raspberry Pi is supported
826 +# HAVE_IMX_API 1 if i.MX is supported
827 # HAVE_TDA995X_API 1 if TDA995X is supported
828 # HAVE_EXYNOS_API 1 if Exynos is supported
829 # HAVE_P8_USB_DETECT 1 if Pulse-Eight devices can be auto-detected
830 @@ -87,6 +88,15 @@ else()
831 list(APPEND CEC_SOURCES ${CEC_SOURCES_ADAPTER_RPI})
832 endif()
834 + # i.MX
835 + if (HAVE_IMX_API)
836 + set(LIB_INFO "${LIB_INFO}, 'IMX'")
837 + set(CEC_SOURCES_ADAPTER_IMX adapter/IMX/IMXCECAdapterDetection.cpp
838 + adapter/IMX/IMXCECAdapterCommunication.cpp)
839 + source_group("Source Files\\adapter\\IMX" FILES ${CEC_SOURCES_ADAPTER_IMX})
840 + list(APPEND CEC_SOURCES ${CEC_SOURCES_ADAPTER_IMX})
841 + endif()
843 # TDA995x
844 check_include_files("tda998x_ioctl.h;comps/tmdlHdmiCEC/inc/tmdlHdmiCEC_Types.h" HAVE_TDA995X_API)
845 if (HAVE_TDA995X_API)
846 diff --git a/src/libcec/cmake/DisplayPlatformSupport.cmake b/src/libcec/cmake/DisplayPlatformSupport.cmake
847 index feee111..0309c56 100644
848 --- a/src/libcec/cmake/DisplayPlatformSupport.cmake
849 +++ b/src/libcec/cmake/DisplayPlatformSupport.cmake
850 @@ -32,6 +32,12 @@ else()
851 message(STATUS "Raspberry Pi support: no")
852 endif()
854 +if (HAVE_IMX_API)
855 + message(STATUS "i.MX support: yes")
856 +else()
857 + message(STATUS "i.MX support: no")
858 +endif()
860 if (HAVE_TDA995X_API)
861 message(STATUS "TDA995x support: yes")
862 else()
863 diff --git a/src/libcec/env.h.in b/src/libcec/env.h.in
864 index a1a1f26..f90e729 100644
865 --- a/src/libcec/env.h.in
866 +++ b/src/libcec/env.h.in
867 @@ -60,6 +60,9 @@
868 /* Define to 1 for Raspberry Pi support */
869 #cmakedefine HAVE_RPI_API @HAVE_RPI_API@
871 +/* Define to 1 for IMX support */
872 +#cmakedefine HAVE_IMX_API @HAVE_IMX_API@
874 /* Define to 1 for TDA995x support */
875 #cmakedefine HAVE_TDA995X_API @HAVE_TDA995X_API@
878 2.1.4