From patchwork Wed Aug 3 18:03:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 9261699 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 DD1BD6089F for ; Wed, 3 Aug 2016 18:05:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D25F028236 for ; Wed, 3 Aug 2016 18:05:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C730428306; Wed, 3 Aug 2016 18:05:27 +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 4F77D28249 for ; Wed, 3 Aug 2016 18:05:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757556AbcHCSFY (ORCPT ); Wed, 3 Aug 2016 14:05:24 -0400 Received: from mail-pa0-f65.google.com ([209.85.220.65]:33109 "EHLO mail-pa0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932414AbcHCSEJ (ORCPT ); Wed, 3 Aug 2016 14:04:09 -0400 Received: by mail-pa0-f65.google.com with SMTP id q2so14438672pap.0; Wed, 03 Aug 2016 11:04:04 -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=DZ+PIsh2WyTiN6YFubvd6OCYnecE/ss0BiLdkyZDLCI=; b=TyPxywt92kGV8SGhMxdUY/e3g5fyVuNBNhxepFdPM9/FKX70LDHiIH48gn2pxmq4tz A67IQOhRW9PZQLcMut39GtCT6S/IWxiNTqYb735oAQmvyGjKiPKtQetoVO5XyK2v7qVN FSYLAsfUXplxi9ZibYvM8TfXPzM1AA8wcxCvyU4G1fUtGWXlcAhjbjHnGyWi4Ov1tHbj Z8hXCHwHFSRS7EKEf2AW7DorFZJEoJscmfKql8Gl2dS5848xiaTIOnUE7lyH/4eVFpZj 1y8ehmlIw+wZ6J3Ymeq72qKQw+waPNzsx/JKfb/5S3LWtHCxwry1Jyrm5f6822Z7MsZT Y3cw== 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=DZ+PIsh2WyTiN6YFubvd6OCYnecE/ss0BiLdkyZDLCI=; b=Q3pqwmpJjXDFMOvc9JxkTRNvRiSm/Dw+ZWHrQCouuJnSHvkC8oEs4HkvIXsH4cnm9o DmmI/RGG3xq/soktR8vrCf1rhpWpAEVXss/GWBdWsXYzoDI3k4H2NrvPxuUp0Ogs9j+s 3WscJwql/Al3XjpPW8J+K6trWImWCcacTSbx16xSrUvPhnHbHy1mdH+hEJl+e7w/iODM PJwVLXUhhyYIB4rwVezFlm57Ovb9Ke/TzJ/NtGdAfqmplHXFrqN4dOklaSkxIVxEEiQN oqfw7BTjmxaIJDn7tbKnnaTo6yiD6YMCz65NpXW22uwPvv+oox8PFbHrLeCfMMBPl8fh 8wdg== X-Gm-Message-State: AEkooutIzBCFTqu+XxjTnbUB17Y9C8x5eZuBEnoDTbL9MdewoBXpymrlKGBSJfevso+KIA== X-Received: by 10.66.123.42 with SMTP id lx10mr117080369pab.95.1470247443387; Wed, 03 Aug 2016 11:04:03 -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 w64sm14219878pfb.93.2016.08.03.11.04.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 03 Aug 2016 11:04:02 -0700 (PDT) From: Steve Longerbeam X-Google-Original-From: Steve Longerbeam To: lars@metafoo.de Cc: mchehab@kernel.org, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Steve Longerbeam Subject: [PATCH v4 4/8] media: adv7180: add power pin control Date: Wed, 3 Aug 2016 11:03:46 -0700 Message-Id: <1470247430-11168-5-git-send-email-steve_longerbeam@mentor.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1470247430-11168-1-git-send-email-steve_longerbeam@mentor.com> References: <1470247430-11168-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 optional support for "powerdown" pin control. Signed-off-by: Steve Longerbeam Tested-by: Tim Harvey Acked-by: Tim Harvey Acked-by: Lars-Peter Clausen --- v4: no changes v3: no changes v2: - placed call to gpiod_get inline in adv7180_probe(). - rename gpio pin to "powerdown". - document optional powerdown-gpios property in Documentation/devicetree/bindings/media/i2c/adv7180.txt. - include error number in error message on gpiod_get failure. --- .../devicetree/bindings/media/i2c/adv7180.txt | 4 ++++ drivers/media/i2c/Kconfig | 2 +- drivers/media/i2c/adv7180.c | 27 ++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/media/i2c/adv7180.txt b/Documentation/devicetree/bindings/media/i2c/adv7180.txt index 6c175d2..ab9ef02 100644 --- a/Documentation/devicetree/bindings/media/i2c/adv7180.txt +++ b/Documentation/devicetree/bindings/media/i2c/adv7180.txt @@ -15,6 +15,10 @@ Required Properties : "adi,adv7282" "adi,adv7282-m" +Optional Properties : +- powerdown-gpios: reference to the GPIO connected to the powerdown pin, + if any. + Optional Endpoint Properties : - newavmode: a boolean property to indicate the BT.656 bus is operating in Analog Device's NEWAVMODE. Valid for BT.656 busses only. diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig index ce9006e..6769898 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 467953e..b2df181 100644 --- a/drivers/media/i2c/adv7180.c +++ b/drivers/media/i2c/adv7180.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -215,6 +216,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 newavmode; bool powered; @@ -466,6 +468,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; @@ -1219,6 +1234,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); @@ -1319,6 +1336,14 @@ static int adv7180_probe(struct i2c_client *client, adv7180_of_parse(state); + state->pwdn_gpio = devm_gpiod_get_optional(&client->dev, "powerdown", + GPIOD_OUT_HIGH); + if (IS_ERR(state->pwdn_gpio)) { + ret = PTR_ERR(state->pwdn_gpio); + v4l_err(client, "request for power pin failed: %d\n", 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); @@ -1410,6 +1435,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;