soundwire: intel_init: add checks on link numbers
authorPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Wed, 22 May 2019 19:47:31 +0000 (14:47 -0500)
committerVinod Koul <vkoul@kernel.org>
Mon, 27 May 2019 05:23:00 +0000 (10:53 +0530)
Add mask to correctly read the SoundWire SHIM LCAP register. Only bits
2..0 are meaningful, the rest is about link synchronization and stream
channel mapping. Without this mask, the hardware information would
always be larger than whatever the BIOS would report.

Also trap the case with zero links.

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Signed-off-by: Vinod Koul <vkoul@kernel.org>
drivers/soundwire/intel_init.c

index 771a53a5c033b7b983108920064c556ce5c1838b..70637a0383d2a1e75f06e82ec4d68ff32ee168b4 100644 (file)
@@ -81,6 +81,7 @@ static struct sdw_intel_ctx
 
        /* Check SNDWLCAP.LCOUNT */
        caps = ioread32(res->mmio_base + SDW_SHIM_BASE + SDW_SHIM_LCAP);
+       caps &= GENMASK(2, 0);
 
        /* Check HW supported vs property value and use min of two */
        count = min_t(u8, caps, count);
@@ -90,6 +91,9 @@ static struct sdw_intel_ctx
                dev_err(&adev->dev, "Link count %d exceeds max %d\n",
                        count, SDW_MAX_LINKS);
                return NULL;
+       } else if (!count) {
+               dev_warn(&adev->dev, "No SoundWire links detected\n");
+               return NULL;
        }
 
        dev_dbg(&adev->dev, "Creating %d SDW Link devices\n", count);