[PATCH v7] rockchip/rga: v4l2 m2m support

2017-08-02 Thread Jacob Chen
Rockchip RGA is a separate 2D raster graphic acceleration unit. It
accelerates 2D graphics operations, such as point/line drawing, image
scaling, rotation, BitBLT, alpha blending and image blur/sharpness

The drvier is mostly based on s5p-g2d v4l2 m2m driver
And supports various operations from the rendering pipeline.
 - copy
 - fast solid color fill
 - rotation
 - flip
 - alpha blending

The code in rga-hw.c is used to configure regs according to operations
The code in rga-buf.c is used to create private mmu table for RGA.

changes in V7:
- fix some warning reported by "checkpatch --strict"

Signed-off-by: Jacob Chen 
---
 drivers/media/platform/Kconfig|   11 +
 drivers/media/platform/Makefile   |2 +
 drivers/media/platform/rockchip-rga/Makefile  |3 +
 drivers/media/platform/rockchip-rga/rga-buf.c |  155 
 drivers/media/platform/rockchip-rga/rga-hw.c  |  670 
 drivers/media/platform/rockchip-rga/rga-hw.h  |  437 +++
 drivers/media/platform/rockchip-rga/rga.c | 1026 +
 drivers/media/platform/rockchip-rga/rga.h |  110 +++
 8 files changed, 2414 insertions(+)
 create mode 100644 drivers/media/platform/rockchip-rga/Makefile
 create mode 100644 drivers/media/platform/rockchip-rga/rga-buf.c
 create mode 100644 drivers/media/platform/rockchip-rga/rga-hw.c
 create mode 100644 drivers/media/platform/rockchip-rga/rga-hw.h
 create mode 100644 drivers/media/platform/rockchip-rga/rga.c
 create mode 100644 drivers/media/platform/rockchip-rga/rga.h

diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index 041cb80a..d0d1a21 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -427,6 +427,17 @@ config VIDEO_RENESAS_VSP1
  To compile this driver as a module, choose M here: the module
  will be called vsp1.
 
+config VIDEO_ROCKCHIP_RGA
+   tristate "Rockchip Raster 2d Grapphic Acceleration Unit"
+   depends on VIDEO_DEV && VIDEO_V4L2 && HAS_DMA
+   depends on ARCH_ROCKCHIP || COMPILE_TEST
+   select VIDEOBUF2_DMA_SG
+   select V4L2_MEM2MEM_DEV
+   default n
+   ---help---
+ This is a v4l2 driver for Rockchip SOC RGA2
+ 2d graphics accelerator.
+
 config VIDEO_TI_VPE
tristate "TI VPE (Video Processing Engine) driver"
depends on VIDEO_DEV && VIDEO_V4L2
diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile
index 63303d6..baf83060 100644
--- a/drivers/media/platform/Makefile
+++ b/drivers/media/platform/Makefile
@@ -57,6 +57,8 @@ obj-$(CONFIG_VIDEO_RENESAS_FDP1)  += rcar_fdp1.o
 obj-$(CONFIG_VIDEO_RENESAS_JPU)+= rcar_jpu.o
 obj-$(CONFIG_VIDEO_RENESAS_VSP1)   += vsp1/
 
+obj-$(CONFIG_VIDEO_ROCKCHIP_RGA)   += rockchip-rga/
+
 obj-y  += omap/
 
 obj-$(CONFIG_VIDEO_AM437X_VPFE)+= am437x/
diff --git a/drivers/media/platform/rockchip-rga/Makefile 
b/drivers/media/platform/rockchip-rga/Makefile
new file mode 100644
index 000..92fe254
--- /dev/null
+++ b/drivers/media/platform/rockchip-rga/Makefile
@@ -0,0 +1,3 @@
+rockchip-rga-objs := rga.o rga-hw.o rga-buf.o
+
+obj-$(CONFIG_VIDEO_ROCKCHIP_RGA) += rockchip-rga.o
diff --git a/drivers/media/platform/rockchip-rga/rga-buf.c 
b/drivers/media/platform/rockchip-rga/rga-buf.c
new file mode 100644
index 000..6a9fd2c
--- /dev/null
+++ b/drivers/media/platform/rockchip-rga/rga-buf.c
@@ -0,0 +1,155 @@
+/*
+ * Copyright (C) 2017 Fuzhou Rockchip Electronics Co.Ltd
+ * Author: Jacob Chen 
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * 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 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "rga-hw.h"
+#include "rga.h"
+
+static int
+rga_queue_setup(struct vb2_queue *vq,
+   unsigned int *nbuffers, unsigned int *nplanes,
+   unsigned int sizes[], struct device *alloc_devs[])
+{
+   struct rga_ctx *ctx = vb2_get_drv_priv(vq);
+   struct rga_frame *f = rga_get_frame(ctx, vq->type);
+
+   if (IS_ERR(f))
+   return PTR_ERR(f);
+
+   if (*nplanes)
+   return sizes[0] < f->size ? -EINVAL : 0;
+
+   sizes[0] = f->size;
+   *nplanes = 1;
+
+   return 0;
+}
+
+static int rga_buf_prepare(struct vb2_buffer *vb)
+{
+   struct rga_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
+   struct rga_frame *f = rga_get_frame(ctx, vb->vb2_queue->type);
+
+   if (IS_ERR(f))
+   return PTR_ERR(f);
+
+   vb2_set_plane_payload(vb, 0, f->size);
+
+   return 0;
+}
+
+static void rga_buf_queu

cron job: media_tree daily build: ERRORS

2017-08-02 Thread Hans Verkuil
This message is generated daily by a cron job that builds media_tree for
the kernels and architectures in the list below.

Results of the daily build of media_tree:

date:   Thu Aug  3 05:00:16 CEST 2017
media-tree git hash:da48c948c263c9d87dfc64566b3373a858cc8aa2
media_build git hash:   f01a9176bb03f22e3cd3b70282bd7fd272e504ae
v4l-utils git hash: 98c162029eb1a21b39028180ac5d36b544a9493c
gcc version:i686-linux-gcc (GCC) 7.1.0
sparse version: v0.5.0
smatch version: v0.5.0-3553-g78b2ea6
host hardware:  x86_64
host os:4.11.0-164

linux-git-arm-at91: OK
linux-git-arm-davinci: OK
linux-git-arm-multi: WARNINGS
linux-git-arm-pxa: OK
linux-git-arm-stm32: OK
linux-git-blackfin-bf561: OK
linux-git-i686: OK
linux-git-m32r: OK
linux-git-mips: OK
linux-git-powerpc64: OK
linux-git-sh: OK
linux-git-x86_64: OK
linux-2.6.36.4-i686: WARNINGS
linux-2.6.37.6-i686: WARNINGS
linux-2.6.38.8-i686: WARNINGS
linux-2.6.39.4-i686: WARNINGS
linux-3.0.60-i686: WARNINGS
linux-3.1.10-i686: WARNINGS
linux-3.2.37-i686: WARNINGS
linux-3.3.8-i686: WARNINGS
linux-3.4.27-i686: ERRORS
linux-3.5.7-i686: WARNINGS
linux-3.6.11-i686: WARNINGS
linux-3.7.4-i686: WARNINGS
linux-3.8-i686: WARNINGS
linux-3.9.2-i686: WARNINGS
linux-3.10.1-i686: WARNINGS
linux-3.11.1-i686: WARNINGS
linux-3.12.67-i686: WARNINGS
linux-3.13.11-i686: WARNINGS
linux-3.14.9-i686: WARNINGS
linux-3.15.2-i686: WARNINGS
linux-3.16.7-i686: WARNINGS
linux-3.17.8-i686: ERRORS
linux-3.18.7-i686: ERRORS
linux-3.19-i686: WARNINGS
linux-4.0.9-i686: WARNINGS
linux-4.1.33-i686: WARNINGS
linux-4.2.8-i686: WARNINGS
linux-4.3.6-i686: WARNINGS
linux-4.4.22-i686: WARNINGS
linux-4.5.7-i686: WARNINGS
linux-4.6.7-i686: WARNINGS
linux-4.7.5-i686: WARNINGS
linux-4.8-i686: OK
linux-4.9.26-i686: OK
linux-4.10.14-i686: OK
linux-4.11-i686: OK
linux-4.12.1-i686: OK
linux-2.6.36.4-x86_64: WARNINGS
linux-2.6.37.6-x86_64: WARNINGS
linux-2.6.38.8-x86_64: WARNINGS
linux-2.6.39.4-x86_64: WARNINGS
linux-3.0.60-x86_64: WARNINGS
linux-3.1.10-x86_64: WARNINGS
linux-3.2.37-x86_64: WARNINGS
linux-3.3.8-x86_64: WARNINGS
linux-3.4.27-x86_64: ERRORS
linux-3.5.7-x86_64: WARNINGS
linux-3.6.11-x86_64: WARNINGS
linux-3.7.4-x86_64: WARNINGS
linux-3.8-x86_64: WARNINGS
linux-3.9.2-x86_64: WARNINGS
linux-3.10.1-x86_64: WARNINGS
linux-3.11.1-x86_64: WARNINGS
linux-3.12.67-x86_64: WARNINGS
linux-3.13.11-x86_64: WARNINGS
linux-3.14.9-x86_64: WARNINGS
linux-3.15.2-x86_64: WARNINGS
linux-3.16.7-x86_64: WARNINGS
linux-3.17.8-x86_64: WARNINGS
linux-3.18.7-x86_64: WARNINGS
linux-3.19-x86_64: WARNINGS
linux-4.0.9-x86_64: WARNINGS
linux-4.1.33-x86_64: WARNINGS
linux-4.2.8-x86_64: WARNINGS
linux-4.3.6-x86_64: WARNINGS
linux-4.4.22-x86_64: WARNINGS
linux-4.5.7-x86_64: WARNINGS
linux-4.6.7-x86_64: WARNINGS
linux-4.7.5-x86_64: WARNINGS
linux-4.8-x86_64: WARNINGS
linux-4.9.26-x86_64: WARNINGS
linux-4.10.14-x86_64: WARNINGS
linux-4.11-x86_64: WARNINGS
linux-4.12.1-x86_64: WARNINGS
apps: WARNINGS
spec-git: OK
sparse: ERRORS

Detailed results are available here:

http://www.xs4all.nl/~hverkuil/logs/Thursday.log

Full logs are available here:

http://www.xs4all.nl/~hverkuil/logs/Thursday.tar.bz2

The Media Infrastructure API from this daily build is here:

http://www.xs4all.nl/~hverkuil/spec/index.html


[PATCH] [media] v4l2-compat-ioctl32: Fix timespec conversion

2017-08-02 Thread Daniel Mentz
Certain syscalls like recvmmsg support 64 bit timespec values for the
X32 ABI. The helper function compat_put_timespec converts a timespec
value to a 32 bit or 64 bit value depending on what ABI is used. The
v4l2 compat layer, however, is not designed to support 64 bit timespec
values and always uses 32 bit values. Hence, compat_put_timespec must
not be used.

Without this patch, user space will be provided with bad timestamp
values from the VIDIOC_DQEVENT ioctl. Also, fields of the struct
v4l2_event32 that come immediately after timestamp get overwritten,
namely the field named id.

Fixes: 81993e81a994 ("compat: Get rid of (get|put)_compat_time(val|spec)")
Cc: sta...@vger.kernel.org
Cc: H. Peter Anvin 
Cc: Hans Verkuil 
Cc: Laurent Pinchart 
Cc: Tiffany Lin 
Cc: Ricardo Ribalda Delgado 
Cc: Sakari Ailus 
Signed-off-by: Daniel Mentz 
---
 drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c 
b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
index 6f52970f8b54..0c14e995667c 100644
--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
@@ -796,7 +796,8 @@ static int put_v4l2_event32(struct v4l2_event *kp, struct 
v4l2_event32 __user *u
copy_to_user(&up->u, &kp->u, sizeof(kp->u)) ||
put_user(kp->pending, &up->pending) ||
put_user(kp->sequence, &up->sequence) ||
-   compat_put_timespec(&kp->timestamp, &up->timestamp) ||
+   put_user(kp->timestamp.tv_sec, &up->timestamp.tv_sec) ||
+   put_user(kp->timestamp.tv_nsec, &up->timestamp.tv_nsec) ||
put_user(kp->id, &up->id) ||
copy_to_user(up->reserved, kp->reserved, 8 * sizeof(__u32)))
return -EFAULT;
-- 
2.14.0.rc1.383.gd1ce394fe2-goog



Revisiting the Digiflower DVR2000B capture card

2017-08-02 Thread Perry Gilfillan
Many years ago when the 2.6 kernel was all the rage I had a working 
patch to support this card:


https://wiki.zoneminder.com/Digiflower

With the latest Fedora 26 kernel sources with the following patch 
applied, the wired input and logical source are scrambled and I don't 
know what changed.


FanoutFanout
Input  Camera  Source Input  Camera  Source
1  .   videoX(??)  9 .   videoX(??)
2  .   videoX(4)  10 .   videoX(12)
3  porch   videoX(3)  11 solar videoX(11)
4  .   videoX(2)  12 .   videoX(10)
5  .   videoX(1)  13 .   videoX(9)
6  .   videoX(0)  14 .   videoX(8)
7  .   videoX(6)  15 south   videoX(13)
8  north   videoX(5)  16 .   videoX(14)

Inputs 1 and 9 (Source 7 and 15) simply don't work at all, and they are 
all out of order.


What am I not doing, or what changed?

Any help will be much appreciated!



--- media_build/linux/drivers/media/pci/bt8xx/bttv-cards.c 2016-12-24 
19:07:32.963090964 -0600
+++ media_build.digiflower/linux/drivers/media/pci/bt8xx/bttv-cards.c 
2016-12-24 16:58:34.689715697 -0600

@@ -90,6 +90,8 @@ static void identify_by_eeprom(struct bt
unsigned char eeprom_data[256]);
 static int pvr_boot(struct bttv *btv);

+static void digiflower_dvr2000b_muxsel(struct bttv *btv, unsigned int 
input);

+
 /* config variables */
 static unsigned int triton1;
 static unsigned int vsfx;
@@ -344,6 +346,7 @@ static struct CARD {
 { 0x15401837, BTTV_BOARD_PV183, "Provideo PV183-8" },
 { 0x3116f200, BTTV_BOARD_TVT_TD3116,"Tongwei Video Technology 
TD-3116" },

 { 0x02280279, BTTV_BOARD_APOSONIC_WDVR, "Aposonic W-DVR" },
+{ 0x, BTTV_BOARD_DIGIFLOWER_DVR2000B, "Digi-Flower DVR2000B" },
 { 0, -1, NULL }
 };

@@ -2885,6 +2888,25 @@ struct tvcard bttv_tvcards[] = {
 .no_tda7432= 1,
 .pll= PLL_35,
 },
+[BTTV_BOARD_DIGIFLOWER_DVR2000B] = {
+.name   = "Digi-Flower DVR2000B (master?)",
+.video_inputs   = 16,
+/* .audio_inputs   = 0, */
+/* .tuner  = UNSET, */
+.svhs   = NO_SVHS,
+.tuner_type= TUNER_ABSENT,
+.tuner_addr= ADDR_UNSET,
+/* .radio_addr= ADDR_UNSET, */
+.no_gpioirq= 1,
+//.gpiomask= 0x0,
+.gpiomask2= 0x140007,
+.muxsel= MUXSEL ( 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 
2, 2, 2, 2 ),

+.muxsel_hook= digiflower_dvr2000b_muxsel,
+.gpiomux= { 0, 0, 0, 0 }, /* card has no audio */
+.no_msp34xx= 1,
+.no_tda7432= 1,
+.pll= PLL_28,
+},
 };

 static const unsigned int bttv_num_tvcards = ARRAY_SIZE(bttv_tvcards);
@@ -4868,6 +4894,21 @@ static void gv800s_init(struct bttv *btv
 master[btv->c.nr+3] = btv;
 }

+/* DB1 = Top connector fan-out.  DB2 = Bottom connector fan-out. */
+#define DB10x10
+#define DB20x04
+
+static void digiflower_dvr2000b_muxsel(struct bttv *btv, unsigned int 
input)

+{
+static const int masks[] = {
+DB1,   DB1|1, DB1|2, DB1|3,
+DB1|4, DB1|5, DB1|6, DB1|7,
+DB2,   DB2|1, DB2|2, DB2|3,
+DB2|4, DB2|5, DB2|6, DB2|7,
+};
+gpio_write(masks[input%16]);
+}
+
 /* 
--- */
 /* motherboard chipset specific 
stuff  */


--- media_build/linux/drivers/media/pci/bt8xx/bttv.h 2016-08-22 
03:58:36.0 -0500
+++ media_build.digiflower/linux/drivers/media/pci/bt8xx/bttv.h 
2016-12-24 16:59:38.365786180 -0600

@@ -190,6 +190,7 @@
 #define BTTV_BOARD_CYBERVISION_CV060xa4
 #define BTTV_BOARD_KWORLD_VSTREAM_XPERT0xa5
 #define BTTV_BOARD_PCI_8604PW  0xa6
+#define BTTV_BOARD_DIGIFLOWER_DVR2000B 0xa7

 /* more card-specific defines */
 #define PT2254_L_CHANNEL 0x10



Re: [PATCH for v4.13] ARM: dts: exynos: add needs-hpd for Odroid-XU3/4

2017-08-02 Thread Krzysztof Kozlowski
On Mon, Jul 31, 2017 at 01:56:42PM +0200, Hans Verkuil wrote:
> CEC support was added for Exynos5 in 4.13, but for the Odroids we need to set
> 'needs-hpd' as well since CEC is disabled when there is no HDMI hotplug 
> signal,
> just as for the exynos4 Odroid-U3.
> 
> This is due to the level-shifter that is disabled when there is no HPD, thus
> blocking the CEC signal as well. Same close-but-no-cigar board design as the
> Odroid-U3.
> 
> Tested with my Odroid XU4.
> 
> Signed-off-by: Hans Verkuil 

Thanks, applied for v4.13.

Best regards,
Krzysztof



[PATCHv3 2/4] drm/bridge: dw-hdmi: add better clock disable control

2017-08-02 Thread Hans Verkuil
From: Russell King 

The video setup path aways sets the clock disable register to a specific
value, which has the effect of disabling the CEC engine.  When we add the
CEC driver, this becomes a problem.

Fix this by only setting/clearing the bits that the video path needs to.

Reviewed-by: Jose Abreu 
Signed-off-by: Russell King 
Acked-by: Hans Verkuil 
Tested-by: Hans Verkuil 
Tested-by: Laurent Pinchart 
---
 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c | 29 ++---
 1 file changed, 18 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c 
b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
index 108495862cac..0ac1e3240cc3 100644
--- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
+++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
@@ -166,6 +166,7 @@ struct dw_hdmi {
bool bridge_is_on;  /* indicates the bridge is on */
bool rxsense;   /* rxsense state */
u8 phy_mask;/* desired phy int mask settings */
+   u8 mc_clkdis;   /* clock disable register */
 
spinlock_t audio_lock;
struct mutex audio_mutex;
@@ -551,8 +552,11 @@ EXPORT_SYMBOL_GPL(dw_hdmi_set_sample_rate);
 
 static void hdmi_enable_audio_clk(struct dw_hdmi *hdmi, bool enable)
 {
-   hdmi_modb(hdmi, enable ? 0 : HDMI_MC_CLKDIS_AUDCLK_DISABLE,
- HDMI_MC_CLKDIS_AUDCLK_DISABLE, HDMI_MC_CLKDIS);
+   if (enable)
+   hdmi->mc_clkdis &= ~HDMI_MC_CLKDIS_AUDCLK_DISABLE;
+   else
+   hdmi->mc_clkdis |= HDMI_MC_CLKDIS_AUDCLK_DISABLE;
+   hdmi_writeb(hdmi, hdmi->mc_clkdis, HDMI_MC_CLKDIS);
 }
 
 static void dw_hdmi_ahb_audio_enable(struct dw_hdmi *hdmi)
@@ -1574,8 +1578,6 @@ static void hdmi_av_composer(struct dw_hdmi *hdmi,
 /* HDMI Initialization Step B.4 */
 static void dw_hdmi_enable_video_path(struct dw_hdmi *hdmi)
 {
-   u8 clkdis;
-
/* control period minimum duration */
hdmi_writeb(hdmi, 12, HDMI_FC_CTRLDUR);
hdmi_writeb(hdmi, 32, HDMI_FC_EXCTRLDUR);
@@ -1587,17 +1589,21 @@ static void dw_hdmi_enable_video_path(struct dw_hdmi 
*hdmi)
hdmi_writeb(hdmi, 0x21, HDMI_FC_CH2PREAM);
 
/* Enable pixel clock and tmds data path */
-   clkdis = 0x7F;
-   clkdis &= ~HDMI_MC_CLKDIS_PIXELCLK_DISABLE;
-   hdmi_writeb(hdmi, clkdis, HDMI_MC_CLKDIS);
+   hdmi->mc_clkdis |= HDMI_MC_CLKDIS_HDCPCLK_DISABLE |
+  HDMI_MC_CLKDIS_CSCCLK_DISABLE |
+  HDMI_MC_CLKDIS_AUDCLK_DISABLE |
+  HDMI_MC_CLKDIS_PREPCLK_DISABLE |
+  HDMI_MC_CLKDIS_TMDSCLK_DISABLE;
+   hdmi->mc_clkdis &= ~HDMI_MC_CLKDIS_PIXELCLK_DISABLE;
+   hdmi_writeb(hdmi, hdmi->mc_clkdis, HDMI_MC_CLKDIS);
 
-   clkdis &= ~HDMI_MC_CLKDIS_TMDSCLK_DISABLE;
-   hdmi_writeb(hdmi, clkdis, HDMI_MC_CLKDIS);
+   hdmi->mc_clkdis &= ~HDMI_MC_CLKDIS_TMDSCLK_DISABLE;
+   hdmi_writeb(hdmi, hdmi->mc_clkdis, HDMI_MC_CLKDIS);
 
/* Enable csc path */
if (is_color_space_conversion(hdmi)) {
-   clkdis &= ~HDMI_MC_CLKDIS_CSCCLK_DISABLE;
-   hdmi_writeb(hdmi, clkdis, HDMI_MC_CLKDIS);
+   hdmi->mc_clkdis &= ~HDMI_MC_CLKDIS_CSCCLK_DISABLE;
+   hdmi_writeb(hdmi, hdmi->mc_clkdis, HDMI_MC_CLKDIS);
}
 
/* Enable color space conversion if needed */
@@ -2272,6 +2278,7 @@ __dw_hdmi_probe(struct platform_device *pdev,
hdmi->disabled = true;
hdmi->rxsense = true;
hdmi->phy_mask = (u8)~(HDMI_PHY_HPD | HDMI_PHY_RX_SENSE);
+   hdmi->mc_clkdis = 0x7f;
 
mutex_init(&hdmi->mutex);
mutex_init(&hdmi->audio_mutex);
-- 
2.13.2



[PATCHv3 1/4] drm/bridge: dw-hdmi: add cec notifier support

2017-08-02 Thread Hans Verkuil
From: Russell King 

Add CEC notifier support to the HDMI bridge driver, so that the CEC
part of the IP can receive its physical address.

Signed-off-by: Russell King 
[hans.verkuil: added missing cec_notifier_put to remove()]
Acked-by: Hans Verkuil 
Tested-by: Hans Verkuil 
Tested-by: Laurent Pinchart 
---
 drivers/gpu/drm/bridge/synopsys/Kconfig   |  1 +
 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c | 25 -
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/bridge/synopsys/Kconfig 
b/drivers/gpu/drm/bridge/synopsys/Kconfig
index 53e78d092d18..351db000599a 100644
--- a/drivers/gpu/drm/bridge/synopsys/Kconfig
+++ b/drivers/gpu/drm/bridge/synopsys/Kconfig
@@ -2,6 +2,7 @@ config DRM_DW_HDMI
tristate
select DRM_KMS_HELPER
select REGMAP_MMIO
+   select CEC_CORE if CEC_NOTIFIER
 
 config DRM_DW_HDMI_AHB_AUDIO
tristate "Synopsys Designware AHB Audio interface"
diff --git a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c 
b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
index ead11242c4b9..108495862cac 100644
--- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
+++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.c
@@ -36,7 +36,10 @@
 #include "dw-hdmi.h"
 #include "dw-hdmi-audio.h"
 
+#include 
+
 #define DDC_SEGMENT_ADDR   0x30
+
 #define HDMI_EDID_LEN  512
 
 enum hdmi_datamap {
@@ -175,6 +178,8 @@ struct dw_hdmi {
struct regmap *regm;
void (*enable_audio)(struct dw_hdmi *hdmi);
void (*disable_audio)(struct dw_hdmi *hdmi);
+
+   struct cec_notifier *cec_notifier;
 };
 
 #define HDMI_IH_PHY_STAT0_RX_SENSE \
@@ -1896,6 +1901,7 @@ static int dw_hdmi_connector_get_modes(struct 
drm_connector *connector)
hdmi->sink_is_hdmi = drm_detect_hdmi_monitor(edid);
hdmi->sink_has_audio = drm_detect_monitor_audio(edid);
drm_mode_connector_update_edid_property(connector, edid);
+   cec_notifier_set_phys_addr_from_edid(hdmi->cec_notifier, edid);
ret = drm_add_edid_modes(connector, edid);
/* Store the ELD */
drm_edid_to_eld(connector, edid);
@@ -2119,11 +2125,16 @@ static irqreturn_t dw_hdmi_irq(int irq, void *dev_id)
 * ask the source to re-read the EDID.
 */
if (intr_stat &
-   (HDMI_IH_PHY_STAT0_RX_SENSE | HDMI_IH_PHY_STAT0_HPD))
+   (HDMI_IH_PHY_STAT0_RX_SENSE | HDMI_IH_PHY_STAT0_HPD)) {
__dw_hdmi_setup_rx_sense(hdmi,
 phy_stat & HDMI_PHY_HPD,
 phy_stat & HDMI_PHY_RX_SENSE);
 
+   if ((phy_stat & (HDMI_PHY_RX_SENSE | HDMI_PHY_HPD)) == 0)
+   cec_notifier_set_phys_addr(hdmi->cec_notifier,
+  CEC_PHYS_ADDR_INVALID);
+   }
+
if (intr_stat & HDMI_IH_PHY_STAT0_HPD) {
dev_dbg(hdmi->dev, "EVENT=%s\n",
phy_int_pol & HDMI_PHY_HPD ? "plugin" : "plugout");
@@ -2376,6 +2387,12 @@ __dw_hdmi_probe(struct platform_device *pdev,
if (ret)
goto err_iahb;
 
+   hdmi->cec_notifier = cec_notifier_get(dev);
+   if (!hdmi->cec_notifier) {
+   ret = -ENOMEM;
+   goto err_iahb;
+   }
+
/*
 * To prevent overflows in HDMI_IH_FC_STAT2, set the clk regenerator
 * N and cts values before enabling phy
@@ -2452,6 +2469,9 @@ __dw_hdmi_probe(struct platform_device *pdev,
hdmi->ddc = NULL;
}
 
+   if (hdmi->cec_notifier)
+   cec_notifier_put(hdmi->cec_notifier);
+
clk_disable_unprepare(hdmi->iahb_clk);
 err_isfr:
clk_disable_unprepare(hdmi->isfr_clk);
@@ -2469,6 +2489,9 @@ static void __dw_hdmi_remove(struct dw_hdmi *hdmi)
/* Disable all interrupts */
hdmi_writeb(hdmi, ~0, HDMI_IH_MUTE_PHY_STAT0);
 
+   if (hdmi->cec_notifier)
+   cec_notifier_put(hdmi->cec_notifier);
+
clk_disable_unprepare(hdmi->iahb_clk);
clk_disable_unprepare(hdmi->isfr_clk);
 
-- 
2.13.2



[PATCHv3 0/4] dw-hdmi CEC support

2017-08-02 Thread Hans Verkuil
From: Hans Verkuil 

Russell's v2 cover letter:

--
Hi,

This series adds dw-hdmi CEC support.  This is done in four stages:

1. Add cec-notifier support
2. Fix up the clkdis register support, as this register contains a
   clock disable bit for the CEC module.
3. Add the driver.
4. Remove definitions that are not required from dw-hdmi.h

The CEC driver has been updated to use the register accessors in the
main driver - it would be nice if it was possible to use the regmap
support directly, but there's some knowledge private to the main
driver that's required to correctly access the registers.  (I don't
understand why the register stride isn't part of regmap.)

 drivers/gpu/drm/bridge/synopsys/Kconfig   |  10 +
 drivers/gpu/drm/bridge/synopsys/Makefile  |   1 +
 drivers/gpu/drm/bridge/synopsys/dw-hdmi-cec.c | 326 ++
 drivers/gpu/drm/bridge/synopsys/dw-hdmi-cec.h |  19 ++
 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c |  93 +++-
 drivers/gpu/drm/bridge/synopsys/dw-hdmi.h |  46 +---
 6 files changed, 437 insertions(+), 58 deletions(-)

v2 - fix selection of CEC_NOTIFIER in Kconfig
--

Changes in this v3:

- add missing cec_notifier_put to remove()
- some checkpatch unsigned -> unsigned int changes
- cec_transmit_done is replaced by the newer cec_transmit_attempt_done
- added missing CEC_CAP_PASSTHROUGH

Regards,

Hans

Russell King (4):
  drm/bridge: dw-hdmi: add cec notifier support
  drm/bridge: dw-hdmi: add better clock disable control
  drm/bridge: dw-hdmi: add cec driver
  drm/bridge: dw-hdmi: remove CEC engine register definitions

 drivers/gpu/drm/bridge/synopsys/Kconfig   |  10 +
 drivers/gpu/drm/bridge/synopsys/Makefile  |   1 +
 drivers/gpu/drm/bridge/synopsys/dw-hdmi-cec.c | 327 ++
 drivers/gpu/drm/bridge/synopsys/dw-hdmi-cec.h |  19 ++
 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c |  96 +++-
 drivers/gpu/drm/bridge/synopsys/dw-hdmi.h |  46 +---
 6 files changed, 441 insertions(+), 58 deletions(-)
 create mode 100644 drivers/gpu/drm/bridge/synopsys/dw-hdmi-cec.c
 create mode 100644 drivers/gpu/drm/bridge/synopsys/dw-hdmi-cec.h

-- 
2.13.2



[PATCHv3 4/4] drm/bridge: dw-hdmi: remove CEC engine register definitions

2017-08-02 Thread Hans Verkuil
From: Russell King 

We don't need the CEC engine register definitions, so let's remove them.

Signed-off-by: Russell King 
Acked-by: Hans Verkuil 
Tested-by: Hans Verkuil 
Tested-by: Laurent Pinchart 
---
 drivers/gpu/drm/bridge/synopsys/dw-hdmi.h | 45 ---
 1 file changed, 45 deletions(-)

diff --git a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.h 
b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.h
index 69644c83a0f8..9d90eb9c46e5 100644
--- a/drivers/gpu/drm/bridge/synopsys/dw-hdmi.h
+++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi.h
@@ -478,51 +478,6 @@
 #define HDMI_A_PRESETUP 0x501A
 #define HDMI_A_SRM_BASE 0x5020
 
-/* CEC Engine Registers */
-#define HDMI_CEC_CTRL   0x7D00
-#define HDMI_CEC_STAT   0x7D01
-#define HDMI_CEC_MASK   0x7D02
-#define HDMI_CEC_POLARITY   0x7D03
-#define HDMI_CEC_INT0x7D04
-#define HDMI_CEC_ADDR_L 0x7D05
-#define HDMI_CEC_ADDR_H 0x7D06
-#define HDMI_CEC_TX_CNT 0x7D07
-#define HDMI_CEC_RX_CNT 0x7D08
-#define HDMI_CEC_TX_DATA0   0x7D10
-#define HDMI_CEC_TX_DATA1   0x7D11
-#define HDMI_CEC_TX_DATA2   0x7D12
-#define HDMI_CEC_TX_DATA3   0x7D13
-#define HDMI_CEC_TX_DATA4   0x7D14
-#define HDMI_CEC_TX_DATA5   0x7D15
-#define HDMI_CEC_TX_DATA6   0x7D16
-#define HDMI_CEC_TX_DATA7   0x7D17
-#define HDMI_CEC_TX_DATA8   0x7D18
-#define HDMI_CEC_TX_DATA9   0x7D19
-#define HDMI_CEC_TX_DATA10  0x7D1a
-#define HDMI_CEC_TX_DATA11  0x7D1b
-#define HDMI_CEC_TX_DATA12  0x7D1c
-#define HDMI_CEC_TX_DATA13  0x7D1d
-#define HDMI_CEC_TX_DATA14  0x7D1e
-#define HDMI_CEC_TX_DATA15  0x7D1f
-#define HDMI_CEC_RX_DATA0   0x7D20
-#define HDMI_CEC_RX_DATA1   0x7D21
-#define HDMI_CEC_RX_DATA2   0x7D22
-#define HDMI_CEC_RX_DATA3   0x7D23
-#define HDMI_CEC_RX_DATA4   0x7D24
-#define HDMI_CEC_RX_DATA5   0x7D25
-#define HDMI_CEC_RX_DATA6   0x7D26
-#define HDMI_CEC_RX_DATA7   0x7D27
-#define HDMI_CEC_RX_DATA8   0x7D28
-#define HDMI_CEC_RX_DATA9   0x7D29
-#define HDMI_CEC_RX_DATA10  0x7D2a
-#define HDMI_CEC_RX_DATA11  0x7D2b
-#define HDMI_CEC_RX_DATA12  0x7D2c
-#define HDMI_CEC_RX_DATA13  0x7D2d
-#define HDMI_CEC_RX_DATA14  0x7D2e
-#define HDMI_CEC_RX_DATA15  0x7D2f
-#define HDMI_CEC_LOCK   0x7D30
-#define HDMI_CEC_WKUPCTRL   0x7D31
-
 /* I2C Master Registers (E-DDC) */
 #define HDMI_I2CM_SLAVE 0x7E00
 #define HDMI_I2CM_ADDRESS   0x7E01
-- 
2.13.2



[PATCHv3 3/4] drm/bridge: dw-hdmi: add cec driver

2017-08-02 Thread Hans Verkuil
From: Russell King 

Add a CEC driver for the dw-hdmi hardware.

Reviewed-by: Neil Armstrong 
Signed-off-by: Russell King 
[hans.verkuil: unsigned -> unsigned int]
[hans.verkuil: cec_transmit_done -> cec_transmit_attempt_done]
[hans.verkuil: add missing CEC_CAP_PASSTHROUGH]
Acked-by: Hans Verkuil 
Tested-by: Hans Verkuil 
Tested-by: Laurent Pinchart 
---
 drivers/gpu/drm/bridge/synopsys/Kconfig   |   9 +
 drivers/gpu/drm/bridge/synopsys/Makefile  |   1 +
 drivers/gpu/drm/bridge/synopsys/dw-hdmi-cec.c | 327 ++
 drivers/gpu/drm/bridge/synopsys/dw-hdmi-cec.h |  19 ++
 drivers/gpu/drm/bridge/synopsys/dw-hdmi.c |  42 +++-
 drivers/gpu/drm/bridge/synopsys/dw-hdmi.h |   1 +
 6 files changed, 398 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/bridge/synopsys/dw-hdmi-cec.c
 create mode 100644 drivers/gpu/drm/bridge/synopsys/dw-hdmi-cec.h

diff --git a/drivers/gpu/drm/bridge/synopsys/Kconfig 
b/drivers/gpu/drm/bridge/synopsys/Kconfig
index 351db000599a..d34c3dc04ba9 100644
--- a/drivers/gpu/drm/bridge/synopsys/Kconfig
+++ b/drivers/gpu/drm/bridge/synopsys/Kconfig
@@ -23,3 +23,12 @@ config DRM_DW_HDMI_I2S_AUDIO
help
  Support the I2S Audio interface which is part of the Synopsys
  Designware HDMI block.
+
+config DRM_DW_HDMI_CEC
+   tristate "Synopsis Designware CEC interface"
+   depends on DRM_DW_HDMI
+   select CEC_CORE
+   select CEC_NOTIFIER
+   help
+ Support the CE interface which is part of the Synopsys
+ Designware HDMI block.
diff --git a/drivers/gpu/drm/bridge/synopsys/Makefile 
b/drivers/gpu/drm/bridge/synopsys/Makefile
index 17aa7a65b57e..6fe415903668 100644
--- a/drivers/gpu/drm/bridge/synopsys/Makefile
+++ b/drivers/gpu/drm/bridge/synopsys/Makefile
@@ -3,3 +3,4 @@
 obj-$(CONFIG_DRM_DW_HDMI) += dw-hdmi.o
 obj-$(CONFIG_DRM_DW_HDMI_AHB_AUDIO) += dw-hdmi-ahb-audio.o
 obj-$(CONFIG_DRM_DW_HDMI_I2S_AUDIO) += dw-hdmi-i2s-audio.o
+obj-$(CONFIG_DRM_DW_HDMI_CEC) += dw-hdmi-cec.o
diff --git a/drivers/gpu/drm/bridge/synopsys/dw-hdmi-cec.c 
b/drivers/gpu/drm/bridge/synopsys/dw-hdmi-cec.c
new file mode 100644
index ..6c323510f128
--- /dev/null
+++ b/drivers/gpu/drm/bridge/synopsys/dw-hdmi-cec.c
@@ -0,0 +1,327 @@
+/*
+ * Designware HDMI CEC driver
+ *
+ * Copyright (C) 2015-2017 Russell King.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include 
+#include 
+
+#include "dw-hdmi-cec.h"
+
+enum {
+   HDMI_IH_CEC_STAT0   = 0x0106,
+   HDMI_IH_MUTE_CEC_STAT0  = 0x0186,
+
+   HDMI_CEC_CTRL   = 0x7d00,
+   CEC_CTRL_START  = BIT(0),
+   CEC_CTRL_FRAME_TYP  = 3 << 1,
+   CEC_CTRL_RETRY  = 0 << 1,
+   CEC_CTRL_NORMAL = 1 << 1,
+   CEC_CTRL_IMMED  = 2 << 1,
+
+   HDMI_CEC_STAT   = 0x7d01,
+   CEC_STAT_DONE   = BIT(0),
+   CEC_STAT_EOM= BIT(1),
+   CEC_STAT_NACK   = BIT(2),
+   CEC_STAT_ARBLOST= BIT(3),
+   CEC_STAT_ERROR_INIT = BIT(4),
+   CEC_STAT_ERROR_FOLL = BIT(5),
+   CEC_STAT_WAKEUP = BIT(6),
+
+   HDMI_CEC_MASK   = 0x7d02,
+   HDMI_CEC_POLARITY   = 0x7d03,
+   HDMI_CEC_INT= 0x7d04,
+   HDMI_CEC_ADDR_L = 0x7d05,
+   HDMI_CEC_ADDR_H = 0x7d06,
+   HDMI_CEC_TX_CNT = 0x7d07,
+   HDMI_CEC_RX_CNT = 0x7d08,
+   HDMI_CEC_TX_DATA0   = 0x7d10,
+   HDMI_CEC_RX_DATA0   = 0x7d20,
+   HDMI_CEC_LOCK   = 0x7d30,
+   HDMI_CEC_WKUPCTRL   = 0x7d31,
+};
+
+struct dw_hdmi_cec {
+   struct dw_hdmi *hdmi;
+   const struct dw_hdmi_cec_ops *ops;
+   u32 addresses;
+   struct cec_adapter *adap;
+   struct cec_msg rx_msg;
+   unsigned int tx_status;
+   bool tx_done;
+   bool rx_done;
+   struct cec_notifier *notify;
+   int irq;
+};
+
+static void dw_hdmi_write(struct dw_hdmi_cec *cec, u8 val, int offset)
+{
+   cec->ops->write(cec->hdmi, val, offset);
+}
+
+static u8 dw_hdmi_read(struct dw_hdmi_cec *cec, int offset)
+{
+   return cec->ops->read(cec->hdmi, offset);
+}
+
+static int dw_hdmi_cec_log_addr(struct cec_adapter *adap, u8 logical_addr)
+{
+   struct dw_hdmi_cec *cec = cec_get_drvdata(adap);
+
+   if (logical_addr == CEC_LOG_ADDR_INVALID)
+   cec->addresses = 0;
+   else
+   cec->addresses |= BIT(logical_addr) | BIT(15);
+
+   dw_hdmi_write(cec, cec->addresses & 255, HDMI_CEC_ADDR_L);
+   dw_hdmi_write(cec, cec->addresses >> 8, HDMI_CEC_ADDR_H);
+
+   return 0;
+}
+
+static int dw_hdmi_cec_transmit(struct cec_adapter *adap, u8 attempts,
+   u32 signal_free_time, struct cec

[PATCH 1/2] scan-tables: add initial table for Mountain View, California

2017-08-02 Thread Reynaldo H. Verdejo Pinochet
Signed-off-by: Reynaldo H. Verdejo Pinochet 
---
 atsc/us-CA-Mountain-View | 171 +++
 1 file changed, 171 insertions(+)
 create mode 100644 atsc/us-CA-Mountain-View

diff --git a/atsc/us-CA-Mountain-View b/atsc/us-CA-Mountain-View
new file mode 100644
index 000..892a531
--- /dev/null
+++ b/atsc/us-CA-Mountain-View
@@ -0,0 +1,171 @@
+# Initial ATSC scan table for Mountain View, California.
+#
+# This file was prepared from official (as of August 1 2017) FCC data[1]
+# for CA 94043.
+#
+# [1] https://www.fcc.gov/media/engineering/dtvmaps
+#
+# Prepared by: Reynaldo H. Verdejo Pinochet 
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 17700
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 18300
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 18900
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 20700
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 21300
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 47300
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 50300
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 52700
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 53900
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 55100
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 56300
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 56900
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 57500
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 58100
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 58700
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 59300
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 60500
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 61700
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 62300
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 63500
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 64700
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 65300
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 65900
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 67100
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 68300
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 68900
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 69500
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
-- 
2.13.2



[PATCH 0/2][dtv-scan-tables] Add new tables for San Jose and Mountain View, California

2017-08-02 Thread Reynaldo H. Verdejo Pinochet
The following two patches add city-specific initial scan tables for San Jose 
and Mountain view. I tried these personally with good results. Particularly in 
MV with 73 channels output by dvbv5-scan.

Bests,

--
Reynaldo H. Verdejo Pinochet
OSG, Samsung Research America
 



[PATCH 2/2] scan-tables: add initial table for San Jose, California

2017-08-02 Thread Reynaldo H. Verdejo Pinochet
Signed-off-by: Reynaldo H. Verdejo Pinochet 
---
 atsc/us-CA-San-Jose | 161 
 1 file changed, 161 insertions(+)
 create mode 100644 atsc/us-CA-San-Jose

diff --git a/atsc/us-CA-San-Jose b/atsc/us-CA-San-Jose
new file mode 100644
index 000..ff514b9
--- /dev/null
+++ b/atsc/us-CA-San-Jose
@@ -0,0 +1,161 @@
+# Initial ATSC scan table for San Jose, California.
+#
+# This file was prepared from official (as of August 1 2017) FCC data[1]
+# for CA 950123, with an added entry for KAXT-CD which is broadcasting
+# in the area on UHF channel 42 but doesn't show up in the FCC database
+# search results for the ZIP code.
+#
+# [1] https://www.fcc.gov/media/engineering/dtvmaps
+#
+# Prepared by: Reynaldo H. Verdejo Pinochet 
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 17700
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 18300
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 20700
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 21300
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 47300
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 50300
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 52700
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 55100
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 56300
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 56900
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 57500
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 58700
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 59300
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 60500
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 61700
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 62300
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 63500
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 64100
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 64700
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 65300
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 65900
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 67100
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 68300
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 68900
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
+[CHANNEL]
+   DELIVERY_SYSTEM = ATSC
+   FREQUENCY = 69500
+   MODULATION = VSB/8
+   INVERSION = AUTO
+
-- 
2.13.2



Universal DTV USB receiver (“Joker TV”)

2017-08-02 Thread Abylay Ospan
Hello Everyone !

Some time ago I had announced my initiative about building truly
universal DTV receiver - “Joker TV” (supports DVB-S2/T2/C2, ISDB-T,
ATSC, DTMB). Now I’m glad to post  an update.

It has been almost 10 months now but during this time, I have prepared
two hardware revisions of “Joker TV” with various fixes. I also wrote
software for FPGA and the host (for Linux/OSx/Windows). This was a lot
of work, but now I’m ready to share all of it with you. I have decided
to donate my work to the community and make this project an Open
Hardware and Open Software project. Here are some posts with
additional information:

https://jokersys.com/2017/07/06/schematic-pcb-share/ - hardware sharing
https://jokersys.com/2017/07/06/joker-tv-linuxosxwindows-drivers-apps/
- user-level driver&app description
https://jokersys.com/2017/07/06/joker-tv-fpga-verilogvhdl-code/ - FPGA
firmware description

And bonus for those who are interested in how the production is done
and how much it cost. Here is my post about this:

https://jokersys.com/2017/07/08/joker-tv-manufacturing/

Additionally, I have just placed the first batch order to the factory
and I’m anticipating the results which should be ready in about three
(3) weeks. I will send freshly baked “Joker TV” gadgets to all
backers.

I’m planning to prepare new posts with internals about Joker TV’s
hardware and software. Here are some topics I’m planning to describe:
 * USB part. ULPI PHY interface, FPGA USB-stack, Isochronous
transactions with TS data, etc;
 * RF part. Tuner and Demods, AGC, LNB, I&Q, etc
 * I2C and SPI buses
 * CI interface
Please let me know if you are interested in some topics listed above -
I will describe them in more detail next time.

I’m open to any comments, collaboration, discussions. Thanks !

-- 
Abylay Ospan


[PATCH] uvcvideo: extend UVC_QUIRK_FIX_BANDWIDTH to MJPEG streams

2017-08-02 Thread Pavel Rojtberg
From: Pavel Rojtberg 

attaching two Logitech C615 webcams currently results in
VIDIOC_STREAMON: No space left on device
as the required bandwidth is not estimated correctly by the device.
In fact it always requests 3060 bytes - no matter the format or resolution.

setting UVC_QUIRK_FIX_BANDWIDTH does not help either as it is only implemented
for uncompressed streams.

This patch extends UVC_QUIRK_FIX_BANDWIDTH to MJPEG streams by making a
(conservative) assumption of 4bpp for MJPEG streams.
As the actual compression ration is often closer to 1bpp this can be overridden
 via the new mjpeg_bpp parameter.

Based on:
https://www.mail-archive.com/linux-uvc-devel@lists.berlios.de/msg05724.html
---
 drivers/media/usb/uvc/uvc_driver.c | 14 +-
 drivers/media/usb/uvc/uvc_video.c  |  3 ++-
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/drivers/media/usb/uvc/uvc_driver.c 
b/drivers/media/usb/uvc/uvc_driver.c
index 70842c5..f7b759e 100644
--- a/drivers/media/usb/uvc/uvc_driver.c
+++ b/drivers/media/usb/uvc/uvc_driver.c
@@ -37,6 +37,7 @@ unsigned int uvc_no_drop_param;
 static unsigned int uvc_quirks_param = -1;
 unsigned int uvc_trace_param;
 unsigned int uvc_timeout_param = UVC_CTRL_STREAMING_TIMEOUT;
+static unsigned int uvc_mjpeg_bpp_param;
 
 /* 
  * Video formats
@@ -463,7 +464,16 @@ static int uvc_parse_format(struct uvc_device *dev,
strlcpy(format->name, "MJPEG", sizeof format->name);
format->fcc = V4L2_PIX_FMT_MJPEG;
format->flags = UVC_FMT_FLAG_COMPRESSED;
-   format->bpp = 0;
+   if ((uvc_mjpeg_bpp_param >= 1) && (uvc_mjpeg_bpp_param <= 16)) {
+   format->bpp = uvc_mjpeg_bpp_param;
+   } else {
+   /* conservative estimate. Actual values are around 1bpp.
+* see e.g.
+* 
https://developers.google.com/speed/webp/docs/webp_study
+*/
+   format->bpp = 4;
+   }
+
ftype = UVC_VS_FRAME_MJPEG;
break;
 
@@ -2274,6 +2284,8 @@ module_param_named(trace, uvc_trace_param, uint, 
S_IRUGO|S_IWUSR);
 MODULE_PARM_DESC(trace, "Trace level bitmask");
 module_param_named(timeout, uvc_timeout_param, uint, S_IRUGO|S_IWUSR);
 MODULE_PARM_DESC(timeout, "Streaming control requests timeout");
+module_param_named(mjpeg_bpp, uvc_mjpeg_bpp_param, uint, S_IRUGO|S_IWUSR);
+MODULE_PARM_DESC(mjpeg_bpp, "MJPEG bits per pixel for bandwidth quirk");
 
 /* 
  * Driver initialization and cleanup
diff --git a/drivers/media/usb/uvc/uvc_video.c 
b/drivers/media/usb/uvc/uvc_video.c
index fb86d6a..382a0be 100644
--- a/drivers/media/usb/uvc/uvc_video.c
+++ b/drivers/media/usb/uvc/uvc_video.c
@@ -127,7 +127,8 @@ static void uvc_fixup_video_ctrl(struct uvc_streaming 
*stream,
if ((ctrl->dwMaxPayloadTransferSize & 0x) == 0x)
ctrl->dwMaxPayloadTransferSize &= ~0x;
 
-   if (!(format->flags & UVC_FMT_FLAG_COMPRESSED) &&
+   if ((!(format->flags & UVC_FMT_FLAG_COMPRESSED) ||
+   (format->fcc == V4L2_PIX_FMT_MJPEG)) &&
stream->dev->quirks & UVC_QUIRK_FIX_BANDWIDTH &&
stream->intf->num_altsetting > 1) {
u32 interval;
-- 
2.7.4



[PATCH 0/9] constify media pci_device_id/pci_tbl.

2017-08-02 Thread Arvind Yadav
SAA7146 DVD card base pci device id const.

Arvind Yadav (9):
  [PATCH 1/9] [media] drv-intf: saa7146: constify pci_device_id.
  [PATCH 2/9] [media] ttpci: budget: constify pci_device_id.
  [PATCH 3/9] [media] ttpci: budget-patch: constify pci_device_id.
  [PATCH 4/9] [media] ttpci: budget-ci: constify pci_device_id.
  [PATCH 5/9] [media] ttpci: budget-av: constify pci_device_id.
  [PATCH 6/9] [media] ttpci: av7110: constify pci_device_id.
  [PATCH 7/9] [media] saa7146: mxb: constify pci_device_id.
  [PATCH 8/9] [media] saa7146: hexium_orion: constify pci_device_id.
  [PATCH 9/9] [media] saa7146: hexium_gemini: constify pci_device_id.

 drivers/media/pci/saa7146/hexium_gemini.c | 2 +-
 drivers/media/pci/saa7146/hexium_orion.c  | 2 +-
 drivers/media/pci/saa7146/mxb.c   | 2 +-
 drivers/media/pci/ttpci/av7110.c  | 2 +-
 drivers/media/pci/ttpci/budget-av.c   | 2 +-
 drivers/media/pci/ttpci/budget-ci.c   | 2 +-
 drivers/media/pci/ttpci/budget-patch.c| 2 +-
 drivers/media/pci/ttpci/budget.c  | 2 +-
 include/media/drv-intf/saa7146.h  | 2 +-
 9 files changed, 9 insertions(+), 9 deletions(-)

-- 
2.7.4



[PATCH 2/9] [media] ttpci: budget: constify pci_device_id.

2017-08-02 Thread Arvind Yadav
pci_device_id are not supposed to change at runtime. All functions
working with pci_device_id provided by 
and  work with const pci_device_id. So mark the non-const
structs as const.

Signed-off-by: Arvind Yadav 
---
 drivers/media/pci/ttpci/budget.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/pci/ttpci/budget.c b/drivers/media/pci/ttpci/budget.c
index 81fe35c..f59eadb 100644
--- a/drivers/media/pci/ttpci/budget.c
+++ b/drivers/media/pci/ttpci/budget.c
@@ -845,7 +845,7 @@ MAKE_BUDGET_INFO(fsact1, "Fujitsu Siemens Activy Budget-T 
PCI (rev AL/ALPS TDHD1
 MAKE_BUDGET_INFO(omicom, "Omicom S2 PCI", BUDGET_TT);
 MAKE_BUDGET_INFO(sylt,   "Philips Semi Sylt PCI", BUDGET_TT_HW_DISEQC);
 
-static struct pci_device_id pci_tbl[] = {
+static const struct pci_device_id pci_tbl[] = {
MAKE_EXTENSION_PCI(ttbs,  0x13c2, 0x1003),
MAKE_EXTENSION_PCI(ttbc,  0x13c2, 0x1004),
MAKE_EXTENSION_PCI(ttbt,  0x13c2, 0x1005),
-- 
2.7.4



[PATCH 1/9] [media] drv-intf: saa7146: constify pci_device_id.

2017-08-02 Thread Arvind Yadav
pci_device_id are not supposed to change at runtime. All functions
working with pci_device_id provided by  work with
const pci_device_id. So mark the non-const structs as const.
So making 'pci_tbl' as const member of 'struct saa7146_extension'.

Signed-off-by: Arvind Yadav 
---
 include/media/drv-intf/saa7146.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/media/drv-intf/saa7146.h b/include/media/drv-intf/saa7146.h
index 96058a5..4529432 100644
--- a/include/media/drv-intf/saa7146.h
+++ b/include/media/drv-intf/saa7146.h
@@ -96,7 +96,7 @@ struct saa7146_extension
   supported devices, last entry 0x, 0xfff */
struct module *module;
struct pci_driver driver;
-   struct pci_device_id *pci_tbl;
+   const struct pci_device_id *pci_tbl;
 
/* extension functions */
int (*probe)(struct saa7146_dev *);
-- 
2.7.4



[PATCH 4/9] [media] ttpci: budget-ci: constify pci_device_id.

2017-08-02 Thread Arvind Yadav
pci_device_id are not supposed to change at runtime. All functions
working with pci_device_id provided by 
and  work with const pci_device_id. So mark the non-const
structs as const.

Signed-off-by: Arvind Yadav 
---
 drivers/media/pci/ttpci/budget-ci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/pci/ttpci/budget-ci.c 
b/drivers/media/pci/ttpci/budget-ci.c
index 11b9227..5b8aab4 100644
--- a/drivers/media/pci/ttpci/budget-ci.c
+++ b/drivers/media/pci/ttpci/budget-ci.c
@@ -1538,7 +1538,7 @@ MAKE_BUDGET_INFO(ttc1501, "TT-Budget C-1501 PCI", 
BUDGET_TT);
 MAKE_BUDGET_INFO(tt3200, "TT-Budget S2-3200 PCI", BUDGET_TT);
 MAKE_BUDGET_INFO(ttbs1500b, "TT-Budget S-1500B PCI", BUDGET_TT);
 
-static struct pci_device_id pci_tbl[] = {
+static const struct pci_device_id pci_tbl[] = {
MAKE_EXTENSION_PCI(ttbci, 0x13c2, 0x100c),
MAKE_EXTENSION_PCI(ttbci, 0x13c2, 0x100f),
MAKE_EXTENSION_PCI(ttbcci, 0x13c2, 0x1010),
-- 
2.7.4



[PATCH 5/9] [media] ttpci: budget-av: constify pci_device_id.

2017-08-02 Thread Arvind Yadav
pci_device_id are not supposed to change at runtime. All functions
working with pci_device_id provided by 
and  work with const pci_device_id. So mark the non-const
structs as const.

Signed-off-by: Arvind Yadav 
---
 drivers/media/pci/ttpci/budget-av.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/pci/ttpci/budget-av.c 
b/drivers/media/pci/ttpci/budget-av.c
index dc7be8f..ac83fff 100644
--- a/drivers/media/pci/ttpci/budget-av.c
+++ b/drivers/media/pci/ttpci/budget-av.c
@@ -1567,7 +1567,7 @@ MAKE_BUDGET_INFO(cin1200c, "Terratec Cinergy 1200 DVB-C", 
BUDGET_CIN1200C);
 MAKE_BUDGET_INFO(cin1200cmk3, "Terratec Cinergy 1200 DVB-C MK3", 
BUDGET_CIN1200C_MK3);
 MAKE_BUDGET_INFO(cin1200t, "Terratec Cinergy 1200 DVB-T", BUDGET_CIN1200T);
 
-static struct pci_device_id pci_tbl[] = {
+static const struct pci_device_id pci_tbl[] = {
MAKE_EXTENSION_PCI(knc1s, 0x1131, 0x4f56),
MAKE_EXTENSION_PCI(knc1s, 0x1131, 0x0010),
MAKE_EXTENSION_PCI(knc1s, 0x1894, 0x0010),
-- 
2.7.4



[PATCH 6/9] [media] ttpci: av7110: constify pci_device_id.

2017-08-02 Thread Arvind Yadav
pci_device_id are not supposed to change at runtime. All functions
working with pci_device_id provided by 
and  work with const pci_device_id. So mark the non-const
structs as const.

Signed-off-by: Arvind Yadav 
---
 drivers/media/pci/ttpci/av7110.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/pci/ttpci/av7110.c b/drivers/media/pci/ttpci/av7110.c
index f2905bd..f46947d 100644
--- a/drivers/media/pci/ttpci/av7110.c
+++ b/drivers/media/pci/ttpci/av7110.c
@@ -2872,7 +2872,7 @@ MAKE_AV7110_INFO(fsc,"Fujitsu Siemens DVB-C");
 MAKE_AV7110_INFO(fss,"Fujitsu Siemens DVB-S rev1.6");
 MAKE_AV7110_INFO(gxs_1_3,"Galaxis DVB-S rev1.3");
 
-static struct pci_device_id pci_tbl[] = {
+static const struct pci_device_id pci_tbl[] = {
MAKE_EXTENSION_PCI(fsc, 0x110a, 0x),
MAKE_EXTENSION_PCI(tts_1_X_fsc, 0x13c2, 0x),
MAKE_EXTENSION_PCI(ttt_1_X, 0x13c2, 0x0001),
-- 
2.7.4



[PATCH 3/9] [media] ttpci: budget-patch: constify pci_device_id.

2017-08-02 Thread Arvind Yadav
pci_device_id are not supposed to change at runtime. All functions
working with pci_device_id provided by 
and  work with const pci_device_id. So mark the non-const
structs as const.

Signed-off-by: Arvind Yadav 
---
 drivers/media/pci/ttpci/budget-patch.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/pci/ttpci/budget-patch.c 
b/drivers/media/pci/ttpci/budget-patch.c
index 4429923..a738018 100644
--- a/drivers/media/pci/ttpci/budget-patch.c
+++ b/drivers/media/pci/ttpci/budget-patch.c
@@ -45,7 +45,7 @@ static struct saa7146_extension budget_extension;
 MAKE_BUDGET_INFO(ttbp, "TT-Budget/Patch DVB-S 1.x PCI", BUDGET_PATCH);
 //MAKE_BUDGET_INFO(satel,"TT-Budget/Patch SATELCO PCI", BUDGET_TT_HW_DISEQC);
 
-static struct pci_device_id pci_tbl[] = {
+static const struct pci_device_id pci_tbl[] = {
MAKE_EXTENSION_PCI(ttbp,0x13c2, 0x),
 //MAKE_EXTENSION_PCI(satel, 0x13c2, 0x1013),
{
-- 
2.7.4



[PATCH 8/9] [media] saa7146: hexium_orion: constify pci_device_id.

2017-08-02 Thread Arvind Yadav
pci_device_id are not supposed to change at runtime. All functions
working with pci_device_id provided by 
and  work with const pci_device_id. So mark the non-const
structs as const.

Signed-off-by: Arvind Yadav 
---
 drivers/media/pci/saa7146/hexium_orion.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/pci/saa7146/hexium_orion.c 
b/drivers/media/pci/saa7146/hexium_orion.c
index c306a92..01f0158 100644
--- a/drivers/media/pci/saa7146/hexium_orion.c
+++ b/drivers/media/pci/saa7146/hexium_orion.c
@@ -427,7 +427,7 @@ static struct saa7146_pci_extension_data hexium_orion_4bnc 
= {
.ext = &extension,
 };
 
-static struct pci_device_id pci_tbl[] = {
+static const struct pci_device_id pci_tbl[] = {
{
 .vendor = PCI_VENDOR_ID_PHILIPS,
 .device = PCI_DEVICE_ID_PHILIPS_SAA7146,
-- 
2.7.4



[PATCH 9/9] [media] saa7146: hexium_gemini: constify pci_device_id.

2017-08-02 Thread Arvind Yadav
pci_device_id are not supposed to change at runtime. All functions
working with pci_device_id provided by 
and  work with const pci_device_id. So mark the non-const
structs as const.

Signed-off-by: Arvind Yadav 
---
 drivers/media/pci/saa7146/hexium_gemini.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/pci/saa7146/hexium_gemini.c 
b/drivers/media/pci/saa7146/hexium_gemini.c
index c889ec9..f708cab 100644
--- a/drivers/media/pci/saa7146/hexium_gemini.c
+++ b/drivers/media/pci/saa7146/hexium_gemini.c
@@ -363,7 +363,7 @@ static struct saa7146_pci_extension_data 
hexium_gemini_dual_4bnc = {
.ext = &hexium_extension,
 };
 
-static struct pci_device_id pci_tbl[] = {
+static const struct pci_device_id pci_tbl[] = {
{
 .vendor = PCI_VENDOR_ID_PHILIPS,
 .device = PCI_DEVICE_ID_PHILIPS_SAA7146,
-- 
2.7.4



[PATCH 7/9] [media] saa7146: mxb: constify pci_device_id.

2017-08-02 Thread Arvind Yadav
pci_device_id are not supposed to change at runtime. All functions
working with pci_device_id provided by 
and  work with const pci_device_id. So mark the non-const
structs as const.

Signed-off-by: Arvind Yadav 
---
 drivers/media/pci/saa7146/mxb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/pci/saa7146/mxb.c b/drivers/media/pci/saa7146/mxb.c
index 504d788..930218c 100644
--- a/drivers/media/pci/saa7146/mxb.c
+++ b/drivers/media/pci/saa7146/mxb.c
@@ -819,7 +819,7 @@ static struct saa7146_pci_extension_data mxb = {
.ext = &extension,
 };
 
-static struct pci_device_id pci_tbl[] = {
+static const struct pci_device_id pci_tbl[] = {
{
.vendor= PCI_VENDOR_ID_PHILIPS,
.device= PCI_DEVICE_ID_PHILIPS_SAA7146,
-- 
2.7.4



[PATCH 2/2] cx231xx: fix use-after-free when unregistering the i2c_client for the dvb demod

2017-08-02 Thread Matthias Schwarzott
Calling i2c_unregister_device for a demod driver destroys the frontend object.
Later it is accessed by calling dvb_unregister_frontend and
dvb_frontend_detach.

In some cases this leads to a general protection fault with this
callstack:

  dvb_unregister_frontend+0x25/0x50 [dvb_core]
  dvb_fini+0xdb/0x160 [cx231xx_dvb]
  cx231xx_unregister_extension+0x3d/0xb0 [cx231xx]
  cx231xx_dvb_unregister+0x10/0x809 [cx231xx_dvb]
  SyS_delete_module+0x18a/0x240
  ? exit_to_usermode_loop+0x7b/0x80
  entry_SYSCALL_64_fastpath+0x17/0x98

Signed-off-by: Matthias Schwarzott 
---
 drivers/media/usb/cx231xx/cx231xx-dvb.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/media/usb/cx231xx/cx231xx-dvb.c 
b/drivers/media/usb/cx231xx/cx231xx-dvb.c
index ee3eeeb600f8..c18bb33e060e 100644
--- a/drivers/media/usb/cx231xx/cx231xx-dvb.c
+++ b/drivers/media/usb/cx231xx/cx231xx-dvb.c
@@ -585,6 +585,9 @@ static void unregister_dvb(struct cx231xx_dvb *dvb)
dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
dvb_dmxdev_release(&dvb->dmxdev);
dvb_dmx_release(&dvb->demux);
+   dvb_unregister_frontend(dvb->frontend);
+   dvb_frontend_detach(dvb->frontend);
+   dvb_unregister_adapter(&dvb->adapter);
/* remove I2C tuner */
client = dvb->i2c_client_tuner;
if (client) {
@@ -597,9 +600,6 @@ static void unregister_dvb(struct cx231xx_dvb *dvb)
module_put(client->dev.driver->owner);
i2c_unregister_device(client);
}
-   dvb_unregister_frontend(dvb->frontend);
-   dvb_frontend_detach(dvb->frontend);
-   dvb_unregister_adapter(&dvb->adapter);
 }
 
 static int dvb_init(struct cx231xx *dev)
-- 
2.13.3



[PATCH 0/2] Fix use-after-free errors when unregistering the i2c_client for the dvb demod

2017-08-02 Thread Matthias Schwarzott
Hi!

There seem to be a general error in a lot of dvb bride drivers about the order 
of i2c_unregister_device
and the calls to dvb_unregister_frontend and dvb_frontend_detach.

As soon as the i2c_client for a demod driver is unregistered the memory for the 
frontend is kfreed.
But the calls to dvb_unregister_frontend and dvb_frontend_detach access it 
later.

I fixed the error in cx23885 and cx231xx driver as I have access to the 
hardware.

Further drivers that might show the same bug (but I cannot test):
* em28xx
* ddbride
* saa7164

Regards
Matthias



[PATCH 1/2] cx23885: Fix use-after-free when unregistering the i2c_client for the dvb demod

2017-08-02 Thread Matthias Schwarzott
Unregistering the i2c_client of the demod driver destroys the frontend
object.
Calling vb2_dvb_unregister_bus later accesses the frontend (and with the
refcount_t) conversion the refcount_t code complains:

kernel: [ cut here ]
kernel: WARNING: CPU: 0 PID: 7883 at lib/refcount.c:128 
refcount_sub_and_test+0x70/0x80
kernel: refcount_t: underflow; use-after-free.
kernel: Modules linked in: bluetooth si2165(O) a8293(O) tda10071(O) tea5767(O) 
tuner(O) cx23885(O-) tda18271(O) videobuf2_dvb(O) videobuf2_dma_sg(O) 
m88ds3103(O) tveeprom(O) cx2341x(O) v4l2_common(O) dvb_core(O) rc_core(O) 
videobuf2_memops(O) videobuf2_v4l2(O) ums_realtek videobuf2_core(O) uas 
videodev(O) media(O) rtl8192cu i2c_mux usb_storage rtl_usb rtl8192c_common 
rtlwifi snd_hda_codec_hdmi snd_hda_codec_realtek snd_hda_codec_generic 
snd_hda_intel snd_hda_codec snd_hwdep snd_hda_core x86_pkg_temp_thermal 
kvm_intel kvm irqbypass
kernel: CPU: 0 PID: 7883 Comm: rmmod Tainted: GW  O4.11.3-gentoo #3
kernel: Hardware name: MEDION E2050 2391/H81H3-EM2, BIOS H81EM2W08.308 
08/25/2014
kernel: Call Trace:
kernel:  dump_stack+0x4d/0x66
kernel:  __warn+0xc6/0xe0
kernel:  warn_slowpath_fmt+0x46/0x50
kernel:  ? kobject_put+0x2f/0x60
kernel:  refcount_sub_and_test+0x70/0x80
kernel:  refcount_dec_and_test+0x11/0x20
kernel:  dvb_unregister_frontend+0x42/0x60 [dvb_core]
kernel:  vb2_dvb_dealloc_frontends+0x9e/0x100 [videobuf2_dvb]
kernel:  vb2_dvb_unregister_bus+0xd/0x20 [videobuf2_dvb]
kernel:  cx23885_dvb_unregister+0xc3/0x110 [cx23885]
kernel:  cx23885_dev_unregister+0xea/0x150 [cx23885]
kernel:  cx23885_finidev+0x4f/0x70 [cx23885]
kernel:  pci_device_remove+0x34/0xb0
kernel:  device_release_driver_internal+0x150/0x200
kernel:  driver_detach+0x33/0x70
kernel:  bus_remove_driver+0x47/0xa0
kernel:  driver_unregister+0x27/0x50
kernel:  pci_unregister_driver+0x34/0x90
kernel:  cx23885_fini+0x10/0x12 [cx23885]
kernel:  SyS_delete_module+0x166/0x220
kernel:  ? exit_to_usermode_loop+0x7b/0x80
kernel:  entry_SYSCALL_64_fastpath+0x17/0x98
kernel: RIP: 0033:0x7f5901680b07
kernel: RSP: 002b:7ffdf6cdb028 EFLAGS: 0206 ORIG_RAX: 00b0
kernel: RAX: ffda RBX: 0003 RCX: 7f5901680b07
kernel: RDX: 000a RSI: 0800 RDI: 01500258
kernel: RBP: 015001f0 R08:  R09: 1999
kernel: R10: 0884 R11: 0206 R12: 7ffdf6cda010
kernel: R13:  R14: 015001f0 R15: 014ff010
kernel: ---[ end trace c3a4659b89086061 ]---

Signed-off-by: Matthias Schwarzott 
---
 drivers/media/pci/cx23885/cx23885-dvb.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/media/pci/cx23885/cx23885-dvb.c 
b/drivers/media/pci/cx23885/cx23885-dvb.c
index 979b66627f60..e795ddeb7fe2 100644
--- a/drivers/media/pci/cx23885/cx23885-dvb.c
+++ b/drivers/media/pci/cx23885/cx23885-dvb.c
@@ -2637,6 +2637,11 @@ int cx23885_dvb_unregister(struct cx23885_tsport *port)
struct vb2_dvb_frontend *fe0;
struct i2c_client *client;
 
+   fe0 = vb2_dvb_get_frontend(&port->frontends, 1);
+
+   if (fe0 && fe0->dvb.frontend)
+   vb2_dvb_unregister_bus(&port->frontends);
+
/* remove I2C client for CI */
client = port->i2c_client_ci;
if (client) {
@@ -2665,11 +2670,6 @@ int cx23885_dvb_unregister(struct cx23885_tsport *port)
i2c_unregister_device(client);
}
 
-   fe0 = vb2_dvb_get_frontend(&port->frontends, 1);
-
-   if (fe0 && fe0->dvb.frontend)
-   vb2_dvb_unregister_bus(&port->frontends);
-
switch (port->dev->board) {
case CX23885_BOARD_NETUP_DUAL_DVBS2_CI:
netup_ci_exit(port);
-- 
2.13.3



Re: [PATCH] [media] solo6x10: export hardware GPIO pins 8:31 to gpiolib interface

2017-08-02 Thread Ismael Luceno
On 02/Aug/2017 18:17, Anton Sviridenko wrote:
> 24 GPIO pins from 32 available on solo6x10 chips are exported
> to gpiolib. First 8 GPIOs are reserved for internal use on capture card
> boards, GPIOs in range 8:15 are configured as outputs to control relays,
> remaining 16:31 are configured as inputs to read sensor states.
> Now with this patch userspace DVR software can switch relays and read
> sensor states when GPIO extension cards are attached to Softlogic solo6x10
> based video capture cards.
> 
> Signed-off-by: Anton Sviridenko 
> ---
>  drivers/media/pci/solo6x10/solo6x10-gpio.c | 97 
> ++
>  drivers/media/pci/solo6x10/solo6x10.h  |  5 ++
>  2 files changed, 102 insertions(+)
> 
> diff --git a/drivers/media/pci/solo6x10/solo6x10-gpio.c 
> b/drivers/media/pci/solo6x10/solo6x10-gpio.c
> index 6d3b4a36bc11..3d0d1aa2f6a8 100644
> --- a/drivers/media/pci/solo6x10/solo6x10-gpio.c
> +++ b/drivers/media/pci/solo6x10/solo6x10-gpio.c
> @@ -57,6 +57,9 @@ static void solo_gpio_mode(struct solo_dev *solo_dev,
>   ret |= 1 << port;
>   }
>  
> + /* Enable GPIO[31:16] */
> + ret |= 0x;
> +
>   solo_reg_write(solo_dev, SOLO_GPIO_CONFIG_1, ret);
>  }
>  
> @@ -90,16 +93,110 @@ static void solo_gpio_config(struct solo_dev *solo_dev)
>  
>   /* Initially set relay status to 0 */
>   solo_gpio_clear(solo_dev, 0xff00);
> +
> + /* Set input pins direction */
> + solo_gpio_mode(solo_dev, 0x, 0);
> +}
> +
> +#ifdef CONFIG_GPIOLIB
> +/* Pins 0-7 are not exported, because it seems from code above they are
> + * used for internal purposes. So offset 0 corresponds to pin 8, therefore
> + * offsets 0-7 are relay GPIOs, 8-23 - input GPIOs.
> + */
> +static int solo_gpiochip_get_direction(struct gpio_chip *chip,
> +unsigned int offset)
> +{
> + int ret, mode;
> + struct solo_dev *solo_dev = gpiochip_get_data(chip);
> +
> + if (offset < 8) {
> + ret = solo_reg_read(solo_dev, SOLO_GPIO_CONFIG_0);
> + mode = 3 & (ret >> ((offset + 8) * 2));
> + } else {
> + ret = solo_reg_read(solo_dev, SOLO_GPIO_CONFIG_1);
> + mode =  1 & (ret >> (offset - 8));
> + }
> +
> + if (!mode)
> + return 1;
> + else if (mode == 1)
> + return 0;
> +
> + return -1;
>  }
>  
> +static int solo_gpiochip_direction_input(struct gpio_chip *chip,
> +  unsigned int offset)
> +{
> + return -1;
> +}
> +
> +static int solo_gpiochip_direction_output(struct gpio_chip *chip,
> +   unsigned int offset, int value)
> +{
> + return -1;
> +}
> +
> +static int solo_gpiochip_get(struct gpio_chip *chip,
> + unsigned int offset)
> +{
> + int ret;
> + struct solo_dev *solo_dev = gpiochip_get_data(chip);
> +
> + ret = solo_reg_read(solo_dev, SOLO_GPIO_DATA_IN);
> +
> + return 1 & (ret >> (offset + 8));
> +}
> +
> +static void solo_gpiochip_set(struct gpio_chip *chip,
> + unsigned int offset, int value)
> +{
> + struct solo_dev *solo_dev = gpiochip_get_data(chip);
> +
> + if (value)
> + solo_gpio_set(solo_dev, 1 << (offset + 8));
> + else
> + solo_gpio_clear(solo_dev, 1 << (offset + 8));
> +}
> +#endif
> +
>  int solo_gpio_init(struct solo_dev *solo_dev)
>  {
> + int ret;
> +
>   solo_gpio_config(solo_dev);
> +#ifdef CONFIG_GPIOLIB
> + solo_dev->gpio_dev.label = SOLO6X10_NAME"_gpio";
> + solo_dev->gpio_dev.parent = &solo_dev->pdev->dev;
> + solo_dev->gpio_dev.owner = THIS_MODULE;
> + solo_dev->gpio_dev.base = -1;
> + solo_dev->gpio_dev.ngpio = 24;
> + solo_dev->gpio_dev.can_sleep = 0;
> +
> + solo_dev->gpio_dev.get_direction = solo_gpiochip_get_direction;
> + solo_dev->gpio_dev.direction_input = solo_gpiochip_direction_input;
> + solo_dev->gpio_dev.direction_output = solo_gpiochip_direction_output;
> + solo_dev->gpio_dev.get = solo_gpiochip_get;
> + solo_dev->gpio_dev.set = solo_gpiochip_set;
> +
> + ret = gpiochip_add_data(&solo_dev->gpio_dev, solo_dev);
> +
> + if (ret) {
> + solo_dev->gpio_dev.label = NULL;
> + return -1;
> + }
> +#endif
>   return 0;
>  }
>  
>  void solo_gpio_exit(struct solo_dev *solo_dev)
>  {
> +#ifdef CONFIG_GPIOLIB
> + if (solo_dev->gpio_dev.label) {
> + gpiochip_remove(&solo_dev->gpio_dev);
> + solo_dev->gpio_dev.label = NULL;
> + }
> +#endif
>   solo_gpio_clear(solo_dev, 0x30);
>   solo_gpio_config(solo_dev);
>  }
> diff --git a/drivers/media/pci/solo6x10/solo6x10.h 
> b/drivers/media/pci/solo6x10/solo6x10.h
> index 3f8da5e8c430..3a1893ae2dad 100644
> --- a/drivers/media/pci/solo6x10/solo6x10.h
> +++ b/drivers/media/pci/solo6x10/solo6x10.h
> @@ -31,6 +31,7 @@
>  #include 
>

[PATCH] [media] DaVinci-VPBE: constify vpbe_dev_ops

2017-08-02 Thread Julia Lawall
vpbe_dev_ops is only copied into the ops field at the end of a vpbe_device
structure, so it can be const.

Signed-off-by: Julia Lawall 

---

Does the ops field need to be inlined into the vpbe_device structure?

 drivers/media/platform/davinci/vpbe.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/davinci/vpbe.c 
b/drivers/media/platform/davinci/vpbe.c
index 3679b1e..7f64625 100644
--- a/drivers/media/platform/davinci/vpbe.c
+++ b/drivers/media/platform/davinci/vpbe.c
@@ -790,7 +790,7 @@ static void vpbe_deinitialize(struct device *dev, struct 
vpbe_device *vpbe_dev)
vpss_enable_clock(VPSS_VPBE_CLOCK, 0);
 }
 
-static struct vpbe_device_ops vpbe_dev_ops = {
+static const struct vpbe_device_ops vpbe_dev_ops = {
.g_cropcap = vpbe_g_cropcap,
.enum_outputs = vpbe_enum_outputs,
.set_output = vpbe_set_output,



[PATCH] [media] solo6x10: export hardware GPIO pins 8:31 to gpiolib interface

2017-08-02 Thread Anton Sviridenko
24 GPIO pins from 32 available on solo6x10 chips are exported
to gpiolib. First 8 GPIOs are reserved for internal use on capture card
boards, GPIOs in range 8:15 are configured as outputs to control relays,
remaining 16:31 are configured as inputs to read sensor states.
Now with this patch userspace DVR software can switch relays and read
sensor states when GPIO extension cards are attached to Softlogic solo6x10
based video capture cards.

Signed-off-by: Anton Sviridenko 
---
 drivers/media/pci/solo6x10/solo6x10-gpio.c | 97 ++
 drivers/media/pci/solo6x10/solo6x10.h  |  5 ++
 2 files changed, 102 insertions(+)

diff --git a/drivers/media/pci/solo6x10/solo6x10-gpio.c 
b/drivers/media/pci/solo6x10/solo6x10-gpio.c
index 6d3b4a36bc11..3d0d1aa2f6a8 100644
--- a/drivers/media/pci/solo6x10/solo6x10-gpio.c
+++ b/drivers/media/pci/solo6x10/solo6x10-gpio.c
@@ -57,6 +57,9 @@ static void solo_gpio_mode(struct solo_dev *solo_dev,
ret |= 1 << port;
}
 
+   /* Enable GPIO[31:16] */
+   ret |= 0x;
+
solo_reg_write(solo_dev, SOLO_GPIO_CONFIG_1, ret);
 }
 
@@ -90,16 +93,110 @@ static void solo_gpio_config(struct solo_dev *solo_dev)
 
/* Initially set relay status to 0 */
solo_gpio_clear(solo_dev, 0xff00);
+
+   /* Set input pins direction */
+   solo_gpio_mode(solo_dev, 0x, 0);
+}
+
+#ifdef CONFIG_GPIOLIB
+/* Pins 0-7 are not exported, because it seems from code above they are
+ * used for internal purposes. So offset 0 corresponds to pin 8, therefore
+ * offsets 0-7 are relay GPIOs, 8-23 - input GPIOs.
+ */
+static int solo_gpiochip_get_direction(struct gpio_chip *chip,
+  unsigned int offset)
+{
+   int ret, mode;
+   struct solo_dev *solo_dev = gpiochip_get_data(chip);
+
+   if (offset < 8) {
+   ret = solo_reg_read(solo_dev, SOLO_GPIO_CONFIG_0);
+   mode = 3 & (ret >> ((offset + 8) * 2));
+   } else {
+   ret = solo_reg_read(solo_dev, SOLO_GPIO_CONFIG_1);
+   mode =  1 & (ret >> (offset - 8));
+   }
+
+   if (!mode)
+   return 1;
+   else if (mode == 1)
+   return 0;
+
+   return -1;
 }
 
+static int solo_gpiochip_direction_input(struct gpio_chip *chip,
+unsigned int offset)
+{
+   return -1;
+}
+
+static int solo_gpiochip_direction_output(struct gpio_chip *chip,
+ unsigned int offset, int value)
+{
+   return -1;
+}
+
+static int solo_gpiochip_get(struct gpio_chip *chip,
+   unsigned int offset)
+{
+   int ret;
+   struct solo_dev *solo_dev = gpiochip_get_data(chip);
+
+   ret = solo_reg_read(solo_dev, SOLO_GPIO_DATA_IN);
+
+   return 1 & (ret >> (offset + 8));
+}
+
+static void solo_gpiochip_set(struct gpio_chip *chip,
+   unsigned int offset, int value)
+{
+   struct solo_dev *solo_dev = gpiochip_get_data(chip);
+
+   if (value)
+   solo_gpio_set(solo_dev, 1 << (offset + 8));
+   else
+   solo_gpio_clear(solo_dev, 1 << (offset + 8));
+}
+#endif
+
 int solo_gpio_init(struct solo_dev *solo_dev)
 {
+   int ret;
+
solo_gpio_config(solo_dev);
+#ifdef CONFIG_GPIOLIB
+   solo_dev->gpio_dev.label = SOLO6X10_NAME"_gpio";
+   solo_dev->gpio_dev.parent = &solo_dev->pdev->dev;
+   solo_dev->gpio_dev.owner = THIS_MODULE;
+   solo_dev->gpio_dev.base = -1;
+   solo_dev->gpio_dev.ngpio = 24;
+   solo_dev->gpio_dev.can_sleep = 0;
+
+   solo_dev->gpio_dev.get_direction = solo_gpiochip_get_direction;
+   solo_dev->gpio_dev.direction_input = solo_gpiochip_direction_input;
+   solo_dev->gpio_dev.direction_output = solo_gpiochip_direction_output;
+   solo_dev->gpio_dev.get = solo_gpiochip_get;
+   solo_dev->gpio_dev.set = solo_gpiochip_set;
+
+   ret = gpiochip_add_data(&solo_dev->gpio_dev, solo_dev);
+
+   if (ret) {
+   solo_dev->gpio_dev.label = NULL;
+   return -1;
+   }
+#endif
return 0;
 }
 
 void solo_gpio_exit(struct solo_dev *solo_dev)
 {
+#ifdef CONFIG_GPIOLIB
+   if (solo_dev->gpio_dev.label) {
+   gpiochip_remove(&solo_dev->gpio_dev);
+   solo_dev->gpio_dev.label = NULL;
+   }
+#endif
solo_gpio_clear(solo_dev, 0x30);
solo_gpio_config(solo_dev);
 }
diff --git a/drivers/media/pci/solo6x10/solo6x10.h 
b/drivers/media/pci/solo6x10/solo6x10.h
index 3f8da5e8c430..3a1893ae2dad 100644
--- a/drivers/media/pci/solo6x10/solo6x10.h
+++ b/drivers/media/pci/solo6x10/solo6x10.h
@@ -31,6 +31,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -199,6 +200,10 @@ struct solo_dev {
u32 irq_mask;
u32 motion_mask;
struct v4l2_device  v

[PATCHv3 1/2] tda18250: support for new silicon tuner

2017-08-02 Thread olli . salonen
From: Olli Salonen 

NXP TDA18250 silicon tuner driver.

Version 3 removes regmap_exit as I was pointed out that device
management code automatically frees the regmap.

Signed-off-by: Olli Salonen 
---
 drivers/media/tuners/Kconfig |   7 +
 drivers/media/tuners/Makefile|   1 +
 drivers/media/tuners/tda18250.c  | 921 +++
 drivers/media/tuners/tda18250.h  |  51 ++
 drivers/media/tuners/tda18250_priv.h | 153 ++
 5 files changed, 1133 insertions(+)
 create mode 100644 drivers/media/tuners/tda18250.c
 create mode 100644 drivers/media/tuners/tda18250.h
 create mode 100644 drivers/media/tuners/tda18250_priv.h

diff --git a/drivers/media/tuners/Kconfig b/drivers/media/tuners/Kconfig
index 05998f0..6687514 100644
--- a/drivers/media/tuners/Kconfig
+++ b/drivers/media/tuners/Kconfig
@@ -26,6 +26,13 @@ config MEDIA_TUNER_SIMPLE
help
  Say Y here to include support for various simple tuners.
 
+config MEDIA_TUNER_TDA18250
+   tristate "NXP TDA18250 silicon tuner"
+   depends on MEDIA_SUPPORT && I2C
+   default m if !MEDIA_SUBDRV_AUTOSELECT
+   help
+ Say Y here to include support for TDA18250 tuner.
+
 config MEDIA_TUNER_TDA8290
tristate "TDA 8290/8295 + 8275(a)/18271 tuner combo"
depends on MEDIA_SUPPORT && I2C
diff --git a/drivers/media/tuners/Makefile b/drivers/media/tuners/Makefile
index 06a9ab6..4b9444b 100644
--- a/drivers/media/tuners/Makefile
+++ b/drivers/media/tuners/Makefile
@@ -41,6 +41,7 @@ obj-$(CONFIG_MEDIA_TUNER_R820T) += r820t.o
 obj-$(CONFIG_MEDIA_TUNER_MXL301RF) += mxl301rf.o
 obj-$(CONFIG_MEDIA_TUNER_QM1D1C0042) += qm1d1c0042.o
 obj-$(CONFIG_MEDIA_TUNER_M88RS6000T) += m88rs6000t.o
+obj-$(CONFIG_MEDIA_TUNER_TDA18250) += tda18250.o
 
 ccflags-y += -I$(srctree)/drivers/media/dvb-core
 ccflags-y += -I$(srctree)/drivers/media/dvb-frontends
diff --git a/drivers/media/tuners/tda18250.c b/drivers/media/tuners/tda18250.c
new file mode 100644
index 000..3a10bd1
--- /dev/null
+++ b/drivers/media/tuners/tda18250.c
@@ -0,0 +1,921 @@
+/*
+ * NXP TDA18250 silicon tuner driver
+ *
+ * Copyright (C) 2017 Olli Salonen 
+ *
+ *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 "tda18250_priv.h"
+#include 
+
+static const struct dvb_tuner_ops tda18250_ops;
+
+static int tda18250_power_control(struct dvb_frontend *fe,
+   unsigned int power_state)
+{
+   struct i2c_client *client = fe->tuner_priv;
+   struct tda18250_dev *dev = i2c_get_clientdata(client);
+   int ret;
+   unsigned int utmp;
+
+   dev_dbg(&client->dev, "power state: %d", power_state);
+
+   switch (power_state) {
+   case TDA18250_POWER_NORMAL:
+   ret = regmap_write_bits(dev->regmap, R06_POWER2, 0x07, 0x00);
+   if (ret)
+   goto err;
+   ret = regmap_write_bits(dev->regmap, R25_REF, 0xc0, 0xc0);
+   if (ret)
+   goto err;
+   break;
+   case TDA18250_POWER_STANDBY:
+   if (dev->loopthrough) {
+   ret = regmap_write_bits(dev->regmap, R25_REF, 0xc0, 
0x80);
+   if (ret)
+   goto err;
+   ret = regmap_write_bits(dev->regmap, R06_POWER2, 0x07, 
0x02);
+   if (ret)
+   goto err;
+   ret = regmap_write_bits(dev->regmap, R10_LT1, 0x80, 
0x00);
+   if (ret)
+   goto err;
+   } else {
+   ret = regmap_write_bits(dev->regmap, R25_REF, 0xc0, 
0x80);
+   if (ret)
+   goto err;
+   ret = regmap_write_bits(dev->regmap, R06_POWER2, 0x07, 
0x01);
+   if (ret)
+   goto err;
+   ret = regmap_read(dev->regmap, R0D_AGC12, &utmp);
+   if (ret)
+   goto err;
+   ret = regmap_write_bits(dev->regmap, R0D_AGC12, 0x03, 
0x03);
+   if (ret)
+   goto err;
+   ret = regmap_write_bits(dev->regmap, R10_LT1, 0x80, 
0x80);
+   if (ret)
+   goto err;
+   ret = regmap_write_bits(dev->regmap, R0D_AGC12, 0x03, 
utmp & 0x03);
+   if (ret)
+  

[PATCHv3 2/2] dib0700: add support for Xbox One Digital TV Tuner

2017-08-02 Thread olli . salonen
From: Olli Salonen 

Xbox One Digital TV Tuner is a low-cost USB 2.0 multistandard TV tuner. It
supports DVB-T, DVB-T2 and DVB-C broadcast standards.

USB bridge: DibCom 0700C
Demodulator: Panasonic MN88472
Tuner: TDA18250BHN

The demodulator requires firmware. Download one from here:
http://palosaari.fi/linux/v4l-dvb/firmware/MN88472/02/latest/

Signed-off-by: Olli Salonen 
---
 drivers/media/dvb-core/dvb-usb-ids.h|   2 +
 drivers/media/usb/dvb-usb/Kconfig   |   2 +
 drivers/media/usb/dvb-usb/dib0700.h |   2 +
 drivers/media/usb/dvb-usb/dib0700_core.c|  26 ++-
 drivers/media/usb/dvb-usb/dib0700_devices.c | 109 +++-
 5 files changed, 139 insertions(+), 2 deletions(-)

diff --git a/drivers/media/dvb-core/dvb-usb-ids.h 
b/drivers/media/dvb-core/dvb-usb-ids.h
index 5b6041d..daf49ec 100644
--- a/drivers/media/dvb-core/dvb-usb-ids.h
+++ b/drivers/media/dvb-core/dvb-usb-ids.h
@@ -80,6 +80,7 @@
 #define USB_VID_AZUREWAVE  0x13d3
 #define USB_VID_TECHNISAT  0x14f7
 #define USB_VID_HAMA   0x147f
+#define USB_VID_MICROSOFT  0x045e
 
 /* Product IDs */
 #define USB_PID_ADSTECH_USB2_COLD  0xa333
@@ -417,4 +418,5 @@
 #define USB_PID_WINTV_SOLOHD0x0264
 #define USB_PID_EVOLVEO_XTRATV_STICK   0xa115
 #define USB_PID_HAMA_DVBT_HYBRID   0x2758
+#define USB_PID_XBOX_ONE_TUNER  0x02d5
 #endif
diff --git a/drivers/media/usb/dvb-usb/Kconfig 
b/drivers/media/usb/dvb-usb/Kconfig
index 959fa09..2651ae2 100644
--- a/drivers/media/usb/dvb-usb/Kconfig
+++ b/drivers/media/usb/dvb-usb/Kconfig
@@ -86,6 +86,7 @@ config DVB_USB_DIB0700
select DVB_USB_DIB3000MC if MEDIA_SUBDRV_AUTOSELECT
select DVB_S5H1411 if MEDIA_SUBDRV_AUTOSELECT
select DVB_LGDT3305 if MEDIA_SUBDRV_AUTOSELECT
+   select DVB_MN88472 if MEDIA_SUBDRV_AUTOSELECT
select DVB_TUNER_DIB0070 if MEDIA_SUBDRV_AUTOSELECT
select DVB_TUNER_DIB0090 if MEDIA_SUBDRV_AUTOSELECT
select MEDIA_TUNER_MT2060 if MEDIA_SUBDRV_AUTOSELECT
@@ -94,6 +95,7 @@ config DVB_USB_DIB0700
select MEDIA_TUNER_XC5000 if MEDIA_SUBDRV_AUTOSELECT
select MEDIA_TUNER_XC4000 if MEDIA_SUBDRV_AUTOSELECT
select MEDIA_TUNER_MXL5007T if MEDIA_SUBDRV_AUTOSELECT
+   select MEDIA_TUNER_TDA18250 if MEDIA_SUBDRV_AUTOSELECT
help
  Support for USB2.0/1.1 DVB receivers based on the DiB0700 USB bridge. 
The
  USB bridge is also present in devices having the DiB7700 DVB-T-USB
diff --git a/drivers/media/usb/dvb-usb/dib0700.h 
b/drivers/media/usb/dvb-usb/dib0700.h
index 8fd8f5b..5f29128 100644
--- a/drivers/media/usb/dvb-usb/dib0700.h
+++ b/drivers/media/usb/dvb-usb/dib0700.h
@@ -51,6 +51,8 @@ struct dib0700_state {
int (*read_status)(struct dvb_frontend *, enum fe_status *);
int (*sleep)(struct dvb_frontend* fe);
u8 buf[255];
+   struct i2c_client *i2c_client_demod;
+   struct i2c_client *i2c_client_tuner;
 };
 
 extern int dib0700_get_version(struct dvb_usb_device *d, u32 *hwversion,
diff --git a/drivers/media/usb/dvb-usb/dib0700_core.c 
b/drivers/media/usb/dvb-usb/dib0700_core.c
index bea1b47..dbd031c 100644
--- a/drivers/media/usb/dvb-usb/dib0700_core.c
+++ b/drivers/media/usb/dvb-usb/dib0700_core.c
@@ -911,10 +911,34 @@ static int dib0700_probe(struct usb_interface *intf,
return -ENODEV;
 }
 
+static void dib0700_disconnect(struct usb_interface *intf)
+{
+   struct dvb_usb_device *d = usb_get_intfdata(intf);
+   struct dib0700_state *st = d->priv;
+   struct i2c_client *client;
+
+   /* remove I2C client for tuner */
+   client = st->i2c_client_tuner;
+   if (client) {
+   module_put(client->dev.driver->owner);
+   i2c_unregister_device(client);
+   }
+
+   /* remove I2C client for demodulator */
+   client = st->i2c_client_demod;
+   if (client) {
+   module_put(client->dev.driver->owner);
+   i2c_unregister_device(client);
+   }
+
+   dvb_usb_device_exit(intf);
+}
+
+
 static struct usb_driver dib0700_driver = {
.name   = "dvb_usb_dib0700",
.probe  = dib0700_probe,
-   .disconnect = dvb_usb_device_exit,
+   .disconnect = dib0700_disconnect,
.id_table   = dib0700_usb_id_table,
 };
 
diff --git a/drivers/media/usb/dvb-usb/dib0700_devices.c 
b/drivers/media/usb/dvb-usb/dib0700_devices.c
index 6a57fc6..7c0fb18 100644
--- a/drivers/media/usb/dvb-usb/dib0700_devices.c
+++ b/drivers/media/usb/dvb-usb/dib0700_devices.c
@@ -23,6 +23,9 @@
 #include "dib0090.h"
 #include "lgdt3305.h"
 #include "mxl5007t.h"
+#include "mn88472.h"
+#include "tda18250.h"
+
 
 static int force_lna_activation;
 module_param(force_lna_activation, int, 0644);
@@ -3725,6 +3728,90 @@ static int mxl5007t_tuner_attach(struct dvb_usb_adapter 
*ad

Re: [PATCH v2 11/14] v4l: vsp1: Add support for header display lists in continuous mode

2017-08-02 Thread Kieran Bingham
On 01/08/17 19:47, Laurent Pinchart wrote:
> Hi Kieran,
> 
> On Tuesday 01 Aug 2017 18:35:48 Kieran Bingham wrote:
>> On 26/06/17 19:12, Laurent Pinchart wrote:
>>> The VSP supports both header and headerless display lists. The latter is
>>> easier to use when the VSP feeds data directly to the DU in continuous
>>> mode, and the driver thus uses headerless display lists for DU operation
>>> and header display lists otherwise.
>>>
>>> Headerless display lists are only available on WPF.0. This has never
>>> been an issue so far, as only WPF.0 is connected to the DU. However, on
>>> H3 ES2.0, the VSP-DL instance has both WPF.0 and WPF.1 connected to the
>>> DU. We thus can't use headerless display lists unconditionally for DU
>>> operation.
>>
>> Would it be crazy to suggest we drop headerless display lists?
>>
>> If we must support header display lists in continuous mode - Rather than
>> having 2 cases for continuous modes to support (having to support
>> headerless, on WPF.0, and header on WPF.1) if we just use your header loop
>> trick - would that simplify our code maintenance?
>>
>> (We can always remove headerless support later if you agree, this is more of
>> an idea at the moment)
> 
> I had the exact same thought, but I believe we should wait a few kernel 
> releases to see if the next code is stable before removing the old one. I 
> have 
> a debug patch that forces usage of header display lists unconditionally, and 
> I'll try to develop a few additional stress-tests for that.

Sounds like a good plan.

--
Kieran


Re: [PATCH v1 0/4] media: rc: add support for IR receiver on MT7622 SoC

2017-08-02 Thread Sean Young
Hi Sean,

On Wed, Aug 02, 2017 at 10:24:07AM +0800, Sean Wang wrote:
> Hi, Mauro and Sean
> 
> Just a gentle ping on the whole patchset porting MediaTek CIR to another
> platform.

I'm creating the rc-core pull request, should be done by the end of the week. 


Sean


[PATCH v6] rockchip/rga: v4l2 m2m support

2017-08-02 Thread Jacob Chen
Rockchip RGA is a separate 2D raster graphic acceleration unit. It
accelerates 2D graphics operations, such as point/line drawing, image
scaling, rotation, BitBLT, alpha blending and image blur/sharpness

The drvier is mostly based on s5p-g2d v4l2 m2m driver
And supports various operations from the rendering pipeline.
 - copy
 - fast solid color fill
 - rotation
 - flip
 - alpha blending

The code in rga-hw.c is used to configure regs according to operations
The code in rga-buf.c is used to create private mmu table for RGA.

changes in v6:
- correct a log order

Signed-off-by: Jacob Chen 
---
 drivers/media/platform/Kconfig|   11 +
 drivers/media/platform/Makefile   |2 +
 drivers/media/platform/rockchip-rga/Makefile  |3 +
 drivers/media/platform/rockchip-rga/rga-buf.c |  155 
 drivers/media/platform/rockchip-rga/rga-hw.c  |  671 
 drivers/media/platform/rockchip-rga/rga-hw.h  |  437 +++
 drivers/media/platform/rockchip-rga/rga.c | 1026 +
 drivers/media/platform/rockchip-rga/rga.h |  110 +++
 8 files changed, 2415 insertions(+)
 create mode 100644 drivers/media/platform/rockchip-rga/Makefile
 create mode 100644 drivers/media/platform/rockchip-rga/rga-buf.c
 create mode 100644 drivers/media/platform/rockchip-rga/rga-hw.c
 create mode 100644 drivers/media/platform/rockchip-rga/rga-hw.h
 create mode 100644 drivers/media/platform/rockchip-rga/rga.c
 create mode 100644 drivers/media/platform/rockchip-rga/rga.h

diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index 041cb80a..d0d1a21 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -427,6 +427,17 @@ config VIDEO_RENESAS_VSP1
  To compile this driver as a module, choose M here: the module
  will be called vsp1.
 
+config VIDEO_ROCKCHIP_RGA
+   tristate "Rockchip Raster 2d Grapphic Acceleration Unit"
+   depends on VIDEO_DEV && VIDEO_V4L2 && HAS_DMA
+   depends on ARCH_ROCKCHIP || COMPILE_TEST
+   select VIDEOBUF2_DMA_SG
+   select V4L2_MEM2MEM_DEV
+   default n
+   ---help---
+ This is a v4l2 driver for Rockchip SOC RGA2
+ 2d graphics accelerator.
+
 config VIDEO_TI_VPE
tristate "TI VPE (Video Processing Engine) driver"
depends on VIDEO_DEV && VIDEO_V4L2
diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile
index 63303d6..baf83060 100644
--- a/drivers/media/platform/Makefile
+++ b/drivers/media/platform/Makefile
@@ -57,6 +57,8 @@ obj-$(CONFIG_VIDEO_RENESAS_FDP1)  += rcar_fdp1.o
 obj-$(CONFIG_VIDEO_RENESAS_JPU)+= rcar_jpu.o
 obj-$(CONFIG_VIDEO_RENESAS_VSP1)   += vsp1/
 
+obj-$(CONFIG_VIDEO_ROCKCHIP_RGA)   += rockchip-rga/
+
 obj-y  += omap/
 
 obj-$(CONFIG_VIDEO_AM437X_VPFE)+= am437x/
diff --git a/drivers/media/platform/rockchip-rga/Makefile 
b/drivers/media/platform/rockchip-rga/Makefile
new file mode 100644
index 000..92fe254
--- /dev/null
+++ b/drivers/media/platform/rockchip-rga/Makefile
@@ -0,0 +1,3 @@
+rockchip-rga-objs := rga.o rga-hw.o rga-buf.o
+
+obj-$(CONFIG_VIDEO_ROCKCHIP_RGA) += rockchip-rga.o
diff --git a/drivers/media/platform/rockchip-rga/rga-buf.c 
b/drivers/media/platform/rockchip-rga/rga-buf.c
new file mode 100644
index 000..6a9fd2c
--- /dev/null
+++ b/drivers/media/platform/rockchip-rga/rga-buf.c
@@ -0,0 +1,155 @@
+/*
+ * Copyright (C) 2017 Fuzhou Rockchip Electronics Co.Ltd
+ * Author: Jacob Chen 
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * 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 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "rga-hw.h"
+#include "rga.h"
+
+static int
+rga_queue_setup(struct vb2_queue *vq,
+   unsigned int *nbuffers, unsigned int *nplanes,
+   unsigned int sizes[], struct device *alloc_devs[])
+{
+   struct rga_ctx *ctx = vb2_get_drv_priv(vq);
+   struct rga_frame *f = rga_get_frame(ctx, vq->type);
+
+   if (IS_ERR(f))
+   return PTR_ERR(f);
+
+   if (*nplanes)
+   return sizes[0] < f->size ? -EINVAL : 0;
+
+   sizes[0] = f->size;
+   *nplanes = 1;
+
+   return 0;
+}
+
+static int rga_buf_prepare(struct vb2_buffer *vb)
+{
+   struct rga_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
+   struct rga_frame *f = rga_get_frame(ctx, vb->vb2_queue->type);
+
+   if (IS_ERR(f))
+   return PTR_ERR(f);
+
+   vb2_set_plane_payload(vb, 0, f->size);
+
+   return 0;
+}
+
+static void rga_buf_queue(struct vb2_buffer *vb)
+{
+  

[PATCHv2 2/9] omapdrm: hdmi.h: extend hdmi_core_data with CEC fields

2017-08-02 Thread Hans Verkuil
From: Hans Verkuil 

Extend the hdmi_core_data struct with the additional fields needed
for CEC.

Also fix a simple typo in a comment.

Signed-off-by: Hans Verkuil 
---
 drivers/gpu/drm/omapdrm/dss/hdmi.h | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/omapdrm/dss/hdmi.h 
b/drivers/gpu/drm/omapdrm/dss/hdmi.h
index fb6cccd02374..3913859146b9 100644
--- a/drivers/gpu/drm/omapdrm/dss/hdmi.h
+++ b/drivers/gpu/drm/omapdrm/dss/hdmi.h
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "omapdss.h"
 #include "dss.h"
@@ -254,6 +255,9 @@ struct hdmi_phy_data {
 
 struct hdmi_core_data {
void __iomem *base;
+   struct hdmi_wp_data *wp;
+   unsigned int core_pwr_cnt;
+   struct cec_adapter *adap;
 };
 
 static inline void hdmi_write_reg(void __iomem *base_addr, const u32 idx,
@@ -361,7 +365,7 @@ struct omap_hdmi {
bool audio_configured;
struct omap_dss_audio audio_config;
 
-   /* This lock should be taken when booleans bellow are touched. */
+   /* This lock should be taken when booleans below are touched. */
spinlock_t audio_playing_lock;
bool audio_playing;
bool display_enabled;
-- 
2.13.2



[PATCHv2 4/9] omapdrm: hdmi4: prepare irq handling for HDMI CEC support

2017-08-02 Thread Hans Verkuil
From: Hans Verkuil 

Pass struct omap_hdmi to the irq handler since it will need access
to hdmi.core.

Do not clear the IRQ_HDMI_CORE bit: that will be controlled by the
HDMI CEC code.

Signed-off-by: Hans Verkuil 
---
 drivers/gpu/drm/omapdrm/dss/hdmi4.c | 11 ++-
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/omapdrm/dss/hdmi4.c 
b/drivers/gpu/drm/omapdrm/dss/hdmi4.c
index 99af926ca0f5..eb9c6636f660 100644
--- a/drivers/gpu/drm/omapdrm/dss/hdmi4.c
+++ b/drivers/gpu/drm/omapdrm/dss/hdmi4.c
@@ -71,7 +71,8 @@ static void hdmi_runtime_put(void)
 
 static irqreturn_t hdmi_irq_handler(int irq, void *data)
 {
-   struct hdmi_wp_data *wp = data;
+   struct omap_hdmi *hdmi = data;
+   struct hdmi_wp_data *wp = &hdmi->wp;
u32 irqstatus;
 
irqstatus = hdmi_wp_get_irqstatus(wp);
@@ -167,8 +168,8 @@ static int hdmi_power_on_full(struct omap_dss_device 
*dssdev)
return r;
 
/* disable and clear irqs */
-   hdmi_wp_clear_irqenable(wp, 0x);
-   hdmi_wp_set_irqstatus(wp, 0x);
+   hdmi_wp_clear_irqenable(wp, ~HDMI_IRQ_CORE);
+   hdmi_wp_set_irqstatus(wp, ~HDMI_IRQ_CORE);
 
vm = &hdmi.cfg.vm;
 
@@ -243,7 +244,7 @@ static void hdmi_power_off_full(struct omap_dss_device 
*dssdev)
 {
enum omap_channel channel = dssdev->dispc_channel;
 
-   hdmi_wp_clear_irqenable(&hdmi.wp, 0x);
+   hdmi_wp_clear_irqenable(&hdmi.wp, ~HDMI_IRQ_CORE);
 
hdmi_wp_video_stop(&hdmi.wp);
 
@@ -725,7 +726,7 @@ static int hdmi4_bind(struct device *dev, struct device 
*master, void *data)
 
r = devm_request_threaded_irq(&pdev->dev, irq,
NULL, hdmi_irq_handler,
-   IRQF_ONESHOT, "OMAP HDMI", &hdmi.wp);
+   IRQF_ONESHOT, "OMAP HDMI", &hdmi);
if (r) {
DSSERR("HDMI IRQ request failed\n");
goto err;
-- 
2.13.2



[PATCHv2 9/9] omapdrm: omapdss_hdmi_ops: add lost_hotplug op

2017-08-02 Thread Hans Verkuil
From: Hans Verkuil 

The CEC framework needs to know when the hotplug detect signal
disappears, since that means the CEC physical address has to be
invalidated (i.e. set to f.f.f.f).

Add a lost_hotplug op that is called when the HPD signal goes away.

Signed-off-by: Hans Verkuil 
---
 drivers/gpu/drm/omapdrm/displays/connector-hdmi.c| 8 ++--
 drivers/gpu/drm/omapdrm/displays/encoder-tpd12s015.c | 6 +-
 drivers/gpu/drm/omapdrm/dss/hdmi4.c  | 8 ++--
 drivers/gpu/drm/omapdrm/dss/omapdss.h| 1 +
 4 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/omapdrm/displays/connector-hdmi.c 
b/drivers/gpu/drm/omapdrm/displays/connector-hdmi.c
index d9d25df6fc1b..4600d3841c25 100644
--- a/drivers/gpu/drm/omapdrm/displays/connector-hdmi.c
+++ b/drivers/gpu/drm/omapdrm/displays/connector-hdmi.c
@@ -165,11 +165,15 @@ static bool hdmic_detect(struct omap_dss_device *dssdev)
 {
struct panel_drv_data *ddata = to_panel_data(dssdev);
struct omap_dss_device *in = ddata->in;
+   bool connected;
 
if (gpio_is_valid(ddata->hpd_gpio))
-   return gpio_get_value_cansleep(ddata->hpd_gpio);
+   connected = gpio_get_value_cansleep(ddata->hpd_gpio);
else
-   return in->ops.hdmi->detect(in);
+   connected = in->ops.hdmi->detect(in);
+   if (!connected && in->ops.hdmi->lost_hotplug)
+   in->ops.hdmi->lost_hotplug(in);
+   return connected;
 }
 
 static int hdmic_register_hpd_cb(struct omap_dss_device *dssdev,
diff --git a/drivers/gpu/drm/omapdrm/displays/encoder-tpd12s015.c 
b/drivers/gpu/drm/omapdrm/displays/encoder-tpd12s015.c
index 293b8fd07cfc..20058800aab3 100644
--- a/drivers/gpu/drm/omapdrm/displays/encoder-tpd12s015.c
+++ b/drivers/gpu/drm/omapdrm/displays/encoder-tpd12s015.c
@@ -159,8 +159,12 @@ static int tpd_read_edid(struct omap_dss_device *dssdev,
 static bool tpd_detect(struct omap_dss_device *dssdev)
 {
struct panel_drv_data *ddata = to_panel_data(dssdev);
+   struct omap_dss_device *in = ddata->in;
+   bool connected = gpiod_get_value_cansleep(ddata->hpd_gpio);
 
-   return gpiod_get_value_cansleep(ddata->hpd_gpio);
+   if (!connected)
+   in->ops.hdmi->lost_hotplug(in);
+   return connected;
 }
 
 static int tpd_register_hpd_cb(struct omap_dss_device *dssdev,
diff --git a/drivers/gpu/drm/omapdrm/dss/hdmi4.c 
b/drivers/gpu/drm/omapdrm/dss/hdmi4.c
index e535010218e6..0eeba0d1a2f5 100644
--- a/drivers/gpu/drm/omapdrm/dss/hdmi4.c
+++ b/drivers/gpu/drm/omapdrm/dss/hdmi4.c
@@ -402,8 +402,6 @@ static void hdmi_display_disable(struct omap_dss_device 
*dssdev)
 
DSSDBG("Enter hdmi_display_disable\n");
 
-   hdmi4_cec_set_phys_addr(&hdmi.core, CEC_PHYS_ADDR_INVALID);
-
mutex_lock(&hdmi.lock);
 
spin_lock_irqsave(&hdmi.audio_playing_lock, flags);
@@ -515,6 +513,11 @@ static int hdmi_read_edid(struct omap_dss_device *dssdev,
return r;
 }
 
+static void hdmi_lost_hotplug(struct omap_dss_device *dssdev)
+{
+   hdmi4_cec_set_phys_addr(&hdmi.core, CEC_PHYS_ADDR_INVALID);
+}
+
 static int hdmi_set_infoframe(struct omap_dss_device *dssdev,
const struct hdmi_avi_infoframe *avi)
 {
@@ -541,6 +544,7 @@ static const struct omapdss_hdmi_ops hdmi_ops = {
.get_timings= hdmi_display_get_timings,
 
.read_edid  = hdmi_read_edid,
+   .lost_hotplug   = hdmi_lost_hotplug,
.set_infoframe  = hdmi_set_infoframe,
.set_hdmi_mode  = hdmi_set_hdmi_mode,
 };
diff --git a/drivers/gpu/drm/omapdrm/dss/omapdss.h 
b/drivers/gpu/drm/omapdrm/dss/omapdss.h
index b9b0bb27069a..482a385894d7 100644
--- a/drivers/gpu/drm/omapdrm/dss/omapdss.h
+++ b/drivers/gpu/drm/omapdrm/dss/omapdss.h
@@ -402,6 +402,7 @@ struct omapdss_hdmi_ops {
struct videomode *vm);
 
int (*read_edid)(struct omap_dss_device *dssdev, u8 *buf, int len);
+   void (*lost_hotplug)(struct omap_dss_device *dssdev);
bool (*detect)(struct omap_dss_device *dssdev);
 
int (*register_hpd_cb)(struct omap_dss_device *dssdev,
-- 
2.13.2



[PATCHv2 1/9] omapdrm: encoder-tpd12s015: keep ls_oe_gpio high

2017-08-02 Thread Hans Verkuil
From: Hans Verkuil 

For OMAP4 CEC support the CEC pin should always be on. So keep
ls_oe_gpio high all the time in order to support CEC.

Background: even if the HPD is low it should still be possible
to use CEC. Some displays will set the HPD low when they go into standby or
when they switch to another input, but CEC is still available and able
to wake up/change input for such a display.

This is explicitly allowed by the CEC standard.

Signed-off-by: Hans Verkuil 
---
 drivers/gpu/drm/omapdrm/displays/encoder-tpd12s015.c | 12 
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/omapdrm/displays/encoder-tpd12s015.c 
b/drivers/gpu/drm/omapdrm/displays/encoder-tpd12s015.c
index a9e9d667c55e..293b8fd07cfc 100644
--- a/drivers/gpu/drm/omapdrm/displays/encoder-tpd12s015.c
+++ b/drivers/gpu/drm/omapdrm/displays/encoder-tpd12s015.c
@@ -51,6 +51,8 @@ static int tpd_connect(struct omap_dss_device *dssdev,
dssdev->dst = dst;
 
gpiod_set_value_cansleep(ddata->ct_cp_hpd_gpio, 1);
+   gpiod_set_value_cansleep(ddata->ls_oe_gpio, 1);
+
/* DC-DC converter needs at max 300us to get to 90% of 5V */
udelay(300);
 
@@ -69,6 +71,7 @@ static void tpd_disconnect(struct omap_dss_device *dssdev,
return;
 
gpiod_set_value_cansleep(ddata->ct_cp_hpd_gpio, 0);
+   gpiod_set_value_cansleep(ddata->ls_oe_gpio, 0);
 
dst->src = NULL;
dssdev->dst = NULL;
@@ -146,18 +149,11 @@ static int tpd_read_edid(struct omap_dss_device *dssdev,
 {
struct panel_drv_data *ddata = to_panel_data(dssdev);
struct omap_dss_device *in = ddata->in;
-   int r;
 
if (!gpiod_get_value_cansleep(ddata->hpd_gpio))
return -ENODEV;
 
-   gpiod_set_value_cansleep(ddata->ls_oe_gpio, 1);
-
-   r = in->ops.hdmi->read_edid(in, edid, len);
-
-   gpiod_set_value_cansleep(ddata->ls_oe_gpio, 0);
-
-   return r;
+   return in->ops.hdmi->read_edid(in, edid, len);
 }
 
 static bool tpd_detect(struct omap_dss_device *dssdev)
-- 
2.13.2



[PATCHv2 5/9] omapdrm: hdmi4: move hdmi4_core_powerdown_disable to hdmi_power_on_core()

2017-08-02 Thread Hans Verkuil
From: Hans Verkuil 

Call hdmi4_core_powerdown_disable() in hdmi_power_on_core() to
power up the HDMI core (needed for CEC). The same call can now be dropped
in hdmi4_configure().

Signed-off-by: Hans Verkuil 
---
 drivers/gpu/drm/omapdrm/dss/hdmi4.c  | 2 ++
 drivers/gpu/drm/omapdrm/dss/hdmi4_core.c | 3 ---
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/omapdrm/dss/hdmi4.c 
b/drivers/gpu/drm/omapdrm/dss/hdmi4.c
index eb9c6636f660..bf91cbef78c1 100644
--- a/drivers/gpu/drm/omapdrm/dss/hdmi4.c
+++ b/drivers/gpu/drm/omapdrm/dss/hdmi4.c
@@ -133,6 +133,8 @@ static int hdmi_power_on_core(struct omap_dss_device 
*dssdev)
if (r)
goto err_runtime_get;
 
+   hdmi4_core_powerdown_disable(&hdmi.core);
+
/* Make selection of HDMI in DSS */
dss_select_hdmi_venc_clk_source(DSS_HDMI_M_PCLK);
 
diff --git a/drivers/gpu/drm/omapdrm/dss/hdmi4_core.c 
b/drivers/gpu/drm/omapdrm/dss/hdmi4_core.c
index b91244378ed1..ca3f2cf773d1 100644
--- a/drivers/gpu/drm/omapdrm/dss/hdmi4_core.c
+++ b/drivers/gpu/drm/omapdrm/dss/hdmi4_core.c
@@ -335,9 +335,6 @@ void hdmi4_configure(struct hdmi_core_data *core,
 */
hdmi_core_swreset_assert(core);
 
-   /* power down off */
-   hdmi4_core_powerdown_disable(core);
-
v_core_cfg.pkt_mode = HDMI_PACKETMODE24BITPERPIXEL;
v_core_cfg.hdmi_dvi = cfg->hdmi_dvi_mode;
 
-- 
2.13.2



[PATCHv2 6/9] omapdrm: hdmi4: refcount hdmi_power_on/off_core

2017-08-02 Thread Hans Verkuil
From: Hans Verkuil 

The hdmi_power_on/off_core functions can be called multiple times:
when the HPD changes and when the HDMI CEC support needs to power
the HDMI core.

So use a counter to know when to really power on or off the HDMI core.

Signed-off-by: Hans Verkuil 
---
 drivers/gpu/drm/omapdrm/dss/hdmi4.c | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/omapdrm/dss/hdmi4.c 
b/drivers/gpu/drm/omapdrm/dss/hdmi4.c
index bf91cbef78c1..166aa4df7688 100644
--- a/drivers/gpu/drm/omapdrm/dss/hdmi4.c
+++ b/drivers/gpu/drm/omapdrm/dss/hdmi4.c
@@ -125,9 +125,12 @@ static int hdmi_power_on_core(struct omap_dss_device 
*dssdev)
 {
int r;
 
+   if (hdmi.core.core_pwr_cnt++)
+   return 0;
+
r = regulator_enable(hdmi.vdda_reg);
if (r)
-   return r;
+   goto err_reg_enable;
 
r = hdmi_runtime_get();
if (r)
@@ -144,12 +147,17 @@ static int hdmi_power_on_core(struct omap_dss_device 
*dssdev)
 
 err_runtime_get:
regulator_disable(hdmi.vdda_reg);
+err_reg_enable:
+   hdmi.core.core_pwr_cnt--;
 
return r;
 }
 
 static void hdmi_power_off_core(struct omap_dss_device *dssdev)
 {
+   if (--hdmi.core.core_pwr_cnt)
+   return;
+
hdmi.core_enabled = false;
 
hdmi_runtime_put();
-- 
2.13.2



[PATCHv2 7/9] omapdrm: hdmi4_cec: add OMAP4 HDMI CEC support

2017-08-02 Thread Hans Verkuil
From: Hans Verkuil 

Add the source and header for the OMAP4 HDMI CEC support.

This code is not yet hooked up, that will happen in the next patch.

Signed-off-by: Hans Verkuil 
---
 drivers/gpu/drm/omapdrm/dss/hdmi4_cec.c | 381 
 drivers/gpu/drm/omapdrm/dss/hdmi4_cec.h |  55 +
 2 files changed, 436 insertions(+)
 create mode 100644 drivers/gpu/drm/omapdrm/dss/hdmi4_cec.c
 create mode 100644 drivers/gpu/drm/omapdrm/dss/hdmi4_cec.h

diff --git a/drivers/gpu/drm/omapdrm/dss/hdmi4_cec.c 
b/drivers/gpu/drm/omapdrm/dss/hdmi4_cec.c
new file mode 100644
index ..d86873f2abe6
--- /dev/null
+++ b/drivers/gpu/drm/omapdrm/dss/hdmi4_cec.c
@@ -0,0 +1,381 @@
+/*
+ * HDMI CEC
+ *
+ * Based on the CEC code from hdmi_ti_4xxx_ip.c from Android.
+ *
+ * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com/
+ * Authors: Yong Zhi
+ * Mythri pk 
+ *
+ * Heavily modified to use the linux CEC framework:
+ *
+ * Copyright 2016-2017 Cisco Systems, Inc. and/or its affiliates. All rights 
reserved.
+ *
+ * This program is free software; you may redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "dss.h"
+#include "hdmi.h"
+#include "hdmi4_core.h"
+#include "hdmi4_cec.h"
+
+/* HDMI CEC */
+#define HDMI_CEC_DEV_ID 0x900
+#define HDMI_CEC_SPEC   0x904
+
+/* Not really a debug register, more a low-level control register */
+#define HDMI_CEC_DBG_3  0x91C
+#define HDMI_CEC_TX_INIT0x920
+#define HDMI_CEC_TX_DEST0x924
+#define HDMI_CEC_SETUP  0x938
+#define HDMI_CEC_TX_COMMAND 0x93C
+#define HDMI_CEC_TX_OPERAND 0x940
+#define HDMI_CEC_TRANSMIT_DATA  0x97C
+#define HDMI_CEC_CA_7_0 0x988
+#define HDMI_CEC_CA_15_80x98C
+#define HDMI_CEC_INT_STATUS_0   0x998
+#define HDMI_CEC_INT_STATUS_1   0x99C
+#define HDMI_CEC_INT_ENABLE_0   0x990
+#define HDMI_CEC_INT_ENABLE_1   0x994
+#define HDMI_CEC_RX_CONTROL 0x9B0
+#define HDMI_CEC_RX_COUNT   0x9B4
+#define HDMI_CEC_RX_CMD_HEADER  0x9B8
+#define HDMI_CEC_RX_COMMAND 0x9BC
+#define HDMI_CEC_RX_OPERAND 0x9C0
+
+#define HDMI_CEC_TX_FIFO_INT_MASK  0x64
+#define HDMI_CEC_RETRANSMIT_CNT_INT_MASK   0x2
+
+#define HDMI_CORE_CEC_RETRY200
+
+static void hdmi_cec_received_msg(struct hdmi_core_data *core)
+{
+   u32 cnt = hdmi_read_reg(core->base, HDMI_CEC_RX_COUNT) & 0xff;
+
+   /* While there are CEC frames in the FIFO */
+   while (cnt & 0x70) {
+   /* and the frame doesn't have an error */
+   if (!(cnt & 0x80)) {
+   struct cec_msg msg = {};
+   unsigned int i;
+
+   /* then read the message */
+   msg.len = cnt & 0xf;
+   msg.msg[0] = hdmi_read_reg(core->base,
+  HDMI_CEC_RX_CMD_HEADER);
+   msg.msg[1] = hdmi_read_reg(core->base,
+  HDMI_CEC_RX_COMMAND);
+   for (i = 0; i < msg.len; i++) {
+   unsigned int reg = HDMI_CEC_RX_OPERAND + i * 4;
+
+   msg.msg[2 + i] =
+   hdmi_read_reg(core->base, reg);
+   }
+   msg.len += 2;
+   cec_received_msg(core->adap, &msg);
+   }
+   /* Clear the current frame from the FIFO */
+   hdmi_write_reg(core->base, HDMI_CEC_RX_CONTROL, 1);
+   /* Wait until the current frame is cleared */
+   while (hdmi_read_reg(core->base, HDMI_CEC_RX_CONTROL) & 1)
+   udelay(1);
+   /*
+* Re-read the count register and loop to see if there are
+* more messages in the FIFO.
+*/
+   cnt = hdmi_read_reg(core->base, HDMI_CEC_RX_COUNT) & 0xff;
+   }
+}
+
+static void hd

[PATCHv2 3/9] omapdrm: hdmi4: make low-level functions available

2017-08-02 Thread Hans Verkuil
From: Hans Verkuil 

Three low-level functions in hdmi4.c and hdmi4_core.c are
made available for use by the OMAP4 CEC support.

Renamed the prefix to hdmi4 since these are OMAP4 specific.

These function deal with the HDMI core and are needed to
power it up for use with CEC, even when the HPD is low.

Background: even if the HPD is low it should still be possible
to use CEC. Some displays will set the HPD low when they go into standby or
when they switch to another input, but CEC is still available and able
to wake up/change input for such a display.

This is explicitly allowed by the CEC standard.

Signed-off-by: Hans Verkuil 
---
 drivers/gpu/drm/omapdrm/dss/hdmi4.c  | 12 ++--
 drivers/gpu/drm/omapdrm/dss/hdmi4_core.c |  6 +++---
 drivers/gpu/drm/omapdrm/dss/hdmi4_core.h |  4 
 3 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/omapdrm/dss/hdmi4.c 
b/drivers/gpu/drm/omapdrm/dss/hdmi4.c
index 284b4942b9ac..99af926ca0f5 100644
--- a/drivers/gpu/drm/omapdrm/dss/hdmi4.c
+++ b/drivers/gpu/drm/omapdrm/dss/hdmi4.c
@@ -394,11 +394,11 @@ static void hdmi_display_disable(struct omap_dss_device 
*dssdev)
mutex_unlock(&hdmi.lock);
 }
 
-static int hdmi_core_enable(struct omap_dss_device *dssdev)
+int hdmi4_core_enable(struct omap_dss_device *dssdev)
 {
int r = 0;
 
-   DSSDBG("ENTER omapdss_hdmi_core_enable\n");
+   DSSDBG("ENTER omapdss_hdmi4_core_enable\n");
 
mutex_lock(&hdmi.lock);
 
@@ -416,9 +416,9 @@ static int hdmi_core_enable(struct omap_dss_device *dssdev)
return r;
 }
 
-static void hdmi_core_disable(struct omap_dss_device *dssdev)
+void hdmi4_core_disable(struct omap_dss_device *dssdev)
 {
-   DSSDBG("Enter omapdss_hdmi_core_disable\n");
+   DSSDBG("Enter omapdss_hdmi4_core_disable\n");
 
mutex_lock(&hdmi.lock);
 
@@ -476,7 +476,7 @@ static int hdmi_read_edid(struct omap_dss_device *dssdev,
need_enable = hdmi.core_enabled == false;
 
if (need_enable) {
-   r = hdmi_core_enable(dssdev);
+   r = hdmi4_core_enable(dssdev);
if (r)
return r;
}
@@ -484,7 +484,7 @@ static int hdmi_read_edid(struct omap_dss_device *dssdev,
r = read_edid(edid, len);
 
if (need_enable)
-   hdmi_core_disable(dssdev);
+   hdmi4_core_disable(dssdev);
 
return r;
 }
diff --git a/drivers/gpu/drm/omapdrm/dss/hdmi4_core.c 
b/drivers/gpu/drm/omapdrm/dss/hdmi4_core.c
index ed6001613405..b91244378ed1 100644
--- a/drivers/gpu/drm/omapdrm/dss/hdmi4_core.c
+++ b/drivers/gpu/drm/omapdrm/dss/hdmi4_core.c
@@ -208,9 +208,9 @@ static void hdmi_core_init(struct hdmi_core_video_config 
*video_cfg)
video_cfg->tclk_sel_clkmult = HDMI_FPLL10IDCK;
 }
 
-static void hdmi_core_powerdown_disable(struct hdmi_core_data *core)
+void hdmi4_core_powerdown_disable(struct hdmi_core_data *core)
 {
-   DSSDBG("Enter hdmi_core_powerdown_disable\n");
+   DSSDBG("Enter hdmi4_core_powerdown_disable\n");
REG_FLD_MOD(core->base, HDMI_CORE_SYS_SYS_CTRL1, 0x1, 0, 0);
 }
 
@@ -336,7 +336,7 @@ void hdmi4_configure(struct hdmi_core_data *core,
hdmi_core_swreset_assert(core);
 
/* power down off */
-   hdmi_core_powerdown_disable(core);
+   hdmi4_core_powerdown_disable(core);
 
v_core_cfg.pkt_mode = HDMI_PACKETMODE24BITPERPIXEL;
v_core_cfg.hdmi_dvi = cfg->hdmi_dvi_mode;
diff --git a/drivers/gpu/drm/omapdrm/dss/hdmi4_core.h 
b/drivers/gpu/drm/omapdrm/dss/hdmi4_core.h
index a069f96ec6f6..b6ab579e44d2 100644
--- a/drivers/gpu/drm/omapdrm/dss/hdmi4_core.h
+++ b/drivers/gpu/drm/omapdrm/dss/hdmi4_core.h
@@ -266,6 +266,10 @@ void hdmi4_configure(struct hdmi_core_data *core, struct 
hdmi_wp_data *wp,
 void hdmi4_core_dump(struct hdmi_core_data *core, struct seq_file *s);
 int hdmi4_core_init(struct platform_device *pdev, struct hdmi_core_data *core);
 
+int hdmi4_core_enable(struct omap_dss_device *dssdev);
+void hdmi4_core_disable(struct omap_dss_device *dssdev);
+void hdmi4_core_powerdown_disable(struct hdmi_core_data *core);
+
 int hdmi4_audio_start(struct hdmi_core_data *core, struct hdmi_wp_data *wp);
 void hdmi4_audio_stop(struct hdmi_core_data *core, struct hdmi_wp_data *wp);
 int hdmi4_audio_config(struct hdmi_core_data *core, struct hdmi_wp_data *wp,
-- 
2.13.2



[PATCHv2 0/9] omapdrm: hdmi4: add CEC support

2017-08-02 Thread Hans Verkuil
From: Hans Verkuil 

This patch series adds CEC support for the omap4. It is based on
the 4.13-rc2 kernel with this patch series applied:

http://www.spinics.net/lists/dri-devel/msg143440.html

It is virtually identical to the first patch series posted in
April:

http://www.spinics.net/lists/dri-devel/msg138950.html

The only two changes are in the Kconfig due to CEC Kconfig
changes in 4.13 (it now selects CEC_CORE instead of depending on
CEC_CORE) and a final patch was added adding a lost_hotplug op
since for proper CEC support I have to know when the hotplug
signal goes away.

Tested with my Pandaboard.

The lost_hotplug op is called only when the hotplug is lost,
but I am happy to change it to an op that is called whenever
the hotplug signal changes. Just let me know. I just implemented
the minimal solution that I needed.

Regards,

Hans

Hans Verkuil (9):
  omapdrm: encoder-tpd12s015: keep ls_oe_gpio high
  omapdrm: hdmi.h: extend hdmi_core_data with CEC fields
  omapdrm: hdmi4: make low-level functions available
  omapdrm: hdmi4: prepare irq handling for HDMI CEC support
  omapdrm: hdmi4: move hdmi4_core_powerdown_disable to
hdmi_power_on_core()
  omapdrm: hdmi4: refcount hdmi_power_on/off_core
  omapdrm: hdmi4_cec: add OMAP4 HDMI CEC support
  omapdrm: hdmi4: hook up the HDMI CEC support
  omapdrm: omapdss_hdmi_ops: add lost_hotplug op

 drivers/gpu/drm/omapdrm/displays/connector-hdmi.c  |   8 +-
 .../gpu/drm/omapdrm/displays/encoder-tpd12s015.c   |  18 +-
 drivers/gpu/drm/omapdrm/dss/Kconfig|   8 +
 drivers/gpu/drm/omapdrm/dss/Makefile   |   1 +
 drivers/gpu/drm/omapdrm/dss/hdmi.h |   6 +-
 drivers/gpu/drm/omapdrm/dss/hdmi4.c|  62 +++-
 drivers/gpu/drm/omapdrm/dss/hdmi4_cec.c| 381 +
 drivers/gpu/drm/omapdrm/dss/hdmi4_cec.h|  55 +++
 drivers/gpu/drm/omapdrm/dss/hdmi4_core.c   |   7 +-
 drivers/gpu/drm/omapdrm/dss/hdmi4_core.h   |   4 +
 drivers/gpu/drm/omapdrm/dss/omapdss.h  |   1 +
 11 files changed, 521 insertions(+), 30 deletions(-)
 create mode 100644 drivers/gpu/drm/omapdrm/dss/hdmi4_cec.c
 create mode 100644 drivers/gpu/drm/omapdrm/dss/hdmi4_cec.h

-- 
2.13.2



[PATCHv2 8/9] omapdrm: hdmi4: hook up the HDMI CEC support

2017-08-02 Thread Hans Verkuil
From: Hans Verkuil 

Hook up the HDMI CEC support in the hdmi4 driver.

It add the CEC irq handler, the CEC (un)init calls and tells the CEC
implementation when the physical address changes.

Signed-off-by: Hans Verkuil 
---
 drivers/gpu/drm/omapdrm/dss/Kconfig  |  8 
 drivers/gpu/drm/omapdrm/dss/Makefile |  1 +
 drivers/gpu/drm/omapdrm/dss/hdmi4.c  | 23 ++-
 3 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/omapdrm/dss/Kconfig 
b/drivers/gpu/drm/omapdrm/dss/Kconfig
index 8b87d5cf45fc..f24ebf7f61dd 100644
--- a/drivers/gpu/drm/omapdrm/dss/Kconfig
+++ b/drivers/gpu/drm/omapdrm/dss/Kconfig
@@ -65,6 +65,14 @@ config OMAP4_DSS_HDMI
help
  HDMI support for OMAP4 based SoCs.
 
+config OMAP4_DSS_HDMI_CEC
+   bool "Enable HDMI CEC support for OMAP4"
+   depends on OMAP4_DSS_HDMI
+   select CEC_CORE
+   default y
+   ---help---
+ When selected the HDMI transmitter will support the CEC feature.
+
 config OMAP5_DSS_HDMI
bool "HDMI support for OMAP5"
default n
diff --git a/drivers/gpu/drm/omapdrm/dss/Makefile 
b/drivers/gpu/drm/omapdrm/dss/Makefile
index 688195e448c5..6a3a116512f3 100644
--- a/drivers/gpu/drm/omapdrm/dss/Makefile
+++ b/drivers/gpu/drm/omapdrm/dss/Makefile
@@ -14,5 +14,6 @@ omapdss-$(CONFIG_OMAP2_DSS_DSI) += dsi.o
 omapdss-$(CONFIG_OMAP2_DSS_HDMI_COMMON) += hdmi_common.o hdmi_wp.o hdmi_pll.o \
hdmi_phy.o
 omapdss-$(CONFIG_OMAP4_DSS_HDMI) += hdmi4.o hdmi4_core.o
+omapdss-$(CONFIG_OMAP4_DSS_HDMI_CEC) += hdmi4_cec.o
 omapdss-$(CONFIG_OMAP5_DSS_HDMI) += hdmi5.o hdmi5_core.o
 ccflags-$(CONFIG_OMAP2_DSS_DEBUG) += -DDEBUG
diff --git a/drivers/gpu/drm/omapdrm/dss/hdmi4.c 
b/drivers/gpu/drm/omapdrm/dss/hdmi4.c
index 166aa4df7688..e535010218e6 100644
--- a/drivers/gpu/drm/omapdrm/dss/hdmi4.c
+++ b/drivers/gpu/drm/omapdrm/dss/hdmi4.c
@@ -36,9 +36,11 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "omapdss.h"
 #include "hdmi4_core.h"
+#include "hdmi4_cec.h"
 #include "dss.h"
 #include "dss_features.h"
 #include "hdmi.h"
@@ -97,6 +99,13 @@ static irqreturn_t hdmi_irq_handler(int irq, void *data)
} else if (irqstatus & HDMI_IRQ_LINK_DISCONNECT) {
hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_LDOON);
}
+   if (irqstatus & HDMI_IRQ_CORE) {
+   u32 intr4 = hdmi_read_reg(hdmi->core.base, HDMI_CORE_SYS_INTR4);
+
+   hdmi_write_reg(hdmi->core.base, HDMI_CORE_SYS_INTR4, intr4);
+   if (intr4 & 8)
+   hdmi4_cec_irq(&hdmi->core);
+   }
 
return IRQ_HANDLED;
 }
@@ -393,6 +402,8 @@ static void hdmi_display_disable(struct omap_dss_device 
*dssdev)
 
DSSDBG("Enter hdmi_display_disable\n");
 
+   hdmi4_cec_set_phys_addr(&hdmi.core, CEC_PHYS_ADDR_INVALID);
+
mutex_lock(&hdmi.lock);
 
spin_lock_irqsave(&hdmi.audio_playing_lock, flags);
@@ -493,7 +504,11 @@ static int hdmi_read_edid(struct omap_dss_device *dssdev,
}
 
r = read_edid(edid, len);
-
+   if (r >= 256)
+   hdmi4_cec_set_phys_addr(&hdmi.core,
+   cec_get_edid_phys_addr(edid, r, NULL));
+   else
+   hdmi4_cec_set_phys_addr(&hdmi.core, CEC_PHYS_ADDR_INVALID);
if (need_enable)
hdmi4_core_disable(dssdev);
 
@@ -727,6 +742,10 @@ static int hdmi4_bind(struct device *dev, struct device 
*master, void *data)
if (r)
goto err;
 
+   r = hdmi4_cec_init(pdev, &hdmi.core, &hdmi.wp);
+   if (r)
+   goto err;
+
irq = platform_get_irq(pdev, 0);
if (irq < 0) {
DSSERR("platform_get_irq failed\n");
@@ -771,6 +790,8 @@ static void hdmi4_unbind(struct device *dev, struct device 
*master, void *data)
 
hdmi_uninit_output(pdev);
 
+   hdmi4_cec_uninit(&hdmi.core);
+
hdmi_pll_uninit(&hdmi.pll);
 
pm_runtime_disable(&pdev->dev);
-- 
2.13.2



[PATCH 3/3] MAINTAINERS: add cec-gpio entry

2017-08-02 Thread Hans Verkuil
From: Hans Verkuil 

Add an entry for the CEC GPIO driver.

Signed-off-by: Hans Verkuil 
---
 MAINTAINERS | 9 +
 1 file changed, 9 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index aeb84877854b..d85959f82a09 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -3199,6 +3199,15 @@ F:   include/uapi/linux/cec.h
 F: include/uapi/linux/cec-funcs.h
 F: Documentation/devicetree/bindings/media/cec.txt
 
+CEC GPIO DRIVER
+M: Hans Verkuil 
+L: linux-media@vger.kernel.org
+T: git git://linuxtv.org/media_tree.git
+W: http://linuxtv.org
+S: Supported
+F: drivers/media/platform/cec-gpio/
+F: Documentation/devicetree/bindings/media/cec-gpio.txt
+
 CELL BROADBAND ENGINE ARCHITECTURE
 M: Arnd Bergmann 
 L: linuxppc-...@lists.ozlabs.org
-- 
2.13.2



[PATCH 2/3] cec-gpio: add HDMI CEC GPIO driver

2017-08-02 Thread Hans Verkuil
From: Hans Verkuil 

Add a simple HDMI CEC GPIO driver that sits on top of the cec-pin framework.

While I have heard of SoCs that use the GPIO pin for CEC (apparently an
early RockChip SoC used that), the main use-case of this driver is to
function as a debugging tool.

By connecting the CEC line to a GPIO pin on a Raspberry Pi 3 for example
it turns it into a CEC debugger and protocol analyzer.

With 'cec-ctl --monitor-pin' the CEC traffic can be analyzed.

But of course it can also be used with any hardware project where the
HDMI CEC pin is hooked up to a pull-up gpio pin.

Signed-off-by: Hans Verkuil 
---
 drivers/media/platform/Kconfig |  10 ++
 drivers/media/platform/Makefile|   2 +
 drivers/media/platform/cec-gpio/Makefile   |   1 +
 drivers/media/platform/cec-gpio/cec-gpio.c | 190 +
 4 files changed, 203 insertions(+)
 create mode 100644 drivers/media/platform/cec-gpio/Makefile
 create mode 100644 drivers/media/platform/cec-gpio/cec-gpio.c

diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index 0c741d12dbc9..681507727259 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -537,6 +537,16 @@ menuconfig CEC_PLATFORM_DRIVERS
 
 if CEC_PLATFORM_DRIVERS
 
+config CEC_GPIO
+   tristate "Generic GPIO-based CEC driver"
+   depends on PREEMPT
+   select CEC_CORE
+   select CEC_PIN
+   ---help---
+ This is a generic GPIO-based CEC driver.
+ The CEC bus is present in the HDMI connector and enables communication
+ between compatible devices.
+
 config VIDEO_SAMSUNG_S5P_CEC
tristate "Samsung S5P CEC driver"
depends on PLAT_S5P || ARCH_EXYNOS || COMPILE_TEST
diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile
index 9beadc760467..d01cc1886ad1 100644
--- a/drivers/media/platform/Makefile
+++ b/drivers/media/platform/Makefile
@@ -26,6 +26,8 @@ obj-$(CONFIG_VIDEO_CODA)  += coda/
 
 obj-$(CONFIG_VIDEO_SH_VEU) += sh_veu.o
 
+obj-$(CONFIG_CEC_GPIO) += cec-gpio/
+
 obj-$(CONFIG_VIDEO_MEM2MEM_DEINTERLACE)+= m2m-deinterlace.o
 
 obj-$(CONFIG_VIDEO_MUX)+= video-mux.o
diff --git a/drivers/media/platform/cec-gpio/Makefile 
b/drivers/media/platform/cec-gpio/Makefile
new file mode 100644
index ..e82b258afa55
--- /dev/null
+++ b/drivers/media/platform/cec-gpio/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_CEC_GPIO) += cec-gpio.o
diff --git a/drivers/media/platform/cec-gpio/cec-gpio.c 
b/drivers/media/platform/cec-gpio/cec-gpio.c
new file mode 100644
index ..43e1d447ad98
--- /dev/null
+++ b/drivers/media/platform/cec-gpio/cec-gpio.c
@@ -0,0 +1,190 @@
+/*
+ * Copyright 2017 Cisco Systems, Inc. and/or its affiliates. All rights 
reserved.
+ *
+ * This program is free software; you may redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct cec_gpio {
+   struct cec_adapter  *adap;
+   struct device   *dev;
+   int gpio;
+   int irq;
+   boolis_low;
+   boolhave_irq;
+};
+
+static bool cec_gpio_read(struct cec_adapter *adap)
+{
+   struct cec_gpio *cec = cec_get_drvdata(adap);
+
+   if (cec->is_low)
+   return false;
+   return gpio_get_value(cec->gpio);
+}
+
+static void cec_gpio_high(struct cec_adapter *adap)
+{
+   struct cec_gpio *cec = cec_get_drvdata(adap);
+
+   if (!cec->is_low)
+   return;
+   cec->is_low = false;
+   gpio_direction_input(cec->gpio);
+}
+
+static void cec_gpio_low(struct cec_adapter *adap)
+{
+   struct cec_gpio *cec = cec_get_drvdata(adap);
+
+   if (cec->is_low)
+   return;
+   if (WARN_ON_ONCE(cec->have_irq))
+   free_irq(cec->irq, cec);
+   cec->have_irq = false;
+   cec->is_low = true;
+   gpio_direction_output(cec->gpio, 0);
+}
+
+static irqreturn_t cec_gpio_irq_handler(int irq, void *priv)
+{
+   struct cec_gpio *cec = priv;
+
+   cec_pin_changed(cec->adap, gpio_get_value(cec->gpio));
+   return IRQ_HANDLED;
+}
+
+static bool cec_gpio_enable_irq(struct cec_adapter *adap)
+{
+   struct cec_gpio *ce

[PATCH 1/3] dt-bindings: document the CEC GPIO bindings

2017-08-02 Thread Hans Verkuil
From: Hans Verkuil 

Document the bindings for the cec-gpio module for hardware where the
CEC pin is connected to a GPIO pin.

Signed-off-by: Hans Verkuil 
---
 Documentation/devicetree/bindings/media/cec-gpio.txt | 18 ++
 1 file changed, 18 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/cec-gpio.txt

diff --git a/Documentation/devicetree/bindings/media/cec-gpio.txt 
b/Documentation/devicetree/bindings/media/cec-gpio.txt
new file mode 100644
index ..58fa56080cda
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/cec-gpio.txt
@@ -0,0 +1,18 @@
+* HDMI CEC GPIO driver
+
+The HDMI CEC GPIO module supports CEC implementations where the CEC pin
+is hooked up to a pull-up GPIO pin.
+
+The CEC GPIO
+
+Required properties:
+  - compatible: value must be "cec-gpio"
+  - gpio: gpio that the CEC line is connected to
+
+Example for the Raspberry Pi 3 where the CEC line is connected to
+pin 7 aka BCM4 aka GPCLK0 on the GPIO pin header:
+
+cec-gpio {
+   compatible = "cec-gpio";
+   gpio = <&gpio 4 GPIO_ACTIVE_HIGH>;
+};
-- 
2.13.2



[PATCH 0/3] cec-gpio: add HDMI CEC GPIO-based driver

2017-08-02 Thread Hans Verkuil
From: Hans Verkuil 

This driver adds support for CEC implementations that use a pull-up
GPIO pin. While SoCs exist that do this, the primary use-case is to
turn a single-board computer into a cheap CEC debugger.

Together with 'cec-ctl --monitor-pin' you can do low-level CEC bus
monitoring and do protocol analysis. And error injection is also
planned for the future.

Here is an example using the Raspberry Pi 3:

https://hverkuil.home.xs4all.nl/rpi3-cec.jpg

A patch for the Raspberry Pi 2B/3 is added below for reference.
It uses pin 7 aka BCM4 aka GPCLK0 on the GPIO pin header.

While this example is for the Rpi, this driver will work for any
SoC with a pull-up GPIO pin.

I have one question: is there a generic way to check/force the gpio
to pull-up mode? I have not found that, but I am no gpio-expert.

Regards,

Hans

--- cut here ---
diff --git a/arch/arm/boot/dts/bcm2836-rpi-2-b.dts 
b/arch/arm/boot/dts/bcm2836-rpi-2-b.dts
index bf19e8cfb9e6..8cb82a70f33d 100644
--- a/arch/arm/boot/dts/bcm2836-rpi-2-b.dts
+++ b/arch/arm/boot/dts/bcm2836-rpi-2-b.dts
@@ -24,6 +24,11 @@
linux,default-trigger = "default-on";
};
};
+
+   cec-gpio {
+   compatible = "cec-gpio";
+   gpio = <&gpio 4 GPIO_ACTIVE_HIGH>;
+   };
 };
 
 &gpio {
diff --git a/arch/arm64/boot/dts/broadcom/bcm2837-rpi-3-b.dts 
b/arch/arm64/boot/dts/broadcom/bcm2837-rpi-3-b.dts
index 972f14db28ac..cd0ec70732f4 100644
--- a/arch/arm64/boot/dts/broadcom/bcm2837-rpi-3-b.dts
+++ b/arch/arm64/boot/dts/broadcom/bcm2837-rpi-3-b.dts
@@ -17,6 +17,11 @@
gpios = <&gpio 47 0>;
};
};
+
+   cec-gpio {
+   compatible = "cec-gpio";
+   gpio = <&gpio 4 GPIO_ACTIVE_HIGH>;
+   };
 };
 
 &uart1 {
--- cut here ---


Hans Verkuil (3):
  dt-bindings: document the CEC GPIO bindings
  cec-gpio: add HDMI CEC GPIO driver
  MAINTAINERS: add cec-gpio entry

 .../devicetree/bindings/media/cec-gpio.txt |  18 ++
 MAINTAINERS|   9 +
 drivers/media/platform/Kconfig |  10 ++
 drivers/media/platform/Makefile|   2 +
 drivers/media/platform/cec-gpio/Makefile   |   1 +
 drivers/media/platform/cec-gpio/cec-gpio.c | 190 +
 6 files changed, 230 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/cec-gpio.txt
 create mode 100644 drivers/media/platform/cec-gpio/Makefile
 create mode 100644 drivers/media/platform/cec-gpio/cec-gpio.c

-- 
2.13.2



[PATCH] media: staging: atomisp: sh_css_calloc shall return a pointer to the allocated space

2017-08-02 Thread Sergei A. Trusov
The calloc function returns either a null pointer or a pointer to the
allocated space. Add the second case that is missed.

Signed-off-by: Sergei A. Trusov 
---
 drivers/staging/media/atomisp/pci/atomisp2/css2400/sh_css.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/staging/media/atomisp/pci/atomisp2/css2400/sh_css.c 
b/drivers/staging/media/atomisp/pci/atomisp2/css2400/sh_css.c
index 471f2be974e2..e882b5596813 100644
--- a/drivers/staging/media/atomisp/pci/atomisp2/css2400/sh_css.c
+++ b/drivers/staging/media/atomisp/pci/atomisp2/css2400/sh_css.c
@@ -1939,6 +1939,7 @@ void *sh_css_calloc(size_t N, size_t size)
p = sh_css_malloc(N*size);
if (p)
memset(p, 0, size);
+   return p;
}
return NULL;
 }



Re: [PATCH] media: staging: atomisp: sh_css_calloc shall return a pointer to the allocated space

2017-08-02 Thread Joe Perches
On Wed, 2017-08-02 at 18:00 +1000, Sergei A. Trusov wrote:
> The calloc function returns either a null pointer or a pointer to the
> allocated space. Add the second case that is missed.

gads.

Bug added by commit da22013f7df4 ("atomisp: remove indirection from
sh_css_malloc")

These wrappers should really be deleted.