mpc832x_rdb.c 5.7 KB

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