1 // SPDX-License-Identifier: GPL-2.0-or-later
2 // Copyright 2020 Cerno
4 #include <linux/clk-provider.h>
5 #include <linux/module.h>
6 #include <linux/platform_device.h>
7 #include <linux/reset-controller.h>
8 #include <linux/reset/reset-simple.h>
10 #define DVP_HT_RPI_SW_INIT 0x04
11 #define DVP_HT_RPI_MISC_CONFIG 0x08
17 struct clk_hw_onecell_data
*data
;
18 struct reset_simple_data reset
;
21 static const struct clk_parent_data clk_dvp_parent
= {
25 static int clk_dvp_probe(struct platform_device
*pdev
)
27 struct clk_hw_onecell_data
*data
;
32 dvp
= devm_kzalloc(&pdev
->dev
, sizeof(*dvp
), GFP_KERNEL
);
35 platform_set_drvdata(pdev
, dvp
);
37 dvp
->data
= devm_kzalloc(&pdev
->dev
,
38 struct_size(dvp
->data
, hws
, NR_CLOCKS
),
44 base
= devm_platform_ioremap_resource(pdev
, 0);
48 dvp
->reset
.rcdev
.owner
= THIS_MODULE
;
49 dvp
->reset
.rcdev
.nr_resets
= NR_RESETS
;
50 dvp
->reset
.rcdev
.ops
= &reset_simple_ops
;
51 dvp
->reset
.rcdev
.of_node
= pdev
->dev
.of_node
;
52 dvp
->reset
.membase
= base
+ DVP_HT_RPI_SW_INIT
;
53 spin_lock_init(&dvp
->reset
.lock
);
55 ret
= devm_reset_controller_register(&pdev
->dev
, &dvp
->reset
.rcdev
);
59 data
->num
= NR_CLOCKS
;
61 data
->hws
[0] = clk_hw_register_gate_parent_data(&pdev
->dev
,
64 base
+ DVP_HT_RPI_MISC_CONFIG
, 3,
65 CLK_GATE_SET_TO_DISABLE
,
67 if (IS_ERR(data
->hws
[0]))
68 return PTR_ERR(data
->hws
[0]);
70 data
->hws
[1] = clk_hw_register_gate_parent_data(&pdev
->dev
,
73 base
+ DVP_HT_RPI_MISC_CONFIG
, 4,
74 CLK_GATE_SET_TO_DISABLE
,
76 if (IS_ERR(data
->hws
[1])) {
77 ret
= PTR_ERR(data
->hws
[1]);
81 ret
= of_clk_add_hw_provider(pdev
->dev
.of_node
, of_clk_hw_onecell_get
,
89 clk_hw_unregister_gate(data
->hws
[1]);
92 clk_hw_unregister_gate(data
->hws
[0]);
96 static void clk_dvp_remove(struct platform_device
*pdev
)
98 struct clk_dvp
*dvp
= platform_get_drvdata(pdev
);
99 struct clk_hw_onecell_data
*data
= dvp
->data
;
101 clk_hw_unregister_gate(data
->hws
[1]);
102 clk_hw_unregister_gate(data
->hws
[0]);
105 static const struct of_device_id clk_dvp_dt_ids
[] = {
106 { .compatible
= "brcm,brcm2711-dvp", },
109 MODULE_DEVICE_TABLE(of
, clk_dvp_dt_ids
);
111 static struct platform_driver clk_dvp_driver
= {
112 .probe
= clk_dvp_probe
,
113 .remove
= clk_dvp_remove
,
115 .name
= "brcm2711-dvp",
116 .of_match_table
= clk_dvp_dt_ids
,
119 module_platform_driver(clk_dvp_driver
);
121 MODULE_AUTHOR("Maxime Ripard <maxime@cerno.tech>");
122 MODULE_DESCRIPTION("BCM2711 DVP clock driver");
123 MODULE_LICENSE("GPL");