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

Commit 2618c12d authored by Bhaumik Bhatt's avatar Bhaumik Bhatt
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 506b4826
Loading
Loading
Loading
Loading
+76 −2
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@
#include <linux/list.h>
#include <linux/of.h>
#include <linux/module.h>
#include <linux/random.h>
#include <linux/slab.h>
#include <linux/wait.h>
#include <linux/mhi.h>
@@ -96,6 +97,25 @@ const char *to_mhi_pm_state_str(enum MHI_PM_STATE state)
	return mhi_pm_state_str[index];
}

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);
}

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,
			 struct device_attribute *attr,
			 char *buf)
@@ -108,7 +128,8 @@ static ssize_t time_show(struct device *dev,
	ret = mhi_get_remote_time_sync(mhi_dev, &t_host, &t_device);
	if (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",
@@ -128,7 +149,8 @@ static ssize_t time_us_show(struct device *dev,
	ret = mhi_get_remote_time_sync(mhi_dev, &t_host, &t_device);
	if (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",
@@ -137,9 +159,59 @@ static ssize_t time_us_show(struct device *dev,
}
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[] = {
	&dev_attr_time.attr,
	&dev_attr_time_us.attr,
	&dev_attr_time_async.attr,
	&dev_attr_time_us_async.attr,
	NULL,
};

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

	mhi_tsync->db_support = true;

	time_cfg_offset = time_offset + TIMESYNC_CFG_OFFSET;

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

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

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