blob: 1bb0d86e289dc1bea90ffcb93c051afc7fa1ddc8 [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
Tom Riniabb9a042024-05-18 20:20:43 -06006#include <common.h>
Sean Andersonb7860542020-06-24 06:41:12 -04007#include <clk.h>
8#include <dm.h>
9
10/*
11 * Power domains are taken care of by driver_probe, so we just have to enable
12 * clocks
13 */
14static int simple_pm_bus_probe(struct udevice *dev)
15{
16 int ret;
17 struct clk_bulk *bulk = dev_get_priv(dev);
18
19 ret = clk_get_bulk(dev, bulk);
20 if (ret)
21 return ret;
22
23 ret = clk_enable_bulk(bulk);
Simon Glass08738222021-03-25 10:26:10 +130024 if (ret && ret != -ENOSYS) {
Sean Andersonb7860542020-06-24 06:41:12 -040025 clk_release_bulk(bulk);
26 return ret;
27 }
28 return 0;
29}
30
31static int simple_pm_bus_remove(struct udevice *dev)
32{
33 int ret;
34 struct clk_bulk *bulk = dev_get_priv(dev);
35
36 ret = clk_release_bulk(bulk);
Simon Glass08738222021-03-25 10:26:10 +130037 if (ret && ret != -ENOSYS)
Sean Andersonb7860542020-06-24 06:41:12 -040038 return ret;
39 else
40 return 0;
41}
42
43static const struct udevice_id simple_pm_bus_ids[] = {
44 { .compatible = "simple-pm-bus" },
45 { }
46};
47
48U_BOOT_DRIVER(simple_pm_bus_drv) = {
49 .name = "simple_pm_bus",
50 .id = UCLASS_SIMPLE_BUS,
51 .of_match = simple_pm_bus_ids,
52 .probe = simple_pm_bus_probe,
53 .remove = simple_pm_bus_remove,
Simon Glass8a2b47f2020-12-03 16:55:17 -070054 .priv_auto = sizeof(struct clk_bulk),
Sean Andersonb7860542020-06-24 06:41:12 -040055 .flags = DM_FLAG_PRE_RELOC,
56};