@@ -12,8 +12,11 @@
#include <fdtdec.h>
#include <asm/io.h>
#include <dm/device_compat.h>
+#include <linux/iopoll.h>
#include <spmi/spmi.h>
+#define SPMI_CMD_DONE_TIMEOUT_US 100000
+
/* PMIC Arbiter configuration registers */
#define PMIC_ARB_VERSION 0x0000
#define PMIC_ARB_VERSION_V2_MIN 0x20010000
@@ -161,10 +164,10 @@ static int msm_spmi_write(struct udevice *dev, int usid, int pid, int off,
writel(reg, priv->spmi_chnls + ch_offset + SPMI_REG_CMD0);
/* Wait till CMD DONE status */
- reg = 0;
- while (!reg) {
- reg = readl(priv->spmi_chnls + ch_offset +
- SPMI_REG_STATUS);
+ if (readl_poll_timeout(priv->spmi_chnls + ch_offset + SPMI_REG_STATUS,
+ reg, reg, SPMI_CMD_DONE_TIMEOUT_US)) {
+ printf("SPMI write timeout (channel %#x).\n", ch_offset);
+ return -ETIMEDOUT;
}
if (reg ^ SPMI_STATUS_DONE) {
@@ -231,9 +234,10 @@ static int msm_spmi_read(struct udevice *dev, int usid, int pid, int off)
writel(reg, priv->spmi_obs + ch_offset + SPMI_REG_CMD0);
/* Wait till CMD DONE status */
- reg = 0;
- while (!reg) {
- reg = readl(priv->spmi_obs + ch_offset + SPMI_REG_STATUS);
+ if (readl_poll_timeout(priv->spmi_obs + ch_offset + SPMI_REG_STATUS,
+ reg, reg, SPMI_CMD_DONE_TIMEOUT_US)) {
+ printf("SPMI read timeout (channel %#x).\n", ch_offset);
+ return -ETIMEDOUT;
}
if (reg ^ SPMI_STATUS_DONE) {