From patchwork Sat Feb 24 18:55:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scheller X-Patchwork-Id: 10240475 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 93DBA602A0 for ; Sat, 24 Feb 2018 18:56:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 881E929BE3 for ; Sat, 24 Feb 2018 18:56:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7CBCB29BFC; Sat, 24 Feb 2018 18:56:02 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, 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 1DAD829BE3 for ; Sat, 24 Feb 2018 18:56:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751531AbeBXS4A (ORCPT ); Sat, 24 Feb 2018 13:56:00 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:55173 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751480AbeBXSzr (ORCPT ); Sat, 24 Feb 2018 13:55:47 -0500 Received: by mail-wm0-f67.google.com with SMTP id z81so10441417wmb.4 for ; Sat, 24 Feb 2018 10:55:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=mwSt0UuXMqW/muw5W4kkwEmf+aYExwnlG8bFS0VLyIo=; b=M/nOMEajeUbxqUv6/CiYd9Qusybq0dXw+4Muo3KTKl2LRuMc8adsbeJoXd+3eCg8Fj GlsMx1rJJQPXG36TLszearpopdOZt49vNuh9WeT6jKfEm6yiVgMriFqx8e9LAltFsHgi 0W94LsJ1IFHYokspMu0IbF8n72pVu2JcVkW8EC+O8nsKMOX+3R8PJ3SynR9JUw3bxdpi oAcJ4Qyc+2UwU8jipWUtLdNMI8d6xEjAfL3jiFrkVgYeb1gsFnDeNNNHZ8zjyiPb3cvU AozOzbKehMWiygI8bbrKa4lYmn5OAXiJO79lw446CuQrSbHBgTTW6AizyAh6q/c5q35+ CV9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=mwSt0UuXMqW/muw5W4kkwEmf+aYExwnlG8bFS0VLyIo=; b=j634ebF3enk3SOv8+Ine82lj4UJocesoK/LVMNDnav/ArJKWWHtBTyEsnLGreGUaxP Dq+CRq0QelCKwptZMpvMm3TbZpDua3TN2Argz/Em6C2lPMNkDAYb5NwOOdlPDncrOJxO DvZMpoS8dtU5QAz1klmbVHDcq5mOSUw9x4D9CPZVbJ23SrDQJujHmNBvflA3PTCYYp1U nFSbF7oc4NbRs1Vk52S0ynfV3HW8SKoo5XPGCZjFoKaVQb5pbsHgEy5NgGbUK9Lb7e8p 4z+0+qtpA33B4T1cw2BJMCU4PpfiP8D8Wnfr8KrGR+W18MbVcRKCHvRyFt1iMbBBLeRO V+IQ== X-Gm-Message-State: APf1xPDjV9NxXGSsKPpVL7r/THgopEiIrLAYM9GC+8ZqocsE0L6E5szm N6kywf3JYNiRYri1y9mg3Tmz+A== X-Google-Smtp-Source: AH8x226Fc1Y0j6EVwLIMRAjW7jTU549JzdGOOwEZm7K2VtuIULNZhWI6ZpqxCH50X2MAmfYra/0dew== X-Received: by 10.28.48.85 with SMTP id w82mr4600800wmw.95.1519498545615; Sat, 24 Feb 2018 10:55:45 -0800 (PST) Received: from dvbdev.wuest.de (ip-84-118-193-200.unity-media.net. [84.118.193.200]) by smtp.gmail.com with ESMTPSA id 3sm526270wry.29.2018.02.24.10.55.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 24 Feb 2018 10:55:45 -0800 (PST) From: Daniel Scheller To: linux-media@vger.kernel.org, mchehab@kernel.org, mchehab@s-opensource.com Subject: [PATCH 09/12] [media] ngene: check for CXD2099AR presence before attaching Date: Sat, 24 Feb 2018 19:55:31 +0100 Message-Id: <20180224185534.13792-10-d.scheller.oss@gmail.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180224185534.13792-1-d.scheller.oss@gmail.com> References: <20180224185534.13792-1-d.scheller.oss@gmail.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 From: Daniel Scheller Currently, if there's no CXD2099AR attached to any expansion connector of the ngene hardware, it will complain with this on every module load: cxd2099 1-0040: No CXD2099AR detected at 0x40 cxd2099: probe of 1-0040 failed with error -5 ngene 0000:02:00.0: CXD2099AR attach failed This happens due to the logic assuming such hardware is always there and blindly tries to attach the cxd2099 I2C driver. Rather add a probe function (in ngene-cards.c with a prototype in ngene.h) to check for the existence of such hardware before probing, and don't try further if no CXD2099 was found. Signed-off-by: Daniel Scheller --- drivers/media/pci/ngene/ngene-cards.c | 19 +++++++++++++++++++ drivers/media/pci/ngene/ngene-core.c | 14 ++++++++++++++ drivers/media/pci/ngene/ngene.h | 3 +++ 3 files changed, 36 insertions(+) diff --git a/drivers/media/pci/ngene/ngene-cards.c b/drivers/media/pci/ngene/ngene-cards.c index dff55c7c9f86..d603d0af703e 100644 --- a/drivers/media/pci/ngene/ngene-cards.c +++ b/drivers/media/pci/ngene/ngene-cards.c @@ -505,6 +505,25 @@ static int port_has_stv0367(struct i2c_adapter *i2c) return 1; } +int ngene_port_has_cxd2099(struct i2c_adapter *i2c, u8 *type) +{ + u8 val; + u8 probe[4] = { 0xe0, 0x00, 0x00, 0x00 }, data[4]; + struct i2c_msg msgs[2] = {{ .addr = 0x40, .flags = 0, + .buf = probe, .len = 4 }, + { .addr = 0x40, .flags = I2C_M_RD, + .buf = data, .len = 4 } }; + val = i2c_transfer(i2c, msgs, 2); + if (val != 2) + return 0; + + if (data[0] == 0x02 && data[1] == 0x2b && data[3] == 0x43) + *type = 2; + else + *type = 1; + return 1; +} + static int demod_attach_drxk(struct ngene_channel *chan, struct i2c_adapter *i2c) { diff --git a/drivers/media/pci/ngene/ngene-core.c b/drivers/media/pci/ngene/ngene-core.c index 526d0adfa427..f69a8fc1ec2a 100644 --- a/drivers/media/pci/ngene/ngene-core.c +++ b/drivers/media/pci/ngene/ngene-core.c @@ -1589,6 +1589,20 @@ static void cxd_attach(struct ngene *dev) .addr = 0x40, .platform_data = &cxd_cfg, }; + int ret; + u8 type; + + /* check for CXD2099AR presence before attaching */ + ret = ngene_port_has_cxd2099(&dev->channel[0].i2c_adapter, &type); + if (!ret) { + dev_dbg(pdev, "No CXD2099AR found\n"); + return; + } + + if (type != 1) { + dev_warn(pdev, "CXD2099AR is uninitialized!\n"); + return; + } cxd_cfg.en = &ci->en; diff --git a/drivers/media/pci/ngene/ngene.h b/drivers/media/pci/ngene/ngene.h index 72195f6552b3..66d8eaa28549 100644 --- a/drivers/media/pci/ngene/ngene.h +++ b/drivers/media/pci/ngene/ngene.h @@ -909,6 +909,9 @@ int ngene_command_gpio_set(struct ngene *dev, u8 select, u8 level); void set_transfer(struct ngene_channel *chan, int state); void FillTSBuffer(void *Buffer, int Length, u32 Flags); +/* Provided by ngene-cards.c */ +int ngene_port_has_cxd2099(struct i2c_adapter *i2c, u8 *type); + /* Provided by ngene-i2c.c */ int ngene_i2c_init(struct ngene *dev, int dev_nr);