diff --git a/soc/swr-wcd-ctrl.c b/soc/swr-wcd-ctrl.c index 8ae22c2bf8..c5ba37bea8 100644 --- a/soc/swr-wcd-ctrl.c +++ b/soc/swr-wcd-ctrl.c @@ -1292,15 +1292,20 @@ static int swrm_get_logical_dev_num(struct swr_master *mstr, u64 dev_id, int ret = -EINVAL; struct swr_mstr_ctrl *swrm = swr_get_ctrl_data(mstr); struct swr_device *swr_dev; + u32 num_dev = 0; if (!swrm) { pr_err("%s: Invalid handle to swr controller\n", __func__); return ret; } + if (swrm->num_dev) + num_dev = swrm->num_dev; + else + num_dev = mstr->num_dev; pm_runtime_get_sync(&swrm->pdev->dev); - for (i = 1; i < (mstr->num_dev + 1); i++) { + for (i = 1; i < (num_dev + 1); i++) { id = ((u64)(swrm->read(swrm->handle, SWRM_ENUMERATOR_SLAVE_DEV_ID_2(i))) << 32); id |= swrm->read(swrm->handle, @@ -1477,6 +1482,19 @@ static int swrm_probe(struct platform_device *pdev) INIT_LIST_HEAD(&swrm->mport_list); mutex_init(&swrm->reslock); + ret = of_property_read_u32(swrm->dev->of_node, "qcom,swr-num-dev", + &swrm->num_dev); + if (ret) + dev_dbg(&pdev->dev, "%s: Looking up %s property failed\n", + __func__, "qcom,swr-num-dev"); + else { + if (swrm->num_dev > SWR_MAX_SLAVE_DEVICES) { + dev_err(&pdev->dev, "%s: num_dev %d > max limit %d\n", + __func__, swrm->num_dev, SWR_MAX_SLAVE_DEVICES); + ret = -EINVAL; + goto err_pdata_fail; + } + } ret = swrm->reg_irq(swrm->handle, swr_mstr_interrupt, swrm, SWR_IRQ_REGISTER); if (ret) { diff --git a/soc/swr-wcd-ctrl.h b/soc/swr-wcd-ctrl.h index 52a60a3c60..fcf0652a64 100644 --- a/soc/swr-wcd-ctrl.h +++ b/soc/swr-wcd-ctrl.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2015-2017, The Linux Foundation. All rights reserved. +/* Copyright (c) 2015-2018, The Linux Foundation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and @@ -23,6 +23,8 @@ #define SWR_MSTR_PORT_LEN 8 /* Number of master ports */ +#define SWR_MAX_SLAVE_DEVICES 11 + #define SWRM_VERSION_1_0 0x01010000 #define SWRM_VERSION_1_2 0x01030000 #define SWRM_VERSION_1_3 0x01040000 @@ -94,6 +96,7 @@ struct swr_mstr_ctrl { void *data), void *swr_handle, int type); int irq; int version; + u32 num_dev; int num_enum_slaves; int slave_status; struct swr_mstr_port *mstr_port;