blob: f38372ec60bcad4d8c630001d164630f2f99dc32 [file] [log] [blame]
Sean Andersonb7860542020-06-24 06:41:12 -04001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2020 Sean Anderson <seanga2@gmail.com>
4 */
5
Sean Andersonb7860542020-06-24 06:41:12 -04006#include <clk.h>
7#include <dm.h>
8
9/*
10 * Power domains are taken care of by driver_probe, so we just have to enable
11 * clocks
12 */
13static int simple_pm_bus_probe(struct udevice *dev)
14{
15 int ret;
16 struct clk_bulk *bulk = dev_get_priv(dev);
17
18 ret = clk_get_bulk(dev, bulk);
19 if (ret)
20 return ret;
21
22 ret = clk_enable_bulk(bulk);
Simon Glass08738222021-03-25 10:26:10 +130023 if (ret && ret != -ENOSYS) {
Sean Andersonb7860542020-06-24 06:41:12 -040024 clk_release_bulk(bulk);
25 return ret;
26 }
27 return 0;
28}
29
30static int simple_pm_bus_remove(struct udevice *dev)
31{
32 int ret;
33 struct clk_bulk *bulk = dev_get_priv(dev);
34
35 ret = clk_release_bulk(bulk);
Simon Glass08738222021-03-25 10:26:10 +130036 if (ret && ret != -ENOSYS)
Sean Andersonb7860542020-06-24 06:41:12 -040037 return ret;
38 else
39 return 0;
40}
41
42static const struct udevice_id simple_pm_bus_ids[] = {
43 { .compatible = "simple-pm-bus" },
44 { }
45};
46
47U_BOOT_DRIVER(simple_pm_bus_drv) = {
48 .name = "simple_pm_bus",
49 .id = UCLASS_SIMPLE_BUS,
50 .of_match = simple_pm_bus_ids,
51 .probe = simple_pm_bus_probe,
52 .remove = simple_pm_bus_remove,
Simon Glass8a2b47f2020-12-03 16:55:17 -070053 .priv_auto = sizeof(struct clk_bulk),
Sean Andersonb7860542020-06-24 06:41:12 -040054 .flags = DM_FLAG_PRE_RELOC,
55};