From patchwork Tue Sep 1 21:59:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antti Palosaari X-Patchwork-Id: 7106991 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 50FF59F36E for ; Tue, 1 Sep 2015 22:00:11 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 57E68205F0 for ; Tue, 1 Sep 2015 22:00:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 679ED2052C for ; Tue, 1 Sep 2015 22:00:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752079AbbIAWAE (ORCPT ); Tue, 1 Sep 2015 18:00:04 -0400 Received: from mail.kapsi.fi ([217.30.184.167]:38201 "EHLO mail.kapsi.fi" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751564AbbIAV7y (ORCPT ); Tue, 1 Sep 2015 17:59:54 -0400 Received: from dyn3-82-128-185-129.psoas.suomi.net ([82.128.185.129] helo=localhost.localdomain.localdomain) by mail.kapsi.fi with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1ZWtar-0004Ub-LD; Wed, 02 Sep 2015 00:59:53 +0300 From: Antti Palosaari To: linux-media@vger.kernel.org Cc: Hans Verkuil , Antti Palosaari Subject: [PATCH 08/13] hackrf: add control for RF amplifier Date: Wed, 2 Sep 2015 00:59:24 +0300 Message-Id: <1441144769-29211-9-git-send-email-crope@iki.fi> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1441144769-29211-1-git-send-email-crope@iki.fi> References: <1441144769-29211-1-git-send-email-crope@iki.fi> X-SA-Exim-Connect-IP: 82.128.185.129 X-SA-Exim-Mail-From: crope@iki.fi X-SA-Exim-Scanned: No (on mail.kapsi.fi); SAEximRunCond expanded to false Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There is Avago MGA-81563 amplifier just right after antenna connector. It could be turned on/off and its gain is around 12dB. Acked-by: Hans Verkuil Signed-off-by: Antti Palosaari --- drivers/media/usb/hackrf/hackrf.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/drivers/media/usb/hackrf/hackrf.c b/drivers/media/usb/hackrf/hackrf.c index fd1fa41..136de9a 100644 --- a/drivers/media/usb/hackrf/hackrf.c +++ b/drivers/media/usb/hackrf/hackrf.c @@ -31,6 +31,7 @@ enum { CMD_BOARD_ID_READ = 0x0e, CMD_VERSION_STRING_READ = 0x0f, CMD_SET_FREQ = 0x10, + CMD_AMP_ENABLE = 0x11, CMD_SET_LNA_GAIN = 0x13, CMD_SET_VGA_GAIN = 0x14, }; @@ -133,6 +134,7 @@ struct hackrf_dev { struct v4l2_ctrl_handler hdl; struct v4l2_ctrl *bandwidth_auto; struct v4l2_ctrl *bandwidth; + struct v4l2_ctrl *rf_gain; struct v4l2_ctrl *lna_gain; struct v4l2_ctrl *if_gain; @@ -164,6 +166,7 @@ static int hackrf_ctrl_msg(struct hackrf_dev *dev, u8 request, u16 value, switch (request) { case CMD_SET_TRANSCEIVER_MODE: case CMD_SET_FREQ: + case CMD_AMP_ENABLE: case CMD_SAMPLE_RATE_SET: case CMD_BASEBAND_FILTER_BANDWIDTH_SET: pipe = usb_sndctrlpipe(dev->udev, 0); @@ -949,6 +952,22 @@ static int hackrf_set_bandwidth(struct hackrf_dev *dev) return ret; } +static int hackrf_set_rf_gain(struct hackrf_dev *dev) +{ + int ret; + u8 u8tmp; + + dev_dbg(dev->dev, "rf val=%d->%d\n", + dev->rf_gain->cur.val, dev->rf_gain->val); + + u8tmp = (dev->rf_gain->val) ? 1 : 0; + ret = hackrf_ctrl_msg(dev, CMD_AMP_ENABLE, u8tmp, 0, NULL, 0); + if (ret) + dev_dbg(dev->dev, "failed=%d\n", ret); + + return ret; +} + static int hackrf_set_lna_gain(struct hackrf_dev *dev) { int ret; @@ -992,6 +1011,9 @@ static int hackrf_s_ctrl(struct v4l2_ctrl *ctrl) case V4L2_CID_RF_TUNER_BANDWIDTH: ret = hackrf_set_bandwidth(dev); break; + case V4L2_CID_RF_TUNER_RF_GAIN: + ret = hackrf_set_rf_gain(dev); + break; case V4L2_CID_RF_TUNER_LNA_GAIN: ret = hackrf_set_lna_gain(dev); break; @@ -1077,13 +1099,15 @@ static int hackrf_probe(struct usb_interface *intf, } /* Register controls */ - v4l2_ctrl_handler_init(&dev->hdl, 4); + v4l2_ctrl_handler_init(&dev->hdl, 5); dev->bandwidth_auto = v4l2_ctrl_new_std(&dev->hdl, &hackrf_ctrl_ops, V4L2_CID_RF_TUNER_BANDWIDTH_AUTO, 0, 1, 1, 1); dev->bandwidth = v4l2_ctrl_new_std(&dev->hdl, &hackrf_ctrl_ops, V4L2_CID_RF_TUNER_BANDWIDTH, 1750000, 28000000, 50000, 1750000); v4l2_ctrl_auto_cluster(2, &dev->bandwidth_auto, 0, false); + dev->rf_gain = v4l2_ctrl_new_std(&dev->hdl, &hackrf_ctrl_ops, + V4L2_CID_RF_TUNER_RF_GAIN, 0, 12, 12, 0); dev->lna_gain = v4l2_ctrl_new_std(&dev->hdl, &hackrf_ctrl_ops, V4L2_CID_RF_TUNER_LNA_GAIN, 0, 40, 8, 0); dev->if_gain = v4l2_ctrl_new_std(&dev->hdl, &hackrf_ctrl_ops,