From patchwork Wed Feb 4 20:55:32 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Klimov X-Patchwork-Id: 5514 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n14Ku7pd026117 for ; Wed, 4 Feb 2009 20:56:07 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755079AbZBDUze (ORCPT ); Wed, 4 Feb 2009 15:55:34 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1755239AbZBDUze (ORCPT ); Wed, 4 Feb 2009 15:55:34 -0500 Received: from fg-out-1718.google.com ([72.14.220.154]:27354 "EHLO fg-out-1718.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755079AbZBDUzd (ORCPT ); Wed, 4 Feb 2009 15:55:33 -0500 Received: by fg-out-1718.google.com with SMTP id 16so1345891fgg.17 for ; Wed, 04 Feb 2009 12:55:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:subject:from:to:cc :in-reply-to:references:content-type:date:message-id:mime-version :x-mailer:content-transfer-encoding; bh=CSGppIq+UHHRLVPADQb2e0rmIdL+yBfmUIPOlnIdOug=; b=WtF1nrV6pfJk1ml4d2zss82bOghkVTrNq4nox1Ri2vSUpZu6cXLuaWI5utaJrU/IGO YsJTVS3jEjp7tv8WCYQHdZ3tq6Q1BCSvrIfzPrg0kL9LHy2dzgWw+3at1T5rsJgMlSdT HSmxHqH8pOJkc9dMHWe0SLb8wuyLWq9DyPrdI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=subject:from:to:cc:in-reply-to:references:content-type:date :message-id:mime-version:x-mailer:content-transfer-encoding; b=mj2DLmkYCq0MBrKUSGtWkdL5TFXM4ZP8vxEMAC2Nle9sUYU0o4c6RF871Ssm+/7ya3 FgRmV+vBaD/vXNuD0DrApvwIGRb8MYUcXPQQUgxnZJqhOktluQxWUhBbZK/WYuD7VNcQ UEMyVXOMBJzpSwhxp1YrMmWxdlMkh7YimQGbY= Received: by 10.86.4.2 with SMTP id 2mr427603fgd.50.1233780931123; Wed, 04 Feb 2009 12:55:31 -0800 (PST) Received: from ?192.168.1.42? (gw.zunet.ru [217.67.117.64]) by mx.google.com with ESMTPS id d4sm207653fga.18.2009.02.04.12.55.30 (version=SSLv3 cipher=RC4-MD5); Wed, 04 Feb 2009 12:55:30 -0800 (PST) Subject: Re: [patch review 6/8] radio-mr800: add stereo support From: Alexey Klimov To: Douglas Schilling Landgraf Cc: linux-media@vger.kernel.org In-Reply-To: <1233623335.17456.262.camel@tux.localhost> References: <1233623335.17456.262.camel@tux.localhost> Date: Wed, 04 Feb 2009 23:55:32 +0300 Message-Id: <1233780932.2038.252.camel@tux.localhost> Mime-Version: 1.0 X-Mailer: Evolution 2.24.2 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Reformatted patch, version 2. Corrects checking of returned value after usb_bulk_msg. --- Patch introduces new amradio_set_stereo function. Driver calls this func to make stereo radio reception. Signed-off-by: Alexey Klimov -- diff -r 34b045702595 linux/drivers/media/radio/radio-mr800.c --- a/linux/drivers/media/radio/radio-mr800.c Tue Feb 03 03:02:39 2009 +0300 +++ b/linux/drivers/media/radio/radio-mr800.c Tue Feb 03 03:04:03 2009 +0300 @@ -94,10 +94,15 @@ */ #define AMRADIO_SET_FREQ 0xa4 #define AMRADIO_SET_MUTE 0xab +#define AMRADIO_SET_MONO 0xae /* Comfortable defines for amradio_set_mute */ #define AMRADIO_START 0x00 #define AMRADIO_STOP 0x01 + +/* Comfortable defines for amradio_set_stereo */ +#define WANT_STEREO 0x00 +#define WANT_MONO 0x01 /* module parameter */ static int radio_nr = -1; @@ -266,12 +271,48 @@ return retval; } - radio->stereo = 0; + mutex_unlock(&radio->lock); + + return retval; +} + +static int amradio_set_stereo(struct amradio_device *radio, char argument) +{ + int retval; + int size; + + /* safety check */ + if (radio->removed) + return -EIO; + + mutex_lock(&radio->lock); + + radio->buffer[0] = 0x00; + radio->buffer[1] = 0x55; + radio->buffer[2] = 0xaa; + radio->buffer[3] = 0x00; + radio->buffer[4] = AMRADIO_SET_MONO; + radio->buffer[5] = argument; + radio->buffer[6] = 0x00; + radio->buffer[7] = 0x00; + + retval = usb_bulk_msg(radio->usbdev, usb_sndintpipe(radio->usbdev, 2), + (void *) (radio->buffer), BUFFER_LENGTH, &size, USB_TIMEOUT); + + if (retval < 0 || size != BUFFER_LENGTH) { + radio->stereo = -1; + mutex_unlock(&radio->lock); + return retval; + } + + radio->stereo = 1; mutex_unlock(&radio->lock); return retval; } + + /* USB subsystem interface begins here */ @@ -310,6 +351,7 @@ struct v4l2_tuner *v) { struct amradio_device *radio = video_get_drvdata(video_devdata(file)); + int retval; /* safety check */ if (radio->removed) @@ -321,7 +363,16 @@ /* TODO: Add function which look is signal stereo or not * amradio_getstat(radio); */ - radio->stereo = -1; + +/* we call amradio_set_stereo to set radio->stereo + * Honestly, amradio_getstat should cover this in future and + * amradio_set_stereo shouldn't be here + */ + retval = amradio_set_stereo(radio, WANT_STEREO); + if (retval < 0) + amradio_dev_warn(&radio->videodev->dev, + "set stereo failed\n"); + strcpy(v->name, "FM"); v->type = V4L2_TUNER_RADIO; v->rangelow = FREQ_MIN * FREQ_MUL; @@ -342,6 +393,7 @@ struct v4l2_tuner *v) { struct amradio_device *radio = video_get_drvdata(video_devdata(file)); + int retval; /* safety check */ if (radio->removed) @@ -349,6 +401,25 @@ if (v->index > 0) return -EINVAL; + + /* mono/stereo selector */ + switch (v->audmode) { + case V4L2_TUNER_MODE_MONO: + retval = amradio_set_stereo(radio, WANT_MONO); + if (retval < 0) + amradio_dev_warn(&radio->videodev->dev, + "set mono failed\n"); + break; + case V4L2_TUNER_MODE_STEREO: + retval = amradio_set_stereo(radio, WANT_STEREO); + if (retval < 0) + amradio_dev_warn(&radio->videodev->dev, + "set stereo failed\n"); + break; + default: + return -EINVAL; + } + return 0; } @@ -508,6 +579,11 @@ return -EIO; } + retval = amradio_set_stereo(radio, WANT_STEREO); + if (retval < 0) + amradio_dev_warn(&radio->videodev->dev, + "set stereo failed\n"); + retval = amradio_setfreq(radio, radio->curfreq); if (retval < 0) amradio_dev_warn(&radio->videodev->dev, @@ -649,6 +725,7 @@ radio->users = 0; radio->usbdev = interface_to_usbdev(intf); radio->curfreq = 95.16 * FREQ_MUL; + radio->stereo = -1; mutex_init(&radio->lock);