13 #include <linux/module.h>
14 #include <linux/kernel.h>
16 #include <linux/errno.h>
20 #include <linux/slab.h>
25 #include <linux/bitops.h>
35 #include <mach/hardware.h>
36 #include <mach/irqs.h>
42 #define PRCMU_FW_VERSION_OFFSET 0xA4
45 #define PRCM_AVS_BASE 0x2FC
46 #define PRCM_AVS_VBB_RET (PRCM_AVS_BASE + 0x0)
47 #define PRCM_AVS_VBB_MAX_OPP (PRCM_AVS_BASE + 0x1)
48 #define PRCM_AVS_VBB_100_OPP (PRCM_AVS_BASE + 0x2)
49 #define PRCM_AVS_VBB_50_OPP (PRCM_AVS_BASE + 0x3)
50 #define PRCM_AVS_VARM_MAX_OPP (PRCM_AVS_BASE + 0x4)
51 #define PRCM_AVS_VARM_100_OPP (PRCM_AVS_BASE + 0x5)
52 #define PRCM_AVS_VARM_50_OPP (PRCM_AVS_BASE + 0x6)
53 #define PRCM_AVS_VARM_RET (PRCM_AVS_BASE + 0x7)
54 #define PRCM_AVS_VAPE_100_OPP (PRCM_AVS_BASE + 0x8)
55 #define PRCM_AVS_VAPE_50_OPP (PRCM_AVS_BASE + 0x9)
56 #define PRCM_AVS_VMOD_100_OPP (PRCM_AVS_BASE + 0xA)
57 #define PRCM_AVS_VMOD_50_OPP (PRCM_AVS_BASE + 0xB)
58 #define PRCM_AVS_VSAFE (PRCM_AVS_BASE + 0xC)
60 #define PRCM_AVS_VOLTAGE 0
61 #define PRCM_AVS_VOLTAGE_MASK 0x3f
62 #define PRCM_AVS_ISSLOWSTARTUP 6
63 #define PRCM_AVS_ISSLOWSTARTUP_MASK (1 << PRCM_AVS_ISSLOWSTARTUP)
64 #define PRCM_AVS_ISMODEENABLE 7
65 #define PRCM_AVS_ISMODEENABLE_MASK (1 << PRCM_AVS_ISMODEENABLE)
67 #define PRCM_BOOT_STATUS 0xFFF
68 #define PRCM_ROMCODE_A2P 0xFFE
69 #define PRCM_ROMCODE_P2A 0xFFD
70 #define PRCM_XP70_CUR_PWR_STATE 0xFFC
72 #define PRCM_SW_RST_REASON 0xFF8
74 #define _PRCM_MBOX_HEADER 0xFE8
75 #define PRCM_MBOX_HEADER_REQ_MB0 (_PRCM_MBOX_HEADER + 0x0)
76 #define PRCM_MBOX_HEADER_REQ_MB1 (_PRCM_MBOX_HEADER + 0x1)
77 #define PRCM_MBOX_HEADER_REQ_MB2 (_PRCM_MBOX_HEADER + 0x2)
78 #define PRCM_MBOX_HEADER_REQ_MB3 (_PRCM_MBOX_HEADER + 0x3)
79 #define PRCM_MBOX_HEADER_REQ_MB4 (_PRCM_MBOX_HEADER + 0x4)
80 #define PRCM_MBOX_HEADER_REQ_MB5 (_PRCM_MBOX_HEADER + 0x5)
81 #define PRCM_MBOX_HEADER_ACK_MB0 (_PRCM_MBOX_HEADER + 0x8)
84 #define PRCM_REQ_MB0 0xFDC
85 #define PRCM_REQ_MB1 0xFD0
86 #define PRCM_REQ_MB2 0xFC0
87 #define PRCM_REQ_MB3 0xE4C
88 #define PRCM_REQ_MB4 0xE48
89 #define PRCM_REQ_MB5 0xE44
92 #define PRCM_ACK_MB0 0xE08
93 #define PRCM_ACK_MB1 0xE04
94 #define PRCM_ACK_MB2 0xE00
95 #define PRCM_ACK_MB3 0xDFC
96 #define PRCM_ACK_MB4 0xDF8
97 #define PRCM_ACK_MB5 0xDF4
100 #define MB0H_POWER_STATE_TRANS 0
101 #define MB0H_CONFIG_WAKEUPS_EXE 1
102 #define MB0H_READ_WAKEUP_ACK 3
103 #define MB0H_CONFIG_WAKEUPS_SLEEP 4
105 #define MB0H_WAKEUP_EXE 2
106 #define MB0H_WAKEUP_SLEEP 5
109 #define PRCM_REQ_MB0_AP_POWER_STATE (PRCM_REQ_MB0 + 0x0)
110 #define PRCM_REQ_MB0_AP_PLL_STATE (PRCM_REQ_MB0 + 0x1)
111 #define PRCM_REQ_MB0_ULP_CLOCK_STATE (PRCM_REQ_MB0 + 0x2)
112 #define PRCM_REQ_MB0_DO_NOT_WFI (PRCM_REQ_MB0 + 0x3)
113 #define PRCM_REQ_MB0_WAKEUP_8500 (PRCM_REQ_MB0 + 0x4)
114 #define PRCM_REQ_MB0_WAKEUP_4500 (PRCM_REQ_MB0 + 0x8)
117 #define PRCM_ACK_MB0_AP_PWRSTTR_STATUS (PRCM_ACK_MB0 + 0x0)
118 #define PRCM_ACK_MB0_READ_POINTER (PRCM_ACK_MB0 + 0x1)
119 #define PRCM_ACK_MB0_WAKEUP_0_8500 (PRCM_ACK_MB0 + 0x4)
120 #define PRCM_ACK_MB0_WAKEUP_0_4500 (PRCM_ACK_MB0 + 0x8)
121 #define PRCM_ACK_MB0_WAKEUP_1_8500 (PRCM_ACK_MB0 + 0x1C)
122 #define PRCM_ACK_MB0_WAKEUP_1_4500 (PRCM_ACK_MB0 + 0x20)
123 #define PRCM_ACK_MB0_EVENT_4500_NUMBERS 20
126 #define MB1H_ARM_APE_OPP 0x0
127 #define MB1H_RESET_MODEM 0x2
128 #define MB1H_REQUEST_APE_OPP_100_VOLT 0x3
129 #define MB1H_RELEASE_APE_OPP_100_VOLT 0x4
130 #define MB1H_RELEASE_USB_WAKEUP 0x5
131 #define MB1H_PLL_ON_OFF 0x6
134 #define PRCM_REQ_MB1_ARM_OPP (PRCM_REQ_MB1 + 0x0)
135 #define PRCM_REQ_MB1_APE_OPP (PRCM_REQ_MB1 + 0x1)
136 #define PRCM_REQ_MB1_PLL_ON_OFF (PRCM_REQ_MB1 + 0x4)
137 #define PLL_SOC0_OFF 0x1
138 #define PLL_SOC0_ON 0x2
139 #define PLL_SOC1_OFF 0x4
140 #define PLL_SOC1_ON 0x8
143 #define PRCM_ACK_MB1_CURRENT_ARM_OPP (PRCM_ACK_MB1 + 0x0)
144 #define PRCM_ACK_MB1_CURRENT_APE_OPP (PRCM_ACK_MB1 + 0x1)
145 #define PRCM_ACK_MB1_APE_VOLTAGE_STATUS (PRCM_ACK_MB1 + 0x2)
146 #define PRCM_ACK_MB1_DVFS_STATUS (PRCM_ACK_MB1 + 0x3)
150 #define MB2H_AUTO_PWR 0x1
153 #define PRCM_REQ_MB2_SVA_MMDSP (PRCM_REQ_MB2 + 0x0)
154 #define PRCM_REQ_MB2_SVA_PIPE (PRCM_REQ_MB2 + 0x1)
155 #define PRCM_REQ_MB2_SIA_MMDSP (PRCM_REQ_MB2 + 0x2)
156 #define PRCM_REQ_MB2_SIA_PIPE (PRCM_REQ_MB2 + 0x3)
157 #define PRCM_REQ_MB2_SGA (PRCM_REQ_MB2 + 0x4)
158 #define PRCM_REQ_MB2_B2R2_MCDE (PRCM_REQ_MB2 + 0x5)
159 #define PRCM_REQ_MB2_ESRAM12 (PRCM_REQ_MB2 + 0x6)
160 #define PRCM_REQ_MB2_ESRAM34 (PRCM_REQ_MB2 + 0x7)
161 #define PRCM_REQ_MB2_AUTO_PM_SLEEP (PRCM_REQ_MB2 + 0x8)
162 #define PRCM_REQ_MB2_AUTO_PM_IDLE (PRCM_REQ_MB2 + 0xC)
165 #define PRCM_ACK_MB2_DPS_STATUS (PRCM_ACK_MB2 + 0x0)
166 #define HWACC_PWR_ST_OK 0xFE
170 #define MB3H_SIDETONE 0x1
171 #define MB3H_SYSCLK 0xE
174 #define PRCM_REQ_MB3_ANC_FIR_COEFF (PRCM_REQ_MB3 + 0x0)
175 #define PRCM_REQ_MB3_ANC_IIR_COEFF (PRCM_REQ_MB3 + 0x20)
176 #define PRCM_REQ_MB3_ANC_SHIFTER (PRCM_REQ_MB3 + 0x60)
177 #define PRCM_REQ_MB3_ANC_WARP (PRCM_REQ_MB3 + 0x64)
178 #define PRCM_REQ_MB3_SIDETONE_FIR_GAIN (PRCM_REQ_MB3 + 0x68)
179 #define PRCM_REQ_MB3_SIDETONE_FIR_COEFF (PRCM_REQ_MB3 + 0x6C)
180 #define PRCM_REQ_MB3_SYSCLK_MGT (PRCM_REQ_MB3 + 0x16C)
183 #define MB4H_DDR_INIT 0x0
184 #define MB4H_MEM_ST 0x1
185 #define MB4H_HOTDOG 0x12
186 #define MB4H_HOTMON 0x13
187 #define MB4H_HOT_PERIOD 0x14
188 #define MB4H_A9WDOG_CONF 0x16
189 #define MB4H_A9WDOG_EN 0x17
190 #define MB4H_A9WDOG_DIS 0x18
191 #define MB4H_A9WDOG_LOAD 0x19
192 #define MB4H_A9WDOG_KICK 0x20
195 #define PRCM_REQ_MB4_DDR_ST_AP_SLEEP_IDLE (PRCM_REQ_MB4 + 0x0)
196 #define PRCM_REQ_MB4_DDR_ST_AP_DEEP_IDLE (PRCM_REQ_MB4 + 0x1)
197 #define PRCM_REQ_MB4_ESRAM0_ST (PRCM_REQ_MB4 + 0x3)
198 #define PRCM_REQ_MB4_HOTDOG_THRESHOLD (PRCM_REQ_MB4 + 0x0)
199 #define PRCM_REQ_MB4_HOTMON_LOW (PRCM_REQ_MB4 + 0x0)
200 #define PRCM_REQ_MB4_HOTMON_HIGH (PRCM_REQ_MB4 + 0x1)
201 #define PRCM_REQ_MB4_HOTMON_CONFIG (PRCM_REQ_MB4 + 0x2)
202 #define PRCM_REQ_MB4_HOT_PERIOD (PRCM_REQ_MB4 + 0x0)
203 #define HOTMON_CONFIG_LOW BIT(0)
204 #define HOTMON_CONFIG_HIGH BIT(1)
205 #define PRCM_REQ_MB4_A9WDOG_0 (PRCM_REQ_MB4 + 0x0)
206 #define PRCM_REQ_MB4_A9WDOG_1 (PRCM_REQ_MB4 + 0x1)
207 #define PRCM_REQ_MB4_A9WDOG_2 (PRCM_REQ_MB4 + 0x2)
208 #define PRCM_REQ_MB4_A9WDOG_3 (PRCM_REQ_MB4 + 0x3)
209 #define A9WDOG_AUTO_OFF_EN BIT(7)
210 #define A9WDOG_AUTO_OFF_DIS 0
211 #define A9WDOG_ID_MASK 0xf
214 #define PRCM_REQ_MB5_I2C_SLAVE_OP (PRCM_REQ_MB5 + 0x0)
215 #define PRCM_REQ_MB5_I2C_HW_BITS (PRCM_REQ_MB5 + 0x1)
216 #define PRCM_REQ_MB5_I2C_REG (PRCM_REQ_MB5 + 0x2)
217 #define PRCM_REQ_MB5_I2C_VAL (PRCM_REQ_MB5 + 0x3)
218 #define PRCMU_I2C_WRITE(slave) \
219 (((slave) << 1) | (cpu_is_u8500v2() ? BIT(6) : 0))
220 #define PRCMU_I2C_READ(slave) \
221 (((slave) << 1) | BIT(0) | (cpu_is_u8500v2() ? BIT(6) : 0))
222 #define PRCMU_I2C_STOP_EN BIT(3)
225 #define PRCM_ACK_MB5_I2C_STATUS (PRCM_ACK_MB5 + 0x1)
226 #define PRCM_ACK_MB5_I2C_VAL (PRCM_ACK_MB5 + 0x3)
227 #define I2C_WR_OK 0x1
228 #define I2C_RD_OK 0x2
232 #define ALL_MBOX_BITS (MBOX_BIT(NUM_MB) - 1)
238 #define WAKEUP_BIT_RTC BIT(0)
239 #define WAKEUP_BIT_RTT0 BIT(1)
240 #define WAKEUP_BIT_RTT1 BIT(2)
241 #define WAKEUP_BIT_HSI0 BIT(3)
242 #define WAKEUP_BIT_HSI1 BIT(4)
243 #define WAKEUP_BIT_CA_WAKE BIT(5)
244 #define WAKEUP_BIT_USB BIT(6)
245 #define WAKEUP_BIT_ABB BIT(7)
246 #define WAKEUP_BIT_ABB_FIFO BIT(8)
247 #define WAKEUP_BIT_SYSCLK_OK BIT(9)
248 #define WAKEUP_BIT_CA_SLEEP BIT(10)
249 #define WAKEUP_BIT_AC_WAKE_ACK BIT(11)
250 #define WAKEUP_BIT_SIDE_TONE_OK BIT(12)
251 #define WAKEUP_BIT_ANC_OK BIT(13)
252 #define WAKEUP_BIT_SW_ERROR BIT(14)
253 #define WAKEUP_BIT_AC_SLEEP_ACK BIT(15)
254 #define WAKEUP_BIT_ARM BIT(17)
255 #define WAKEUP_BIT_HOTMON_LOW BIT(18)
256 #define WAKEUP_BIT_HOTMON_HIGH BIT(19)
257 #define WAKEUP_BIT_MODEM_SW_RESET_REQ BIT(20)
258 #define WAKEUP_BIT_GPIO0 BIT(23)
259 #define WAKEUP_BIT_GPIO1 BIT(24)
260 #define WAKEUP_BIT_GPIO2 BIT(25)
261 #define WAKEUP_BIT_GPIO3 BIT(26)
262 #define WAKEUP_BIT_GPIO4 BIT(27)
263 #define WAKEUP_BIT_GPIO5 BIT(28)
264 #define WAKEUP_BIT_GPIO6 BIT(29)
265 #define WAKEUP_BIT_GPIO7 BIT(30)
266 #define WAKEUP_BIT_GPIO8 BIT(31)
283 #define IRQ_INDEX(_name) ((IRQ_PRCMU_##_name) - IRQ_PRCMU_BASE)
284 #define IRQ_ENTRY(_name)[IRQ_INDEX(_name)] = (WAKEUP_BIT_##_name)
285 static u32 prcmu_irq_bit[NUM_PRCMU_WAKEUPS] = {
311 #define VALID_WAKEUPS (BIT(NUM_PRCMU_WAKEUP_INDICES) - 1)
312 #define WAKEUP_ENTRY(_name)[PRCMU_WAKEUP_INDEX_##_name] = (WAKEUP_BIT_##_name)
424 static void compute_armss_rate(
void);
431 static __iomem void *tcdm_base;
448 #define CLK_MGT_ENTRY(_name, _branch, _clk38div)[PRCMU_##_name] = \
449 { (PRCM_##_name##_MGT), 0 , _branch, _clk38div}
529 #define PRCMU_RESET_DSIPLL 0x00004000
530 #define PRCMU_UNCLAMP_DSIPLL 0x00400800
532 #define PRCMU_CLK_PLL_DIV_SHIFT 0
533 #define PRCMU_CLK_PLL_SW_SHIFT 5
534 #define PRCMU_CLK_38 (1 << 9)
535 #define PRCMU_CLK_38_SRC (1 << 10)
536 #define PRCMU_CLK_38_DIV (1 << 11)
539 #define PRCMU_DSI_CLOCK_SETTING 0x0000008C
542 #define PRCMU_DPI_CLOCK_SETTING ((1 << PRCMU_CLK_PLL_SW_SHIFT) | \
543 (16 << PRCMU_CLK_PLL_DIV_SHIFT))
544 #define PRCMU_DSI_LP_CLOCK_SETTING 0x00000E00
547 #define PRCMU_PLLDSI_FREQ_SETTING 0x00040165
549 #define PRCMU_ENABLE_PLLDSI 0x00000001
550 #define PRCMU_DISABLE_PLLDSI 0x00000000
551 #define PRCMU_RELEASE_RESET_DSS 0x0000400C
552 #define PRCMU_DSI_PLLOUT_SEL_SETTING 0x00000202
554 #define PRCMU_ENABLE_ESCAPE_CLOCK_DIV 0x07030101
555 #define PRCMU_DISABLE_ESCAPE_CLOCK_DIV 0x00030101
556 #define PRCMU_DSI_RESET_SW 0x00000007
558 #define PRCMU_PLLDSI_LOCKP_LOCKED 0x3
579 for (i = 0; i < 10; i++) {
581 == PRCMU_PLLDSI_LOCKP_LOCKED)
616 spin_unlock_irqrestore(&clk_mgt_lock, flags);
632 spin_unlock_irqrestore(&prcmu_lock, flags);
642 val = ((val & ~mask) | (value & mask));
644 spin_unlock_irqrestore(&prcmu_lock, flags);
717 static int requests[2];
729 if (!div && !requests[clkout])
752 if (val & div_mask) {
754 if ((val & mask) != bits) {
756 goto unlock_and_return;
759 if ((val & mask & ~div_mask) != bits) {
761 goto unlock_and_return;
766 requests[clkout] += (div ? 1 : -1);
769 spin_unlock_irqrestore(&clkout_lock, flags);
788 writeb((keep_ulp_clk ? 1 : 0),
793 spin_unlock_irqrestore(&mb0_transfer.lock, flags);
832 #define PRCMU_GIC_NUMBER_REGS 5
917 static void config_wakeups(
void)
923 static u32 last_dbb_events;
924 static u32 last_abb_events;
929 dbb_events = mb0_transfer.req.dbb_irqs | mb0_transfer.req.dbb_wakeups;
932 abb_events = mb0_transfer.req.abb_events;
934 if ((dbb_events == last_dbb_events) && (abb_events == last_abb_events))
937 for (i = 0; i < 2; i++) {
945 last_dbb_events = dbb_events;
958 if (wakeups &
BIT(i))
959 bits |= prcmu_wakeup_bit[
i];
964 mb0_transfer.req.dbb_wakeups =
bits;
967 spin_unlock_irqrestore(&mb0_transfer.lock, flags);
979 spin_unlock_irqrestore(&mb0_transfer.lock, flags);
1019 (mb1_transfer.ack.arm_opp != opp))
1022 compute_armss_rate();
1060 if (cpu_is_u8500v20_or_later() && !cpu_is_u8500v20())
1067 static void request_even_slower_clocks(
bool enable)
1073 unsigned long flags;
1082 for (i = 0; i <
ARRAY_SIZE(clock_reg); i++) {
1086 val =
readl(clock_reg[i]);
1089 if ((div <= 1) || (div > 15)) {
1090 pr_err(
"prcmu: Bad clock divider %d in %s\n",
1092 goto unlock_and_return;
1097 goto unlock_and_return;
1102 writel(val, clock_reg[i]);
1109 spin_unlock_irqrestore(&clk_mgt_lock, flags);
1123 if (opp == mb1_transfer.ape_opp)
1129 request_even_slower_clocks(
false);
1146 (mb1_transfer.ack.ape_opp != opp))
1152 request_even_slower_clocks(
true);
1154 mb1_transfer.ape_opp = opp;
1181 static unsigned int requests;
1186 if (0 != requests++)
1187 goto unlock_and_return;
1190 if (requests == 0) {
1192 goto unlock_and_return;
1193 }
else if (1 != requests--) {
1194 goto unlock_and_return;
1207 if ((mb1_transfer.ack.header != header) ||
1208 ((mb1_transfer.ack.ape_voltage_status &
BIT(0)) != 0))
1238 ((mb1_transfer.ack.ape_voltage_status &
BIT(0)) != 0))
1246 static int request_pll(
u8 clock,
bool enable)
1287 bool ram_retention =
false;
1299 ram_retention =
true;
1330 pr_err(
"prcmu: %s timed out (20 s) waiting for a reply.\n",
1333 goto unlock_and_return;
1354 unsigned long flags;
1360 sleep_cfg = ((sleep_cfg << 8) | (sleep->
sva_power_on & 0xFF));
1361 sleep_cfg = ((sleep_cfg << 8) | (sleep->
sia_power_on & 0xFF));
1362 sleep_cfg = ((sleep_cfg << 4) | (sleep->
sva_policy & 0xF));
1363 sleep_cfg = ((sleep_cfg << 4) | (sleep->
sia_policy & 0xF));
1367 idle_cfg = ((idle_cfg << 8) | (idle->
sva_power_on & 0xFF));
1368 idle_cfg = ((idle_cfg << 8) | (idle->
sia_power_on & 0xFF));
1369 idle_cfg = ((idle_cfg << 4) | (idle->
sva_policy & 0xF));
1370 idle_cfg = ((idle_cfg << 4) | (idle->
sia_policy & 0xF));
1382 mb2_transfer.auto_pm_enabled =
1388 spin_unlock_irqrestore(&mb2_transfer.auto_pm_lock, flags);
1394 return mb2_transfer.auto_pm_enabled;
1397 static int request_sysclk(
bool enable)
1400 unsigned long flags;
1416 spin_unlock_irqrestore(&mb3_transfer.lock, flags);
1424 pr_err(
"prcmu: %s timed out (20 s) waiting for a reply.\n",
1434 static int request_timclk(
bool enable)
1445 static int request_clock(
u8 clock,
bool enable)
1448 unsigned long flags;
1468 spin_unlock_irqrestore(&clk_mgt_lock, flags);
1473 static int request_sga_clock(
u8 clock,
bool enable)
1483 ret = request_clock(clock, enable);
1485 if (!ret && !enable) {
1493 static inline bool plldsi_locked(
void)
1502 static int request_plldsi(
bool enable)
1520 bool locked = plldsi_locked();
1522 for (i = 10; !locked && (i > 0); --
i) {
1524 locked = plldsi_locked();
1543 static int request_dsiclk(
u8 n,
bool enable)
1550 dsiclk[n].divsel_shift);
1555 static int request_dsiescclk(
u8 n,
bool enable)
1560 enable ? (val |= dsiescclk[
n].
en) : (val &= ~dsiescclk[n].en);
1576 return request_sga_clock(clock, enable);
1578 return request_clock(clock, enable);
1580 return request_timclk(enable);
1586 return request_plldsi(enable);
1588 return request_sysclk(enable);
1590 return request_pll(clock, enable);
1595 static unsigned long pll_rate(
void __iomem *
reg,
unsigned long src_rate,
1628 return (
unsigned long)
rate;
1631 #define ROOT_CLOCK_RATE 38400000
1639 val =
readl(clk_mgt[clock].reg);
1661 u64 r = (rate * 10);
1664 return (
unsigned long)
r;
1672 static unsigned long latest_armss_rate;
1673 static unsigned long armss_rate(
void)
1675 return latest_armss_rate;
1678 static void compute_armss_rate(
void)
1703 latest_armss_rate =
rate;
1706 static unsigned long dsiclk_rate(
u8 n)
1712 divsel = ((divsel & dsiclk[
n].
divsel_mask) >> dsiclk[n].divsel_shift);
1730 static unsigned long dsiescclk_rate(
u8 n)
1735 div = ((div & dsiescclk[
n].
div_mask) >> (dsiescclk[n].div_shift));
1752 return armss_rate();
1766 static unsigned long clock_source_rate(
u32 clk_mgt_val,
int branch)
1781 static u32 clock_divider(
unsigned long src_rate,
unsigned long rate)
1785 div = (src_rate /
rate);
1788 if (rate < (src_rate / div))
1793 static long round_clock_rate(
u8 clock,
unsigned long rate)
1797 unsigned long src_rate;
1800 val =
readl(clk_mgt[clock].reg);
1801 src_rate = clock_source_rate((val | clk_mgt[clock].pllsw),
1802 clk_mgt[clock].branch);
1803 div = clock_divider(src_rate, rate);
1804 if (val & PRCM_CLK_MGT_CLK38) {
1805 if (clk_mgt[clock].clk38div) {
1812 u64 r = (src_rate * 10);
1816 return (
unsigned long)
r;
1818 rounded_rate = (src_rate /
min(div, (
u32)31));
1820 return rounded_rate;
1823 #define MIN_PLL_VCO_RATE 600000000ULL
1824 #define MAX_PLL_VCO_RATE 1680640000ULL
1826 static long round_plldsi_rate(
unsigned long rate)
1828 long rounded_rate = 0;
1829 unsigned long src_rate;
1836 for (r = 7; (rem > 0) && (r > 0); r--) {
1851 if (rounded_rate == 0)
1852 rounded_rate = (
long)d;
1855 if ((rate - d) < rem) {
1857 rounded_rate = (
long)d;
1860 return rounded_rate;
1863 static long round_dsiclk_rate(
unsigned long rate)
1866 unsigned long src_rate;
1871 div = clock_divider(src_rate, rate);
1872 rounded_rate = (src_rate / ((div > 2) ? 4 : div));
1874 return rounded_rate;
1877 static long round_dsiescclk_rate(
unsigned long rate)
1880 unsigned long src_rate;
1884 div = clock_divider(src_rate, rate);
1885 rounded_rate = (src_rate /
min(div, (
u32)255));
1887 return rounded_rate;
1893 return round_clock_rate(clock, rate);
1895 return round_plldsi_rate(rate);
1897 return round_dsiclk_rate(rate);
1899 return round_dsiescclk_rate(rate);
1904 static void set_clock_rate(
u8 clock,
unsigned long rate)
1908 unsigned long src_rate;
1909 unsigned long flags;
1917 val =
readl(clk_mgt[clock].reg);
1918 src_rate = clock_source_rate((val | clk_mgt[clock].pllsw),
1919 clk_mgt[clock].branch);
1920 div = clock_divider(src_rate, rate);
1921 if (val & PRCM_CLK_MGT_CLK38) {
1922 if (clk_mgt[clock].clk38div) {
1932 u64 r = (src_rate * 10);
1940 val |=
min(div, (
u32)31);
1943 val |=
min(div, (
u32)31);
1945 writel(val, clk_mgt[clock].reg);
1950 spin_unlock_irqrestore(&clk_mgt_lock, flags);
1953 static int set_plldsi_rate(
unsigned long rate)
1955 unsigned long src_rate;
1963 for (r = 7; (rem > 0) && (r > 0); r--) {
1973 hwrate = (d * src_rate);
1978 if (rate < hwrate) {
1984 if ((rate - hwrate) < rem) {
1985 rem = (rate - hwrate);
1999 static void set_dsiclk_rate(
u8 n,
unsigned long rate)
2017 static void set_dsiescclk_rate(
u8 n,
unsigned long rate)
2032 set_clock_rate(clock, rate);
2034 return set_plldsi_rate(rate);
2107 static int config_hot_period(
u16 val)
2127 if (cycles32k == 0xFFFF)
2130 return config_hot_period(cycles32k);
2135 return config_hot_period(0xFFFF);
2164 BUG_ON(num == 0 || num > 0xf);
2196 (
u8)((timeout << 4) & 0xf0),
2197 (
u8)((timeout >> 4) & 0xff),
2198 (
u8)((timeout >> 12) & 0xff),
2199 (
u8)((timeout >> 20) & 0xff));
2234 pr_err(
"prcmu: %s timed out (20 s) waiting for a reply.\n",
2238 r = ((mb5_transfer.ack.status ==
I2C_RD_OK) ? 0 : -
EIO);
2242 *value = mb5_transfer.ack.value;
2284 pr_err(
"prcmu: %s timed out (20 s) waiting for a reply.\n",
2288 r = ((mb5_transfer.ack.status ==
I2C_WR_OK) ? 0 : -
EIO);
2325 goto unlock_and_return;
2344 #if defined(CONFIG_DBX500_PRCMU_DEBUG)
2345 db8500_prcmu_debug_dump(__func__,
true,
true);
2347 pr_crit(
"prcmu: %s timed out (5 s) waiting for a reply.\n",
2368 goto unlock_and_return;
2370 writel((val & ~PRCM_HOSTACCESS_REQ_HOSTACCESS_REQ),
2375 pr_crit(
"prcmu: %s timed out (5 s) waiting for a reply.\n",
2435 static void ack_dbb_wakeup(
void)
2437 unsigned long flags;
2447 spin_unlock_irqrestore(&mb0_transfer.lock, flags);
2450 static inline void print_unknown_header_warning(
u8 n,
u8 header)
2452 pr_warning(
"prcmu: Unknown message header (%d) in mailbox %d.\n",
2456 static bool read_mailbox_0(
void)
2473 complete(&mb0_transfer.ac_wake_work);
2475 complete(&mb3_transfer.sysclk_work);
2477 ev &= mb0_transfer.req.dbb_irqs;
2479 for (n = 0; n < NUM_PRCMU_WAKEUPS; n++) {
2480 if (ev & prcmu_irq_bit[n])
2486 print_unknown_header_warning(0, header);
2494 static bool read_mailbox_1(
void)
2497 mb1_transfer.ack.arm_opp =
readb(tcdm_base +
2499 mb1_transfer.ack.ape_opp =
readb(tcdm_base +
2501 mb1_transfer.ack.ape_voltage_status =
readb(tcdm_base +
2508 static bool read_mailbox_2(
void)
2516 static bool read_mailbox_3(
void)
2522 static bool read_mailbox_4(
void)
2525 bool do_complete =
true;
2540 print_unknown_header_warning(4, header);
2541 do_complete =
false;
2553 static bool read_mailbox_5(
void)
2562 static bool read_mailbox_6(
void)
2568 static bool read_mailbox_7(
void)
2596 for (n = 0;
bits; n++) {
2599 if (read_mailbox[n]())
2606 static irqreturn_t prcmu_irq_thread_fn(
int irq,
void *data)
2614 unsigned long flags;
2620 spin_unlock_irqrestore(&mb0_transfer.lock, flags);
2623 static void prcmu_irq_mask(
struct irq_data *d)
2625 unsigned long flags;
2629 mb0_transfer.req.dbb_irqs &= ~prcmu_irq_bit[d->
hwirq];
2631 spin_unlock_irqrestore(&mb0_transfer.dbb_irqs_lock, flags);
2633 if (d->
irq != IRQ_PRCMU_CA_SLEEP)
2637 static void prcmu_irq_unmask(
struct irq_data *d)
2639 unsigned long flags;
2643 mb0_transfer.req.dbb_irqs |= prcmu_irq_bit[d->
hwirq];
2645 spin_unlock_irqrestore(&mb0_transfer.dbb_irqs_lock, flags);
2647 if (d->
irq != IRQ_PRCMU_CA_SLEEP)
2651 static void noop(
struct irq_data *d)
2655 static struct irq_chip prcmu_irq_chip = {
2657 .irq_disable = prcmu_irq_mask,
2659 .irq_mask = prcmu_irq_mask,
2660 .irq_unmask = prcmu_irq_unmask,
2663 static char *fw_project_name(
u8 project)
2683 static int db8500_irq_map(
struct irq_domain *d,
unsigned int virq,
2686 irq_set_chip_and_handler(virq, &prcmu_irq_chip,
2694 .map = db8500_irq_map,
2698 static int db8500_irq_init(
struct device_node *np)
2701 np, NUM_PRCMU_WAKEUPS, IRQ_PRCMU_BASE,
2702 0, &db8500_irq_ops,
NULL);
2704 if (!db8500_irq_domain) {
2705 pr_err(
"Failed to create irqdomain\n");
2714 if (cpu_is_u8500v2()) {
2717 if (tcpm_base !=
NULL) {
2725 pr_info(
"PRCMU firmware: %s, version %d.%d.%d\n",
2727 (version >> 8) & 0xFF, (version >> 16) & 0xFF,
2728 (version >> 24) & 0xFF);
2734 pr_err(
"prcmu: Unsupported chip version\n");
2741 init_completion(&mb0_transfer.ac_wake_work);
2743 init_completion(&mb1_transfer.work);
2746 init_completion(&mb2_transfer.work);
2750 init_completion(&mb3_transfer.sysclk_work);
2752 init_completion(&mb4_transfer.work);
2754 init_completion(&mb5_transfer.work);
2756 INIT_WORK(&mb0_transfer.mask_work, prcmu_mask_work);
2758 compute_armss_rate();
2761 static void __init init_prcm_registers(
void)
2848 .name =
"db8500-vape",
2852 .consumer_supplies = db8500_vape_consumers,
2853 .num_consumer_supplies =
ARRAY_SIZE(db8500_vape_consumers),
2857 .name =
"db8500-varm",
2863 .name =
"db8500-vmodem",
2869 .name =
"db8500-vpll",
2875 .name =
"db8500-vsmps1",
2881 .name =
"db8500-vsmps2",
2884 .consumer_supplies = db8500_vsmps2_consumers,
2885 .num_consumer_supplies =
ARRAY_SIZE(db8500_vsmps2_consumers),
2889 .name =
"db8500-vsmps3",
2895 .name =
"db8500-vrf1",
2902 .name =
"db8500-sva-mmdsp",
2905 .consumer_supplies = db8500_svammdsp_consumers,
2906 .num_consumer_supplies =
ARRAY_SIZE(db8500_svammdsp_consumers),
2911 .name =
"db8500-sva-mmdsp-ret",
2918 .name =
"db8500-sva-pipe",
2921 .consumer_supplies = db8500_svapipe_consumers,
2922 .num_consumer_supplies =
ARRAY_SIZE(db8500_svapipe_consumers),
2927 .name =
"db8500-sia-mmdsp",
2930 .consumer_supplies = db8500_siammdsp_consumers,
2931 .num_consumer_supplies =
ARRAY_SIZE(db8500_siammdsp_consumers),
2935 .name =
"db8500-sia-mmdsp-ret",
2942 .name =
"db8500-sia-pipe",
2945 .consumer_supplies = db8500_siapipe_consumers,
2946 .num_consumer_supplies =
ARRAY_SIZE(db8500_siapipe_consumers),
2949 .supply_regulator =
"db8500-vape",
2951 .name =
"db8500-sga",
2954 .consumer_supplies = db8500_sga_consumers,
2955 .num_consumer_supplies =
ARRAY_SIZE(db8500_sga_consumers),
2959 .supply_regulator =
"db8500-vape",
2961 .name =
"db8500-b2r2-mcde",
2964 .consumer_supplies = db8500_b2r2_mcde_consumers,
2965 .num_consumer_supplies =
ARRAY_SIZE(db8500_b2r2_mcde_consumers),
2973 .name =
"db8500-esram12",
2976 .consumer_supplies = db8500_esram12_consumers,
2977 .num_consumer_supplies =
ARRAY_SIZE(db8500_esram12_consumers),
2981 .name =
"db8500-esram12-ret",
2991 .name =
"db8500-esram34",
2994 .consumer_supplies = db8500_esram34_consumers,
2995 .num_consumer_supplies =
ARRAY_SIZE(db8500_esram34_consumers),
2999 .name =
"db8500-esram34-ret",
3005 static struct resource ab8500_resources[] = {
3013 static struct mfd_cell db8500_prcmu_devs[] = {
3015 .name =
"db8500-prcmu-regulators",
3016 .of_compatible =
"stericsson,db8500-prcmu-regulator",
3017 .platform_data = &db8500_regulators,
3018 .pdata_size =
sizeof(db8500_regulators),
3021 .name =
"cpufreq-u8500",
3022 .of_compatible =
"stericsson,cpufreq-u8500",
3025 .name =
"ab8500-core",
3026 .of_compatible =
"stericsson,ab8500",
3027 .num_resources =
ARRAY_SIZE(ab8500_resources),
3028 .resources = ab8500_resources,
3041 int irq = 0,
err = 0,
i;
3046 init_prcm_registers();
3054 if (!np || irq <= 0)
3060 pr_err(
"prcmu: Failed to allocate IRQ_DB8500_PRCMU1.\n");
3065 db8500_irq_init(np);
3067 for (i = 0; i <
ARRAY_SIZE(db8500_prcmu_devs); i++) {
3068 if (!
strcmp(db8500_prcmu_devs[i].
name,
"ab8500-core")) {
3074 if (cpu_is_u8500v20_or_later())
3080 pr_err(
"prcmu: Failed to add subdevices\n");
3084 pr_info(
"DB8500 PRCMU initialized\n");
3089 static const struct of_device_id db8500_prcmu_match[] = {
3090 { .compatible =
"stericsson,db8500-prcmu"},
3096 .name =
"db8500-prcmu",
3098 .of_match_table = db8500_prcmu_match,
3100 .probe = db8500_prcmu_probe,
3103 static int __init db8500_prcmu_init(
void)