From patchwork Sun Jun 9 02:36:42 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangfei Gao X-Patchwork-Id: 2693621 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) by patchwork1.kernel.org (Postfix) with ESMTP id A153E3FC23 for ; Sun, 9 Jun 2013 02:41:37 +0000 (UTC) Received: from merlin.infradead.org ([205.233.59.134]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UlVZW-0000xv-Om; Sun, 09 Jun 2013 02:41:36 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UlVZT-0007kj-Ed; Sun, 09 Jun 2013 02:41:31 +0000 Received: from mail-pd0-f174.google.com ([209.85.192.174]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UlVZJ-0007ij-06 for linux-arm-kernel@lists.infradead.org; Sun, 09 Jun 2013 02:41:28 +0000 Received: by mail-pd0-f174.google.com with SMTP id 10so5229854pdc.19 for ; Sat, 08 Jun 2013 19:38:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=yEPTvmPEEm+TeyRdJX30q9JUpiP+dNDvlgj433aHsrM=; b=aFQCGe+33abuX4Kp6f5/DJ6AmX9nC2Ac/TKZotlJmHmGTRQEQh7dXc3uiVNCpURMVb FVFrLkz3fG3h4QRQSjK+53mI0M0eUcRFR9Jdid4iMzns/JFOnJ6Jru5ujW2muG5jE/d1 z5pCFBzgOnP1ypkX4oGaQ1xkRlDkiI9OYjfnS4XCfoE0qKn3zjhPU7XDvQnSllY9wlR0 KdWu0UrO/+9H0RyCPCzMradUnDQUAZbGSm/9hx9GyVo4C2LQasivCf5bIgSVxQVdIeCX v2x2CbngXzS8/NMO7taJ6tt7FPLA8avFjF3ucT/jdrmM0+XZMy1SaZxC9RiEhGE7XuiB +bZg== X-Received: by 10.66.2.103 with SMTP id 7mr8608835pat.211.1370745516415; Sat, 08 Jun 2013 19:38:36 -0700 (PDT) Received: from localhost.localdomain ([124.73.8.29]) by mx.google.com with ESMTPSA id xu10sm9578181pab.3.2013.06.08.19.38.26 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 08 Jun 2013 19:38:35 -0700 (PDT) From: Zhangfei Gao To: Wolfram Sang , Dirk Brandewie Subject: [PATCH 2/2] i2c: designware: Add i2c-designware-hs Date: Sun, 9 Jun 2013 10:36:42 +0800 Message-Id: <1370745402-11844-3-git-send-email-zhangfei.gao@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1370745402-11844-1-git-send-email-zhangfei.gao@linaro.org> References: <1370745402-11844-1-git-send-email-zhangfei.gao@linaro.org> X-Gm-Message-State: ALoCoQmbG8N0W4+mfIPsj8FeAcmGjpCqHhHlTGQ4FM+rinr6Dh++44/13fo9vTjcgwJ2E9L9VCW5 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130608_224121_267571_3CDDE7B2 X-CRM114-Status: GOOD ( 22.89 ) X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [209.85.192.174 listed in list.dnswl.org] Cc: Zhangfei Gao , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Add support hisilicon i2c driver, which reuse designware i2c ip Signed-off-by: Zhangfei Gao --- .../devicetree/bindings/i2c/i2c-designware-hs.txt | 30 +++ drivers/i2c/busses/Kconfig | 10 + drivers/i2c/busses/Makefile | 1 + drivers/i2c/busses/i2c-designware-hs.c | 194 ++++++++++++++++++++ 4 files changed, 235 insertions(+) create mode 100644 Documentation/devicetree/bindings/i2c/i2c-designware-hs.txt create mode 100644 drivers/i2c/busses/i2c-designware-hs.c diff --git a/Documentation/devicetree/bindings/i2c/i2c-designware-hs.txt b/Documentation/devicetree/bindings/i2c/i2c-designware-hs.txt new file mode 100644 index 0000000..08908fa --- /dev/null +++ b/Documentation/devicetree/bindings/i2c/i2c-designware-hs.txt @@ -0,0 +1,30 @@ +* Hisilicon I2C Controller + +Required properties : + + - compatible : should be "hisilicon,designware-i2c" + - reg : Offset and length of the register set for the device + - interrupts : where IRQ is the interrupt number. + +Example : + + i2c0: i2c@fcb08000 { + compatible = "hs,designware-i2c"; + #address-cells = <1>; + #size-cells = <0>; + reg = <0xfcb08000 0x1000>; + interrupts = <0 28 4>; + clocks = <&pclk>; + status = "disabled"; + }; + + Client in i2c0 bus with add 0x58 could be added as example + i2c0: i2c@fcb08000 { + status = "ok"; + pinctrl-names = "default"; + pinctrl-0 = <&i2c0_pmx_func &i2c0_cfg_func>; + i2c_client1: i2c_client@58 { + compatible = "hisilicon,i2c_client_tpa2028"; + reg = <0x58>; + }; + }; diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig index 631736e..4405476 100644 --- a/drivers/i2c/busses/Kconfig +++ b/drivers/i2c/busses/Kconfig @@ -419,6 +419,16 @@ config I2C_DESIGNWARE_PCI This driver can also be built as a module. If so, the module will be called i2c-designware-pci. +config I2C_DESIGNWARE_HS + tristate "Synopsys DesignWare Hisilicon" + depends on ARCH_HI3xxx + depends on HAVE_CLK + select I2C_DESIGNWARE_CORE + help + If you say yes to this option, support will be included for the + Synopsys DesignWare I2C adapter on Hisilicon. + Only master mode is supported. + config I2C_EG20T tristate "Intel EG20T PCH/LAPIS Semicon IOH(ML7213/ML7223/ML7831) I2C" depends on PCI diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile index 8f4fc23..2408932 100644 --- a/drivers/i2c/busses/Makefile +++ b/drivers/i2c/busses/Makefile @@ -41,6 +41,7 @@ obj-$(CONFIG_I2C_DESIGNWARE_PLATFORM) += i2c-designware-platform.o i2c-designware-platform-objs := i2c-designware-platdrv.o obj-$(CONFIG_I2C_DESIGNWARE_PCI) += i2c-designware-pci.o i2c-designware-pci-objs := i2c-designware-pcidrv.o +obj-$(CONFIG_I2C_DESIGNWARE_HS) += i2c-designware-hs.o obj-$(CONFIG_I2C_EG20T) += i2c-eg20t.o obj-$(CONFIG_I2C_GPIO) += i2c-gpio.o obj-$(CONFIG_I2C_HIGHLANDER) += i2c-highlander.o diff --git a/drivers/i2c/busses/i2c-designware-hs.c b/drivers/i2c/busses/i2c-designware-hs.c new file mode 100644 index 0000000..94d1496 --- /dev/null +++ b/drivers/i2c/busses/i2c-designware-hs.c @@ -0,0 +1,194 @@ +/* + * Hisilicon Synopsys DesignWare I2C adapter driver (master only). + * + * Copyright (c) 2013 Linaro Ltd. + * Copyright (c) 2013 Hisilicon Limited. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "i2c-designware-core.h" + +static struct i2c_algorithm hs_i2c_dw_algo = { + .master_xfer = i2c_dw_xfer, + .functionality = i2c_dw_func, +}; +static u32 hs_i2c_dw_get_clk_rate_khz(struct dw_i2c_dev *dev) +{ + return clk_get_rate(dev->clk)/1000; +} + +static int hs_dw_i2c_probe(struct platform_device *pdev) +{ + struct dw_i2c_dev *d; + struct i2c_adapter *adap; + struct resource *iores; + struct pinctrl *pinctrl; + int r; + + d = devm_kzalloc(&pdev->dev, sizeof(struct dw_i2c_dev), GFP_KERNEL); + if (!d) + return -ENOMEM; + + /* NOTE: driver uses the static register mapping */ + iores = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!iores) + return -EINVAL; + + d->base = devm_request_and_ioremap(&pdev->dev, iores); + if (!d->base) + return -EADDRNOTAVAIL; + + d->irq = platform_get_irq(pdev, 0); + if (d->irq < 0) { + dev_err(&pdev->dev, "no irq resource?\n"); + return d->irq; /* -ENXIO */ + } + + r = devm_request_irq(&pdev->dev, d->irq, + i2c_dw_isr, IRQF_DISABLED, pdev->name, d); + if (r) { + dev_err(&pdev->dev, "failure requesting irq %i\n", d->irq); + return -EINVAL; + } + + pinctrl = devm_pinctrl_get_select_default(&pdev->dev); + if (IS_ERR(pinctrl)) + dev_warn(&pdev->dev, + "pins are not configured from the driver\n"); + + d->clk = devm_clk_get(&pdev->dev, NULL); + if (IS_ERR(d->clk)) + return -ENODEV; + + d->get_clk_rate_khz = hs_i2c_dw_get_clk_rate_khz; + clk_prepare_enable(d->clk); + init_completion(&d->cmd_complete); + mutex_init(&d->lock); + d->dev = get_device(&pdev->dev); + + d->functionality = + I2C_FUNC_I2C | + I2C_FUNC_10BIT_ADDR | + I2C_FUNC_SMBUS_BYTE | + I2C_FUNC_SMBUS_BYTE_DATA | + I2C_FUNC_SMBUS_WORD_DATA | + I2C_FUNC_SMBUS_I2C_BLOCK; + d->master_cfg = DW_IC_CON_MASTER | DW_IC_CON_SLAVE_DISABLE | + DW_IC_CON_RESTART_EN | DW_IC_CON_SPEED_FAST; + d->accessor_flags = ACCESS_32BIT; + d->tx_fifo_depth = 16; + d->rx_fifo_depth = 16; + + r = i2c_dw_init(d); + if (r) + goto err; + + i2c_dw_disable_int(d); + + adap = &d->adapter; + i2c_set_adapdata(adap, d); + adap->owner = THIS_MODULE; + adap->class = I2C_CLASS_HWMON; + strlcpy(adap->name, "Synopsys DesignWare I2C adapter", + sizeof(adap->name)); + adap->algo = &hs_i2c_dw_algo; + adap->dev.parent = &pdev->dev; + adap->dev.of_node = pdev->dev.of_node; + + adap->nr = pdev->id; + r = i2c_add_numbered_adapter(adap); + if (r) { + dev_err(&pdev->dev, "failure adding adapter\n"); + goto err; + } + of_i2c_register_devices(adap); + platform_set_drvdata(pdev, d); + + return 0; +err: + clk_disable_unprepare(d->clk); + put_device(&pdev->dev); + return r; +} + +static int hs_dw_i2c_remove(struct platform_device *pdev) +{ + struct dw_i2c_dev *d = platform_get_drvdata(pdev); + + platform_set_drvdata(pdev, NULL); + i2c_del_adapter(&d->adapter); + put_device(&pdev->dev); + clk_disable_unprepare(d->clk); + i2c_dw_disable(d); + + return 0; +} + +#ifdef CONFIG_OF +static const struct of_device_id hs_dw_i2c_of_match[] = { + { .compatible = "hisilicon,designware-i2c", }, + {}, +}; +MODULE_DEVICE_TABLE(of, hs_dw_i2c_of_match); +#endif + +#ifdef CONFIG_PM +static int hs_dw_i2c_suspend(struct device *dev) +{ + struct platform_device *pdev = to_platform_device(dev); + struct dw_i2c_dev *i_dev = platform_get_drvdata(pdev); + + clk_disable_unprepare(i_dev->clk); + + return 0; +} + +static int hs_dw_i2c_resume(struct device *dev) +{ + struct platform_device *pdev = to_platform_device(dev); + struct dw_i2c_dev *i_dev = platform_get_drvdata(pdev); + + clk_prepare_enable(i_dev->clk); + i2c_dw_init(i_dev); + + return 0; +} +#endif + +static SIMPLE_DEV_PM_OPS(hs_dw_i2c_dev_pm_ops, hs_dw_i2c_suspend, + hs_dw_i2c_resume); + +static struct platform_driver hs_dw_i2c_driver = { + .probe = hs_dw_i2c_probe, + .remove = hs_dw_i2c_remove, + .driver = { + .name = "i2c_designware-hs", + .owner = THIS_MODULE, + .of_match_table = of_match_ptr(hs_dw_i2c_of_match), + .pm = &hs_dw_i2c_dev_pm_ops, + }, +}; +module_platform_driver(hs_dw_i2c_driver); + +MODULE_DESCRIPTION("HS Synopsys DesignWare I2C bus adapter"); +MODULE_ALIAS("platform:i2c_designware-hs"); +MODULE_LICENSE("GPL");