From patchwork Thu Jun 15 03:31:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antti Palosaari X-Patchwork-Id: 9787975 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 0A93660231 for ; Thu, 15 Jun 2017 03:32:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F3AD12854A for ; Thu, 15 Jun 2017 03:32:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E89DE285A8; Thu, 15 Jun 2017 03:32:04 +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.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_HI 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 1FFF3285BE for ; Thu, 15 Jun 2017 03:32:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752151AbdFODb6 (ORCPT ); Wed, 14 Jun 2017 23:31:58 -0400 Received: from mail.kapsi.fi ([217.30.184.167]:37616 "EHLO mail.kapsi.fi" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751711AbdFODbg (ORCPT ); Wed, 14 Jun 2017 23:31:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=kapsi.fi; s=20161220; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=bif40Lsp8aLogF/cOre4Ecy6E90WK9CepLn9S+K7re8=; b=QHsbXOPoho+XmVvtwWxYE4UDxXWKhGI3+tiggiJq1xO+wDYBLfxvQ4PhpoamtT/951caM+6JeKU+vJX/c53KBMzEpryAtdxwWNuyxBCSKsXmaYy3rc/CgWxzCF2PBzwPlc8eCIAgGYG7P9xC4nGzZoBKE9HG3aGYUIrH+Zsv9OjvNcFmh1+rcsoy0nEbrZ5rE1wfXClpGTgt5RU9dm9sLlDcmM4Zj3Uo7o1mklvCYMMyig2mJUa53YhkTSY0zzPINTnVAg79mNsf//XzebSpjd+K28I0DwAMGrVRT/LLFqrlUV4mtg01V3LuZ6xVHycvbw1vHrrS1GT7kTM63HX/1A==; Received: from dyn3-82-128-189-68.psoas.suomi.net ([82.128.189.68] helo=localhost.localdomain) by mail.kapsi.fi with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dLLVP-0001Yv-5K; Thu, 15 Jun 2017 06:31:35 +0300 From: Antti Palosaari To: linux-media@vger.kernel.org Cc: Antti Palosaari Subject: [PATCH 15/15] af9013: refactor power control Date: Thu, 15 Jun 2017 06:31:05 +0300 Message-Id: <20170615033105.13517-15-crope@iki.fi> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170615033105.13517-1-crope@iki.fi> References: <20170615033105.13517-1-crope@iki.fi> X-SA-Exim-Connect-IP: 82.128.189.68 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-Virus-Scanned: ClamAV using ClamSMTP Move power-up and power-down functionality to init/sleep ops and get rid of old function. Fixes and simplifies power-up functionality slightly. Signed-off-by: Antti Palosaari --- drivers/media/dvb-frontends/af9013.c | 93 ++++++++++++++---------------------- 1 file changed, 36 insertions(+), 57 deletions(-) diff --git a/drivers/media/dvb-frontends/af9013.c b/drivers/media/dvb-frontends/af9013.c index 40fd2ea..128d915 100644 --- a/drivers/media/dvb-frontends/af9013.c +++ b/drivers/media/dvb-frontends/af9013.c @@ -101,59 +101,6 @@ static int af9013_set_gpio(struct af9013_state *state, u8 gpio, u8 gpioval) return ret; } -static int af9013_power_ctrl(struct af9013_state *state, u8 onoff) -{ - struct i2c_client *client = state->client; - int ret; - unsigned int utmp; - - dev_dbg(&client->dev, "onoff %d\n", onoff); - - /* enable reset */ - ret = regmap_update_bits(state->regmap, 0xd417, 0x10, 0x10); - if (ret) - goto err; - - /* start reset mechanism */ - ret = regmap_write(state->regmap, 0xaeff, 0x01); - if (ret) - goto err; - - /* wait reset performs */ - ret = regmap_read_poll_timeout(state->regmap, 0xd417, utmp, - (utmp >> 1) & 0x01, 5000, 1000000); - if (ret) - goto err; - - if (!((utmp >> 1) & 0x01)) - return -ETIMEDOUT; - - if (onoff) { - /* clear reset */ - ret = regmap_update_bits(state->regmap, 0xd417, 0x02, 0x00); - if (ret) - goto err; - /* disable reset */ - ret = regmap_update_bits(state->regmap, 0xd417, 0x10, 0x00); - if (ret) - goto err; - /* power on */ - ret = regmap_update_bits(state->regmap, 0xd73a, 0x08, 0x00); - if (ret) - goto err; - } else { - /* power off */ - ret = regmap_update_bits(state->regmap, 0xd73a, 0x08, 0x08); - if (ret) - goto err; - } - - return 0; -err: - dev_dbg(&client->dev, "failed %d\n", ret); - return ret; -} - static int af9013_statistics_ber_unc_start(struct dvb_frontend *fe) { struct af9013_state *state = fe->demodulator_priv; @@ -889,8 +836,18 @@ static int af9013_init(struct dvb_frontend *fe) dev_dbg(&client->dev, "\n"); - /* power on */ - ret = af9013_power_ctrl(state, 1); + /* ADC on */ + ret = regmap_update_bits(state->regmap, 0xd73a, 0x08, 0x00); + if (ret) + goto err; + + /* Clear reset */ + ret = regmap_update_bits(state->regmap, 0xd417, 0x02, 0x00); + if (ret) + goto err; + + /* Disable reset */ + ret = regmap_update_bits(state->regmap, 0xd417, 0x10, 0x00); if (ret) goto err; @@ -1070,6 +1027,7 @@ static int af9013_sleep(struct dvb_frontend *fe) struct af9013_state *state = fe->demodulator_priv; struct i2c_client *client = state->client; int ret; + unsigned int utmp; dev_dbg(&client->dev, "\n"); @@ -1081,8 +1039,29 @@ static int af9013_sleep(struct dvb_frontend *fe) if (ret) goto err; - /* power off */ - ret = af9013_power_ctrl(state, 0); + /* Enable reset */ + ret = regmap_update_bits(state->regmap, 0xd417, 0x10, 0x10); + if (ret) + goto err; + + /* Start reset execution */ + ret = regmap_write(state->regmap, 0xaeff, 0x01); + if (ret) + goto err; + + /* Wait reset performs */ + ret = regmap_read_poll_timeout(state->regmap, 0xd417, utmp, + (utmp >> 1) & 0x01, 5000, 1000000); + if (ret) + goto err; + + if (!((utmp >> 1) & 0x01)) { + ret = -ETIMEDOUT; + goto err; + } + + /* ADC off */ + ret = regmap_update_bits(state->regmap, 0xd73a, 0x08, 0x08); if (ret) goto err;