From patchwork Wed Feb 6 07:16:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 157583 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp6090528jaa; Tue, 5 Feb 2019 23:19:00 -0800 (PST) X-Google-Smtp-Source: AHgI3IYSJ3KO+wjmVcfnsEmqhvNUCcmxeCfggkyNlcBgYnvnbKlnJzwOvjwm7QTOkH2/N1rzS6qh X-Received: by 2002:a63:5207:: with SMTP id g7mr8404184pgb.253.1549437540504; Tue, 05 Feb 2019 23:19:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549437540; cv=none; d=google.com; s=arc-20160816; b=hqtiWcWqpBYlKsd9RhfoDl8oqWp2DIHa35ZAuWKciLG6XKhsirly3cZK7IODZ1SiiJ D9hPAfDSr7H8nrkhpflmIpz2LGZGqehpXpogwSiY1oxn1j9SgR8qVz1JaLh3UwvQxF6Q 1DVTEgQO8tB2+OtaxRu1A+aPp8FkyJsVtpTOPZO04YWbmRNMXUsYZO3wPCcDCUtiX1Y9 cmBJrpgzArgZAMcCWkekHu5/a+3v7g0ZtAzhqp6kN1RuQxAucxrlCzDKLtIzPaLV96XW RbALwofDhdy/M1R/aLk6bVA4+cMC1PlK80BStTBAXBJpVh5OTZu+8uBiTf9JKGLRdGs/ sFLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=HbkHzGeHpcRXvJZLaAidJBCbkUs+JxxFQJ8nsjBjusQ=; b=IU6wDyhJIO7DTg1TLTHpoAmY9jWV2b3sGjZEKRuiUgEkWsAgozMtbEtpcHTRScrN3X iJwcqRMqhOWQcxAHglF5P1Ux64cty/MwzUhpDZK2KyHX5GCY4WmTbtSI0J4exd17ZGPA 7iiUF71SLRhDdqcSVvFAl+AeZ6b1Wy+XTVdVuhTV4AQBZDBpRpj+GzYyOaJnKhSUopPZ 2WAk90mcgh2DgeWLLq1A+Oi+6cjmYF06fhvMhO6x2M4YsLgm4FprFAOXRw+nRb+stAQO qK3xYF6SxAHgrm4l+5Mq9dLaYZxw6WZfm07Fd08tnBMtHhooEEIV7n36mFvKCQwHgw6j +Hyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PccQ0Caf; spf=pass (google.com: best guess record for domain of linux-omap-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-omap-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 2si42007pgj.104.2019.02.05.23.19.00; Tue, 05 Feb 2019 23:19:00 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-omap-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=PccQ0Caf; spf=pass (google.com: best guess record for domain of linux-omap-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-omap-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 S1726804AbfBFHS7 (ORCPT + 5 others); Wed, 6 Feb 2019 02:18:59 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:39871 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725897AbfBFHS7 (ORCPT ); Wed, 6 Feb 2019 02:18:59 -0500 Received: by mail-lj1-f193.google.com with SMTP id t9-v6so5104068ljh.6 for ; Tue, 05 Feb 2019 23:18:57 -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:mime-version :content-transfer-encoding; bh=HbkHzGeHpcRXvJZLaAidJBCbkUs+JxxFQJ8nsjBjusQ=; b=PccQ0CafORXhFDfuP+94XMco/TUinkFdv1disC+A3I03nCZknafhKmKNb6GEuJkVSS QIhKLfyfkKf5oLiBEn7BDu2Qob0hmaQKlLCYeDxMuvkJCOqFx3+go1FWDDKsHelnThvj teOsQgAWUaqSwkyiCPtB85aRDNLFKpbJJEBsJ0QLYkxTeLHrEMjLf99KDnThxito+Nv9 gsNZ7W6+RQeCGN+Q9fKx77UZmBVqem59cpIMRX3DXpY/1+rWG7W+XGFdV4/Lxq3Lt/Y1 kKXK0joBD0P23PS54/cQbZWWZM6fSFfMRzAdmni70qNCcb4Ow8UTv101KMb9l6FwS93E FoUw== 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:mime-version :content-transfer-encoding; bh=HbkHzGeHpcRXvJZLaAidJBCbkUs+JxxFQJ8nsjBjusQ=; b=oAOBU9dxnAOpHTRXWMSF8v4HM2On8Id40Ugalat7SChgDGF+tXh0BP0iLl2RNM49d0 EVWohsbRVBGIVmySBP/NWbwxFN8gbHTY+GZoh1pzIz4xpfHxtxXFlDgDXPhgAG0IuWp/ 6YAMFSRduyFVmaGPftiIREzflU0Ab2ac2lgx/kH/jygTwUq33SUIGOgA5vN94eSJsrfY pmQP6EjDkzlPrtgYyDskT4NlfXCuU9c4zG4vqSgcwMWTt7zTb01DFuvLhwUt5gx3QZVP ZkxDvdQ9aXfYylWJyqCeNj+t7DwASTQxeWk9Q7MrVx5/W5Z6Db9Q8DL+D1jbGL6VmrAL FjPQ== X-Gm-Message-State: AHQUAuY7oFvQoofw38LtZZ7JFxy/FTZhM7P8FuQQBoi/S6S/aoJlO3PJ +VnQTQtNoj3lxoO/xhNx97T8tRScxTo= X-Received: by 2002:a2e:7e04:: with SMTP id z4-v6mr5673617ljc.97.1549437536273; Tue, 05 Feb 2019 23:18:56 -0800 (PST) Received: from localhost.localdomain (c-ae7b71d5.014-348-6c756e10.bbcust.telenor.se. [213.113.123.174]) by smtp.gmail.com with ESMTPSA id l21-v6sm3600290lji.6.2019.02.05.23.18.54 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Feb 2019 23:18:55 -0800 (PST) From: Linus Walleij To: Wolfram Sang , linux-i2c@vger.kernel.org Cc: Linus Walleij , linux-omap@vger.kernel.org, Tony Lindgren , Aaro Koskinen Subject: [PATCH v2] i2c: cbus-gpio: Switch to use GPIO descriptors Date: Wed, 6 Feb 2019 08:16:51 +0100 Message-Id: <20190206071651.11644-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org This augments the CBUS GPIO I2C driver to use GPIO descriptors for clock, sel and data. We drop the platform data that was only used for carrying GPIO numbers and use machine descriptor tables instead. Cc: linux-omap@vger.kernel.org Cc: Tony Lindgren Cc: Aaro Koskinen Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Add .dev_id to the machine descriptor table so we can actually find the right device. - Look up GPIOs from the boardfile using proper index instead of by name as first assumed. - Name the dat line "CSGPIO dat" --- arch/arm/mach-omap1/board-nokia770.c | 18 ++--- drivers/i2c/busses/i2c-cbus-gpio.c | 80 ++++++++------------- include/linux/platform_data/i2c-cbus-gpio.h | 27 ------- 3 files changed, 40 insertions(+), 85 deletions(-) delete mode 100644 include/linux/platform_data/i2c-cbus-gpio.h -- 2.20.1 diff --git a/arch/arm/mach-omap1/board-nokia770.c b/arch/arm/mach-omap1/board-nokia770.c index eb41db78cd47..10848f573d37 100644 --- a/arch/arm/mach-omap1/board-nokia770.c +++ b/arch/arm/mach-omap1/board-nokia770.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -25,7 +26,6 @@ #include #include #include -#include #include #include @@ -217,18 +217,19 @@ static inline void nokia770_mmc_init(void) #endif #if IS_ENABLED(CONFIG_I2C_CBUS_GPIO) -static struct i2c_cbus_platform_data nokia770_cbus_data = { - .clk_gpio = OMAP_MPUIO(9), - .dat_gpio = OMAP_MPUIO(10), - .sel_gpio = OMAP_MPUIO(11), +static struct gpiod_lookup_table nokia770_cbus_gpio_table = { + .dev_id = "i2c-cbus-gpio.2", + .table = { + GPIO_LOOKUP_IDX("mpuio", 9, NULL, 0, 0), /* clk */ + GPIO_LOOKUP_IDX("mpuio", 10, NULL, 1, 0), /* dat */ + GPIO_LOOKUP_IDX("mpuio", 11, NULL, 2, 0), /* sel */ + { }, + }, }; static struct platform_device nokia770_cbus_device = { .name = "i2c-cbus-gpio", .id = 2, - .dev = { - .platform_data = &nokia770_cbus_data, - }, }; static struct i2c_board_info nokia770_i2c_board_info_2[] __initdata = { @@ -257,6 +258,7 @@ static void __init nokia770_cbus_init(void) nokia770_i2c_board_info_2[1].irq = gpio_to_irq(tahvo_irq_gpio); i2c_register_board_info(2, nokia770_i2c_board_info_2, ARRAY_SIZE(nokia770_i2c_board_info_2)); + gpiod_add_lookup_table(&nokia770_cbus_gpio_table); platform_device_register(&nokia770_cbus_device); } #else /* CONFIG_I2C_CBUS_GPIO */ diff --git a/drivers/i2c/busses/i2c-cbus-gpio.c b/drivers/i2c/busses/i2c-cbus-gpio.c index b4f91e48948a..72df563477b1 100644 --- a/drivers/i2c/busses/i2c-cbus-gpio.c +++ b/drivers/i2c/busses/i2c-cbus-gpio.c @@ -18,16 +18,14 @@ #include #include -#include #include #include #include #include #include -#include +#include #include #include -#include /* * Bit counts are derived from Nokia implementation. These should be checked @@ -39,9 +37,9 @@ struct cbus_host { spinlock_t lock; /* host lock */ struct device *dev; - int clk_gpio; - int dat_gpio; - int sel_gpio; + struct gpio_desc *clk; + struct gpio_desc *dat; + struct gpio_desc *sel; }; /** @@ -51,9 +49,9 @@ struct cbus_host { */ static void cbus_send_bit(struct cbus_host *host, unsigned bit) { - gpio_set_value(host->dat_gpio, bit ? 1 : 0); - gpio_set_value(host->clk_gpio, 1); - gpio_set_value(host->clk_gpio, 0); + gpiod_set_value(host->dat, bit ? 1 : 0); + gpiod_set_value(host->clk, 1); + gpiod_set_value(host->clk, 0); } /** @@ -78,9 +76,9 @@ static int cbus_receive_bit(struct cbus_host *host) { int ret; - gpio_set_value(host->clk_gpio, 1); - ret = gpio_get_value(host->dat_gpio); - gpio_set_value(host->clk_gpio, 0); + gpiod_set_value(host->clk, 1); + ret = gpiod_get_value(host->dat); + gpiod_set_value(host->clk, 0); return ret; } @@ -123,10 +121,10 @@ static int cbus_transfer(struct cbus_host *host, char rw, unsigned dev, spin_lock_irqsave(&host->lock, flags); /* Reset state and start of transfer, SEL stays down during transfer */ - gpio_set_value(host->sel_gpio, 0); + gpiod_set_value(host->sel, 0); /* Set the DAT pin to output */ - gpio_direction_output(host->dat_gpio, 1); + gpiod_direction_output(host->dat, 1); /* Send the device address */ cbus_send_data(host, dev, CBUS_ADDR_BITS); @@ -141,12 +139,12 @@ static int cbus_transfer(struct cbus_host *host, char rw, unsigned dev, cbus_send_data(host, data, 16); ret = 0; } else { - ret = gpio_direction_input(host->dat_gpio); + ret = gpiod_direction_input(host->dat); if (ret) { dev_dbg(host->dev, "failed setting direction\n"); goto out; } - gpio_set_value(host->clk_gpio, 1); + gpiod_set_value(host->clk, 1); ret = cbus_receive_word(host); if (ret < 0) { @@ -156,9 +154,9 @@ static int cbus_transfer(struct cbus_host *host, char rw, unsigned dev, } /* Indicate end of transfer, SEL goes up until next transfer */ - gpio_set_value(host->sel_gpio, 1); - gpio_set_value(host->clk_gpio, 1); - gpio_set_value(host->clk_gpio, 0); + gpiod_set_value(host->sel, 1); + gpiod_set_value(host->clk, 1); + gpiod_set_value(host->clk, 0); out: spin_unlock_irqrestore(&host->lock, flags); @@ -214,7 +212,6 @@ static int cbus_i2c_probe(struct platform_device *pdev) { struct i2c_adapter *adapter; struct cbus_host *chost; - int ret; adapter = devm_kzalloc(&pdev->dev, sizeof(struct i2c_adapter), GFP_KERNEL); @@ -225,22 +222,20 @@ static int cbus_i2c_probe(struct platform_device *pdev) if (!chost) return -ENOMEM; - if (pdev->dev.of_node) { - struct device_node *dnode = pdev->dev.of_node; - if (of_gpio_count(dnode) != 3) - return -ENODEV; - chost->clk_gpio = of_get_gpio(dnode, 0); - chost->dat_gpio = of_get_gpio(dnode, 1); - chost->sel_gpio = of_get_gpio(dnode, 2); - } else if (dev_get_platdata(&pdev->dev)) { - struct i2c_cbus_platform_data *pdata = - dev_get_platdata(&pdev->dev); - chost->clk_gpio = pdata->clk_gpio; - chost->dat_gpio = pdata->dat_gpio; - chost->sel_gpio = pdata->sel_gpio; - } else { + if (gpiod_count(&pdev->dev, NULL) != 3) return -ENODEV; - } + chost->clk = devm_gpiod_get_index(&pdev->dev, NULL, 0, GPIOD_OUT_LOW); + if (IS_ERR(chost->clk)) + return PTR_ERR(chost->clk); + chost->dat = devm_gpiod_get_index(&pdev->dev, NULL, 1, GPIOD_IN); + if (IS_ERR(chost->dat)) + return PTR_ERR(chost->dat); + chost->sel = devm_gpiod_get_index(&pdev->dev, NULL, 2, GPIOD_OUT_HIGH); + if (IS_ERR(chost->sel)) + return PTR_ERR(chost->sel); + gpiod_set_consumer_name(chost->clk, "CBUS clk"); + gpiod_set_consumer_name(chost->dat, "CBUS dat"); + gpiod_set_consumer_name(chost->sel, "CBUS sel"); adapter->owner = THIS_MODULE; adapter->class = I2C_CLASS_HWMON; @@ -254,21 +249,6 @@ static int cbus_i2c_probe(struct platform_device *pdev) spin_lock_init(&chost->lock); chost->dev = &pdev->dev; - ret = devm_gpio_request_one(&pdev->dev, chost->clk_gpio, - GPIOF_OUT_INIT_LOW, "CBUS clk"); - if (ret) - return ret; - - ret = devm_gpio_request_one(&pdev->dev, chost->dat_gpio, GPIOF_IN, - "CBUS data"); - if (ret) - return ret; - - ret = devm_gpio_request_one(&pdev->dev, chost->sel_gpio, - GPIOF_OUT_INIT_HIGH, "CBUS sel"); - if (ret) - return ret; - i2c_set_adapdata(adapter, chost); platform_set_drvdata(pdev, adapter); diff --git a/include/linux/platform_data/i2c-cbus-gpio.h b/include/linux/platform_data/i2c-cbus-gpio.h deleted file mode 100644 index 6faa992a9502..000000000000 --- a/include/linux/platform_data/i2c-cbus-gpio.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * i2c-cbus-gpio.h - CBUS I2C platform_data definition - * - * Copyright (C) 2004-2009 Nokia Corporation - * - * Written by Felipe Balbi and Aaro Koskinen. - * - * This file is subject to the terms and conditions of the GNU General - * Public License. See the file "COPYING" in the main directory of this - * archive for more details. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - */ - -#ifndef __INCLUDE_LINUX_I2C_CBUS_GPIO_H -#define __INCLUDE_LINUX_I2C_CBUS_GPIO_H - -struct i2c_cbus_platform_data { - int dat_gpio; - int clk_gpio; - int sel_gpio; -}; - -#endif /* __INCLUDE_LINUX_I2C_CBUS_GPIO_H */