Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751459AbbHQSyD (ORCPT ); Mon, 17 Aug 2015 14:54:03 -0400 Received: from mail-bl2on0144.outbound.protection.outlook.com ([65.55.169.144]:60032 "EHLO na01-bl2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750788AbbHQSyA (ORCPT ); Mon, 17 Aug 2015 14:54:00 -0400 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=freescale.com; nokia.com; dkim=none (message not signed) header.d=none; From: York Sun To: CC: , , York Sun , Paul Bolle , Peter Korsgaard , Alexander Sverdlin Subject: [Patch v5] driver/i2c/mux: Add register-based mux i2c-mux-reg Date: Mon, 17 Aug 2015 11:53:48 -0700 Message-ID: <1439837628-2295-1-git-send-email-yorksun@freescale.com> X-Mailer: git-send-email 1.7.9.5 X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1;BY2FFO11FD054;1:Rz9iLiSAlazGL6efBmdU4a7GQWndaAJbkngr+W2AB9PXhd9BanvBeTEKr32fmAhBzvzCGncPldoVRpEkd1mVqnHmF/O4vLtqNR+UFeRNhNV7WSVvNQl8Dpni5Kr9X0Q1QRFPsg6IaUCZtzWT1Ddbx0syFEu9a/+bBE2sV3xONENcsNSydWfNaSV5WZb0J7eoXf7rPXS20CIC0bnB9yeHffIbZDCowyndS6g6ZqfxxEfMNw5PYdKp32WCPeq9ypZXyVqEOthWAiHtMK3//WAaok7+grExZaDdopd0G4gJPQJKV78qXi8tZvWEhAEAUAs0lXwJGB/CNCPcv6OkR6d7LLB/uDwMhzglldfhsXwgnvc6MgogfYOl1di+2VZpm1JsrFgFBWJrDlmdCrfWQHyPSw== X-Forefront-Antispam-Report: CIP:192.88.168.50;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10019020)(6009001)(2980300002)(3050300001)(339900001)(54534003)(479174004)(189002)(199003)(189998001)(87936001)(110136002)(4001540100001)(5001860100001)(6806004)(77156002)(86362001)(64706001)(50466002)(47776003)(230783001)(92566002)(85426001)(106466001)(62966003)(5003940100001)(229853001)(81156007)(105606002)(97736004)(2351001)(36756003)(5001830100001)(68736005)(48376002)(46102003)(19580395003)(77096005)(50226001)(5001960100002)(50986999)(104016003)(33646002)(19580405001)(2004002);DIR:OUT;SFP:1102;SCL:1;SRVR:BY2PR03MB157;H:tx30smr01.am.freescale.net;FPR:;SPF:Fail;PTR:InfoDomainNonexistent;MX:1;A:1;LANG:en; MIME-Version: 1.0 Content-Type: text/plain X-Microsoft-Exchange-Diagnostics: 1;BY2PR03MB157;2:2KnTA7bvRl1xZo370g+Zx9v2SDfNAZV5DMKCso/upgaxwAB2wLh8lgxFWop2pChLEy3B3CVfOBSq1Sqt5ssJ3Secwm56+Ur696jCMLcpw5GpcrC3EGwHXln0v70S9CY9JTBTzQ5yy68Ac4Qo+TT+0SmDkkwmxOszfD2/LJlbSdk=;3:smbHKNz20mZVuQUZJ/nRJmPE6c3X6LIAJU2RNpweFDnUIrwWsEvDkvyvs8FMc3aY8tV4hgGdVSoXlaLVngdlelzDKbCnkMdzIHDULFOFEN44cTzRCsaN5/iZ9iA8HPltNg+Yvk+WDfUVGUsV6oWXh1M0JAmtwRE55ornpRQyFEObUkaFVHLj5pKx33f3jwLTemlRYhrmujRiDcfUlMPj7LDis6e5pnWpSX9lPZ4KAM8=;25:FhtZrzVUmbjBmSvufgMk3tii8BCb/Irj/iQgByua1c4C23rQNcO8VxU6OkzITo8NgeHaP+nEmNGXaRc0ytLAL+zf/4xeOe2+w++6avRQNecSb6ciphAse0hEXU5uo8tv1LKVi8+10PbNLfgoyzGCkJDKnYb5pH2fBTPjBgbA5hQRSyhOYaTXYmV+H/KP59gP16ruOHKwwigFxXvFMR0A4yUH4k006bV/LgE/4h3IrEecQQ+9AnZBx7KWC7CvF4lp X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY2PR03MB157; X-Microsoft-Exchange-Diagnostics: 1;BY2PR03MB157;20:4L3thdK7rPMVoY5y06PeUVSjz08IagegrQizxgC6x2xvoqaHzzXVu+Dxnvo/wDV5MKMi2GrGknTCDjyH3PyRuAiKdcfjxYLO0TJ/qJzcJdcVOS1H6JzayVlRVWapWBd7j51lZyNdhYUoT6b5qi0Mp+Q1E8FR6Z3qgU3vIiDkju01qW2AaywAxzoNszXFzOuRl+TLA2E3L5DaPwqWaaKGQUxpq4Wc5hStyYRY04KtFuFRgXeK1+PziYqjwOTCnmk1xdZd6GClwcqoyeU5JHhCROC0pDf7Cxau3ZNNRaGAXuFJC9sKH8YNhoMmusUcd1r679KmC0BY3+XjLdB5DTp/CppWMgyinuChmGfSi6yurv8=;4:zGhnBuGxyiM2u0No8EQSHsu+UI9MadXtNEh8pjNaxGFLysF8IhglCqyOkfKUGEEyzMhrpCyVXqn2+NNSeGA9i6AQuxUv2GpLm3JQ9P8e1uYiJJ1xPSArPLajlVtJzzEBLGdY+IHnN3udM0ZA+AtQXz5nmQe7rl/bv4EBUCZvMpIWLXpwm8D/BMi2OXa2jNW457m05rddDV6ls0gVY/CZVXBZre+mHn3vKaBlDu2IyFZF4KL3s3MF0iMGW4aI7+VwUzRyXnJrMQJLYBI7G108SU1312Ry8cuTuC+lqhLP5owP9PzPxM+vef3t79YcCRPN X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(8121501046)(5005006)(3002001);SRVR:BY2PR03MB157;BCL:0;PCL:0;RULEID:;SRVR:BY2PR03MB157; X-Forefront-PRVS: 0671F32598 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BY2PR03MB157;23:46Vfi8wiOFunncvcm8+HTN1BM3RRdPAxQulmJ+4Nwt?= =?us-ascii?Q?cqQPcPTRu94jLCwyt6GTVys4+pzBTaB9w2LCV+vrwkT/bZl6oQXCiQRZLJ7S?= =?us-ascii?Q?o6Qw0h68Aw0h9YAgWjGN9eaomM3d3YkiyOwmNHOJki0+mvgEK8kK9VRD6V1H?= =?us-ascii?Q?d7D3ApVjZnaZI3kPfCcKc0mPsFE9OCWHE94TUtdYaeYbXwez5yrUYC+Ls5XE?= =?us-ascii?Q?EZvHVaFDDxGV21tBX7oYWmkZTEyRagptY/Iitryc/DcuxB8QOBkX6zIgmwOG?= =?us-ascii?Q?sKVGD+AnG9hMvQmY6mRpP3UvBzlehUIO0DEVMlJI4SyUYWVybF3Ou6Ff4MUe?= =?us-ascii?Q?3cm8NPUvX9qQcrd5kNGijrZqO+NVkW0o4wYg4qY41GVSim+uW38a/4HodjIg?= =?us-ascii?Q?J4echmZYJmIYqAu2LVdBcCbfohpuMFDjIa6coD8TKBJief4aXywV2GmciBIj?= =?us-ascii?Q?BckX14TlTkRn2OTb45LJODvGNTwdbevmUQmolroJTwNm2Ag4twVOjsaBSEdX?= =?us-ascii?Q?Fv1FATjH2YNkFmINPkTZAUqqcceQy83vpBWjIcV0f3LcGL0UrXnq88V1ONL9?= =?us-ascii?Q?IaRh2odk9/NEfMfmShYBFApvEjon776bLV4bGsrKR7anzRmUfcXTCyp2eQqS?= =?us-ascii?Q?X1Yb3TZ6qIkPeq2nYTzRrMCzLzdi58dSLZwLCL7RsSNsMQoDuPA5hGsi1vmY?= =?us-ascii?Q?6AL7C7AdPjQTwdRoGVDq7f4HIx5khLBW4d1flQmZxmKuwBXlIKKU6vy1htIG?= =?us-ascii?Q?AsyGml7g9euaqoq90CIzZ+Bqh4wj3940+5pkzEi/KEXkM8OZ+1WDNPAbbcYP?= =?us-ascii?Q?XZHYovXBB2o/sy9JIUvtZj4/0ho0R6JnhvkrDIkc4QujoAy1DZjkiOVwQI/4?= =?us-ascii?Q?r5HuuTP7kxY+H6ybpazTtr7H8urgYlWyo5FkLbjHVQdWrHbu0Jg7a6uRPqHW?= =?us-ascii?Q?6KuZTdUbnovkOqdMK2W/uZC2vgyBnBXi46+92MjXw+4lODRblGEWSPXcePZb?= =?us-ascii?Q?YI5vY3Zml2KdQIbCEyH6IAFqOWGOxePvmNBM2TegFzl80b80lBvF0dnLgRoR?= =?us-ascii?Q?J3RdWezNzzQThjZEl2YgoI5bNoV6bey+ZBuLICjcd6DC3Ern92/T4UoWPnqs?= =?us-ascii?Q?I3v4EIjqpba9e3jQVZAL+JTzHmH5I4hoKEkUUK9+QA3FVxQzywQCDcM7RGUV?= =?us-ascii?Q?F1QjiDAGyWWr8=3D?= X-Microsoft-Exchange-Diagnostics: 1;BY2PR03MB157;5:aBr/KNu98p63Ho6lds+bhHaYJQW4RHIBKXd5h2C8YbPv2OwoulFsYCiq7UrGeHwd/eXIWWyUiRyTLGL+yXeSL7fPofkhNekX6wA7G+UWcPa3cDc/wtiXH5d1CoPjH50Q/UxyCIZLRAxKdqkNeKULJg==;24:0fK6N9EQnNYUYAgQ4CShOqFGq4yVhhAzyomFD6KX41wuOR7xJ29UZ823oSbXj+qAhu8+i8RbLJ2BKrpO6LhX8nGLUf4koisSKd7yRId94YA=;20:abs2kWY4S/1UkdYYT2Z8TB7PinKDe0juHP1qr7yXpn0MfS5GfyvnETdiPoAjKra7OsxaHD9qGfluGS3XaiRhwQ== X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Aug 2015 18:53:54.8620 (UTC) X-MS-Exchange-CrossTenant-Id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=710a03f5-10f6-4d38-9ff4-a80b81da590d;Ip=[192.88.168.50];Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR03MB157 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 15642 Lines: 518 Based on i2c-mux-gpio driver, similarly the register-based mux switch from one bus to another by setting a single register. The register can be on PCIe bus, local bus, or any memory-mapped address. The endianness of such register can be specified in device tree if used, or in platform data. Signed-off-by: York Sun CC: Wolfram Sang CC: Paul Bolle CC: Peter Korsgaard CC: Alexander Sverdlin --- Change log: v5: Remove variable initial_state Remove .owner = THIS_MODULE v4: Rename no-read to write-only Revise binding document Revise endianness checking Reorder in Kconfig and Makefile Remove print for deferred probing Remove debug print for unloading driver v3: Add support of both big- and little-endian register Add readback after writing to register Add no-read option. By default, readback is alowed. Fix using chan_id transferred back from i2c-mux. It was mistakenly used as an index. It is actually the data to be written. v2: Update to GPLv2+ licence header Use iowrite instead of direct dereference the pointer to write register Add support of difference register size of 1/2/4 bytes Remove i2c_put_adapter(parent) in probe fucntion Replace multiple dev_info() with dev_dbg() Add idle_in_use variable to gate using idle value Add __iomem for register pointer Move platform data header file to include/linux/platform_data/ .../devicetree/bindings/i2c/i2c-mux-reg.txt | 74 +++++ drivers/i2c/muxes/Kconfig | 11 + drivers/i2c/muxes/Makefile | 1 + drivers/i2c/muxes/i2c-mux-reg.c | 294 ++++++++++++++++++++ include/linux/platform_data/i2c-mux-reg.h | 44 +++ 5 files changed, 424 insertions(+) create mode 100644 Documentation/devicetree/bindings/i2c/i2c-mux-reg.txt create mode 100644 drivers/i2c/muxes/i2c-mux-reg.c create mode 100644 include/linux/platform_data/i2c-mux-reg.h diff --git a/Documentation/devicetree/bindings/i2c/i2c-mux-reg.txt b/Documentation/devicetree/bindings/i2c/i2c-mux-reg.txt new file mode 100644 index 0000000..ecc5323 --- /dev/null +++ b/Documentation/devicetree/bindings/i2c/i2c-mux-reg.txt @@ -0,0 +1,74 @@ +Register-based I2C Bus Mux + +This binding describes an I2C bus multiplexer that uses a single register +to route the I2C signals. + +Required properties: +- compatible: i2c-mux-reg +- i2c-parent: The phandle of the I2C bus that this multiplexer's master-side + port is connected to. +* Standard I2C mux properties. See mux.txt in this directory. +* I2C child bus nodes. See mux.txt in this directory. + +Optional properties: +- reg: this pair of specifies the register to control the mux. + The depends on its parent node. It can be any memory-mapped + address. The size must be either 1, 2, or 4 bytes. If reg is omitted, the + resource of this device will be used. +- little-endian: The existence indicates the register is in little endian. +- big-endian: The existence indicates the register is in big endian. + If both little-endian and big-endian are omitted, the endianness of the + CPU will be used. +- write-only: The existence indicates the register is write-only. +- idle-state: value to set the muxer to when idle. When no value is + given, it defaults to the last value used. + +Whenever an access is made to a device on a child bus, the value set +in the revelant node's reg property will be output to the register. + +If an idle state is defined, using the idle-state (optional) property, +whenever an access is not being made to a device on a child bus, the +register will be set according to the idle value. + +If an idle state is not defined, the most recently used value will be +left programmed into the register. + +Example of a mux on PCIe card, the host is a powerpc SoC (big endian): + + i2c-mux { + /* the depends on the address translation + * of the parent device. If omitted, device resource + * will be used instead. The size is to determine + * whether iowrite32, iowrite16, or iowrite8 will be used. + */ + reg = <0x6028 0x4>; + little-endian; /* little endian register on PCIe */ + compatible = "i2c-mux-reg"; + #address-cells = <1>; + #size-cells = <0>; + i2c-parent = <&i2c1>; + i2c@0 { + reg = <0>; + #address-cells = <1>; + #size-cells = <0>; + + si5338: clock-generator@70 { + compatible = "silabs,si5338"; + reg = <0x70>; + /* other stuff */ + }; + }; + + i2c@1 { + /* data is written using iowrite32 */ + reg = <1>; + #address-cells = <1>; + #size-cells = <0>; + + si5338: clock-generator@70 { + compatible = "silabs,si5338"; + reg = <0x70>; + /* other stuff */ + }; + }; + }; diff --git a/drivers/i2c/muxes/Kconfig b/drivers/i2c/muxes/Kconfig index f6d313e..e48881a 100644 --- a/drivers/i2c/muxes/Kconfig +++ b/drivers/i2c/muxes/Kconfig @@ -60,4 +60,15 @@ config I2C_MUX_PINCTRL This driver can also be built as a module. If so, the module will be called pinctrl-i2cmux. +config I2C_MUX_REG + tristate "Register-based I2C multiplexer" + help + If you say yes to this option, support will be included for a + register based I2C multiplexer. This driver provides access to + I2C busses connected through a MUX, which is controlled + by a single register. + + This driver can also be built as a module. If so, the module + will be called i2c-mux-reg. + endmenu diff --git a/drivers/i2c/muxes/Makefile b/drivers/i2c/muxes/Makefile index 465778b..e89799b 100644 --- a/drivers/i2c/muxes/Makefile +++ b/drivers/i2c/muxes/Makefile @@ -7,5 +7,6 @@ obj-$(CONFIG_I2C_MUX_GPIO) += i2c-mux-gpio.o obj-$(CONFIG_I2C_MUX_PCA9541) += i2c-mux-pca9541.o obj-$(CONFIG_I2C_MUX_PCA954x) += i2c-mux-pca954x.o obj-$(CONFIG_I2C_MUX_PINCTRL) += i2c-mux-pinctrl.o +obj-$(CONFIG_I2C_MUX_REG) += i2c-mux-reg.o ccflags-$(CONFIG_I2C_DEBUG_BUS) := -DDEBUG diff --git a/drivers/i2c/muxes/i2c-mux-reg.c b/drivers/i2c/muxes/i2c-mux-reg.c new file mode 100644 index 0000000..86d41d36 --- /dev/null +++ b/drivers/i2c/muxes/i2c-mux-reg.c @@ -0,0 +1,294 @@ +/* + * I2C multiplexer using a single register + * + * Copyright 2015 Freescale Semiconductor + * York Sun + * + * 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 + +struct regmux { + struct i2c_adapter *parent; + struct i2c_adapter **adap; /* child busses */ + struct i2c_mux_reg_platform_data data; +}; + +static int i2c_mux_reg_set(const struct regmux *mux, unsigned int chan_id) +{ + if (!mux->data.reg) + return -EINVAL; + + switch (mux->data.reg_size) { + case 4: + if (mux->data.little_endian) { + iowrite32(chan_id, mux->data.reg); + if (!mux->data.write_only) + ioread32(mux->data.reg); + } else { + iowrite32be(chan_id, mux->data.reg); + if (!mux->data.write_only) + ioread32(mux->data.reg); + } + break; + case 2: + if (mux->data.little_endian) { + iowrite16(chan_id, mux->data.reg); + if (!mux->data.write_only) + ioread16(mux->data.reg); + } else { + iowrite16be(chan_id, mux->data.reg); + if (!mux->data.write_only) + ioread16be(mux->data.reg); + } + break; + case 1: + iowrite8(chan_id, mux->data.reg); + if (!mux->data.write_only) + ioread8(mux->data.reg); + break; + default: + pr_err("Invalid register size\n"); + return -EINVAL; + } + + return 0; +} + +static int i2c_mux_reg_select(struct i2c_adapter *adap, void *data, + unsigned int chan) +{ + struct regmux *mux = data; + + return i2c_mux_reg_set(mux, chan); +} + +static int i2c_mux_reg_deselect(struct i2c_adapter *adap, void *data, + unsigned int chan) +{ + struct regmux *mux = data; + + if (mux->data.idle_in_use) + return i2c_mux_reg_set(mux, mux->data.idle); + + return 0; +} + +#ifdef CONFIG_OF +static int i2c_mux_reg_probe_dt(struct regmux *mux, + struct platform_device *pdev) +{ + struct device_node *np = pdev->dev.of_node; + struct device_node *adapter_np, *child; + struct i2c_adapter *adapter; + struct resource res; + unsigned *values; + int i = 0; + + if (!np) + return -ENODEV; + + adapter_np = of_parse_phandle(np, "i2c-parent", 0); + if (!adapter_np) { + dev_err(&pdev->dev, "Cannot parse i2c-parent\n"); + return -ENODEV; + } + adapter = of_find_i2c_adapter_by_node(adapter_np); + if (!adapter) + return -EPROBE_DEFER; + + mux->parent = adapter; + mux->data.parent = i2c_adapter_id(adapter); + put_device(&adapter->dev); + + mux->data.n_values = of_get_child_count(np); + if (of_find_property(np, "little-endian", NULL)) { + mux->data.little_endian = true; + } else if (of_find_property(np, "big-endian", NULL)) { + mux->data.little_endian = false; + } else { +#if defined(__BYTE_ORDER) ? __BYTE_ORDER == __LITTLE_ENDIAN : \ + defined(__LITTLE_ENDIAN) + mux->data.little_endian = true; +#elif defined(__BYTE_ORDER) ? __BYTE_ORDER == __BIG_ENDIAN : \ + defined(__BIG_ENDIAN) + mux->data.little_endian = false; +#else +#error Endianness not defined? +#endif + } + if (of_find_property(np, "write-only", NULL)) + mux->data.write_only = true; + else + mux->data.write_only = false; + + values = devm_kzalloc(&pdev->dev, + sizeof(*mux->data.values) * mux->data.n_values, + GFP_KERNEL); + if (!values) { + dev_err(&pdev->dev, "Cannot allocate values array"); + return -ENOMEM; + } + + for_each_child_of_node(np, child) { + of_property_read_u32(child, "reg", values + i); + i++; + } + mux->data.values = values; + + if (!of_property_read_u32(np, "idle-state", &mux->data.idle)) + mux->data.idle_in_use = true; + + /* map address from "reg" if exists */ + if (of_address_to_resource(np, 0, &res)) { + mux->data.reg_size = resource_size(&res); + if (mux->data.reg_size > 4) { + dev_err(&pdev->dev, "Invalid address size\n"); + return -EINVAL; + } + mux->data.reg = devm_ioremap_resource(&pdev->dev, &res); + if (IS_ERR(mux->data.reg)) + return PTR_ERR(mux->data.reg); + } + + return 0; +} +#else +static int i2c_mux_reg_probe_dt(struct gpiomux *mux, + struct platform_device *pdev) +{ + return 0; +} +#endif + +static int i2c_mux_reg_probe(struct platform_device *pdev) +{ + struct regmux *mux; + struct i2c_adapter *parent; + struct resource *res; + int (*deselect)(struct i2c_adapter *, void *, u32); + unsigned int class; + int i, ret, nr; + + mux = devm_kzalloc(&pdev->dev, sizeof(*mux), GFP_KERNEL); + if (!mux) + return -ENOMEM; + + platform_set_drvdata(pdev, mux); + + if (dev_get_platdata(&pdev->dev)) { + memcpy(&mux->data, dev_get_platdata(&pdev->dev), + sizeof(mux->data)); + + parent = i2c_get_adapter(mux->data.parent); + if (!parent) + return -EPROBE_DEFER; + + mux->parent = parent; + } else { + ret = i2c_mux_reg_probe_dt(mux, pdev); + if (ret < 0) { + dev_err(&pdev->dev, "Error parsing device tree"); + return ret; + } + } + + if (!mux->data.reg) { + dev_info(&pdev->dev, + "Register not set, using platform resource\n"); + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + mux->data.reg_size = resource_size(res); + if (mux->data.reg_size > 4) { + dev_err(&pdev->dev, "Invalid resource size\n"); + return -EINVAL; + } + mux->data.reg = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(mux->data.reg)) + return PTR_ERR(mux->data.reg); + } + + mux->adap = devm_kzalloc(&pdev->dev, + sizeof(*mux->adap) * mux->data.n_values, + GFP_KERNEL); + if (!mux->adap) { + dev_err(&pdev->dev, "Cannot allocate i2c_adapter structure"); + return -ENOMEM; + } + + if (mux->data.idle_in_use) + deselect = i2c_mux_reg_deselect; + else + deselect = NULL; + + for (i = 0; i < mux->data.n_values; i++) { + nr = mux->data.base_nr ? (mux->data.base_nr + i) : 0; + class = mux->data.classes ? mux->data.classes[i] : 0; + + mux->adap[i] = i2c_add_mux_adapter(mux->parent, &pdev->dev, mux, + nr, mux->data.values[i], + class, i2c_mux_reg_select, + deselect); + if (!mux->adap[i]) { + ret = -ENODEV; + dev_err(&pdev->dev, "Failed to add adapter %d\n", i); + goto add_adapter_failed; + } + } + + dev_dbg(&pdev->dev, "%d port mux on %s adapter\n", + mux->data.n_values, mux->parent->name); + + return 0; + +add_adapter_failed: + for (; i > 0; i--) + i2c_del_mux_adapter(mux->adap[i - 1]); + + return ret; +} + +static int i2c_mux_reg_remove(struct platform_device *pdev) +{ + struct regmux *mux = platform_get_drvdata(pdev); + int i; + + for (i = 0; i < mux->data.n_values; i++) + i2c_del_mux_adapter(mux->adap[i]); + + i2c_put_adapter(mux->parent); + + return 0; +} + +static const struct of_device_id i2c_mux_reg_of_match[] = { + { .compatible = "i2c-mux-reg", }, + {}, +}; +MODULE_DEVICE_TABLE(of, i2c_mux_reg_of_match); + +static struct platform_driver i2c_mux_reg_driver = { + .probe = i2c_mux_reg_probe, + .remove = i2c_mux_reg_remove, + .driver = { + .name = "i2c-mux-reg", + }, +}; + +module_platform_driver(i2c_mux_reg_driver); + +MODULE_DESCRIPTION("Register-based I2C multiplexer driver"); +MODULE_AUTHOR("York Sun "); +MODULE_LICENSE("GPL"); +MODULE_ALIAS("platform:i2c-mux-reg"); diff --git a/include/linux/platform_data/i2c-mux-reg.h b/include/linux/platform_data/i2c-mux-reg.h new file mode 100644 index 0000000..c68712a --- /dev/null +++ b/include/linux/platform_data/i2c-mux-reg.h @@ -0,0 +1,44 @@ +/* + * I2C multiplexer using a single register + * + * Copyright 2015 Freescale Semiconductor + * York Sun + * + * 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. + */ + +#ifndef __LINUX_PLATFORM_DATA_I2C_MUX_REG_H +#define __LINUX_PLATFORM_DATA_I2C_MUX_REG_H + +/** + * struct i2c_mux_reg_platform_data - Platform-dependent data for i2c-mux-reg + * @parent: Parent I2C bus adapter number + * @base_nr: Base I2C bus number to number adapters from or zero for dynamic + * @values: Array of value for each channel + * @n_values: Number of multiplexer channels + * @little_endian: Indicating if the register is in little endian + * @write_only: Reading the register is not allowed by hardware + * @classes: Optional I2C auto-detection classes + * @idle: Value to write to mux when idle + * @idle_in_use: indicate if idle value is in use + * @reg: Virtual address of the register to switch channel + * @reg_size: register size in bytes + */ +struct i2c_mux_reg_platform_data { + int parent; + int base_nr; + const unsigned int *values; + int n_values; + bool little_endian; + bool write_only; + const unsigned int *classes; + u32 idle; + bool idle_in_use; + void __iomem *reg; + resource_size_t reg_size; +}; + +#endif /* __LINUX_PLATFORM_DATA_I2C_MUX_REG_H */ -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/