Merge branch 'fixes-dts' into omap-for-v4.20/fixes
[linux-2.6-block.git] / drivers / soc / actions / owl-sps-helper.c
CommitLineData
afe51827 1// SPDX-License-Identifier: GPL-2.0+
6932ec60
AF
2/*
3 * Actions Semi Owl Smart Power System (SPS) shared helpers
4 *
5 * Copyright 2012 Actions Semi Inc.
6 * Author: Actions Semi, Inc.
7 *
8 * Copyright (c) 2017 Andreas Färber
6932ec60
AF
9 */
10
11#include <linux/delay.h>
12#include <linux/io.h>
13
14#define OWL_SPS_PG_CTL 0x0
15
16int owl_sps_set_pg(void __iomem *base, u32 pwr_mask, u32 ack_mask, bool enable)
17{
18 u32 val;
19 bool ack;
20 int timeout;
21
22 val = readl(base + OWL_SPS_PG_CTL);
23 ack = val & ack_mask;
24 if (ack == enable)
25 return 0;
26
27 if (enable)
28 val |= pwr_mask;
29 else
30 val &= ~pwr_mask;
31
32 writel(val, base + OWL_SPS_PG_CTL);
33
34 for (timeout = 5000; timeout > 0; timeout -= 50) {
35 val = readl(base + OWL_SPS_PG_CTL);
36 if ((val & ack_mask) == (enable ? ack_mask : 0))
37 break;
38 udelay(50);
39 }
40 if (timeout <= 0)
41 return -ETIMEDOUT;
42
43 udelay(10);
44
45 return 0;
46}
47EXPORT_SYMBOL_GPL(owl_sps_set_pg);