Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0+
0002 /*
0003  * Actions Semi Owl Smart Power System (SPS) shared helpers
0004  *
0005  * Copyright 2012 Actions Semi Inc.
0006  * Author: Actions Semi, Inc.
0007  *
0008  * Copyright (c) 2017 Andreas Färber
0009  */
0010 
0011 #include <linux/delay.h>
0012 #include <linux/io.h>
0013 #include <linux/soc/actions/owl-sps.h>
0014 
0015 #define OWL_SPS_PG_CTL  0x0
0016 
0017 int owl_sps_set_pg(void __iomem *base, u32 pwr_mask, u32 ack_mask, bool enable)
0018 {
0019     u32 val;
0020     bool ack;
0021     int timeout;
0022 
0023     val = readl(base + OWL_SPS_PG_CTL);
0024     ack = val & ack_mask;
0025     if (ack == enable)
0026         return 0;
0027 
0028     if (enable)
0029         val |= pwr_mask;
0030     else
0031         val &= ~pwr_mask;
0032 
0033     writel(val, base + OWL_SPS_PG_CTL);
0034 
0035     for (timeout = 5000; timeout > 0; timeout -= 50) {
0036         val = readl(base + OWL_SPS_PG_CTL);
0037         if ((val & ack_mask) == (enable ? ack_mask : 0))
0038             break;
0039         udelay(50);
0040     }
0041     if (timeout <= 0)
0042         return -ETIMEDOUT;
0043 
0044     udelay(10);
0045 
0046     return 0;
0047 }
0048 EXPORT_SYMBOL_GPL(owl_sps_set_pg);