From patchwork Fri Dec 8 13:31:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 121157 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp663343qgn; Fri, 8 Dec 2017 05:31:45 -0800 (PST) X-Google-Smtp-Source: AGs4zMYLfaeo0nHf78edqWVy5wMbvircBttAB9e9ybdOEGNVsO/3x9YWmFUTmtacgXL5zWzbmIZI X-Received: by 10.159.198.148 with SMTP id g20mr29965880plo.89.1512739905562; Fri, 08 Dec 2017 05:31:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512739905; cv=none; d=google.com; s=arc-20160816; b=NR6Y1x1MtylPWEhbl0J2bBUlb8RwMmQtbhdRUWansN2dYnB4zXKJwNVxI9P9YfBJJ9 YtET3Tv1BImJ0AiV3M2/us0IzkcxvlaU3hksjyw6AiWFAlybp+tJN9isSt66WyUc43U3 6kQYZTClUiJu/FadZQxAwDf6tdliICQyaQB/oC+MlRclibme1b4Y+IG2u4QjkQ1fDod1 QoXRilwzlb/JSIjJMltMPs3++Y9FhvoPAIh0fLsAHAz+/Y8aHkYok1uW841Ba1LHj8la ncfQpdhiaqKjU1NbDe+zOXPTAQ0K0aOZCkofO3DtWNtzJnMBSLa9M/vEv0CLiHP+4U+t 0vlw== 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=qlCHhS/g4KFX7Fw+VAX7XY7WzqLzqlndf7LsPFNitxE=; b=PR3U2DNYUAP2h2CL2X6FujvafsClif3lrK4Pj5JvvIjyJA/V7gmg943KeDX9hb4u9F xZ+5lQXTJyQh69M45ojA3QuPqXVK212OtCdqbF12TyI31+V+I1mrEwP+cO+6HKZ/NRgy v3LzkLe0KjdH3rh4FlM0n45MBPQkh7qnu8Sl4rPkjyb/1nnrGQvGDEhDD1Kyo5qrIFU3 NOlpeVKnbh/YNgfVoYdC08Tbak0IJisXMWtNy3xnqdz0eWG6vkv6tvZ5hCG66F0tM7Bt 6weentN8gh1vdIumgEV+TPZoW99Zp4oj5jx0bPoW/7T3ud6Iec2a2JVPdx/TzVDRTW5S H0CQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kGHUXhsO; 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 b23si5655243pge.247.2017.12.08.05.31.45; Fri, 08 Dec 2017 05:31:45 -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=kGHUXhsO; 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 S1752989AbdLHNbo (ORCPT + 3 others); Fri, 8 Dec 2017 08:31:44 -0500 Received: from mail-lf0-f67.google.com ([209.85.215.67]:34812 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752883AbdLHNbo (ORCPT ); Fri, 8 Dec 2017 08:31:44 -0500 Received: by mail-lf0-f67.google.com with SMTP id x20so11934626lff.1 for ; Fri, 08 Dec 2017 05:31:43 -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=qlCHhS/g4KFX7Fw+VAX7XY7WzqLzqlndf7LsPFNitxE=; b=kGHUXhsOrbFmXnL45j7iZ5ZH7qC6qf9Gfl/sbcjK2m3t5/xqaZPAtJTcnKkhGGHp84 qO8WxOX4OIypgPUERBxy6sKmosuWwOrJWH++QPj2dzkz3Ih3JYeh4QocGXISxohw6CrP TLxaxU1xmmDCUigOXBF6S3XtwYNNLIFsHB1lY= 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=qlCHhS/g4KFX7Fw+VAX7XY7WzqLzqlndf7LsPFNitxE=; b=Er0hshZHeLNVE0H1XzrEc3irYpIgjxyWm/RZcAQ4DF8cB/A3d/olH8bCz/9yCNjw2d JEIbJhjMuxj9cDVB6xujE/G0yKemUWCEFmo7JFw5/rjenkGzeK7ChRKPYaZ+V6syTmUz B40V9uhYKTTU4siA8kKtQfJrGcKpBH+suNzgJRNn7t2Xlhg4Mr2nQedBy7+ffgjsplms IXU6rKBvvoxBi4Ts/Y283fYpKUHKHjx1LOhE/we0pSnKR71Jc0bdANtYFWNMc3Kmu/9n EmB8yZhqLiWpBrLr5KZHT4izy8hs5KEkibCqg110xczmy0/NrJj5l0O1JYY9dY3oO+QV msVQ== X-Gm-Message-State: AJaThX6/7FuPAZ0p9+DqQfnSIeuEgoukSD1ryKS6nVRd0COCvv131ZOR s5sUGk4XTslIJaIHZYM42GIn1A== X-Received: by 10.46.29.151 with SMTP id w23mr15852620lje.66.1512739902538; Fri, 08 Dec 2017 05:31:42 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id x21sm1413909lfi.36.2017.12.08.05.31.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 08 Dec 2017 05:31:41 -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, Sekhar Nori , Kevin Hilman , Keerthy Subject: [PATCH] i2c/ARM: davinci: Deep refactoring of I2C recovery Date: Fri, 8 Dec 2017 14:31:32 +0100 Message-Id: <20171208133132.17099-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: Sekhar Nori Cc: Kevin Hilman Cc: Keerthy Signed-off-by: Linus Walleij --- It turns out someone else was busy doing the same thing I was doing. Trying to carry over the useful part with this patch! A Tested-by or ACK from a DaVinci maintainer would be appreciated, also an ACK from and ARM SoC maintainer. The patch can be easily tested by applying on top of linux-next. --- 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: Sekhar Nori diff --git a/arch/arm/mach-davinci/board-dm355-evm.c b/arch/arm/mach-davinci/board-dm355-evm.c index 62e7bc3018f0..60aec5437276 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.0", 15, "sda", + GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), + GPIO_LOOKUP("davinci_gpio.0", 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..2efc6dbc5ac0 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.0", 44, "sda", + GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), + GPIO_LOOKUP("davinci_gpio.0", 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 */