2019-05-30 06:57:50 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2012-09-14 21:30:27 +07:00
|
|
|
/*
|
|
|
|
* TWL6040 clock module driver for OMAP4 McPDM functional clock
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Texas Instruments Inc.
|
|
|
|
* Peter Ujfalusi <peter.ujfalusi@ti.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/mfd/twl6040.h>
|
|
|
|
#include <linux/clk-provider.h>
|
|
|
|
|
2016-05-30 15:55:11 +07:00
|
|
|
struct twl6040_pdmclk {
|
2012-09-14 21:30:27 +07:00
|
|
|
struct twl6040 *twl6040;
|
|
|
|
struct device *dev;
|
2016-05-30 15:55:11 +07:00
|
|
|
struct clk_hw pdmclk_hw;
|
2012-09-14 21:30:27 +07:00
|
|
|
int enabled;
|
|
|
|
};
|
|
|
|
|
2016-05-30 15:55:11 +07:00
|
|
|
static int twl6040_pdmclk_is_prepared(struct clk_hw *hw)
|
2012-09-14 21:30:27 +07:00
|
|
|
{
|
2016-05-30 15:55:11 +07:00
|
|
|
struct twl6040_pdmclk *pdmclk = container_of(hw, struct twl6040_pdmclk,
|
|
|
|
pdmclk_hw);
|
|
|
|
|
|
|
|
return pdmclk->enabled;
|
2012-09-14 21:30:27 +07:00
|
|
|
}
|
|
|
|
|
2019-02-12 05:59:07 +07:00
|
|
|
static int twl6040_pdmclk_reset_one_clock(struct twl6040_pdmclk *pdmclk,
|
|
|
|
unsigned int reg)
|
|
|
|
{
|
|
|
|
const u8 reset_mask = TWL6040_HPLLRST; /* Same for HPPLL and LPPLL */
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = twl6040_set_bits(pdmclk->twl6040, reg, reset_mask);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = twl6040_clear_bits(pdmclk->twl6040, reg, reset_mask);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TWL6040A2 Phoenix Audio IC erratum #6: "PDM Clock Generation Issue At
|
|
|
|
* Cold Temperature". This affects cold boot and deeper idle states it
|
|
|
|
* seems. The workaround consists of resetting HPPLL and LPPLL.
|
|
|
|
*/
|
|
|
|
static int twl6040_pdmclk_quirk_reset_clocks(struct twl6040_pdmclk *pdmclk)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = twl6040_pdmclk_reset_one_clock(pdmclk, TWL6040_REG_HPPLLCTL);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = twl6040_pdmclk_reset_one_clock(pdmclk, TWL6040_REG_LPPLLCTL);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-05-30 15:55:11 +07:00
|
|
|
static int twl6040_pdmclk_prepare(struct clk_hw *hw)
|
2012-09-14 21:30:27 +07:00
|
|
|
{
|
2016-05-30 15:55:11 +07:00
|
|
|
struct twl6040_pdmclk *pdmclk = container_of(hw, struct twl6040_pdmclk,
|
|
|
|
pdmclk_hw);
|
2012-09-14 21:30:27 +07:00
|
|
|
int ret;
|
|
|
|
|
2016-05-30 15:55:11 +07:00
|
|
|
ret = twl6040_power(pdmclk->twl6040, 1);
|
2019-02-12 05:59:07 +07:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = twl6040_pdmclk_quirk_reset_clocks(pdmclk);
|
|
|
|
if (ret)
|
|
|
|
goto out_err;
|
|
|
|
|
|
|
|
pdmclk->enabled = 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_err:
|
|
|
|
dev_err(pdmclk->dev, "%s: error %i\n", __func__, ret);
|
|
|
|
twl6040_power(pdmclk->twl6040, 0);
|
2012-09-14 21:30:27 +07:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-05-30 15:55:11 +07:00
|
|
|
static void twl6040_pdmclk_unprepare(struct clk_hw *hw)
|
2012-09-14 21:30:27 +07:00
|
|
|
{
|
2016-05-30 15:55:11 +07:00
|
|
|
struct twl6040_pdmclk *pdmclk = container_of(hw, struct twl6040_pdmclk,
|
|
|
|
pdmclk_hw);
|
2012-09-14 21:30:27 +07:00
|
|
|
int ret;
|
|
|
|
|
2016-05-30 15:55:11 +07:00
|
|
|
ret = twl6040_power(pdmclk->twl6040, 0);
|
2012-09-14 21:30:27 +07:00
|
|
|
if (!ret)
|
2016-05-30 15:55:11 +07:00
|
|
|
pdmclk->enabled = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned long twl6040_pdmclk_recalc_rate(struct clk_hw *hw,
|
|
|
|
unsigned long parent_rate)
|
|
|
|
{
|
|
|
|
struct twl6040_pdmclk *pdmclk = container_of(hw, struct twl6040_pdmclk,
|
|
|
|
pdmclk_hw);
|
|
|
|
|
|
|
|
return twl6040_get_sysclk(pdmclk->twl6040);
|
2012-09-14 21:30:27 +07:00
|
|
|
}
|
|
|
|
|
2016-05-30 15:55:11 +07:00
|
|
|
static const struct clk_ops twl6040_pdmclk_ops = {
|
|
|
|
.is_prepared = twl6040_pdmclk_is_prepared,
|
|
|
|
.prepare = twl6040_pdmclk_prepare,
|
|
|
|
.unprepare = twl6040_pdmclk_unprepare,
|
|
|
|
.recalc_rate = twl6040_pdmclk_recalc_rate,
|
2012-09-14 21:30:27 +07:00
|
|
|
};
|
|
|
|
|
2017-08-18 17:08:17 +07:00
|
|
|
static const struct clk_init_data twl6040_pdmclk_init = {
|
2016-05-30 15:55:11 +07:00
|
|
|
.name = "pdmclk",
|
|
|
|
.ops = &twl6040_pdmclk_ops,
|
|
|
|
.flags = CLK_GET_RATE_NOCACHE,
|
2012-09-14 21:30:27 +07:00
|
|
|
};
|
|
|
|
|
2016-05-30 15:55:11 +07:00
|
|
|
static int twl6040_pdmclk_probe(struct platform_device *pdev)
|
2012-09-14 21:30:27 +07:00
|
|
|
{
|
|
|
|
struct twl6040 *twl6040 = dev_get_drvdata(pdev->dev.parent);
|
2016-05-30 15:55:11 +07:00
|
|
|
struct twl6040_pdmclk *clkdata;
|
2016-06-02 06:15:30 +07:00
|
|
|
int ret;
|
2012-09-14 21:30:27 +07:00
|
|
|
|
|
|
|
clkdata = devm_kzalloc(&pdev->dev, sizeof(*clkdata), GFP_KERNEL);
|
|
|
|
if (!clkdata)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
clkdata->dev = &pdev->dev;
|
|
|
|
clkdata->twl6040 = twl6040;
|
|
|
|
|
2016-05-30 15:55:11 +07:00
|
|
|
clkdata->pdmclk_hw.init = &twl6040_pdmclk_init;
|
2016-06-02 06:15:30 +07:00
|
|
|
ret = devm_clk_hw_register(&pdev->dev, &clkdata->pdmclk_hw);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2012-09-14 21:30:27 +07:00
|
|
|
|
2013-05-24 08:11:46 +07:00
|
|
|
platform_set_drvdata(pdev, clkdata);
|
2012-09-14 21:30:27 +07:00
|
|
|
|
2018-12-04 18:38:32 +07:00
|
|
|
return devm_of_clk_add_hw_provider(&pdev->dev, of_clk_hw_simple_get,
|
|
|
|
&clkdata->pdmclk_hw);
|
2012-09-14 21:30:27 +07:00
|
|
|
}
|
|
|
|
|
2016-05-30 15:55:11 +07:00
|
|
|
static struct platform_driver twl6040_pdmclk_driver = {
|
2012-09-14 21:30:27 +07:00
|
|
|
.driver = {
|
2016-05-30 15:55:11 +07:00
|
|
|
.name = "twl6040-pdmclk",
|
2012-09-14 21:30:27 +07:00
|
|
|
},
|
2016-05-30 15:55:11 +07:00
|
|
|
.probe = twl6040_pdmclk_probe,
|
2012-09-14 21:30:27 +07:00
|
|
|
};
|
|
|
|
|
2016-05-30 15:55:11 +07:00
|
|
|
module_platform_driver(twl6040_pdmclk_driver);
|
2012-09-14 21:30:27 +07:00
|
|
|
|
|
|
|
MODULE_DESCRIPTION("TWL6040 clock driver for McPDM functional clock");
|
|
|
|
MODULE_AUTHOR("Peter Ujfalusi <peter.ujfalusi@ti.com>");
|
2016-05-30 15:55:11 +07:00
|
|
|
MODULE_ALIAS("platform:twl6040-pdmclk");
|
2012-09-14 21:30:27 +07:00
|
|
|
MODULE_LICENSE("GPL");
|