linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
To: gregkh@linuxfoundation.org, arnd@arndb.de
Cc: smohanad@codeaurora.org, jhugo@codeaurora.org,
	kvalo@codeaurora.org, bjorn.andersson@linaro.org,
	hemantk@codeaurora.org, linux-arm-msm@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Subject: [PATCH 04/16] bus: mhi: core: Add support for creating and destroying MHI devices
Date: Thu, 23 Jan 2020 16:48:24 +0530	[thread overview]
Message-ID: <20200123111836.7414-5-manivannan.sadhasivam@linaro.org> (raw)
In-Reply-To: <20200123111836.7414-1-manivannan.sadhasivam@linaro.org>

This commit adds support for creating and destroying MHI devices. The
MHI devices binds to the MHI channels and are used to transfer data
between MHI host and client device.

This is based on the patch submitted by Sujeev Dias:
https://lkml.org/lkml/2018/7/9/989

Signed-off-by: Sujeev Dias <sdias@codeaurora.org>
Signed-off-by: Siddartha Mohanadoss <smohanad@codeaurora.org>
[mani: splitted from pm patch and cleaned up for upstream]
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
---
 drivers/bus/mhi/core/Makefile   |   2 +-
 drivers/bus/mhi/core/internal.h |   1 +
 drivers/bus/mhi/core/main.c     | 123 ++++++++++++++++++++++++++++++++
 include/linux/mhi.h             |   6 ++
 4 files changed, 131 insertions(+), 1 deletion(-)
 create mode 100644 drivers/bus/mhi/core/main.c

diff --git a/drivers/bus/mhi/core/Makefile b/drivers/bus/mhi/core/Makefile
index 2db32697c67f..77f7730da4bf 100644
--- a/drivers/bus/mhi/core/Makefile
+++ b/drivers/bus/mhi/core/Makefile
@@ -1,3 +1,3 @@
 obj-$(CONFIG_MHI_BUS) := mhi.o
 
-mhi-y := init.o
+mhi-y := init.o main.o
diff --git a/drivers/bus/mhi/core/internal.h b/drivers/bus/mhi/core/internal.h
index 21f686d3a140..ea7f1d7b0129 100644
--- a/drivers/bus/mhi/core/internal.h
+++ b/drivers/bus/mhi/core/internal.h
@@ -140,6 +140,7 @@ struct mhi_chan {
 	bool offload_ch;
 	bool pre_alloc;
 	bool auto_start;
+	bool wake_capable;
 	int (*gen_tre)(struct mhi_controller *mhi_cntrl,
 		       struct mhi_chan *mhi_chan, void *buf, void *cb,
 		       size_t len, enum mhi_flags flags);
diff --git a/drivers/bus/mhi/core/main.c b/drivers/bus/mhi/core/main.c
new file mode 100644
index 000000000000..216fd8691140
--- /dev/null
+++ b/drivers/bus/mhi/core/main.c
@@ -0,0 +1,123 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2018-2020, The Linux Foundation. All rights reserved.
+ *
+ */
+
+#define dev_fmt(fmt) "MHI: " fmt
+
+#include <linux/device.h>
+#include <linux/dma-direction.h>
+#include <linux/dma-mapping.h>
+#include <linux/interrupt.h>
+#include <linux/list.h>
+#include <linux/mhi.h>
+#include <linux/module.h>
+#include <linux/skbuff.h>
+#include <linux/slab.h>
+#include "internal.h"
+
+int mhi_destroy_device(struct device *dev, void *data)
+{
+	struct mhi_device *mhi_dev;
+	struct mhi_controller *mhi_cntrl;
+
+	if (dev->bus != &mhi_bus_type)
+		return 0;
+
+	mhi_dev = to_mhi_device(dev);
+	mhi_cntrl = mhi_dev->mhi_cntrl;
+
+	/* Only destroy virtual devices thats attached to bus */
+	if (mhi_dev->dev_type ==  MHI_DEVICE_CONTROLLER)
+		return 0;
+
+	dev_dbg(mhi_cntrl->dev, "destroy device for chan:%s\n",
+		 mhi_dev->chan_name);
+
+	/* Notify the client and remove the device from MHI bus */
+	device_del(dev);
+	put_device(dev);
+
+	return 0;
+}
+
+static void mhi_notify(struct mhi_device *mhi_dev, enum mhi_callback cb_reason)
+{
+	struct mhi_driver *mhi_drv;
+
+	if (!mhi_dev->dev.driver)
+		return;
+
+	mhi_drv = to_mhi_driver(mhi_dev->dev.driver);
+
+	if (mhi_drv->status_cb)
+		mhi_drv->status_cb(mhi_dev, cb_reason);
+}
+
+/* Bind MHI channels to MHI devices */
+void mhi_create_devices(struct mhi_controller *mhi_cntrl)
+{
+	int i;
+	struct mhi_chan *mhi_chan;
+	struct mhi_device *mhi_dev;
+	int ret;
+
+	mhi_chan = mhi_cntrl->mhi_chan;
+	for (i = 0; i < mhi_cntrl->max_chan; i++, mhi_chan++) {
+		if (!mhi_chan->configured || mhi_chan->mhi_dev ||
+		    !(mhi_chan->ee_mask & BIT(mhi_cntrl->ee)))
+			continue;
+		mhi_dev = mhi_alloc_device(mhi_cntrl);
+		if (!mhi_dev)
+			return;
+
+		mhi_dev->dev_type = MHI_DEVICE_XFER;
+		switch (mhi_chan->dir) {
+		case DMA_TO_DEVICE:
+			mhi_dev->ul_chan = mhi_chan;
+			mhi_dev->ul_chan_id = mhi_chan->chan;
+			break;
+		case DMA_FROM_DEVICE:
+			/* We use dl_chan as offload channels */
+			mhi_dev->dl_chan = mhi_chan;
+			mhi_dev->dl_chan_id = mhi_chan->chan;
+			break;
+		default:
+			dev_err(mhi_cntrl->dev, "Direction not supported\n");
+			mhi_dealloc_device(mhi_cntrl, mhi_dev);
+			return;
+		}
+
+		mhi_chan->mhi_dev = mhi_dev;
+
+		/* Check next channel if it matches */
+		if ((i + 1) < mhi_cntrl->max_chan && mhi_chan[1].configured) {
+			if (!strcmp(mhi_chan[1].name, mhi_chan->name)) {
+				i++;
+				mhi_chan++;
+				if (mhi_chan->dir == DMA_TO_DEVICE) {
+					mhi_dev->ul_chan = mhi_chan;
+					mhi_dev->ul_chan_id = mhi_chan->chan;
+				} else {
+					mhi_dev->dl_chan = mhi_chan;
+					mhi_dev->dl_chan_id = mhi_chan->chan;
+				}
+				mhi_chan->mhi_dev = mhi_dev;
+			}
+		}
+
+		/* Channel name is same for both UL and DL */
+		mhi_dev->chan_name = mhi_chan->name;
+		dev_set_name(&mhi_dev->dev, "%04x_%s", mhi_chan->chan,
+			     mhi_dev->chan_name);
+
+		/* Init wakeup source if available */
+		if (mhi_dev->dl_chan && mhi_dev->dl_chan->wake_capable)
+			device_init_wakeup(&mhi_dev->dev, true);
+
+		ret = device_add(&mhi_dev->dev);
+		if (ret)
+			mhi_dealloc_device(mhi_cntrl, mhi_dev);
+	}
+}
diff --git a/include/linux/mhi.h b/include/linux/mhi.h
index 0fdad987dd70..cb6ddd23463c 100644
--- a/include/linux/mhi.h
+++ b/include/linux/mhi.h
@@ -166,6 +166,7 @@ enum mhi_db_brst_mode {
  * @doorbell_mode_switch: Channel switches to doorbell mode on M0 transition
  * @auto_queue: Framework will automatically queue buffers for DL traffic
  * @auto_start: Automatically start (open) this channel
+ * @wake-capable: Channel capable of waking up the system
  */
 struct mhi_channel_config {
 	u32 num;
@@ -184,6 +185,7 @@ struct mhi_channel_config {
 	bool doorbell_mode_switch;
 	bool auto_queue;
 	bool auto_start;
+	bool wake_capable;
 };
 
 /**
@@ -365,6 +367,8 @@ struct mhi_controller {
  * struct mhi_device - Structure representing a MHI device which binds
  *                     to channels
  * @dev: Driver model device node for the MHI device
+ * @ul_chan_id: MHI channel id for UL transfer
+ * @dl_chan_id: MHI channel id for DL transfer
  * @tiocm: Device current terminal settings
  * @id: Pointer to MHI device ID struct
  * @chan_name: Name of the channel to which the device binds
@@ -376,6 +380,8 @@ struct mhi_controller {
  */
 struct mhi_device {
 	struct device dev;
+	int ul_chan_id;
+	int dl_chan_id;
 	u32 tiocm;
 	const struct mhi_device_id *id;
 	const char *chan_name;
-- 
2.17.1


  parent reply	other threads:[~2020-01-23 11:19 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-23 11:18 [PATCH 00/16] Add MHI bus support Manivannan Sadhasivam
2020-01-23 11:18 ` [PATCH 01/16] docs: Add documentation for MHI bus Manivannan Sadhasivam
2020-01-23 12:58   ` Arnd Bergmann
2020-01-23 13:10     ` Manivannan Sadhasivam
2020-01-23 13:19       ` Arnd Bergmann
2020-01-23 13:30         ` Manivannan Sadhasivam
2020-01-23 14:52           ` Jeffrey Hugo
2020-01-23 16:41   ` Jeffrey Hugo
2020-01-27 12:02     ` Manivannan Sadhasivam
2020-01-23 11:18 ` [PATCH 02/16] bus: mhi: core: Add support for registering MHI controllers Manivannan Sadhasivam
2020-01-23 11:33   ` Greg KH
2020-01-23 11:56     ` Manivannan Sadhasivam
2020-01-23 17:05   ` Jeffrey Hugo
2020-01-23 18:14     ` Greg KH
2020-01-26 23:58     ` Jeffrey Hugo
2020-01-28  7:19       ` Manivannan Sadhasivam
2020-01-27 11:56     ` Manivannan Sadhasivam
2020-01-27 14:52       ` Jeffrey Hugo
2020-01-28  6:37         ` Manivannan Sadhasivam
2020-01-28  7:24           ` Greg KH
2020-01-28  7:27             ` Manivannan Sadhasivam
2020-01-24  8:29   ` Greg KH
2020-01-24 14:24     ` Jeffrey Hugo
2020-01-24 17:47       ` Greg KH
2020-01-24 18:12         ` Jeffrey Hugo
2020-01-25 13:26           ` Greg KH
2020-01-26 21:00             ` Jeffrey Hugo
2020-01-27  7:02       ` Manivannan Sadhasivam
2020-01-27  7:11         ` Greg KH
2020-01-23 11:18 ` [PATCH 03/16] bus: mhi: core: Add support for registering MHI client drivers Manivannan Sadhasivam
2020-01-23 11:18 ` Manivannan Sadhasivam [this message]
2020-01-23 11:18 ` [PATCH 05/16] bus: mhi: core: Add support for ringing channel/event ring doorbells Manivannan Sadhasivam
2020-01-23 11:39   ` Arnd Bergmann
2020-01-23 12:00     ` Manivannan Sadhasivam
2020-01-23 12:44       ` Arnd Bergmann
2020-01-23 13:01         ` Manivannan Sadhasivam
2020-01-23 14:44       ` Jeffrey Hugo
2020-01-24 22:51   ` Jeffrey Hugo
2020-01-25 13:46     ` Greg KH
2020-01-27  7:10       ` Manivannan Sadhasivam
2020-01-27  7:21         ` Greg KH
2020-01-23 11:18 ` [PATCH 06/16] bus: mhi: core: Add support for PM state transitions Manivannan Sadhasivam
2020-01-23 11:18 ` [PATCH 07/16] bus: mhi: core: Add support for basic PM operations Manivannan Sadhasivam
2020-01-23 11:18 ` [PATCH 08/16] bus: mhi: core: Add support for downloading firmware over BHIe Manivannan Sadhasivam
2020-01-28 19:36   ` Jeffrey Hugo
2020-01-29  6:56     ` Manivannan Sadhasivam
2020-01-23 11:18 ` [PATCH 09/16] bus: mhi: core: Add support for downloading RDDM image during panic Manivannan Sadhasivam
2020-01-23 11:18 ` [PATCH 10/16] bus: mhi: core: Add support for processing events from client device Manivannan Sadhasivam
2020-01-23 11:18 ` [PATCH 11/16] bus: mhi: core: Add support for data transfer Manivannan Sadhasivam
2020-01-23 11:18 ` [PATCH 12/16] bus: mhi: core: Add uevent support for module autoloading Manivannan Sadhasivam
2020-01-23 11:18 ` [PATCH 13/16] MAINTAINERS: Add entry for MHI bus Manivannan Sadhasivam
2020-01-23 11:18 ` [PATCH 14/16] net: qrtr: Add MHI transport layer Manivannan Sadhasivam
2020-01-23 11:18 ` [PATCH 15/16] net: qrtr: Do not depend on ARCH_QCOM Manivannan Sadhasivam
2020-01-23 11:18 ` [PATCH 16/16] soc: qcom: Do not depend on ARCH_QCOM for QMI helpers Manivannan Sadhasivam
2020-01-23 11:45   ` Arnd Bergmann
2020-01-23 12:03     ` Manivannan Sadhasivam

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200123111836.7414-5-manivannan.sadhasivam@linaro.org \
    --to=manivannan.sadhasivam@linaro.org \
    --cc=arnd@arndb.de \
    --cc=bjorn.andersson@linaro.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=hemantk@codeaurora.org \
    --cc=jhugo@codeaurora.org \
    --cc=kvalo@codeaurora.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=smohanad@codeaurora.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).