From patchwork Mon Jun 8 20:56:41 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 6568121 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id DBCFB9F1C1 for ; Mon, 8 Jun 2015 21:08:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A7DE720451 for ; Mon, 8 Jun 2015 21:08:24 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8E34020450 for ; Mon, 8 Jun 2015 21:08:23 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Z24DR-0006rW-KS; Mon, 08 Jun 2015 21:04:17 +0000 Received: from merlin.infradead.org ([2001:4978:20e::2]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Z247G-0000uP-51 for linux-arm-kernel@bombadil.infradead.org; Mon, 08 Jun 2015 20:57:54 +0000 Received: from mail-la0-x230.google.com ([2a00:1450:4010:c03::230]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Z247D-00005e-Pf for linux-arm-kernel@lists.infradead.org; Mon, 08 Jun 2015 20:57:52 +0000 Received: by laar3 with SMTP id r3so56705968laa.3 for ; Mon, 08 Jun 2015 13:57:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=FOpm1nDbnoyHqa/PS+iYIkHtMKHjP33TL7R2SQRyMo8=; b=adkWrv82gWv+b3Y0tjrnHi18j9QALAFuXKpyM7Za21zqvhGTn7EfPXycoWDJ69ouhe anqcvMmZ/cPphWSil/u+yHO0heWaaAIqpYWiXpd1AbJNyD+K/I2p9oPoTfYyNgx6dWwC LkWudUd9YCRzazOLmpycjiLXhKB4AC4dcIdgwyyx9DpeixFvNQoEbywJjoQIaP4+ngAO dPwiXiZa4668l5v3JYWTBdMYGElvgLuuybjfhh1CyICTD3myUwpHst+SYhiVYaxBe6KY EJnHVjHAPdYnjl/VBJoAyMyf5npqZIKqqc2XCO8yWWFMVcAMpmbVsyBP76Qo/VORmwkj XxRw== X-Received: by 10.152.18.163 with SMTP id x3mr19061530lad.70.1433797043976; Mon, 08 Jun 2015 13:57:23 -0700 (PDT) Received: from anuminas.rup.mentorg.com (ppp89-110-20-81.pppoe.avangarddsl.ru. [89.110.20.81]) by mx.google.com with ESMTPSA id s8sm892556las.29.2015.06.08.13.57.21 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 08 Jun 2015 13:57:22 -0700 (PDT) From: Dmitry Eremin-Solenikov To: Russell King , Lee Jones Subject: [PATCH v5 10/17] i2c: add locomo i2c driver Date: Mon, 8 Jun 2015 23:56:41 +0300 Message-Id: <1433797008-6246-11-git-send-email-dbaryshkov@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1433797008-6246-1-git-send-email-dbaryshkov@gmail.com> References: <1433797008-6246-1-git-send-email-dbaryshkov@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150608_165752_139018_255CADF1 X-CRM114-Status: GOOD ( 20.49 ) X-Spam-Score: -2.7 (--) Cc: Andrea Adami , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 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 X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP LoCoMo chip contains a tiny i2c controller destined to control M62332 DAC. Provide a separate I2C driver for this cell. Signed-off-by: Dmitry Eremin-Solenikov Reviewed-by: Wolfram Sang --- drivers/i2c/busses/Kconfig | 12 ++++ drivers/i2c/busses/Makefile | 1 + drivers/i2c/busses/i2c-locomo.c | 135 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 148 insertions(+) create mode 100644 drivers/i2c/busses/i2c-locomo.c diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig index 2255af2..114d9da 100644 --- a/drivers/i2c/busses/Kconfig +++ b/drivers/i2c/busses/Kconfig @@ -602,6 +602,18 @@ config I2C_KEMPLD This driver can also be built as a module. If so, the module will be called i2c-kempld. +config I2C_LOCOMO + tristate "I2C bus support for LoCoMo chips" + depends on MFD_LOCOMO + select I2C_ALGOBIT + help + Say yes if you will run the kernel on Sharp SL-5x00 family of devices. + + If you don't know what to do here, say N. + + This driver can also be built as a module. If so, the module + will be called i2c-locomo. + config I2C_MESON tristate "Amlogic Meson I2C controller" depends on ARCH_MESON diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile index cdf941d..e09dcf6 100644 --- a/drivers/i2c/busses/Makefile +++ b/drivers/i2c/busses/Makefile @@ -58,6 +58,7 @@ obj-$(CONFIG_I2C_IMX) += i2c-imx.o obj-$(CONFIG_I2C_IOP3XX) += i2c-iop3xx.o obj-$(CONFIG_I2C_JZ4780) += i2c-jz4780.o obj-$(CONFIG_I2C_KEMPLD) += i2c-kempld.o +obj-$(CONFIG_I2C_LOCOMO) += i2c-locomo.o obj-$(CONFIG_I2C_MESON) += i2c-meson.o obj-$(CONFIG_I2C_MPC) += i2c-mpc.o obj-$(CONFIG_I2C_MV64XXX) += i2c-mv64xxx.o diff --git a/drivers/i2c/busses/i2c-locomo.c b/drivers/i2c/busses/i2c-locomo.c new file mode 100644 index 0000000..d520513 --- /dev/null +++ b/drivers/i2c/busses/i2c-locomo.c @@ -0,0 +1,135 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ +#include +#include +#include +#include +#include +#include +#include +#include + +struct locomo_i2c { + struct regmap *regmap; + struct i2c_adapter adap; + struct i2c_algo_bit_data bit; +}; + +static void locomo_i2c_setsda(void *data, int state) +{ + struct locomo_i2c *li2c = data; + + regmap_update_bits(li2c->regmap, LOCOMO_DAC, + LOCOMO_DAC_SDAOEB, + state ? LOCOMO_DAC_SDAOEB : 0); +} + +static void locomo_i2c_setscl(void *data, int state) +{ + struct locomo_i2c *li2c = data; + + regmap_update_bits(li2c->regmap, LOCOMO_DAC, + LOCOMO_DAC_SCLOEB, + state ? LOCOMO_DAC_SCLOEB : 0); +} + +static int locomo_i2c_getsda(void *data) +{ + struct locomo_i2c *li2c = data; + unsigned int r; + + regmap_read(li2c->regmap, LOCOMO_DAC, &r); + + return !!(r & LOCOMO_DAC_SDA); +} + +static int locomo_i2c_probe(struct platform_device *dev) +{ + struct locomo_i2c *li2c; + int ret; + + li2c = devm_kzalloc(&dev->dev, sizeof(struct locomo_i2c), GFP_KERNEL); + if (li2c == NULL) + return -ENOMEM; + + li2c->regmap = dev_get_regmap(dev->dev.parent, NULL); + if (!li2c->regmap) + return -ENODEV; + + li2c->adap.owner = THIS_MODULE; + li2c->adap.dev.parent = &dev->dev; + li2c->adap.dev.of_node = dev->dev.of_node; + li2c->adap.algo_data = &li2c->bit; + li2c->adap.nr = 1; /* On poodle, 0 is pxa internal bus */ + + strlcpy(li2c->adap.name, "LoCoMo I2C", sizeof(li2c->adap.name)); + + li2c->bit.data = li2c; + li2c->bit.setsda = locomo_i2c_setsda; + li2c->bit.setscl = locomo_i2c_setscl; + li2c->bit.getsda = locomo_i2c_getsda; + li2c->bit.udelay = 6; + li2c->bit.timeout = HZ; + + ret = i2c_bit_add_numbered_bus(&li2c->adap); + if (ret) + return ret; + + platform_set_drvdata(dev, li2c); + + return 0; +} + +static int locomo_i2c_remove(struct platform_device *dev) +{ + struct locomo_i2c *li2c = platform_get_drvdata(dev); + + i2c_del_adapter(&li2c->adap); + + return 0; +} + +#ifdef CONFIG_PM_SLEEP +static int locomo_i2c_suspend(struct device *dev) +{ + struct locomo_i2c *li2c = dev_get_drvdata(dev); + + regmap_write(li2c->regmap, LOCOMO_DAC, 0x00); + + return 0; +} + +static int locomo_i2c_resume(struct device *dev) +{ + struct locomo_i2c *li2c = dev_get_drvdata(dev); + + regmap_write(li2c->regmap, LOCOMO_DAC, + LOCOMO_DAC_SDAOEB | LOCOMO_DAC_SCLOEB); + + return 0; +} +static SIMPLE_DEV_PM_OPS(locomo_i2c_pm, locomo_i2c_suspend, locomo_i2c_resume); +#define LOCOMO_I2C_PM (&locomo_i2c_pm) +#else +#define LOCOMO_I2C_PM NULL +#endif + + +static struct platform_driver locomo_i2c_driver = { + .driver = { + .name = "locomo-i2c", + .pm = LOCOMO_I2C_PM, + }, + .probe = locomo_i2c_probe, + .remove = locomo_i2c_remove, +}; + +module_platform_driver(locomo_i2c_driver); + +MODULE_DESCRIPTION("LoCoMo i2c bus driver"); +MODULE_AUTHOR("Dmitry Eremin-Solenikov "); +MODULE_LICENSE("GPL v2"); +MODULE_ALIAS("platform:locomo-i2c");