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