From patchwork Wed Dec 20 09:51:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugues FRUCHET X-Patchwork-Id: 10125357 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 AE0186019C for ; Wed, 20 Dec 2017 09:51:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF3EB2961D for ; Wed, 20 Dec 2017 09:51:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B3F29296A0; Wed, 20 Dec 2017 09:51:58 +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,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 2B7152961D for ; Wed, 20 Dec 2017 09:51:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754694AbdLTJvw (ORCPT ); Wed, 20 Dec 2017 04:51:52 -0500 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:16596 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754290AbdLTJvo (ORCPT ); Wed, 20 Dec 2017 04:51:44 -0500 Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx08-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vBK9nJ0l012221; Wed, 20 Dec 2017 10:51:29 +0100 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-00178001.pphosted.com with ESMTP id 2evsg90cb8-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Wed, 20 Dec 2017 10:51:29 +0100 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 50D3734; Wed, 20 Dec 2017 09:51:28 +0000 (GMT) Received: from Webmail-eu.st.com (Safex1hubcas24.st.com [10.75.90.94]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 2DEA225AC; Wed, 20 Dec 2017 09:51:28 +0000 (GMT) Received: from SAFEX1HUBCAS22.st.com (10.75.90.92) by Safex1hubcas24.st.com (10.75.90.94) with Microsoft SMTP Server (TLS) id 14.3.352.0; Wed, 20 Dec 2017 10:51:28 +0100 Received: from localhost (10.201.23.73) by Webmail-ga.st.com (10.75.90.48) with Microsoft SMTP Server (TLS) id 14.3.352.0; Wed, 20 Dec 2017 10:51:27 +0100 From: Hugues Fruchet To: Steve Longerbeam , Sakari Ailus , Hans Verkuil , "Mauro Carvalho Chehab" , Rob Herring , Mark Rutland CC: , Hugues Fruchet , Benjamin Gaignard Subject: [PATCH v4 2/5] media: ov5640: check chip id Date: Wed, 20 Dec 2017 10:51:11 +0100 Message-ID: <1513763474-1174-3-git-send-email-hugues.fruchet@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1513763474-1174-1-git-send-email-hugues.fruchet@st.com> References: <1513763474-1174-1-git-send-email-hugues.fruchet@st.com> MIME-Version: 1.0 X-Originating-IP: [10.201.23.73] X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-12-20_05:, , signatures=0 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 Verify that chip identifier is correct when probing. Signed-off-by: Hugues Fruchet --- drivers/media/i2c/ov5640.c | 95 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 79 insertions(+), 16 deletions(-) diff --git a/drivers/media/i2c/ov5640.c b/drivers/media/i2c/ov5640.c index 61071f5..9f031f3 100644 --- a/drivers/media/i2c/ov5640.c +++ b/drivers/media/i2c/ov5640.c @@ -1547,24 +1547,58 @@ static void ov5640_reset(struct ov5640_dev *sensor) usleep_range(5000, 10000); } -static int ov5640_set_power(struct ov5640_dev *sensor, bool on) +static int ov5640_set_power_on(struct ov5640_dev *sensor) { - int ret = 0; + struct i2c_client *client = sensor->i2c_client; + int ret; - if (on) { - clk_prepare_enable(sensor->xclk); + ret = clk_prepare_enable(sensor->xclk); + if (ret) { + dev_err(&client->dev, "%s: failed to enable clock\n", + __func__); + return ret; + } - ret = regulator_bulk_enable(OV5640_NUM_SUPPLIES, - sensor->supplies); - if (ret) - goto xclk_off; + ret = regulator_bulk_enable(OV5640_NUM_SUPPLIES, + sensor->supplies); + if (ret) { + dev_err(&client->dev, "%s: failed to enable regulators\n", + __func__); + goto xclk_off; + } + + ov5640_reset(sensor); + ov5640_power(sensor, true); + + ret = ov5640_init_slave_id(sensor); + if (ret) + goto power_off; + + return 0; + +power_off: + ov5640_power(sensor, false); + regulator_bulk_disable(OV5640_NUM_SUPPLIES, sensor->supplies); +xclk_off: + clk_disable_unprepare(sensor->xclk); + return ret; +} + +static void ov5640_set_power_off(struct ov5640_dev *sensor) +{ + ov5640_power(sensor, false); + regulator_bulk_disable(OV5640_NUM_SUPPLIES, sensor->supplies); + clk_disable_unprepare(sensor->xclk); +} - ov5640_reset(sensor); - ov5640_power(sensor, true); +static int ov5640_set_power(struct ov5640_dev *sensor, bool on) +{ + int ret = 0; - ret = ov5640_init_slave_id(sensor); + if (on) { + ret = ov5640_set_power_on(sensor); if (ret) - goto power_off; + return ret; ret = ov5640_restore_mode(sensor); if (ret) @@ -1586,10 +1620,7 @@ static int ov5640_set_power(struct ov5640_dev *sensor, bool on) } power_off: - ov5640_power(sensor, false); - regulator_bulk_disable(OV5640_NUM_SUPPLIES, sensor->supplies); -xclk_off: - clk_disable_unprepare(sensor->xclk); + ov5640_set_power_off(sensor); return ret; } @@ -2202,6 +2233,34 @@ static int ov5640_get_regulators(struct ov5640_dev *sensor) sensor->supplies); } +static int ov5640_check_chip_id(struct ov5640_dev *sensor) +{ + struct i2c_client *client = sensor->i2c_client; + int ret = 0; + u16 chip_id; + + ret = ov5640_set_power_on(sensor); + if (ret) + return ret; + + ret = ov5640_read_reg16(sensor, OV5640_REG_CHIP_ID, &chip_id); + if (ret) { + dev_err(&client->dev, "%s: failed to read chip identifier\n", + __func__); + goto power_off; + } + + if (chip_id != 0x5640) { + dev_err(&client->dev, "%s: wrong chip identifier, expected 0x5640, got 0x%x\n", + __func__, chip_id); + ret = -ENXIO; + } + +power_off: + ov5640_set_power_off(sensor); + return ret; +} + static int ov5640_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -2284,6 +2343,10 @@ static int ov5640_probe(struct i2c_client *client, mutex_init(&sensor->lock); + ret = ov5640_check_chip_id(sensor); + if (ret) + goto entity_cleanup; + ret = ov5640_init_controls(sensor); if (ret) goto entity_cleanup;