Merge tag 'riscv-for-linus-4.15-rc2_cleanups' of git://git.kernel.org/pub/scm/linux...
[linux/fpc-iii.git] / drivers / soc / actions / owl-sps-helper.c
blob9d7a2c2b44ec804a15eea28e2526eea3443b6c45
1 /*
2 * Actions Semi Owl Smart Power System (SPS) shared helpers
4 * Copyright 2012 Actions Semi Inc.
5 * Author: Actions Semi, Inc.
7 * Copyright (c) 2017 Andreas Färber
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
15 #include <linux/delay.h>
16 #include <linux/io.h>
18 #define OWL_SPS_PG_CTL 0x0
20 int owl_sps_set_pg(void __iomem *base, u32 pwr_mask, u32 ack_mask, bool enable)
22 u32 val;
23 bool ack;
24 int timeout;
26 val = readl(base + OWL_SPS_PG_CTL);
27 ack = val & ack_mask;
28 if (ack == enable)
29 return 0;
31 if (enable)
32 val |= pwr_mask;
33 else
34 val &= ~pwr_mask;
36 writel(val, base + OWL_SPS_PG_CTL);
38 for (timeout = 5000; timeout > 0; timeout -= 50) {
39 val = readl(base + OWL_SPS_PG_CTL);
40 if ((val & ack_mask) == (enable ? ack_mask : 0))
41 break;
42 udelay(50);
44 if (timeout <= 0)
45 return -ETIMEDOUT;
47 udelay(10);
49 return 0;
51 EXPORT_SYMBOL_GPL(owl_sps_set_pg);