From patchwork Fri Nov 18 07:46:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mika Kahola X-Patchwork-Id: 9435911 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 3FAF960238 for ; Fri, 18 Nov 2016 07:50:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 33D06297ED for ; Fri, 18 Nov 2016 07:50:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 27CDF29801; Fri, 18 Nov 2016 07:50:33 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C3FB1297ED for ; Fri, 18 Nov 2016 07:50:32 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4EE876E907; Fri, 18 Nov 2016 07:50:31 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by gabe.freedesktop.org (Postfix) with ESMTPS id AC62E6E907 for ; Fri, 18 Nov 2016 07:50:28 +0000 (UTC) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga101.fm.intel.com with ESMTP; 17 Nov 2016 23:50:28 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,655,1473145200"; d="scan'208";a="5963330" Received: from sorvi.fi.intel.com ([10.237.72.109]) by orsmga002.jf.intel.com with ESMTP; 17 Nov 2016 23:50:27 -0800 From: Mika Kahola To: intel-gfx@lists.freedesktop.org Date: Fri, 18 Nov 2016 09:46:40 +0200 Message-Id: <1479455201-27917-3-git-send-email-mika.kahola@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1479455201-27917-1-git-send-email-mika.kahola@intel.com> References: <1479455201-27917-1-git-send-email-mika.kahola@intel.com> MIME-Version: 1.0 Cc: Jani Nikula , Deepak M Subject: [Intel-gfx] [PATCH CI run 2/3] drm/i915: Get the i2c bus number from the ACPI X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP Currently for executing the i2c MIPI sequence, we are relaying on the i2c bus bunmber which is specified in the VBT. But there are cases where different Fab versions of the board will drive the same chip with different i2c port, in which case the i2c bus number from the VBT cant be relied on. To overcome this the i2c bus number is read from the BIOS acpi table; BIOS can detect the Fab version in runtime and will store the correct i2c bus number in the ACPI table. v2 by Deepak: - Reading the i2c from the ACPI and storing them in list v3 by Mika: - rebase Cc: Jani Nikula Cc: Ville Syrjälä Signed-off-by: Deepak M Signed-off-by: Mika Kahola --- drivers/gpu/drm/i915/i915_drv.c | 2 ++ drivers/gpu/drm/i915/i915_drv.h | 10 +++++++ drivers/gpu/drm/i915/intel_acpi.c | 59 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+) diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c index 4f0e56d..563756e 100644 --- a/drivers/gpu/drm/i915/i915_drv.c +++ b/drivers/gpu/drm/i915/i915_drv.c @@ -580,6 +580,8 @@ static int i915_load_modeset_init(struct drm_device *dev) intel_register_dsm_handler(); + intel_acpi_find_i2c(dev_priv); + ret = vga_switcheroo_register_client(pdev, &i915_switcheroo_ops, false); if (ret) goto cleanup_vga_client; diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index 006914c..0a6ad9f 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -33,6 +33,7 @@ #include #include +#include #include #include #include @@ -1778,6 +1779,12 @@ struct intel_wm_config { bool sprites_scaled; }; +struct acpi_i2c_data_node { + struct list_head head; + int i2c_bus_number; + int i2c_slave_address; +}; + struct drm_i915_private { struct drm_device drm; @@ -1870,6 +1877,8 @@ struct drm_i915_private { /* backlight registers and fields in struct intel_panel */ struct mutex backlight_lock; + struct list_head acpi_i2c_list; + /* LVDS info */ bool no_aux_handshake; @@ -3444,6 +3453,7 @@ static inline int intel_opregion_get_panel_type(struct drm_i915_private *dev) #ifdef CONFIG_ACPI extern void intel_register_dsm_handler(void); extern void intel_unregister_dsm_handler(void); +extern acpi_status intel_acpi_find_i2c(struct drm_i915_private *dev_priv); #else static inline void intel_register_dsm_handler(void) { return; } static inline void intel_unregister_dsm_handler(void) { return; } diff --git a/drivers/gpu/drm/i915/intel_acpi.c b/drivers/gpu/drm/i915/intel_acpi.c index eb638a1..1b18c89 100644 --- a/drivers/gpu/drm/i915/intel_acpi.c +++ b/drivers/gpu/drm/i915/intel_acpi.c @@ -110,6 +110,65 @@ static void intel_dsm_platform_mux_info(void) ACPI_FREE(pkg); } +static int i2c_acpi_get_name(struct acpi_resource *ares, void *data) +{ + struct drm_i915_private *dev_priv = data; + struct acpi_resource_i2c_serialbus *sb; + unsigned int val; + char *resource; + int error; + + + if (ares->type == ACPI_RESOURCE_TYPE_SERIAL_BUS) { + sb = &ares->data.i2c_serial_bus; + + if (sb->type == ACPI_RESOURCE_SERIAL_TYPE_I2C) { + struct acpi_i2c_data_node *i2c_entry = NULL; + + resource = sb->resource_source.string_ptr; + resource = strstr(resource, "I2C"); + error = kstrtouint(resource+3, 0, &val); + if (error) + return error; + + i2c_entry = kzalloc(sizeof(struct acpi_i2c_data_node), + GFP_NOWAIT); + i2c_entry->i2c_bus_number = val; + i2c_entry->i2c_slave_address = sb->slave_address; + + list_add_tail(&i2c_entry->head, + &dev_priv->acpi_i2c_list); + } + } + + return 1; +} + +acpi_status intel_acpi_find_i2c(struct drm_i915_private *dev_priv) +{ + struct pci_dev *pdev = dev_priv->drm.pdev; + struct list_head resource_list; + struct acpi_device *adev; + acpi_handle dhandle; + + dhandle = ACPI_HANDLE(&pdev->dev); + if (!dhandle) + return false; + + if (acpi_bus_get_device(dhandle, &adev)) + return AE_OK; + if (acpi_bus_get_status(adev) || !adev->status.present) + return AE_OK; + + INIT_LIST_HEAD(&resource_list); + INIT_LIST_HEAD(&dev_priv->acpi_i2c_list); + acpi_dev_get_resources(adev, &resource_list, + i2c_acpi_get_name, dev_priv); + acpi_dev_free_resource_list(&resource_list); + + return AE_OK; +} + static bool intel_dsm_pci_probe(struct pci_dev *pdev) { acpi_handle dhandle;