From patchwork Fri Nov 18 07:46:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mika Kahola X-Patchwork-Id: 9435913 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 7028260238 for ; Fri, 18 Nov 2016 07:50:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 64E08297ED for ; Fri, 18 Nov 2016 07:50:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 59BB229801; Fri, 18 Nov 2016 07:50:36 +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 0DFDC297ED for ; Fri, 18 Nov 2016 07:50:36 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 886726E90B; Fri, 18 Nov 2016 07:50:34 +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 7DCA96E907 for ; Fri, 18 Nov 2016 07:50:30 +0000 (UTC) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga101.fm.intel.com with ESMTP; 17 Nov 2016 23:50:30 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,655,1473145200"; d="scan'208";a="5963337" Received: from sorvi.fi.intel.com ([10.237.72.109]) by orsmga002.jf.intel.com with ESMTP; 17 Nov 2016 23:50:28 -0800 From: Mika Kahola To: intel-gfx@lists.freedesktop.org Date: Fri, 18 Nov 2016 09:46:41 +0200 Message-Id: <1479455201-27917-4-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: Deepak M , Jani Nikula , vkorjani Subject: [Intel-gfx] [PATCH CI run 3/3] drm/i915: Adding the parsing logic for the i2c element 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 New sequence element for i2c is been added in the mipi sequence block of the VBT. This patch parses and executes the i2c sequence. v2: Add i2c_put_adapter call(Jani), rebase v3: corrected the retry loop(Jani), rebase v4 by Jani: - don't put the adapter if get fails - print an error message if all retries exhausted - use a for loop - fix warnings for unused variables v5 by Jani: - rebase on the skip i2c element patch v6: by Jani: - ignore the gmbus i2c elements (Ville) v7: by Deepak - Use the i2c port number which is read from ACPI based on the resource id. v8: by Mika - rebase Cc: Ville Syrjälä Signed-off-by: vkorjani Signed-off-by: Deepak M Signed-off-by: Jani Nikula Signed-off-by: Mika Kahola --- drivers/gpu/drm/i915/intel_dsi_panel_vbt.c | 78 +++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/i915/intel_dsi_panel_vbt.c b/drivers/gpu/drm/i915/intel_dsi_panel_vbt.c index a4cbe68..7fe57c2 100644 --- a/drivers/gpu/drm/i915/intel_dsi_panel_vbt.c +++ b/drivers/gpu/drm/i915/intel_dsi_panel_vbt.c @@ -1004,9 +1004,83 @@ static const u8 *mipi_exec_gpio(struct intel_dsi *intel_dsi, const u8 *data) static const u8 *mipi_exec_i2c(struct intel_dsi *intel_dsi, const u8 *data) { - DRM_DEBUG_KMS("Skipping I2C element execution\n"); + struct drm_i915_private *dev_priv = intel_dsi->base.base.dev->dev_private; + struct i2c_adapter *adapter; + int ret, i; + u8 reg_offset, payload_size; + struct i2c_msg msg; + struct acpi_i2c_data_node *i2c_entry = NULL; + u8 *transmit_buffer; + u8 flag, resource_id, bus_number; + u16 slave_add; + u8 count = 0; + + flag = *data++; + resource_id = *data++; + bus_number = *data++; + slave_add = *(u16 *)(data); + data += 2; + reg_offset = *data++; + payload_size = *data++; + + if (resource_id == 0xff || bus_number == 0xff) { + DRM_DEBUG_KMS("ignoring gmbus (resource id %02x, bus %02x)\n", + resource_id, bus_number); + goto out; + } + + /* Parse the list and get the required i2c bus number */ + list_for_each_entry(i2c_entry, &dev_priv->acpi_i2c_list, + head) { + if (count == resource_id) { + /* override the busnumber */ + bus_number = i2c_entry->i2c_bus_number; + break; + } + count++; + } + + /* + * Since the i2c bus number indexing in BIOS starts from 1 + * decrementing the bus number which we are reading. + */ + bus_number--; - return data + *(data + 6) + 7; + adapter = i2c_get_adapter(bus_number); + if (!adapter) { + DRM_ERROR("i2c_get_adapter(%u)\n", bus_number); + goto out; + } + + transmit_buffer = kmalloc(1 + payload_size, GFP_TEMPORARY); + if (!transmit_buffer) + goto out_put; + + transmit_buffer[0] = reg_offset; + memcpy(&transmit_buffer[1], data, payload_size); + + msg.addr = slave_add; + msg.flags = 0; + msg.len = payload_size + 1; + msg.buf = &transmit_buffer[0]; + + for (i = 0; i < 6; i++) { + ret = i2c_transfer(adapter, &msg, 1); + if (ret == 1) + goto out_free; + else if (ret == -EAGAIN) + usleep_range(1000, 2500); + else + break; + } + + DRM_ERROR("i2c transfer failed: %d\n", ret); +out_free: + kfree(transmit_buffer); +out_put: + i2c_put_adapter(adapter); +out: + return data + payload_size; } static const u8 *mipi_exec_spi(struct intel_dsi *intel_dsi, const u8 *data)