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: 846223 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="kGHUXhsO"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ytYD22ZZXz9ryv for ; Sat, 9 Dec 2017 00:31:46 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752989AbdLHNbo (ORCPT ); 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-Google-Smtp-Source: AGs4zMaortVMzE1QFuAREWVA3hwrSYeBBQkOKIbIOuQex6NeJIz0qYMWsho2qaBj49qOF5ynlL9Kdg== 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 Acked-by: Sekhar Nori --- 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(-) 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 */