From patchwork Fri Mar 26 06:39:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 409474 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp1165346jai; Thu, 25 Mar 2021 23:42:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxxO4LuOTKR0PyeLZ8OiW+Kp0A/dF//sDkKcG+I1FNI0y/XD/cVC+kGaqHR5q03BQgi4/86 X-Received: by 2002:a17:906:8308:: with SMTP id j8mr13214688ejx.339.1616740952382; Thu, 25 Mar 2021 23:42:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616740952; cv=none; d=google.com; s=arc-20160816; b=Pi8CehEoLSFT24TewkEPID6+0htWJ8+bdNuDwuIPu3gXmPEbcRKLPkL2MYqSBVRqkC QLeTCGDYOaAZICxKpyg1Phg6YPf87GxSlVLbYWhj50zclVzPiAXskJMY0lwBAwAum2R4 PlHEfUcsgOfclSuW+BAtORGIkBnW+nlbj2LPe4QG9pWK7NrSsnnCw5W9M3fiSzZVQSBe BsyRNA4m2XAr/WCatcEKfs1rbSqtaO7TRqCaGQX7usbVrEMp1nasqB/FQaqxQtc4d21D 0YH7vjzVgIa89K0Kk2kPnXl4xmWmrkGjg5CDEqsRXrLCABr/EZytsHFQYseicOMP5Ify KW8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=n+0SLp5bys43157dIPELL3xi2LwO4Hd+7UwWQjJAfcc=; b=R3nGRaO4MOUzV2ApV/m8na1yDAkE9rNeZZck3lk17L7P7h8gEZ9s+mJXkljTv0iyWB d+I1bTExozo36hHmsTPxOwJMKbQK6FkgA6kDenmi9cj/M2ZWr/iwAdYQVw7ArUwCt2SZ x5/g8RFxnvaAMDKZIPPIkjL+g+D/7lXZrbn0fZX6n88SYOBm9qgN+MP4XrK1PT23E67d DIkmewGx9cr0zFy+FUqAnCACJjIbaykQqjv7+Q+OviHJKo5Ai4DVgmBo/3wjS08Jg5vz d3drXnA6qP8eH/xPMyN3mAYK3wQL5BUSe3drVAWqHnJcY9DSDtWhd3FBwzgAF+GSyX0H D+OQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="JoyAMkb/"; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p11si5754958ejg.105.2021.03.25.23.42.32; Thu, 25 Mar 2021 23:42:32 -0700 (PDT) Received-SPF: pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="JoyAMkb/"; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230182AbhCZGmA (ORCPT + 6 others); Fri, 26 Mar 2021 02:42:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230191AbhCZGl0 (ORCPT ); Fri, 26 Mar 2021 02:41:26 -0400 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D59A5C0613B2 for ; Thu, 25 Mar 2021 23:41:25 -0700 (PDT) Received: by mail-ed1-x52a.google.com with SMTP id bx7so5029477edb.12 for ; Thu, 25 Mar 2021 23:41:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=n+0SLp5bys43157dIPELL3xi2LwO4Hd+7UwWQjJAfcc=; b=JoyAMkb/CytOSLNJEkTp63AUySgtJVGlnaeGsk3LbwZYQOUMwTiruvczpg6DNGjQAR o2xW20EAm6R97lv/lkN9XhJpXrCG7VdGuguIC9RaarehuzEEBD+7XEBarraCKEMT7ROY egLuGyKcaRR6rHzi4GD+jHywLlrp3U7IBrp7cV+HM0/vJ5mMX1FNeZCJA0O7jSiSPpkH R7S1wmIsroPI16FceH7EUrzdGvKF279UYYG1plhjmwqiPggvV6KDp1GuW1dk/VutwnwZ mkoOhY0EHq+CL84h1BG52bSoRKSFGH7JJsuAKPlvXthKrp0nttl7aI+nwUyTRcKfX4Py nJnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=n+0SLp5bys43157dIPELL3xi2LwO4Hd+7UwWQjJAfcc=; b=BEhzCBsnFAq79aJvjZh1gu0upc5Vzg4YOa/epJ/8G5kqRCqjMEWn24aKh3LUF5QSE/ Jtczk4w1bkXSrS4TIXGf1ugvJFx/nZayoEef7YmIvyw7cqHqzaa2pbW+MWvYO24+ydOm x9mH3T4glaKZR4jfBEpH43BqJpUB6K57fbmSsPLiEjERH2L12rusQ+duOHq1jYaPARQ2 Es1U5gSM/Xsh8sIvIrvqz1XCnAi1BlzWjKJhPNZy+gLP/9zz3KHOWteHOGtP3SRrUJMq OHf9QGW+2LWLd+DESq8vNt32DLOnULYA9DY/w60KiNzSdkBLOGVbmCEtiEE+PEx643kP BxwA== X-Gm-Message-State: AOAM530me+0NGiQVWpf++E95mBdGmsgEbLruyz236+sBYgRjoY8LqjHX Ftxf7VQOh4eCgEWYldyLMZDKrg== X-Received: by 2002:aa7:dd99:: with SMTP id g25mr12937150edv.230.1616740884618; Thu, 25 Mar 2021 23:41:24 -0700 (PDT) Received: from srini-hackbox.lan (cpc86377-aztw32-2-0-cust226.18-1.cable.virginm.net. [92.233.226.227]) by smtp.gmail.com with ESMTPSA id ci22sm125325ejc.54.2021.03.25.23.41.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Mar 2021 23:41:24 -0700 (PDT) From: Srinivas Kandagatla To: vkoul@kernel.org Cc: yung-chuan.liao@linux.intel.com, pierre-louis.bossart@linux.intel.com, sanyog.r.kale@intel.com, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, robh@kernel.org, devicetree@vger.kernel.org, Srinivas Kandagatla Subject: [PATCH v5 8/9] soundwire: qcom: add auto enumeration support Date: Fri, 26 Mar 2021 06:39:43 +0000 Message-Id: <20210326063944.31683-9-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20210326063944.31683-1-srinivas.kandagatla@linaro.org> References: <20210326063944.31683-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Qualcomm SoundWire controller supports Auto Enumeration of the devices within the IP. This patch enables support for this feature. Signed-off-by: Srinivas Kandagatla Reviewed-by: Pierre-Louis Bossart --- drivers/soundwire/qcom.c | 86 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 81 insertions(+), 5 deletions(-) -- 2.21.0 diff --git a/drivers/soundwire/qcom.c b/drivers/soundwire/qcom.c index 6a563fb52444..c6c923329b15 100644 --- a/drivers/soundwire/qcom.c +++ b/drivers/soundwire/qcom.c @@ -57,6 +57,8 @@ #define SWRM_CMD_FIFO_RD_FIFO_ADDR 0x318 #define SWRM_RD_FIFO_CMD_ID_MASK GENMASK(11, 8) #define SWRM_ENUMERATOR_CFG_ADDR 0x500 +#define SWRM_ENUMERATOR_SLAVE_DEV_ID_1(m) (0x530 + 0x8 * (m)) +#define SWRM_ENUMERATOR_SLAVE_DEV_ID_2(m) (0x534 + 0x8 * (m)) #define SWRM_MCP_FRAME_CTRL_BANK_ADDR(m) (0x101C + 0x40 * (m)) #define SWRM_MCP_FRAME_CTRL_BANK_COL_CTRL_BMSK GENMASK(2, 0) #define SWRM_MCP_FRAME_CTRL_BANK_ROW_CTRL_BMSK GENMASK(7, 3) @@ -143,6 +145,7 @@ struct qcom_swrm_ctrl { enum sdw_slave_status status[SDW_MAX_DEVICES]; int (*reg_read)(struct qcom_swrm_ctrl *ctrl, int reg, u32 *val); int (*reg_write)(struct qcom_swrm_ctrl *ctrl, int reg, int val); + u32 slave_status; }; struct qcom_swrm_data { @@ -342,6 +345,7 @@ static void qcom_swrm_get_device_status(struct qcom_swrm_ctrl *ctrl) int i; ctrl->reg_read(ctrl, SWRM_MCP_SLV_STATUS, &val); + ctrl->slave_status = val; for (i = 0; i < SDW_MAX_DEVICES; i++) { u32 s; @@ -352,10 +356,74 @@ static void qcom_swrm_get_device_status(struct qcom_swrm_ctrl *ctrl) } } +static void qcom_swrm_set_slave_dev_num(struct sdw_bus *bus, + struct sdw_slave *slave, int devnum) +{ + struct qcom_swrm_ctrl *ctrl = to_qcom_sdw(bus); + u32 status; + + ctrl->reg_read(ctrl, SWRM_MCP_SLV_STATUS, &status); + status = (status >> (devnum * SWRM_MCP_SLV_STATUS_SZ)); + status &= SWRM_MCP_SLV_STATUS_MASK; + + if (status == SDW_SLAVE_ATTACHED) { + if (slave) + slave->dev_num = devnum; + mutex_lock(&bus->bus_lock); + set_bit(devnum, bus->assigned); + mutex_unlock(&bus->bus_lock); + } +} + +static int qcom_swrm_enumerate(struct sdw_bus *bus) +{ + struct qcom_swrm_ctrl *ctrl = to_qcom_sdw(bus); + struct sdw_slave *slave, *_s; + struct sdw_slave_id id; + u32 val1, val2; + bool found; + u64 addr; + int i; + char *buf1 = (char *)&val1, *buf2 = (char *)&val2; + + for (i = 1; i <= SDW_MAX_DEVICES; i++) { + /*SCP_Devid5 - Devid 4*/ + ctrl->reg_read(ctrl, SWRM_ENUMERATOR_SLAVE_DEV_ID_1(i), &val1); + + /*SCP_Devid3 - DevId 2 Devid 1 Devid 0*/ + ctrl->reg_read(ctrl, SWRM_ENUMERATOR_SLAVE_DEV_ID_2(i), &val2); + + if (!val1 && !val2) + break; + + addr = buf2[1] | (buf2[0] << 8) | (buf1[3] << 16) | + ((u64)buf1[2] << 24) | ((u64)buf1[1] << 32) | + ((u64)buf1[0] << 40); + + sdw_extract_slave_id(bus, addr, &id); + found = false; + /* Now compare with entries */ + list_for_each_entry_safe(slave, _s, &bus->slaves, node) { + if (sdw_compare_devid(slave, id) == 0) { + qcom_swrm_set_slave_dev_num(bus, slave, i); + found = true; + break; + } + } + + if (!found) { + qcom_swrm_set_slave_dev_num(bus, NULL, i); + sdw_slave_add(bus, &id, NULL); + } + } + + return 0; +} + static irqreturn_t qcom_swrm_irq_handler(int irq, void *dev_id) { struct qcom_swrm_ctrl *swrm = dev_id; - u32 value, intr_sts, intr_sts_masked; + u32 value, intr_sts, intr_sts_masked, slave_status; u32 i; u8 devnum = 0; int ret = IRQ_HANDLED; @@ -384,8 +452,15 @@ static irqreturn_t qcom_swrm_irq_handler(int irq, void *dev_id) case SWRM_INTERRUPT_STATUS_CHANGE_ENUM_SLAVE_STATUS: dev_err_ratelimited(swrm->dev, "%s: SWR new slave attached\n", __func__); - qcom_swrm_get_device_status(swrm); - sdw_handle_slave_status(&swrm->bus, swrm->status); + swrm->reg_read(swrm, SWRM_MCP_SLV_STATUS, &slave_status); + if (swrm->slave_status == slave_status) { + dev_err(swrm->dev, "Slave status not changed %x\n", + slave_status); + } else { + qcom_swrm_get_device_status(swrm); + qcom_swrm_enumerate(&swrm->bus); + sdw_handle_slave_status(&swrm->bus, swrm->status); + } break; case SWRM_INTERRUPT_STATUS_MASTER_CLASH_DET: dev_err_ratelimited(swrm->dev, @@ -472,8 +547,8 @@ static int qcom_swrm_init(struct qcom_swrm_ctrl *ctrl) ctrl->reg_write(ctrl, SWRM_MCP_FRAME_CTRL_BANK_ADDR(0), val); - /* Disable Auto enumeration */ - ctrl->reg_write(ctrl, SWRM_ENUMERATOR_CFG_ADDR, 0); + /* Enable Auto enumeration */ + ctrl->reg_write(ctrl, SWRM_ENUMERATOR_CFG_ADDR, 1); ctrl->intr_mask = SWRM_INTERRUPT_STATUS_RMSK; /* Mask soundwire interrupts */ @@ -507,6 +582,7 @@ static int qcom_swrm_init(struct qcom_swrm_ctrl *ctrl) ctrl->reg_write(ctrl, SWRM_INTERRUPT_CPU_EN, SWRM_INTERRUPT_STATUS_RMSK); } + ctrl->slave_status = 0; return 0; }