clk-bcm2835-aux.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2015 Broadcom
  4. */
  5. #include <linux/clk.h>
  6. #include <linux/clk-provider.h>
  7. #include <linux/io.h>
  8. #include <linux/module.h>
  9. #include <linux/platform_device.h>
  10. #include <dt-bindings/clock/bcm2835-aux.h>
  11. #define BCM2835_AUXIRQ 0x00
  12. #define BCM2835_AUXENB 0x04
  13. static int bcm2835_aux_clk_probe(struct platform_device *pdev)
  14. {
  15. struct device *dev = &pdev->dev;
  16. struct clk_hw_onecell_data *onecell;
  17. const char *parent;
  18. struct clk *parent_clk;
  19. void __iomem *reg, *gate;
  20. parent_clk = devm_clk_get(dev, NULL);
  21. if (IS_ERR(parent_clk))
  22. return PTR_ERR(parent_clk);
  23. parent = __clk_get_name(parent_clk);
  24. reg = devm_platform_ioremap_resource(pdev, 0);
  25. if (IS_ERR(reg))
  26. return PTR_ERR(reg);
  27. onecell = devm_kmalloc(dev,
  28. struct_size(onecell, hws,
  29. BCM2835_AUX_CLOCK_COUNT),
  30. GFP_KERNEL);
  31. if (!onecell)
  32. return -ENOMEM;
  33. onecell->num = BCM2835_AUX_CLOCK_COUNT;
  34. gate = reg + BCM2835_AUXENB;
  35. onecell->hws[BCM2835_AUX_CLOCK_UART] =
  36. clk_hw_register_gate(dev, "aux_uart", parent, 0, gate, 0, 0, NULL);
  37. onecell->hws[BCM2835_AUX_CLOCK_SPI1] =
  38. clk_hw_register_gate(dev, "aux_spi1", parent, 0, gate, 1, 0, NULL);
  39. onecell->hws[BCM2835_AUX_CLOCK_SPI2] =
  40. clk_hw_register_gate(dev, "aux_spi2", parent, 0, gate, 2, 0, NULL);
  41. return of_clk_add_hw_provider(pdev->dev.of_node, of_clk_hw_onecell_get,
  42. onecell);
  43. }
  44. static const struct of_device_id bcm2835_aux_clk_of_match[] = {
  45. { .compatible = "brcm,bcm2835-aux", },
  46. {},
  47. };
  48. MODULE_DEVICE_TABLE(of, bcm2835_aux_clk_of_match);
  49. static struct platform_driver bcm2835_aux_clk_driver = {
  50. .driver = {
  51. .name = "bcm2835-aux-clk",
  52. .of_match_table = bcm2835_aux_clk_of_match,
  53. },
  54. .probe = bcm2835_aux_clk_probe,
  55. };
  56. builtin_platform_driver(bcm2835_aux_clk_driver);
  57. MODULE_AUTHOR("Eric Anholt <[email protected]>");
  58. MODULE_DESCRIPTION("BCM2835 auxiliary peripheral clock driver");
  59. MODULE_LICENSE("GPL");