Minor Comment!
On 10/11/17 11:49, Vinod Koul wrote:
From: Sanyog Kale <sanyog.r.kale@xxxxxxxxx>
SoundWire Slaves report status to bus. Add helpers to handle
the status changes.
Signed-off-by: Hardik T Shah <hardik.t.shah@xxxxxxxxx>
Signed-off-by: Sanyog Kale <sanyog.r.kale@xxxxxxxxx>
Signed-off-by: Vinod Koul <vinod.koul@xxxxxxxxx>
---
+static int sdw_compare_devid(struct sdw_slave *slave, struct sdw_slave_id id)
+{
+
+ if ((slave->id.unique_id != id.unique_id) ||
+ (slave->id.mfg_id != id.mfg_id) ||
+ (slave->id.part_id != id.part_id) ||
+ (slave->id.class_id != id.class_id))
+ return -ENODEV;
+
+ return 0;
+}
+
+/* called with bus_lock held */
+static int sdw_get_device_num(struct sdw_slave *slave)
+{
If we use ida we would not need this function.
+ int bit;
+
+ bit = find_first_zero_bit(slave->bus->assigned, SDW_MAX_DEVICES);
+ if (bit == SDW_MAX_DEVICES) {
+ bit = -ENODEV;
+ goto err;
+ }
+
+ /*
+ * Do not update dev_num in Slave data structure here,
+ * Update once program dev_num is successful
+ */
+ set_bit(bit, slave->bus->assigned);
+
+err:
+ return bit;
+}
+
+static int sdw_assign_device_num(struct sdw_slave *slave)
+{
+ int ret, dev_num;
+
+ /* check first if device number is assigned, if so reuse that */
+ if (!slave->dev_num) {
+ mutex_lock(&slave->bus->bus_lock);
+ dev_num = sdw_get_device_num(slave);
+ mutex_unlock(&slave->bus->bus_lock);
+ if (dev_num < 0) {
+ dev_err(slave->bus->dev, "Get dev_num failed: %d",
+ dev_num);
+ return dev_num;
+ }
+ } else {
+ dev_info(slave->bus->dev,
+ "Slave already registered dev_num:%d",
+ slave->dev_num);
+
+ /* Clear the slave->dev_num to transfer message on device 0 */
+ dev_num = slave->dev_num;
+ slave->dev_num = 0;
+
+ }
+
+ ret = sdw_write(slave, SDW_SCP_DEVNUMBER, dev_num);
+ if (ret < 0) {
+ dev_err(&slave->dev, "Program device_num failed: %d", ret);
+ return ret;
+ }
+
+ /* After xfer of msg, restore dev_num */
+ slave->dev_num = dev_num;
+
+ return 0;
+}
+
void sdw_extract_slave_id(struct sdw_bus *bus,
u64 addr, struct sdw_slave_id *id)
{
@@ -447,3 +534,129 @@ void sdw_extract_slave_id(struct sdw_bus *bus,
id->unique_id, id->sdw_version);
}
+
_______________________________________________
Alsa-devel mailing list
Alsa-devel@xxxxxxxxxxxxxxxx
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel