From patchwork Wed Dec 20 12:17:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 122464 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp5496157qgn; Wed, 20 Dec 2017 04:19:57 -0800 (PST) X-Google-Smtp-Source: ACJfBoteU5DE6mEyeu4hsCmLf4qhcfjRsy4WpexKH93C0Bk0Z9x4tFxqo6tKc6uF2TbXKwB6BmD/ X-Received: by 10.99.191.69 with SMTP id i5mr6149795pgo.13.1513772397201; Wed, 20 Dec 2017 04:19:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513772397; cv=none; d=google.com; s=arc-20160816; b=we46FOM7RxAZcoHmzQxGhnJKZejQCYT7sEEpEQY4uXGEvhC9qFN6741os5mptHZXOK EjCwavdUhZTmool1WgzmtHiuUu5FKrbwOh78aJMKd9U8I0YhhwkDwPaYPfoZjeeqIhQC A4brjBkiPd478J+OrixbuzMHWpeFDTJ+Qwa3wFYk6jUyrVSu1wz1wN7vvg1kC0R8ODu2 3H3edVmwYhTo7qvfyKAFqvCPsRjpbsVFcm8Jg2lIJn4LzhGZBsg4A1R4vTo1kEgGLSgD BgVuTWNNiHIYFA5pCuXdM107WbSw0hSAUEUh14PtZh+EdVqvYCDOAuFwKGKH0+yFVvvC r2wQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=QPwQZAW9LVXkFiiyvzfw+tTedBP5IOWQ+CZwABuXGCA=; b=kz4Pg6QnvqqkLIE61KGasrBUrBt6VyhtHXJgB/a3sFM6eBMh9BFBPtUtqSn9ETucAI P7jnusfajnoALY1IeL6fxCJEuaV++i0TZ7JRMP9P3fzw2Ok75hYSCPnRsqvp4H3UlE1i CwCUWkjmF0W+T/rrN79OlMUjG41vRlWe2sO/EemxB9WML4uMeJPia8iMAUEFq199Pxuv aK2yG5Qomg9+PnEKxnSuPlTGAzuohoCOTw2fH+8YxET8eNU83qRs0yUOxyi0iTzJ2PJh QwfmIohyRm2pKbyQELYhtnkno687fRx9e3QaxBd12BhuBUuvJnx9F/6L+W5rZQjhYlYe sbVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PyPtmUpb; spf=pass (google.com: best guess record for domain of linux-i2c-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-i2c-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v7si13292110plk.168.2017.12.20.04.19.57; Wed, 20 Dec 2017 04:19:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-i2c-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PyPtmUpb; spf=pass (google.com: best guess record for domain of linux-i2c-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-i2c-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755269AbdLTMT4 (ORCPT + 3 others); Wed, 20 Dec 2017 07:19:56 -0500 Received: from mail-lf0-f67.google.com ([209.85.215.67]:41890 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755002AbdLTMTz (ORCPT ); Wed, 20 Dec 2017 07:19:55 -0500 Received: by mail-lf0-f67.google.com with SMTP id f18so23766706lfg.8 for ; Wed, 20 Dec 2017 04:19:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=QPwQZAW9LVXkFiiyvzfw+tTedBP5IOWQ+CZwABuXGCA=; b=PyPtmUpb37gFm3AEEs6hyoz0boR05VYUIBcnSHmI8e0HZBfvXmlqjUlHuoMmY6gXUc CtHAskSvIZy3thZGPShXJYk11NpC2NDaA4rkMBVCc0cFHRjtQqqvxWCskx0EHyASe2Vg mDAP3AIerJFRyzde6zywlYznh7VbHIMIZHYII= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=QPwQZAW9LVXkFiiyvzfw+tTedBP5IOWQ+CZwABuXGCA=; b=ChBPAWAjxF/GkbbvqOMsaZL0wmRB9kJCAGjIaOI3hCv2rNyT+byV2eiiUZZYnpAtyo ji07cAZe2aTf84OSwwlUjrlmM3KthDWzACra3iDz+6TwP2tx1aAKue6cDFLjO9Zp+Gdj Gn7EG39RMooKy9m2KjNK+wHBvzT3NABmxy3ioBEYrcr4Mr7W9NmlclOqr51l4ncDXA+z oa8CmuqAS6E89EoFtDPI3LruxoY3l31Rq3/0qp6o541uSw+KYvN8xKDBkz9OwS4KqgWk AjEHu7AMKo1uXywJ7X7GylfJ664DaQBbmvQMX3Bc2xi7Xgu5EdFNUbNg+AExXpV+8Zvr kptg== X-Gm-Message-State: AKGB3mIBq5KuMMH/v3EVtxZo70XWwUa2UOhyOiKPCBv4NjEBcbn3E95p 7HLiXPLCFXoqkBi87Dt1fV6K/w== X-Received: by 10.46.22.82 with SMTP id 18mr4587883ljw.20.1513772394185; Wed, 20 Dec 2017 04:19:54 -0800 (PST) Received: from localhost.localdomain (c-cb7471d5.014-348-6c756e10.cust.bredbandsbolaget.se. [213.113.116.203]) by smtp.gmail.com with ESMTPSA id w29sm2859503lfc.30.2017.12.20.04.19.52 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Dec 2017 04:19:53 -0800 (PST) From: Linus Walleij To: Wolfram Sang , linux-i2c@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, Linus Walleij , arm@kernel.org, Kevin Hilman , Keerthy , Sekhar Nori Subject: [PATCH v2] i2c/ARM: davinci: Deep refactoring of I2C recovery Date: Wed, 20 Dec 2017 13:17:49 +0100 Message-Id: <20171220121749.12064-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.14.3 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Alter the DaVinci GPIO recovery fetch to use descriptors all the way down into the board files. Cc: arm@kernel.org Cc: Kevin Hilman Cc: Keerthy Cc: Sekhar Nori Acked-by: Sekhar Nori Tested-by: Sekhar Nori Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Change gpiochip name from gpio_davinci.0 to gpio_davinci, simply. --- arch/arm/mach-davinci/board-dm355-evm.c | 15 +++++++++++++-- arch/arm/mach-davinci/board-dm644x-evm.c | 15 +++++++++++++-- drivers/i2c/busses/i2c-davinci.c | 21 +++++++++++---------- include/linux/platform_data/i2c-davinci.h | 5 ++--- 4 files changed, 39 insertions(+), 17 deletions(-) -- 2.14.3 Acked-by: Arnd Bergmann diff --git a/arch/arm/mach-davinci/board-dm355-evm.c b/arch/arm/mach-davinci/board-dm355-evm.c index 62e7bc3018f0..e457f299cd44 100644 --- a/arch/arm/mach-davinci/board-dm355-evm.c +++ b/arch/arm/mach-davinci/board-dm355-evm.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -108,11 +109,20 @@ static struct platform_device davinci_nand_device = { }, }; +static struct gpiod_lookup_table i2c_recovery_gpiod_table = { + .dev_id = "i2c_davinci", + .table = { + GPIO_LOOKUP("davinci_gpio", 15, "sda", + GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), + GPIO_LOOKUP("davinci_gpio", 14, "scl", + GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), + }, +}; + static struct davinci_i2c_platform_data i2c_pdata = { .bus_freq = 400 /* kHz */, .bus_delay = 0 /* usec */, - .sda_pin = 15, - .scl_pin = 14, + .gpio_recovery = true, }; static int dm355evm_mmc_gpios = -EINVAL; @@ -141,6 +151,7 @@ static struct i2c_board_info dm355evm_i2c_info[] = { static void __init evm_init_i2c(void) { + gpiod_add_lookup_table(&i2c_recovery_gpiod_table); davinci_init_i2c(&i2c_pdata); gpio_request(5, "dm355evm_msp"); diff --git a/arch/arm/mach-davinci/board-dm644x-evm.c b/arch/arm/mach-davinci/board-dm644x-evm.c index b07c9b18d427..85e6fb33b1ee 100644 --- a/arch/arm/mach-davinci/board-dm644x-evm.c +++ b/arch/arm/mach-davinci/board-dm644x-evm.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -595,18 +596,28 @@ static struct i2c_board_info __initdata i2c_info[] = { }, }; +static struct gpiod_lookup_table i2c_recovery_gpiod_table = { + .dev_id = "i2c_davinci", + .table = { + GPIO_LOOKUP("davinci_gpio", 44, "sda", + GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), + GPIO_LOOKUP("davinci_gpio", 43, "scl", + GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), + }, +}; + /* The msp430 uses a slow bitbanged I2C implementation (ergo 20 KHz), * which requires 100 usec of idle bus after i2c writes sent to it. */ static struct davinci_i2c_platform_data i2c_pdata = { .bus_freq = 20 /* kHz */, .bus_delay = 100 /* usec */, - .sda_pin = 44, - .scl_pin = 43, + .gpio_recovery = true, }; static void __init evm_init_i2c(void) { + gpiod_add_lookup_table(&i2c_recovery_gpiod_table); davinci_init_i2c(&i2c_pdata); i2c_add_driver(&dm6446evm_msp_driver); i2c_register_board_info(1, i2c_info, ARRAY_SIZE(i2c_info)); diff --git a/drivers/i2c/busses/i2c-davinci.c b/drivers/i2c/busses/i2c-davinci.c index 2afb12a89eb3..cb24a3ffdfa2 100644 --- a/drivers/i2c/busses/i2c-davinci.c +++ b/drivers/i2c/busses/i2c-davinci.c @@ -33,7 +33,7 @@ #include #include #include -#include +#include #include #include #include @@ -869,19 +869,20 @@ static int davinci_i2c_probe(struct platform_device *pdev) if (dev->pdata->has_pfunc) adap->bus_recovery_info = &davinci_i2c_scl_recovery_info; - else if (dev->pdata->scl_pin) { + else if (dev->pdata->gpio_recovery) { rinfo = &davinci_i2c_gpio_recovery_info; adap->bus_recovery_info = rinfo; - r = gpio_request_one(dev->pdata->scl_pin, GPIOF_OPEN_DRAIN | - GPIOF_OUT_INIT_HIGH, "i2c-scl"); - if (r) + rinfo->scl_gpiod = devm_gpiod_get(&pdev->dev, "scl", + GPIOD_OUT_HIGH_OPEN_DRAIN); + if (IS_ERR(rinfo->scl_gpiod)) { + r = PTR_ERR(rinfo->scl_gpiod); goto err_unuse_clocks; - rinfo->scl_gpiod = gpio_to_desc(dev->pdata->scl_pin); - - r = gpio_request_one(dev->pdata->sda_pin, GPIOF_IN, "i2c-sda"); - if (r) + } + rinfo->sda_gpiod = devm_gpiod_get(&pdev->dev, "sda", GPIOD_IN); + if (IS_ERR(rinfo->sda_gpiod)) { + r = PTR_ERR(rinfo->sda_gpiod); goto err_unuse_clocks; - rinfo->sda_gpiod = gpio_to_desc(dev->pdata->scl_pin); + } } adap->nr = pdev->id; diff --git a/include/linux/platform_data/i2c-davinci.h b/include/linux/platform_data/i2c-davinci.h index 89fd34727a24..98967df07468 100644 --- a/include/linux/platform_data/i2c-davinci.h +++ b/include/linux/platform_data/i2c-davinci.h @@ -16,9 +16,8 @@ struct davinci_i2c_platform_data { unsigned int bus_freq; /* standard bus frequency (kHz) */ unsigned int bus_delay; /* post-transaction delay (usec) */ - unsigned int sda_pin; /* GPIO pin ID to use for SDA */ - unsigned int scl_pin; /* GPIO pin ID to use for SCL */ - bool has_pfunc; /*chip has a ICPFUNC register */ + bool gpio_recovery; /* Use GPIO recovery method */ + bool has_pfunc; /* Chip has a ICPFUNC register */ }; /* for board setup code */