Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 34e46f48 authored by Bhaumik Bhatt's avatar Bhaumik Bhatt Committed by Gerrit - the friendly Code Review server
Browse files

mhi: core: add asynchronous time request support in sysfs



Add support to request time from device using the asynchronous
method in ticks and microseconds using sysfs entries.

Change-Id: Idb661ad6db9f1cc4cd594c96755986ece4961b03
Signed-off-by: default avatarBhaumik Bhatt <bbhatt@codeaurora.org>
parent 6d967e6d
Loading
Loading
Loading
Loading
+76 −2
Original line number Original line Diff line number Diff line
@@ -9,6 +9,7 @@
#include <linux/list.h>
#include <linux/list.h>
#include <linux/of.h>
#include <linux/of.h>
#include <linux/module.h>
#include <linux/module.h>
#include <linux/random.h>
#include <linux/slab.h>
#include <linux/slab.h>
#include <linux/wait.h>
#include <linux/wait.h>
#include <linux/mhi.h>
#include <linux/mhi.h>
@@ -98,6 +99,25 @@ const char *to_mhi_pm_state_str(enum MHI_PM_STATE state)
	return mhi_pm_state_str[index];
	return mhi_pm_state_str[index];
}
}


static void mhi_time_async_cb(struct mhi_device *mhi_dev, u32 sequence,
		       u64 local_time, u64 remote_time)
{
	struct mhi_controller *mhi_cntrl = mhi_dev->mhi_cntrl;

	MHI_LOG("Time response: seq:%llx local: %llu remote: %llu (ticks)\n",
		sequence, local_time, remote_time);
}

static void mhi_time_us_async_cb(struct mhi_device *mhi_dev, u32 sequence,
			  u64 local_time, u64 remote_time)
{
	struct mhi_controller *mhi_cntrl = mhi_dev->mhi_cntrl;

	MHI_LOG("Time response: seq:%llx local: %llu remote: %llu (us)\n",
		sequence, LOCAL_TICKS_TO_US(local_time),
		REMOTE_TICKS_TO_US(remote_time));
}

static ssize_t time_show(struct device *dev,
static ssize_t time_show(struct device *dev,
			 struct device_attribute *attr,
			 struct device_attribute *attr,
			 char *buf)
			 char *buf)
@@ -110,7 +130,8 @@ static ssize_t time_show(struct device *dev,
	ret = mhi_get_remote_time_sync(mhi_dev, &t_host, &t_device);
	ret = mhi_get_remote_time_sync(mhi_dev, &t_host, &t_device);
	if (ret) {
	if (ret) {
		MHI_ERR("Failed to obtain time, ret:%d\n", ret);
		MHI_ERR("Failed to obtain time, ret:%d\n", ret);
		return ret;
		return scnprintf(buf, PAGE_SIZE,
				 "Request failed or feature unsupported\n");
	}
	}


	return scnprintf(buf, PAGE_SIZE, "local: %llu remote: %llu (ticks)\n",
	return scnprintf(buf, PAGE_SIZE, "local: %llu remote: %llu (ticks)\n",
@@ -130,7 +151,8 @@ static ssize_t time_us_show(struct device *dev,
	ret = mhi_get_remote_time_sync(mhi_dev, &t_host, &t_device);
	ret = mhi_get_remote_time_sync(mhi_dev, &t_host, &t_device);
	if (ret) {
	if (ret) {
		MHI_ERR("Failed to obtain time, ret:%d\n", ret);
		MHI_ERR("Failed to obtain time, ret:%d\n", ret);
		return ret;
		return scnprintf(buf, PAGE_SIZE,
				 "Request failed or feature unsupported\n");
	}
	}


	return scnprintf(buf, PAGE_SIZE, "local: %llu remote: %llu (us)\n",
	return scnprintf(buf, PAGE_SIZE, "local: %llu remote: %llu (us)\n",
@@ -139,9 +161,59 @@ static ssize_t time_us_show(struct device *dev,
}
}
static DEVICE_ATTR_RO(time_us);
static DEVICE_ATTR_RO(time_us);


static ssize_t time_async_show(struct device *dev,
			       struct device_attribute *attr,
			       char *buf)
{
	struct mhi_device *mhi_dev = to_mhi_device(dev);
	struct mhi_controller *mhi_cntrl = mhi_dev->mhi_cntrl;
	u32 seq = prandom_u32();
	int ret;

	if (!seq)
		seq = 1;

	ret = mhi_get_remote_time(mhi_dev, seq, &mhi_time_async_cb);
	if (ret) {
		MHI_ERR("Failed to request time, seq:%llx, ret:%d\n", seq, ret);
		return scnprintf(buf, PAGE_SIZE,
				 "Request failed or feature unsupported\n");
	}

	return scnprintf(buf, PAGE_SIZE,
			 "Requested time asynchronously with seq:%llx\n", seq);
}
static DEVICE_ATTR_RO(time_async);

static ssize_t time_us_async_show(struct device *dev,
				  struct device_attribute *attr,
				  char *buf)
{
	struct mhi_device *mhi_dev = to_mhi_device(dev);
	struct mhi_controller *mhi_cntrl = mhi_dev->mhi_cntrl;
	u32 seq = prandom_u32();
	int ret;

	if (!seq)
		seq = 1;

	ret = mhi_get_remote_time(mhi_dev, seq, &mhi_time_us_async_cb);
	if (ret) {
		MHI_ERR("Failed to request time, seq:%llx, ret:%d\n", seq, ret);
		return scnprintf(buf, PAGE_SIZE,
				 "Request failed or feature unsupported\n");
	}

	return scnprintf(buf, PAGE_SIZE,
			 "Requested time asynchronously with seq:%llx\n", seq);
}
static DEVICE_ATTR_RO(time_us_async);

static struct attribute *mhi_tsync_attrs[] = {
static struct attribute *mhi_tsync_attrs[] = {
	&dev_attr_time.attr,
	&dev_attr_time.attr,
	&dev_attr_time_us.attr,
	&dev_attr_time_us.attr,
	&dev_attr_time_async.attr,
	&dev_attr_time_us_async.attr,
	NULL,
	NULL,
};
};


@@ -725,6 +797,8 @@ static int mhi_init_timesync(struct mhi_controller *mhi_cntrl)
		return er_index;
		return er_index;
	}
	}


	mhi_tsync->db_support = true;

	time_cfg_offset = time_offset + TIMESYNC_CFG_OFFSET;
	time_cfg_offset = time_offset + TIMESYNC_CFG_OFFSET;


	/* advertise host support */
	/* advertise host support */
+1 −0
Original line number Original line Diff line number Diff line
@@ -727,6 +727,7 @@ struct tsync_node {
struct mhi_timesync {
struct mhi_timesync {
	void __iomem *time_reg;
	void __iomem *time_reg;
	u32 int_sequence;
	u32 int_sequence;
	bool db_support;
	spinlock_t lock; /* list protection */
	spinlock_t lock; /* list protection */
	struct list_head head;
	struct list_head head;
};
};
+3 −3
Original line number Original line Diff line number Diff line
@@ -2545,7 +2545,7 @@ int mhi_get_remote_time_sync(struct mhi_device *mhi_dev,
	int ret;
	int ret;


	mutex_lock(&mhi_cntrl->tsync_mutex);
	mutex_lock(&mhi_cntrl->tsync_mutex);
	/* not all devices support time feature */
	/* not all devices support time features */
	if (!mhi_tsync) {
	if (!mhi_tsync) {
		ret = -EIO;
		ret = -EIO;
		goto error_unlock;
		goto error_unlock;
@@ -2620,9 +2620,9 @@ int mhi_get_remote_time(struct mhi_device *mhi_dev,
	struct tsync_node *tsync_node;
	struct tsync_node *tsync_node;
	int ret;
	int ret;


	/* not all devices support time feature */
	/* not all devices support all time features */
	mutex_lock(&mhi_cntrl->tsync_mutex);
	mutex_lock(&mhi_cntrl->tsync_mutex);
	if (!mhi_tsync) {
	if (!mhi_tsync || !mhi_tsync->db_support) {
		ret = -EIO;
		ret = -EIO;
		goto error_unlock;
		goto error_unlock;
	}
	}