1 // SPDX-License-Identifier: GPL-2.0-only
3 * TWL6040 clock module driver for OMAP4 McPDM functional clock
5 * Copyright (C) 2012 Texas Instruments Inc.
6 * Peter Ujfalusi <peter.ujfalusi@ti.com>
9 #include <linux/module.h>
10 #include <linux/slab.h>
11 #include <linux/platform_device.h>
12 #include <linux/mfd/twl6040.h>
13 #include <linux/clk-provider.h>
15 struct twl6040_pdmclk
{
16 struct twl6040
*twl6040
;
18 struct clk_hw pdmclk_hw
;
22 static int twl6040_pdmclk_is_prepared(struct clk_hw
*hw
)
24 struct twl6040_pdmclk
*pdmclk
= container_of(hw
, struct twl6040_pdmclk
,
27 return pdmclk
->enabled
;
30 static int twl6040_pdmclk_reset_one_clock(struct twl6040_pdmclk
*pdmclk
,
33 const u8 reset_mask
= TWL6040_HPLLRST
; /* Same for HPPLL and LPPLL */
36 ret
= twl6040_set_bits(pdmclk
->twl6040
, reg
, reset_mask
);
40 ret
= twl6040_clear_bits(pdmclk
->twl6040
, reg
, reset_mask
);
48 * TWL6040A2 Phoenix Audio IC erratum #6: "PDM Clock Generation Issue At
49 * Cold Temperature". This affects cold boot and deeper idle states it
50 * seems. The workaround consists of resetting HPPLL and LPPLL.
52 static int twl6040_pdmclk_quirk_reset_clocks(struct twl6040_pdmclk
*pdmclk
)
56 ret
= twl6040_pdmclk_reset_one_clock(pdmclk
, TWL6040_REG_HPPLLCTL
);
60 ret
= twl6040_pdmclk_reset_one_clock(pdmclk
, TWL6040_REG_LPPLLCTL
);
67 static int twl6040_pdmclk_prepare(struct clk_hw
*hw
)
69 struct twl6040_pdmclk
*pdmclk
= container_of(hw
, struct twl6040_pdmclk
,
73 ret
= twl6040_power(pdmclk
->twl6040
, 1);
77 ret
= twl6040_pdmclk_quirk_reset_clocks(pdmclk
);
86 dev_err(pdmclk
->dev
, "%s: error %i\n", __func__
, ret
);
87 twl6040_power(pdmclk
->twl6040
, 0);
92 static void twl6040_pdmclk_unprepare(struct clk_hw
*hw
)
94 struct twl6040_pdmclk
*pdmclk
= container_of(hw
, struct twl6040_pdmclk
,
98 ret
= twl6040_power(pdmclk
->twl6040
, 0);
104 static unsigned long twl6040_pdmclk_recalc_rate(struct clk_hw
*hw
,
105 unsigned long parent_rate
)
107 struct twl6040_pdmclk
*pdmclk
= container_of(hw
, struct twl6040_pdmclk
,
110 return twl6040_get_sysclk(pdmclk
->twl6040
);
113 static const struct clk_ops twl6040_pdmclk_ops
= {
114 .is_prepared
= twl6040_pdmclk_is_prepared
,
115 .prepare
= twl6040_pdmclk_prepare
,
116 .unprepare
= twl6040_pdmclk_unprepare
,
117 .recalc_rate
= twl6040_pdmclk_recalc_rate
,
120 static const struct clk_init_data twl6040_pdmclk_init
= {
122 .ops
= &twl6040_pdmclk_ops
,
123 .flags
= CLK_GET_RATE_NOCACHE
,
126 static int twl6040_pdmclk_probe(struct platform_device
*pdev
)
128 struct twl6040
*twl6040
= dev_get_drvdata(pdev
->dev
.parent
);
129 struct twl6040_pdmclk
*clkdata
;
132 clkdata
= devm_kzalloc(&pdev
->dev
, sizeof(*clkdata
), GFP_KERNEL
);
136 clkdata
->dev
= &pdev
->dev
;
137 clkdata
->twl6040
= twl6040
;
139 clkdata
->pdmclk_hw
.init
= &twl6040_pdmclk_init
;
140 ret
= devm_clk_hw_register(&pdev
->dev
, &clkdata
->pdmclk_hw
);
144 platform_set_drvdata(pdev
, clkdata
);
146 return devm_of_clk_add_hw_provider(&pdev
->dev
, of_clk_hw_simple_get
,
147 &clkdata
->pdmclk_hw
);
150 static struct platform_driver twl6040_pdmclk_driver
= {
152 .name
= "twl6040-pdmclk",
154 .probe
= twl6040_pdmclk_probe
,
157 module_platform_driver(twl6040_pdmclk_driver
);
159 MODULE_DESCRIPTION("TWL6040 clock driver for McPDM functional clock");
160 MODULE_AUTHOR("Peter Ujfalusi <peter.ujfalusi@ti.com>");
161 MODULE_ALIAS("platform:twl6040-pdmclk");
162 MODULE_LICENSE("GPL");