cron job: media_tree daily build: ERRORS

2017-10-29 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:   Mon Oct 30 05:00:15 CET 2017
media-tree git hash:bbae615636155fa43a9b0fe0ea31c678984be864
media_build git hash:   c93534951f5d66bef7f17f16293acf2be346b726
v4l-utils git hash: 482c52f946af4c6b16efa63a35790d92fb65326c
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.12.0-164

linux-git-arm-at91: OK
linux-git-arm-davinci: OK
linux-git-arm-multi: OK
linux-git-arm-pxa: OK
linux-git-arm-stm32: OK
linux-git-blackfin-bf561: OK
linux-git-i686: OK
linux-git-m32r: WARNINGS
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: WARNINGS
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: ERRORS
linux-3.12.67-i686: ERRORS
linux-3.13.11-i686: ERRORS
linux-3.14.9-i686: ERRORS
linux-3.15.2-i686: ERRORS
linux-3.16.7-i686: ERRORS
linux-3.17.8-i686: WARNINGS
linux-3.18.7-i686: WARNINGS
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-4.13-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: WARNINGS
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: ERRORS
linux-3.12.67-x86_64: ERRORS
linux-3.13.11-x86_64: ERRORS
linux-3.14.9-x86_64: ERRORS
linux-3.15.2-x86_64: ERRORS
linux-3.16.7-x86_64: ERRORS
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
linux-4.13-x86_64: OK
apps: OK
spec-git: OK

Detailed results are available here:

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

Full logs are available here:

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

The Media Infrastructure API from this daily build is here:

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


[PATCH] st-hva: hva-h264: use swap macro in hva_h264_encode

2017-10-29 Thread Gustavo A. R. Silva
Make use of the swap macro and remove unnecessary variable tmp_frame.
This makes the code easier to read and maintain.

This code was detected with the help of Coccinelle.

Signed-off-by: Gustavo A. R. Silva 
---
 drivers/media/platform/sti/hva/hva-h264.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/media/platform/sti/hva/hva-h264.c 
b/drivers/media/platform/sti/hva/hva-h264.c
index e6f247a..a7e5eed 100644
--- a/drivers/media/platform/sti/hva/hva-h264.c
+++ b/drivers/media/platform/sti/hva/hva-h264.c
@@ -999,7 +999,6 @@ static int hva_h264_encode(struct hva_ctx *pctx, struct 
hva_frame *frame,
 {
struct hva_h264_ctx *ctx = (struct hva_h264_ctx *)pctx->priv;
struct hva_h264_task *task = (struct hva_h264_task *)ctx->task->vaddr;
-   struct hva_buffer *tmp_frame;
u32 stuffing_bytes = 0;
int ret = 0;
 
@@ -1023,9 +1022,7 @@ static int hva_h264_encode(struct hva_ctx *pctx, struct 
hva_frame *frame,
   >bytesused);
 
/* switch reference & reconstructed frame */
-   tmp_frame = ctx->ref_frame;
-   ctx->ref_frame = ctx->rec_frame;
-   ctx->rec_frame = tmp_frame;
+   swap(ctx->ref_frame, ctx->rec_frame);
 
return 0;
 err:
-- 
2.7.4



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

2017-10-29 Thread Olli Salonen
Hello Michael,

Many thanks for taking the time to review the patches.

On 27 October 2017 at 13:27, Michael Ira Krufky  wrote:
>> +static int tda18250_sleep(struct dvb_frontend *fe)
>> +{
>> +   struct i2c_client *client = fe->tuner_priv;
>> +   struct tda18250_dev *dev = i2c_get_clientdata(client);
>> +   int ret;
>> +
>> +   dev_dbg(>dev, "\n");
>> +
>> +   /* power down LNA */
>> +   ret = regmap_write_bits(dev->regmap, R0C_AGC11, 0x80, 0x00);
>> +   if (ret)
>> +   return ret;
>> +
>> +   ret = tda18250_power_control(fe, TDA18250_POWER_STANDBY);
>> +   return ret;
>> +}
>
> Do we know for sure if the IF_FREQUENCY is preserved after returning
> from a sleep?   It might be a good idea to set `dev->if_frequency = 0`
> within `tda18250_sleep` to be sure that it gets set again on the next
> tune, but you may want to check the specification first, if its
> available.
>
> This is not a show-stopper -- We can merge this as-is and this can be
> handled in a follow-up patch.

I will look into this and send a patch on top of this one if needed.

Thank you for pointing it out.

Cheers,
-olli


[PATCH v3 3/3] MAINTAINERS: Add a new entry of the ov7740 driver

2017-10-29 Thread Wenyou Yang
Add a new entry of the ov7740 sensor driver to the MAINTAINERS file.

Signed-off-by: Wenyou Yang 
---

Changes in v3:
 - Put the MAINTAINERS change to a separate patch.

Changes in v2:
 - Split off the bindings into a separate patch.
 - Add a new entry to the MAINTAINERS file.

 MAINTAINERS | 8 
 1 file changed, 8 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index adbf69306e9e..42b93599a0af 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -9973,6 +9973,14 @@ S:   Maintained
 F: drivers/media/i2c/ov7670.c
 F: Documentation/devicetree/bindings/media/i2c/ov7670.txt
 
+OMNIVISION OV7740 SENSOR DRIVER
+M: Wenyou Yang 
+L: linux-media@vger.kernel.org
+T: git git://linuxtv.org/media_tree.git
+S: Maintained
+F: drivers/media/i2c/ov7740.c
+F: Documentation/devicetree/bindings/media/i2c/ov7740.txt
+
 ONENAND FLASH DRIVER
 M: Kyungmin Park 
 L: linux-...@lists.infradead.org
-- 
2.13.0



[PATCH v3 2/3] media: ov7740: Document device tree bindings

2017-10-29 Thread Wenyou Yang
Add the device tree binding documentation for the ov7740 sensor driver.

Signed-off-by: Wenyou Yang 
---

Changes in v3:
 - Explicitly document the "remote-endpoint" property.

Changes in v2: None

 .../devicetree/bindings/media/i2c/ov7740.txt   | 47 ++
 1 file changed, 47 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/ov7740.txt

diff --git a/Documentation/devicetree/bindings/media/i2c/ov7740.txt 
b/Documentation/devicetree/bindings/media/i2c/ov7740.txt
new file mode 100644
index ..af781c3a5f0e
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/i2c/ov7740.txt
@@ -0,0 +1,47 @@
+* Omnivision OV7740 CMOS image sensor
+
+The Omnivision OV7740 image sensor supports multiple output image
+size, such as VGA, and QVGA, CIF and any size smaller. It also
+supports the RAW RGB and YUV output formats.
+
+The common video interfaces bindings (see video-interfaces.txt) should
+be used to specify link to the image data receiver. The OV7740 device
+node should contain one 'port' child node with an 'endpoint' subnode.
+
+Required Properties:
+- compatible:  "ovti,ov7740".
+- reg: I2C slave address of the sensor.
+- clocks:  Reference to the xvclk input clock.
+- clock-names: "xvclk".
+
+Optional Properties:
+- reset-gpios: Rreference to the GPIO connected to the reset_b pin,
+  if any. Active low with pull-ip resistor.
+- powerdown-gpios: Reference to the GPIO connected to the pwdn pin,
+  if any. Active high with pull-down resistor.
+
+Endpoint node mandatory properties:
+- remote-endpoint: A phandle to the bus receiver's endpoint node.
+
+Example:
+
+   i2c1: i2c@fc028000 {
+   ov7740: camera@21 {
+   compatible = "ovti,ov7740";
+   reg = <0x21>;
+   pinctrl-names = "default";
+   pinctrl-0 = <_sensor_power 
_sensor_reset>;
+   clocks = <>;
+   clock-names = "xvclk";
+   assigned-clocks = <>;
+   assigned-clock-rates = <2400>;
+   reset-gpios = < 43 GPIO_ACTIVE_LOW>;
+   powerdown-gpios = < 44 GPIO_ACTIVE_HIGH>;
+
+   port {
+   ov7740_0: endpoint {
+   remote-endpoint = <_0>;
+   };
+   };
+   };
+   };
-- 
2.13.0



[PATCH v3 1/3] media: i2c: Add the ov7740 image sensor driver

2017-10-29 Thread Wenyou Yang
The ov7740 (color) image sensor is a high performance VGA CMOS
image snesor, which supports for output formats: RAW RGB and YUV
and image sizes: VGA, and QVGA, CIF and any size smaller.

Signed-off-by: Songjun Wu 
Signed-off-by: Wenyou Yang 
---

Changes in v3: None
Changes in v2: None

 drivers/media/i2c/Kconfig  |8 +
 drivers/media/i2c/Makefile |1 +
 drivers/media/i2c/ov7740.c | 1220 
 3 files changed, 1229 insertions(+)
 create mode 100644 drivers/media/i2c/ov7740.c

diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 3c6d6428f525..ac484bb82fae 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -665,6 +665,14 @@ config VIDEO_OV7670
  OV7670 VGA camera.  It currently only works with the M88ALP01
  controller.
 
+config VIDEO_OV7740
+   tristate "OmniVision OV7740 sensor support"
+   depends on I2C && VIDEO_V4L2
+   depends on MEDIA_CAMERA_SUPPORT
+   ---help---
+ This is a Video4Linux2 sensor-level driver for the OmniVision
+ OV7740 VGA camera sensor.
+
 config VIDEO_OV9650
tristate "OmniVision OV9650/OV9652 sensor support"
depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
index f8d57e453936..be800c674e8d 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -67,6 +67,7 @@ obj-$(CONFIG_VIDEO_OV5670) += ov5670.o
 obj-$(CONFIG_VIDEO_OV6650) += ov6650.o
 obj-$(CONFIG_VIDEO_OV7640) += ov7640.o
 obj-$(CONFIG_VIDEO_OV7670) += ov7670.o
+obj-$(CONFIG_VIDEO_OV7740) += ov7740.o
 obj-$(CONFIG_VIDEO_OV9650) += ov9650.o
 obj-$(CONFIG_VIDEO_OV13858) += ov13858.o
 obj-$(CONFIG_VIDEO_MT9M032) += mt9m032.o
diff --git a/drivers/media/i2c/ov7740.c b/drivers/media/i2c/ov7740.c
new file mode 100644
index ..d68add05b46e
--- /dev/null
+++ b/drivers/media/i2c/ov7740.c
@@ -0,0 +1,1220 @@
+/*
+ * Copyright (c) 2017 Microchip Corporation.
+ *
+ * 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.
+ *
+ * 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 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define REG_OUTSIZE_LSB 0x34
+
+/* OV7740 register tables */
+#define REG_GAIN   0x00/* Gain lower 8 bits (rest in vref) */
+#define REG_BGAIN  0x01/* blue gain */
+#define REG_RGAIN  0x02/* red gain */
+#define REG_GGAIN  0x03/* green gain */
+#define REG_REG04  0x04/* analog setting, dont change*/
+#define REG_BAVG   0x05/* b channel average */
+#define REG_GAVG   0x06/* g channel average */
+#define REG_RAVG   0x07/* r channel average */
+
+#define REG_REG0C  0x0C/* filp enable */
+#define REG0C_IMG_FLIP 0x80
+#define REG0C_IMG_MIRROR   0x40
+
+#define REG_REG0E  0x0E/* blc line */
+#define REG_HAEC   0x0F/* auto exposure cntrl */
+#define REG_AEC0x10/* auto exposure cntrl */
+
+#define REG_CLK0x11/* Clock control */
+#define REG_REG55  0x55/* Clock PLL DIV/PreDiv */
+
+#define REG_REG12  0x12
+
+#define REG_REG13  0x13/* auto/manual AGC, AEC, Write Balance*/
+#define REG13_AEC_EN   0x01
+#define REG13_AGC_EN   0x04
+
+#define REG_REG14  0x14
+#define REG_REG15  0x15
+#define REG15_GAIN_MSB 0x03
+
+#define REG_REG16  0x16
+
+#define REG_MIDH   0x1C/* manufacture id byte */
+#define REG_MIDL   0x1D/* manufacture id byre */
+#define REG_PIDH   0x0A/* Product ID MSB */
+#define REG_PIDL   0x0B/* Product ID LSB */
+
+#define REG_84 0x84/* lots of stuff */
+#define REG_REG38  0x38/* sub-addr */
+
+#define REG_AHSTART0x17/* Horiz start high bits */
+#define REG_AHSIZE 0x18
+#define REG_AVSTART0x19/* Vert start high bits */
+#define REG_AVSIZE 0x1A
+#define REG_PSHFT  0x1b/* Pixel delay after HREF */
+
+#define REG_HOUTSIZE   0x31
+#define REG_VOUTSIZE   0x32
+#define REG_HVSIZEOFF  0x33
+#define REG_REG34  0x34/* DSP output size H/V LSB*/
+
+#define REG_ISP_CTRL00 0x80
+#define ISPCTRL00_AWB_EN   0x10
+#define ISPCTRL00_AWB_GAIN_EN  0x04
+
+#defineREG_YGAIN   0xE2/* ygain for contrast control */
+
+#defineREG_YBRIGHT   0xE3
+#defineREG_SGNSET0xE4
+#defineSGNSET_YBRIGHT_MASK   0x08
+
+#define REG_USAT   0xDD
+#define REG_VSAT   0xDE
+
+
+struct ov7740 {
+   struct v4l2_subdev 

[PATCH v3 0/3] media: ov7740: Add a V4L2 sensor-level driver

2017-10-29 Thread Wenyou Yang
Add a Video4Linux2 sensor-level driver for the OmniVision OV7740
VGA camera image sensor.

Changes in v3:
 - Explicitly document the "remote-endpoint" property.
 - Put the MAINTAINERS change to a separate patch.

Changes in v2:
 - Split off the bindings into a separate patch.
 - Add a new entry to the MAINTAINERS file.

Wenyou Yang (3):
  media: i2c: Add the ov7740 image sensor driver
  media: ov7740: Document device tree bindings
  MAINTAINERS: Add a new entry of the ov7740 driver

 .../devicetree/bindings/media/i2c/ov7740.txt   |   47 +
 MAINTAINERS|8 +
 drivers/media/i2c/Kconfig  |8 +
 drivers/media/i2c/Makefile |1 +
 drivers/media/i2c/ov7740.c | 1220 
 5 files changed, 1284 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/ov7740.txt
 create mode 100644 drivers/media/i2c/ov7740.c

-- 
2.13.0



Re: [PATCH v2 2/2] media: ov7740: Document device tree bindings

2017-10-29 Thread Yang, Wenyou

Hi Sakari,

Thank you very much for your review and advice.

I will send a new version to fix it.

On 2017/10/27 18:59, Sakari Ailus wrote:

Hi Wenyou,

On Fri, Oct 27, 2017 at 03:42:20PM +0800, Wenyou Yang wrote:

Add the device tree binding documentation for ov7740 driver and
add a new entry of ov7740 to the MAINTAINERS file.

Signed-off-by: Wenyou Yang 
---

Changes in v2:
  - Split off the bindings into a separate patch.
  - Add a new entry to the MAINTAINERS file.

  .../devicetree/bindings/media/i2c/ov7740.txt   | 43 ++
  MAINTAINERS|  8 
  2 files changed, 51 insertions(+)
  create mode 100644 Documentation/devicetree/bindings/media/i2c/ov7740.txt

diff --git a/Documentation/devicetree/bindings/media/i2c/ov7740.txt 
b/Documentation/devicetree/bindings/media/i2c/ov7740.txt
new file mode 100644
index ..b306e5aa97bf
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/i2c/ov7740.txt
@@ -0,0 +1,43 @@
+* Omnivision OV7740 CMOS image sensor
+
+The Omnivision OV7740 image sensor supports multiple output image
+size, such as VGA, and QVGA, CIF and any size smaller. It also
+supports the RAW RGB and YUV output formats.
+
+Required Properties:
+- compatible: should be "ovti,ov7740"
+- clocks: reference to the xvclk input clock.
+- clock-names: should be "xvclk".
+
+Optional Properties:
+- reset-gpios: reference to the GPIO connected to the reset_b pin,
+  if any. Active low with pull-ip resistor.
+- powerdown-gpios: reference to the GPIO connected to the pwdn pin,
+  if any. Active high with pull-down resistor.
+
+The device node must contain one 'port' child node for its digital
+output video port, in accordance with the video interface bindings
+defined in Documentation/devicetree/bindings/media/video-interfaces.txt.

Could you add there's a single endpoint node as well, and explicitly
document the relevant properties? E.g. as in
Documentation/devicetree/bindings/media/i2c/nokia,smia.txt .


+
+Example:
+
+   i2c1: i2c@fc028000 {
+   ov7740: camera@21 {
+   compatible = "ovti,ov7740";
+   reg = <0x21>;
+   pinctrl-names = "default";
+   pinctrl-0 = <_sensor_power 
_sensor_reset>;
+   clocks = <>;
+   clock-names = "xvclk";
+   assigned-clocks = <>;
+   assigned-clock-rates = <2400>;
+   reset-gpios = < 43 GPIO_ACTIVE_LOW>;
+   powerdown-gpios = < 44 GPIO_ACTIVE_HIGH>;
+
+   port {
+   ov7740_0: endpoint {
+   remote-endpoint = <_0>;
+   };
+   };
+   };
+   };
diff --git a/MAINTAINERS b/MAINTAINERS
index 90230fe020f3..f0f3f121d1d8 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -9965,6 +9965,14 @@ S:   Maintained
  F:drivers/media/i2c/ov7670.c
  F:Documentation/devicetree/bindings/media/i2c/ov7670.txt
  
+OMNIVISION OV7740 SENSOR DRIVER

+M: Wenyou Yang 
+L: linux-media@vger.kernel.org
+T: git git://linuxtv.org/media_tree.git
+S: Maintained
+F: drivers/media/i2c/ov7740.c
+F: Documentation/devicetree/bindings/media/i2c/ov7740.txt
+
  ONENAND FLASH DRIVER
  M:Kyungmin Park 
  L:linux-...@lists.infradead.org

Please put the MAINTAINERS change to the driver patch after the DT binding
patch.


Best Regards,
Wenyou Yang



[PATCH] media: atmel-isc: Fix clock ID for clk_prepare/unprepare

2017-10-29 Thread Wenyou Yang
Fix the clock ID to do the runtime pm should be ISC_ISPCK,
instead of ISC_MCK in clk_prepare(), clk_unprepare() and
isc_clk_is_enabled().

Signed-off-by: Wenyou Yang 
---

 drivers/media/platform/atmel/atmel-isc.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/media/platform/atmel/atmel-isc.c 
b/drivers/media/platform/atmel/atmel-isc.c
index 2c40a7886542..9294ff0c7b83 100644
--- a/drivers/media/platform/atmel/atmel-isc.c
+++ b/drivers/media/platform/atmel/atmel-isc.c
@@ -598,7 +598,7 @@ static int isc_clk_prepare(struct clk_hw *hw)
 {
struct isc_clk *isc_clk = to_isc_clk(hw);
 
-   if (isc_clk->id == ISC_MCK)
+   if (isc_clk->id == ISC_ISPCK)
pm_runtime_get_sync(isc_clk->dev);
 
return isc_wait_clk_stable(hw);
@@ -610,7 +610,7 @@ static void isc_clk_unprepare(struct clk_hw *hw)
 
isc_wait_clk_stable(hw);
 
-   if (isc_clk->id == ISC_MCK)
+   if (isc_clk->id == ISC_ISPCK)
pm_runtime_put_sync(isc_clk->dev);
 }
 
@@ -657,12 +657,12 @@ static int isc_clk_is_enabled(struct clk_hw *hw)
struct isc_clk *isc_clk = to_isc_clk(hw);
u32 status;
 
-   if (isc_clk->id == ISC_MCK)
+   if (isc_clk->id == ISC_ISPCK)
pm_runtime_get_sync(isc_clk->dev);
 
regmap_read(isc_clk->regmap, ISC_CLKSR, );
 
-   if (isc_clk->id == ISC_MCK)
+   if (isc_clk->id == ISC_ISPCK)
pm_runtime_put_sync(isc_clk->dev);
 
return status & ISC_CLK(isc_clk->id) ? 1 : 0;
-- 
2.13.0



Re: [PATCH v5 0/5] media: atmel-isc: Rework the format list and clock provider

2017-10-29 Thread Yang, Wenyou

Hi Hans,


On 2017/10/27 20:41, Hans Verkuil wrote:

Hi Wenyou,

Unfortunately the v4 patch series was just merged instead of v5. Can you make a 
new
patch applying just the v4 -> v5 changes?

Thank you for your merging.

Of course, I will send a patch to fix it.



Thanks!

Hans

On 10/27/2017 05:21 AM, Wenyou Yang wrote:

To improve the readability of code, rework the format list table,
split the format array into two. Meanwhile, fix the issue of the
clock provider operation and the pm runtime support.

Changes in v5:
  - Fix the clock ID which enters the runtime suspend should be
ISC_ISPCK, instead of ISC_MCK for clk_prepare/clk_unprepare().
  - Fix the clock ID to ISC_ISPCK, instead of ISC_MCK for
isc_clk_is_enabled().

Changes in v4:
  - Call pm_runtime_get_sync() and pm_runtime_put_sync() in ->prepare
and ->unprepare callback.
  - Move pm_runtime_enable() call from the complete callback to the
end of probe.
  - Call pm_runtime_get_sync() and pm_runtime_put_sync() in
->is_enabled() callbacks.
  - Call clk_disable_unprepare() in ->remove callback.

Changes in v3:
  - Fix the wrong used spinlock.
  - s/_/- on the subject.
  - Add a new flag for Raw Bayer format to remove MAX_RAW_FMT_INDEX define.
  - Add the comments for define of the format flag.
  - Rebase media_tree/master.

Changes in v2:
  - Add the new patch to remove the unnecessary member from
isc_subdev_entity struct.
  - Rebase on the patch set,
 [PATCH 0/6] [media] Atmel: Adjustments for seven function 
implementations
 https://www.mail-archive.com/linux-media@vger.kernel.org/msg118342.html

Wenyou Yang (5):
   media: atmel-isc: Add spin lock for clock enable ops
   media: atmel-isc: Add prepare and unprepare ops
   media: atmel-isc: Enable the clocks during probe
   media: atmel-isc: Remove unnecessary member
   media: atmel-isc: Rework the format list

  drivers/media/platform/atmel/atmel-isc-regs.h |   1 +
  drivers/media/platform/atmel/atmel-isc.c  | 629 --
  2 files changed, 498 insertions(+), 132 deletions(-)


Best Regards,
Wenyou Yang


Re: [PATCH v16 32/32] arm: dts: omap3: N9/N950: Add flash references to the camera

2017-10-29 Thread Sebastian Reichel
Hi,

On Thu, Oct 26, 2017 at 10:53:42AM +0300, Sakari Ailus wrote:
> Add flash and indicator LED phandles to the sensor node.
> 
> Signed-off-by: Sakari Ailus 
> Acked-by: Hans Verkuil 
> Acked-by: Pavel Machek 
> ---

Reviewed-by: Sebastian Reichel 

-- Sebastian

>  arch/arm/boot/dts/omap3-n9.dts   | 1 +
>  arch/arm/boot/dts/omap3-n950-n9.dtsi | 4 ++--
>  arch/arm/boot/dts/omap3-n950.dts | 1 +
>  3 files changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/arm/boot/dts/omap3-n9.dts b/arch/arm/boot/dts/omap3-n9.dts
> index b9e58c536afd..39e35f8b8206 100644
> --- a/arch/arm/boot/dts/omap3-n9.dts
> +++ b/arch/arm/boot/dts/omap3-n9.dts
> @@ -26,6 +26,7 @@
>   clocks = < 0>;
>   clock-frequency = <960>;
>   nokia,nvm-size = <(16 * 64)>;
> + flash-leds = <_flash _indicator>;
>   port {
>   smia_1_1: endpoint {
>   link-frequencies = /bits/ 64 <19920 
> 21000 49920>;
> diff --git a/arch/arm/boot/dts/omap3-n950-n9.dtsi 
> b/arch/arm/boot/dts/omap3-n950-n9.dtsi
> index 1b0bd72945f2..12fbb3da5fce 100644
> --- a/arch/arm/boot/dts/omap3-n950-n9.dtsi
> +++ b/arch/arm/boot/dts/omap3-n950-n9.dtsi
> @@ -271,14 +271,14 @@
>   #size-cells = <0>;
>   reg = <0x30>;
>   compatible = "ams,as3645a";
> - flash@0 {
> + as3645a_flash: flash@0 {
>   reg = <0x0>;
>   flash-timeout-us = <15>;
>   flash-max-microamp = <32>;
>   led-max-microamp = <6>;
>   ams,input-max-microamp = <175>;
>   };
> - indicator@1 {
> + as3645a_indicator: indicator@1 {
>   reg = <0x1>;
>   led-max-microamp = <1>;
>   };
> diff --git a/arch/arm/boot/dts/omap3-n950.dts 
> b/arch/arm/boot/dts/omap3-n950.dts
> index 646601a3ebd8..c354a1ed1e70 100644
> --- a/arch/arm/boot/dts/omap3-n950.dts
> +++ b/arch/arm/boot/dts/omap3-n950.dts
> @@ -60,6 +60,7 @@
>   clocks = < 0>;
>   clock-frequency = <960>;
>   nokia,nvm-size = <(16 * 64)>;
> + flash-leds = <_flash _indicator>;
>   port {
>   smia_1_1: endpoint {
>   link-frequencies = /bits/ 64 <21000 
> 33360 39840>;
> -- 
> 2.11.0
> 


signature.asc
Description: PGP signature


Re: [PATCH v16 31/32] ov13858: Add support for flash and lens devices

2017-10-29 Thread Sebastian Reichel
Hi,

On Thu, Oct 26, 2017 at 10:53:41AM +0300, Sakari Ailus wrote:
> Parse async sub-devices related to the sensor by switching the async
> sub-device registration function.
> 
> Signed-off-by: Sakari Ailus 
> Acked-by: Hans Verkuil 
> ---

Reviewed-by: Sebastian Reichel 

-- Sebastian

>  drivers/media/i2c/ov13858.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/media/i2c/ov13858.c b/drivers/media/i2c/ov13858.c
> index fdce2befed02..bf7d06f3f21a 100644
> --- a/drivers/media/i2c/ov13858.c
> +++ b/drivers/media/i2c/ov13858.c
> @@ -1761,7 +1761,7 @@ static int ov13858_probe(struct i2c_client *client,
>   goto error_handler_free;
>   }
>  
> - ret = v4l2_async_register_subdev(>sd);
> + ret = v4l2_async_register_subdev_sensor_common(>sd);
>   if (ret < 0)
>   goto error_media_entity;
>  
> -- 
> 2.11.0
> 


signature.asc
Description: PGP signature


Re: [PATCH v16 30/32] ov5670: Add support for flash and lens devices

2017-10-29 Thread Sebastian Reichel
Hi,

On Thu, Oct 26, 2017 at 10:53:40AM +0300, Sakari Ailus wrote:
> Parse async sub-devices related to the sensor by switching the async
> sub-device registration function.
> 
> Signed-off-by: Sakari Ailus 
> Acked-by: Hans Verkuil 
> ---

Reviewed-by: Sebastian Reichel 

-- Sebastian

>  drivers/media/i2c/ov5670.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/media/i2c/ov5670.c b/drivers/media/i2c/ov5670.c
> index a65469f88e36..9f9196568eb8 100644
> --- a/drivers/media/i2c/ov5670.c
> +++ b/drivers/media/i2c/ov5670.c
> @@ -2529,7 +2529,7 @@ static int ov5670_probe(struct i2c_client *client)
>   }
>  
>   /* Async register for subdev */
> - ret = v4l2_async_register_subdev(>sd);
> + ret = v4l2_async_register_subdev_sensor_common(>sd);
>   if (ret < 0) {
>   err_msg = "v4l2_async_register_subdev() error";
>   goto error_entity_cleanup;
> -- 
> 2.11.0
> 


signature.asc
Description: PGP signature


Re: [PATCH v16 29/32] et8ek8: Add support for flash and lens devices

2017-10-29 Thread Sebastian Reichel
Hi,

On Thu, Oct 26, 2017 at 10:53:39AM +0300, Sakari Ailus wrote:
> Parse async sub-devices related to the sensor by switching the async
> sub-device registration function.
> 
> Signed-off-by: Sakari Ailus 
> Acked-by: Hans Verkuil 
> Acked-by: Pavel Machek 
> ---

Reviewed-by: Sebastian Reichel 

-- Sebastian

>  drivers/media/i2c/et8ek8/et8ek8_driver.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/media/i2c/et8ek8/et8ek8_driver.c 
> b/drivers/media/i2c/et8ek8/et8ek8_driver.c
> index c14f0fd6ded3..e9eff9039ef5 100644
> --- a/drivers/media/i2c/et8ek8/et8ek8_driver.c
> +++ b/drivers/media/i2c/et8ek8/et8ek8_driver.c
> @@ -1453,7 +1453,7 @@ static int et8ek8_probe(struct i2c_client *client,
>   goto err_mutex;
>   }
>  
> - ret = v4l2_async_register_subdev(>subdev);
> + ret = v4l2_async_register_subdev_sensor_common(>subdev);
>   if (ret < 0)
>   goto err_entity;
>  
> -- 
> 2.11.0
> 


signature.asc
Description: PGP signature


Re: [PATCH v16 28/32] smiapp: Add support for flash and lens devices

2017-10-29 Thread Sebastian Reichel
Hi,

On Thu, Oct 26, 2017 at 10:53:38AM +0300, Sakari Ailus wrote:
> Parse async sub-devices related to the sensor by switching the async
> sub-device registration function.
> 
> These types devices aren't directly related to the sensor, but are
> nevertheless handled by the smiapp driver due to the relationship of these
> component to the main part of the camera module --- the sensor.
> 
> This does not yet address providing the user space with information on how
> to associate the sensor or lens devices but the kernel now has the
> necessary information to do that.
> 
> Signed-off-by: Sakari Ailus 
> Acked-by: Hans Verkuil 
> Acked-by: Pavel Machek 
> ---

Reviewed-by: Sebastian Reichel 

-- Sebastian

>  drivers/media/i2c/smiapp/smiapp-core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/media/i2c/smiapp/smiapp-core.c 
> b/drivers/media/i2c/smiapp/smiapp-core.c
> index fbd851be51d2..a87c50373813 100644
> --- a/drivers/media/i2c/smiapp/smiapp-core.c
> +++ b/drivers/media/i2c/smiapp/smiapp-core.c
> @@ -3118,7 +3118,7 @@ static int smiapp_probe(struct i2c_client *client,
>   if (rval < 0)
>   goto out_media_entity_cleanup;
>  
> - rval = v4l2_async_register_subdev(>src->sd);
> + rval = v4l2_async_register_subdev_sensor_common(>src->sd);
>   if (rval < 0)
>   goto out_media_entity_cleanup;
>  
> -- 
> 2.11.0
> 


signature.asc
Description: PGP signature


Re: [PATCH v16 27/32] dt: bindings: smiapp: Document lens-focus and flash-leds properties

2017-10-29 Thread Sebastian Reichel
Hi,

On Thu, Oct 26, 2017 at 10:53:37AM +0300, Sakari Ailus wrote:
> Document optional lens-focus and flash-leds properties for the smiapp
> driver.
> 
> Signed-off-by: Sakari Ailus 
> Acked-by: Hans Verkuil 
> Acked-by: Pavel Machek 

Reviewed-by: Sebastian Reichel 

-- Sebastian

> ---
>  Documentation/devicetree/bindings/media/i2c/nokia,smia.txt | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/media/i2c/nokia,smia.txt 
> b/Documentation/devicetree/bindings/media/i2c/nokia,smia.txt
> index 855e1faf73e2..33f10a94c381 100644
> --- a/Documentation/devicetree/bindings/media/i2c/nokia,smia.txt
> +++ b/Documentation/devicetree/bindings/media/i2c/nokia,smia.txt
> @@ -27,6 +27,8 @@ Optional properties
>  - nokia,nvm-size: The size of the NVM, in bytes. If the size is not given,
>the NVM contents will not be read.
>  - reset-gpios: XSHUTDOWN GPIO
> +- flash-leds: See ../video-interfaces.txt
> +- lens-focus: See ../video-interfaces.txt
>  
>  
>  Endpoint node mandatory properties
> -- 
> 2.11.0
> 


signature.asc
Description: PGP signature


Re: [PATCH v16 26/32] v4l: fwnode: Add a convenience function for registering sensors

2017-10-29 Thread Sebastian Reichel
Hi,

On Thu, Oct 26, 2017 at 10:53:36AM +0300, Sakari Ailus wrote:
> Add a convenience function for parsing firmware for information on related
> devices using v4l2_async_notifier_parse_fwnode_sensor_common() registering
> the notifier and finally the async sub-device itself.
> 
> This should be useful for sensor drivers that do not have device specific
> requirements related to firmware information parsing or the async
> framework.
> 
> Signed-off-by: Sakari Ailus 
> Acked-by: Hans Verkuil 
> ---

Reviewed-by: Sebastian Reichel 

-- Sebastian

>  drivers/media/v4l2-core/v4l2-async.c  | 19 
>  drivers/media/v4l2-core/v4l2-fwnode.c | 41 
> +++
>  include/media/v4l2-async.h| 22 +++
>  include/media/v4l2-subdev.h   |  3 +++
>  4 files changed, 81 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/media/v4l2-core/v4l2-async.c 
> b/drivers/media/v4l2-core/v4l2-async.c
> index b4e88eef195f..e81a72b8d46e 100644
> --- a/drivers/media/v4l2-core/v4l2-async.c
> +++ b/drivers/media/v4l2-core/v4l2-async.c
> @@ -474,19 +474,25 @@ int v4l2_async_subdev_notifier_register(struct 
> v4l2_subdev *sd,
>  }
>  EXPORT_SYMBOL(v4l2_async_subdev_notifier_register);
>  
> -void v4l2_async_notifier_unregister(struct v4l2_async_notifier *notifier)
> +static void __v4l2_async_notifier_unregister(
> + struct v4l2_async_notifier *notifier)
>  {
> - if (!notifier->v4l2_dev && !notifier->sd)
> + if (!notifier || (!notifier->v4l2_dev && !notifier->sd))
>   return;
>  
> - mutex_lock(_lock);
> -
>   v4l2_async_notifier_unbind_all_subdevs(notifier);
>  
>   notifier->sd = NULL;
>   notifier->v4l2_dev = NULL;
>  
>   list_del(>list);
> +}
> +
> +void v4l2_async_notifier_unregister(struct v4l2_async_notifier *notifier)
> +{
> + mutex_lock(_lock);
> +
> + __v4l2_async_notifier_unregister(notifier);
>  
>   mutex_unlock(_lock);
>  }
> @@ -596,6 +602,11 @@ void v4l2_async_unregister_subdev(struct v4l2_subdev *sd)
>  {
>   mutex_lock(_lock);
>  
> + __v4l2_async_notifier_unregister(sd->subdev_notifier);
> + v4l2_async_notifier_cleanup(sd->subdev_notifier);
> + kfree(sd->subdev_notifier);
> + sd->subdev_notifier = NULL;
> +
>   if (sd->asd) {
>   struct v4l2_async_notifier *notifier = sd->notifier;
>  
> diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c 
> b/drivers/media/v4l2-core/v4l2-fwnode.c
> index 1234bd1a2f49..82af608fd626 100644
> --- a/drivers/media/v4l2-core/v4l2-fwnode.c
> +++ b/drivers/media/v4l2-core/v4l2-fwnode.c
> @@ -29,6 +29,7 @@
>  
>  #include 
>  #include 
> +#include 
>  
>  enum v4l2_fwnode_bus_type {
>   V4L2_FWNODE_BUS_TYPE_GUESS = 0,
> @@ -900,6 +901,46 @@ int v4l2_async_notifier_parse_fwnode_sensor_common(
>  }
>  EXPORT_SYMBOL_GPL(v4l2_async_notifier_parse_fwnode_sensor_common);
>  
> +int v4l2_async_register_subdev_sensor_common(struct v4l2_subdev *sd)
> +{
> + struct v4l2_async_notifier *notifier;
> + int ret;
> +
> + if (WARN_ON(!sd->dev))
> + return -ENODEV;
> +
> + notifier = kzalloc(sizeof(*notifier), GFP_KERNEL);
> + if (!notifier)
> + return -ENOMEM;
> +
> + ret = v4l2_async_notifier_parse_fwnode_sensor_common(sd->dev,
> +  notifier);
> + if (ret < 0)
> + goto out_cleanup;
> +
> + ret = v4l2_async_subdev_notifier_register(sd, notifier);
> + if (ret < 0)
> + goto out_cleanup;
> +
> + ret = v4l2_async_register_subdev(sd);
> + if (ret < 0)
> + goto out_unregister;
> +
> + sd->subdev_notifier = notifier;
> +
> + return 0;
> +
> +out_unregister:
> + v4l2_async_notifier_unregister(notifier);
> +
> +out_cleanup:
> + v4l2_async_notifier_cleanup(notifier);
> + kfree(notifier);
> +
> + return ret;
> +}
> +EXPORT_SYMBOL_GPL(v4l2_async_register_subdev_sensor_common);
> +
>  MODULE_LICENSE("GPL");
>  MODULE_AUTHOR("Sakari Ailus ");
>  MODULE_AUTHOR("Sylwester Nawrocki ");
> diff --git a/include/media/v4l2-async.h b/include/media/v4l2-async.h
> index 8d8cfc3f3100..6152434cbe82 100644
> --- a/include/media/v4l2-async.h
> +++ b/include/media/v4l2-async.h
> @@ -174,6 +174,28 @@ void v4l2_async_notifier_cleanup(struct 
> v4l2_async_notifier *notifier);
>  int v4l2_async_register_subdev(struct v4l2_subdev *sd);
>  
>  /**
> + * v4l2_async_register_subdev_sensor_common - registers a sensor sub-device 
> to
> + * the asynchronous sub-device
> + * framework and parse set up common
> + * sensor related devices
> + *
> + * @sd: pointer to struct _subdev
> + *
> + * This function is just like 

Re: [PATCH v16.1 25/32] v4l: fwnode: Add convenience function for parsing common external refs

2017-10-29 Thread Sebastian Reichel
Hi,

On Thu, Oct 26, 2017 at 06:03:27PM +0300, Sakari Ailus wrote:
> Add v4l2_fwnode_parse_reference_sensor_common for parsing common
> sensor properties that refer to adjacent devices such as flash or lens
> driver chips.
> 
> As this is an association only, there's little a regular driver needs to
> know about these devices as such.
> 
> Signed-off-by: Sakari Ailus 
> Acked-by: Hans Verkuil 
> Acked-by: Pavel Machek 

Reviewd-by: Sebastian Reichel 

-- Sebastian

> ---
> since v16:
> 
> - use const char * const *props for string arrays with property names.
> 
>  drivers/media/v4l2-core/v4l2-fwnode.c | 35 
> +++
>  include/media/v4l2-async.h|  3 ++-
>  include/media/v4l2-fwnode.h   | 21 +
>  3 files changed, 58 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c 
> b/drivers/media/v4l2-core/v4l2-fwnode.c
> index f8cd88f791c4..39387dc6cadd 100644
> --- a/drivers/media/v4l2-core/v4l2-fwnode.c
> +++ b/drivers/media/v4l2-core/v4l2-fwnode.c
> @@ -865,6 +865,41 @@ static int v4l2_fwnode_reference_parse_int_props(
>   return ret;
>  }
>  
> +int v4l2_async_notifier_parse_fwnode_sensor_common(
> + struct device *dev, struct v4l2_async_notifier *notifier)
> +{
> + static const char * const led_props[] = { "led" };
> + static const struct {
> + const char *name;
> + const char * const *props;
> + unsigned int nprops;
> + } props[] = {
> + { "flash-leds", led_props, ARRAY_SIZE(led_props) },
> + { "lens-focus", NULL, 0 },
> + };
> + unsigned int i;
> +
> + for (i = 0; i < ARRAY_SIZE(props); i++) {
> + int ret;
> +
> + if (props[i].props && is_acpi_node(dev_fwnode(dev)))
> + ret = v4l2_fwnode_reference_parse_int_props(
> + dev, notifier, props[i].name,
> + props[i].props, props[i].nprops);
> + else
> + ret = v4l2_fwnode_reference_parse(
> + dev, notifier, props[i].name);
> + if (ret && ret != -ENOENT) {
> + dev_warn(dev, "parsing property \"%s\" failed (%d)\n",
> +  props[i].name, ret);
> + return ret;
> + }
> + }
> +
> + return 0;
> +}
> +EXPORT_SYMBOL_GPL(v4l2_async_notifier_parse_fwnode_sensor_common);
> +
>  MODULE_LICENSE("GPL");
>  MODULE_AUTHOR("Sakari Ailus ");
>  MODULE_AUTHOR("Sylwester Nawrocki ");
> diff --git a/include/media/v4l2-async.h b/include/media/v4l2-async.h
> index 17c4ac7c73e8..8d8cfc3f3100 100644
> --- a/include/media/v4l2-async.h
> +++ b/include/media/v4l2-async.h
> @@ -156,7 +156,8 @@ void v4l2_async_notifier_unregister(struct 
> v4l2_async_notifier *notifier);
>   * Release memory resources related to a notifier, including the async
>   * sub-devices allocated for the purposes of the notifier but not the 
> notifier
>   * itself. The user is responsible for calling this function to clean up the
> - * notifier after calling @v4l2_async_notifier_parse_fwnode_endpoints.
> + * notifier after calling @v4l2_async_notifier_parse_fwnode_endpoints or
> + * @v4l2_fwnode_reference_parse_sensor_common.
>   *
>   * There is no harm from calling v4l2_async_notifier_cleanup in other
>   * cases as long as its memory has been zeroed after it has been
> diff --git a/include/media/v4l2-fwnode.h b/include/media/v4l2-fwnode.h
> index 105cfeee44ef..ca50108dfd8f 100644
> --- a/include/media/v4l2-fwnode.h
> +++ b/include/media/v4l2-fwnode.h
> @@ -319,4 +319,25 @@ int v4l2_async_notifier_parse_fwnode_endpoints_by_port(
> struct v4l2_fwnode_endpoint *vep,
> struct v4l2_async_subdev *asd));
>  
> +/**
> + * v4l2_fwnode_reference_parse_sensor_common - parse common references on
> + *  sensors for async sub-devices
> + * @dev: the device node the properties of which are parsed for references
> + * @notifier: the async notifier where the async subdevs will be added
> + *
> + * Parse common sensor properties for remote devices related to the
> + * sensor and set up async sub-devices for them.
> + *
> + * Any notifier populated using this function must be released with a call to
> + * v4l2_async_notifier_release() after it has been unregistered and the async
> + * sub-devices are no longer in use, even in the case the function returned 
> an
> + * error.
> + *
> + * Return: 0 on success
> + *  -ENOMEM if memory allocation failed
> + *  -EINVAL if property parsing failed
> + */
> +int v4l2_async_notifier_parse_fwnode_sensor_common(
> + struct device *dev, struct v4l2_async_notifier *notifier);
> +
>  #endif /* 

Re: [PATCH v16.1 24/32] v4l: fwnode: Add a helper function to obtain device / integer references

2017-10-29 Thread Sebastian Reichel
Hi,

On Thu, Oct 26, 2017 at 06:01:58PM +0300, Sakari Ailus wrote:
> v4l2_fwnode_reference_parse_int_prop() will find an fwnode such that under
> the device's own fwnode, it will follow child fwnodes with the given
> property-value pair and return the resulting fwnode.
> 
> Signed-off-by: Sakari Ailus 
> Acked-by: Hans Verkuil 
> ---

Reviewed-by: Sebastian Reichel 

-- Sebastian

> since v16:
> 
> - use const char * const *props for string arrays with property names.
> 
>  drivers/media/v4l2-core/v4l2-fwnode.c | 287 
> ++
>  1 file changed, 287 insertions(+)
> 
> diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c 
> b/drivers/media/v4l2-core/v4l2-fwnode.c
> index edd2e8d983a1..f8cd88f791c4 100644
> --- a/drivers/media/v4l2-core/v4l2-fwnode.c
> +++ b/drivers/media/v4l2-core/v4l2-fwnode.c
> @@ -578,6 +578,293 @@ static int v4l2_fwnode_reference_parse(
>   return ret;
>  }
>  
> +/*
> + * v4l2_fwnode_reference_get_int_prop - parse a reference with integer
> + *   arguments
> + * @fwnode: fwnode to read @prop from
> + * @notifier: notifier for @dev
> + * @prop: the name of the property
> + * @index: the index of the reference to get
> + * @props: the array of integer property names
> + * @nprops: the number of integer property names in @nprops
> + *
> + * First find an fwnode referred to by the reference at @index in @prop.
> + *
> + * Then under that fwnode, @nprops times, for each property in @props,
> + * iteratively follow child nodes starting from fwnode such that they have 
> the
> + * property in @props array at the index of the child node distance from the
> + * root node and the value of that property matching with the integer 
> argument
> + * of the reference, at the same index.
> + *
> + * The child fwnode reched at the end of the iteration is then returned to 
> the
> + * caller.
> + *
> + * The core reason for this is that you cannot refer to just any node in 
> ACPI.
> + * So to refer to an endpoint (easy in DT) you need to refer to a device, 
> then
> + * provide a list of (property name, property value) tuples where each tuple
> + * uniquely identifies a child node. The first tuple identifies a child 
> directly
> + * underneath the device fwnode, the next tuple identifies a child node
> + * underneath the fwnode identified by the previous tuple, etc. until you
> + * reached the fwnode you need.
> + *
> + * An example with a graph, as defined in Documentation/acpi/dsd/graph.txt:
> + *
> + *   Scope (\_SB.PCI0.I2C2)
> + *   {
> + *   Device (CAM0)
> + *   {
> + *   Name (_DSD, Package () {
> + *   ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
> + *   Package () {
> + *   Package () {
> + *   "compatible",
> + *   Package () { "nokia,smia" }
> + *   },
> + *   },
> + *   ToUUID("dbb8e3e6-5886-4ba6-8795-1319f52a966b"),
> + *   Package () {
> + *   Package () { "port0", "PRT0" },
> + *   }
> + *   })
> + *   Name (PRT0, Package() {
> + *   ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
> + *   Package () {
> + *   Package () { "port", 0 },
> + *   },
> + *   ToUUID("dbb8e3e6-5886-4ba6-8795-1319f52a966b"),
> + *   Package () {
> + *   Package () { "endpoint0", "EP00" },
> + *   }
> + *   })
> + *   Name (EP00, Package() {
> + *   ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
> + *   Package () {
> + *   Package () { "endpoint", 0 },
> + *   Package () {
> + *   "remote-endpoint",
> + *   Package() {
> + *   \_SB.PCI0.ISP, 4, 0
> + *   }
> + *   },
> + *   }
> + *   })
> + *   }
> + *   }
> + *
> + *   Scope (\_SB.PCI0)
> + *   {
> + *   Device (ISP)
> + *   {
> + *   Name (_DSD, Package () {
> + *   ToUUID("dbb8e3e6-5886-4ba6-8795-1319f52a966b"),
> + *   Package () {
> + *   Package () { "port4", "PRT4" },
> + *   }
> + *   

Re: [PATCH v16 23/32] v4l: fwnode: Add a helper function for parsing generic references

2017-10-29 Thread Sebastian Reichel
Hi,

On Thu, Oct 26, 2017 at 10:53:33AM +0300, Sakari Ailus wrote:
> Add function v4l2_fwnode_reference_parse() for parsing them as async
> sub-devices. This can be done on e.g. flash or lens async sub-devices that
> are not part of but are associated with a sensor.
> 
> Signed-off-by: Sakari Ailus 
> Acked-by: Hans Verkuil 
> ---

Reviewed-by: Sebastian Reichel 

-- Sebastian

>  drivers/media/v4l2-core/v4l2-fwnode.c | 69 
> +++
>  1 file changed, 69 insertions(+)
> 
> diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c 
> b/drivers/media/v4l2-core/v4l2-fwnode.c
> index 65bdcd59744a..edd2e8d983a1 100644
> --- a/drivers/media/v4l2-core/v4l2-fwnode.c
> +++ b/drivers/media/v4l2-core/v4l2-fwnode.c
> @@ -509,6 +509,75 @@ int v4l2_async_notifier_parse_fwnode_endpoints_by_port(
>  }
>  EXPORT_SYMBOL_GPL(v4l2_async_notifier_parse_fwnode_endpoints_by_port);
>  
> +/*
> + * v4l2_fwnode_reference_parse - parse references for async sub-devices
> + * @dev: the device node the properties of which are parsed for references
> + * @notifier: the async notifier where the async subdevs will be added
> + * @prop: the name of the property
> + *
> + * Return: 0 on success
> + *  -ENOENT if no entries were found
> + *  -ENOMEM if memory allocation failed
> + *  -EINVAL if property parsing failed
> + */
> +static int v4l2_fwnode_reference_parse(
> + struct device *dev, struct v4l2_async_notifier *notifier,
> + const char *prop)
> +{
> + struct fwnode_reference_args args;
> + unsigned int index;
> + int ret;
> +
> + for (index = 0;
> +  !(ret = fwnode_property_get_reference_args(
> +dev_fwnode(dev), prop, NULL, 0, index, ));
> +  index++)
> + fwnode_handle_put(args.fwnode);
> +
> + if (!index)
> + return -ENOENT;
> +
> + /*
> +  * Note that right now both -ENODATA and -ENOENT may signal
> +  * out-of-bounds access. Return the error in cases other than that.
> +  */
> + if (ret != -ENOENT && ret != -ENODATA)
> + return ret;
> +
> + ret = v4l2_async_notifier_realloc(notifier,
> +   notifier->num_subdevs + index);
> + if (ret)
> + return ret;
> +
> + for (index = 0; !fwnode_property_get_reference_args(
> +  dev_fwnode(dev), prop, NULL, 0, index, );
> +  index++) {
> + struct v4l2_async_subdev *asd;
> +
> + if (WARN_ON(notifier->num_subdevs >= notifier->max_subdevs)) {
> + ret = -EINVAL;
> + goto error;
> + }
> +
> + asd = kzalloc(sizeof(*asd), GFP_KERNEL);
> + if (!asd) {
> + ret = -ENOMEM;
> + goto error;
> + }
> +
> + notifier->subdevs[notifier->num_subdevs] = asd;
> + asd->match.fwnode.fwnode = args.fwnode;
> + asd->match_type = V4L2_ASYNC_MATCH_FWNODE;
> + notifier->num_subdevs++;
> + }
> +
> + return 0;
> +
> +error:
> + fwnode_handle_put(args.fwnode);
> + return ret;
> +}
> +
>  MODULE_LICENSE("GPL");
>  MODULE_AUTHOR("Sakari Ailus ");
>  MODULE_AUTHOR("Sylwester Nawrocki ");
> -- 
> 2.11.0
> 


signature.asc
Description: PGP signature


Re: [PATCH v16 22/32] v4l: fwnode: Move KernelDoc documentation to the header

2017-10-29 Thread Sebastian Reichel
Hi,

On Thu, Oct 26, 2017 at 10:53:32AM +0300, Sakari Ailus wrote:
> In V4L2 the practice is to have the KernelDoc documentation in the header
> and not in .c source code files. This consequently makes the V4L2 fwnode
> function documentation part of the Media documentation build.
> 
> Also correct the link related function and argument naming in
> documentation and add an asterisk to v4l2_fwnode_endpoint_free()
> documentation to make it proper KernelDoc documentation.
> 
> Signed-off-by: Sakari Ailus 
> Reviewed-by: Niklas Söderlund 
> Acked-by: Hans Verkuil 
> Acked-by: Pavel Machek 
> ---

Reviewed-by: Sebastian Reichel 

-- Sebastian

>  drivers/media/v4l2-core/v4l2-fwnode.c | 75 
>  include/media/v4l2-fwnode.h   | 81 
> ++-
>  2 files changed, 80 insertions(+), 76 deletions(-)
> 
> diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c 
> b/drivers/media/v4l2-core/v4l2-fwnode.c
> index df0695b7bbcc..65bdcd59744a 100644
> --- a/drivers/media/v4l2-core/v4l2-fwnode.c
> +++ b/drivers/media/v4l2-core/v4l2-fwnode.c
> @@ -183,25 +183,6 @@ v4l2_fwnode_endpoint_parse_csi1_bus(struct fwnode_handle 
> *fwnode,
>   vep->bus_type = V4L2_MBUS_CSI1;
>  }
>  
> -/**
> - * v4l2_fwnode_endpoint_parse() - parse all fwnode node properties
> - * @fwnode: pointer to the endpoint's fwnode handle
> - * @vep: pointer to the V4L2 fwnode data structure
> - *
> - * All properties are optional. If none are found, we don't set any flags. 
> This
> - * means the port has a static configuration and no properties have to be
> - * specified explicitly. If any properties that identify the bus as parallel
> - * are found and slave-mode isn't set, we set V4L2_MBUS_MASTER. Similarly, if
> - * we recognise the bus as serial CSI-2 and clock-noncontinuous isn't set, we
> - * set the V4L2_MBUS_CSI2_CONTINUOUS_CLOCK flag. The caller should hold a
> - * reference to @fwnode.
> - *
> - * NOTE: This function does not parse properties the size of which is 
> variable
> - * without a low fixed limit. Please use v4l2_fwnode_endpoint_alloc_parse() 
> in
> - * new drivers instead.
> - *
> - * Return: 0 on success or a negative error code on failure.
> - */
>  int v4l2_fwnode_endpoint_parse(struct fwnode_handle *fwnode,
>  struct v4l2_fwnode_endpoint *vep)
>  {
> @@ -241,14 +222,6 @@ int v4l2_fwnode_endpoint_parse(struct fwnode_handle 
> *fwnode,
>  }
>  EXPORT_SYMBOL_GPL(v4l2_fwnode_endpoint_parse);
>  
> -/*
> - * v4l2_fwnode_endpoint_free() - free the V4L2 fwnode acquired by
> - * v4l2_fwnode_endpoint_alloc_parse()
> - * @vep - the V4L2 fwnode the resources of which are to be released
> - *
> - * It is safe to call this function with NULL argument or on a V4L2 fwnode 
> the
> - * parsing of which failed.
> - */
>  void v4l2_fwnode_endpoint_free(struct v4l2_fwnode_endpoint *vep)
>  {
>   if (IS_ERR_OR_NULL(vep))
> @@ -259,29 +232,6 @@ void v4l2_fwnode_endpoint_free(struct 
> v4l2_fwnode_endpoint *vep)
>  }
>  EXPORT_SYMBOL_GPL(v4l2_fwnode_endpoint_free);
>  
> -/**
> - * v4l2_fwnode_endpoint_alloc_parse() - parse all fwnode node properties
> - * @fwnode: pointer to the endpoint's fwnode handle
> - *
> - * All properties are optional. If none are found, we don't set any flags. 
> This
> - * means the port has a static configuration and no properties have to be
> - * specified explicitly. If any properties that identify the bus as parallel
> - * are found and slave-mode isn't set, we set V4L2_MBUS_MASTER. Similarly, if
> - * we recognise the bus as serial CSI-2 and clock-noncontinuous isn't set, we
> - * set the V4L2_MBUS_CSI2_CONTINUOUS_CLOCK flag. The caller should hold a
> - * reference to @fwnode.
> - *
> - * v4l2_fwnode_endpoint_alloc_parse() has two important differences to
> - * v4l2_fwnode_endpoint_parse():
> - *
> - * 1. It also parses variable size data.
> - *
> - * 2. The memory it has allocated to store the variable size data must be 
> freed
> - *using v4l2_fwnode_endpoint_free() when no longer needed.
> - *
> - * Return: Pointer to v4l2_fwnode_endpoint if successful, on an error pointer
> - * on error.
> - */
>  struct v4l2_fwnode_endpoint *v4l2_fwnode_endpoint_alloc_parse(
>   struct fwnode_handle *fwnode)
>  {
> @@ -324,24 +274,6 @@ struct v4l2_fwnode_endpoint 
> *v4l2_fwnode_endpoint_alloc_parse(
>  }
>  EXPORT_SYMBOL_GPL(v4l2_fwnode_endpoint_alloc_parse);
>  
> -/**
> - * v4l2_fwnode_endpoint_parse_link() - parse a link between two endpoints
> - * @__fwnode: pointer to the endpoint's fwnode at the local end of the link
> - * @link: pointer to the V4L2 fwnode link data structure
> - *
> - * Fill the link structure with the local and remote nodes and port numbers.
> - * The local_node and remote_node fields are set to point to the local and
> - * remote port's parent nodes 

Re: [PATCH v16 20/32] dt: bindings: Add a binding for flash LED devices associated to a sensor

2017-10-29 Thread Sebastian Reichel
Hi,

On Thu, Oct 26, 2017 at 10:53:30AM +0300, Sakari Ailus wrote:
> Camera flash drivers (and LEDs) are separate from the sensor devices in
> DT. In order to make an association between the two, provide the
> association information to the software.
> 
> Signed-off-by: Sakari Ailus 
> Cc: Rob Herring 
> Cc: devicet...@vger.kernel.org
> Acked-by: Hans Verkuil 
> Acked-by: Pavel Machek 
> Acked-by: Rob Herring 
> ---

Reviewed-by: Sebastian Reichel 

-- Sebastian

>  Documentation/devicetree/bindings/media/video-interfaces.txt | 8 
>  1 file changed, 8 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/media/video-interfaces.txt 
> b/Documentation/devicetree/bindings/media/video-interfaces.txt
> index bd6474920510..dc66e3224692 100644
> --- a/Documentation/devicetree/bindings/media/video-interfaces.txt
> +++ b/Documentation/devicetree/bindings/media/video-interfaces.txt
> @@ -76,6 +76,14 @@ are required in a relevant parent node:
>   identifier, should be 1.
>   - #size-cells: should be zero.
>  
> +
> +Optional properties
> +---
> +
> +- flash-leds: An array of phandles, each referring to a flash LED, a sub-node
> +  of the LED driver device node.
> +
> +
>  Optional endpoint properties
>  
>  
> -- 
> 2.11.0
> 


signature.asc
Description: PGP signature


Re: [PATCH v16.1 19/32] v4l: async: Ensure only unique fwnodes are registered to notifiers

2017-10-29 Thread Sebastian Reichel
Hi,

On Fri, Oct 27, 2017 at 01:53:09PM +0300, Sakari Ailus wrote:
> While registering a notifier, check that each newly added fwnode is
> unique, and return an error if it is not. Also check that a newly added
> notifier does not have the same fwnodes twice.
> 
> Signed-off-by: Sakari Ailus 
> Acked-by: Hans Verkuil 
> Acked-by: Niklas Söderlund 
> ---
>  drivers/media/v4l2-core/v4l2-async.c | 89 
> 
>  1 file changed, 81 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/media/v4l2-core/v4l2-async.c 
> b/drivers/media/v4l2-core/v4l2-async.c
> index ed539c4fd5dc..a33a68e5417b 100644
> --- a/drivers/media/v4l2-core/v4l2-async.c
> +++ b/drivers/media/v4l2-core/v4l2-async.c
> @@ -308,8 +308,71 @@ static void v4l2_async_notifier_unbind_all_subdevs(
>   notifier->parent = NULL;
>  }
>  
> +/* See if an fwnode can be found in a notifier's lists. */
> +static bool __v4l2_async_notifier_fwnode_has_async_subdev(
> + struct v4l2_async_notifier *notifier, struct fwnode_handle *fwnode)
> +{
> + struct v4l2_async_subdev *asd;
> + struct v4l2_subdev *sd;
> +
> + list_for_each_entry(asd, >waiting, list) {
> + if (asd->match_type != V4L2_ASYNC_MATCH_FWNODE)
> + continue;
> +
> + if (asd->match.fwnode.fwnode == fwnode)
> + return true;
> + }
> +
> + list_for_each_entry(sd, >done, async_list) {
> + if (WARN_ON(!sd->asd))
> + continue;
> +
> + if (sd->asd->match_type != V4L2_ASYNC_MATCH_FWNODE)
> + continue;
> +
> + if (sd->asd->match.fwnode.fwnode == fwnode)
> + return true;
> + }
> +
> + return false;
> +}
> +
> +/*
> + * Find out whether an async sub-device was set up for an fwnode already or
> + * whether it exists in a given notifier before @this_index.
> + */
> +static bool v4l2_async_notifier_fwnode_has_async_subdev(
> + struct v4l2_async_notifier *notifier, struct fwnode_handle *fwnode,
> + unsigned int this_index)
> +{
> + unsigned int j;
> +
> + lockdep_assert_held(_lock);
> +
> + /* Check that an fwnode is not being added more than once. */
> + for (j = 0; j < this_index; j++) {
> + struct v4l2_async_subdev *asd = notifier->subdevs[this_index];
> + struct v4l2_async_subdev *other_asd = notifier->subdevs[j];
> +
> + if (other_asd->match_type == V4L2_ASYNC_MATCH_FWNODE &&
> + asd->match.fwnode.fwnode ==
> + other_asd->match.fwnode.fwnode)
> + return true;
> + }
> +
> + /* Check than an fwnode did not exist in other notifiers. */
> + list_for_each_entry(notifier, _list, list)
> + if (__v4l2_async_notifier_fwnode_has_async_subdev(
> + notifier, fwnode))
> + return true;
> +
> + return false;
> +}
> +
>  static int __v4l2_async_notifier_register(struct v4l2_async_notifier 
> *notifier)
>  {
> + struct device *dev =
> + notifier->v4l2_dev ? notifier->v4l2_dev->dev : NULL;
>   struct v4l2_async_subdev *asd;
>   int ret;
>   int i;
> @@ -320,6 +383,8 @@ static int __v4l2_async_notifier_register(struct 
> v4l2_async_notifier *notifier)
>   INIT_LIST_HEAD(>waiting);
>   INIT_LIST_HEAD(>done);
>  
> + mutex_lock(_lock);
> +
>   for (i = 0; i < notifier->num_subdevs; i++) {
>   asd = notifier->subdevs[i];
>  
> @@ -327,33 +392,41 @@ static int __v4l2_async_notifier_register(struct 
> v4l2_async_notifier *notifier)
>   case V4L2_ASYNC_MATCH_CUSTOM:
>   case V4L2_ASYNC_MATCH_DEVNAME:
>   case V4L2_ASYNC_MATCH_I2C:
> + break;
>   case V4L2_ASYNC_MATCH_FWNODE:
> + if (v4l2_async_notifier_fwnode_has_async_subdev(
> + notifier, asd->match.fwnode.fwnode, i)) {
> + dev_err(dev,
> + "fwnode has already been registered or 
> in notifier's subdev list\n");
> + ret = -EEXIST;
> + goto out_unlock;
> + }
>   break;
>   default:
> - dev_err(notifier->v4l2_dev ? notifier->v4l2_dev->dev : 
> NULL,
> - "Invalid match type %u on %p\n",
> + dev_err(dev, "Invalid match type %u on %p\n",
>   asd->match_type, asd);
> - return -EINVAL;
> + ret = -EINVAL;
> + goto out_unlock;
>   }
>   list_add_tail(>list, >waiting);
>   }
>  
> - mutex_lock(_lock);
> -
>   ret = v4l2_async_notifier_try_all_subdevs(notifier);
> -   

Re: [PATCH v16.1 18/32] v4l: async: Allow binding notifiers to sub-devices

2017-10-29 Thread Sebastian Reichel
Hi,

On Fri, Oct 27, 2017 at 11:27:09AM +0300, Sakari Ailus wrote:
> Registering a notifier has required the knowledge of struct v4l2_device
> for the reason that sub-devices generally are registered to the
> v4l2_device (as well as the media device, also available through
> v4l2_device).
> 
> This information is not available for sub-device drivers at probe time.
> 
> What this patch does is that it allows registering notifiers without
> having v4l2_device around. Instead the sub-device pointer is stored in the
> notifier. Once the sub-device of the driver that registered the notifier
> is registered, the notifier will gain the knowledge of the v4l2_device,
> and the binding of async sub-devices from the sub-device driver's notifier
> may proceed.
> 
> The complete callback of the root notifier will be called only when the
> v4l2_device is available and no notifier has pending sub-devices to bind.
> No complete callbacks are supported for sub-device notifiers.
> 
> Signed-off-by: Sakari Ailus 
> Acked-by: Hans Verkuil 
> ---

Reviewed-by: Sebastian Reichel 

-- Sebastian

>  drivers/media/v4l2-core/v4l2-async.c | 212 
> ---
>  include/media/v4l2-async.h   |  19 +++-
>  2 files changed, 189 insertions(+), 42 deletions(-)
> 
> diff --git a/drivers/media/v4l2-core/v4l2-async.c 
> b/drivers/media/v4l2-core/v4l2-async.c
> index 6265717769d2..ed539c4fd5dc 100644
> --- a/drivers/media/v4l2-core/v4l2-async.c
> +++ b/drivers/media/v4l2-core/v4l2-async.c
> @@ -124,11 +124,87 @@ static struct v4l2_async_subdev *v4l2_async_find_match(
>   return NULL;
>  }
>  
> +/* Find the sub-device notifier registered by a sub-device driver. */
> +static struct v4l2_async_notifier *v4l2_async_find_subdev_notifier(
> + struct v4l2_subdev *sd)
> +{
> + struct v4l2_async_notifier *n;
> +
> + list_for_each_entry(n, _list, list)
> + if (n->sd == sd)
> + return n;
> +
> + return NULL;
> +}
> +
> +/* Get v4l2_device related to the notifier if one can be found. */
> +static struct v4l2_device *v4l2_async_notifier_find_v4l2_dev(
> + struct v4l2_async_notifier *notifier)
> +{
> + while (notifier->parent)
> + notifier = notifier->parent;
> +
> + return notifier->v4l2_dev;
> +}
> +
> +/*
> + * Return true if all child sub-device notifiers are complete, false 
> otherwise.
> + */
> +static bool v4l2_async_notifier_can_complete(
> + struct v4l2_async_notifier *notifier)
> +{
> + struct v4l2_subdev *sd;
> +
> + if (!list_empty(>waiting))
> + return false;
> +
> + list_for_each_entry(sd, >done, async_list) {
> + struct v4l2_async_notifier *subdev_notifier =
> + v4l2_async_find_subdev_notifier(sd);
> +
> + if (subdev_notifier &&
> + !v4l2_async_notifier_can_complete(subdev_notifier))
> + return false;
> + }
> +
> + return true;
> +}
> +
> +/*
> + * Complete the master notifier if possible. This is done when all async
> + * sub-devices have been bound; v4l2_device is also available then.
> + */
> +static int v4l2_async_notifier_try_complete(
> + struct v4l2_async_notifier *notifier)
> +{
> + /* Quick check whether there are still more sub-devices here. */
> + if (!list_empty(>waiting))
> + return 0;
> +
> + /* Check the entire notifier tree; find the root notifier first. */
> + while (notifier->parent)
> + notifier = notifier->parent;
> +
> + /* This is root if it has v4l2_dev. */
> + if (!notifier->v4l2_dev)
> + return 0;
> +
> + /* Is everything ready? */
> + if (!v4l2_async_notifier_can_complete(notifier))
> + return 0;
> +
> + return v4l2_async_notifier_call_complete(notifier);
> +}
> +
> +static int v4l2_async_notifier_try_all_subdevs(
> + struct v4l2_async_notifier *notifier);
> +
>  static int v4l2_async_match_notify(struct v4l2_async_notifier *notifier,
>  struct v4l2_device *v4l2_dev,
>  struct v4l2_subdev *sd,
>  struct v4l2_async_subdev *asd)
>  {
> + struct v4l2_async_notifier *subdev_notifier;
>   int ret;
>  
>   ret = v4l2_device_register_subdev(v4l2_dev, sd);
> @@ -149,17 +225,36 @@ static int v4l2_async_match_notify(struct 
> v4l2_async_notifier *notifier,
>   /* Move from the global subdevice list to notifier's done */
>   list_move(>async_list, >done);
>  
> - return 0;
> + /*
> +  * See if the sub-device has a notifier. If not, return here.
> +  */
> + subdev_notifier = v4l2_async_find_subdev_notifier(sd);
> + if (!subdev_notifier || subdev_notifier->parent)
> + return 0;
> +
> + /*
> +  * Proceed with checking for the sub-device notifier's async
> +  * 

[PATCH 28/28] kfifo: DECLARE_KIFO_PTR(fifo, u64) does not work on arm 32 bit

2017-10-29 Thread Sean Young
If you try to store u64 in a kfifo (or a struct with u64 members),
then the buf member of __STRUCT_KFIFO_PTR will cause 4 bytes
padding due to alignment (note that struct __kfifo is 20 bytes
on 32 bit).

That in turn causes the __is_kfifo_ptr() to fail, which is caught
by kfifo_alloc(), which now returns EINVAL.

So, ensure that __is_kfifo_ptr() compares to the right structure.

Signed-off-by: Sean Young 
Acked-by: Stefani Seibold 
---
 include/linux/kfifo.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/linux/kfifo.h b/include/linux/kfifo.h
index 41eb6fdf87a8..86b5fb08e96c 100644
--- a/include/linux/kfifo.h
+++ b/include/linux/kfifo.h
@@ -113,7 +113,8 @@ struct kfifo_rec_ptr_2 __STRUCT_KFIFO_PTR(unsigned char, 2, 
void);
  * array is a part of the structure and the fifo type where the array is
  * outside of the fifo structure.
  */
-#define__is_kfifo_ptr(fifo)(sizeof(*fifo) == sizeof(struct 
__kfifo))
+#define__is_kfifo_ptr(fifo) \
+   (sizeof(*fifo) == sizeof(STRUCT_KFIFO_PTR(typeof(*(fifo)->type
 
 /**
  * DECLARE_KFIFO_PTR - macro to declare a fifo pointer object
-- 
2.13.6



[PATCH 25/28] media: lirc: document LIRC_MODE_SCANCODE

2017-10-29 Thread Sean Young
Lirc supports a new mode which requires documentation.

Signed-off-by: Sean Young 
---
 Documentation/media/lirc.h.rst.exceptions  | 26 +++
 Documentation/media/uapi/rc/lirc-dev-intro.rst | 51 +++---
 Documentation/media/uapi/rc/lirc-get-features.rst  | 16 +++
 Documentation/media/uapi/rc/lirc-get-rec-mode.rst  |  3 +-
 Documentation/media/uapi/rc/lirc-get-send-mode.rst |  3 +-
 Documentation/media/uapi/rc/lirc-read.rst  | 15 +--
 Documentation/media/uapi/rc/lirc-write.rst | 19 ++--
 7 files changed, 118 insertions(+), 15 deletions(-)

diff --git a/Documentation/media/lirc.h.rst.exceptions 
b/Documentation/media/lirc.h.rst.exceptions
index 63ba1d341905..c6e3a35d2c4e 100644
--- a/Documentation/media/lirc.h.rst.exceptions
+++ b/Documentation/media/lirc.h.rst.exceptions
@@ -32,6 +32,32 @@ ignore define LIRC_CAN_SET_REC_DUTY_CYCLE
 
 ignore ioctl LIRC_GET_LENGTH
 
+# rc protocols
+
+ignore symbol RC_PROTO_UNKNOWN
+ignore symbol RC_PROTO_OTHER
+ignore symbol RC_PROTO_RC5
+ignore symbol RC_PROTO_RC5X_20
+ignore symbol RC_PROTO_RC5_SZ
+ignore symbol RC_PROTO_JVC
+ignore symbol RC_PROTO_SONY12
+ignore symbol RC_PROTO_SONY15
+ignore symbol RC_PROTO_SONY20
+ignore symbol RC_PROTO_NEC
+ignore symbol RC_PROTO_NECX
+ignore symbol RC_PROTO_NEC32
+ignore symbol RC_PROTO_SANYO
+ignore symbol RC_PROTO_MCIR2_KBD
+ignore symbol RC_PROTO_MCIR2_MSE
+ignore symbol RC_PROTO_RC6_0
+ignore symbol RC_PROTO_RC6_6A_20
+ignore symbol RC_PROTO_RC6_6A_24
+ignore symbol RC_PROTO_RC6_6A_32
+ignore symbol RC_PROTO_RC6_MCE
+ignore symbol RC_PROTO_SHARP
+ignore symbol RC_PROTO_XMP
+ignore symbol RC_PROTO_CEC
+
 # Undocumented macros
 
 ignore define PULSE_BIT
diff --git a/Documentation/media/uapi/rc/lirc-dev-intro.rst 
b/Documentation/media/uapi/rc/lirc-dev-intro.rst
index a3fa3c1ef169..47c6c218e72a 100644
--- a/Documentation/media/uapi/rc/lirc-dev-intro.rst
+++ b/Documentation/media/uapi/rc/lirc-dev-intro.rst
@@ -6,11 +6,12 @@
 Introduction
 
 
-The LIRC device interface is a bi-directional interface for transporting
-raw IR data between userspace and kernelspace. Fundamentally, it is just
-a chardev (/dev/lircX, for X = 0, 1, 2, ...), with a number of standard
-struct file_operations defined on it. With respect to transporting raw
-IR data to and fro, the essential fops are read, write and ioctl.
+LIRC stands for Linux Infrared Remote Control. The LIRC device interface is
+a bi-directional interface for transporting raw IR and decoded scancodes
+data between userspace and kernelspace. Fundamentally, it is just a chardev
+(/dev/lircX, for X = 0, 1, 2, ...), with a number of standard struct
+file_operations defined on it. With respect to transporting raw IR and
+decoded scancodes to and fro, the essential fops are read, write and ioctl.
 
 Example dmesg output upon a driver registering w/LIRC:
 
@@ -36,6 +37,46 @@ LIRC modes
 LIRC supports some modes of receiving and sending IR codes, as shown
 on the following table.
 
+.. _lirc-mode-scancode:
+.. _lirc-scancode-flag-toggle:
+.. _lirc-scancode-flag-repeat:
+
+``LIRC_MODE_SCANCODE``
+
+This mode is for both sending and receiving IR.
+
+For transmitting (aka sending), create a ``struct lirc_scancode`` with
+the desired scancode set in the ``scancode`` member, ``rc_proto`` set
+the IR protocol, and all other members set to 0. Write this struct to
+the lirc device.
+
+For receiving, you read ``struct lirc_scancode`` from the lirc device,
+with ``scancode`` set to the received scancode and the IR protocol
+``rc_proto``. If the scancode maps to a valid key code, this is set
+in the ``keycode`` field, else it is set to ``KEY_RESERVED``.
+
+The ``flags`` can have ``LIRC_SCANCODE_FLAG_TOGGLE`` set if the toggle
+bit is set in protocols that support it (e.g. rc-5 and rc-6), or
+``LIRC_SCANCODE_FLAG_REPEAT`` for when a repeat is received for protocols
+that support it (e.g. nec).
+
+In the Sanyo and NEC protocol, if you hold a button on remote, rather than
+repeating the entire scancode, the remote sends a shorter message with
+no scancode, which just means button is held, a "repeat". When this is
+received, the ``LIRC_SCANCODE_FLAG_REPEAT`` is set and the scancode and
+keycode is repeated.
+
+With nec, there is no way to distinguish "button hold" from "repeatedly
+pressing the same button". The rc-5 and rc-6 protocols have a toggle bit.
+When a button is released and pressed again, the toggle bit is inverted.
+If the toggle bit is set, the ``LIRC_SCANCODE_FLAG_TOGGLE`` is set.
+
+The ``timestamp`` field is filled with the time nanoseconds
+(in ``CLOCK_MONOTONIC``) when the scancode was decoded.
+
+An ``enum rc_proto`` in the :ref:`lirc_header` lists all the supported
+IR protocols.
+
 .. _lirc-mode-mode2:
 
 ``LIRC_MODE_MODE2``
diff --git a/Documentation/media/uapi/rc/lirc-get-features.rst 

[PATCH 26/28] media: lirc: introduce LIRC_SET_POLL_MODES

2017-10-29 Thread Sean Young
If you want to poll for both decoded scancodes and raw IR, then this
ioctl will help you.

int fd = open("/dev/lirc0", O_RDONLY | O_NONBLOCK);

for (;;) {
unsigned mode = LIRC_MODE_SCANCODE | LIRC_MODE_MODE2;
ioctl(fd, LIRC_SET_POLL_MODES, );
poll(&((struct pollfd){ .fd = fd, .events = POLLIN }), 1, -1);
mode = LIRC_MODE_SCANCODE;
ioctl(fd, LIRC_SET_REC_MODE, );
struct lirc_scancode sc;
if (read(fd, , sizeof(sc)) == sizeof(sc)) {
printf("scancode protocol:%d scancode:%llx\n",
sc.rc_proto, sc.scancode);
}
mode = LIRC_MODE_MODE2;
ioctl(fd, LIRC_SET_REC_MODE, );
unsigned sample;
if (read(fd, , sizeof(sample)) == sizeof(sample)) {
if (LIRC_IS_SPACE(sample))
printf("space %u\n", LIRC_VAL(sample)));
if (LIRC_IS_PULSE(sample))
printf("pulse %u\n", LIRC_VAL(sample)));
}
}

Note that LIRC_SET_REC_MODE will also affect the poll mode, so you
must set it again before calling poll.

Signed-off-by: Sean Young 
---
 Documentation/media/uapi/rc/lirc-func.rst  |  1 +
 .../media/uapi/rc/lirc-set-poll-modes.rst  | 52 ++
 drivers/media/rc/ir-lirc-codec.c   | 19 ++--
 drivers/media/rc/lirc_dev.c|  1 +
 include/media/rc-core.h|  3 ++
 include/uapi/linux/lirc.h  |  9 
 6 files changed, 81 insertions(+), 4 deletions(-)
 create mode 100644 Documentation/media/uapi/rc/lirc-set-poll-modes.rst

diff --git a/Documentation/media/uapi/rc/lirc-func.rst 
b/Documentation/media/uapi/rc/lirc-func.rst
index ddb4620de294..6493430aabef 100644
--- a/Documentation/media/uapi/rc/lirc-func.rst
+++ b/Documentation/media/uapi/rc/lirc-func.rst
@@ -25,3 +25,4 @@ LIRC Function Reference
 lirc-set-rec-timeout-reports
 lirc-set-measure-carrier-mode
 lirc-set-wideband-receiver
+lirc-set-poll-modes
diff --git a/Documentation/media/uapi/rc/lirc-set-poll-modes.rst 
b/Documentation/media/uapi/rc/lirc-set-poll-modes.rst
new file mode 100644
index ..2ae08dcd86ea
--- /dev/null
+++ b/Documentation/media/uapi/rc/lirc-set-poll-modes.rst
@@ -0,0 +1,52 @@
+.. -*- coding: utf-8; mode: rst -*-
+
+.. _lirc_set_poll_modes:
+
+**
+ioctls LIRC_SET_POLL_MODES
+**
+
+Name
+
+
+LIRC_SET_POLL_MODES - Set LIRC modes to use for poll
+
+Synopsis
+
+
+.. c:function:: int ioctl( int fd, LIRC_SET_POLL_MODES, __u32 modes)
+   :name: LIRC_SET_POLL_MODES
+
+Arguments
+=
+
+``fd``
+File descriptor returned by open().
+
+``modes``
+Bitmask with enabled poll lirc modes
+
+Description
+===
+
+Set lirc modes for which read readiness is reported by poll. Only
+:ref:`LIRC_MODE_MODE2 ` and
+:ref:`LIRC_MODE_SCANCODE ` are supported. Poll
+can report read readiness for both modes if you bitwise or them together.
+Use :ref:`lirc_get_features` to find out which modes the driver supports.
+
+This ioctl is useful when you want to read both raw IR and decoded
+scancodes. You can set :ref:`LIRC_MODE_MODE2 ` and
+poll for raw IR for some time, and then set
+:ref:`LIRC_MODE_SCANCODE ` and poll for decoded
+scancodes, and repeat both modes again. Using this ioctl, you can poll
+for both without having to wait for a limited period in each mode.
+
+Note that using :ref:`lirc_set_rec_mode` resets the poll mode.
+
+Return Value
+
+
+On success 0 is returned, on error -1 and the ``errno`` variable is set
+appropriately. The generic error codes are described at the
+:ref:`Generic Error Codes ` chapter.
diff --git a/drivers/media/rc/ir-lirc-codec.c b/drivers/media/rc/ir-lirc-codec.c
index 6a439ef4293e..f3dc3c250261 100644
--- a/drivers/media/rc/ir-lirc-codec.c
+++ b/drivers/media/rc/ir-lirc-codec.c
@@ -351,6 +351,17 @@ static long ir_lirc_ioctl(struct file *filep, unsigned int 
cmd,
return -EINVAL;
 
dev->rec_mode = val;
+   dev->poll_mode = val;
+   return 0;
+
+   case LIRC_SET_POLL_MODES:
+   if (dev->driver_type == RC_DRIVER_IR_RAW_TX)
+   return -ENOTTY;
+
+   if (val & ~(LIRC_MODE_MODE2 | LIRC_MODE_SCANCODE))
+   return -EINVAL;
+
+   dev->poll_mode = val;
return 0;
 
case LIRC_GET_SEND_MODE:
@@ -493,13 +504,13 @@ static unsigned int ir_lirc_poll(struct file *file,
if (!rcdev->registered) {
events = POLLHUP | POLLERR;
} else if (rcdev->driver_type != RC_DRIVER_IR_RAW_TX) {
-   if (rcdev->rec_mode == LIRC_MODE_SCANCODE &&
+   if ((rcdev->poll_mode & LIRC_MODE_SCANCODE) &&
!kfifo_is_empty(>scancodes))
-   events = 

[PATCH 27/28] media: lirc: scancode rc devices should have a lirc device too

2017-10-29 Thread Sean Young
Now that the lirc interface supports scancodes, RC scancode devices
can also have a lirc device. The only receiving feature they will have
enabled is LIRC_CAN_REC_SCANCODE.

Note that CEC devices have no lirc device, since they can be controlled
from their /dev/cecN chardev.

Signed-off-by: Sean Young 
---
 drivers/media/rc/ir-lirc-codec.c | 34 ++
 drivers/media/rc/lirc_dev.c  |  9 +++--
 drivers/media/rc/rc-main.c   |  6 +++---
 3 files changed, 36 insertions(+), 13 deletions(-)

diff --git a/drivers/media/rc/ir-lirc-codec.c b/drivers/media/rc/ir-lirc-codec.c
index f3dc3c250261..78934479bcff 100644
--- a/drivers/media/rc/ir-lirc-codec.c
+++ b/drivers/media/rc/ir-lirc-codec.c
@@ -304,6 +304,9 @@ static long ir_lirc_ioctl(struct file *filep, unsigned int 
cmd,
 
switch (cmd) {
case LIRC_GET_FEATURES:
+   if (dev->driver_type == RC_DRIVER_SCANCODE)
+   val |= LIRC_CAN_REC_SCANCODE;
+
if (dev->driver_type == RC_DRIVER_IR_RAW) {
val |= LIRC_CAN_REC_MODE2 | LIRC_CAN_REC_SCANCODE;
if (dev->rx_resolution)
@@ -344,22 +347,37 @@ static long ir_lirc_ioctl(struct file *filep, unsigned 
int cmd,
break;
 
case LIRC_SET_REC_MODE:
-   if (dev->driver_type == RC_DRIVER_IR_RAW_TX)
+   switch (dev->driver_type) {
+   case RC_DRIVER_IR_RAW_TX:
return -ENOTTY;
-
-   if (!(val == LIRC_MODE_MODE2 || val == LIRC_MODE_SCANCODE))
-   return -EINVAL;
+   case RC_DRIVER_SCANCODE:
+   if (val != LIRC_MODE_SCANCODE)
+   return -EINVAL;
+   break;
+   case RC_DRIVER_IR_RAW:
+   if (!(val == LIRC_MODE_MODE2 ||
+ val == LIRC_MODE_SCANCODE))
+   return -EINVAL;
+   break;
+   }
 
dev->rec_mode = val;
dev->poll_mode = val;
return 0;
 
case LIRC_SET_POLL_MODES:
-   if (dev->driver_type == RC_DRIVER_IR_RAW_TX)
+   switch (dev->driver_type) {
+   case RC_DRIVER_IR_RAW_TX:
return -ENOTTY;
-
-   if (val & ~(LIRC_MODE_MODE2 | LIRC_MODE_SCANCODE))
-   return -EINVAL;
+   case RC_DRIVER_SCANCODE:
+   if (val != LIRC_MODE_SCANCODE)
+   return -EINVAL;
+   break;
+   case RC_DRIVER_IR_RAW:
+   if (val & ~(LIRC_MODE_MODE2 | LIRC_MODE_SCANCODE))
+   return -EINVAL;
+   break;
+   }
 
dev->poll_mode = val;
return 0;
diff --git a/drivers/media/rc/lirc_dev.c b/drivers/media/rc/lirc_dev.c
index c3f86da50707..04a2d521c441 100644
--- a/drivers/media/rc/lirc_dev.c
+++ b/drivers/media/rc/lirc_dev.c
@@ -57,8 +57,13 @@ int ir_lirc_register(struct rc_dev *dev)
dev->lirc_dev.release = lirc_release_device;
dev->send_mode = LIRC_MODE_PULSE;
 
-   dev->rec_mode = LIRC_MODE_MODE2;
-   dev->poll_mode = LIRC_MODE_MODE2;
+   if (dev->driver_type == RC_DRIVER_SCANCODE) {
+   dev->rec_mode = LIRC_MODE_SCANCODE;
+   dev->poll_mode = LIRC_MODE_SCANCODE;
+   } else {
+   dev->rec_mode = LIRC_MODE_MODE2;
+   dev->poll_mode = LIRC_MODE_MODE2;
+   }
 
if (dev->driver_type == RC_DRIVER_IR_RAW) {
if (kfifo_alloc(>rawir, MAX_IR_EVENT_SIZE, GFP_KERNEL))
diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
index dae427e25d71..9f39bc074837 100644
--- a/drivers/media/rc/rc-main.c
+++ b/drivers/media/rc/rc-main.c
@@ -1810,7 +1810,7 @@ int rc_register_device(struct rc_dev *dev)
}
 
/* Ensure that the lirc kfifo is setup before we start the thread */
-   if (dev->driver_type != RC_DRIVER_SCANCODE) {
+   if (dev->allowed_protocols != RC_PROTO_BIT_CEC) {
rc = ir_lirc_register(dev);
if (rc < 0)
goto out_rx;
@@ -1831,7 +1831,7 @@ int rc_register_device(struct rc_dev *dev)
return 0;
 
 out_lirc:
-   if (dev->driver_type != RC_DRIVER_SCANCODE)
+   if (dev->allowed_protocols != RC_PROTO_BIT_CEC)
ir_lirc_unregister(dev);
 out_rx:
rc_free_rx_device(dev);
@@ -1892,7 +1892,7 @@ void rc_unregister_device(struct rc_dev *dev)
 * lirc device should be freed with dev->registered = false, so
 * that userspace polling will get notified.
 */
-   if (dev->driver_type != RC_DRIVER_SCANCODE)
+   if (dev->allowed_protocols != RC_PROTO_BIT_CEC)
ir_lirc_unregister(dev);
 
device_del(>dev);
-- 

[PATCH 23/28] media: lirc: implement reading scancode

2017-10-29 Thread Sean Young
This implements LIRC_MODE_SCANCODE reading from the lirc device. The
scancode can be read from the input device too, but with this interface
you get the rc protocol, keycode, toggle and repeat status in addition
to just the scancode.

int main()
{
int fd, mode, rc;
fd = open("/dev/lirc0", O_RDWR);

mode = LIRC_MODE_SCANCODE;
if (ioctl(fd, LIRC_SET_REC_MODE, )) {
// kernel too old or lirc does not support transmit
}
struct lirc_scancode scancode;
while (read(fd, , sizeof(scancode)) == sizeof(scancode)) {
printf("protocol:%d scancode:0x%x toggle:%d repeat:%d\n",
scancode.rc_proto, scancode.scancode,
!!(scancode.flags & LIRC_SCANCODE_FLAG_TOGGLE),
!!(scancode.flags & LIRC_SCANCODE_FLAG_REPEAT));
}
close(fd);
}

Signed-off-by: Sean Young 
---
 drivers/media/rc/ir-lirc-codec.c  | 102 +-
 drivers/media/rc/ir-mce_kbd-decoder.c |   5 ++
 drivers/media/rc/lirc_dev.c   |  13 +
 drivers/media/rc/rc-core-priv.h   |   3 +
 drivers/media/rc/rc-main.c|   7 +++
 include/media/rc-core.h   |   5 ++
 6 files changed, 120 insertions(+), 15 deletions(-)

diff --git a/drivers/media/rc/ir-lirc-codec.c b/drivers/media/rc/ir-lirc-codec.c
index 0e8e067390c3..6a439ef4293e 100644
--- a/drivers/media/rc/ir-lirc-codec.c
+++ b/drivers/media/rc/ir-lirc-codec.c
@@ -88,6 +88,21 @@ void ir_lirc_raw_event(struct rc_dev *dev, struct 
ir_raw_event ev)
wake_up_poll(>wait_poll, POLLIN | POLLRDNORM);
 }
 
+/**
+ * ir_lirc_scancode_event() - Send scancode data to lirc to be relayed to
+ * userspace
+ * @dev:   the struct rc_dev descriptor of the device
+ * @lscthe struct lirc_scancode describing the decoded scancode
+ */
+void ir_lirc_scancode_event(struct rc_dev *dev, struct lirc_scancode *lsc)
+{
+   lsc->timestamp = ktime_get_ns();
+
+   if (kfifo_put(>scancodes, *lsc))
+   wake_up_poll(>wait_poll, POLLIN | POLLRDNORM);
+}
+EXPORT_SYMBOL_GPL(ir_lirc_scancode_event);
+
 static int ir_lirc_open(struct inode *inode, struct file *file)
 {
struct rc_dev *dev = container_of(inode->i_cdev, struct rc_dev,
@@ -114,6 +129,8 @@ static int ir_lirc_open(struct inode *inode, struct file 
*file)
 
if (dev->driver_type == RC_DRIVER_IR_RAW)
kfifo_reset_out(>rawir);
+   if (dev->driver_type != RC_DRIVER_IR_RAW_TX)
+   kfifo_reset_out(>scancodes);
 
dev->lirc_open++;
file->private_data = dev;
@@ -288,7 +305,7 @@ static long ir_lirc_ioctl(struct file *filep, unsigned int 
cmd,
switch (cmd) {
case LIRC_GET_FEATURES:
if (dev->driver_type == RC_DRIVER_IR_RAW) {
-   val |= LIRC_CAN_REC_MODE2;
+   val |= LIRC_CAN_REC_MODE2 | LIRC_CAN_REC_SCANCODE;
if (dev->rx_resolution)
val |= LIRC_CAN_GET_REC_RESOLUTION;
}
@@ -323,15 +340,17 @@ static long ir_lirc_ioctl(struct file *filep, unsigned 
int cmd,
if (dev->driver_type == RC_DRIVER_IR_RAW_TX)
return -ENOTTY;
 
-   val = LIRC_MODE_MODE2;
+   val = dev->rec_mode;
break;
 
case LIRC_SET_REC_MODE:
if (dev->driver_type == RC_DRIVER_IR_RAW_TX)
return -ENOTTY;
 
-   if (val != LIRC_MODE_MODE2)
+   if (!(val == LIRC_MODE_MODE2 || val == LIRC_MODE_SCANCODE))
return -EINVAL;
+
+   dev->rec_mode = val;
return 0;
 
case LIRC_GET_SEND_MODE:
@@ -471,31 +490,31 @@ static unsigned int ir_lirc_poll(struct file *file,
 
poll_wait(file, >wait_poll, wait);
 
-   if (!rcdev->registered)
+   if (!rcdev->registered) {
events = POLLHUP | POLLERR;
-   else if (rcdev->driver_type == RC_DRIVER_IR_RAW &&
-!kfifo_is_empty(>rawir))
-   events = POLLIN | POLLRDNORM;
+   } else if (rcdev->driver_type != RC_DRIVER_IR_RAW_TX) {
+   if (rcdev->rec_mode == LIRC_MODE_SCANCODE &&
+   !kfifo_is_empty(>scancodes))
+   events = POLLIN | POLLRDNORM;
+
+   if (rcdev->rec_mode == LIRC_MODE_MODE2 &&
+   !kfifo_is_empty(>rawir))
+   events = POLLIN | POLLRDNORM;
+   }
 
return events;
 }
 
-static ssize_t ir_lirc_read(struct file *file, char __user *buffer,
-   size_t length, loff_t *ppos)
+static ssize_t ir_lirc_read_mode2(struct file *file, char __user *buffer,
+ size_t length)
 {
struct rc_dev *rcdev = file->private_data;
unsigned int copied;
int ret;
 
-   if 

[PATCH 24/28] media: rc: ensure lirc device receives nec repeats

2017-10-29 Thread Sean Young
The lirc device should get lirc repeats whether there is a keymap
match or not.

Signed-off-by: Sean Young 
---
 drivers/media/rc/rc-main.c | 27 +--
 1 file changed, 17 insertions(+), 10 deletions(-)

diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
index e9d6ce024cd2..dae427e25d71 100644
--- a/drivers/media/rc/rc-main.c
+++ b/drivers/media/rc/rc-main.c
@@ -662,19 +662,25 @@ void rc_repeat(struct rc_dev *dev)
 {
unsigned long flags;
unsigned int timeout = protocols[dev->last_protocol].repeat_period;
+   struct lirc_scancode sc = {
+   .scancode = dev->last_scancode, .rc_proto = dev->last_protocol,
+   .keycode = dev->keypressed ? dev->last_keycode : KEY_RESERVED,
+   .flags = LIRC_SCANCODE_FLAG_REPEAT |
+(dev->last_toggle ? LIRC_SCANCODE_FLAG_TOGGLE : 0)
+   };
 
-   spin_lock_irqsave(>keylock, flags);
+   ir_lirc_scancode_event(dev, );
 
-   if (!dev->keypressed)
-   goto out;
+   spin_lock_irqsave(>keylock, flags);
 
input_event(dev->input_dev, EV_MSC, MSC_SCAN, dev->last_scancode);
input_sync(dev->input_dev);
 
-   dev->keyup_jiffies = jiffies + msecs_to_jiffies(timeout);
-   mod_timer(>timer_keyup, dev->keyup_jiffies);
+   if (dev->keypressed) {
+   dev->keyup_jiffies = jiffies + msecs_to_jiffies(timeout);
+   mod_timer(>timer_keyup, dev->keyup_jiffies);
+   }
 
-out:
spin_unlock_irqrestore(>keylock, flags);
 }
 EXPORT_SYMBOL_GPL(rc_repeat);
@@ -710,13 +716,14 @@ static void ir_do_keydown(struct rc_dev *dev, enum 
rc_proto protocol,
 
input_event(dev->input_dev, EV_MSC, MSC_SCAN, scancode);
 
+   dev->last_protocol = protocol;
+   dev->last_scancode = scancode;
+   dev->last_toggle = toggle;
+   dev->last_keycode = keycode;
+
if (new_event && keycode != KEY_RESERVED) {
/* Register a keypress */
dev->keypressed = true;
-   dev->last_protocol = protocol;
-   dev->last_scancode = scancode;
-   dev->last_toggle = toggle;
-   dev->last_keycode = keycode;
 
IR_dprintk(1, "%s: key down event, key 0x%04x, protocol 0x%04x, 
scancode 0x%08x\n",
   dev->device_name, keycode, protocol, scancode);
-- 
2.13.6



[PATCH 22/28] media: lirc: remove last remnants of lirc kapi

2017-10-29 Thread Sean Young
rc-core has replaced the lirc kapi many years ago, and now with the last
driver ported to rc-core, we can finally remove it.

Note this has no effect on userspace.

All future IR drivers should use the rc-core api.

Signed-off-by: Sean Young 
---
 Documentation/media/kapi/rc-core.rst |   5 --
 drivers/media/rc/ir-lirc-codec.c |  41 +-
 drivers/media/rc/lirc_dev.c  | 145 ---
 drivers/media/rc/rc-core-priv.h  |   3 +
 drivers/media/rc/rc-main.c   |   1 -
 include/media/lirc_dev.h |  50 
 include/media/rc-core.h  |   8 +-
 7 files changed, 60 insertions(+), 193 deletions(-)
 delete mode 100644 include/media/lirc_dev.h

diff --git a/Documentation/media/kapi/rc-core.rst 
b/Documentation/media/kapi/rc-core.rst
index a45895886257..41c2256dbf6a 100644
--- a/Documentation/media/kapi/rc-core.rst
+++ b/Documentation/media/kapi/rc-core.rst
@@ -7,8 +7,3 @@ Remote Controller core
 .. kernel-doc:: include/media/rc-core.h
 
 .. kernel-doc:: include/media/rc-map.h
-
-LIRC
-
-
-.. kernel-doc:: include/media/lirc_dev.h
diff --git a/drivers/media/rc/ir-lirc-codec.c b/drivers/media/rc/ir-lirc-codec.c
index b3976263457a..0e8e067390c3 100644
--- a/drivers/media/rc/ir-lirc-codec.c
+++ b/drivers/media/rc/ir-lirc-codec.c
@@ -12,10 +12,10 @@
  *  GNU General Public License for more details.
  */
 
+#include 
 #include 
 #include 
 #include 
-#include 
 #include 
 #include "rc-core-priv.h"
 
@@ -90,8 +90,8 @@ void ir_lirc_raw_event(struct rc_dev *dev, struct 
ir_raw_event ev)
 
 static int ir_lirc_open(struct inode *inode, struct file *file)
 {
-   struct lirc_dev *d = container_of(inode->i_cdev, struct lirc_dev, cdev);
-   struct rc_dev *dev = d->rdev;
+   struct rc_dev *dev = container_of(inode->i_cdev, struct rc_dev,
+ lirc_cdev);
int retval;
 
retval = rc_open(dev);
@@ -521,7 +521,7 @@ static ssize_t ir_lirc_read(struct file *file, char __user 
*buffer,
return copied;
 }
 
-static const struct file_operations lirc_fops = {
+const struct file_operations lirc_fops = {
.owner  = THIS_MODULE,
.write  = ir_lirc_transmit_ir,
.unlocked_ioctl = ir_lirc_ioctl,
@@ -534,36 +534,3 @@ static const struct file_operations lirc_fops = {
.release= ir_lirc_close,
.llseek = no_llseek,
 };
-
-int ir_lirc_register(struct rc_dev *dev)
-{
-   struct lirc_dev *ldev;
-   int rc = -ENOMEM;
-
-   ldev = lirc_allocate_device();
-   if (!ldev)
-   return rc;
-
-   ldev->fops = _fops;
-   ldev->dev.parent = >dev;
-   ldev->rdev = dev;
-   ldev->owner = THIS_MODULE;
-
-   rc = lirc_register_device(ldev);
-   if (rc < 0)
-   goto out;
-
-   dev->send_mode = LIRC_MODE_PULSE;
-   dev->lirc_dev = ldev;
-   return 0;
-
-out:
-   lirc_free_device(ldev);
-   return rc;
-}
-
-void ir_lirc_unregister(struct rc_dev *dev)
-{
-   lirc_unregister_device(dev->lirc_dev);
-   dev->lirc_dev = NULL;
-}
diff --git a/drivers/media/rc/lirc_dev.c b/drivers/media/rc/lirc_dev.c
index 4ac74fd86fd4..155a4de249a0 100644
--- a/drivers/media/rc/lirc_dev.c
+++ b/drivers/media/rc/lirc_dev.c
@@ -18,24 +18,19 @@
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
 #include 
-#include 
-#include 
-#include 
 #include 
 #include 
-#include 
 #include 
+#include 
 
 #include "rc-core-priv.h"
 #include 
-#include 
 
 #define LOGHEAD"lirc_dev (%s[%d]): "
 
 static dev_t lirc_base_dev;
 
 /* Used to keep track of allocated lirc devices */
-#define LIRC_MAX_DEVICES 256
 static DEFINE_IDA(lirc_ida);
 
 /* Only used for sysfs but defined to void otherwise */
@@ -43,124 +38,80 @@ static struct class *lirc_class;
 
 static void lirc_release_device(struct device *ld)
 {
-   struct lirc_dev *d = container_of(ld, struct lirc_dev, dev);
-   struct rc_dev *rcdev = d->rdev;
+   struct rc_dev *rcdev = container_of(ld, struct rc_dev, lirc_dev);
 
if (rcdev->driver_type == RC_DRIVER_IR_RAW)
kfifo_free(>rawir);
 
-   kfree(d);
-   module_put(THIS_MODULE);
-   put_device(d->dev.parent);
-}
-
-struct lirc_dev *
-lirc_allocate_device(void)
-{
-   struct lirc_dev *d;
-
-   d = kzalloc(sizeof(*d), GFP_KERNEL);
-   if (d) {
-   device_initialize(>dev);
-   d->dev.class = lirc_class;
-   d->dev.release = lirc_release_device;
-   __module_get(THIS_MODULE);
-   }
-
-   return d;
-}
-EXPORT_SYMBOL(lirc_allocate_device);
-
-void lirc_free_device(struct lirc_dev *d)
-{
-   if (!d)
-   return;
-
-   put_device(>dev);
+   put_device(>dev);
 }
-EXPORT_SYMBOL(lirc_free_device);
 
-int lirc_register_device(struct lirc_dev *d)
+int ir_lirc_register(struct rc_dev *dev)
 {
-   struct rc_dev *rcdev = d->rdev;
-   int minor;

[PATCH 20/28] media: lirc: create rc-core open and close lirc functions

2017-10-29 Thread Sean Young
Replace the generic kernel lirc api with ones which use rc-core, further
reducing the lirc_dev members.

Signed-off-by: Sean Young 
---
 drivers/media/rc/ir-lirc-codec.c | 59 --
 drivers/media/rc/lirc_dev.c  | 68 ++--
 include/media/lirc_dev.h | 11 ---
 include/media/rc-core.h  |  2 ++
 4 files changed, 62 insertions(+), 78 deletions(-)

diff --git a/drivers/media/rc/ir-lirc-codec.c b/drivers/media/rc/ir-lirc-codec.c
index 9a780fac207c..94e7b309383b 100644
--- a/drivers/media/rc/ir-lirc-codec.c
+++ b/drivers/media/rc/ir-lirc-codec.c
@@ -88,6 +88,61 @@ void ir_lirc_raw_event(struct rc_dev *dev, struct 
ir_raw_event ev)
wake_up_poll(>wait_poll, POLLIN | POLLRDNORM);
 }
 
+static int ir_lirc_open(struct inode *inode, struct file *file)
+{
+   struct lirc_dev *d = container_of(inode->i_cdev, struct lirc_dev, cdev);
+   struct rc_dev *dev = d->rdev;
+   int retval;
+
+   retval = rc_open(dev);
+   if (retval)
+   return retval;
+
+   retval = mutex_lock_interruptible(>lock);
+   if (retval)
+   goto out_rc;
+
+   if (!dev->registered) {
+   retval = -ENODEV;
+   goto out_unlock;
+   }
+
+   if (dev->lirc_open) {
+   retval = -EBUSY;
+   goto out_unlock;
+   }
+
+   if (dev->driver_type == RC_DRIVER_IR_RAW)
+   kfifo_reset_out(>rawir);
+
+   dev->lirc_open++;
+   file->private_data = dev;
+
+   nonseekable_open(inode, file);
+   mutex_unlock(>lock);
+
+   return 0;
+
+out_unlock:
+   mutex_unlock(>lock);
+out_rc:
+   rc_close(dev);
+   return retval;
+}
+
+static int ir_lirc_close(struct inode *inode, struct file *file)
+{
+   struct rc_dev *dev = file->private_data;
+
+   mutex_lock(>lock);
+   dev->lirc_open--;
+   mutex_unlock(>lock);
+
+   rc_close(dev);
+
+   return 0;
+}
+
 static ssize_t ir_lirc_transmit_ir(struct file *file, const char __user *buf,
   size_t n, loff_t *ppos)
 {
@@ -475,8 +530,8 @@ static const struct file_operations lirc_fops = {
 #endif
.read   = ir_lirc_read,
.poll   = ir_lirc_poll,
-   .open   = lirc_dev_fop_open,
-   .release= lirc_dev_fop_close,
+   .open   = ir_lirc_open,
+   .release= ir_lirc_close,
.llseek = no_llseek,
 };
 
diff --git a/drivers/media/rc/lirc_dev.c b/drivers/media/rc/lirc_dev.c
index 22171267aa90..32124fb5c88e 100644
--- a/drivers/media/rc/lirc_dev.c
+++ b/drivers/media/rc/lirc_dev.c
@@ -61,7 +61,6 @@ lirc_allocate_device(void)
 
d = kzalloc(sizeof(*d), GFP_KERNEL);
if (d) {
-   mutex_init(>mutex);
device_initialize(>dev);
d->dev.class = lirc_class;
d->dev.release = lirc_release_device;
@@ -150,15 +149,15 @@ void lirc_unregister_device(struct lirc_dev *d)
dev_dbg(>dev, "lirc_dev: driver %s unregistered from minor = %d\n",
d->name, d->minor);
 
-   mutex_lock(>mutex);
+   mutex_lock(>lock);
 
-   if (d->open) {
+   if (rcdev->lirc_open) {
dev_dbg(>dev, LOGHEAD "releasing opened driver\n",
d->name, d->minor);
wake_up_poll(>wait_poll, POLLHUP);
}
 
-   mutex_unlock(>mutex);
+   mutex_unlock(>lock);
 
cdev_device_del(>cdev, >dev);
ida_simple_remove(_ida, d->minor);
@@ -166,67 +165,6 @@ void lirc_unregister_device(struct lirc_dev *d)
 }
 EXPORT_SYMBOL(lirc_unregister_device);
 
-int lirc_dev_fop_open(struct inode *inode, struct file *file)
-{
-   struct lirc_dev *d = container_of(inode->i_cdev, struct lirc_dev, cdev);
-   struct rc_dev *rcdev = d->rdev;
-   int retval;
-
-   dev_dbg(>dev, LOGHEAD "open called\n", d->name, d->minor);
-
-   retval = mutex_lock_interruptible(>mutex);
-   if (retval)
-   return retval;
-
-   if (!rcdev->registered) {
-   retval = -ENODEV;
-   goto out;
-   }
-
-   if (d->open) {
-   retval = -EBUSY;
-   goto out;
-   }
-
-   if (d->rdev) {
-   retval = rc_open(d->rdev);
-   if (retval)
-   goto out;
-   }
-
-   if (rcdev->driver_type == RC_DRIVER_IR_RAW)
-   kfifo_reset_out(>rawir);
-
-   d->open++;
-
-   file->private_data = d->rdev;
-   nonseekable_open(inode, file);
-   mutex_unlock(>mutex);
-
-   return 0;
-
-out:
-   mutex_unlock(>mutex);
-   return retval;
-}
-EXPORT_SYMBOL(lirc_dev_fop_open);
-
-int lirc_dev_fop_close(struct inode *inode, struct file *file)
-{
-   struct rc_dev *rcdev = file->private_data;
-   struct lirc_dev *d = rcdev->lirc_dev;
-
-   mutex_lock(>mutex);
-
-   rc_close(rcdev);
-

[PATCH 21/28] media: lirc: remove name from lirc_dev

2017-10-29 Thread Sean Young
This is a duplicate of rcdev->driver_name.

Signed-off-by: Sean Young 
---
 Documentation/media/uapi/rc/lirc-dev-intro.rst | 2 +-
 drivers/media/rc/ir-lirc-codec.c   | 2 --
 drivers/media/rc/lirc_dev.c| 9 +++--
 include/media/lirc_dev.h   | 2 --
 4 files changed, 4 insertions(+), 11 deletions(-)

diff --git a/Documentation/media/uapi/rc/lirc-dev-intro.rst 
b/Documentation/media/uapi/rc/lirc-dev-intro.rst
index 3cacf9aeac40..a3fa3c1ef169 100644
--- a/Documentation/media/uapi/rc/lirc-dev-intro.rst
+++ b/Documentation/media/uapi/rc/lirc-dev-intro.rst
@@ -18,7 +18,7 @@ Example dmesg output upon a driver registering w/LIRC:
 
 $ dmesg |grep lirc_dev
 lirc_dev: IR Remote Control driver registered, major 248
-rc rc0: lirc_dev: driver ir-lirc-codec (mceusb) registered at minor = 0
+rc rc0: lirc_dev: driver mceusb registered at minor = 0
 
 What you should see for a chardev:
 
diff --git a/drivers/media/rc/ir-lirc-codec.c b/drivers/media/rc/ir-lirc-codec.c
index 94e7b309383b..b3976263457a 100644
--- a/drivers/media/rc/ir-lirc-codec.c
+++ b/drivers/media/rc/ir-lirc-codec.c
@@ -544,8 +544,6 @@ int ir_lirc_register(struct rc_dev *dev)
if (!ldev)
return rc;
 
-   snprintf(ldev->name, sizeof(ldev->name), "ir-lirc-codec (%s)",
-dev->driver_name);
ldev->fops = _fops;
ldev->dev.parent = >dev;
ldev->rdev = dev;
diff --git a/drivers/media/rc/lirc_dev.c b/drivers/media/rc/lirc_dev.c
index 32124fb5c88e..4ac74fd86fd4 100644
--- a/drivers/media/rc/lirc_dev.c
+++ b/drivers/media/rc/lirc_dev.c
@@ -101,9 +101,6 @@ int lirc_register_device(struct lirc_dev *d)
return -EINVAL;
}
 
-   /* some safety check 8-) */
-   d->name[sizeof(d->name) - 1] = '\0';
-
if (rcdev->driver_type == RC_DRIVER_IR_RAW) {
if (kfifo_alloc(>rawir, MAX_IR_EVENT_SIZE, GFP_KERNEL))
return -ENOMEM;
@@ -131,7 +128,7 @@ int lirc_register_device(struct lirc_dev *d)
get_device(d->dev.parent);
 
dev_info(>dev, "lirc_dev: driver %s registered at minor = %d\n",
-d->name, d->minor);
+rcdev->driver_name, d->minor);
 
return 0;
 }
@@ -147,13 +144,13 @@ void lirc_unregister_device(struct lirc_dev *d)
rcdev = d->rdev;
 
dev_dbg(>dev, "lirc_dev: driver %s unregistered from minor = %d\n",
-   d->name, d->minor);
+   rcdev->driver_name, d->minor);
 
mutex_lock(>lock);
 
if (rcdev->lirc_open) {
dev_dbg(>dev, LOGHEAD "releasing opened driver\n",
-   d->name, d->minor);
+   rcdev->driver_name, d->minor);
wake_up_poll(>wait_poll, POLLHUP);
}
 
diff --git a/include/media/lirc_dev.h b/include/media/lirc_dev.h
index b45af81b4633..d12e1d1c3d67 100644
--- a/include/media/lirc_dev.h
+++ b/include/media/lirc_dev.h
@@ -21,7 +21,6 @@
 /**
  * struct lirc_dev - represents a LIRC device
  *
- * @name:  used for logging
  * @minor: the minor device (/dev/lircX) number for the device
  * @rdev:   rc_dev associated with the device
  * @fops:   file_operations for the device
@@ -30,7 +29,6 @@
  * @cdev:   cdev assigned to the device
  */
 struct lirc_dev {
-   char name[40];
unsigned int minor;
 
struct rc_dev *rdev;
-- 
2.13.6



[PATCH 12/28] media: rc: auto load encoder if necessary

2017-10-29 Thread Sean Young
When sending scancodes, load the encoder if we need it.

Signed-off-by: Sean Young 
---
 drivers/media/rc/rc-core-priv.h | 1 +
 drivers/media/rc/rc-ir-raw.c| 2 ++
 drivers/media/rc/rc-main.c  | 2 +-
 3 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/media/rc/rc-core-priv.h b/drivers/media/rc/rc-core-priv.h
index 3cf09408df6c..d29b1b1ef4b7 100644
--- a/drivers/media/rc/rc-core-priv.h
+++ b/drivers/media/rc/rc-core-priv.h
@@ -271,6 +271,7 @@ void ir_raw_event_free(struct rc_dev *dev);
 void ir_raw_event_unregister(struct rc_dev *dev);
 int ir_raw_handler_register(struct ir_raw_handler *ir_raw_handler);
 void ir_raw_handler_unregister(struct ir_raw_handler *ir_raw_handler);
+void ir_raw_load_modules(u64 *protocols);
 void ir_raw_init(void);
 
 /*
diff --git a/drivers/media/rc/rc-ir-raw.c b/drivers/media/rc/rc-ir-raw.c
index 0814e08a280b..b84201cb012a 100644
--- a/drivers/media/rc/rc-ir-raw.c
+++ b/drivers/media/rc/rc-ir-raw.c
@@ -457,6 +457,8 @@ int ir_raw_encode_scancode(enum rc_proto protocol, u32 
scancode,
int ret = -EINVAL;
u64 mask = 1ULL << protocol;
 
+   ir_raw_load_modules();
+
mutex_lock(_raw_handler_lock);
list_for_each_entry(handler, _raw_handler_list, list) {
if (handler->protocols & mask && handler->encode) {
diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
index cb78e5702bef..62102b3ef5aa 100644
--- a/drivers/media/rc/rc-main.c
+++ b/drivers/media/rc/rc-main.c
@@ -1081,7 +1081,7 @@ static int parse_protocol_change(u64 *protocols, const 
char *buf)
return count;
 }
 
-static void ir_raw_load_modules(u64 *protocols)
+void ir_raw_load_modules(u64 *protocols)
 {
u64 available;
int i, ret;
-- 
2.13.6



[PATCH 08/28] media: MAINTAINERS: remove lirc staging area

2017-10-29 Thread Sean Young
Now that lirc is no longer in the staging area, remove the entry.

Signed-off-by: Sean Young 
---
 MAINTAINERS | 6 --
 1 file changed, 6 deletions(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index adbf69306e9e..59c061d3d61a 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -12712,12 +12712,6 @@ S: Odd Fixes
 F: Documentation/devicetree/bindings/staging/iio/
 F: drivers/staging/iio/
 
-STAGING - LIRC (LINUX INFRARED REMOTE CONTROL) DRIVERS
-M: Jarod Wilson 
-W: http://www.lirc.org/
-S: Odd Fixes
-F: drivers/staging/media/lirc/
-
 STAGING - LUSTRE PARALLEL FILESYSTEM
 M: Oleg Drokin 
 M: Andreas Dilger 
-- 
2.13.6



[PATCH 16/28] media: lirc: merge lirc_dev_fop_ioctl and ir_lirc_ioctl

2017-10-29 Thread Sean Young
Calculate lirc features when necessary, and add LIRC_{S,G}ET_REC_MODE
cases to ir_lirc_ioctl.

This makes lirc_dev_fop_ioctl() unnecessary since all cases are
already handled by ir_lirc_ioctl().

Signed-off-by: Sean Young 
---
 drivers/media/rc/ir-lirc-codec.c | 79 
 drivers/media/rc/lirc_dev.c  | 62 ++-
 include/media/lirc_dev.h |  4 --
 3 files changed, 50 insertions(+), 95 deletions(-)

diff --git a/drivers/media/rc/ir-lirc-codec.c b/drivers/media/rc/ir-lirc-codec.c
index 1ed69c9e64bf..f933e7617882 100644
--- a/drivers/media/rc/ir-lirc-codec.c
+++ b/drivers/media/rc/ir-lirc-codec.c
@@ -231,8 +231,54 @@ static long ir_lirc_ioctl(struct file *filep, unsigned int 
cmd,
}
 
switch (cmd) {
+   case LIRC_GET_FEATURES:
+   if (dev->driver_type == RC_DRIVER_IR_RAW) {
+   val |= LIRC_CAN_REC_MODE2;
+   if (dev->rx_resolution)
+   val |= LIRC_CAN_GET_REC_RESOLUTION;
+   }
+
+   if (dev->tx_ir) {
+   val |= LIRC_CAN_SEND_PULSE | LIRC_CAN_SEND_SCANCODE;
+   if (dev->s_tx_mask)
+   val |= LIRC_CAN_SET_TRANSMITTER_MASK;
+   if (dev->s_tx_carrier)
+   val |= LIRC_CAN_SET_SEND_CARRIER;
+   if (dev->s_tx_duty_cycle)
+   val |= LIRC_CAN_SET_SEND_DUTY_CYCLE;
+   }
+
+   if (dev->s_rx_carrier_range)
+   val |= LIRC_CAN_SET_REC_CARRIER |
+   LIRC_CAN_SET_REC_CARRIER_RANGE;
+
+   if (dev->s_learning_mode)
+   val |= LIRC_CAN_USE_WIDEBAND_RECEIVER;
+
+   if (dev->s_carrier_report)
+   val |= LIRC_CAN_MEASURE_CARRIER;
+
+   if (dev->max_timeout)
+   val |= LIRC_CAN_SET_REC_TIMEOUT;
+
+   break;
 
/* mode support */
+   case LIRC_GET_REC_MODE:
+   if (dev->driver_type == RC_DRIVER_IR_RAW_TX)
+   return -ENOTTY;
+
+   val = LIRC_MODE_MODE2;
+   break;
+
+   case LIRC_SET_REC_MODE:
+   if (dev->driver_type == RC_DRIVER_IR_RAW_TX)
+   return -ENOTTY;
+
+   if (val != LIRC_MODE_MODE2)
+   return -EINVAL;
+   return 0;
+
case LIRC_GET_SEND_MODE:
if (!dev->tx_ir)
return -ENOTTY;
@@ -353,7 +399,7 @@ static long ir_lirc_ioctl(struct file *filep, unsigned int 
cmd,
break;
 
default:
-   return lirc_dev_fop_ioctl(filep, cmd, arg);
+   return -ENOTTY;
}
 
if (_IOC_DIR(cmd) & _IOC_READ)
@@ -380,44 +426,13 @@ int ir_lirc_register(struct rc_dev *dev)
 {
struct lirc_dev *ldev;
int rc = -ENOMEM;
-   unsigned long features = 0;
 
ldev = lirc_allocate_device();
if (!ldev)
return rc;
 
-   if (dev->driver_type != RC_DRIVER_IR_RAW_TX) {
-   features |= LIRC_CAN_REC_MODE2;
-   if (dev->rx_resolution)
-   features |= LIRC_CAN_GET_REC_RESOLUTION;
-   }
-
-   if (dev->tx_ir) {
-   features |= LIRC_CAN_SEND_PULSE | LIRC_CAN_SEND_SCANCODE;
-   if (dev->s_tx_mask)
-   features |= LIRC_CAN_SET_TRANSMITTER_MASK;
-   if (dev->s_tx_carrier)
-   features |= LIRC_CAN_SET_SEND_CARRIER;
-   if (dev->s_tx_duty_cycle)
-   features |= LIRC_CAN_SET_SEND_DUTY_CYCLE;
-   }
-
-   if (dev->s_rx_carrier_range)
-   features |= LIRC_CAN_SET_REC_CARRIER |
-   LIRC_CAN_SET_REC_CARRIER_RANGE;
-
-   if (dev->s_learning_mode)
-   features |= LIRC_CAN_USE_WIDEBAND_RECEIVER;
-
-   if (dev->s_carrier_report)
-   features |= LIRC_CAN_MEASURE_CARRIER;
-
-   if (dev->max_timeout)
-   features |= LIRC_CAN_SET_REC_TIMEOUT;
-
snprintf(ldev->name, sizeof(ldev->name), "ir-lirc-codec (%s)",
 dev->driver_name);
-   ldev->features = features;
ldev->buf = NULL;
ldev->chunk_size = sizeof(int);
ldev->buffer_size = LIRCBUF_SIZE;
diff --git a/drivers/media/rc/lirc_dev.c b/drivers/media/rc/lirc_dev.c
index 3cc95deaa84e..95058ea01e62 100644
--- a/drivers/media/rc/lirc_dev.c
+++ b/drivers/media/rc/lirc_dev.c
@@ -109,6 +109,7 @@ EXPORT_SYMBOL(lirc_free_device);
 
 int lirc_register_device(struct lirc_dev *d)
 {
+   struct rc_dev *rcdev = d->rdev;
int minor;
int err;
 
@@ -146,7 +147,7 @@ int lirc_register_device(struct lirc_dev *d)
/* some safety check 8-) */
d->name[sizeof(d->name) - 1] = '\0';
 
-   if 

[PATCH 17/28] media: lirc: use kfifo rather than lirc_buffer for raw IR

2017-10-29 Thread Sean Young
Since the only mode lirc devices can handle is raw IR, handle this
in a plain kfifo.

Remove lirc_buffer since this is no longer needed.

Signed-off-by: Sean Young 
---
 drivers/media/rc/ir-lirc-codec.c |  79 +---
 drivers/media/rc/lirc_dev.c  | 199 ---
 include/media/lirc_dev.h | 109 -
 include/media/rc-core.h  |   4 +
 4 files changed, 85 insertions(+), 306 deletions(-)

diff --git a/drivers/media/rc/ir-lirc-codec.c b/drivers/media/rc/ir-lirc-codec.c
index f933e7617882..1ac7a5aa0437 100644
--- a/drivers/media/rc/ir-lirc-codec.c
+++ b/drivers/media/rc/ir-lirc-codec.c
@@ -66,8 +66,6 @@ void ir_lirc_raw_event(struct rc_dev *dev, struct 
ir_raw_event ev)
} else {
 
if (dev->gap) {
-   int gap_sample;
-
dev->gap_duration += ktime_to_ns(ktime_sub(ktime_get(),
 dev->gap_start));
 
@@ -76,9 +74,7 @@ void ir_lirc_raw_event(struct rc_dev *dev, struct 
ir_raw_event ev)
dev->gap_duration = min_t(u64, dev->gap_duration,
  LIRC_VALUE_MASK);
 
-   gap_sample = LIRC_SPACE(dev->gap_duration);
-   lirc_buffer_write(dev->lirc_dev->buf,
- (unsigned char *)_sample);
+   kfifo_put(>rawir, LIRC_SPACE(dev->gap_duration));
dev->gap = false;
}
 
@@ -88,10 +84,8 @@ void ir_lirc_raw_event(struct rc_dev *dev, struct 
ir_raw_event ev)
   TO_US(ev.duration), TO_STR(ev.pulse));
}
 
-   lirc_buffer_write(dev->lirc_dev->buf,
- (unsigned char *) );
-
-   wake_up(>lirc_dev->buf->wait_poll);
+   kfifo_put(>rawir, sample);
+   wake_up_poll(>wait_poll, POLLIN | POLLRDNORM);
 }
 
 static ssize_t ir_lirc_transmit_ir(struct file *file, const char __user *buf,
@@ -408,6 +402,66 @@ static long ir_lirc_ioctl(struct file *filep, unsigned int 
cmd,
return ret;
 }
 
+static unsigned int ir_lirc_poll(struct file *file,
+struct poll_table_struct *wait)
+{
+   struct rc_dev *rcdev = file->private_data;
+   struct lirc_dev *d = rcdev->lirc_dev;
+   unsigned int events = 0;
+
+   poll_wait(file, >wait_poll, wait);
+
+   if (!d->attached)
+   events = POLLHUP | POLLERR;
+   else if (rcdev->driver_type == RC_DRIVER_IR_RAW &&
+!kfifo_is_empty(>rawir))
+   events = POLLIN | POLLRDNORM;
+
+   return events;
+}
+
+static ssize_t ir_lirc_read(struct file *file, char __user *buffer,
+   size_t length, loff_t *ppos)
+{
+   struct rc_dev *rcdev = file->private_data;
+   struct lirc_dev *d = rcdev->lirc_dev;
+   unsigned int copied;
+   int ret;
+
+   if (rcdev->driver_type == RC_DRIVER_IR_RAW_TX)
+   return -EINVAL;
+
+   if (length < sizeof(unsigned int) || length % sizeof(unsigned int))
+   return -EINVAL;
+
+   if (!d->attached)
+   return -ENODEV;
+
+   do {
+   if (kfifo_is_empty(>rawir)) {
+   if (file->f_flags & O_NONBLOCK)
+   return -EAGAIN;
+
+   ret = wait_event_interruptible(rcdev->wait_poll,
+   !kfifo_is_empty(>rawir) ||
+   !d->attached);
+   if (ret)
+   return ret;
+   }
+
+   if (!d->attached)
+   return -ENODEV;
+
+   mutex_lock(>lock);
+   ret = kfifo_to_user(>rawir, buffer, length, );
+   mutex_unlock(>lock);
+   if (ret)
+   return ret;
+   } while (copied == 0);
+
+   return copied;
+}
+
 static const struct file_operations lirc_fops = {
.owner  = THIS_MODULE,
.write  = ir_lirc_transmit_ir,
@@ -415,8 +469,8 @@ static const struct file_operations lirc_fops = {
 #ifdef CONFIG_COMPAT
.compat_ioctl   = ir_lirc_ioctl,
 #endif
-   .read   = lirc_dev_fop_read,
-   .poll   = lirc_dev_fop_poll,
+   .read   = ir_lirc_read,
+   .poll   = ir_lirc_poll,
.open   = lirc_dev_fop_open,
.release= lirc_dev_fop_close,
.llseek = no_llseek,
@@ -433,9 +487,6 @@ int ir_lirc_register(struct rc_dev *dev)
 
snprintf(ldev->name, sizeof(ldev->name), "ir-lirc-codec (%s)",
 dev->driver_name);
-   ldev->buf = NULL;
-   ldev->chunk_size = sizeof(int);
-   ldev->buffer_size = LIRCBUF_SIZE;
ldev->fops = _fops;
ldev->dev.parent = >dev;
ldev->rdev = dev;
diff --git 

[PATCH 11/28] media: lirc: use the correct carrier for scancode transmit

2017-10-29 Thread Sean Young
If the lirc device supports it, set the carrier for the protocol.

Signed-off-by: Sean Young 
---
 drivers/media/rc/ir-jvc-decoder.c |  1 +
 drivers/media/rc/ir-lirc-codec.c  | 29 ++---
 drivers/media/rc/ir-mce_kbd-decoder.c |  1 +
 drivers/media/rc/ir-nec-decoder.c |  1 +
 drivers/media/rc/ir-rc5-decoder.c |  1 +
 drivers/media/rc/ir-rc6-decoder.c |  1 +
 drivers/media/rc/ir-sanyo-decoder.c   |  1 +
 drivers/media/rc/ir-sharp-decoder.c   |  1 +
 drivers/media/rc/ir-sony-decoder.c|  1 +
 drivers/media/rc/rc-core-priv.h   |  1 +
 drivers/media/rc/rc-ir-raw.c  | 30 ++
 include/media/rc-core.h   |  1 +
 12 files changed, 58 insertions(+), 11 deletions(-)

diff --git a/drivers/media/rc/ir-jvc-decoder.c 
b/drivers/media/rc/ir-jvc-decoder.c
index e2bd68c42edf..2ae20dfc0e61 100644
--- a/drivers/media/rc/ir-jvc-decoder.c
+++ b/drivers/media/rc/ir-jvc-decoder.c
@@ -212,6 +212,7 @@ static struct ir_raw_handler jvc_handler = {
.protocols  = RC_PROTO_BIT_JVC,
.decode = ir_jvc_decode,
.encode = ir_jvc_encode,
+   .carrier= 38000,
 };
 
 static int __init ir_jvc_decode_init(void)
diff --git a/drivers/media/rc/ir-lirc-codec.c b/drivers/media/rc/ir-lirc-codec.c
index 73e4ff3cb023..d733179e2a94 100644
--- a/drivers/media/rc/ir-lirc-codec.c
+++ b/drivers/media/rc/ir-lirc-codec.c
@@ -122,6 +122,17 @@ static ssize_t ir_lirc_transmit_ir(struct file *file, 
const char __user *buf,
if (!lirc)
return -EFAULT;
 
+   dev = lirc->dev;
+   if (!dev) {
+   ret = -EFAULT;
+   goto out;
+   }
+
+   if (!dev->tx_ir) {
+   ret = -EINVAL;
+   goto out;
+   }
+
if (lirc->send_mode == LIRC_MODE_SCANCODE) {
struct lirc_scancode scan;
 
@@ -154,6 +165,13 @@ static ssize_t ir_lirc_transmit_ir(struct file *file, 
const char __user *buf,
for (i = 0; i < count; i++)
/* Convert from NS to US */
txbuf[i] = DIV_ROUND_UP(raw[i].duration, 1000);
+
+   if (dev->s_tx_carrier) {
+   int carrier = ir_raw_encode_carrier(scan.rc_proto);
+
+   if (carrier > 0)
+   dev->s_tx_carrier(dev, carrier);
+   }
} else {
if (n < sizeof(unsigned int) || n % sizeof(unsigned int))
return -EINVAL;
@@ -167,17 +185,6 @@ static ssize_t ir_lirc_transmit_ir(struct file *file, 
const char __user *buf,
return PTR_ERR(txbuf);
}
 
-   dev = lirc->dev;
-   if (!dev) {
-   ret = -EFAULT;
-   goto out;
-   }
-
-   if (!dev->tx_ir) {
-   ret = -EINVAL;
-   goto out;
-   }
-
for (i = 0; i < count; i++) {
if (txbuf[i] > IR_MAX_DURATION / 1000 - duration || !txbuf[i]) {
ret = -EINVAL;
diff --git a/drivers/media/rc/ir-mce_kbd-decoder.c 
b/drivers/media/rc/ir-mce_kbd-decoder.c
index 7c572a643656..efa3b735dcc4 100644
--- a/drivers/media/rc/ir-mce_kbd-decoder.c
+++ b/drivers/media/rc/ir-mce_kbd-decoder.c
@@ -474,6 +474,7 @@ static struct ir_raw_handler mce_kbd_handler = {
.encode = ir_mce_kbd_encode,
.raw_register   = ir_mce_kbd_register,
.raw_unregister = ir_mce_kbd_unregister,
+   .carrier= 36000,
 };
 
 static int __init ir_mce_kbd_decode_init(void)
diff --git a/drivers/media/rc/ir-nec-decoder.c 
b/drivers/media/rc/ir-nec-decoder.c
index a95d09acc22a..4ace5648866d 100644
--- a/drivers/media/rc/ir-nec-decoder.c
+++ b/drivers/media/rc/ir-nec-decoder.c
@@ -264,6 +264,7 @@ static struct ir_raw_handler nec_handler = {
RC_PROTO_BIT_NEC32,
.decode = ir_nec_decode,
.encode = ir_nec_encode,
+   .carrier= 38000,
 };
 
 static int __init ir_nec_decode_init(void)
diff --git a/drivers/media/rc/ir-rc5-decoder.c 
b/drivers/media/rc/ir-rc5-decoder.c
index 1292f534de43..cd1c4ee5fcd4 100644
--- a/drivers/media/rc/ir-rc5-decoder.c
+++ b/drivers/media/rc/ir-rc5-decoder.c
@@ -282,6 +282,7 @@ static struct ir_raw_handler rc5_handler = {
RC_PROTO_BIT_RC5_SZ,
.decode = ir_rc5_decode,
.encode = ir_rc5_encode,
+   .carrier= 36000,
 };
 
 static int __init ir_rc5_decode_init(void)
diff --git a/drivers/media/rc/ir-rc6-decoder.c 
b/drivers/media/rc/ir-rc6-decoder.c
index 5d0d2fe3b7a7..665025303c28 100644
--- a/drivers/media/rc/ir-rc6-decoder.c
+++ b/drivers/media/rc/ir-rc6-decoder.c
@@ -408,6 +408,7 @@ static struct ir_raw_handler rc6_handler = {
  RC_PROTO_BIT_RC6_MCE,
.decode = ir_rc6_decode,
.encode   

[PATCH 09/28] media: lirc: remove LIRCCODE and LIRC_GET_LENGTH

2017-10-29 Thread Sean Young
LIRCCODE is a lirc mode where a driver produces driver-dependent
codes for receive and transmit. No driver uses this any more. The
LIRC_GET_LENGTH ioctl was used for this mode only.

Signed-off-by: Sean Young 
---
 Documentation/media/lirc.h.rst.exceptions  |  5 +++
 Documentation/media/uapi/rc/lirc-dev-intro.rst | 15 
 Documentation/media/uapi/rc/lirc-func.rst  |  1 -
 Documentation/media/uapi/rc/lirc-get-features.rst  |  7 +---
 Documentation/media/uapi/rc/lirc-get-length.rst| 44 --
 Documentation/media/uapi/rc/lirc-get-rec-mode.rst  |  4 +-
 Documentation/media/uapi/rc/lirc-get-send-mode.rst |  3 +-
 drivers/media/rc/ir-lirc-codec.c   |  1 -
 drivers/media/rc/lirc_dev.c| 12 --
 include/media/lirc_dev.h   |  4 --
 10 files changed, 9 insertions(+), 87 deletions(-)
 delete mode 100644 Documentation/media/uapi/rc/lirc-get-length.rst

diff --git a/Documentation/media/lirc.h.rst.exceptions 
b/Documentation/media/lirc.h.rst.exceptions
index c130617a9986..63ba1d341905 100644
--- a/Documentation/media/lirc.h.rst.exceptions
+++ b/Documentation/media/lirc.h.rst.exceptions
@@ -28,6 +28,10 @@ ignore define LIRC_CAN_SEND_MASK
 ignore define LIRC_CAN_REC_MASK
 ignore define LIRC_CAN_SET_REC_DUTY_CYCLE
 
+# Obsolete ioctls
+
+ignore ioctl LIRC_GET_LENGTH
+
 # Undocumented macros
 
 ignore define PULSE_BIT
@@ -40,3 +44,4 @@ ignore define LIRC_VALUE_MASK
 ignore define LIRC_MODE2_MASK
 
 ignore define LIRC_MODE_RAW
+ignore define LIRC_MODE_LIRCCODE
diff --git a/Documentation/media/uapi/rc/lirc-dev-intro.rst 
b/Documentation/media/uapi/rc/lirc-dev-intro.rst
index d1936eeb9ce0..3cacf9aeac40 100644
--- a/Documentation/media/uapi/rc/lirc-dev-intro.rst
+++ b/Documentation/media/uapi/rc/lirc-dev-intro.rst
@@ -72,21 +72,6 @@ on the following table.
 this packet will be sent, with the number of microseconds with
 no IR.
 
-.. _lirc-mode-lirccode:
-
-``LIRC_MODE_LIRCCODE``
-
-This mode can be used for IR receive and send.
-
-The IR signal is decoded internally by the receiver, or encoded by the
-transmitter. The LIRC interface represents the scancode as byte string,
-which might not be a u32, it can be any length. The value is entirely
-driver dependent. This mode is used by some older lirc drivers.
-
-The length of each code depends on the driver, which can be retrieved
-with :ref:`lirc_get_length`. This length is used both
-for transmitting and receiving IR.
-
 .. _lirc-mode-pulse:
 
 ``LIRC_MODE_PULSE``
diff --git a/Documentation/media/uapi/rc/lirc-func.rst 
b/Documentation/media/uapi/rc/lirc-func.rst
index 9b5a772ec96c..ddb4620de294 100644
--- a/Documentation/media/uapi/rc/lirc-func.rst
+++ b/Documentation/media/uapi/rc/lirc-func.rst
@@ -18,7 +18,6 @@ LIRC Function Reference
 lirc-set-send-duty-cycle
 lirc-get-timeout
 lirc-set-rec-timeout
-lirc-get-length
 lirc-set-rec-carrier
 lirc-set-rec-carrier-range
 lirc-set-send-carrier
diff --git a/Documentation/media/uapi/rc/lirc-get-features.rst 
b/Documentation/media/uapi/rc/lirc-get-features.rst
index 64f89a4f9d9c..50c2c26d8e89 100644
--- a/Documentation/media/uapi/rc/lirc-get-features.rst
+++ b/Documentation/media/uapi/rc/lirc-get-features.rst
@@ -62,8 +62,7 @@ LIRC features
 
 ``LIRC_CAN_REC_LIRCCODE``
 
-The driver is capable of receiving using
-:ref:`LIRC_MODE_LIRCCODE `.
+Unused. Kept just to avoid breaking uAPI.
 
 .. _LIRC-CAN-SET-SEND-CARRIER:
 
@@ -170,9 +169,7 @@ LIRC features
 
 ``LIRC_CAN_SEND_LIRCCODE``
 
-The driver supports sending (also called as IR blasting or IR TX) using
-:ref:`LIRC_MODE_LIRCCODE `.
-
+Unused. Kept just to avoid breaking uAPI.
 
 Return Value
 
diff --git a/Documentation/media/uapi/rc/lirc-get-length.rst 
b/Documentation/media/uapi/rc/lirc-get-length.rst
deleted file mode 100644
index 3990af5de0e9..
--- a/Documentation/media/uapi/rc/lirc-get-length.rst
+++ /dev/null
@@ -1,44 +0,0 @@
-.. -*- coding: utf-8; mode: rst -*-
-
-.. _lirc_get_length:
-
-*
-ioctl LIRC_GET_LENGTH
-*
-
-Name
-
-
-LIRC_GET_LENGTH - Retrieves the code length in bits.
-
-Synopsis
-
-
-.. c:function:: int ioctl( int fd, LIRC_GET_LENGTH, __u32 *length )
-:name: LIRC_GET_LENGTH
-
-Arguments
-=
-
-``fd``
-File descriptor returned by open().
-
-``length``
-length, in bits
-
-
-Description
-===
-
-Retrieves the code length in bits (only for
-:ref:`LIRC_MODE_LIRCCODE `).
-Reads on the device must be done in blocks matching the bit count.
-The bit could should be rounded up so that it matches full bytes.
-
-
-Return Value
-
-
-On success 0 is returned, on error -1 and the ``errno`` variable is set
-appropriately. The generic error codes are described at the
-:ref:`Generic Error Codes ` chapter.
diff --git 

[PATCH 13/28] media: lirc: lirc interface should not be a raw decoder

2017-10-29 Thread Sean Young
The lirc user interface exists as a raw decoder, which does not make
much sense for transmit-only devices.

In addition, we want to have lirc char devices for devices which do not
use raw IR, i.e. scancode only devices.

Note that rc-code, lirc_dev, ir-lirc-codec are now calling functions of
each other, so they've been merged into one module rc-core to avoid
circular dependencies.

Since ir-lirc-codec no longer exists as separate codec module, there is no
need for RC_DRIVER_IR_RAW_TX type drivers to call ir_raw_event_register().

Signed-off-by: Sean Young 
---
 drivers/media/rc/Kconfig  |  29 ++-
 drivers/media/rc/Makefile |   5 +-
 drivers/media/rc/ir-lirc-codec.c  | 137 +-
 drivers/media/rc/ir-mce_kbd-decoder.c |   6 --
 drivers/media/rc/lirc_dev.c   |  47 
 drivers/media/rc/rc-core-priv.h   |  45 ---
 drivers/media/rc/rc-ir-raw.c  |  24 ++
 drivers/media/rc/rc-main.c|  52 ++---
 include/media/lirc_dev.h  |  10 ---
 include/media/rc-core.h   |  33 
 10 files changed, 144 insertions(+), 244 deletions(-)

diff --git a/drivers/media/rc/Kconfig b/drivers/media/rc/Kconfig
index afb3456d4e20..0f863822889e 100644
--- a/drivers/media/rc/Kconfig
+++ b/drivers/media/rc/Kconfig
@@ -16,34 +16,21 @@ menuconfig RC_CORE
 if RC_CORE
 source "drivers/media/rc/keymaps/Kconfig"
 
-menuconfig RC_DECODERS
-bool "Remote controller decoders"
-   depends on RC_CORE
-   default y
-
-if RC_DECODERS
 config LIRC
-   tristate "LIRC interface driver"
+   bool "LIRC user interface"
depends on RC_CORE
-
---help---
-  Enable this option to build the Linux Infrared Remote
-  Control (LIRC) core device interface driver. The LIRC
-  interface passes raw IR to and from userspace, where the
-  LIRC daemon handles protocol decoding for IR reception and
-  encoding for IR transmitting (aka "blasting").
+  Enable this option to enable the Linux Infrared Remote
+  Control user interface (e.g. /dev/lirc*). This interface
+  passes raw IR to and from userspace, which is needed for
+  IR transmitting (aka "blasting") and for the lirc daemon.
 
-config IR_LIRC_CODEC
-   tristate "Enable IR to LIRC bridge"
+menuconfig RC_DECODERS
+bool "Remote controller decoders"
depends on RC_CORE
-   depends on LIRC
default y
 
-   ---help---
-  Enable this option to pass raw IR to and from userspace via
-  the LIRC interface.
-
-
+if RC_DECODERS
 config IR_NEC_DECODER
tristate "Enable IR raw decoder for the NEC protocol"
depends on RC_CORE
diff --git a/drivers/media/rc/Makefile b/drivers/media/rc/Makefile
index 643797dc971b..a1ef86767aef 100644
--- a/drivers/media/rc/Makefile
+++ b/drivers/media/rc/Makefile
@@ -1,9 +1,9 @@
-rc-core-objs   := rc-main.o rc-ir-raw.o
 
 obj-y += keymaps/
 
 obj-$(CONFIG_RC_CORE) += rc-core.o
-obj-$(CONFIG_LIRC) += lirc_dev.o
+rc-core-y := rc-main.o rc-ir-raw.o
+rc-core-$(CONFIG_LIRC) += lirc_dev.o ir-lirc-codec.o
 obj-$(CONFIG_IR_NEC_DECODER) += ir-nec-decoder.o
 obj-$(CONFIG_IR_RC5_DECODER) += ir-rc5-decoder.o
 obj-$(CONFIG_IR_RC6_DECODER) += ir-rc6-decoder.o
@@ -12,7 +12,6 @@ obj-$(CONFIG_IR_SONY_DECODER) += ir-sony-decoder.o
 obj-$(CONFIG_IR_SANYO_DECODER) += ir-sanyo-decoder.o
 obj-$(CONFIG_IR_SHARP_DECODER) += ir-sharp-decoder.o
 obj-$(CONFIG_IR_MCE_KBD_DECODER) += ir-mce_kbd-decoder.o
-obj-$(CONFIG_IR_LIRC_CODEC) += ir-lirc-codec.o
 obj-$(CONFIG_IR_XMP_DECODER) += ir-xmp-decoder.o
 
 # stand-alone IR receivers/transmitters
diff --git a/drivers/media/rc/ir-lirc-codec.c b/drivers/media/rc/ir-lirc-codec.c
index d733179e2a94..aec0109b1a69 100644
--- a/drivers/media/rc/ir-lirc-codec.c
+++ b/drivers/media/rc/ir-lirc-codec.c
@@ -14,7 +14,6 @@
 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -23,21 +22,15 @@
 #define LIRCBUF_SIZE 256
 
 /**
- * ir_lirc_decode() - Send raw IR data to lirc_dev to be relayed to the
- *   lircd userspace daemon for decoding.
- * @input_dev: the struct rc_dev descriptor of the device
- * @duration:  the struct ir_raw_event descriptor of the pulse/space
+ * ir_lirc_raw_event() - Send raw IR data to lirc to be relayed to userspace
  *
- * This function returns -EINVAL if the lirc interfaces aren't wired up.
+ * @dev:   the struct rc_dev descriptor of the device
+ * @ev:the struct ir_raw_event descriptor of the pulse/space
  */
-static int ir_lirc_decode(struct rc_dev *dev, struct ir_raw_event ev)
+void ir_lirc_raw_event(struct rc_dev *dev, struct ir_raw_event ev)
 {
-   struct lirc_codec *lirc = >raw->lirc;
int sample;
 
-   if (!dev->raw->lirc.ldev || !dev->raw->lirc.ldev->buf)
-   return -EINVAL;
-
/* Packet start */
if (ev.reset) {
/* 

[PATCH 18/28] media: lirc: move lirc_dev->attached to rc_dev->registered

2017-10-29 Thread Sean Young
This is done to further remove the lirc kernel api. Ensure that every
fops checks for this.

Signed-off-by: Sean Young 
---
 drivers/media/rc/ir-lirc-codec.c | 16 ++--
 drivers/media/rc/lirc_dev.c  |  4 +---
 drivers/media/rc/rc-main.c   |  8 
 include/media/lirc_dev.h |  2 --
 include/media/rc-core.h  |  3 +++
 5 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/drivers/media/rc/ir-lirc-codec.c b/drivers/media/rc/ir-lirc-codec.c
index 1ac7a5aa0437..9a780fac207c 100644
--- a/drivers/media/rc/ir-lirc-codec.c
+++ b/drivers/media/rc/ir-lirc-codec.c
@@ -101,6 +101,9 @@ static ssize_t ir_lirc_transmit_ir(struct file *file, const 
char __user *buf,
unsigned int duration = 0; /* signal duration in us */
int i;
 
+   if (!dev->registered)
+   return -ENODEV;
+
start = ktime_get();
 
if (!dev->tx_ir) {
@@ -224,6 +227,9 @@ static long ir_lirc_ioctl(struct file *filep, unsigned int 
cmd,
return ret;
}
 
+   if (!dev->registered)
+   return -ENODEV;
+
switch (cmd) {
case LIRC_GET_FEATURES:
if (dev->driver_type == RC_DRIVER_IR_RAW) {
@@ -406,12 +412,11 @@ static unsigned int ir_lirc_poll(struct file *file,
 struct poll_table_struct *wait)
 {
struct rc_dev *rcdev = file->private_data;
-   struct lirc_dev *d = rcdev->lirc_dev;
unsigned int events = 0;
 
poll_wait(file, >wait_poll, wait);
 
-   if (!d->attached)
+   if (!rcdev->registered)
events = POLLHUP | POLLERR;
else if (rcdev->driver_type == RC_DRIVER_IR_RAW &&
 !kfifo_is_empty(>rawir))
@@ -424,7 +429,6 @@ static ssize_t ir_lirc_read(struct file *file, char __user 
*buffer,
size_t length, loff_t *ppos)
 {
struct rc_dev *rcdev = file->private_data;
-   struct lirc_dev *d = rcdev->lirc_dev;
unsigned int copied;
int ret;
 
@@ -434,7 +438,7 @@ static ssize_t ir_lirc_read(struct file *file, char __user 
*buffer,
if (length < sizeof(unsigned int) || length % sizeof(unsigned int))
return -EINVAL;
 
-   if (!d->attached)
+   if (!rcdev->registered)
return -ENODEV;
 
do {
@@ -444,12 +448,12 @@ static ssize_t ir_lirc_read(struct file *file, char 
__user *buffer,
 
ret = wait_event_interruptible(rcdev->wait_poll,
!kfifo_is_empty(>rawir) ||
-   !d->attached);
+   !rcdev->registered);
if (ret)
return ret;
}
 
-   if (!d->attached)
+   if (!rcdev->registered)
return -ENODEV;
 
mutex_lock(>lock);
diff --git a/drivers/media/rc/lirc_dev.c b/drivers/media/rc/lirc_dev.c
index 9a0ad8d9a0cb..22171267aa90 100644
--- a/drivers/media/rc/lirc_dev.c
+++ b/drivers/media/rc/lirc_dev.c
@@ -122,7 +122,6 @@ int lirc_register_device(struct lirc_dev *d)
 
cdev_init(>cdev, d->fops);
d->cdev.owner = d->owner;
-   d->attached = true;
 
err = cdev_device_add(>cdev, >dev);
if (err) {
@@ -153,7 +152,6 @@ void lirc_unregister_device(struct lirc_dev *d)
 
mutex_lock(>mutex);
 
-   d->attached = false;
if (d->open) {
dev_dbg(>dev, LOGHEAD "releasing opened driver\n",
d->name, d->minor);
@@ -180,7 +178,7 @@ int lirc_dev_fop_open(struct inode *inode, struct file 
*file)
if (retval)
return retval;
 
-   if (!d->attached) {
+   if (!rcdev->registered) {
retval = -ENODEV;
goto out;
}
diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
index ae1df089c96f..9e73899b5994 100644
--- a/drivers/media/rc/rc-main.c
+++ b/drivers/media/rc/rc-main.c
@@ -1809,6 +1809,8 @@ int rc_register_device(struct rc_dev *dev)
goto out_lirc;
}
 
+   dev->registered = true;
+
IR_dprintk(1, "Registered rc%u (driver: %s)\n",
   dev->minor,
   dev->driver_name ? dev->driver_name : "unknown");
@@ -1871,6 +1873,12 @@ void rc_unregister_device(struct rc_dev *dev)
 
rc_free_rx_device(dev);
 
+   dev->registered = false;
+
+   /*
+* lirc device should be freed with dev->registered = false, so
+* that userspace polling will get notified.
+*/
if (dev->driver_type != RC_DRIVER_SCANCODE)
ir_lirc_unregister(dev);
 
diff --git a/include/media/lirc_dev.h b/include/media/lirc_dev.h
index 14d3eb36672e..5782add67edd 100644
--- a/include/media/lirc_dev.h
+++ b/include/media/lirc_dev.h
@@ -26,7 +26,6 @@
  * @rdev:   rc_dev associated with the 

[PATCH 14/28] media: lirc: validate scancode for transmit

2017-10-29 Thread Sean Young
Ensure we reject an attempt to transmit invalid scancodes.

Signed-off-by: Sean Young 
---
 drivers/media/rc/ir-lirc-codec.c | 10 
 drivers/media/rc/rc-core-priv.h  |  1 +
 drivers/media/rc/rc-main.c   | 53 +---
 3 files changed, 44 insertions(+), 20 deletions(-)

diff --git a/drivers/media/rc/ir-lirc-codec.c b/drivers/media/rc/ir-lirc-codec.c
index aec0109b1a69..1ed69c9e64bf 100644
--- a/drivers/media/rc/ir-lirc-codec.c
+++ b/drivers/media/rc/ir-lirc-codec.c
@@ -126,6 +126,16 @@ static ssize_t ir_lirc_transmit_ir(struct file *file, 
const char __user *buf,
if (scan.flags || scan.keycode || scan.timestamp)
return -EINVAL;
 
+   /*
+* The scancode field in lirc_scancode is 64-bit simply
+* to future-proof it, since there are IR protocols encode
+* use more than 32 bits. For now only 32-bit protocols
+* are supported.
+*/
+   if (scan.scancode > U32_MAX ||
+   !rc_validate_scancode(scan.rc_proto, scan.scancode))
+   return -EINVAL;
+
raw = kmalloc_array(LIRCBUF_SIZE, sizeof(*raw), GFP_KERNEL);
if (!raw)
return -ENOMEM;
diff --git a/drivers/media/rc/rc-core-priv.h b/drivers/media/rc/rc-core-priv.h
index 21e515d34f64..a064c401fa38 100644
--- a/drivers/media/rc/rc-core-priv.h
+++ b/drivers/media/rc/rc-core-priv.h
@@ -160,6 +160,7 @@ static inline bool is_timing_event(struct ir_raw_event ev)
 #define TO_STR(is_pulse)   ((is_pulse) ? "pulse" : "space")
 
 /* functions for IR encoders */
+bool rc_validate_scancode(enum rc_proto proto, u32 scancode);
 
 static inline void init_ir_raw_event_duration(struct ir_raw_event *ev,
  unsigned int pulse,
diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
index 758c14b90a87..38393f13822f 100644
--- a/drivers/media/rc/rc-main.c
+++ b/drivers/media/rc/rc-main.c
@@ -776,6 +776,37 @@ void rc_keydown_notimeout(struct rc_dev *dev, enum 
rc_proto protocol,
 EXPORT_SYMBOL_GPL(rc_keydown_notimeout);
 
 /**
+ * rc_validate_scancode() - checks that a scancode is valid for a protocol
+ * @proto: protocol
+ * @scancode:  scancode
+ */
+bool rc_validate_scancode(enum rc_proto proto, u32 scancode)
+{
+   switch (proto) {
+   case RC_PROTO_NECX:
+   if scancode >> 16) ^ ~(scancode >> 8)) & 0xff) == 0)
+   return false;
+   break;
+   case RC_PROTO_NEC32:
+   if scancode >> 24) ^ ~(scancode >> 16)) & 0xff) == 0)
+   return false;
+   break;
+   case RC_PROTO_RC6_MCE:
+   if ((scancode & 0x) != 0x800f)
+   return false;
+   break;
+   case RC_PROTO_RC6_6A_32:
+   if ((scancode & 0x) == 0x800f)
+   return false;
+   break;
+   default:
+   break;
+   }
+
+   return true;
+}
+
+/**
  * rc_validate_filter() - checks that the scancode and mask are valid and
  *   provides sensible defaults
  * @dev:   the struct rc_dev descriptor of the device
@@ -793,26 +824,8 @@ static int rc_validate_filter(struct rc_dev *dev,
 
mask = protocols[protocol].scancode_bits;
 
-   switch (protocol) {
-   case RC_PROTO_NECX:
-   if s >> 16) ^ ~(s >> 8)) & 0xff) == 0)
-   return -EINVAL;
-   break;
-   case RC_PROTO_NEC32:
-   if s >> 24) ^ ~(s >> 16)) & 0xff) == 0)
-   return -EINVAL;
-   break;
-   case RC_PROTO_RC6_MCE:
-   if ((s & 0x) != 0x800f)
-   return -EINVAL;
-   break;
-   case RC_PROTO_RC6_6A_32:
-   if ((s & 0x) == 0x800f)
-   return -EINVAL;
-   break;
-   default:
-   break;
-   }
+   if (!rc_validate_scancode(protocol, s))
+   return -EINVAL;
 
filter->data &= mask;
filter->mask &= mask;
-- 
2.13.6



[PATCH 05/28] media: rc: implement zilog transmitter

2017-10-29 Thread Sean Young
This code implements the transmitter which is currently implemented
in the staging lirc_zilog driver.

The new code does not need a signal database, iow. the
haup-ir-blaster.bin firmware file is no longer needed, and the driver
does not know anything about the keycodes in that file.

Instead, the new driver can send raw IR, but the hardware is limited
o few different lengths of pulse and spaces, so it is best to use
generated IR rather than recorded IR.

Signed-off-by: Sean Young 
---
 drivers/media/i2c/ir-kbd-i2c.c | 436 -
 include/media/i2c/ir-kbd-i2c.h |   5 +
 2 files changed, 433 insertions(+), 8 deletions(-)

diff --git a/drivers/media/i2c/ir-kbd-i2c.c b/drivers/media/i2c/ir-kbd-i2c.c
index ec669ec4cfc5..b656c8ec31ca 100644
--- a/drivers/media/i2c/ir-kbd-i2c.c
+++ b/drivers/media/i2c/ir-kbd-i2c.c
@@ -18,6 +18,20 @@
  *  Brian Rogers 
  * modified for AVerMedia Cardbus by
  *  Oldrich Jedlicka 
+ * Zilog Transmitter portions/ideas were derived from GPLv2+ sources:
+ *  - drivers/char/pctv_zilogir.[ch] from Hauppauge Broadway product
+ * Copyright 2011 Hauppauge Computer works
+ *  - drivers/staging/media/lirc/lirc_zilog.c
+ * Copyright (c) 2000 Gerd Knorr 
+ * Michal Kochanowicz 
+ * Christoph Bartelmus 
+ * Ulrich Mueller 
+ * Stefan Jahn 
+ * Jerome Brock 
+ * Thomas Reitmayr (treitm...@yahoo.com)
+ * Mark Weaver 
+ * Jarod Wilson 
+ * Copyright (C) 2011 Andy Walls 
  *
  *  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
@@ -46,6 +60,8 @@
 #include 
 #include 
 
+#define FLAG_TX1
+#define FLAG_HDPVR 2
 
 static int get_key_haup_common(struct IR_i2c *ir, enum rc_proto *protocol,
   u32 *scancode, u8 *ptoggle, int size)
@@ -288,11 +304,18 @@ static void ir_work(struct work_struct *work)
int rc;
struct IR_i2c *ir = container_of(work, struct IR_i2c, work.work);
 
-   rc = ir_key_poll(ir);
-   if (rc == -ENODEV) {
-   rc_unregister_device(ir->rc);
-   ir->rc = NULL;
-   return;
+   /*
+* If the transmit code is holding the lock, skip polling for
+* IR, we'll get it to it next time round
+*/
+   if (mutex_trylock(>lock)) {
+   rc = ir_key_poll(ir);
+   mutex_unlock(>lock);
+   if (rc == -ENODEV) {
+   rc_unregister_device(ir->rc);
+   ir->rc = NULL;
+   return;
+   }
}
 
schedule_delayed_work(>work, 
msecs_to_jiffies(ir->polling_interval));
@@ -314,7 +337,383 @@ static void ir_close(struct rc_dev *dev)
cancel_delayed_work_sync(>work);
 }
 
-/* --- */
+/* Zilog Transmit Interface */
+#define XTAL_FREQ  18432000
+
+#define ZILOG_SEND 0x80
+#define ZILOG_UIR_END  0x40
+#define ZILOG_INIT_END 0x20
+#define ZILOG_LIR_END  0x10
+
+#define ZILOG_STATUS_OK0x80
+#define ZILOG_STATUS_TX0x40
+#define ZILOG_STATUS_SET   0x20
+
+/*
+ * As you can see here, very few different lengths of pulse and space
+ * can be encoded. This means that the hardware does not work well with
+ * recorded IR. It's best to work with generated IR, like from ir-ctl or
+ * the in-kernel encoders.
+ */
+struct code_block {
+   u8  length;
+   u16 pulse[7];   /* not aligned */
+   u8  carrier_pulse;
+   u8  carrier_space;
+   u16 space[8];   /* not aligned */
+   u8  codes[61];
+   u8  csum[2];
+} __packed;
+
+static int send_data_block(struct IR_i2c *ir, int cmd,
+  struct code_block *code_block)
+{
+   int i, j, ret;
+   u8 buf[5], *p;
+
+   p = _block->length;
+   for (i = 0; p < code_block->csum; i++)
+   code_block->csum[i & 1] ^= *p++;
+
+   p = _block->length;
+
+   for (i = 0; i < sizeof(*code_block);) {
+   int tosend = sizeof(*code_block) - i;
+
+   if (tosend > 4)
+   tosend = 4;
+   buf[0] = i + 1;
+   for (j = 0; j < tosend; ++j)
+   buf[1 + j] = p[i + j];
+   dev_dbg(>rc->dev, "%*ph", tosend + 1, buf);
+   ret = i2c_master_send(ir->tx_c, buf, tosend + 1);
+   if (ret != tosend + 1) {
+   dev_dbg(>rc->dev,
+   "i2c_master_send failed with %d\n", ret);
+   

[PATCH 10/28] media: lirc: implement scancode sending

2017-10-29 Thread Sean Young
This introduces a new lirc mode: scancode. Any device which can send raw IR
can now also send scancodes.

int main()
{
int mode, fd = open("/dev/lirc0", O_RDWR);

mode = LIRC_MODE_SCANCODE;
if (ioctl(fd, LIRC_SET_SEND_MODE, )) {
// kernel too old or lirc does not support transmit
}
struct lirc_scancode scancode = {
.scancode = 0x1e3d,
.rc_proto = RC_PROTO_RC5,
};
write(fd, , sizeof(scancode));
close(fd);
}

The other fields of lirc_scancode must be set to 0.

Note that toggle (rc5, rc6) and repeats (nec) are not implemented. Nor is
there a method for holding down a key for a period.

Signed-off-by: Sean Young 
---
 drivers/media/rc/ir-lirc-codec.c | 99 +---
 drivers/media/rc/rc-core-priv.h  |  2 +-
 include/media/rc-map.h   | 54 +-
 include/uapi/linux/lirc.h| 82 +
 4 files changed, 156 insertions(+), 81 deletions(-)

diff --git a/drivers/media/rc/ir-lirc-codec.c b/drivers/media/rc/ir-lirc-codec.c
index 6a68d9e4a36b..73e4ff3cb023 100644
--- a/drivers/media/rc/ir-lirc-codec.c
+++ b/drivers/media/rc/ir-lirc-codec.c
@@ -107,7 +107,8 @@ static ssize_t ir_lirc_transmit_ir(struct file *file, const 
char __user *buf,
 {
struct lirc_codec *lirc;
struct rc_dev *dev;
-   unsigned int *txbuf; /* buffer with values to transmit */
+   unsigned int *txbuf = NULL;
+   struct ir_raw_event *raw = NULL;
ssize_t ret = -EINVAL;
size_t count;
ktime_t start;
@@ -121,16 +122,50 @@ static ssize_t ir_lirc_transmit_ir(struct file *file, 
const char __user *buf,
if (!lirc)
return -EFAULT;
 
-   if (n < sizeof(unsigned) || n % sizeof(unsigned))
-   return -EINVAL;
+   if (lirc->send_mode == LIRC_MODE_SCANCODE) {
+   struct lirc_scancode scan;
 
-   count = n / sizeof(unsigned);
-   if (count > LIRCBUF_SIZE || count % 2 == 0)
-   return -EINVAL;
+   if (n != sizeof(scan))
+   return -EINVAL;
 
-   txbuf = memdup_user(buf, n);
-   if (IS_ERR(txbuf))
-   return PTR_ERR(txbuf);
+   if (copy_from_user(, buf, sizeof(scan)))
+   return -EFAULT;
+
+   if (scan.flags || scan.keycode || scan.timestamp)
+   return -EINVAL;
+
+   raw = kmalloc_array(LIRCBUF_SIZE, sizeof(*raw), GFP_KERNEL);
+   if (!raw)
+   return -ENOMEM;
+
+   ret = ir_raw_encode_scancode(scan.rc_proto, scan.scancode,
+raw, LIRCBUF_SIZE);
+   if (ret < 0)
+   goto out;
+
+   count = ret;
+
+   txbuf = kmalloc_array(count, sizeof(unsigned int), GFP_KERNEL);
+   if (!txbuf) {
+   ret = -ENOMEM;
+   goto out;
+   }
+
+   for (i = 0; i < count; i++)
+   /* Convert from NS to US */
+   txbuf[i] = DIV_ROUND_UP(raw[i].duration, 1000);
+   } else {
+   if (n < sizeof(unsigned int) || n % sizeof(unsigned int))
+   return -EINVAL;
+
+   count = n / sizeof(unsigned int);
+   if (count > LIRCBUF_SIZE || count % 2 == 0)
+   return -EINVAL;
+
+   txbuf = memdup_user(buf, n);
+   if (IS_ERR(txbuf))
+   return PTR_ERR(txbuf);
+   }
 
dev = lirc->dev;
if (!dev) {
@@ -156,24 +191,30 @@ static ssize_t ir_lirc_transmit_ir(struct file *file, 
const char __user *buf,
if (ret < 0)
goto out;
 
-   for (duration = i = 0; i < ret; i++)
-   duration += txbuf[i];
-
-   ret *= sizeof(unsigned int);
-
-   /*
-* The lircd gap calculation expects the write function to
-* wait for the actual IR signal to be transmitted before
-* returning.
-*/
-   towait = ktime_us_delta(ktime_add_us(start, duration), ktime_get());
-   if (towait > 0) {
-   set_current_state(TASK_INTERRUPTIBLE);
-   schedule_timeout(usecs_to_jiffies(towait));
+   if (lirc->send_mode == LIRC_MODE_SCANCODE) {
+   ret = n;
+   } else {
+   for (duration = i = 0; i < ret; i++)
+   duration += txbuf[i];
+
+   ret *= sizeof(unsigned int);
+
+   /*
+* The lircd gap calculation expects the write function to
+* wait for the actual IR signal to be transmitted before
+* returning.
+*/
+   towait = ktime_us_delta(ktime_add_us(start, duration),
+   ktime_get());
+   if 

[PATCH 06/28] media: i2c: enable i2c IR for hardware which isn't HD-PVR

2017-10-29 Thread Sean Young
This is a fix for commit 329d88da4df9 ("[media] media: i2c: Don't export
ir-kbd-i2c module alias") that stopped the module from being loaded
automagically.

The problems described only affect the HD-PVR, so it should not affect
other hardware; also if the module happens to be loaded, the i2c IR
part of the HD-PVR will be enabled anyway.

Fixes: 329d88da4df9 ("[media] media: i2c: Don't export ir-kbd-i2c module alias")

Signed-off-by: Sean Young 
---
 drivers/media/i2c/ir-kbd-i2c.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/drivers/media/i2c/ir-kbd-i2c.c b/drivers/media/i2c/ir-kbd-i2c.c
index b656c8ec31ca..919c4a4e6007 100644
--- a/drivers/media/i2c/ir-kbd-i2c.c
+++ b/drivers/media/i2c/ir-kbd-i2c.c
@@ -63,6 +63,9 @@
 #define FLAG_TX1
 #define FLAG_HDPVR 2
 
+static bool enable_hdpvr;
+module_param(enable_hdpvr, bool, 0644);
+
 static int get_key_haup_common(struct IR_i2c *ir, enum rc_proto *protocol,
   u32 *scancode, u8 *ptoggle, int size)
 {
@@ -726,6 +729,11 @@ static int ir_probe(struct i2c_client *client, const 
struct i2c_device_id *id)
unsigned short addr = client->addr;
int err;
 
+   if ((id->driver_data & FLAG_HDPVR) && !enable_hdpvr) {
+   dev_err(>dev, "IR for HDPVR is known to cause problems 
during recording, use enable_hdpvr modparam to enable\n");
+   return -ENODEV;
+   }
+
ir = devm_kzalloc(>dev, sizeof(*ir), GFP_KERNEL);
if (!ir)
return -ENOMEM;
@@ -925,6 +933,7 @@ static const struct i2c_device_id ir_kbd_id[] = {
{ "ir_z8f0811_hdpvr", FLAG_TX | FLAG_HDPVR },
{ }
 };
+MODULE_DEVICE_TABLE(i2c, ir_kbd_id);
 
 static struct i2c_driver ir_kbd_driver = {
.driver = {
-- 
2.13.6



[PATCH 19/28] media: lirc: do not call rc_close() on unregistered devices

2017-10-29 Thread Sean Young
If a lirc chardev is held open after a device is unplugged, rc_close()
will be called after rc_unregister_device(). The driver is not expecting
any calls at this point, and the iguanair driver causes an oops in
this scenario.

Signed-off-by: Sean Young 
---
 drivers/media/rc/rc-main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
index 9e73899b5994..9a8fc86b0835 100644
--- a/drivers/media/rc/rc-main.c
+++ b/drivers/media/rc/rc-main.c
@@ -885,7 +885,7 @@ void rc_close(struct rc_dev *rdev)
if (rdev) {
mutex_lock(>lock);
 
-   if (!--rdev->users && rdev->close != NULL)
+   if (!--rdev->users && rdev->close && rdev->registered)
rdev->close(rdev);
 
mutex_unlock(>lock);
-- 
2.13.6



[PATCH 15/28] media: rc: document and fix rc_validate_scancode()

2017-10-29 Thread Sean Young
For some IR protocols, some scancode values not valid, i.e. they're part
of a different protocol variant.

Signed-off-by: Sean Young 
---
 drivers/media/rc/rc-main.c | 18 --
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
index 38393f13822f..ae1df089c96f 100644
--- a/drivers/media/rc/rc-main.c
+++ b/drivers/media/rc/rc-main.c
@@ -776,21 +776,35 @@ void rc_keydown_notimeout(struct rc_dev *dev, enum 
rc_proto protocol,
 EXPORT_SYMBOL_GPL(rc_keydown_notimeout);
 
 /**
- * rc_validate_scancode() - checks that a scancode is valid for a protocol
+ * rc_validate_scancode() - checks that a scancode is valid for a protocol.
+ * For nec, it should do the opposite of ir_nec_bytes_to_scancode()
  * @proto: protocol
  * @scancode:  scancode
  */
 bool rc_validate_scancode(enum rc_proto proto, u32 scancode)
 {
switch (proto) {
+   /*
+* NECX has a 16-bit address; if the lower 8 bits match the upper
+* 8 bits inverted, then the address would match regular nec.
+*/
case RC_PROTO_NECX:
if scancode >> 16) ^ ~(scancode >> 8)) & 0xff) == 0)
return false;
break;
+   /*
+* NEC32 has a 16 bit address and 16 bit command. If the lower 8 bits
+* of the command match the upper 8 bits inverted, then it would
+* be either NEC or NECX.
+*/
case RC_PROTO_NEC32:
-   if scancode >> 24) ^ ~(scancode >> 16)) & 0xff) == 0)
+   if scancode >> 8) ^ ~scancode) & 0xff) == 0)
return false;
break;
+   /*
+* If the customer code (top 32-bit) is 0x800f, it is MCE else it
+* is regular mode-6a 32 bit
+*/
case RC_PROTO_RC6_MCE:
if ((scancode & 0x) != 0x800f)
return false;
-- 
2.13.6



[PATCH 07/28] media: staging: remove lirc_zilog driver

2017-10-29 Thread Sean Young
The ir-kbd-i2c driver is functionally equivalent to the lirc_zilog
driver.

The lirc_zilog driver only polls if the lirc chardev is opened;
similarly the ir-kbd-i2c driver only polls if the corresponding input
device is opened, or the lirc device.

Polling is disabled during IR transmission through the mutex.

The polling period is 402ms in the ir-kdb-i2c driver, and 260ms in the
lirc_zilog driver.

Signed-off-by: Sean Young 
---
 drivers/staging/media/Kconfig   |3 -
 drivers/staging/media/Makefile  |1 -
 drivers/staging/media/lirc/Kconfig  |   21 -
 drivers/staging/media/lirc/Makefile |6 -
 drivers/staging/media/lirc/TODO |   36 -
 drivers/staging/media/lirc/lirc_zilog.c | 1653 ---
 6 files changed, 1720 deletions(-)
 delete mode 100644 drivers/staging/media/lirc/Kconfig
 delete mode 100644 drivers/staging/media/lirc/Makefile
 delete mode 100644 drivers/staging/media/lirc/TODO
 delete mode 100644 drivers/staging/media/lirc/lirc_zilog.c

diff --git a/drivers/staging/media/Kconfig b/drivers/staging/media/Kconfig
index f8c25ee082ef..3a09140700e6 100644
--- a/drivers/staging/media/Kconfig
+++ b/drivers/staging/media/Kconfig
@@ -31,7 +31,4 @@ source "drivers/staging/media/imx/Kconfig"
 
 source "drivers/staging/media/omap4iss/Kconfig"
 
-# Keep LIRC at the end, as it has sub-menus
-source "drivers/staging/media/lirc/Kconfig"
-
 endif
diff --git a/drivers/staging/media/Makefile b/drivers/staging/media/Makefile
index ac090c5fce30..9c057126d61f 100644
--- a/drivers/staging/media/Makefile
+++ b/drivers/staging/media/Makefile
@@ -1,7 +1,6 @@
 obj-$(CONFIG_I2C_BCM2048)  += bcm2048/
 obj-$(CONFIG_DVB_CXD2099)  += cxd2099/
 obj-$(CONFIG_VIDEO_IMX_MEDIA)  += imx/
-obj-$(CONFIG_LIRC_STAGING) += lirc/
 obj-$(CONFIG_VIDEO_DM365_VPFE) += davinci_vpfe/
 obj-$(CONFIG_VIDEO_OMAP4)  += omap4iss/
 obj-$(CONFIG_INTEL_ATOMISP) += atomisp/
diff --git a/drivers/staging/media/lirc/Kconfig 
b/drivers/staging/media/lirc/Kconfig
deleted file mode 100644
index 3e350a9922de..
--- a/drivers/staging/media/lirc/Kconfig
+++ /dev/null
@@ -1,21 +0,0 @@
-#
-# LIRC driver(s) configuration
-#
-menuconfig LIRC_STAGING
-   bool "Linux Infrared Remote Control IR receiver/transmitter drivers"
-   depends on LIRC
-   help
- Say Y here, and all supported Linux Infrared Remote Control IR and
- RF receiver and transmitter drivers will be displayed. When paired
- with a remote control and the lirc daemon, the receiver drivers
- allow control of your Linux system via remote control.
-
-if LIRC_STAGING
-
-config LIRC_ZILOG
-   tristate "Zilog/Hauppauge IR Transmitter"
-   depends on LIRC && I2C
-   help
- Driver for the Zilog/Hauppauge IR Transmitter, found on
- PVR-150/500, HVR-1200/1250/1700/1800, HD-PVR and other cards
-endif
diff --git a/drivers/staging/media/lirc/Makefile 
b/drivers/staging/media/lirc/Makefile
deleted file mode 100644
index 665562436e30..
--- a/drivers/staging/media/lirc/Makefile
+++ /dev/null
@@ -1,6 +0,0 @@
-# Makefile for the lirc drivers.
-#
-
-# Each configuration option enables a list of files.
-
-obj-$(CONFIG_LIRC_ZILOG)   += lirc_zilog.o
diff --git a/drivers/staging/media/lirc/TODO b/drivers/staging/media/lirc/TODO
deleted file mode 100644
index a97800a8e127..
--- a/drivers/staging/media/lirc/TODO
+++ /dev/null
@@ -1,36 +0,0 @@
-1. Both ir-kbd-i2c and lirc_zilog provide support for RX events for
-the chips supported by lirc_zilog.  Before moving lirc_zilog out of staging:
-
-a. ir-kbd-i2c needs a module parameter added to allow the user to tell
-   ir-kbd-i2c to ignore Z8 IR units.
-
-b. lirc_zilog should provide Rx key presses to the rc core like ir-kbd-i2c
-   does.
-
-
-2. lirc_zilog module ref-counting need examination.  It has not been
-verified that cdev and lirc_dev will take the proper module references on
-lirc_zilog to prevent removal of lirc_zilog when the /dev/lircN device node
-is open.
-
-(The good news is ref-counting of lirc_zilog internal structures appears to be
-complete.  Testing has shown the cx18 module can be unloaded out from under
-irw + lircd + lirc_dev, with the /dev/lirc0 device node open, with no adverse
-effects.  The cx18 module could then be reloaded and irw properly began
-receiving button presses again and ir_send worked without error.)
-
-
-3. Bridge drivers, if able, should provide a chip reset() callback
-to lirc_zilog via struct IR_i2c_init_data.  cx18 and ivtv already have routines
-to perform Z8 chip resets via GPIO manipulations.  This would allow lirc_zilog
-to bring the chip back to normal when it hangs, in the same places the
-original lirc_pvr150 driver code does.  This is not strictly needed, so it
-is not required to move lirc_zilog out of staging.
-
-Note: Both lirc_zilog and ir-kbd-i2c support the Zilog Z8 for IR, as programmed
-and installed on Hauppauge 

[PATCH 03/28] media: rc: i2c: only poll if the rc device is opened

2017-10-29 Thread Sean Young
The lirc_zilog driver only polls the device if the lirc chardev
is opened; do the same with the rc-core driver.

Signed-off-by: Sean Young 
---
 drivers/media/i2c/ir-kbd-i2c.c | 25 +
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/drivers/media/i2c/ir-kbd-i2c.c b/drivers/media/i2c/ir-kbd-i2c.c
index 1b8cd1b75bfb..22f32717638a 100644
--- a/drivers/media/i2c/ir-kbd-i2c.c
+++ b/drivers/media/i2c/ir-kbd-i2c.c
@@ -298,6 +298,22 @@ static void ir_work(struct work_struct *work)
schedule_delayed_work(>work, 
msecs_to_jiffies(ir->polling_interval));
 }
 
+static int ir_open(struct rc_dev *dev)
+{
+   struct IR_i2c *ir = dev->priv;
+
+   schedule_delayed_work(>work, 0);
+
+   return 0;
+}
+
+static void ir_close(struct rc_dev *dev)
+{
+   struct IR_i2c *ir = dev->priv;
+
+   cancel_delayed_work_sync(>work);
+}
+
 /* --- */
 
 static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
@@ -441,6 +457,9 @@ static int ir_probe(struct i2c_client *client, const struct 
i2c_device_id *id)
rc->input_phys   = ir->phys;
rc->device_name  = name;
rc->dev.parent   = >dev;
+   rc->priv = ir;
+   rc->open = ir_open;
+   rc->close= ir_close;
 
/*
 * Initialize the other fields of rc_dev
@@ -450,14 +469,12 @@ static int ir_probe(struct i2c_client *client, const 
struct i2c_device_id *id)
if (!rc->driver_name)
rc->driver_name = KBUILD_MODNAME;
 
+   INIT_DELAYED_WORK(>work, ir_work);
+
err = rc_register_device(rc);
if (err)
goto err_out_free;
 
-   /* start polling via eventd */
-   INIT_DELAYED_WORK(>work, ir_work);
-   schedule_delayed_work(>work, 0);
-
return 0;
 
  err_out_free:
-- 
2.13.6



[PATCH 01/28] media: rc: i2c: set parent of rc device and improve name

2017-10-29 Thread Sean Young
With the parent set for the rc device, the messages clearly state
that it is attached via i2c. The additional printk is unnecessary.

So these are the old messages:

rc rc1: i2c IR (Hauppauge WinTV PVR-150 as /devices/virtual/rc/rc1
ir-kbd-i2c: i2c IR (Hauppauge WinTV PVR-150 detected at i2c-10/10-0071/ir0 
[ivtv i2c driver #0]

Now we simply get:

rc rc1: Hauppauge WinTV PVR-150 as 
/devices/pci:00/:00:1e.0/:02:00.0/i2c-10/10-0071/rc/rc1

Note that we no longer copy the name. I've checked all call sites
to verfiy this is not a problem.

Signed-off-by: Sean Young 
---
 drivers/media/i2c/ir-kbd-i2c.c| 11 +++
 drivers/media/pci/saa7134/saa7134-input.c |  3 ++-
 include/media/i2c/ir-kbd-i2c.h|  1 -
 3 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/drivers/media/i2c/ir-kbd-i2c.c b/drivers/media/i2c/ir-kbd-i2c.c
index 8b5f7d0435e4..27e36f45286c 100644
--- a/drivers/media/i2c/ir-kbd-i2c.c
+++ b/drivers/media/i2c/ir-kbd-i2c.c
@@ -439,12 +439,9 @@ static int ir_probe(struct i2c_client *client, const 
struct i2c_device_id *id)
goto err_out_free;
}
 
-   /* Sets name */
-   snprintf(ir->name, sizeof(ir->name), "i2c IR (%s)", name);
ir->ir_codes = ir_codes;
 
-   snprintf(ir->phys, sizeof(ir->phys), "%s/%s/ir0",
-dev_name(>dev),
+   snprintf(ir->phys, sizeof(ir->phys), "%s/%s", dev_name(>dev),
 dev_name(>dev));
 
/*
@@ -453,7 +450,8 @@ static int ir_probe(struct i2c_client *client, const struct 
i2c_device_id *id)
 */
rc->input_id.bustype = BUS_I2C;
rc->input_phys   = ir->phys;
-   rc->device_name  = ir->name;
+   rc->device_name  = name;
+   rc->dev.parent   = >dev;
 
/*
 * Initialize the other fields of rc_dev
@@ -467,9 +465,6 @@ static int ir_probe(struct i2c_client *client, const struct 
i2c_device_id *id)
if (err)
goto err_out_free;
 
-   printk(MODULE_NAME ": %s detected at %s [%s]\n",
-  ir->name, ir->phys, adap->name);
-
/* start polling via eventd */
INIT_DELAYED_WORK(>work, ir_work);
schedule_delayed_work(>work, 0);
diff --git a/drivers/media/pci/saa7134/saa7134-input.c 
b/drivers/media/pci/saa7134/saa7134-input.c
index 9337e4615519..965098e74c64 100644
--- a/drivers/media/pci/saa7134/saa7134-input.c
+++ b/drivers/media/pci/saa7134/saa7134-input.c
@@ -43,7 +43,8 @@ MODULE_PARM_DESC(pinnacle_remote, "Specify Pinnacle PCTV 
remote: 0=coloured, 1=g
} while (0)
 #define ir_dbg(ir, fmt, arg...) do { \
if (ir_debug) \
-   printk(KERN_DEBUG pr_fmt("ir %s: " fmt), ir->name, ## arg); \
+   printk(KERN_DEBUG pr_fmt("ir %s: " fmt), ir->rc->device_name, \
+  ## arg); \
} while (0)
 
 /* Helper function for raw decoding at GPIO16 or GPIO18 */
diff --git a/include/media/i2c/ir-kbd-i2c.h b/include/media/i2c/ir-kbd-i2c.h
index ac8c55617a79..092ab44da7e0 100644
--- a/include/media/i2c/ir-kbd-i2c.h
+++ b/include/media/i2c/ir-kbd-i2c.h
@@ -18,7 +18,6 @@ struct IR_i2c {
u32polling_interval; /* in ms */
 
struct delayed_workwork;
-   char   name[32];
char   phys[32];
int(*get_key)(struct IR_i2c *ir,
  enum rc_proto *protocol,
-- 
2.13.6



[PATCH 04/28] media: merge ir_tx_z8f0811_haup and ir_rx_z8f0811_haup i2c devices

2017-10-29 Thread Sean Young
These two devices ids are really just one device with multiple
addresses. Probing becomes much simpler if we simply fold this into
one i2c device with two address.

Note that this breaks the lirc_zilog driver, however we will teach
ir-kbd-i2c to do what lirc_zilog does in a later commit.

Signed-off-by: Sean Young 
---
 drivers/media/i2c/ir-kbd-i2c.c   |  4 ++--
 drivers/media/pci/cx18/cx18-cards.h  |  8 +---
 drivers/media/pci/cx18/cx18-i2c.c| 13 +
 drivers/media/pci/ivtv/ivtv-cards.h  | 22 +++---
 drivers/media/pci/ivtv/ivtv-i2c.c| 20 
 drivers/media/usb/hdpvr/hdpvr-core.c | 11 ++-
 drivers/media/usb/hdpvr/hdpvr-i2c.c  | 23 +--
 drivers/media/usb/hdpvr/hdpvr.h  |  3 +--
 drivers/media/usb/pvrusb2/pvrusb2-i2c-core.c | 13 +++--
 9 files changed, 30 insertions(+), 87 deletions(-)

diff --git a/drivers/media/i2c/ir-kbd-i2c.c b/drivers/media/i2c/ir-kbd-i2c.c
index 22f32717638a..ec669ec4cfc5 100644
--- a/drivers/media/i2c/ir-kbd-i2c.c
+++ b/drivers/media/i2c/ir-kbd-i2c.c
@@ -501,8 +501,8 @@ static const struct i2c_device_id ir_kbd_id[] = {
/* Generic entry for any IR receiver */
{ "ir_video", 0 },
/* IR device specific entries should be added here */
-   { "ir_rx_z8f0811_haup", 0 },
-   { "ir_rx_z8f0811_hdpvr", 0 },
+   { "ir_z8f0811_haup", 0 },
+   { "ir_z8f0811_hdpvr", 0 },
{ }
 };
 
diff --git a/drivers/media/pci/cx18/cx18-cards.h 
b/drivers/media/pci/cx18/cx18-cards.h
index 667e2d7b1d03..5478f62b5cf3 100644
--- a/drivers/media/pci/cx18/cx18-cards.h
+++ b/drivers/media/pci/cx18/cx18-cards.h
@@ -25,13 +25,7 @@
 #define CX18_HW_418_AV (1 << 4)
 #define CX18_HW_GPIO_MUX   (1 << 5)
 #define CX18_HW_GPIO_RESET_CTRL(1 << 6)
-#define CX18_HW_Z8F0811_IR_TX_HAUP (1 << 7)
-#define CX18_HW_Z8F0811_IR_RX_HAUP (1 << 8)
-#define CX18_HW_Z8F0811_IR_HAUP(CX18_HW_Z8F0811_IR_RX_HAUP | \
-CX18_HW_Z8F0811_IR_TX_HAUP)
-
-#define CX18_HW_IR_ANY (CX18_HW_Z8F0811_IR_RX_HAUP | \
-   CX18_HW_Z8F0811_IR_TX_HAUP)
+#define CX18_HW_Z8F0811_IR_HAUP(1 << 7)
 
 /* video inputs */
 #defineCX18_CARD_INPUT_VID_TUNER   1
diff --git a/drivers/media/pci/cx18/cx18-i2c.c 
b/drivers/media/pci/cx18/cx18-i2c.c
index 7f588eeac60f..f0eb181f2b94 100644
--- a/drivers/media/pci/cx18/cx18-i2c.c
+++ b/drivers/media/pci/cx18/cx18-i2c.c
@@ -47,8 +47,7 @@ static const u8 hw_addrs[] = {
0,  /* CX18_HW_418_AV */
0,  /* CX18_HW_GPIO_MUX */
0,  /* CX18_HW_GPIO_RESET_CTRL */
-   CX18_Z8F0811_IR_TX_I2C_ADDR,/* CX18_HW_Z8F0811_IR_TX_HAUP */
-   CX18_Z8F0811_IR_RX_I2C_ADDR,/* CX18_HW_Z8F0811_IR_RX_HAUP */
+   CX18_Z8F0811_IR_RX_I2C_ADDR,/* CX18_HW_Z8F0811_IR_HAUP */
 };
 
 /* This array should match the CX18_HW_ defines */
@@ -61,8 +60,7 @@ static const u8 hw_bus[] = {
0,  /* CX18_HW_418_AV */
0,  /* CX18_HW_GPIO_MUX */
0,  /* CX18_HW_GPIO_RESET_CTRL */
-   0,  /* CX18_HW_Z8F0811_IR_TX_HAUP */
-   0,  /* CX18_HW_Z8F0811_IR_RX_HAUP */
+   0,  /* CX18_HW_Z8F0811_IR_HAUP */
 };
 
 /* This array should match the CX18_HW_ defines */
@@ -74,8 +72,7 @@ static const char * const hw_devicenames[] = {
"cx23418_AV",
"gpio_mux",
"gpio_reset_ctrl",
-   "ir_tx_z8f0811_haup",
-   "ir_rx_z8f0811_haup",
+   "ir_z8f0811_haup",
 };
 
 static int cx18_i2c_new_ir(struct cx18 *cx, struct i2c_adapter *adap, u32 hw,
@@ -90,7 +87,7 @@ static int cx18_i2c_new_ir(struct cx18 *cx, struct 
i2c_adapter *adap, u32 hw,
 
/* Our default information for ir-kbd-i2c.c to use */
switch (hw) {
-   case CX18_HW_Z8F0811_IR_RX_HAUP:
+   case CX18_HW_Z8F0811_IR_HAUP:
init_data->ir_codes = RC_MAP_HAUPPAUGE;
init_data->internal_get_key_func = IR_KBD_GET_KEY_HAUP_XVR;
init_data->type = RC_PROTO_BIT_RC5 | RC_PROTO_BIT_RC6_MCE |
@@ -129,7 +126,7 @@ int cx18_i2c_register(struct cx18 *cx, unsigned idx)
return sd != NULL ? 0 : -1;
}
 
-   if (hw & CX18_HW_IR_ANY)
+   if (hw == CX18_HW_Z8F0811_IR_HAUP)
return cx18_i2c_new_ir(cx, adap, hw, type, hw_addrs[idx]);
 
/* Is it not an I2C device or one we do not wish to register? */
diff --git a/drivers/media/pci/ivtv/ivtv-cards.h 
b/drivers/media/pci/ivtv/ivtv-cards.h
index e6f5c02981f1..06e7b4ed6444 100644
--- a/drivers/media/pci/ivtv/ivtv-cards.h
+++ b/drivers/media/pci/ivtv/ivtv-cards.h
@@ -109,24 +109,16 @@
 #define IVTV_HW_I2C_IR_RX_AVER (1 << 16)
 #define IVTV_HW_I2C_IR_RX_HAUP_EXT (1 << 17) /* External before internal */
 #define 

[PATCH 00/28] lirc scancode interface, and more

2017-10-29 Thread Sean Young
Port lirc_zilog to rc-core, introduce lirc scancode mode for
sending and receiving, and then remove the lirc kernel api.

Note that the ported zilog driver needs the scancode interface,
since without it the RC_DRIVER_SCANCODE type IR driver would not
have a lirc chardev.

In summary:
 - This removes the lirc staging directory.
 - lirc IR TX can use in-kernel encoders for scancode encoding
 - lirc_zilog now can transmit raw IR (or scancodes using above interface)
 - lirc kapi (not uapi!) is gone
 - The reading lirc scancode interface gives more information (e.g. protocol,
   toggle, repeat). So you can determine what protocol variant a remotes uses
 - Line count is actually down and code cleaner (imo)

v2:
 - Add MAINTAINERS entries
 - Fixes for nec repeat
 - Validate scancode for tx
 - Minor bugfixes

v3:
 - Review comments from Hans Verkuil
 - Documented and fixed rc_validate_scancode()
 - Fix a bug in kfifo on arm 32-bit
 - this inferface won't be used for cec remote control passthrough

v4:
 - Rewrote zilog driver to send raw IR rather than codes from database
 - Minor ir-kbd-i2c improvements

Sean Young (28):
  media: rc: i2c: set parent of rc device and improve name
  media: rc: i2c: use dev_dbg rather hand-rolled debug
  media: rc: i2c: only poll if the rc device is opened
  media: merge ir_tx_z8f0811_haup and ir_rx_z8f0811_haup i2c devices
  media: rc: implement zilog transmitter
  media: i2c: enable i2c IR for hardware which isn't HD-PVR
  media: staging: remove lirc_zilog driver
  media: MAINTAINERS: remove lirc staging area
  media: lirc: remove LIRCCODE and LIRC_GET_LENGTH
  media: lirc: implement scancode sending
  media: lirc: use the correct carrier for scancode transmit
  media: rc: auto load encoder if necessary
  media: lirc: lirc interface should not be a raw decoder
  media: lirc: validate scancode for transmit
  media: rc: document and fix rc_validate_scancode()
  media: lirc: merge lirc_dev_fop_ioctl and ir_lirc_ioctl
  media: lirc: use kfifo rather than lirc_buffer for raw IR
  media: lirc: move lirc_dev->attached to rc_dev->registered
  media: lirc: do not call rc_close() on unregistered devices
  media: lirc: create rc-core open and close lirc functions
  media: lirc: remove name from lirc_dev
  media: lirc: remove last remnants of lirc kapi
  media: lirc: implement reading scancode
  media: rc: ensure lirc device receives nec repeats
  media: lirc: document LIRC_MODE_SCANCODE
  media: lirc: introduce LIRC_SET_POLL_MODES
  media: lirc: scancode rc devices should have a lirc device too
  kfifo: DECLARE_KIFO_PTR(fifo, u64) does not work on arm 32 bit

 Documentation/media/kapi/rc-core.rst   |5 -
 Documentation/media/lirc.h.rst.exceptions  |   31 +
 Documentation/media/uapi/rc/lirc-dev-intro.rst |   68 +-
 Documentation/media/uapi/rc/lirc-func.rst  |2 +-
 Documentation/media/uapi/rc/lirc-get-features.rst  |   17 +-
 Documentation/media/uapi/rc/lirc-get-length.rst|   44 -
 Documentation/media/uapi/rc/lirc-get-rec-mode.rst  |5 +-
 Documentation/media/uapi/rc/lirc-get-send-mode.rst |2 +-
 Documentation/media/uapi/rc/lirc-read.rst  |   15 +-
 .../media/uapi/rc/lirc-set-poll-modes.rst  |   52 +
 Documentation/media/uapi/rc/lirc-write.rst |   19 +-
 MAINTAINERS|6 -
 drivers/media/i2c/ir-kbd-i2c.c |  540 ++-
 drivers/media/pci/cx18/cx18-cards.h|8 +-
 drivers/media/pci/cx18/cx18-i2c.c  |   13 +-
 drivers/media/pci/ivtv/ivtv-cards.h|   22 +-
 drivers/media/pci/ivtv/ivtv-i2c.c  |   20 +-
 drivers/media/pci/saa7134/saa7134-input.c  |3 +-
 drivers/media/rc/Kconfig   |   29 +-
 drivers/media/rc/Makefile  |5 +-
 drivers/media/rc/ir-jvc-decoder.c  |1 +
 drivers/media/rc/ir-lirc-codec.c   |  559 ---
 drivers/media/rc/ir-mce_kbd-decoder.c  |   12 +-
 drivers/media/rc/ir-nec-decoder.c  |1 +
 drivers/media/rc/ir-rc5-decoder.c  |1 +
 drivers/media/rc/ir-rc6-decoder.c  |1 +
 drivers/media/rc/ir-sanyo-decoder.c|1 +
 drivers/media/rc/ir-sharp-decoder.c|1 +
 drivers/media/rc/ir-sony-decoder.c |1 +
 drivers/media/rc/lirc_dev.c|  487 +-
 drivers/media/rc/rc-core-priv.h|   54 +-
 drivers/media/rc/rc-ir-raw.c   |   56 +-
 drivers/media/rc/rc-main.c |  166 +-
 drivers/media/usb/hdpvr/hdpvr-core.c   |   11 +-
 drivers/media/usb/hdpvr/hdpvr-i2c.c|   23 +-
 drivers/media/usb/hdpvr/hdpvr.h|3 +-
 drivers/media/usb/pvrusb2/pvrusb2-i2c-core.c   |   13 +-
 drivers/staging/media/Kconfig  |3 -
 

[PATCH 02/28] media: rc: i2c: use dev_dbg rather hand-rolled debug

2017-10-29 Thread Sean Young
Use the dev_dbg dynamic infrastructure instead of rolling our own custom
debug logic.

Signed-off-by: Sean Young 
---
 drivers/media/i2c/ir-kbd-i2c.c | 61 +-
 1 file changed, 25 insertions(+), 36 deletions(-)

diff --git a/drivers/media/i2c/ir-kbd-i2c.c b/drivers/media/i2c/ir-kbd-i2c.c
index 27e36f45286c..1b8cd1b75bfb 100644
--- a/drivers/media/i2c/ir-kbd-i2c.c
+++ b/drivers/media/i2c/ir-kbd-i2c.c
@@ -46,18 +46,6 @@
 #include 
 #include 
 
-/* --- */
-/* insmod parameters   */
-
-static int debug;
-module_param(debug, int, 0644);/* debug level (0,1,2) */
-
-
-#define MODULE_NAME "ir-kbd-i2c"
-#define dprintk(level, fmt, arg...)if (debug >= level) \
-   printk(KERN_DEBUG MODULE_NAME ": " fmt , ## arg)
-
-/* --- */
 
 static int get_key_haup_common(struct IR_i2c *ir, enum rc_proto *protocol,
   u32 *scancode, u8 *ptoggle, int size)
@@ -96,7 +84,8 @@ static int get_key_haup_common(struct IR_i2c *ir, enum 
rc_proto *protocol,
if (!range)
code += 64;
 
-   dprintk(1, "ir hauppauge (rc5): s%d r%d t%d dev=%d code=%d\n",
+   dev_dbg(>rc->dev,
+   "ir hauppauge (rc5): s%d r%d t%d dev=%d code=%d\n",
start, range, toggle, dev, code);
 
*protocol = RC_PROTO_RC5;
@@ -113,13 +102,15 @@ static int get_key_haup_common(struct IR_i2c *ir, enum 
rc_proto *protocol,
*ptoggle = (dev & 0x80) != 0;
*protocol = RC_PROTO_RC6_MCE;
dev &= 0x7f;
-   dprintk(1, "ir hauppauge (rc6-mce): t%d vendor=%d 
dev=%d code=%d\n",
-   *ptoggle, vendor, dev, code);
+   dev_dbg(>rc->dev,
+   "ir hauppauge (rc6-mce): t%d vendor=%d dev=%d 
code=%d\n",
+   *ptoggle, vendor, dev, code);
} else {
*ptoggle = 0;
*protocol = RC_PROTO_RC6_6A_32;
-   dprintk(1, "ir hauppauge (rc6-6a-32): vendor=%d dev=%d 
code=%d\n",
-   vendor, dev, code);
+   dev_dbg(>rc->dev,
+   "ir hauppauge (rc6-6a-32): vendor=%d dev=%d 
code=%d\n",
+   vendor, dev, code);
}
 
*scancode = RC_SCANCODE_RC6_6A(vendor, dev, code);
@@ -162,7 +153,7 @@ static int get_key_pixelview(struct IR_i2c *ir, enum 
rc_proto *protocol,
 
/* poll IR chip */
if (1 != i2c_master_recv(ir->c, , 1)) {
-   dprintk(1,"read error\n");
+   dev_dbg(>rc->dev, "read error\n");
return -EIO;
}
 
@@ -179,13 +170,12 @@ static int get_key_fusionhdtv(struct IR_i2c *ir, enum 
rc_proto *protocol,
 
/* poll IR chip */
if (4 != i2c_master_recv(ir->c, buf, 4)) {
-   dprintk(1,"read error\n");
+   dev_dbg(>rc->dev, "read error\n");
return -EIO;
}
 
-   if(buf[0] !=0 || buf[1] !=0 || buf[2] !=0 || buf[3] != 0)
-   dprintk(2, "%s: 0x%2x 0x%2x 0x%2x 0x%2x\n", __func__,
-   buf[0], buf[1], buf[2], buf[3]);
+   if (buf[0] != 0 || buf[1] != 0 || buf[2] != 0 || buf[3] != 0)
+   dev_dbg(>rc->dev, "%s: %*ph\n", __func__, 4, buf);
 
/* no key pressed or signal from other ir remote */
if(buf[0] != 0x1 ||  buf[1] != 0xfe)
@@ -204,7 +194,7 @@ static int get_key_knc1(struct IR_i2c *ir, enum rc_proto 
*protocol,
 
/* poll IR chip */
if (1 != i2c_master_recv(ir->c, , 1)) {
-   dprintk(1,"read error\n");
+   dev_dbg(>rc->dev, "read error\n");
return -EIO;
}
 
@@ -212,7 +202,7 @@ static int get_key_knc1(struct IR_i2c *ir, enum rc_proto 
*protocol,
   down, while 0xff indicates that no button is hold
   down. 0xfe sequences are sometimes interrupted by 0xFF */
 
-   dprintk(2,"key %02x\n", b);
+   dev_dbg(>rc->dev, "key %02x\n", b);
 
if (b == 0xff)
return 0;
@@ -237,7 +227,7 @@ static int get_key_avermedia_cardbus(struct IR_i2c *ir, 
enum rc_proto *protocol,
  .buf = , .len = 1} };
subaddr = 0x0d;
if (2 != i2c_transfer(ir->c->adapter, msg, 2)) {
-   dprintk(1, "read error\n");
+   dev_dbg(>rc->dev, "read error\n");
return -EIO;
}
 
@@ -247,18 +237,17 @@ static int get_key_avermedia_cardbus(struct IR_i2c *ir, 
enum rc_proto *protocol,
subaddr = 0x0b;
msg[1].buf = 
if (2 != 

Re: 'LITE-ON USB2.0 DVB-T Tune' driver crash with kernel 4.13 / ubuntu 17.10

2017-10-29 Thread Sean Young
On Sun, Oct 29, 2017 at 06:54:28PM +0100, Laurent Caumont wrote:
> Hi Sean,
> 
> I recompiled the modules by following the
> https://www.linuxtv.org/wiki/index.php/How_to_Obtain,_Build_and_Install_V4L-DVB_Device_Drivers
> page and applied the patch.
> But I still have problems (see below). It doesn't seem to be the same 
> callstack.
> Is it the right way to get the fix ?

Yes, it's the right way to get the fix. However, you've hit a new problem
of a similar making. Please can you try with this patch as well:

Thanks
Sean
--- 
>From 84efb0bf72ae5d9183f25d69d95fb9ad9b9bc644 Mon Sep 17 00:00:00 2001
From: Sean Young 
Date: Sun, 29 Oct 2017 19:28:32 +
Subject: [PATCH] media: dibusb: don't do DMA on stack

The USB control messages require DMA to work. We cannot pass
a stack-allocated buffer, as it is not warranted that the
stack would be into a DMA enabled area.

Signed-off-by: Sean Young 
---
 drivers/media/usb/dvb-usb/dibusb-common.c | 14 --
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/media/usb/dvb-usb/dibusb-common.c 
b/drivers/media/usb/dvb-usb/dibusb-common.c
index 8207e6900656..18c6e454b1b7 100644
--- a/drivers/media/usb/dvb-usb/dibusb-common.c
+++ b/drivers/media/usb/dvb-usb/dibusb-common.c
@@ -223,8 +223,18 @@ EXPORT_SYMBOL(dibusb_i2c_algo);
 
 int dibusb_read_eeprom_byte(struct dvb_usb_device *d, u8 offs, u8 *val)
 {
-   u8 wbuf[1] = { offs };
-   return dibusb_i2c_msg(d, 0x50, wbuf, 1, val, 1);
+   u8 *wbuf;
+   int rc;
+
+   wbuf = kmalloc(1, GFP_KERNEL);
+   if (!wbuf)
+   return -ENOMEM;
+
+   *wbuf = offs;
+   rc = dibusb_i2c_msg(d, 0x50, wbuf, 1, val, 1);
+   kfree(wbuf);
+
+   return rc;
 }
 EXPORT_SYMBOL(dibusb_read_eeprom_byte);
 
-- 
2.13.6



Re: 'LITE-ON USB2.0 DVB-T Tune' driver crash with kernel 4.13 / ubuntu 17.10

2017-10-29 Thread Laurent Caumont
Hi Sean,

I recompiled the modules by following the
https://www.linuxtv.org/wiki/index.php/How_to_Obtain,_Build_and_Install_V4L-DVB_Device_Drivers
page and applied the patch.
But I still have problems (see below). It doesn't seem to be the same callstack.
Is it the right way to get the fix ?

Thanks.
Regards,
Laurent

[   14.625565] CPU: 2 PID: 45 Comm: kworker/2:1 Tainted: GW
OE   4.13.0-16-generic #19-Ubuntu
[   14.625565] Hardware name: System manufacturer System Product
Name/H110I-PLUS, BIOS 0406 11/16/2015
[   14.625567] Workqueue: usb_hub_wq hub_event
[   14.625568] task: 9928b1c897c0 task.stack: ab7880e1
[   14.625569] RIP: 0010:usb_hcd_map_urb_for_dma+0x41d/0x620
[   14.625570] RSP: :ab7880e13458 EFLAGS: 00010282
[   14.625571] RAX: 001f RBX: 9928b0350540 RCX: 0006
[   14.625571] RDX:  RSI: 0096 RDI: 9928bbd0dc70
[   14.625572] RBP: ab7880e13498 R08: 0001 R09: 03dc
[   14.625572] R10: 0001 R11:  R12: fff5
[   14.625573] R13: 0140 R14: 0002 R15: 9928b1c5a000
[   14.625574] FS:  () GS:9928bbd0()
knlGS:
[   14.625574] CS:  0010 DS:  ES:  CR0: 80050033
[   14.625575] CR2: 5621442492d8 CR3: 00022b4b3000 CR4: 003406e0
[   14.625575] Call Trace:
[   14.625578]  usb_hcd_submit_urb+0x4ab/0xb70
[   14.625580]  ? del_timer_sync+0x39/0x40
[   14.625581]  ? schedule_timeout+0x18a/0x350
[   14.625582]  ? call_timer_fn+0x130/0x130
[   14.625583]  usb_submit_urb+0x22d/0x560
[   14.625584]  ? wake_up_q+0x80/0x80
[   14.625586]  usb_start_wait_urb+0x6e/0x180
[   14.625586]  usb_bulk_msg+0xb8/0x160
[   14.625589]  dvb_usb_generic_rw+0x189/0x2e0 [dvb_usb]
[   14.625591]  dibusb_i2c_msg+0xe1/0x130 [dvb_usb_dibusb_common]
[   14.625592]  dibusb_read_eeprom_byte+0x3c/0x60 [dvb_usb_dibusb_common]
[   14.625593]  dibusb_dib3000mc_tuner_attach+0xed/0xe90
[dvb_usb_dibusb_mc_common]
[   14.625595]  dvb_usb_adapter_frontend_init+0xb5/0x1d0 [dvb_usb]
[   14.625596]  dvb_usb_device_init+0x548/0x740 [dvb_usb]
[   14.625598]  ? kernfs_add_one+0xe4/0x130
[   14.625599]  dibusb_mc_probe+0x25/0x27 [dvb_usb_dibusb_mc]
[   14.625601]  usb_probe_interface+0x124/0x300
[   14.625602]  driver_probe_device+0x2ff/0x450
[   14.625603]  __device_attach_driver+0x83/0x100
[   14.625604]  ? __driver_attach+0xe0/0xe0
[   14.625605]  bus_for_each_drv+0x69/0xb0
[   14.625606]  __device_attach+0xdd/0x160
[   14.625607]  device_initial_probe+0x13/0x20
[   14.625608]  bus_probe_device+0x92/0xa0
[   14.625610]  device_add+0x448/0x680
[   14.625610]  usb_set_configuration+0x505/0x850
[   14.625612]  generic_probe+0x2e/0x80
[   14.625613]  usb_probe_device+0x2e/0x60
[   14.625613]  driver_probe_device+0x2ff/0x450
[   14.625614]  __device_attach_driver+0x83/0x100
[   14.625615]  ? __driver_attach+0xe0/0xe0
[   14.625616]  bus_for_each_drv+0x69/0xb0
[   14.625617]  __device_attach+0xdd/0x160
[   14.625618]  device_initial_probe+0x13/0x20
[   14.625619]  bus_probe_device+0x92/0xa0
[   14.625620]  device_add+0x448/0x680
[   14.625622]  ? add_device_randomness+0x9a/0x110
[   14.625623]  usb_new_device+0x269/0x490
[   14.625625]  hub_port_connect+0x62d/0x9f0
[   14.625626]  port_event+0x586/0x6b0
[   14.625627]  hub_event+0x2e0/0x3a0
[   14.625629]  process_one_work+0x1e7/0x410
[   14.625630]  worker_thread+0x4a/0x410
[   14.625631]  kthread+0x125/0x140
[   14.625632]  ? process_one_work+0x410/0x410
[   14.625633]  ? kthread_create_on_node+0x70/0x70
[   14.625634]  ret_from_fork+0x25/0x30
[   14.625634] Code: 48 39 c8 73 30 80 3d 76 66 96 00 00 41 bc f5 ff
ff ff 0f 85 26 ff ff ff 48 c7 c7 a0 20 73 be c6 05 5c 66 96 00 01 e8
64 47 a3 ff <0f> ff 8b 53 64 e9 09 ff ff ff 65 48 8b 0c 25 00 d3 00 00
48 8b
[   14.625651] ---[ end trace ebcd73627fe6fcd1 ]---
[   14.625652] dvb-usb: recv bulk message failed: -11
[   14.625792] dvb-usb: recv bulk message failed: -11
[   14.625794] dibusb: LITE-ON DVB-T: Strange IF1 calibration :FF FF


2017-10-23 20:57 GMT+02:00 Sean Young :
> Hi Laurent,
>
> Please reply to the list.
>
> On Mon, Oct 23, 2017 at 08:48:14PM +0200, Laurent Caumont wrote:
>> I'm sorry, the log has been cut when I copy-past it.
>> Here is the rest:
>> (The crash of the intel driver doesn't seem to make issue to my display.)
>>
>> [   12.013019] dvb-usb: found a 'LITE-ON USB2.0 DVB-T Tuner' in warm state.
>> [   12.013086] dvb-usb: will pass the complete MPEG2 transport stream
>> to the software demuxer.
>> [   12.017153] dvbdev: DVB: registering new adapter (LITE-ON USB2.0 DVB-T 
>> Tuner)
>> [   12.576681] r8169 :03:00.0 enp3s0: link up
>> [   12.576687] IPv6: ADDRCONF(NETDEV_CHANGE): enp3s0: link becomes ready
>> [   12.680633] FS-Cache: Loaded
>> [   12.702899] FS-Cache: Netfs 'cifs' registered for caching
>> [   12.702965] Key type cifs.spnego registered
>> [   12.702967] Key 

[PATCH] [media] dvb-core: always call invoke_release() in fe_free()

2017-10-29 Thread Daniel Scheller
From: Daniel Scheller 

Follow-up to: ead666000a5f ("media: dvb_frontend: only use kref after 
initialized")

The aforementioned commit fixed refcount OOPSes when demod driver attaching
succeeded but tuner driver didn't. However, the use count of the attached
demod drivers don't go back to zero and thus couldn't be cleanly unloaded.
Improve on this by calling dvb_frontend_invoke_release() in
__dvb_frontend_free() regardless of fepriv being NULL, instead of returning
when fepriv is NULL. This is safe to do since _invoke_release() will check
for passed pointers being valid before calling the .release() function.

Signed-off-by: Daniel Scheller 

---
I discovered, checked and tested this with ddbridge, which, in
ddbridge-core.c:dvb_input_attach(), follows this common logic:

* attach demod
* if demod ok, attach tuner
* if tuner attach ok, proceed with dvb_reg_fe()
* else (tuner attach NOK): dvb_fe_detach(demod)

Without ead666000a5f, this caused refcount OOPSes when - at the latest -
unloading the kernel modules. This doesn't happen any more, yet the
loaded drivers still have a >0 use count. At first I tested calling
dvb_register_device() directly followed by dvb_unregister_device() on
the failure case, which worked but obviously isn't what is wanted. With
this patch, all refs are finally freed, drivers have a zero use count
on failure and can be unloaded cleanly.

Since dvb_frontend_invoke_release() checks the passed pointers before
calling them, I believe this is a safe thing to do.

 drivers/media/dvb-core/dvb_frontend.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/media/dvb-core/dvb_frontend.c 
b/drivers/media/dvb-core/dvb_frontend.c
index daaf969719e4..bda1eac8f4c0 100644
--- a/drivers/media/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb-core/dvb_frontend.c
@@ -145,15 +145,15 @@ static void __dvb_frontend_free(struct dvb_frontend *fe)
 {
struct dvb_frontend_private *fepriv = fe->frontend_priv;
 
-   if (!fepriv)
-   return;
-
-   dvb_free_device(fepriv->dvbdev);
+   if (fepriv)
+   dvb_free_device(fepriv->dvbdev);
 
dvb_frontend_invoke_release(fe, fe->ops.release);
 
-   kfree(fepriv);
-   fe->frontend_priv = NULL;
+   if (fepriv) {
+   kfree(fepriv);
+   fe->frontend_priv = NULL;
+   }
 }
 
 static void dvb_frontend_free(struct kref *ref)
-- 
2.13.6



[PATCH][V2] bdisp: remove redundant assignment to pix

2017-10-29 Thread Colin King
From: Colin Ian King 

Pointer pix is being initialized to a value and a little later
being assigned the same value again. Remove the initial assignment to
avoid a duplicate assignment. Cleans up the clang warning:

drivers/media/platform/sti/bdisp/bdisp-v4l2.c:726:26: warning: Value
stored to 'pix' during its initialization is never read

Signed-off-by: Colin Ian King 
---
 drivers/media/platform/sti/bdisp/bdisp-v4l2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/sti/bdisp/bdisp-v4l2.c 
b/drivers/media/platform/sti/bdisp/bdisp-v4l2.c
index 939da6da7644..7e9ed9c7b3e1 100644
--- a/drivers/media/platform/sti/bdisp/bdisp-v4l2.c
+++ b/drivers/media/platform/sti/bdisp/bdisp-v4l2.c
@@ -723,7 +723,7 @@ static int bdisp_enum_fmt(struct file *file, void *fh, 
struct v4l2_fmtdesc *f)
 static int bdisp_g_fmt(struct file *file, void *fh, struct v4l2_format *f)
 {
struct bdisp_ctx *ctx = fh_to_ctx(fh);
-   struct v4l2_pix_format *pix = >fmt.pix;
+   struct v4l2_pix_format *pix;
struct bdisp_frame *frame  = ctx_get_frame(ctx, f->type);
 
if (IS_ERR(frame)) {
-- 
2.14.1



[GIT PULL FOR v4.15] ids and RC timer API change

2017-10-29 Thread Sean Young
Hi Mauro,

Here the timer updates and some IDs for mceusb and cx231xx.

Thanks
Sean

The following changes since commit bbae615636155fa43a9b0fe0ea31c678984be864:

  media: staging: atomisp2: cleanup null check on memory allocation (2017-10-27 
17:33:39 +0200)

are available in the git repository at:

  git://linuxtv.org/syoung/media_tree.git for-v4.15d

for you to fetch changes up to 1bfd8c214a396fb51f8428bfda66c2eff6076f12:

  media: cx231xx: Fix NTSC/PAL on Astrometa T2hybrid (2017-10-29 12:09:14 +)


Kees Cook (1):
  media: rc: Convert timers to use timer_setup()

Oleh Kravchenko (5):
  media: rc: mceusb: add support for 1b80:d3b2
  media: rc: Add Astrometa T2hybrid keymap module
  media: rc: mceusb: add support for 15f4:0135
  media: cx231xx: Fix NTSC/PAL on Evromedia USB Full Hybrid Full HD
  media: cx231xx: Fix NTSC/PAL on Astrometa T2hybrid

 drivers/media/rc/ene_ir.c|  7 +--
 drivers/media/rc/igorplugusb.c   |  6 +-
 drivers/media/rc/img-ir/img-ir-hw.c  | 13 ++---
 drivers/media/rc/img-ir/img-ir-raw.c |  6 +-
 drivers/media/rc/imon.c  |  7 +--
 drivers/media/rc/ir-mce_kbd-decoder.c|  7 +--
 drivers/media/rc/keymaps/Makefile|  1 +
 drivers/media/rc/keymaps/rc-astrometa-t2hybrid.c | 70 
 drivers/media/rc/mceusb.c| 18 ++
 drivers/media/rc/rc-ir-raw.c |  8 +--
 drivers/media/rc/rc-main.c   |  7 +--
 drivers/media/rc/sir_ir.c|  4 +-
 drivers/media/usb/cx231xx/cx231xx-cards.c|  3 +-
 include/media/rc-map.h   |  1 +
 14 files changed, 122 insertions(+), 36 deletions(-)
 create mode 100644 drivers/media/rc/keymaps/rc-astrometa-t2hybrid.c


Re: [PATCH] [media] bdisp: remove redundant assignment to pix

2017-10-29 Thread Colin Ian King
On 29/10/17 13:30, Julia Lawall wrote:
> 
> 
> On Sun, 29 Oct 2017, Colin King wrote:
> 
>> From: Colin Ian King 
>>
>> Pointer pix is being initialized to a value and a little later
>> being assigned the same value again. Remove the redundant second
>> duplicate assignment. Cleans up the clang warning:
>>
>> drivers/media/platform/sti/bdisp/bdisp-v4l2.c:726:26: warning: Value
>> stored to 'pix' during its initialization is never read
>>
>> Signed-off-by: Colin Ian King 
>> ---
>>  drivers/media/platform/sti/bdisp/bdisp-v4l2.c | 1 -
>>  1 file changed, 1 deletion(-)
>>
>> diff --git a/drivers/media/platform/sti/bdisp/bdisp-v4l2.c 
>> b/drivers/media/platform/sti/bdisp/bdisp-v4l2.c
>> index 939da6da7644..14e99aeae140 100644
>> --- a/drivers/media/platform/sti/bdisp/bdisp-v4l2.c
>> +++ b/drivers/media/platform/sti/bdisp/bdisp-v4l2.c
>> @@ -731,7 +731,6 @@ static int bdisp_g_fmt(struct file *file, void *fh, 
>> struct v4l2_format *f)
>>  return PTR_ERR(frame);
>>  }
>>
>> -pix = >fmt.pix;
> 
> Why not keep this one and drop the first one?  Maybe it would be nice to
> keep all the initializations related to pix together?

Good point. Will send a V2.

> 
> julia
> 
>>  pix->width = frame->width;
>>  pix->height = frame->height;
>>  pix->pixelformat = frame->fmt->pixelformat;
>> --
>> 2.14.1
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
>> the body of a message to majord...@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>>



Re: [PATCH] [media] bdisp: remove redundant assignment to pix

2017-10-29 Thread Julia Lawall


On Sun, 29 Oct 2017, Colin King wrote:

> From: Colin Ian King 
>
> Pointer pix is being initialized to a value and a little later
> being assigned the same value again. Remove the redundant second
> duplicate assignment. Cleans up the clang warning:
>
> drivers/media/platform/sti/bdisp/bdisp-v4l2.c:726:26: warning: Value
> stored to 'pix' during its initialization is never read
>
> Signed-off-by: Colin Ian King 
> ---
>  drivers/media/platform/sti/bdisp/bdisp-v4l2.c | 1 -
>  1 file changed, 1 deletion(-)
>
> diff --git a/drivers/media/platform/sti/bdisp/bdisp-v4l2.c 
> b/drivers/media/platform/sti/bdisp/bdisp-v4l2.c
> index 939da6da7644..14e99aeae140 100644
> --- a/drivers/media/platform/sti/bdisp/bdisp-v4l2.c
> +++ b/drivers/media/platform/sti/bdisp/bdisp-v4l2.c
> @@ -731,7 +731,6 @@ static int bdisp_g_fmt(struct file *file, void *fh, 
> struct v4l2_format *f)
>   return PTR_ERR(frame);
>   }
>
> - pix = >fmt.pix;

Why not keep this one and drop the first one?  Maybe it would be nice to
keep all the initializations related to pix together?

julia

>   pix->width = frame->width;
>   pix->height = frame->height;
>   pix->pixelformat = frame->fmt->pixelformat;
> --
> 2.14.1
>
> --
> To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>


[PATCH] [media] bdisp: remove redundant assignment to pix

2017-10-29 Thread Colin King
From: Colin Ian King 

Pointer pix is being initialized to a value and a little later
being assigned the same value again. Remove the redundant second
duplicate assignment. Cleans up the clang warning:

drivers/media/platform/sti/bdisp/bdisp-v4l2.c:726:26: warning: Value
stored to 'pix' during its initialization is never read

Signed-off-by: Colin Ian King 
---
 drivers/media/platform/sti/bdisp/bdisp-v4l2.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/media/platform/sti/bdisp/bdisp-v4l2.c 
b/drivers/media/platform/sti/bdisp/bdisp-v4l2.c
index 939da6da7644..14e99aeae140 100644
--- a/drivers/media/platform/sti/bdisp/bdisp-v4l2.c
+++ b/drivers/media/platform/sti/bdisp/bdisp-v4l2.c
@@ -731,7 +731,6 @@ static int bdisp_g_fmt(struct file *file, void *fh, struct 
v4l2_format *f)
return PTR_ERR(frame);
}
 
-   pix = >fmt.pix;
pix->width = frame->width;
pix->height = frame->height;
pix->pixelformat = frame->fmt->pixelformat;
-- 
2.14.1



[PATCH] [media] gspca: remove redundant assignment to variable j

2017-10-29 Thread Colin King
From: Colin Ian King 

Variable j is being set to zero before a loop and also
immediately inside the loop and is not used after the loop.
Hence the first assignment is redundant and can be removed.
Cleans up clang warning:

drivers/media/usb/gspca/gspca.c:1078:2: warning: Value stored
to 'j' is never read

Signed-off-by: Colin Ian King 
---
 drivers/media/usb/gspca/gspca.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/media/usb/gspca/gspca.c b/drivers/media/usb/gspca/gspca.c
index 0f141762abf1..961343873fd0 100644
--- a/drivers/media/usb/gspca/gspca.c
+++ b/drivers/media/usb/gspca/gspca.c
@@ -1075,7 +1075,6 @@ static int vidioc_enum_fmt_vid_cap(struct file *file, 
void  *priv,
 
/* give an index to each format */
index = 0;
-   j = 0;
for (i = gspca_dev->cam.nmodes; --i >= 0; ) {
fmt_tb[index] = gspca_dev->cam.cam_mode[i].pixelformat;
j = 0;
-- 
2.14.1



[PATCH] [media] mxl111sf: remove redundant assignment to index

2017-10-29 Thread Colin King
From: Colin Ian King 

Variable index is set to zero and then set to zero again
a few lines later in a for loop initialization. Remove the
redundant setting of index to zero. Cleans up the clang
warning:

drivers/media/usb/dvb-usb-v2/mxl111sf-i2c.c:519:3: warning: Value
stored to 'index' is never read

Signed-off-by: Colin Ian King 
---
 drivers/media/usb/dvb-usb-v2/mxl111sf-i2c.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/media/usb/dvb-usb-v2/mxl111sf-i2c.c 
b/drivers/media/usb/dvb-usb-v2/mxl111sf-i2c.c
index 0eb33e043079..a221bb8a12b4 100644
--- a/drivers/media/usb/dvb-usb-v2/mxl111sf-i2c.c
+++ b/drivers/media/usb/dvb-usb-v2/mxl111sf-i2c.c
@@ -516,7 +516,6 @@ static int mxl111sf_i2c_hw_xfer_msg(struct mxl111sf_state 
*state,
   data required to program */
block_len = (msg->len / 8);
left_over_len = (msg->len % 8);
-   index = 0;
 
mxl_i2c("block_len %d, left_over_len %d",
block_len, left_over_len);
-- 
2.14.1