WIP FPC-III support
[linux/fpc-iii.git] / drivers / clk / clk-fsl-sai.c
blob6238fcea04673052e60e6a2293f021bd44d34d40
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Freescale SAI BCLK as a generic clock driver
5 * Copyright 2020 Michael Walle <michael@walle.cc>
6 */
8 #include <linux/module.h>
9 #include <linux/platform_device.h>
10 #include <linux/clk-provider.h>
11 #include <linux/err.h>
12 #include <linux/of.h>
13 #include <linux/of_address.h>
14 #include <linux/slab.h>
16 #define I2S_CSR 0x00
17 #define I2S_CR2 0x08
18 #define CSR_BCE_BIT 28
19 #define CR2_BCD BIT(24)
20 #define CR2_DIV_SHIFT 0
21 #define CR2_DIV_WIDTH 8
23 struct fsl_sai_clk {
24 struct clk_divider div;
25 struct clk_gate gate;
26 spinlock_t lock;
29 static int fsl_sai_clk_probe(struct platform_device *pdev)
31 struct device *dev = &pdev->dev;
32 struct fsl_sai_clk *sai_clk;
33 struct clk_parent_data pdata = { .index = 0 };
34 void __iomem *base;
35 struct clk_hw *hw;
36 struct resource *res;
38 sai_clk = devm_kzalloc(dev, sizeof(*sai_clk), GFP_KERNEL);
39 if (!sai_clk)
40 return -ENOMEM;
42 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
43 base = devm_ioremap_resource(dev, res);
44 if (IS_ERR(base))
45 return PTR_ERR(base);
47 spin_lock_init(&sai_clk->lock);
49 sai_clk->gate.reg = base + I2S_CSR;
50 sai_clk->gate.bit_idx = CSR_BCE_BIT;
51 sai_clk->gate.lock = &sai_clk->lock;
53 sai_clk->div.reg = base + I2S_CR2;
54 sai_clk->div.shift = CR2_DIV_SHIFT;
55 sai_clk->div.width = CR2_DIV_WIDTH;
56 sai_clk->div.lock = &sai_clk->lock;
58 /* set clock direction, we are the BCLK master */
59 writel(CR2_BCD, base + I2S_CR2);
61 hw = devm_clk_hw_register_composite_pdata(dev, dev->of_node->name,
62 &pdata, 1, NULL, NULL,
63 &sai_clk->div.hw,
64 &clk_divider_ops,
65 &sai_clk->gate.hw,
66 &clk_gate_ops,
67 CLK_SET_RATE_GATE);
68 if (IS_ERR(hw))
69 return PTR_ERR(hw);
71 return devm_of_clk_add_hw_provider(dev, of_clk_hw_simple_get, hw);
74 static const struct of_device_id of_fsl_sai_clk_ids[] = {
75 { .compatible = "fsl,vf610-sai-clock" },
76 { }
78 MODULE_DEVICE_TABLE(of, of_fsl_sai_clk_ids);
80 static struct platform_driver fsl_sai_clk_driver = {
81 .probe = fsl_sai_clk_probe,
82 .driver = {
83 .name = "fsl-sai-clk",
84 .of_match_table = of_fsl_sai_clk_ids,
87 module_platform_driver(fsl_sai_clk_driver);
89 MODULE_DESCRIPTION("Freescale SAI bitclock-as-a-clock driver");
90 MODULE_AUTHOR("Michael Walle <michael@walle.cc>");
91 MODULE_LICENSE("GPL");
92 MODULE_ALIAS("platform:fsl-sai-clk");