mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-08 12:58:12 -04:00
Merge "mhi: core: remove duplicate timesync sysfs functions"
This commit is contained in:
commit
c16557c4cf
3 changed files with 80 additions and 74 deletions
|
|
@ -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>
|
||||
|
|
@ -98,6 +99,25 @@ const char *to_mhi_pm_state_str(enum MHI_PM_STATE state)
|
|||
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,
|
||||
struct device_attribute *attr,
|
||||
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);
|
||||
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",
|
||||
|
|
@ -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);
|
||||
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",
|
||||
|
|
@ -139,9 +161,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,
|
||||
};
|
||||
|
||||
|
|
@ -725,6 +797,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 */
|
||||
|
|
|
|||
|
|
@ -727,6 +727,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;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -797,75 +797,6 @@ static void mhi_assign_of_node(struct mhi_controller *mhi_cntrl,
|
|||
}
|
||||
}
|
||||
|
||||
static ssize_t time_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;
|
||||
u64 t_host, t_device;
|
||||
int ret;
|
||||
|
||||
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, "local: %llu remote: %llu (ticks)\n",
|
||||
t_host, t_device);
|
||||
}
|
||||
static DEVICE_ATTR_RO(time);
|
||||
|
||||
static ssize_t time_us_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;
|
||||
u64 t_host, t_device;
|
||||
int ret;
|
||||
|
||||
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, "local: %llu remote: %llu (us)\n",
|
||||
LOCAL_TICKS_TO_US(t_host),
|
||||
REMOTE_TICKS_TO_US(t_device));
|
||||
}
|
||||
static DEVICE_ATTR_RO(time_us);
|
||||
|
||||
static struct attribute *mhi_tsync_attrs[] = {
|
||||
&dev_attr_time.attr,
|
||||
&dev_attr_time_us.attr,
|
||||
NULL,
|
||||
};
|
||||
|
||||
static const struct attribute_group mhi_tsync_group = {
|
||||
.attrs = mhi_tsync_attrs,
|
||||
};
|
||||
|
||||
void mhi_destroy_timesync(struct mhi_controller *mhi_cntrl)
|
||||
{
|
||||
if (mhi_cntrl->mhi_tsync) {
|
||||
mutex_lock(&mhi_cntrl->tsync_mutex);
|
||||
sysfs_remove_group(&mhi_cntrl->mhi_dev->dev.kobj,
|
||||
&mhi_tsync_group);
|
||||
kfree(mhi_cntrl->mhi_tsync);
|
||||
mhi_cntrl->mhi_tsync = NULL;
|
||||
mutex_unlock(&mhi_cntrl->tsync_mutex);
|
||||
}
|
||||
}
|
||||
|
||||
int mhi_create_timesync_sysfs(struct mhi_controller *mhi_cntrl)
|
||||
{
|
||||
return sysfs_create_group(&mhi_cntrl->mhi_dev->dev.kobj,
|
||||
&mhi_tsync_group);
|
||||
}
|
||||
|
||||
/* bind mhi channels into mhi devices */
|
||||
void mhi_create_devices(struct mhi_controller *mhi_cntrl)
|
||||
{
|
||||
|
|
@ -2545,7 +2476,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 error_unlock;
|
||||
|
|
@ -2620,9 +2551,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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue