clk-bcm2835-aux.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright (C) 2015 Broadcom
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. */
  14. #include <linux/clk.h>
  15. #include <linux/clk-provider.h>
  16. #include <linux/module.h>
  17. #include <linux/platform_device.h>
  18. #include <dt-bindings/clock/bcm2835-aux.h>
  19. #define BCM2835_AUXIRQ 0x00
  20. #define BCM2835_AUXENB 0x04
  21. static int bcm2835_aux_clk_probe(struct platform_device *pdev)
  22. {
  23. struct device *dev = &pdev->dev;
  24. struct clk_hw_onecell_data *onecell;
  25. const char *parent;
  26. struct clk *parent_clk;
  27. struct resource *res;
  28. void __iomem *reg, *gate;
  29. parent_clk = devm_clk_get(dev, NULL);
  30. if (IS_ERR(parent_clk))
  31. return PTR_ERR(parent_clk);
  32. parent = __clk_get_name(parent_clk);
  33. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  34. reg = devm_ioremap_resource(dev, res);
  35. if (IS_ERR(reg))
  36. return PTR_ERR(reg);
  37. onecell = devm_kmalloc(dev,
  38. struct_size(onecell, hws,
  39. BCM2835_AUX_CLOCK_COUNT),
  40. GFP_KERNEL);
  41. if (!onecell)
  42. return -ENOMEM;
  43. onecell->num = BCM2835_AUX_CLOCK_COUNT;
  44. gate = reg + BCM2835_AUXENB;
  45. onecell->hws[BCM2835_AUX_CLOCK_UART] =
  46. clk_hw_register_gate(dev, "aux_uart", parent, 0, gate, 0, 0, NULL);
  47. onecell->hws[BCM2835_AUX_CLOCK_SPI1] =
  48. clk_hw_register_gate(dev, "aux_spi1", parent, 0, gate, 1, 0, NULL);
  49. onecell->hws[BCM2835_AUX_CLOCK_SPI2] =
  50. clk_hw_register_gate(dev, "aux_spi2", parent, 0, gate, 2, 0, NULL);
  51. return of_clk_add_hw_provider(pdev->dev.of_node, of_clk_hw_onecell_get,
  52. onecell);
  53. }
  54. static const struct of_device_id bcm2835_aux_clk_of_match[] = {
  55. { .compatible = "brcm,bcm2835-aux", },
  56. {},
  57. };
  58. MODULE_DEVICE_TABLE(of, bcm2835_aux_clk_of_match);
  59. static struct platform_driver bcm2835_aux_clk_driver = {
  60. .driver = {
  61. .name = "bcm2835-aux-clk",
  62. .of_match_table = bcm2835_aux_clk_of_match,
  63. },
  64. .probe = bcm2835_aux_clk_probe,
  65. };
  66. builtin_platform_driver(bcm2835_aux_clk_driver);
  67. MODULE_AUTHOR("Eric Anholt <eric@anholt.net>");
  68. MODULE_DESCRIPTION("BCM2835 auxiliary peripheral clock driver");
  69. MODULE_LICENSE("GPL v2");