[PATCH v5 10/14] media: ov772x: reconstruct s_frame_interval()

2018-05-06 Thread Akinobu Mita
This splits the s_frame_interval() in subdev video ops into selecting the
frame interval and setting up the registers.

This is a preparatory change to avoid accessing registers under power
saving mode.

Cc: Jacopo Mondi 
Cc: Laurent Pinchart 
Cc: Hans Verkuil 
Cc: Sakari Ailus 
Cc: Mauro Carvalho Chehab 
Signed-off-by: Akinobu Mita 
---
* v5
- Align arguments to open parenthesis
- Sort variable declarations

 drivers/media/i2c/ov772x.c | 56 +-
 1 file changed, 35 insertions(+), 21 deletions(-)

diff --git a/drivers/media/i2c/ov772x.c b/drivers/media/i2c/ov772x.c
index 6c0c792..92ad13f 100644
--- a/drivers/media/i2c/ov772x.c
+++ b/drivers/media/i2c/ov772x.c
@@ -617,25 +617,16 @@ static int ov772x_s_stream(struct v4l2_subdev *sd, int 
enable)
return 0;
 }
 
-static int ov772x_set_frame_rate(struct ov772x_priv *priv,
-struct v4l2_fract *tpf,
-const struct ov772x_color_format *cfmt,
-const struct ov772x_win_size *win)
+static unsigned int ov772x_select_fps(struct ov772x_priv *priv,
+ struct v4l2_fract *tpf)
 {
-   struct i2c_client *client = v4l2_get_subdevdata(>subdev);
-   unsigned long fin = clk_get_rate(priv->clk);
unsigned int fps = tpf->numerator ?
   tpf->denominator / tpf->numerator :
   tpf->denominator;
unsigned int best_diff;
-   unsigned int fsize;
-   unsigned int pclk;
unsigned int diff;
unsigned int idx;
unsigned int i;
-   u8 clkrc = 0;
-   u8 com4 = 0;
-   int ret;
 
/* Approximate to the closest supported frame interval. */
best_diff = ~0L;
@@ -646,7 +637,25 @@ static int ov772x_set_frame_rate(struct ov772x_priv *priv,
best_diff = diff;
}
}
-   fps = ov772x_frame_intervals[idx];
+
+   return ov772x_frame_intervals[idx];
+}
+
+static int ov772x_set_frame_rate(struct ov772x_priv *priv,
+unsigned int fps,
+const struct ov772x_color_format *cfmt,
+const struct ov772x_win_size *win)
+{
+   struct i2c_client *client = v4l2_get_subdevdata(>subdev);
+   unsigned long fin = clk_get_rate(priv->clk);
+   unsigned int best_diff;
+   unsigned int fsize;
+   unsigned int pclk;
+   unsigned int diff;
+   unsigned int i;
+   u8 clkrc = 0;
+   u8 com4 = 0;
+   int ret;
 
/* Use image size (with blankings) to calculate desired pixel clock. */
switch (cfmt->com7 & OFMT_MASK) {
@@ -711,10 +720,6 @@ static int ov772x_set_frame_rate(struct ov772x_priv *priv,
if (ret < 0)
return ret;
 
-   tpf->numerator = 1;
-   tpf->denominator = fps;
-   priv->fps = tpf->denominator;
-
return 0;
 }
 
@@ -735,8 +740,20 @@ static int ov772x_s_frame_interval(struct v4l2_subdev *sd,
 {
struct ov772x_priv *priv = to_ov772x(sd);
struct v4l2_fract *tpf = >interval;
+   unsigned int fps;
+   int ret;
+
+   fps = ov772x_select_fps(priv, tpf);
+
+   ret = ov772x_set_frame_rate(priv, fps, priv->cfmt, priv->win);
+   if (ret)
+   return ret;
 
-   return ov772x_set_frame_rate(priv, tpf, priv->cfmt, priv->win);
+   tpf->numerator = 1;
+   tpf->denominator = fps;
+   priv->fps = fps;
+
+   return 0;
 }
 
 static int ov772x_s_ctrl(struct v4l2_ctrl *ctrl)
@@ -993,7 +1010,6 @@ static int ov772x_set_params(struct ov772x_priv *priv,
 const struct ov772x_win_size *win)
 {
struct i2c_client *client = v4l2_get_subdevdata(>subdev);
-   struct v4l2_fract tpf;
int ret;
u8  val;
 
@@ -1075,9 +1091,7 @@ static int ov772x_set_params(struct ov772x_priv *priv,
goto ov772x_set_fmt_error;
 
/* COM4, CLKRC: Set pixel clock and framerate. */
-   tpf.numerator = 1;
-   tpf.denominator = priv->fps;
-   ret = ov772x_set_frame_rate(priv, , cfmt, win);
+   ret = ov772x_set_frame_rate(priv, priv->fps, cfmt, win);
if (ret < 0)
goto ov772x_set_fmt_error;
 
-- 
2.7.4



[PATCH v5 08/14] media: ov772x: support device tree probing

2018-05-06 Thread Akinobu Mita
The ov772x driver currently only supports legacy platform data probe.
This change enables device tree probing.

Note that the platform data probe can select auto or manual edge control
mode, but the device tree probling can only select auto edge control mode
for now.

Cc: Jacopo Mondi 
Cc: Laurent Pinchart 
Cc: Hans Verkuil 
Cc: Sakari Ailus 
Cc: Mauro Carvalho Chehab 
Reviewed-by: Jacopo Mondi 
Signed-off-by: Akinobu Mita 
---
* v5
- Remove unnecessary space

 drivers/media/i2c/ov772x.c | 64 --
 1 file changed, 45 insertions(+), 19 deletions(-)

diff --git a/drivers/media/i2c/ov772x.c b/drivers/media/i2c/ov772x.c
index f939e28..2b02411 100644
--- a/drivers/media/i2c/ov772x.c
+++ b/drivers/media/i2c/ov772x.c
@@ -749,13 +749,13 @@ static int ov772x_s_ctrl(struct v4l2_ctrl *ctrl)
case V4L2_CID_VFLIP:
val = ctrl->val ? VFLIP_IMG : 0x00;
priv->flag_vflip = ctrl->val;
-   if (priv->info->flags & OV772X_FLAG_VFLIP)
+   if (priv->info && (priv->info->flags & OV772X_FLAG_VFLIP))
val ^= VFLIP_IMG;
return ov772x_mask_set(client, COM3, VFLIP_IMG, val);
case V4L2_CID_HFLIP:
val = ctrl->val ? HFLIP_IMG : 0x00;
priv->flag_hflip = ctrl->val;
-   if (priv->info->flags & OV772X_FLAG_HFLIP)
+   if (priv->info && (priv->info->flags & OV772X_FLAG_HFLIP))
val ^= HFLIP_IMG;
return ov772x_mask_set(client, COM3, HFLIP_IMG, val);
case V4L2_CID_BAND_STOP_FILTER:
@@ -914,19 +914,14 @@ static void ov772x_select_params(const struct 
v4l2_mbus_framefmt *mf,
*win = ov772x_select_win(mf->width, mf->height);
 }
 
-static int ov772x_set_params(struct ov772x_priv *priv,
-const struct ov772x_color_format *cfmt,
-const struct ov772x_win_size *win)
+static int ov772x_edgectrl(struct ov772x_priv *priv)
 {
struct i2c_client *client = v4l2_get_subdevdata(>subdev);
-   struct v4l2_fract tpf;
int ret;
-   u8  val;
 
-   /* Reset hardware. */
-   ov772x_reset(client);
+   if (!priv->info)
+   return 0;
 
-   /* Edge Ctrl. */
if (priv->info->edgectrl.strength & OV772X_MANUAL_EDGE_CTRL) {
/*
 * Manual Edge Control Mode.
@@ -937,19 +932,19 @@ static int ov772x_set_params(struct ov772x_priv *priv,
 
ret = ov772x_mask_set(client, DSPAUTO, EDGE_ACTRL, 0x00);
if (ret < 0)
-   goto ov772x_set_fmt_error;
+   return ret;
 
ret = ov772x_mask_set(client,
  EDGE_TRSHLD, OV772X_EDGE_THRESHOLD_MASK,
  priv->info->edgectrl.threshold);
if (ret < 0)
-   goto ov772x_set_fmt_error;
+   return ret;
 
ret = ov772x_mask_set(client,
  EDGE_STRNGT, OV772X_EDGE_STRENGTH_MASK,
  priv->info->edgectrl.strength);
if (ret < 0)
-   goto ov772x_set_fmt_error;
+   return ret;
 
} else if (priv->info->edgectrl.upper > priv->info->edgectrl.lower) {
/*
@@ -961,15 +956,35 @@ static int ov772x_set_params(struct ov772x_priv *priv,
  EDGE_UPPER, OV772X_EDGE_UPPER_MASK,
  priv->info->edgectrl.upper);
if (ret < 0)
-   goto ov772x_set_fmt_error;
+   return ret;
 
ret = ov772x_mask_set(client,
  EDGE_LOWER, OV772X_EDGE_LOWER_MASK,
  priv->info->edgectrl.lower);
if (ret < 0)
-   goto ov772x_set_fmt_error;
+   return ret;
}
 
+   return 0;
+}
+
+static int ov772x_set_params(struct ov772x_priv *priv,
+const struct ov772x_color_format *cfmt,
+const struct ov772x_win_size *win)
+{
+   struct i2c_client *client = v4l2_get_subdevdata(>subdev);
+   struct v4l2_fract tpf;
+   int ret;
+   u8  val;
+
+   /* Reset hardware. */
+   ov772x_reset(client);
+
+   /* Edge Ctrl. */
+   ret = ov772x_edgectrl(priv);
+   if (ret < 0)
+   return ret;
+
/* Format and window size. */
ret = ov772x_write(client, HSTART, win->rect.left >> 2);
if (ret < 0)
@@ -1020,9 +1035,9 @@ static int ov772x_set_params(struct ov772x_priv *priv,
 
/* Set 

[PATCH v5 11/14] media: ov772x: use v4l2_ctrl to get current control value

2018-05-06 Thread Akinobu Mita
The ov772x driver provides three V4L2 controls and the current value of
each control is saved as a variable in the private data structure.

We don't need to keep track of the current value by ourself, if we use
v4l2_ctrl returned from v4l2_ctrl_new_std() instead.

This is a preparatory change to avoid accessing registers under power
saving mode.  This simplifies s_ctrl() by making it just return without
saving the current control value in private area when it is called under
power saving mode.

Cc: Jacopo Mondi 
Cc: Laurent Pinchart 
Cc: Hans Verkuil 
Cc: Sakari Ailus 
Cc: Mauro Carvalho Chehab 
Signed-off-by: Akinobu Mita 
---
* v5
- No changes

 drivers/media/i2c/ov772x.c | 34 +-
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/drivers/media/i2c/ov772x.c b/drivers/media/i2c/ov772x.c
index 92ad13f..9292a18 100644
--- a/drivers/media/i2c/ov772x.c
+++ b/drivers/media/i2c/ov772x.c
@@ -419,10 +419,10 @@ struct ov772x_priv {
struct gpio_desc *rstb_gpio;
const struct ov772x_color_format *cfmt;
const struct ov772x_win_size *win;
-   unsigned shortflag_vflip:1;
-   unsigned shortflag_hflip:1;
+   struct v4l2_ctrl *vflip_ctrl;
+   struct v4l2_ctrl *hflip_ctrl;
/* band_filter = COM8[5] ? 256 - BDBASE : 0 */
-   unsigned shortband_filter;
+   struct v4l2_ctrl *band_filter_ctrl;
unsigned int  fps;
/* lock to protect power_count */
struct mutex  lock;
@@ -768,13 +768,11 @@ static int ov772x_s_ctrl(struct v4l2_ctrl *ctrl)
switch (ctrl->id) {
case V4L2_CID_VFLIP:
val = ctrl->val ? VFLIP_IMG : 0x00;
-   priv->flag_vflip = ctrl->val;
if (priv->info && (priv->info->flags & OV772X_FLAG_VFLIP))
val ^= VFLIP_IMG;
return ov772x_mask_set(client, COM3, VFLIP_IMG, val);
case V4L2_CID_HFLIP:
val = ctrl->val ? HFLIP_IMG : 0x00;
-   priv->flag_hflip = ctrl->val;
if (priv->info && (priv->info->flags & OV772X_FLAG_HFLIP))
val ^= HFLIP_IMG;
return ov772x_mask_set(client, COM3, HFLIP_IMG, val);
@@ -794,8 +792,7 @@ static int ov772x_s_ctrl(struct v4l2_ctrl *ctrl)
ret = ov772x_mask_set(client, BDBASE,
  0xff, val);
}
-   if (!ret)
-   priv->band_filter = ctrl->val;
+
return ret;
}
 
@@ -1075,9 +1072,9 @@ static int ov772x_set_params(struct ov772x_priv *priv,
val |= VFLIP_IMG;
if (priv->info && (priv->info->flags & OV772X_FLAG_HFLIP))
val |= HFLIP_IMG;
-   if (priv->flag_vflip)
+   if (priv->vflip_ctrl->val)
val ^= VFLIP_IMG;
-   if (priv->flag_hflip)
+   if (priv->hflip_ctrl->val)
val ^= HFLIP_IMG;
 
ret = ov772x_mask_set(client,
@@ -1096,11 +1093,13 @@ static int ov772x_set_params(struct ov772x_priv *priv,
goto ov772x_set_fmt_error;
 
/* Set COM8. */
-   if (priv->band_filter) {
+   if (priv->band_filter_ctrl->val) {
+   unsigned short band_filter = priv->band_filter_ctrl->val;
+
ret = ov772x_mask_set(client, COM8, BNDF_ON_OFF, BNDF_ON_OFF);
if (!ret)
ret = ov772x_mask_set(client, BDBASE,
- 0xff, 256 - priv->band_filter);
+ 0xff, 256 - band_filter);
if (ret < 0)
goto ov772x_set_fmt_error;
}
@@ -1341,12 +1340,13 @@ static int ov772x_probe(struct i2c_client *client,
 
v4l2_i2c_subdev_init(>subdev, client, _subdev_ops);
v4l2_ctrl_handler_init(>hdl, 3);
-   v4l2_ctrl_new_std(>hdl, _ctrl_ops,
- V4L2_CID_VFLIP, 0, 1, 1, 0);
-   v4l2_ctrl_new_std(>hdl, _ctrl_ops,
- V4L2_CID_HFLIP, 0, 1, 1, 0);
-   v4l2_ctrl_new_std(>hdl, _ctrl_ops,
- V4L2_CID_BAND_STOP_FILTER, 0, 256, 1, 0);
+   priv->vflip_ctrl = v4l2_ctrl_new_std(>hdl, _ctrl_ops,
+V4L2_CID_VFLIP, 0, 1, 1, 0);
+   priv->hflip_ctrl = v4l2_ctrl_new_std(>hdl, _ctrl_ops,
+V4L2_CID_HFLIP, 0, 1, 1, 0);
+   priv->band_filter_ctrl = v4l2_ctrl_new_std(>hdl, _ctrl_ops,
+  V4L2_CID_BAND_STOP_FILTER,
+ 

[PATCH v5 09/14] media: ov772x: handle nested s_power() calls

2018-05-06 Thread Akinobu Mita
Depending on the v4l2 driver, calling s_power() could be nested.  So the
actual transitions between power saving mode and normal operation mode
should only happen at the first power on and the last power off.

This adds an s_power() nesting counter and updates the power state if the
counter is modified from 0 to != 0 or from != 0 to 0.

Cc: Jacopo Mondi 
Cc: Laurent Pinchart 
Cc: Hans Verkuil 
Cc: Sakari Ailus 
Cc: Mauro Carvalho Chehab 
Reviewed-by: Jacopo Mondi 
Signed-off-by: Akinobu Mita 
---
* v5
- No changes

 drivers/media/i2c/ov772x.c | 34 ++
 1 file changed, 30 insertions(+), 4 deletions(-)

diff --git a/drivers/media/i2c/ov772x.c b/drivers/media/i2c/ov772x.c
index 2b02411..6c0c792 100644
--- a/drivers/media/i2c/ov772x.c
+++ b/drivers/media/i2c/ov772x.c
@@ -424,6 +424,9 @@ struct ov772x_priv {
/* band_filter = COM8[5] ? 256 - BDBASE : 0 */
unsigned shortband_filter;
unsigned int  fps;
+   /* lock to protect power_count */
+   struct mutex  lock;
+   int   power_count;
 #ifdef CONFIG_MEDIA_CONTROLLER
struct media_pad pad;
 #endif
@@ -871,9 +874,26 @@ static int ov772x_power_off(struct ov772x_priv *priv)
 static int ov772x_s_power(struct v4l2_subdev *sd, int on)
 {
struct ov772x_priv *priv = to_ov772x(sd);
+   int ret = 0;
+
+   mutex_lock(>lock);
+
+   /* If the power count is modified from 0 to != 0 or from != 0 to 0,
+* update the power state.
+*/
+   if (priv->power_count == !on)
+   ret = on ? ov772x_power_on(priv) : ov772x_power_off(priv);
+
+   if (!ret) {
+   /* Update the power count. */
+   priv->power_count += on ? 1 : -1;
+   WARN(priv->power_count < 0, "Unbalanced power count\n");
+   WARN(priv->power_count > 1, "Duplicated s_power call\n");
+   }
+
+   mutex_unlock(>lock);
 
-   return on ? ov772x_power_on(priv) :
-   ov772x_power_off(priv);
+   return ret;
 }
 
 static const struct ov772x_win_size *ov772x_select_win(u32 width, u32 height)
@@ -1303,6 +1323,7 @@ static int ov772x_probe(struct i2c_client *client,
return -ENOMEM;
 
priv->info = client->dev.platform_data;
+   mutex_init(>lock);
 
v4l2_i2c_subdev_init(>subdev, client, _subdev_ops);
v4l2_ctrl_handler_init(>hdl, 3);
@@ -1313,8 +1334,10 @@ static int ov772x_probe(struct i2c_client *client,
v4l2_ctrl_new_std(>hdl, _ctrl_ops,
  V4L2_CID_BAND_STOP_FILTER, 0, 256, 1, 0);
priv->subdev.ctrl_handler = >hdl;
-   if (priv->hdl.error)
-   return priv->hdl.error;
+   if (priv->hdl.error) {
+   ret = priv->hdl.error;
+   goto error_mutex_destroy;
+   }
 
priv->clk = clk_get(>dev, NULL);
if (IS_ERR(priv->clk)) {
@@ -1362,6 +1385,8 @@ static int ov772x_probe(struct i2c_client *client,
clk_put(priv->clk);
 error_ctrl_free:
v4l2_ctrl_handler_free(>hdl);
+error_mutex_destroy:
+   mutex_destroy(>lock);
 
return ret;
 }
@@ -1376,6 +1401,7 @@ static int ov772x_remove(struct i2c_client *client)
gpiod_put(priv->pwdn_gpio);
v4l2_async_unregister_subdev(>subdev);
v4l2_ctrl_handler_free(>hdl);
+   mutex_destroy(>lock);
 
return 0;
 }
-- 
2.7.4



[PATCH v2 2/2] dvbsky: Add support for MyGica T230C v2

2018-05-06 Thread Thomas Hollstegge
Support for newer revisions of the MyGica T230C, shipping with a
different USB pid. Although sometimes referred to as T230C2, the device
is sold under its original name T230C.

Besides a slightly different PCB layout and some different minor
components, it utilizes the same bridge, demodulator and tuner as the
older revision. However, it requires a fixed TS clock frequency of 10
MHz to tune to some muxes.

Tested with various DVB-T2 HEVC and DVB-C channels.

Signed-off-by: Thomas Hollstegge 
Cc: Stefan BrĂ¼ns 
---
 drivers/media/usb/dvb-usb-v2/dvbsky.c | 90 +++
 include/media/dvb-usb-ids.h   |  1 +
 2 files changed, 91 insertions(+)

diff --git a/drivers/media/usb/dvb-usb-v2/dvbsky.c 
b/drivers/media/usb/dvb-usb-v2/dvbsky.c
index e28bd88..4a4c6ae 100644
--- a/drivers/media/usb/dvb-usb-v2/dvbsky.c
+++ b/drivers/media/usb/dvb-usb-v2/dvbsky.c
@@ -583,6 +583,66 @@ static int dvbsky_mygica_t230c_attach(struct 
dvb_usb_adapter *adap)
return 0;
 }
 
+static int dvbsky_mygica_t230c_v2_attach(struct dvb_usb_adapter *adap)
+{
+   struct dvbsky_state *state = adap_to_priv(adap);
+   struct dvb_usb_device *d = adap_to_d(adap);
+   struct i2c_adapter *i2c_adapter;
+   struct i2c_client *client_demod, *client_tuner;
+   struct i2c_board_info info;
+   struct si2168_config si2168_config;
+   struct si2157_config si2157_config;
+
+   /* attach demod */
+   memset(_config, 0, sizeof(si2168_config));
+   si2168_config.i2c_adapter = _adapter;
+   si2168_config.fe = >fe[0];
+   si2168_config.ts_mode = SI2168_TS_PARALLEL;
+   si2168_config.ts_clock_inv = 1;
+   si2168_config.ts_clock_mode = SI2168_TS_CLOCK_MODE_MANUAL;
+   si2168_config.ts_clock_freq = 1000;
+   memset(, 0, sizeof(struct i2c_board_info));
+   strlcpy(info.type, "si2168", sizeof(info.type));
+   info.addr = 0x64;
+   info.platform_data = _config;
+
+   request_module("si2168");
+   client_demod = i2c_new_device(>i2c_adap, );
+   if (!client_demod || !client_demod->dev.driver)
+   goto fail_demod_device;
+   if (!try_module_get(client_demod->dev.driver->owner))
+   goto fail_demod_module;
+
+   /* attach tuner */
+   memset(_config, 0, sizeof(si2157_config));
+   si2157_config.fe = adap->fe[0];
+   si2157_config.if_port = 0;
+   memset(, 0, sizeof(struct i2c_board_info));
+   strlcpy(info.type, "si2141", sizeof(info.type));
+   info.addr = 0x60;
+   info.platform_data = _config;
+
+   request_module("si2157");
+   client_tuner = i2c_new_device(i2c_adapter, );
+   if (!client_tuner || !client_tuner->dev.driver)
+   goto fail_tuner_device;
+   if (!try_module_get(client_tuner->dev.driver->owner))
+   goto fail_tuner_module;
+
+   state->i2c_client_demod = client_demod;
+   state->i2c_client_tuner = client_tuner;
+   return 0;
+
+fail_tuner_module:
+   i2c_unregister_device(client_tuner);
+fail_tuner_device:
+   module_put(client_demod->dev.driver->owner);
+fail_demod_module:
+   i2c_unregister_device(client_demod);
+fail_demod_device:
+   return -ENODEV;
+}
+
 
 static int dvbsky_identify_state(struct dvb_usb_device *d, const char **name)
 {
@@ -762,6 +822,33 @@ static struct dvb_usb_device_properties mygica_t230c_props 
= {
}
 };
 
+static struct dvb_usb_device_properties mygica_t230c_v2_props = {
+   .driver_name = KBUILD_MODNAME,
+   .owner = THIS_MODULE,
+   .adapter_nr = adapter_nr,
+   .size_of_priv = sizeof(struct dvbsky_state),
+
+   .generic_bulk_ctrl_endpoint = 0x01,
+   .generic_bulk_ctrl_endpoint_response = 0x81,
+   .generic_bulk_ctrl_delay = DVBSKY_MSG_DELAY,
+
+   .i2c_algo = _i2c_algo,
+   .frontend_attach  = dvbsky_mygica_t230c_v2_attach,
+   .init = dvbsky_init,
+   .get_rc_config= dvbsky_get_rc_config,
+   .streaming_ctrl   = dvbsky_streaming_ctrl,
+   .identify_state   = dvbsky_identify_state,
+   .exit = dvbsky_exit,
+
+   .num_adapters = 1,
+   .adapter = {
+   {
+   .stream = DVB_USB_STREAM_BULK(0x82, 8, 4096),
+   }
+   }
+};
+
+
 static const struct usb_device_id dvbsky_id_table[] = {
{ DVB_USB_DEVICE(0x0572, 0x6831,
_s960_props, "DVBSky S960/S860", RC_MAP_DVBSKY) },
@@ -797,6 +884,9 @@ static const struct usb_device_id dvbsky_id_table[] = {
{ DVB_USB_DEVICE(USB_VID_CONEXANT, USB_PID_MYGICA_T230C,
_t230c_props, "MyGica Mini DVB-T2 USB Stick T230C",
RC_MAP_TOTAL_MEDIA_IN_HAND_02) },
+   { DVB_USB_DEVICE(USB_VID_CONEXANT, USB_PID_MYGICA_T230C_V2,
+   _t230c_v2_props, "MyGica Mini DVB-T2 USB Stick T230C v2",
+   RC_MAP_TOTAL_MEDIA_IN_HAND_02) },
{ }
 };
 

[PATCH v2 0/2] media: dvbsky: Add support for MyGica T230C v2

2018-05-06 Thread Thomas Hollstegge
Add support for newer revisions of the USB DVB-C/DVB-T/DVB-T2 stick MyGica
T230C, sometimes referred to as MyGica T230C2. The device needs a fixed TS
clock frequency of 10MHz to be able to demod some channels. This is done by
adding two new optional configuration options for the Si2168 demod
(ts_clock_mode and ts_clock_freq).

Although there is a third TS clock mode available (AUTO_FIXED = 0x00), I chose
not to implement it yet as I don't have a device that uses this mode.

Tested with all available DVB-T2 HEVC and DVB-C muxes in my region (Germany).

Patch v2 notes: rebased against https://git.linuxtv.org/media_tree.git/

Thomas Hollstegge (2):
  si2168: Set TS clock mode and frequency
  dvbsky: Add support for MyGica T230C v2

 drivers/media/dvb-frontends/si2168.c  | 20 ++-
 drivers/media/dvb-frontends/si2168.h  |  8 +++
 drivers/media/dvb-frontends/si2168_priv.h |  2 +
 drivers/media/usb/dvb-usb-v2/dvbsky.c | 90 +++
 include/media/dvb-usb-ids.h   |  1 +
 5 files changed, 120 insertions(+), 1 deletion(-)

-- 
2.7.4



[PATCH v2 1/2] si2168: Set TS clock mode and frequency

2018-05-06 Thread Thomas Hollstegge
Some devices require a higher TS clock frequency to demodulate some
muxes. This adds two optional parameters to control the TS clock
frequency mode as well as the frequency.

Signed-off-by: Thomas Hollstegge 
---
 drivers/media/dvb-frontends/si2168.c  | 20 +++-
 drivers/media/dvb-frontends/si2168.h  |  8 
 drivers/media/dvb-frontends/si2168_priv.h |  2 ++
 3 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/drivers/media/dvb-frontends/si2168.c 
b/drivers/media/dvb-frontends/si2168.c
index 324493e..80740db 100644
--- a/drivers/media/dvb-frontends/si2168.c
+++ b/drivers/media/dvb-frontends/si2168.c
@@ -92,13 +92,15 @@ static int si2168_ts_bus_ctrl(struct dvb_frontend *fe, int 
acquire)
dev_dbg(>dev, "%s acquire: %d\n", __func__, acquire);
 
/* set TS_MODE property */
-   memcpy(cmd.args, "\x14\x00\x01\x10\x10\x00", 6);
+   memcpy(cmd.args, "\x14\x00\x01\x10\x00\x00", 6);
if (acquire)
cmd.args[4] |= dev->ts_mode;
else
cmd.args[4] |= SI2168_TS_TRISTATE;
if (dev->ts_clock_gapped)
cmd.args[4] |= 0x40;
+   cmd.args[4] |= (dev->ts_clock_mode & 0x03) << 4;
+
cmd.wlen = 6;
cmd.rlen = 4;
ret = si2168_cmd_execute(client, );
@@ -398,6 +400,18 @@ static int si2168_set_frontend(struct dvb_frontend *fe)
if (ret)
goto err;
 
+   /* set TS frequency */
+   if (dev->ts_clock_freq) {
+   memcpy(cmd.args, "\x14\x00\x0d\x10", 4);
+   cmd.args[4] = ((dev->ts_clock_freq / 1) >> 0) & 0xff;
+   cmd.args[5] = ((dev->ts_clock_freq / 1) >> 8) & 0xff;
+   cmd.wlen = 6;
+   cmd.rlen = 4;
+   ret = si2168_cmd_execute(client, );
+   if (ret)
+   goto err;
+   }
+
memcpy(cmd.args, "\x14\x00\x08\x10\xd7\x05", 6);
cmd.args[5] |= dev->ts_clock_inv ? 0x00 : 0x10;
cmd.wlen = 6;
@@ -806,6 +820,10 @@ static int si2168_probe(struct i2c_client *client,
dev->ts_mode = config->ts_mode;
dev->ts_clock_inv = config->ts_clock_inv;
dev->ts_clock_gapped = config->ts_clock_gapped;
+   dev->ts_clock_mode = config->ts_clock_mode;
+   if (!dev->ts_clock_mode)
+   dev->ts_clock_mode = SI2168_TS_CLOCK_MODE_AUTO_ADAPT;
+   dev->ts_clock_freq = config->ts_clock_freq;
dev->spectral_inversion = config->spectral_inversion;
 
dev_info(>dev, "Silicon Labs Si2168-%c%d%d successfully 
identified\n",
diff --git a/drivers/media/dvb-frontends/si2168.h 
b/drivers/media/dvb-frontends/si2168.h
index d519edd..3f52ee8 100644
--- a/drivers/media/dvb-frontends/si2168.h
+++ b/drivers/media/dvb-frontends/si2168.h
@@ -47,6 +47,14 @@ struct si2168_config {
/* TS clock gapped */
bool ts_clock_gapped;
 
+   /* TS clock mode */
+#define SI2168_TS_CLOCK_MODE_AUTO_ADAPT0x01
+#define SI2168_TS_CLOCK_MODE_MANUAL0x02
+   u8 ts_clock_mode;
+
+   /* TS clock frequency (for manual mode) */
+   u32 ts_clock_freq;
+
/* Inverted spectrum */
bool spectral_inversion;
 };
diff --git a/drivers/media/dvb-frontends/si2168_priv.h 
b/drivers/media/dvb-frontends/si2168_priv.h
index 2d362e1..8173d6c 100644
--- a/drivers/media/dvb-frontends/si2168_priv.h
+++ b/drivers/media/dvb-frontends/si2168_priv.h
@@ -48,6 +48,8 @@ struct si2168_dev {
u8 ts_mode;
bool ts_clock_inv;
bool ts_clock_gapped;
+   u8 ts_clock_mode;
+   u32 ts_clock_freq;
bool spectral_inversion;
 };
 
-- 
2.7.4



[PATCH v5 13/14] media: ov772x: make set_fmt() and s_frame_interval() return -EBUSY while streaming

2018-05-06 Thread Akinobu Mita
The ov772x driver is going to offer a V4L2 sub-device interface, so
changing the output data format and the frame interval on this sub-device
can be made anytime.  However, these requests are preferred to fail while
the video stream on the device is active.

Cc: Jacopo Mondi 
Cc: Laurent Pinchart 
Cc: Hans Verkuil 
Cc: Sakari Ailus 
Cc: Mauro Carvalho Chehab 
Signed-off-by: Akinobu Mita 
---
* v5:
- Make s_frame_interval() return -EBUSY while streaming

 drivers/media/i2c/ov772x.c | 43 +--
 1 file changed, 33 insertions(+), 10 deletions(-)

diff --git a/drivers/media/i2c/ov772x.c b/drivers/media/i2c/ov772x.c
index 262a7e5..4b479f9 100644
--- a/drivers/media/i2c/ov772x.c
+++ b/drivers/media/i2c/ov772x.c
@@ -424,9 +424,10 @@ struct ov772x_priv {
/* band_filter = COM8[5] ? 256 - BDBASE : 0 */
struct v4l2_ctrl *band_filter_ctrl;
unsigned int  fps;
-   /* lock to protect power_count */
+   /* lock to protect power_count and streaming */
struct mutex  lock;
int   power_count;
+   int   streaming;
 #ifdef CONFIG_MEDIA_CONTROLLER
struct media_pad pad;
 #endif
@@ -603,18 +604,28 @@ static int ov772x_s_stream(struct v4l2_subdev *sd, int 
enable)
 {
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct ov772x_priv *priv = to_ov772x(sd);
+   int ret = 0;
 
-   if (!enable) {
-   ov772x_mask_set(client, COM2, SOFT_SLEEP_MODE, SOFT_SLEEP_MODE);
-   return 0;
-   }
+   mutex_lock(>lock);
 
-   ov772x_mask_set(client, COM2, SOFT_SLEEP_MODE, 0);
+   if (priv->streaming == enable)
+   goto done;
 
-   dev_dbg(>dev, "format %d, win %s\n",
-   priv->cfmt->code, priv->win->name);
+   ret = ov772x_mask_set(client, COM2, SOFT_SLEEP_MODE,
+ enable ? 0 : SOFT_SLEEP_MODE);
+   if (ret)
+   goto done;
 
-   return 0;
+   if (enable) {
+   dev_dbg(>dev, "format %d, win %s\n",
+   priv->cfmt->code, priv->win->name);
+   }
+   priv->streaming = enable;
+
+done:
+   mutex_unlock(>lock);
+
+   return ret;
 }
 
 static unsigned int ov772x_select_fps(struct ov772x_priv *priv,
@@ -743,9 +754,15 @@ static int ov772x_s_frame_interval(struct v4l2_subdev *sd,
unsigned int fps;
int ret = 0;
 
+   mutex_lock(>lock);
+
+   if (priv->streaming) {
+   ret = -EBUSY;
+   goto error;
+   }
+
fps = ov772x_select_fps(priv, tpf);
 
-   mutex_lock(>lock);
/*
 * If the device is not powered up by the host driver do
 * not apply any changes to H/W at this time. Instead
@@ -1222,6 +1239,12 @@ static int ov772x_set_fmt(struct v4l2_subdev *sd,
}
 
mutex_lock(>lock);
+
+   if (priv->streaming) {
+   ret = -EBUSY;
+   goto error;
+   }
+
/*
 * If the device is not powered up by the host driver do
 * not apply any changes to H/W at this time. Instead
-- 
2.7.4



[PATCH v5 12/14] media: ov772x: avoid accessing registers under power saving mode

2018-05-06 Thread Akinobu Mita
The set_fmt() in subdev pad ops, the s_ctrl() for subdev control handler,
and the s_frame_interval() in subdev video ops could be called when the
device is under power saving mode.  These callbacks for ov772x driver
cause updating H/W registers that will fail under power saving mode.

This avoids it by not apply any changes to H/W if the device is not powered
up.  Instead the changes will be restored right after power-up.

Cc: Jacopo Mondi 
Cc: Laurent Pinchart 
Cc: Hans Verkuil 
Cc: Sakari Ailus 
Cc: Mauro Carvalho Chehab 
Signed-off-by: Akinobu Mita 
---
* v5
- No changes

 drivers/media/i2c/ov772x.c | 79 +-
 1 file changed, 64 insertions(+), 15 deletions(-)

diff --git a/drivers/media/i2c/ov772x.c b/drivers/media/i2c/ov772x.c
index 9292a18..262a7e5 100644
--- a/drivers/media/i2c/ov772x.c
+++ b/drivers/media/i2c/ov772x.c
@@ -741,19 +741,30 @@ static int ov772x_s_frame_interval(struct v4l2_subdev *sd,
struct ov772x_priv *priv = to_ov772x(sd);
struct v4l2_fract *tpf = >interval;
unsigned int fps;
-   int ret;
+   int ret = 0;
 
fps = ov772x_select_fps(priv, tpf);
 
-   ret = ov772x_set_frame_rate(priv, fps, priv->cfmt, priv->win);
-   if (ret)
-   return ret;
+   mutex_lock(>lock);
+   /*
+* If the device is not powered up by the host driver do
+* not apply any changes to H/W at this time. Instead
+* the frame rate will be restored right after power-up.
+*/
+   if (priv->power_count > 0) {
+   ret = ov772x_set_frame_rate(priv, fps, priv->cfmt, priv->win);
+   if (ret)
+   goto error;
+   }
 
tpf->numerator = 1;
tpf->denominator = fps;
priv->fps = fps;
 
-   return 0;
+error:
+   mutex_unlock(>lock);
+
+   return ret;
 }
 
 static int ov772x_s_ctrl(struct v4l2_ctrl *ctrl)
@@ -765,6 +776,16 @@ static int ov772x_s_ctrl(struct v4l2_ctrl *ctrl)
int ret = 0;
u8 val;
 
+   /* v4l2_ctrl_lock() locks our own mutex */
+
+   /*
+* If the device is not powered up by the host driver do
+* not apply any controls to H/W at this time. Instead
+* the controls will be restored right after power-up.
+*/
+   if (priv->power_count == 0)
+   return 0;
+
switch (ctrl->id) {
case V4L2_CID_VFLIP:
val = ctrl->val ? VFLIP_IMG : 0x00;
@@ -885,6 +906,10 @@ static int ov772x_power_off(struct ov772x_priv *priv)
return 0;
 }
 
+static int ov772x_set_params(struct ov772x_priv *priv,
+const struct ov772x_color_format *cfmt,
+const struct ov772x_win_size *win);
+
 static int ov772x_s_power(struct v4l2_subdev *sd, int on)
 {
struct ov772x_priv *priv = to_ov772x(sd);
@@ -895,8 +920,20 @@ static int ov772x_s_power(struct v4l2_subdev *sd, int on)
/* If the power count is modified from 0 to != 0 or from != 0 to 0,
 * update the power state.
 */
-   if (priv->power_count == !on)
-   ret = on ? ov772x_power_on(priv) : ov772x_power_off(priv);
+   if (priv->power_count == !on) {
+   if (on) {
+   ret = ov772x_power_on(priv);
+   /*
+* Restore the format, the frame rate, and
+* the controls
+*/
+   if (!ret)
+   ret = ov772x_set_params(priv, priv->cfmt,
+   priv->win);
+   } else {
+   ret = ov772x_power_off(priv);
+   }
+   }
 
if (!ret) {
/* Update the power count. */
@@ -1163,7 +1200,7 @@ static int ov772x_set_fmt(struct v4l2_subdev *sd,
struct v4l2_mbus_framefmt *mf = >format;
const struct ov772x_color_format *cfmt;
const struct ov772x_win_size *win;
-   int ret;
+   int ret = 0;
 
if (format->pad)
return -EINVAL;
@@ -1184,14 +1221,24 @@ static int ov772x_set_fmt(struct v4l2_subdev *sd,
return 0;
}
 
-   ret = ov772x_set_params(priv, cfmt, win);
-   if (ret < 0)
-   return ret;
-
+   mutex_lock(>lock);
+   /*
+* If the device is not powered up by the host driver do
+* not apply any changes to H/W at this time. Instead
+* the format will be restored right after power-up.
+*/
+   if (priv->power_count > 0) {
+   ret = ov772x_set_params(priv, cfmt, win);
+   if (ret < 0)
+   goto error;
+   }
priv->win = win;
priv->cfmt = cfmt;
 
-   return 0;

[PATCH v5 14/14] media: ov772x: create subdevice device node

2018-05-06 Thread Akinobu Mita
Set the V4L2_SUBDEV_FL_HAS_DEVNODE flag for the subdevice so that the
subdevice device node is created.

Cc: Jacopo Mondi 
Cc: Laurent Pinchart 
Cc: Hans Verkuil 
Cc: Sakari Ailus 
Cc: Mauro Carvalho Chehab 
Signed-off-by: Akinobu Mita 
---
* v5
- No changes

 drivers/media/i2c/ov772x.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/media/i2c/ov772x.c b/drivers/media/i2c/ov772x.c
index 4b479f9..f7f4fe6 100644
--- a/drivers/media/i2c/ov772x.c
+++ b/drivers/media/i2c/ov772x.c
@@ -1409,6 +1409,7 @@ static int ov772x_probe(struct i2c_client *client,
mutex_init(>lock);
 
v4l2_i2c_subdev_init(>subdev, client, _subdev_ops);
+   priv->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
v4l2_ctrl_handler_init(>hdl, 3);
/* Use our mutex for the controls */
priv->hdl.lock = >lock;
-- 
2.7.4



[PATCH v5 03/14] media: ov772x: allow i2c controllers without I2C_FUNC_PROTOCOL_MANGLING

2018-05-06 Thread Akinobu Mita
The ov772x driver only works when the i2c controller have
I2C_FUNC_PROTOCOL_MANGLING.  However, many i2c controller drivers don't
support it.

The reason that the ov772x requires I2C_FUNC_PROTOCOL_MANGLING is that
it doesn't support repeated starts.

This changes the reading ov772x register method so that it doesn't
require I2C_FUNC_PROTOCOL_MANGLING by calling two separated i2c messages.

Cc: Jacopo Mondi 
Cc: Laurent Pinchart 
Cc: Hans Verkuil 
Cc: Sakari Ailus 
Cc: Mauro Carvalho Chehab 
Cc: Wolfram Sang 
Reviewed-by: Jacopo Mondi 
Signed-off-by: Akinobu Mita 
---
* v5
- Add Reviewed-by: line

 drivers/media/i2c/ov772x.c | 20 ++--
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/drivers/media/i2c/ov772x.c b/drivers/media/i2c/ov772x.c
index e255070..b6223bf 100644
--- a/drivers/media/i2c/ov772x.c
+++ b/drivers/media/i2c/ov772x.c
@@ -542,9 +542,19 @@ static struct ov772x_priv *to_ov772x(struct v4l2_subdev 
*sd)
return container_of(sd, struct ov772x_priv, subdev);
 }
 
-static inline int ov772x_read(struct i2c_client *client, u8 addr)
+static int ov772x_read(struct i2c_client *client, u8 addr)
 {
-   return i2c_smbus_read_byte_data(client, addr);
+   int ret;
+   u8 val;
+
+   ret = i2c_master_send(client, , 1);
+   if (ret < 0)
+   return ret;
+   ret = i2c_master_recv(client, , 1);
+   if (ret < 0)
+   return ret;
+
+   return val;
 }
 
 static inline int ov772x_write(struct i2c_client *client, u8 addr, u8 value)
@@ -1255,13 +1265,11 @@ static int ov772x_probe(struct i2c_client *client,
return -EINVAL;
}
 
-   if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
- I2C_FUNC_PROTOCOL_MANGLING)) {
+   if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
dev_err(>dev,
-   "I2C-Adapter doesn't support SMBUS_BYTE_DATA or 
PROTOCOL_MANGLING\n");
+   "I2C-Adapter doesn't support SMBUS_BYTE_DATA\n");
return -EIO;
}
-   client->flags |= I2C_CLIENT_SCCB;
 
priv = devm_kzalloc(>dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
-- 
2.7.4



[PATCH v5 01/14] media: dt-bindings: ov772x: add device tree binding

2018-05-06 Thread Akinobu Mita
This adds a device tree binding documentation for OV7720/OV7725 sensor.

Cc: Jacopo Mondi 
Cc: Laurent Pinchart 
Cc: Hans Verkuil 
Cc: Sakari Ailus 
Cc: Mauro Carvalho Chehab 
Cc: Rob Herring 
Reviewed-by: Rob Herring 
Reviewed-by: Jacopo Mondi 
Reviewed-by: Laurent Pinchart 
Signed-off-by: Akinobu Mita 
---
* v5
- No changes

 .../devicetree/bindings/media/i2c/ov772x.txt   | 40 ++
 MAINTAINERS|  1 +
 2 files changed, 41 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/ov772x.txt

diff --git a/Documentation/devicetree/bindings/media/i2c/ov772x.txt 
b/Documentation/devicetree/bindings/media/i2c/ov772x.txt
new file mode 100644
index 000..0b3ede5
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/i2c/ov772x.txt
@@ -0,0 +1,40 @@
+* Omnivision OV7720/OV7725 CMOS sensor
+
+The Omnivision OV7720/OV7725 sensor supports multiple resolutions output,
+such as VGA, QVGA, and any size scaling down from CIF to 40x30. It also can
+support the YUV422, RGB565/555/444, GRB422 or raw RGB output formats.
+
+Required Properties:
+- compatible: shall be one of
+   "ovti,ov7720"
+   "ovti,ov7725"
+- clocks: reference to the xclk input clock.
+
+Optional Properties:
+- reset-gpios: reference to the GPIO connected to the RSTB pin which is
+  active low, if any.
+- powerdown-gpios: reference to the GPIO connected to the PWDN pin which is
+  active high, if any.
+
+The device node shall contain one 'port' child node with one child 'endpoint'
+subnode for its digital output video port, in accordance with the video
+interface bindings defined in Documentation/devicetree/bindings/media/
+video-interfaces.txt.
+
+Example:
+
+ {
+   ov772x: camera@21 {
+   compatible = "ovti,ov7725";
+   reg = <0x21>;
+   reset-gpios = <_gpio_0 0 GPIO_ACTIVE_LOW>;
+   powerdown-gpios = <_gpio_0 1 GPIO_ACTIVE_LOW>;
+   clocks = <>;
+
+   port {
+   ov772x_0: endpoint {
+   remote-endpoint = <_in0>;
+   };
+   };
+   };
+};
diff --git a/MAINTAINERS b/MAINTAINERS
index df6e9bb..cd4c270 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -10356,6 +10356,7 @@ T:  git git://linuxtv.org/media_tree.git
 S: Odd fixes
 F: drivers/media/i2c/ov772x.c
 F: include/media/i2c/ov772x.h
+F: Documentation/devicetree/bindings/media/i2c/ov772x.txt
 
 OMNIVISION OV7740 SENSOR DRIVER
 M: Wenyou Yang 
-- 
2.7.4



[PATCH v5 04/14] media: ov772x: add checks for register read errors

2018-05-06 Thread Akinobu Mita
This change adds checks for register read errors and returns correct
error code.

Cc: Jacopo Mondi 
Cc: Laurent Pinchart 
Cc: Hans Verkuil 
Cc: Sakari Ailus 
Cc: Mauro Carvalho Chehab 
Reviewed-by: Jacopo Mondi 
Signed-off-by: Akinobu Mita 
---
* v5
- No changes

 drivers/media/i2c/ov772x.c | 20 ++--
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/drivers/media/i2c/ov772x.c b/drivers/media/i2c/ov772x.c
index b6223bf..3fdbe64 100644
--- a/drivers/media/i2c/ov772x.c
+++ b/drivers/media/i2c/ov772x.c
@@ -1146,7 +1146,7 @@ static int ov772x_set_fmt(struct v4l2_subdev *sd,
 static int ov772x_video_probe(struct ov772x_priv *priv)
 {
struct i2c_client  *client = v4l2_get_subdevdata(>subdev);
-   u8  pid, ver;
+   int pid, ver, midh, midl;
const char *devname;
int ret;
 
@@ -1156,7 +1156,11 @@ static int ov772x_video_probe(struct ov772x_priv *priv)
 
/* Check and show product ID and manufacturer ID. */
pid = ov772x_read(client, PID);
+   if (pid < 0)
+   return pid;
ver = ov772x_read(client, VER);
+   if (ver < 0)
+   return ver;
 
switch (VERSION(pid, ver)) {
case OV7720:
@@ -1172,13 +1176,17 @@ static int ov772x_video_probe(struct ov772x_priv *priv)
goto done;
}
 
+   midh = ov772x_read(client, MIDH);
+   if (midh < 0)
+   return midh;
+   midl = ov772x_read(client, MIDL);
+   if (midl < 0)
+   return midl;
+
dev_info(>dev,
 "%s Product ID %0x:%0x Manufacturer ID %x:%x\n",
-devname,
-pid,
-ver,
-ov772x_read(client, MIDH),
-ov772x_read(client, MIDL));
+devname, pid, ver, midh, midl);
+
ret = v4l2_ctrl_handler_setup(>hdl);
 
 done:
-- 
2.7.4



[PATCH v5 00/14] media: ov772x: support media controller, device tree probing, etc.

2018-05-06 Thread Akinobu Mita
This patchset includes support media controller, sub-device interface,
device tree probing and other miscellanuous changes for ov772x driver.

* v5 (thanks to Jacopo Mondi)
- Add Acked-by: line
- Add Reviewed-by: line
- Remove unnecessary space
- Align arguments to open parenthesis
- Sort variable declarations
- Make s_frame_interval() return -EBUSY while streaming

* v4 (thanks to Laurent Pinchart)
- Add Reviewed-by: lines
- Correct setting of banding filter (New)
- Omit consumer ID when getting clock reference (New)
- Use v4l2_ctrl to get current control value (New)
- Correctly restore the controls changed under power saving mode

* v3 (thanks to Sakari Ailus and Jacopo Mondi)
- Reorder the patches
- Add Reviewed-by: lines
- Remove I2C_CLIENT_SCCB flag set as it isn't needed anymore
- Fix typo in the commit log
- Return without resetting if ov772x_edgectrl() failed
- Update the error message for missing platform data
- Rename mutex name from power_lock to lock
- Add warning for duplicated s_power call
- Add newlines before labels
- Remove __v4l2_ctrl_handler_setup in s_power() as it causes duplicated
  register settings
- Make set_fmt() return -EBUSY while streaming (New)

* v2 (thanks to Jacopo Mondi)
- Replace the implementation of ov772x_read() instead of adding an
  alternative method
- Assign the ov772x_read() return value to pid and ver directly
- Do the same for MIDH and MIDL
- Move video_probe() before the entity initialization and remove the #ifdef
  around the media_entity_cleanup()
- Use generic names for reset and powerdown gpios (New)
- Add "dt-bindings:" in the subject
- Add a brief description of the sensor
- Update the GPIO names
- Indicate the GPIO active level
- Add missing NULL checks for priv->info
- Leave the check for the missing platform data if legacy platform data
  probe is used.
- Handle nested s_power() calls (New)
- Reconstruct s_frame_interval() (New)
- Avoid accessing registers

Akinobu Mita (14):
  media: dt-bindings: ov772x: add device tree binding
  media: ov772x: correct setting of banding filter
  media: ov772x: allow i2c controllers without
I2C_FUNC_PROTOCOL_MANGLING
  media: ov772x: add checks for register read errors
  media: ov772x: add media controller support
  media: ov772x: use generic names for reset and powerdown gpios
  media: ov772x: omit consumer ID when getting clock reference
  media: ov772x: support device tree probing
  media: ov772x: handle nested s_power() calls
  media: ov772x: reconstruct s_frame_interval()
  media: ov772x: use v4l2_ctrl to get current control value
  media: ov772x: avoid accessing registers under power saving mode
  media: ov772x: make set_fmt() and s_frame_interval() return -EBUSY
while streaming
  media: ov772x: create subdevice device node

 .../devicetree/bindings/media/i2c/ov772x.txt   |  40 +++
 MAINTAINERS|   1 +
 arch/sh/boards/mach-migor/setup.c  |   7 +-
 drivers/media/i2c/ov772x.c | 357 +++--
 4 files changed, 308 insertions(+), 97 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/media/i2c/ov772x.txt

Cc: Jacopo Mondi 
Cc: Laurent Pinchart 
Cc: Hans Verkuil 
Cc: Sakari Ailus 
Cc: Mauro Carvalho Chehab 
Cc: Rob Herring 
Cc: Wolfram Sang 
-- 
2.7.4



[PATCH v5 02/14] media: ov772x: correct setting of banding filter

2018-05-06 Thread Akinobu Mita
The banding filter ON/OFF is controlled via bit 5 of COM8 register.  It
is attempted to be enabled in ov772x_set_params() by the following line.

ret = ov772x_mask_set(client, COM8, BNDF_ON_OFF, 1);

But this unexpectedly results disabling the banding filter, because the
mask and set bits are exclusive.

On the other hand, ov772x_s_ctrl() correctly sets the bit by:

ret = ov772x_mask_set(client, COM8, BNDF_ON_OFF, BNDF_ON_OFF);

Cc: Jacopo Mondi 
Cc: Laurent Pinchart 
Cc: Hans Verkuil 
Cc: Sakari Ailus 
Cc: Mauro Carvalho Chehab 
Acked-by: Jacopo Mondi 
Signed-off-by: Akinobu Mita 
---
* v5
- Add Acked-by: line

 drivers/media/i2c/ov772x.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/i2c/ov772x.c b/drivers/media/i2c/ov772x.c
index b62860c..e255070 100644
--- a/drivers/media/i2c/ov772x.c
+++ b/drivers/media/i2c/ov772x.c
@@ -1035,7 +1035,7 @@ static int ov772x_set_params(struct ov772x_priv *priv,
 
/* Set COM8. */
if (priv->band_filter) {
-   ret = ov772x_mask_set(client, COM8, BNDF_ON_OFF, 1);
+   ret = ov772x_mask_set(client, COM8, BNDF_ON_OFF, BNDF_ON_OFF);
if (!ret)
ret = ov772x_mask_set(client, BDBASE,
  0xff, 256 - priv->band_filter);
-- 
2.7.4



[PATCH v5 06/14] media: ov772x: use generic names for reset and powerdown gpios

2018-05-06 Thread Akinobu Mita
The ov772x driver uses "rstb-gpios" and "pwdn-gpios" for reset and
powerdown pins.  However, using generic names for these gpios is
preferred.  ("reset-gpios" and "powerdown-gpios" respectively)

There is only one mainline user for these gpios, so rename to generic
names.

Cc: Jacopo Mondi 
Cc: Laurent Pinchart 
Cc: Hans Verkuil 
Cc: Sakari Ailus 
Cc: Mauro Carvalho Chehab 
Reviewed-by: Jacopo Mondi 
Signed-off-by: Akinobu Mita 
---
* v5
- No changes

 arch/sh/boards/mach-migor/setup.c | 5 +++--
 drivers/media/i2c/ov772x.c| 8 
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/arch/sh/boards/mach-migor/setup.c 
b/arch/sh/boards/mach-migor/setup.c
index 271dfc2..73b9ee4 100644
--- a/arch/sh/boards/mach-migor/setup.c
+++ b/arch/sh/boards/mach-migor/setup.c
@@ -351,8 +351,9 @@ static struct platform_device migor_ceu_device = {
 static struct gpiod_lookup_table ov7725_gpios = {
.dev_id = "0-0021",
.table  = {
-   GPIO_LOOKUP("sh7722_pfc", GPIO_PTT0, "pwdn", GPIO_ACTIVE_HIGH),
-   GPIO_LOOKUP("sh7722_pfc", GPIO_PTT3, "rstb", GPIO_ACTIVE_LOW),
+   GPIO_LOOKUP("sh7722_pfc", GPIO_PTT0, "powerdown",
+   GPIO_ACTIVE_HIGH),
+   GPIO_LOOKUP("sh7722_pfc", GPIO_PTT3, "reset", GPIO_ACTIVE_LOW),
},
 };
 
diff --git a/drivers/media/i2c/ov772x.c b/drivers/media/i2c/ov772x.c
index bb5327f..97a65ce 100644
--- a/drivers/media/i2c/ov772x.c
+++ b/drivers/media/i2c/ov772x.c
@@ -837,10 +837,10 @@ static int ov772x_power_on(struct ov772x_priv *priv)
 * available to handle this cleanly, request the GPIO temporarily
 * to avoid conflicts.
 */
-   priv->rstb_gpio = gpiod_get_optional(>dev, "rstb",
+   priv->rstb_gpio = gpiod_get_optional(>dev, "reset",
 GPIOD_OUT_LOW);
if (IS_ERR(priv->rstb_gpio)) {
-   dev_info(>dev, "Unable to get GPIO \"rstb\"");
+   dev_info(>dev, "Unable to get GPIO \"reset\"");
return PTR_ERR(priv->rstb_gpio);
}
 
@@ -1307,10 +1307,10 @@ static int ov772x_probe(struct i2c_client *client,
goto error_ctrl_free;
}
 
-   priv->pwdn_gpio = gpiod_get_optional(>dev, "pwdn",
+   priv->pwdn_gpio = gpiod_get_optional(>dev, "powerdown",
 GPIOD_OUT_LOW);
if (IS_ERR(priv->pwdn_gpio)) {
-   dev_info(>dev, "Unable to get GPIO \"pwdn\"");
+   dev_info(>dev, "Unable to get GPIO \"powerdown\"");
ret = PTR_ERR(priv->pwdn_gpio);
goto error_clk_put;
}
-- 
2.7.4



[PATCH v5 07/14] media: ov772x: omit consumer ID when getting clock reference

2018-05-06 Thread Akinobu Mita
Currently the ov772x driver obtains a clock with a specific consumer ID.
As there's a single clock for this driver, we could omit clock-names
property in device tree by passing NULL as a consumer ID to clk_get().

Cc: Jacopo Mondi 
Cc: Laurent Pinchart 
Cc: Hans Verkuil 
Cc: Sakari Ailus 
Cc: Mauro Carvalho Chehab 
Suggested-by: Laurent Pinchart 
Tested-by: Jacopo Mondi 
Signed-off-by: Akinobu Mita 
---
* v5
- No changes

 arch/sh/boards/mach-migor/setup.c | 2 +-
 drivers/media/i2c/ov772x.c| 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/sh/boards/mach-migor/setup.c 
b/arch/sh/boards/mach-migor/setup.c
index 73b9ee4..11f8001 100644
--- a/arch/sh/boards/mach-migor/setup.c
+++ b/arch/sh/boards/mach-migor/setup.c
@@ -593,7 +593,7 @@ static int __init migor_devices_setup(void)
}
 
/* Add a clock alias for ov7725 xclk source. */
-   clk_add_alias("xclk", "0-0021", "video_clk", NULL);
+   clk_add_alias(NULL, "0-0021", "video_clk", NULL);
 
/* Register GPIOs for video sources. */
gpiod_add_lookup_table(_gpios);
diff --git a/drivers/media/i2c/ov772x.c b/drivers/media/i2c/ov772x.c
index 97a65ce..f939e28 100644
--- a/drivers/media/i2c/ov772x.c
+++ b/drivers/media/i2c/ov772x.c
@@ -1300,7 +1300,7 @@ static int ov772x_probe(struct i2c_client *client,
if (priv->hdl.error)
return priv->hdl.error;
 
-   priv->clk = clk_get(>dev, "xclk");
+   priv->clk = clk_get(>dev, NULL);
if (IS_ERR(priv->clk)) {
dev_err(>dev, "Unable to get xclk clock\n");
ret = PTR_ERR(priv->clk);
-- 
2.7.4



[PATCH v5 05/14] media: ov772x: add media controller support

2018-05-06 Thread Akinobu Mita
Create a source pad and set the media controller type to the sensor.

Cc: Jacopo Mondi 
Cc: Laurent Pinchart 
Cc: Hans Verkuil 
Cc: Sakari Ailus 
Cc: Mauro Carvalho Chehab 
Reviewed-by: Jacopo Mondi 
Signed-off-by: Akinobu Mita 
---
* v5
- No changes

 drivers/media/i2c/ov772x.c | 16 +++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/drivers/media/i2c/ov772x.c b/drivers/media/i2c/ov772x.c
index 3fdbe64..bb5327f 100644
--- a/drivers/media/i2c/ov772x.c
+++ b/drivers/media/i2c/ov772x.c
@@ -424,6 +424,9 @@ struct ov772x_priv {
/* band_filter = COM8[5] ? 256 - BDBASE : 0 */
unsigned shortband_filter;
unsigned int  fps;
+#ifdef CONFIG_MEDIA_CONTROLLER
+   struct media_pad pad;
+#endif
 };
 
 /*
@@ -1316,16 +1319,26 @@ static int ov772x_probe(struct i2c_client *client,
if (ret < 0)
goto error_gpio_put;
 
+#ifdef CONFIG_MEDIA_CONTROLLER
+   priv->pad.flags = MEDIA_PAD_FL_SOURCE;
+   priv->subdev.entity.function = MEDIA_ENT_F_CAM_SENSOR;
+   ret = media_entity_pads_init(>subdev.entity, 1, >pad);
+   if (ret < 0)
+   goto error_gpio_put;
+#endif
+
priv->cfmt = _cfmts[0];
priv->win = _win_sizes[0];
priv->fps = 15;
 
ret = v4l2_async_register_subdev(>subdev);
if (ret)
-   goto error_gpio_put;
+   goto error_entity_cleanup;
 
return 0;
 
+error_entity_cleanup:
+   media_entity_cleanup(>subdev.entity);
 error_gpio_put:
if (priv->pwdn_gpio)
gpiod_put(priv->pwdn_gpio);
@@ -1341,6 +1354,7 @@ static int ov772x_remove(struct i2c_client *client)
 {
struct ov772x_priv *priv = to_ov772x(i2c_get_clientdata(client));
 
+   media_entity_cleanup(>subdev.entity);
clk_put(priv->clk);
if (priv->pwdn_gpio)
gpiod_put(priv->pwdn_gpio);
-- 
2.7.4



help

2018-05-06 Thread Richard Lee




cron job: media_tree daily build: ERRORS

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

Results of the daily build of media_tree:

date:   Mon May  7 05:00:14 CEST 2018
media-tree git hash:f10379aad39e9da8bc7d1822e251b5f0673067ef
media_build git hash:   5dff1aa3ce3ee56119038707b21af24b8a2dc7fa
v4l-utils git hash: 03e763fd4b361b2082019032fc315b7606669335
gcc version:i686-linux-gcc (GCC) 7.3.0
sparse version: 0.5.2-RC1
smatch version: 0.5.1
host hardware:  x86_64
host os:4.15.0-3-amd64

linux-git-arm-at91: OK
linux-git-arm-davinci: OK
linux-git-arm-multi: OK
linux-git-arm-pxa: OK
linux-git-arm-stm32: OK
linux-git-arm64: OK
linux-git-i686: OK
linux-git-mips: WARNINGS
linux-git-powerpc64: OK
linux-git-sh: OK
linux-git-x86_64: OK
Check COMPILE_TEST: OK
linux-2.6.36.4-i686: ERRORS
linux-2.6.36.4-x86_64: ERRORS
linux-2.6.37.6-i686: ERRORS
linux-2.6.37.6-x86_64: ERRORS
linux-2.6.38.8-i686: ERRORS
linux-2.6.38.8-x86_64: ERRORS
linux-2.6.39.4-i686: ERRORS
linux-2.6.39.4-x86_64: ERRORS
linux-3.0.101-i686: ERRORS
linux-3.0.101-x86_64: ERRORS
linux-3.1.10-i686: ERRORS
linux-3.1.10-x86_64: ERRORS
linux-3.2.101-i686: ERRORS
linux-3.2.101-x86_64: ERRORS
linux-3.3.8-i686: ERRORS
linux-3.3.8-x86_64: ERRORS
linux-3.4.113-i686: ERRORS
linux-3.4.113-x86_64: ERRORS
linux-3.5.7-i686: ERRORS
linux-3.5.7-x86_64: ERRORS
linux-3.6.11-i686: ERRORS
linux-3.6.11-x86_64: ERRORS
linux-3.7.10-i686: ERRORS
linux-3.7.10-x86_64: ERRORS
linux-3.8.13-i686: ERRORS
linux-3.8.13-x86_64: ERRORS
linux-3.9.11-i686: ERRORS
linux-3.9.11-x86_64: ERRORS
linux-3.10.108-i686: ERRORS
linux-3.10.108-x86_64: ERRORS
linux-3.11.10-i686: ERRORS
linux-3.11.10-x86_64: ERRORS
linux-3.12.74-i686: ERRORS
linux-3.12.74-x86_64: ERRORS
linux-3.13.11-i686: ERRORS
linux-3.13.11-x86_64: ERRORS
linux-3.14.79-i686: ERRORS
linux-3.14.79-x86_64: ERRORS
linux-3.15.10-i686: ERRORS
linux-3.15.10-x86_64: ERRORS
linux-3.16.56-i686: ERRORS
linux-3.16.56-x86_64: ERRORS
linux-3.17.8-i686: OK
linux-3.17.8-x86_64: OK
linux-3.18.102-i686: OK
linux-3.18.102-x86_64: OK
linux-3.19.8-i686: OK
linux-3.19.8-x86_64: OK
linux-4.0.9-i686: OK
linux-4.0.9-x86_64: OK
linux-4.1.51-i686: OK
linux-4.1.51-x86_64: OK
linux-4.2.8-i686: OK
linux-4.2.8-x86_64: OK
linux-4.3.6-i686: OK
linux-4.3.6-x86_64: OK
linux-4.4.109-i686: OK
linux-4.4.109-x86_64: OK
linux-4.5.7-i686: OK
linux-4.5.7-x86_64: OK
linux-4.6.7-i686: OK
linux-4.6.7-x86_64: OK
linux-4.7.10-i686: OK
linux-4.7.10-x86_64: OK
linux-4.8.17-i686: OK
linux-4.8.17-x86_64: OK
linux-4.9.91-i686: OK
linux-4.9.91-x86_64: OK
linux-4.10.17-i686: OK
linux-4.10.17-x86_64: OK
linux-4.11.12-i686: OK
linux-4.11.12-x86_64: OK
linux-4.12.14-i686: OK
linux-4.12.14-x86_64: OK
linux-4.13.16-i686: OK
linux-4.13.16-x86_64: OK
linux-4.14.31-i686: OK
linux-4.14.31-x86_64: OK
linux-4.15.14-i686: OK
linux-4.15.14-x86_64: OK
linux-4.16-i686: OK
linux-4.16-x86_64: OK
apps: OK
spec-git: OK
sparse: WARNINGS

Detailed results are available here:

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

Full logs are available here:

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

The Media Infrastructure API from this daily build is here:

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


[PATCH] [media] media: delete unneeded include

2018-05-06 Thread Julia Lawall
pvrusb2-video-v4l.h only declares pvr2_saa7115_subdev_update and
includes pvrusb2-hdw-internal.h.  pvrusb2-cx2584x-v4l.c does not
use pvr2_saa7115_subdev_update and it explicitly includes
pvrusb2-hdw-internal.h.

Signed-off-by: Julia Lawall 

---
 drivers/media/usb/pvrusb2/pvrusb2-cx2584x-v4l.c |1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/media/usb/pvrusb2/pvrusb2-cx2584x-v4l.c 
b/drivers/media/usb/pvrusb2/pvrusb2-cx2584x-v4l.c
index 242b213..d5bec0f 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-cx2584x-v4l.c
+++ b/drivers/media/usb/pvrusb2/pvrusb2-cx2584x-v4l.c
@@ -23,7 +23,6 @@
 */
 
 #include "pvrusb2-cx2584x-v4l.h"
-#include "pvrusb2-video-v4l.h"
 
 
 #include "pvrusb2-hdw-internal.h"



Re: [PATCH 1/2] media: siano: don't use GFP_DMA

2018-05-06 Thread Mauro Carvalho Chehab
Em Sun, 6 May 2018 08:05:05 +0900
Tomoki Sekiyama  escreveu:

> 2018/5/6 1:09 Mauro Carvalho Chehab :
> 
> > I can't think on a single reason why this driver would be using
> > GFP_DMA. The typical usage is as an USB driver. Any DMA restrictions
> > should be handled inside the HCI driver, if any.
> >  
> 
> siano driver supports SDIO (implemented
> in drivers/media/mmc/siano/smssdio.c) as well as USB.
> It looks like using sdio_memcpy_toio() to DMA transfer. I think that's why
> it is using GFP_DMA.

Good point. I always forget about the mmc variant, as I don't
have any hardware to test.

The best seems to add a new parameter to sms core register
function, allowing it to use extra gfp flags, and pass it only
for the SDIO variant.

Patch enclosed.

Regards,
Mauro

[PATCH 1/2 v2] media: siano: use GFP_DMA only for smssdio

Right now, the Siano's core uses GFP_DMA for both USB and
SDIO variants of the driver. There's no reason to use it
for USB. So, pass GFP_DMA as a parameter during sms core
register.

Signed-off-by: Mauro Carvalho Chehab 

diff --git a/drivers/media/common/siano/smscoreapi.c 
b/drivers/media/common/siano/smscoreapi.c
index b5dcc6d1fe90..9ed7afa7b2ae 100644
--- a/drivers/media/common/siano/smscoreapi.c
+++ b/drivers/media/common/siano/smscoreapi.c
@@ -649,6 +649,7 @@ smscore_buffer_t *smscore_createbuffer(u8 *buffer, void 
*common_buffer,
  */
 int smscore_register_device(struct smsdevice_params_t *params,
struct smscore_device_t **coredev,
+   gfp_t gfp_buf_flags,
void *mdev)
 {
struct smscore_device_t *dev;
@@ -661,6 +662,7 @@ int smscore_register_device(struct smsdevice_params_t 
*params,
 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
dev->media_dev = mdev;
 #endif
+   dev->gfp_buf_flags = gfp_buf_flags;
 
/* init list entry so it could be safe in smscore_unregister_device */
INIT_LIST_HEAD(>entry);
@@ -697,7 +699,7 @@ int smscore_register_device(struct smsdevice_params_t 
*params,
buffer = dma_alloc_coherent(params->device,
dev->common_buffer_size,
>common_buffer_phys,
-   GFP_KERNEL | GFP_DMA);
+   GFP_KERNEL | dev->gfp_buf_flags);
if (!buffer) {
smscore_unregister_device(dev);
return -ENOMEM;
@@ -792,7 +794,7 @@ static int smscore_init_ir(struct smscore_device_t *coredev)
else {
buffer = kmalloc(sizeof(struct sms_msg_data2) +
SMS_DMA_ALIGNMENT,
-   GFP_KERNEL | GFP_DMA);
+   GFP_KERNEL | 
coredev->gfp_buf_flags);
if (buffer) {
struct sms_msg_data2 *msg =
(struct sms_msg_data2 *)
@@ -933,7 +935,7 @@ static int smscore_load_firmware_family2(struct 
smscore_device_t *coredev,
}
 
/* PAGE_SIZE buffer shall be enough and dma aligned */
-   msg = kmalloc(PAGE_SIZE, GFP_KERNEL | GFP_DMA);
+   msg = kmalloc(PAGE_SIZE, GFP_KERNEL | coredev->gfp_buf_flags);
if (!msg)
return -ENOMEM;
 
@@ -1168,7 +1170,7 @@ static int smscore_load_firmware_from_file(struct 
smscore_device_t *coredev,
}
pr_debug("read fw %s, buffer size=0x%zx\n", fw_filename, fw->size);
fw_buf = kmalloc(ALIGN(fw->size + sizeof(struct sms_firmware),
-SMS_ALLOC_ALIGNMENT), GFP_KERNEL | GFP_DMA);
+SMS_ALLOC_ALIGNMENT), GFP_KERNEL | 
coredev->gfp_buf_flags);
if (!fw_buf) {
pr_err("failed to allocate firmware buffer\n");
rc = -ENOMEM;
@@ -1260,7 +1262,7 @@ EXPORT_SYMBOL_GPL(smscore_unregister_device);
 static int smscore_detect_mode(struct smscore_device_t *coredev)
 {
void *buffer = kmalloc(sizeof(struct sms_msg_hdr) + SMS_DMA_ALIGNMENT,
-  GFP_KERNEL | GFP_DMA);
+  GFP_KERNEL | coredev->gfp_buf_flags);
struct sms_msg_hdr *msg =
(struct sms_msg_hdr *) SMS_ALIGN_ADDRESS(buffer);
int rc;
@@ -1309,7 +1311,7 @@ static int smscore_init_device(struct smscore_device_t 
*coredev, int mode)
int rc = 0;
 
buffer = kmalloc(sizeof(struct sms_msg_data) +
-   SMS_DMA_ALIGNMENT, GFP_KERNEL | GFP_DMA);
+   SMS_DMA_ALIGNMENT, GFP_KERNEL | coredev->gfp_buf_flags);
if (!buffer)
return -ENOMEM;
 
@@ -1398,7 +1400,7 @@ int smscore_set_device_mode(struct smscore_device_t 
*coredev, int mode)
coredev->device_flags &= ~SMS_DEVICE_NOT_READY;
 
  

[PATCH] media: i2c: lm3560: add support for lm3559 chip

2018-05-06 Thread Pavel Machek

Add support for LM3559, as found in Motorola Droid 4 phone, for
example. SW interface seems to be identical.

Signed-off-by: Pavel Machek 

diff --git a/drivers/media/i2c/lm3560.c b/drivers/media/i2c/lm3560.c
index b600e03a..c4e5ed5 100644
--- a/drivers/media/i2c/lm3560.c
+++ b/drivers/media/i2c/lm3560.c
@@ -1,6 +1,6 @@
 /*
  * drivers/media/i2c/lm3560.c
- * General device driver for TI lm3560, FLASH LED Driver
+ * General device driver for TI lm3559, lm3560, FLASH LED Driver
  *
  * Copyright (C) 2013 Texas Instruments
  *
@@ -465,6 +479,7 @@ static int lm3560_remove(struct i2c_client *client)
 }
 
 static const struct i2c_device_id lm3560_id_table[] = {
+   {LM3559_NAME, 0},
{LM3560_NAME, 0},
{}
 };
diff --git a/include/media/i2c/lm3560.h b/include/media/i2c/lm3560.h
index a5bd310..0e2b1c7 100644
--- a/include/media/i2c/lm3560.h
+++ b/include/media/i2c/lm3560.h
@@ -22,6 +22,7 @@
 
 #include 
 
+#define LM3559_NAME"lm3559"
 #define LM3560_NAME"lm3560"
 #define LM3560_I2C_ADDR(0x53)
 

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) 
http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html


signature.asc
Description: Digital signature


[PATCH] media: i2c: lm3560: use conservative defaults

2018-05-06 Thread Pavel Machek

If no pdata is found, we should use lowest current settings, not highest.

Signed-off-by: Pavel Machek 

diff --git a/drivers/media/i2c/lm3560.c b/drivers/media/i2c/lm3560.c
index b600e03a..c4e5ed5 100644
--- a/drivers/media/i2c/lm3560.c
+++ b/drivers/media/i2c/lm3560.c
@@ -420,14 +434,14 @@ static int lm3560_probe(struct i2c_client *client,
pdata = devm_kzalloc(>dev, sizeof(*pdata), GFP_KERNEL);
if (pdata == NULL)
return -ENODEV;
-   pdata->peak = LM3560_PEAK_3600mA;
-   pdata->max_flash_timeout = LM3560_FLASH_TOUT_MAX;
+   pdata->peak = LM3560_PEAK_1600mA;
+   pdata->max_flash_timeout = LM3560_FLASH_TOUT_MIN;
/* led 1 */
-   pdata->max_flash_brt[LM3560_LED0] = LM3560_FLASH_BRT_MAX;
-   pdata->max_torch_brt[LM3560_LED0] = LM3560_TORCH_BRT_MAX;
+   pdata->max_flash_brt[LM3560_LED0] = LM3560_FLASH_BRT_MIN;
+   pdata->max_torch_brt[LM3560_LED0] = LM3560_TORCH_BRT_MIN;
/* led 2 */
-   pdata->max_flash_brt[LM3560_LED1] = LM3560_FLASH_BRT_MAX;
-   pdata->max_torch_brt[LM3560_LED1] = LM3560_TORCH_BRT_MAX;
+   pdata->max_flash_brt[LM3560_LED1] = LM3560_FLASH_BRT_MIN;
+   pdata->max_torch_brt[LM3560_LED1] = LM3560_TORCH_BRT_MIN;
}
flash->pdata = pdata;
flash->dev = >dev;

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) 
http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html


signature.asc
Description: Digital signature


[PATCH v2] [media] pvrusb2: delete unneeded include

2018-05-06 Thread Julia Lawall
pvrusb2-video-v4l.h only declares pvr2_saa7115_subdev_update and
includes pvrusb2-hdw-internal.h.  pvrusb2-cx2584x-v4l.c does not
use pvr2_saa7115_subdev_update and it explicitly includes
pvrusb2-hdw-internal.h.

Signed-off-by: Julia Lawall 

---

v2: Make the subject line a bit less generic

 drivers/media/usb/pvrusb2/pvrusb2-cx2584x-v4l.c |1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/media/usb/pvrusb2/pvrusb2-cx2584x-v4l.c 
b/drivers/media/usb/pvrusb2/pvrusb2-cx2584x-v4l.c
index 242b213..d5bec0f 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-cx2584x-v4l.c
+++ b/drivers/media/usb/pvrusb2/pvrusb2-cx2584x-v4l.c
@@ -23,7 +23,6 @@
 */

 #include "pvrusb2-cx2584x-v4l.h"
-#include "pvrusb2-video-v4l.h"


 #include "pvrusb2-hdw-internal.h"

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


[PATCH] media: Use ktime_set() in pt1.c

2018-05-06 Thread Jasmin J.
From: Jasmin Jessich 

In commit 20a63349b142 a new variable ktime_t delay has been added.
We decided to use the API functions to initialize ktime_t variables
within media-tree. Thus variable delay needs to be initialized with
ktime_set() instead of setting it directly.

Signed-off-by: Jasmin Jessich 
---
 drivers/media/pci/pt1/pt1.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/pci/pt1/pt1.c b/drivers/media/pci/pt1/pt1.c
index 55a89ea..5708f69 100644
--- a/drivers/media/pci/pt1/pt1.c
+++ b/drivers/media/pci/pt1/pt1.c
@@ -485,7 +485,7 @@ static int pt1_thread(void *data)
if (!pt1_filter(pt1, page)) {
ktime_t delay;
 
-   delay = PT1_FETCH_DELAY * NSEC_PER_MSEC;
+   delay = ktime_set(0, PT1_FETCH_DELAY * NSEC_PER_MSEC);
set_current_state(TASK_INTERRUPTIBLE);
schedule_hrtimeout_range(,
PT1_FETCH_DELAY_DELTA * NSEC_PER_MSEC,
-- 
2.7.4



Re: [PATCH v3 0/8] R-Car DU: Support CRC calculation

2018-05-06 Thread Laurent Pinchart
Hi Mauro,

On Saturday, 5 May 2018 18:05:13 EEST Mauro Carvalho Chehab wrote:
> Em Sat, 05 May 2018 17:06:50 +0300 Laurent Pinchart escreveu:
> > On Thursday, 3 May 2018 16:45:36 EEST Daniel Vetter wrote:
> >> On Thu, May 3, 2018 at 2:06 PM, Laurent Pinchart wrote:
> >>> Hi Dave,
> >>> 
> >>> Ping ?
> >> 
> >> Not aware of any crc core work going on in drm, so has my ack.
> > 
> > Thank you.
> > 
> >> Worst case we do a topic branch or something like that (since I guess
> >> you'll do a pull request anyway on the v4l side).
> > 
> > That would unfortunately not be possible, as Mauro cherry-picks patches
> > instead of merging pull requests. In rare cases I can ask for a
> > pull-request to be merged as-is, but it's too late in this case as the
> > previous pull request that this series is based on has been
> > cherry-picked, not merged.
> 
> I probably missed something, but I fail to see what's the problem.
> 
> If DRM needs a patch that was already merged on our tree, I can gladly
> create a stable branch/tag for it - well, media master branch is stable,
> but I can add a tag there just after the patch DRM needs, in order
> to avoid them to merge from us at some random point.
> 
> If otherwise we need a patch applied at DRM, they can do the same:
> create a branch/tag, and I can pull from it.

Well, my assumption is that Dave would rather not pull the whole linux-media 
tree in the DRM tree. That's easily prevented when handling pull requests 
through a merge instead of a cherry-pick operation, in that case I can just 
base a patch series on top of -rc1 and send a pull request to both of you. The 
linux-media and DRM tree will merge cleanly in Linus' tree as they will both 
contain the same branch.

-- 
Regards,

Laurent Pinchart





Re: [PATCH 1/2] media: siano: don't use GFP_DMA

2018-05-06 Thread Tomoki Sekiyama
2018-05-06 18:21 GMT+09:00 Mauro Carvalho Chehab :
> Em Sun, 6 May 2018 08:05:05 +0900
> Tomoki Sekiyama  escreveu:
>
>> 2018/5/6 1:09 Mauro Carvalho Chehab :
>>
>> > I can't think on a single reason why this driver would be using
>> > GFP_DMA. The typical usage is as an USB driver. Any DMA restrictions
>> > should be handled inside the HCI driver, if any.
>> >
>>
>> siano driver supports SDIO (implemented
>> in drivers/media/mmc/siano/smssdio.c) as well as USB.
>> It looks like using sdio_memcpy_toio() to DMA transfer. I think that's why
>> it is using GFP_DMA.
>
> Good point. I always forget about the mmc variant, as I don't
> have any hardware to test.
>
> The best seems to add a new parameter to sms core register
> function, allowing it to use extra gfp flags, and pass it only
> for the SDIO variant.
>
> Patch enclosed.

I have confirmed that the USB stick works without GFP_DMA.
The patch LGTM.

Thanks,
Tomoki

> Regards,
> Mauro
>
> [PATCH 1/2 v2] media: siano: use GFP_DMA only for smssdio
>
> Right now, the Siano's core uses GFP_DMA for both USB and
> SDIO variants of the driver. There's no reason to use it
> for USB. So, pass GFP_DMA as a parameter during sms core
> register.
>
> Signed-off-by: Mauro Carvalho Chehab 
>
> diff --git a/drivers/media/common/siano/smscoreapi.c 
> b/drivers/media/common/siano/smscoreapi.c
> index b5dcc6d1fe90..9ed7afa7b2ae 100644
> --- a/drivers/media/common/siano/smscoreapi.c
> +++ b/drivers/media/common/siano/smscoreapi.c
> @@ -649,6 +649,7 @@ smscore_buffer_t *smscore_createbuffer(u8 *buffer, void 
> *common_buffer,
>   */
>  int smscore_register_device(struct smsdevice_params_t *params,
> struct smscore_device_t **coredev,
> +   gfp_t gfp_buf_flags,
> void *mdev)
>  {
> struct smscore_device_t *dev;
> @@ -661,6 +662,7 @@ int smscore_register_device(struct smsdevice_params_t 
> *params,
>  #ifdef CONFIG_MEDIA_CONTROLLER_DVB
> dev->media_dev = mdev;
>  #endif
> +   dev->gfp_buf_flags = gfp_buf_flags;
>
> /* init list entry so it could be safe in smscore_unregister_device */
> INIT_LIST_HEAD(>entry);
> @@ -697,7 +699,7 @@ int smscore_register_device(struct smsdevice_params_t 
> *params,
> buffer = dma_alloc_coherent(params->device,
> dev->common_buffer_size,
> >common_buffer_phys,
> -   GFP_KERNEL | GFP_DMA);
> +   GFP_KERNEL | dev->gfp_buf_flags);
> if (!buffer) {
> smscore_unregister_device(dev);
> return -ENOMEM;
> @@ -792,7 +794,7 @@ static int smscore_init_ir(struct smscore_device_t 
> *coredev)
> else {
> buffer = kmalloc(sizeof(struct sms_msg_data2) +
> SMS_DMA_ALIGNMENT,
> -   GFP_KERNEL | GFP_DMA);
> +   GFP_KERNEL | 
> coredev->gfp_buf_flags);
> if (buffer) {
> struct sms_msg_data2 *msg =
> (struct sms_msg_data2 *)
> @@ -933,7 +935,7 @@ static int smscore_load_firmware_family2(struct 
> smscore_device_t *coredev,
> }
>
> /* PAGE_SIZE buffer shall be enough and dma aligned */
> -   msg = kmalloc(PAGE_SIZE, GFP_KERNEL | GFP_DMA);
> +   msg = kmalloc(PAGE_SIZE, GFP_KERNEL | coredev->gfp_buf_flags);
> if (!msg)
> return -ENOMEM;
>
> @@ -1168,7 +1170,7 @@ static int smscore_load_firmware_from_file(struct 
> smscore_device_t *coredev,
> }
> pr_debug("read fw %s, buffer size=0x%zx\n", fw_filename, fw->size);
> fw_buf = kmalloc(ALIGN(fw->size + sizeof(struct sms_firmware),
> -SMS_ALLOC_ALIGNMENT), GFP_KERNEL | GFP_DMA);
> +SMS_ALLOC_ALIGNMENT), GFP_KERNEL | 
> coredev->gfp_buf_flags);
> if (!fw_buf) {
> pr_err("failed to allocate firmware buffer\n");
> rc = -ENOMEM;
> @@ -1260,7 +1262,7 @@ EXPORT_SYMBOL_GPL(smscore_unregister_device);
>  static int smscore_detect_mode(struct smscore_device_t *coredev)
>  {
> void *buffer = kmalloc(sizeof(struct sms_msg_hdr) + SMS_DMA_ALIGNMENT,
> -  GFP_KERNEL | GFP_DMA);
> +  GFP_KERNEL | coredev->gfp_buf_flags);
> struct sms_msg_hdr *msg =
> (struct sms_msg_hdr *) SMS_ALIGN_ADDRESS(buffer);
> int rc;
> @@ -1309,7 +1311,7 @@ static int smscore_init_device(struct smscore_device_t 
> *coredev, int mode)
> int rc = 0;
>
> buffer = kmalloc(sizeof(struct sms_msg_data) +

Re: [PATCH] lirc.4: remove ioctls and feature bits which were never implemented

2018-05-06 Thread Michael Kerrisk (man-opages)

[CCing original author of this page]


On 04/23/2018 12:26 PM, Sean Young wrote:

The lirc header file included ioctls and feature bits which were never
implemented by any driver. They were removed in commit:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=d55f09abe24b4dfadab246b6f217da547361cdb6


Alec, does this patch look okay to you?

Cheers,

Michael


Signed-off-by: Sean Young 
---
  man4/lirc.4 | 92 ++---
  1 file changed, 2 insertions(+), 90 deletions(-)

diff --git a/man4/lirc.4 b/man4/lirc.4
index 1e94a7163..3adff55f1 100644
--- a/man4/lirc.4
+++ b/man4/lirc.4
@@ -78,9 +78,7 @@ The package reflects a timeout; see the
  .B LIRC_SET_REC_TIMEOUT_REPORTS
  ioctl.
  .\"
-.SS Reading input with the
-.B LIRC_MODE_LIRCCODE
-drivers
+.SS Reading input with the LIRC_MODE_LIRCCODE drivers
  .PP
  In the \fBLIRC_MODE_LIRCCODE\fR
  mode, the data returned by
@@ -204,17 +202,11 @@ Currently serves no purpose since only
  .BR LIRC_MODE_PULSE
  is supported.
  .TP
-.BR LIRC_GET_SEND_CARRIER " (\fIvoid\fP)"
-Get the modulation frequency (Hz).
-.TP
  .BR LIRC_SET_SEND_CARRIER " (\fIint\fP)"
  Set the modulation frequency.
  The argument is the frequency (Hz).
  .TP
-.BR LIRC_GET_SEND_CARRIER " (\fIvoid\fP)"
-Get the modulation frequency used when decoding (Hz).
-.TP
-.BR SET_SEND_DUTY_CYCLE " (\fIint\fP)"
+.BR LIRC_SET_SEND_DUTY_CYCLE " (\fIint\fP)"
  Set the carrier duty cycle.
  .I val
  is a number in the range [0,100] which
@@ -284,36 +276,6 @@ By default this should be turned off.
  .BR LIRC_GET_REC_RESOLUTION " (\fIvoid\fP)"
  Return the driver resolution (microseconds).
  .TP
-.BR LIRC_GET_MIN_FILTER_PULSE " (\fIvoid\fP)", " " \
-LIRC_GET_MAX_FILTER_PULSE " (\fIvoid\fP)"
-Some devices are able to filter out spikes in the incoming signal
-using given filter rules.
-These ioctls return the hardware capabilities that describe the bounds
-of the possible filters.
-Filter settings depend on the IR protocols that are expected.
-.BR lircd (8)
-derives the settings from all protocols definitions found in its
-.BR lircd.conf (5)
-config file.
-.TP
-.BR LIRC_GET_MIN_FILTER_SPACE " (\fIvoid\fP)", " " \
-LIRC_GET_MAX_FILTER_SPACE " (\fIvoid\fP)"
-See
-.BR LIRC_GET_MIN_FILTER_PULSE .
-.TP
-.BR LIRC_SET_REC_FILTER " (\fIint\fP)"
-Pulses/spaces shorter than this (microseconds) are filtered out by
-hardware.
-.TP
-.BR LIRC_SET_REC_FILTER_PULSE " (\fIint\fP)", " " \
-LIRC_SET_REC_FILTER_SPACE " (\fIint\fP)"
-Pulses/spaces shorter than this (microseconds) are filtered out by
-hardware.
-If filters cannot be set independently for pulse/space, the
-corresponding ioctls must return an error and
-.BR LIRC_SET_REC_FILTER
-should be used instead.
-.TP
  .BR LIRC_SET_TRANSMITTER_MASK
  Enable the set of transmitters specified in
  .IR val ,
@@ -343,32 +305,6 @@ carrier reports.
  In that case, it will be disabled as soon as you disable carrier reports.
  Trying to disable a wide band receiver while carrier reports are active
  will do nothing.
-.TP
-.BR LIRC_SETUP_START " (\fIvoid\fP), " LIRC_SETUP_END " (\fIvoid\fP)"
-Setting of several driver parameters can be optimized by bracketing
-the actual ioctl calls
-.BR LIRC_SETUP_START
-and
-.BR LIRC_SETUP_END .
-When a driver receives a
-.BR LIRC_SETUP_START
-ioctl, it can choose to not commit further setting changes to the
-hardware until a
-.BR LIRC_SETUP_END
-is received.
-But this is open to the driver implementation and every driver
-must also handle parameter changes which are not encapsulated by
-.BR LIRC_SETUP_START
-and
-.BR LIRC_SETUP_END .
-Drivers can also choose to ignore these ioctls.
-.TP
-.BR LIRC_NOTIFY_DECODE " (\fIvoid\fP)"
-This ioctl is called by
-.BR lircd (8)
-whenever a successful decoding of an incoming IR signal is possible.
-This can be used by supporting hardware to give visual user
-feedback, for example by flashing an LED.
  .\"
  .SH FEATURES
  .PP
@@ -378,14 +314,6 @@ The
  ioctl returns a bit mask describing features of the driver.
  The following bits may be returned in the mask:
  .TP
-.BR LIRC_CAN_REC_RAW
-The driver is capable of receiving using
-.BR LIRC_MODE_RAW .
-.TP
-.BR LIRC_CAN_REC_PULSE
-The driver is capable of receiving using
-.BR LIRC_MODE_PULSE .
-.TP
  .BR LIRC_CAN_REC_MODE2
  The driver is capable of receiving using
  .BR LIRC_MODE_MODE2 .
@@ -426,10 +354,6 @@ The driver supports
  The driver supports
  .BR LIRC_SET_REC_TIMEOUT .
  .TP
-.BR LIRC_CAN_SET_REC_FILTER
-The driver supports
-.BR LIRC_SET_REC_FILTER .
-.TP
  .BR LIRC_CAN_MEASURE_CARRIER
  The driver supports measuring of the modulation frequency using
  .BR LIRC_SET_MEASURE_CARRIER_MODE .
@@ -438,22 +362,10 @@ The driver supports measuring of the modulation frequency 
using
  The driver supports learning mode using
  .BR LIRC_SET_WIDEBAND_RECEIVER .
  .TP
-.BR LIRC_CAN_NOTIFY_DECODE
-The driver supports
-.BR LIRC_NOTIFY_DECODE .
-.TP
-.BR LIRC_CAN_SEND_RAW
-The driver