Peter Ujfalusi | f9f8c04 | 2012-09-14 17:30:27 +0300 | [diff] [blame] | 1 | /* |
| 2 | * TWL6040 clock module driver for OMAP4 McPDM functional clock |
| 3 | * |
| 4 | * Copyright (C) 2012 Texas Instruments Inc. |
| 5 | * Peter Ujfalusi <peter.ujfalusi@ti.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * version 2 as published by the Free Software Foundation. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, but |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 19 | * 02110-1301 USA |
| 20 | * |
| 21 | */ |
| 22 | |
Peter Ujfalusi | f9f8c04 | 2012-09-14 17:30:27 +0300 | [diff] [blame] | 23 | #include <linux/module.h> |
| 24 | #include <linux/slab.h> |
| 25 | #include <linux/platform_device.h> |
| 26 | #include <linux/mfd/twl6040.h> |
| 27 | #include <linux/clk-provider.h> |
| 28 | |
Peter Ujfalusi | 7e37deb | 2016-05-30 11:55:11 +0300 | [diff] [blame] | 29 | struct twl6040_pdmclk { |
Peter Ujfalusi | f9f8c04 | 2012-09-14 17:30:27 +0300 | [diff] [blame] | 30 | struct twl6040 *twl6040; |
| 31 | struct device *dev; |
Peter Ujfalusi | 7e37deb | 2016-05-30 11:55:11 +0300 | [diff] [blame] | 32 | struct clk_hw pdmclk_hw; |
Peter Ujfalusi | f9f8c04 | 2012-09-14 17:30:27 +0300 | [diff] [blame] | 33 | struct clk *clk; |
| 34 | int enabled; |
| 35 | }; |
| 36 | |
Peter Ujfalusi | 7e37deb | 2016-05-30 11:55:11 +0300 | [diff] [blame] | 37 | static int twl6040_pdmclk_is_prepared(struct clk_hw *hw) |
Peter Ujfalusi | f9f8c04 | 2012-09-14 17:30:27 +0300 | [diff] [blame] | 38 | { |
Peter Ujfalusi | 7e37deb | 2016-05-30 11:55:11 +0300 | [diff] [blame] | 39 | struct twl6040_pdmclk *pdmclk = container_of(hw, struct twl6040_pdmclk, |
| 40 | pdmclk_hw); |
| 41 | |
| 42 | return pdmclk->enabled; |
Peter Ujfalusi | f9f8c04 | 2012-09-14 17:30:27 +0300 | [diff] [blame] | 43 | } |
| 44 | |
Peter Ujfalusi | 7e37deb | 2016-05-30 11:55:11 +0300 | [diff] [blame] | 45 | static int twl6040_pdmclk_prepare(struct clk_hw *hw) |
Peter Ujfalusi | f9f8c04 | 2012-09-14 17:30:27 +0300 | [diff] [blame] | 46 | { |
Peter Ujfalusi | 7e37deb | 2016-05-30 11:55:11 +0300 | [diff] [blame] | 47 | struct twl6040_pdmclk *pdmclk = container_of(hw, struct twl6040_pdmclk, |
| 48 | pdmclk_hw); |
Peter Ujfalusi | f9f8c04 | 2012-09-14 17:30:27 +0300 | [diff] [blame] | 49 | int ret; |
| 50 | |
Peter Ujfalusi | 7e37deb | 2016-05-30 11:55:11 +0300 | [diff] [blame] | 51 | ret = twl6040_power(pdmclk->twl6040, 1); |
Peter Ujfalusi | f9f8c04 | 2012-09-14 17:30:27 +0300 | [diff] [blame] | 52 | if (!ret) |
Peter Ujfalusi | 7e37deb | 2016-05-30 11:55:11 +0300 | [diff] [blame] | 53 | pdmclk->enabled = 1; |
Peter Ujfalusi | f9f8c04 | 2012-09-14 17:30:27 +0300 | [diff] [blame] | 54 | |
| 55 | return ret; |
| 56 | } |
| 57 | |
Peter Ujfalusi | 7e37deb | 2016-05-30 11:55:11 +0300 | [diff] [blame] | 58 | static void twl6040_pdmclk_unprepare(struct clk_hw *hw) |
Peter Ujfalusi | f9f8c04 | 2012-09-14 17:30:27 +0300 | [diff] [blame] | 59 | { |
Peter Ujfalusi | 7e37deb | 2016-05-30 11:55:11 +0300 | [diff] [blame] | 60 | struct twl6040_pdmclk *pdmclk = container_of(hw, struct twl6040_pdmclk, |
| 61 | pdmclk_hw); |
Peter Ujfalusi | f9f8c04 | 2012-09-14 17:30:27 +0300 | [diff] [blame] | 62 | int ret; |
| 63 | |
Peter Ujfalusi | 7e37deb | 2016-05-30 11:55:11 +0300 | [diff] [blame] | 64 | ret = twl6040_power(pdmclk->twl6040, 0); |
Peter Ujfalusi | f9f8c04 | 2012-09-14 17:30:27 +0300 | [diff] [blame] | 65 | if (!ret) |
Peter Ujfalusi | 7e37deb | 2016-05-30 11:55:11 +0300 | [diff] [blame] | 66 | pdmclk->enabled = 0; |
| 67 | |
Peter Ujfalusi | f9f8c04 | 2012-09-14 17:30:27 +0300 | [diff] [blame] | 68 | } |
| 69 | |
Peter Ujfalusi | 7e37deb | 2016-05-30 11:55:11 +0300 | [diff] [blame] | 70 | static unsigned long twl6040_pdmclk_recalc_rate(struct clk_hw *hw, |
| 71 | unsigned long parent_rate) |
| 72 | { |
| 73 | struct twl6040_pdmclk *pdmclk = container_of(hw, struct twl6040_pdmclk, |
| 74 | pdmclk_hw); |
| 75 | |
| 76 | return twl6040_get_sysclk(pdmclk->twl6040); |
| 77 | } |
| 78 | |
| 79 | static const struct clk_ops twl6040_pdmclk_ops = { |
| 80 | .is_prepared = twl6040_pdmclk_is_prepared, |
| 81 | .prepare = twl6040_pdmclk_prepare, |
| 82 | .unprepare = twl6040_pdmclk_unprepare, |
| 83 | .recalc_rate = twl6040_pdmclk_recalc_rate, |
Peter Ujfalusi | f9f8c04 | 2012-09-14 17:30:27 +0300 | [diff] [blame] | 84 | }; |
| 85 | |
Peter Ujfalusi | 7e37deb | 2016-05-30 11:55:11 +0300 | [diff] [blame] | 86 | static struct clk_init_data twl6040_pdmclk_init = { |
| 87 | .name = "pdmclk", |
| 88 | .ops = &twl6040_pdmclk_ops, |
| 89 | .flags = CLK_GET_RATE_NOCACHE, |
Peter Ujfalusi | f9f8c04 | 2012-09-14 17:30:27 +0300 | [diff] [blame] | 90 | }; |
| 91 | |
Peter Ujfalusi | 7e37deb | 2016-05-30 11:55:11 +0300 | [diff] [blame] | 92 | static int twl6040_pdmclk_probe(struct platform_device *pdev) |
Peter Ujfalusi | f9f8c04 | 2012-09-14 17:30:27 +0300 | [diff] [blame] | 93 | { |
| 94 | struct twl6040 *twl6040 = dev_get_drvdata(pdev->dev.parent); |
Peter Ujfalusi | 7e37deb | 2016-05-30 11:55:11 +0300 | [diff] [blame] | 95 | struct twl6040_pdmclk *clkdata; |
Peter Ujfalusi | f9f8c04 | 2012-09-14 17:30:27 +0300 | [diff] [blame] | 96 | |
| 97 | clkdata = devm_kzalloc(&pdev->dev, sizeof(*clkdata), GFP_KERNEL); |
| 98 | if (!clkdata) |
| 99 | return -ENOMEM; |
| 100 | |
| 101 | clkdata->dev = &pdev->dev; |
| 102 | clkdata->twl6040 = twl6040; |
| 103 | |
Peter Ujfalusi | 7e37deb | 2016-05-30 11:55:11 +0300 | [diff] [blame] | 104 | clkdata->pdmclk_hw.init = &twl6040_pdmclk_init; |
| 105 | clkdata->clk = devm_clk_register(&pdev->dev, &clkdata->pdmclk_hw); |
Wei Yongjun | ddc07ef | 2012-11-01 13:33:55 +0800 | [diff] [blame] | 106 | if (IS_ERR(clkdata->clk)) |
| 107 | return PTR_ERR(clkdata->clk); |
Peter Ujfalusi | f9f8c04 | 2012-09-14 17:30:27 +0300 | [diff] [blame] | 108 | |
Jingoo Han | c043103 | 2013-05-24 10:11:46 +0900 | [diff] [blame] | 109 | platform_set_drvdata(pdev, clkdata); |
Peter Ujfalusi | f9f8c04 | 2012-09-14 17:30:27 +0300 | [diff] [blame] | 110 | |
Peter Ujfalusi | 994deaa | 2016-05-30 11:55:10 +0300 | [diff] [blame] | 111 | return of_clk_add_provider(pdev->dev.parent->of_node, |
| 112 | of_clk_src_simple_get, clkdata->clk); |
Peter Ujfalusi | f9f8c04 | 2012-09-14 17:30:27 +0300 | [diff] [blame] | 113 | } |
| 114 | |
Peter Ujfalusi | 7e37deb | 2016-05-30 11:55:11 +0300 | [diff] [blame] | 115 | static struct platform_driver twl6040_pdmclk_driver = { |
Peter Ujfalusi | f9f8c04 | 2012-09-14 17:30:27 +0300 | [diff] [blame] | 116 | .driver = { |
Peter Ujfalusi | 7e37deb | 2016-05-30 11:55:11 +0300 | [diff] [blame] | 117 | .name = "twl6040-pdmclk", |
Peter Ujfalusi | f9f8c04 | 2012-09-14 17:30:27 +0300 | [diff] [blame] | 118 | }, |
Peter Ujfalusi | 7e37deb | 2016-05-30 11:55:11 +0300 | [diff] [blame] | 119 | .probe = twl6040_pdmclk_probe, |
Peter Ujfalusi | f9f8c04 | 2012-09-14 17:30:27 +0300 | [diff] [blame] | 120 | }; |
| 121 | |
Peter Ujfalusi | 7e37deb | 2016-05-30 11:55:11 +0300 | [diff] [blame] | 122 | module_platform_driver(twl6040_pdmclk_driver); |
Peter Ujfalusi | f9f8c04 | 2012-09-14 17:30:27 +0300 | [diff] [blame] | 123 | |
| 124 | MODULE_DESCRIPTION("TWL6040 clock driver for McPDM functional clock"); |
| 125 | MODULE_AUTHOR("Peter Ujfalusi <peter.ujfalusi@ti.com>"); |
Peter Ujfalusi | 7e37deb | 2016-05-30 11:55:11 +0300 | [diff] [blame] | 126 | MODULE_ALIAS("platform:twl6040-pdmclk"); |
Peter Ujfalusi | f9f8c04 | 2012-09-14 17:30:27 +0300 | [diff] [blame] | 127 | MODULE_LICENSE("GPL"); |