devices.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /*
  2. * linux/arch/arm/mach-omap2/devices.c
  3. *
  4. * OMAP2 platform device setup/initialization
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. */
  11. #include <linux/gpio.h>
  12. #include <linux/kernel.h>
  13. #include <linux/init.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/io.h>
  16. #include <linux/clk.h>
  17. #include <linux/err.h>
  18. #include <linux/slab.h>
  19. #include <linux/of.h>
  20. #include <linux/pinctrl/machine.h>
  21. #include <asm/mach-types.h>
  22. #include <asm/mach/map.h>
  23. #include <linux/omap-dma.h>
  24. #include "iomap.h"
  25. #include "omap_hwmod.h"
  26. #include "omap_device.h"
  27. #include "soc.h"
  28. #include "common.h"
  29. #include "mux.h"
  30. #include "control.h"
  31. #include "display.h"
  32. #define L3_MODULES_MAX_LEN 12
  33. #define L3_MODULES 3
  34. static int __init omap3_l3_init(void)
  35. {
  36. struct omap_hwmod *oh;
  37. struct platform_device *pdev;
  38. char oh_name[L3_MODULES_MAX_LEN];
  39. /*
  40. * To avoid code running on other OMAPs in
  41. * multi-omap builds
  42. */
  43. if (!(cpu_is_omap34xx()) || of_have_populated_dt())
  44. return -ENODEV;
  45. snprintf(oh_name, L3_MODULES_MAX_LEN, "l3_main");
  46. oh = omap_hwmod_lookup(oh_name);
  47. if (!oh)
  48. pr_err("could not look up %s\n", oh_name);
  49. pdev = omap_device_build("omap_l3_smx", 0, oh, NULL, 0);
  50. WARN(IS_ERR(pdev), "could not build omap_device for %s\n", oh_name);
  51. return PTR_ERR_OR_ZERO(pdev);
  52. }
  53. omap_postcore_initcall(omap3_l3_init);
  54. static inline void omap_init_sti(void) {}
  55. #if IS_ENABLED(CONFIG_SPI_OMAP24XX)
  56. #include <linux/platform_data/spi-omap2-mcspi.h>
  57. static int __init omap_mcspi_init(struct omap_hwmod *oh, void *unused)
  58. {
  59. struct platform_device *pdev;
  60. char *name = "omap2_mcspi";
  61. struct omap2_mcspi_platform_config *pdata;
  62. static int spi_num;
  63. struct omap2_mcspi_dev_attr *mcspi_attrib = oh->dev_attr;
  64. pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
  65. if (!pdata) {
  66. pr_err("Memory allocation for McSPI device failed\n");
  67. return -ENOMEM;
  68. }
  69. pdata->num_cs = mcspi_attrib->num_chipselect;
  70. switch (oh->class->rev) {
  71. case OMAP2_MCSPI_REV:
  72. case OMAP3_MCSPI_REV:
  73. pdata->regs_offset = 0;
  74. break;
  75. case OMAP4_MCSPI_REV:
  76. pdata->regs_offset = OMAP4_MCSPI_REG_OFFSET;
  77. break;
  78. default:
  79. pr_err("Invalid McSPI Revision value\n");
  80. kfree(pdata);
  81. return -EINVAL;
  82. }
  83. spi_num++;
  84. pdev = omap_device_build(name, spi_num, oh, pdata, sizeof(*pdata));
  85. WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s\n",
  86. name, oh->name);
  87. kfree(pdata);
  88. return 0;
  89. }
  90. static void omap_init_mcspi(void)
  91. {
  92. omap_hwmod_for_each_by_class("mcspi", omap_mcspi_init, NULL);
  93. }
  94. #else
  95. static inline void omap_init_mcspi(void) {}
  96. #endif
  97. /**
  98. * omap_init_rng - bind the RNG hwmod to the RNG omap_device
  99. *
  100. * Bind the RNG hwmod to the RNG omap_device. No return value.
  101. */
  102. static void omap_init_rng(void)
  103. {
  104. struct omap_hwmod *oh;
  105. struct platform_device *pdev;
  106. oh = omap_hwmod_lookup("rng");
  107. if (!oh)
  108. return;
  109. pdev = omap_device_build("omap_rng", -1, oh, NULL, 0);
  110. WARN(IS_ERR(pdev), "Can't build omap_device for omap_rng\n");
  111. }
  112. static void __init omap_init_sham(void)
  113. {
  114. struct omap_hwmod *oh;
  115. struct platform_device *pdev;
  116. oh = omap_hwmod_lookup("sham");
  117. if (!oh)
  118. return;
  119. pdev = omap_device_build("omap-sham", -1, oh, NULL, 0);
  120. WARN(IS_ERR(pdev), "Can't build omap_device for omap-sham\n");
  121. }
  122. static void __init omap_init_aes(void)
  123. {
  124. struct omap_hwmod *oh;
  125. struct platform_device *pdev;
  126. oh = omap_hwmod_lookup("aes");
  127. if (!oh)
  128. return;
  129. pdev = omap_device_build("omap-aes", -1, oh, NULL, 0);
  130. WARN(IS_ERR(pdev), "Can't build omap_device for omap-aes\n");
  131. }
  132. /*-------------------------------------------------------------------------*/
  133. #if IS_ENABLED(CONFIG_VIDEO_OMAP2_VOUT)
  134. #if IS_ENABLED(CONFIG_FB_OMAP2)
  135. static struct resource omap_vout_resource[3 - CONFIG_FB_OMAP2_NUM_FBS] = {
  136. };
  137. #else
  138. static struct resource omap_vout_resource[2] = {
  139. };
  140. #endif
  141. static struct platform_device omap_vout_device = {
  142. .name = "omap_vout",
  143. .num_resources = ARRAY_SIZE(omap_vout_resource),
  144. .resource = &omap_vout_resource[0],
  145. .id = -1,
  146. };
  147. int __init omap_init_vout(void)
  148. {
  149. return platform_device_register(&omap_vout_device);
  150. }
  151. #else
  152. int __init omap_init_vout(void) { return 0; }
  153. #endif
  154. /*-------------------------------------------------------------------------*/
  155. static int __init omap2_init_devices(void)
  156. {
  157. /* Enable dummy states for those platforms without pinctrl support */
  158. if (!of_have_populated_dt())
  159. pinctrl_provide_dummies();
  160. /* If dtb is there, the devices will be created dynamically */
  161. if (!of_have_populated_dt()) {
  162. /*
  163. * please keep these calls, and their implementations above,
  164. * in alphabetical order so they're easier to sort through.
  165. */
  166. omap_init_mcspi();
  167. omap_init_sham();
  168. omap_init_aes();
  169. omap_init_rng();
  170. }
  171. omap_init_sti();
  172. return 0;
  173. }
  174. omap_arch_initcall(omap2_init_devices);
  175. static int __init omap_gpmc_init(void)
  176. {
  177. struct omap_hwmod *oh;
  178. struct platform_device *pdev;
  179. char *oh_name = "gpmc";
  180. /*
  181. * if the board boots up with a populated DT, do not
  182. * manually add the device from this initcall
  183. */
  184. if (of_have_populated_dt())
  185. return -ENODEV;
  186. oh = omap_hwmod_lookup(oh_name);
  187. if (!oh) {
  188. pr_err("Could not look up %s\n", oh_name);
  189. return -ENODEV;
  190. }
  191. pdev = omap_device_build("omap-gpmc", -1, oh, NULL, 0);
  192. WARN(IS_ERR(pdev), "could not build omap_device for %s\n", oh_name);
  193. return PTR_ERR_OR_ZERO(pdev);
  194. }
  195. omap_postcore_initcall(omap_gpmc_init);