From patchwork Wed Aug 16 13:22:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulrich Hecht X-Patchwork-Id: 9903789 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0E64460231 for ; Wed, 16 Aug 2017 13:22:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0061E289E7 for ; Wed, 16 Aug 2017 13:22:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E8E5C289EE; Wed, 16 Aug 2017 13:22:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5B4D3289E7 for ; Wed, 16 Aug 2017 13:22:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751695AbdHPNWp (ORCPT ); Wed, 16 Aug 2017 09:22:45 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:38062 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751638AbdHPNWn (ORCPT ); Wed, 16 Aug 2017 09:22:43 -0400 Received: by mail-wr0-f193.google.com with SMTP id g32so3046061wrd.5; Wed, 16 Aug 2017 06:22:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=OcEWFiBLW1osIKOYSEisvKZwCvGNiQOz9Y3Ni7j8jWY=; b=jTwMTT1Au0HeUFLmXPKwuVoKBvUNB+ym/KkMyefx/xNK2T0WsE/YXzF4qiFwcvCFCK 4GOdQfZ3H/p8d5tIMZyEetywoJoGDQ2aeT6o2ESPRsqx1HXpzpa4PFIbqoGdy5RsjxR+ rawO3YP6xCyKsDAtDFXcyKBOxabE9fNVwhDBRvga7PuEhtccumcZJYaIJW5Pt/vJ9EYP gti6hUFMTiqTELEDpjPjA5Um0+7AaLYInAi9Hbn+mNFPO3DxSTGCW+vEqwxz4Mx6QtBD QWSN007vWTMk/Jz3r2uJ36VFcn0j6BwTVutivkHHscvVw3wsKf7r3OW9xVorlOwsxeQe WkSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=OcEWFiBLW1osIKOYSEisvKZwCvGNiQOz9Y3Ni7j8jWY=; b=f17L2HqCipTtXjYHzQ9f87twsi7XnbSYTH5bY/VOWrgEPiKOn3se9LSupirb6mighd 1vtLNbf+q/YIjscK/hg4DdU5F4UgA3iUSc640aJTDdL3quDWVkmmOkc5kHO4NGdxDaZX 39/zVPtH/xS/nwtX741jQ0Im3ZqOTNRgT+AzaYHZx+ze2+DMexKTSP/+l98toh3R+sKI 8meQ7cRatGlehjCVj7MGiClhmLQP3YvNjfxKiNFKw1Dk7Wna8nvf31kdR69v8Ays7JMC LQajCNOWibPYtzsZa1/DAiuAvMJJ2Cr8+rZ4SWnUQ0vqP7kUpZiWPr+Zgx3CIxjdkE/e fSPQ== X-Gm-Message-State: AHYfb5jXgz90QaLW514mTKAKF/fZN8BSOjEVSIAaL2KQvq2gfPRbb2jv Etnco95TUR0tdSWMbjg= X-Received: by 10.28.232.29 with SMTP id f29mr115929wmh.181.1502889761569; Wed, 16 Aug 2017 06:22:41 -0700 (PDT) Received: from groucho.site (ipbcc2817c.dynamic.kabel-deutschland.de. [188.194.129.124]) by smtp.gmail.com with ESMTPSA id m130sm1054894wma.27.2017.08.16.06.22.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 16 Aug 2017 06:22:40 -0700 (PDT) From: Ulrich Hecht To: linux-serial@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, magnus.damm@gmail.com, laurent.pinchart@ideasonboard.com, wsa@the-dreams.de, robh@kernel.org, peda@axentia.se, geert@linux-m68k.org, linux-i2c@vger.kernel.org, Ulrich Hecht Subject: [PATCH 2/6] serdev: add multiplexer support Date: Wed, 16 Aug 2017 15:22:24 +0200 Message-Id: <1502889748-31499-3-git-send-email-ulrich.hecht+renesas@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1502889748-31499-1-git-send-email-ulrich.hecht+renesas@gmail.com> References: <1502889748-31499-1-git-send-email-ulrich.hecht+renesas@gmail.com> Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Adds an interface for slave device multiplexing using the mux subsystem. Signed-off-by: Ulrich Hecht --- drivers/tty/serdev/Kconfig | 1 + drivers/tty/serdev/Makefile | 2 +- drivers/tty/serdev/core.c | 13 ++++++++- drivers/tty/serdev/mux.c | 66 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/serdev.h | 14 ++++++++-- 5 files changed, 92 insertions(+), 4 deletions(-) create mode 100644 drivers/tty/serdev/mux.c diff --git a/drivers/tty/serdev/Kconfig b/drivers/tty/serdev/Kconfig index cdc6b82..8fd75cb 100644 --- a/drivers/tty/serdev/Kconfig +++ b/drivers/tty/serdev/Kconfig @@ -3,6 +3,7 @@ # menuconfig SERIAL_DEV_BUS tristate "Serial device bus" + select MULTIPLEXER help Core support for devices connected via a serial port. diff --git a/drivers/tty/serdev/Makefile b/drivers/tty/serdev/Makefile index 0cbdb94..abe5b2a 100644 --- a/drivers/tty/serdev/Makefile +++ b/drivers/tty/serdev/Makefile @@ -1,5 +1,5 @@ serdev-objs := core.o -obj-$(CONFIG_SERIAL_DEV_BUS) += serdev.o +obj-$(CONFIG_SERIAL_DEV_BUS) += serdev.o mux.o obj-$(CONFIG_SERIAL_DEV_CTRL_TTYPORT) += serdev-ttyport.o diff --git a/drivers/tty/serdev/core.c b/drivers/tty/serdev/core.c index 8491056..22acd08 100644 --- a/drivers/tty/serdev/core.c +++ b/drivers/tty/serdev/core.c @@ -307,7 +307,8 @@ struct serdev_device *serdev_device_alloc(struct serdev_controller *ctrl) return NULL; serdev->ctrl = ctrl; - ctrl->serdev = serdev; + if (!ctrl->serdev) + ctrl->serdev = serdev; device_initialize(&serdev->dev); serdev->dev.parent = &ctrl->dev; serdev->dev.bus = &serdev_bus_type; @@ -370,6 +371,7 @@ static int of_serdev_register_devices(struct serdev_controller *ctrl) struct serdev_device *serdev = NULL; int err; bool found = false; + u32 reg; for_each_available_child_of_node(ctrl->dev.of_node, node) { if (!of_get_property(node, "compatible", NULL)) @@ -383,6 +385,11 @@ static int of_serdev_register_devices(struct serdev_controller *ctrl) serdev->dev.of_node = node; + if (!of_property_read_u32(node, "reg", ®)) { + serdev->mux_addr = reg; + serdev->nr = reg; + } + err = serdev_device_add(serdev); if (err) { dev_err(&serdev->dev, @@ -416,6 +423,10 @@ int serdev_controller_add(struct serdev_controller *ctrl) if (ret) return ret; + if (ctrl->dev.of_node && + of_serdev_register_mux(ctrl) == -EPROBE_DEFER) + return -EPROBE_DEFER; + ret = of_serdev_register_devices(ctrl); if (ret) goto out_dev_del; diff --git a/drivers/tty/serdev/mux.c b/drivers/tty/serdev/mux.c new file mode 100644 index 0000000..fc9405b --- /dev/null +++ b/drivers/tty/serdev/mux.c @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2017 Ulrich Hecht + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 and + * only version 2 as published by the Free Software Foundation. + * + * 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. + */ + +#include +#include +#include +#include +#include + +int serdev_device_mux_select(struct serdev_device *serdev) +{ + struct mux_control *mux = serdev->ctrl->mux; + int ret; + + if (!mux) + return -EINVAL; + + ret = mux_control_select(mux, serdev->mux_addr); + serdev->ctrl->mux_do_not_deselect = ret < 0; + + serdev->ctrl->serdev = serdev; + + return ret; +} + +int serdev_device_mux_deselect(struct serdev_device *serdev) +{ + struct mux_control *mux = serdev->ctrl->mux; + + if (!mux) + return -EINVAL; + + if (!serdev->ctrl->mux_do_not_deselect) + return mux_control_deselect(mux); + else + return 0; +} + +int of_serdev_register_mux(struct serdev_controller *ctrl) +{ + struct mux_control *mux; + struct device *dev = &ctrl->dev; + + mux = devm_mux_control_get(dev, NULL); + + if (IS_ERR(mux)) { + if (PTR_ERR(mux) != -EPROBE_DEFER) + dev_err(dev, "failed to get control mux\n"); + return PTR_ERR(mux); + } + + ctrl->mux = mux; + + return 0; +} + diff --git a/include/linux/serdev.h b/include/linux/serdev.h index 8f60f11..3ed0f75 100644 --- a/include/linux/serdev.h +++ b/include/linux/serdev.h @@ -17,6 +17,7 @@ #include #include #include +#include struct serdev_controller; struct serdev_device; @@ -51,6 +52,7 @@ struct serdev_device { const struct serdev_device_ops *ops; struct completion write_comp; struct mutex write_lock; + int mux_addr; }; static inline struct serdev_device *to_serdev_device(struct device *d) @@ -82,6 +84,8 @@ enum serdev_parity { SERDEV_PARITY_ODD, }; +int of_serdev_register_mux(struct serdev_controller *ctrl); + /* * serdev controller structures */ @@ -103,14 +107,18 @@ struct serdev_controller_ops { * struct serdev_controller - interface to the serdev controller * @dev: Driver model representation of the device. * @nr: number identifier for this controller/bus. - * @serdev: Pointer to slave device for this controller. + * @serdev: Pointer to active slave device for this controller. * @ops: Controller operations. + * @mux: Slave multiplexer control. + * @mux_do_not_deselect: Set if slave selection failed. */ struct serdev_controller { struct device dev; unsigned int nr; struct serdev_device *serdev; const struct serdev_controller_ops *ops; + struct mux_control *mux; + int mux_do_not_deselect; }; static inline struct serdev_controller *to_serdev_controller(struct device *d) @@ -190,7 +198,7 @@ static inline int serdev_controller_receive_buf(struct serdev_controller *ctrl, { struct serdev_device *serdev = ctrl->serdev; - if (!serdev || !serdev->ops->receive_buf) + if (!serdev || !serdev->ops || !serdev->ops->receive_buf) return -EINVAL; return serdev->ops->receive_buf(serdev, data, count); @@ -210,6 +218,8 @@ void serdev_device_write_wakeup(struct serdev_device *); int serdev_device_write(struct serdev_device *, const unsigned char *, size_t, unsigned long); void serdev_device_write_flush(struct serdev_device *); int serdev_device_write_room(struct serdev_device *); +int serdev_device_mux_select(struct serdev_device *); +int serdev_device_mux_deselect(struct serdev_device *); /* * serdev device driver functions