[PATCHv10 14/16] cec: adv7511: add cec support.

2015-11-12 Thread Hans Verkuil
From: Hans Verkuil <hans.verk...@cisco.com>

Add CEC support to the adv7511 driver.

Signed-off-by: Hans Verkuil <hansv...@cisco.com>
[k.deb...@samsung.com: Merged changes from CEC Updates commit by Hans Verkuil]
Signed-off-by: Kamil Debski <ka...@wypas.org>
Signed-off-by: Hans Verkuil <hans.verk...@cisco.com>
---
 drivers/media/i2c/adv7511.c | 364 +++-
 include/media/adv7511.h |   6 +-
 2 files changed, 358 insertions(+), 12 deletions(-)

diff --git a/drivers/media/i2c/adv7511.c b/drivers/media/i2c/adv7511.c
index e4900df..dee73a6 100644
--- a/drivers/media/i2c/adv7511.c
+++ b/drivers/media/i2c/adv7511.c
@@ -33,6 +33,7 @@
 #include 
 #include 
 #include 
+#include 
 
 static int debug;
 module_param(debug, int, 0644);
@@ -59,6 +60,8 @@ MODULE_LICENSE("GPL v2");
 #define ADV7511_MIN_PIXELCLOCK 2000
 #define ADV7511_MAX_PIXELCLOCK 22500
 
+#define ADV7511_MAX_ADDRS (3)
+
 /*
 **
 *
@@ -90,12 +93,19 @@ struct adv7511_state {
struct v4l2_ctrl_handler hdl;
int chip_revision;
u8 i2c_edid_addr;
-   u8 i2c_cec_addr;
u8 i2c_pktmem_addr;
+   u8 i2c_cec_addr;
+
+   struct i2c_client *i2c_cec;
+   u8   cec_addr[ADV7511_MAX_ADDRS];
+   u8   cec_valid_addrs;
+   bool cec_enabled_adap;
+
/* Is the adv7511 powered on? */
bool power_on;
/* Did we receive hotplug and rx-sense signals? */
bool have_monitor;
+   bool enabled_irq;
/* timings from s_dv_timings */
struct v4l2_dv_timings dv_timings;
u32 fmt_code;
@@ -225,7 +235,7 @@ static int adv_smbus_read_i2c_block_data(struct i2c_client 
*client,
return ret;
 }
 
-static inline void adv7511_edid_rd(struct v4l2_subdev *sd, u16 len, u8 *buf)
+static void adv7511_edid_rd(struct v4l2_subdev *sd, uint16_t len, uint8_t *buf)
 {
struct adv7511_state *state = get_adv7511_state(sd);
int i;
@@ -240,6 +250,34 @@ static inline void adv7511_edid_rd(struct v4l2_subdev *sd, 
u16 len, u8 *buf)
v4l2_err(sd, "%s: i2c read error\n", __func__);
 }
 
+static inline int adv7511_cec_read(struct v4l2_subdev *sd, u8 reg)
+{
+   struct adv7511_state *state = get_adv7511_state(sd);
+
+   return i2c_smbus_read_byte_data(state->i2c_cec, reg);
+}
+
+static int adv7511_cec_write(struct v4l2_subdev *sd, u8 reg, u8 val)
+{
+   struct adv7511_state *state = get_adv7511_state(sd);
+   int ret;
+   int i;
+
+   for (i = 0; i < 3; i++) {
+   ret = i2c_smbus_write_byte_data(state->i2c_cec, reg, val);
+   if (ret == 0)
+   return 0;
+   }
+   v4l2_err(sd, "%s: I2C Write Problem\n", __func__);
+   return ret;
+}
+
+static inline int adv7511_cec_write_and_or(struct v4l2_subdev *sd, u8 reg, u8 
mask,
+  u8 val)
+{
+   return adv7511_cec_write(sd, reg, (adv7511_cec_read(sd, reg) & mask) | 
val);
+}
+
 static int adv7511_pktmem_rd(struct v4l2_subdev *sd, u8 reg)
 {
struct adv7511_state *state = get_adv7511_state(sd);
@@ -413,16 +451,28 @@ static const struct v4l2_ctrl_ops adv7511_ctrl_ops = {
 #ifdef CONFIG_VIDEO_ADV_DEBUG
 static void adv7511_inv_register(struct v4l2_subdev *sd)
 {
+   struct adv7511_state *state = get_adv7511_state(sd);
+
v4l2_info(sd, "0x000-0x0ff: Main Map\n");
+   if (state->i2c_cec)
+   v4l2_info(sd, "0x100-0x1ff: CEC Map\n");
 }
 
 static int adv7511_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register 
*reg)
 {
+   struct adv7511_state *state = get_adv7511_state(sd);
+
reg->size = 1;
switch (reg->reg >> 8) {
case 0:
reg->val = adv7511_rd(sd, reg->reg & 0xff);
break;
+   case 1:
+   if (state->i2c_cec) {
+   reg->val = adv7511_cec_read(sd, reg->reg & 0xff);
+   break;
+   }
+   /* fall through */
default:
v4l2_info(sd, "Register %03llx not supported\n", reg->reg);
adv7511_inv_register(sd);
@@ -433,10 +483,18 @@ static int adv7511_g_register(struct v4l2_subdev *sd, 
struct v4l2_dbg_register *
 
 static int adv7511_s_register(struct v4l2_subdev *sd, const struct 
v4l2_dbg_register *reg)
 {
+   struct adv7511_state *state = get_adv7511_state(sd);
+
switch (reg->reg >> 8) {
case 0:
adv7511_wr(sd, reg->reg & 0xff, reg->val & 0xff);
break;
+   case 1:
+   if (state->i2c_cec) {
+   adv7511_cec_write(sd, reg->reg & 0xff, reg->val & 0xff);
+   break;
+   }
+   /* fall through */
defau

[PATCHv10 13/16] cec: adv7842: add cec support

2015-11-12 Thread Hans Verkuil
From: Hans Verkuil <hans.verk...@cisco.com>

Add CEC support to the adv7842 driver.

Signed-off-by: Hans Verkuil <hans.verk...@cisco.com>
---
 drivers/media/i2c/adv7842.c | 255 +---
 1 file changed, 238 insertions(+), 17 deletions(-)

diff --git a/drivers/media/i2c/adv7842.c b/drivers/media/i2c/adv7842.c
index b7269b8..0f29b33 100644
--- a/drivers/media/i2c/adv7842.c
+++ b/drivers/media/i2c/adv7842.c
@@ -39,6 +39,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -79,6 +80,8 @@ MODULE_LICENSE("GPL");
 
 #define ADV7842_OP_SWAP_CB_CR  (1 << 0)
 
+#define ADV7842_MAX_ADDRS (3)
+
 /*
 **
 *
@@ -142,6 +145,10 @@ struct adv7842_state {
struct v4l2_ctrl *free_run_color_ctrl_manual;
struct v4l2_ctrl *free_run_color_ctrl;
struct v4l2_ctrl *rgb_quantization_range_ctrl;
+
+   u8   cec_addr[ADV7842_MAX_ADDRS];
+   u8   cec_valid_addrs;
+   bool cec_enabled_adap;
 };
 
 /* Unsupported timings. This device cannot support 720p30. */
@@ -418,9 +425,9 @@ static inline int cec_write(struct v4l2_subdev *sd, u8 reg, 
u8 val)
return adv_smbus_write_byte_data(state->i2c_cec, reg, val);
 }
 
-static inline int cec_write_and_or(struct v4l2_subdev *sd, u8 reg, u8 mask, u8 
val)
+static inline int cec_write_clr_set(struct v4l2_subdev *sd, u8 reg, u8 mask, 
u8 val)
 {
-   return cec_write(sd, reg, (cec_read(sd, reg) & mask) | val);
+   return cec_write(sd, reg, (cec_read(sd, reg) & ~mask) | val);
 }
 
 static inline int infoframe_read(struct v4l2_subdev *sd, u8 reg)
@@ -696,6 +703,18 @@ adv7842_get_dv_timings_cap(struct v4l2_subdev *sd)
 
 /* --- */
 
+static u16 adv7842_read_cable_det(struct v4l2_subdev *sd)
+{
+   u8 reg = io_read(sd, 0x6f);
+   u16 val = 0;
+
+   if (reg & 0x02)
+   val |= 1; /* port A */
+   if (reg & 0x01)
+   val |= 2; /* port B */
+   return val;
+}
+
 static void adv7842_delayed_work_enable_hotplug(struct work_struct *work)
 {
struct delayed_work *dwork = to_delayed_work(work);
@@ -703,8 +722,13 @@ static void adv7842_delayed_work_enable_hotplug(struct 
work_struct *work)
struct adv7842_state, delayed_work_enable_hotplug);
struct v4l2_subdev *sd = >sd;
int present = state->hdmi_edid.present;
+   u16 connected_inputs;
u8 mask = 0;
 
+   connected_inputs = present & adv7842_read_cable_det(sd);
+   v4l2_subdev_notify(sd, V4L2_SUBDEV_CEC_CONN_INPUTS,
+  _inputs);
+
v4l2_dbg(2, debug, sd, "%s: enable hotplug on ports: 0x%x\n",
__func__, present);
 
@@ -983,20 +1007,16 @@ static int adv7842_s_register(struct v4l2_subdev *sd,
 static int adv7842_s_detect_tx_5v_ctrl(struct v4l2_subdev *sd)
 {
struct adv7842_state *state = to_state(sd);
-   int prev = v4l2_ctrl_g_ctrl(state->detect_tx_5v_ctrl);
-   u8 reg_io_6f = io_read(sd, 0x6f);
-   int val = 0;
+   u16 cable_det = adv7842_read_cable_det(sd);
+   u16 connected_inputs;
 
-   if (reg_io_6f & 0x02)
-   val |= 1; /* port A */
-   if (reg_io_6f & 0x01)
-   val |= 2; /* port B */
+   v4l2_dbg(1, debug, sd, "%s: 0x%x\n", __func__, cable_det);
 
-   v4l2_dbg(1, debug, sd, "%s: 0x%x -> 0x%x\n", __func__, prev, val);
+   connected_inputs = state->hdmi_edid.present & cable_det;
+   v4l2_subdev_notify(sd, V4L2_SUBDEV_CEC_CONN_INPUTS,
+  _inputs);
 
-   if (val != prev)
-   return v4l2_ctrl_s_ctrl(state->detect_tx_5v_ctrl, val);
-   return 0;
+   return v4l2_ctrl_s_ctrl(state->detect_tx_5v_ctrl, cable_det);
 }
 
 static int find_and_set_predefined_video_timings(struct v4l2_subdev *sd,
@@ -2157,6 +2177,183 @@ static void adv7842_irq_enable(struct v4l2_subdev *sd, 
bool enable)
}
 }
 
+static void adv7842_cec_tx_raw_status(struct v4l2_subdev *sd, u8 tx_raw_status)
+{
+   if ((cec_read(sd, 0x11) & 0x01) == 0) {
+   v4l2_dbg(1, debug, sd, "%s: tx raw: tx disabled\n", __func__);
+   return;
+   }
+
+   if (tx_raw_status & 0x02) {
+   v4l2_dbg(1, debug, sd, "%s: tx raw: arbitration lost\n",
+__func__);
+   v4l2_subdev_notify(sd, V4L2_SUBDEV_CEC_TX_DONE,
+  (void *)CEC_TX_STATUS_ARB_LOST);
+   return;
+   }
+   if (tx_raw_status & 0x04) {
+   v4l2_dbg(1, debug, sd, "%s: tx raw: retry failed\n", __func__);
+   v4l2_subdev_notify(sd, V4L2_SUBDEV_CEC_TX_DONE,
+  (v

[PATCHv10 04/16] input.h: add BUS_CEC type

2015-11-12 Thread Hans Verkuil
From: Hans Verkuil <hans.verk...@cisco.com>

Inputs can come in over the HDMI CEC bus, so add a new type for this.

Signed-off-by: Hans Verkuil <hans.verk...@cisco.com>
Acked-by: Dmitry Torokhov <dmitry.torok...@gmail.com>
---
 include/uapi/linux/input.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/uapi/linux/input.h b/include/uapi/linux/input.h
index 731417c..a32bff1 100644
--- a/include/uapi/linux/input.h
+++ b/include/uapi/linux/input.h
@@ -972,6 +972,7 @@ struct input_keymap_entry {
 #define BUS_GSC0x1A
 #define BUS_ATARI  0x1B
 #define BUS_SPI0x1C
+#define BUS_CEC0x1D
 
 /*
  * MT_TOOL types
-- 
2.6.2

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


[PATCHv10 02/16] dts: exynos4: add node for the HDMI CEC device

2015-11-12 Thread Hans Verkuil
From: Kamil Debski <ka...@wypas.org>

This patch adds HDMI CEC node specific to the Exynos4210/4x12 SoC series.

Signed-off-by: Kamil Debski <ka...@wypas.org>
Signed-off-by: Hans Verkuil <hans.verk...@cisco.com>
Acked-by: Krzysztof Kozlowski <k.kozlow...@samsung.com>
---
 arch/arm/boot/dts/exynos4.dtsi | 12 
 1 file changed, 12 insertions(+)

diff --git a/arch/arm/boot/dts/exynos4.dtsi b/arch/arm/boot/dts/exynos4.dtsi
index 98c0a36..7baff26 100644
--- a/arch/arm/boot/dts/exynos4.dtsi
+++ b/arch/arm/boot/dts/exynos4.dtsi
@@ -720,6 +720,18 @@
status = "disabled";
};
 
+   hdmicec: cec@100B {
+   compatible = "samsung,s5p-cec";
+   reg = <0x100B 0x200>;
+   interrupts = <0 114 0>;
+   clocks = < CLK_HDMI_CEC>;
+   clock-names = "hdmicec";
+   samsung,syscon-phandle = <_system_controller>;
+   pinctrl-names = "default";
+   pinctrl-0 = <_cec>;
+   status = "disabled";
+   };
+
mixer: mixer@12C1 {
compatible = "samsung,exynos4210-mixer";
interrupts = <0 91 0>;
-- 
2.6.2

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


[PATCHv10 00/16] HDMI CEC framework

2015-11-12 Thread Hans Verkuil
).
- add a second debug level for message debugging.
- fix a nasty kernel Oops in cec_transmit_msg while waiting for transmit 
completion
  (adap->tx_queue[idx].func wasn't set to NULL).
- add support for CEC_MSG_REPORT_FEATURES (CEC 2.0 only).
- correctly abort unsupported messages.
- add support for the device power status feature.
- add support for the audio return channel (preliminary).
- add support for the CDC hotplug message (preliminary).
- added osd_name to struct cec_log_addrs.
- reported physical addresses are stored internally.
- fix enabling/disabling the CEC adapter (internal fields weren't cleared 
correctly).
- zero reserved fields.
- return an error if you try to receive/transmit and the adapter isn't 
configured.
- when creating the adapter provide the owner module and the parent device.
- add a CEC_VENDOR_ID_NONE define to signal if no vendor ID was set.
- add new capabilities: RC (remote control), ARC (audio return channel) and CDC
  (Capability Discovery and Control).
- applications that want to handle messages for a logical address need to set 
the
  CEC_LOG_ADDRS_FL_HANDLE_MSGS flag. Otherwise the CEC core will be the one 
handling
  all messages.
- Each logical address has its own all_device_types value. So this should be an 
array,
  not a single value.
- I'm sure I've forgotten some changes...

Changes since v5

- drop struct cec_timeval in favour of a __u64 that keeps the timestamp in ns
- remove userspace documentation from Documentation/cec.txt as userspace API
  is described in the DocBook
- add missing documentation for the passthrough mode to the DocBook
- add information about the number of events that can be queued
- fix misspelling of reply
- fix behaviour of posting an event in cec_received_msg, such that the behaviour
  is consistent with the documentation

Changes since v4

- add sequence numbering to transmitted messages
- add sequence number handling to event hanlding
- add passthrough mode
- change reserved field sizes
- fixed CEC version defines and addec CEC 2.0 commands
- add DocBook documentation

Changes since v3

- remove the promiscuous mode
- rewrite the devicetree patches
- fixes, expansion and partial rewrite of the documentation
- reorder of API structures and addition of reserved fields
- use own struct to report time (32/64 bit safe)
- fix of handling events
- add cec.h to include/uapi/linux/Kbuild
- fixes in the adv76xx driver (add missing methods, change adv7604 to adv76xx)
- cleanup of debug messages in s5p-cec driver
- remove non necessary claiming of a gpio in the s5p-cec driver
- cleanup headers of the s5p-cec driver

Changes since v2
===-
- added promiscuous mode
- added new key codes to the input framework
- add vendor ID reporting
- add the possibility to clear assigned logical addresses
- cleanup of the rc cec map

Changes since v1

- documentation edited and moved to the Documentation folder
- added key up/down message handling
- add missing CEC commands to the cec.h file

Background
==

The work on a common CEC framework was started over three years ago by Hans
Verkuil. Unfortunately the work has stalled. As I have received the task of
creating a driver for the CEC interface module present on the Exynos range of
SoCs, I got in touch with Hans. He replied that the work stalled due to his
lack of time.

Original RFC by Hans Verkuil/Martin Bugge
=
https://www.mail-archive.com/linux-media@vger.kernel.org/msg28735.html


Hans Verkuil (10):
  input.h: add BUS_CEC type
  cec: add HDMI CEC framework
  cec: add compat32 ioctl support
  cec.txt: add CEC framework documentation
  DocBook/media: add CEC documentation
  v4l2-subdev: add HDMI CEC ops
  cec: adv7604: add cec support.
  cec: adv7842: add cec support
  cec: adv7511: add cec support.
  cobalt: add cec support

Kamil Debski (6):
  dts: exynos4*: add HDMI CEC pin definition to pinctrl
  dts: exynos4: add node for the HDMI CEC device
  dts: exynos4412-odroid*: enable the HDMI CEC device
  HID: add HDMI CEC specific keycodes
  rc: Add HDMI CEC protocol handling
  cec: s5p-cec: Add s5p-cec driver

 Documentation/DocBook/device-drivers.tmpl  |3 +
 Documentation/DocBook/media/Makefile   |2 +
 Documentation/DocBook/media/v4l/biblio.xml |   10 +
 Documentation/DocBook/media/v4l/cec-api.xml|   76 +
 Documentation/DocBook/media/v4l/cec-func-close.xml |   59 +
 Documentation/DocBook/media/v4l/cec-func-ioctl.xml |   73 +
 Documentation/DocBook/media/v4l/cec-func-open.xml  |   94 +
 Documentation/DocBook/media/v4l/cec-func-poll.xml  |   89 +
 .../DocBook/media/v4l/cec-ioc-adap-g-caps.xml  |  167 ++
 .../DocBook/media/v4l/cec-ioc-adap-g-log-addrs.xml |  306 +++
 .../DocBook/media/v4l/cec-ioc-adap-g-phys-addr.xml |   80 +
 .../DocBook/media/v4l/cec-ioc-adap-g-state.xml |   87 +
 .../DocBook/media/v4l/cec-ioc-adap-g-vendor-id.xml |  

[PATCHv10 03/16] dts: exynos4412-odroid*: enable the HDMI CEC device

2015-11-12 Thread Hans Verkuil
From: Kamil Debski <ka...@wypas.org>

Add a dts node entry and enable the HDMI CEC device present in the Exynos4
family of SoCs.

Signed-off-by: Kamil Debski <ka...@wypas.org>
Signed-off-by: Hans Verkuil <hans.verk...@cisco.com>
Acked-by: Krzysztof Kozlowski <k.kozlow...@samsung.com>
---
 arch/arm/boot/dts/exynos4210-universal_c210.dts | 4 
 1 file changed, 4 insertions(+)

diff --git a/arch/arm/boot/dts/exynos4210-universal_c210.dts 
b/arch/arm/boot/dts/exynos4210-universal_c210.dts
index eb37952..5c4393d 100644
--- a/arch/arm/boot/dts/exynos4210-universal_c210.dts
+++ b/arch/arm/boot/dts/exynos4210-universal_c210.dts
@@ -222,6 +222,10 @@
enable-active-high;
};
 
+   cec@100B {
+   status = "okay";
+   };
+
hdmi_ddc: i2c-ddc {
compatible = "i2c-gpio";
gpios = < 2 0  3 0>;
-- 
2.6.2

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


[PATCHv10 05/16] HID: add HDMI CEC specific keycodes

2015-11-12 Thread Hans Verkuil
From: Kamil Debski <ka...@wypas.org>

Add HDMI CEC specific keycodes to the keycodes definition.

Signed-off-by: Kamil Debski <ka...@wypas.org>
Signed-off-by: Hans Verkuil <hans.verk...@cisco.com>
---
 include/uapi/linux/input.h | 28 
 1 file changed, 28 insertions(+)

diff --git a/include/uapi/linux/input.h b/include/uapi/linux/input.h
index a32bff1..5e7019a 100644
--- a/include/uapi/linux/input.h
+++ b/include/uapi/linux/input.h
@@ -752,6 +752,34 @@ struct input_keymap_entry {
 #define KEY_KBDINPUTASSIST_ACCEPT  0x264
 #define KEY_KBDINPUTASSIST_CANCEL  0x265
 
+#define KEY_RIGHT_UP   0x266
+#define KEY_RIGHT_DOWN 0x267
+#define KEY_LEFT_UP0x268
+#define KEY_LEFT_DOWN  0x269
+#define KEY_ROOT_MENU  0x26a /* Show Device's Root Menu */
+#define KEY_MEDIA_TOP_MENU 0x26b /* Show Top Menu of the Media 
(e.g. DVD) */
+#define KEY_NUMERIC_11 0x26c
+#define KEY_NUMERIC_12 0x26d
+/*
+ * Toggle Audio Description: refers to an audio service that helps blind and
+ * visually impaired consumers understand the action in a program. Note: in
+ * some countries this is referred to as "Video Description".
+ */
+#define KEY_AUDIO_DESC 0x26e
+#define KEY_3D_MODE0x26f
+#define KEY_NEXT_FAVORITE  0x270
+#define KEY_STOP_RECORD0x271
+#define KEY_PAUSE_RECORD   0x272
+#define KEY_VOD0x273 /* Video on Demand */
+#define KEY_UNMUTE 0x274
+#define KEY_FASTREVERSE0x275
+#define KEY_SLOWREVERSE0x276
+/*
+ * Control a data application associated with the currently viewed channel,
+ * e.g. teletext or data broadcast application (MHEG, MHP, HbbTV, etc.)
+ */
+#define KEY_DATA   0x275
+
 #define BTN_TRIGGER_HAPPY  0x2c0
 #define BTN_TRIGGER_HAPPY1 0x2c0
 #define BTN_TRIGGER_HAPPY2 0x2c1
-- 
2.6.2

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


[PATCHv10 15/16] cec: s5p-cec: Add s5p-cec driver

2015-11-12 Thread Hans Verkuil
From: Kamil Debski <ka...@wypas.org>

Add CEC interface driver present in the Samsung Exynos range of
SoCs.

The following files were based on work by SangPil Moon:
- exynos_hdmi_cec.h
- exynos_hdmi_cecctl.c

Signed-off-by: Kamil Debski <ka...@wypas.org>
Signed-off-by: Hans Verkuil <hans.verk...@cisco.com>
---
 .../devicetree/bindings/media/s5p-cec.txt  |  31 +++
 drivers/media/platform/Kconfig |  12 +
 drivers/media/platform/Makefile|   1 +
 drivers/media/platform/s5p-cec/Makefile|   2 +
 drivers/media/platform/s5p-cec/exynos_hdmi_cec.h   |  37 +++
 .../media/platform/s5p-cec/exynos_hdmi_cecctrl.c   | 208 +++
 drivers/media/platform/s5p-cec/regs-cec.h  |  96 +++
 drivers/media/platform/s5p-cec/s5p_cec.c   | 289 +
 drivers/media/platform/s5p-cec/s5p_cec.h   |  76 ++
 9 files changed, 752 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/s5p-cec.txt
 create mode 100644 drivers/media/platform/s5p-cec/Makefile
 create mode 100644 drivers/media/platform/s5p-cec/exynos_hdmi_cec.h
 create mode 100644 drivers/media/platform/s5p-cec/exynos_hdmi_cecctrl.c
 create mode 100644 drivers/media/platform/s5p-cec/regs-cec.h
 create mode 100644 drivers/media/platform/s5p-cec/s5p_cec.c
 create mode 100644 drivers/media/platform/s5p-cec/s5p_cec.h

diff --git a/Documentation/devicetree/bindings/media/s5p-cec.txt 
b/Documentation/devicetree/bindings/media/s5p-cec.txt
new file mode 100644
index 000..925ab4d
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/s5p-cec.txt
@@ -0,0 +1,31 @@
+* Samsung HDMI CEC driver
+
+The HDMI CEC module is present is Samsung SoCs and its purpose is to
+handle communication between HDMI connected devices over the CEC bus.
+
+Required properties:
+  - compatible : value should be following
+   "samsung,s5p-cec"
+
+  - reg : Physical base address of the IP registers and length of memory
+ mapped region.
+
+  - interrupts : HDMI CEC interrupt number to the CPU.
+  - clocks : from common clock binding: handle to HDMI CEC clock.
+  - clock-names : from common clock binding: must contain "hdmicec",
+ corresponding to entry in the clocks property.
+  - samsung,syscon-phandle - phandle to the PMU system controller
+
+Example:
+
+hdmicec: cec@100B {
+   compatible = "samsung,s5p-cec";
+   reg = <0x100B 0x200>;
+   interrupts = <0 114 0>;
+   clocks = < CLK_HDMI_CEC>;
+   clock-names = "hdmicec";
+   samsung,syscon-phandle = <_system_controller>;
+   pinctrl-names = "default";
+   pinctrl-0 = <_cec>;
+   status = "okay";
+};
diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index ccbc974..91794a6 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -117,6 +117,18 @@ config VIDEO_S3C_CAMIF
 source "drivers/media/platform/soc_camera/Kconfig"
 source "drivers/media/platform/exynos4-is/Kconfig"
 source "drivers/media/platform/s5p-tv/Kconfig"
+
+config VIDEO_SAMSUNG_S5P_CEC
+   tristate "Samsung S5P CEC driver"
+   depends on VIDEO_DEV && VIDEO_V4L2 && (PLAT_S5P || ARCH_EXYNOS || 
COMPILE_TEST)
+   select MEDIA_CEC
+   default n
+   ---help---
+ This is a driver for Samsung S5P HDMI CEC interface. It uses the
+ generic CEC framework interface.
+ CEC bus is present in the HDMI connector and enables communication
+ between compatible devices.
+
 source "drivers/media/platform/am437x/Kconfig"
 source "drivers/media/platform/xilinx/Kconfig"
 
diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile
index efa0295..957af5f 100644
--- a/drivers/media/platform/Makefile
+++ b/drivers/media/platform/Makefile
@@ -27,6 +27,7 @@ obj-$(CONFIG_VIDEO_MEM2MEM_DEINTERLACE)   += 
m2m-deinterlace.o
 
 obj-$(CONFIG_VIDEO_S3C_CAMIF)  += s3c-camif/
 obj-$(CONFIG_VIDEO_SAMSUNG_EXYNOS4_IS) += exynos4-is/
+obj-$(CONFIG_VIDEO_SAMSUNG_S5P_CEC)+= s5p-cec/
 obj-$(CONFIG_VIDEO_SAMSUNG_S5P_JPEG)   += s5p-jpeg/
 obj-$(CONFIG_VIDEO_SAMSUNG_S5P_MFC)+= s5p-mfc/
 obj-$(CONFIG_VIDEO_SAMSUNG_S5P_TV) += s5p-tv/
diff --git a/drivers/media/platform/s5p-cec/Makefile 
b/drivers/media/platform/s5p-cec/Makefile
new file mode 100644
index 000..0e2cf45
--- /dev/null
+++ b/drivers/media/platform/s5p-cec/Makefile
@@ -0,0 +1,2 @@
+obj-$(CONFIG_VIDEO_SAMSUNG_S5P_CEC)+= s5p-cec.o
+s5p-cec-y += s5p_cec.o exynos_hdmi_cecctrl.o
diff --git a/drivers/media/platform/s5p-cec/exynos_hdmi_cec.h 
b/drivers/media/platform/s5p-cec/exynos_hdmi_cec.h
new file mode 100644
index 000..d008695
--- /dev/null
+++ b/drivers/media/platform/s5p-cec/exynos_hdmi_cec.h
@@ -0,0 +1,37 @@
+/* drivers/media/plat

[PATCHv10 12/16] cec: adv7604: add cec support.

2015-11-12 Thread Hans Verkuil
From: Hans Verkuil <hans.verk...@cisco.com>

Add CEC support to the adv7604 driver.

Signed-off-by: Hans Verkuil <hansv...@cisco.com>
[k.deb...@samsung.com: Merged changes from CEC Updates commit by Hans Verkuil]
[k.deb...@samsung.com: add missing methods cec/io_write_and_or]
[k.deb...@samsung.com: change adv7604 to adv76xx in added functions]
[hansv...@cisco.com: use _clr_set instead of _and_or]
---
 drivers/media/i2c/adv7604.c | 241 +++-
 1 file changed, 237 insertions(+), 4 deletions(-)

diff --git a/drivers/media/i2c/adv7604.c b/drivers/media/i2c/adv7604.c
index 5631ec0..f039ae6 100644
--- a/drivers/media/i2c/adv7604.c
+++ b/drivers/media/i2c/adv7604.c
@@ -40,6 +40,7 @@
 #include 
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -80,6 +81,8 @@ MODULE_LICENSE("GPL");
 
 #define ADV76XX_OP_SWAP_CB_CR  (1 << 0)
 
+#define ADV76XX_MAX_ADDRS (3)
+
 enum adv76xx_type {
ADV7604,
ADV7611,
@@ -184,6 +187,10 @@ struct adv76xx_state {
u16 spa_port_a[2];
struct v4l2_fract aspect_ratio;
u32 rgb_quantization_range;
+   u8   cec_addr[ADV76XX_MAX_ADDRS];
+   u8   cec_valid_addrs;
+   bool cec_enabled_adap;
+
struct workqueue_struct *work_queues;
struct delayed_work delayed_work_enable_hotplug;
bool restart_stdi_once;
@@ -430,7 +437,8 @@ static inline int io_write(struct v4l2_subdev *sd, u8 reg, 
u8 val)
return regmap_write(state->regmap[ADV76XX_PAGE_IO], reg, val);
 }
 
-static inline int io_write_clr_set(struct v4l2_subdev *sd, u8 reg, u8 mask, u8 
val)
+static inline int io_write_clr_set(struct v4l2_subdev *sd, u8 reg, u8 mask,
+  u8 val)
 {
return io_write(sd, reg, (io_read(sd, reg) & ~mask) | val);
 }
@@ -463,6 +471,12 @@ static inline int cec_write(struct v4l2_subdev *sd, u8 
reg, u8 val)
return regmap_write(state->regmap[ADV76XX_PAGE_CEC], reg, val);
 }
 
+static inline int cec_write_clr_set(struct v4l2_subdev *sd, u8 reg, u8 mask,
+  u8 val)
+{
+   return cec_write(sd, reg, (cec_read(sd, reg) & ~mask) | val);
+}
+
 static inline int infoframe_read(struct v4l2_subdev *sd, u8 reg)
 {
struct adv76xx_state *state = to_state(sd);
@@ -550,8 +564,13 @@ static inline int edid_write_block(struct v4l2_subdev *sd,
 
 static void adv76xx_set_hpd(struct adv76xx_state *state, unsigned int hpd)
 {
+   u16 connected_inputs;
unsigned int i;
 
+   connected_inputs = hpd & state->info->read_cable_det(>sd);
+   v4l2_subdev_notify(>sd, V4L2_SUBDEV_CEC_CONN_INPUTS,
+  _inputs);
+
for (i = 0; i < state->info->num_dv_ports; ++i)
gpiod_set_value_cansleep(state->hpd_gpio[i], hpd & BIT(i));
 
@@ -891,9 +910,12 @@ static int adv76xx_s_detect_tx_5v_ctrl(struct v4l2_subdev 
*sd)
 {
struct adv76xx_state *state = to_state(sd);
const struct adv76xx_chip_info *info = state->info;
+   u16 cable_det = info->read_cable_det(sd);
+   u16 connected_inputs = state->edid.present & cable_det;
 
-   return v4l2_ctrl_s_ctrl(state->detect_tx_5v_ctrl,
-   info->read_cable_det(sd));
+   v4l2_subdev_notify(sd, V4L2_SUBDEV_CEC_CONN_INPUTS,
+  _inputs);
+   return v4l2_ctrl_s_ctrl(state->detect_tx_5v_ctrl, cable_det);
 }
 
 static int find_and_set_predefined_video_timings(struct v4l2_subdev *sd,
@@ -1914,6 +1936,187 @@ static int adv76xx_set_format(struct v4l2_subdev *sd,
return 0;
 }
 
+static void adv76xx_cec_tx_raw_status(struct v4l2_subdev *sd, u8 tx_raw_status)
+{
+   if ((cec_read(sd, 0x11) & 0x01) == 0) {
+   v4l2_dbg(1, debug, sd, "%s: tx raw: tx disabled\n", __func__);
+   return;
+   }
+
+   if (tx_raw_status & 0x02) {
+   v4l2_dbg(1, debug, sd, "%s: tx raw: arbitration lost\n",
+__func__);
+   v4l2_subdev_notify(sd, V4L2_SUBDEV_CEC_TX_DONE,
+  (void *)CEC_TX_STATUS_ARB_LOST);
+   return;
+   }
+   if (tx_raw_status & 0x04) {
+   v4l2_dbg(1, debug, sd, "%s: tx raw: retry failed\n", __func__);
+   v4l2_subdev_notify(sd, V4L2_SUBDEV_CEC_TX_DONE,
+  (void *)CEC_TX_STATUS_RETRY_TIMEOUT);
+   return;
+   }
+   if (tx_raw_status & 0x01) {
+   v4l2_dbg(1, debug, sd, "%s: tx raw: ready ok\n", __func__);
+   v4l2_subdev_notify(sd, V4L2_SUBDEV_CEC_TX_DONE,
+  (void *)CEC_TX_STATUS_OK);
+   return;
+   }
+}
+
+static void adv76xx_cec_isr(struct v4l2_subdev *sd, bool *handled)
+{
+   u8 cec_irq;
+
+   /* cec contr

[PATCHv10 01/16] dts: exynos4*: add HDMI CEC pin definition to pinctrl

2015-11-12 Thread Hans Verkuil
From: Kamil Debski <ka...@wypas.org>

Add pinctrl nodes for the HDMI CEC device to the Exynos4210 and
Exynos4x12 SoCs. These are required by the HDMI CEC device.

Signed-off-by: Kamil Debski <ka...@wypas.org>
Signed-off-by: Hans Verkuil <hans.verk...@cisco.com>
Acked-by: Krzysztof Kozlowski <k.kozlow...@samsung.com>
---
 arch/arm/boot/dts/exynos4210-pinctrl.dtsi | 7 +++
 arch/arm/boot/dts/exynos4x12-pinctrl.dtsi | 7 +++
 2 files changed, 14 insertions(+)

diff --git a/arch/arm/boot/dts/exynos4210-pinctrl.dtsi 
b/arch/arm/boot/dts/exynos4210-pinctrl.dtsi
index a7c2128..9331c62 100644
--- a/arch/arm/boot/dts/exynos4210-pinctrl.dtsi
+++ b/arch/arm/boot/dts/exynos4210-pinctrl.dtsi
@@ -820,6 +820,13 @@
samsung,pin-pud = <1>;
samsung,pin-drv = <0>;
};
+
+   hdmi_cec: hdmi-cec {
+   samsung,pins = "gpx3-6";
+   samsung,pin-function = <3>;
+   samsung,pin-pud = <0>;
+   samsung,pin-drv = <0>;
+   };
};
 
pinctrl@0386 {
diff --git a/arch/arm/boot/dts/exynos4x12-pinctrl.dtsi 
b/arch/arm/boot/dts/exynos4x12-pinctrl.dtsi
index bac25c6..856b292 100644
--- a/arch/arm/boot/dts/exynos4x12-pinctrl.dtsi
+++ b/arch/arm/boot/dts/exynos4x12-pinctrl.dtsi
@@ -885,6 +885,13 @@
samsung,pin-pud = <0>;
samsung,pin-drv = <0>;
};
+
+   hdmi_cec: hdmi-cec {
+   samsung,pins = "gpx3-6";
+   samsung,pin-function = <3>;
+   samsung,pin-pud = <0>;
+   samsung,pin-drv = <0>;
+   };
};
 
pinctrl_2: pinctrl@0386 {
-- 
2.6.2

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


[PATCHv10 08/16] cec: add compat32 ioctl support

2015-11-12 Thread Hans Verkuil
From: Hans Verkuil <hans.verk...@cisco.com>

The CEC ioctls didn't have compat32 support, so they returned -ENOTTY
when used in a 32 bit application on a 64 bit kernel.

Since all the CEC ioctls are 32-bit compatible adding support for this
API is trivial.

Signed-off-by: Hans Verkuil <hans.verk...@cisco.com>
---
 fs/compat_ioctl.c | 19 +++
 1 file changed, 19 insertions(+)

diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
index 48851f6..c8651aa 100644
--- a/fs/compat_ioctl.c
+++ b/fs/compat_ioctl.c
@@ -57,6 +57,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -1381,6 +1382,24 @@ COMPATIBLE_IOCTL(VIDEO_GET_NAVI)
 COMPATIBLE_IOCTL(VIDEO_SET_ATTRIBUTES)
 COMPATIBLE_IOCTL(VIDEO_GET_SIZE)
 COMPATIBLE_IOCTL(VIDEO_GET_FRAME_RATE)
+/* cec */
+COMPATIBLE_IOCTL(CEC_ADAP_G_CAPS)
+COMPATIBLE_IOCTL(CEC_ADAP_G_LOG_ADDRS)
+COMPATIBLE_IOCTL(CEC_ADAP_S_LOG_ADDRS)
+COMPATIBLE_IOCTL(CEC_ADAP_G_STATE)
+COMPATIBLE_IOCTL(CEC_ADAP_S_STATE)
+COMPATIBLE_IOCTL(CEC_ADAP_G_PHYS_ADDR)
+COMPATIBLE_IOCTL(CEC_ADAP_S_PHYS_ADDR)
+COMPATIBLE_IOCTL(CEC_ADAP_G_VENDOR_ID)
+COMPATIBLE_IOCTL(CEC_ADAP_S_VENDOR_ID)
+COMPATIBLE_IOCTL(CEC_G_MONITOR)
+COMPATIBLE_IOCTL(CEC_S_MONITOR)
+COMPATIBLE_IOCTL(CEC_CLAIM)
+COMPATIBLE_IOCTL(CEC_RELEASE)
+COMPATIBLE_IOCTL(CEC_G_PASSTHROUGH)
+COMPATIBLE_IOCTL(CEC_TRANSMIT)
+COMPATIBLE_IOCTL(CEC_RECEIVE)
+COMPATIBLE_IOCTL(CEC_DQEVENT)
 
 /* joystick */
 COMPATIBLE_IOCTL(JSIOCGVERSION)
-- 
2.6.2

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


[PATCHv10 06/16] rc: Add HDMI CEC protocol handling

2015-11-12 Thread Hans Verkuil
From: Kamil Debski <ka...@wypas.org>

Add handling of remote control events coming from the HDMI CEC bus.
This patch includes a new keymap that maps values found in the CEC
messages to the keys pressed and released. Also, a new protocol has
been added to the core.

Signed-off-by: Kamil Debski <ka...@wypas.org>
Signed-off-by: Hans Verkuil <hans.verk...@cisco.com>
---
 drivers/media/rc/keymaps/Makefile |   1 +
 drivers/media/rc/keymaps/rc-cec.c | 174 ++
 drivers/media/rc/rc-main.c|   1 +
 include/media/rc-core.h   |   1 +
 include/media/rc-map.h|   5 +-
 5 files changed, 181 insertions(+), 1 deletion(-)
 create mode 100644 drivers/media/rc/keymaps/rc-cec.c

diff --git a/drivers/media/rc/keymaps/Makefile 
b/drivers/media/rc/keymaps/Makefile
index fbbd3bb..9cffcc6 100644
--- a/drivers/media/rc/keymaps/Makefile
+++ b/drivers/media/rc/keymaps/Makefile
@@ -18,6 +18,7 @@ obj-$(CONFIG_RC_MAP) += rc-adstech-dvb-t-pci.o \
rc-behold.o \
rc-behold-columbus.o \
rc-budget-ci-old.o \
+   rc-cec.o \
rc-cinergy-1400.o \
rc-cinergy.o \
rc-delock-61959.o \
diff --git a/drivers/media/rc/keymaps/rc-cec.c 
b/drivers/media/rc/keymaps/rc-cec.c
new file mode 100644
index 000..193cdca
--- /dev/null
+++ b/drivers/media/rc/keymaps/rc-cec.c
@@ -0,0 +1,174 @@
+/* Keytable for the CEC remote control
+ *
+ * Copyright (c) 2015 by Kamil Debski
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include 
+#include 
+
+/* CEC Spec "High-Definition Multimedia Interface Specification" can be 
obtained
+ * here: http://xtreamerdev.googlecode.com/files/CEC_Specs.pdf
+ * The list of control codes is listed in Table 27: User Control Codes p. 95 */
+
+static struct rc_map_table cec[] = {
+   { 0x00, KEY_OK },
+   { 0x01, KEY_UP },
+   { 0x02, KEY_DOWN },
+   { 0x03, KEY_LEFT },
+   { 0x04, KEY_RIGHT },
+   { 0x05, KEY_RIGHT_UP },
+   { 0x06, KEY_RIGHT_DOWN },
+   { 0x07, KEY_LEFT_UP },
+   { 0x08, KEY_LEFT_DOWN },
+   { 0x09, KEY_ROOT_MENU }, /* CEC Spec: Device Root Menu - see Note 2 */
+   /* Note 2: This is the initial display that a device shows. It is
+* device-dependent and can be, for example, a contents menu, setup
+* menu, favorite menu or other menu. The actual menu displayed
+* may also depend on the device's current state. */
+   { 0x0a, KEY_SETUP },
+   { 0x0b, KEY_MENU }, /* CEC Spec: Contents Menu */
+   { 0x0c, KEY_FAVORITES }, /* CEC Spec: Favorite Menu */
+   { 0x0d, KEY_EXIT },
+   /* 0x0e-0x0f: Reserved */
+   { 0x10, KEY_MEDIA_TOP_MENU },
+   { 0x11, KEY_CONTEXT_MENU },
+   /* 0x12-0x1c: Reserved */
+   { 0x1d, KEY_DIGITS }, /* CEC Spec: select/toggle a Number Entry Mode */
+   { 0x1e, KEY_NUMERIC_11 },
+   { 0x1f, KEY_NUMERIC_12 },
+   /* 0x20-0x29: Keys 0 to 9 */
+   { 0x20, KEY_NUMERIC_0 },
+   { 0x21, KEY_NUMERIC_1 },
+   { 0x22, KEY_NUMERIC_2 },
+   { 0x23, KEY_NUMERIC_3 },
+   { 0x24, KEY_NUMERIC_4 },
+   { 0x25, KEY_NUMERIC_5 },
+   { 0x26, KEY_NUMERIC_6 },
+   { 0x27, KEY_NUMERIC_7 },
+   { 0x28, KEY_NUMERIC_8 },
+   { 0x29, KEY_NUMERIC_9 },
+   { 0x2a, KEY_DOT },
+   { 0x2b, KEY_ENTER },
+   { 0x2c, KEY_CLEAR },
+   /* 0x2d-0x2e: Reserved */
+   { 0x2f, KEY_NEXT_FAVORITE }, /* CEC Spec: Next Favorite */
+   { 0x30, KEY_CHANNELUP },
+   { 0x31, KEY_CHANNELDOWN },
+   { 0x32, KEY_PREVIOUS }, /* CEC Spec: Previous Channel */
+   { 0x33, KEY_SOUND }, /* CEC Spec: Sound Select */
+   { 0x34, KEY_VIDEO }, /* 0x34: CEC Spec: Input Select */
+   { 0x35, KEY_INFO }, /* CEC Spec: Display Information */
+   { 0x36, KEY_HELP },
+   { 0x37, KEY_PAGEUP },
+   { 0x38, KEY_PAGEDOWN },
+   /* 0x39-0x3f: Reserved */
+   { 0x40, KEY_POWER },
+   { 0x41, KEY_VOLUMEUP },
+   { 0x42, KEY_VOLUMEDOWN },
+   { 0x43, KEY_MUTE },
+   { 0x44, KEY_PLAYCD },
+   { 0x45, KEY_STOPCD },
+   { 0x46, KEY_PAUSECD },
+   { 0x47, KEY_RECORD },
+   { 0x48, KEY_REWIND },
+   { 0x49, KEY_FASTFORWARD },
+   { 0x4a, KEY_EJECTCD }, /* CEC Spec: Eject */
+   { 0x4b, KEY_FORWARD },
+   { 0x4c, KEY_BACK },
+   { 0x4d, KEY_STOP_RECORD }, /* CEC Spec: Stop-Record */
+   { 0x4e, KEY_PAUSE_RECORD }, /* CEC Spec: Pause-Record */
+   /* 0x4f: Reserved */
+   { 0x50, KEY_ANGLE },
+   { 0x51, KEY_TV2 },
+   { 0x52, KEY_VOD }, /* CEC Spec: Video on Demand */
+   { 0x53, KEY_EPG },
+   { 0x54, KE

[PATCHv10 09/16] cec.txt: add CEC framework documentation

2015-11-12 Thread Hans Verkuil
Document the new HDMI CEC framework.

Signed-off-by: Hans Verkuil <hansv...@cisco.com>
[k.deb...@samsung.com: add DocBook documentation by Hans Verkuil, with
Signed-off-by: Kamil Debski <ka...@wypas.org>
Signed-off-by: Hans Verkuil <hans.verk...@cisco.com>
---
 Documentation/cec.txt | 326 ++
 1 file changed, 326 insertions(+)
 create mode 100644 Documentation/cec.txt

diff --git a/Documentation/cec.txt b/Documentation/cec.txt
new file mode 100644
index 000..90c2c7f
--- /dev/null
+++ b/Documentation/cec.txt
@@ -0,0 +1,326 @@
+CEC Kernel Support
+==
+
+The CEC framework provides a unified kernel interface for use with HDMI CEC
+hardware. It is designed to handle a multiple types of hardware (receivers,
+transmitters, USB dongles). The framework also gives the option to decide
+what to do in the kernel driver and what should be handled by userspace
+applications. In addition it integrates the remote control passthrough
+feature into the kernel's remote control framework.
+
+
+The CEC Protocol
+
+
+The CEC protocol enables consumer electronic devices to communicate with each
+other through the HDMI connection. The protocol uses logical addresses in the
+communication. The logical address is strictly connected with the functionality
+provided by the device. The TV acting as the communication hub is always
+assigned address 0. The physical address is determined by the physical
+connection between devices.
+
+The CEC framework described here is up to date with the CEC 2.0 specification.
+It is documented in the HDMI 1.4 specification with the new 2.0 bits documented
+in the HDMI 2.0 specification. But for most of the features the freely 
available
+HDMI 1.3a specification is sufficient:
+
+http://www.microprocessor.org/HDMISpecification13a.pdf
+
+
+The Kernel Interface
+
+
+CEC Adapter
+---
+
+The struct cec_adapter represents the CEC adapter hardware. It is created by
+calling cec_create_adapter() and deleted by calling cec_delete_adapter():
+
+struct cec_adapter *cec_create_adapter(const struct cec_adap_ops *ops,
+  void *priv, const char *name, u32 caps,
+  u8 ninputs, struct module *owner, struct device *parent);
+void cec_delete_adapter(struct cec_adapter *adap);
+
+To create an adapter you need to pass the following information:
+
+ops: adapter operations which are called by the CEC framework and that you
+have to implement.
+
+priv: will be stored in adap->priv and can be used by the adapter ops.
+
+name: the name of the CEC adapter
+
+caps: capabilities of the CEC adapter. These capabilities determine the
+   capabilities of the hardware and which parts are to be handled
+   by userspace and which parts are handled by kernelspace. The
+   capabilities are returned by CEC_ADAP_G_CAPS.
+
+ninputs: the number of HDMI inputs of the device. This may be 0. This
+   is returned by CEC_ADAP_G_CAPS.
+
+owner: the module owner.
+
+parent: the parent device.
+
+
+After creating the adapter the driver can modify the following fields
+in struct cec_adapter:
+
+   u8 available_log_addrs;
+
+This determines the number of simultaneous logical addresses the hardware
+can program. Often this is 1, which is also the default.
+
+   u8 pwr_state;
+
+The CEC_MSG_GIVE_DEVICE_POWER_STATUS power state. By default this is
+CEC_OP_POWER_STATUS_ON (0). The driver can change this to signal power
+state transitions.
+
+   u16 phys_addr;
+
+By default this is 0x, but drivers can change this. The phys_addr field
+must be set before the CEC adapter is enabled (see the adap_enable op below).
+While the CEC adapter remains enabled it cannot be changed. Drivers never set
+this if CEC_CAP_PHYS_ADDR is set.
+
+   u32 vendor_id;
+
+By default this is CEC_VENDOR_ID_NONE (0x). It should not be changed
+once the adapter is configured. Drivers never set this if CEC_CAP_VENDOR_ID
+is set.
+
+   u8 cec_version;
+
+The CEC version that the framework should support. By default this is the
+latest version, but it can be changed to an older version, causing attempts
+to use later extensions to fail. Obviously this should be set before the
+CEC adapter is enabled.
+
+To register the /dev/cecX device node and the remote control device (if
+CEC_CAP_RC is set) you call:
+
+int cec_register_adapter(struct cec_adapter *adap);
+
+To unregister the devices call:
+
+void cec_unregister_adapter(struct cec_adapter *adap);
+
+
+Implementing the Low-Level CEC Adapter
+--
+
+The following low-level adapter operations have to be implemented in
+your driver:
+
+struct cec_adap_ops {
+   /* Low-level callbacks */
+   int (*adap_enable)(struct cec_adapter *adap, bool enable);
+   int (*adap_log_addr)(struct cec_adapter *adap, u8 logical_addr);
+   int (*adap_transmit)(struct cec_adapter *adap, u

[PATCHv10 11/16] v4l2-subdev: add HDMI CEC ops

2015-11-12 Thread Hans Verkuil
From: Hans Verkuil <hans.verk...@cisco.com>

Add CEC callbacks to the new v4l2_subdev_cec_ops struct. These are the
low-level CEC ops that subdevs that support CEC have to implement.

Signed-off-by: Hans Verkuil <hansv...@cisco.com>
[k.deb...@samsung.com: Merged changes from CEC Updates commit by Hans Verkuil]
Signed-off-by: Kamil Debski <ka...@wypas.org>
---
 include/media/v4l2-subdev.h | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
index b273cf9..e55031e 100644
--- a/include/media/v4l2-subdev.h
+++ b/include/media/v4l2-subdev.h
@@ -42,6 +42,10 @@
 
 #defineV4L2_DEVICE_NOTIFY_EVENT_IOW('v', 2, struct 
v4l2_event)
 
+#define V4L2_SUBDEV_CEC_TX_DONE_IOW('v', 3, u32)
+#define V4L2_SUBDEV_CEC_RX_MSG _IOW('v', 4, struct cec_msg)
+#define V4L2_SUBDEV_CEC_CONN_INPUTS_IOW('v', 5, u16)
+
 struct v4l2_device;
 struct v4l2_ctrl_handler;
 struct v4l2_event;
@@ -51,6 +55,7 @@ struct v4l2_subdev;
 struct v4l2_subdev_fh;
 struct tuner_setup;
 struct v4l2_mbus_frame_desc;
+struct cec_msg;
 
 /* decode_vbi_line */
 struct v4l2_decode_vbi_line {
@@ -642,6 +647,14 @@ struct v4l2_subdev_pad_ops {
  struct v4l2_mbus_frame_desc *fd);
 };
 
+struct v4l2_subdev_cec_ops {
+   unsigned (*available_log_addrs)(struct v4l2_subdev *sd);
+   int (*enable)(struct v4l2_subdev *sd, bool enable);
+   int (*log_addr)(struct v4l2_subdev *sd, u8 logical_addr);
+   int (*transmit)(struct v4l2_subdev *sd, u32 timeout_ms,
+   u8 retries, struct cec_msg *msg);
+};
+
 struct v4l2_subdev_ops {
const struct v4l2_subdev_core_ops   *core;
const struct v4l2_subdev_tuner_ops  *tuner;
@@ -651,6 +664,7 @@ struct v4l2_subdev_ops {
const struct v4l2_subdev_ir_ops *ir;
const struct v4l2_subdev_sensor_ops *sensor;
const struct v4l2_subdev_pad_ops*pad;
+   const struct v4l2_subdev_cec_ops*cec;
 };
 
 /*
-- 
2.6.2

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


[PATCHv10 16/16] cobalt: add cec support

2015-11-12 Thread Hans Verkuil
From: Hans Verkuil <hans.verk...@cisco.com>

Add CEC support to the cobalt driver.

Signed-off-by: Hans Verkuil <hans.verk...@cisco.com>
---
 drivers/media/pci/cobalt/Kconfig |   1 +
 drivers/media/pci/cobalt/cobalt-driver.c | 108 +-
 drivers/media/pci/cobalt/cobalt-driver.h |   2 +
 drivers/media/pci/cobalt/cobalt-irq.c|   3 +
 drivers/media/pci/cobalt/cobalt-v4l2.c   | 126 ---
 drivers/media/pci/cobalt/cobalt-v4l2.h   |   2 +
 6 files changed, 216 insertions(+), 26 deletions(-)

diff --git a/drivers/media/pci/cobalt/Kconfig b/drivers/media/pci/cobalt/Kconfig
index a01f0cc..9125747 100644
--- a/drivers/media/pci/cobalt/Kconfig
+++ b/drivers/media/pci/cobalt/Kconfig
@@ -4,6 +4,7 @@ config VIDEO_COBALT
depends on PCI_MSI && MTD_COMPLEX_MAPPINGS
depends on GPIOLIB || COMPILE_TEST
depends on SND
+   select MEDIA_CEC
select I2C_ALGOBIT
select VIDEO_ADV7604
select VIDEO_ADV7511
diff --git a/drivers/media/pci/cobalt/cobalt-driver.c 
b/drivers/media/pci/cobalt/cobalt-driver.c
index 8fed61e..0b9e194 100644
--- a/drivers/media/pci/cobalt/cobalt-driver.c
+++ b/drivers/media/pci/cobalt/cobalt-driver.c
@@ -76,6 +76,7 @@ static u8 edid[256] = {
0x0A, 0x0A, 0x0A, 0x0A, 0x00, 0x00, 0x00, 0x10,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x68,
+
0x02, 0x03, 0x1a, 0xc0, 0x48, 0xa2, 0x10, 0x04,
0x02, 0x01, 0x21, 0x14, 0x13, 0x23, 0x09, 0x07,
0x07, 0x65, 0x03, 0x0c, 0x00, 0x10, 0x00, 0xe2,
@@ -149,17 +150,44 @@ static void cobalt_notify(struct v4l2_subdev *sd,
struct cobalt *cobalt = to_cobalt(sd->v4l2_dev);
unsigned sd_nr = cobalt_get_sd_nr(sd);
struct cobalt_stream *s = >streams[sd_nr];
-   bool hotplug = arg ? *((int *)arg) : false;
 
-   if (s->is_output)
+   switch (notification) {
+   case V4L2_SUBDEV_CEC_TX_DONE:
+   cec_transmit_done(s->cec_adap, (unsigned long)arg);
+   return;
+   case V4L2_SUBDEV_CEC_RX_MSG:
+   cec_received_msg(s->cec_adap, arg);
+   return;
+   case V4L2_SUBDEV_CEC_CONN_INPUTS:
+   cec_connected_inputs(s->cec_adap, *(u16 *)arg);
+   return;
+   default:
+   break;
+   }
+
+   if (s->is_output) {
+   switch (notification) {
+   case ADV7511_EDID_DETECT: {
+   struct adv7511_edid_detect *ed = arg;
+
+   s->cec_adap->phys_addr = ed->phys_addr;
+   break;
+   }
+   }
return;
+   }
 
switch (notification) {
-   case ADV76XX_HOTPLUG:
+   case ADV76XX_HOTPLUG: {
+   bool hotplug = arg ? *((int *)arg) : false;
+
cobalt_s_bit_sysctrl(cobalt,
COBALT_SYS_CTRL_HPD_TO_CONNECTOR_BIT(sd_nr), hotplug);
+   if (s->cec_adap)
+   cec_connected_inputs(s->cec_adap, hotplug);
cobalt_dbg(1, "Set hotplug for adv %d to %d\n", sd_nr, hotplug);
break;
+   }
case V4L2_DEVICE_NOTIFY_EVENT:
cobalt_dbg(1, "Format changed for adv %d\n", sd_nr);
v4l2_event_queue(>vdev, arg);
@@ -438,12 +466,15 @@ static void cobalt_stream_struct_init(struct cobalt 
*cobalt)
 
for (i = 0; i < COBALT_NUM_STREAMS; i++) {
struct cobalt_stream *s = >streams[i];
+   struct video_device *vdev = >vdev;
 
s->cobalt = cobalt;
s->flags = 0;
s->is_audio = false;
s->is_output = false;
s->is_dummy = true;
+   snprintf(vdev->name, sizeof(vdev->name),
+"%s-%d", cobalt->v4l2_dev.name, i);
 
/* The Memory DMA channels will always get a lower channel
 * number than the FIFO DMA. Video input should map to the
@@ -485,6 +516,23 @@ static void cobalt_stream_struct_init(struct cobalt 
*cobalt)
}
 }
 
+static int cobalt_create_cec_adap(struct cobalt_stream *s)
+{
+   u32 caps = CEC_CAP_IO | CEC_CAP_LOG_ADDRS |
+   CEC_CAP_PASSTHROUGH | CEC_CAP_RC |
+   CEC_CAP_ARC | CEC_CAP_VENDOR_ID;
+   u8 nsinks = 0;
+
+   if (s->is_output)
+   caps |= CEC_CAP_IS_SOURCE | CEC_CAP_CDC_HPD;
+   else
+   nsinks = 1;
+   s->cec_adap = cec_create_adapter(_cec_adap_ops,
+s, s->vdev.name, caps, nsinks,
+THIS_MODULE, >cobalt->pci_dev->dev);
+   return PTR_ERR_OR_ZERO(s->cec_adap);
+}
+
 static int cobalt_subdevs_init(struct cobalt *coba

Re: [PATCHv9 06/15] rc: Add HDMI CEC protocol handling

2015-10-14 Thread Hans Verkuil
On 10/14/2015 01:09 AM, Russell King - ARM Linux wrote:
> On Mon, Oct 12, 2015 at 01:50:47PM +0200, Hans Verkuil wrote:
>> On 10/06/2015 08:05 PM, Russell King - ARM Linux wrote:
>>> On Mon, Sep 07, 2015 at 03:44:35PM +0200, Hans Verkuil wrote:
>>>> From: Kamil Debski <ka...@wypas.org>
>>>>
>>>> Add handling of remote control events coming from the HDMI CEC bus.
>>>> This patch includes a new keymap that maps values found in the CEC
>>>> messages to the keys pressed and released. Also, a new protocol has
>>>> been added to the core.
>>>>
>>>> Signed-off-by: Kamil Debski <ka...@wypas.org>
>>>> Signed-off-by: Hans Verkuil <hans.verk...@cisco.com>
>>>
>>> (Added Mauro)
>>>
>>> Hmm, how is rc-cec supposed to be loaded?
>>
>> Is CONFIG_RC_MAP enabled in your config? Ran 'depmod -a'? (Sorry, I'm sure 
>> you've done
>> that, just checking...)
> 
> CONFIG_RC_MAP=m
> 
> and yes, if depmod hadn't have been run, modprobing rc-cec would not
> have worked - modprobe always looks up in the depmod information to
> find out where the module is located, and also to determine any
> dependencies.
> 
>> It's optional as I understand it, since you could configure the keytable from
>> userspace instead of using this module.
>>
>> For the record (just tried it), it does load fine on my setup.
> 
> Immediately after boot, I have:
> 
> # lsmod
> Module  Size  Used by
> ...
> coda   54685  0
> v4l2_mem2mem   14517  1 coda
> videobuf2_dma_contig 9478  1 coda
> videobuf2_vmalloc   5529  1 coda
> videobuf2_memops1888  2 videobuf2_dma_contig,videobuf2_vmalloc
> cecd_dw_hdmi3129  0
> # modprobe rc-cec
> # lsmod
> Module  Size  Used by
> rc_cec  1785  0
> ...
> coda   54685  0
> v4l2_mem2mem   14517  1 coda
> videobuf2_dma_contig 9478  1 coda
> videobuf2_vmalloc   5529  1 coda
> videobuf2_memops1888  2 videobuf2_dma_contig,videobuf2_vmalloc
> cecd_dw_hdmi3129  0
> 
> So, rc-cec is perfectly loadable, it just doesn't get loaded at boot.
> Manually loading it like this is useless though - I have to unload
> cecd_dw_hdmi and then re-load it after rc-cec is loaded for rc-cec to
> be seen.  At that point, (and with the help of a userspace program)
> things start working as expected.

Did you compile and install the v4l-utils found here:

http://git.linuxtv.org/cgit.cgi/hverkuil/v4l-utils.git/log/?h=cec

I think that the rc_cec module is loaded through some udev rules and
keytables that are installed by v4l-utils. The standard v4l-utils
doesn't know about cec, but my repo above does.

To be honest, I don't really understand how it works, but if you haven't
installed it yet then try it and see if that solves the problem.

>> BTW, I am still on the fence whether using the kernel RC subsystem is
>> the right thing to do. There are a number of CEC RC commands that use
>> extra parameters that cannot be mapped to the RC API, so you still
>> need to handle those manually.
> 
> Even though it is a remote control which is being forwarded for the
> most part, but there are operation codes which aren't related to
> key presses specified by the standard.  I don't think there's anything
> wrong with having a RC interface present, but allowing other interfaces
> as a possibility is a good thing too - it allows a certain amount of
> flexibility.
> 
> For example, with rc-cec loaded and properly bound, I can control at
> least rhythmbox within gnome using the TVs remote control with no
> modifications - and that happens because the X server passes on the
> events it receives via the event device.
> 
> Given the range of media applications, I think that's key - it needs
> to at least have the capability to plug into the existing ways of doing
> things, even if those ways are not perfect.
> 
>> Perhaps I should split it off into a separate patch and keep it out
>> from the initial pull request once we're ready for that.
> 
> I'm biased because it is an enablement feature - it allows CEC to work
> out of the box with at least some existing media apps. :)
> 

OK, useful feedback. I am considering putting the RC code under a kernel
config option though. So if the RC core is not enabled or you don't want
the RC part to be created, then you can opt to disable it.

Regards,

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


Re: [PATCHv9 07/15] cec: add HDMI CEC framework

2015-10-14 Thread Hans Verkuil
On 10/14/2015 12:51 AM, Russell King - ARM Linux wrote:
> On Mon, Oct 12, 2015 at 01:35:54PM +0200, Hans Verkuil wrote:
>> On 10/06/2015 07:06 PM, Russell King - ARM Linux wrote:
>>> Surely you aren't proposing that drivers should write directly to
>>> adap->phys_addr without calling some notification function that the
>>> physical address has changed?
>>
>> Userspace is informed through CEC_EVENT_STATE_CHANGE when the adapter is
>> enabled/disabled. When the adapter is enabled and CEC_CAP_PHYS_ADDR is
>> not set (i.e. the kernel takes care of this), then calling 
>> CEC_ADAP_G_PHYS_ADDR
>> returns the new physical address.
> 
> Okay, so when I see the EDID arrive, I should be doing:
> 
> phys = parse_hdmi_addr(block->edid);
> cec->adap->phys_addr = phys;
> cec_enable(cec->adap, true);
> 
> IOW, you _are_ expecting adap->phys_addr to be written, but only while
> the adapter is disabled?

Right.

And when the hotplug goes down you should call cec_enable(cec->adap, false).
While the adapter is disabled, CEC_ADAP_G_PHYS_ADDR will always return
CEC_PHYS_ADDR_INVALID regardless of the cec->adap->phys_addr value.

Regards,

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


Re: [PATCHv9 14/15] cec: s5p-cec: Add s5p-cec driver

2015-10-12 Thread Hans Verkuil
On 10/06/2015 01:11 AM, Russell King - ARM Linux wrote:
> On Mon, Sep 07, 2015 at 03:44:43PM +0200, Hans Verkuil wrote:
>> +cec->adap = cec_create_adapter(_cec_adap_ops, cec,
>> +CEC_NAME, CEC_CAP_STATE |
>> +CEC_CAP_PHYS_ADDR | CEC_CAP_LOG_ADDRS | CEC_CAP_IO |
>> +CEC_CAP_IS_SOURCE,
>> +0, THIS_MODULE, >dev);
>> +ret = PTR_ERR_OR_ZERO(cec->adap);
>> +if (ret)
>> +return ret;
>> +cec->adap->available_log_addrs = 1;
>> +
>> +platform_set_drvdata(pdev, cec);
>> +pm_runtime_enable(dev);
> 
> This is really not a good interface.
> 
> "cec_create_adapter" creates and registers the adapter, at which point it
> becomes available to userspace.  However, you haven't finished setting it
> up, so it's possible to nip in here and start using it before the setup
> has completed.  This needs fixing.
> 

Good point, I'll split off the registration part into a separate function.

Regards,

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


Re: [PATCHv9 07/15] cec: add HDMI CEC framework

2015-10-12 Thread Hans Verkuil
On 10/06/2015 07:06 PM, Russell King - ARM Linux wrote:
> On Mon, Sep 07, 2015 at 03:44:36PM +0200, Hans Verkuil wrote:
>> From: Hans Verkuil <hans.verk...@cisco.com>
>>
>> The added HDMI CEC framework provides a generic kernel interface for
>> HDMI CEC devices.
>>
>> Signed-off-by: Hans Verkuil <hansv...@cisco.com>
>> [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]
>> [k.deb...@samsung.com: add sequence number handling]
>> [k.deb...@samsung.com: add passthrough mode]
>> [k.deb...@samsung.com: fix CEC defines, add missing CEC 2.0 commands]
>> minor additions]
>> Signed-off-by: Kamil Debski <ka...@wypas.org>
>> Signed-off-by: Hans Verkuil <hans.verk...@cisco.com>
> 
> I don't see much in the way of support for source devices in this:
> how do we handle hotplug of the sink, and how to do we configure the
> physical address?

The source device driver should call cec_enable(false) if the hotplug
goes down and cec_enable(true) when the EDID has been read and the physical
address has been retrieved and configured in the cec adapter.

This however assumes that the source driver is the one controlling the
CEC hardware. This is the case for the cobalt driver, but not apparently
for the exynos hardware. In that case userspace will have to handle this:
disable the CEC adapter when the hotplug disappears, set the physical address
and enable the CEC adapter when a new EDID is read.

Such drivers have the CEC_CAP_STATE and CEC_CAP_PHYS_ADDR caps set. I.e.
they expect that userspace does this.

This is also something that USB CEC dongles will do, although I don't have
a driver for that.

> Surely you aren't proposing that drivers should write directly to
> adap->phys_addr without calling some notification function that the
> physical address has changed?

Userspace is informed through CEC_EVENT_STATE_CHANGE when the adapter is
enabled/disabled. When the adapter is enabled and CEC_CAP_PHYS_ADDR is
not set (i.e. the kernel takes care of this), then calling CEC_ADAP_G_PHYS_ADDR
returns the new physical address.
 
> Please can you give some guidance on how a HDMI source bridge driver
> should deal with these issues.  Thanks.
> 

The cec.txt file will give more information about the kernel internals.
All I need is time (ha!) to update that file since the current version
is completely outdated (as mentioned in the cover letter).

Regards,

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


Re: [PATCH 4/4] ARM64: dts: exynos5433: add jpeg node

2015-09-21 Thread Hans Verkuil
On 18-09-15 16:21, Andrzej Pietrasiewicz wrote:
> From: Marek Szyprowski 
> 
> Add Exynos 5433 jpeg h/w codec node.
> 
> Signed-off-by: Marek Szyprowski 
> Signed-off-by: Andrzej Pietrasiewicz 
> ---
>  arch/arm64/boot/dts/exynos/exynos5433.dtsi | 21 +
>  1 file changed, 21 insertions(+)
> 
> diff --git a/arch/arm64/boot/dts/exynos/exynos5433.dtsi 
> b/arch/arm64/boot/dts/exynos/exynos5433.dtsi

This dtsi file doesn't exist in the media-git tree. What is the story here?

Should this go through a different subsystem?

I think the media subsystem can take patches 1-3 and whoever does DT patches can
take this patch, right?

Regards,

Hans

> index 59e21b6..5cb489f 100644
> --- a/arch/arm64/boot/dts/exynos/exynos5433.dtsi
> +++ b/arch/arm64/boot/dts/exynos/exynos5433.dtsi
> @@ -916,6 +916,27 @@
>   io-channel-ranges;
>   status = "disabled";
>   };
> + jpeg: jpeg@1502 {
> + compatible = "samsung,exynos5433-jpeg";
> + reg = <0x1502 0x1>;
> + interrupts = <0 411 0>;
> + clock-names = "pclk",
> +   "aclk",
> +   "aclk_xiu",
> +   "sclk";
> + clocks = <_mscl CLK_PCLK_JPEG>,
> +  <_mscl CLK_ACLK_JPEG>,
> +  <_mscl CLK_ACLK_XIU_MSCLX>,
> +  <_mscl CLK_SCLK_JPEG>;
> + assigned-clocks = <_mscl 
> CLK_MOUT_ACLK_MSCL_400_USER>,
> +   <_mscl CLK_MOUT_SCLK_JPEG_USER>,
> +   <_mscl CLK_MOUT_SCLK_JPEG>,
> +   <_top CLK_MOUT_SCLK_JPEG_A>;
> + assigned-clock-parents = <_top CLK_ACLK_MSCL_400>,
> +  <_top CLK_SCLK_JPEG_MSCL>,
> +  <_mscl 
> CLK_MOUT_SCLK_JPEG_USER>,
> +  <_top 
> CLK_MOUT_BUS_PLL_USER>;
> + };
>   };
>  
>   timer {
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 7/9] [media] v4l2: introduce v4l2_timeval

2015-09-18 Thread Hans Verkuil
On 09/17/15 23:19, Arnd Bergmann wrote:
> The v4l2 API uses a 'struct timeval' to communicate time stamps to user
> space. This is broken on 32-bit architectures as soon as we have a C library
> that defines time_t as 64 bit, which then changes the structure layout of
> struct v4l2_buffer.
> 
> Since existing user space source code relies on the type to be 'struct
> timeva' and we want to preserve compile-time compatibility when moving

s/timeva/timeval/

> to a new libc, we cannot make user-visible changes to the header file.
> 
> In this patch, we change the type of the timestamp to 'struct v4l2_timeval'

Don't we need a kernel-wide timeval64? Rather than adding a v4l2-specific
struct?

> as a preparation for a follow-up that adds API compatiblity for both
> 32-bit and 64-bit time_t. This patch should have no impact on generated
> code in either user space or kernel.
> 
> Signed-off-by: Arnd Bergmann 
> ---
>  drivers/media/pci/bt8xx/bttv-driver.c  |  2 +-
>  drivers/media/pci/meye/meye.h  |  2 +-
>  drivers/media/pci/zoran/zoran.h|  2 +-
>  drivers/media/platform/coda/coda.h |  2 +-
>  drivers/media/platform/omap/omap_vout.c|  4 ++--
>  drivers/media/platform/omap3isp/ispstat.c  |  3 ++-
>  drivers/media/platform/omap3isp/ispstat.h  |  2 +-
>  drivers/media/platform/vim2m.c |  2 +-
>  drivers/media/platform/vivid/vivid-ctrls.c |  2 +-
>  drivers/media/usb/cpia2/cpia2.h|  2 +-
>  drivers/media/usb/cpia2/cpia2_v4l.c|  2 +-
>  drivers/media/usb/gspca/gspca.c|  2 +-
>  drivers/media/usb/usbvision/usbvision.h|  2 +-
>  drivers/media/v4l2-core/v4l2-common.c  |  6 +++---
>  include/media/v4l2-common.h|  2 +-
>  include/media/videobuf-core.h  |  2 +-
>  include/trace/events/v4l2.h| 12 ++--
>  include/uapi/linux/videodev2.h | 17 +
>  18 files changed, 47 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/media/pci/bt8xx/bttv-driver.c 
> b/drivers/media/pci/bt8xx/bttv-driver.c
> index 15a4ebc2844d..b0ed8d799c14 100644
> --- a/drivers/media/pci/bt8xx/bttv-driver.c
> +++ b/drivers/media/pci/bt8xx/bttv-driver.c
> @@ -3585,7 +3585,7 @@ static void
>  bttv_irq_wakeup_video(struct bttv *btv, struct bttv_buffer_set *wakeup,
> struct bttv_buffer_set *curr, unsigned int state)
>  {
> - struct timeval ts;
> + struct v4l2_timeval ts;
>  
>   v4l2_get_timestamp();
>  
> diff --git a/drivers/media/pci/meye/meye.h b/drivers/media/pci/meye/meye.h
> index 751be5e533c7..a06aa5ba9abc 100644
> --- a/drivers/media/pci/meye/meye.h
> +++ b/drivers/media/pci/meye/meye.h
> @@ -281,7 +281,7 @@
>  struct meye_grab_buffer {
>   int state;  /* state of buffer */
>   unsigned long size; /* size of jpg frame */
> - struct timeval timestamp;   /* timestamp */
> + struct v4l2_timeval timestamp;  /* timestamp */
>   unsigned long sequence; /* sequence number */
>  };
>  
> diff --git a/drivers/media/pci/zoran/zoran.h b/drivers/media/pci/zoran/zoran.h
> index 4e7db8939c2b..9a9f782cede9 100644
> --- a/drivers/media/pci/zoran/zoran.h
> +++ b/drivers/media/pci/zoran/zoran.h
> @@ -39,7 +39,7 @@ struct zoran_sync {
>   unsigned long frame;/* number of buffer that has been free'd */
>   unsigned long length;   /* number of code bytes in buffer (capture 
> only) */
>   unsigned long seq;  /* frame sequence number */
> - struct timeval timestamp;   /* timestamp */
> + struct v4l2_timeval timestamp;  /* timestamp */
>  };
>  
>  
> diff --git a/drivers/media/platform/coda/coda.h 
> b/drivers/media/platform/coda/coda.h
> index 59b2af9c7749..fa1e15a757cd 100644
> --- a/drivers/media/platform/coda/coda.h
> +++ b/drivers/media/platform/coda/coda.h
> @@ -138,7 +138,7 @@ struct coda_buffer_meta {
>   struct list_headlist;
>   u32 sequence;
>   struct v4l2_timecodetimecode;
> - struct timeval  timestamp;
> + struct v4l2_timeval timestamp;
>   u32 start;
>   u32 end;
>  };
> diff --git a/drivers/media/platform/omap/omap_vout.c 
> b/drivers/media/platform/omap/omap_vout.c
> index 70c28d19ea04..974a238a86fe 100644
> --- a/drivers/media/platform/omap/omap_vout.c
> +++ b/drivers/media/platform/omap/omap_vout.c
> @@ -513,7 +513,7 @@ static int omapvid_apply_changes(struct omap_vout_device 
> *vout)
>  }
>  
>  static int omapvid_handle_interlace_display(struct omap_vout_device *vout,
> - unsigned int irqstatus, struct timeval timevalue)
> + unsigned int irqstatus, struct v4l2_timeval timevalue)
>  {
>   u32 fid;
>  
> @@ -557,7 +557,7 @@ static void omap_vout_isr(void *arg, unsigned int 
> irqstatus)
>   int ret, fid, mgr_id;
>   u32 addr, irq;
>   struct omap_overlay *ovl;
> - struct timeval 

Re: [PATCH v2 8/9] [media] handle 64-bit time_t in v4l2_buffer

2015-09-18 Thread Hans Verkuil
On 09/18/15 11:26, Arnd Bergmann wrote:
> On Friday 18 September 2015 09:18:45 Hans Verkuil wrote:
>> Hi Arnd,
>>
>> Thanks once again for working on this! Unfortunately, this approach won't
>> work, see my comments below.
>>
>> BTW, I would expect to see compile errors when compiling for 32 bit. Did
>> you try that?
> 
> I only tested on 32-bit, both ARM and x86, but had a longer set of patches
> applied below.
> 
>>> +static void v4l_put_buffer_time32(struct v4l2_buffer_time32 *to,
>>> + const struct v4l2_buffer *from)
>>> +{
>>> +   to->index   = from->index;
>>> +   to->type= from->type;
>>> +   to->bytesused   = from->bytesused;
>>> +   to->flags   = from->flags;
>>> +   to->field   = from->field;
>>> +   to->timestamp.tv_sec= from->timestamp.tv_sec;
>>> +   to->timestamp.tv_usec   = from->timestamp.tv_usec;
>>> +   to->timecode= from->timecode;
>>> +   to->sequence= from->sequence;
>>> +   to->memory  = from->memory;
>>> +   to->m.offset= from->m.offset;
>>> +   to->length  = from->length;
>>> +   to->reserved2   = from->reserved2;
>>> +   to->reserved= from->reserved;
>>> +}
>>
>> Is there a reason why you didn't use memcpy like you did for VIDIOC_DQEVENT 
>> (path 5/9)?
>> I would prefer that over these explicit assignments.
> 
> No strong reason. I went back and forth a bit on the m.offset field that
> is part of a union: In a previous version, I planned to move all the
> compat handling here, and doing the conversion one field at a time would
> make it easier to share the code between 32-bit and 64-bit kernels
> handling old 32-bit user space. This version doesn't do that, so I can
> use the memcpy approach instead.
> 
>>>  static int v4l_g_parm(const struct v4l2_ioctl_ops *ops,
>>> struct file *file, void *fh, void *arg)
>>>  {
>>> @@ -2408,12 +2524,21 @@ static struct v4l2_ioctl_info v4l2_ioctls[] = {
>>> IOCTL_INFO_FNC(VIDIOC_S_FMT, v4l_s_fmt, v4l_print_format, INFO_FL_PRIO),
>>> IOCTL_INFO_FNC(VIDIOC_REQBUFS, v4l_reqbufs, v4l_print_requestbuffers, 
>>> INFO_FL_PRIO | INFO_FL_QUEUE),
>>> IOCTL_INFO_FNC(VIDIOC_QUERYBUF, v4l_querybuf, v4l_print_buffer, 
>>> INFO_FL_QUEUE | INFO_FL_CLEAR(v4l2_buffer, length)),
>>> +#ifndef CONFIG_64BIT
>>> +   IOCTL_INFO_FNC(VIDIOC_QUERYBUF_TIME32, v4l_querybuf_time32, 
>>> v4l_print_buffer_time32, INFO_FL_QUEUE | INFO_FL_CLEAR(v4l2_buffer, 
>>> length)),
>>> +#endif
>>
>> This doesn't work. These IOCTL macros use the ioctl nr as the index in the 
>> array. Since
>> VIDIOC_QUERYBUF and VIDIOC_QUERYBUF_TIME32 have the same index, this will 
>> fail.
> 
> Ah, I see. No idea why that did not cause a compile-time error. I got some
> errors for duplicate 'case' values when the structures are the same size
> (that's why we need the '#ifdef CONFIG_64BIT' in some places) but not here.
> 
>> I think (not 100% certain, there may be better suggestions) that the 
>> conversion is best
>> done in video_usercopy(): just before func() is called have a switch for the 
>> TIME32
>> variants, convert to the regular variant, call func() and convert back.
> 
> Does the handler have access to the _IOC_SIZE() value that was passed? If
> it does, we could add a conditional inside of v4l_querybuf().
> I did not see an easy way to do that though.

No, the v4l_ handlers don't have access to that. But I think it is much easier 
to
do the conversion at the first opportunity (video_usercopy), so no other code
needs to be modified. Easier to review and maintain that way.

>> My only concern here is that an additional v4l2_buffer struct (68 bytes) is 
>> needed on the
>> stack. I don't see any way around that, though.
> 
> Agreed.
> 
>>> +struct v4l2_buffer_time32 {
>>> +   __u32   index;
>>> +   __u32   type;
>>> +   __u32   bytesused;
>>> +   __u32   flags;
>>> +   __u32   field;
>>> +   struct {
>>> +   __s32   tv_sec;
>>> +   __s32   tv_usec;
>>> +   }   timestamp;
>>> +   struct v4l2_timecodetimecode;
>>> +   __u32   sequence;
>>>

Re: [PATCH v2 7/9] [media] v4l2: introduce v4l2_timeval

2015-09-18 Thread Hans Verkuil
On 09/18/15 11:09, Arnd Bergmann wrote:
> On Friday 18 September 2015 10:05:06 Hans Verkuil wrote:
>> On 09/17/15 23:19, Arnd Bergmann wrote:
>>> The v4l2 API uses a 'struct timeval' to communicate time stamps to user
>>> space. This is broken on 32-bit architectures as soon as we have a C library
>>> that defines time_t as 64 bit, which then changes the structure layout of
>>> struct v4l2_buffer.
>>>
>>> Since existing user space source code relies on the type to be 'struct
>>> timeva' and we want to preserve compile-time compatibility when moving
>>
>> s/timeva/timeval/
> 
> Fixed
> 
>>> to a new libc, we cannot make user-visible changes to the header file.
>>>
>>> In this patch, we change the type of the timestamp to 'struct v4l2_timeval'
>>
>> Don't we need a kernel-wide timeval64? Rather than adding a v4l2-specific
>> struct?
> 
> I still hope to avoid doing that. All in-kernel users should be changed to
> use timespec64 or ktime_t, which are always more efficient and accurate.
> 
> For the system call interface, all timeval APIs are deprecated and have
> replacements using timespec64 (e.g. clock_gettime() replaces gettimeofday).
> 
> Only a handful of ioctls pass timeval, and so far my impression is that
> we are better off handling each one separately. The total amount of code
> we need to add this way should be less than if we have to duplicate all
> common code functions that today operate on timeval and can eventually
> get removed.

Ah, OK. Got it.

I think this is dependent on the upcoming media workshop next month. If we
decide to redesign v4l2_buffer anyway, then we can avoid timeval completely.
And the only place where we would need to convert it in the compat code
hidden in the v4l2 core (likely v4l2-ioctl.c).

I am not really keen on having v4l2_timeval in all these drivers. I would
have to check them anyway since I suspect that in several drivers the local
timeval variable can be avoided by rewriting that part of the driver.

Personally I am in favor of a redesigned v4l2_buffer: it's awkward to use
with multiplanar formats, there is cruft in there that can be removed 
(timecode),
and there is little space for additions (HW-specific timecodes, more buffer
meta data, etc).

We'll see.

Regards,

Hans

> 
>>> diff --git a/drivers/media/platform/vim2m.c b/drivers/media/platform/vim2m.c
>>> index 295fde5fdb75..df5daac6d099 100644
>>> --- a/drivers/media/platform/vim2m.c
>>> +++ b/drivers/media/platform/vim2m.c
>>> @@ -235,7 +235,7 @@ static int device_process(struct vim2m_ctx *ctx,
>>> in_vb->v4l2_buf.sequence = q_data->sequence++;
>>> memcpy(_vb->v4l2_buf.timestamp,
>>> _vb->v4l2_buf.timestamp,
>>> -   sizeof(struct timeval));
>>> +   sizeof(struct v4l2_timeval));
>>> if (in_vb->v4l2_buf.flags & V4L2_BUF_FLAG_TIMECODE)
>>> memcpy(_vb->v4l2_buf.timecode, _vb->v4l2_buf.timecode,
>>> sizeof(struct v4l2_timecode));
>>
>> See https://patchwork.linuxtv.org/patch/31405/
>>
>> I'll merge that one for 4.4 very soon.
> 
> Ok.
> 
>   Arnd
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 7/9] [media] v4l2: introduce v4l2_timeval

2015-09-18 Thread Hans Verkuil
On 09/18/15 11:43, Arnd Bergmann wrote:
> On Friday 18 September 2015 11:27:40 Hans Verkuil wrote:
>> Ah, OK. Got it.
>>
>> I think this is dependent on the upcoming media workshop next month. If we
>> decide to redesign v4l2_buffer anyway, then we can avoid timeval completely.
>> And the only place where we would need to convert it in the compat code
>> hidden in the v4l2 core (likely v4l2-ioctl.c).
> 
> Ah, I think I understood the idea now, I missed that earlier when you mention
> the idea.
> 
> So what you are saying here is that you could come up with a new unambiguous
> (using only __u32 and __u64 types and no pointers) format that gets exposed
> to a new set of ioctls, and then change the handling of the existing three
> formats (native 64-bit, traditional 32-bit, and 32-bit with 64-bit time_t)
> so they get converted into the new format by the common ioctl handling code?

Right. Drivers only see the new struct, and only v4l2-ioctl.c (and possible
v4l2-compat-ioctl32.c) see the old ones.

BTW, I will probably pick up patches 4 and 6 for 4.4. That should help a bit.

Regards,

Hans

>> I am not really keen on having v4l2_timeval in all these drivers. I would
>> have to check them anyway since I suspect that in several drivers the local
>> timeval variable can be avoided by rewriting that part of the driver.
> 
> I've tried to do that for all the drivers where I could find an easy solution
> in patch 6/9, but I'm sure you can do it for a couple more.
> 
> We could also do a lightweight redesign and use 'timespec64' internally
> in all the drivers and then convert that to 'timeval' or the 64-bit
> format of that in the ioctl handler. This is also something I tried at
> some point but then found it a bit more intuitive to leave the normal ioctl
> path alone and have an explicit type.
> 
>> Personally I am in favor of a redesigned v4l2_buffer: it's awkward to use
>> with multiplanar formats, there is cruft in there that can be removed 
>> (timecode),
>> and there is little space for additions (HW-specific timecodes, more buffer
>> meta data, etc).
>>
>> We'll see.
> 
> Ok.
> 
>   Arnd
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 7/9] [media] v4l2: introduce v4l2_timeval

2015-09-18 Thread Hans Verkuil
On 09/18/15 12:08, Arnd Bergmann wrote:
> On Friday 18 September 2015 11:52:28 Hans Verkuil wrote:
>> On 09/18/15 11:43, Arnd Bergmann wrote:
>>> On Friday 18 September 2015 11:27:40 Hans Verkuil wrote:
>>>> Ah, OK. Got it.
>>>>
>>>> I think this is dependent on the upcoming media workshop next month. If we
>>>> decide to redesign v4l2_buffer anyway, then we can avoid timeval 
>>>> completely.
>>>> And the only place where we would need to convert it in the compat code
>>>> hidden in the v4l2 core (likely v4l2-ioctl.c).
>>>
>>> Ah, I think I understood the idea now, I missed that earlier when you 
>>> mention
>>> the idea.
>>>
>>> So what you are saying here is that you could come up with a new unambiguous
>>> (using only __u32 and __u64 types and no pointers) format that gets exposed
>>> to a new set of ioctls, and then change the handling of the existing three
>>> formats (native 64-bit, traditional 32-bit, and 32-bit with 64-bit time_t)
>>> so they get converted into the new format by the common ioctl handling code?
>>
>> Right. Drivers only see the new struct, and only v4l2-ioctl.c (and possible
>> v4l2-compat-ioctl32.c) see the old ones.
>>
>> BTW, I will probably pick up patches 4 and 6 for 4.4. That should help a bit.
> 
> Ok, thanks!
> 
> I guess it's up to Mauro to pick up the first three patches?

Yes.

> As I don't see anything more to do for me here until you've had the
> discussion about the new format, I'll move on to another subsystem now.
> I have around 70 patches waiting to be submitted, plus the system call
> series.

Agreed.

Thanks again for working on this!

Regards,

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


Re: [PATCH v2 8/9] [media] handle 64-bit time_t in v4l2_buffer

2015-09-18 Thread Hans Verkuil
Hi Arnd,

Thanks once again for working on this! Unfortunately, this approach won't
work, see my comments below.

BTW, I would expect to see compile errors when compiling for 32 bit. Did
you try that?

On 09/17/2015 11:19 PM, Arnd Bergmann wrote:
> This is the final change to enable user space with 64-bit time_t
> in the core v4l2 code.
> 
> Four ioctls are affected here: VIDIOC_QUERYBUF, VIDIOC_QBUF,
> VIDIOC_DQBUF, and VIDIOC_PREPARE_BUF. All of them pass a
> struct v4l2_buffer, which can either contain a 32-bit time_t
> or a 64-bit time on 32-bit architectures.
> 
> In this patch, we redefine the in-kernel version of this structure
> to use the 64-bit __s64 type through the use of v4l2_timeval.
> This means the normal ioctl handling now assumes 64-bit time_t
> and so we have to add support for 32-bit time_t in new handlers.
> 
> This is somewhat similar to the 32-bit compat handling on 64-bit
> architectures, but those also have to modify other fields of
> the structure. For now, I leave that compat code alone, as it
> handles the normal case (32-bit compat_time_t) correctly, this
> has to be done as a follow-up.
> 
> Signed-off-by: Arnd Bergmann 
> ---
>  drivers/media/v4l2-core/v4l2-ioctl.c | 174 
> +--
>  include/uapi/linux/videodev2.h   |  34 ++-
>  2 files changed, 199 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c 
> b/drivers/media/v4l2-core/v4l2-ioctl.c
> index 7aab18dd2ca5..137475c28e8f 100644
> --- a/drivers/media/v4l2-core/v4l2-ioctl.c
> +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
> @@ -438,15 +438,14 @@ static void v4l_print_buffer(const void *arg, bool 
> write_only)
>   const struct v4l2_timecode *tc = >timecode;
>   const struct v4l2_plane *plane;
>   int i;
> + /* y2038 safe because of monotonic time */
> + unsigned int seconds = p->timestamp.tv_sec;
>  
> - pr_cont("%02ld:%02d:%02d.%08ld index=%d, type=%s, "
> + pr_cont("%02d:%02d:%02d.%08ld index=%d, type=%s, "
>   "flags=0x%08x, field=%s, sequence=%d, memory=%s",
> - p->timestamp.tv_sec / 3600,
> - (int)(p->timestamp.tv_sec / 60) % 60,
> - (int)(p->timestamp.tv_sec % 60),
> - (long)p->timestamp.tv_usec,
> - p->index,
> - prt_names(p->type, v4l2_type_names),
> + seconds / 3600, (seconds / 60) % 60,
> + seconds % 60, (long)p->timestamp.tv_usec,
> + p->index, prt_names(p->type, v4l2_type_names),
>   p->flags, prt_names(p->field, v4l2_field_names),
>   p->sequence, prt_names(p->memory, v4l2_memory_names));
>  
> @@ -1846,6 +1845,123 @@ static int v4l_prepare_buf(const struct 
> v4l2_ioctl_ops *ops,
>   return ret ? ret : ops->vidioc_prepare_buf(file, fh, b);
>  }
>  
> +#ifndef CONFIG_64BIT
> +static void v4l_get_buffer_time32(struct v4l2_buffer *to,
> +   const struct v4l2_buffer_time32 *from)
> +{
> + to->index   = from->index;
> + to->type= from->type;
> + to->bytesused   = from->bytesused;
> + to->flags   = from->flags;
> + to->field   = from->field;
> + to->timestamp.tv_sec= from->timestamp.tv_sec;
> + to->timestamp.tv_usec   = from->timestamp.tv_usec;
> + to->timecode= from->timecode;
> + to->sequence= from->sequence;
> + to->memory  = from->memory;
> + to->m.offset= from->m.offset;
> + to->length  = from->length;
> + to->reserved2   = from->reserved2;
> + to->reserved= from->reserved;
> +}
> +
> +static void v4l_put_buffer_time32(struct v4l2_buffer_time32 *to,
> +   const struct v4l2_buffer *from)
> +{
> + to->index   = from->index;
> + to->type= from->type;
> + to->bytesused   = from->bytesused;
> + to->flags   = from->flags;
> + to->field   = from->field;
> + to->timestamp.tv_sec= from->timestamp.tv_sec;
> + to->timestamp.tv_usec   = from->timestamp.tv_usec;
> + to->timecode= from->timecode;
> + to->sequence= from->sequence;
> + to->memory  = from->memory;
> + to->m.offset= from->m.offset;
> + to->length  = from->length;
> + to->reserved2   = from->reserved2;
> + to->reserved= from->reserved;
> +}

Is there a reason why you didn't use memcpy like you did for VIDIOC_DQEVENT 
(path 5/9)?
I would prefer that over these explicit assignments.

> +
> +static int v4l_querybuf_time32(const struct v4l2_ioctl_ops *ops,
> + struct file *file, void *fh, void *arg)
> +{
> + struct v4l2_buffer buffer;
> + int 

Re: [PATCH 6/7] [RFC] [media]: v4l2: introduce v4l2_timeval

2015-09-16 Thread Hans Verkuil
On 09/16/2015 09:56 AM, Arnd Bergmann wrote:
> On Wednesday 16 September 2015 08:51:14 Hans Verkuil wrote:
> 
>>> a) Similar to my first attempt, define a new struct v4l2_timeval, but
>>>only use it when building with a y2038-aware libc, so we don't break
>>>existing environments:
>>>
>>> /* some compile-time conditional that we first need to agree on with 
>>> libc */
>>> #if __BITS_PER_TIME_T > __BITS_PER_LONG
>>> struct v4l2_timeval { long tv_sec; long tv_usec; }
>>> #else
>>> #define v4l2_timeval timeval
>>> #endif
>>>
>>>This means that any user space that currently assumes the timestamp
>>>member to be a 'struct timeval' has to be changed to access the members
>>>individually, or get a build error.
>>>The __BITS_PER_TIME_T trick has to be used in a couple of other 
>>> subsystems
>>>too, as some of them have no other way to identify an interface
>>
>> I don't like this as this means some applications will compile on 64 bit or
>> with a non-y2038-aware libc, but fail on a 32-bit with y2038-aware libc. This
>> will be confusing and it may take a long time before the application 
>> developer
>> discovers this.
> 
> Right.
> 
>>> b) Keep the header file unchanged, but deal with both formats of v4l2_buffer
>>>in the kernel. Fortunately, all ioctls that pass a v4l2_buffer have
>>>properly defined command codes, and it does not get passed using a
>>>read/write style interface. This means we move the v4l2_buffer32
>>>handling from v4l2-compat-ioctl32.c to v4l2-ioctl.c and add an in-kernel
>>>v4l2_buffer64 that matches the 64-bit variant of v4l2_buffer.
>>>This way, user space can use either definition of time_t, and the
>>>kernel will just handle them natively.
>>>This is going to be the most common way to handle y2038 compatibility
>>>in device drivers, and it has the additional advantage of simplifying
>>>the compat path.
>>
>> This would work.
> 
> Ok. So the only downside I can think of for this is that it uses a slightly
> less efficient format with additional padding in it. The kernel side will
> be a little ugly as I'm trying to avoid defining a generic timeval64
> structure (the generic syscalls should not need one), but I'll try to
> implement it first to see how it ends up.
> 
>>> c) As you describe above, introduce a new v4l2_buffer replacement with
>>>a different layout that does not reference timeval. For this case, I
>>>would recommend using a single 64-bit nanosecond timestamp that can
>>>be generated using ktime_get_ns().
>>>However, to avoid ambiguity with the user space definition of struct
>>>timeval, we still have to hide the existing 'struct v4l2_buffer' from
>>>y2038-aware user space by enclosing it in '#if __BITS_PER_TIME_T > 
>>>__BITS_PER_LONG' or similar.
>>
>> Right, and if we do that we still have the problem I describe under a). So we
>> would need to implement b) regardless.
>>
>> In other words, choosing c) doesn't depend on y2038 and it should be decided
>> on its own merits.
>>
>> I've proposed this as a topic to the media workshop we'll have during the 
>> Linux
>> Kernel Summit.
> 
> Thanks, good idea. I'll be at the kernel summit, but don't plan to attend
> the media workshop otherwise. If you let me know about the schedule, I can
> come to this session (or ping me on IRC or hangout when it starts).

Are you also attending the ELCE in Dublin? We could have a quick talk there.
I think the discussion whether to switch to a new v4l2_buffer struct isn't 
really
dependent on anything y2038.

Regards,

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


Re: [PATCH 6/7] [RFC] [media]: v4l2: introduce v4l2_timeval

2015-09-16 Thread Hans Verkuil
On 09/15/2015 10:26 PM, Arnd Bergmann wrote:
> On Tuesday 15 September 2015 18:27:19 Hans Verkuil wrote:
>> On 09/15/2015 05:49 PM, Arnd Bergmann wrote:
>>> The v4l2 API uses a 'struct timeval' to communicate time stamps to user
>>> space. This is broken on 32-bit architectures as soon as we have a C library
>>> that defines time_t as 64 bit, which then changes the structure layout of
>>> struct v4l2_buffer.
>>>
>>> Fortunately, almost all v4l2 drivers use monotonic timestamps and call
>>> v4l2_get_timestamp(), which means they don't also have a y2038 problem.
>>> This means we can keep using the existing binary layout of the structure
>>> and do not need to worry about defining a new kernel interface for
>>> userland with 64-bit time_t.
>>>
>>> A possible downside of this approach is that it breaks any user space
>>> that tries to assign the timeval structure returned from the kernel
>>> to another timeval, or to pass a pointer to it into a function that
>>> expects a timeval. Those will cause a build-time warning or error
>>> that can be fixed up in a backwards compatible way.
>>>
>>> The alternative to this patch is to leave the structure using
>>> 'struct timeval', but then we have to rework the kernel to let
>>> it handle both 32-bit and 64-bit time_t for 32-bit user space
>>> processes.
>>
>> Cool. Only this morning I was thinking about what would be needed in v4l2
>> to be y2038 safe, and here it is!
> 
> Nice!
> 
> fwiw, I also have a list of drivers at
> https://docs.google.com/spreadsheets/d/1HCYwHXxs48TsTb6IGUduNjQnmfRvMPzCN6T_0YiQwis/edit?usp=sharing
> which lists all known files that still need changing, in case you are
> wondering what else needs to be done, though it currently only covers
> things that nobody so far has started working on, and I have a couple
> patches on my disk that need polishing (I pushed out the v4l2 portion
> of that as a start)

I just *thought* about it, I never said I would do it! :-)

> 
>>> @@ -839,7 +845,7 @@ struct v4l2_buffer {
>>> __u32   bytesused;
>>> __u32   flags;
>>> __u32   field;
>>> -   struct timeval  timestamp;
>>> +   struct v4l2_timeval timestamp;
>>> struct v4l2_timecodetimecode;
>>> __u32   sequence;
>>>  
>>>
>>
>> I suspect that quite a few apps use assign the timestamp to another timeval
>> struct. A quick grep in v4l-utils (which we maintain) shows at least two of
>> those assignments. Ditto for xawtv3.
> 
> Ok, that is very helpful information, thanks for finding that!
> 
>> So I don't think v4l2_timeval is an option as it would break userspace too 
>> badly.
> 
> Agreed, we definitely don't want to break building user space with
> existing environments, i.e. 64-bit architectures, or 32-bit architectures
> with 32-bit time_t.
> 
>> An alternative to supporting a 64-bit timeval for 32-bit userspace is to 
>> make a
>> new y2038-aware struct and a new set of ioctls and use this opportunity to 
>> clean
>> up and extend the v4l2_buffer struct.
>>
>> So any 32-bit app that needs to be y2038 compliant would just use the new
>> struct and ioctls.
>>
>> But this is something to discuss among the v4l2 developers.
> 
> Ok. We generally to require as few source level changes to user space
> as possible for the conversion, and we want to make sure that when
> using a 32-bit libc with 64-bit time_t, we don't accidentally get
> broken interfaces (i.e. we should get a compile error whenever we
> can't get it right automatically).
> 
> One aspect that makes v4l2_buffer special is that the binary format
> is already clean for y2038 (once patch 4/7 "exynos4-is: use monotonic
> timestamps as advertized" gets merged), and we only need to worry about
> what happens when user space disagrees about the size of timeval.
> 
> Let me describe the options that I can think of here:
> 
> a) Similar to my first attempt, define a new struct v4l2_timeval, but
>only use it when building with a y2038-aware libc, so we don't break
>existing environments:
> 
>   /* some compile-time conditional that we first need to agree on with 
> libc */
>   #if __BITS_PER_TIME_T > __BITS_PER_LONG
>   struct v4l2_timeval { long tv_sec; long tv_usec; }
>   #else
>   #define v4l2_timeval timeval
>   #endif
> 
>This means that any user space that currently assumes the timestamp
>member to be a 'stru

Re: [PATCH 6/7] [RFC] [media]: v4l2: introduce v4l2_timeval

2015-09-15 Thread Hans Verkuil
On 09/15/2015 05:49 PM, Arnd Bergmann wrote:
> The v4l2 API uses a 'struct timeval' to communicate time stamps to user
> space. This is broken on 32-bit architectures as soon as we have a C library
> that defines time_t as 64 bit, which then changes the structure layout of
> struct v4l2_buffer.
> 
> Fortunately, almost all v4l2 drivers use monotonic timestamps and call
> v4l2_get_timestamp(), which means they don't also have a y2038 problem.
> This means we can keep using the existing binary layout of the structure
> and do not need to worry about defining a new kernel interface for
> userland with 64-bit time_t.
> 
> A possible downside of this approach is that it breaks any user space
> that tries to assign the timeval structure returned from the kernel
> to another timeval, or to pass a pointer to it into a function that
> expects a timeval. Those will cause a build-time warning or error
> that can be fixed up in a backwards compatible way.
> 
> The alternative to this patch is to leave the structure using
> 'struct timeval', but then we have to rework the kernel to let
> it handle both 32-bit and 64-bit time_t for 32-bit user space
> processes.

Cool. Only this morning I was thinking about what would be needed in v4l2
to be y2038 safe, and here it is!

> diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
> index 3228fbebcd63..b02cf054fbb8 100644
> --- a/include/uapi/linux/videodev2.h
> +++ b/include/uapi/linux/videodev2.h
> @@ -803,6 +803,12 @@ struct v4l2_plane {
>   __u32   reserved[11];
>  };
>  
> +/* used for monotonic times, therefore y2038 safe */
> +struct v4l2_timeval {
> + long tv_sec;
> + long tv_usec;
> +};
> +
>  /**
>   * struct v4l2_buffer - video buffer info
>   * @index:   id number of the buffer
> @@ -839,7 +845,7 @@ struct v4l2_buffer {
>   __u32   bytesused;
>   __u32   flags;
>   __u32   field;
> - struct timeval  timestamp;
> + struct v4l2_timeval timestamp;
>   struct v4l2_timecodetimecode;
>   __u32   sequence;
>  
> 

I suspect that quite a few apps use assign the timestamp to another timeval
struct. A quick grep in v4l-utils (which we maintain) shows at least two of
those assignments. Ditto for xawtv3.

So I don't think v4l2_timeval is an option as it would break userspace too 
badly.

An alternative to supporting a 64-bit timeval for 32-bit userspace is to make a
new y2038-aware struct and a new set of ioctls and use this opportunity to clean
up and extend the v4l2_buffer struct.

So any 32-bit app that needs to be y2038 compliant would just use the new
struct and ioctls.

But this is something to discuss among the v4l2 developers.

Regards,

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


Re: [PATCH 7/7] [RFC] [media] introduce v4l2_timespec type for timestamps

2015-09-15 Thread Hans Verkuil
On 09/15/2015 05:49 PM, Arnd Bergmann wrote:
> The v4l2 event queue uses a 'struct timespec' to pass monotonic
> timestamps. This is not a problem by itself, but it breaks when user
> space redefines timespec to use 'long long' on 32-bit systems.
> 
> To avoid that problem, we define our own replacement for timespec here,
> using 'long' tv_sec and tv_nsec members. This means no change to the
> existing API, but lets us keep using it with a y2038 compatible libc.
> 
> As a side-effect, this changes the API for x32 programs to be the same
> as native 32-bit, using a 32-bit tv_sec/tv_nsec value, but both old and
> new kernels already support both formats for on the binary level for
> compat and x32.
> 
> Alternatively, we could leave the header file to define the interface
> based on 'struct timespec', and implement both ioctls for native
> processes. I picked the approach in this case because it matches what
> we do for v4l2_timeval in the respective patch, but both would work
> equally well here.
> 
> Signed-off-by: Arnd Bergmann 
> ---
>  drivers/media/v4l2-core/v4l2-event.c | 20 +---
>  include/uapi/linux/videodev2.h   |  8 +++-
>  2 files changed, 20 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/media/v4l2-core/v4l2-event.c 
> b/drivers/media/v4l2-core/v4l2-event.c
> index 8d3171c6bee8..2a26ad591f59 100644
> --- a/drivers/media/v4l2-core/v4l2-event.c
> +++ b/drivers/media/v4l2-core/v4l2-event.c
> @@ -108,7 +108,7 @@ static struct v4l2_subscribed_event 
> *v4l2_event_subscribed(
>  }
>  
>  static void __v4l2_event_queue_fh(struct v4l2_fh *fh, const struct 
> v4l2_event *ev,
> - const struct timespec *ts)
> + const struct v4l2_timespec *ts)
>  {
>   struct v4l2_subscribed_event *sev;
>   struct v4l2_kevent *kev;
> @@ -170,17 +170,20 @@ void v4l2_event_queue(struct video_device *vdev, const 
> struct v4l2_event *ev)
>  {
>   struct v4l2_fh *fh;
>   unsigned long flags;
> - struct timespec timestamp;
> + struct timespec64 timestamp;
> + struct v4l2_timespec vts;
>  
>   if (vdev == NULL)
>   return;
>  
> - ktime_get_ts();
> + ktime_get_ts64();
> + vts.tv_sec = timestamp.tv_sec;
> + vts.tv_nsec = timestamp.tv_nsec;

I prefer to take this opportunity to create a v4l2_get_timespec helper
function, just like v4l2_get_timeval.

>  
>   spin_lock_irqsave(>fh_lock, flags);
>  
>   list_for_each_entry(fh, >fh_list, list)
> - __v4l2_event_queue_fh(fh, ev, );
> + __v4l2_event_queue_fh(fh, ev, );
>  
>   spin_unlock_irqrestore(>fh_lock, flags);
>  }
> @@ -189,12 +192,15 @@ EXPORT_SYMBOL_GPL(v4l2_event_queue);
>  void v4l2_event_queue_fh(struct v4l2_fh *fh, const struct v4l2_event *ev)
>  {
>   unsigned long flags;
> - struct timespec timestamp;
> + struct timespec64 timestamp;
> + struct v4l2_timespec vts;
>  
> - ktime_get_ts();
> + ktime_get_ts64();
> + vts.tv_sec = timestamp.tv_sec;
> + vts.tv_nsec = timestamp.tv_nsec;
>  
>   spin_lock_irqsave(>vdev->fh_lock, flags);
> - __v4l2_event_queue_fh(fh, ev, );
> + __v4l2_event_queue_fh(fh, ev, );
>   spin_unlock_irqrestore(>vdev->fh_lock, flags);
>  }
>  EXPORT_SYMBOL_GPL(v4l2_event_queue_fh);
> diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
> index b02cf054fbb8..bc659be87260 100644
> --- a/include/uapi/linux/videodev2.h
> +++ b/include/uapi/linux/videodev2.h
> @@ -809,6 +809,12 @@ struct v4l2_timeval {
>   long tv_usec;
>  };
>  
> +/* used for monotonic times, therefore y2038 safe */
> +struct v4l2_timespec {
> + long tv_sec;
> + long tv_nsec;
> +};
> +
>  /**
>   * struct v4l2_buffer - video buffer info
>   * @index:   id number of the buffer
> @@ -2088,7 +2094,7 @@ struct v4l2_event {
>   } u;
>   __u32   pending;
>   __u32   sequence;
> - struct timespec timestamp;
> + struct v4l2_timespectimestamp;
>   __u32   id;
>   __u32   reserved[8];
>  };
> 

I think I am OK with this. This timestamp is used much more rarely and I do
not expect this ABI change to cause any problems in userspace.

Regards,

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


[PATCHv9 13/15] cec: adv7511: add cec support.

2015-09-07 Thread Hans Verkuil
From: Hans Verkuil <hans.verk...@cisco.com>

Add CEC support to the adv7511 driver.

Signed-off-by: Hans Verkuil <hansv...@cisco.com>
[k.deb...@samsung.com: Merged changes from CEC Updates commit by Hans Verkuil]
Signed-off-by: Kamil Debski <ka...@wypas.org>
Signed-off-by: Hans Verkuil <hans.verk...@cisco.com>
---
 drivers/media/i2c/adv7511.c | 359 +++-
 include/media/adv7511.h |   6 +-
 2 files changed, 353 insertions(+), 12 deletions(-)

diff --git a/drivers/media/i2c/adv7511.c b/drivers/media/i2c/adv7511.c
index e4900df..645d4ba 100644
--- a/drivers/media/i2c/adv7511.c
+++ b/drivers/media/i2c/adv7511.c
@@ -33,6 +33,7 @@
 #include 
 #include 
 #include 
+#include 
 
 static int debug;
 module_param(debug, int, 0644);
@@ -59,6 +60,8 @@ MODULE_LICENSE("GPL v2");
 #define ADV7511_MIN_PIXELCLOCK 2000
 #define ADV7511_MAX_PIXELCLOCK 22500
 
+#define ADV7511_MAX_ADDRS (3)
+
 /*
 **
 *
@@ -90,12 +93,19 @@ struct adv7511_state {
struct v4l2_ctrl_handler hdl;
int chip_revision;
u8 i2c_edid_addr;
-   u8 i2c_cec_addr;
u8 i2c_pktmem_addr;
+   u8 i2c_cec_addr;
+
+   struct i2c_client *i2c_cec;
+   u8   cec_addr[ADV7511_MAX_ADDRS];
+   u8   cec_valid_addrs;
+   bool cec_enabled_adap;
+
/* Is the adv7511 powered on? */
bool power_on;
/* Did we receive hotplug and rx-sense signals? */
bool have_monitor;
+   bool enabled_irq;
/* timings from s_dv_timings */
struct v4l2_dv_timings dv_timings;
u32 fmt_code;
@@ -225,7 +235,7 @@ static int adv_smbus_read_i2c_block_data(struct i2c_client 
*client,
return ret;
 }
 
-static inline void adv7511_edid_rd(struct v4l2_subdev *sd, u16 len, u8 *buf)
+static void adv7511_edid_rd(struct v4l2_subdev *sd, uint16_t len, uint8_t *buf)
 {
struct adv7511_state *state = get_adv7511_state(sd);
int i;
@@ -240,6 +250,34 @@ static inline void adv7511_edid_rd(struct v4l2_subdev *sd, 
u16 len, u8 *buf)
v4l2_err(sd, "%s: i2c read error\n", __func__);
 }
 
+static inline int adv7511_cec_read(struct v4l2_subdev *sd, u8 reg)
+{
+   struct adv7511_state *state = get_adv7511_state(sd);
+
+   return i2c_smbus_read_byte_data(state->i2c_cec, reg);
+}
+
+static int adv7511_cec_write(struct v4l2_subdev *sd, u8 reg, u8 val)
+{
+   struct adv7511_state *state = get_adv7511_state(sd);
+   int ret;
+   int i;
+
+   for (i = 0; i < 3; i++) {
+   ret = i2c_smbus_write_byte_data(state->i2c_cec, reg, val);
+   if (ret == 0)
+   return 0;
+   }
+   v4l2_err(sd, "%s: I2C Write Problem\n", __func__);
+   return ret;
+}
+
+static inline int adv7511_cec_write_and_or(struct v4l2_subdev *sd, u8 reg, u8 
mask,
+  u8 val)
+{
+   return adv7511_cec_write(sd, reg, (adv7511_cec_read(sd, reg) & mask) | 
val);
+}
+
 static int adv7511_pktmem_rd(struct v4l2_subdev *sd, u8 reg)
 {
struct adv7511_state *state = get_adv7511_state(sd);
@@ -413,16 +451,28 @@ static const struct v4l2_ctrl_ops adv7511_ctrl_ops = {
 #ifdef CONFIG_VIDEO_ADV_DEBUG
 static void adv7511_inv_register(struct v4l2_subdev *sd)
 {
+   struct adv7511_state *state = get_adv7511_state(sd);
+
v4l2_info(sd, "0x000-0x0ff: Main Map\n");
+   if (state->i2c_cec)
+   v4l2_info(sd, "0x100-0x1ff: CEC Map\n");
 }
 
 static int adv7511_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register 
*reg)
 {
+   struct adv7511_state *state = get_adv7511_state(sd);
+
reg->size = 1;
switch (reg->reg >> 8) {
case 0:
reg->val = adv7511_rd(sd, reg->reg & 0xff);
break;
+   case 1:
+   if (state->i2c_cec) {
+   reg->val = adv7511_cec_read(sd, reg->reg & 0xff);
+   break;
+   }
+   /* fall through */
default:
v4l2_info(sd, "Register %03llx not supported\n", reg->reg);
adv7511_inv_register(sd);
@@ -433,10 +483,18 @@ static int adv7511_g_register(struct v4l2_subdev *sd, 
struct v4l2_dbg_register *
 
 static int adv7511_s_register(struct v4l2_subdev *sd, const struct 
v4l2_dbg_register *reg)
 {
+   struct adv7511_state *state = get_adv7511_state(sd);
+
switch (reg->reg >> 8) {
case 0:
adv7511_wr(sd, reg->reg & 0xff, reg->val & 0xff);
break;
+   case 1:
+   if (state->i2c_cec) {
+   adv7511_cec_write(sd, reg->reg & 0xff, reg->val & 0xff);
+   break;
+   }
+   /* fall through */
defau

[PATCHv9 09/15] DocBook/media: add CEC documentation

2015-09-07 Thread Hans Verkuil
From: Hans Verkuil <hans.verk...@cisco.com>

Add DocBook documentation for the CEC API.

Signed-off-by: Hans Verkuil <hansv...@cisco.com>
[k.deb...@samsung.com: add documentation for passthrough mode]
[k.deb...@samsung.com: minor fixes and change of reserved field sizes]
Signed-off-by: Kamil Debski <ka...@wypas.org>
Signed-off-by: Hans Verkuil <hans.verk...@cisco.com>
---
 Documentation/DocBook/media/Makefile   |   2 +
 Documentation/DocBook/media/v4l/biblio.xml |  10 +
 Documentation/DocBook/media/v4l/cec-api.xml|  76 +
 Documentation/DocBook/media/v4l/cec-func-close.xml |  59 
 Documentation/DocBook/media/v4l/cec-func-ioctl.xml |  73 +
 Documentation/DocBook/media/v4l/cec-func-open.xml  |  94 +++
 Documentation/DocBook/media/v4l/cec-func-poll.xml  |  89 ++
 .../DocBook/media/v4l/cec-ioc-adap-g-caps.xml  | 161 +++
 .../DocBook/media/v4l/cec-ioc-adap-g-log-addrs.xml | 306 +
 .../DocBook/media/v4l/cec-ioc-adap-g-phys-addr.xml |  78 ++
 .../DocBook/media/v4l/cec-ioc-adap-g-state.xml |  87 ++
 .../DocBook/media/v4l/cec-ioc-adap-g-vendor-id.xml |  70 +
 Documentation/DocBook/media/v4l/cec-ioc-claim.xml  |  71 +
 .../DocBook/media/v4l/cec-ioc-dqevent.xml  | 208 ++
 .../DocBook/media/v4l/cec-ioc-g-monitor.xml|  86 ++
 .../DocBook/media/v4l/cec-ioc-g-passthrough.xml|  81 ++
 .../DocBook/media/v4l/cec-ioc-receive.xml  | 185 +
 Documentation/DocBook/media_api.tmpl   |   8 +-
 18 files changed, 1742 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/DocBook/media/v4l/cec-api.xml
 create mode 100644 Documentation/DocBook/media/v4l/cec-func-close.xml
 create mode 100644 Documentation/DocBook/media/v4l/cec-func-ioctl.xml
 create mode 100644 Documentation/DocBook/media/v4l/cec-func-open.xml
 create mode 100644 Documentation/DocBook/media/v4l/cec-func-poll.xml
 create mode 100644 Documentation/DocBook/media/v4l/cec-ioc-adap-g-caps.xml
 create mode 100644 Documentation/DocBook/media/v4l/cec-ioc-adap-g-log-addrs.xml
 create mode 100644 Documentation/DocBook/media/v4l/cec-ioc-adap-g-phys-addr.xml
 create mode 100644 Documentation/DocBook/media/v4l/cec-ioc-adap-g-state.xml
 create mode 100644 Documentation/DocBook/media/v4l/cec-ioc-adap-g-vendor-id.xml
 create mode 100644 Documentation/DocBook/media/v4l/cec-ioc-claim.xml
 create mode 100644 Documentation/DocBook/media/v4l/cec-ioc-dqevent.xml
 create mode 100644 Documentation/DocBook/media/v4l/cec-ioc-g-monitor.xml
 create mode 100644 Documentation/DocBook/media/v4l/cec-ioc-g-passthrough.xml
 create mode 100644 Documentation/DocBook/media/v4l/cec-ioc-receive.xml

diff --git a/Documentation/DocBook/media/Makefile 
b/Documentation/DocBook/media/Makefile
index 08527e7..b97fb71 100644
--- a/Documentation/DocBook/media/Makefile
+++ b/Documentation/DocBook/media/Makefile
@@ -64,6 +64,7 @@ IOCTLS = \
$(shell perl -ne 'print "$$1 " if /\#define\s+([A-Z][^\s]+)\s+_IO/' 
$(srctree)/include/uapi/linux/dvb/net.h) \
$(shell perl -ne 'print "$$1 " if /\#define\s+([^\s]+)\s+_IO/' 
$(srctree)/include/uapi/linux/dvb/video.h) \
$(shell perl -ne 'print "$$1 " if /\#define\s+([^\s]+)\s+_IO/' 
$(srctree)/include/uapi/linux/media.h) \
+   $(shell perl -ne 'print "$$1 " if /\#define\s+([^\s]+)\s+_IO/' 
$(srctree)/include/uapi/linux/cec.h) \
$(shell perl -ne 'print "$$1 " if /\#define\s+([^\s]+)\s+_IO/' 
$(srctree)/include/uapi/linux/v4l2-subdev.h) \
 
 DEFINES = \
@@ -100,6 +101,7 @@ STRUCTS = \
$(shell perl -ne 'print "$$1 " if (/^struct\s+([^\s]+)\s+/ && !/_old/)' 
$(srctree)/include/uapi/linux/dvb/net.h) \
$(shell perl -ne 'print "$$1 " if (/^struct\s+([^\s]+)\s+/)' 
$(srctree)/include/uapi/linux/dvb/video.h) \
$(shell perl -ne 'print "$$1 " if /^struct\s+([^\s]+)\s+/' 
$(srctree)/include/uapi/linux/media.h) \
+   $(shell perl -ne 'print "$$1 " if /^struct\s+([^\s]+)\s+/' 
$(srctree)/include/uapi/linux/cec.h) \
$(shell perl -ne 'print "$$1 " if /^struct\s+([^\s]+)\s+/' 
$(srctree)/include/uapi/linux/v4l2-subdev.h) \
$(shell perl -ne 'print "$$1 " if /^struct\s+([^\s]+)\s+/' 
$(srctree)/include/uapi/linux/v4l2-mediabus.h)
 
diff --git a/Documentation/DocBook/media/v4l/biblio.xml 
b/Documentation/DocBook/media/v4l/biblio.xml
index fdee6b3..bed940b 100644
--- a/Documentation/DocBook/media/v4l/biblio.xml
+++ b/Documentation/DocBook/media/v4l/biblio.xml
@@ -324,6 +324,16 @@ in the frequency range from 87,5 to 108,0 MHz
   Specification Version 1.4a
 
 
+
+  HDMI2
+  
+   HDMI Licensing LLC
+(http://www.hdmi.org;>http://www.hdmi.org)
+  
+  High-Definition Multimedia Interface
+  Specification Version 2.0
+
+
 
   DP
   
diff --git a/Documenta

[PATCHv9 12/15] cec: adv7842: add cec support

2015-09-07 Thread Hans Verkuil
From: Hans Verkuil <hans.verk...@cisco.com>

Add CEC support to the adv7842 driver.

Signed-off-by: Hans Verkuil <hans.verk...@cisco.com>
---
 drivers/media/i2c/adv7842.c | 267 +---
 1 file changed, 250 insertions(+), 17 deletions(-)

diff --git a/drivers/media/i2c/adv7842.c b/drivers/media/i2c/adv7842.c
index b7269b8..b9f3e46 100644
--- a/drivers/media/i2c/adv7842.c
+++ b/drivers/media/i2c/adv7842.c
@@ -39,6 +39,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -79,6 +80,8 @@ MODULE_LICENSE("GPL");
 
 #define ADV7842_OP_SWAP_CB_CR  (1 << 0)
 
+#define ADV7842_MAX_ADDRS (3)
+
 /*
 **
 *
@@ -142,6 +145,11 @@ struct adv7842_state {
struct v4l2_ctrl *free_run_color_ctrl_manual;
struct v4l2_ctrl *free_run_color_ctrl;
struct v4l2_ctrl *rgb_quantization_range_ctrl;
+
+   bool cec_ready;
+   u8   cec_addr[ADV7842_MAX_ADDRS];
+   u8   cec_valid_addrs;
+   bool cec_enabled_adap;
 };
 
 /* Unsupported timings. This device cannot support 720p30. */
@@ -418,9 +426,9 @@ static inline int cec_write(struct v4l2_subdev *sd, u8 reg, 
u8 val)
return adv_smbus_write_byte_data(state->i2c_cec, reg, val);
 }
 
-static inline int cec_write_and_or(struct v4l2_subdev *sd, u8 reg, u8 mask, u8 
val)
+static inline int cec_write_clr_set(struct v4l2_subdev *sd, u8 reg, u8 mask, 
u8 val)
 {
-   return cec_write(sd, reg, (cec_read(sd, reg) & mask) | val);
+   return cec_write(sd, reg, (cec_read(sd, reg) & ~mask) | val);
 }
 
 static inline int infoframe_read(struct v4l2_subdev *sd, u8 reg)
@@ -696,6 +704,18 @@ adv7842_get_dv_timings_cap(struct v4l2_subdev *sd)
 
 /* --- */
 
+static u16 adv7842_read_cable_det(struct v4l2_subdev *sd)
+{
+   u8 reg = io_read(sd, 0x6f);
+   u16 val = 0;
+
+   if (reg & 0x02)
+   val |= 1; /* port A */
+   if (reg & 0x01)
+   val |= 2; /* port B */
+   return val;
+}
+
 static void adv7842_delayed_work_enable_hotplug(struct work_struct *work)
 {
struct delayed_work *dwork = to_delayed_work(work);
@@ -703,8 +723,15 @@ static void adv7842_delayed_work_enable_hotplug(struct 
work_struct *work)
struct adv7842_state, delayed_work_enable_hotplug);
struct v4l2_subdev *sd = >sd;
int present = state->hdmi_edid.present;
+   u16 connected_inputs;
u8 mask = 0;
 
+   if (state->cec_ready) {
+   connected_inputs = present & adv7842_read_cable_det(sd);
+   v4l2_subdev_notify(sd, V4L2_SUBDEV_CEC_CONN_INPUTS,
+  _inputs);
+   }
+
v4l2_dbg(2, debug, sd, "%s: enable hotplug on ports: 0x%x\n",
__func__, present);
 
@@ -983,20 +1010,17 @@ static int adv7842_s_register(struct v4l2_subdev *sd,
 static int adv7842_s_detect_tx_5v_ctrl(struct v4l2_subdev *sd)
 {
struct adv7842_state *state = to_state(sd);
-   int prev = v4l2_ctrl_g_ctrl(state->detect_tx_5v_ctrl);
-   u8 reg_io_6f = io_read(sd, 0x6f);
-   int val = 0;
+   u16 cable_det = adv7842_read_cable_det(sd);
+   u16 connected_inputs;
 
-   if (reg_io_6f & 0x02)
-   val |= 1; /* port A */
-   if (reg_io_6f & 0x01)
-   val |= 2; /* port B */
+   v4l2_dbg(1, debug, sd, "%s: 0x%x\n", __func__, cable_det);
 
-   v4l2_dbg(1, debug, sd, "%s: 0x%x -> 0x%x\n", __func__, prev, val);
+   connected_inputs = state->hdmi_edid.present & cable_det;
+   if (state->cec_ready)
+   v4l2_subdev_notify(sd, V4L2_SUBDEV_CEC_CONN_INPUTS,
+  _inputs);
 
-   if (val != prev)
-   return v4l2_ctrl_s_ctrl(state->detect_tx_5v_ctrl, val);
-   return 0;
+   return v4l2_ctrl_s_ctrl(state->detect_tx_5v_ctrl, cable_det);
 }
 
 static int find_and_set_predefined_video_timings(struct v4l2_subdev *sd,
@@ -2157,6 +2181,194 @@ static void adv7842_irq_enable(struct v4l2_subdev *sd, 
bool enable)
}
 }
 
+static void adv7842_cec_tx_raw_status(struct v4l2_subdev *sd, u8 tx_raw_status)
+{
+   if ((cec_read(sd, 0x11) & 0x01) == 0) {
+   v4l2_dbg(1, debug, sd, "%s: tx raw: tx disabled\n", __func__);
+   return;
+   }
+
+   if (tx_raw_status & 0x02) {
+   v4l2_dbg(1, debug, sd, "%s: tx raw: arbitration lost\n",
+__func__);
+   v4l2_subdev_notify(sd, V4L2_SUBDEV_CEC_TX_DONE,
+  (void *)CEC_TX_STATUS_ARB_LOST);
+   return;
+   }
+   if (tx_raw_status & 0x04) {
+   v4l2_dbg(1, debu

[PATCHv9 11/15] cec: adv7604: add cec support.

2015-09-07 Thread Hans Verkuil
From: Hans Verkuil <hans.verk...@cisco.com>

Add CEC support to the adv7604 driver.

Signed-off-by: Hans Verkuil <hansv...@cisco.com>
[k.deb...@samsung.com: Merged changes from CEC Updates commit by Hans Verkuil]
[k.deb...@samsung.com: add missing methods cec/io_write_and_or]
[k.deb...@samsung.com: change adv7604 to adv76xx in added functions]
[hansv...@cisco.com: use _clr_set instead of _and_or]
---
 drivers/media/i2c/adv7604.c | 254 +++-
 1 file changed, 250 insertions(+), 4 deletions(-)

diff --git a/drivers/media/i2c/adv7604.c b/drivers/media/i2c/adv7604.c
index 5631ec0..c8142c2 100644
--- a/drivers/media/i2c/adv7604.c
+++ b/drivers/media/i2c/adv7604.c
@@ -40,6 +40,7 @@
 #include 
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -80,6 +81,8 @@ MODULE_LICENSE("GPL");
 
 #define ADV76XX_OP_SWAP_CB_CR  (1 << 0)
 
+#define ADV76XX_MAX_ADDRS (3)
+
 enum adv76xx_type {
ADV7604,
ADV7611,
@@ -184,6 +187,11 @@ struct adv76xx_state {
u16 spa_port_a[2];
struct v4l2_fract aspect_ratio;
u32 rgb_quantization_range;
+   bool cec_ready;
+   u8   cec_addr[ADV76XX_MAX_ADDRS];
+   u8   cec_valid_addrs;
+   bool cec_enabled_adap;
+
struct workqueue_struct *work_queues;
struct delayed_work delayed_work_enable_hotplug;
bool restart_stdi_once;
@@ -430,7 +438,8 @@ static inline int io_write(struct v4l2_subdev *sd, u8 reg, 
u8 val)
return regmap_write(state->regmap[ADV76XX_PAGE_IO], reg, val);
 }
 
-static inline int io_write_clr_set(struct v4l2_subdev *sd, u8 reg, u8 mask, u8 
val)
+static inline int io_write_clr_set(struct v4l2_subdev *sd, u8 reg, u8 mask,
+  u8 val)
 {
return io_write(sd, reg, (io_read(sd, reg) & ~mask) | val);
 }
@@ -463,6 +472,12 @@ static inline int cec_write(struct v4l2_subdev *sd, u8 
reg, u8 val)
return regmap_write(state->regmap[ADV76XX_PAGE_CEC], reg, val);
 }
 
+static inline int cec_write_clr_set(struct v4l2_subdev *sd, u8 reg, u8 mask,
+  u8 val)
+{
+   return cec_write(sd, reg, (cec_read(sd, reg) & ~mask) | val);
+}
+
 static inline int infoframe_read(struct v4l2_subdev *sd, u8 reg)
 {
struct adv76xx_state *state = to_state(sd);
@@ -550,8 +565,15 @@ static inline int edid_write_block(struct v4l2_subdev *sd,
 
 static void adv76xx_set_hpd(struct adv76xx_state *state, unsigned int hpd)
 {
+   u16 connected_inputs;
unsigned int i;
 
+   if (state->cec_ready) {
+   connected_inputs = hpd & 
state->info->read_cable_det(>sd);
+   v4l2_subdev_notify(>sd, V4L2_SUBDEV_CEC_CONN_INPUTS,
+  _inputs);
+   }
+
for (i = 0; i < state->info->num_dv_ports; ++i)
gpiod_set_value_cansleep(state->hpd_gpio[i], hpd & BIT(i));
 
@@ -891,9 +913,14 @@ static int adv76xx_s_detect_tx_5v_ctrl(struct v4l2_subdev 
*sd)
 {
struct adv76xx_state *state = to_state(sd);
const struct adv76xx_chip_info *info = state->info;
+   u16 cable_det = info->read_cable_det(sd);
+   u16 connected_inputs = state->edid.present & cable_det;
+
+   if (state->cec_ready)
+   v4l2_subdev_notify(sd, V4L2_SUBDEV_CEC_CONN_INPUTS,
+  _inputs);
 
-   return v4l2_ctrl_s_ctrl(state->detect_tx_5v_ctrl,
-   info->read_cable_det(sd));
+   return v4l2_ctrl_s_ctrl(state->detect_tx_5v_ctrl, cable_det);
 }
 
 static int find_and_set_predefined_video_timings(struct v4l2_subdev *sd,
@@ -1914,6 +1941,198 @@ static int adv76xx_set_format(struct v4l2_subdev *sd,
return 0;
 }
 
+static void adv76xx_cec_tx_raw_status(struct v4l2_subdev *sd, u8 tx_raw_status)
+{
+   if ((cec_read(sd, 0x11) & 0x01) == 0) {
+   v4l2_dbg(1, debug, sd, "%s: tx raw: tx disabled\n", __func__);
+   return;
+   }
+
+   if (tx_raw_status & 0x02) {
+   v4l2_dbg(1, debug, sd, "%s: tx raw: arbitration lost\n",
+__func__);
+   v4l2_subdev_notify(sd, V4L2_SUBDEV_CEC_TX_DONE,
+  (void *)CEC_TX_STATUS_ARB_LOST);
+   return;
+   }
+   if (tx_raw_status & 0x04) {
+   v4l2_dbg(1, debug, sd, "%s: tx raw: retry failed\n", __func__);
+   v4l2_subdev_notify(sd, V4L2_SUBDEV_CEC_TX_DONE,
+  (void *)CEC_TX_STATUS_RETRY_TIMEOUT);
+   return;
+   }
+   if (tx_raw_status & 0x01) {
+   v4l2_dbg(1, debug, sd, "%s: tx raw: ready ok\n", __func__);
+   v4l2_subdev_notify(sd, V4L2_SUBDEV_CEC_TX_DONE,
+  (void *)CEC_TX_STATUS_OK);

[PATCHv9 15/15] cobalt: add cec support

2015-09-07 Thread Hans Verkuil
From: Hans Verkuil <hans.verk...@cisco.com>

Add CEC support to the cobalt driver.

Signed-off-by: Hans Verkuil <hans.verk...@cisco.com>
---
 drivers/media/pci/cobalt/Kconfig |   1 +
 drivers/media/pci/cobalt/cobalt-driver.c |  51 --
 drivers/media/pci/cobalt/cobalt-driver.h |   2 +
 drivers/media/pci/cobalt/cobalt-irq.c|   3 +
 drivers/media/pci/cobalt/cobalt-v4l2.c   | 113 +--
 5 files changed, 159 insertions(+), 11 deletions(-)

diff --git a/drivers/media/pci/cobalt/Kconfig b/drivers/media/pci/cobalt/Kconfig
index 1f88ccc..46483ee 100644
--- a/drivers/media/pci/cobalt/Kconfig
+++ b/drivers/media/pci/cobalt/Kconfig
@@ -4,6 +4,7 @@ config VIDEO_COBALT
depends on PCI_MSI && MTD_COMPLEX_MAPPINGS
depends on GPIOLIB || COMPILE_TEST
depends on SND
+   select CEC
select I2C_ALGOBIT
select VIDEO_ADV7604
select VIDEO_ADV7511
diff --git a/drivers/media/pci/cobalt/cobalt-driver.c 
b/drivers/media/pci/cobalt/cobalt-driver.c
index 8fed61e..ed53781 100644
--- a/drivers/media/pci/cobalt/cobalt-driver.c
+++ b/drivers/media/pci/cobalt/cobalt-driver.c
@@ -76,6 +76,7 @@ static u8 edid[256] = {
0x0A, 0x0A, 0x0A, 0x0A, 0x00, 0x00, 0x00, 0x10,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x68,
+
0x02, 0x03, 0x1a, 0xc0, 0x48, 0xa2, 0x10, 0x04,
0x02, 0x01, 0x21, 0x14, 0x13, 0x23, 0x09, 0x07,
0x07, 0x65, 0x03, 0x0c, 0x00, 0x10, 0x00, 0xe2,
@@ -149,17 +150,58 @@ static void cobalt_notify(struct v4l2_subdev *sd,
struct cobalt *cobalt = to_cobalt(sd->v4l2_dev);
unsigned sd_nr = cobalt_get_sd_nr(sd);
struct cobalt_stream *s = >streams[sd_nr];
-   bool hotplug = arg ? *((int *)arg) : false;
 
-   if (s->is_output)
+   switch (notification) {
+   case V4L2_SUBDEV_CEC_TX_DONE:
+   cec_transmit_done(s->cec_adap, (unsigned long)arg);
+   return;
+   case V4L2_SUBDEV_CEC_RX_MSG:
+   cec_received_msg(s->cec_adap, arg);
+   return;
+   case V4L2_SUBDEV_CEC_CONN_INPUTS:
+   cec_connected_inputs(s->cec_adap, *(u16 *)arg);
+   return;
+   default:
+   break;
+   }
+
+   if (s->is_output) {
+   switch (notification) {
+   case ADV7511_EDID_DETECT: {
+   struct adv7511_edid_detect *ed = arg;
+
+   s->cec_adap->phys_addr = ed->phys_addr;
+   if (!ed->present) {
+   cec_enable(s->cec_adap, false);
+   break;
+   }
+   cec_enable(s->cec_adap, true);
+   break;
+   }
+   case ADV7511_MONITOR_DETECT: {
+   struct adv7511_monitor_detect *md = arg;
+
+   if (!md->present) {
+   cec_enable(s->cec_adap, false);
+   break;
+   }
+   break;
+   }
+   }
return;
+   }
 
switch (notification) {
-   case ADV76XX_HOTPLUG:
+   case ADV76XX_HOTPLUG: {
+   bool hotplug = arg ? *((int *)arg) : false;
+
cobalt_s_bit_sysctrl(cobalt,
COBALT_SYS_CTRL_HPD_TO_CONNECTOR_BIT(sd_nr), hotplug);
+   if (s->cec_adap)
+   cec_connected_inputs(s->cec_adap, hotplug);
cobalt_dbg(1, "Set hotplug for adv %d to %d\n", sd_nr, hotplug);
break;
+   }
case V4L2_DEVICE_NOTIFY_EVENT:
cobalt_dbg(1, "Format changed for adv %d\n", sd_nr);
v4l2_event_queue(>vdev, arg);
@@ -627,8 +669,9 @@ static int cobalt_subdevs_hsma_init(struct cobalt *cobalt)
s->sd = v4l2_i2c_new_subdev_board(>v4l2_dev,
s->i2c_adap, _info, NULL);
if (s->sd) {
-   int err = v4l2_subdev_call(s->sd, pad, set_edid, _edid);
+   int err;
 
+   err = v4l2_subdev_call(s->sd, pad, set_edid, _edid);
if (err)
return err;
err = v4l2_subdev_call(s->sd, pad, set_fmt, NULL,
diff --git a/drivers/media/pci/cobalt/cobalt-driver.h 
b/drivers/media/pci/cobalt/cobalt-driver.h
index c206df9..55a8c0d 100644
--- a/drivers/media/pci/cobalt/cobalt-driver.h
+++ b/drivers/media/pci/cobalt/cobalt-driver.h
@@ -31,6 +31,7 @@
 #include 
 #include 
 
+#include 
 #include 
 #include 
 #include 
@@ -221,6 +222,7 @@ struct cobalt_stream {
struct list_head bufs;
struct i2c_adapter *i2c_adap;
struct v4l2_subdev *sd;
+   struct cec_adapter *cec_adap;
struct mutex lock;
  

[PATCHv9 10/15] v4l2-subdev: add HDMI CEC ops

2015-09-07 Thread Hans Verkuil
From: Hans Verkuil <hans.verk...@cisco.com>

Add CEC callbacks to the v4l2_subdev_video_ops. These are the low-level CEC
ops that subdevs that support CEC have to implement.

Signed-off-by: Hans Verkuil <hansv...@cisco.com>
[k.deb...@samsung.com: Merged changes from CEC Updates commit by Hans Verkuil]
Signed-off-by: Kamil Debski <ka...@wypas.org>
---
 include/media/v4l2-subdev.h | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
index b273cf9..3adddc7 100644
--- a/include/media/v4l2-subdev.h
+++ b/include/media/v4l2-subdev.h
@@ -42,6 +42,10 @@
 
 #defineV4L2_DEVICE_NOTIFY_EVENT_IOW('v', 2, struct 
v4l2_event)
 
+#define V4L2_SUBDEV_CEC_TX_DONE_IOW('v', 3, u32)
+#define V4L2_SUBDEV_CEC_RX_MSG _IOW('v', 4, struct cec_msg)
+#define V4L2_SUBDEV_CEC_CONN_INPUTS_IOW('v', 5, u16)
+
 struct v4l2_device;
 struct v4l2_ctrl_handler;
 struct v4l2_event;
@@ -51,6 +55,7 @@ struct v4l2_subdev;
 struct v4l2_subdev_fh;
 struct tuner_setup;
 struct v4l2_mbus_frame_desc;
+struct cec_msg;
 
 /* decode_vbi_line */
 struct v4l2_decode_vbi_line {
@@ -421,6 +426,11 @@ struct v4l2_subdev_video_ops {
 const struct v4l2_mbus_config *cfg);
int (*s_rx_buffer)(struct v4l2_subdev *sd, void *buf,
   unsigned int *size);
+   void (*cec_ready)(struct v4l2_subdev *sd);
+   unsigned (*cec_available_log_addrs)(struct v4l2_subdev *sd);
+   int (*cec_enable)(struct v4l2_subdev *sd, bool enable);
+   int (*cec_log_addr)(struct v4l2_subdev *sd, u8 logical_addr);
+   int (*cec_transmit)(struct v4l2_subdev *sd, u32 timeout_ms, struct 
cec_msg *msg);
 };
 
 /**
-- 
2.1.4

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


[PATCHv9 03/15] dts: exynos4412-odroid*: enable the HDMI CEC device

2015-09-07 Thread Hans Verkuil
From: Kamil Debski <ka...@wypas.org>

Add a dts node entry and enable the HDMI CEC device present in the Exynos4
family of SoCs.

Signed-off-by: Kamil Debski <ka...@wypas.org>
Signed-off-by: Hans Verkuil <hans.verk...@cisco.com>
Acked-by: Krzysztof Kozlowski <k.kozlow...@samsung.com>
---
 arch/arm/boot/dts/exynos4210-universal_c210.dts | 4 
 1 file changed, 4 insertions(+)

diff --git a/arch/arm/boot/dts/exynos4210-universal_c210.dts 
b/arch/arm/boot/dts/exynos4210-universal_c210.dts
index d4f2b11..06df693 100644
--- a/arch/arm/boot/dts/exynos4210-universal_c210.dts
+++ b/arch/arm/boot/dts/exynos4210-universal_c210.dts
@@ -515,6 +515,10 @@
enable-active-high;
};
 
+   cec@100B {
+   status = "okay";
+   };
+
hdmi_ddc: i2c-ddc {
compatible = "i2c-gpio";
gpios = < 2 0  3 0>;
-- 
2.1.4

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


[PATCHv9 05/15] HID: add HDMI CEC specific keycodes

2015-09-07 Thread Hans Verkuil
From: Kamil Debski <ka...@wypas.org>

Add HDMI CEC specific keycodes to the keycodes definition.

Signed-off-by: Kamil Debski <ka...@wypas.org>
Signed-off-by: Hans Verkuil <hans.verk...@cisco.com>
---
 include/uapi/linux/input.h | 28 
 1 file changed, 28 insertions(+)

diff --git a/include/uapi/linux/input.h b/include/uapi/linux/input.h
index a32bff1..5e7019a 100644
--- a/include/uapi/linux/input.h
+++ b/include/uapi/linux/input.h
@@ -752,6 +752,34 @@ struct input_keymap_entry {
 #define KEY_KBDINPUTASSIST_ACCEPT  0x264
 #define KEY_KBDINPUTASSIST_CANCEL  0x265
 
+#define KEY_RIGHT_UP   0x266
+#define KEY_RIGHT_DOWN 0x267
+#define KEY_LEFT_UP0x268
+#define KEY_LEFT_DOWN  0x269
+#define KEY_ROOT_MENU  0x26a /* Show Device's Root Menu */
+#define KEY_MEDIA_TOP_MENU 0x26b /* Show Top Menu of the Media 
(e.g. DVD) */
+#define KEY_NUMERIC_11 0x26c
+#define KEY_NUMERIC_12 0x26d
+/*
+ * Toggle Audio Description: refers to an audio service that helps blind and
+ * visually impaired consumers understand the action in a program. Note: in
+ * some countries this is referred to as "Video Description".
+ */
+#define KEY_AUDIO_DESC 0x26e
+#define KEY_3D_MODE0x26f
+#define KEY_NEXT_FAVORITE  0x270
+#define KEY_STOP_RECORD0x271
+#define KEY_PAUSE_RECORD   0x272
+#define KEY_VOD0x273 /* Video on Demand */
+#define KEY_UNMUTE 0x274
+#define KEY_FASTREVERSE0x275
+#define KEY_SLOWREVERSE0x276
+/*
+ * Control a data application associated with the currently viewed channel,
+ * e.g. teletext or data broadcast application (MHEG, MHP, HbbTV, etc.)
+ */
+#define KEY_DATA   0x275
+
 #define BTN_TRIGGER_HAPPY  0x2c0
 #define BTN_TRIGGER_HAPPY1 0x2c0
 #define BTN_TRIGGER_HAPPY2 0x2c1
-- 
2.1.4

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


[PATCHv9 04/15] input.h: add BUS_CEC type

2015-09-07 Thread Hans Verkuil
From: Hans Verkuil <hans.verk...@cisco.com>

Inputs can come in over the HDMI CEC bus, so add a new type for this.

Signed-off-by: Hans Verkuil <hans.verk...@cisco.com>
Acked-by: Dmitry Torokhov <dmitry.torok...@gmail.com>
---
 include/uapi/linux/input.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/uapi/linux/input.h b/include/uapi/linux/input.h
index 731417c..a32bff1 100644
--- a/include/uapi/linux/input.h
+++ b/include/uapi/linux/input.h
@@ -972,6 +972,7 @@ struct input_keymap_entry {
 #define BUS_GSC0x1A
 #define BUS_ATARI  0x1B
 #define BUS_SPI0x1C
+#define BUS_CEC0x1D
 
 /*
  * MT_TOOL types
-- 
2.1.4

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


[PATCHv9 08/15] cec.txt: add CEC framework documentation

2015-09-07 Thread Hans Verkuil
Document the new HDMI CEC framework.

Signed-off-by: Hans Verkuil <hansv...@cisco.com>
[k.deb...@samsung.com: add DocBook documentation by Hans Verkuil, with
Signed-off-by: Kamil Debski <ka...@wypas.org>
Signed-off-by: Hans Verkuil <hans.verk...@cisco.com>
---
 Documentation/cec.txt | 166 ++
 1 file changed, 166 insertions(+)
 create mode 100644 Documentation/cec.txt

diff --git a/Documentation/cec.txt b/Documentation/cec.txt
new file mode 100644
index 000..b298249
--- /dev/null
+++ b/Documentation/cec.txt
@@ -0,0 +1,166 @@
+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 logical addresses in the
+communication. The logical address is strictly connected with the functionality
+provided by the device. The TV acting as the communication hub is always
+assigned address 0. The physical address is determined by the physical
+connection between devices.
+
+The protocol enables control of compatible devices with a single remote.
+Synchronous power on/standby, instant playback with changing the content source
+on the TV.
+
+The Kernel Interface
+
+
+CEC Adapter
+---
+
+#define CEC_LOG_ADDR_INVALID 0xff
+
+/* The maximum number of logical addresses one device can be assigned to.
+ * The CEC 2.0 spec allows for only 2 logical addresses at the moment. The
+ * Analog Devices CEC hardware supports 3. So let's go wild and go for 4. */
+#define CEC_MAX_LOG_ADDRS 4
+
+/* The "Primary Device Type" */
+#define CEC_OP_PRIM_DEVTYPE_TV 0
+#define CEC_OP_PRIM_DEVTYPE_RECORD 1
+#define CEC_OP_PRIM_DEVTYPE_TUNER  3
+#define CEC_OP_PRIM_DEVTYPE_PLAYBACK   4
+#define CEC_OP_PRIM_DEVTYPE_AUDIOSYSTEM5
+#define CEC_OP_PRIM_DEVTYPE_SWITCH 6
+#define CEC_OP_PRIM_DEVTYPE_VIDEOPROC  7
+
+/* The "All Device Types" flags (CEC 2.0) */
+#define CEC_OP_ALL_DEVTYPE_TV  (1 << 7)
+#define CEC_OP_ALL_DEVTYPE_RECORD  (1 << 6)
+#define CEC_OP_ALL_DEVTYPE_TUNER   (1 << 5)
+#define CEC_OP_ALL_DEVTYPE_PLAYBACK(1 << 4)
+#define CEC_OP_ALL_DEVTYPE_AUDIOSYSTEM (1 << 3)
+#define CEC_OP_ALL_DEVTYPE_SWITCH  (1 << 2)
+/* And if you wondering what happened to VIDEOPROC devices: those should
+ * be mapped to a SWITCH. */
+
+/* The logical address types that the CEC device wants to claim */
+#define CEC_LOG_ADDR_TYPE_TV   0
+#define CEC_LOG_ADDR_TYPE_RECORD   1
+#define CEC_LOG_ADDR_TYPE_TUNER2
+#define CEC_LOG_ADDR_TYPE_PLAYBACK 3
+#define CEC_LOG_ADDR_TYPE_AUDIOSYSTEM  4
+#define CEC_LOG_ADDR_TYPE_SPECIFIC 5
+#define CEC_LOG_ADDR_TYPE_UNREGISTERED 6
+/* Switches should use UNREGISTERED.
+ * Video processors should use SPECIFIC. */
+
+/* The CEC version */
+#define CEC_OP_CEC_VERSION_1_3A4
+#define CEC_OP_CEC_VERSION_1_4 5
+#define CEC_OP_CEC_VERSION_2_0 6
+
+struct cec_adapter {
+   /* internal fields removed */
+
+   u16 phys_addr;
+   u32 capabilities;
+   u8 version;
+   u8 num_log_addrs;
+   u8 prim_device[CEC_MAX_LOG_ADDRS];
+   u8 log_addr_type[CEC_MAX_LOG_ADDRS];
+   u8 log_addr[CEC_MAX_LOG_ADDRS];
+
+   int (*adap_enable)(struct cec_adapter *adap, bool enable);
+   int (*adap_log_addr)(struct cec_adapter *adap, u8 logical_addr);
+   int (*adap_transmit)(struct cec_adapter *adap, struct cec_msg *msg);
+   void (*adap_transmit_timed_out)(struct cec_adapter *adap);
+
+   void (*claimed_log_addr)(struct cec_adapter *adap, u8 idx);
+   int (*received)(struct cec_adapter *adap, struct cec_msg *msg);
+};
+
+int cec_create_adapter(struct cec_adapter *adap, u32 caps);
+void cec_delete_adapter(struct cec_adapter *adap);
+int cec_transmit_msg(struct cec_adapter *adap, struct cec_data *data, bool 
block);
+
+/* Called by the adapter */
+void cec_transmit_done(struct cec_adapter *adap, u32 status);
+void cec_received_msg(struct cec_adapter *adap, struct cec_msg *msg);
+
+int cec_receive_msg(struct cec_adapter *adap, struct cec_msg *msg, bool block);
+int cec_claim_log_addrs(struct cec_adapter *adap, struct cec_log_addrs 
*log_addrs, bool block);
+
+The device type defines are defined by the CEC standard.
+
+The cec_adapter structure represents the adapter. It has a number of
+operations that have to be implemented in the driver: adap_enable() enables
+or disables the physical adapter, adap_log_addr() tells the driver whic

[PATCHv9 14/15] cec: s5p-cec: Add s5p-cec driver

2015-09-07 Thread Hans Verkuil
From: Kamil Debski <ka...@wypas.org>

Add CEC interface driver present in the Samsung Exynos range of
SoCs.

The following files were based on work by SangPil Moon:
- exynos_hdmi_cec.h
- exynos_hdmi_cecctl.c

Signed-off-by: Kamil Debski <ka...@wypas.org>
Signed-off-by: Hans Verkuil <hans.verk...@cisco.com>
---
 .../devicetree/bindings/media/s5p-cec.txt  |  31 +++
 drivers/media/platform/Kconfig |  12 +
 drivers/media/platform/Makefile|   1 +
 drivers/media/platform/s5p-cec/Makefile|   2 +
 drivers/media/platform/s5p-cec/exynos_hdmi_cec.h   |  37 +++
 .../media/platform/s5p-cec/exynos_hdmi_cecctrl.c   | 208 +++
 drivers/media/platform/s5p-cec/regs-cec.h  |  96 +++
 drivers/media/platform/s5p-cec/s5p_cec.c   | 284 +
 drivers/media/platform/s5p-cec/s5p_cec.h   |  76 ++
 9 files changed, 747 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/s5p-cec.txt
 create mode 100644 drivers/media/platform/s5p-cec/Makefile
 create mode 100644 drivers/media/platform/s5p-cec/exynos_hdmi_cec.h
 create mode 100644 drivers/media/platform/s5p-cec/exynos_hdmi_cecctrl.c
 create mode 100644 drivers/media/platform/s5p-cec/regs-cec.h
 create mode 100644 drivers/media/platform/s5p-cec/s5p_cec.c
 create mode 100644 drivers/media/platform/s5p-cec/s5p_cec.h

diff --git a/Documentation/devicetree/bindings/media/s5p-cec.txt 
b/Documentation/devicetree/bindings/media/s5p-cec.txt
new file mode 100644
index 000..925ab4d
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/s5p-cec.txt
@@ -0,0 +1,31 @@
+* Samsung HDMI CEC driver
+
+The HDMI CEC module is present is Samsung SoCs and its purpose is to
+handle communication between HDMI connected devices over the CEC bus.
+
+Required properties:
+  - compatible : value should be following
+   "samsung,s5p-cec"
+
+  - reg : Physical base address of the IP registers and length of memory
+ mapped region.
+
+  - interrupts : HDMI CEC interrupt number to the CPU.
+  - clocks : from common clock binding: handle to HDMI CEC clock.
+  - clock-names : from common clock binding: must contain "hdmicec",
+ corresponding to entry in the clocks property.
+  - samsung,syscon-phandle - phandle to the PMU system controller
+
+Example:
+
+hdmicec: cec@100B {
+   compatible = "samsung,s5p-cec";
+   reg = <0x100B 0x200>;
+   interrupts = <0 114 0>;
+   clocks = < CLK_HDMI_CEC>;
+   clock-names = "hdmicec";
+   samsung,syscon-phandle = <_system_controller>;
+   pinctrl-names = "default";
+   pinctrl-0 = <_cec>;
+   status = "okay";
+};
diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index dc75694..58346e6 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -117,6 +117,18 @@ config VIDEO_S3C_CAMIF
 source "drivers/media/platform/soc_camera/Kconfig"
 source "drivers/media/platform/exynos4-is/Kconfig"
 source "drivers/media/platform/s5p-tv/Kconfig"
+
+config VIDEO_SAMSUNG_S5P_CEC
+   tristate "Samsung S5P CEC driver"
+   depends on VIDEO_DEV && VIDEO_V4L2 && (PLAT_S5P || ARCH_EXYNOS || 
COMPILE_TEST)
+   select CEC
+   default n
+   ---help---
+ This is a driver for Samsung S5P HDMI CEC interface. It uses the
+ generic CEC framework interface.
+ CEC bus is present in the HDMI connector and enables communication
+ between compatible devices.
+
 source "drivers/media/platform/am437x/Kconfig"
 source "drivers/media/platform/xilinx/Kconfig"
 
diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile
index efa0295..957af5f 100644
--- a/drivers/media/platform/Makefile
+++ b/drivers/media/platform/Makefile
@@ -27,6 +27,7 @@ obj-$(CONFIG_VIDEO_MEM2MEM_DEINTERLACE)   += 
m2m-deinterlace.o
 
 obj-$(CONFIG_VIDEO_S3C_CAMIF)  += s3c-camif/
 obj-$(CONFIG_VIDEO_SAMSUNG_EXYNOS4_IS) += exynos4-is/
+obj-$(CONFIG_VIDEO_SAMSUNG_S5P_CEC)+= s5p-cec/
 obj-$(CONFIG_VIDEO_SAMSUNG_S5P_JPEG)   += s5p-jpeg/
 obj-$(CONFIG_VIDEO_SAMSUNG_S5P_MFC)+= s5p-mfc/
 obj-$(CONFIG_VIDEO_SAMSUNG_S5P_TV) += s5p-tv/
diff --git a/drivers/media/platform/s5p-cec/Makefile 
b/drivers/media/platform/s5p-cec/Makefile
new file mode 100644
index 000..0e2cf45
--- /dev/null
+++ b/drivers/media/platform/s5p-cec/Makefile
@@ -0,0 +1,2 @@
+obj-$(CONFIG_VIDEO_SAMSUNG_S5P_CEC)+= s5p-cec.o
+s5p-cec-y += s5p_cec.o exynos_hdmi_cecctrl.o
diff --git a/drivers/media/platform/s5p-cec/exynos_hdmi_cec.h 
b/drivers/media/platform/s5p-cec/exynos_hdmi_cec.h
new file mode 100644
index 000..d008695
--- /dev/null
+++ b/drivers/media/platform/s5p-cec/exynos_hdmi_cec.h
@@ -0,0 +1,37 @@
+/* drivers/media/plat

[PATCHv9 02/15] dts: exynos4: add node for the HDMI CEC device

2015-09-07 Thread Hans Verkuil
From: Kamil Debski <ka...@wypas.org>

This patch adds HDMI CEC node specific to the Exynos4210/4x12 SoC series.

Signed-off-by: Kamil Debski <ka...@wypas.org>
Signed-off-by: Hans Verkuil <hans.verk...@cisco.com>
Acked-by: Krzysztof Kozlowski <k.kozlow...@samsung.com>
---
 arch/arm/boot/dts/exynos4.dtsi | 12 
 1 file changed, 12 insertions(+)

diff --git a/arch/arm/boot/dts/exynos4.dtsi b/arch/arm/boot/dts/exynos4.dtsi
index b0d52b1..0d5319e 100644
--- a/arch/arm/boot/dts/exynos4.dtsi
+++ b/arch/arm/boot/dts/exynos4.dtsi
@@ -719,6 +719,18 @@
status = "disabled";
};
 
+   hdmicec: cec@100B {
+   compatible = "samsung,s5p-cec";
+   reg = <0x100B 0x200>;
+   interrupts = <0 114 0>;
+   clocks = < CLK_HDMI_CEC>;
+   clock-names = "hdmicec";
+   samsung,syscon-phandle = <_system_controller>;
+   pinctrl-names = "default";
+   pinctrl-0 = <_cec>;
+   status = "disabled";
+   };
+
mixer: mixer@12C1 {
compatible = "samsung,exynos4210-mixer";
interrupts = <0 91 0>;
-- 
2.1.4

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


[PATCHv9 00/15] HDMI CEC framework

2015-09-07 Thread Hans Verkuil
ion

Changes since v4

- add sequence numbering to transmitted messages
- add sequence number handling to event hanlding
- add passthrough mode
- change reserved field sizes
- fixed CEC version defines and addec CEC 2.0 commands
- add DocBook documentation

Changes since v3

- remove the promiscuous mode
- rewrite the devicetree patches
- fixes, expansion and partial rewrite of the documentation
- reorder of API structures and addition of reserved fields
- use own struct to report time (32/64 bit safe)
- fix of handling events
- add cec.h to include/uapi/linux/Kbuild
- fixes in the adv76xx driver (add missing methods, change adv7604 to adv76xx)
- cleanup of debug messages in s5p-cec driver
- remove non necessary claiming of a gpio in the s5p-cec driver
- cleanup headers of the s5p-cec driver

Changes since v2
===-
- added promiscuous mode
- added new key codes to the input framework
- add vendor ID reporting
- add the possibility to clear assigned logical addresses
- cleanup of the rc cec map

Changes since v1

- documentation edited and moved to the Documentation folder
- added key up/down message handling
- add missing CEC commands to the cec.h file

Background
==

The work on a common CEC framework was started over three years ago by Hans
Verkuil. Unfortunately the work has stalled. As I have received the task of
creating a driver for the CEC interface module present on the Exynos range of
SoCs, I got in touch with Hans. He replied that the work stalled due to his
lack of time.

Original RFC by Hans Verkuil/Martin Bugge
=
https://www.mail-archive.com/linux-media@vger.kernel.org/msg28735.html


Hans Verkuil (9):
  input.h: add BUS_CEC type
  cec: add HDMI CEC framework
  cec.txt: add CEC framework documentation
  DocBook/media: add CEC documentation
  v4l2-subdev: add HDMI CEC ops
  cec: adv7604: add cec support.
  cec: adv7842: add cec support
  cec: adv7511: add cec support.
  cobalt: add cec support

Kamil Debski (6):
  dts: exynos4*: add HDMI CEC pin definition to pinctrl
  dts: exynos4: add node for the HDMI CEC device
  dts: exynos4412-odroid*: enable the HDMI CEC device
  HID: add HDMI CEC specific keycodes
  rc: Add HDMI CEC protocol handling
  cec: s5p-cec: Add s5p-cec driver

 Documentation/DocBook/media/Makefile   |2 +
 Documentation/DocBook/media/v4l/biblio.xml |   10 +
 Documentation/DocBook/media/v4l/cec-api.xml|   76 +
 Documentation/DocBook/media/v4l/cec-func-close.xml |   59 +
 Documentation/DocBook/media/v4l/cec-func-ioctl.xml |   73 +
 Documentation/DocBook/media/v4l/cec-func-open.xml  |   94 +
 Documentation/DocBook/media/v4l/cec-func-poll.xml  |   89 +
 .../DocBook/media/v4l/cec-ioc-adap-g-caps.xml  |  161 ++
 .../DocBook/media/v4l/cec-ioc-adap-g-log-addrs.xml |  306 
 .../DocBook/media/v4l/cec-ioc-adap-g-phys-addr.xml |   78 +
 .../DocBook/media/v4l/cec-ioc-adap-g-state.xml |   87 +
 .../DocBook/media/v4l/cec-ioc-adap-g-vendor-id.xml |   70 +
 Documentation/DocBook/media/v4l/cec-ioc-claim.xml  |   71 +
 .../DocBook/media/v4l/cec-ioc-dqevent.xml  |  208 +++
 .../DocBook/media/v4l/cec-ioc-g-monitor.xml|   86 +
 .../DocBook/media/v4l/cec-ioc-g-passthrough.xml|   81 +
 .../DocBook/media/v4l/cec-ioc-receive.xml  |  185 ++
 Documentation/DocBook/media_api.tmpl   |8 +-
 Documentation/cec.txt  |  166 ++
 .../devicetree/bindings/media/s5p-cec.txt  |   31 +
 MAINTAINERS|   12 +
 arch/arm/boot/dts/exynos4.dtsi |   12 +
 arch/arm/boot/dts/exynos4210-pinctrl.dtsi  |7 +
 arch/arm/boot/dts/exynos4210-universal_c210.dts|4 +
 arch/arm/boot/dts/exynos4x12-pinctrl.dtsi  |7 +
 drivers/media/Kconfig  |6 +
 drivers/media/Makefile |2 +
 drivers/media/cec.c| 1921 
 drivers/media/i2c/adv7511.c|  359 +++-
 drivers/media/i2c/adv7604.c|  254 ++-
 drivers/media/i2c/adv7842.c|  267 ++-
 drivers/media/pci/cobalt/Kconfig   |1 +
 drivers/media/pci/cobalt/cobalt-driver.c   |   51 +-
 drivers/media/pci/cobalt/cobalt-driver.h   |2 +
 drivers/media/pci/cobalt/cobalt-irq.c  |3 +
 drivers/media/pci/cobalt/cobalt-v4l2.c |  113 +-
 drivers/media/platform/Kconfig |   12 +
 drivers/media/platform/Makefile|1 +
 drivers/media/platform/s5p-cec/Makefile|2 +
 drivers/media/platform/s5p-cec/exynos_hdmi_cec.h   |   37 +
 .../media/platform/s5p-cec/exynos_hdmi_cecctrl.c   |  208 +++
 drivers/media/platform/s5p-cec/regs-cec.h  |   96 +
 drivers/media/platform/s5p-cec/s5p_cec.c   |  284 +++
 driv

[PATCHv9 06/15] rc: Add HDMI CEC protocol handling

2015-09-07 Thread Hans Verkuil
From: Kamil Debski <ka...@wypas.org>

Add handling of remote control events coming from the HDMI CEC bus.
This patch includes a new keymap that maps values found in the CEC
messages to the keys pressed and released. Also, a new protocol has
been added to the core.

Signed-off-by: Kamil Debski <ka...@wypas.org>
Signed-off-by: Hans Verkuil <hans.verk...@cisco.com>
---
 drivers/media/rc/keymaps/Makefile |   1 +
 drivers/media/rc/keymaps/rc-cec.c | 174 ++
 drivers/media/rc/rc-main.c|   1 +
 include/media/rc-core.h   |   1 +
 include/media/rc-map.h|   5 +-
 5 files changed, 181 insertions(+), 1 deletion(-)
 create mode 100644 drivers/media/rc/keymaps/rc-cec.c

diff --git a/drivers/media/rc/keymaps/Makefile 
b/drivers/media/rc/keymaps/Makefile
index fbbd3bb..9cffcc6 100644
--- a/drivers/media/rc/keymaps/Makefile
+++ b/drivers/media/rc/keymaps/Makefile
@@ -18,6 +18,7 @@ obj-$(CONFIG_RC_MAP) += rc-adstech-dvb-t-pci.o \
rc-behold.o \
rc-behold-columbus.o \
rc-budget-ci-old.o \
+   rc-cec.o \
rc-cinergy-1400.o \
rc-cinergy.o \
rc-delock-61959.o \
diff --git a/drivers/media/rc/keymaps/rc-cec.c 
b/drivers/media/rc/keymaps/rc-cec.c
new file mode 100644
index 000..193cdca
--- /dev/null
+++ b/drivers/media/rc/keymaps/rc-cec.c
@@ -0,0 +1,174 @@
+/* Keytable for the CEC remote control
+ *
+ * Copyright (c) 2015 by Kamil Debski
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include 
+#include 
+
+/* CEC Spec "High-Definition Multimedia Interface Specification" can be 
obtained
+ * here: http://xtreamerdev.googlecode.com/files/CEC_Specs.pdf
+ * The list of control codes is listed in Table 27: User Control Codes p. 95 */
+
+static struct rc_map_table cec[] = {
+   { 0x00, KEY_OK },
+   { 0x01, KEY_UP },
+   { 0x02, KEY_DOWN },
+   { 0x03, KEY_LEFT },
+   { 0x04, KEY_RIGHT },
+   { 0x05, KEY_RIGHT_UP },
+   { 0x06, KEY_RIGHT_DOWN },
+   { 0x07, KEY_LEFT_UP },
+   { 0x08, KEY_LEFT_DOWN },
+   { 0x09, KEY_ROOT_MENU }, /* CEC Spec: Device Root Menu - see Note 2 */
+   /* Note 2: This is the initial display that a device shows. It is
+* device-dependent and can be, for example, a contents menu, setup
+* menu, favorite menu or other menu. The actual menu displayed
+* may also depend on the device's current state. */
+   { 0x0a, KEY_SETUP },
+   { 0x0b, KEY_MENU }, /* CEC Spec: Contents Menu */
+   { 0x0c, KEY_FAVORITES }, /* CEC Spec: Favorite Menu */
+   { 0x0d, KEY_EXIT },
+   /* 0x0e-0x0f: Reserved */
+   { 0x10, KEY_MEDIA_TOP_MENU },
+   { 0x11, KEY_CONTEXT_MENU },
+   /* 0x12-0x1c: Reserved */
+   { 0x1d, KEY_DIGITS }, /* CEC Spec: select/toggle a Number Entry Mode */
+   { 0x1e, KEY_NUMERIC_11 },
+   { 0x1f, KEY_NUMERIC_12 },
+   /* 0x20-0x29: Keys 0 to 9 */
+   { 0x20, KEY_NUMERIC_0 },
+   { 0x21, KEY_NUMERIC_1 },
+   { 0x22, KEY_NUMERIC_2 },
+   { 0x23, KEY_NUMERIC_3 },
+   { 0x24, KEY_NUMERIC_4 },
+   { 0x25, KEY_NUMERIC_5 },
+   { 0x26, KEY_NUMERIC_6 },
+   { 0x27, KEY_NUMERIC_7 },
+   { 0x28, KEY_NUMERIC_8 },
+   { 0x29, KEY_NUMERIC_9 },
+   { 0x2a, KEY_DOT },
+   { 0x2b, KEY_ENTER },
+   { 0x2c, KEY_CLEAR },
+   /* 0x2d-0x2e: Reserved */
+   { 0x2f, KEY_NEXT_FAVORITE }, /* CEC Spec: Next Favorite */
+   { 0x30, KEY_CHANNELUP },
+   { 0x31, KEY_CHANNELDOWN },
+   { 0x32, KEY_PREVIOUS }, /* CEC Spec: Previous Channel */
+   { 0x33, KEY_SOUND }, /* CEC Spec: Sound Select */
+   { 0x34, KEY_VIDEO }, /* 0x34: CEC Spec: Input Select */
+   { 0x35, KEY_INFO }, /* CEC Spec: Display Information */
+   { 0x36, KEY_HELP },
+   { 0x37, KEY_PAGEUP },
+   { 0x38, KEY_PAGEDOWN },
+   /* 0x39-0x3f: Reserved */
+   { 0x40, KEY_POWER },
+   { 0x41, KEY_VOLUMEUP },
+   { 0x42, KEY_VOLUMEDOWN },
+   { 0x43, KEY_MUTE },
+   { 0x44, KEY_PLAYCD },
+   { 0x45, KEY_STOPCD },
+   { 0x46, KEY_PAUSECD },
+   { 0x47, KEY_RECORD },
+   { 0x48, KEY_REWIND },
+   { 0x49, KEY_FASTFORWARD },
+   { 0x4a, KEY_EJECTCD }, /* CEC Spec: Eject */
+   { 0x4b, KEY_FORWARD },
+   { 0x4c, KEY_BACK },
+   { 0x4d, KEY_STOP_RECORD }, /* CEC Spec: Stop-Record */
+   { 0x4e, KEY_PAUSE_RECORD }, /* CEC Spec: Pause-Record */
+   /* 0x4f: Reserved */
+   { 0x50, KEY_ANGLE },
+   { 0x51, KEY_TV2 },
+   { 0x52, KEY_VOD }, /* CEC Spec: Video on Demand */
+   { 0x53, KEY_EPG },
+   { 0x54, KE

[PATCHv9 01/15] dts: exynos4*: add HDMI CEC pin definition to pinctrl

2015-09-07 Thread Hans Verkuil
From: Kamil Debski <ka...@wypas.org>

Add pinctrl nodes for the HDMI CEC device to the Exynos4210 and
Exynos4x12 SoCs. These are required by the HDMI CEC device.

Signed-off-by: Kamil Debski <ka...@wypas.org>
Signed-off-by: Hans Verkuil <hans.verk...@cisco.com>
Acked-by: Krzysztof Kozlowski <k.kozlow...@samsung.com>
---
 arch/arm/boot/dts/exynos4210-pinctrl.dtsi | 7 +++
 arch/arm/boot/dts/exynos4x12-pinctrl.dtsi | 7 +++
 2 files changed, 14 insertions(+)

diff --git a/arch/arm/boot/dts/exynos4210-pinctrl.dtsi 
b/arch/arm/boot/dts/exynos4210-pinctrl.dtsi
index a7c2128..9331c62 100644
--- a/arch/arm/boot/dts/exynos4210-pinctrl.dtsi
+++ b/arch/arm/boot/dts/exynos4210-pinctrl.dtsi
@@ -820,6 +820,13 @@
samsung,pin-pud = <1>;
samsung,pin-drv = <0>;
};
+
+   hdmi_cec: hdmi-cec {
+   samsung,pins = "gpx3-6";
+   samsung,pin-function = <3>;
+   samsung,pin-pud = <0>;
+   samsung,pin-drv = <0>;
+   };
};
 
pinctrl@0386 {
diff --git a/arch/arm/boot/dts/exynos4x12-pinctrl.dtsi 
b/arch/arm/boot/dts/exynos4x12-pinctrl.dtsi
index bac25c6..856b292 100644
--- a/arch/arm/boot/dts/exynos4x12-pinctrl.dtsi
+++ b/arch/arm/boot/dts/exynos4x12-pinctrl.dtsi
@@ -885,6 +885,13 @@
samsung,pin-pud = <0>;
samsung,pin-drv = <0>;
};
+
+   hdmi_cec: hdmi-cec {
+   samsung,pins = "gpx3-6";
+   samsung,pin-function = <3>;
+   samsung,pin-pud = <0>;
+   samsung,pin-drv = <0>;
+   };
};
 
pinctrl_2: pinctrl@0386 {
-- 
2.1.4

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


Re: [PATCH v7 11/44] [media] media: use entity.graph_obj.mdev instead of .parent

2015-08-25 Thread Hans Verkuil
On 08/23/2015 10:17 PM, Mauro Carvalho Chehab wrote:
 From: Javier Martinez Canillas jav...@osg.samsung.com
 
 The struct media_entity has a .parent field that stores a pointer
 to the parent struct media_device. But recently a media_gobj was
 embedded into the entities and since struct media_gojb already has
 a pointer to a struct media_device in the .mdev field, the .parent
 field becomes redundant and can be removed.
 
 This patch replaces all the usage of .parent by .graph_obj.mdev so
 that field will become unused and can be removed on a later patch.
 
 No functional changes.
 
 The transformation was made using the following coccinelle spatch:
 
 @@
 struct media_entity *me;
 @@
 
 - me-parent
 + me-graph_obj.mdev
 
 @@
 struct media_entity *link;
 @@
 
 - link-source-entity-parent
 + link-source-entity-graph_obj.mdev
 
 @@
 struct exynos_video_entity *ve;
 @@
 
 - ve-vdev.entity.parent
 + ve-vdev.entity.graph_obj.mdev
 
 Suggested-by: Mauro Carvalho Chehab mche...@osg.samsung.com
 
 Signed-off-by: Javier Martinez Canillas jav...@osg.samsung.com
 Signed-off-by: Mauro Carvalho Chehab mche...@osg.samsung.com

Acked-by: Hans Verkuil hans.verk...@cisco.com
--
To unsubscribe from this list: send the line unsubscribe linux-samsung-soc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 0/4] [media] Media entity cleanups and build fixes

2015-08-20 Thread Hans Verkuil
On 08/19/15 17:35, Javier Martinez Canillas wrote:
 Hello,
 
 This series contains a couple of build fixes and cleanups for the
 Media Controller framework. The goal of the series is to get rid of
 the struct media_entity .parent member since now that a media_gobj is
 embedded into entities, the media_gobj .mdev member can be used to
 store a pointer to the parent struct media_device.
 
 So the .parent field becomes redundant and can be removed after all
 the users are converted to use entity .graph_obj.mdev instead.
 
 Patches 1/4 and 2/4 are build fixes I found while build testing if no
 regressions were introduced by the conversion. Patch 3/4 converts
 all the drivers and the MC core to use .mdev instead of .parent and
 finally patch 4/4 removes the .parent field since now is unused.

Regarding patches 1 and 2: these should of course be merged with Mauro's
patches that make this particular change (patch 3/8), otherwise it would
break git bisect.

Anyway,

Acked-by: Hans Verkuil hans.verk...@cisco.com for the changes in patch
1 and 2, as long as they are added to Mauro's patch 3/8.

Regards,

Hans

 
 The series depend on Mauro's [PATCH v6 0/8] MC preparation patches
 series [0].
 
 The transformation were automated using a coccinelle semantic patch
 and the drivers were build tested using allyesconfig and x-building
 the ARM Exynos and OMAP defconfigs + the needed media config options.
 
 Best regards,
 Javier
 
 [0]: http://www.mail-archive.com/linux-media@vger.kernel.org/msg91330.html
 
 
 Javier Martinez Canillas (4):
   [media] staging: omap4iss: get entity ID using media_entity_id()
   [media] omap3isp: get entity ID using media_entity_id()
   [media] media: use entity.graph_obj.mdev instead of .parent
   [media] media: remove media entity .parent field
 
  drivers/media/media-device.c   |  8 ++---
  drivers/media/media-entity.c   | 34 
 --
  drivers/media/platform/exynos4-is/fimc-isp-video.c |  6 ++--
  drivers/media/platform/exynos4-is/fimc-lite.c  |  8 ++---
  drivers/media/platform/exynos4-is/media-dev.c  |  2 +-
  drivers/media/platform/exynos4-is/media-dev.h  |  8 ++---
  drivers/media/platform/omap3isp/isp.c  | 11 ---
  drivers/media/platform/omap3isp/ispccdc.c  |  2 +-
  drivers/media/platform/omap3isp/ispvideo.c | 10 ---
  drivers/media/platform/vsp1/vsp1_video.c   |  2 +-
  drivers/media/platform/xilinx/xilinx-dma.c |  2 +-
  drivers/staging/media/davinci_vpfe/vpfe_video.c|  6 ++--
  drivers/staging/media/omap4iss/iss.c   |  6 ++--
  drivers/staging/media/omap4iss/iss_video.c |  4 +--
  include/media/media-entity.h   |  1 -
  15 files changed, 58 insertions(+), 52 deletions(-)
 
--
To unsubscribe from this list: send the line unsubscribe linux-samsung-soc in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 3/4] [media] media: use entity.graph_obj.mdev instead of .parent

2015-08-20 Thread Hans Verkuil
On 08/19/15 17:35, Javier Martinez Canillas wrote:
 The struct media_entity has a .parent field that stores a pointer
 to the parent struct media_device. But recently a media_gobj was
 embedded into the entities and since struct media_gojb already has
 a pointer to a struct media_device in the .mdev field, the .parent
 field becomes redundant and can be removed.
 
 This patch replaces all the usage of .parent by .graph_obj.mdev so
 that field will become unused and can be removed on a later patch.
 
 No functional changes.
 
 The transformation was made using the following coccinelle spatch:
 
 @@
 struct media_entity *me;
 @@
 
 - me-parent
 + me-graph_obj.mdev
 
 @@
 struct media_entity *link;
 @@
 
 - link-source-entity-parent
 + link-source-entity-graph_obj.mdev
 
 @@
 struct exynos_video_entity *ve;
 @@
 
 - ve-vdev.entity.parent
 + ve-vdev.entity.graph_obj.mdev
 
 Suggested-by: Mauro Carvalho Chehab mche...@osg.samsung.com
 Signed-off-by: Javier Martinez Canillas jav...@osg.samsung.com

Acked-by: Hans Verkuil hans.verk...@cisco.com

Regards,

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


Re: [PATCH RFC v5 8/8] [media] media: rename the function that create pad links

2015-08-19 Thread Hans Verkuil
On 08/18/2015 10:04 PM, Mauro Carvalho Chehab wrote:
 Now that a link can be either between two different graph
 objects, we'll need to add more functions to create links.
 So, rename the existing one that create links only between
 two pads as media_create_pad_link().
 
 No functional changes.
 
 This patch was created via this shell script:
   for i in $(find drivers/media -name '*.[ch]' -type f) $(find 
 drivers/staging/media -name '*.[ch]' -type f) $(find include/ -name '*.h' 
 -type f) ; do sed s,media_entity_create_link,media_create_pad_link,g $i a 
  mv a $i; done
 
 Signed-off-by: Mauro Carvalho Chehab mche...@osg.samsung.com


Acked-by: Hans Verkuil hans.verk...@cisco.com

Thanks!

Hans

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


[PATCHv8 04/15] input.h: add BUS_CEC type

2015-08-18 Thread Hans Verkuil
Inputs can come in over the HDMI CEC bus, so add a new type for this.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
Acked-by: Dmitry Torokhov dmitry.torok...@gmail.com
---
 include/uapi/linux/input.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/uapi/linux/input.h b/include/uapi/linux/input.h
index 731417c..a32bff1 100644
--- a/include/uapi/linux/input.h
+++ b/include/uapi/linux/input.h
@@ -972,6 +972,7 @@ struct input_keymap_entry {
 #define BUS_GSC0x1A
 #define BUS_ATARI  0x1B
 #define BUS_SPI0x1C
+#define BUS_CEC0x1D
 
 /*
  * MT_TOOL types
-- 
2.1.4

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


[PATCHv8 01/15] dts: exynos4*: add HDMI CEC pin definition to pinctrl

2015-08-18 Thread Hans Verkuil
From: Kamil Debski ka...@wypas.org

Add pinctrl nodes for the HDMI CEC device to the Exynos4210 and
Exynos4x12 SoCs. These are required by the HDMI CEC device.

Signed-off-by: Kamil Debski ka...@wypas.org
Signed-off-by: Hans Verkuil hans.verk...@cisco.com
Acked-by: Krzysztof Kozlowski k.kozlow...@samsung.com
---
 arch/arm/boot/dts/exynos4210-pinctrl.dtsi | 7 +++
 arch/arm/boot/dts/exynos4x12-pinctrl.dtsi | 7 +++
 2 files changed, 14 insertions(+)

diff --git a/arch/arm/boot/dts/exynos4210-pinctrl.dtsi 
b/arch/arm/boot/dts/exynos4210-pinctrl.dtsi
index a7c2128..9331c62 100644
--- a/arch/arm/boot/dts/exynos4210-pinctrl.dtsi
+++ b/arch/arm/boot/dts/exynos4210-pinctrl.dtsi
@@ -820,6 +820,13 @@
samsung,pin-pud = 1;
samsung,pin-drv = 0;
};
+
+   hdmi_cec: hdmi-cec {
+   samsung,pins = gpx3-6;
+   samsung,pin-function = 3;
+   samsung,pin-pud = 0;
+   samsung,pin-drv = 0;
+   };
};
 
pinctrl@0386 {
diff --git a/arch/arm/boot/dts/exynos4x12-pinctrl.dtsi 
b/arch/arm/boot/dts/exynos4x12-pinctrl.dtsi
index bac25c6..856b292 100644
--- a/arch/arm/boot/dts/exynos4x12-pinctrl.dtsi
+++ b/arch/arm/boot/dts/exynos4x12-pinctrl.dtsi
@@ -885,6 +885,13 @@
samsung,pin-pud = 0;
samsung,pin-drv = 0;
};
+
+   hdmi_cec: hdmi-cec {
+   samsung,pins = gpx3-6;
+   samsung,pin-function = 3;
+   samsung,pin-pud = 0;
+   samsung,pin-drv = 0;
+   };
};
 
pinctrl_2: pinctrl@0386 {
-- 
2.1.4

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


[PATCHv8 08/15] cec.txt: add CEC framework documentation

2015-08-18 Thread Hans Verkuil
From: Hans Verkuil hansv...@cisco.com

Document the new HDMI CEC framework.

Signed-off-by: Hans Verkuil hansv...@cisco.com
[k.deb...@samsung.com: add DocBook documentation by Hans Verkuil, with
Signed-off-by: Kamil Debski ka...@wypas.org
Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 Documentation/cec.txt | 166 ++
 1 file changed, 166 insertions(+)
 create mode 100644 Documentation/cec.txt

diff --git a/Documentation/cec.txt b/Documentation/cec.txt
new file mode 100644
index 000..b298249
--- /dev/null
+++ b/Documentation/cec.txt
@@ -0,0 +1,166 @@
+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 logical addresses in the
+communication. The logical address is strictly connected with the functionality
+provided by the device. The TV acting as the communication hub is always
+assigned address 0. The physical address is determined by the physical
+connection between devices.
+
+The protocol enables control of compatible devices with a single remote.
+Synchronous power on/standby, instant playback with changing the content source
+on the TV.
+
+The Kernel Interface
+
+
+CEC Adapter
+---
+
+#define CEC_LOG_ADDR_INVALID 0xff
+
+/* The maximum number of logical addresses one device can be assigned to.
+ * The CEC 2.0 spec allows for only 2 logical addresses at the moment. The
+ * Analog Devices CEC hardware supports 3. So let's go wild and go for 4. */
+#define CEC_MAX_LOG_ADDRS 4
+
+/* The Primary Device Type */
+#define CEC_OP_PRIM_DEVTYPE_TV 0
+#define CEC_OP_PRIM_DEVTYPE_RECORD 1
+#define CEC_OP_PRIM_DEVTYPE_TUNER  3
+#define CEC_OP_PRIM_DEVTYPE_PLAYBACK   4
+#define CEC_OP_PRIM_DEVTYPE_AUDIOSYSTEM5
+#define CEC_OP_PRIM_DEVTYPE_SWITCH 6
+#define CEC_OP_PRIM_DEVTYPE_VIDEOPROC  7
+
+/* The All Device Types flags (CEC 2.0) */
+#define CEC_OP_ALL_DEVTYPE_TV  (1  7)
+#define CEC_OP_ALL_DEVTYPE_RECORD  (1  6)
+#define CEC_OP_ALL_DEVTYPE_TUNER   (1  5)
+#define CEC_OP_ALL_DEVTYPE_PLAYBACK(1  4)
+#define CEC_OP_ALL_DEVTYPE_AUDIOSYSTEM (1  3)
+#define CEC_OP_ALL_DEVTYPE_SWITCH  (1  2)
+/* And if you wondering what happened to VIDEOPROC devices: those should
+ * be mapped to a SWITCH. */
+
+/* The logical address types that the CEC device wants to claim */
+#define CEC_LOG_ADDR_TYPE_TV   0
+#define CEC_LOG_ADDR_TYPE_RECORD   1
+#define CEC_LOG_ADDR_TYPE_TUNER2
+#define CEC_LOG_ADDR_TYPE_PLAYBACK 3
+#define CEC_LOG_ADDR_TYPE_AUDIOSYSTEM  4
+#define CEC_LOG_ADDR_TYPE_SPECIFIC 5
+#define CEC_LOG_ADDR_TYPE_UNREGISTERED 6
+/* Switches should use UNREGISTERED.
+ * Video processors should use SPECIFIC. */
+
+/* The CEC version */
+#define CEC_OP_CEC_VERSION_1_3A4
+#define CEC_OP_CEC_VERSION_1_4 5
+#define CEC_OP_CEC_VERSION_2_0 6
+
+struct cec_adapter {
+   /* internal fields removed */
+
+   u16 phys_addr;
+   u32 capabilities;
+   u8 version;
+   u8 num_log_addrs;
+   u8 prim_device[CEC_MAX_LOG_ADDRS];
+   u8 log_addr_type[CEC_MAX_LOG_ADDRS];
+   u8 log_addr[CEC_MAX_LOG_ADDRS];
+
+   int (*adap_enable)(struct cec_adapter *adap, bool enable);
+   int (*adap_log_addr)(struct cec_adapter *adap, u8 logical_addr);
+   int (*adap_transmit)(struct cec_adapter *adap, struct cec_msg *msg);
+   void (*adap_transmit_timed_out)(struct cec_adapter *adap);
+
+   void (*claimed_log_addr)(struct cec_adapter *adap, u8 idx);
+   int (*received)(struct cec_adapter *adap, struct cec_msg *msg);
+};
+
+int cec_create_adapter(struct cec_adapter *adap, u32 caps);
+void cec_delete_adapter(struct cec_adapter *adap);
+int cec_transmit_msg(struct cec_adapter *adap, struct cec_data *data, bool 
block);
+
+/* Called by the adapter */
+void cec_transmit_done(struct cec_adapter *adap, u32 status);
+void cec_received_msg(struct cec_adapter *adap, struct cec_msg *msg);
+
+int cec_receive_msg(struct cec_adapter *adap, struct cec_msg *msg, bool block);
+int cec_claim_log_addrs(struct cec_adapter *adap, struct cec_log_addrs 
*log_addrs, bool block);
+
+The device type defines are defined by the CEC standard.
+
+The cec_adapter structure represents the adapter. It has a number of
+operations that have to be implemented in the driver: adap_enable() enables
+or disables the physical adapter, adap_log_addr() tells the driver which
+logical address should be configured. This may

[PATCHv2 3/4] cec-compliance: add new CEC compliance utility

2015-08-18 Thread Hans Verkuil
This utility will attempt to test whether the CEC protocol was
implemented correctly.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 configure.ac|   1 +
 utils/Makefile.am   |   1 +
 utils/cec-compliance/Makefile.am|   3 +
 utils/cec-compliance/cec-compliance.cpp | 926 
 utils/cec-compliance/cec-compliance.h   |  87 +++
 5 files changed, 1018 insertions(+)
 create mode 100644 utils/cec-compliance/Makefile.am
 create mode 100644 utils/cec-compliance/cec-compliance.cpp
 create mode 100644 utils/cec-compliance/cec-compliance.h

diff --git a/configure.ac b/configure.ac
index d4e312c..12c2eb9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -26,6 +26,7 @@ AC_CONFIG_FILES([Makefile
utils/keytable/Makefile
utils/media-ctl/Makefile
utils/rds/Makefile
+   utils/cec-compliance/Makefile
utils/v4l2-compliance/Makefile
utils/v4l2-ctl/Makefile
utils/v4l2-dbg/Makefile
diff --git a/utils/Makefile.am b/utils/Makefile.am
index 31b2979..c78e97b 100644
--- a/utils/Makefile.am
+++ b/utils/Makefile.am
@@ -5,6 +5,7 @@ SUBDIRS = \
decode_tm6000 \
keytable \
media-ctl \
+   cec-compliance \
v4l2-compliance \
v4l2-ctl \
v4l2-dbg \
diff --git a/utils/cec-compliance/Makefile.am b/utils/cec-compliance/Makefile.am
new file mode 100644
index 000..da4c0ef
--- /dev/null
+++ b/utils/cec-compliance/Makefile.am
@@ -0,0 +1,3 @@
+bin_PROGRAMS = cec-compliance
+
+cec_compliance_SOURCES = cec-compliance.cpp
diff --git a/utils/cec-compliance/cec-compliance.cpp 
b/utils/cec-compliance/cec-compliance.cpp
new file mode 100644
index 000..59db8ab
--- /dev/null
+++ b/utils/cec-compliance/cec-compliance.cpp
@@ -0,0 +1,926 @@
+/*
+Copyright 2015 Cisco Systems, Inc. and/or its affiliates. All rights 
reserved.
+Author: Hans Verkuil hans.verk...@cisco.com
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+ */
+
+#include unistd.h
+#include stdlib.h
+#include stdio.h
+#include string.h
+#include inttypes.h
+#include getopt.h
+#include sys/types.h
+#include sys/stat.h
+#include fcntl.h
+#include ctype.h
+#include errno.h
+#include sys/ioctl.h
+#include config.h
+
+#include cec-compliance.h
+
+/* Short option list
+
+   Please keep in alphabetical order.
+   That makes it easier to see which short options are still free.
+
+   In general the lower case is used to set something and the upper
+   case is used to retrieve a setting. */
+enum Option {
+   OptPhysAddr = 'a',
+   OptSetDevice = 'd',
+   OptHelp = 'h',
+   OptNoWarnings = 'n',
+   OptTrace = 'T',
+   OptVerbose = 'v',
+   OptVendorID = 'V',
+
+   OptTV,
+   OptRecord,
+   OptTuner,
+   OptPlayback,
+   OptAudio,
+   OptProcessor,
+   OptSwitch,
+   OptCDCOnly,
+   OptUnregistered,
+   OptLast = 256
+};
+
+static char options[OptLast];
+
+static int app_result;
+static int tests_total, tests_ok;
+
+bool show_info;
+bool show_warnings = true;
+unsigned warnings;
+
+static struct option long_options[] = {
+   {device, required_argument, 0, OptSetDevice},
+   {help, no_argument, 0, OptHelp},
+   {no-warnings, no_argument, 0, OptNoWarnings},
+   {trace, no_argument, 0, OptTrace},
+   {verbose, no_argument, 0, OptVerbose},
+   {phys-addr, required_argument, 0, OptPhysAddr},
+   {vendor-id, required_argument, 0, OptVendorID},
+
+   {tv, no_argument, 0, OptTV},
+   {record, no_argument, 0, OptRecord},
+   {tuner, no_argument, 0, OptTuner},
+   {playback, no_argument, 0, OptPlayback},
+   {audio, no_argument, 0, OptAudio},
+   {processor, no_argument, 0, OptProcessor},
+   {switch, no_argument, 0, OptSwitch},
+   {cdc-only, no_argument, 0, OptCDCOnly},
+   {unregistered, no_argument, 0, OptUnregistered},
+   {0, 0, 0, 0}
+};
+
+static void usage(void)
+{
+   printf(Usage:\n
+-d, --device=dev Use device dev instead of /dev/cec0\n
+   If dev starts with a digit, then 
/dev/cecdev is used.\n
+-h, --help Display this help message\n
+-n, --no-warnings  Turn off warning messages.\n
+-T, --traceTrace all called ioctls.\n
+-v, --verbose  Turn on verbose reporting.\n
+-a, --phys-addr=addr\n
+   Use this physical address.\n

[PATCHv8 14/15] cec: s5p-cec: Add s5p-cec driver

2015-08-18 Thread Hans Verkuil
From: Kamil Debski ka...@wypas.org

Add CEC interface driver present in the Samsung Exynos range of
SoCs.

The following files were based on work by SangPil Moon:
- exynos_hdmi_cec.h
- exynos_hdmi_cecctl.c

Signed-off-by: Kamil Debski ka...@wypas.org
Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 .../devicetree/bindings/media/s5p-cec.txt  |  31 +++
 drivers/media/platform/Kconfig |  10 +
 drivers/media/platform/Makefile|   1 +
 drivers/media/platform/s5p-cec/Makefile|   2 +
 drivers/media/platform/s5p-cec/exynos_hdmi_cec.h   |  37 +++
 .../media/platform/s5p-cec/exynos_hdmi_cecctrl.c   | 208 
 drivers/media/platform/s5p-cec/regs-cec.h  |  96 +++
 drivers/media/platform/s5p-cec/s5p_cec.c   | 277 +
 drivers/media/platform/s5p-cec/s5p_cec.h   |  76 ++
 9 files changed, 738 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/s5p-cec.txt
 create mode 100644 drivers/media/platform/s5p-cec/Makefile
 create mode 100644 drivers/media/platform/s5p-cec/exynos_hdmi_cec.h
 create mode 100644 drivers/media/platform/s5p-cec/exynos_hdmi_cecctrl.c
 create mode 100644 drivers/media/platform/s5p-cec/regs-cec.h
 create mode 100644 drivers/media/platform/s5p-cec/s5p_cec.c
 create mode 100644 drivers/media/platform/s5p-cec/s5p_cec.h

diff --git a/Documentation/devicetree/bindings/media/s5p-cec.txt 
b/Documentation/devicetree/bindings/media/s5p-cec.txt
new file mode 100644
index 000..925ab4d
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/s5p-cec.txt
@@ -0,0 +1,31 @@
+* Samsung HDMI CEC driver
+
+The HDMI CEC module is present is Samsung SoCs and its purpose is to
+handle communication between HDMI connected devices over the CEC bus.
+
+Required properties:
+  - compatible : value should be following
+   samsung,s5p-cec
+
+  - reg : Physical base address of the IP registers and length of memory
+ mapped region.
+
+  - interrupts : HDMI CEC interrupt number to the CPU.
+  - clocks : from common clock binding: handle to HDMI CEC clock.
+  - clock-names : from common clock binding: must contain hdmicec,
+ corresponding to entry in the clocks property.
+  - samsung,syscon-phandle - phandle to the PMU system controller
+
+Example:
+
+hdmicec: cec@100B {
+   compatible = samsung,s5p-cec;
+   reg = 0x100B 0x200;
+   interrupts = 0 114 0;
+   clocks = clock CLK_HDMI_CEC;
+   clock-names = hdmicec;
+   samsung,syscon-phandle = pmu_system_controller;
+   pinctrl-names = default;
+   pinctrl-0 = hdmi_cec;
+   status = okay;
+};
diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index dc75694..c5828de 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -157,6 +157,16 @@ config VIDEO_MEM2MEM_DEINTERLACE
help
Generic deinterlacing V4L2 driver.
 
+config VIDEO_SAMSUNG_S5P_CEC
+   tristate Samsung S5P CEC driver
+   depends on CEC  VIDEO_DEV  VIDEO_V4L2  (PLAT_S5P || ARCH_EXYNOS)
+   default n
+   ---help---
+ This is a driver for Samsung S5P HDMI CEC interface. It uses the
+ generic CEC framework interface.
+ CEC bus is present in the HDMI connector and enables communication
+ between compatible devices.
+
 config VIDEO_SAMSUNG_S5P_G2D
tristate Samsung S5P and EXYNOS4 G2D 2d graphics accelerator driver
depends on VIDEO_DEV  VIDEO_V4L2
diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile
index efa0295..957af5f 100644
--- a/drivers/media/platform/Makefile
+++ b/drivers/media/platform/Makefile
@@ -27,6 +27,7 @@ obj-$(CONFIG_VIDEO_MEM2MEM_DEINTERLACE)   += 
m2m-deinterlace.o
 
 obj-$(CONFIG_VIDEO_S3C_CAMIF)  += s3c-camif/
 obj-$(CONFIG_VIDEO_SAMSUNG_EXYNOS4_IS) += exynos4-is/
+obj-$(CONFIG_VIDEO_SAMSUNG_S5P_CEC)+= s5p-cec/
 obj-$(CONFIG_VIDEO_SAMSUNG_S5P_JPEG)   += s5p-jpeg/
 obj-$(CONFIG_VIDEO_SAMSUNG_S5P_MFC)+= s5p-mfc/
 obj-$(CONFIG_VIDEO_SAMSUNG_S5P_TV) += s5p-tv/
diff --git a/drivers/media/platform/s5p-cec/Makefile 
b/drivers/media/platform/s5p-cec/Makefile
new file mode 100644
index 000..0e2cf45
--- /dev/null
+++ b/drivers/media/platform/s5p-cec/Makefile
@@ -0,0 +1,2 @@
+obj-$(CONFIG_VIDEO_SAMSUNG_S5P_CEC)+= s5p-cec.o
+s5p-cec-y += s5p_cec.o exynos_hdmi_cecctrl.o
diff --git a/drivers/media/platform/s5p-cec/exynos_hdmi_cec.h 
b/drivers/media/platform/s5p-cec/exynos_hdmi_cec.h
new file mode 100644
index 000..d008695
--- /dev/null
+++ b/drivers/media/platform/s5p-cec/exynos_hdmi_cec.h
@@ -0,0 +1,37 @@
+/* drivers/media/platform/s5p-cec/exynos_hdmi_cec.h
+ *
+ * Copyright (c) 2010, 2014 Samsung Electronics
+ * http://www.samsung.com/
+ *
+ * Header file for interface of Samsung Exynos hdmi cec hardware
+ *
+ * This program is free software; you can redistribute it and/or modify

[PATCHv2 4/4] cec-ctl: CEC control utility

2015-08-18 Thread Hans Verkuil
Generic CEC utility that can be used to send/receive/monitor CEC
messages.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 configure.ac  |1 +
 utils/Makefile.am |1 +
 utils/cec-ctl/Makefile.am |8 +
 utils/cec-ctl/cec-ctl.cpp | 1296 +
 utils/cec-ctl/msg2ctl.pl  |  430 +++
 5 files changed, 1736 insertions(+)
 create mode 100644 utils/cec-ctl/Makefile.am
 create mode 100644 utils/cec-ctl/cec-ctl.cpp
 create mode 100644 utils/cec-ctl/msg2ctl.pl

diff --git a/configure.ac b/configure.ac
index 12c2eb9..72d59bd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -27,6 +27,7 @@ AC_CONFIG_FILES([Makefile
utils/media-ctl/Makefile
utils/rds/Makefile
utils/cec-compliance/Makefile
+   utils/cec-ctl/Makefile
utils/v4l2-compliance/Makefile
utils/v4l2-ctl/Makefile
utils/v4l2-dbg/Makefile
diff --git a/utils/Makefile.am b/utils/Makefile.am
index c78e97b..617abf1 100644
--- a/utils/Makefile.am
+++ b/utils/Makefile.am
@@ -6,6 +6,7 @@ SUBDIRS = \
keytable \
media-ctl \
cec-compliance \
+   cec-ctl \
v4l2-compliance \
v4l2-ctl \
v4l2-dbg \
diff --git a/utils/cec-ctl/Makefile.am b/utils/cec-ctl/Makefile.am
new file mode 100644
index 000..378d7db
--- /dev/null
+++ b/utils/cec-ctl/Makefile.am
@@ -0,0 +1,8 @@
+bin_PROGRAMS = cec-ctl
+
+cec_ctl_SOURCES = cec-ctl.cpp
+
+cec-ctl.cpp: cec-ctl-gen.h
+
+cec-ctl-gen.h: msg2ctl.pl ../../include/linux/cec.h 
../../include/linux/cec-funcs.h
+   msg2ctl.pl ../../include/linux/cec.h ../../include/linux/cec-funcs.h 
cec-ctl-gen.h
diff --git a/utils/cec-ctl/cec-ctl.cpp b/utils/cec-ctl/cec-ctl.cpp
new file mode 100644
index 000..6a1edb5
--- /dev/null
+++ b/utils/cec-ctl/cec-ctl.cpp
@@ -0,0 +1,1296 @@
+/*
+Copyright 2015 Cisco Systems, Inc. and/or its affiliates. All rights 
reserved.
+Author: Hans Verkuil hans.verk...@cisco.com
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+ */
+
+#include unistd.h
+#include stdlib.h
+#include stdio.h
+#include string.h
+#include inttypes.h
+#include getopt.h
+#include sys/types.h
+#include sys/stat.h
+#include fcntl.h
+#include ctype.h
+#include errno.h
+#include sys/ioctl.h
+#include stdarg.h
+#include cerrno
+#include string
+#include vector
+#include linux/cec-funcs.h
+#include config.h
+
+#define CEC_MAX_ARGS 16
+
+#define xstr(s) str(s)
+#define str(s) #s
+
+struct cec_enum_values {
+   const char *type_name;
+   __u8 value;
+};
+
+enum cec_types {
+   CEC_TYPE_U8,
+   CEC_TYPE_U16,
+   CEC_TYPE_U32,
+   CEC_TYPE_STRING,
+   CEC_TYPE_ENUM,
+};
+
+struct arg {
+   enum cec_types type;
+   __u8 num_enum_values;
+   const struct cec_enum_values *values;
+};
+
+static const struct arg arg_u8 = {
+   CEC_TYPE_U8,
+};
+
+static const struct arg arg_u16 = {
+   CEC_TYPE_U16,
+};
+
+static const struct arg arg_u32 = {
+   CEC_TYPE_U32,
+};
+
+static const struct arg arg_string = {
+   CEC_TYPE_STRING,
+};
+
+static const struct cec_enum_values type_ui_cmd[] = {
+   { Select, 0x00 },
+   { Up, 0x01 },
+   { Down, 0x02 },
+   { Left, 0x03 },
+   { Right, 0x04 },
+   { Right-Up, 0x05 },
+   { Right-Down, 0x06 },
+   { Left-Up, 0x07 },
+   { Left-Down, 0x08 },
+   { Device Root Menu, 0x09 },
+   { Device Setup Menu, 0x0a },
+   { Contents Menu, 0x0b },
+   { Favorite Menu, 0x0c },
+   { Back, 0x0d },
+   { Media Top Menu, 0x10 },
+   { Media Context-sensitive Menu, 0x11 },
+   { Number Entry Mode, 0x1d },
+   { Number 11, 0x1e },
+   { Number 12, 0x1f },
+   { Number 0 or Number 10, 0x20 },
+   { Number 1, 0x21 },
+   { Number 2, 0x22 },
+   { Number 3, 0x23 },
+   { Number 4, 0x24 },
+   { Number 5, 0x25 },
+   { Number 6, 0x26 },
+   { Number 7, 0x27 },
+   { Number 8, 0x28 },
+   { Number 9, 0x29 },
+   { Dot, 0x2a },
+   { Enter, 0x2b },
+   { Clear, 0x2c },
+   { Next Favorite, 0x2f },
+   { Channel Up, 0x30 },
+   { Channel Down, 0x31 },
+   { Previous Channel, 0x32 },
+   { Sound Select, 0x33 },
+   { Input Select, 0x34 },
+   { Display Information, 0x35 },
+   { Help, 0x36 },
+   { Page Up, 0x37 },
+   { Page Down, 0x38 },
+   { Power, 0x40 },
+   { Volume Up, 0x41 },
+   { Volume Down, 0x42 },
+   { Mute, 0x43 },
+   { Play, 0x44

[PATCHv8 09/15] DocBook/media: add CEC documentation

2015-08-18 Thread Hans Verkuil
From: Hans Verkuil hverk...@xs4all.nl

Add DocBook documentation for the CEC API.

Signed-off-by: Hans Verkuil hansv...@cisco.com
[k.deb...@samsung.com: add documentation for passthrough mode]
[k.deb...@samsung.com: minor fixes and change of reserved field sizes]
Signed-off-by: Kamil Debski ka...@wypas.org
Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 Documentation/DocBook/media/Makefile   |   2 +
 Documentation/DocBook/media/v4l/biblio.xml |  10 +
 Documentation/DocBook/media/v4l/cec-api.xml|  75 +
 Documentation/DocBook/media/v4l/cec-func-close.xml |  59 
 Documentation/DocBook/media/v4l/cec-func-ioctl.xml |  73 +
 Documentation/DocBook/media/v4l/cec-func-open.xml  |  94 +++
 Documentation/DocBook/media/v4l/cec-func-poll.xml  |  89 ++
 .../DocBook/media/v4l/cec-ioc-adap-g-caps.xml  | 138 ++
 .../DocBook/media/v4l/cec-ioc-adap-g-log-addrs.xml | 306 +
 .../DocBook/media/v4l/cec-ioc-adap-g-phys-addr.xml |  78 ++
 .../DocBook/media/v4l/cec-ioc-adap-g-state.xml |  87 ++
 .../DocBook/media/v4l/cec-ioc-adap-g-vendor-id.xml |  70 +
 .../DocBook/media/v4l/cec-ioc-dqevent.xml  | 125 +
 .../DocBook/media/v4l/cec-ioc-g-monitor.xml|  86 ++
 .../DocBook/media/v4l/cec-ioc-g-passthrough.xml|  81 ++
 .../DocBook/media/v4l/cec-ioc-receive.xml  | 185 +
 Documentation/DocBook/media_api.tmpl   |   8 +-
 17 files changed, 1564 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/DocBook/media/v4l/cec-api.xml
 create mode 100644 Documentation/DocBook/media/v4l/cec-func-close.xml
 create mode 100644 Documentation/DocBook/media/v4l/cec-func-ioctl.xml
 create mode 100644 Documentation/DocBook/media/v4l/cec-func-open.xml
 create mode 100644 Documentation/DocBook/media/v4l/cec-func-poll.xml
 create mode 100644 Documentation/DocBook/media/v4l/cec-ioc-adap-g-caps.xml
 create mode 100644 Documentation/DocBook/media/v4l/cec-ioc-adap-g-log-addrs.xml
 create mode 100644 Documentation/DocBook/media/v4l/cec-ioc-adap-g-phys-addr.xml
 create mode 100644 Documentation/DocBook/media/v4l/cec-ioc-adap-g-state.xml
 create mode 100644 Documentation/DocBook/media/v4l/cec-ioc-adap-g-vendor-id.xml
 create mode 100644 Documentation/DocBook/media/v4l/cec-ioc-dqevent.xml
 create mode 100644 Documentation/DocBook/media/v4l/cec-ioc-g-monitor.xml
 create mode 100644 Documentation/DocBook/media/v4l/cec-ioc-g-passthrough.xml
 create mode 100644 Documentation/DocBook/media/v4l/cec-ioc-receive.xml

diff --git a/Documentation/DocBook/media/Makefile 
b/Documentation/DocBook/media/Makefile
index 23996f8..5c89f4b 100644
--- a/Documentation/DocBook/media/Makefile
+++ b/Documentation/DocBook/media/Makefile
@@ -64,6 +64,7 @@ IOCTLS = \
$(shell perl -ne 'print $$1  if /\#define\s+([A-Z][^\s]+)\s+_IO/' 
$(srctree)/include/uapi/linux/dvb/net.h) \
$(shell perl -ne 'print $$1  if /\#define\s+([^\s]+)\s+_IO/' 
$(srctree)/include/uapi/linux/dvb/video.h) \
$(shell perl -ne 'print $$1  if /\#define\s+([^\s]+)\s+_IO/' 
$(srctree)/include/uapi/linux/media.h) \
+   $(shell perl -ne 'print $$1  if /\#define\s+([^\s]+)\s+_IO/' 
$(srctree)/include/uapi/linux/cec.h) \
$(shell perl -ne 'print $$1  if /\#define\s+([^\s]+)\s+_IO/' 
$(srctree)/include/uapi/linux/v4l2-subdev.h) \
 
 DEFINES = \
@@ -100,6 +101,7 @@ STRUCTS = \
$(shell perl -ne 'print $$1  if (/^struct\s+([^\s]+)\s+/  !/_old/)' 
$(srctree)/include/uapi/linux/dvb/net.h) \
$(shell perl -ne 'print $$1  if (/^struct\s+([^\s]+)\s+/)' 
$(srctree)/include/uapi/linux/dvb/video.h) \
$(shell perl -ne 'print $$1  if /^struct\s+([^\s]+)\s+/' 
$(srctree)/include/uapi/linux/media.h) \
+   $(shell perl -ne 'print $$1  if /^struct\s+([^\s]+)\s+/' 
$(srctree)/include/uapi/linux/cec.h) \
$(shell perl -ne 'print $$1  if /^struct\s+([^\s]+)\s+/' 
$(srctree)/include/uapi/linux/v4l2-subdev.h) \
$(shell perl -ne 'print $$1  if /^struct\s+([^\s]+)\s+/' 
$(srctree)/include/uapi/linux/v4l2-mediabus.h)
 
diff --git a/Documentation/DocBook/media/v4l/biblio.xml 
b/Documentation/DocBook/media/v4l/biblio.xml
index fdee6b3..bed940b 100644
--- a/Documentation/DocBook/media/v4l/biblio.xml
+++ b/Documentation/DocBook/media/v4l/biblio.xml
@@ -324,6 +324,16 @@ in the frequency range from 87,5 to 108,0 MHz/title
   subtitleSpecification Version 1.4a/subtitle
 /biblioentry
 
+biblioentry id=hdmi2
+  abbrevHDMI2/abbrev
+  authorgroup
+   corpauthorHDMI Licensing LLC
+(ulink url=http://www.hdmi.org;http://www.hdmi.org/ulink)/corpauthor
+  /authorgroup
+  titleHigh-Definition Multimedia Interface/title
+  subtitleSpecification Version 2.0/subtitle
+/biblioentry
+
 biblioentry id=dp
   abbrevDP/abbrev
   authorgroup
diff --git a/Documentation/DocBook/media/v4l/cec-api.xml 
b/Documentation/DocBook/media/v4l/cec-api.xml
new file mode 100644
index 000

[PATCHv8 12/15] cec: adv7842: add cec support

2015-08-18 Thread Hans Verkuil
Add CEC support to the adv7842 driver.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/i2c/adv7842.c | 250 +---
 1 file changed, 233 insertions(+), 17 deletions(-)

diff --git a/drivers/media/i2c/adv7842.c b/drivers/media/i2c/adv7842.c
index b7269b8..73c67c4 100644
--- a/drivers/media/i2c/adv7842.c
+++ b/drivers/media/i2c/adv7842.c
@@ -39,6 +39,7 @@
 #include linux/workqueue.h
 #include linux/v4l2-dv-timings.h
 #include linux/hdmi.h
+#include media/cec.h
 #include media/v4l2-device.h
 #include media/v4l2-event.h
 #include media/v4l2-ctrls.h
@@ -79,6 +80,8 @@ MODULE_LICENSE(GPL);
 
 #define ADV7842_OP_SWAP_CB_CR  (1  0)
 
+#define ADV7842_MAX_ADDRS (3)
+
 /*
 **
 *
@@ -142,6 +145,10 @@ struct adv7842_state {
struct v4l2_ctrl *free_run_color_ctrl_manual;
struct v4l2_ctrl *free_run_color_ctrl;
struct v4l2_ctrl *rgb_quantization_range_ctrl;
+
+   u8   cec_addr[ADV7842_MAX_ADDRS];
+   u8   cec_valid_addrs;
+   bool cec_enabled_adap;
 };
 
 /* Unsupported timings. This device cannot support 720p30. */
@@ -418,9 +425,9 @@ static inline int cec_write(struct v4l2_subdev *sd, u8 reg, 
u8 val)
return adv_smbus_write_byte_data(state-i2c_cec, reg, val);
 }
 
-static inline int cec_write_and_or(struct v4l2_subdev *sd, u8 reg, u8 mask, u8 
val)
+static inline int cec_write_clr_set(struct v4l2_subdev *sd, u8 reg, u8 mask, 
u8 val)
 {
-   return cec_write(sd, reg, (cec_read(sd, reg)  mask) | val);
+   return cec_write(sd, reg, (cec_read(sd, reg)  ~mask) | val);
 }
 
 static inline int infoframe_read(struct v4l2_subdev *sd, u8 reg)
@@ -696,6 +703,18 @@ adv7842_get_dv_timings_cap(struct v4l2_subdev *sd)
 
 /* --- */
 
+static u16 adv7842_read_cable_det(struct v4l2_subdev *sd)
+{
+   u8 reg = io_read(sd, 0x6f);
+   u16 val = 0;
+
+   if (reg  0x02)
+   val |= 1; /* port A */
+   if (reg  0x01)
+   val |= 2; /* port B */
+   return val;
+}
+
 static void adv7842_delayed_work_enable_hotplug(struct work_struct *work)
 {
struct delayed_work *dwork = to_delayed_work(work);
@@ -703,8 +722,13 @@ static void adv7842_delayed_work_enable_hotplug(struct 
work_struct *work)
struct adv7842_state, delayed_work_enable_hotplug);
struct v4l2_subdev *sd = state-sd;
int present = state-hdmi_edid.present;
+   u16 connected_inputs;
u8 mask = 0;
 
+   connected_inputs = present  adv7842_read_cable_det(sd);
+   v4l2_subdev_notify(sd, V4L2_SUBDEV_CEC_CONN_INPUTS,
+  connected_inputs);
+
v4l2_dbg(2, debug, sd, %s: enable hotplug on ports: 0x%x\n,
__func__, present);
 
@@ -983,20 +1007,16 @@ static int adv7842_s_register(struct v4l2_subdev *sd,
 static int adv7842_s_detect_tx_5v_ctrl(struct v4l2_subdev *sd)
 {
struct adv7842_state *state = to_state(sd);
-   int prev = v4l2_ctrl_g_ctrl(state-detect_tx_5v_ctrl);
-   u8 reg_io_6f = io_read(sd, 0x6f);
-   int val = 0;
+   u16 cable_det = adv7842_read_cable_det(sd);
+   u16 connected_inputs;
 
-   if (reg_io_6f  0x02)
-   val |= 1; /* port A */
-   if (reg_io_6f  0x01)
-   val |= 2; /* port B */
+   v4l2_dbg(1, debug, sd, %s: 0x%x\n, __func__, cable_det);
 
-   v4l2_dbg(1, debug, sd, %s: 0x%x - 0x%x\n, __func__, prev, val);
+   connected_inputs = state-hdmi_edid.present  cable_det;
+   v4l2_subdev_notify(sd, V4L2_SUBDEV_CEC_CONN_INPUTS,
+  connected_inputs);
 
-   if (val != prev)
-   return v4l2_ctrl_s_ctrl(state-detect_tx_5v_ctrl, val);
-   return 0;
+   return v4l2_ctrl_s_ctrl(state-detect_tx_5v_ctrl, cable_det);
 }
 
 static int find_and_set_predefined_video_timings(struct v4l2_subdev *sd,
@@ -2157,6 +2177,182 @@ static void adv7842_irq_enable(struct v4l2_subdev *sd, 
bool enable)
}
 }
 
+static void adv7842_cec_tx_raw_status(struct v4l2_subdev *sd, u8 tx_raw_status)
+{
+   if ((cec_read(sd, 0x11)  0x01) == 0) {
+   v4l2_dbg(1, debug, sd, %s: tx raw: tx disabled\n, __func__);
+   return;
+   }
+
+   if (tx_raw_status  0x02) {
+   v4l2_dbg(1, debug, sd, %s: tx raw: arbitration lost\n,
+__func__);
+   v4l2_subdev_notify(sd, V4L2_SUBDEV_CEC_TX_DONE,
+  (void *)CEC_TX_STATUS_ARB_LOST);
+   return;
+   }
+   if (tx_raw_status  0x04) {
+   v4l2_dbg(1, debug, sd, %s: tx raw: retry failed\n, __func__);
+   v4l2_subdev_notify(sd, V4L2_SUBDEV_CEC_TX_DONE,
+  (void *)CEC_TX_STATUS_RETRY_TIMEOUT);
+   return;
+   }
+   if (tx_raw_status

[PATCHv2 2/4] sync-with-kernel

2015-08-18 Thread Hans Verkuil
Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 contrib/freebsd/include/linux/input.h |   29 +
 contrib/freebsd/include/linux/v4l2-controls.h |4 +
 include/linux/cec-funcs.h | 1771 +
 include/linux/cec.h   |  781 +++
 include/linux/v4l2-controls.h |4 +
 utils/keytable/parse.h|   18 +
 utils/keytable/rc_keymaps/lme2510 |  132 +-
 utils/keytable/rc_maps.cfg|1 +
 8 files changed, 2674 insertions(+), 66 deletions(-)
 create mode 100644 include/linux/cec-funcs.h
 create mode 100644 include/linux/cec.h

diff --git a/contrib/freebsd/include/linux/input.h 
b/contrib/freebsd/include/linux/input.h
index 19345e1..1bc7241 100644
--- a/contrib/freebsd/include/linux/input.h
+++ b/contrib/freebsd/include/linux/input.h
@@ -786,6 +786,34 @@ struct input_keymap_entry {
 #define KEY_KBDINPUTASSIST_ACCEPT  0x264
 #define KEY_KBDINPUTASSIST_CANCEL  0x265
 
+#define KEY_RIGHT_UP   0x266
+#define KEY_RIGHT_DOWN 0x267
+#define KEY_LEFT_UP0x268
+#define KEY_LEFT_DOWN  0x269
+#define KEY_ROOT_MENU  0x26a /* Show Device's Root Menu */
+#define KEY_MEDIA_TOP_MENU 0x26b /* Show Top Menu of the Media 
(e.g. DVD) */
+#define KEY_NUMERIC_11 0x26c
+#define KEY_NUMERIC_12 0x26d
+/*
+ * Toggle Audio Description: refers to an audio service that helps blind and
+ * visually impaired consumers understand the action in a program. Note: in
+ * some countries this is referred to as Video Description.
+ */
+#define KEY_AUDIO_DESC 0x26e
+#define KEY_3D_MODE0x26f
+#define KEY_NEXT_FAVORITE  0x270
+#define KEY_STOP_RECORD0x271
+#define KEY_PAUSE_RECORD   0x272
+#define KEY_VOD0x273 /* Video on Demand */
+#define KEY_UNMUTE 0x274
+#define KEY_FASTREVERSE0x275
+#define KEY_SLOWREVERSE0x276
+/*
+ * Control a data application associated with the currently viewed channel,
+ * e.g. teletext or data broadcast application (MHEG, MHP, HbbTV, etc.)
+ */
+#define KEY_DATA   0x275
+
 #define BTN_TRIGGER_HAPPY  0x2c0
 #define BTN_TRIGGER_HAPPY1 0x2c0
 #define BTN_TRIGGER_HAPPY2 0x2c1
@@ -1006,6 +1034,7 @@ struct input_keymap_entry {
 #define BUS_GSC0x1A
 #define BUS_ATARI  0x1B
 #define BUS_SPI0x1C
+#define BUS_CEC0x1D
 
 /*
  * MT_TOOL types
diff --git a/contrib/freebsd/include/linux/v4l2-controls.h 
b/contrib/freebsd/include/linux/v4l2-controls.h
index 9f6e108..d448c53 100644
--- a/contrib/freebsd/include/linux/v4l2-controls.h
+++ b/contrib/freebsd/include/linux/v4l2-controls.h
@@ -174,6 +174,10 @@ enum v4l2_colorfx {
  * We reserve 16 controls for this driver. */
 #define V4L2_CID_USER_ADV7180_BASE (V4L2_CID_USER_BASE + 0x1070)
 
+/* The base for the tc358743 driver controls.
+ * We reserve 16 controls for this driver. */
+#define V4L2_CID_USER_TC358743_BASE(V4L2_CID_USER_BASE + 0x1080)
+
 /* MPEG-class control IDs */
 /* The MPEG controls are applicable to all codec controls
  * and the 'MPEG' part of the define is historical */
diff --git a/include/linux/cec-funcs.h b/include/linux/cec-funcs.h
new file mode 100644
index 000..45fb7bd
--- /dev/null
+++ b/include/linux/cec-funcs.h
@@ -0,0 +1,1771 @@
+#ifndef _CEC_FUNCS_H
+#define _CEC_FUNCS_H
+
+#include linux/cec.h
+
+/* One Touch Play Feature */
+static __inline__ void cec_msg_active_source(struct cec_msg *msg, __u16 
phys_addr)
+{
+   msg-len = 4;
+   msg-msg[0] |= 0xf; /* broadcast */
+   msg-msg[1] = CEC_MSG_ACTIVE_SOURCE;
+   msg-msg[2] = phys_addr  8;
+   msg-msg[3] = phys_addr  0xff;
+}
+
+static __inline__ void cec_ops_active_source(const struct cec_msg *msg,
+__u16 *phys_addr)
+{
+   *phys_addr = (msg-msg[2]  8) | msg-msg[3];
+}
+
+static __inline__ void cec_msg_image_view_on(struct cec_msg *msg)
+{
+   msg-len = 2;
+   msg-msg[1] = CEC_MSG_IMAGE_VIEW_ON;
+}
+
+static __inline__ void cec_msg_text_view_on(struct cec_msg *msg)
+{
+   msg-len = 2;
+   msg-msg[1] = CEC_MSG_TEXT_VIEW_ON;
+}
+
+
+/* Routing Control Feature */
+static __inline__ void cec_msg_inactive_source(struct cec_msg *msg,
+  __u16 phys_addr)
+{
+   msg-len = 4;
+   msg-msg[1] = CEC_MSG_INACTIVE_SOURCE;
+   msg-msg[2] = phys_addr  8;
+   msg-msg[3] = phys_addr  0xff;
+}
+
+static __inline__ void cec_ops_inactive_source(const struct cec_msg *msg,
+  __u16 *phys_addr)
+{
+   *phys_addr = (msg

[PATCHv8 02/15] dts: exynos4: add node for the HDMI CEC device

2015-08-18 Thread Hans Verkuil
From: Kamil Debski ka...@wypas.org

This patch adds HDMI CEC node specific to the Exynos4210/4x12 SoC series.

Signed-off-by: Kamil Debski ka...@wypas.org
Signed-off-by: Hans Verkuil hans.verk...@cisco.com
Acked-by: Krzysztof Kozlowski k.kozlow...@samsung.com
---
 arch/arm/boot/dts/exynos4.dtsi | 12 
 1 file changed, 12 insertions(+)

diff --git a/arch/arm/boot/dts/exynos4.dtsi b/arch/arm/boot/dts/exynos4.dtsi
index b0d52b1..0d5319e 100644
--- a/arch/arm/boot/dts/exynos4.dtsi
+++ b/arch/arm/boot/dts/exynos4.dtsi
@@ -719,6 +719,18 @@
status = disabled;
};
 
+   hdmicec: cec@100B {
+   compatible = samsung,s5p-cec;
+   reg = 0x100B 0x200;
+   interrupts = 0 114 0;
+   clocks = clock CLK_HDMI_CEC;
+   clock-names = hdmicec;
+   samsung,syscon-phandle = pmu_system_controller;
+   pinctrl-names = default;
+   pinctrl-0 = hdmi_cec;
+   status = disabled;
+   };
+
mixer: mixer@12C1 {
compatible = samsung,exynos4210-mixer;
interrupts = 0 91 0;
-- 
2.1.4

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


[PATCHv8 00/15] HDMI CEC framework

2015-08-18 Thread Hans Verkuil
 to event hanlding
- add passthrough mode
- change reserved field sizes
- fixed CEC version defines and addec CEC 2.0 commands
- add DocBook documentation

Changes since v3

- remove the promiscuous mode
- rewrite the devicetree patches
- fixes, expansion and partial rewrite of the documentation
- reorder of API structures and addition of reserved fields
- use own struct to report time (32/64 bit safe)
- fix of handling events
- add cec.h to include/uapi/linux/Kbuild
- fixes in the adv76xx driver (add missing methods, change adv7604 to adv76xx)
- cleanup of debug messages in s5p-cec driver
- remove non necessary claiming of a gpio in the s5p-cec driver
- cleanup headers of the s5p-cec driver

Changes since v2
===-
- added promiscuous mode
- added new key codes to the input framework
- add vendor ID reporting
- add the possibility to clear assigned logical addresses
- cleanup of the rc cec map

Changes since v1

- documentation edited and moved to the Documentation folder
- added key up/down message handling
- add missing CEC commands to the cec.h file

Background
==

The work on a common CEC framework was started over three years ago by Hans
Verkuil. Unfortunately the work has stalled. As I have received the task of
creating a driver for the CEC interface module present on the Exynos range of
SoCs, I got in touch with Hans. He replied that the work stalled due to his
lack of time.

Original RFC by Hans Verkuil/Martin Bugge
=
https://www.mail-archive.com/linux-media@vger.kernel.org/msg28735.html

Hans Verkuil (9):
  input.h: add BUS_CEC type
  cec: add HDMI CEC framework
  cec.txt: add CEC framework documentation
  DocBook/media: add CEC documentation
  v4l2-subdev: add HDMI CEC ops
  cec: adv7604: add cec support.
  cec: adv7842: add cec support
  cec: adv7511: add cec support.
  cobalt: add cec support

Kamil Debski (6):
  dts: exynos4*: add HDMI CEC pin definition to pinctrl
  dts: exynos4: add node for the HDMI CEC device
  dts: exynos4412-odroid*: enable the HDMI CEC device
  HID: add HDMI CEC specific keycodes
  rc: Add HDMI CEC protocol handling
  cec: s5p-cec: Add s5p-cec driver

 Documentation/DocBook/media/Makefile   |2 +
 Documentation/DocBook/media/v4l/biblio.xml |   10 +
 Documentation/DocBook/media/v4l/cec-api.xml|   75 +
 Documentation/DocBook/media/v4l/cec-func-close.xml |   59 +
 Documentation/DocBook/media/v4l/cec-func-ioctl.xml |   73 +
 Documentation/DocBook/media/v4l/cec-func-open.xml  |   94 +
 Documentation/DocBook/media/v4l/cec-func-poll.xml  |   89 +
 .../DocBook/media/v4l/cec-ioc-adap-g-caps.xml  |  138 ++
 .../DocBook/media/v4l/cec-ioc-adap-g-log-addrs.xml |  306 
 .../DocBook/media/v4l/cec-ioc-adap-g-phys-addr.xml |   78 +
 .../DocBook/media/v4l/cec-ioc-adap-g-state.xml |   87 +
 .../DocBook/media/v4l/cec-ioc-adap-g-vendor-id.xml |   70 +
 .../DocBook/media/v4l/cec-ioc-dqevent.xml  |  125 ++
 .../DocBook/media/v4l/cec-ioc-g-monitor.xml|   86 +
 .../DocBook/media/v4l/cec-ioc-g-passthrough.xml|   81 +
 .../DocBook/media/v4l/cec-ioc-receive.xml  |  185 ++
 Documentation/DocBook/media_api.tmpl   |8 +-
 Documentation/cec.txt  |  166 ++
 .../devicetree/bindings/media/s5p-cec.txt  |   31 +
 MAINTAINERS|   12 +
 arch/arm/boot/dts/exynos4.dtsi |   12 +
 arch/arm/boot/dts/exynos4210-pinctrl.dtsi  |7 +
 arch/arm/boot/dts/exynos4210-universal_c210.dts|4 +
 arch/arm/boot/dts/exynos4x12-pinctrl.dtsi  |7 +
 drivers/media/Kconfig  |6 +
 drivers/media/Makefile |2 +
 drivers/media/cec.c| 1903 
 drivers/media/i2c/adv7511.c|  359 +++-
 drivers/media/i2c/adv7604.c|  236 ++-
 drivers/media/i2c/adv7842.c|  250 ++-
 drivers/media/pci/cobalt/cobalt-driver.c   |   50 +-
 drivers/media/pci/cobalt/cobalt-driver.h   |2 +
 drivers/media/pci/cobalt/cobalt-irq.c  |3 +
 drivers/media/pci/cobalt/cobalt-v4l2.c |  107 +-
 drivers/media/platform/Kconfig |   10 +
 drivers/media/platform/Makefile|1 +
 drivers/media/platform/s5p-cec/Makefile|2 +
 drivers/media/platform/s5p-cec/exynos_hdmi_cec.h   |   37 +
 .../media/platform/s5p-cec/exynos_hdmi_cecctrl.c   |  208 +++
 drivers/media/platform/s5p-cec/regs-cec.h  |   96 +
 drivers/media/platform/s5p-cec/s5p_cec.c   |  277 +++
 drivers/media/platform/s5p-cec/s5p_cec.h   |   76 +
 drivers/media/rc/keymaps/Makefile  |1 +
 drivers/media/rc/keymaps/rc-cec.c  |  174 ++
 drivers/media/rc/rc-main.c |1

[PATCHv2 1/4] Makefile.am: copy cec headers with make sync-with-kernel

2015-08-18 Thread Hans Verkuil
Copy the new cec headers.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 Makefile.am | 4 
 1 file changed, 4 insertions(+)

diff --git a/Makefile.am b/Makefile.am
index 1a61592..b8c450d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -21,6 +21,8 @@ sync-with-kernel:
  ! -f $(KERNEL_DIR)/usr/include/linux/v4l2-common.h -o \
  ! -f $(KERNEL_DIR)/usr/include/linux/v4l2-subdev.h -o \
  ! -f $(KERNEL_DIR)/usr/include/linux/v4l2-mediabus.h -o \
+ ! -f $(KERNEL_DIR)/usr/include/linux/cec.h -o \
+ ! -f $(KERNEL_DIR)/usr/include/linux/cec-funcs.h -o \
  ! -f $(KERNEL_DIR)/usr/include/linux/ivtv.h -o \
  ! -f $(KERNEL_DIR)/usr/include/linux/dvb/frontend.h -o \
  ! -f $(KERNEL_DIR)/usr/include/linux/dvb/dmx.h -o \
@@ -38,6 +40,8 @@ sync-with-kernel:
cp -a $(KERNEL_DIR)/usr/include/linux/v4l2-mediabus.h 
$(top_srcdir)/include/linux
cp -a $(KERNEL_DIR)/usr/include/linux/media-bus-format.h 
$(top_srcdir)/include/linux
cp -a $(KERNEL_DIR)/usr/include/linux/media.h 
$(top_srcdir)/include/linux
+   cp -a $(KERNEL_DIR)/usr/include/linux/cec.h $(top_srcdir)/include/linux
+   cp -a $(KERNEL_DIR)/usr/include/linux/cec-funcs.h 
$(top_srcdir)/include/linux
cp -a $(KERNEL_DIR)/usr/include/linux/ivtv.h $(top_srcdir)/include/linux
cp -a $(KERNEL_DIR)/usr/include/linux/dvb/frontend.h 
$(top_srcdir)/include/linux/dvb
cp -a $(KERNEL_DIR)/usr/include/linux/dvb/dmx.h 
$(top_srcdir)/include/linux/dvb
-- 
2.1.4

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


[PATCHv8 03/15] dts: exynos4412-odroid*: enable the HDMI CEC device

2015-08-18 Thread Hans Verkuil
From: Kamil Debski ka...@wypas.org

Add a dts node entry and enable the HDMI CEC device present in the Exynos4
family of SoCs.

Signed-off-by: Kamil Debski ka...@wypas.org
Signed-off-by: Hans Verkuil hans.verk...@cisco.com
Acked-by: Krzysztof Kozlowski k.kozlow...@samsung.com
---
 arch/arm/boot/dts/exynos4210-universal_c210.dts | 4 
 1 file changed, 4 insertions(+)

diff --git a/arch/arm/boot/dts/exynos4210-universal_c210.dts 
b/arch/arm/boot/dts/exynos4210-universal_c210.dts
index d4f2b11..06df693 100644
--- a/arch/arm/boot/dts/exynos4210-universal_c210.dts
+++ b/arch/arm/boot/dts/exynos4210-universal_c210.dts
@@ -515,6 +515,10 @@
enable-active-high;
};
 
+   cec@100B {
+   status = okay;
+   };
+
hdmi_ddc: i2c-ddc {
compatible = i2c-gpio;
gpios = gpe4 2 0 gpe4 3 0;
-- 
2.1.4

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


[PATCHv8 11/15] cec: adv7604: add cec support.

2015-08-18 Thread Hans Verkuil
From: Hans Verkuil hverk...@xs4all.nl

Add CEC support to the adv7604 driver.

Signed-off-by: Hans Verkuil hansv...@cisco.com
[k.deb...@samsung.com: Merged changes from CEC Updates commit by Hans Verkuil]
[k.deb...@samsung.com: add missing methods cec/io_write_and_or]
[k.deb...@samsung.com: change adv7604 to adv76xx in added functions]
[hansv...@cisco.com: use _clr_set instead of _and_or]
Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/i2c/adv7604.c | 236 +++-
 1 file changed, 232 insertions(+), 4 deletions(-)

diff --git a/drivers/media/i2c/adv7604.c b/drivers/media/i2c/adv7604.c
index 5631ec0..20b0838 100644
--- a/drivers/media/i2c/adv7604.c
+++ b/drivers/media/i2c/adv7604.c
@@ -40,6 +40,7 @@
 #include linux/regmap.h
 
 #include media/adv7604.h
+#include media/cec.h
 #include media/v4l2-ctrls.h
 #include media/v4l2-device.h
 #include media/v4l2-event.h
@@ -80,6 +81,8 @@ MODULE_LICENSE(GPL);
 
 #define ADV76XX_OP_SWAP_CB_CR  (1  0)
 
+#define ADV76XX_MAX_ADDRS (3)
+
 enum adv76xx_type {
ADV7604,
ADV7611,
@@ -184,6 +187,10 @@ struct adv76xx_state {
u16 spa_port_a[2];
struct v4l2_fract aspect_ratio;
u32 rgb_quantization_range;
+   u8   cec_addr[ADV76XX_MAX_ADDRS];
+   u8   cec_valid_addrs;
+   bool cec_enabled_adap;
+
struct workqueue_struct *work_queues;
struct delayed_work delayed_work_enable_hotplug;
bool restart_stdi_once;
@@ -430,7 +437,8 @@ static inline int io_write(struct v4l2_subdev *sd, u8 reg, 
u8 val)
return regmap_write(state-regmap[ADV76XX_PAGE_IO], reg, val);
 }
 
-static inline int io_write_clr_set(struct v4l2_subdev *sd, u8 reg, u8 mask, u8 
val)
+static inline int io_write_clr_set(struct v4l2_subdev *sd, u8 reg, u8 mask,
+  u8 val)
 {
return io_write(sd, reg, (io_read(sd, reg)  ~mask) | val);
 }
@@ -463,6 +471,12 @@ static inline int cec_write(struct v4l2_subdev *sd, u8 
reg, u8 val)
return regmap_write(state-regmap[ADV76XX_PAGE_CEC], reg, val);
 }
 
+static inline int cec_write_clr_set(struct v4l2_subdev *sd, u8 reg, u8 mask,
+  u8 val)
+{
+   return cec_write(sd, reg, (cec_read(sd, reg)  ~mask) | val);
+}
+
 static inline int infoframe_read(struct v4l2_subdev *sd, u8 reg)
 {
struct adv76xx_state *state = to_state(sd);
@@ -550,8 +564,13 @@ static inline int edid_write_block(struct v4l2_subdev *sd,
 
 static void adv76xx_set_hpd(struct adv76xx_state *state, unsigned int hpd)
 {
+   u16 connected_inputs;
unsigned int i;
 
+   connected_inputs = hpd  state-info-read_cable_det(state-sd);
+   v4l2_subdev_notify(state-sd, V4L2_SUBDEV_CEC_CONN_INPUTS,
+  connected_inputs);
+
for (i = 0; i  state-info-num_dv_ports; ++i)
gpiod_set_value_cansleep(state-hpd_gpio[i], hpd  BIT(i));
 
@@ -891,9 +910,12 @@ static int adv76xx_s_detect_tx_5v_ctrl(struct v4l2_subdev 
*sd)
 {
struct adv76xx_state *state = to_state(sd);
const struct adv76xx_chip_info *info = state-info;
+   u16 cable_det = info-read_cable_det(sd);
+   u16 connected_inputs = state-edid.present  cable_det;
+
+   v4l2_subdev_notify(sd, V4L2_SUBDEV_CEC_CONN_INPUTS, connected_inputs);
 
-   return v4l2_ctrl_s_ctrl(state-detect_tx_5v_ctrl,
-   info-read_cable_det(sd));
+   return v4l2_ctrl_s_ctrl(state-detect_tx_5v_ctrl, cable_det);
 }
 
 static int find_and_set_predefined_video_timings(struct v4l2_subdev *sd,
@@ -1914,6 +1936,186 @@ static int adv76xx_set_format(struct v4l2_subdev *sd,
return 0;
 }
 
+static void adv76xx_cec_tx_raw_status(struct v4l2_subdev *sd, u8 tx_raw_status)
+{
+   if ((cec_read(sd, 0x11)  0x01) == 0) {
+   v4l2_dbg(1, debug, sd, %s: tx raw: tx disabled\n, __func__);
+   return;
+   }
+
+   if (tx_raw_status  0x02) {
+   v4l2_dbg(1, debug, sd, %s: tx raw: arbitration lost\n,
+__func__);
+   v4l2_subdev_notify(sd, V4L2_SUBDEV_CEC_TX_DONE,
+  (void *)CEC_TX_STATUS_ARB_LOST);
+   return;
+   }
+   if (tx_raw_status  0x04) {
+   v4l2_dbg(1, debug, sd, %s: tx raw: retry failed\n, __func__);
+   v4l2_subdev_notify(sd, V4L2_SUBDEV_CEC_TX_DONE,
+  (void *)CEC_TX_STATUS_RETRY_TIMEOUT);
+   return;
+   }
+   if (tx_raw_status  0x01) {
+   v4l2_dbg(1, debug, sd, %s: tx raw: ready ok\n, __func__);
+   v4l2_subdev_notify(sd, V4L2_SUBDEV_CEC_TX_DONE,
+  (void *)CEC_TX_STATUS_OK);
+   return;
+   }
+}
+
+static void adv76xx_cec_isr(struct v4l2_subdev *sd, bool *handled)
+{
+   u8 cec_irq;
+
+   /* cec controller */
+   cec_irq = io_read(sd, 0x4d)  0x0f

[PATCHv8 05/15] HID: add HDMI CEC specific keycodes

2015-08-18 Thread Hans Verkuil
From: Kamil Debski ka...@wypas.org

Add HDMI CEC specific keycodes to the keycodes definition.

Signed-off-by: Kamil Debski ka...@wypas.org
Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 include/uapi/linux/input.h | 28 
 1 file changed, 28 insertions(+)

diff --git a/include/uapi/linux/input.h b/include/uapi/linux/input.h
index a32bff1..5e7019a 100644
--- a/include/uapi/linux/input.h
+++ b/include/uapi/linux/input.h
@@ -752,6 +752,34 @@ struct input_keymap_entry {
 #define KEY_KBDINPUTASSIST_ACCEPT  0x264
 #define KEY_KBDINPUTASSIST_CANCEL  0x265
 
+#define KEY_RIGHT_UP   0x266
+#define KEY_RIGHT_DOWN 0x267
+#define KEY_LEFT_UP0x268
+#define KEY_LEFT_DOWN  0x269
+#define KEY_ROOT_MENU  0x26a /* Show Device's Root Menu */
+#define KEY_MEDIA_TOP_MENU 0x26b /* Show Top Menu of the Media 
(e.g. DVD) */
+#define KEY_NUMERIC_11 0x26c
+#define KEY_NUMERIC_12 0x26d
+/*
+ * Toggle Audio Description: refers to an audio service that helps blind and
+ * visually impaired consumers understand the action in a program. Note: in
+ * some countries this is referred to as Video Description.
+ */
+#define KEY_AUDIO_DESC 0x26e
+#define KEY_3D_MODE0x26f
+#define KEY_NEXT_FAVORITE  0x270
+#define KEY_STOP_RECORD0x271
+#define KEY_PAUSE_RECORD   0x272
+#define KEY_VOD0x273 /* Video on Demand */
+#define KEY_UNMUTE 0x274
+#define KEY_FASTREVERSE0x275
+#define KEY_SLOWREVERSE0x276
+/*
+ * Control a data application associated with the currently viewed channel,
+ * e.g. teletext or data broadcast application (MHEG, MHP, HbbTV, etc.)
+ */
+#define KEY_DATA   0x275
+
 #define BTN_TRIGGER_HAPPY  0x2c0
 #define BTN_TRIGGER_HAPPY1 0x2c0
 #define BTN_TRIGGER_HAPPY2 0x2c1
-- 
2.1.4

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


[PATCHv8 13/15] cec: adv7511: add cec support.

2015-08-18 Thread Hans Verkuil
Add CEC support to the adv7511 driver.

Signed-off-by: Hans Verkuil hansv...@cisco.com
[k.deb...@samsung.com: Merged changes from CEC Updates commit by Hans Verkuil]
Signed-off-by: Kamil Debski ka...@wypas.org
Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/i2c/adv7511.c | 359 +++-
 include/media/adv7511.h |   6 +-
 2 files changed, 353 insertions(+), 12 deletions(-)

diff --git a/drivers/media/i2c/adv7511.c b/drivers/media/i2c/adv7511.c
index e4900df..645d4ba 100644
--- a/drivers/media/i2c/adv7511.c
+++ b/drivers/media/i2c/adv7511.c
@@ -33,6 +33,7 @@
 #include media/v4l2-ctrls.h
 #include media/v4l2-dv-timings.h
 #include media/adv7511.h
+#include media/cec.h
 
 static int debug;
 module_param(debug, int, 0644);
@@ -59,6 +60,8 @@ MODULE_LICENSE(GPL v2);
 #define ADV7511_MIN_PIXELCLOCK 2000
 #define ADV7511_MAX_PIXELCLOCK 22500
 
+#define ADV7511_MAX_ADDRS (3)
+
 /*
 **
 *
@@ -90,12 +93,19 @@ struct adv7511_state {
struct v4l2_ctrl_handler hdl;
int chip_revision;
u8 i2c_edid_addr;
-   u8 i2c_cec_addr;
u8 i2c_pktmem_addr;
+   u8 i2c_cec_addr;
+
+   struct i2c_client *i2c_cec;
+   u8   cec_addr[ADV7511_MAX_ADDRS];
+   u8   cec_valid_addrs;
+   bool cec_enabled_adap;
+
/* Is the adv7511 powered on? */
bool power_on;
/* Did we receive hotplug and rx-sense signals? */
bool have_monitor;
+   bool enabled_irq;
/* timings from s_dv_timings */
struct v4l2_dv_timings dv_timings;
u32 fmt_code;
@@ -225,7 +235,7 @@ static int adv_smbus_read_i2c_block_data(struct i2c_client 
*client,
return ret;
 }
 
-static inline void adv7511_edid_rd(struct v4l2_subdev *sd, u16 len, u8 *buf)
+static void adv7511_edid_rd(struct v4l2_subdev *sd, uint16_t len, uint8_t *buf)
 {
struct adv7511_state *state = get_adv7511_state(sd);
int i;
@@ -240,6 +250,34 @@ static inline void adv7511_edid_rd(struct v4l2_subdev *sd, 
u16 len, u8 *buf)
v4l2_err(sd, %s: i2c read error\n, __func__);
 }
 
+static inline int adv7511_cec_read(struct v4l2_subdev *sd, u8 reg)
+{
+   struct adv7511_state *state = get_adv7511_state(sd);
+
+   return i2c_smbus_read_byte_data(state-i2c_cec, reg);
+}
+
+static int adv7511_cec_write(struct v4l2_subdev *sd, u8 reg, u8 val)
+{
+   struct adv7511_state *state = get_adv7511_state(sd);
+   int ret;
+   int i;
+
+   for (i = 0; i  3; i++) {
+   ret = i2c_smbus_write_byte_data(state-i2c_cec, reg, val);
+   if (ret == 0)
+   return 0;
+   }
+   v4l2_err(sd, %s: I2C Write Problem\n, __func__);
+   return ret;
+}
+
+static inline int adv7511_cec_write_and_or(struct v4l2_subdev *sd, u8 reg, u8 
mask,
+  u8 val)
+{
+   return adv7511_cec_write(sd, reg, (adv7511_cec_read(sd, reg)  mask) | 
val);
+}
+
 static int adv7511_pktmem_rd(struct v4l2_subdev *sd, u8 reg)
 {
struct adv7511_state *state = get_adv7511_state(sd);
@@ -413,16 +451,28 @@ static const struct v4l2_ctrl_ops adv7511_ctrl_ops = {
 #ifdef CONFIG_VIDEO_ADV_DEBUG
 static void adv7511_inv_register(struct v4l2_subdev *sd)
 {
+   struct adv7511_state *state = get_adv7511_state(sd);
+
v4l2_info(sd, 0x000-0x0ff: Main Map\n);
+   if (state-i2c_cec)
+   v4l2_info(sd, 0x100-0x1ff: CEC Map\n);
 }
 
 static int adv7511_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register 
*reg)
 {
+   struct adv7511_state *state = get_adv7511_state(sd);
+
reg-size = 1;
switch (reg-reg  8) {
case 0:
reg-val = adv7511_rd(sd, reg-reg  0xff);
break;
+   case 1:
+   if (state-i2c_cec) {
+   reg-val = adv7511_cec_read(sd, reg-reg  0xff);
+   break;
+   }
+   /* fall through */
default:
v4l2_info(sd, Register %03llx not supported\n, reg-reg);
adv7511_inv_register(sd);
@@ -433,10 +483,18 @@ static int adv7511_g_register(struct v4l2_subdev *sd, 
struct v4l2_dbg_register *
 
 static int adv7511_s_register(struct v4l2_subdev *sd, const struct 
v4l2_dbg_register *reg)
 {
+   struct adv7511_state *state = get_adv7511_state(sd);
+
switch (reg-reg  8) {
case 0:
adv7511_wr(sd, reg-reg  0xff, reg-val  0xff);
break;
+   case 1:
+   if (state-i2c_cec) {
+   adv7511_cec_write(sd, reg-reg  0xff, reg-val  0xff);
+   break;
+   }
+   /* fall through */
default:
v4l2_info(sd, Register %03llx not supported\n, reg-reg);
adv7511_inv_register(sd);
@@ -524,6 +582,7 @@ static int adv7511_log_status(struct v4l2_subdev *sd

[PATCHv8 10/15] v4l2-subdev: add HDMI CEC ops

2015-08-18 Thread Hans Verkuil
Add CEC callbacks to the v4l2_subdev_video_ops. These are the low-level CEC
ops that subdevs that support CEC have to implement.

Signed-off-by: Hans Verkuil hansv...@cisco.com
[k.deb...@samsung.com: Merged changes from CEC Updates commit by Hans Verkuil]
Signed-off-by: Kamil Debski ka...@wypas.org
Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 include/media/v4l2-subdev.h | 9 +
 1 file changed, 9 insertions(+)

diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
index 370fc38..1b04d94 100644
--- a/include/media/v4l2-subdev.h
+++ b/include/media/v4l2-subdev.h
@@ -42,6 +42,10 @@
 
 #defineV4L2_DEVICE_NOTIFY_EVENT_IOW('v', 2, struct 
v4l2_event)
 
+#define V4L2_SUBDEV_CEC_TX_DONE_IOW('v', 3, u32)
+#define V4L2_SUBDEV_CEC_RX_MSG _IOW('v', 4, struct cec_msg)
+#define V4L2_SUBDEV_CEC_CONN_INPUTS_IOW('v', 5, u16)
+
 struct v4l2_device;
 struct v4l2_ctrl_handler;
 struct v4l2_event;
@@ -51,6 +55,7 @@ struct v4l2_subdev;
 struct v4l2_subdev_fh;
 struct tuner_setup;
 struct v4l2_mbus_frame_desc;
+struct cec_msg;
 
 /* decode_vbi_line */
 struct v4l2_decode_vbi_line {
@@ -339,6 +344,10 @@ struct v4l2_subdev_video_ops {
 const struct v4l2_mbus_config *cfg);
int (*s_rx_buffer)(struct v4l2_subdev *sd, void *buf,
   unsigned int *size);
+   unsigned (*cec_available_log_addrs)(struct v4l2_subdev *sd);
+   int (*cec_enable)(struct v4l2_subdev *sd, bool enable);
+   int (*cec_log_addr)(struct v4l2_subdev *sd, u8 logical_addr);
+   int (*cec_transmit)(struct v4l2_subdev *sd, u32 timeout_ms, struct 
cec_msg *msg);
 };
 
 /*
-- 
2.1.4

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


[PATCHv8 15/15] cobalt: add cec support

2015-08-18 Thread Hans Verkuil
Add CEC support to the cobalt driver.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/pci/cobalt/cobalt-driver.c |  50 +--
 drivers/media/pci/cobalt/cobalt-driver.h |   2 +
 drivers/media/pci/cobalt/cobalt-irq.c|   3 +
 drivers/media/pci/cobalt/cobalt-v4l2.c   | 107 +--
 4 files changed, 151 insertions(+), 11 deletions(-)

diff --git a/drivers/media/pci/cobalt/cobalt-driver.c 
b/drivers/media/pci/cobalt/cobalt-driver.c
index 8fed61e..920c9de 100644
--- a/drivers/media/pci/cobalt/cobalt-driver.c
+++ b/drivers/media/pci/cobalt/cobalt-driver.c
@@ -76,6 +76,7 @@ static u8 edid[256] = {
0x0A, 0x0A, 0x0A, 0x0A, 0x00, 0x00, 0x00, 0x10,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x68,
+
0x02, 0x03, 0x1a, 0xc0, 0x48, 0xa2, 0x10, 0x04,
0x02, 0x01, 0x21, 0x14, 0x13, 0x23, 0x09, 0x07,
0x07, 0x65, 0x03, 0x0c, 0x00, 0x10, 0x00, 0xe2,
@@ -149,17 +150,57 @@ static void cobalt_notify(struct v4l2_subdev *sd,
struct cobalt *cobalt = to_cobalt(sd-v4l2_dev);
unsigned sd_nr = cobalt_get_sd_nr(sd);
struct cobalt_stream *s = cobalt-streams[sd_nr];
-   bool hotplug = arg ? *((int *)arg) : false;
 
-   if (s-is_output)
+   switch (notification) {
+   case V4L2_SUBDEV_CEC_TX_DONE:
+   cec_transmit_done(s-cec_adap, (unsigned long)arg);
+   return;
+   case V4L2_SUBDEV_CEC_RX_MSG:
+   cec_received_msg(s-cec_adap, arg);
+   return;
+   case V4L2_SUBDEV_CEC_CONN_INPUTS:
+   cec_connected_inputs(s-cec_adap, *(u16 *)arg);
+   return;
+   default:
+   break;
+   }
+
+   if (s-is_output) {
+   switch (notification) {
+   case ADV7511_EDID_DETECT: {
+   struct adv7511_edid_detect *ed = arg;
+
+   s-cec_adap.phys_addr = ed-phys_addr;
+   if (!ed-present) {
+   cec_enable(s-cec_adap, false);
+   break;
+   }
+   cec_enable(s-cec_adap, true);
+   break;
+   }
+   case ADV7511_MONITOR_DETECT: {
+   struct adv7511_monitor_detect *md = arg;
+
+   if (!md-present) {
+   cec_enable(s-cec_adap, false);
+   break;
+   }
+   break;
+   }
+   }
return;
+   }
 
switch (notification) {
-   case ADV76XX_HOTPLUG:
+   case ADV76XX_HOTPLUG: {
+   bool hotplug = arg ? *((int *)arg) : false;
+
cobalt_s_bit_sysctrl(cobalt,
COBALT_SYS_CTRL_HPD_TO_CONNECTOR_BIT(sd_nr), hotplug);
+   cec_connected_inputs(s-cec_adap, hotplug);
cobalt_dbg(1, Set hotplug for adv %d to %d\n, sd_nr, hotplug);
break;
+   }
case V4L2_DEVICE_NOTIFY_EVENT:
cobalt_dbg(1, Format changed for adv %d\n, sd_nr);
v4l2_event_queue(s-vdev, arg);
@@ -627,8 +668,9 @@ static int cobalt_subdevs_hsma_init(struct cobalt *cobalt)
s-sd = v4l2_i2c_new_subdev_board(cobalt-v4l2_dev,
s-i2c_adap, adv7842_info, NULL);
if (s-sd) {
-   int err = v4l2_subdev_call(s-sd, pad, set_edid, cobalt_edid);
+   int err;
 
+   err = v4l2_subdev_call(s-sd, pad, set_edid, cobalt_edid);
if (err)
return err;
err = v4l2_subdev_call(s-sd, pad, set_fmt, NULL,
diff --git a/drivers/media/pci/cobalt/cobalt-driver.h 
b/drivers/media/pci/cobalt/cobalt-driver.h
index c206df9..151c80f 100644
--- a/drivers/media/pci/cobalt/cobalt-driver.h
+++ b/drivers/media/pci/cobalt/cobalt-driver.h
@@ -31,6 +31,7 @@
 #include linux/workqueue.h
 #include linux/mutex.h
 
+#include media/cec.h
 #include media/v4l2-common.h
 #include media/v4l2-ioctl.h
 #include media/v4l2-device.h
@@ -221,6 +222,7 @@ struct cobalt_stream {
struct list_head bufs;
struct i2c_adapter *i2c_adap;
struct v4l2_subdev *sd;
+   struct cec_adapter cec_adap;
struct mutex lock;
spinlock_t irqlock;
struct v4l2_dv_timings timings;
diff --git a/drivers/media/pci/cobalt/cobalt-irq.c 
b/drivers/media/pci/cobalt/cobalt-irq.c
index dd4bff9..0963d96 100644
--- a/drivers/media/pci/cobalt/cobalt-irq.c
+++ b/drivers/media/pci/cobalt/cobalt-irq.c
@@ -233,6 +233,9 @@ void cobalt_irq_log_status(struct cobalt *cobalt)
u32 mask;
int i;
 
+   cobalt_info(irq: edge=%08x mask=%08x\n,
+   cobalt_read_bar1(cobalt, COBALT_SYS_STAT_EDGE),
+   cobalt_read_bar1(cobalt, COBALT_SYS_STAT_MASK));
cobalt_info(irq: adv1=%u adv2

[PATCHv8 06/15] rc: Add HDMI CEC protocol handling

2015-08-18 Thread Hans Verkuil
From: Kamil Debski ka...@wypas.org

Add handling of remote control events coming from the HDMI CEC bus.
This patch includes a new keymap that maps values found in the CEC
messages to the keys pressed and released. Also, a new protocol has
been added to the core.

Signed-off-by: Kamil Debski ka...@wypas.org
Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/rc/keymaps/Makefile |   1 +
 drivers/media/rc/keymaps/rc-cec.c | 174 ++
 drivers/media/rc/rc-main.c|   1 +
 include/media/rc-core.h   |   1 +
 include/media/rc-map.h|   5 +-
 5 files changed, 181 insertions(+), 1 deletion(-)
 create mode 100644 drivers/media/rc/keymaps/rc-cec.c

diff --git a/drivers/media/rc/keymaps/Makefile 
b/drivers/media/rc/keymaps/Makefile
index fbbd3bb..9cffcc6 100644
--- a/drivers/media/rc/keymaps/Makefile
+++ b/drivers/media/rc/keymaps/Makefile
@@ -18,6 +18,7 @@ obj-$(CONFIG_RC_MAP) += rc-adstech-dvb-t-pci.o \
rc-behold.o \
rc-behold-columbus.o \
rc-budget-ci-old.o \
+   rc-cec.o \
rc-cinergy-1400.o \
rc-cinergy.o \
rc-delock-61959.o \
diff --git a/drivers/media/rc/keymaps/rc-cec.c 
b/drivers/media/rc/keymaps/rc-cec.c
new file mode 100644
index 000..193cdca
--- /dev/null
+++ b/drivers/media/rc/keymaps/rc-cec.c
@@ -0,0 +1,174 @@
+/* Keytable for the CEC remote control
+ *
+ * Copyright (c) 2015 by Kamil Debski
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include media/rc-map.h
+#include linux/module.h
+
+/* CEC Spec High-Definition Multimedia Interface Specification can be 
obtained
+ * here: http://xtreamerdev.googlecode.com/files/CEC_Specs.pdf
+ * The list of control codes is listed in Table 27: User Control Codes p. 95 */
+
+static struct rc_map_table cec[] = {
+   { 0x00, KEY_OK },
+   { 0x01, KEY_UP },
+   { 0x02, KEY_DOWN },
+   { 0x03, KEY_LEFT },
+   { 0x04, KEY_RIGHT },
+   { 0x05, KEY_RIGHT_UP },
+   { 0x06, KEY_RIGHT_DOWN },
+   { 0x07, KEY_LEFT_UP },
+   { 0x08, KEY_LEFT_DOWN },
+   { 0x09, KEY_ROOT_MENU }, /* CEC Spec: Device Root Menu - see Note 2 */
+   /* Note 2: This is the initial display that a device shows. It is
+* device-dependent and can be, for example, a contents menu, setup
+* menu, favorite menu or other menu. The actual menu displayed
+* may also depend on the device's current state. */
+   { 0x0a, KEY_SETUP },
+   { 0x0b, KEY_MENU }, /* CEC Spec: Contents Menu */
+   { 0x0c, KEY_FAVORITES }, /* CEC Spec: Favorite Menu */
+   { 0x0d, KEY_EXIT },
+   /* 0x0e-0x0f: Reserved */
+   { 0x10, KEY_MEDIA_TOP_MENU },
+   { 0x11, KEY_CONTEXT_MENU },
+   /* 0x12-0x1c: Reserved */
+   { 0x1d, KEY_DIGITS }, /* CEC Spec: select/toggle a Number Entry Mode */
+   { 0x1e, KEY_NUMERIC_11 },
+   { 0x1f, KEY_NUMERIC_12 },
+   /* 0x20-0x29: Keys 0 to 9 */
+   { 0x20, KEY_NUMERIC_0 },
+   { 0x21, KEY_NUMERIC_1 },
+   { 0x22, KEY_NUMERIC_2 },
+   { 0x23, KEY_NUMERIC_3 },
+   { 0x24, KEY_NUMERIC_4 },
+   { 0x25, KEY_NUMERIC_5 },
+   { 0x26, KEY_NUMERIC_6 },
+   { 0x27, KEY_NUMERIC_7 },
+   { 0x28, KEY_NUMERIC_8 },
+   { 0x29, KEY_NUMERIC_9 },
+   { 0x2a, KEY_DOT },
+   { 0x2b, KEY_ENTER },
+   { 0x2c, KEY_CLEAR },
+   /* 0x2d-0x2e: Reserved */
+   { 0x2f, KEY_NEXT_FAVORITE }, /* CEC Spec: Next Favorite */
+   { 0x30, KEY_CHANNELUP },
+   { 0x31, KEY_CHANNELDOWN },
+   { 0x32, KEY_PREVIOUS }, /* CEC Spec: Previous Channel */
+   { 0x33, KEY_SOUND }, /* CEC Spec: Sound Select */
+   { 0x34, KEY_VIDEO }, /* 0x34: CEC Spec: Input Select */
+   { 0x35, KEY_INFO }, /* CEC Spec: Display Information */
+   { 0x36, KEY_HELP },
+   { 0x37, KEY_PAGEUP },
+   { 0x38, KEY_PAGEDOWN },
+   /* 0x39-0x3f: Reserved */
+   { 0x40, KEY_POWER },
+   { 0x41, KEY_VOLUMEUP },
+   { 0x42, KEY_VOLUMEDOWN },
+   { 0x43, KEY_MUTE },
+   { 0x44, KEY_PLAYCD },
+   { 0x45, KEY_STOPCD },
+   { 0x46, KEY_PAUSECD },
+   { 0x47, KEY_RECORD },
+   { 0x48, KEY_REWIND },
+   { 0x49, KEY_FASTFORWARD },
+   { 0x4a, KEY_EJECTCD }, /* CEC Spec: Eject */
+   { 0x4b, KEY_FORWARD },
+   { 0x4c, KEY_BACK },
+   { 0x4d, KEY_STOP_RECORD }, /* CEC Spec: Stop-Record */
+   { 0x4e, KEY_PAUSE_RECORD }, /* CEC Spec: Pause-Record */
+   /* 0x4f: Reserved */
+   { 0x50, KEY_ANGLE },
+   { 0x51, KEY_TV2 },
+   { 0x52, KEY_VOD }, /* CEC Spec: Video on Demand */
+   { 0x53, KEY_EPG },
+   { 0x54, KEY_TIME }, /* CEC Spec

[PATCHv2 0/4] cec-ctl/compliance: new CEC utilities

2015-08-18 Thread Hans Verkuil
This patch series adds two new utilities to the v4l-utils git repository
(http://git.linuxtv.org/cgit.cgi/v4l-utils.git/). It assumes that the new
CEC framework available in the kernel:

http://www.mail-archive.com/linux-media@vger.kernel.org/msg90085.html

The first patch adds the new cec headers to the 'sync-with-kernel' target,
the second syncs with the kernel and adds the new cec headers to v4l-utils,
the third adds the compliance utility and the last adds the cec-ctl utility.

The cec-compliance utility is by no means 100% coverage, in particular the
event API and non-blocking ioctls are untested. But it is a starting point,
and a complex protocol like CEC really needs a compliance tool.

The cec-ctl utility has almost full CEC message coverage: all generated from
the cec headers, so this is easy to keep up to date.

Regards,

Hans

Changes since v1:

- Added CEC message logging/monitoring to cec-ctl.
- Add support to clear the logical addresses.

Hans Verkuil (4):
  Makefile.am: copy cec headers with make sync-with-kernel
  sync-with-kernel
  cec-compliance: add new CEC compliance utility
  cec-ctl: CEC control utility

 Makefile.am   |4 +
 configure.ac  |2 +
 contrib/freebsd/include/linux/input.h |   29 +
 contrib/freebsd/include/linux/v4l2-controls.h |4 +
 include/linux/cec-funcs.h | 1771 +
 include/linux/cec.h   |  781 +++
 include/linux/v4l2-controls.h |4 +
 utils/Makefile.am |2 +
 utils/cec-compliance/Makefile.am  |3 +
 utils/cec-compliance/cec-compliance.cpp   |  926 +
 utils/cec-compliance/cec-compliance.h |   87 ++
 utils/cec-ctl/Makefile.am |8 +
 utils/cec-ctl/cec-ctl.cpp | 1296 ++
 utils/cec-ctl/msg2ctl.pl  |  430 ++
 utils/keytable/parse.h|   18 +
 utils/keytable/rc_keymaps/lme2510 |  132 +-
 utils/keytable/rc_maps.cfg|1 +
 17 files changed, 5432 insertions(+), 66 deletions(-)
 create mode 100644 include/linux/cec-funcs.h
 create mode 100644 include/linux/cec.h
 create mode 100644 utils/cec-compliance/Makefile.am
 create mode 100644 utils/cec-compliance/cec-compliance.cpp
 create mode 100644 utils/cec-compliance/cec-compliance.h
 create mode 100644 utils/cec-ctl/Makefile.am
 create mode 100644 utils/cec-ctl/cec-ctl.cpp
 create mode 100644 utils/cec-ctl/msg2ctl.pl

-- 
2.1.4

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


Re: [PATCHv2 0/4] cec-ctl/compliance: new CEC utilities

2015-08-18 Thread Hans Verkuil
Oops, this cover letter is incomplete, here is the full cover letter:

This patch series adds two new utilities to the v4l-utils git repository
(http://git.linuxtv.org/cgit.cgi/v4l-utils.git/). It assumes that the new
CEC framework (v8) is available in the kernel:

http://www.mail-archive.com/linux-media@vger.kernel.org/msg91285.html

The first patch adds the new cec headers to the 'sync-with-kernel' target,
the second syncs with the kernel and adds the new cec headers to v4l-utils,
the third adds the compliance utility and the last adds the cec-ctl utility.

The cec-compliance utility is by no means 100% coverage, in particular the
event API and non-blocking ioctls are untested. But it is a starting point,
and a complex protocol like CEC really needs a compliance tool.

The cec-ctl utility has almost full CEC message coverage: all generated from
the cec headers, so this is easy to keep up to date.

Regards,

Hans

Changes since v1:

- cec-ctl: added CEC message logging/monitoring.
- cec-ctl: add support to clear the logical addresses.
- cec-ctl: log events.



On 08/18/15 10:36, Hans Verkuil wrote:
 Hans Verkuil (4):
   Makefile.am: copy cec headers with make sync-with-kernel
   sync-with-kernel
   cec-compliance: add new CEC compliance utility
   cec-ctl: CEC control utility
 
  Makefile.am   |4 +
  configure.ac  |2 +
  contrib/freebsd/include/linux/input.h |   29 +
  contrib/freebsd/include/linux/v4l2-controls.h |4 +
  include/linux/cec-funcs.h | 1771 
 +
  include/linux/cec.h   |  781 +++
  include/linux/v4l2-controls.h |4 +
  utils/Makefile.am |2 +
  utils/cec-compliance/Makefile.am  |3 +
  utils/cec-compliance/cec-compliance.cpp   |  926 +
  utils/cec-compliance/cec-compliance.h |   87 ++
  utils/cec-ctl/Makefile.am |8 +
  utils/cec-ctl/cec-ctl.cpp | 1296 ++
  utils/cec-ctl/msg2ctl.pl  |  430 ++
  utils/keytable/parse.h|   18 +
  utils/keytable/rc_keymaps/lme2510 |  132 +-
  utils/keytable/rc_maps.cfg|1 +
  17 files changed, 5432 insertions(+), 66 deletions(-)
  create mode 100644 include/linux/cec-funcs.h
  create mode 100644 include/linux/cec.h
  create mode 100644 utils/cec-compliance/Makefile.am
  create mode 100644 utils/cec-compliance/cec-compliance.cpp
  create mode 100644 utils/cec-compliance/cec-compliance.h
  create mode 100644 utils/cec-ctl/Makefile.am
  create mode 100644 utils/cec-ctl/cec-ctl.cpp
  create mode 100644 utils/cec-ctl/msg2ctl.pl
 
--
To unsubscribe from this list: send the line unsubscribe linux-samsung-soc 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 1/6] media: get rid of unused extra_links param on media_entity_init()

2015-08-14 Thread Hans Verkuil
On 08/14/2015 04:56 PM, Mauro Carvalho Chehab wrote:
 Currently, media_entity_init() creates an array with the links,
 allocated at init time. It provides a parameter (extra_links)
 that would allocate more links than the current needs, but this
 is not used by any driver.
 
 As we want to be able to do dynamic link allocation/removal,
 we'll need to change the implementation of the links. So,
 before doing that, let's first remove that extra unused
 parameter, in order to cleanup the interface first.
 
 Signed-off-by: Mauro Carvalho Chehab mche...@osg.samsung.com
 Acked-by: Sakari Ailus sakari.ai...@linux.intel.com

Acked-by: Hans Verkuil hans.verk...@cisco.com

Thanks!

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


Re: [PATCH RFC v3 10/16] media: rename link source/sink to pad0_source/pad1_sink

2015-08-13 Thread Hans Verkuil
On 08/12/15 22:14, Mauro Carvalho Chehab wrote:
 Change the internal namespace for links between two pads to
 have the pad there.
 
 We're also numbering it, as a common constructor is to do
 things like:
 
   if (link-port1.type != MEDIA_GRAPH_PAD)
   continue;
   if (link-pad1_sink-entity == entity)
   /* do something */
 
 by preserving the number, we keep consistency between
 port1 and pad1_sink, and port0 and pad0_source.

I would really leave this patch out. As long as sink and source are consistently
used for pads (and they are), then I see no benefit at all to this change.

Another reason why I don't like this is that pad0_ and pad1_ are actually
confusing since they suggested to me when I first read it that pad0_ referred to
the pad with index 0 and pad1_ referred to the pad with index 1.

That's obviously not the case, but it does mean that the prefix doesn't really
make things clearer.

I would just stick with source and sink.

Regards,

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


Re: [PATCH RFC v2 09/16] media: use media_graph_obj for link endpoints

2015-08-11 Thread Hans Verkuil
Hi Mauro,

Thanks for posting the missing patches.

On 08/11/15 14:09, Mauro Carvalho Chehab wrote:
 As we'll need to create links between entities and interfaces,
 we need to identify the link endpoints by the media_graph_obj.
 
 Most of the changes here was done by this small script:
 
 for i in `find drivers/media -type f` `find drivers/staging/media -type f`; do
   perl -ne 
 's,([\w]+)\-\(source|sink)\-\entity,gobj_to_pad($1-$2)-entity,; print 
 $_;' $i a  mv a $i
 done
 
 Please note that, while we're now using graph_obj to reference
 the link endpoints, we're still assuming that all endpoints are
 pads. This is true for all existing links, so no problems
 are expected so far.
 
 Yet, as we introduce links between entities and interfaces,
 we may need to change some existing code to work with links
 that aren't pad to pad.
 
 Signed-off-by: Mauro Carvalho Chehab mche...@osg.samsung.com
 

snip

 diff --git a/include/media/media-entity.h b/include/media/media-entity.h
 index 403019035424..f6e2136480f1 100644
 --- a/include/media/media-entity.h
 +++ b/include/media/media-entity.h
 @@ -43,6 +43,17 @@ enum media_graph_type {
   MEDIA_GRAPH_LINK,
  };
  
 +/**
 + * enum media_graph_link_dir - direction of a link
 + *
 + * @MEDIA_LINK_DIR_BIDIRECTIONAL Link is bidirectional
 + * @MEDIA_LINK_DIR_PAD_0_TO_1Link is unidirectional,
 + *   from port 0 (source) to port 1 (sink)
 + */
 +enum media_graph_link_dir {
 + MEDIA_LINK_DIR_BIDIRECTIONAL,
 + MEDIA_LINK_DIR_PORT0_TO_PORT1,
 +};

1) the comment and the actual enum are out-of-sync
2) why not just make a 'BIRECTIONAL' link flag instead of inventing
   a new enum? Adding yet another field seems overkill to me. Have a
   'BIDIRECTIONAL' flag seems perfectly OK to me (and useful for the
   application as well).

  
  /* Structs to represent the objects that belong to a media graph */
  
 @@ -72,9 +83,9 @@ struct media_pipeline {
  
  struct media_link {
   struct list_head list;
 - struct media_graph_obj  graph_obj;
 - struct media_pad *source;   /* Source pad */
 - struct media_pad *sink; /* Sink pad  */
 + struct media_graph_obj  graph_obj;
 + enum media_graph_link_dir   dir;
 + struct media_graph_obj  *source, *sink;

I'm not too keen about all the gobj_to_foo(obj) macros that this requires. It
is rather ugly code.

What about this:

union {
struct media_graph_obj *source;
struct media_pad *source_pad;
struct media_interface *source_intf;
};
union {
struct media_graph_obj *sink;
struct media_pad *sink_pad;
struct media_entity *sink_ent;
};

Now the code can just use -source_pad etc.

   struct media_link *reverse; /* Link in the reverse direction */
   unsigned long flags;/* Link flags (MEDIA_LNK_FL_*) */
  };
 @@ -115,6 +126,11 @@ struct media_entity {
   u32 group_id;   /* Entity group ID */
  
   u16 num_pads;   /* Number of sink and source pads */
 +
 + /*
 +  * Both num_links and num_backlinks are used only to report
 +  * the number of links via MEDIA_IOC_ENUM_ENTITIES at media_device.c
 +  */
   u16 num_links;  /* Number of existing links, both
* enabled and disabled */
   u16 num_backlinks;  /* Number of backlinks */
 @@ -171,6 +187,12 @@ struct media_entity_graph {
  #define gobj_to_entity(gobj) \
   container_of(gobj, struct media_entity, graph_obj)
  
 +#define gobj_to_link(gobj) \
 + container_of(gobj, struct media_link, graph_obj)
 +
 +#define gobj_to_pad(gobj) \
 + container_of(gobj, struct media_pad, graph_obj)
 +

I saw a lot of type checks (if (link-sink.type != MEDIA_GRAPH_PAD))
that I think would look cleaner if there was a simple static inline
helper:

static inline bool is_pad(const struct media_graph_obj *obj)
{
return obj-type == MEDIA_GRAPH_PAD;
}

media_is_pad() will work as well, but I think brevity is more useful
in this case. Personal opinion, though.

  void graph_obj_init(struct media_device *mdev,
   enum media_graph_type type,
   struct media_graph_obj *gobj);
 

Regards,

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


Re: [PATCH RFC v2 09/16] media: use media_graph_obj for link endpoints

2015-08-11 Thread Hans Verkuil
 diff --git a/include/media/media-entity.h b/include/media/media-entity.h
 index 403019035424..f6e2136480f1 100644
 --- a/include/media/media-entity.h
 +++ b/include/media/media-entity.h
 @@ -43,6 +43,17 @@ enum media_graph_type {
 MEDIA_GRAPH_LINK,
  };
  
 +/**
 + * enum media_graph_link_dir - direction of a link
 + *
 + * @MEDIA_LINK_DIR_BIDIRECTIONAL   Link is bidirectional
 + * @MEDIA_LINK_DIR_PAD_0_TO_1  Link is unidirectional,
 + * from port 0 (source) to port 1 (sink)
 + */
 +enum media_graph_link_dir {
 +   MEDIA_LINK_DIR_BIDIRECTIONAL,
 +   MEDIA_LINK_DIR_PORT0_TO_PORT1,
 +};

 1) the comment and the actual enum are out-of-sync
 
 Ah, yes. I was in doubt about using PAD or PORT here. I ended by using
 port at the links, as the endpoints can either be an interface/entity
 or a pad. So, I decided to use port.

It's either bi-directional (between interface and entity) or directional
(between two pads), so I think PAD is better here. We don't use the term
port anywhere else in the MC, so I think it is a bit confusing to
introduce a new name here.

 
 2) why not just make a 'BIRECTIONAL' link flag instead of inventing
a new enum? Adding yet another field seems overkill to me. Have a
'BIDIRECTIONAL' flag seems perfectly OK to me (and useful for the
application as well).
 
 Yeah, we can use flags, instead. I decided to use an enum here just
 to make it clearer about the two possible options.
 
 I was actually considering to rename media_link source/sink to
 port0/port1, as using source/sink names on a bidirection link
 doesn't make sense. I'm still in doubt about such rename, though,
 as it would make harder to inspect the graph traversal routines.

Right. I really wouldn't rename it. As suggested below using an
anonymous union would allow you to create proper names.

 Also, I want to force all places that create a link to choose
 between either BIRECTIONAL or PORT0_TO_PORT1, as this makes easier
 to review if the code is doing the right thing when inspecting it.

By creating two different functions? I think that would be very useful.
E.g. make_pad_link() and make_intf_to_ent_link() or something like
that. That would also hide the link direction. I still prefer a flag,
though :-) That's mostly personal preference, though.

 
 In summary, I would prefer to keep this internally as a separate
  enum, at least for now. We can latter simplify it and use a flag
 for that (or maybe two flags?).
 

  
  /* Structs to represent the objects that belong to a media graph */
  
 @@ -72,9 +83,9 @@ struct media_pipeline {
  
  struct media_link {
 struct list_head list;
 -   struct media_graph_obj  graph_obj;
 -   struct media_pad *source;   /* Source pad */
 -   struct media_pad *sink; /* Sink pad  */
 +   struct media_graph_obj  graph_obj;
 +   enum media_graph_link_dir   dir;
 +   struct media_graph_obj  *source, *sink;

 I'm not too keen about all the gobj_to_foo(obj) macros that this requires. It
 is rather ugly code.

 What about this:

  union {
  struct media_graph_obj *source;
  struct media_pad *source_pad;
  struct media_interface *source_intf;
  };
  union {
  struct media_graph_obj *sink;
  struct media_pad *sink_pad;
  struct media_entity *sink_ent;
  };

 Now the code can just use -source_pad etc.
 
 good idea. Will do that on a version 3. I think that, in this case, the
 best is to write a note that the first element at pad/entity/interface
 should be the graph_obj.
 
 I would actually call port0_intf and port1_ent on the above structs,
 as it makes no sense to call sink/source for interface-entity links.

How about this:

union {
struct media_graph_obj *port0;
struct media_interface *port0_intf; // perhaps just intf or 
interface?
struct media_pad *source;
};
union {
struct media_graph_obj *port1;
struct media_entity *port1_ent; // perhaps just ent or entity?
struct media_pad *sink;
};

This has the advantage that the source/sink pads are still called source and
sink and you don't have to rename the existing code.

Regards,

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


Re: [PATCHv7 14/15] cec: s5p-cec: Add s5p-cec driver

2015-07-23 Thread Hans Verkuil

On 07/23/2015 06:39 PM, Kamil Debski wrote:

Hi,

On 21 July 2015 at 15:03, Marek Szyprowski m.szyprow...@samsung.com wrote:

Hello,

On 2015-07-16 15:09, Hans Verkuil wrote:


Marek, Kamil,

On 06/29/15 12:14, Hans Verkuil wrote:


From: Kamil Debski ka...@wypas.org

Add CEC interface driver present in the Samsung Exynos range of
SoCs.

The following files were based on work by SangPil Moon:
- exynos_hdmi_cec.h
- exynos_hdmi_cecctl.c

Signed-off-by: Kamil Debski ka...@wypas.org
Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---


snip


diff --git a/drivers/media/platform/s5p-cec/s5p_cec.c
b/drivers/media/platform/s5p-cec/s5p_cec.c
new file mode 100644
index 000..0f16d00
--- /dev/null
+++ b/drivers/media/platform/s5p-cec/s5p_cec.c
@@ -0,0 +1,283 @@
+/* drivers/media/platform/s5p-cec/s5p_cec.c
+ *
+ * Samsung S5P CEC driver
+ *
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This driver is based on the cec interface driver for exynos soc by
+ * SangPil Moon.
+ */
+
+#include linux/clk.h
+#include linux/interrupt.h
+#include linux/kernel.h
+#include linux/mfd/syscon.h
+#include linux/module.h
+#include linux/of.h
+#include linux/platform_device.h
+#include linux/pm_runtime.h
+#include linux/timer.h
+#include linux/version.h
+#include linux/workqueue.h
+#include media/cec.h
+
+#include exynos_hdmi_cec.h
+#include regs-cec.h
+#include s5p_cec.h
+
+#define CEC_NAME   s5p-cec
+
+static int debug;
+module_param(debug, int, 0644);
+MODULE_PARM_DESC(debug, debug level (0-2));
+
+static int s5p_cec_enable(struct cec_adapter *adap, bool enable)
+{
+   struct s5p_cec_dev *cec = container_of(adap, struct s5p_cec_dev,
adap);
+   int ret;
+
+   if (enable) {
+   ret = pm_runtime_get_sync(cec-dev);
+
+   adap-phys_addr = 0x100b;


This is a bogus physical address. The actual physical address has to be
derived
from the EDID that is read by the HDMI transmitter.

I think in the case of this driver it will have to be userspace that
assigns
the physical address after reading the EDID from drm/kms?

How did you test this, Kamil?



If I remember correctly, physical address has been derived from EDID in the
userspace (it is available in /sys/class/drm/*) and passed to s5p-cec driver
by
appropriate ioctl.

I don't know what is the reason for the above 'adap-phys_addr = 0x100b'
assignment.


At some point there was an idea to read the address from the EDID in
kernel. This static address was a hack until the code that reads the
EDID is written. As you say, it is much better to leave the address to
be set by the userspace. So this assignment serves no purpose anymore.


Thank you, that's what I thought. It's fixed in my current tree. Still
working on the CEC framework: I'm chasing race conditions and I suspect
that there may be a bug in the adv7604 or adv7511 CEC implementation.

Once I've sorted that I post a new version which has been tested a lot
more thoroughly and should be complete except for the documentation.

Regards,

Hans

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


Re: [PATCH 0/9 v7] Helper to abstract vma handling in media layer

2015-07-17 Thread Hans Verkuil
Hi Jan,

On 07/13/2015 04:55 PM, Jan Kara wrote:
 From: Jan Kara j...@suse.cz
 
   Hello,
 
 I'm sending the seventh version of my patch series to abstract vma handling
 from the various media drivers. Since the previous version there are just
 minor cleanups and fixes (see detailed changelog at the end of the email).
 
 After this patch set drivers have to know much less details about vmas, their
 types, and locking. Also quite some code is removed from them. As a bonus
 drivers get automatically VM_FAULT_RETRY handling. The primary motivation for
 this series is to remove knowledge about mmap_sem locking from as many places 
 a
 possible so that we can change it with reasonable effort.
 
 The core of the series is the new helper get_vaddr_frames() which is given a
 virtual address and it fills in PFNs / struct page pointers (depending on VMA
 type) into the provided array. If PFNs correspond to normal pages it also 
 grabs
 references to these pages. The difference from get_user_pages() is that this
 function can also deal with pfnmap, and io mappings which is what the media
 drivers need.
 
 I have tested the patches with vivid driver so at least vb2 code got some
 exposure. Conversion of other drivers was just compile-tested (for x86 so e.g.
 exynos driver which is only for Samsung platform is completely untested).
 
 Hans, can you please pull the changes? Thanks!

I've done some testing myself and it all looks fine to me. All I need is an
additional Ack for the mm patch from Andrew or other mm maintainers.

Regards,

Hans

 
   Honza
 
 Changes since v6:
 * Fixed compilation error introduced into exynos driver
 * Folded patch allowing get_vaddr_pfn() code to be selected by a config option
   into previous patches
 * Rebased on top of linux-media tree
 
 Changes since v5:
 * Moved mm helper into a separate file and behind a config option
 * Changed the first patch pushing mmap_sem down in videobuf2 core to avoid
   possible deadlock
 
 Changes since v4:
 * Minor cleanups and fixes pointed out by Mel and Vlasta
 * Added Acked-by tags
 
 Changes since v3:
 * Added include linux/vmalloc.h into mm/gup.c as it's needed for some archs
 * Fixed error path for exynos driver
 
 Changes since v2:
 * Renamed functions and structures as Mel suggested
 * Other minor changes suggested by Mel
 * Rebased on top of 4.1-rc2
 * Changed functions to get pointer to array of pages / pfns to perform
   conversion if necessary. This fixes possible issue in the omap I may have
   introduced in v2 and generally makes the API less errorprone.
 --
 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
 

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


Re: [PATCH 2/9] mm: Provide new get_vaddr_frames() helper

2015-07-17 Thread Hans Verkuil
On 07/13/2015 04:55 PM, Jan Kara wrote:
 From: Jan Kara j...@suse.cz
 
 Provide new function get_vaddr_frames().  This function maps virtual
 addresses from given start and fills given array with page frame numbers of
 the corresponding pages. If given start belongs to a normal vma, the function
 grabs reference to each of the pages to pin them in memory. If start
 belongs to VM_IO | VM_PFNMAP vma, we don't touch page structures. Caller
 must make sure pfns aren't reused for anything else while he is using
 them.
 
 This function is created for various drivers to simplify handling of
 their buffers.
 
 Acked-by: Mel Gorman mgor...@suse.de
 Acked-by: Vlastimil Babka vba...@suse.cz
 Signed-off-by: Jan Kara j...@suse.cz

I'd like to see an Acked-by from Andrew or mm-maintainers before I merge this.

Anyone?

Regards,

Hans

 ---
  include/linux/mm.h |  44 ++
  mm/Kconfig |   3 +
  mm/Makefile|   1 +
  mm/frame_vector.c  | 231 
 +
  4 files changed, 279 insertions(+)
  create mode 100644 mm/frame_vector.c
 
 diff --git a/include/linux/mm.h b/include/linux/mm.h
 index 2e872f92dbac..79ad29a8a60a 100644
 --- a/include/linux/mm.h
 +++ b/include/linux/mm.h
 @@ -20,6 +20,7 @@
  #include linux/shrinker.h
  #include linux/resource.h
  #include linux/page_ext.h
 +#include linux/err.h
  
  struct mempolicy;
  struct anon_vma;
 @@ -1198,6 +1199,49 @@ long get_user_pages_unlocked(struct task_struct *tsk, 
 struct mm_struct *mm,
   int write, int force, struct page **pages);
  int get_user_pages_fast(unsigned long start, int nr_pages, int write,
   struct page **pages);
 +
 +/* Container for pinned pfns / pages */
 +struct frame_vector {
 + unsigned int nr_allocated;  /* Number of frames we have space for */
 + unsigned int nr_frames; /* Number of frames stored in ptrs array */
 + bool got_ref;   /* Did we pin pages by getting page ref? */
 + bool is_pfns;   /* Does array contain pages or pfns? */
 + void *ptrs[0];  /* Array of pinned pfns / pages. Use
 +  * pfns_vector_pages() or pfns_vector_pfns()
 +  * for access */
 +};
 +
 +struct frame_vector *frame_vector_create(unsigned int nr_frames);
 +void frame_vector_destroy(struct frame_vector *vec);
 +int get_vaddr_frames(unsigned long start, unsigned int nr_pfns,
 +  bool write, bool force, struct frame_vector *vec);
 +void put_vaddr_frames(struct frame_vector *vec);
 +int frame_vector_to_pages(struct frame_vector *vec);
 +void frame_vector_to_pfns(struct frame_vector *vec);
 +
 +static inline unsigned int frame_vector_count(struct frame_vector *vec)
 +{
 + return vec-nr_frames;
 +}
 +
 +static inline struct page **frame_vector_pages(struct frame_vector *vec)
 +{
 + if (vec-is_pfns) {
 + int err = frame_vector_to_pages(vec);
 +
 + if (err)
 + return ERR_PTR(err);
 + }
 + return (struct page **)(vec-ptrs);
 +}
 +
 +static inline unsigned long *frame_vector_pfns(struct frame_vector *vec)
 +{
 + if (!vec-is_pfns)
 + frame_vector_to_pfns(vec);
 + return (unsigned long *)(vec-ptrs);
 +}
 +
  struct kvec;
  int get_kernel_pages(const struct kvec *iov, int nr_pages, int write,
   struct page **pages);
 diff --git a/mm/Kconfig b/mm/Kconfig
 index e79de2bd12cd..7f146dd32fc5 100644
 --- a/mm/Kconfig
 +++ b/mm/Kconfig
 @@ -654,3 +654,6 @@ config DEFERRED_STRUCT_PAGE_INIT
 when kswapd starts. This has a potential performance impact on
 processes running early in the lifetime of the systemm until kswapd
 finishes the initialisation.
 +
 +config FRAME_VECTOR
 + bool
 diff --git a/mm/Makefile b/mm/Makefile
 index 98c4eaeabdcb..be5d5c866305 100644
 --- a/mm/Makefile
 +++ b/mm/Makefile
 @@ -78,3 +78,4 @@ obj-$(CONFIG_CMA)   += cma.o
  obj-$(CONFIG_MEMORY_BALLOON) += balloon_compaction.o
  obj-$(CONFIG_PAGE_EXTENSION) += page_ext.o
  obj-$(CONFIG_CMA_DEBUGFS) += cma_debug.o
 +obj-$(CONFIG_FRAME_VECTOR) += frame_vector.o
 diff --git a/mm/frame_vector.c b/mm/frame_vector.c
 new file mode 100644
 index ..f76b579e46f1
 --- /dev/null
 +++ b/mm/frame_vector.c
 @@ -0,0 +1,231 @@
 +#include linux/kernel.h
 +#include linux/errno.h
 +#include linux/err.h
 +#include linux/mm.h
 +#include linux/slab.h
 +#include linux/vmalloc.h
 +#include linux/pagemap.h
 +#include linux/sched.h
 +
 +/*
 + * get_vaddr_frames() - map virtual addresses to pfns
 + * @start:   starting user address
 + * @nr_frames:   number of pages / pfns from start to map
 + * @write:   whether pages will be written to by the caller
 + * @force:   whether to force write access even if user mapping is
 + *   readonly. See description of the same argument of
 + get_user_pages().
 + * @vec: structure which receives pages / pfns of the 

Re: [PATCH 9/9] drm/exynos: Convert g2d_userptr_get_dma_addr() to use get_vaddr_frames()

2015-07-17 Thread Hans Verkuil
On 07/13/2015 04:55 PM, Jan Kara wrote:
 From: Jan Kara j...@suse.cz
 
 Convert g2d_userptr_get_dma_addr() to pin pages using get_vaddr_frames().
 This removes the knowledge about vmas and mmap_sem locking from exynos
 driver. Also it fixes a problem that the function has been mapping user
 provided address without holding mmap_sem.

I'd like to see an Ack from one of the exynos drm driver maintainers before
I merge this.

Inki, Marek?

Regards,

Hans

 
 Signed-off-by: Jan Kara j...@suse.cz
 ---
  drivers/gpu/drm/exynos/Kconfig  |  1 +
  drivers/gpu/drm/exynos/exynos_drm_g2d.c | 91 ++-
  drivers/gpu/drm/exynos/exynos_drm_gem.c | 97 
 -
  3 files changed, 30 insertions(+), 159 deletions(-)
 
 diff --git a/drivers/gpu/drm/exynos/Kconfig b/drivers/gpu/drm/exynos/Kconfig
 index 43003c4ad80b..b364562dc6c1 100644
 --- a/drivers/gpu/drm/exynos/Kconfig
 +++ b/drivers/gpu/drm/exynos/Kconfig
 @@ -77,6 +77,7 @@ config DRM_EXYNOS_VIDI
  config DRM_EXYNOS_G2D
   bool Exynos DRM G2D
   depends on DRM_EXYNOS  !VIDEO_SAMSUNG_S5P_G2D
 + select FRAME_VECTOR
   help
 Choose this option if you want to use Exynos G2D for DRM.
  
 diff --git a/drivers/gpu/drm/exynos/exynos_drm_g2d.c 
 b/drivers/gpu/drm/exynos/exynos_drm_g2d.c
 index 81a250830808..1d8d9a508373 100644
 --- a/drivers/gpu/drm/exynos/exynos_drm_g2d.c
 +++ b/drivers/gpu/drm/exynos/exynos_drm_g2d.c
 @@ -190,10 +190,8 @@ struct g2d_cmdlist_userptr {
   dma_addr_t  dma_addr;
   unsigned long   userptr;
   unsigned long   size;
 - struct page **pages;
 - unsigned intnpages;
 + struct frame_vector *vec;
   struct sg_table *sgt;
 - struct vm_area_struct   *vma;
   atomic_trefcount;
   boolin_pool;
   boolout_of_list;
 @@ -363,6 +361,7 @@ static void g2d_userptr_put_dma_addr(struct drm_device 
 *drm_dev,
  {
   struct g2d_cmdlist_userptr *g2d_userptr =
   (struct g2d_cmdlist_userptr *)obj;
 + struct page **pages;
  
   if (!obj)
   return;
 @@ -382,19 +381,21 @@ out:
   exynos_gem_unmap_sgt_from_dma(drm_dev, g2d_userptr-sgt,
   DMA_BIDIRECTIONAL);
  
 - exynos_gem_put_pages_to_userptr(g2d_userptr-pages,
 - g2d_userptr-npages,
 - g2d_userptr-vma);
 + pages = frame_vector_pages(g2d_userptr-vec);
 + if (!IS_ERR(pages)) {
 + int i;
  
 - exynos_gem_put_vma(g2d_userptr-vma);
 + for (i = 0; i  frame_vector_count(g2d_userptr-vec); i++)
 + set_page_dirty_lock(pages[i]);
 + }
 + put_vaddr_frames(g2d_userptr-vec);
 + frame_vector_destroy(g2d_userptr-vec);
  
   if (!g2d_userptr-out_of_list)
   list_del_init(g2d_userptr-list);
  
   sg_free_table(g2d_userptr-sgt);
   kfree(g2d_userptr-sgt);
 -
 - drm_free_large(g2d_userptr-pages);
   kfree(g2d_userptr);
  }
  
 @@ -408,9 +409,7 @@ static dma_addr_t *g2d_userptr_get_dma_addr(struct 
 drm_device *drm_dev,
   struct exynos_drm_g2d_private *g2d_priv = file_priv-g2d_priv;
   struct g2d_cmdlist_userptr *g2d_userptr;
   struct g2d_data *g2d;
 - struct page **pages;
   struct sg_table *sgt;
 - struct vm_area_struct *vma;
   unsigned long start, end;
   unsigned int npages, offset;
   int ret;
 @@ -456,65 +455,38 @@ static dma_addr_t *g2d_userptr_get_dma_addr(struct 
 drm_device *drm_dev,
   return ERR_PTR(-ENOMEM);
  
   atomic_set(g2d_userptr-refcount, 1);
 + g2d_userptr-size = size;
  
   start = userptr  PAGE_MASK;
   offset = userptr  ~PAGE_MASK;
   end = PAGE_ALIGN(userptr + size);
   npages = (end - start)  PAGE_SHIFT;
 - g2d_userptr-npages = npages;
 -
 - pages = drm_calloc_large(npages, sizeof(struct page *));
 - if (!pages) {
 - DRM_ERROR(failed to allocate pages.\n);
 - ret = -ENOMEM;
 + g2d_userptr-vec = frame_vector_create(npages);
 + if (!g2d_userptr-vec)
   goto err_free;
 - }
  
 - down_read(current-mm-mmap_sem);
 - vma = find_vma(current-mm, userptr);
 - if (!vma) {
 - up_read(current-mm-mmap_sem);
 - DRM_ERROR(failed to get vm region.\n);
 + ret = get_vaddr_frames(start, npages, true, true, g2d_userptr-vec);
 + if (ret != npages) {
 + DRM_ERROR(failed to get user pages from userptr.\n);
 + if (ret  0)
 + goto err_destroy_framevec;
   ret = -EFAULT;
 - goto err_free_pages;
 + goto err_put_framevec;
   }
 -
 - if (vma-vm_end  userptr + size) {
 - up_read(current-mm-mmap_sem);
 - DRM_ERROR(vma is too small.\n);
 +  

Re: [PATCH 9/9] drm/exynos: Convert g2d_userptr_get_dma_addr() to use get_vaddr_frames()

2015-07-17 Thread Hans Verkuil
On 07/17/2015 12:29 PM, Inki Dae wrote:
 On 2015년 07월 17일 19:20, Hans Verkuil wrote:
 On 07/13/2015 04:55 PM, Jan Kara wrote:
 From: Jan Kara j...@suse.cz

 Convert g2d_userptr_get_dma_addr() to pin pages using get_vaddr_frames().
 This removes the knowledge about vmas and mmap_sem locking from exynos
 driver. Also it fixes a problem that the function has been mapping user
 provided address without holding mmap_sem.

 I'd like to see an Ack from one of the exynos drm driver maintainers before
 I merge this.

 Inki, Marek?
 
 I already gave Ack but it seems that Jan missed it while updating.
 
 Anyway,
 Acked-by: Inki Dae inki@samsung.com

Thanks!

BTW, I didn't see your earlier Ack either. Was it posted to the linux-media 
list as well?
It didn't turn up there.

Regards,

Hans

 
 Thanks,
 Inki Dae
 

 Regards,

  Hans


 Signed-off-by: Jan Kara j...@suse.cz
 ---
  drivers/gpu/drm/exynos/Kconfig  |  1 +
  drivers/gpu/drm/exynos/exynos_drm_g2d.c | 91 
 ++-
  drivers/gpu/drm/exynos/exynos_drm_gem.c | 97 
 -
  3 files changed, 30 insertions(+), 159 deletions(-)

 diff --git a/drivers/gpu/drm/exynos/Kconfig b/drivers/gpu/drm/exynos/Kconfig
 index 43003c4ad80b..b364562dc6c1 100644
 --- a/drivers/gpu/drm/exynos/Kconfig
 +++ b/drivers/gpu/drm/exynos/Kconfig
 @@ -77,6 +77,7 @@ config DRM_EXYNOS_VIDI
  config DRM_EXYNOS_G2D
 bool Exynos DRM G2D
 depends on DRM_EXYNOS  !VIDEO_SAMSUNG_S5P_G2D
 +   select FRAME_VECTOR
 help
   Choose this option if you want to use Exynos G2D for DRM.
  
 diff --git a/drivers/gpu/drm/exynos/exynos_drm_g2d.c 
 b/drivers/gpu/drm/exynos/exynos_drm_g2d.c
 index 81a250830808..1d8d9a508373 100644
 --- a/drivers/gpu/drm/exynos/exynos_drm_g2d.c
 +++ b/drivers/gpu/drm/exynos/exynos_drm_g2d.c
 @@ -190,10 +190,8 @@ struct g2d_cmdlist_userptr {
 dma_addr_t  dma_addr;
 unsigned long   userptr;
 unsigned long   size;
 -   struct page **pages;
 -   unsigned intnpages;
 +   struct frame_vector *vec;
 struct sg_table *sgt;
 -   struct vm_area_struct   *vma;
 atomic_trefcount;
 boolin_pool;
 boolout_of_list;
 @@ -363,6 +361,7 @@ static void g2d_userptr_put_dma_addr(struct drm_device 
 *drm_dev,
  {
 struct g2d_cmdlist_userptr *g2d_userptr =
 (struct g2d_cmdlist_userptr *)obj;
 +   struct page **pages;
  
 if (!obj)
 return;
 @@ -382,19 +381,21 @@ out:
 exynos_gem_unmap_sgt_from_dma(drm_dev, g2d_userptr-sgt,
 DMA_BIDIRECTIONAL);
  
 -   exynos_gem_put_pages_to_userptr(g2d_userptr-pages,
 -   g2d_userptr-npages,
 -   g2d_userptr-vma);
 +   pages = frame_vector_pages(g2d_userptr-vec);
 +   if (!IS_ERR(pages)) {
 +   int i;
  
 -   exynos_gem_put_vma(g2d_userptr-vma);
 +   for (i = 0; i  frame_vector_count(g2d_userptr-vec); i++)
 +   set_page_dirty_lock(pages[i]);
 +   }
 +   put_vaddr_frames(g2d_userptr-vec);
 +   frame_vector_destroy(g2d_userptr-vec);
  
 if (!g2d_userptr-out_of_list)
 list_del_init(g2d_userptr-list);
  
 sg_free_table(g2d_userptr-sgt);
 kfree(g2d_userptr-sgt);
 -
 -   drm_free_large(g2d_userptr-pages);
 kfree(g2d_userptr);
  }
  
 @@ -408,9 +409,7 @@ static dma_addr_t *g2d_userptr_get_dma_addr(struct 
 drm_device *drm_dev,
 struct exynos_drm_g2d_private *g2d_priv = file_priv-g2d_priv;
 struct g2d_cmdlist_userptr *g2d_userptr;
 struct g2d_data *g2d;
 -   struct page **pages;
 struct sg_table *sgt;
 -   struct vm_area_struct *vma;
 unsigned long start, end;
 unsigned int npages, offset;
 int ret;
 @@ -456,65 +455,38 @@ static dma_addr_t *g2d_userptr_get_dma_addr(struct 
 drm_device *drm_dev,
 return ERR_PTR(-ENOMEM);
  
 atomic_set(g2d_userptr-refcount, 1);
 +   g2d_userptr-size = size;
  
 start = userptr  PAGE_MASK;
 offset = userptr  ~PAGE_MASK;
 end = PAGE_ALIGN(userptr + size);
 npages = (end - start)  PAGE_SHIFT;
 -   g2d_userptr-npages = npages;
 -
 -   pages = drm_calloc_large(npages, sizeof(struct page *));
 -   if (!pages) {
 -   DRM_ERROR(failed to allocate pages.\n);
 -   ret = -ENOMEM;
 +   g2d_userptr-vec = frame_vector_create(npages);
 +   if (!g2d_userptr-vec)
 goto err_free;
 -   }
  
 -   down_read(current-mm-mmap_sem);
 -   vma = find_vma(current-mm, userptr);
 -   if (!vma) {
 -   up_read(current-mm-mmap_sem);
 -   DRM_ERROR(failed to get vm region.\n);
 +   ret = get_vaddr_frames(start, npages, true, true, g2d_userptr-vec);
 +   if (ret != npages) {
 +   DRM_ERROR(failed to get user pages from userptr.\n);
 +   if (ret  0)
 +   goto err_destroy_framevec;
 ret

Re: [PATCHv7 14/15] cec: s5p-cec: Add s5p-cec driver

2015-07-16 Thread Hans Verkuil
Marek, Kamil,



On 06/29/15 12:14, Hans Verkuil wrote:
 From: Kamil Debski ka...@wypas.org
 
 Add CEC interface driver present in the Samsung Exynos range of
 SoCs.
 
 The following files were based on work by SangPil Moon:
 - exynos_hdmi_cec.h
 - exynos_hdmi_cecctl.c
 
 Signed-off-by: Kamil Debski ka...@wypas.org
 Signed-off-by: Hans Verkuil hans.verk...@cisco.com
 ---

snip

 diff --git a/drivers/media/platform/s5p-cec/s5p_cec.c 
 b/drivers/media/platform/s5p-cec/s5p_cec.c
 new file mode 100644
 index 000..0f16d00
 --- /dev/null
 +++ b/drivers/media/platform/s5p-cec/s5p_cec.c
 @@ -0,0 +1,283 @@
 +/* drivers/media/platform/s5p-cec/s5p_cec.c
 + *
 + * Samsung S5P CEC driver
 + *
 + * Copyright (c) 2014 Samsung Electronics Co., Ltd.
 + *
 + * This program is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
 + * the Free Software Foundation; either version 2 of the License, or
 + * (at your option) any later version.
 + *
 + * This driver is based on the cec interface driver for exynos soc by
 + * SangPil Moon.
 + */
 +
 +#include linux/clk.h
 +#include linux/interrupt.h
 +#include linux/kernel.h
 +#include linux/mfd/syscon.h
 +#include linux/module.h
 +#include linux/of.h
 +#include linux/platform_device.h
 +#include linux/pm_runtime.h
 +#include linux/timer.h
 +#include linux/version.h
 +#include linux/workqueue.h
 +#include media/cec.h
 +
 +#include exynos_hdmi_cec.h
 +#include regs-cec.h
 +#include s5p_cec.h
 +
 +#define CEC_NAME s5p-cec
 +
 +static int debug;
 +module_param(debug, int, 0644);
 +MODULE_PARM_DESC(debug, debug level (0-2));
 +
 +static int s5p_cec_enable(struct cec_adapter *adap, bool enable)
 +{
 + struct s5p_cec_dev *cec = container_of(adap, struct s5p_cec_dev, adap);
 + int ret;
 +
 + if (enable) {
 + ret = pm_runtime_get_sync(cec-dev);
 +
 + adap-phys_addr = 0x100b;

This is a bogus physical address. The actual physical address has to be derived
from the EDID that is read by the HDMI transmitter.

I think in the case of this driver it will have to be userspace that assigns
the physical address after reading the EDID from drm/kms?

How did you test this, Kamil?

Regards,

Hans

 + s5p_cec_reset(cec);
 +
 + s5p_cec_set_divider(cec);
 + s5p_cec_threshold(cec);
 +
 + s5p_cec_unmask_tx_interrupts(cec);
 + s5p_cec_unmask_rx_interrupts(cec);
 + s5p_cec_enable_rx(cec);
 + } else {
 + s5p_cec_mask_tx_interrupts(cec);
 + s5p_cec_mask_rx_interrupts(cec);
 + pm_runtime_disable(cec-dev);
 + }
 +
 + return 0;
 +}
 +
 +static int s5p_cec_log_addr(struct cec_adapter *adap, u8 addr)
 +{
 + struct s5p_cec_dev *cec = container_of(adap, struct s5p_cec_dev, adap);
 +
 + s5p_cec_set_addr(cec, addr);
 + return 0;
 +}
 +
 +static int s5p_cec_transmit(struct cec_adapter *adap, struct cec_msg *msg)
 +{
 + struct s5p_cec_dev *cec = container_of(adap, struct s5p_cec_dev, adap);
 +
 + s5p_cec_copy_packet(cec, msg-msg, msg-len);
 + return 0;
 +}
 +
 +static void s5p_cec_transmit_timed_out(struct cec_adapter *adap)
 +{
 +
 +}
 +
 +static irqreturn_t s5p_cec_irq_handler(int irq, void *priv)
 +{
 + struct s5p_cec_dev *cec = priv;
 + u32 status = 0;
 +
 + status = s5p_cec_get_status(cec);
 +
 + dev_dbg(cec-dev, irq received\n);
 +
 + if (status  CEC_STATUS_TX_DONE) {
 + if (status  CEC_STATUS_TX_ERROR) {
 + dev_dbg(cec-dev, CEC_STATUS_TX_ERROR set\n);
 + cec-tx = STATE_ERROR;
 + } else {
 + dev_dbg(cec-dev, CEC_STATUS_TX_DONE\n);
 + cec-tx = STATE_DONE;
 + }
 + s5p_clr_pending_tx(cec);
 + }
 +
 + if (status  CEC_STATUS_RX_DONE) {
 + if (status  CEC_STATUS_RX_ERROR) {
 + dev_dbg(cec-dev, CEC_STATUS_RX_ERROR set\n);
 + s5p_cec_rx_reset(cec);
 + s5p_cec_enable_rx(cec);
 + } else {
 + dev_dbg(cec-dev, CEC_STATUS_RX_DONE set\n);
 + if (cec-rx != STATE_IDLE)
 + dev_dbg(cec-dev, Buffer overrun (worker did 
 not process previous message)\n);
 + cec-rx = STATE_BUSY;
 + cec-msg.len = status  24;
 + cec-msg.status = CEC_RX_STATUS_READY;
 + s5p_cec_get_rx_buf(cec, cec-msg.len,
 + cec-msg.msg);
 + cec-rx = STATE_DONE;
 + s5p_cec_enable_rx(cec);
 + }
 + /* Clear interrupt pending bit */
 + s5p_clr_pending_rx(cec);
 + }
 + return IRQ_WAKE_THREAD;
 +}
 +
 +static irqreturn_t s5p_cec_irq_handler_thread(int irq, void *priv)
 +{
 + struct s5p_cec_dev *cec = priv

Re: [PATCH 0/10 v6] Helper to abstract vma handling in media layer

2015-07-13 Thread Hans Verkuil
On 07/09/2015 02:12 PM, Hans Verkuil wrote:
 On 07/09/2015 01:48 PM, Jan Kara wrote:
   Hello,

   Hans, did you have a chance to look at these patches? I have tested them
 with the vivid driver but it would be good if you could run them through
 your standard testing procedure as well. Andrew has updated the patches in
 his tree but some ack from you would be welcome...
 
 I've planned a 'patch day' for Monday. So hopefully you'll see a pull request
 by then.

OK, I'm confused. I thought the non-vb2 patches would go in for 4.2? That didn't
happen, so I guess the plan is to merge the whole lot for 4.3 via our media
tree? If that's the case, can you post a new patch series on top of the master
branch of the media tree? I want to make sure I use the right patches. Also, if
you do make a new patch series, then it would be better if patch 10/10 is folded
into patch 2/10.

If that's not the case, then you have to let me know what I should do.

Regards,

Hans


  Honza
 On Thu 18-06-15 16:08:30, Jan Kara wrote:
   Hello,

 I'm sending the sixth version of my patch series to abstract vma handling 
 from
 the various media drivers. Since the previous version I have added a patch 
 to
 move mm helpers into a separate file and behind a config option. I also
 changed patch pushing mmap_sem down in videobuf2 core to avoid lockdep 
 warning
 and NULL dereference Hans found in his testing. I've also included small
 fixups Andrew was carrying.

 After this patch set drivers have to know much less details about vmas, 
 their
 types, and locking. Also quite some code is removed from them. As a bonus
 drivers get automatically VM_FAULT_RETRY handling. The primary motivation 
 for
 this series is to remove knowledge about mmap_sem locking from as many 
 places a
 possible so that we can change it with reasonable effort.

 The core of the series is the new helper get_vaddr_frames() which is given a
 virtual address and it fills in PFNs / struct page pointers (depending on 
 VMA
 type) into the provided array. If PFNs correspond to normal pages it also 
 grabs
 references to these pages. The difference from get_user_pages() is that this
 function can also deal with pfnmap, and io mappings which is what the media
 drivers need.

 I have tested the patches with vivid driver so at least vb2 code got some
 exposure. Conversion of other drivers was just compile-tested (for x86 so 
 e.g.
 exynos driver which is only for Samsung platform is completely untested).

 Andrew, can you please update the patches in mm three? Thanks!

 Honza

 Changes since v5:
 * Moved mm helper into a separate file and behind a config option
 * Changed the first patch pushing mmap_sem down in videobuf2 core to avoid
   possible deadlock

 Changes since v4:
 * Minor cleanups and fixes pointed out by Mel and Vlasta
 * Added Acked-by tags

 Changes since v3:
 * Added include linux/vmalloc.h into mm/gup.c as it's needed for some 
 archs
 * Fixed error path for exynos driver

 Changes since v2:
 * Renamed functions and structures as Mel suggested
 * Other minor changes suggested by Mel
 * Rebased on top of 4.1-rc2
 * Changed functions to get pointer to array of pages / pfns to perform
   conversion if necessary. This fixes possible issue in the omap I may have
   introduced in v2 and generally makes the API less errorprone.
 
 --
 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
 

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


Re: [PATCH 0/9 v7] Helper to abstract vma handling in media layer

2015-07-13 Thread Hans Verkuil
On 07/13/2015 04:55 PM, Jan Kara wrote:
 From: Jan Kara j...@suse.cz
 
   Hello,
 
 I'm sending the seventh version of my patch series to abstract vma handling
 from the various media drivers. Since the previous version there are just
 minor cleanups and fixes (see detailed changelog at the end of the email).
 
 After this patch set drivers have to know much less details about vmas, their
 types, and locking. Also quite some code is removed from them. As a bonus
 drivers get automatically VM_FAULT_RETRY handling. The primary motivation for
 this series is to remove knowledge about mmap_sem locking from as many places 
 a
 possible so that we can change it with reasonable effort.
 
 The core of the series is the new helper get_vaddr_frames() which is given a
 virtual address and it fills in PFNs / struct page pointers (depending on VMA
 type) into the provided array. If PFNs correspond to normal pages it also 
 grabs
 references to these pages. The difference from get_user_pages() is that this
 function can also deal with pfnmap, and io mappings which is what the media
 drivers need.
 
 I have tested the patches with vivid driver so at least vb2 code got some
 exposure. Conversion of other drivers was just compile-tested (for x86 so e.g.
 exynos driver which is only for Samsung platform is completely untested).
 
 Hans, can you please pull the changes? Thanks!

Scheduled for Friday or the following Monday!

Thanks,

Hans

 
   Honza
 
 Changes since v6:
 * Fixed compilation error introduced into exynos driver
 * Folded patch allowing get_vaddr_pfn() code to be selected by a config option
   into previous patches
 * Rebased on top of linux-media tree
 
 Changes since v5:
 * Moved mm helper into a separate file and behind a config option
 * Changed the first patch pushing mmap_sem down in videobuf2 core to avoid
   possible deadlock
 
 Changes since v4:
 * Minor cleanups and fixes pointed out by Mel and Vlasta
 * Added Acked-by tags
 
 Changes since v3:
 * Added include linux/vmalloc.h into mm/gup.c as it's needed for some archs
 * Fixed error path for exynos driver
 
 Changes since v2:
 * Renamed functions and structures as Mel suggested
 * Other minor changes suggested by Mel
 * Rebased on top of 4.1-rc2
 * Changed functions to get pointer to array of pages / pfns to perform
   conversion if necessary. This fixes possible issue in the omap I may have
   introduced in v2 and generally makes the API less errorprone.
 --
 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
 

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


Re: [PATCH 0/10 v6] Helper to abstract vma handling in media layer

2015-07-09 Thread Hans Verkuil
On 07/09/2015 01:48 PM, Jan Kara wrote:
   Hello,
 
   Hans, did you have a chance to look at these patches? I have tested them
 with the vivid driver but it would be good if you could run them through
 your standard testing procedure as well. Andrew has updated the patches in
 his tree but some ack from you would be welcome...

I've planned a 'patch day' for Monday. So hopefully you'll see a pull request
by then.

Regards,

Hans

 
   Honza
 On Thu 18-06-15 16:08:30, Jan Kara wrote:
   Hello,

 I'm sending the sixth version of my patch series to abstract vma handling 
 from
 the various media drivers. Since the previous version I have added a patch to
 move mm helpers into a separate file and behind a config option. I also
 changed patch pushing mmap_sem down in videobuf2 core to avoid lockdep 
 warning
 and NULL dereference Hans found in his testing. I've also included small
 fixups Andrew was carrying.

 After this patch set drivers have to know much less details about vmas, their
 types, and locking. Also quite some code is removed from them. As a bonus
 drivers get automatically VM_FAULT_RETRY handling. The primary motivation for
 this series is to remove knowledge about mmap_sem locking from as many 
 places a
 possible so that we can change it with reasonable effort.

 The core of the series is the new helper get_vaddr_frames() which is given a
 virtual address and it fills in PFNs / struct page pointers (depending on VMA
 type) into the provided array. If PFNs correspond to normal pages it also 
 grabs
 references to these pages. The difference from get_user_pages() is that this
 function can also deal with pfnmap, and io mappings which is what the media
 drivers need.

 I have tested the patches with vivid driver so at least vb2 code got some
 exposure. Conversion of other drivers was just compile-tested (for x86 so 
 e.g.
 exynos driver which is only for Samsung platform is completely untested).

 Andrew, can you please update the patches in mm three? Thanks!

  Honza

 Changes since v5:
 * Moved mm helper into a separate file and behind a config option
 * Changed the first patch pushing mmap_sem down in videobuf2 core to avoid
   possible deadlock

 Changes since v4:
 * Minor cleanups and fixes pointed out by Mel and Vlasta
 * Added Acked-by tags

 Changes since v3:
 * Added include linux/vmalloc.h into mm/gup.c as it's needed for some archs
 * Fixed error path for exynos driver

 Changes since v2:
 * Renamed functions and structures as Mel suggested
 * Other minor changes suggested by Mel
 * Rebased on top of 4.1-rc2
 * Changed functions to get pointer to array of pages / pfns to perform
   conversion if necessary. This fixes possible issue in the omap I may have
   introduced in v2 and generally makes the API less errorprone.

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


Re: [PATCHv7 04/15] HID: add HDMI CEC specific keycodes

2015-06-30 Thread Hans Verkuil
On 06/29/15 21:25, Dmitry Torokhov wrote:
 On Mon, Jun 29, 2015 at 12:14:49PM +0200, Hans Verkuil wrote:
 From: Kamil Debski ka...@wypas.org

 Add HDMI CEC specific keycodes to the keycodes definition.

 Signed-off-by: Kamil Debski ka...@wypas.org
 Signed-off-by: Hans Verkuil hans.verk...@cisco.com
 
 Could you please describe the intended use for these keycodes for people
 who do not live and breathe CEC specs?

Do you want this as comments in the patch or as the commit description?

I realized that this patch needs to be updated anyway since there are a few
keys missing that were added for CEC 2.0.

Regards,

Hans

 
 Thanks!
 
 ---
  include/uapi/linux/input.h | 12 
  1 file changed, 12 insertions(+)

 diff --git a/include/uapi/linux/input.h b/include/uapi/linux/input.h
 index 731417c..7430a3f 100644
 --- a/include/uapi/linux/input.h
 +++ b/include/uapi/linux/input.h
 @@ -752,6 +752,18 @@ struct input_keymap_entry {
  #define KEY_KBDINPUTASSIST_ACCEPT   0x264
  #define KEY_KBDINPUTASSIST_CANCEL   0x265
  
 +#define KEY_RIGHT_UP0x266
 +#define KEY_RIGHT_DOWN  0x267
 +#define KEY_LEFT_UP 0x268
 +#define KEY_LEFT_DOWN   0x269
 +
 +#define KEY_NEXT_FAVORITE   0x270
 +#define KEY_STOP_RECORD 0x271
 +#define KEY_PAUSE_RECORD0x272
 +#define KEY_VOD 0x273
 +#define KEY_UNMUTE  0x274
 +#define KEY_DVB 0x275
 +
  #define BTN_TRIGGER_HAPPY   0x2c0
  #define BTN_TRIGGER_HAPPY1  0x2c0
  #define BTN_TRIGGER_HAPPY2  0x2c1
 -- 
 2.1.4

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


[PATCHv7 09/15] DocBook/media: add CEC documentation

2015-06-29 Thread Hans Verkuil
From: Hans Verkuil hverk...@xs4all.nl

Add DocBook documentation for the CEC API.

Signed-off-by: Hans Verkuil hansv...@cisco.com
[k.deb...@samsung.com: add documentation for passthrough mode]
[k.deb...@samsung.com: minor fixes and change of reserved field sizes]
Signed-off-by: Kamil Debski ka...@wypas.org
Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 Documentation/DocBook/media/Makefile   |   2 +
 Documentation/DocBook/media/v4l/biblio.xml |  10 +
 Documentation/DocBook/media/v4l/cec-api.xml|  74 +
 Documentation/DocBook/media/v4l/cec-func-close.xml |  59 
 Documentation/DocBook/media/v4l/cec-func-ioctl.xml |  73 +
 Documentation/DocBook/media/v4l/cec-func-open.xml  |  94 +++
 Documentation/DocBook/media/v4l/cec-func-poll.xml  |  89 ++
 .../DocBook/media/v4l/cec-ioc-g-adap-log-addrs.xml | 299 +
 .../DocBook/media/v4l/cec-ioc-g-adap-phys-addr.xml |  78 ++
 .../DocBook/media/v4l/cec-ioc-g-adap-state.xml |  87 ++
 Documentation/DocBook/media/v4l/cec-ioc-g-caps.xml | 138 ++
 .../DocBook/media/v4l/cec-ioc-g-event.xml  | 125 +
 .../DocBook/media/v4l/cec-ioc-g-passthrough.xml|  88 ++
 .../DocBook/media/v4l/cec-ioc-g-vendor-id.xml  |  70 +
 .../DocBook/media/v4l/cec-ioc-receive.xml  | 185 +
 Documentation/DocBook/media_api.tmpl   |   8 +-
 16 files changed, 1477 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/DocBook/media/v4l/cec-api.xml
 create mode 100644 Documentation/DocBook/media/v4l/cec-func-close.xml
 create mode 100644 Documentation/DocBook/media/v4l/cec-func-ioctl.xml
 create mode 100644 Documentation/DocBook/media/v4l/cec-func-open.xml
 create mode 100644 Documentation/DocBook/media/v4l/cec-func-poll.xml
 create mode 100644 Documentation/DocBook/media/v4l/cec-ioc-g-adap-log-addrs.xml
 create mode 100644 Documentation/DocBook/media/v4l/cec-ioc-g-adap-phys-addr.xml
 create mode 100644 Documentation/DocBook/media/v4l/cec-ioc-g-adap-state.xml
 create mode 100644 Documentation/DocBook/media/v4l/cec-ioc-g-caps.xml
 create mode 100644 Documentation/DocBook/media/v4l/cec-ioc-g-event.xml
 create mode 100644 Documentation/DocBook/media/v4l/cec-ioc-g-passthrough.xml
 create mode 100644 Documentation/DocBook/media/v4l/cec-ioc-g-vendor-id.xml
 create mode 100644 Documentation/DocBook/media/v4l/cec-ioc-receive.xml

diff --git a/Documentation/DocBook/media/Makefile 
b/Documentation/DocBook/media/Makefile
index 23996f8..5c89f4b 100644
--- a/Documentation/DocBook/media/Makefile
+++ b/Documentation/DocBook/media/Makefile
@@ -64,6 +64,7 @@ IOCTLS = \
$(shell perl -ne 'print $$1  if /\#define\s+([A-Z][^\s]+)\s+_IO/' 
$(srctree)/include/uapi/linux/dvb/net.h) \
$(shell perl -ne 'print $$1  if /\#define\s+([^\s]+)\s+_IO/' 
$(srctree)/include/uapi/linux/dvb/video.h) \
$(shell perl -ne 'print $$1  if /\#define\s+([^\s]+)\s+_IO/' 
$(srctree)/include/uapi/linux/media.h) \
+   $(shell perl -ne 'print $$1  if /\#define\s+([^\s]+)\s+_IO/' 
$(srctree)/include/uapi/linux/cec.h) \
$(shell perl -ne 'print $$1  if /\#define\s+([^\s]+)\s+_IO/' 
$(srctree)/include/uapi/linux/v4l2-subdev.h) \
 
 DEFINES = \
@@ -100,6 +101,7 @@ STRUCTS = \
$(shell perl -ne 'print $$1  if (/^struct\s+([^\s]+)\s+/  !/_old/)' 
$(srctree)/include/uapi/linux/dvb/net.h) \
$(shell perl -ne 'print $$1  if (/^struct\s+([^\s]+)\s+/)' 
$(srctree)/include/uapi/linux/dvb/video.h) \
$(shell perl -ne 'print $$1  if /^struct\s+([^\s]+)\s+/' 
$(srctree)/include/uapi/linux/media.h) \
+   $(shell perl -ne 'print $$1  if /^struct\s+([^\s]+)\s+/' 
$(srctree)/include/uapi/linux/cec.h) \
$(shell perl -ne 'print $$1  if /^struct\s+([^\s]+)\s+/' 
$(srctree)/include/uapi/linux/v4l2-subdev.h) \
$(shell perl -ne 'print $$1  if /^struct\s+([^\s]+)\s+/' 
$(srctree)/include/uapi/linux/v4l2-mediabus.h)
 
diff --git a/Documentation/DocBook/media/v4l/biblio.xml 
b/Documentation/DocBook/media/v4l/biblio.xml
index fdee6b3..bed940b 100644
--- a/Documentation/DocBook/media/v4l/biblio.xml
+++ b/Documentation/DocBook/media/v4l/biblio.xml
@@ -324,6 +324,16 @@ in the frequency range from 87,5 to 108,0 MHz/title
   subtitleSpecification Version 1.4a/subtitle
 /biblioentry
 
+biblioentry id=hdmi2
+  abbrevHDMI2/abbrev
+  authorgroup
+   corpauthorHDMI Licensing LLC
+(ulink url=http://www.hdmi.org;http://www.hdmi.org/ulink)/corpauthor
+  /authorgroup
+  titleHigh-Definition Multimedia Interface/title
+  subtitleSpecification Version 2.0/subtitle
+/biblioentry
+
 biblioentry id=dp
   abbrevDP/abbrev
   authorgroup
diff --git a/Documentation/DocBook/media/v4l/cec-api.xml 
b/Documentation/DocBook/media/v4l/cec-api.xml
new file mode 100644
index 000..b59f610
--- /dev/null
+++ b/Documentation/DocBook/media/v4l/cec-api.xml
@@ -0,0 +1,74 @@
+partinfo
+  authorgroup
+author
+  firstnameHans

[PATCHv7 12/15] adv7842: add cec support

2015-06-29 Thread Hans Verkuil
Add CEC support to the adv7842 driver.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/i2c/adv7842.c | 211 +++-
 1 file changed, 208 insertions(+), 3 deletions(-)

diff --git a/drivers/media/i2c/adv7842.c b/drivers/media/i2c/adv7842.c
index 4cf79b2..0ef01bd 100644
--- a/drivers/media/i2c/adv7842.c
+++ b/drivers/media/i2c/adv7842.c
@@ -39,6 +39,7 @@
 #include linux/workqueue.h
 #include linux/v4l2-dv-timings.h
 #include linux/hdmi.h
+#include media/cec.h
 #include media/v4l2-device.h
 #include media/v4l2-ctrls.h
 #include media/v4l2-dv-timings.h
@@ -78,6 +79,8 @@ MODULE_LICENSE(GPL);
 
 #define ADV7842_OP_SWAP_CB_CR  (1  0)
 
+#define ADV7842_MAX_ADDRS (3)
+
 /*
 **
 *
@@ -141,6 +144,10 @@ struct adv7842_state {
struct v4l2_ctrl *free_run_color_ctrl_manual;
struct v4l2_ctrl *free_run_color_ctrl;
struct v4l2_ctrl *rgb_quantization_range_ctrl;
+
+   u8   cec_addr[ADV7842_MAX_ADDRS];
+   u8   cec_valid_addrs;
+   bool cec_enabled_adap;
 };
 
 /* Unsupported timings. This device cannot support 720p30. */
@@ -417,9 +424,9 @@ static inline int cec_write(struct v4l2_subdev *sd, u8 reg, 
u8 val)
return adv_smbus_write_byte_data(state-i2c_cec, reg, val);
 }
 
-static inline int cec_write_and_or(struct v4l2_subdev *sd, u8 reg, u8 mask, u8 
val)
+static inline int cec_write_clr_set(struct v4l2_subdev *sd, u8 reg, u8 mask, 
u8 val)
 {
-   return cec_write(sd, reg, (cec_read(sd, reg)  mask) | val);
+   return cec_write(sd, reg, (cec_read(sd, reg)  ~mask) | val);
 }
 
 static inline int infoframe_read(struct v4l2_subdev *sd, u8 reg)
@@ -2157,6 +2164,185 @@ static void adv7842_irq_enable(struct v4l2_subdev *sd, 
bool enable)
}
 }
 
+static void adv7842_cec_tx_raw_status(struct v4l2_subdev *sd, u8 tx_raw_status)
+{
+   if ((cec_read(sd, 0x11)  0x01) == 0) {
+   v4l2_dbg(1, debug, sd, %s: tx raw: tx disabled\n, __func__);
+   return;
+   }
+
+   if (tx_raw_status  0x02) {
+   v4l2_dbg(1, debug, sd, %s: tx raw: arbitration lost\n,
+__func__);
+   v4l2_subdev_notify(sd, V4L2_SUBDEV_CEC_TX_DONE,
+  (void *)CEC_TX_STATUS_ARB_LOST);
+   return;
+   }
+   if (tx_raw_status  0x04) {
+   v4l2_dbg(1, debug, sd, %s: tx raw: retry failed\n, __func__);
+   v4l2_subdev_notify(sd, V4L2_SUBDEV_CEC_TX_DONE,
+  (void *)CEC_TX_STATUS_RETRY_TIMEOUT);
+   return;
+   }
+   if (tx_raw_status  0x01) {
+   v4l2_dbg(1, debug, sd, %s: tx raw: ready ok\n, __func__);
+   v4l2_subdev_notify(sd, V4L2_SUBDEV_CEC_TX_DONE,
+  (void *)CEC_TX_STATUS_OK);
+   return;
+   }
+}
+
+static void adv7842_cec_isr(struct v4l2_subdev *sd, bool *handled)
+{
+   struct cec_msg msg;
+   u8 cec_irq;
+
+   /* cec controller */
+   cec_irq = io_read(sd, 0x93)  0x0f;
+   if (!cec_irq)
+   return;
+
+   v4l2_dbg(1, debug, sd, %s: cec: irq 0x%x\n, __func__, cec_irq);
+   adv7842_cec_tx_raw_status(sd, cec_irq);
+   if (cec_irq  0x08) {
+   msg.len = cec_read(sd, 0x25)  0x1f;
+   if (msg.len  16)
+   msg.len = 16;
+
+   if (msg.len) {
+   u8 i;
+
+   for (i = 0; i  msg.len; i++)
+   msg.msg[i] = cec_read(sd, i + 0x15);
+   cec_write(sd, 0x26, 0x01); /* re-enable rx */
+   v4l2_subdev_notify(sd, V4L2_SUBDEV_CEC_RX_MSG, msg);
+   }
+   }
+
+   io_write(sd, 0x94, cec_irq);
+
+   if (handled)
+   *handled = true;
+}
+
+static unsigned adv7842_cec_available_log_addrs(struct v4l2_subdev *sd)
+{
+   return ADV7842_MAX_ADDRS;
+}
+
+static int adv7842_cec_enable(struct v4l2_subdev *sd, bool enable)
+{
+   struct adv7842_state *state = to_state(sd);
+
+   if (!state-cec_enabled_adap  enable) {
+   cec_write_clr_set(sd, 0x2a, 0x01, 0x01);/* power up cec 
*/
+   cec_write(sd, 0x2c, 0x01);  /* cec soft reset */
+   cec_write_clr_set(sd, 0x11, 0x01, 0);  /* initially disable tx 
*/
+   /* enabled irqs: */
+   /* tx: ready */
+   /* tx: arbitration lost */
+   /* tx: retry timeout */
+   /* rx: ready */
+   io_write_clr_set(sd, 0x96, 0x0f, 0x0f);
+   cec_write(sd, 0x26, 0x01);/* enable rx */
+   } else if (state-cec_enabled_adap  !enable) {
+   /* disable cec interrupts */
+   io_write_clr_set(sd, 0x96, 0x0f, 0x00);
+   /* disable address mask 1-3

[PATCH 1/4] Makefile.am: copy cec headers with make sync-with-kernel

2015-06-29 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

Copy the new cec headers.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 Makefile.am | 4 
 1 file changed, 4 insertions(+)

diff --git a/Makefile.am b/Makefile.am
index 1a61592..b8c450d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -21,6 +21,8 @@ sync-with-kernel:
  ! -f $(KERNEL_DIR)/usr/include/linux/v4l2-common.h -o \
  ! -f $(KERNEL_DIR)/usr/include/linux/v4l2-subdev.h -o \
  ! -f $(KERNEL_DIR)/usr/include/linux/v4l2-mediabus.h -o \
+ ! -f $(KERNEL_DIR)/usr/include/linux/cec.h -o \
+ ! -f $(KERNEL_DIR)/usr/include/linux/cec-funcs.h -o \
  ! -f $(KERNEL_DIR)/usr/include/linux/ivtv.h -o \
  ! -f $(KERNEL_DIR)/usr/include/linux/dvb/frontend.h -o \
  ! -f $(KERNEL_DIR)/usr/include/linux/dvb/dmx.h -o \
@@ -38,6 +40,8 @@ sync-with-kernel:
cp -a $(KERNEL_DIR)/usr/include/linux/v4l2-mediabus.h 
$(top_srcdir)/include/linux
cp -a $(KERNEL_DIR)/usr/include/linux/media-bus-format.h 
$(top_srcdir)/include/linux
cp -a $(KERNEL_DIR)/usr/include/linux/media.h 
$(top_srcdir)/include/linux
+   cp -a $(KERNEL_DIR)/usr/include/linux/cec.h $(top_srcdir)/include/linux
+   cp -a $(KERNEL_DIR)/usr/include/linux/cec-funcs.h 
$(top_srcdir)/include/linux
cp -a $(KERNEL_DIR)/usr/include/linux/ivtv.h $(top_srcdir)/include/linux
cp -a $(KERNEL_DIR)/usr/include/linux/dvb/frontend.h 
$(top_srcdir)/include/linux/dvb
cp -a $(KERNEL_DIR)/usr/include/linux/dvb/dmx.h 
$(top_srcdir)/include/linux/dvb
-- 
2.1.4

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


[PATCH 0/4] cec-ctl/compliance: new CEC utilities

2015-06-29 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

This patch series adds two new utilities to the v4l-utils git repository
(http://git.linuxtv.org/cgit.cgi/v4l-utils.git/). It assumes that the new
CEC framework available in the kernel:

http://www.mail-archive.com/linux-media@vger.kernel.org/msg90085.html

The first patch adds the new cec headers to the 'sync-with-kernel' target,
the second syncs with the kernel and adds the new cec headers to v4l-utils,
the third adds the compliance utility and the last adds the cec-ctl utility.

The cec-compliance utility is by no means 100% coverage, in particular the
event API and non-blocking ioctls are untested. But it is a starting point,
and a complex protocol like CEC really needs a compliance tool.

The cec-ctl utility has almost full CEC message coverage: all generated from
the cec headers, so this is easy to keep up to date.

The main missing feature is that there is no logging of received messages.
This would be very useful to add. There is also no event handling/async message
handling yet.

But it is very useful to test CEC messages.

Regards,

Hans

Hans Verkuil (4):
  Makefile.am: copy cec headers with make sync-with-kernel
  sync-with-kernel
  cec-compliance: add new CEC compliance utility
  cec-ctl: CEC control utility

 Makefile.am  |4 +
 configure.ac |2 +
 contrib/freebsd/include/linux/input.h|   13 +
 include/linux/cec-funcs.h| 1516 ++
 include/linux/cec.h  |  709 ++
 utils/Makefile.am|2 +
 utils/cec-compliance/Makefile.am |3 +
 utils/cec-compliance/cec-compliance.cpp  |  943 ++
 utils/cec-compliance/cec-compliance.h|   87 ++
 utils/cec-ctl/Makefile.am|8 +
 utils/cec-ctl/cec-ctl.cpp| 1000 ++
 utils/cec-ctl/msg2ctl.pl |  330 +
 utils/keytable/parse.h   |   10 +
 utils/keytable/rc_keymaps/cec|   77 ++
 utils/keytable/rc_keymaps/technisat_ts35 |   34 +
 utils/keytable/rc_keymaps/terratec_cinergy_c_pci |   49 +
 utils/keytable/rc_keymaps/terratec_cinergy_s2_hd |   49 +
 utils/keytable/rc_keymaps/twinhan_dtv_cab_ci |   54 +
 utils/keytable/rc_maps.cfg   |1 +
 19 files changed, 4891 insertions(+)
 create mode 100644 include/linux/cec-funcs.h
 create mode 100644 include/linux/cec.h
 create mode 100644 utils/cec-compliance/Makefile.am
 create mode 100644 utils/cec-compliance/cec-compliance.cpp
 create mode 100644 utils/cec-compliance/cec-compliance.h
 create mode 100644 utils/cec-ctl/Makefile.am
 create mode 100644 utils/cec-ctl/cec-ctl.cpp
 create mode 100755 utils/cec-ctl/msg2ctl.pl
 create mode 100644 utils/keytable/rc_keymaps/cec
 create mode 100644 utils/keytable/rc_keymaps/technisat_ts35
 create mode 100644 utils/keytable/rc_keymaps/terratec_cinergy_c_pci
 create mode 100644 utils/keytable/rc_keymaps/terratec_cinergy_s2_hd
 create mode 100644 utils/keytable/rc_keymaps/twinhan_dtv_cab_ci

-- 
2.1.4

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


[PATCH 2/4] sync-with-kernel

2015-06-29 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 contrib/freebsd/include/linux/input.h|   13 +
 include/linux/cec-funcs.h| 1516 ++
 include/linux/cec.h  |  709 ++
 utils/keytable/parse.h   |   10 +
 utils/keytable/rc_keymaps/cec|   77 ++
 utils/keytable/rc_keymaps/technisat_ts35 |   34 +
 utils/keytable/rc_keymaps/terratec_cinergy_c_pci |   49 +
 utils/keytable/rc_keymaps/terratec_cinergy_s2_hd |   49 +
 utils/keytable/rc_keymaps/twinhan_dtv_cab_ci |   54 +
 utils/keytable/rc_maps.cfg   |1 +
 10 files changed, 2512 insertions(+)
 create mode 100644 include/linux/cec-funcs.h
 create mode 100644 include/linux/cec.h
 create mode 100644 utils/keytable/rc_keymaps/cec
 create mode 100644 utils/keytable/rc_keymaps/technisat_ts35
 create mode 100644 utils/keytable/rc_keymaps/terratec_cinergy_c_pci
 create mode 100644 utils/keytable/rc_keymaps/terratec_cinergy_s2_hd
 create mode 100644 utils/keytable/rc_keymaps/twinhan_dtv_cab_ci

diff --git a/contrib/freebsd/include/linux/input.h 
b/contrib/freebsd/include/linux/input.h
index 19345e1..eaef6ac 100644
--- a/contrib/freebsd/include/linux/input.h
+++ b/contrib/freebsd/include/linux/input.h
@@ -786,6 +786,18 @@ struct input_keymap_entry {
 #define KEY_KBDINPUTASSIST_ACCEPT  0x264
 #define KEY_KBDINPUTASSIST_CANCEL  0x265
 
+#define KEY_RIGHT_UP   0x266
+#define KEY_RIGHT_DOWN 0x267
+#define KEY_LEFT_UP0x268
+#define KEY_LEFT_DOWN  0x269
+
+#define KEY_NEXT_FAVORITE  0x270
+#define KEY_STOP_RECORD0x271
+#define KEY_PAUSE_RECORD   0x272
+#define KEY_VOD0x273
+#define KEY_UNMUTE 0x274
+#define KEY_DVB0x275
+
 #define BTN_TRIGGER_HAPPY  0x2c0
 #define BTN_TRIGGER_HAPPY1 0x2c0
 #define BTN_TRIGGER_HAPPY2 0x2c1
@@ -1006,6 +1018,7 @@ struct input_keymap_entry {
 #define BUS_GSC0x1A
 #define BUS_ATARI  0x1B
 #define BUS_SPI0x1C
+#define BUS_CEC0x1D
 
 /*
  * MT_TOOL types
diff --git a/include/linux/cec-funcs.h b/include/linux/cec-funcs.h
new file mode 100644
index 000..b74d003
--- /dev/null
+++ b/include/linux/cec-funcs.h
@@ -0,0 +1,1516 @@
+#ifndef _CEC_FUNCS_H
+#define _CEC_FUNCS_H
+
+#include linux/cec.h
+
+/* One Touch Play Feature */
+static __inline__ void cec_msg_active_source(struct cec_msg *msg, __u16 
phys_addr)
+{
+   msg-len = 4;
+   msg-msg[0] |= 0xf; /* broadcast */
+   msg-msg[1] = CEC_MSG_ACTIVE_SOURCE;
+   msg-msg[2] = phys_addr  8;
+   msg-msg[3] = phys_addr  0xff;
+}
+
+static __inline__ void cec_ops_active_source(const struct cec_msg *msg,
+__u16 *phys_addr)
+{
+   *phys_addr = (msg-msg[2]  8) | msg-msg[3];
+}
+
+static __inline__ void cec_msg_image_view_on(struct cec_msg *msg)
+{
+   msg-len = 2;
+   msg-msg[1] = CEC_MSG_IMAGE_VIEW_ON;
+}
+
+static __inline__ void cec_msg_text_view_on(struct cec_msg *msg)
+{
+   msg-len = 2;
+   msg-msg[1] = CEC_MSG_TEXT_VIEW_ON;
+}
+
+
+/* Routing Control Feature */
+static __inline__ void cec_msg_inactive_source(struct cec_msg *msg,
+  __u16 phys_addr)
+{
+   msg-len = 4;
+   msg-msg[1] = CEC_MSG_INACTIVE_SOURCE;
+   msg-msg[2] = phys_addr  8;
+   msg-msg[3] = phys_addr  0xff;
+}
+
+static __inline__ void cec_ops_inactive_source(const struct cec_msg *msg,
+  __u16 *phys_addr)
+{
+   *phys_addr = (msg-msg[2]  8) | msg-msg[3];
+}
+
+static __inline__ void cec_msg_request_active_source(struct cec_msg *msg,
+bool reply)
+{
+   msg-len = 2;
+   msg-msg[0] |= 0xf; /* broadcast */
+   msg-msg[1] = CEC_MSG_REQUEST_ACTIVE_SOURCE;
+   msg-reply = reply ? CEC_MSG_ACTIVE_SOURCE : 0;
+}
+
+static __inline__ void cec_msg_routing_information(struct cec_msg *msg,
+  __u16 phys_addr)
+{
+   msg-len = 4;
+   msg-msg[0] |= 0xf; /* broadcast */
+   msg-msg[1] = CEC_MSG_ROUTING_INFORMATION;
+   msg-msg[2] = phys_addr  8;
+   msg-msg[3] = phys_addr  0xff;
+}
+
+static __inline__ void cec_ops_routing_information(const struct cec_msg *msg,
+  __u16 *phys_addr)
+{
+   *phys_addr = (msg-msg[2]  8) | msg-msg[3];
+}
+
+static __inline__ void cec_msg_routing_change(struct cec_msg *msg,
+ bool reply,
+ __u16 orig_phys_addr

[PATCH 3/4] cec-compliance: add new CEC compliance utility

2015-06-29 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

This utility will attempt to test whether the CEC protocol was
implemented correctly.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 configure.ac|   1 +
 utils/Makefile.am   |   1 +
 utils/cec-compliance/Makefile.am|   3 +
 utils/cec-compliance/cec-compliance.cpp | 943 
 utils/cec-compliance/cec-compliance.h   |  87 +++
 5 files changed, 1035 insertions(+)
 create mode 100644 utils/cec-compliance/Makefile.am
 create mode 100644 utils/cec-compliance/cec-compliance.cpp
 create mode 100644 utils/cec-compliance/cec-compliance.h

diff --git a/configure.ac b/configure.ac
index d4e312c..12c2eb9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -26,6 +26,7 @@ AC_CONFIG_FILES([Makefile
utils/keytable/Makefile
utils/media-ctl/Makefile
utils/rds/Makefile
+   utils/cec-compliance/Makefile
utils/v4l2-compliance/Makefile
utils/v4l2-ctl/Makefile
utils/v4l2-dbg/Makefile
diff --git a/utils/Makefile.am b/utils/Makefile.am
index 31b2979..c78e97b 100644
--- a/utils/Makefile.am
+++ b/utils/Makefile.am
@@ -5,6 +5,7 @@ SUBDIRS = \
decode_tm6000 \
keytable \
media-ctl \
+   cec-compliance \
v4l2-compliance \
v4l2-ctl \
v4l2-dbg \
diff --git a/utils/cec-compliance/Makefile.am b/utils/cec-compliance/Makefile.am
new file mode 100644
index 000..da4c0ef
--- /dev/null
+++ b/utils/cec-compliance/Makefile.am
@@ -0,0 +1,3 @@
+bin_PROGRAMS = cec-compliance
+
+cec_compliance_SOURCES = cec-compliance.cpp
diff --git a/utils/cec-compliance/cec-compliance.cpp 
b/utils/cec-compliance/cec-compliance.cpp
new file mode 100644
index 000..c8c51dc
--- /dev/null
+++ b/utils/cec-compliance/cec-compliance.cpp
@@ -0,0 +1,943 @@
+/*
+Copyright 2015 Cisco Systems, Inc. and/or its affiliates. All rights 
reserved.
+Author: Hans Verkuil hans.verk...@cisco.com
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+ */
+
+#include unistd.h
+#include stdlib.h
+#include stdio.h
+#include string.h
+#include inttypes.h
+#include getopt.h
+#include sys/types.h
+#include sys/stat.h
+#include fcntl.h
+#include ctype.h
+#include errno.h
+#include sys/ioctl.h
+#include config.h
+
+#include cec-compliance.h
+
+/* Short option list
+
+   Please keep in alphabetical order.
+   That makes it easier to see which short options are still free.
+
+   In general the lower case is used to set something and the upper
+   case is used to retrieve a setting. */
+enum Option {
+   OptPhysAddr = 'a',
+   OptSetDevice = 'd',
+   OptHelp = 'h',
+   OptNoWarnings = 'n',
+   OptTrace = 'T',
+   OptVerbose = 'v',
+   OptVendorID = 'V',
+
+   OptTV,
+   OptRecord,
+   OptTuner,
+   OptPlayback,
+   OptAudio,
+   OptProcessor,
+   OptSwitch,
+   OptCDCOnly,
+   OptUnregistered,
+   OptLast = 256
+};
+
+static char options[OptLast];
+
+static int app_result;
+static int tests_total, tests_ok;
+
+bool show_info;
+bool show_warnings = true;
+unsigned warnings;
+
+static struct option long_options[] = {
+   {device, required_argument, 0, OptSetDevice},
+   {help, no_argument, 0, OptHelp},
+   {no-warnings, no_argument, 0, OptNoWarnings},
+   {trace, no_argument, 0, OptTrace},
+   {verbose, no_argument, 0, OptVerbose},
+   {phys-addr, required_argument, 0, OptPhysAddr},
+   {vendor-id, required_argument, 0, OptVendorID},
+
+   {tv, no_argument, 0, OptTV},
+   {record, no_argument, 0, OptRecord},
+   {tuner, no_argument, 0, OptTuner},
+   {playback, no_argument, 0, OptPlayback},
+   {audio, no_argument, 0, OptAudio},
+   {processor, no_argument, 0, OptProcessor},
+   {switch, no_argument, 0, OptSwitch},
+   {cdc-only, no_argument, 0, OptCDCOnly},
+   {unregistered, no_argument, 0, OptUnregistered},
+   {0, 0, 0, 0}
+};
+
+static void usage(void)
+{
+   printf(Usage:\n
+-d, --device=dev Use device dev instead of /dev/cec0\n
+   If dev starts with a digit, then 
/dev/cecdev is used.\n
+-h, --help Display this help message\n
+-n, --no-warnings  Turn off warning messages.\n
+-T, --traceTrace all called ioctls.\n
+-v, --verbose  Turn on verbose reporting.\n
+-a, --phys-addr=addr\n

[PATCH 4/4] cec-ctl: CEC control utility

2015-06-29 Thread Hans Verkuil
From: Hans Verkuil hans.verk...@cisco.com

Generic CEC utility that can be used to send/receive/monitor CEC
messages.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 configure.ac  |1 +
 utils/Makefile.am |1 +
 utils/cec-ctl/Makefile.am |8 +
 utils/cec-ctl/cec-ctl.cpp | 1000 +
 utils/cec-ctl/msg2ctl.pl  |  330 +++
 5 files changed, 1340 insertions(+)
 create mode 100644 utils/cec-ctl/Makefile.am
 create mode 100644 utils/cec-ctl/cec-ctl.cpp
 create mode 100755 utils/cec-ctl/msg2ctl.pl

diff --git a/configure.ac b/configure.ac
index 12c2eb9..72d59bd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -27,6 +27,7 @@ AC_CONFIG_FILES([Makefile
utils/media-ctl/Makefile
utils/rds/Makefile
utils/cec-compliance/Makefile
+   utils/cec-ctl/Makefile
utils/v4l2-compliance/Makefile
utils/v4l2-ctl/Makefile
utils/v4l2-dbg/Makefile
diff --git a/utils/Makefile.am b/utils/Makefile.am
index c78e97b..617abf1 100644
--- a/utils/Makefile.am
+++ b/utils/Makefile.am
@@ -6,6 +6,7 @@ SUBDIRS = \
keytable \
media-ctl \
cec-compliance \
+   cec-ctl \
v4l2-compliance \
v4l2-ctl \
v4l2-dbg \
diff --git a/utils/cec-ctl/Makefile.am b/utils/cec-ctl/Makefile.am
new file mode 100644
index 000..378d7db
--- /dev/null
+++ b/utils/cec-ctl/Makefile.am
@@ -0,0 +1,8 @@
+bin_PROGRAMS = cec-ctl
+
+cec_ctl_SOURCES = cec-ctl.cpp
+
+cec-ctl.cpp: cec-ctl-gen.h
+
+cec-ctl-gen.h: msg2ctl.pl ../../include/linux/cec.h 
../../include/linux/cec-funcs.h
+   msg2ctl.pl ../../include/linux/cec.h ../../include/linux/cec-funcs.h 
cec-ctl-gen.h
diff --git a/utils/cec-ctl/cec-ctl.cpp b/utils/cec-ctl/cec-ctl.cpp
new file mode 100644
index 000..1d0f663
--- /dev/null
+++ b/utils/cec-ctl/cec-ctl.cpp
@@ -0,0 +1,1000 @@
+/*
+Copyright 2015 Cisco Systems, Inc. and/or its affiliates. All rights 
reserved.
+Author: Hans Verkuil hans.verk...@cisco.com
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+ */
+
+#include unistd.h
+#include stdlib.h
+#include stdio.h
+#include string.h
+#include inttypes.h
+#include getopt.h
+#include sys/types.h
+#include sys/stat.h
+#include fcntl.h
+#include ctype.h
+#include errno.h
+#include sys/ioctl.h
+#include stdarg.h
+#include cerrno
+#include string
+#include vector
+#include linux/cec-funcs.h
+#include config.h
+
+#define CEC_MAX_ARGS 16
+
+struct cec_enum_values {
+   const char *type_name;
+   __u8 value;
+};
+
+enum cec_types {
+   CEC_TYPE_U8,
+   CEC_TYPE_U16,
+   CEC_TYPE_U32,
+   CEC_TYPE_STRING,
+   CEC_TYPE_ENUM,
+};
+
+struct arg {
+   enum cec_types type;
+   __u8 num_enum_values;
+   const struct cec_enum_values *values;
+};
+
+struct message {
+   __u8 msg;
+   unsigned option;
+   __u8 num_args;
+   const char *arg_names[CEC_MAX_ARGS+1];
+   const struct arg *args[CEC_MAX_ARGS];
+   const char *msg_name;
+};
+
+static struct cec_op_digital_service_id *args2digital_service_id(__u8 
service_id_method,
+__u8 
dig_bcast_system,
+__u16 
transport_id,
+__u16 
service_id,
+__u16 
orig_network_id,
+__u16 
program_number,
+__u8 
channel_number_fmt,
+__u16 major,
+__u16 minor)
+{
+   static struct cec_op_digital_service_id dsid;
+
+   dsid.service_id_method = service_id_method;
+   dsid.dig_bcast_system = dig_bcast_system;
+   if (service_id_method == CEC_OP_SERVICE_ID_METHOD_BY_CHANNEL) {
+   dsid.channel.channel_number_fmt = channel_number_fmt;
+   dsid.channel.major = major;
+   dsid.channel.minor = minor;
+   return dsid;
+   }
+   switch (dig_bcast_system) {
+   case CEC_OP_DIG_SERVICE_BCAST_SYSTEM_ATSC_GEN:
+   case CEC_OP_DIG_SERVICE_BCAST_SYSTEM_ATSC_CABLE:
+   case CEC_OP_DIG_SERVICE_BCAST_SYSTEM_ATSC_SAT:
+   case CEC_OP_DIG_SERVICE_BCAST_SYSTEM_ATSC_T:
+   dsid.atsc.transport_id

[PATCHv7 00/15] HDMI CEC framework

2015-06-29 Thread Hans Verkuil
 to the cec.h file

Background
==

The work on a common CEC framework was started over three years ago by Hans
Verkuil. Unfortunately the work has stalled. As I have received the task of
creating a driver for the CEC interface module present on the Exynos range of
SoCs, I got in touch with Hans. He replied that the work stalled due to his
lack of time.

Original RFC by Hans Verkuil/Martin Bugge
=
https://www.mail-archive.com/linux-media@vger.kernel.org/msg28735.html


Hans Verkuil (9):
  input.h: add BUS_CEC type
  cec: add HDMI CEC framework
  cec.txt: add CEC framework documentation
  DocBook/media: add CEC documentation
  v4l2-subdev: add HDMI CEC ops
  cec: adv7604: add cec support.
  adv7842: add cec support
  cec: adv7511: add cec support.
  cobalt: add cec support

Kamil Debski (6):
  dts: exynos4*: add HDMI CEC pin definition to pinctrl
  dts: exynos4: add node for the HDMI CEC device
  dts: exynos4412-odroid*: enable the HDMI CEC device
  HID: add HDMI CEC specific keycodes
  rc: Add HDMI CEC protocol handling
  cec: s5p-cec: Add s5p-cec driver

 Documentation/DocBook/media/Makefile   |2 +
 Documentation/DocBook/media/v4l/biblio.xml |   10 +
 Documentation/DocBook/media/v4l/cec-api.xml|   74 +
 Documentation/DocBook/media/v4l/cec-func-close.xml |   59 +
 Documentation/DocBook/media/v4l/cec-func-ioctl.xml |   73 +
 Documentation/DocBook/media/v4l/cec-func-open.xml  |   94 ++
 Documentation/DocBook/media/v4l/cec-func-poll.xml  |   89 ++
 .../DocBook/media/v4l/cec-ioc-g-adap-log-addrs.xml |  299 
 .../DocBook/media/v4l/cec-ioc-g-adap-phys-addr.xml |   78 +
 .../DocBook/media/v4l/cec-ioc-g-adap-state.xml |   87 ++
 Documentation/DocBook/media/v4l/cec-ioc-g-caps.xml |  138 ++
 .../DocBook/media/v4l/cec-ioc-g-event.xml  |  125 ++
 .../DocBook/media/v4l/cec-ioc-g-passthrough.xml|   88 ++
 .../DocBook/media/v4l/cec-ioc-g-vendor-id.xml  |   70 +
 .../DocBook/media/v4l/cec-ioc-receive.xml  |  185 +++
 Documentation/DocBook/media_api.tmpl   |8 +-
 Documentation/cec.txt  |  166 ++
 .../devicetree/bindings/media/s5p-cec.txt  |   31 +
 MAINTAINERS|   11 +
 arch/arm/boot/dts/exynos4.dtsi |   12 +
 arch/arm/boot/dts/exynos4210-pinctrl.dtsi  |7 +
 arch/arm/boot/dts/exynos4412-odroid-common.dtsi|4 +
 arch/arm/boot/dts/exynos4x12-pinctrl.dtsi  |7 +
 drivers/media/Kconfig  |6 +
 drivers/media/Makefile |2 +
 drivers/media/cec.c| 1580 
 drivers/media/i2c/adv7511.c|  350 -
 drivers/media/i2c/adv7604.c|  219 ++-
 drivers/media/i2c/adv7842.c|  211 ++-
 drivers/media/pci/cobalt/cobalt-driver.c   |   37 +-
 drivers/media/pci/cobalt/cobalt-driver.h   |2 +
 drivers/media/pci/cobalt/cobalt-v4l2.c |  110 +-
 drivers/media/platform/Kconfig |   10 +
 drivers/media/platform/Makefile|1 +
 drivers/media/platform/s5p-cec/Makefile|2 +
 drivers/media/platform/s5p-cec/exynos_hdmi_cec.h   |   37 +
 .../media/platform/s5p-cec/exynos_hdmi_cecctrl.c   |  208 +++
 drivers/media/platform/s5p-cec/regs-cec.h  |   96 ++
 drivers/media/platform/s5p-cec/s5p_cec.c   |  283 
 drivers/media/platform/s5p-cec/s5p_cec.h   |   76 +
 drivers/media/rc/keymaps/Makefile  |1 +
 drivers/media/rc/keymaps/rc-cec.c  |  144 ++
 drivers/media/rc/rc-main.c |1 +
 include/media/adv7511.h|6 +-
 include/media/cec.h|  161 ++
 include/media/rc-core.h|1 +
 include/media/rc-map.h |5 +-
 include/media/v4l2-subdev.h|9 +
 include/uapi/linux/Kbuild  |2 +
 include/uapi/linux/cec-funcs.h | 1516 +++
 include/uapi/linux/cec.h   |  709 +
 include/uapi/linux/input.h |   13 +
 52 files changed, 7485 insertions(+), 30 deletions(-)
 create mode 100644 Documentation/DocBook/media/v4l/cec-api.xml
 create mode 100644 Documentation/DocBook/media/v4l/cec-func-close.xml
 create mode 100644 Documentation/DocBook/media/v4l/cec-func-ioctl.xml
 create mode 100644 Documentation/DocBook/media/v4l/cec-func-open.xml
 create mode 100644 Documentation/DocBook/media/v4l/cec-func-poll.xml
 create mode 100644 Documentation/DocBook/media/v4l/cec-ioc-g-adap-log-addrs.xml
 create mode 100644 Documentation/DocBook/media/v4l/cec-ioc-g-adap-phys-addr.xml
 create mode 100644 Documentation/DocBook/media/v4l/cec-ioc-g-adap

[PATCHv7 06/15] rc: Add HDMI CEC protocol handling

2015-06-29 Thread Hans Verkuil
From: Kamil Debski ka...@wypas.org

Add handling of remote control events coming from the HDMI CEC bus.
This patch includes a new keymap that maps values found in the CEC
messages to the keys pressed and released. Also, a new protocol has
been added to the core.

Signed-off-by: Kamil Debski ka...@wypas.org
Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/rc/keymaps/Makefile |   1 +
 drivers/media/rc/keymaps/rc-cec.c | 144 ++
 drivers/media/rc/rc-main.c|   1 +
 include/media/rc-core.h   |   1 +
 include/media/rc-map.h|   5 +-
 5 files changed, 151 insertions(+), 1 deletion(-)
 create mode 100644 drivers/media/rc/keymaps/rc-cec.c

diff --git a/drivers/media/rc/keymaps/Makefile 
b/drivers/media/rc/keymaps/Makefile
index fbbd3bb..9cffcc6 100644
--- a/drivers/media/rc/keymaps/Makefile
+++ b/drivers/media/rc/keymaps/Makefile
@@ -18,6 +18,7 @@ obj-$(CONFIG_RC_MAP) += rc-adstech-dvb-t-pci.o \
rc-behold.o \
rc-behold-columbus.o \
rc-budget-ci-old.o \
+   rc-cec.o \
rc-cinergy-1400.o \
rc-cinergy.o \
rc-delock-61959.o \
diff --git a/drivers/media/rc/keymaps/rc-cec.c 
b/drivers/media/rc/keymaps/rc-cec.c
new file mode 100644
index 000..cc5b318
--- /dev/null
+++ b/drivers/media/rc/keymaps/rc-cec.c
@@ -0,0 +1,144 @@
+/* Keytable for the CEC remote control
+ *
+ * Copyright (c) 2015 by Kamil Debski
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include media/rc-map.h
+#include linux/module.h
+
+/* CEC Spec High-Definition Multimedia Interface Specification can be 
obtained
+ * here: http://xtreamerdev.googlecode.com/files/CEC_Specs.pdf
+ * The list of control codes is listed in Table 27: User Control Codes p. 95 */
+
+static struct rc_map_table cec[] = {
+   { 0x00, KEY_OK },
+   { 0x01, KEY_UP },
+   { 0x02, KEY_DOWN },
+   { 0x03, KEY_LEFT },
+   { 0x04, KEY_RIGHT },
+   { 0x05, KEY_RIGHT_UP },
+   { 0x06, KEY_RIGHT_DOWN },
+   { 0x07, KEY_LEFT_UP },
+   { 0x08, KEY_LEFT_DOWN },
+   { 0x09, KEY_CONTEXT_MENU }, /* CEC Spec: Root Menu - see Note 2 */
+   /* Note 2: This is the initial display that a device shows. It is
+* device-dependent and can be, for example, a contents menu, setup
+* menu, favorite menu or other menu. The actual menu displayed
+* may also depend on the device’s current state. */
+   { 0x0a, KEY_SETUP },
+   { 0x0b, KEY_MENU }, /* CEC Spec: Contents Menu */
+   { 0x0c, KEY_FAVORITES }, /* CEC Spec: Favorite Menu */
+   { 0x0d, KEY_EXIT },
+   /* 0x0e-0x1f: Reserved */
+   /* 0x20-0x29: Keys 0 to 9 */
+   { 0x20, KEY_NUMERIC_0 },
+   { 0x21, KEY_NUMERIC_1 },
+   { 0x22, KEY_NUMERIC_2 },
+   { 0x23, KEY_NUMERIC_3 },
+   { 0x24, KEY_NUMERIC_4 },
+   { 0x25, KEY_NUMERIC_5 },
+   { 0x26, KEY_NUMERIC_6 },
+   { 0x27, KEY_NUMERIC_7 },
+   { 0x28, KEY_NUMERIC_8 },
+   { 0x29, KEY_NUMERIC_9 },
+   { 0x2a, KEY_DOT },
+   { 0x2b, KEY_ENTER },
+   { 0x2c, KEY_CLEAR },
+   /* 0x2d-0x2e: Reserved */
+   { 0x2f, KEY_NEXT_FAVORITE }, /* CEC Spec: Next Favorite */
+   { 0x30, KEY_CHANNELUP },
+   { 0x31, KEY_CHANNELDOWN },
+   { 0x32, KEY_PREVIOUS }, /* CEC Spec: Previous Channel */
+   { 0x33, KEY_SOUND }, /* CEC Spec: Sound Select */
+   { 0x34, KEY_VIDEO }, /* 0x34: CEC Spec: Input Select */
+   { 0x35, KEY_INFO }, /* CEC Spec: Display Information */
+   { 0x36, KEY_HELP },
+   { 0x37, KEY_PAGEUP },
+   { 0x38, KEY_PAGEDOWN },
+   /* 0x39-0x3f: Reserved */
+   { 0x40, KEY_POWER },
+   { 0x41, KEY_VOLUMEUP },
+   { 0x42, KEY_VOLUMEDOWN },
+   { 0x43, KEY_MUTE },
+   { 0x44, KEY_PLAY },
+   { 0x45, KEY_STOP },
+   { 0x46, KEY_PAUSE },
+   { 0x47, KEY_RECORD },
+   { 0x48, KEY_REWIND },
+   { 0x49, KEY_FASTFORWARD },
+   { 0x4a, KEY_EJECTCD }, /* CEC Spec: Eject */
+   { 0x4b, KEY_FORWARD },
+   { 0x4c, KEY_BACK },
+   { 0x4d, KEY_STOP_RECORD }, /* CEC Spec: Stop-Record */
+   { 0x4e, KEY_PAUSE_RECORD }, /* CEC Spec: Pause-Record */
+   /* 0x4f: Reserved */
+   { 0x50, KEY_ANGLE },
+   { 0x51, KEY_TV2 },
+   { 0x52, KEY_VOD }, /* CEC Spec: Video on Demand */
+   { 0x53, KEY_EPG },
+   { 0x54, KEY_TIME }, /* CEC Spec: Timer */
+   { 0x55, KEY_CONFIG },
+   /* 0x56-0x5f: Reserved */
+   { 0x60, KEY_PLAY }, /* CEC Spec: Play Function */
+   { 0x6024, KEY_PLAY },
+   { 0x6020, KEY_PAUSE },
+   { 0x61, KEY_PLAYPAUSE }, /* CEC Spec: Pause-Play Function

[PATCHv7 02/15] dts: exynos4: add node for the HDMI CEC device

2015-06-29 Thread Hans Verkuil
From: Kamil Debski ka...@wypas.org

This patch adds HDMI CEC node specific to the Exynos4210/4x12 SoC series.

Signed-off-by: Kamil Debski ka...@wypas.org
Signed-off-by: Hans Verkuil hans.verk...@cisco.com
Acked-by: Krzysztof Kozlowski k.kozlow...@samsung.com
---
 arch/arm/boot/dts/exynos4.dtsi | 12 
 1 file changed, 12 insertions(+)

diff --git a/arch/arm/boot/dts/exynos4.dtsi b/arch/arm/boot/dts/exynos4.dtsi
index e20cdc2..8776db9 100644
--- a/arch/arm/boot/dts/exynos4.dtsi
+++ b/arch/arm/boot/dts/exynos4.dtsi
@@ -704,6 +704,18 @@
status = disabled;
};
 
+   hdmicec: cec@100B {
+   compatible = samsung,s5p-cec;
+   reg = 0x100B 0x200;
+   interrupts = 0 114 0;
+   clocks = clock CLK_HDMI_CEC;
+   clock-names = hdmicec;
+   samsung,syscon-phandle = pmu_system_controller;
+   pinctrl-names = default;
+   pinctrl-0 = hdmi_cec;
+   status = disabled;
+   };
+
mixer: mixer@12C1 {
compatible = samsung,exynos4210-mixer;
interrupts = 0 91 0;
-- 
2.1.4

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


[PATCHv7 01/15] dts: exynos4*: add HDMI CEC pin definition to pinctrl

2015-06-29 Thread Hans Verkuil
From: Kamil Debski ka...@wypas.org

Add pinctrl nodes for the HDMI CEC device to the Exynos4210 and
Exynos4x12 SoCs. These are required by the HDMI CEC device.

Signed-off-by: Kamil Debski ka...@wypas.org
Signed-off-by: Hans Verkuil hans.verk...@cisco.com
Acked-by: Krzysztof Kozlowski k.kozlow...@samsung.com
---
 arch/arm/boot/dts/exynos4210-pinctrl.dtsi | 7 +++
 arch/arm/boot/dts/exynos4x12-pinctrl.dtsi | 7 +++
 2 files changed, 14 insertions(+)

diff --git a/arch/arm/boot/dts/exynos4210-pinctrl.dtsi 
b/arch/arm/boot/dts/exynos4210-pinctrl.dtsi
index a7c2128..9331c62 100644
--- a/arch/arm/boot/dts/exynos4210-pinctrl.dtsi
+++ b/arch/arm/boot/dts/exynos4210-pinctrl.dtsi
@@ -820,6 +820,13 @@
samsung,pin-pud = 1;
samsung,pin-drv = 0;
};
+
+   hdmi_cec: hdmi-cec {
+   samsung,pins = gpx3-6;
+   samsung,pin-function = 3;
+   samsung,pin-pud = 0;
+   samsung,pin-drv = 0;
+   };
};
 
pinctrl@0386 {
diff --git a/arch/arm/boot/dts/exynos4x12-pinctrl.dtsi 
b/arch/arm/boot/dts/exynos4x12-pinctrl.dtsi
index c141931..875464e 100644
--- a/arch/arm/boot/dts/exynos4x12-pinctrl.dtsi
+++ b/arch/arm/boot/dts/exynos4x12-pinctrl.dtsi
@@ -885,6 +885,13 @@
samsung,pin-pud = 0;
samsung,pin-drv = 0;
};
+
+   hdmi_cec: hdmi-cec {
+   samsung,pins = gpx3-6;
+   samsung,pin-function = 3;
+   samsung,pin-pud = 0;
+   samsung,pin-drv = 0;
+   };
};
 
pinctrl@0386 {
-- 
2.1.4

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


[PATCHv7 03/15] dts: exynos4412-odroid*: enable the HDMI CEC device

2015-06-29 Thread Hans Verkuil
From: Kamil Debski ka...@wypas.org

Add a dts node entry and enable the HDMI CEC device present in the Exynos4
family of SoCs.

Signed-off-by: Kamil Debski ka...@wypas.org
Signed-off-by: Hans Verkuil hans.verk...@cisco.com
Acked-by: Krzysztof Kozlowski k.kozlow...@samsung.com
---
 arch/arm/boot/dts/exynos4412-odroid-common.dtsi | 4 
 1 file changed, 4 insertions(+)

diff --git a/arch/arm/boot/dts/exynos4412-odroid-common.dtsi 
b/arch/arm/boot/dts/exynos4412-odroid-common.dtsi
index d6b49e5..a97362a 100644
--- a/arch/arm/boot/dts/exynos4412-odroid-common.dtsi
+++ b/arch/arm/boot/dts/exynos4412-odroid-common.dtsi
@@ -472,6 +472,10 @@
status = okay;
};
 
+   cec@100B {
+   status = okay;
+   };
+
hdmi_ddc: i2c@1388 {
status = okay;
pinctrl-names = default;
-- 
2.1.4

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


[PATCHv7 04/15] HID: add HDMI CEC specific keycodes

2015-06-29 Thread Hans Verkuil
From: Kamil Debski ka...@wypas.org

Add HDMI CEC specific keycodes to the keycodes definition.

Signed-off-by: Kamil Debski ka...@wypas.org
Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 include/uapi/linux/input.h | 12 
 1 file changed, 12 insertions(+)

diff --git a/include/uapi/linux/input.h b/include/uapi/linux/input.h
index 731417c..7430a3f 100644
--- a/include/uapi/linux/input.h
+++ b/include/uapi/linux/input.h
@@ -752,6 +752,18 @@ struct input_keymap_entry {
 #define KEY_KBDINPUTASSIST_ACCEPT  0x264
 #define KEY_KBDINPUTASSIST_CANCEL  0x265
 
+#define KEY_RIGHT_UP   0x266
+#define KEY_RIGHT_DOWN 0x267
+#define KEY_LEFT_UP0x268
+#define KEY_LEFT_DOWN  0x269
+
+#define KEY_NEXT_FAVORITE  0x270
+#define KEY_STOP_RECORD0x271
+#define KEY_PAUSE_RECORD   0x272
+#define KEY_VOD0x273
+#define KEY_UNMUTE 0x274
+#define KEY_DVB0x275
+
 #define BTN_TRIGGER_HAPPY  0x2c0
 #define BTN_TRIGGER_HAPPY1 0x2c0
 #define BTN_TRIGGER_HAPPY2 0x2c1
-- 
2.1.4

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


[PATCHv7 15/15] cobalt: add cec support

2015-06-29 Thread Hans Verkuil
Add CEC support to the cobalt driver.

Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/pci/cobalt/cobalt-driver.c |  37 +--
 drivers/media/pci/cobalt/cobalt-driver.h |   2 +
 drivers/media/pci/cobalt/cobalt-v4l2.c   | 110 +--
 3 files changed, 138 insertions(+), 11 deletions(-)

diff --git a/drivers/media/pci/cobalt/cobalt-driver.c 
b/drivers/media/pci/cobalt/cobalt-driver.c
index b994b8e..a6d3644 100644
--- a/drivers/media/pci/cobalt/cobalt-driver.c
+++ b/drivers/media/pci/cobalt/cobalt-driver.c
@@ -76,6 +76,7 @@ static u8 edid[256] = {
0x0A, 0x0A, 0x0A, 0x0A, 0x00, 0x00, 0x00, 0x10,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x68,
+
0x02, 0x03, 0x1a, 0xc0, 0x48, 0xa2, 0x10, 0x04,
0x02, 0x01, 0x21, 0x14, 0x13, 0x23, 0x09, 0x07,
0x07, 0x65, 0x03, 0x0c, 0x00, 0x10, 0x00, 0xe2,
@@ -149,17 +150,44 @@ static void cobalt_notify(struct v4l2_subdev *sd,
struct cobalt *cobalt = to_cobalt(sd-v4l2_dev);
unsigned sd_nr = cobalt_get_sd_nr(sd);
struct cobalt_stream *s = cobalt-streams[sd_nr];
-   bool hotplug = arg ? *((int *)arg) : false;
 
-   if (s-is_output)
+   switch (notification) {
+   case V4L2_SUBDEV_CEC_TX_DONE:
+   cec_transmit_done(s-cec_adap, (unsigned long)arg);
+   return;
+   case V4L2_SUBDEV_CEC_RX_MSG:
+   cec_received_msg(s-cec_adap, arg);
+   return;
+   default:
+   break;
+   }
+
+   if (s-is_output) {
+   switch (notification) {
+   case ADV7511_EDID_DETECT: {
+   struct adv7511_edid_detect *ed = arg;
+
+   s-cec_adap.phys_addr = ed-phys_addr;
+   if (!ed-present) {
+   cec_enable(s-cec_adap, false);
+   break;
+   }
+   cec_enable(s-cec_adap, true);
+   break;
+   }
+   }
return;
+   }
 
switch (notification) {
-   case ADV76XX_HOTPLUG:
+   case ADV76XX_HOTPLUG: {
+   bool hotplug = arg ? *((int *)arg) : false;
+
cobalt_s_bit_sysctrl(cobalt,
COBALT_SYS_CTRL_HPD_TO_CONNECTOR_BIT(sd_nr), hotplug);
cobalt_dbg(1, Set hotplug for adv %d to %d\n, sd_nr, hotplug);
break;
+   }
case V4L2_DEVICE_NOTIFY_EVENT:
cobalt_dbg(1, Format changed for adv %d\n, sd_nr);
v4l2_event_queue(s-vdev, arg);
@@ -626,8 +654,9 @@ static int cobalt_subdevs_hsma_init(struct cobalt *cobalt)
s-sd = v4l2_i2c_new_subdev_board(cobalt-v4l2_dev,
s-i2c_adap, adv7842_info, NULL);
if (s-sd) {
-   int err = v4l2_subdev_call(s-sd, pad, set_edid, cobalt_edid);
+   int err;
 
+   err = v4l2_subdev_call(s-sd, pad, set_edid, cobalt_edid);
if (err)
return err;
err = v4l2_subdev_call(s-sd, pad, set_fmt, NULL,
diff --git a/drivers/media/pci/cobalt/cobalt-driver.h 
b/drivers/media/pci/cobalt/cobalt-driver.h
index c206df9..151c80f 100644
--- a/drivers/media/pci/cobalt/cobalt-driver.h
+++ b/drivers/media/pci/cobalt/cobalt-driver.h
@@ -31,6 +31,7 @@
 #include linux/workqueue.h
 #include linux/mutex.h
 
+#include media/cec.h
 #include media/v4l2-common.h
 #include media/v4l2-ioctl.h
 #include media/v4l2-device.h
@@ -221,6 +222,7 @@ struct cobalt_stream {
struct list_head bufs;
struct i2c_adapter *i2c_adap;
struct v4l2_subdev *sd;
+   struct cec_adapter cec_adap;
struct mutex lock;
spinlock_t irqlock;
struct v4l2_dv_timings timings;
diff --git a/drivers/media/pci/cobalt/cobalt-v4l2.c 
b/drivers/media/pci/cobalt/cobalt-v4l2.c
index b40c2d1..b37bfd5 100644
--- a/drivers/media/pci/cobalt/cobalt-v4l2.c
+++ b/drivers/media/pci/cobalt/cobalt-v4l2.c
@@ -1156,6 +1156,69 @@ static const struct v4l2_file_operations 
cobalt_empty_fops = {
.release = v4l2_fh_release,
 };
 
+static inline struct v4l2_subdev *adap_to_sd(struct cec_adapter *adap)
+{
+   struct cobalt_stream *s = container_of(adap, struct cobalt_stream, 
cec_adap);
+
+   return s-sd;
+}
+
+static int cobalt_cec_enable(struct cec_adapter *adap, bool enable)
+{
+   return v4l2_subdev_call(adap_to_sd(adap), video, cec_enable, enable);
+}
+
+static int cobalt_cec_log_addr(struct cec_adapter *adap, u8 log_addr)
+{
+   return v4l2_subdev_call(adap_to_sd(adap), video, cec_log_addr,
+   log_addr);
+}
+
+static int cobalt_cec_transmit(struct cec_adapter *adap, struct cec_msg *msg)
+{
+   return v4l2_subdev_call(adap_to_sd(adap), video, cec_transmit, msg);
+}
+
+static void cobalt_cec_transmit_timed_out(struct cec_adapter *adap

[PATCHv7 13/15] cec: adv7511: add cec support.

2015-06-29 Thread Hans Verkuil
Add CEC support to the adv7511 driver.

Signed-off-by: Hans Verkuil hansv...@cisco.com
[k.deb...@samsung.com: Merged changes from CEC Updates commit by Hans Verkuil]
Signed-off-by: Kamil Debski ka...@wypas.org
Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 drivers/media/i2c/adv7511.c | 350 +++-
 include/media/adv7511.h |   6 +-
 2 files changed, 345 insertions(+), 11 deletions(-)

diff --git a/drivers/media/i2c/adv7511.c b/drivers/media/i2c/adv7511.c
index 95bcd40..a0166c7 100644
--- a/drivers/media/i2c/adv7511.c
+++ b/drivers/media/i2c/adv7511.c
@@ -33,6 +33,7 @@
 #include media/v4l2-ctrls.h
 #include media/v4l2-dv-timings.h
 #include media/adv7511.h
+#include media/cec.h
 
 static int debug;
 module_param(debug, int, 0644);
@@ -59,6 +60,8 @@ MODULE_LICENSE(GPL);
 #define ADV7511_MIN_PIXELCLOCK 2000
 #define ADV7511_MAX_PIXELCLOCK 22500
 
+#define ADV7511_MAX_ADDRS (3)
+
 /*
 **
 *
@@ -90,8 +93,14 @@ struct adv7511_state {
struct v4l2_ctrl_handler hdl;
int chip_revision;
u8 i2c_edid_addr;
-   u8 i2c_cec_addr;
u8 i2c_pktmem_addr;
+   u8 i2c_cec_addr;
+
+   struct i2c_client *i2c_cec;
+   u8   cec_addr[ADV7511_MAX_ADDRS];
+   u8   cec_valid_addrs;
+   bool cec_enabled_adap;
+
/* Is the adv7511 powered on? */
bool power_on;
/* Did we receive hotplug and rx-sense signals? */
@@ -225,7 +234,7 @@ static int adv_smbus_read_i2c_block_data(struct i2c_client 
*client,
return ret;
 }
 
-static inline void adv7511_edid_rd(struct v4l2_subdev *sd, u16 len, u8 *buf)
+static void adv7511_edid_rd(struct v4l2_subdev *sd, uint16_t len, uint8_t *buf)
 {
struct adv7511_state *state = get_adv7511_state(sd);
int i;
@@ -240,6 +249,34 @@ static inline void adv7511_edid_rd(struct v4l2_subdev *sd, 
u16 len, u8 *buf)
v4l2_err(sd, %s: i2c read error\n, __func__);
 }
 
+static inline int adv7511_cec_read(struct v4l2_subdev *sd, u8 reg)
+{
+   struct adv7511_state *state = get_adv7511_state(sd);
+
+   return i2c_smbus_read_byte_data(state-i2c_cec, reg);
+}
+
+static int adv7511_cec_write(struct v4l2_subdev *sd, u8 reg, u8 val)
+{
+   struct adv7511_state *state = get_adv7511_state(sd);
+   int ret;
+   int i;
+
+   for (i = 0; i  3; i++) {
+   ret = i2c_smbus_write_byte_data(state-i2c_cec, reg, val);
+   if (ret == 0)
+   return 0;
+   }
+   v4l2_err(sd, %s: I2C Write Problem\n, __func__);
+   return ret;
+}
+
+static inline int adv7511_cec_write_and_or(struct v4l2_subdev *sd, u8 reg, u8 
mask,
+  u8 val)
+{
+   return adv7511_cec_write(sd, reg, (adv7511_cec_read(sd, reg)  mask) | 
val);
+}
+
 static int adv7511_pktmem_rd(struct v4l2_subdev *sd, u8 reg)
 {
struct adv7511_state *state = get_adv7511_state(sd);
@@ -413,16 +450,28 @@ static const struct v4l2_ctrl_ops adv7511_ctrl_ops = {
 #ifdef CONFIG_VIDEO_ADV_DEBUG
 static void adv7511_inv_register(struct v4l2_subdev *sd)
 {
+   struct adv7511_state *state = get_adv7511_state(sd);
+
v4l2_info(sd, 0x000-0x0ff: Main Map\n);
+   if (state-i2c_cec)
+   v4l2_info(sd, 0x100-0x1ff: CEC Map\n);
 }
 
 static int adv7511_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register 
*reg)
 {
+   struct adv7511_state *state = get_adv7511_state(sd);
+
reg-size = 1;
switch (reg-reg  8) {
case 0:
reg-val = adv7511_rd(sd, reg-reg  0xff);
break;
+   case 1:
+   if (state-i2c_cec) {
+   reg-val = adv7511_cec_read(sd, reg-reg  0xff);
+   break;
+   }
+   /* fall through */
default:
v4l2_info(sd, Register %03llx not supported\n, reg-reg);
adv7511_inv_register(sd);
@@ -433,10 +482,18 @@ static int adv7511_g_register(struct v4l2_subdev *sd, 
struct v4l2_dbg_register *
 
 static int adv7511_s_register(struct v4l2_subdev *sd, const struct 
v4l2_dbg_register *reg)
 {
+   struct adv7511_state *state = get_adv7511_state(sd);
+
switch (reg-reg  8) {
case 0:
adv7511_wr(sd, reg-reg  0xff, reg-val  0xff);
break;
+   case 1:
+   if (state-i2c_cec) {
+   adv7511_cec_write(sd, reg-reg  0xff, reg-val  0xff);
+   break;
+   }
+   /* fall through */
default:
v4l2_info(sd, Register %03llx not supported\n, reg-reg);
adv7511_inv_register(sd);
@@ -524,6 +581,7 @@ static int adv7511_log_status(struct v4l2_subdev *sd)
 {
struct adv7511_state *state = get_adv7511_state(sd);
struct adv7511_state_edid *edid = state-edid;
+   int i;
 
static const char * const states

[PATCHv7 14/15] cec: s5p-cec: Add s5p-cec driver

2015-06-29 Thread Hans Verkuil
From: Kamil Debski ka...@wypas.org

Add CEC interface driver present in the Samsung Exynos range of
SoCs.

The following files were based on work by SangPil Moon:
- exynos_hdmi_cec.h
- exynos_hdmi_cecctl.c

Signed-off-by: Kamil Debski ka...@wypas.org
Signed-off-by: Hans Verkuil hans.verk...@cisco.com
---
 .../devicetree/bindings/media/s5p-cec.txt  |  31 +++
 drivers/media/platform/Kconfig |  10 +
 drivers/media/platform/Makefile|   1 +
 drivers/media/platform/s5p-cec/Makefile|   2 +
 drivers/media/platform/s5p-cec/exynos_hdmi_cec.h   |  37 +++
 .../media/platform/s5p-cec/exynos_hdmi_cecctrl.c   | 208 +++
 drivers/media/platform/s5p-cec/regs-cec.h  |  96 +++
 drivers/media/platform/s5p-cec/s5p_cec.c   | 283 +
 drivers/media/platform/s5p-cec/s5p_cec.h   |  76 ++
 9 files changed, 744 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/s5p-cec.txt
 create mode 100644 drivers/media/platform/s5p-cec/Makefile
 create mode 100644 drivers/media/platform/s5p-cec/exynos_hdmi_cec.h
 create mode 100644 drivers/media/platform/s5p-cec/exynos_hdmi_cecctrl.c
 create mode 100644 drivers/media/platform/s5p-cec/regs-cec.h
 create mode 100644 drivers/media/platform/s5p-cec/s5p_cec.c
 create mode 100644 drivers/media/platform/s5p-cec/s5p_cec.h

diff --git a/Documentation/devicetree/bindings/media/s5p-cec.txt 
b/Documentation/devicetree/bindings/media/s5p-cec.txt
new file mode 100644
index 000..da63a4c
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/s5p-cec.txt
@@ -0,0 +1,31 @@
+* Samsung HDMI CEC driver
+
+The HDMI CEC module is present is Samsung SoCs and its purpose is to
+handle communication between HDMI connected devices over the CEC bus.
+
+Required properties:
+  - compatible : value should be follwoing
+   samsung,s5p-cec
+
+  - reg : Physical base address of the IP registers and length of memory
+ mapped region.
+
+  - interrupts : HDMI CEC interrupt number to the CPU.
+  - clocks : from common clock binding: handle to HDMI CEC clock.
+  - clock-names : from common clock binding: must contain hdmicec,
+ corresponding to entry in the clocks property.
+  - samsung,syscon-phandle - phandle to the PMU system controller
+
+Example:
+
+hdmicec: cec@100B {
+   compatible = samsung,s5p-cec;
+   reg = 0x100B 0x200;
+   interrupts = 0 114 0;
+   clocks = clock CLK_HDMI_CEC;
+   clock-names = hdmicec;
+   samsung,syscon-phandle = pmu_system_controller;
+   pinctrl-names = default;
+   pinctrl-0 = hdmi_cec;
+   status = okay;
+};
diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index 4776a8c..d3843fc 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -157,6 +157,16 @@ config VIDEO_MEM2MEM_DEINTERLACE
help
Generic deinterlacing V4L2 driver.
 
+config VIDEO_SAMSUNG_S5P_CEC
+   tristate Samsung S5P CEC driver
+   depends on CEC  VIDEO_DEV  VIDEO_V4L2  (PLAT_S5P || ARCH_EXYNOS)
+   default n
+   ---help---
+ This is a driver for Samsung S5P HDMI CEC interface. It uses the
+ generic CEC framework interface.
+ CEC bus is present in the HDMI connector and enables communication
+ between compatible devices.
+
 config VIDEO_SAMSUNG_S5P_G2D
tristate Samsung S5P and EXYNOS4 G2D 2d graphics accelerator driver
depends on VIDEO_DEV  VIDEO_V4L2
diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile
index 114f9ab..95dd78d 100644
--- a/drivers/media/platform/Makefile
+++ b/drivers/media/platform/Makefile
@@ -27,6 +27,7 @@ obj-$(CONFIG_VIDEO_MEM2MEM_DEINTERLACE)   += 
m2m-deinterlace.o
 
 obj-$(CONFIG_VIDEO_S3C_CAMIF)  += s3c-camif/
 obj-$(CONFIG_VIDEO_SAMSUNG_EXYNOS4_IS) += exynos4-is/
+obj-$(CONFIG_VIDEO_SAMSUNG_S5P_CEC)+= s5p-cec/
 obj-$(CONFIG_VIDEO_SAMSUNG_S5P_JPEG)   += s5p-jpeg/
 obj-$(CONFIG_VIDEO_SAMSUNG_S5P_MFC)+= s5p-mfc/
 obj-$(CONFIG_VIDEO_SAMSUNG_S5P_TV) += s5p-tv/
diff --git a/drivers/media/platform/s5p-cec/Makefile 
b/drivers/media/platform/s5p-cec/Makefile
new file mode 100644
index 000..0e2cf45
--- /dev/null
+++ b/drivers/media/platform/s5p-cec/Makefile
@@ -0,0 +1,2 @@
+obj-$(CONFIG_VIDEO_SAMSUNG_S5P_CEC)+= s5p-cec.o
+s5p-cec-y += s5p_cec.o exynos_hdmi_cecctrl.o
diff --git a/drivers/media/platform/s5p-cec/exynos_hdmi_cec.h 
b/drivers/media/platform/s5p-cec/exynos_hdmi_cec.h
new file mode 100644
index 000..d008695
--- /dev/null
+++ b/drivers/media/platform/s5p-cec/exynos_hdmi_cec.h
@@ -0,0 +1,37 @@
+/* drivers/media/platform/s5p-cec/exynos_hdmi_cec.h
+ *
+ * Copyright (c) 2010, 2014 Samsung Electronics
+ * http://www.samsung.com/
+ *
+ * Header file for interface of Samsung Exynos hdmi cec hardware
+ *
+ * This program is free software; you can redistribute it and/or modify

  1   2   >