blob: 96b27e6e5ade26751379523f7e89d05cd05ae423 [file] [log] [blame]
Philippe Reynes5aa6cfb2019-03-15 15:14:36 +01001// SPDX-License-Identifier: GPL-2.0+
2
3#include <common.h>
4#include "brcmnand_compat.h"
5
6struct clk *devm_clk_get(struct udevice *dev, const char *id)
7{
8 struct clk *clk;
9 int ret;
10
11 clk = devm_kzalloc(dev, sizeof(*clk), GFP_KERNEL);
12 if (!clk) {
13 debug("%s: can't allocate clock\n", __func__);
14 return ERR_PTR(-ENOMEM);
15 }
16
17 ret = clk_get_by_name(dev, id, clk);
18 if (ret < 0) {
19 debug("%s: can't get clock (ret = %d)!\n", __func__, ret);
20 return ERR_PTR(ret);
21 }
22
23 return clk;
24}
25
26int clk_prepare_enable(struct clk *clk)
27{
28 return clk_enable(clk);
29}
30
31void clk_disable_unprepare(struct clk *clk)
32{
33 clk_disable(clk);
34}
35
36static char *devm_kvasprintf(struct udevice *dev, gfp_t gfp, const char *fmt,
37 va_list ap)
38{
39 unsigned int len;
40 char *p;
41 va_list aq;
42
43 va_copy(aq, ap);
44 len = vsnprintf(NULL, 0, fmt, aq);
45 va_end(aq);
46
47 p = devm_kmalloc(dev, len + 1, gfp);
48 if (!p)
49 return NULL;
50
51 vsnprintf(p, len + 1, fmt, ap);
52
53 return p;
54}
55
56char *devm_kasprintf(struct udevice *dev, gfp_t gfp, const char *fmt, ...)
57{
58 va_list ap;
59 char *p;
60
61 va_start(ap, fmt);
62 p = devm_kvasprintf(dev, gfp, fmt, ap);
63 va_end(ap);
64
65 return p;
66}