Browse Source

SoC: soundwire: Add support for device wakeup

Add soundwire API to wakeup soundwire master and slave devices.
These APIs will be used by slave driver to vote and unvote for
master wakeup, when it requires master for register access
operations. Master will be aware of the slave usage with the
vote for device wakeup.

Change-Id: Ifa93f35ab2cffba778cd2fd9a2461e5a58445b75
Signed-off-by: Sudheer Papothi <[email protected]>
Signed-off-by: Ramprasad Katkam <[email protected]>
Sudheer Papothi 6 years ago
parent
commit
1b9932e154
2 changed files with 61 additions and 0 deletions
  1. 6 0
      include/soc/soundwire.h
  2. 55 0
      soc/soundwire.c

+ 6 - 0
include/soc/soundwire.h

@@ -167,6 +167,8 @@ struct swr_master {
 				u8 *dev_num);
 	int (*slvdev_datapath_control)(struct swr_master *mstr, bool enable);
 	bool (*remove_from_group)(struct swr_master *mstr);
+	void (*device_wakeup_vote)(struct swr_master *mstr);
+	void (*device_wakeup_unvote)(struct swr_master *mstr);
 	u16 port_en_mask;
 
 };
@@ -334,4 +336,8 @@ extern void swr_remove_device(struct swr_device *swr_dev);
 
 extern struct swr_device *get_matching_swr_slave_device(struct device_node *np);
 
+extern int swr_device_wakeup_vote(struct swr_device *dev);
+
+extern int swr_device_wakeup_unvote(struct swr_device *dev);
+
 #endif /* _LINUX_SOUNDWIRE_H */

+ 55 - 0
soc/soundwire.c

@@ -482,6 +482,61 @@ int swr_get_logical_dev_num(struct swr_device *dev, u64 dev_id,
 }
 EXPORT_SYMBOL(swr_get_logical_dev_num);
 
+/**
+ * swr_device_wakeup_vote - Wakeup master and slave devices from clock stop
+ * @dev: pointer to soundwire slave device
+ *
+ * This API will wake up soundwire master and slave device(s) from
+ * clock stop.
+ */
+int swr_device_wakeup_vote(struct swr_device *dev)
+{
+	int ret = 0;
+	struct swr_master *master = dev->master;
+
+	if (!master) {
+		pr_err("%s: Master is NULL\n", __func__);
+		return -EINVAL;
+	}
+	mutex_lock(&master->mlock);
+	if (master->device_wakeup_vote)
+		master->device_wakeup_vote(master);
+	else
+		ret = -EINVAL;
+	mutex_unlock(&master->mlock);
+
+	return ret;
+}
+EXPORT_SYMBOL(swr_device_wakeup_vote);
+
+/**
+ * swr_device_wakeup_unvote - Unvote Wakeup so that master and slave
+ * devices can go back to  clock stop
+ * @dev: pointer to soundwire slave device
+ *
+ * This API will remove vote for wakeup so that soundwire master and
+ * slave device(s) can go back to clock stop.
+ */
+int swr_device_wakeup_unvote(struct swr_device *dev)
+{
+	int ret = 0;
+	struct swr_master *master = dev->master;
+
+	if (!master) {
+		pr_err("%s: Master is NULL\n", __func__);
+		return -EINVAL;
+	}
+	mutex_lock(&master->mlock);
+	if (master->device_wakeup_unvote)
+		master->device_wakeup_unvote(master);
+	else
+		ret = -EINVAL;
+	mutex_unlock(&master->mlock);
+
+	return ret;
+}
+EXPORT_SYMBOL(swr_device_wakeup_unvote);
+
 /**
  * swr_read - read soundwire slave device registers
  * @dev: pointer to soundwire slave device