cron job: media_tree daily build: ERRORS

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

Results of the daily build of media_tree:

date:   Sat Sep  3 04:00:15 CEST 2016
git branch: test
git hash:   fb6609280db902bd5d34445fba1c926e95e63914
gcc version:i686-linux-gcc (GCC) 5.4.0
sparse version: v0.5.0-56-g7647c77
smatch version: v0.5.0-3428-gdfe27cf
host hardware:  x86_64
host os:4.6.0-164

linux-git-arm-at91: OK
linux-git-arm-davinci: OK
linux-git-arm-multi: OK
linux-git-blackfin-bf561: OK
linux-git-i686: OK
linux-git-m32r: OK
linux-git-mips: OK
linux-git-powerpc64: OK
linux-git-sh: OK
linux-git-x86_64: WARNINGS
linux-2.6.36.4-i686: OK
linux-2.6.37.6-i686: OK
linux-2.6.38.8-i686: OK
linux-2.6.39.4-i686: OK
linux-3.0.60-i686: OK
linux-3.1.10-i686: OK
linux-3.2.37-i686: OK
linux-3.3.8-i686: OK
linux-3.4.27-i686: OK
linux-3.5.7-i686: OK
linux-3.6.11-i686: OK
linux-3.7.4-i686: OK
linux-3.8-i686: OK
linux-3.9.2-i686: OK
linux-3.10.1-i686: OK
linux-3.11.1-i686: OK
linux-3.12.23-i686: OK
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: OK
linux-3.18.7-i686: OK
linux-3.19-i686: OK
linux-4.0-i686: OK
linux-4.1.1-i686: OK
linux-4.2-i686: OK
linux-4.3-i686: OK
linux-4.4-i686: OK
linux-4.5-i686: OK
linux-4.6-i686: OK
linux-4.7-i686: OK
linux-4.8-rc1-i686: OK
linux-2.6.36.4-x86_64: OK
linux-2.6.37.6-x86_64: OK
linux-2.6.38.8-x86_64: OK
linux-2.6.39.4-x86_64: OK
linux-3.0.60-x86_64: OK
linux-3.1.10-x86_64: OK
linux-3.2.37-x86_64: OK
linux-3.3.8-x86_64: OK
linux-3.4.27-x86_64: OK
linux-3.5.7-x86_64: OK
linux-3.6.11-x86_64: OK
linux-3.7.4-x86_64: OK
linux-3.8-x86_64: OK
linux-3.9.2-x86_64: OK
linux-3.10.1-x86_64: OK
linux-3.11.1-x86_64: OK
linux-3.12.23-x86_64: OK
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: OK
linux-3.18.7-x86_64: OK
linux-3.19-x86_64: OK
linux-4.0-x86_64: OK
linux-4.1.1-x86_64: OK
linux-4.2-x86_64: OK
linux-4.3-x86_64: OK
linux-4.4-x86_64: OK
linux-4.5-x86_64: OK
linux-4.6-x86_64: OK
linux-4.7-x86_64: OK
linux-4.8-rc1-x86_64: OK
apps: WARNINGS
spec-git: OK
sparse: WARNINGS
smatch: WARNINGS

Detailed results are available here:

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

Full logs are available here:

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

The Media Infrastructure API from this daily build is here:

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


[GIT PULL STABLE 4.6] af9035 regression

2016-09-02 Thread Antti Palosaari

The following changes since commit 2dcd0af568b0cf583645c8a317dd12e344b1c72a:

  Linux 4.6 (2016-05-15 15:43:13 -0700)

are available in the git repository at:

  git://linuxtv.org/anttip/media_tree.git af9035_fix

for you to fetch changes up to 7bb87ff5255defe87916f32cd1fcef163a489339:

  af9035: fix dual tuner detection with PCTV 79e (2016-09-03 02:23:44 
+0300)



Stefan Pöschel (1):
  af9035: fix dual tuner detection with PCTV 79e

 drivers/media/usb/dvb-usb-v2/af9035.c | 53 
+++--

 drivers/media/usb/dvb-usb-v2/af9035.h |  2 +-
 2 files changed, 36 insertions(+), 19 deletions(-)

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


[PATCH] af9035: fix dual tuner detection with PCTV 79e

2016-09-02 Thread Antti Palosaari
From: Stefan Pöschel 

The value 5 of the EEPROM_TS_MODE register (meaning dual tuner presence) is
only valid for AF9035 devices. For IT9135 devices it is invalid and led to a
false positive dual tuner mode detection with PCTV 79e.
Therefore on non-AF9035 devices and with value 5 the driver now defaults to
single tuner mode and outputs a regarding info message to log.

This fixes Bugzilla bug #118561.

(backport of 4.7)

Fixes: b8278f8b961a ("[media] af9035: add support for 2nd tuner of MSI DigiVox 
Diversity")
Cc:  # 4.6
Reported-by: Marc Duponcheel 
Signed-off-by: Stefan Pöschel 
Signed-off-by: Antti Palosaari 
---
 drivers/media/usb/dvb-usb-v2/af9035.c | 53 +++
 drivers/media/usb/dvb-usb-v2/af9035.h |  2 +-
 2 files changed, 36 insertions(+), 19 deletions(-)

diff --git a/drivers/media/usb/dvb-usb-v2/af9035.c 
b/drivers/media/usb/dvb-usb-v2/af9035.c
index 2638e32..14dbfeb 100644
--- a/drivers/media/usb/dvb-usb-v2/af9035.c
+++ b/drivers/media/usb/dvb-usb-v2/af9035.c
@@ -475,7 +475,8 @@ static struct i2c_algorithm af9035_i2c_algo = {
 static int af9035_identify_state(struct dvb_usb_device *d, const char **name)
 {
struct state *state = d_to_priv(d);
-   int ret;
+   int ret, ts_mode_invalid;
+   u8 tmp;
u8 wbuf[1] = { 1 };
u8 rbuf[4];
struct usb_req req = { CMD_FW_QUERYINFO, 0, sizeof(wbuf), wbuf,
@@ -511,6 +512,38 @@ static int af9035_identify_state(struct dvb_usb_device *d, 
const char **name)
state->eeprom_addr = EEPROM_BASE_AF9035;
}
 
+
+   /* check for dual tuner mode */
+   ret = af9035_rd_reg(d, state->eeprom_addr + EEPROM_TS_MODE, );
+   if (ret < 0)
+   goto err;
+
+   ts_mode_invalid = 0;
+   switch (tmp) {
+   case 0:
+   break;
+   case 1:
+   case 3:
+   state->dual_mode = true;
+   break;
+   case 5:
+   if (state->chip_type != 0x9135 && state->chip_type != 0x9306)
+   state->dual_mode = true;/* AF9035 */
+   else
+   ts_mode_invalid = 1;
+   break;
+   default:
+   ts_mode_invalid = 1;
+   }
+
+   dev_dbg(>udev->dev, "%s: ts mode=%d dual mode=%d\n",
+   __func__, tmp, state->dual_mode);
+
+   if (ts_mode_invalid)
+   dev_info(>udev->dev, "%s: ts mode=%d not supported, 
defaulting to single tuner mode!",
+   __func__, tmp);
+
+
ret = af9035_ctrl_msg(d, );
if (ret < 0)
goto err;
@@ -680,11 +713,7 @@ static int af9035_download_firmware(struct dvb_usb_device 
*d,
 * which is done by master demod.
 * Master feeds also clock and controls power via GPIO.
 */
-   ret = af9035_rd_reg(d, state->eeprom_addr + EEPROM_TS_MODE, );
-   if (ret < 0)
-   goto err;
-
-   if (tmp == 1 || tmp == 3 || tmp == 5) {
+   if (state->dual_mode) {
/* configure gpioh1, reset & power slave demod */
ret = af9035_wr_reg_mask(d, 0x00d8b0, 0x01, 0x01);
if (ret < 0)
@@ -817,18 +846,6 @@ static int af9035_read_config(struct dvb_usb_device *d)
}
 
 
-
-   /* check if there is dual tuners */
-   ret = af9035_rd_reg(d, state->eeprom_addr + EEPROM_TS_MODE, );
-   if (ret < 0)
-   goto err;
-
-   if (tmp == 1 || tmp == 3 || tmp == 5)
-   state->dual_mode = true;
-
-   dev_dbg(>udev->dev, "%s: ts mode=%d dual mode=%d\n", __func__,
-   tmp, state->dual_mode);
-
if (state->dual_mode) {
/* read 2nd demodulator I2C address */
ret = af9035_rd_reg(d,
diff --git a/drivers/media/usb/dvb-usb-v2/af9035.h 
b/drivers/media/usb/dvb-usb-v2/af9035.h
index df22001..d50ff15 100644
--- a/drivers/media/usb/dvb-usb-v2/af9035.h
+++ b/drivers/media/usb/dvb-usb-v2/af9035.h
@@ -112,7 +112,7 @@ static const u32 clock_lut_it9135[] = {
  * 0  TS
  * 1  DCA + PIP
  * 3  PIP
- * 5  DCA + PIP
+ * 5  DCA + PIP (AF9035 only)
  * n  DCA
  *
  * Values 0, 3 and 5 are seen to this day. 0 for single TS and 3/5 for dual TS.
-- 
http://palosaari.fi/

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


[PATCH 4/9] cxd2820r: dvbv5 statistics for DVB-C

2016-09-02 Thread Antti Palosaari
Implement dvbv5 statistics for DVB-C.

Signed-off-by: Antti Palosaari 
---
 drivers/media/dvb-frontends/cxd2820r_c.c | 104 ++-
 1 file changed, 102 insertions(+), 2 deletions(-)

diff --git a/drivers/media/dvb-frontends/cxd2820r_c.c 
b/drivers/media/dvb-frontends/cxd2820r_c.c
index 957ec94..7cdcd55 100644
--- a/drivers/media/dvb-frontends/cxd2820r_c.c
+++ b/drivers/media/dvb-frontends/cxd2820r_c.c
@@ -260,11 +260,13 @@ int cxd2820r_read_ucblocks_c(struct dvb_frontend *fe, u32 
*ucblocks)
 int cxd2820r_read_status_c(struct dvb_frontend *fe, enum fe_status *status)
 {
struct cxd2820r_priv *priv = fe->demodulator_priv;
+   struct dtv_frontend_properties *c = >dtv_property_cache;
int ret;
-   u8 buf[2];
+   unsigned int utmp;
+   u8 buf[3];
*status = 0;
 
-   ret = cxd2820r_rd_regs(priv, 0x10088, buf, sizeof(buf));
+   ret = cxd2820r_rd_regs(priv, 0x10088, buf, 2);
if (ret)
goto error;
 
@@ -281,6 +283,104 @@ int cxd2820r_read_status_c(struct dvb_frontend *fe, enum 
fe_status *status)
dev_dbg(>i2c->dev, "%s: lock=%02x %02x\n", __func__, buf[0],
buf[1]);
 
+   /* Signal strength */
+   if (*status & FE_HAS_SIGNAL) {
+   unsigned int strength;
+
+   ret = cxd2820r_rd_regs(priv, 0x10049, buf, 2);
+   if (ret)
+   goto error;
+
+   utmp = buf[0] << 8 | buf[1] << 0;
+   utmp = 511 - sign_extend32(utmp, 9);
+   /* Scale value to 0x-0x */
+   strength = utmp << 6 | utmp >> 4;
+
+   c->strength.len = 1;
+   c->strength.stat[0].scale = FE_SCALE_RELATIVE;
+   c->strength.stat[0].uvalue = strength;
+   } else {
+   c->strength.len = 1;
+   c->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+   }
+
+   /* CNR */
+   if (*status & FE_HAS_VITERBI) {
+   unsigned int cnr, const_a, const_b;
+
+   ret = cxd2820r_rd_reg(priv, 0x10019, [0]);
+   if (ret)
+   goto error;
+
+   if (((buf[0] >> 0) & 0x03) % 2) {
+   const_a = 8750;
+   const_b = 650;
+   } else {
+   const_a = 9500;
+   const_b = 760;
+   }
+
+   ret = cxd2820r_rd_reg(priv, 0x1004d, [0]);
+   if (ret)
+   goto error;
+
+   utmp = buf[0] << 0;
+   #define CXD2820R_LOG2_E_24 24204406 /* log2(e) << 24 */
+   if (utmp)
+   cnr = div_u64((u64)(intlog2(const_b) - intlog2(utmp))
+ * const_a, CXD2820R_LOG2_E_24);
+   else
+   cnr = 0;
+
+   c->cnr.len = 1;
+   c->cnr.stat[0].scale = FE_SCALE_DECIBEL;
+   c->cnr.stat[0].svalue = cnr;
+   } else {
+   c->cnr.len = 1;
+   c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+   }
+
+   /* BER */
+   if (*status & FE_HAS_SYNC) {
+   unsigned int post_bit_error;
+   bool start_ber;
+
+   if (priv->ber_running) {
+   ret = cxd2820r_rd_regs(priv, 0x10076, buf, 3);
+   if (ret)
+   goto error;
+
+   if ((buf[2] >> 7) & 0x01) {
+   post_bit_error = buf[2] << 16 | buf[1] << 8 |
+buf[0] << 0;
+   post_bit_error &= 0x0f;
+   start_ber = true;
+   } else {
+   post_bit_error = 0;
+   start_ber = false;
+   }
+   } else {
+   post_bit_error = 0;
+   start_ber = true;
+   }
+
+   if (start_ber) {
+   ret = cxd2820r_wr_reg(priv, 0x10079, 0x01);
+   if (ret)
+   goto error;
+   priv->ber_running = true;
+   }
+
+   priv->post_bit_error += post_bit_error;
+
+   c->post_bit_error.len = 1;
+   c->post_bit_error.stat[0].scale = FE_SCALE_COUNTER;
+   c->post_bit_error.stat[0].uvalue = priv->post_bit_error;
+   } else {
+   c->post_bit_error.len = 1;
+   c->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+   }
+
return ret;
 error:
dev_dbg(>i2c->dev, "%s: failed=%d\n", __func__, ret);
-- 
http://palosaari.fi/

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

[PATCH 3/9] cxd2820r: dvbv5 statistics for DVB-T2

2016-09-02 Thread Antti Palosaari
Implement dvbv5 statistics for DVB-T2.

Signed-off-by: Antti Palosaari 
---
 drivers/media/dvb-frontends/cxd2820r_t2.c | 77 ++-
 1 file changed, 76 insertions(+), 1 deletion(-)

diff --git a/drivers/media/dvb-frontends/cxd2820r_t2.c 
b/drivers/media/dvb-frontends/cxd2820r_t2.c
index 14c9a26..e2875f2 100644
--- a/drivers/media/dvb-frontends/cxd2820r_t2.c
+++ b/drivers/media/dvb-frontends/cxd2820r_t2.c
@@ -286,8 +286,10 @@ error:
 int cxd2820r_read_status_t2(struct dvb_frontend *fe, enum fe_status *status)
 {
struct cxd2820r_priv *priv = fe->demodulator_priv;
+   struct dtv_frontend_properties *c = >dtv_property_cache;
int ret;
-   u8 buf[1];
+   unsigned int utmp;
+   u8 buf[4];
*status = 0;
 
ret = cxd2820r_rd_reg(priv, 0x02010 , [0]);
@@ -306,6 +308,79 @@ int cxd2820r_read_status_t2(struct dvb_frontend *fe, enum 
fe_status *status)
 
dev_dbg(>i2c->dev, "%s: lock=%02x\n", __func__, buf[0]);
 
+   /* Signal strength */
+   if (*status & FE_HAS_SIGNAL) {
+   unsigned int strength;
+
+   ret = cxd2820r_rd_regs(priv, 0x02026, buf, 2);
+   if (ret)
+   goto error;
+
+   utmp = buf[0] << 8 | buf[1] << 0;
+   utmp = ~utmp & 0x0fff;
+   /* Scale value to 0x-0x */
+   strength = utmp << 4 | utmp >> 8;
+
+   c->strength.len = 1;
+   c->strength.stat[0].scale = FE_SCALE_RELATIVE;
+   c->strength.stat[0].uvalue = strength;
+   } else {
+   c->strength.len = 1;
+   c->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+   }
+
+   /* CNR */
+   if (*status & FE_HAS_VITERBI) {
+   unsigned int cnr;
+
+   ret = cxd2820r_rd_regs(priv, 0x02028, buf, 2);
+   if (ret)
+   goto error;
+
+   utmp = buf[0] << 8 | buf[1] << 0;
+   utmp = utmp & 0x0fff;
+   #define CXD2820R_LOG10_8_24 15151336 /* log10(8) << 24 */
+   if (utmp)
+   cnr = div_u64((u64)(intlog10(utmp)
+ - CXD2820R_LOG10_8_24) * 1,
+ (1 << 24));
+   else
+   cnr = 0;
+
+   c->cnr.len = 1;
+   c->cnr.stat[0].scale = FE_SCALE_DECIBEL;
+   c->cnr.stat[0].svalue = cnr;
+   } else {
+   c->cnr.len = 1;
+   c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+   }
+
+   /* BER */
+   if (*status & FE_HAS_SYNC) {
+   unsigned int post_bit_error;
+
+   ret = cxd2820r_rd_regs(priv, 0x02039, buf, 4);
+   if (ret)
+   goto error;
+
+   if ((buf[0] >> 4) & 0x01) {
+   post_bit_error = buf[0] << 24 | buf[1] << 16 |
+buf[2] << 8 | buf[3] << 0;
+   post_bit_error &= 0x0fff;
+   } else {
+   post_bit_error = 0;
+   }
+
+   priv->post_bit_error += post_bit_error;
+
+   c->post_bit_error.len = 1;
+   c->post_bit_error.stat[0].scale = FE_SCALE_COUNTER;
+   c->post_bit_error.stat[0].uvalue = priv->post_bit_error;
+   } else {
+   c->post_bit_error.len = 1;
+   c->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+   }
+
return ret;
 error:
dev_dbg(>i2c->dev, "%s: failed=%d\n", __func__, ret);
-- 
http://palosaari.fi/

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


[PATCH 8/9] cxd2820r: improve lock detection

2016-09-02 Thread Antti Palosaari
Check demod and ts locks and report lock status according to those.

Signed-off-by: Antti Palosaari 
---
 drivers/media/dvb-frontends/cxd2820r_c.c  | 29 
 drivers/media/dvb-frontends/cxd2820r_t.c  | 44 ---
 drivers/media/dvb-frontends/cxd2820r_t2.c | 26 ++
 3 files changed, 50 insertions(+), 49 deletions(-)

diff --git a/drivers/media/dvb-frontends/cxd2820r_c.c 
b/drivers/media/dvb-frontends/cxd2820r_c.c
index beb46a6..0f96add 100644
--- a/drivers/media/dvb-frontends/cxd2820r_c.c
+++ b/drivers/media/dvb-frontends/cxd2820r_c.c
@@ -160,25 +160,32 @@ int cxd2820r_read_status_c(struct dvb_frontend *fe, enum 
fe_status *status)
struct i2c_client *client = priv->client[0];
struct dtv_frontend_properties *c = >dtv_property_cache;
int ret;
-   unsigned int utmp;
+   unsigned int utmp, utmp1, utmp2;
u8 buf[3];
-   *status = 0;
 
-   ret = cxd2820r_rd_regs(priv, 0x10088, buf, 2);
+   /* Lock detection */
+   ret = cxd2820r_rd_reg(priv, 0x10088, [0]);
+   if (ret)
+   goto error;
+   ret = cxd2820r_rd_reg(priv, 0x10073, [1]);
if (ret)
goto error;
 
-   if (((buf[0] >> 0) & 0x01) == 1) {
-   *status |= FE_HAS_SIGNAL | FE_HAS_CARRIER |
-   FE_HAS_VITERBI | FE_HAS_SYNC;
+   utmp1 = (buf[0] >> 0) & 0x01;
+   utmp2 = (buf[1] >> 3) & 0x01;
 
-   if (((buf[1] >> 3) & 0x01) == 1) {
-   *status |= FE_HAS_SIGNAL | FE_HAS_CARRIER |
-   FE_HAS_VITERBI | FE_HAS_SYNC | FE_HAS_LOCK;
-   }
+   if (utmp1 == 1 && utmp2 == 1) {
+   *status = FE_HAS_SIGNAL | FE_HAS_CARRIER |
+ FE_HAS_VITERBI | FE_HAS_SYNC | FE_HAS_LOCK;
+   } else if (utmp1 == 1 || utmp2 == 1) {
+   *status = FE_HAS_SIGNAL | FE_HAS_CARRIER |
+ FE_HAS_VITERBI | FE_HAS_SYNC;
+   } else {
+   *status = 0;
}
 
-   dev_dbg(>dev, "lock=%*ph\n", 2, buf);
+   dev_dbg(>dev, "status=%02x raw=%*ph sync=%u ts=%u\n",
+   *status, 2, buf, utmp1, utmp2);
 
/* Signal strength */
if (*status & FE_HAS_SIGNAL) {
diff --git a/drivers/media/dvb-frontends/cxd2820r_t.c 
b/drivers/media/dvb-frontends/cxd2820r_t.c
index 174d916..19f72cd 100644
--- a/drivers/media/dvb-frontends/cxd2820r_t.c
+++ b/drivers/media/dvb-frontends/cxd2820r_t.c
@@ -265,42 +265,32 @@ int cxd2820r_read_status_t(struct dvb_frontend *fe, enum 
fe_status *status)
struct i2c_client *client = priv->client[0];
struct dtv_frontend_properties *c = >dtv_property_cache;
int ret;
-   unsigned int utmp;
-   u8 buf[4];
-   *status = 0;
+   unsigned int utmp, utmp1, utmp2;
+   u8 buf[3];
 
+   /* Lock detection */
ret = cxd2820r_rd_reg(priv, 0x00010, [0]);
if (ret)
goto error;
+   ret = cxd2820r_rd_reg(priv, 0x00073, [1]);
+   if (ret)
+   goto error;
 
-   if ((buf[0] & 0x07) == 6) {
-   ret = cxd2820r_rd_reg(priv, 0x00073, [1]);
-   if (ret)
-   goto error;
+   utmp1 = (buf[0] >> 0) & 0x07;
+   utmp2 = (buf[1] >> 3) & 0x01;
 
-   if (((buf[1] >> 3) & 0x01) == 1) {
-   *status |= FE_HAS_SIGNAL | FE_HAS_CARRIER |
-   FE_HAS_VITERBI | FE_HAS_SYNC | FE_HAS_LOCK;
-   } else {
-   *status |= FE_HAS_SIGNAL | FE_HAS_CARRIER |
-   FE_HAS_VITERBI | FE_HAS_SYNC;
-   }
+   if (utmp1 == 6 && utmp2 == 1) {
+   *status = FE_HAS_SIGNAL | FE_HAS_CARRIER |
+ FE_HAS_VITERBI | FE_HAS_SYNC | FE_HAS_LOCK;
+   } else if (utmp1 == 6 || utmp2 == 1) {
+   *status = FE_HAS_SIGNAL | FE_HAS_CARRIER |
+ FE_HAS_VITERBI | FE_HAS_SYNC;
} else {
-   ret = cxd2820r_rd_reg(priv, 0x00014, [2]);
-   if (ret)
-   goto error;
-
-   if ((buf[2] & 0x0f) >= 4) {
-   ret = cxd2820r_rd_reg(priv, 0x00a14, [3]);
-   if (ret)
-   goto error;
-
-   if (((buf[3] >> 4) & 0x01) == 1)
-   *status |= FE_HAS_SIGNAL;
-   }
+   *status = 0;
}
 
-   dev_dbg(>dev, "lock=%*ph\n", 4, buf);
+   dev_dbg(>dev, "status=%02x raw=%*ph sync=%u ts=%u\n",
+   *status, 2, buf, utmp1, utmp2);
 
/* Signal strength */
if (*status & FE_HAS_SIGNAL) {
diff --git a/drivers/media/dvb-frontends/cxd2820r_t2.c 
b/drivers/media/dvb-frontends/cxd2820r_t2.c
index 939a68d..4a6fbf8 100644
--- a/drivers/media/dvb-frontends/cxd2820r_t2.c
+++ b/drivers/media/dvb-frontends/cxd2820r_t2.c
@@ 

[PATCH 2/9] cxd2820r: dvbv5 statistics for DVB-T

2016-09-02 Thread Antti Palosaari
Implement dvbv5 statistics for DVB-T.

Signed-off-by: Antti Palosaari 
---
 drivers/media/dvb-frontends/cxd2820r_priv.h |  2 +
 drivers/media/dvb-frontends/cxd2820r_t.c| 88 +
 2 files changed, 90 insertions(+)

diff --git a/drivers/media/dvb-frontends/cxd2820r_priv.h 
b/drivers/media/dvb-frontends/cxd2820r_priv.h
index acfae17..a97570b 100644
--- a/drivers/media/dvb-frontends/cxd2820r_priv.h
+++ b/drivers/media/dvb-frontends/cxd2820r_priv.h
@@ -27,6 +27,7 @@
 #include "dvb_math.h"
 #include "cxd2820r.h"
 #include 
+#include 
 
 struct reg_val_mask {
u32 reg;
@@ -40,6 +41,7 @@ struct cxd2820r_priv {
struct i2c_adapter *i2c;
struct dvb_frontend fe;
struct cxd2820r_config cfg;
+   u64 post_bit_error;
 
bool ber_running;
 
diff --git a/drivers/media/dvb-frontends/cxd2820r_t.c 
b/drivers/media/dvb-frontends/cxd2820r_t.c
index 67cc33b..d402ab6 100644
--- a/drivers/media/dvb-frontends/cxd2820r_t.c
+++ b/drivers/media/dvb-frontends/cxd2820r_t.c
@@ -351,7 +351,9 @@ int cxd2820r_read_ucblocks_t(struct dvb_frontend *fe, u32 
*ucblocks)
 int cxd2820r_read_status_t(struct dvb_frontend *fe, enum fe_status *status)
 {
struct cxd2820r_priv *priv = fe->demodulator_priv;
+   struct dtv_frontend_properties *c = >dtv_property_cache;
int ret;
+   unsigned int utmp;
u8 buf[4];
*status = 0;
 
@@ -388,6 +390,92 @@ int cxd2820r_read_status_t(struct dvb_frontend *fe, enum 
fe_status *status)
 
dev_dbg(>i2c->dev, "%s: lock=%*ph\n", __func__, 4, buf);
 
+   /* Signal strength */
+   if (*status & FE_HAS_SIGNAL) {
+   unsigned int strength;
+
+   ret = cxd2820r_rd_regs(priv, 0x00026, buf, 2);
+   if (ret)
+   goto error;
+
+   utmp = buf[0] << 8 | buf[1] << 0;
+   utmp = ~utmp & 0x0fff;
+   /* Scale value to 0x-0x */
+   strength = utmp << 4 | utmp >> 8;
+
+   c->strength.len = 1;
+   c->strength.stat[0].scale = FE_SCALE_RELATIVE;
+   c->strength.stat[0].uvalue = strength;
+   } else {
+   c->strength.len = 1;
+   c->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+   }
+
+   /* CNR */
+   if (*status & FE_HAS_VITERBI) {
+   unsigned int cnr;
+
+   ret = cxd2820r_rd_regs(priv, 0x0002c, buf, 2);
+   if (ret)
+   goto error;
+
+   utmp = buf[0] << 8 | buf[1] << 0;
+   if (utmp)
+   cnr = div_u64((u64)(intlog10(utmp)
+ - intlog10(32000 - utmp) + 55532585)
+ * 1, (1 << 24));
+   else
+   cnr = 0;
+
+   c->cnr.len = 1;
+   c->cnr.stat[0].scale = FE_SCALE_DECIBEL;
+   c->cnr.stat[0].svalue = cnr;
+   } else {
+   c->cnr.len = 1;
+   c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+   }
+
+   /* BER */
+   if (*status & FE_HAS_SYNC) {
+   unsigned int post_bit_error;
+   bool start_ber;
+
+   if (priv->ber_running) {
+   ret = cxd2820r_rd_regs(priv, 0x00076, buf, 3);
+   if (ret)
+   goto error;
+
+   if ((buf[2] >> 7) & 0x01) {
+   post_bit_error = buf[2] << 16 | buf[1] << 8 |
+buf[0] << 0;
+   post_bit_error &= 0x0f;
+   start_ber = true;
+   } else {
+   post_bit_error = 0;
+   start_ber = false;
+   }
+   } else {
+   post_bit_error = 0;
+   start_ber = true;
+   }
+
+   if (start_ber) {
+   ret = cxd2820r_wr_reg(priv, 0x00079, 0x01);
+   if (ret)
+   goto error;
+   priv->ber_running = true;
+   }
+
+   priv->post_bit_error += post_bit_error;
+
+   c->post_bit_error.len = 1;
+   c->post_bit_error.stat[0].scale = FE_SCALE_COUNTER;
+   c->post_bit_error.stat[0].uvalue = priv->post_bit_error;
+   } else {
+   c->post_bit_error.len = 1;
+   c->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
+   }
+
return ret;
 error:
dev_dbg(>i2c->dev, "%s: failed=%d\n", __func__, ret);
-- 
http://palosaari.fi/

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


[PATCH 7/9] cxd2820r: correct logging

2016-09-02 Thread Antti Palosaari
Use correct device for logging functions as we now have it due to
proper I2C client bindings.

Signed-off-by: Antti Palosaari 
---
 drivers/media/dvb-frontends/cxd2820r_c.c|  33 +---
 drivers/media/dvb-frontends/cxd2820r_core.c | 115 +++-
 drivers/media/dvb-frontends/cxd2820r_t.c|  32 +---
 drivers/media/dvb-frontends/cxd2820r_t2.c   |  34 
 4 files changed, 123 insertions(+), 91 deletions(-)

diff --git a/drivers/media/dvb-frontends/cxd2820r_c.c 
b/drivers/media/dvb-frontends/cxd2820r_c.c
index 0d036e1..beb46a6 100644
--- a/drivers/media/dvb-frontends/cxd2820r_c.c
+++ b/drivers/media/dvb-frontends/cxd2820r_c.c
@@ -24,6 +24,7 @@
 int cxd2820r_set_frontend_c(struct dvb_frontend *fe)
 {
struct cxd2820r_priv *priv = fe->demodulator_priv;
+   struct i2c_client *client = priv->client[0];
struct dtv_frontend_properties *c = >dtv_property_cache;
int ret, i;
unsigned int utmp;
@@ -47,8 +48,10 @@ int cxd2820r_set_frontend_c(struct dvb_frontend *fe)
{ 0x10071, !priv->ts_clk_inv << 4, 0x10 },
};
 
-   dev_dbg(>i2c->dev, "%s: frequency=%d symbol_rate=%d\n", __func__,
-   c->frequency, c->symbol_rate);
+   dev_dbg(>dev,
+   "delivery_system=%d modulation=%d frequency=%u symbol_rate=%u 
inversion=%d\n",
+   c->delivery_system, c->modulation, c->frequency,
+   c->symbol_rate, c->inversion);
 
/* program tuner */
if (fe->ops.tuner_ops.set_params)
@@ -71,8 +74,7 @@ int cxd2820r_set_frontend_c(struct dvb_frontend *fe)
ret = fe->ops.tuner_ops.get_if_frequency(fe, _frequency);
if (ret)
goto error;
-   dev_dbg(>i2c->dev, "%s: if_frequency=%u\n", __func__,
-   if_frequency);
+   dev_dbg(>dev, "if_frequency=%u\n", if_frequency);
} else {
ret = -EINVAL;
goto error;
@@ -95,7 +97,7 @@ int cxd2820r_set_frontend_c(struct dvb_frontend *fe)
 
return ret;
 error:
-   dev_dbg(>i2c->dev, "%s: failed=%d\n", __func__, ret);
+   dev_dbg(>dev, "failed=%d\n", ret);
return ret;
 }
 
@@ -103,9 +105,12 @@ int cxd2820r_get_frontend_c(struct dvb_frontend *fe,
struct dtv_frontend_properties *c)
 {
struct cxd2820r_priv *priv = fe->demodulator_priv;
+   struct i2c_client *client = priv->client[0];
int ret;
u8 buf[2];
 
+   dev_dbg(>dev, "\n");
+
ret = cxd2820r_rd_regs(priv, 0x1001a, buf, 2);
if (ret)
goto error;
@@ -145,13 +150,14 @@ int cxd2820r_get_frontend_c(struct dvb_frontend *fe,
 
return ret;
 error:
-   dev_dbg(>i2c->dev, "%s: failed=%d\n", __func__, ret);
+   dev_dbg(>dev, "failed=%d\n", ret);
return ret;
 }
 
 int cxd2820r_read_status_c(struct dvb_frontend *fe, enum fe_status *status)
 {
struct cxd2820r_priv *priv = fe->demodulator_priv;
+   struct i2c_client *client = priv->client[0];
struct dtv_frontend_properties *c = >dtv_property_cache;
int ret;
unsigned int utmp;
@@ -172,8 +178,7 @@ int cxd2820r_read_status_c(struct dvb_frontend *fe, enum 
fe_status *status)
}
}
 
-   dev_dbg(>i2c->dev, "%s: lock=%02x %02x\n", __func__, buf[0],
-   buf[1]);
+   dev_dbg(>dev, "lock=%*ph\n", 2, buf);
 
/* Signal strength */
if (*status & FE_HAS_SIGNAL) {
@@ -275,28 +280,32 @@ int cxd2820r_read_status_c(struct dvb_frontend *fe, enum 
fe_status *status)
 
return ret;
 error:
-   dev_dbg(>i2c->dev, "%s: failed=%d\n", __func__, ret);
+   dev_dbg(>dev, "failed=%d\n", ret);
return ret;
 }
 
 int cxd2820r_init_c(struct dvb_frontend *fe)
 {
struct cxd2820r_priv *priv = fe->demodulator_priv;
+   struct i2c_client *client = priv->client[0];
int ret;
 
+   dev_dbg(>dev, "\n");
+
ret = cxd2820r_wr_reg(priv, 0x00085, 0x07);
if (ret)
goto error;
 
return ret;
 error:
-   dev_dbg(>i2c->dev, "%s: failed=%d\n", __func__, ret);
+   dev_dbg(>dev, "failed=%d\n", ret);
return ret;
 }
 
 int cxd2820r_sleep_c(struct dvb_frontend *fe)
 {
struct cxd2820r_priv *priv = fe->demodulator_priv;
+   struct i2c_client *client = priv->client[0];
int ret, i;
struct reg_val_mask tab[] = {
{ 0x000ff, 0x1f, 0xff },
@@ -306,7 +315,7 @@ int cxd2820r_sleep_c(struct dvb_frontend *fe)
{ 0x00080, 0x00, 0xff },
};
 
-   dev_dbg(>i2c->dev, "%s\n", __func__);
+   dev_dbg(>dev, "\n");
 
priv->delivery_system = SYS_UNDEFINED;
 
@@ -319,7 +328,7 @@ int cxd2820r_sleep_c(struct dvb_frontend *fe)
 
return ret;
 error:
-   dev_dbg(>i2c->dev, "%s: failed=%d\n", __func__, ret);
+   dev_dbg(>dev, "failed=%d\n", ret);
return 

[PATCH 1/9] cxd2820r: improve IF frequency setting

2016-09-02 Thread Antti Palosaari
Use 64-bit calculation.

Return error if tuner does not provide get_if_frequency() callback.
All currently used tuners has it.

Signed-off-by: Antti Palosaari 
---
 drivers/media/dvb-frontends/cxd2820r_c.c| 26 +++
 drivers/media/dvb-frontends/cxd2820r_priv.h |  2 ++
 drivers/media/dvb-frontends/cxd2820r_t.c| 27 ---
 drivers/media/dvb-frontends/cxd2820r_t2.c   | 33 ++---
 4 files changed, 43 insertions(+), 45 deletions(-)

diff --git a/drivers/media/dvb-frontends/cxd2820r_c.c 
b/drivers/media/dvb-frontends/cxd2820r_c.c
index a674a63..957ec94 100644
--- a/drivers/media/dvb-frontends/cxd2820r_c.c
+++ b/drivers/media/dvb-frontends/cxd2820r_c.c
@@ -26,10 +26,9 @@ int cxd2820r_set_frontend_c(struct dvb_frontend *fe)
struct cxd2820r_priv *priv = fe->demodulator_priv;
struct dtv_frontend_properties *c = >dtv_property_cache;
int ret, i;
+   unsigned int utmp;
u8 buf[2];
-   u32 if_freq;
-   u16 if_ctl;
-   u64 num;
+   u32 if_frequency;
struct reg_val_mask tab[] = {
{ 0x00080, 0x01, 0xff },
{ 0x00081, 0x05, 0xff },
@@ -69,20 +68,19 @@ int cxd2820r_set_frontend_c(struct dvb_frontend *fe)
 
/* program IF frequency */
if (fe->ops.tuner_ops.get_if_frequency) {
-   ret = fe->ops.tuner_ops.get_if_frequency(fe, _freq);
+   ret = fe->ops.tuner_ops.get_if_frequency(fe, _frequency);
if (ret)
goto error;
-   } else
-   if_freq = 0;
-
-   dev_dbg(>i2c->dev, "%s: if_freq=%d\n", __func__, if_freq);
-
-   num = if_freq / 1000; /* Hz => kHz */
-   num *= 0x4000;
-   if_ctl = 0x4000 - DIV_ROUND_CLOSEST_ULL(num, 41000);
-   buf[0] = (if_ctl >> 8) & 0x3f;
-   buf[1] = (if_ctl >> 0) & 0xff;
+   dev_dbg(>i2c->dev, "%s: if_frequency=%u\n", __func__,
+   if_frequency);
+   } else {
+   ret = -EINVAL;
+   goto error;
+   }
 
+   utmp = 0x4000 - DIV_ROUND_CLOSEST_ULL((u64)if_frequency * 0x4000, 
CXD2820R_CLK);
+   buf[0] = (utmp >> 8) & 0xff;
+   buf[1] = (utmp >> 0) & 0xff;
ret = cxd2820r_wr_regs(priv, 0x10042, buf, 2);
if (ret)
goto error;
diff --git a/drivers/media/dvb-frontends/cxd2820r_priv.h 
b/drivers/media/dvb-frontends/cxd2820r_priv.h
index e31c48e..acfae17 100644
--- a/drivers/media/dvb-frontends/cxd2820r_priv.h
+++ b/drivers/media/dvb-frontends/cxd2820r_priv.h
@@ -34,6 +34,8 @@ struct reg_val_mask {
u8  mask;
 };
 
+#define CXD2820R_CLK 4100
+
 struct cxd2820r_priv {
struct i2c_adapter *i2c;
struct dvb_frontend fe;
diff --git a/drivers/media/dvb-frontends/cxd2820r_t.c 
b/drivers/media/dvb-frontends/cxd2820r_t.c
index 75ce7d8..67cc33b 100644
--- a/drivers/media/dvb-frontends/cxd2820r_t.c
+++ b/drivers/media/dvb-frontends/cxd2820r_t.c
@@ -26,8 +26,8 @@ int cxd2820r_set_frontend_t(struct dvb_frontend *fe)
struct cxd2820r_priv *priv = fe->demodulator_priv;
struct dtv_frontend_properties *c = >dtv_property_cache;
int ret, i, bw_i;
-   u32 if_freq, if_ctl;
-   u64 num;
+   unsigned int utmp;
+   u32 if_frequency;
u8 buf[3], bw_param;
u8 bw_params1[][5] = {
{ 0x17, 0xea, 0xaa, 0xaa, 0xaa }, /* 6 MHz */
@@ -93,21 +93,20 @@ int cxd2820r_set_frontend_t(struct dvb_frontend *fe)
 
/* program IF frequency */
if (fe->ops.tuner_ops.get_if_frequency) {
-   ret = fe->ops.tuner_ops.get_if_frequency(fe, _freq);
+   ret = fe->ops.tuner_ops.get_if_frequency(fe, _frequency);
if (ret)
goto error;
-   } else
-   if_freq = 0;
-
-   dev_dbg(>i2c->dev, "%s: if_freq=%d\n", __func__, if_freq);
-
-   num = if_freq / 1000; /* Hz => kHz */
-   num *= 0x100;
-   if_ctl = DIV_ROUND_CLOSEST_ULL(num, 41000);
-   buf[0] = ((if_ctl >> 16) & 0xff);
-   buf[1] = ((if_ctl >>  8) & 0xff);
-   buf[2] = ((if_ctl >>  0) & 0xff);
+   dev_dbg(>i2c->dev, "%s: if_frequency=%u\n", __func__,
+   if_frequency);
+   } else {
+   ret = -EINVAL;
+   goto error;
+   }
 
+   utmp = DIV_ROUND_CLOSEST_ULL((u64)if_frequency * 0x100, 
CXD2820R_CLK);
+   buf[0] = (utmp >> 16) & 0xff;
+   buf[1] = (utmp >>  8) & 0xff;
+   buf[2] = (utmp >>  0) & 0xff;
ret = cxd2820r_wr_regs(priv, 0x000b6, buf, 3);
if (ret)
goto error;
diff --git a/drivers/media/dvb-frontends/cxd2820r_t2.c 
b/drivers/media/dvb-frontends/cxd2820r_t2.c
index 7044756..14c9a26 100644
--- a/drivers/media/dvb-frontends/cxd2820r_t2.c
+++ b/drivers/media/dvb-frontends/cxd2820r_t2.c
@@ -26,8 +26,8 @@ int cxd2820r_set_frontend_t2(struct dvb_frontend *fe)
struct dtv_frontend_properties *c = 

[PATCH 9/9] cxd2820r: convert to regmap api

2016-09-02 Thread Antti Palosaari
Use regmap for I2C register access.

Signed-off-by: Antti Palosaari 
---
 drivers/media/dvb-frontends/Kconfig |   1 +
 drivers/media/dvb-frontends/cxd2820r_c.c|  56 +++---
 drivers/media/dvb-frontends/cxd2820r_core.c | 259 ++--
 drivers/media/dvb-frontends/cxd2820r_priv.h |   6 +-
 drivers/media/dvb-frontends/cxd2820r_t.c|  55 +++---
 drivers/media/dvb-frontends/cxd2820r_t2.c   |  55 +++---
 6 files changed, 173 insertions(+), 259 deletions(-)

diff --git a/drivers/media/dvb-frontends/Kconfig 
b/drivers/media/dvb-frontends/Kconfig
index c645aa8..c4b67f7 100644
--- a/drivers/media/dvb-frontends/Kconfig
+++ b/drivers/media/dvb-frontends/Kconfig
@@ -463,6 +463,7 @@ config DVB_STV0367
 config DVB_CXD2820R
tristate "Sony CXD2820R"
depends on DVB_CORE && I2C
+   select REGMAP_I2C
default m if !MEDIA_SUBDRV_AUTOSELECT
help
  Say Y when you want to support this frontend.
diff --git a/drivers/media/dvb-frontends/cxd2820r_c.c 
b/drivers/media/dvb-frontends/cxd2820r_c.c
index 0f96add..d75b077 100644
--- a/drivers/media/dvb-frontends/cxd2820r_c.c
+++ b/drivers/media/dvb-frontends/cxd2820r_c.c
@@ -26,7 +26,7 @@ int cxd2820r_set_frontend_c(struct dvb_frontend *fe)
struct cxd2820r_priv *priv = fe->demodulator_priv;
struct i2c_client *client = priv->client[0];
struct dtv_frontend_properties *c = >dtv_property_cache;
-   int ret, i;
+   int ret;
unsigned int utmp;
u8 buf[2];
u32 if_frequency;
@@ -58,12 +58,9 @@ int cxd2820r_set_frontend_c(struct dvb_frontend *fe)
fe->ops.tuner_ops.set_params(fe);
 
if (priv->delivery_system !=  SYS_DVBC_ANNEX_A) {
-   for (i = 0; i < ARRAY_SIZE(tab); i++) {
-   ret = cxd2820r_wr_reg_mask(priv, tab[i].reg,
-   tab[i].val, tab[i].mask);
-   if (ret)
-   goto error;
-   }
+   ret = cxd2820r_wr_reg_val_mask_tab(priv, tab, ARRAY_SIZE(tab));
+   if (ret)
+   goto error;
}
 
priv->delivery_system = SYS_DVBC_ANNEX_A;
@@ -83,15 +80,15 @@ int cxd2820r_set_frontend_c(struct dvb_frontend *fe)
utmp = 0x4000 - DIV_ROUND_CLOSEST_ULL((u64)if_frequency * 0x4000, 
CXD2820R_CLK);
buf[0] = (utmp >> 8) & 0xff;
buf[1] = (utmp >> 0) & 0xff;
-   ret = cxd2820r_wr_regs(priv, 0x10042, buf, 2);
+   ret = regmap_bulk_write(priv->regmap[1], 0x0042, buf, 2);
if (ret)
goto error;
 
-   ret = cxd2820r_wr_reg(priv, 0x000ff, 0x08);
+   ret = regmap_write(priv->regmap[0], 0x00ff, 0x08);
if (ret)
goto error;
 
-   ret = cxd2820r_wr_reg(priv, 0x000fe, 0x01);
+   ret = regmap_write(priv->regmap[0], 0x00fe, 0x01);
if (ret)
goto error;
 
@@ -107,21 +104,22 @@ int cxd2820r_get_frontend_c(struct dvb_frontend *fe,
struct cxd2820r_priv *priv = fe->demodulator_priv;
struct i2c_client *client = priv->client[0];
int ret;
+   unsigned int utmp;
u8 buf[2];
 
dev_dbg(>dev, "\n");
 
-   ret = cxd2820r_rd_regs(priv, 0x1001a, buf, 2);
+   ret = regmap_bulk_read(priv->regmap[1], 0x001a, buf, 2);
if (ret)
goto error;
 
c->symbol_rate = 2500 * ((buf[0] & 0x0f) << 8 | buf[1]);
 
-   ret = cxd2820r_rd_reg(priv, 0x10019, [0]);
+   ret = regmap_read(priv->regmap[1], 0x0019, );
if (ret)
goto error;
 
-   switch ((buf[0] >> 0) & 0x07) {
+   switch ((utmp >> 0) & 0x07) {
case 0:
c->modulation = QAM_16;
break;
@@ -139,7 +137,7 @@ int cxd2820r_get_frontend_c(struct dvb_frontend *fe,
break;
}
 
-   switch ((buf[0] >> 7) & 0x01) {
+   switch ((utmp >> 7) & 0x01) {
case 0:
c->inversion = INVERSION_OFF;
break;
@@ -164,10 +162,10 @@ int cxd2820r_read_status_c(struct dvb_frontend *fe, enum 
fe_status *status)
u8 buf[3];
 
/* Lock detection */
-   ret = cxd2820r_rd_reg(priv, 0x10088, [0]);
+   ret = regmap_bulk_read(priv->regmap[1], 0x0088, [0], 1);
if (ret)
goto error;
-   ret = cxd2820r_rd_reg(priv, 0x10073, [1]);
+   ret = regmap_bulk_read(priv->regmap[1], 0x0073, [1], 1);
if (ret)
goto error;
 
@@ -191,7 +189,7 @@ int cxd2820r_read_status_c(struct dvb_frontend *fe, enum 
fe_status *status)
if (*status & FE_HAS_SIGNAL) {
unsigned int strength;
 
-   ret = cxd2820r_rd_regs(priv, 0x10049, buf, 2);
+   ret = regmap_bulk_read(priv->regmap[1], 0x0049, buf, 2);
if (ret)
goto error;
 
@@ -212,11 +210,11 @@ int cxd2820r_read_status_c(struct dvb_frontend *fe, enum 
fe_status *status)
if 

[PATCH 5/9] cxd2820r: wrap legacy DVBv3 statistics via DVBv5 statistics

2016-09-02 Thread Antti Palosaari
Return DVBv5 statistics via legacy DVBv3 API.

Signed-off-by: Antti Palosaari 
---
 drivers/media/dvb-frontends/cxd2820r_c.c| 108 
 drivers/media/dvb-frontends/cxd2820r_core.c |  85 ++
 drivers/media/dvb-frontends/cxd2820r_priv.h |  25 +--
 drivers/media/dvb-frontends/cxd2820r_t.c|  94 
 drivers/media/dvb-frontends/cxd2820r_t2.c   |  87 --
 5 files changed, 22 insertions(+), 377 deletions(-)

diff --git a/drivers/media/dvb-frontends/cxd2820r_c.c 
b/drivers/media/dvb-frontends/cxd2820r_c.c
index 7cdcd55..82df944 100644
--- a/drivers/media/dvb-frontends/cxd2820r_c.c
+++ b/drivers/media/dvb-frontends/cxd2820r_c.c
@@ -149,114 +149,6 @@ error:
return ret;
 }
 
-int cxd2820r_read_ber_c(struct dvb_frontend *fe, u32 *ber)
-{
-   struct cxd2820r_priv *priv = fe->demodulator_priv;
-   int ret;
-   u8 buf[3], start_ber = 0;
-   *ber = 0;
-
-   if (priv->ber_running) {
-   ret = cxd2820r_rd_regs(priv, 0x10076, buf, sizeof(buf));
-   if (ret)
-   goto error;
-
-   if ((buf[2] >> 7) & 0x01 || (buf[2] >> 4) & 0x01) {
-   *ber = (buf[2] & 0x0f) << 16 | buf[1] << 8 | buf[0];
-   start_ber = 1;
-   }
-   } else {
-   priv->ber_running = true;
-   start_ber = 1;
-   }
-
-   if (start_ber) {
-   /* (re)start BER */
-   ret = cxd2820r_wr_reg(priv, 0x10079, 0x01);
-   if (ret)
-   goto error;
-   }
-
-   return ret;
-error:
-   dev_dbg(>i2c->dev, "%s: failed=%d\n", __func__, ret);
-   return ret;
-}
-
-int cxd2820r_read_signal_strength_c(struct dvb_frontend *fe,
-   u16 *strength)
-{
-   struct cxd2820r_priv *priv = fe->demodulator_priv;
-   int ret;
-   u8 buf[2];
-   u16 tmp;
-
-   ret = cxd2820r_rd_regs(priv, 0x10049, buf, sizeof(buf));
-   if (ret)
-   goto error;
-
-   tmp = (buf[0] & 0x03) << 8 | buf[1];
-   tmp = (~tmp & 0x03ff);
-
-   if (tmp == 512)
-   /* ~no signal */
-   tmp = 0;
-   else if (tmp > 350)
-   tmp = 350;
-
-   /* scale value to 0x-0x */
-   *strength = tmp * 0x / (350-0);
-
-   return ret;
-error:
-   dev_dbg(>i2c->dev, "%s: failed=%d\n", __func__, ret);
-   return ret;
-}
-
-int cxd2820r_read_snr_c(struct dvb_frontend *fe, u16 *snr)
-{
-   struct cxd2820r_priv *priv = fe->demodulator_priv;
-   int ret;
-   u8 tmp;
-   unsigned int A, B;
-   /* report SNR in dB * 10 */
-
-   ret = cxd2820r_rd_reg(priv, 0x10019, );
-   if (ret)
-   goto error;
-
-   if (((tmp >> 0) & 0x03) % 2) {
-   A = 875;
-   B = 650;
-   } else {
-   A = 950;
-   B = 760;
-   }
-
-   ret = cxd2820r_rd_reg(priv, 0x1004d, );
-   if (ret)
-   goto error;
-
-   #define CXD2820R_LOG2_E_24 24204406 /* log2(e) << 24 */
-   if (tmp)
-   *snr = A * (intlog2(B / tmp) >> 5) / (CXD2820R_LOG2_E_24 >> 5)
-   / 10;
-   else
-   *snr = 0;
-
-   return ret;
-error:
-   dev_dbg(>i2c->dev, "%s: failed=%d\n", __func__, ret);
-   return ret;
-}
-
-int cxd2820r_read_ucblocks_c(struct dvb_frontend *fe, u32 *ucblocks)
-{
-   *ucblocks = 0;
-   /* no way to read ? */
-   return 0;
-}
-
 int cxd2820r_read_status_c(struct dvb_frontend *fe, enum fe_status *status)
 {
struct cxd2820r_priv *priv = fe->demodulator_priv;
diff --git a/drivers/media/dvb-frontends/cxd2820r_core.c 
b/drivers/media/dvb-frontends/cxd2820r_core.c
index 314d3b8..66da821 100644
--- a/drivers/media/dvb-frontends/cxd2820r_core.c
+++ b/drivers/media/dvb-frontends/cxd2820r_core.c
@@ -345,101 +345,58 @@ static int cxd2820r_get_frontend(struct dvb_frontend *fe,
 static int cxd2820r_read_ber(struct dvb_frontend *fe, u32 *ber)
 {
struct cxd2820r_priv *priv = fe->demodulator_priv;
-   int ret;
 
dev_dbg(>i2c->dev, "%s: delsys=%d\n", __func__,
fe->dtv_property_cache.delivery_system);
 
-   switch (fe->dtv_property_cache.delivery_system) {
-   case SYS_DVBT:
-   ret = cxd2820r_read_ber_t(fe, ber);
-   break;
-   case SYS_DVBT2:
-   ret = cxd2820r_read_ber_t2(fe, ber);
-   break;
-   case SYS_DVBC_ANNEX_A:
-   ret = cxd2820r_read_ber_c(fe, ber);
-   break;
-   default:
-   ret = -EINVAL;
-   break;
-   }
-   return ret;
+   *ber = (priv->post_bit_error - priv->post_bit_error_prev_dvbv3);
+   priv->post_bit_error_prev_dvbv3 = priv->post_bit_error;
+
+   return 0;
 }
 
 static int cxd2820r_read_signal_strength(struct dvb_frontend *fe, u16 

[PATCH 6/9] cxd2820r: add I2C driver bindings

2016-09-02 Thread Antti Palosaari
Add I2C driver bindings in order to support proper I2C driver
registration with driver core.

Signed-off-by: Antti Palosaari 
---
 drivers/media/dvb-frontends/cxd2820r.h  |  26 
 drivers/media/dvb-frontends/cxd2820r_c.c|   6 +-
 drivers/media/dvb-frontends/cxd2820r_core.c | 190 ++--
 drivers/media/dvb-frontends/cxd2820r_priv.h |   7 +-
 drivers/media/dvb-frontends/cxd2820r_t.c|   6 +-
 drivers/media/dvb-frontends/cxd2820r_t2.c   |   8 +-
 6 files changed, 191 insertions(+), 52 deletions(-)

diff --git a/drivers/media/dvb-frontends/cxd2820r.h 
b/drivers/media/dvb-frontends/cxd2820r.h
index 56d4276..d77afe0 100644
--- a/drivers/media/dvb-frontends/cxd2820r.h
+++ b/drivers/media/dvb-frontends/cxd2820r.h
@@ -37,6 +37,32 @@
 #define CXD2820R_TS_PARALLEL  0x30
 #define CXD2820R_TS_PARALLEL_MSB  0x70
 
+/*
+ * I2C address: 0x6c, 0x6d
+ */
+
+/**
+ * struct cxd2820r_platform_data - Platform data for the cxd2820r driver
+ * @ts_mode: TS mode.
+ * @ts_clk_inv: TS clock inverted.
+ * @if_agc_polarity: IF AGC polarity.
+ * @spec_inv: Input spectrum inverted.
+ * @gpio_chip_base: GPIO.
+ * @get_dvb_frontend: Get DVB frontend.
+ */
+
+struct cxd2820r_platform_data {
+   u8 ts_mode;
+   bool ts_clk_inv;
+   bool if_agc_polarity;
+   bool spec_inv;
+   int **gpio_chip_base;
+
+   struct dvb_frontend* (*get_dvb_frontend)(struct i2c_client *);
+/* private: For legacy media attach wrapper. Do not set value. */
+   bool attach_in_use;
+};
+
 struct cxd2820r_config {
/* Demodulator I2C address.
 * Driver determines DVB-C slave I2C address automatically from master
diff --git a/drivers/media/dvb-frontends/cxd2820r_c.c 
b/drivers/media/dvb-frontends/cxd2820r_c.c
index 82df944..0d036e1 100644
--- a/drivers/media/dvb-frontends/cxd2820r_c.c
+++ b/drivers/media/dvb-frontends/cxd2820r_c.c
@@ -42,9 +42,9 @@ int cxd2820r_set_frontend_c(struct dvb_frontend *fe)
{ 0x10059, 0x50, 0xff },
{ 0x10087, 0x0c, 0x3c },
{ 0x1008b, 0x07, 0xff },
-   { 0x1001f, priv->cfg.if_agc_polarity << 7, 0x80 },
-   { 0x10070, priv->cfg.ts_mode, 0xff },
-   { 0x10071, !priv->cfg.ts_clock_inv << 4, 0x10 },
+   { 0x1001f, priv->if_agc_polarity << 7, 0x80 },
+   { 0x10070, priv->ts_mode, 0xff },
+   { 0x10071, !priv->ts_clk_inv << 4, 0x10 },
};
 
dev_dbg(>i2c->dev, "%s: frequency=%d symbol_rate=%d\n", __func__,
diff --git a/drivers/media/dvb-frontends/cxd2820r_core.c 
b/drivers/media/dvb-frontends/cxd2820r_core.c
index 66da821..cf5eed4 100644
--- a/drivers/media/dvb-frontends/cxd2820r_core.c
+++ b/drivers/media/dvb-frontends/cxd2820r_core.c
@@ -49,7 +49,7 @@ static int cxd2820r_wr_regs_i2c(struct cxd2820r_priv *priv, 
u8 i2c, u8 reg,
buf[0] = reg;
memcpy([1], val, len);
 
-   ret = i2c_transfer(priv->i2c, msg, 1);
+   ret = i2c_transfer(priv->client[0]->adapter, msg, 1);
if (ret == 1) {
ret = 0;
} else {
@@ -87,7 +87,7 @@ static int cxd2820r_rd_regs_i2c(struct cxd2820r_priv *priv, 
u8 i2c, u8 reg,
return -EINVAL;
}
 
-   ret = i2c_transfer(priv->i2c, msg, 2);
+   ret = i2c_transfer(priv->client[0]->adapter, msg, 2);
if (ret == 2) {
memcpy(val, buf, len);
ret = 0;
@@ -112,9 +112,9 @@ int cxd2820r_wr_regs(struct cxd2820r_priv *priv, u32 
reginfo, u8 *val,
 
/* select I2C */
if (i2c)
-   i2c_addr = priv->cfg.i2c_address | (1 << 1); /* DVB-C */
+   i2c_addr = priv->client[1]->addr; /* DVB-C */
else
-   i2c_addr = priv->cfg.i2c_address; /* DVB-T/T2 */
+   i2c_addr = priv->client[0]->addr; /* DVB-T/T2 */
 
/* switch bank if needed */
if (bank != priv->bank[i2c]) {
@@ -138,9 +138,9 @@ int cxd2820r_rd_regs(struct cxd2820r_priv *priv, u32 
reginfo, u8 *val,
 
/* select I2C */
if (i2c)
-   i2c_addr = priv->cfg.i2c_address | (1 << 1); /* DVB-C */
+   i2c_addr = priv->client[1]->addr; /* DVB-C */
else
-   i2c_addr = priv->cfg.i2c_address; /* DVB-T/T2 */
+   i2c_addr = priv->client[0]->addr; /* DVB-T/T2 */
 
/* switch bank if needed */
if (bank != priv->bank[i2c]) {
@@ -537,16 +537,12 @@ static int cxd2820r_get_frontend_algo(struct dvb_frontend 
*fe)
 static void cxd2820r_release(struct dvb_frontend *fe)
 {
struct cxd2820r_priv *priv = fe->demodulator_priv;
+   struct i2c_client *client = priv->client[0];
 
dev_dbg(>i2c->dev, "%s\n", __func__);
 
-#ifdef CONFIG_GPIOLIB
-   /* remove GPIOs */
-   if (priv->gpio_chip.label)
-   gpiochip_remove(>gpio_chip);
+   i2c_unregister_device(client);
 
-#endif
-   kfree(priv);
return;
 }
 
@@ -646,49 +642,113 @@ static const struct dvb_frontend_ops 

[PATCHv3 4/6] media: rcar-vin: fix bug in scaling

2016-09-02 Thread Niklas Söderlund
It was not possible to scale beyond the image size of the video source
limitation. The output frame would be bigger but the captured image was
limited to the size of the video source.

The error was that the crop boundary was set after the requested frame
size and not the video source size. This patch breaks out the resetting
of the crop, compose and format to separate functions so the error wont
creep back.

Signed-off-by: Niklas Söderlund 
---
 drivers/media/platform/rcar-vin/rcar-v4l2.c | 105 ++--
 1 file changed, 54 insertions(+), 51 deletions(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c 
b/drivers/media/platform/rcar-vin/rcar-v4l2.c
index 88bfee3..47d8d97 100644
--- a/drivers/media/platform/rcar-vin/rcar-v4l2.c
+++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c
@@ -92,6 +92,54 @@ static u32 rvin_format_sizeimage(struct v4l2_pix_format *pix)
  * V4L2
  */
 
+static void rvin_reset_crop_compose(struct rvin_dev *vin)
+{
+   vin->crop.top = vin->crop.left = 0;
+   vin->crop.width = vin->source.width;
+   vin->crop.height = vin->source.height;
+
+   vin->compose.top = vin->compose.left = 0;
+   vin->compose.width = vin->format.width;
+   vin->compose.height = vin->format.height;
+}
+
+static int rvin_reset_format(struct rvin_dev *vin)
+{
+   struct v4l2_subdev_format fmt = {
+   .which = V4L2_SUBDEV_FORMAT_ACTIVE,
+   };
+   struct v4l2_mbus_framefmt *mf = 
+   int ret;
+
+   fmt.pad = vin->src_pad_idx;
+
+   ret = v4l2_subdev_call(vin_to_source(vin), pad, get_fmt, NULL, );
+   if (ret)
+   return ret;
+
+   vin->format.width   = mf->width;
+   vin->format.height  = mf->height;
+   vin->format.colorspace  = mf->colorspace;
+   vin->format.field   = mf->field;
+
+   switch (vin->format.field) {
+   case V4L2_FIELD_TOP:
+   case V4L2_FIELD_BOTTOM:
+   case V4L2_FIELD_NONE:
+   case V4L2_FIELD_INTERLACED_TB:
+   case V4L2_FIELD_INTERLACED_BT:
+   case V4L2_FIELD_INTERLACED:
+   break;
+   default:
+   vin->format.field = V4L2_FIELD_NONE;
+   break;
+   }
+
+   rvin_reset_crop_compose(vin);
+
+   return 0;
+}
+
 static int __rvin_try_format_source(struct rvin_dev *vin,
u32 which,
struct v4l2_pix_format *pix,
@@ -255,6 +303,8 @@ static int rvin_s_fmt_vid_cap(struct file *file, void *priv,
 
vin->format = f->fmt.pix;
 
+   rvin_reset_crop_compose(vin);
+
return 0;
 }
 
@@ -446,35 +496,14 @@ static int rvin_querystd(struct file *file, void *priv, 
v4l2_std_id *a)
 static int rvin_s_std(struct file *file, void *priv, v4l2_std_id a)
 {
struct rvin_dev *vin = video_drvdata(file);
-   struct v4l2_subdev *sd = vin_to_source(vin);
-   struct v4l2_subdev_format fmt = {
-   .which = V4L2_SUBDEV_FORMAT_ACTIVE,
-   };
-   struct v4l2_mbus_framefmt *mf = 
-   int ret = v4l2_subdev_call(sd, video, s_std, a);
+   int ret;
 
+   ret = v4l2_subdev_call(vin_to_source(vin), video, s_std, a);
if (ret < 0)
return ret;
 
/* Changing the standard will change the width/height */
-   ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, );
-   if (ret) {
-   vin_err(vin, "Failed to get initial format\n");
-   return ret;
-   }
-
-   vin->format.width = mf->width;
-   vin->format.height = mf->height;
-
-   vin->crop.top = vin->crop.left = 0;
-   vin->crop.width = mf->width;
-   vin->crop.height = mf->height;
-
-   vin->compose.top = vin->compose.left = 0;
-   vin->compose.width = mf->width;
-   vin->compose.height = mf->height;
-
-   return 0;
+   return rvin_reset_format(vin);
 }
 
 static int rvin_g_std(struct file *file, void *priv, v4l2_std_id *a)
@@ -779,10 +808,6 @@ static void rvin_notify(struct v4l2_subdev *sd,
 
 int rvin_v4l2_probe(struct rvin_dev *vin)
 {
-   struct v4l2_subdev_format fmt = {
-   .which = V4L2_SUBDEV_FORMAT_ACTIVE,
-   };
-   struct v4l2_mbus_framefmt *mf = 
struct video_device *vdev = >vdev;
struct v4l2_subdev *sd = vin_to_source(vin);
int pad_idx, ret;
@@ -839,31 +864,9 @@ int rvin_v4l2_probe(struct rvin_dev *vin)
return -EINVAL;
 
vin->src_pad_idx = pad_idx;
-   fmt.pad = vin->src_pad_idx;
-
-   /* Try to improve our guess of a reasonable window format */
-   ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, );
-   if (ret) {
-   vin_err(vin, "Failed to get initial format\n");
-   return ret;
-   }
 
-   /* Set default format */
-   vin->format.width   = mf->width;
-   vin->format.height  = mf->height;
-   vin->format.colorspace  = mf->colorspace;
-   vin->format.field  

[PATCHv3 1/6] media: adv7180: fill in mbus format in set_fmt

2016-09-02 Thread Niklas Söderlund
If the V4L2_SUBDEV_FORMAT_TRY is used in set_fmt the width, height etc
would not be filled.

Signed-off-by: Niklas Söderlund 
---
 drivers/media/i2c/adv7180.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/media/i2c/adv7180.c b/drivers/media/i2c/adv7180.c
index 515ea6a..50efecc 100644
--- a/drivers/media/i2c/adv7180.c
+++ b/drivers/media/i2c/adv7180.c
@@ -711,6 +711,7 @@ static int adv7180_set_pad_format(struct v4l2_subdev *sd,
 {
struct adv7180_state *state = to_state(sd);
struct v4l2_mbus_framefmt *framefmt;
+   int ret;
 
switch (format->format.field) {
case V4L2_FIELD_NONE:
@@ -722,8 +723,9 @@ static int adv7180_set_pad_format(struct v4l2_subdev *sd,
break;
}
 
+   ret = adv7180_mbus_fmt(sd,  >format);
+
if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
-   framefmt = >format;
if (state->field != format->format.field) {
state->field = format->format.field;
adv7180_set_power(state, false);
@@ -735,7 +737,7 @@ static int adv7180_set_pad_format(struct v4l2_subdev *sd,
*framefmt = format->format;
}
 
-   return adv7180_mbus_fmt(sd, framefmt);
+   return ret;
 }
 
 static int adv7180_g_mbus_config(struct v4l2_subdev *sd,
-- 
2.9.3

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


[PATCHv3 2/6] media: rcar-vin: make V4L2_FIELD_INTERLACED standard dependent

2016-09-02 Thread Niklas Söderlund
The field V4L2_FIELD_INTERLACED is standard dependent and should not
unconditionally be equivalent to V4L2_FIELD_INTERLACED_TB.

This patch adds a check to see if the video standard can be obtained and
if it's a 60 Hz format. If the condition is met V4L2_FIELD_INTERLACED
is treated as V4L2_FIELD_INTERLACED_BT if not as
V4L2_FIELD_INTERLACED_TB.

Signed-off-by: Niklas Söderlund 
---
 drivers/media/platform/rcar-vin/rcar-dma.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/drivers/media/platform/rcar-vin/rcar-dma.c 
b/drivers/media/platform/rcar-vin/rcar-dma.c
index 46abdb0..d57801b 100644
--- a/drivers/media/platform/rcar-vin/rcar-dma.c
+++ b/drivers/media/platform/rcar-vin/rcar-dma.c
@@ -131,6 +131,7 @@ static u32 rvin_read(struct rvin_dev *vin, u32 offset)
 static int rvin_setup(struct rvin_dev *vin)
 {
u32 vnmc, dmr, dmr2, interrupts;
+   v4l2_std_id std;
bool progressive = false, output_is_yuv = false, input_is_yuv = false;
 
switch (vin->format.field) {
@@ -141,6 +142,14 @@ static int rvin_setup(struct rvin_dev *vin)
vnmc = VNMC_IM_EVEN;
break;
case V4L2_FIELD_INTERLACED:
+   /* Default to TB */
+   vnmc = VNMC_IM_FULL;
+   /* Use BT if video standard can be read and is 60 Hz format */
+   if (!v4l2_subdev_call(vin_to_source(vin), video, g_std, )) {
+   if (std & V4L2_STD_525_60)
+   vnmc = VNMC_IM_FULL | VNMC_FOC;
+   }
+   break;
case V4L2_FIELD_INTERLACED_TB:
vnmc = VNMC_IM_FULL;
break;
-- 
2.9.3

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


[PATCHv3 5/6] media: rcar-vin: fix height for TOP and BOTTOM fields

2016-09-02 Thread Niklas Söderlund
The height used for V4L2_FIELD_TOP and V4L2_FIELD_BOTTOM where wrong.
The frames only contain one field so the height should be half of the
frame.

Signed-off-by: Niklas Söderlund 
---
 drivers/media/platform/rcar-vin/rcar-v4l2.c | 29 +
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c 
b/drivers/media/platform/rcar-vin/rcar-v4l2.c
index 47d8d97..1392514 100644
--- a/drivers/media/platform/rcar-vin/rcar-v4l2.c
+++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c
@@ -125,6 +125,8 @@ static int rvin_reset_format(struct rvin_dev *vin)
switch (vin->format.field) {
case V4L2_FIELD_TOP:
case V4L2_FIELD_BOTTOM:
+   vin->format.height /= 2;
+   break;
case V4L2_FIELD_NONE:
case V4L2_FIELD_INTERLACED_TB:
case V4L2_FIELD_INTERLACED_BT:
@@ -220,21 +222,13 @@ static int __rvin_try_format(struct rvin_dev *vin,
/* Limit to source capabilities */
__rvin_try_format_source(vin, which, pix, source);
 
-   /* If source can't match format try if VIN can scale */
-   if (source->width != rwidth || source->height != rheight)
-   rvin_scale_try(vin, pix, rwidth, rheight);
-
-   /* HW limit width to a multiple of 32 (2^5) for NV16 else 2 (2^1) */
-   walign = vin->format.pixelformat == V4L2_PIX_FMT_NV16 ? 5 : 1;
-
-   /* Limit to VIN capabilities */
-   v4l_bound_align_image(>width, 2, RVIN_MAX_WIDTH, walign,
- >height, 4, RVIN_MAX_HEIGHT, 2, 0);
-
switch (pix->field) {
-   case V4L2_FIELD_NONE:
case V4L2_FIELD_TOP:
case V4L2_FIELD_BOTTOM:
+   pix->height /= 2;
+   source->height /= 2;
+   break;
+   case V4L2_FIELD_NONE:
case V4L2_FIELD_INTERLACED_TB:
case V4L2_FIELD_INTERLACED_BT:
case V4L2_FIELD_INTERLACED:
@@ -244,6 +238,17 @@ static int __rvin_try_format(struct rvin_dev *vin,
break;
}
 
+   /* If source can't match format try if VIN can scale */
+   if (source->width != rwidth || source->height != rheight)
+   rvin_scale_try(vin, pix, rwidth, rheight);
+
+   /* HW limit width to a multiple of 32 (2^5) for NV16 else 2 (2^1) */
+   walign = vin->format.pixelformat == V4L2_PIX_FMT_NV16 ? 5 : 1;
+
+   /* Limit to VIN capabilities */
+   v4l_bound_align_image(>width, 2, RVIN_MAX_WIDTH, walign,
+ >height, 4, RVIN_MAX_HEIGHT, 2, 0);
+
pix->bytesperline = max_t(u32, pix->bytesperline,
  rvin_format_bytesperline(pix));
pix->sizeimage = max_t(u32, pix->sizeimage,
-- 
2.9.3

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


[PATCHv3 0/6] Fix rcar-vin field handling

2016-09-02 Thread Niklas Söderlund
Hi,

This series deals with how fields are handled in the rcar-vin driver.  
The current state is that the user is forced to use whatever field type 
is set by the subdevice. This series allows the user to freely choose 
the filed type.

It fixes the current handling of V4L2_FIELD_INTERLACED so that it 
depends on the current video standard to select between TB or BT mode 
(if the video standard can be determined that is). It also adds support 
for V4L2_FIELD_ALTERNATE.

All work is based on top of media-tree and is tested on Koelsch. Output 
of 'v4l2-compliance -fs' is attached bellow and I have tested all fields 
using qv4l2 and it looks OK to me. I need to disable 'Enable Video 
Scaling' in the 'Capture' Menu for ODD/EVEN/ALTERNATE or I get a 
horizontally stretched image. Also for ALTERNATE the 1 line difference 
between the fields are noticeable. The image jumps up/down 1 line for 
each other field, but I guess that is normal since the fields are 
different right?

# v4l2-compliance -d 2 -fs
v4l2-compliance SHA   : a737a6161485fffb70bf51e4fd7f6e2d910174c1

Driver Info:
Driver name   : rcar_vin
Card type : R_Car_VIN
Bus info  : platform:e6ef1000.video
Driver version: 4.8.0
Capabilities  : 0x8521
Video Capture
Read/Write
Streaming
Extended Pix Format
Device Capabilities
Device Caps   : 0x0521
Video Capture
Read/Write
Streaming
Extended Pix Format

Compliance test for device /dev/video2 (not using libv4l2):

Required ioctls:
test VIDIOC_QUERYCAP: OK

Allow for multiple opens:
test second video open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OK

Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported)
test VIDIOC_LOG_STATUS: OK

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported)
test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK
test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 1 Audio Inputs: 0 Tuners: 0

Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_ENUMAUDOUT: OK (Not Supported)
test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported)
test VIDIOC_G/S_AUDOUT: OK (Not Supported)
Outputs: 0 Audio Outputs: 0 Modulators: 0

Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK
test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported)
test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported)
test VIDIOC_G/S_EDID: OK (Not Supported)

Test input 0:

Control ioctls:
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK
test VIDIOC_QUERYCTRL: OK
test VIDIOC_G/S_CTRL: OK
test VIDIOC_G/S/TRY_EXT_CTRLS: OK
test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK
test VIDIOC_G/S_JPEGCOMP: OK (Not Supported)
Standard Controls: 5 Private Controls: 1

Format ioctls:
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK
test VIDIOC_G/S_PARM: OK
test VIDIOC_G_FBUF: OK (Not Supported)
test VIDIOC_G_FMT: OK
test VIDIOC_TRY_FMT: OK
test VIDIOC_S_FMT: OK
test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported)
test Cropping: OK
test Composing: OK
test Scaling: OK

Codec ioctls:
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported)
test VIDIOC_G_ENC_INDEX: OK (Not Supported)
test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)

Buffer ioctls:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK
test VIDIOC_EXPBUF: OK

Test input 0:

Streaming ioctls:
test read/write: OK
test MMAP: OKg
test USERPTR: OK (Not Supported)
test DMABUF: Cannot test, specify --expbuf-device

Stream using all formats:
test MMAP for Format NV16, Frame Size 2x4:
Crop 720x576@0x0, Compose 6x4@0x0, Stride 32, Field None: OKg
Crop 720x288@0x0, Compose 6x4@0x0, Stride 32, Field Top: OKg
Crop 720x288@0x0, Compose 6x4@0x0, Stride 32, Field Bottom: OKg
Crop 720x288@0x0, Compose 6x4@0x0, Stride 32, Field Interlaced: 
OKg
Crop 720x288@0x0, Compose 6x4@0x0, Stride 32, Field 
Alternating: OKg
Crop 720x288@0x0, Compose 6x4@0x0, Stride 32, Field Interlaced 
Top-Bottom: OKg
Crop 720x288@0x0, Compose 6x4@0x0, Stride 32, Field Interlaced 
Bottom-Top: OKg
  

[PATCHv3 6/6] media: rcar-vin: add support for V4L2_FIELD_ALTERNATE

2016-09-02 Thread Niklas Söderlund
The HW can capture both ODD and EVEN fields in separate buffers so it's
possible to support V4L2_FIELD_ALTERNATE. This patch add support for
this mode.

At probe time and when S_STD is called the driver will default to use
V4L2_FIELD_INTERLACED if the subdevice reports V4L2_FIELD_ALTERNATE. The
driver will only change the field type if the subdevice implements
G_STD, if not it will keep the default at V4L2_FIELD_ALTERNATE.

The user can always explicitly ask for V4L2_FIELD_ALTERNATE in S_FMT and
the driver will use that field format.

Signed-off-by: Niklas Söderlund 
---
 drivers/media/platform/rcar-vin/rcar-dma.c  | 26 --
 drivers/media/platform/rcar-vin/rcar-v4l2.c | 13 +
 2 files changed, 33 insertions(+), 6 deletions(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-dma.c 
b/drivers/media/platform/rcar-vin/rcar-dma.c
index d57801b..1da95ab 100644
--- a/drivers/media/platform/rcar-vin/rcar-dma.c
+++ b/drivers/media/platform/rcar-vin/rcar-dma.c
@@ -95,6 +95,7 @@
 /* Video n Module Status Register bits */
 #define VNMS_FBS_MASK  (3 << 3)
 #define VNMS_FBS_SHIFT 3
+#define VNMS_FS(1 << 2)
 #define VNMS_AV(1 << 1)
 #define VNMS_CA(1 << 0)
 
@@ -156,6 +157,7 @@ static int rvin_setup(struct rvin_dev *vin)
case V4L2_FIELD_INTERLACED_BT:
vnmc = VNMC_IM_FULL | VNMC_FOC;
break;
+   case V4L2_FIELD_ALTERNATE:
case V4L2_FIELD_NONE:
if (vin->continuous) {
vnmc = VNMC_IM_ODD_EVEN;
@@ -329,15 +331,26 @@ static bool rvin_capture_active(struct rvin_dev *vin)
return rvin_read(vin, VNMS_REG) & VNMS_CA;
 }
 
-static int rvin_get_active_slot(struct rvin_dev *vin)
+static int rvin_get_active_slot(struct rvin_dev *vin, u32 vnms)
 {
if (vin->continuous)
-   return (rvin_read(vin, VNMS_REG) & VNMS_FBS_MASK)
-   >> VNMS_FBS_SHIFT;
+   return (vnms & VNMS_FBS_MASK) >> VNMS_FBS_SHIFT;
 
return 0;
 }
 
+static enum v4l2_field rvin_get_active_field(struct rvin_dev *vin, u32 vnms)
+{
+   if (vin->format.field == V4L2_FIELD_ALTERNATE) {
+   /* If FS is set it's a Even field */
+   if (vnms & VNMS_FS)
+   return V4L2_FIELD_BOTTOM;
+   return V4L2_FIELD_TOP;
+   }
+
+   return vin->format.field;
+}
+
 static void rvin_set_slot_addr(struct rvin_dev *vin, int slot, dma_addr_t addr)
 {
const struct rvin_video_format *fmt;
@@ -878,7 +891,7 @@ static bool rvin_fill_hw(struct rvin_dev *vin)
 static irqreturn_t rvin_irq(int irq, void *data)
 {
struct rvin_dev *vin = data;
-   u32 int_status;
+   u32 int_status, vnms;
int slot;
unsigned int sequence, handled = 0;
unsigned long flags;
@@ -905,7 +918,8 @@ static irqreturn_t rvin_irq(int irq, void *data)
}
 
/* Prepare for capture and update state */
-   slot = rvin_get_active_slot(vin);
+   vnms = rvin_read(vin, VNMS_REG);
+   slot = rvin_get_active_slot(vin, vnms);
sequence = vin->sequence++;
 
vin_dbg(vin, "IRQ %02d: %d\tbuf0: %c buf1: %c buf2: %c\tmore: %d\n",
@@ -920,7 +934,7 @@ static irqreturn_t rvin_irq(int irq, void *data)
goto done;
 
/* Capture frame */
-   vin->queue_buf[slot]->field = vin->format.field;
+   vin->queue_buf[slot]->field = rvin_get_active_field(vin, vnms);
vin->queue_buf[slot]->sequence = sequence;
vin->queue_buf[slot]->vb2_buf.timestamp = ktime_get_ns();
vb2_buffer_done(>queue_buf[slot]->vb2_buf, VB2_BUF_STATE_DONE);
diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c 
b/drivers/media/platform/rcar-vin/rcar-v4l2.c
index 1392514..61e9b59 100644
--- a/drivers/media/platform/rcar-vin/rcar-v4l2.c
+++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c
@@ -122,9 +122,21 @@ static int rvin_reset_format(struct rvin_dev *vin)
vin->format.colorspace  = mf->colorspace;
vin->format.field   = mf->field;
 
+   /*
+* If the subdevice uses ALTERNATE field mode and G_STD is
+* implemented use the VIN HW to combine the two fields to
+* one INTERLACED frame. The ALTERNATE field mode can still
+* be requested in S_FMT and be respected, this is just the
+* default which is applied at probing or when S_STD is called.
+*/
+   if (vin->format.field == V4L2_FIELD_ALTERNATE &&
+   v4l2_subdev_has_op(vin_to_source(vin), video, g_std))
+   vin->format.field = V4L2_FIELD_INTERLACED;
+
switch (vin->format.field) {
case V4L2_FIELD_TOP:
case V4L2_FIELD_BOTTOM:
+   case V4L2_FIELD_ALTERNATE:
vin->format.height /= 2;
break;
case V4L2_FIELD_NONE:
@@ -225,6 +237,7 @@ static int __rvin_try_format(struct rvin_dev 

[PATCHv3 3/6] media: rcar-vin: allow field to be changed

2016-09-02 Thread Niklas Söderlund
The driver forced whatever field was set by the source subdevice to be
used. This patch allows the user to change from the default field.

Signed-off-by: Niklas Söderlund 
---
 drivers/media/platform/rcar-vin/rcar-v4l2.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/drivers/media/platform/rcar-vin/rcar-v4l2.c 
b/drivers/media/platform/rcar-vin/rcar-v4l2.c
index 62ca7e3..88bfee3 100644
--- a/drivers/media/platform/rcar-vin/rcar-v4l2.c
+++ b/drivers/media/platform/rcar-vin/rcar-v4l2.c
@@ -102,6 +102,7 @@ static int __rvin_try_format_source(struct rvin_dev *vin,
struct v4l2_subdev_format format = {
.which = which,
};
+   enum v4l2_field field;
int ret;
 
sd = vin_to_source(vin);
@@ -114,12 +115,16 @@ static int __rvin_try_format_source(struct rvin_dev *vin,
 
format.pad = vin->src_pad_idx;
 
+   field = pix->field;
+
ret = v4l2_subdev_call(sd, pad, set_fmt, pad_cfg, );
if (ret < 0 && ret != -ENOIOCTLCMD)
goto done;
 
v4l2_fill_pix_format(pix, );
 
+   pix->field = field;
+
source->width = pix->width;
source->height = pix->height;
 
@@ -143,6 +148,10 @@ static int __rvin_try_format(struct rvin_dev *vin,
rwidth = pix->width;
rheight = pix->height;
 
+   /* Keep current field if no specific one is asked for */
+   if (pix->field == V4L2_FIELD_ANY)
+   pix->field = vin->format.field;
+
/*
 * Retrieve format information and select the current format if the
 * requested format isn't supported.
-- 
2.9.3

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


Re: [PATCH] [media] rcar-vin: add legacy mode for wrong media bus formats

2016-09-02 Thread Niklas Söderlund
On 2016-08-22 11:12:59 +0200, Hans Verkuil wrote:
> On 07/20/2016 02:36 PM, Hans Verkuil wrote:
> > On 07/20/2016 02:29 PM, Niklas Söderlund wrote:
> >> Hi Hans,
> >>
> >> Thanks for your feedback.
> >>
> >> On 2016-07-20 11:48:40 +0200, Hans Verkuil wrote:
> >>> On 07/08/2016 12:43 PM, Niklas Söderlund wrote:
>  A recent bugfix to adv7180 brought to light that the rcar-vin driver are
>  looking for the wrong media bus format. It was looking for a YUVU format
>  but then expecting UYVY data. The bugfix for adv7180 will break the
>  usage of rcar-vin together with a adv7180 as found on Renesas R-Car2
>  Koelsch boards for example.
> 
>  This patch fix the rcar-vin driver to look for the correct UYVU formats
>  and adds a legacy mode. The legacy mode is needed since I don't know if
>  other devices provide a incorrect media bus format and I don't want to
>  break any working configurations. Hopefully the legacy mode can be
>  removed sometime in the future.
> >>>
> >>> I'd rather have a version without the legacy code. You have to assume that
> >>> subdevs return correct values otherwise what's the point of the mediabus
> >>> formats?
> >>>
> >>> So this is simply an adv7180 bug fix + this r-car fix to stay consistent
> >>> with the adv7180.
> >>
> >> On principal I agree with you. My goal with this patch is just to make
> >> sure there is no case where the rcar-vin driver won't work with the
> >> adv7180. The plan was to drop the legacy mode in a separate patch after
> >> both the adv7182 and rcar-vin patches where picked up.
> >>
> >> I'm happy to drop the 'legacy support' for the wrong formats from this
> >> patch as long as I can be sure that there is no breaking. Should I
> >> rewrite this patch to drop the wrong formats and submit it as a series
> >> together with the adv7180 patch so they can be picked up together? Or do
> >> you know of a better way?
> > 
> > Why not combine this patch and the adv7180 patch in a single patch? Just 
> > keep
> > Steve's Signed-off-by line together with yours. That way everything stays
> > in sync. The only other user of the adv7180 doesn't look at the mediabus
> > formats at all, so it isn't affected.
> 
> Niklas,
> 
> Were you planning to make a combined adv7180/rcar-vin patch for this?
> 
> I would prefer this solution rather than keeping legacy code around.

Sorry for the delay Hans. I just posted a combined patch for adv7180 and 
rcar-vin. Thanks for picking up the cleanup patches!

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


[PATCH] [media] adv7180: rcar-vin: change mbus format to UYVY

2016-09-02 Thread Niklas Söderlund
The media bus format reported by the adv7180 is wrong. Steve Longerbeam
posted a patch which changed the format to UYVY8_2X8 with the commit
message:

  Change the media bus format from YUYV8_2X8 to UYVY8_2X8. Colors
  now look correct when capturing with the i.mx6 backend. The other
  option is to set the SWPC bit in register 0x27 to swap the Cr and Cb
  output samples.

The rcar-vin driver was developed and tested with the adv7180 and
therefor suffers from the same issue, looking for the wrong media bus
format. The two errors corrected each other.

This patch takes Steve's patch and merge it with a fix for rcar-vin
driver. The rcar-vin driver is used used in together with the adv7180
och Koelsch and this ensures it will not break while fixing the adv7180
issue. I checked wit Steve and he was fine with me merging the patches.

Signed-off-by: Niklas Söderlund 
Suggested-by: Steve Longerbeam 

ADV7180 parts:

Signed-off-by: Steve Longerbeam 
Acked-by: Lars-Peter Clausen 
Tested-by: Tim Harvey 
Acked-by: Tim Harvey 
---
 drivers/media/i2c/adv7180.c | 4 ++--
 drivers/media/platform/rcar-vin/rcar-core.c | 4 ++--
 drivers/media/platform/rcar-vin/rcar-dma.c  | 4 ++--
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/media/i2c/adv7180.c b/drivers/media/i2c/adv7180.c
index 515ea6a..a6ac78b 100644
--- a/drivers/media/i2c/adv7180.c
+++ b/drivers/media/i2c/adv7180.c
@@ -633,7 +633,7 @@ static int adv7180_enum_mbus_code(struct v4l2_subdev *sd,
if (code->index != 0)
return -EINVAL;
 
-   code->code = MEDIA_BUS_FMT_YUYV8_2X8;
+   code->code = MEDIA_BUS_FMT_UYVY8_2X8;
 
return 0;
 }
@@ -643,7 +643,7 @@ static int adv7180_mbus_fmt(struct v4l2_subdev *sd,
 {
struct adv7180_state *state = to_state(sd);
 
-   fmt->code = MEDIA_BUS_FMT_YUYV8_2X8;
+   fmt->code = MEDIA_BUS_FMT_UYVY8_2X8;
fmt->colorspace = V4L2_COLORSPACE_SMPTE170M;
fmt->width = 720;
fmt->height = state->curr_norm & V4L2_STD_525_60 ? 480 : 576;
diff --git a/drivers/media/platform/rcar-vin/rcar-core.c 
b/drivers/media/platform/rcar-vin/rcar-core.c
index 64999a2..6219cba 100644
--- a/drivers/media/platform/rcar-vin/rcar-core.c
+++ b/drivers/media/platform/rcar-vin/rcar-core.c
@@ -43,8 +43,8 @@ static bool rvin_mbus_supported(struct rvin_graph_entity 
*entity)
code.index++;
switch (code.code) {
case MEDIA_BUS_FMT_YUYV8_1X16:
-   case MEDIA_BUS_FMT_YUYV8_2X8:
-   case MEDIA_BUS_FMT_YUYV10_2X10:
+   case MEDIA_BUS_FMT_UYVY8_2X8:
+   case MEDIA_BUS_FMT_UYVY10_2X10:
case MEDIA_BUS_FMT_RGB888_1X24:
entity->code = code.code;
return true;
diff --git a/drivers/media/platform/rcar-vin/rcar-dma.c 
b/drivers/media/platform/rcar-vin/rcar-dma.c
index 46abdb0..8c66a93 100644
--- a/drivers/media/platform/rcar-vin/rcar-dma.c
+++ b/drivers/media/platform/rcar-vin/rcar-dma.c
@@ -169,7 +169,7 @@ static int rvin_setup(struct rvin_dev *vin)
vnmc |= VNMC_INF_YUV16;
input_is_yuv = true;
break;
-   case MEDIA_BUS_FMT_YUYV8_2X8:
+   case MEDIA_BUS_FMT_UYVY8_2X8:
/* BT.656 8bit YCbCr422 or BT.601 8bit YCbCr422 */
vnmc |= vin->digital.mbus_cfg.type == V4L2_MBUS_BT656 ?
VNMC_INF_YUV8_BT656 : VNMC_INF_YUV8_BT601;
@@ -178,7 +178,7 @@ static int rvin_setup(struct rvin_dev *vin)
case MEDIA_BUS_FMT_RGB888_1X24:
vnmc |= VNMC_INF_RGB888;
break;
-   case MEDIA_BUS_FMT_YUYV10_2X10:
+   case MEDIA_BUS_FMT_UYVY10_2X10:
/* BT.656 10bit YCbCr422 or BT.601 10bit YCbCr422 */
vnmc |= vin->digital.mbus_cfg.type == V4L2_MBUS_BT656 ?
VNMC_INF_YUV10_BT656 : VNMC_INF_YUV10_BT601;
-- 
2.9.3

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


Re: [PATCH v4 3/5] media: Refactor copying IOCTL arguments from and to user space

2016-09-02 Thread Laurent Pinchart
Hi Sakari,

Thank you for the patch.

On Thursday 11 Aug 2016 23:29:16 Sakari Ailus wrote:
> Refactor copying the IOCTL argument structs from the user space and back,
> in order to reduce code copied around and make the implementation more
> robust.
> 
> As a result, the copying is done while not holding the graph mutex.
> 
> Signed-off-by: Sakari Ailus 
> Acked-by: Hans Verkuil 

Acked-by: Laurent Pinchart 

> ---
>  drivers/media/media-device.c | 190 +--
>  1 file changed, 90 insertions(+), 100 deletions(-)
> 
> diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
> index cc6c566..d1b47a4 100644
> --- a/drivers/media/media-device.c
> +++ b/drivers/media/media-device.c
> @@ -59,27 +59,24 @@ static int media_device_close(struct file *filp)
>  }
> 
>  static int media_device_get_info(struct media_device *dev,
> -  struct media_device_info __user *__info)
> +  struct media_device_info *info)
>  {
> - struct media_device_info info;
> -
> - memset(, 0, sizeof(info));
> + memset(info, 0, sizeof(*info));
> 
>   if (dev->driver_name[0])
> - strlcpy(info.driver, dev->driver_name, sizeof(info.driver));
> + strlcpy(info->driver, dev->driver_name, sizeof(info->driver));
>   else
> - strlcpy(info.driver, dev->dev->driver->name, 
sizeof(info.driver));
> + strlcpy(info->driver, dev->dev->driver->name,
> + sizeof(info->driver));
> 
> - strlcpy(info.model, dev->model, sizeof(info.model));
> - strlcpy(info.serial, dev->serial, sizeof(info.serial));
> - strlcpy(info.bus_info, dev->bus_info, sizeof(info.bus_info));
> + strlcpy(info->model, dev->model, sizeof(info->model));
> + strlcpy(info->serial, dev->serial, sizeof(info->serial));
> + strlcpy(info->bus_info, dev->bus_info, sizeof(info->bus_info));
> 
> - info.media_version = MEDIA_API_VERSION;
> - info.hw_revision = dev->hw_revision;
> - info.driver_version = dev->driver_version;
> + info->media_version = MEDIA_API_VERSION;
> + info->hw_revision = dev->hw_revision;
> + info->driver_version = dev->driver_version;
> 
> - if (copy_to_user(__info, , sizeof(*__info)))
> - return -EFAULT;
>   return 0;
>  }
> 
> @@ -101,29 +98,25 @@ static struct media_entity *find_entity(struct
> media_device *mdev, u32 id) }
> 
>  static long media_device_enum_entities(struct media_device *mdev,
> -struct media_entity_desc __user *uent)
> +struct media_entity_desc *entd)
>  {
>   struct media_entity *ent;
> - struct media_entity_desc u_ent;
> -
> - memset(_ent, 0, sizeof(u_ent));
> - if (copy_from_user(_ent.id, >id, sizeof(u_ent.id)))
> - return -EFAULT;
> -
> - ent = find_entity(mdev, u_ent.id);
> 
> + ent = find_entity(mdev, entd->id);
>   if (ent == NULL)
>   return -EINVAL;
> 
> - u_ent.id = media_entity_id(ent);
> + memset(entd, 0, sizeof(*entd));
> +
> + entd->id = media_entity_id(ent);
>   if (ent->name)
> - strlcpy(u_ent.name, ent->name, sizeof(u_ent.name));
> - u_ent.type = ent->function;
> - u_ent.revision = 0; /* Unused */
> - u_ent.flags = ent->flags;
> - u_ent.group_id = 0; /* Unused */
> - u_ent.pads = ent->num_pads;
> - u_ent.links = ent->num_links - ent->num_backlinks;
> + strlcpy(entd->name, ent->name, sizeof(entd->name));
> + entd->type = ent->function;
> + entd->revision = 0; /* Unused */
> + entd->flags = ent->flags;
> + entd->group_id = 0; /* Unused */
> + entd->pads = ent->num_pads;
> + entd->links = ent->num_links - ent->num_backlinks;
> 
>   /*
>* Workaround for a bug at media-ctl <= v1.10 that makes it to
> @@ -139,14 +132,13 @@ static long media_device_enum_entities(struct
> media_device *mdev, if (ent->function < MEDIA_ENT_F_OLD_BASE ||
>   ent->function > MEDIA_ENT_T_DEVNODE_UNKNOWN) {
>   if (is_media_entity_v4l2_subdev(ent))
> - u_ent.type = MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN;
> + entd->type = MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN;
>   else if (ent->function != MEDIA_ENT_F_IO_V4L)
> - u_ent.type = MEDIA_ENT_T_DEVNODE_UNKNOWN;
> + entd->type = MEDIA_ENT_T_DEVNODE_UNKNOWN;
>   }
> 
> - memcpy(_ent.raw, >info, sizeof(ent->info));
> - if (copy_to_user(uent, _ent, sizeof(u_ent)))
> - return -EFAULT;
> + memcpy(>raw, >info, sizeof(ent->info));
> +
>   return 0;
>  }
> 
> @@ -158,8 +150,8 @@ static void media_device_kpad_to_upad(const struct
> media_pad *kpad, upad->flags = kpad->flags;
>  }
> 
> -static long 

Re: [PATCH] [media] vivid: allow usage of vb2_dma_contig_memops through module param

2016-09-02 Thread Hans Verkuil
Hi Vincent,

On 09/02/2016 02:49 PM, Vincent Abriou wrote:
> Allow dma contiguous buffer allocation.
> The buffers generated by vivid could then be imported by drm/kms driver.

Does this work for a regular x86 PC? This has been tried before, and this 
assumes
that the device struct you pass to dma-contig can actually be used to allocate
'proper' memory. The last time I tried that (almost two years ago) it didn't 
work.

See my old code here:

https://git.linuxtv.org/hverkuil/media_tree.git/log/?h=vivid-alloc

So I won't accept this unless it has been tested on a regular intel cpu.

You should also base you patch on the media_tree master branch, the way 
allocation
context are passed around has changed so you patch won't apply.

Regards,

Hans

> 
> Signed-off-by: Vincent Abriou 
> ---
>  Documentation/video4linux/vivid.txt  |  5 +
>  drivers/media/platform/vivid/Kconfig |  1 +
>  drivers/media/platform/vivid/vivid-core.c| 28 
> +++-
>  drivers/media/platform/vivid/vivid-core.h|  1 +
>  drivers/media/platform/vivid/vivid-sdr-cap.c |  4 
>  drivers/media/platform/vivid/vivid-vbi-cap.c |  2 ++
>  drivers/media/platform/vivid/vivid-vbi-out.c |  2 ++
>  drivers/media/platform/vivid/vivid-vid-cap.c |  5 +
>  drivers/media/platform/vivid/vivid-vid-out.c |  5 +
>  9 files changed, 40 insertions(+), 13 deletions(-)
> 
> diff --git a/Documentation/video4linux/vivid.txt 
> b/Documentation/video4linux/vivid.txt
> index e35d376..5e978f7 100644
> --- a/Documentation/video4linux/vivid.txt
> +++ b/Documentation/video4linux/vivid.txt
> @@ -243,6 +243,11 @@ no_error_inj: if set disable the error injecting 
> controls. This option is
>   removed. Unless overridden by ccs_cap_mode and/or ccs_out_mode the
>   will default to enabling crop, compose and scaling.
>  
> +mem_ops_type: vb2 mem_ops type, default is 0. It specifies the way buffer 
> will
> + be allocated.
> + 0: vb2_vmalloc_memops
> + 1: vb2_dma_contig_memops
> +
>  Taken together, all these module options allow you to precisely customize
>  the driver behavior and test your application with all sorts of permutations.
>  It is also very suitable to emulate hardware that is not yet available, e.g.
> diff --git a/drivers/media/platform/vivid/Kconfig 
> b/drivers/media/platform/vivid/Kconfig
> index 0885e93..bc3b140 100644
> --- a/drivers/media/platform/vivid/Kconfig
> +++ b/drivers/media/platform/vivid/Kconfig
> @@ -7,6 +7,7 @@ config VIDEO_VIVID
>   select FB_CFB_COPYAREA
>   select FB_CFB_IMAGEBLIT
>   select VIDEOBUF2_VMALLOC
> + select VIDEOBUF2_DMA_CONTIG
>   default n
>   ---help---
> Enables a virtual video driver. This driver emulates a webcam,
> diff --git a/drivers/media/platform/vivid/vivid-core.c 
> b/drivers/media/platform/vivid/vivid-core.c
> index ec125bec..28be8a1 100644
> --- a/drivers/media/platform/vivid/vivid-core.c
> +++ b/drivers/media/platform/vivid/vivid-core.c
> @@ -30,6 +30,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -150,6 +151,12 @@ static bool no_error_inj;
>  module_param(no_error_inj, bool, 0444);
>  MODULE_PARM_DESC(no_error_inj, " if set disable the error injecting 
> controls");
>  
> +static unsigned mem_ops_type[VIVID_MAX_DEVS] = { [0 ... (VIVID_MAX_DEVS - 
> 1)] = 0 };
> +module_param_array(mem_ops_type, uint, NULL, 0444);
> +MODULE_PARM_DESC(mem_ops_type, " vb2 mem_ops type, default is 0.\n"
> +   "\t\t0 == vb2_vmalloc_memops\n"
> +   "\t\t1 == vb2_dma_contig_memops");
> +
>  static struct vivid_dev *vivid_devs[VIVID_MAX_DEVS];
>  
>  const struct v4l2_rect vivid_min_rect = {
> @@ -660,6 +667,7 @@ static int vivid_create_instance(struct platform_device 
> *pdev, int inst)
>   struct video_device *vfd;
>   struct vb2_queue *q;
>   unsigned node_type = node_types[inst];
> + const struct vb2_mem_ops *mem_ops = _vmalloc_memops;
>   v4l2_std_id tvnorms_cap = 0, tvnorms_out = 0;
>   int ret;
>   int i;
> @@ -1025,6 +1033,12 @@ static int vivid_create_instance(struct 
> platform_device *pdev, int inst)
>   INIT_LIST_HEAD(>vbi_out_active);
>   INIT_LIST_HEAD(>sdr_cap_active);
>  
> + if (mem_ops_type[inst] == 1) {
> + mem_ops = _dma_contig_memops;
> + dma_set_coherent_mask(>dev, DMA_BIT_MASK(32));
> + dev->alloc_ctx = vb2_dma_contig_init_ctx(dev->v4l2_dev.dev);
> + }
> +
>   /* start creating the vb2 queues */
>   if (dev->has_vid_cap) {
>   /* initialize vid_cap queue */
> @@ -1035,7 +1049,7 @@ static int vivid_create_instance(struct platform_device 
> *pdev, int inst)
>   q->drv_priv = dev;
>   q->buf_struct_size = sizeof(struct vivid_buffer);
>   q->ops = _vid_cap_qops;
> - q->mem_ops = _vmalloc_memops;
> + 

Re: [PATCH] doc-rst:sphinx-extensions: add metadata parallel-safe

2016-09-02 Thread Mauro Carvalho Chehab
Em Thu, 1 Sep 2016 18:22:09 +0200
Markus Heiser  escreveu:

> Am 01.09.2016 um 16:29 schrieb Jani Nikula :
> 
> > On Thu, 01 Sep 2016, Jonathan Corbet  wrote:  
> >> On Wed, 24 Aug 2016 15:35:24 +0200
> >> Markus Heiser  wrote:
> >>   
> >>> With metadata "parallel_read_safe = True" a extension is marked as
> >>> save for "parallel reading of source". This is needed if you want
> >>> build in parallel with N processes. E.g.:
> >>> 
> >>>  make SPHINXOPTS=-j4 htmldocs  
> >> 
> >> A definite improvement; applied to the docs tree, thanks.  
> > 
> > The Sphinx docs say -jN "should be considered experimental" [1]. Any
> > idea *how* experimental that is, really? Could we add some -j by
> > default?  
> 
> My experience is, that parallel build is only strong on "reading
> input" and weak on "writing output". I can't see any rich performance
> increase on more than -j2 ... 
> 
> Mauro posted [2] his experience with -j8 compared to serial. He
> also compares -j8 to -j16:
> 
> > PS: on my server with 16 dual-thread Xeon CPU, the gain with a
> > bigger value for -j was not impressive. Got about the same time as
> > with -j8 or -j32 there.  
> 
> I guess he will get nearly the same results with -j2 ;)
> 
> If we want to add a -j default, I suggest -j2. 

Actually, here I got better results with -j4, on my NUC with
one quad-core, 8 threads Intel(R) Core(TM) i7-6770HQ CPU @ 2.60GHz
and m2SATA SSD disk. 

This is with -j2:

$ make DOCBOOKS="" SPHINXOPTS="-j2" SPHINXDIRS=media 
SPHINX_CONF="conf_nitpick.py" htmldocs 2>err

real0m46.568s
user1m0.676s
sys 0m3.019s

And this is with -j4:

$ make DOCBOOKS="" SPHINXOPTS="-j4" SPHINXDIRS=media 
SPHINX_CONF="conf_nitpick.py" htmldocs 2>err

real0m25.356s
user1m1.408s
sys 0m2.912s

Btw, this is the result on a dual octa-core Intel(R) Xeon(R) CPU E5-2670 0 
@ 2.60GHz, CPU (total of 32 threads), using PCIe SSD disks:

$ for i in $(seq 32 -1 1); do echo "with SPHINXOPTS= -j$i"; make 
cleandocs;/usr/bin/time --format="real %E nuser %U sys %S" make DOCBOOKS=""  
SPHINXOPTS="-j$i" SPHINXDIRS=media SPHINX_CONF="conf.py" SPHINXDIRS=media 
htmldocs >err; done
with SPHINXOPTS= -j32
make[2]: warning: jobserver unavailable: using -j1.  Add '+' to parent make 
rule.
real 0:23.05 nuser 98.77 sys 6.45
with SPHINXOPTS= -j31
make[2]: warning: jobserver unavailable: using -j1.  Add '+' to parent make 
rule.
real 0:22.81 nuser 97.80 sys 6.12
with SPHINXOPTS= -j30
make[2]: warning: jobserver unavailable: using -j1.  Add '+' to parent make 
rule.
real 0:23.16 nuser 97.68 sys 6.41
with SPHINXOPTS= -j29
make[2]: warning: jobserver unavailable: using -j1.  Add '+' to parent make 
rule.
real 0:22.74 nuser 98.02 sys 6.33
with SPHINXOPTS= -j28
make[2]: warning: jobserver unavailable: using -j1.  Add '+' to parent make 
rule.
real 0:23.18 nuser 95.75 sys 6.14
with SPHINXOPTS= -j27
make[2]: warning: jobserver unavailable: using -j1.  Add '+' to parent make 
rule.
real 0:22.67 nuser 96.66 sys 6.27
with SPHINXOPTS= -j26
make[2]: warning: jobserver unavailable: using -j1.  Add '+' to parent make 
rule.
real 0:22.66 nuser 95.93 sys 6.50
with SPHINXOPTS= -j25
make[2]: warning: jobserver unavailable: using -j1.  Add '+' to parent make 
rule.
real 0:23.71 nuser 95.43 sys 6.43
with SPHINXOPTS= -j24
make[2]: warning: jobserver unavailable: using -j1.  Add '+' to parent make 
rule.
real 0:23.71 nuser 94.27 sys 6.42
with SPHINXOPTS= -j23
make[2]: warning: jobserver unavailable: using -j1.  Add '+' to parent make 
rule.
real 0:23.46 nuser 93.85 sys 6.35
with SPHINXOPTS= -j22
make[2]: warning: jobserver unavailable: using -j1.  Add '+' to parent make 
rule.
real 0:23.28 nuser 91.52 sys 6.29
with SPHINXOPTS= -j21
make[2]: warning: jobserver unavailable: using -j1.  Add '+' to parent make 
rule.
real 0:23.93 nuser 90.37 sys 6.14
with SPHINXOPTS= -j20
make[2]: warning: jobserver unavailable: using -j1.  Add '+' to parent make 
rule.
real 0:24.88 nuser 91.40 sys 6.36
with SPHINXOPTS= -j19
make[2]: warning: jobserver unavailable: using -j1.  Add '+' to parent make 
rule.
real 0:24.00 nuser 89.68 sys 5.82
with SPHINXOPTS= -j18
make[2]: warning: jobserver unavailable: using -j1.  Add '+' to parent make 
rule.
real 0:23.73 nuser 89.68 sys 5.92
with SPHINXOPTS= -j17
make[2]: warning: jobserver unavailable: using -j1.  Add '+' to parent make 
rule.
real 0:23.75 nuser 87.85 sys 5.58
with SPHINXOPTS= -j16
make[2]: warning: jobserver unavailable: using -j1.  Add '+' to parent make 
rule.
real 0:24.54 nuser 87.87 sys 5.94
with SPHINXOPTS= -j15
make[2]: warning: jobserver unavailable: using -j1.  Add '+' to parent make 
rule.
real 0:25.45 nuser 88.25 sys 6.28
with SPHINXOPTS= -j14
make[2]: warning: jobserver unavailable: using -j1.  Add '+' to parent make 
rule.
real 0:23.79 nuser 87.23 sys 5.80
with SPHINXOPTS= -j13
make[2]: warning: jobserver unavailable: using -j1.  Add '+' to parent make 
rule.
real 0:24.15 

[PATCH 1/2] v4l: Define a pixel format for the R-Car VSP1 2-D histogram engine

2016-09-02 Thread Niklas Söderlund
The format is used on the R-Car VSP1 video queues that carry
2-D histogram statistics data.

Signed-off-by: Niklas Söderlund 
---
 Documentation/media/uapi/v4l/meta-formats.rst  |   1 +
 .../media/uapi/v4l/pixfmt-meta-vsp1-hgt.rst| 150 +
 drivers/media/v4l2-core/v4l2-ioctl.c   |   1 +
 include/uapi/linux/videodev2.h |   3 +-
 4 files changed, 154 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/media/uapi/v4l/pixfmt-meta-vsp1-hgt.rst

diff --git a/Documentation/media/uapi/v4l/meta-formats.rst 
b/Documentation/media/uapi/v4l/meta-formats.rst
index 05ab91e..01e24e3 100644
--- a/Documentation/media/uapi/v4l/meta-formats.rst
+++ b/Documentation/media/uapi/v4l/meta-formats.rst
@@ -13,3 +13,4 @@ These formats are used for the :ref:`metadata` interface only.
 :maxdepth: 1
 
 pixfmt-meta-vsp1-hgo
+pixfmt-meta-vsp1-hgt
diff --git a/Documentation/media/uapi/v4l/pixfmt-meta-vsp1-hgt.rst 
b/Documentation/media/uapi/v4l/pixfmt-meta-vsp1-hgt.rst
new file mode 100644
index 000..a093f0a
--- /dev/null
+++ b/Documentation/media/uapi/v4l/pixfmt-meta-vsp1-hgt.rst
@@ -0,0 +1,150 @@
+.. -*- coding: utf-8; mode: rst -*-
+
+.. _v4l2-meta-fmt-vsp1-hgt:
+
+***
+V4L2_META_FMT_VSP1_HGT ('VSPT')
+***
+
+*man V4L2_META_FMT_VSP1_HGT(2)*
+
+Renesas R-Car VSP1 2-D Histogram Data
+
+
+Description
+===
+
+This format describes histogram data generated by the Renesas R-Car VSP1
+2-D Histogram (HGT) engine.
+
+The VSP1 HGT is a histogram computation engine that operates on HSV
+data. It operates on a possibly cropped and subsampled input image and
+computes the sum, maximum and minimum of the S component as well as a
+weighted frequency histogram based on the H and S components.
+
+The histogram is a matrix of 6 Hue and 32 Saturation buckets, 192 in
+total. Each HSV value is added to one or more buckets with a wight
+between 1 and 16 depending on how the Hue areas are setup. Finding the
+correct buckets is done by inspecting the H and S value independently.
+
+The Saturation position **n** (0 - 31) in the matrix are found by the
+expression:
+
+8 * n <= S < 8 * (n + 1)
+
+The Hue positions **m** (0 - 5) in the matrix depends on how the HGT Hue
+areas are configured. There are 6 user configurable Hue Areas which can
+be configured to cover overlapping Hue values:
+
+::
+
+ Area 0   Area 1   Area 2   Area 3   Area 4   Area 
5
+     

+   \   /|  |\   /|  |\   /|  |\   /|  |\   /|  |\   /| 
 |\   /
+\ / |  | \ / |  | \ / |  | \ / |  | \ / |  | \ / | 
 | \ /
+ X  |  |  X  |  |  X  |  |  X  |  |  X  |  |  X  | 
 |  X
+/ \ |  | / \ |  | / \ |  | / \ |  | / \ |  | / \ | 
 | / \
+   /   \|  |/   \|  |/   \|  |/   \|  |/   \|  |/   \| 
 |/   \
+  5U   0L  0U   1L  1U   2L  2U   3L  3U   4L  4U   5L 
 5U   0L
+<0..Hue 
Value255>
+
+As shown in the diagram a single Hue vale can be attributed to more then
+one Hue area. In such case the Hue value is attributed to both Hue
+Areas, but with a weight. The maximum weight is 16 and is associated
+with all Hue values that are inside the center of a Hue area (between nL
+-- nU). Values outside this area are weighted with a rounded down value
+along the diagonal line. If there is no overlapped areas specified the
+value is included in the lower area.
+
+The Hue area setup must match one of the following constrains:
+
+::
+
+0L <= 0U <= 1L <= 1U <= 2L <= 2U <= 3L <= 3U <= 4L <= 4U <= 5L <= 5U
+
+::
+
+0U <= 1L <= 1U <= 2L <= 2U <= 3L <= 3U <= 4L <= 4U <= 5L <= 5U <= 0L
+
+**Byte Order.**
+All data is stored in memory in little endian format. Each cell in the tables
+contains one byte.
+
+.. flat-table:: VSP1 HGT Data - (800 bytes)
+:header-rows:  2
+:stub-columns: 0
+
+* - Offset
+  - :cspan:`4` Memory
+* -
+  - [31:24]
+  - [23:16]
+  - [15:8]
+  - [7:0]
+* - 0
+  - -
+  - S max [7:0]
+  - -
+  - S min [7:0]
+* - 4
+  - :cspan:`4` S sum [31:0]
+* - 8
+  - -
+  - Hue Area 0 Lower Boundary (0L) [0:7]
+  - -
+  - Hue Area 0 Upper Boundary (0U) [0:7]
+* - 12
+  - -
+  - Hue Area 1 Lower Boundary (1L) [0:7]
+  - -
+  - Hue Area 1 Upper Boundary (1U) [0:7]
+* - 16
+  - -
+  - Hue Area 2 Lower Boundary (2L) [0:7]
+  - -
+  - Hue Area 2 Upper Boundary (2U) [0:7]
+* - 20
+  - -
+  - Hue Area 3 Lower Boundary (3L) [0:7]
+  - -
+  - Hue Area 3 Upper Boundary (3U) [0:7]
+* - 24
+  - -
+  - Hue Area 4 Lower Boundary (4L) [0:7]
+  - -
+  - 

[PATCH 0/2] v4l: vsp1: Add HGT support

2016-09-02 Thread Niklas Söderlund
Hi,

This series add support for the VSP1 2-D histogram engine HGT.

It's based on top of Laurent Pinchart tree at 
git://linuxtv.org/pinchartl/media.git hgo.

It is tested on Koelsch using a modified vsp-tests suite package, 
modifications can be found at https://git.ragnatech.se/vsp-tests hgt.

Niklas Söderlund (2):
  v4l: Define a pixel format for the R-Car VSP1 2-D histogram engine
  v4l: vsp1: Add HGT support

 Documentation/media/uapi/v4l/meta-formats.rst  |   1 +
 .../media/uapi/v4l/pixfmt-meta-vsp1-hgt.rst| 150 +++
 drivers/media/platform/vsp1/Makefile   |   2 +-
 drivers/media/platform/vsp1/vsp1.h |   3 +
 drivers/media/platform/vsp1/vsp1_drv.c |  32 +-
 drivers/media/platform/vsp1/vsp1_entity.c  |  33 +-
 drivers/media/platform/vsp1/vsp1_entity.h  |   1 +
 drivers/media/platform/vsp1/vsp1_hgt.c | 495 +
 drivers/media/platform/vsp1/vsp1_hgt.h |  51 +++
 drivers/media/platform/vsp1/vsp1_pipe.c|  16 +
 drivers/media/platform/vsp1/vsp1_pipe.h|   2 +
 drivers/media/platform/vsp1/vsp1_regs.h|   9 +
 drivers/media/platform/vsp1/vsp1_video.c   |  10 +-
 drivers/media/v4l2-core/v4l2-ioctl.c   |   1 +
 include/uapi/linux/videodev2.h |   3 +-
 15 files changed, 792 insertions(+), 17 deletions(-)
 create mode 100644 Documentation/media/uapi/v4l/pixfmt-meta-vsp1-hgt.rst
 create mode 100644 drivers/media/platform/vsp1/vsp1_hgt.c
 create mode 100644 drivers/media/platform/vsp1/vsp1_hgt.h

-- 
2.9.3

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


[PATCH 2/2] v4l: vsp1: Add HGT support

2016-09-02 Thread Niklas Söderlund
The HGT is a Histogram Generator Two-Dimensions. It computes a weighted
frequency histograms for hue and saturation areas over a configurable
region of the image with optional subsampling.

Signed-off-by: Niklas Söderlund 
---
 drivers/media/platform/vsp1/Makefile  |   2 +-
 drivers/media/platform/vsp1/vsp1.h|   3 +
 drivers/media/platform/vsp1/vsp1_drv.c|  32 +-
 drivers/media/platform/vsp1/vsp1_entity.c |  33 +-
 drivers/media/platform/vsp1/vsp1_entity.h |   1 +
 drivers/media/platform/vsp1/vsp1_hgt.c| 495 ++
 drivers/media/platform/vsp1/vsp1_hgt.h|  51 +++
 drivers/media/platform/vsp1/vsp1_pipe.c   |  16 +
 drivers/media/platform/vsp1/vsp1_pipe.h   |   2 +
 drivers/media/platform/vsp1/vsp1_regs.h   |   9 +
 drivers/media/platform/vsp1/vsp1_video.c  |  10 +-
 11 files changed, 638 insertions(+), 16 deletions(-)
 create mode 100644 drivers/media/platform/vsp1/vsp1_hgt.c
 create mode 100644 drivers/media/platform/vsp1/vsp1_hgt.h

diff --git a/drivers/media/platform/vsp1/Makefile 
b/drivers/media/platform/vsp1/Makefile
index 8ab6a06..a33afc3 100644
--- a/drivers/media/platform/vsp1/Makefile
+++ b/drivers/media/platform/vsp1/Makefile
@@ -3,7 +3,7 @@ vsp1-y  += vsp1_dl.o vsp1_drm.o 
vsp1_video.o
 vsp1-y += vsp1_rpf.o vsp1_rwpf.o vsp1_wpf.o
 vsp1-y += vsp1_clu.o vsp1_hsit.o vsp1_lut.o
 vsp1-y += vsp1_bru.o vsp1_sru.o vsp1_uds.o
-vsp1-y += vsp1_hgo.o vsp1_histo.o
+vsp1-y += vsp1_hgo.o vsp1_hgt.o vsp1_histo.o
 vsp1-y += vsp1_lif.o
 
 obj-$(CONFIG_VIDEO_RENESAS_VSP1)   += vsp1.o
diff --git a/drivers/media/platform/vsp1/vsp1.h 
b/drivers/media/platform/vsp1/vsp1.h
index 9dce3ea..012ce40 100644
--- a/drivers/media/platform/vsp1/vsp1.h
+++ b/drivers/media/platform/vsp1/vsp1.h
@@ -33,6 +33,7 @@ struct vsp1_platform_data;
 struct vsp1_bru;
 struct vsp1_clu;
 struct vsp1_hgo;
+struct vsp1_hgt;
 struct vsp1_hsit;
 struct vsp1_lif;
 struct vsp1_lut;
@@ -52,6 +53,7 @@ struct vsp1_uds;
 #define VSP1_HAS_WPF_VFLIP (1 << 5)
 #define VSP1_HAS_WPF_HFLIP (1 << 6)
 #define VSP1_HAS_HGO   (1 << 7)
+#define VSP1_HAS_HGT   (1 << 8)
 
 struct vsp1_device_info {
u32 version;
@@ -74,6 +76,7 @@ struct vsp1_device {
struct vsp1_bru *bru;
struct vsp1_clu *clu;
struct vsp1_hgo *hgo;
+   struct vsp1_hgt *hgt;
struct vsp1_hsit *hsi;
struct vsp1_hsit *hst;
struct vsp1_lif *lif;
diff --git a/drivers/media/platform/vsp1/vsp1_drv.c 
b/drivers/media/platform/vsp1/vsp1_drv.c
index 9684abf..828584f 100644
--- a/drivers/media/platform/vsp1/vsp1_drv.c
+++ b/drivers/media/platform/vsp1/vsp1_drv.c
@@ -31,6 +31,7 @@
 #include "vsp1_dl.h"
 #include "vsp1_drm.h"
 #include "vsp1_hgo.h"
+#include "vsp1_hgt.h"
 #include "vsp1_hsit.h"
 #include "vsp1_lif.h"
 #include "vsp1_lut.h"
@@ -107,6 +108,7 @@ static int vsp1_create_sink_links(struct vsp1_device *vsp1,
continue;
 
if (source->type == VSP1_ENTITY_HGO ||
+   source->type == VSP1_ENTITY_HGT ||
source->type == VSP1_ENTITY_LIF ||
source->type == VSP1_ENTITY_WPF)
continue;
@@ -160,6 +162,16 @@ static int vsp1_uapi_create_links(struct vsp1_device *vsp1)
return ret;
}
 
+   if (vsp1->hgt) {
+   ret = media_create_pad_link(>hgt->entity.subdev.entity,
+   HGT_PAD_SOURCE,
+   >hgt->histo.video.entity, 0,
+   MEDIA_LNK_FL_ENABLED |
+   MEDIA_LNK_FL_IMMUTABLE);
+   if (ret < 0)
+   return ret;
+   }
+
if (vsp1->lif) {
ret = media_create_pad_link(>wpf[0]->entity.subdev.entity,
RWPF_PAD_SOURCE,
@@ -300,6 +312,16 @@ static int vsp1_create_entities(struct vsp1_device *vsp1)
list_add_tail(>hgo->entity.list_dev, >entities);
}
 
+   if (vsp1->info->features & VSP1_HAS_HGT && vsp1->info->uapi) {
+   vsp1->hgt = vsp1_hgt_create(vsp1);
+   if (IS_ERR(vsp1->hgt)) {
+   ret = PTR_ERR(vsp1->hgt);
+   goto done;
+   }
+
+   list_add_tail(>hgt->entity.list_dev, >entities);
+   }
+
/* The LIF is only supported when used in conjunction with the DU, in
 * which case the userspace API is disabled. If the userspace API is
 * enabled skip the LIF, even when present.
@@ -583,7 +605,8 @@ static const struct vsp1_device_info vsp1_device_infos[] = {
.version = 

[PATCH] [media] vivid: allow usage of vb2_dma_contig_memops through module param

2016-09-02 Thread Vincent Abriou
Allow dma contiguous buffer allocation.
The buffers generated by vivid could then be imported by drm/kms driver.

Signed-off-by: Vincent Abriou 
---
 Documentation/video4linux/vivid.txt  |  5 +
 drivers/media/platform/vivid/Kconfig |  1 +
 drivers/media/platform/vivid/vivid-core.c| 28 +++-
 drivers/media/platform/vivid/vivid-core.h|  1 +
 drivers/media/platform/vivid/vivid-sdr-cap.c |  4 
 drivers/media/platform/vivid/vivid-vbi-cap.c |  2 ++
 drivers/media/platform/vivid/vivid-vbi-out.c |  2 ++
 drivers/media/platform/vivid/vivid-vid-cap.c |  5 +
 drivers/media/platform/vivid/vivid-vid-out.c |  5 +
 9 files changed, 40 insertions(+), 13 deletions(-)

diff --git a/Documentation/video4linux/vivid.txt 
b/Documentation/video4linux/vivid.txt
index e35d376..5e978f7 100644
--- a/Documentation/video4linux/vivid.txt
+++ b/Documentation/video4linux/vivid.txt
@@ -243,6 +243,11 @@ no_error_inj: if set disable the error injecting controls. 
This option is
removed. Unless overridden by ccs_cap_mode and/or ccs_out_mode the
will default to enabling crop, compose and scaling.
 
+mem_ops_type: vb2 mem_ops type, default is 0. It specifies the way buffer will
+   be allocated.
+   0: vb2_vmalloc_memops
+   1: vb2_dma_contig_memops
+
 Taken together, all these module options allow you to precisely customize
 the driver behavior and test your application with all sorts of permutations.
 It is also very suitable to emulate hardware that is not yet available, e.g.
diff --git a/drivers/media/platform/vivid/Kconfig 
b/drivers/media/platform/vivid/Kconfig
index 0885e93..bc3b140 100644
--- a/drivers/media/platform/vivid/Kconfig
+++ b/drivers/media/platform/vivid/Kconfig
@@ -7,6 +7,7 @@ config VIDEO_VIVID
select FB_CFB_COPYAREA
select FB_CFB_IMAGEBLIT
select VIDEOBUF2_VMALLOC
+   select VIDEOBUF2_DMA_CONTIG
default n
---help---
  Enables a virtual video driver. This driver emulates a webcam,
diff --git a/drivers/media/platform/vivid/vivid-core.c 
b/drivers/media/platform/vivid/vivid-core.c
index ec125bec..28be8a1 100644
--- a/drivers/media/platform/vivid/vivid-core.c
+++ b/drivers/media/platform/vivid/vivid-core.c
@@ -30,6 +30,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -150,6 +151,12 @@ static bool no_error_inj;
 module_param(no_error_inj, bool, 0444);
 MODULE_PARM_DESC(no_error_inj, " if set disable the error injecting controls");
 
+static unsigned mem_ops_type[VIVID_MAX_DEVS] = { [0 ... (VIVID_MAX_DEVS - 1)] 
= 0 };
+module_param_array(mem_ops_type, uint, NULL, 0444);
+MODULE_PARM_DESC(mem_ops_type, " vb2 mem_ops type, default is 0.\n"
+ "\t\t0 == vb2_vmalloc_memops\n"
+ "\t\t1 == vb2_dma_contig_memops");
+
 static struct vivid_dev *vivid_devs[VIVID_MAX_DEVS];
 
 const struct v4l2_rect vivid_min_rect = {
@@ -660,6 +667,7 @@ static int vivid_create_instance(struct platform_device 
*pdev, int inst)
struct video_device *vfd;
struct vb2_queue *q;
unsigned node_type = node_types[inst];
+   const struct vb2_mem_ops *mem_ops = _vmalloc_memops;
v4l2_std_id tvnorms_cap = 0, tvnorms_out = 0;
int ret;
int i;
@@ -1025,6 +1033,12 @@ static int vivid_create_instance(struct platform_device 
*pdev, int inst)
INIT_LIST_HEAD(>vbi_out_active);
INIT_LIST_HEAD(>sdr_cap_active);
 
+   if (mem_ops_type[inst] == 1) {
+   mem_ops = _dma_contig_memops;
+   dma_set_coherent_mask(>dev, DMA_BIT_MASK(32));
+   dev->alloc_ctx = vb2_dma_contig_init_ctx(dev->v4l2_dev.dev);
+   }
+
/* start creating the vb2 queues */
if (dev->has_vid_cap) {
/* initialize vid_cap queue */
@@ -1035,7 +1049,7 @@ static int vivid_create_instance(struct platform_device 
*pdev, int inst)
q->drv_priv = dev;
q->buf_struct_size = sizeof(struct vivid_buffer);
q->ops = _vid_cap_qops;
-   q->mem_ops = _vmalloc_memops;
+   q->mem_ops = mem_ops;
q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
q->min_buffers_needed = 2;
q->lock = >mutex;
@@ -1054,7 +1068,7 @@ static int vivid_create_instance(struct platform_device 
*pdev, int inst)
q->drv_priv = dev;
q->buf_struct_size = sizeof(struct vivid_buffer);
q->ops = _vid_out_qops;
-   q->mem_ops = _vmalloc_memops;
+   q->mem_ops = mem_ops;
q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
q->min_buffers_needed = 2;
q->lock = >mutex;
@@ -1073,7 +1087,7 @@ static int vivid_create_instance(struct platform_device 
*pdev, int inst)
q->drv_priv = dev;

[PATCH v5 8/9] Add documentation for V4L2_PIX_FMT_VP9.

2016-09-02 Thread Tiffany Lin
Add documentation for V4L2_PIX_FMT_VP9.

Signed-off-by: Tiffany Lin 
Signed-off-by: Wu-Cheng Li 
---
 Documentation/media/uapi/v4l/pixfmt-013.rst |8 
 1 file changed, 8 insertions(+)

diff --git a/Documentation/media/uapi/v4l/pixfmt-013.rst 
b/Documentation/media/uapi/v4l/pixfmt-013.rst
index bfef4f4..58e3ce6 100644
--- a/Documentation/media/uapi/v4l/pixfmt-013.rst
+++ b/Documentation/media/uapi/v4l/pixfmt-013.rst
@@ -129,3 +129,11 @@ Compressed Formats
-  'VP80'
 
-  VP8 video elementary stream.
+
+-  .. _V4L2-PIX-FMT-VP9:
+
+   -  ``V4L2_PIX_FMT_VP9``
+
+   -  'VP90'
+
+   -  VP9 video elementary stream.
-- 
1.7.9.5

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


[PATCH v5 5/9] vcodec: mediatek: Add Mediatek VP8 Video Decoder Driver

2016-09-02 Thread Tiffany Lin
Add vp8 decoder driver for MT8173

Signed-off-by: PC Chen 
Signed-off-by: Tiffany Lin 
---
 drivers/media/platform/mtk-vcodec/Makefile |1 +
 .../media/platform/mtk-vcodec/vdec/vdec_vp8_if.c   |  633 
 drivers/media/platform/mtk-vcodec/vdec_drv_if.c|3 +
 3 files changed, 637 insertions(+)
 create mode 100644 drivers/media/platform/mtk-vcodec/vdec/vdec_vp8_if.c

diff --git a/drivers/media/platform/mtk-vcodec/Makefile 
b/drivers/media/platform/mtk-vcodec/Makefile
index 58243ed..7743c81 100644
--- a/drivers/media/platform/mtk-vcodec/Makefile
+++ b/drivers/media/platform/mtk-vcodec/Makefile
@@ -4,6 +4,7 @@ obj-$(CONFIG_VIDEO_MEDIATEK_VCODEC) += mtk-vcodec-dec.o \
   mtk-vcodec-common.o
 
 mtk-vcodec-dec-y := vdec/vdec_h264_if.o \
+   vdec/vdec_vp8_if.o \
mtk_vcodec_dec_drv.o \
vdec_drv_if.o \
vdec_vpu_if.o \
diff --git a/drivers/media/platform/mtk-vcodec/vdec/vdec_vp8_if.c 
b/drivers/media/platform/mtk-vcodec/vdec/vdec_vp8_if.c
new file mode 100644
index 000..d4fce3e
--- /dev/null
+++ b/drivers/media/platform/mtk-vcodec/vdec/vdec_vp8_if.c
@@ -0,0 +1,633 @@
+/*
+ * Copyright (c) 2016 MediaTek Inc.
+ * Author: Jungchang Tsao 
+ *PC Chen 
+ *
+ * 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 "../vdec_drv_if.h"
+#include "../mtk_vcodec_util.h"
+#include "../mtk_vcodec_dec.h"
+#include "../mtk_vcodec_intr.h"
+#include "../vdec_vpu_if.h"
+#include "../vdec_drv_base.h"
+
+/* Decoding picture buffer size (3 reference frames plus current frame) */
+#define VP8_DPB_SIZE   4
+
+/* HW working buffer size (bytes) */
+#define VP8_WORKING_BUF_SZ (45 * 4096)
+
+/* HW control register address */
+#define VP8_SEGID_DRAM_ADDR0x3c
+#define VP8_HW_VLD_ADDR0x93C
+#define VP8_HW_VLD_VALUE   0x940
+#define VP8_BSASET 0x100
+#define VP8_BSDSET 0x104
+#define VP8_RW_CKEN_SET0x0
+#define VP8_RW_DCM_CON 0x18
+#define VP8_WO_VLD_SRST0x108
+#define VP8_RW_MISC_SYS_SEL0x84
+#define VP8_RW_MISC_SPEC_CON   0xC8
+#define VP8_WO_VLD_SRST0x108
+#define VP8_RW_VP8_CTRL0xA4
+#define VP8_RW_MISC_DCM_CON0xEC
+#define VP8_RW_MISC_SRST   0xF4
+#define VP8_RW_MISC_FUNC_CON   0xCC
+
+#define VP8_MAX_FRM_BUF_NUM5
+#define VP8_MAX_FRM_BUF_NODE_NUM   (VP8_MAX_FRM_BUF_NUM * 2)
+
+/* required buffer size (bytes) to store decode information */
+#define VP8_HW_SEGMENT_DATA_SZ 272
+#define VP8_HW_SEGMENT_UINT4
+
+#define VP8_DEC_TABLE_PROC_LOOP96
+#define VP8_DEC_TABLE_UNIT 3
+#define VP8_DEC_TABLE_SZ   300
+#define VP8_DEC_TABLE_OFFSET   2
+#define VP8_DEC_TABLE_RW_UNIT  4
+
+/**
+ * struct vdec_vp8_dec_info - decode misc information
+ * @working_buf_dma   : working buffer dma address
+ * @prev_y_dma: previous decoded frame buffer Y plane address
+ * @cur_y_fb_dma  : current plane Y frame buffer dma address
+ * @cur_c_fb_dma  : current plane C frame buffer dma address
+ * @bs_dma   : bitstream dma address
+ * @bs_sz: bitstream size
+ * @resolution_changed: resolution change flag 1 - changed,  0 - not change
+ * @show_frame   : display this frame or not
+ * @wait_key_frame: wait key frame coming
+ */
+struct vdec_vp8_dec_info {
+   uint64_t working_buf_dma;
+   uint64_t prev_y_dma;
+   uint64_t cur_y_fb_dma;
+   uint64_t cur_c_fb_dma;
+   uint64_t bs_dma;
+   uint32_t bs_sz;
+   uint32_t resolution_changed;
+   uint32_t show_frame;
+   uint32_t wait_key_frame;
+};
+
+/**
+ * struct vdec_vp8_vsi - VPU shared information
+ * @dec: decoding information
+ * @pic: picture information
+ * @dec_table  : decoder coefficient table
+ * @segment_buf: segmentation buffer
+ * @load_data  : flag to indicate reload decode data
+ */
+struct vdec_vp8_vsi {
+   struct vdec_vp8_dec_info dec;
+   struct vdec_pic_info pic;
+   uint32_t dec_table[VP8_DEC_TABLE_SZ];
+   uint32_t segment_buf[VP8_HW_SEGMENT_DATA_SZ][VP8_HW_SEGMENT_UINT];
+   uint32_t load_data;
+};
+
+/**
+ * struct 

[PATCH v5 6/9] videodev2.h: add V4L2_PIX_FMT_VP9 format.

2016-09-02 Thread Tiffany Lin
From: Wu-Cheng Li 

This adds VP9 video coding format, a successor to VP8.

Signed-off-by: Wu-Cheng Li 
Signed-off-by: Tiffany Lin 
---
 include/uapi/linux/videodev2.h |1 +
 1 file changed, 1 insertion(+)

diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index 5529741..43326c3 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -603,6 +603,7 @@ struct v4l2_pix_format {
 #define V4L2_PIX_FMT_VC1_ANNEX_G v4l2_fourcc('V', 'C', '1', 'G') /* SMPTE 421M 
Annex G compliant stream */
 #define V4L2_PIX_FMT_VC1_ANNEX_L v4l2_fourcc('V', 'C', '1', 'L') /* SMPTE 421M 
Annex L compliant stream */
 #define V4L2_PIX_FMT_VP8  v4l2_fourcc('V', 'P', '8', '0') /* VP8 */
+#define V4L2_PIX_FMT_VP9  v4l2_fourcc('V', 'P', '9', '0') /* VP9 */
 
 /*  Vendor-specific formats   */
 #define V4L2_PIX_FMT_CPIA1v4l2_fourcc('C', 'P', 'I', 'A') /* cpia1 YUV */
-- 
1.7.9.5

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


[PATCH v5 0/9] Add MT8173 Video Decoder Driver

2016-09-02 Thread Tiffany Lin
==
 Introduction
==

The purpose of this series is to add the driver for video codec hw embedded in 
the Mediatek's MT8173 SoCs.
Mediatek Video Codec is able to handle video decoding and encoding of in a 
range of formats.

This patch series rely on MTK VPU driver that have been merged in v4.8-rc1.
Mediatek Video Decoder driver rely on VPU driver to load, communicate with VPU.

Internally the driver uses videobuf2 framework, and MTK IOMMU and MTK SMI both 
have been merged in v4.6-rc1.

[1]https://chromium-review.googlesource.com/#/c/245241/

==
 Device interface
==

In principle the driver bases on v4l2 memory-to-memory framework:
it provides a single video node and each opened file handle gets its own 
private context with separate buffer queues. Each context consist of 2 buffer 
queues: OUTPUT (for source buffers, i.e. bitstream) and CAPTURE (for 
destination buffers, i.e. decoded video frames).
OUTPUT and CAPTURE buffer could be MMAP or DMABUF memory type.

Change in v5:
1. Merge wucheng's V4L2_PIX_FMT_VP9 series to this series
   V4L: add VP9 format documentation
   v4l2-ioctl: add VP9 format description.
   videodev2.h: add V4L2_PIX_FMT_VP9 format.
2. Remove V4L2_PIX_FMT_MT21C to another series

Change in v4:
1.Change V4L2_PIX_FMT_MT21 to v4l2_PIX_FMT_MT21C
2.Fix g/s_selection implementation
3.Refine code according to review comments and pass V4l2-compliance test

-/bin/sh: v4l2: not found
# v4l2-compliance -d /dev/video0
v4l2-compliance SHA   : fc45cdc502065bc1dfb4ef9ceb9a822bb9877bce

Driver Info:
Driver name   : mtk-vcodec-dec
Card type : platform:mt8173
Bus info  : platform:mt8173
Driver version: 4.8.0
Capabilities  : 0x84204000
Video Memory-to-Memory Multiplanar
Streaming
Extended Pix Format
Device Capabilities
Device Caps   : 0x04204000
Video Memory-to-Memory Multiplanar
Streaming
Extended Pix Format

Compliance test for device /dev/video0 (not using libv4l2):

Required ioctls:
test VIDIOC_QUERYCAP: OK

Allow for multiple opens:
test second video open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OK

Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported)
test VIDIOC_LOG_STATUS: OK (Not Supported)

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported)
test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK (Not Supported)
test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 0 Audio Inputs: 0 Tuners: 0

Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported)
test VIDIOC_G/S_FREQUENCY: OK (Not Supported)
test VIDIOC_ENUMAUDOUT: OK (Not Supported)
test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported)
test VIDIOC_G/S_AUDOUT: OK (Not Supported)
Outputs: 0 Audio Outputs: 0 Modulators: 0

Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported)
test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported)
test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported)
test VIDIOC_G/S_EDID: OK (Not Supported)

Control ioctls:
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK
test VIDIOC_QUERYCTRL: OK
test VIDIOC_G/S_CTRL: OK
test VIDIOC_G/S/TRY_EXT_CTRLS: OK
test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK
test VIDIOC_G/S_JPEGCOMP: OK (Not Supported)
Standard Controls: 2 Private Controls: 0

Format ioctls:
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK
test VIDIOC_G/S_PARM: OK (Not Supported)
test VIDIOC_G_FBUF: OK (Not Supported)
test VIDIOC_G_FMT: OK
test VIDIOC_TRY_FMT: OK
test VIDIOC_S_FMT: OK
test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported)
test Cropping: OK (Not Supported)
test Composing: OK
test Scaling: OK

Codec ioctls:
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported)
test VIDIOC_G_ENC_INDEX: OK (Not Supported)
test VIDIOC_(TRY_)DECODER_CMD: OK (Not Supported)

Buffer ioctls:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK
test VIDIOC_EXPBUF: OK

Test input 0:

Total: 43, Succeeded: 43, Failed: 0, Warnings: 0


Change in v3:
1. Refine vdec hw clock setting
2. Refine vp9 codec driver
3. Refine v4l2 codec driver

Change in v2:
1. Add documentation for V4L2_PIX_FMT_MT21 2. Remove DRM_FORMAT_MT21 2. Refine 
code according to review comments


Andrew-CT 

[PATCH v5 2/9] dt-bindings: Add a binding for Mediatek Video Decoder

2016-09-02 Thread Tiffany Lin
Add a DT binding documentation of Video Decoder for the
MT8173 SoC from Mediatek.

Signed-off-by: Tiffany Lin 
Acked-by: Rob Herring 
---
 .../devicetree/bindings/media/mediatek-vcodec.txt  |   57 ++--
 1 file changed, 53 insertions(+), 4 deletions(-)

diff --git a/Documentation/devicetree/bindings/media/mediatek-vcodec.txt 
b/Documentation/devicetree/bindings/media/mediatek-vcodec.txt
index 59a47a5..46c15c5 100644
--- a/Documentation/devicetree/bindings/media/mediatek-vcodec.txt
+++ b/Documentation/devicetree/bindings/media/mediatek-vcodec.txt
@@ -1,25 +1,74 @@
 Mediatek Video Codec
 
 Mediatek Video Codec is the video codec hw present in Mediatek SoCs which
-supports high resolution encoding functionalities.
+supports high resolution encoding and decoding functionalities.
 
 Required properties:
 - compatible : "mediatek,mt8173-vcodec-enc" for encoder
+  "mediatek,mt8173-vcodec-dec" for decoder.
 - reg : Physical base address of the video codec registers and length of
   memory mapped region.
 - interrupts : interrupt number to the cpu.
 - mediatek,larb : must contain the local arbiters in the current Socs.
 - clocks : list of clock specifiers, corresponding to entries in
   the clock-names property.
-- clock-names: encoder must contain "venc_sel_src", "venc_sel",
-- "venc_lt_sel_src", "venc_lt_sel".
+- clock-names: encoder must contain "venc_sel_src", "venc_sel",,
+  "venc_lt_sel_src", "venc_lt_sel", decoder must contain "vcodecpll",
+  "univpll_d2", "clk_cci400_sel", "vdec_sel", "vdecpll", "vencpll",
+  "venc_lt_sel", "vdec_bus_clk_src".
 - iommus : should point to the respective IOMMU block with master port as
   argument, see Documentation/devicetree/bindings/iommu/mediatek,iommu.txt
   for details.
 - mediatek,vpu : the node of video processor unit
 
+
 Example:
-vcodec_enc: vcodec@0x18002000 {
+
+vcodec_dec: vcodec@1600 {
+compatible = "mediatek,mt8173-vcodec-dec";
+reg = <0 0x1600 0 0x100>,   /*VDEC_SYS*/
+  <0 0x1602 0 0x1000>,  /*VDEC_MISC*/
+  <0 0x16021000 0 0x800>,   /*VDEC_LD*/
+  <0 0x16021800 0 0x800>,   /*VDEC_TOP*/
+  <0 0x16022000 0 0x1000>,  /*VDEC_CM*/
+  <0 0x16023000 0 0x1000>,  /*VDEC_AD*/
+  <0 0x16024000 0 0x1000>,  /*VDEC_AV*/
+  <0 0x16025000 0 0x1000>,  /*VDEC_PP*/
+  <0 0x16026800 0 0x800>,   /*VP8_VD*/
+  <0 0x16027000 0 0x800>,   /*VP6_VD*/
+  <0 0x16027800 0 0x800>,   /*VP8_VL*/
+  <0 0x16028400 0 0x400>;   /*VP9_VD*/
+interrupts = ;
+mediatek,larb = <>;
+iommus = < M4U_PORT_HW_VDEC_MC_EXT>,
+ < M4U_PORT_HW_VDEC_PP_EXT>,
+ < M4U_PORT_HW_VDEC_AVC_MV_EXT>,
+ < M4U_PORT_HW_VDEC_PRED_RD_EXT>,
+ < M4U_PORT_HW_VDEC_PRED_WR_EXT>,
+ < M4U_PORT_HW_VDEC_UFO_EXT>,
+ < M4U_PORT_HW_VDEC_VLD_EXT>,
+ < M4U_PORT_HW_VDEC_VLD2_EXT>;
+mediatek,vpu = <>;
+power-domains = < MT8173_POWER_DOMAIN_VDEC>;
+clocks = < CLK_APMIXED_VCODECPLL>,
+ < CLK_TOP_UNIVPLL_D2>,
+ < CLK_TOP_CCI400_SEL>,
+ < CLK_TOP_VDEC_SEL>,
+ < CLK_TOP_VCODECPLL>,
+ < CLK_APMIXED_VENCPLL>,
+ < CLK_TOP_VENC_LT_SEL>,
+ < CLK_TOP_VCODECPLL_370P5>;
+clock-names = "vcodecpll",
+  "univpll_d2",
+  "clk_cci400_sel",
+  "vdec_sel",
+  "vdecpll",
+  "vencpll",
+  "venc_lt_sel",
+  "vdec_bus_clk_src";
+  };
+
+  vcodec_enc: vcodec@0x18002000 {
 compatible = "mediatek,mt8173-vcodec-enc";
 reg = <0 0x18002000 0 0x1000>,/*VENC_SYS*/
   <0 0x19002000 0 0x1000>;/*VENC_LT_SYS*/
-- 
1.7.9.5

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


[PATCH v5 7/9] v4l2-ioctl: add VP9 format description.

2016-09-02 Thread Tiffany Lin
From: Wu-Cheng Li 

VP9 is a video coding format and a successor to VP8.

Signed-off-by: Wu-Cheng Li 
Signed-off-by: Tiffany Lin 
---
 drivers/media/v4l2-core/v4l2-ioctl.c |1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c 
b/drivers/media/v4l2-core/v4l2-ioctl.c
index eb6ccc7..2bd1581 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -1269,6 +1269,7 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
case V4L2_PIX_FMT_VC1_ANNEX_G:  descr = "VC-1 (SMPTE 412M Annex 
G)"; break;
case V4L2_PIX_FMT_VC1_ANNEX_L:  descr = "VC-1 (SMPTE 412M Annex 
L)"; break;
case V4L2_PIX_FMT_VP8:  descr = "VP8"; break;
+   case V4L2_PIX_FMT_VP9:  descr = "VP9"; break;
case V4L2_PIX_FMT_CPIA1:descr = "GSPCA CPiA YUV"; break;
case V4L2_PIX_FMT_WNVA: descr = "WNVA"; break;
case V4L2_PIX_FMT_SN9C10X:  descr = "GSPCA SN9C10X"; break;
-- 
1.7.9.5

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


[PATCH v5 3/9] vcodec: mediatek: Add Mediatek V4L2 Video Decoder Driver

2016-09-02 Thread Tiffany Lin
Add v4l2 layer decoder driver for MT8173

Signed-off-by: Tiffany Lin 
---
 drivers/media/platform/mtk-vcodec/Makefile |   12 +-
 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c | 1433 
 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h |   88 ++
 .../media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c |  394 ++
 .../media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c  |  205 +++
 .../media/platform/mtk-vcodec/mtk_vcodec_dec_pm.h  |   28 +
 drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h |   62 +-
 .../media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c |8 +-
 .../media/platform/mtk-vcodec/mtk_vcodec_intr.c|3 +-
 .../media/platform/mtk-vcodec/mtk_vcodec_util.c|   33 +-
 .../media/platform/mtk-vcodec/mtk_vcodec_util.h|5 +
 drivers/media/platform/mtk-vcodec/vdec_drv_base.h  |   55 +
 drivers/media/platform/mtk-vcodec/vdec_drv_if.c|  112 ++
 drivers/media/platform/mtk-vcodec/vdec_drv_if.h|  101 ++
 drivers/media/platform/mtk-vcodec/vdec_ipi_msg.h   |  103 ++
 drivers/media/platform/mtk-vcodec/vdec_vpu_if.c|  168 +++
 drivers/media/platform/mtk-vcodec/vdec_vpu_if.h|   96 ++
 17 files changed, 2884 insertions(+), 22 deletions(-)
 create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c
 create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.h
 create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
 create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c
 create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.h
 create mode 100644 drivers/media/platform/mtk-vcodec/vdec_drv_base.h
 create mode 100644 drivers/media/platform/mtk-vcodec/vdec_drv_if.c
 create mode 100644 drivers/media/platform/mtk-vcodec/vdec_drv_if.h
 create mode 100644 drivers/media/platform/mtk-vcodec/vdec_ipi_msg.h
 create mode 100644 drivers/media/platform/mtk-vcodec/vdec_vpu_if.c
 create mode 100644 drivers/media/platform/mtk-vcodec/vdec_vpu_if.h

diff --git a/drivers/media/platform/mtk-vcodec/Makefile 
b/drivers/media/platform/mtk-vcodec/Makefile
index dc5cb00..b54e823 100644
--- a/drivers/media/platform/mtk-vcodec/Makefile
+++ b/drivers/media/platform/mtk-vcodec/Makefile
@@ -1,7 +1,13 @@
 
-
-obj-$(CONFIG_VIDEO_MEDIATEK_VCODEC) += mtk-vcodec-enc.o mtk-vcodec-common.o
-
+obj-$(CONFIG_VIDEO_MEDIATEK_VCODEC) += mtk-vcodec-dec.o \
+  mtk-vcodec-enc.o \
+  mtk-vcodec-common.o
+
+mtk-vcodec-dec-y := mtk_vcodec_dec_drv.o \
+   vdec_drv_if.o \
+   vdec_vpu_if.o \
+   mtk_vcodec_dec.o \
+   mtk_vcodec_dec_pm.o \
 
 
 mtk-vcodec-enc-y := venc/venc_vp8_if.o \
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c 
b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c
new file mode 100644
index 000..d634e61
--- /dev/null
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c
@@ -0,0 +1,1433 @@
+/*
+* Copyright (c) 2016 MediaTek Inc.
+* Author: PC Chen 
+* Tiffany Lin 
+*
+* 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 "mtk_vcodec_drv.h"
+#include "mtk_vcodec_dec.h"
+#include "mtk_vcodec_intr.h"
+#include "mtk_vcodec_util.h"
+#include "vdec_drv_if.h"
+#include "mtk_vcodec_dec_pm.h"
+
+#define OUT_FMT_IDX0
+#define CAP_FMT_IDX0
+
+#define MTK_VDEC_MIN_W 64U
+#define MTK_VDEC_MIN_H 64U
+#define DFT_CFG_WIDTH  MTK_VDEC_MIN_W
+#define DFT_CFG_HEIGHT MTK_VDEC_MIN_H
+
+static struct mtk_video_fmt mtk_video_formats[] = {
+   {
+   .fourcc = V4L2_PIX_FMT_H264,
+   .type = MTK_FMT_DEC,
+   .num_planes = 1,
+   },
+   {
+   .fourcc = V4L2_PIX_FMT_VP8,
+   .type = MTK_FMT_DEC,
+   .num_planes = 1,
+   },
+};
+
+static const struct mtk_codec_framesizes mtk_vdec_framesizes[] = {
+   {
+   .fourcc = V4L2_PIX_FMT_H264,
+   .stepwise = {  MTK_VDEC_MIN_W, MTK_VDEC_MAX_W, 16,
+   MTK_VDEC_MIN_H, MTK_VDEC_MAX_H, 16 },
+   },
+   {
+   .fourcc = V4L2_PIX_FMT_VP8,
+   .stepwise = {  MTK_VDEC_MIN_W, MTK_VDEC_MAX_W, 16,
+   MTK_VDEC_MIN_H, MTK_VDEC_MAX_H, 16 },
+   },
+};
+
+#define NUM_SUPPORTED_FRAMESIZE ARRAY_SIZE(mtk_vdec_framesizes)
+#define NUM_FORMATS ARRAY_SIZE(mtk_video_formats)
+
+static struct mtk_video_fmt *mtk_vdec_find_format(struct v4l2_format *f)
+{
+   struct 

[PATCH v5 1/9] VPU: mediatek: Add decode support

2016-09-02 Thread Tiffany Lin
From: Andrew-CT Chen 

VPU driver add decode support

Signed-off-by: Andrew-CT Chen 
Signed-off-by: Tiffany Lin 
---
 drivers/media/platform/mtk-vpu/mtk_vpu.c |   12 
 drivers/media/platform/mtk-vpu/mtk_vpu.h |   27 +++
 2 files changed, 39 insertions(+)

diff --git a/drivers/media/platform/mtk-vpu/mtk_vpu.c 
b/drivers/media/platform/mtk-vpu/mtk_vpu.c
index c9bf58c..63510de 100644
--- a/drivers/media/platform/mtk-vpu/mtk_vpu.c
+++ b/drivers/media/platform/mtk-vpu/mtk_vpu.c
@@ -134,6 +134,8 @@ struct vpu_wdt {
  *
  * @signaled:  the signal of vpu initialization completed
  * @fw_ver:VPU firmware version
+ * @dec_capability:decoder capability which is not used for now and
+ * the value is reserved for future use
  * @enc_capability:encoder capability which is not used for now and
  * the value is reserved for future use
  * @wq:wait queue for VPU initialization status
@@ -141,6 +143,7 @@ struct vpu_wdt {
 struct vpu_run {
u32 signaled;
char fw_ver[VPU_FW_VER_LEN];
+   unsigned intdec_capability;
unsigned intenc_capability;
wait_queue_head_t wq;
 };
@@ -415,6 +418,14 @@ int vpu_wdt_reg_handler(struct platform_device *pdev,
 }
 EXPORT_SYMBOL_GPL(vpu_wdt_reg_handler);
 
+unsigned int vpu_get_vdec_hw_capa(struct platform_device *pdev)
+{
+   struct mtk_vpu *vpu = platform_get_drvdata(pdev);
+
+   return vpu->run.dec_capability;
+}
+EXPORT_SYMBOL_GPL(vpu_get_vdec_hw_capa);
+
 unsigned int vpu_get_venc_hw_capa(struct platform_device *pdev)
 {
struct mtk_vpu *vpu = platform_get_drvdata(pdev);
@@ -600,6 +611,7 @@ static void vpu_init_ipi_handler(void *data, unsigned int 
len, void *priv)
 
vpu->run.signaled = run->signaled;
strncpy(vpu->run.fw_ver, run->fw_ver, VPU_FW_VER_LEN);
+   vpu->run.dec_capability = run->dec_capability;
vpu->run.enc_capability = run->enc_capability;
wake_up_interruptible(>run.wq);
 }
diff --git a/drivers/media/platform/mtk-vpu/mtk_vpu.h 
b/drivers/media/platform/mtk-vpu/mtk_vpu.h
index 5ab37f0..f457479 100644
--- a/drivers/media/platform/mtk-vpu/mtk_vpu.h
+++ b/drivers/media/platform/mtk-vpu/mtk_vpu.h
@@ -37,6 +37,18 @@ typedef void (*ipi_handler_t) (void *data,
 command to VPU.
 For other IPI below, AP should send the request
 to VPU to trigger the interrupt.
+ * @IPI_VDEC_H264:  The interrupt from vpu is to notify kernel to
+handle H264 vidoe decoder job, and vice versa.
+Decode output format is always MT21 no matter what
+the input format is.
+ * @IPI_VDEC_VP8:   The interrupt from is to notify kernel to
+handle VP8 video decoder job, and vice versa.
+Decode output format is always MT21 no matter what
+the input format is.
+ * @IPI_VDEC_VP9:   The interrupt from vpu is to notify kernel to
+handle VP9 video decoder job, and vice versa.
+Decode output format is always MT21 no matter what
+the input format is.
  * @IPI_VENC_H264:  The interrupt from vpu is to notify kernel to
 handle H264 video encoder job, and vice versa.
  * @IPI_VENC_VP8:   The interrupt fro vpu is to notify kernel to
@@ -46,6 +58,9 @@ typedef void (*ipi_handler_t) (void *data,
 
 enum ipi_id {
IPI_VPU_INIT = 0,
+   IPI_VDEC_H264,
+   IPI_VDEC_VP8,
+   IPI_VDEC_VP9,
IPI_VENC_H264,
IPI_VENC_VP8,
IPI_MAX,
@@ -55,10 +70,12 @@ enum ipi_id {
  * enum rst_id - reset id to register reset function for VPU watchdog timeout
  *
  * @VPU_RST_ENC: encoder reset id
+ * @VPU_RST_DEC: decoder reset id
  * @VPU_RST_MAX: maximum reset id
  */
 enum rst_id {
VPU_RST_ENC,
+   VPU_RST_DEC,
VPU_RST_MAX,
 };
 
@@ -125,6 +142,16 @@ struct platform_device *vpu_get_plat_device(struct 
platform_device *pdev);
 int vpu_wdt_reg_handler(struct platform_device *pdev,
void vpu_wdt_reset_func(void *),
void *priv, enum rst_id id);
+
+/**
+ * vpu_get_vdec_hw_capa - get video decoder hardware capability
+ *
+ * @pdev:  VPU platform device
+ *
+ * Return: video decoder hardware capability
+ **/
+unsigned int vpu_get_vdec_hw_capa(struct platform_device *pdev);
+
 /**
  * vpu_get_venc_hw_capa - get video encoder hardware capability
  *
-- 
1.7.9.5

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


[PATCH v5 9/9] vcodec: mediatek: Add Mediatek VP9 Video Decoder Driver

2016-09-02 Thread Tiffany Lin
Add vp9 decoder driver for MT8173

Signed-off-by: Tiffany Lin 
---
 drivers/media/platform/mtk-vcodec/Makefile |1 +
 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c |   10 +
 .../media/platform/mtk-vcodec/vdec/vdec_vp9_if.c   |  967 
 drivers/media/platform/mtk-vcodec/vdec_drv_base.h  |1 +
 drivers/media/platform/mtk-vcodec/vdec_drv_if.c|4 +
 5 files changed, 983 insertions(+)
 create mode 100644 drivers/media/platform/mtk-vcodec/vdec/vdec_vp9_if.c

diff --git a/drivers/media/platform/mtk-vcodec/Makefile 
b/drivers/media/platform/mtk-vcodec/Makefile
index 7743c81..852d969 100644
--- a/drivers/media/platform/mtk-vcodec/Makefile
+++ b/drivers/media/platform/mtk-vcodec/Makefile
@@ -5,6 +5,7 @@ obj-$(CONFIG_VIDEO_MEDIATEK_VCODEC) += mtk-vcodec-dec.o \
 
 mtk-vcodec-dec-y := vdec/vdec_h264_if.o \
vdec/vdec_vp8_if.o \
+   vdec/vdec_vp9_if.o \
mtk_vcodec_dec_drv.o \
vdec_drv_if.o \
vdec_vpu_if.o \
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c 
b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c
index d634e61..28a8453 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c
@@ -43,6 +43,11 @@ static struct mtk_video_fmt mtk_video_formats[] = {
.type = MTK_FMT_DEC,
.num_planes = 1,
},
+   {
+   .fourcc = V4L2_PIX_FMT_VP9,
+   .type = MTK_FMT_DEC,
+   .num_planes = 1,
+   },
 };
 
 static const struct mtk_codec_framesizes mtk_vdec_framesizes[] = {
@@ -56,6 +61,11 @@ static const struct mtk_codec_framesizes 
mtk_vdec_framesizes[] = {
.stepwise = {  MTK_VDEC_MIN_W, MTK_VDEC_MAX_W, 16,
MTK_VDEC_MIN_H, MTK_VDEC_MAX_H, 16 },
},
+   {
+   .fourcc = V4L2_PIX_FMT_VP9,
+   .stepwise = {  MTK_VDEC_MIN_W, MTK_VDEC_MAX_W, 16,
+   MTK_VDEC_MIN_H, MTK_VDEC_MAX_H, 16 },
+   },
 };
 
 #define NUM_SUPPORTED_FRAMESIZE ARRAY_SIZE(mtk_vdec_framesizes)
diff --git a/drivers/media/platform/mtk-vcodec/vdec/vdec_vp9_if.c 
b/drivers/media/platform/mtk-vcodec/vdec/vdec_vp9_if.c
new file mode 100644
index 000..60a7b00
--- /dev/null
+++ b/drivers/media/platform/mtk-vcodec/vdec/vdec_vp9_if.c
@@ -0,0 +1,967 @@
+/*
+ * Copyright (c) 2016 MediaTek Inc.
+ * Author: Daniel Hsiao 
+ * Kai-Sean Yang 
+ * Tiffany Lin 
+ *
+ * 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 "../mtk_vcodec_intr.h"
+#include "../vdec_drv_base.h"
+#include "../vdec_vpu_if.h"
+
+#define VP9_SUPER_FRAME_BS_SZ 64
+#define MAX_VP9_DPB_SIZE   9
+
+#define REFS_PER_FRAME 3
+#define MAX_NUM_REF_FRAMES 8
+#define VP9_MAX_FRM_BUF_NUM 9
+#define VP9_MAX_FRM_BUF_NODE_NUM (VP9_MAX_FRM_BUF_NUM * 2)
+
+/**
+ * struct vp9_dram_buf - contains buffer info for vpu
+ * @va : cpu address
+ * @pa : iova address
+ * @sz : buffer size
+ * @padding : for 64 bytes alignment
+ */
+struct vp9_dram_buf {
+   unsigned long va;
+   unsigned long pa;
+   unsigned int sz;
+   unsigned int padding;
+};
+
+/**
+ * struct vp9_fb_info - contains frame buffer info
+ * @fb : frmae buffer
+ * @reserved : reserved field used by vpu
+ */
+struct vp9_fb_info {
+   struct vdec_fb *fb;
+   unsigned int reserved[32];
+};
+
+/**
+ * struct vp9_ref_cnt_buf - contains reference buffer information
+ * @buf : referenced frame buffer
+ * @ref_cnt : referenced frame buffer's reference count.
+ * When reference count=0, remove it from reference list
+ */
+struct vp9_ref_cnt_buf {
+   struct vp9_fb_info buf;
+   unsigned int ref_cnt;
+};
+
+/**
+ * struct vp9_fb_info - contains current frame's reference buffer information
+ * @buf : reference buffer
+ * @idx : reference buffer index to frm_bufs
+ * @reserved : reserved field used by vpu
+ */
+struct vp9_ref_buf {
+   struct vp9_fb_info *buf;
+   unsigned int idx;
+   unsigned int reserved[6];
+};
+
+/**
+ * struct vp9_fb_info - contains frame buffer info
+ * @fb : super frame reference frame buffer
+ * @used : this reference frame info entry is used
+ * @padding : for 64 bytes size align
+ */
+struct vp9_sf_ref_fb {
+   struct vdec_fb fb;
+   int used;
+   int padding;
+};
+
+/*
+ * struct vdec_vp9_vsi - shared buffer between host and VPU 

[PATCH v5 4/9] vcodec: mediatek: Add Mediatek H264 Video Decoder Drive

2016-09-02 Thread Tiffany Lin
Add h264 decoder driver for MT8173

Signed-off-by: PC Chen 
Signed-off-by: Tiffany Lin 
---
 drivers/media/platform/mtk-vcodec/Makefile |3 +-
 .../media/platform/mtk-vcodec/vdec/vdec_h264_if.c  |  506 
 drivers/media/platform/mtk-vcodec/vdec_drv_if.c|3 +
 3 files changed, 511 insertions(+), 1 deletion(-)
 create mode 100644 drivers/media/platform/mtk-vcodec/vdec/vdec_h264_if.c

diff --git a/drivers/media/platform/mtk-vcodec/Makefile 
b/drivers/media/platform/mtk-vcodec/Makefile
index b54e823..58243ed 100644
--- a/drivers/media/platform/mtk-vcodec/Makefile
+++ b/drivers/media/platform/mtk-vcodec/Makefile
@@ -3,7 +3,8 @@ obj-$(CONFIG_VIDEO_MEDIATEK_VCODEC) += mtk-vcodec-dec.o \
   mtk-vcodec-enc.o \
   mtk-vcodec-common.o
 
-mtk-vcodec-dec-y := mtk_vcodec_dec_drv.o \
+mtk-vcodec-dec-y := vdec/vdec_h264_if.o \
+   mtk_vcodec_dec_drv.o \
vdec_drv_if.o \
vdec_vpu_if.o \
mtk_vcodec_dec.o \
diff --git a/drivers/media/platform/mtk-vcodec/vdec/vdec_h264_if.c 
b/drivers/media/platform/mtk-vcodec/vdec/vdec_h264_if.c
new file mode 100644
index 000..0353a47
--- /dev/null
+++ b/drivers/media/platform/mtk-vcodec/vdec/vdec_h264_if.c
@@ -0,0 +1,506 @@
+/*
+ * Copyright (c) 2016 MediaTek Inc.
+ * Author: PC Chen 
+ *
+ * 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 "../vdec_drv_if.h"
+#include "../mtk_vcodec_util.h"
+#include "../mtk_vcodec_dec.h"
+#include "../mtk_vcodec_intr.h"
+#include "../vdec_vpu_if.h"
+#include "../vdec_drv_base.h"
+
+#define NAL_NON_IDR_SLICE  0x01
+#define NAL_IDR_SLICE  0x05
+#define NAL_H264_PPS   0x08
+#define NAL_TYPE(value)((value) & 0x1F)
+
+#define BUF_PREDICTION_SZ  (32 * 1024)
+
+#define MB_UNIT_LEN16
+
+/* motion vector size (bytes) for every macro block */
+#define HW_MB_STORE_SZ 64
+
+#define H264_MAX_FB_NUM17
+#define HDR_PARSING_BUF_SZ 1024
+
+/**
+ * struct h264_fb - h264 decode frame buffer information
+ * @vdec_fb_va  : virtual address of struct vdec_fb
+ * @y_fb_dma: dma address of Y frame buffer (luma)
+ * @c_fb_dma: dma address of C frame buffer (chroma)
+ * @poc : picture order count of frame buffer
+ * @reserved: for 8 bytes alignment
+ */
+struct h264_fb {
+   uint64_t vdec_fb_va;
+   uint64_t y_fb_dma;
+   uint64_t c_fb_dma;
+   int32_t poc;
+   uint32_t reserved;
+};
+
+/**
+ * struct h264_ring_fb_list - ring frame buffer list
+ * @fb_list   : frame buffer arrary
+ * @read_idx  : read index
+ * @write_idx : write index
+ * @count : buffer count in list
+ */
+struct h264_ring_fb_list {
+   struct h264_fb fb_list[H264_MAX_FB_NUM];
+   unsigned int read_idx;
+   unsigned int write_idx;
+   unsigned int count;
+   unsigned int reserved;
+};
+
+/**
+ * struct vdec_h264_dec_info - decode information
+ * @dpb_sz : decoding picture buffer size
+ * @resolution_changed  : resoltion change happen
+ * @realloc_mv_buf : flag to notify driver to re-allocate mv buffer
+ * @reserved   : for 8 bytes alignment
+ * @bs_dma : Input bit-stream buffer dma address
+ * @y_fb_dma   : Y frame buffer dma address
+ * @c_fb_dma   : C frame buffer dma address
+ * @vdec_fb_va : VDEC frame buffer struct virtual address
+ */
+struct vdec_h264_dec_info {
+   uint32_t dpb_sz;
+   uint32_t resolution_changed;
+   uint32_t realloc_mv_buf;
+   uint32_t reserved;
+   uint64_t bs_dma;
+   uint64_t y_fb_dma;
+   uint64_t c_fb_dma;
+   uint64_t vdec_fb_va;
+};
+
+/**
+ * struct vdec_h264_vsi - shared memory for decode information exchange
+ *between VPU and Host.
+ *The memory is allocated by VPU then mapping to Host
+ *in vpu_dec_init() and freed in vpu_dec_deinit()
+ *by VPU.
+ *AP-W/R : AP is writer/reader on this item
+ *VPU-W/R: VPU is write/reader on this item
+ * @hdr_buf  : Header parsing buffer (AP-W, VPU-R)
+ * @pred_buf_dma : HW working predication buffer dma address (AP-W, VPU-R)
+ * @mv_buf_dma   : HW working 

Re: [PATCH] v4l: Add metadata buffer type and format

2016-09-02 Thread Sakari Ailus
Hi Laurent,

On Fri, Sep 02, 2016 at 03:07:03PM +0300, Laurent Pinchart wrote:
> The metadata buffer type is used to transfer metadata between userspace
> and kernelspace through a V4L2 buffers queue. It comes with a new
> metadata capture capability and format description.
> 
> Signed-off-by: Laurent Pinchart 
> Tested-by: Guennadi Liakhovetski 

Acked-by: Sakari Ailus 

-- 
Sakari Ailus
e-mail: sakari.ai...@iki.fi XMPP: sai...@retiisi.org.uk
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] v4l: Add metadata buffer type and format

2016-09-02 Thread Laurent Pinchart
The metadata buffer type is used to transfer metadata between userspace
and kernelspace through a V4L2 buffers queue. It comes with a new
metadata capture capability and format description.

Signed-off-by: Laurent Pinchart 
Tested-by: Guennadi Liakhovetski 
---
Changes since v2:

- Dropped the reserved field from struct v4l2_meta_format
- Removed redundant documentation sentence
- Fixed typos

Changes since v1:

- Rebased on top of the DocBook to reST conversion

 Documentation/media/uapi/v4l/buffer.rst  |  8 +++
 Documentation/media/uapi/v4l/dev-meta.rst| 63 
 Documentation/media/uapi/v4l/devices.rst |  1 +
 Documentation/media/uapi/v4l/vidioc-querycap.rst | 14 --
 Documentation/media/videodev2.h.rst.exceptions   |  2 +
 drivers/media/v4l2-core/v4l2-compat-ioctl32.c| 19 +++
 drivers/media/v4l2-core/v4l2-dev.c   | 16 +++---
 drivers/media/v4l2-core/v4l2-ioctl.c | 34 +
 drivers/media/v4l2-core/videobuf2-v4l2.c |  3 ++
 include/media/v4l2-ioctl.h   | 17 +++
 include/uapi/linux/videodev2.h   | 13 +
 11 files changed, 181 insertions(+), 9 deletions(-)
 create mode 100644 Documentation/media/uapi/v4l/dev-meta.rst

diff --git a/Documentation/media/uapi/v4l/buffer.rst 
b/Documentation/media/uapi/v4l/buffer.rst
index 5deb4a46f992..b5177cc63b86 100644
--- a/Documentation/media/uapi/v4l/buffer.rst
+++ b/Documentation/media/uapi/v4l/buffer.rst
@@ -499,6 +499,14 @@ enum v4l2_buf_type
-  Buffer for Software Defined Radio (SDR) output stream, see
  :ref:`sdr`.
 
+-  .. row 13
+
+   -  ``V4L2_BUF_TYPE_META_CAPTURE``
+
+   -  13
+
+   -  Buffer for metadata capture, see :ref:`metadata`.
+
 
 
 .. _buffer-flags:
diff --git a/Documentation/media/uapi/v4l/dev-meta.rst 
b/Documentation/media/uapi/v4l/dev-meta.rst
new file mode 100644
index ..d3a33fea9cc9
--- /dev/null
+++ b/Documentation/media/uapi/v4l/dev-meta.rst
@@ -0,0 +1,63 @@
+.. -*- coding: utf-8; mode: rst -*-
+
+.. _metadata:
+
+**
+Metadata Interface
+**
+
+Metadata refers to any non-image data that supplements video frames with
+additional information. This may include statistics computed over the image
+or frame capture parameters supplied by the image source. This interface is
+intended for transfer of metadata to userspace and control of that operation.
+
+The metadata interface is implemented on video capture device nodes. The device
+can be dedicated to metadata or can implement both video and metadata capture
+as specified in its reported capabilities.
+
+.. note::
+
+This is an :ref:`experimental` interface and may
+change in the future.
+
+Querying Capabilities
+=
+
+Device nodes supporting the metadata interface set the 
``V4L2_CAP_META_CAPTURE``
+flag in the ``device_caps`` field of the
+:ref:`v4l2_capability ` structure returned by the
+:ref:`VIDIOC_QUERYCAP` ioctl. That flag means the device can capture
+metadata to memory.
+
+At least one of the read/write or streaming I/O methods must be supported.
+
+
+Data Format Negotiation
+===
+
+The metadata device uses the :ref:`format` ioctls to select the capture format.
+The metadata buffer content format is bound to that selected format. In 
addition
+to the basic :ref:`format` ioctls, the :ref:`VIDIOC_ENUM_FMT` ioctl must be
+supported as well.
+
+To use the :ref:`format` ioctls applications set the ``type`` field of the
+:ref:`v4l2_format ` structure to ``V4L2_BUF_TYPE_META_CAPTURE``
+and use the :ref:`v4l2_meta_format ` ``meta`` member of the
+``fmt`` union as needed per the desired operation. Both drivers and 
applications
+must set the remainder of the :ref:`v4l2_format ` structure to 0.
+
+.. _v4l2-meta-format:
+.. flat-table:: struct v4l2_meta_format
+:header-rows:  0
+:stub-columns: 0
+:widths:   1 1 2
+
+* - __u32
+  - ``dataformat``
+  - The data format, set by the application. This is a little endian
+:ref:`four character code `. V4L2 defines metadata formats
+in :ref:`meta-formats`.
+* - __u32
+  - ``buffersize``
+  - Maximum buffer size in bytes required for data. The value is set by the
+driver.
diff --git a/Documentation/media/uapi/v4l/devices.rst 
b/Documentation/media/uapi/v4l/devices.rst
index aed0ce11d1f8..961e7fb62063 100644
--- a/Documentation/media/uapi/v4l/devices.rst
+++ b/Documentation/media/uapi/v4l/devices.rst
@@ -24,3 +24,4 @@ Interfaces
 dev-sdr
 dev-event
 dev-subdev
+dev-meta
diff --git a/Documentation/media/uapi/v4l/vidioc-querycap.rst 
b/Documentation/media/uapi/v4l/vidioc-querycap.rst
index b10fed313f99..734fae6fc5e4 100644
--- a/Documentation/media/uapi/v4l/vidioc-querycap.rst
+++ b/Documentation/media/uapi/v4l/vidioc-querycap.rst
@@ -387,6 +387,14 @@ 

Re: [PATCH v2 7/7] [media] rc: add support for IR LEDs driven through SPI

2016-09-02 Thread Sean Young
On Fri, Sep 02, 2016 at 02:27:08PM +0900, Andi Shyti wrote:
> > Thanks Andi, this is looking great!
> 
> Thanks Sean! With your reviews the whole thing looks much better
> now :)
> 
> I agree with all your points here, I will fix them. Can I add
> your reviewd-by?

Yes, please add it to this patch.

Thanks,

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


Re: [PATCH v2 5/7] [media] ir-lirc-codec: don't wait any transmitting time for tx only devices

2016-09-02 Thread Sean Young
On Fri, Sep 02, 2016 at 02:16:27AM +0900, Andi Shyti wrote:
> Transmitters do not need to wait until the data has been sent
> (and of course received). Return before waiting.
> 
> Signed-off-by: Andi Shyti 
> ---
>  drivers/media/rc/ir-lirc-codec.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/media/rc/ir-lirc-codec.c 
> b/drivers/media/rc/ir-lirc-codec.c
> index c327730..d8953fb 100644
> --- a/drivers/media/rc/ir-lirc-codec.c
> +++ b/drivers/media/rc/ir-lirc-codec.c
> @@ -153,7 +153,7 @@ static ssize_t ir_lirc_transmit_ir(struct file *file, 
> const char __user *buf,
>   }
>  
>   ret = dev->tx_ir(dev, txbuf, count);
> - if (ret < 0)
> + if (ret < 0 || dev->driver_type == RC_DRIVER_IR_RAW_TX)

Just because a driver only does transmit doesn't mean its transmit ABI
should change.

Now this bit of code is pretty horrible. It ensures that the call to write()
takes at least as long as the length of the transmit IR by sleeping. That's
not much of a guarantee that the IR has been sent.

Note that in the case of ir-spi, since your spi transfer is sync no sleep
should be introduced here.

The gap calculation in lirc checks that if the call to write() took _longer_
than expected wait before sending the next IR code (when either multiple
IR codes or repeats are specified). Introducing the sleep in the kernel
here does not help at all, lirc already ensures that it waits as long as
the IR is long (see schedule_repeat_timer in lirc).

This change was introduced in 3.10, commit f8e00d5. 


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


Re: [PATCH v2 1/4] v4l: Add metadata buffer type and format

2016-09-02 Thread Sakari Ailus
Hi Laurent,

On Fri, Sep 02, 2016 at 12:40:18AM +0300, Laurent Pinchart wrote:
...
> > >> +Data Format Negotiation
> > >> +===
> > >> +
> > >> +The metadata device uses the :ref:`format` ioctls to select the capture
> > >> format. +The metadata buffer content format is bound to that selected
> > >> format. In addition +to the basic :ref:`format` ioctls, the
> > >> 
> > >> :ref:`VIDIOC_ENUM_FMT` ioctl must be +supported as well.
> > >> 
> > >> +
> > >> +To use the :ref:`format` ioctls applications set the ``type`` of the
> > >> +:ref:`v4l2_format ` structure to
> > >> ``V4L2_BUF_TYPE_META_CAPTURE`` +and use the :ref:`v4l2_meta_format
> > >> ` ``meta`` member of the +``fmt`` union as needed per
> > >> the desired operation. The :ref:`v4l2-meta-format` +structure contains
> > >> two fields, ``dataformat`` is set by applications to the V4L2
> > > 
> > > I might not specify the number of number of fields here. It has high
> > > chances of not getting updated when more fields are added. Up to you.
> > 
> > This has been copied from dev-sdr.rst. I can drop the last sentence
> > completely as the parameters are described in the table below. Hans, any
> > opinion ?
> 
> How about this ?
> 
> To use the :ref:`format` ioctls applications set the ``type`` of the

s/of/field of/

?

> :ref:`v4l2_format ` structure to ``V4L2_BUF_TYPE_META_CAPTURE``
> and use the :ref:`v4l2_meta_format ` ``meta`` member of the
> ``fmt`` union as needed per the desired operation. Both drivers and 
> applications must set the remainder of the :ref:`v4l2_format ` 
> structure to 0.

-- 
Sakari Ailus
e-mail: sakari.ai...@iki.fi XMPP: sai...@retiisi.org.uk
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 1/4] v4l: Add metadata buffer type and format

2016-09-02 Thread Sakari Ailus
Huomenta!

On Fri, Sep 02, 2016 at 12:22:42AM +0300, Laurent Pinchart wrote:
> Hi Sakari,
> 
> On Monday 29 Aug 2016 12:13:40 Sakari Ailus wrote:
> > On Wed, Aug 17, 2016 at 03:20:27PM +0300, Laurent Pinchart wrote:
> > > The metadata buffer type is used to transfer metadata between userspace
> > > and kernelspace through a V4L2 buffers queue. It comes with a new
> > > metadata capture capability and format description.
> > > 
> > > Signed-off-by: Laurent Pinchart
> > > 
> > > Tested-by: Guennadi Liakhovetski 
> > > ---
> > > Changes since v1:
> > > 
> > > - Rebased on top of the DocBook to reST conversion
> > > 
> > >  Documentation/media/uapi/v4l/buffer.rst  |  8 +++
> > >  Documentation/media/uapi/v4l/dev-meta.rst| 69 +++
> > >  Documentation/media/uapi/v4l/devices.rst |  1 +
> > >  Documentation/media/uapi/v4l/vidioc-querycap.rst | 14 +++--
> > >  Documentation/media/videodev2.h.rst.exceptions   |  2 +
> > >  drivers/media/v4l2-core/v4l2-compat-ioctl32.c| 19 +++
> > >  drivers/media/v4l2-core/v4l2-dev.c   | 16 +++---
> > >  drivers/media/v4l2-core/v4l2-ioctl.c | 41 ++
> > >  drivers/media/v4l2-core/videobuf2-v4l2.c |  3 ++
> > >  include/media/v4l2-ioctl.h   | 17 ++
> > >  include/uapi/linux/videodev2.h   | 14 +
> > >  11 files changed, 195 insertions(+), 9 deletions(-)
> > >  create mode 100644 Documentation/media/uapi/v4l/dev-meta.rst
> 
> [snip]
> 
> > > diff --git a/Documentation/media/uapi/v4l/dev-meta.rst
> > > b/Documentation/media/uapi/v4l/dev-meta.rst new file mode 100644
> > > index ..252ed05b4841
> > > --- /dev/null
> > > +++ b/Documentation/media/uapi/v4l/dev-meta.rst
> > > @@ -0,0 +1,69 @@
> > > +.. -*- coding: utf-8; mode: rst -*-
> > > +
> > > +.. _metadata:
> > > +
> > > +**
> > > +Metadata Interface
> > > +**
> > > +
> > > +Metadata refers to any non-image data that supplements video frames with
> > > +additional information. This may include statistics computed over the
> > > image +or frame capture parameters supplied by the image source. This
> > > interface is +intended for transfer of metadata to userspace and control
> > > of that operation. +
> > > +The metadata interface is implemented on video capture device nodes. The
> > > device +can be dedicated to metadata or can implement both video and
> > > metadata capture +as specified in its reported capabilities.
> > > +
> > > +.. note::
> > > +
> > > +This is an :ref:`experimental` interface and may
> > > +change in the future.
> > > +
> > > +Querying Capabilities
> > > +=
> > > +
> > > +Device nodes supporting the metadata interface set the
> > > ``V4L2_CAP_META_CAPTURE`` +flag in the ``device_caps`` field of the
> > > +:ref:`v4l2_capability ` structure returned by the
> > > +:ref:`VIDIOC_QUERYCAP` ioctl. That flag means the device can capture
> > > +metadata to memory.
> > > +
> > > +At least one of the read/write or streaming I/O methods must be
> > > supported.
> > > +
> > > +
> > > +Data Format Negotiation
> > > +===
> > > +
> > > +The metadata device uses the :ref:`format` ioctls to select the capture
> > > format. +The metadata buffer content format is bound to that selected
> > > format. In addition +to the basic :ref:`format` ioctls, the
> > > :ref:`VIDIOC_ENUM_FMT` ioctl must be +supported as well.
> > > +
> > > +To use the :ref:`format` ioctls applications set the ``type`` of the
> > > +:ref:`v4l2_format ` structure to
> > > ``V4L2_BUF_TYPE_META_CAPTURE`` +and use the :ref:`v4l2_meta_format
> > > ` ``meta`` member of the +``fmt`` union as needed per
> > > the desired operation. The :ref:`v4l2-meta-format` +structure contains
> > > two fields, ``dataformat`` is set by applications to the V4L2
> >
> > I might not specify the number of number of fields here. It has high chances
> > of not getting updated when more fields are added. Up to you.
> 
> This has been copied from dev-sdr.rst. I can drop the last sentence 
> completely 
> as the parameters are described in the table below. Hans, any opinion ?
> 
> > > +FourCC code of the desired format, and ``buffersize`` set by drivers to
> > > the +maximum buffer size (in bytes) required for data transfer.
> > > +
> > > +.. _v4l2-meta-format:
> > > +.. flat-table:: struct v4l2_meta_format
> > > +:header-rows:  0
> > > +:stub-columns: 0
> > > +:widths:   1 1 2
> > > +
> > > +* - __u32
> > > +  - ``dataformat``
> > > +  - The data format, set by the application. This is a little endian
> > > +:ref:`four character code `. V4L2 defines metadata
> > > formats +in :ref:`meta-formats`.
> > > +* - __u32
> > > +  - ``buffersize``
> > > +  - Maximum buffer size in bytes required for data. The value is set
> > > by the +driver.