Merge tag 'perf-core-for-mingo-5.2-20190517' of git://git.kernel.org/pub/scm/linux...
[linux-2.6-microblaze.git] / drivers / clk / bcm / clk-bcm2835-aux.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2015 Broadcom
4  */
5
6 #include <linux/clk.h>
7 #include <linux/clk-provider.h>
8 #include <linux/module.h>
9 #include <linux/platform_device.h>
10 #include <dt-bindings/clock/bcm2835-aux.h>
11
12 #define BCM2835_AUXIRQ          0x00
13 #define BCM2835_AUXENB          0x04
14
15 static int bcm2835_aux_clk_probe(struct platform_device *pdev)
16 {
17         struct device *dev = &pdev->dev;
18         struct clk_hw_onecell_data *onecell;
19         const char *parent;
20         struct clk *parent_clk;
21         struct resource *res;
22         void __iomem *reg, *gate;
23
24         parent_clk = devm_clk_get(dev, NULL);
25         if (IS_ERR(parent_clk))
26                 return PTR_ERR(parent_clk);
27         parent = __clk_get_name(parent_clk);
28
29         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
30         reg = devm_ioremap_resource(dev, res);
31         if (IS_ERR(reg))
32                 return PTR_ERR(reg);
33
34         onecell = devm_kmalloc(dev,
35                                struct_size(onecell, hws,
36                                            BCM2835_AUX_CLOCK_COUNT),
37                                GFP_KERNEL);
38         if (!onecell)
39                 return -ENOMEM;
40         onecell->num = BCM2835_AUX_CLOCK_COUNT;
41
42         gate = reg + BCM2835_AUXENB;
43         onecell->hws[BCM2835_AUX_CLOCK_UART] =
44                 clk_hw_register_gate(dev, "aux_uart", parent, 0, gate, 0, 0, NULL);
45
46         onecell->hws[BCM2835_AUX_CLOCK_SPI1] =
47                 clk_hw_register_gate(dev, "aux_spi1", parent, 0, gate, 1, 0, NULL);
48
49         onecell->hws[BCM2835_AUX_CLOCK_SPI2] =
50                 clk_hw_register_gate(dev, "aux_spi2", parent, 0, gate, 2, 0, NULL);
51
52         return of_clk_add_hw_provider(pdev->dev.of_node, of_clk_hw_onecell_get,
53                                       onecell);
54 }
55
56 static const struct of_device_id bcm2835_aux_clk_of_match[] = {
57         { .compatible = "brcm,bcm2835-aux", },
58         {},
59 };
60 MODULE_DEVICE_TABLE(of, bcm2835_aux_clk_of_match);
61
62 static struct platform_driver bcm2835_aux_clk_driver = {
63         .driver = {
64                 .name = "bcm2835-aux-clk",
65                 .of_match_table = bcm2835_aux_clk_of_match,
66         },
67         .probe          = bcm2835_aux_clk_probe,
68 };
69 builtin_platform_driver(bcm2835_aux_clk_driver);
70
71 MODULE_AUTHOR("Eric Anholt <eric@anholt.net>");
72 MODULE_DESCRIPTION("BCM2835 auxiliary peripheral clock driver");
73 MODULE_LICENSE("GPL");