1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * TI clock utilities
4 *
5 * Copyright (C) 2020 Dario Binacchi <dariobin@libero.it>
6 */
7
8 #include <common.h>
9 #include <fdtdec.h>
10 #include <asm/io.h>
11 #include "clk.h"
12
clk_ti_rmw(u32 val,u32 mask,fdt_addr_t reg)13 static void clk_ti_rmw(u32 val, u32 mask, fdt_addr_t reg)
14 {
15 u32 v;
16
17 v = readl(reg);
18 v &= ~mask;
19 v |= val;
20 writel(v, reg);
21 }
22
clk_ti_latch(fdt_addr_t reg,s8 shift)23 void clk_ti_latch(fdt_addr_t reg, s8 shift)
24 {
25 u32 latch;
26
27 if (shift < 0)
28 return;
29
30 latch = 1 << shift;
31
32 clk_ti_rmw(latch, latch, reg);
33 clk_ti_rmw(0, latch, reg);
34 readl(reg); /* OCP barrier */
35 }
36