From patchwork Tue Jun 14 22:49:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 9177105 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 C40BC60868 for ; Tue, 14 Jun 2016 22:52:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B495728307 for ; Tue, 14 Jun 2016 22:52:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A9B4E2833F; Tue, 14 Jun 2016 22:52:03 +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 3E5792833E for ; Tue, 14 Jun 2016 22:52:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932271AbcFNWv6 (ORCPT ); Tue, 14 Jun 2016 18:51:58 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:33548 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932194AbcFNWvb (ORCPT ); Tue, 14 Jun 2016 18:51:31 -0400 Received: by mail-pf0-f193.google.com with SMTP id c74so307109pfb.0 for ; Tue, 14 Jun 2016 15:51: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=pqH4CNsonJzvBmvFc+QRHSVFBiDh3vKz+zDDxPqHdJQ=; b=bpUY+BLqnMzPRHrzectIoJOBxFZ+xJQCALUxyV7x2Mejy+dpmgnGOCsvUSw1tp9f4S y7N8aOwj1+bYmKHaqanAZOH2cA+p1ew8GAfDsZmS12DKmSJc4N6k/CK5aemOC3laMMQH BbY/oqmrXyHT7UAcWKub49jItnXt3SNEfTUnyJf0phf76KmKp8/cfLf/ZnjMnODvVQrJ sM4zk93Ub1B9vAxr7r5VV3rGBfiZKyi227yOkdvoQhtXztwd8J/lSIEjs5Y8m5h5wd7a gd57mlgHPPPv9DaWb1aiK0PHwQnuryod32ufiJSbJF75qdhWojRdOqJt5i1TS+7sHozh S3mA== 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=pqH4CNsonJzvBmvFc+QRHSVFBiDh3vKz+zDDxPqHdJQ=; b=Cgg1lsSm5AvtEIvU9NvQ1Xo4lRCT3eYzOWabYL567Yk3E4uGLQUkhiihucsCwaOHFl dwKxCXPRpktnm6iGdB83gPMtoDt5GYtWOZA5GVlOyWbpmYAaKvPY19fYP07YgFzSEV2w ozgBxuD+1lj0+WPSApYRogZ0ivXYJU9aKSAxx3jD+GUUjBV7B0iAK7g/bX14XETyNMsF GgP2OlfNBpOViMeA2PIAPDglDm27+gtyRA1WNFdQG6BfILsVfoRgZ/5QhjpoThxE9uIy V8eEwoAcNgwYloqtqEDIR13yA/LK8iHZNVZOpzqWbP1nNbCYzSUSrmYiodub55fAgrxL PGFw== X-Gm-Message-State: ALyK8tIOaCNfgw5ylQN74ELR4DQAvRKhEnTRNMeXMtEn5lNHyBFn2nNerZUo7OvqOJ7YbA== X-Received: by 10.66.62.196 with SMTP id a4mr51359pas.25.1465944691261; Tue, 14 Jun 2016 15:51:31 -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 v184sm47829999pfb.24.2016.06.14.15.51.30 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 14 Jun 2016 15:51:30 -0700 (PDT) From: Steve Longerbeam X-Google-Original-From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Steve Longerbeam Subject: [PATCH 35/38] media: adv7180: add power pin control Date: Tue, 14 Jun 2016 15:49:31 -0700 Message-Id: <1465944574-15745-36-git-send-email-steve_longerbeam@mentor.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1465944574-15745-1-git-send-email-steve_longerbeam@mentor.com> References: <1465944574-15745-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" device node and pin control. Signed-off-by: Steve Longerbeam --- drivers/media/i2c/adv7180.c | 51 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/drivers/media/i2c/adv7180.c b/drivers/media/i2c/adv7180.c index b77b0a4..b3bb19f 100644 --- a/drivers/media/i2c/adv7180.c +++ b/drivers/media/i2c/adv7180.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -192,6 +193,7 @@ struct adv7180_state { struct media_pad pad; struct mutex mutex; /* mutual excl. when accessing chip */ int irq; + int pwdn_gpio; v4l2_std_id curr_norm; bool powered; bool streaming; @@ -442,6 +444,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 (!gpio_is_valid(state->pwdn_gpio)) + return; + + if (on) { + gpio_set_value_cansleep(state->pwdn_gpio, 1); + usleep_range(5000, 5001); + } else { + gpio_set_value_cansleep(state->pwdn_gpio, 0); + } +} + static int adv7180_set_power(struct adv7180_state *state, bool on) { u8 val; @@ -1185,6 +1200,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); @@ -1232,6 +1249,34 @@ out_unlock: return ret; } +static int adv7180_of_parse(struct adv7180_state *state) +{ + struct i2c_client *client = state->client; + struct device_node *np = client->dev.of_node; + int ret; + + ret = of_get_named_gpio(np, "pwdn-gpio", 0); + + if (gpio_is_valid(ret)) { + state->pwdn_gpio = ret; + ret = devm_gpio_request_one(&client->dev, + state->pwdn_gpio, + GPIOF_OUT_INIT_HIGH, + "adv7180_pwdn"); + if (ret < 0) { + v4l_err(client, "request for power pin failed\n"); + return ret; + } + } else { + if (ret == -EPROBE_DEFER) + return ret; + /* assume a power-down gpio is not required */ + state->pwdn_gpio = -1; + } + + return 0; +} + static int adv7180_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -1254,6 +1299,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); @@ -1345,6 +1394,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;