Re: [PATCHv2 3/5] pulse8-cec: new driver for the Pulse-Eight USB-CEC Adapter

2016-07-11 Thread Lars Op den Kamp

Hi Hans,

On 11-07-16 12:02, Hans Verkuil wrote:

Hi Lars,

On 07/11/2016 11:41 AM, Lars Op den Kamp wrote:

Hi Hans,

just did a quick scan of this patch.

The code should work on any firmware >= v2 revision 8, though older
versions may return 0 when the build date is requested. I believe I
added that in v3. Might want to add a !=0 check before writing to the log.

The CEC adapter has an "autonomous mode", used when it's not being
controlled by our userspace application or this kernel driver. It'll
respond to some basic CEC commands that allow the PC to be woken up by TV.
If the adapter doesn't receive a MSGCODE_PING for 30 seconds when it's
in "controlled mode", then it'll revert to autonomous mode and it'll
reset all states internally.

Ah, that was rather obscure. Good to know.

What I do now (and that seems to work) is that in the pulse8_setup I turn
off the autonomous mode and then write that new setting to the EEPROM. After
that it looks like the autonomous mode stays off. Is that correct?
Correct, that'll work too, but I suggest you don't do that and update 
the eeprom values like we do in userspace. That'll allow the adapter to 
wake up the PC when the kernel module isn't running. Disabling 
autonomous mode will prevent that from working. You can only write to 
the eeprom once every 10 seconds by the way.




The autonomous mode really doesn't work well with the framework as it is
today.

CEC framework support for 'wakeup on CEC command' is something that is planned
for the future.
The autonomous mode is only really meant for waking up the PC, from S3 
with the USB version and all modes with the internal version for Intel 
boards. It should be disabled as long as the userspace application or 
kernel module is running, by sending MSGCODE_SET_CONTROLLED 1 and then 
send a poll before the 30 second timeout times out. Then, when the 
kernel module stops using the module, when the system powers off or goes 
to standby, you send a MSGCODE_SET_CONTROLLED 0 and then close the 
connection. The adapter will then take over, allowing the TV to wake up 
the PC again.


thanks, Lars
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCHv2 3/5] pulse8-cec: new driver for the Pulse-Eight USB-CEC Adapter

2016-07-11 Thread Lars Op den Kamp

Hi Hans,

just did a quick scan of this patch.

The code should work on any firmware >= v2 revision 8, though older 
versions may return 0 when the build date is requested. I believe I 
added that in v3. Might want to add a !=0 check before writing to the log.


The CEC adapter has an "autonomous mode", used when it's not being 
controlled by our userspace application or this kernel driver. It'll 
respond to some basic CEC commands that allow the PC to be woken up by TV.
If the adapter doesn't receive a MSGCODE_PING for 30 seconds when it's 
in "controlled mode", then it'll revert to autonomous mode and it'll 
reset all states internally.


This driver currently checks for rejected commands, which only happens 
when the PC went to standby and gets resumed, when the userspace app 
doesn't know about it. The firmware will then have reverted to 
autonomous mode while the PC was asleep.


For the kernel, sending a MSGCODE_PING before the 30 second timeout 
passes should be fine. I use 15 seconds in libCEC.


Thank you for writing this driver!

Lars

On 11-07-16 10:54, Hans Verkuil wrote:

This supports the Pulse-Eight USB-CEC Adapter.

It has been tested with firmware versions 4 and 5, but it should
hopefully work fine with older firmwares as well.

Signed-off-by: Hans Verkuil 
---
Changes since v1:
- Fix broken escape message offset. All codes >= 0xfd were corrupted because of
   that.
---
  drivers/staging/media/Kconfig |   2 +
  drivers/staging/media/Makefile|   1 +
  drivers/staging/media/pulse8-cec/Kconfig  |  10 +
  drivers/staging/media/pulse8-cec/Makefile |   1 +
  drivers/staging/media/pulse8-cec/pulse8-cec.c | 507 ++
  5 files changed, 521 insertions(+)
  create mode 100644 drivers/staging/media/pulse8-cec/Kconfig
  create mode 100644 drivers/staging/media/pulse8-cec/Makefile
  create mode 100644 drivers/staging/media/pulse8-cec/pulse8-cec.c

diff --git a/drivers/staging/media/Kconfig b/drivers/staging/media/Kconfig
index 5670789..cae42e5 100644
--- a/drivers/staging/media/Kconfig
+++ b/drivers/staging/media/Kconfig
@@ -29,6 +29,8 @@ source "drivers/staging/media/davinci_vpfe/Kconfig"

  source "drivers/staging/media/omap4iss/Kconfig"

+source "drivers/staging/media/pulse8-cec/Kconfig"
+
  source "drivers/staging/media/tw686x-kh/Kconfig"

  source "drivers/staging/media/s5p-cec/Kconfig"
diff --git a/drivers/staging/media/Makefile b/drivers/staging/media/Makefile
index 989c844..87ce8ad 100644
--- a/drivers/staging/media/Makefile
+++ b/drivers/staging/media/Makefile
@@ -5,4 +5,5 @@ obj-$(CONFIG_DVB_CXD2099)   += cxd2099/
  obj-$(CONFIG_LIRC_STAGING)+= lirc/
  obj-$(CONFIG_VIDEO_DM365_VPFE)+= davinci_vpfe/
  obj-$(CONFIG_VIDEO_OMAP4) += omap4iss/
+obj-$(CONFIG_USB_PULSE8_CEC)+= pulse8-cec/
  obj-$(CONFIG_VIDEO_TW686X_KH) += tw686x-kh/
diff --git a/drivers/staging/media/pulse8-cec/Kconfig 
b/drivers/staging/media/pulse8-cec/Kconfig
new file mode 100644
index 000..c6aa2d1
--- /dev/null
+++ b/drivers/staging/media/pulse8-cec/Kconfig
@@ -0,0 +1,10 @@
+config USB_PULSE8_CEC
+   tristate "Pulse Eight HDMI CEC"
+   depends on USB_ACM && MEDIA_CEC
+   select SERIO
+   select SERIO_SERPORT
+   ---help---
+ This is a cec driver for the Pulse Eight HDMI CEC device.
+
+ To compile this driver as a module, choose M here: the
+ module will be called pulse8-cec.
diff --git a/drivers/staging/media/pulse8-cec/Makefile 
b/drivers/staging/media/pulse8-cec/Makefile
new file mode 100644
index 000..9800690
--- /dev/null
+++ b/drivers/staging/media/pulse8-cec/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_USB_PULSE8_CEC) += pulse8-cec.o
diff --git a/drivers/staging/media/pulse8-cec/pulse8-cec.c 
b/drivers/staging/media/pulse8-cec/pulse8-cec.c
new file mode 100644
index 000..3bf9737
--- /dev/null
+++ b/drivers/staging/media/pulse8-cec/pulse8-cec.c
@@ -0,0 +1,507 @@
+/*
+ * Pulse Eight HDMI CEC driver
+ *
+ * Copyright 2016 Hans Verkuil 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+MODULE_AUTHOR("Hans Verkuil ");
+MODULE_DESCRIPTION("Pulse Eight HDMI CEC driver");
+MODULE_LICENSE("GPL");
+
+static int debug;
+module_param(debug, int, 0644);
+MODULE_PARM_DESC(debug, "debug level (0-1)");
+
+enum pulse8_msgcodes {
+   MSGCODE_NOTHING = 0,
+   MSGCODE_PING,
+   MSGCODE_TIMEOUT_ERROR,
+   MSGCODE_HIGH_ERROR,
+   MSGCODE_LOW_ERROR,
+   MSGCODE_FRAME_START,
+   MSGCODE_FRAME_DATA,
+   MSGCODE_RECEIVE_FAILED,
+   MSGCODE_COMMAND_ACCEPTED,   /* 0x08 */
+   MSGCODE_COMMAND_REJECTED,
+   MSGCODE_SET_ACK_MASK,
+   MSGCODE_TRANSMIT,
+   MSGCODE_TRANSMIT_EOM,
+   MSGCODE_TRANSMIT_IDLETIME,
+   MSGCODE_TRANSMIT_ACK_POLARITY,
+   MSGCODE_TRANSMIT_LINE_TIMEOUT,
+   MSGCODE_TRANSMIT_SUCCEEDED, /* 0x10 */
+   MSGCODE_TRANSMIT_FAILED_LINE,
+   MSGCODE_TRANSMIT_FA

Re: [PATCH 0/5] Pulse-Eight USB CEC driver

2016-07-11 Thread Lars Op den Kamp

Hi Hans,

I'm subscribed to this mailing list, though haven't been participating 
in discussions here (no time). I work for Pulse-Eight and did most of 
the CEC software.


There's no difference between firmware v4 and v5 for the USB model of 
the adapter. v5 just adds support for the new Intel NUC internal CEC 
adapter.


You can snoop the bus by setting the ack mask to 0 and just read what 
comes in (MSGCODE_SET_ACK_MASK 0)
This is the same as "cec-client -m" does when using libCEC: 
https://github.com/Pulse-Eight/libcec/blob/master/src/libcec/adapter/Pulse-Eight/USBCECAdapterCommands.cpp#L584


Let me know if you need more help, or send an email to 
supp...@pulse-eight.com (which will likely end up in my inbox anyway 
eventually).


thanks, Lars

On 10-07-16 15:11, Hans Verkuil wrote:

From: Hans Verkuil 

This adds support for the Pulse-Eight USB CEC dongle. It has been tested
with both v4 and v5 firmware.

It is still in staging because 1) the CEC framework it depends on is still in
staging, 2) the code needs to be refactored a bit and 3) it needs more testing.

That said, it's in pretty decent shape. It's pretty neat, but I do wish it
would support a CEC bus snooping mode: that would make it an ideal CEC bus
sniffer. But I don't see any support for it, unfortunately.

If anyone knows how this can be achieved then please let me know!

Please note that this needs support from inputattach (part of 
linuxconsoletools),
a patch is included in the TODO file.

Regards,

Hans

Hans Verkuil (5):
   cec: add check if adapter is unregistered.
   serio.h: add new define for the Pulse-Eight USB-CEC Adapter
   pulse8-cec: new driver for the Pulse-Eight USB-CEC Adapter
   MAINTAINERS: add entry for the pulse8-cec driver
   pulse8-cec: add TODO file

  MAINTAINERS   |   7 +
  drivers/staging/media/Kconfig |   2 +
  drivers/staging/media/Makefile|   1 +
  drivers/staging/media/cec/cec-adap.c  |   5 +-
  drivers/staging/media/pulse8-cec/Kconfig  |  10 +
  drivers/staging/media/pulse8-cec/Makefile |   1 +
  drivers/staging/media/pulse8-cec/TODO |  35 ++
  drivers/staging/media/pulse8-cec/pulse8-cec.c | 502 ++
  include/uapi/linux/serio.h|   1 +
  9 files changed, 563 insertions(+), 1 deletion(-)
  create mode 100644 drivers/staging/media/pulse8-cec/Kconfig
  create mode 100644 drivers/staging/media/pulse8-cec/Makefile
  create mode 100644 drivers/staging/media/pulse8-cec/TODO
  create mode 100644 drivers/staging/media/pulse8-cec/pulse8-cec.c



--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v4 06/10] cec: add HDMI CEC framework

2015-04-24 Thread Lars Op den Kamp

Hi Kamil, Hans,

I'm the main developer of libCEC 
(https://github.com/Pulse-Eight/libcec). Sorry for the late time to jump 
in here, but I wasn't signed up to this mailing list and someone pointed 
me to this discussion.


Unfortunately this approach will not work with half the TVs that are out 
there. I'll explain why:


* because of how some (common) brands implemented CEC in their TVs, this 
implementation will not work, as the TV will just reject it. In libCEC, 
we've created work arounds for brands like this. Without these work 
arounds, your in-kernel implementation will be very vendor specific. 
e.g. this implementation will work for Samsung's TVs, but not for the 
TVs made by another big TV brand. All commands, including CEC_OP_ABORT, 
should be passed to userspace to make it work with all brands.


* it should be made possible to not have the kernel send any CEC 
message, try to process any received CEC message, or ack to any logical 
address at all, to allow libraries like libCEC to fully handle all CEC 
traffic. Some brands only enable routing of some CEC keys when a 
specific device type is used. libCEC will allocate a logical address of 
the correct type for the brand that's used. If another address is first 
allocated by the kernel, and the TV communicates with it to find out 
it's name and things like that, and libCEC allocates another address a 
bit later when initialised, then you'll end up with multiple entries in 
the device list on the TV, and only one of them will work.


* CEC is *very* vendor specific. The main reason is, in my opinion, the 
use of the word "should" instead of "shall" in the spec. It's addressed 
in the new version, but it'll take years before all the non 2.x devices 
are gone. What works for vendor A will simply not work for vendor B. 
libCEC aims to address this, in a library that can be used on all major 
platforms and by all major programming languages. You could duplicate 
the work done there in the kernel to make make the implementation work 
with all brands, but I think that this does simply not belong in the 
kernel when it can be handled in userspace perfectly.


So I suggest that you limit the in-kernel implementation to handling raw 
traffic only, to have it do this (and nothing more):
* allocate one or more logical addresses, and ack CEC traffic sent to 
those logical addresses
* receive CEC traffic and forward it to userspace (traffic sent to all 
addresses is preferred, not just traffic sent to the logical address 
used by the device running this code)

* transmit CEC traffic initiated by userspace

thanks,

Lars Op den Kamp


On 23-04-15 15:03, Kamil Debski wrote:

From: Hans Verkuil 

The added HDMI CEC framework provides a generic kernel interface for
HDMI CEC devices.

Signed-off-by: Hans Verkuil 
[k.deb...@samsung.com: Merged CEC Updates commit by Hans Verkuil]
[k.deb...@samsung.com: Merged Update author commit by Hans Verkuil]
[k.deb...@samsung.com: change kthread handling when setting logical
address]
[k.deb...@samsung.com: code cleanup and fixes]
[k.deb...@samsung.com: add missing CEC commands to match spec]
[k.deb...@samsung.com: add RC framework support]
[k.deb...@samsung.com: move and edit documentation]
[k.deb...@samsung.com: add vendor id reporting]
[k.deb...@samsung.com: add possibility to clear assigned logical
addresses]
[k.deb...@samsung.com: documentation fixes, clenaup and expansion]
[k.deb...@samsung.com: reorder of API structs and add reserved fields]
[k.deb...@samsung.com: fix handling of events and fix 32/64bit timespec
problem]
[k.deb...@samsung.com: add cec.h to include/uapi/linux/Kbuild]
Signed-off-by: Kamil Debski 
---
  Documentation/cec.txt |  396 
  drivers/media/Kconfig |6 +
  drivers/media/Makefile|2 +
  drivers/media/cec.c   | 1161 +
  include/media/cec.h   |  140 ++
  include/uapi/linux/Kbuild |1 +
  include/uapi/linux/cec.h  |  303 
  7 files changed, 2009 insertions(+)
  create mode 100644 Documentation/cec.txt
  create mode 100644 drivers/media/cec.c
  create mode 100644 include/media/cec.h
  create mode 100644 include/uapi/linux/cec.h

diff --git a/Documentation/cec.txt b/Documentation/cec.txt
new file mode 100644
index 000..2b6c08a
--- /dev/null
+++ b/Documentation/cec.txt
@@ -0,0 +1,396 @@
+CEC Kernel Support
+==
+
+The CEC framework provides a unified kernel interface for use with HDMI CEC
+hardware. It is designed to handle a multiple variants of hardware. Adding to
+the flexibility of the framework it enables to set which parts of the CEC
+protocol processing is handled by the hardware, by the driver and by the
+userspace application.
+
+
+The CEC Protocol
+
+
+The CEC protocol enables consumer electronic devices to communicate with each
+other through the HDMI connection. The protocol uses lo