central.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /* central.c: Central FHC driver for Sunfire/Starfire/Wildfire.
  2. *
  3. * Copyright (C) 1997, 1999, 2008 David S. Miller (davem@davemloft.net)
  4. */
  5. #include <linux/kernel.h>
  6. #include <linux/types.h>
  7. #include <linux/slab.h>
  8. #include <linux/export.h>
  9. #include <linux/string.h>
  10. #include <linux/init.h>
  11. #include <linux/of_device.h>
  12. #include <linux/platform_device.h>
  13. #include <asm/fhc.h>
  14. #include <asm/upa.h>
  15. struct clock_board {
  16. void __iomem *clock_freq_regs;
  17. void __iomem *clock_regs;
  18. void __iomem *clock_ver_reg;
  19. int num_slots;
  20. struct resource leds_resource;
  21. struct platform_device leds_pdev;
  22. };
  23. struct fhc {
  24. void __iomem *pregs;
  25. bool central;
  26. bool jtag_master;
  27. int board_num;
  28. struct resource leds_resource;
  29. struct platform_device leds_pdev;
  30. };
  31. static int clock_board_calc_nslots(struct clock_board *p)
  32. {
  33. u8 reg = upa_readb(p->clock_regs + CLOCK_STAT1) & 0xc0;
  34. switch (reg) {
  35. case 0x40:
  36. return 16;
  37. case 0xc0:
  38. return 8;
  39. case 0x80:
  40. reg = 0;
  41. if (p->clock_ver_reg)
  42. reg = upa_readb(p->clock_ver_reg);
  43. if (reg) {
  44. if (reg & 0x80)
  45. return 4;
  46. else
  47. return 5;
  48. }
  49. /* Fallthrough */
  50. default:
  51. return 4;
  52. }
  53. }
  54. static int clock_board_probe(struct platform_device *op)
  55. {
  56. struct clock_board *p = kzalloc(sizeof(*p), GFP_KERNEL);
  57. int err = -ENOMEM;
  58. if (!p) {
  59. printk(KERN_ERR "clock_board: Cannot allocate struct clock_board\n");
  60. goto out;
  61. }
  62. p->clock_freq_regs = of_ioremap(&op->resource[0], 0,
  63. resource_size(&op->resource[0]),
  64. "clock_board_freq");
  65. if (!p->clock_freq_regs) {
  66. printk(KERN_ERR "clock_board: Cannot map clock_freq_regs\n");
  67. goto out_free;
  68. }
  69. p->clock_regs = of_ioremap(&op->resource[1], 0,
  70. resource_size(&op->resource[1]),
  71. "clock_board_regs");
  72. if (!p->clock_regs) {
  73. printk(KERN_ERR "clock_board: Cannot map clock_regs\n");
  74. goto out_unmap_clock_freq_regs;
  75. }
  76. if (op->resource[2].flags) {
  77. p->clock_ver_reg = of_ioremap(&op->resource[2], 0,
  78. resource_size(&op->resource[2]),
  79. "clock_ver_reg");
  80. if (!p->clock_ver_reg) {
  81. printk(KERN_ERR "clock_board: Cannot map clock_ver_reg\n");
  82. goto out_unmap_clock_regs;
  83. }
  84. }
  85. p->num_slots = clock_board_calc_nslots(p);
  86. p->leds_resource.start = (unsigned long)
  87. (p->clock_regs + CLOCK_CTRL);
  88. p->leds_resource.end = p->leds_resource.start;
  89. p->leds_resource.name = "leds";
  90. p->leds_pdev.name = "sunfire-clockboard-leds";
  91. p->leds_pdev.id = -1;
  92. p->leds_pdev.resource = &p->leds_resource;
  93. p->leds_pdev.num_resources = 1;
  94. p->leds_pdev.dev.parent = &op->dev;
  95. err = platform_device_register(&p->leds_pdev);
  96. if (err) {
  97. printk(KERN_ERR "clock_board: Could not register LEDS "
  98. "platform device\n");
  99. goto out_unmap_clock_ver_reg;
  100. }
  101. printk(KERN_INFO "clock_board: Detected %d slot Enterprise system.\n",
  102. p->num_slots);
  103. err = 0;
  104. out:
  105. return err;
  106. out_unmap_clock_ver_reg:
  107. if (p->clock_ver_reg)
  108. of_iounmap(&op->resource[2], p->clock_ver_reg,
  109. resource_size(&op->resource[2]));
  110. out_unmap_clock_regs:
  111. of_iounmap(&op->resource[1], p->clock_regs,
  112. resource_size(&op->resource[1]));
  113. out_unmap_clock_freq_regs:
  114. of_iounmap(&op->resource[0], p->clock_freq_regs,
  115. resource_size(&op->resource[0]));
  116. out_free:
  117. kfree(p);
  118. goto out;
  119. }
  120. static const struct of_device_id clock_board_match[] = {
  121. {
  122. .name = "clock-board",
  123. },
  124. {},
  125. };
  126. static struct platform_driver clock_board_driver = {
  127. .probe = clock_board_probe,
  128. .driver = {
  129. .name = "clock_board",
  130. .of_match_table = clock_board_match,
  131. },
  132. };
  133. static int fhc_probe(struct platform_device *op)
  134. {
  135. struct fhc *p = kzalloc(sizeof(*p), GFP_KERNEL);
  136. int err = -ENOMEM;
  137. u32 reg;
  138. if (!p) {
  139. printk(KERN_ERR "fhc: Cannot allocate struct fhc\n");
  140. goto out;
  141. }
  142. if (!strcmp(op->dev.of_node->parent->name, "central"))
  143. p->central = true;
  144. p->pregs = of_ioremap(&op->resource[0], 0,
  145. resource_size(&op->resource[0]),
  146. "fhc_pregs");
  147. if (!p->pregs) {
  148. printk(KERN_ERR "fhc: Cannot map pregs\n");
  149. goto out_free;
  150. }
  151. if (p->central) {
  152. reg = upa_readl(p->pregs + FHC_PREGS_BSR);
  153. p->board_num = ((reg >> 16) & 1) | ((reg >> 12) & 0x0e);
  154. } else {
  155. p->board_num = of_getintprop_default(op->dev.of_node, "board#", -1);
  156. if (p->board_num == -1) {
  157. printk(KERN_ERR "fhc: No board# property\n");
  158. goto out_unmap_pregs;
  159. }
  160. if (upa_readl(p->pregs + FHC_PREGS_JCTRL) & FHC_JTAG_CTRL_MENAB)
  161. p->jtag_master = true;
  162. }
  163. if (!p->central) {
  164. p->leds_resource.start = (unsigned long)
  165. (p->pregs + FHC_PREGS_CTRL);
  166. p->leds_resource.end = p->leds_resource.start;
  167. p->leds_resource.name = "leds";
  168. p->leds_pdev.name = "sunfire-fhc-leds";
  169. p->leds_pdev.id = p->board_num;
  170. p->leds_pdev.resource = &p->leds_resource;
  171. p->leds_pdev.num_resources = 1;
  172. p->leds_pdev.dev.parent = &op->dev;
  173. err = platform_device_register(&p->leds_pdev);
  174. if (err) {
  175. printk(KERN_ERR "fhc: Could not register LEDS "
  176. "platform device\n");
  177. goto out_unmap_pregs;
  178. }
  179. }
  180. reg = upa_readl(p->pregs + FHC_PREGS_CTRL);
  181. if (!p->central)
  182. reg |= FHC_CONTROL_IXIST;
  183. reg &= ~(FHC_CONTROL_AOFF |
  184. FHC_CONTROL_BOFF |
  185. FHC_CONTROL_SLINE);
  186. upa_writel(reg, p->pregs + FHC_PREGS_CTRL);
  187. upa_readl(p->pregs + FHC_PREGS_CTRL);
  188. reg = upa_readl(p->pregs + FHC_PREGS_ID);
  189. printk(KERN_INFO "fhc: Board #%d, Version[%x] PartID[%x] Manuf[%x] %s\n",
  190. p->board_num,
  191. (reg & FHC_ID_VERS) >> 28,
  192. (reg & FHC_ID_PARTID) >> 12,
  193. (reg & FHC_ID_MANUF) >> 1,
  194. (p->jtag_master ?
  195. "(JTAG Master)" :
  196. (p->central ? "(Central)" : "")));
  197. err = 0;
  198. out:
  199. return err;
  200. out_unmap_pregs:
  201. of_iounmap(&op->resource[0], p->pregs, resource_size(&op->resource[0]));
  202. out_free:
  203. kfree(p);
  204. goto out;
  205. }
  206. static const struct of_device_id fhc_match[] = {
  207. {
  208. .name = "fhc",
  209. },
  210. {},
  211. };
  212. static struct platform_driver fhc_driver = {
  213. .probe = fhc_probe,
  214. .driver = {
  215. .name = "fhc",
  216. .of_match_table = fhc_match,
  217. },
  218. };
  219. static int __init sunfire_init(void)
  220. {
  221. (void) platform_driver_register(&fhc_driver);
  222. (void) platform_driver_register(&clock_board_driver);
  223. return 0;
  224. }
  225. fs_initcall(sunfire_init);