mpc832x_rdb.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * arch/powerpc/platforms/83xx/mpc832x_rdb.c
  4. *
  5. * Copyright (C) Freescale Semiconductor, Inc. 2007. All rights reserved.
  6. *
  7. * Description:
  8. * MPC832x RDB board specific routines.
  9. * This file is based on mpc832x_mds.c and mpc8313_rdb.c
  10. * Author: Michael Barkowski <michael.barkowski@freescale.com>
  11. */
  12. #include <linux/pci.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/spi/spi.h>
  15. #include <linux/spi/mmc_spi.h>
  16. #include <linux/mmc/host.h>
  17. #include <linux/of.h>
  18. #include <linux/of_address.h>
  19. #include <linux/of_irq.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/fsl_devices.h>
  22. #include <asm/time.h>
  23. #include <asm/ipic.h>
  24. #include <asm/udbg.h>
  25. #include <soc/fsl/qe/qe.h>
  26. #include <sysdev/fsl_soc.h>
  27. #include <sysdev/fsl_pci.h>
  28. #include "mpc83xx.h"
  29. #undef DEBUG
  30. #ifdef DEBUG
  31. #define DBG(fmt...) udbg_printf(fmt)
  32. #else
  33. #define DBG(fmt...)
  34. #endif
  35. #ifdef CONFIG_QUICC_ENGINE
  36. static int __init of_fsl_spi_probe(char *type, char *compatible, u32 sysclk,
  37. struct spi_board_info *board_infos,
  38. unsigned int num_board_infos,
  39. void (*cs_control)(struct spi_device *dev,
  40. bool on))
  41. {
  42. struct device_node *np;
  43. unsigned int i = 0;
  44. for_each_compatible_node(np, type, compatible) {
  45. int ret;
  46. unsigned int j;
  47. const void *prop;
  48. struct resource res[2];
  49. struct platform_device *pdev;
  50. struct fsl_spi_platform_data pdata = {
  51. .cs_control = cs_control,
  52. };
  53. memset(res, 0, sizeof(res));
  54. pdata.sysclk = sysclk;
  55. prop = of_get_property(np, "reg", NULL);
  56. if (!prop)
  57. goto err;
  58. pdata.bus_num = *(u32 *)prop;
  59. prop = of_get_property(np, "cell-index", NULL);
  60. if (prop)
  61. i = *(u32 *)prop;
  62. prop = of_get_property(np, "mode", NULL);
  63. if (prop && !strcmp(prop, "cpu-qe"))
  64. pdata.flags = SPI_QE_CPU_MODE;
  65. for (j = 0; j < num_board_infos; j++) {
  66. if (board_infos[j].bus_num == pdata.bus_num)
  67. pdata.max_chipselect++;
  68. }
  69. if (!pdata.max_chipselect)
  70. continue;
  71. ret = of_address_to_resource(np, 0, &res[0]);
  72. if (ret)
  73. goto err;
  74. ret = of_irq_to_resource(np, 0, &res[1]);
  75. if (ret <= 0)
  76. goto err;
  77. pdev = platform_device_alloc("mpc83xx_spi", i);
  78. if (!pdev)
  79. goto err;
  80. ret = platform_device_add_data(pdev, &pdata, sizeof(pdata));
  81. if (ret)
  82. goto unreg;
  83. ret = platform_device_add_resources(pdev, res,
  84. ARRAY_SIZE(res));
  85. if (ret)
  86. goto unreg;
  87. ret = platform_device_add(pdev);
  88. if (ret)
  89. goto unreg;
  90. goto next;
  91. unreg:
  92. platform_device_put(pdev);
  93. err:
  94. pr_err("%pOF: registration failed\n", np);
  95. next:
  96. i++;
  97. }
  98. return i;
  99. }
  100. static int __init fsl_spi_init(struct spi_board_info *board_infos,
  101. unsigned int num_board_infos,
  102. void (*cs_control)(struct spi_device *spi,
  103. bool on))
  104. {
  105. u32 sysclk = -1;
  106. int ret;
  107. /* SPI controller is either clocked from QE or SoC clock */
  108. sysclk = get_brgfreq();
  109. if (sysclk == -1) {
  110. sysclk = fsl_get_sys_freq();
  111. if (sysclk == -1)
  112. return -ENODEV;
  113. }
  114. ret = of_fsl_spi_probe(NULL, "fsl,spi", sysclk, board_infos,
  115. num_board_infos, cs_control);
  116. if (!ret)
  117. of_fsl_spi_probe("spi", "fsl_spi", sysclk, board_infos,
  118. num_board_infos, cs_control);
  119. return spi_register_board_info(board_infos, num_board_infos);
  120. }
  121. static void mpc83xx_spi_cs_control(struct spi_device *spi, bool on)
  122. {
  123. pr_debug("%s %d %d\n", __func__, spi_get_chipselect(spi, 0), on);
  124. par_io_data_set(3, 13, on);
  125. }
  126. static struct mmc_spi_platform_data mpc832x_mmc_pdata = {
  127. .ocr_mask = MMC_VDD_33_34,
  128. };
  129. static struct spi_board_info mpc832x_spi_boardinfo = {
  130. .bus_num = 0x4c0,
  131. .chip_select = 0,
  132. .max_speed_hz = 50000000,
  133. .modalias = "mmc_spi",
  134. .platform_data = &mpc832x_mmc_pdata,
  135. };
  136. static int __init mpc832x_spi_init(void)
  137. {
  138. struct device_node *np;
  139. par_io_config_pin(3, 0, 3, 0, 1, 0); /* SPI1 MOSI, I/O */
  140. par_io_config_pin(3, 1, 3, 0, 1, 0); /* SPI1 MISO, I/O */
  141. par_io_config_pin(3, 2, 3, 0, 1, 0); /* SPI1 CLK, I/O */
  142. par_io_config_pin(3, 3, 2, 0, 1, 0); /* SPI1 SEL, I */
  143. par_io_config_pin(3, 13, 1, 0, 0, 0); /* !SD_CS, O */
  144. par_io_config_pin(3, 14, 2, 0, 0, 0); /* SD_INSERT, I */
  145. par_io_config_pin(3, 15, 2, 0, 0, 0); /* SD_PROTECT,I */
  146. /*
  147. * Don't bother with legacy stuff when device tree contains
  148. * mmc-spi-slot node.
  149. */
  150. np = of_find_compatible_node(NULL, NULL, "mmc-spi-slot");
  151. of_node_put(np);
  152. if (np)
  153. return 0;
  154. return fsl_spi_init(&mpc832x_spi_boardinfo, 1, mpc83xx_spi_cs_control);
  155. }
  156. machine_device_initcall(mpc832x_rdb, mpc832x_spi_init);
  157. #endif /* CONFIG_QUICC_ENGINE */
  158. /* ************************************************************************
  159. *
  160. * Setup the architecture
  161. *
  162. */
  163. static void __init mpc832x_rdb_setup_arch(void)
  164. {
  165. #if defined(CONFIG_QUICC_ENGINE)
  166. struct device_node *np;
  167. #endif
  168. mpc83xx_setup_arch();
  169. #ifdef CONFIG_QUICC_ENGINE
  170. if ((np = of_find_node_by_name(NULL, "par_io")) != NULL) {
  171. par_io_init(np);
  172. of_node_put(np);
  173. for_each_node_by_name(np, "ucc")
  174. par_io_of_config(np);
  175. }
  176. #endif /* CONFIG_QUICC_ENGINE */
  177. }
  178. machine_device_initcall(mpc832x_rdb, mpc83xx_declare_of_platform_devices);
  179. define_machine(mpc832x_rdb) {
  180. .name = "MPC832x RDB",
  181. .compatible = "MPC832xRDB",
  182. .setup_arch = mpc832x_rdb_setup_arch,
  183. .discover_phbs = mpc83xx_setup_pci,
  184. .init_IRQ = mpc83xx_ipic_init_IRQ,
  185. .get_irq = ipic_get_irq,
  186. .restart = mpc83xx_restart,
  187. .time_init = mpc83xx_time_init,
  188. .progress = udbg_progress,
  189. };