From patchwork Wed Jul 6 22:59:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 9217405 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AEA2D60467 for ; Wed, 6 Jul 2016 23:18:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9ED5C284D5 for ; Wed, 6 Jul 2016 23:18:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8FD8E28532; Wed, 6 Jul 2016 23:18:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 27FB1284D5 for ; Wed, 6 Jul 2016 23:18:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755907AbcGFXSc (ORCPT ); Wed, 6 Jul 2016 19:18:32 -0400 Received: from mail-pa0-f67.google.com ([209.85.220.67]:36769 "EHLO mail-pa0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755651AbcGFXSa (ORCPT ); Wed, 6 Jul 2016 19:18:30 -0400 Received: by mail-pa0-f67.google.com with SMTP id ib6so106537pad.3 for ; Wed, 06 Jul 2016 16:17:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=uxTUsgpe7OMS67XX+A5aUiwk6hIF/Qcmetmu6u246LU=; b=lj1wbxPGT7g6GIngAJ9DOq5lgnB9I1E9mKLhogmAk3ANh9JPcR0gkfRAGW5QUqpkOb Ad5SHagcivPQMsh3+7vy+y3i8c5bxm0DBRvsK5ignFw3YZc8c85z1tNE2blnkilVMjwY OKCyIjEl1/v4vKGUmryRiYZ7rc1METRxn6neMi3PG5hB/5O/3t9RoLxBKL3GveClI6EN HPVthyTzCi7ETKwvzFcPOgR0/pSMqQghfs9iIGyi8aRUIjTTdStxfKyYCgJUnnv+kmz8 HX9URowDOOaWazErXrXzQHV5sEFLEsnd0Ve5gvpNZax2oHGHHlnoPNlxZKZF3zVHj7/Z e3Kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=uxTUsgpe7OMS67XX+A5aUiwk6hIF/Qcmetmu6u246LU=; b=mKdnQDaEgZvDF1JDvdggje2t+kZt0Hgj/HCpTZ8bwG5h3B7fUI98Q37j/s6GlEV/FE uJt9i6RS/PumKOZjeBWNE/uD7z7GMzp5S3mAkAUpA5vZjBYxY58tvmZHPDpn/KiZ/14M FGzhwSde+utpQZW6C3LaPCKNcKQj3IwwWMaPz7duPxkM0rffLQCINNYzD/Rb/3etSd6s LE4+B5CtG/se28wytokKJ6nZPjub766DUVQLMm234olriwc8eGRMLuMNg8ThvW2hVXmi qr1D9nXDgVo6wu5MDmhqRSaKRcktQ3OYu6N60GaWFXfKioAxxDQ/UK/3NIcNRZEwjTD4 41PQ== X-Gm-Message-State: ALyK8tI9wlZ20Av0WTohhoRmabPqmJGirBHynCYYG0qwt02ajK4+euEXl4Pm+fxRlNguuw== X-Received: by 10.66.97.104 with SMTP id dz8mr46146691pab.22.1467846052232; Wed, 06 Jul 2016 16:00:52 -0700 (PDT) Received: from mothership.sklembedded.com (c-73-241-2-21.hsd1.ca.comcast.net. [73.241.2.21]) by smtp.googlemail.com with ESMTPSA id v126sm6915578pfb.60.2016.07.06.16.00.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 06 Jul 2016 16:00:51 -0700 (PDT) From: Steve Longerbeam X-Google-Original-From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Steve Longerbeam Subject: [PATCH 03/11] media: adv7180: add power pin control Date: Wed, 6 Jul 2016 15:59:56 -0700 Message-Id: <1467846004-12731-4-git-send-email-steve_longerbeam@mentor.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1467846004-12731-1-git-send-email-steve_longerbeam@mentor.com> References: <1467846004-12731-1-git-send-email-steve_longerbeam@mentor.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Some targets control the ADV7180 power pin via a gpio, so add support for "pwdn-gpio" pin control. Signed-off-by: Steve Longerbeam Tested-by: Tim Harvey Acked-by: Tim Harvey --- drivers/media/i2c/Kconfig | 2 +- drivers/media/i2c/adv7180.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig index 993dc50..80d39f6 100644 --- a/drivers/media/i2c/Kconfig +++ b/drivers/media/i2c/Kconfig @@ -187,7 +187,7 @@ comment "Video decoders" config VIDEO_ADV7180 tristate "Analog Devices ADV7180 decoder" - depends on VIDEO_V4L2 && I2C && VIDEO_V4L2_SUBDEV_API + depends on GPIOLIB && VIDEO_V4L2 && I2C && VIDEO_V4L2_SUBDEV_API ---help--- Support for the Analog Devices ADV7180 video decoder. diff --git a/drivers/media/i2c/adv7180.c b/drivers/media/i2c/adv7180.c index 967303a..38e5161 100644 --- a/drivers/media/i2c/adv7180.c +++ b/drivers/media/i2c/adv7180.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -191,6 +192,7 @@ struct adv7180_state { struct media_pad pad; struct mutex mutex; /* mutual excl. when accessing chip */ int irq; + struct gpio_desc *pwdn_gpio; v4l2_std_id curr_norm; bool autodetect; bool powered; @@ -443,6 +445,19 @@ static int adv7180_g_std(struct v4l2_subdev *sd, v4l2_std_id *norm) return 0; } +static void adv7180_set_power_pin(struct adv7180_state *state, bool on) +{ + if (!state->pwdn_gpio) + return; + + if (on) { + gpiod_set_value_cansleep(state->pwdn_gpio, 0); + usleep_range(5000, 10000); + } else { + gpiod_set_value_cansleep(state->pwdn_gpio, 1); + } +} + static int adv7180_set_power(struct adv7180_state *state, bool on) { u8 val; @@ -1143,6 +1158,8 @@ static int init_device(struct adv7180_state *state) mutex_lock(&state->mutex); + adv7180_set_power_pin(state, true); + adv7180_write(state, ADV7180_REG_PWR_MAN, ADV7180_PWR_MAN_RES); usleep_range(5000, 10000); @@ -1190,6 +1207,20 @@ out_unlock: return ret; } +static int adv7180_of_parse(struct adv7180_state *state) +{ + struct i2c_client *client = state->client; + + state->pwdn_gpio = devm_gpiod_get_optional(&client->dev, "pwdn", + GPIOD_OUT_HIGH); + if (IS_ERR(state->pwdn_gpio)) { + v4l_err(client, "request for power pin failed\n"); + return PTR_ERR(state->pwdn_gpio); + } + + return 0; +} + static int adv7180_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -1212,6 +1243,10 @@ static int adv7180_probe(struct i2c_client *client, state->field = V4L2_FIELD_INTERLACED; state->chip_info = (struct adv7180_chip_info *)id->driver_data; + ret = adv7180_of_parse(state); + if (ret) + return ret; + if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2) { state->csi_client = i2c_new_dummy(client->adapter, ADV7180_DEFAULT_CSI_I2C_ADDR); @@ -1303,6 +1338,8 @@ static int adv7180_remove(struct i2c_client *client) if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2) i2c_unregister_device(state->csi_client); + adv7180_set_power_pin(state, false); + mutex_destroy(&state->mutex); return 0;