Re: [PATCH v5 6/9] soundwire: qcom: add support to new interrupts

2021-03-30 Thread Vinod Koul
On 26-03-21, 06:39, Srinivas Kandagatla wrote:

> - ctrl->reg_write(ctrl, SWRM_INTERRUPT_CLEAR, sts);
> + do {
> + for (i = 0; i < SWRM_INTERRUPT_MAX; i++) {
> + value = intr_sts_masked & (1 << i);

BIT(i) istead of shifiting?

> + if (!value)
> + continue;
> +
> + switch (value) {
> + case SWRM_INTERRUPT_STATUS_SLAVE_PEND_IRQ:
> + devnum = 
> qcom_swrm_get_alert_slave_dev_num(swrm);
> + if (devnum < 0) {
> + dev_err_ratelimited(swrm->dev,
> + "no slave alert found.spurious 
> interrupt\n");
> + } else {
> + sdw_handle_slave_status(&swrm->bus, 
> swrm->status);
> + }
>  
> - if (sts & SWRM_INTERRUPT_STATUS_SPECIAL_CMD_ID_FINISHED)
> - complete(&ctrl->broadcast);
> + break;
> + case SWRM_INTERRUPT_STATUS_NEW_SLAVE_ATTACHED:
> + case SWRM_INTERRUPT_STATUS_CHANGE_ENUM_SLAVE_STATUS:
> + dev_err_ratelimited(swrm->dev, "%s: SWR new 
> slave attached\n",
> + __func__);

This should be debug
-- 
~Vinod


[PATCH v5 6/9] soundwire: qcom: add support to new interrupts

2021-03-25 Thread Srinivas Kandagatla
Add support to new interrupts which includes reporting some of the
error interrupts and adding support to SLAVE pending interrupt!

This patch also changes the interrupt handler behaviour on handling
any pending interrupts by checking it before returning out of irq handler.

Signed-off-by: Srinivas Kandagatla 
Reviewed-by: Pierre-Louis Bossart 
---
 drivers/soundwire/qcom.c | 161 ---
 1 file changed, 135 insertions(+), 26 deletions(-)

diff --git a/drivers/soundwire/qcom.c b/drivers/soundwire/qcom.c
index 0cbd611fb8c6..6a563fb52444 100644
--- a/drivers/soundwire/qcom.c
+++ b/drivers/soundwire/qcom.c
@@ -28,10 +28,21 @@
 #define SWRM_COMP_PARAMS_DIN_PORTS_MASK
GENMASK(9, 5)
 #define SWRM_INTERRUPT_STATUS  0x200
 #define SWRM_INTERRUPT_STATUS_RMSK GENMASK(16, 0)
+#define SWRM_INTERRUPT_STATUS_SLAVE_PEND_IRQ   BIT(0)
 #define SWRM_INTERRUPT_STATUS_NEW_SLAVE_ATTACHED   BIT(1)
 #define SWRM_INTERRUPT_STATUS_CHANGE_ENUM_SLAVE_STATUS BIT(2)
+#define SWRM_INTERRUPT_STATUS_MASTER_CLASH_DET BIT(3)
+#define SWRM_INTERRUPT_STATUS_RD_FIFO_OVERFLOW BIT(4)
+#define SWRM_INTERRUPT_STATUS_RD_FIFO_UNDERFLOWBIT(5)
+#define SWRM_INTERRUPT_STATUS_WR_CMD_FIFO_OVERFLOW BIT(6)
 #define SWRM_INTERRUPT_STATUS_CMD_ERRORBIT(7)
+#define SWRM_INTERRUPT_STATUS_DOUT_PORT_COLLISION  BIT(8)
+#define SWRM_INTERRUPT_STATUS_READ_EN_RD_VALID_MISMATCHBIT(9)
 #define SWRM_INTERRUPT_STATUS_SPECIAL_CMD_ID_FINISHED  BIT(10)
+#define SWRM_INTERRUPT_STATUS_BUS_RESET_FINISHED_V2 BIT(13)
+#define SWRM_INTERRUPT_STATUS_CLK_STOP_FINISHED_V2  BIT(14)
+#define SWRM_INTERRUPT_STATUS_EXT_CLK_STOP_WAKEUP   BIT(16)
+#define SWRM_INTERRUPT_MAX 17
 #define SWRM_INTERRUPT_MASK_ADDR   0x204
 #define SWRM_INTERRUPT_CLEAR   0x208
 #define SWRM_INTERRUPT_CPU_EN  0x210
@@ -58,6 +69,7 @@
 #define SWRM_MCP_STATUS_BANK_NUM_MASK  BIT(0)
 #define SWRM_MCP_SLV_STATUS0x1090
 #define SWRM_MCP_SLV_STATUS_MASK   GENMASK(1, 0)
+#define SWRM_MCP_SLV_STATUS_SZ 2
 #define SWRM_DP_PORT_CTRL_BANK(n, m)   (0x1124 + 0x100 * (n - 1) + 0x40 * m)
 #define SWRM_DP_PORT_CTRL_2_BANK(n, m) (0x1128 + 0x100 * (n - 1) + 0x40 * m)
 #define SWRM_DP_BLOCK_CTRL_1(n)(0x112C + 0x100 * (n - 1))
@@ -123,6 +135,7 @@ struct qcom_swrm_ctrl {
int rows_index;
unsigned long dout_port_mask;
unsigned long din_port_mask;
+   u32 intr_mask;
u8 rcmd_id;
u8 wcmd_id;
struct qcom_swrm_port_config pconfig[QCOM_SDW_MAX_PORTS];
@@ -304,6 +317,25 @@ static int qcom_swrm_cmd_fifo_rd_cmd(struct qcom_swrm_ctrl 
*swrm,
return SDW_CMD_IGNORED;
 }
 
+static int qcom_swrm_get_alert_slave_dev_num(struct qcom_swrm_ctrl *ctrl)
+{
+   u32 val, status;
+   int dev_num;
+
+   ctrl->reg_read(ctrl, SWRM_MCP_SLV_STATUS, &val);
+
+   for (dev_num = 0; dev_num < SDW_MAX_DEVICES; dev_num++) {
+   status = (val >> (dev_num * SWRM_MCP_SLV_STATUS_SZ));
+
+   if ((status & SWRM_MCP_SLV_STATUS_MASK) == SDW_SLAVE_ALERT) {
+   ctrl->status[dev_num] = status;
+   return dev_num;
+   }
+   }
+
+   return -EINVAL;
+}
+
 static void qcom_swrm_get_device_status(struct qcom_swrm_ctrl *ctrl)
 {
u32 val;
@@ -322,36 +354,112 @@ static void qcom_swrm_get_device_status(struct 
qcom_swrm_ctrl *ctrl)
 
 static irqreturn_t qcom_swrm_irq_handler(int irq, void *dev_id)
 {
-   struct qcom_swrm_ctrl *ctrl = dev_id;
-   u32 sts, value;
+   struct qcom_swrm_ctrl *swrm = dev_id;
+   u32 value, intr_sts, intr_sts_masked;
+   u32 i;
+   u8 devnum = 0;
+   int ret = IRQ_HANDLED;
 
-   ctrl->reg_read(ctrl, SWRM_INTERRUPT_STATUS, &sts);
+   swrm->reg_read(swrm, SWRM_INTERRUPT_STATUS, &intr_sts);
+   intr_sts_masked = intr_sts & swrm->intr_mask;
 
-   if (sts & SWRM_INTERRUPT_STATUS_CMD_ERROR) {
-   ctrl->reg_read(ctrl, SWRM_CMD_FIFO_STATUS, &value);
-   dev_err_ratelimited(ctrl->dev,
-   "CMD error, fifo status 0x%x\n",
-value);
-   ctrl->reg_write(ctrl, SWRM_CMD_FIFO_CMD, 0x1);
-   }
-
-   if ((sts & SWRM_INTERRUPT_STATUS_NEW_SLAVE_ATTACHED) ||
-   sts & SWRM_INTERRUPT_STATUS_CHANGE_ENUM_SLAVE_STATUS) {
-   qcom_swrm_get_device_status(ctrl);
-   sdw_handle_slave_status(&ctrl->bus, ctrl->status);
-   }
-
-   /**
-* cle