1 // SPDX-License-Identifier: GPL-2.0 OR MIT
2 /* Copyright 2017-2019 Qiang Yu <yuq825@gmail.com> */
4 #include <linux/iopoll.h>
5 #include <linux/device.h>
7 #include "lima_device.h"
11 #define pmu_write(reg, data) writel(data, ip->iomem + reg)
12 #define pmu_read(reg) readl(ip->iomem + reg)
14 static int lima_pmu_wait_cmd(struct lima_ip
*ip
)
16 struct lima_device
*dev
= ip
->dev
;
20 err
= readl_poll_timeout(ip
->iomem
+ LIMA_PMU_INT_RAWSTAT
,
21 v
, v
& LIMA_PMU_INT_CMD_MASK
,
24 dev_err(dev
->dev
, "timeout wait pmd cmd\n");
28 pmu_write(LIMA_PMU_INT_CLEAR
, LIMA_PMU_INT_CMD_MASK
);
32 int lima_pmu_init(struct lima_ip
*ip
)
37 pmu_write(LIMA_PMU_INT_MASK
, 0);
39 /* If this value is too low, when in high GPU clk freq,
40 * GPU will be in unstable state.
42 pmu_write(LIMA_PMU_SW_DELAY
, 0xffff);
44 /* status reg 1=off 0=on */
45 stat
= pmu_read(LIMA_PMU_STATUS
);
49 pmu_write(LIMA_PMU_POWER_UP
, stat
);
50 err
= lima_pmu_wait_cmd(ip
);
57 void lima_pmu_fini(struct lima_ip
*ip
)