22
22
#include <linux/slab.h>
23
23
#include <linux/platform_device.h>
24
24
25
- /* Clock rate of CLK44EN attached to GPIO6 pin */
26
- #define CLK_44EN_RATE 22579200UL
27
- /* Clock rate of CLK48EN attached to GPIO3 pin */
28
- #define CLK_48EN_RATE 24576000UL
25
+ struct ext_clk_rates {
26
+ /* Clock rate of CLK44EN attached to GPIO6 pin */
27
+ unsigned long clk_44en ;
28
+ /* Clock rate of CLK48EN attached to GPIO3 pin */
29
+ unsigned long clk_48en ;
30
+ };
29
31
30
32
/**
31
33
* struct hifiberry_dacpro_clk - Common struct to the HiFiBerry DAC Pro
35
37
struct clk_hifiberry_hw {
36
38
struct clk_hw hw ;
37
39
uint8_t mode ;
40
+ struct ext_clk_rates clk_rates ;
38
41
};
39
42
40
43
#define to_hifiberry_clk (_hw ) container_of(_hw, struct clk_hifiberry_hw, hw)
41
44
45
+ static const struct ext_clk_rates hifiberry_dacpro_clks = {
46
+ .clk_44en = 22579200UL ,
47
+ .clk_48en = 24576000UL ,
48
+ };
49
+
50
+ static const struct ext_clk_rates allo_dac_clks = {
51
+ .clk_44en = 45158400UL ,
52
+ .clk_48en = 49152000UL ,
53
+ };
54
+
42
55
static const struct of_device_id clk_hifiberry_dacpro_dt_ids [] = {
43
- { .compatible = "hifiberry,dacpro-clk" ,},
56
+ { .compatible = "hifiberry,dacpro-clk" , & hifiberry_dacpro_clks },
57
+ { .compatible = "allo,dac-clk" , & allo_dac_clks },
44
58
{ }
45
59
};
46
60
MODULE_DEVICE_TABLE (of , clk_hifiberry_dacpro_dt_ids );
47
61
48
62
static unsigned long clk_hifiberry_dacpro_recalc_rate (struct clk_hw * hw ,
49
63
unsigned long parent_rate )
50
64
{
51
- return (to_hifiberry_clk (hw )-> mode == 0 ) ? CLK_44EN_RATE :
52
- CLK_48EN_RATE ;
65
+ struct clk_hifiberry_hw * clk = to_hifiberry_clk (hw );
66
+ return (clk -> mode == 0 ) ? clk -> clk_rates .clk_44en :
67
+ clk -> clk_rates .clk_48en ;
53
68
}
54
69
55
70
static long clk_hifiberry_dacpro_round_rate (struct clk_hw * hw ,
56
71
unsigned long rate , unsigned long * parent_rate )
57
72
{
73
+ struct clk_hifiberry_hw * clk = to_hifiberry_clk (hw );
58
74
long actual_rate ;
59
75
60
- if (rate <= CLK_44EN_RATE ) {
61
- actual_rate = (long )CLK_44EN_RATE ;
62
- } else if (rate >= CLK_48EN_RATE ) {
63
- actual_rate = (long )CLK_48EN_RATE ;
76
+ if (rate <= clk -> clk_rates . clk_44en ) {
77
+ actual_rate = (long )clk -> clk_rates . clk_44en ;
78
+ } else if (rate >= clk -> clk_rates . clk_48en ) {
79
+ actual_rate = (long )clk -> clk_rates . clk_48en ;
64
80
} else {
65
- long diff44Rate = (long )(rate - CLK_44EN_RATE );
66
- long diff48Rate = (long )(CLK_48EN_RATE - rate );
81
+ long diff44Rate = (long )(rate - clk -> clk_rates . clk_44en );
82
+ long diff48Rate = (long )(clk -> clk_rates . clk_48en - rate );
67
83
68
84
if (diff44Rate < diff48Rate )
69
- actual_rate = (long )CLK_44EN_RATE ;
85
+ actual_rate = (long )clk -> clk_rates . clk_44en ;
70
86
else
71
- actual_rate = (long )CLK_48EN_RATE ;
87
+ actual_rate = (long )clk -> clk_rates . clk_48en ;
72
88
}
73
89
return actual_rate ;
74
90
}
@@ -77,12 +93,12 @@ static long clk_hifiberry_dacpro_round_rate(struct clk_hw *hw,
77
93
static int clk_hifiberry_dacpro_set_rate (struct clk_hw * hw ,
78
94
unsigned long rate , unsigned long parent_rate )
79
95
{
80
- unsigned long actual_rate ;
81
96
struct clk_hifiberry_hw * clk = to_hifiberry_clk (hw );
97
+ unsigned long actual_rate ;
82
98
83
99
actual_rate = (unsigned long )clk_hifiberry_dacpro_round_rate (hw , rate ,
84
100
& parent_rate );
85
- clk -> mode = (actual_rate == CLK_44EN_RATE ) ? 0 : 1 ;
101
+ clk -> mode = (actual_rate == clk -> clk_rates . clk_44en ) ? 0 : 1 ;
86
102
return 0 ;
87
103
}
88
104
@@ -95,13 +111,17 @@ const struct clk_ops clk_hifiberry_dacpro_rate_ops = {
95
111
96
112
static int clk_hifiberry_dacpro_probe (struct platform_device * pdev )
97
113
{
98
- int ret ;
114
+ const struct of_device_id * of_id ;
99
115
struct clk_hifiberry_hw * proclk ;
100
116
struct clk * clk ;
101
117
struct device * dev ;
102
118
struct clk_init_data init ;
119
+ int ret ;
103
120
104
121
dev = & pdev -> dev ;
122
+ of_id = of_match_node (clk_hifiberry_dacpro_dt_ids , dev -> of_node );
123
+ if (!of_id )
124
+ return - EINVAL ;
105
125
106
126
proclk = kzalloc (sizeof (struct clk_hifiberry_hw ), GFP_KERNEL );
107
127
if (!proclk )
@@ -115,6 +135,7 @@ static int clk_hifiberry_dacpro_probe(struct platform_device *pdev)
115
135
116
136
proclk -> mode = 0 ;
117
137
proclk -> hw .init = & init ;
138
+ memcpy (& proclk -> clk_rates , of_id -> data , sizeof (proclk -> clk_rates ));
118
139
119
140
clk = devm_clk_register (dev , & proclk -> hw );
120
141
if (!IS_ERR (clk )) {
0 commit comments