-
Notifications
You must be signed in to change notification settings - Fork 0
/
imx93-ccm-clko.c
117 lines (91 loc) · 2.52 KB
/
imx93-ccm-clko.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// SPDX-License-Identifier: GPL-2.0
/*
* i.MX93 CCM CLKO driver
*
* Copyright 2023 Norik Systems d.o.o
* Author: Primoz Fiser <[email protected]>
*/
#include <linux/clk.h>
#include <linux/err.h>
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
#include <linux/module.h>
struct imx93_ccm_clko {
struct platform_device *pdev;
struct device *dev;
struct clk *clk;
};
static int imx93_ccm_clko_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct imx93_ccm_clko *icc;
int ret;
icc = devm_kzalloc(dev, sizeof(*icc), GFP_KERNEL);
if (!icc)
return -ENOMEM;
icc->pdev = pdev;
icc->dev = dev;
platform_set_drvdata(pdev, icc);
dev_info(dev, "Driver probing...\n");
icc->clk = devm_clk_get(dev, NULL);
if (IS_ERR(icc->clk)) {
return dev_err_probe(dev,
PTR_ERR(icc->clk), "Failed getting clock\n");
}
dev_info(dev, "Enabling clock\n");
ret = clk_prepare_enable(icc->clk);
if (ret) {
dev_err(dev, "Could not prepare or enable the clock.\n");
return ret;
}
dev_info(dev, "Clock rate = %ld\n", clk_get_rate(icc->clk));
return ret;
}
static int imx93_ccm_clko_remove(struct platform_device *pdev)
{
struct imx93_ccm_clko *icc = platform_get_drvdata(pdev);
clk_disable_unprepare(icc->clk);
return 0;
}
static int imx93_ccm_clko_suspend(struct device *dev)
{
struct platform_device *pdev = to_platform_device(dev);
struct imx93_ccm_clko *icc = platform_get_drvdata(pdev);
clk_disable_unprepare(icc->clk);
return 0;
}
static int imx93_ccm_clko_resume(struct device *dev)
{
struct platform_device *pdev = to_platform_device(dev);
struct imx93_ccm_clko *icc = platform_get_drvdata(pdev);
int ret;
ret = clk_prepare_enable(icc->clk);
if (ret) {
dev_err(dev, "Could not prepare or enable the clock.\n");
return ret;
}
return 0;
}
static const struct of_device_id imx93_ccm_clko_match[] = {
{ .compatible = "nxp,imx93-ccm-clko", },
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, imx93_ccm_clko_match);
static const struct dev_pm_ops imx93_ccm_clko_pm_ops = {
.suspend = imx93_ccm_clko_suspend,
.resume = imx93_ccm_clko_resume,
};
static struct platform_driver imx93_ccm_clko_driver = {
.probe = imx93_ccm_clko_probe,
.remove = imx93_ccm_clko_remove,
.driver = {
.name = "imx93-ccm-clko",
.of_match_table = imx93_ccm_clko_match,
.pm = &imx93_ccm_clko_pm_ops,
},
};
module_platform_driver(imx93_ccm_clko_driver);
MODULE_DESCRIPTION("i.MX93 CCM CLKO driver");
MODULE_AUTHOR("Primoz Fiser <[email protected]>");
MODULE_LICENSE("GPL");