public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Hans Verkuil <hverkuil@xs4all.nl>
To: Antti Palosaari <crope@iki.fi>
Cc: linux-media@vger.kernel.org,
	Mauro Carvalho Chehab <m.chehab@samsung.com>
Subject: Re: [PATCH] e4000: implement controls via v4l2 control framework
Date: Wed, 05 Feb 2014 08:28:40 +0100	[thread overview]
Message-ID: <52F1E828.6020000@xs4all.nl> (raw)
In-Reply-To: <1391558734-26237-2-git-send-email-crope@iki.fi>

Hi Antti,

Hmm, it's a bit ugly this code. I have some suggestions below...

On 02/05/2014 01:05 AM, Antti Palosaari wrote:
> Implement gain and bandwidth controls using v4l2 control framework.
> Pointer to control handler is provided by exported symbol.
> 
> Cc: Mauro Carvalho Chehab <m.chehab@samsung.com>
> Cc: Hans Verkuil <hverkuil@xs4all.nl>
> Signed-off-by: Antti Palosaari <crope@iki.fi>
> ---
>  drivers/media/tuners/e4000.c      | 210 +++++++++++++++++++++++++++++++++++++-
>  drivers/media/tuners/e4000.h      |  14 +++
>  drivers/media/tuners/e4000_priv.h |  12 +++
>  3 files changed, 235 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/tuners/e4000.c b/drivers/media/tuners/e4000.c
> index 9187190..77318e9 100644
> --- a/drivers/media/tuners/e4000.c
> +++ b/drivers/media/tuners/e4000.c
> @@ -448,6 +448,178 @@ err:
>  	return ret;
>  }
>  
> +static int e4000_set_lna_gain(struct dvb_frontend *fe)

I would change this to:

 e4000_set_lna_if_gain(struct dvb_frontend *fe, bool lna_auto, bool if_auto, bool set_lna)

> +{
> +	struct e4000_priv *priv = fe->tuner_priv;
> +	int ret;
> +	u8 u8tmp;

General comment: always add a newline after variable declarations.

> +	dev_dbg(&priv->client->dev, "%s: lna auto=%d->%d val=%d->%d\n",
> +			__func__, priv->lna_gain_auto->cur.val,
> +			priv->lna_gain_auto->val, priv->lna_gain->cur.val,
> +			priv->lna_gain->val);
> +
> +	if (fe->ops.i2c_gate_ctrl)
> +		fe->ops.i2c_gate_ctrl(fe, 1);
> +
> +	if (priv->lna_gain_auto->val && priv->if_gain_auto->cur.val)
> +		u8tmp = 0x17;
> +	else if (priv->lna_gain_auto->val)
> +		u8tmp = 0x19;
> +	else if (priv->if_gain_auto->cur.val)
> +		u8tmp = 0x16;
> +	else
> +		u8tmp = 0x10;
> +
> +	ret = e4000_wr_reg(priv, 0x1a, u8tmp);
> +	if (ret)
> +		goto err;
> +
> +	if (priv->lna_gain_auto->val == false) {
> +		ret = e4000_wr_reg(priv, 0x14, priv->lna_gain->val);
> +		if (ret)
> +			goto err;
> +	}

Set lna gain if set_lna is true and lna_auto is false, set if gain if
set_lna is false and if_gain is false.

> +
> +	if (fe->ops.i2c_gate_ctrl)
> +		fe->ops.i2c_gate_ctrl(fe, 0);
> +
> +	return 0;

I would remove the 4 lines above, and instead just...

> +err:
> +	if (fe->ops.i2c_gate_ctrl)
> +		fe->ops.i2c_gate_ctrl(fe, 0);
> +

...add this:

	if (ret)

> +	dev_dbg(&priv->client->dev, "%s: failed=%d\n", __func__, ret);
> +	return ret;
> +}
> +
> +static int e4000_set_mixer_gain(struct dvb_frontend *fe)
> +{
> +	struct e4000_priv *priv = fe->tuner_priv;
> +	int ret;
> +	u8 u8tmp;
> +	dev_dbg(&priv->client->dev, "%s: mixer auto=%d->%d val=%d->%d\n",
> +			__func__, priv->mixer_gain_auto->cur.val,
> +			priv->mixer_gain_auto->val, priv->mixer_gain->cur.val,
> +			priv->mixer_gain->val);
> +
> +	if (fe->ops.i2c_gate_ctrl)
> +		fe->ops.i2c_gate_ctrl(fe, 1);
> +
> +	if (priv->mixer_gain_auto->val)
> +		u8tmp = 0x15;
> +	else
> +		u8tmp = 0x14;
> +
> +	ret = e4000_wr_reg(priv, 0x20, u8tmp);
> +	if (ret)
> +		goto err;
> +
> +	if (priv->mixer_gain_auto->val == false) {
> +		ret = e4000_wr_reg(priv, 0x15, priv->mixer_gain->val);
> +		if (ret)
> +			goto err;
> +	}
> +
> +	if (fe->ops.i2c_gate_ctrl)
> +		fe->ops.i2c_gate_ctrl(fe, 0);
> +
> +	return 0;
> +err:
> +	if (fe->ops.i2c_gate_ctrl)
> +		fe->ops.i2c_gate_ctrl(fe, 0);
> +
> +	dev_dbg(&priv->client->dev, "%s: failed=%d\n", __func__, ret);
> +	return ret;
> +}
> +
> +static int e4000_set_if_gain(struct dvb_frontend *fe)
> +{
> +	struct e4000_priv *priv = fe->tuner_priv;
> +	int ret;
> +	u8 buf[2];
> +	u8 u8tmp;
> +	dev_dbg(&priv->client->dev, "%s: if auto=%d->%d val=%d->%d\n",
> +			__func__, priv->if_gain_auto->cur.val,
> +			priv->if_gain_auto->val, priv->if_gain->cur.val,
> +			priv->if_gain->val);
> +
> +	if (fe->ops.i2c_gate_ctrl)
> +		fe->ops.i2c_gate_ctrl(fe, 1);
> +
> +	if (priv->if_gain_auto->val && priv->lna_gain_auto->cur.val)
> +		u8tmp = 0x17;
> +	else if (priv->lna_gain_auto->cur.val)
> +		u8tmp = 0x19;
> +	else if (priv->if_gain_auto->val)
> +		u8tmp = 0x16;
> +	else
> +		u8tmp = 0x10;
> +
> +	ret = e4000_wr_reg(priv, 0x1a, u8tmp);
> +	if (ret)
> +		goto err;
> +
> +	if (priv->if_gain_auto->val == false) {
> +		buf[0] = e4000_if_gain_lut[priv->if_gain->val].reg16_val;
> +		buf[1] = e4000_if_gain_lut[priv->if_gain->val].reg17_val;
> +		ret = e4000_wr_regs(priv, 0x16, buf, 2);
> +		if (ret)
> +			goto err;
> +	}
> +
> +	if (fe->ops.i2c_gate_ctrl)
> +		fe->ops.i2c_gate_ctrl(fe, 0);
> +
> +	return 0;
> +err:
> +	if (fe->ops.i2c_gate_ctrl)
> +		fe->ops.i2c_gate_ctrl(fe, 0);
> +
> +	dev_dbg(&priv->client->dev, "%s: failed=%d\n", __func__, ret);
> +	return ret;
> +}

This function can be dropped.

> +
> +static int e4000_s_ctrl(struct v4l2_ctrl *ctrl)
> +{
> +	struct e4000_priv *priv =
> +			container_of(ctrl->handler, struct e4000_priv, hdl);
> +	struct dvb_frontend *fe = priv->fe;
> +	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
> +	int ret;
> +	dev_dbg(&priv->client->dev,
> +			"%s: id=%d name=%s val=%d min=%d max=%d step=%d\n",
> +			__func__, ctrl->id, ctrl->name, ctrl->val,
> +			ctrl->minimum, ctrl->maximum, ctrl->step);
> +
> +	switch (ctrl->id) {
> +	case V4L2_CID_BANDWIDTH_AUTO:
> +	case V4L2_CID_BANDWIDTH:
> +		c->bandwidth_hz = priv->bandwidth->val;
> +		ret = e4000_set_params(priv->fe);
> +		break;
> +	case  V4L2_CID_LNA_GAIN_AUTO:
> +	case  V4L2_CID_LNA_GAIN:
> +		ret = e4000_set_lna_gain(priv->fe);

Becomes:

		ret = e4000_set_lna_if_gain(priv->fe, priv->lna_gain_auto->val,
				priv->if_gain_auto->cur.val, true);

> +		break;
> +	case  V4L2_CID_MIXER_GAIN_AUTO:
> +	case  V4L2_CID_MIXER_GAIN:
> +		ret = e4000_set_mixer_gain(priv->fe);
> +		break;
> +	case  V4L2_CID_IF_GAIN_AUTO:
> +	case  V4L2_CID_IF_GAIN:
> +		ret = e4000_set_if_gain(priv->fe);

		ret = e4000_set_lna_if_gain(priv->fe, priv->lna_gain_auto->cur.val,
				priv->if_gain_auto->val, false);

> +		break;
> +	default:
> +		ret = -EINVAL;
> +	}
> +
> +	return ret;
> +}

Regards,

	Hans


  reply	other threads:[~2014-02-05  7:29 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-05  0:05 [PATCH v2] DVB tuner use v4l2 controls Antti Palosaari
2014-02-05  0:05 ` [PATCH] e4000: implement controls via v4l2 control framework Antti Palosaari
2014-02-05  7:28   ` Hans Verkuil [this message]
2014-02-05  9:16     ` Antti Palosaari

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=52F1E828.6020000@xs4all.nl \
    --to=hverkuil@xs4all.nl \
    --cc=crope@iki.fi \
    --cc=linux-media@vger.kernel.org \
    --cc=m.chehab@samsung.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox