Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0+
0002 /*
0003  * Copyright (C) 2015 Broadcom
0004  */
0005 
0006 #include <linux/clk.h>
0007 #include <linux/clk-provider.h>
0008 #include <linux/io.h>
0009 #include <linux/module.h>
0010 #include <linux/platform_device.h>
0011 #include <dt-bindings/clock/bcm2835-aux.h>
0012 
0013 #define BCM2835_AUXIRQ      0x00
0014 #define BCM2835_AUXENB      0x04
0015 
0016 static int bcm2835_aux_clk_probe(struct platform_device *pdev)
0017 {
0018     struct device *dev = &pdev->dev;
0019     struct clk_hw_onecell_data *onecell;
0020     const char *parent;
0021     struct clk *parent_clk;
0022     void __iomem *reg, *gate;
0023 
0024     parent_clk = devm_clk_get(dev, NULL);
0025     if (IS_ERR(parent_clk))
0026         return PTR_ERR(parent_clk);
0027     parent = __clk_get_name(parent_clk);
0028 
0029     reg = devm_platform_ioremap_resource(pdev, 0);
0030     if (IS_ERR(reg))
0031         return PTR_ERR(reg);
0032 
0033     onecell = devm_kmalloc(dev,
0034                    struct_size(onecell, hws,
0035                        BCM2835_AUX_CLOCK_COUNT),
0036                    GFP_KERNEL);
0037     if (!onecell)
0038         return -ENOMEM;
0039     onecell->num = BCM2835_AUX_CLOCK_COUNT;
0040 
0041     gate = reg + BCM2835_AUXENB;
0042     onecell->hws[BCM2835_AUX_CLOCK_UART] =
0043         clk_hw_register_gate(dev, "aux_uart", parent, 0, gate, 0, 0, NULL);
0044 
0045     onecell->hws[BCM2835_AUX_CLOCK_SPI1] =
0046         clk_hw_register_gate(dev, "aux_spi1", parent, 0, gate, 1, 0, NULL);
0047 
0048     onecell->hws[BCM2835_AUX_CLOCK_SPI2] =
0049         clk_hw_register_gate(dev, "aux_spi2", parent, 0, gate, 2, 0, NULL);
0050 
0051     return of_clk_add_hw_provider(pdev->dev.of_node, of_clk_hw_onecell_get,
0052                       onecell);
0053 }
0054 
0055 static const struct of_device_id bcm2835_aux_clk_of_match[] = {
0056     { .compatible = "brcm,bcm2835-aux", },
0057     {},
0058 };
0059 MODULE_DEVICE_TABLE(of, bcm2835_aux_clk_of_match);
0060 
0061 static struct platform_driver bcm2835_aux_clk_driver = {
0062     .driver = {
0063         .name = "bcm2835-aux-clk",
0064         .of_match_table = bcm2835_aux_clk_of_match,
0065     },
0066     .probe          = bcm2835_aux_clk_probe,
0067 };
0068 builtin_platform_driver(bcm2835_aux_clk_driver);
0069 
0070 MODULE_AUTHOR("Eric Anholt <eric@anholt.net>");
0071 MODULE_DESCRIPTION("BCM2835 auxiliary peripheral clock driver");
0072 MODULE_LICENSE("GPL");