octeon-platform.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2004-2011 Cavium Networks
  7. * Copyright (C) 2008 Wind River Systems
  8. */
  9. #include <linux/init.h>
  10. #include <linux/irq.h>
  11. #include <linux/i2c.h>
  12. #include <linux/usb.h>
  13. #include <linux/dma-mapping.h>
  14. #include <linux/module.h>
  15. #include <linux/slab.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/of_platform.h>
  18. #include <linux/of_fdt.h>
  19. #include <linux/libfdt.h>
  20. #include <asm/octeon/octeon.h>
  21. #include <asm/octeon/cvmx-rnm-defs.h>
  22. #include <asm/octeon/cvmx-helper.h>
  23. #include <asm/octeon/cvmx-helper-board.h>
  24. /* Octeon Random Number Generator. */
  25. static int __init octeon_rng_device_init(void)
  26. {
  27. struct platform_device *pd;
  28. int ret = 0;
  29. struct resource rng_resources[] = {
  30. {
  31. .flags = IORESOURCE_MEM,
  32. .start = XKPHYS_TO_PHYS(CVMX_RNM_CTL_STATUS),
  33. .end = XKPHYS_TO_PHYS(CVMX_RNM_CTL_STATUS) + 0xf
  34. }, {
  35. .flags = IORESOURCE_MEM,
  36. .start = cvmx_build_io_address(8, 0),
  37. .end = cvmx_build_io_address(8, 0) + 0x7
  38. }
  39. };
  40. pd = platform_device_alloc("octeon_rng", -1);
  41. if (!pd) {
  42. ret = -ENOMEM;
  43. goto out;
  44. }
  45. ret = platform_device_add_resources(pd, rng_resources,
  46. ARRAY_SIZE(rng_resources));
  47. if (ret)
  48. goto fail;
  49. ret = platform_device_add(pd);
  50. if (ret)
  51. goto fail;
  52. return ret;
  53. fail:
  54. platform_device_put(pd);
  55. out:
  56. return ret;
  57. }
  58. device_initcall(octeon_rng_device_init);
  59. #ifdef CONFIG_USB
  60. static int __init octeon_ehci_device_init(void)
  61. {
  62. struct platform_device *pd;
  63. int ret = 0;
  64. struct resource usb_resources[] = {
  65. {
  66. .flags = IORESOURCE_MEM,
  67. }, {
  68. .flags = IORESOURCE_IRQ,
  69. }
  70. };
  71. /* Only Octeon2 has ehci/ohci */
  72. if (!OCTEON_IS_MODEL(OCTEON_CN63XX))
  73. return 0;
  74. if (octeon_is_simulation() || usb_disabled())
  75. return 0; /* No USB in the simulator. */
  76. pd = platform_device_alloc("octeon-ehci", 0);
  77. if (!pd) {
  78. ret = -ENOMEM;
  79. goto out;
  80. }
  81. usb_resources[0].start = 0x00016F0000000000ULL;
  82. usb_resources[0].end = usb_resources[0].start + 0x100;
  83. usb_resources[1].start = OCTEON_IRQ_USB0;
  84. usb_resources[1].end = OCTEON_IRQ_USB0;
  85. ret = platform_device_add_resources(pd, usb_resources,
  86. ARRAY_SIZE(usb_resources));
  87. if (ret)
  88. goto fail;
  89. ret = platform_device_add(pd);
  90. if (ret)
  91. goto fail;
  92. return ret;
  93. fail:
  94. platform_device_put(pd);
  95. out:
  96. return ret;
  97. }
  98. device_initcall(octeon_ehci_device_init);
  99. static int __init octeon_ohci_device_init(void)
  100. {
  101. struct platform_device *pd;
  102. int ret = 0;
  103. struct resource usb_resources[] = {
  104. {
  105. .flags = IORESOURCE_MEM,
  106. }, {
  107. .flags = IORESOURCE_IRQ,
  108. }
  109. };
  110. /* Only Octeon2 has ehci/ohci */
  111. if (!OCTEON_IS_MODEL(OCTEON_CN63XX))
  112. return 0;
  113. if (octeon_is_simulation() || usb_disabled())
  114. return 0; /* No USB in the simulator. */
  115. pd = platform_device_alloc("octeon-ohci", 0);
  116. if (!pd) {
  117. ret = -ENOMEM;
  118. goto out;
  119. }
  120. usb_resources[0].start = 0x00016F0000000400ULL;
  121. usb_resources[0].end = usb_resources[0].start + 0x100;
  122. usb_resources[1].start = OCTEON_IRQ_USB0;
  123. usb_resources[1].end = OCTEON_IRQ_USB0;
  124. ret = platform_device_add_resources(pd, usb_resources,
  125. ARRAY_SIZE(usb_resources));
  126. if (ret)
  127. goto fail;
  128. ret = platform_device_add(pd);
  129. if (ret)
  130. goto fail;
  131. return ret;
  132. fail:
  133. platform_device_put(pd);
  134. out:
  135. return ret;
  136. }
  137. device_initcall(octeon_ohci_device_init);
  138. #endif /* CONFIG_USB */
  139. static struct of_device_id __initdata octeon_ids[] = {
  140. { .compatible = "simple-bus", },
  141. { .compatible = "cavium,octeon-6335-uctl", },
  142. { .compatible = "cavium,octeon-3860-bootbus", },
  143. { .compatible = "cavium,mdio-mux", },
  144. { .compatible = "gpio-leds", },
  145. {},
  146. };
  147. static bool __init octeon_has_88e1145(void)
  148. {
  149. return !OCTEON_IS_MODEL(OCTEON_CN52XX) &&
  150. !OCTEON_IS_MODEL(OCTEON_CN6XXX) &&
  151. !OCTEON_IS_MODEL(OCTEON_CN56XX);
  152. }
  153. static void __init octeon_fdt_set_phy(int eth, int phy_addr)
  154. {
  155. const __be32 *phy_handle;
  156. const __be32 *alt_phy_handle;
  157. const __be32 *reg;
  158. u32 phandle;
  159. int phy;
  160. int alt_phy;
  161. const char *p;
  162. int current_len;
  163. char new_name[20];
  164. phy_handle = fdt_getprop(initial_boot_params, eth, "phy-handle", NULL);
  165. if (!phy_handle)
  166. return;
  167. phandle = be32_to_cpup(phy_handle);
  168. phy = fdt_node_offset_by_phandle(initial_boot_params, phandle);
  169. alt_phy_handle = fdt_getprop(initial_boot_params, eth, "cavium,alt-phy-handle", NULL);
  170. if (alt_phy_handle) {
  171. u32 alt_phandle = be32_to_cpup(alt_phy_handle);
  172. alt_phy = fdt_node_offset_by_phandle(initial_boot_params, alt_phandle);
  173. } else {
  174. alt_phy = -1;
  175. }
  176. if (phy_addr < 0 || phy < 0) {
  177. /* Delete the PHY things */
  178. fdt_nop_property(initial_boot_params, eth, "phy-handle");
  179. /* This one may fail */
  180. fdt_nop_property(initial_boot_params, eth, "cavium,alt-phy-handle");
  181. if (phy >= 0)
  182. fdt_nop_node(initial_boot_params, phy);
  183. if (alt_phy >= 0)
  184. fdt_nop_node(initial_boot_params, alt_phy);
  185. return;
  186. }
  187. if (phy_addr >= 256 && alt_phy > 0) {
  188. const struct fdt_property *phy_prop;
  189. struct fdt_property *alt_prop;
  190. u32 phy_handle_name;
  191. /* Use the alt phy node instead.*/
  192. phy_prop = fdt_get_property(initial_boot_params, eth, "phy-handle", NULL);
  193. phy_handle_name = phy_prop->nameoff;
  194. fdt_nop_node(initial_boot_params, phy);
  195. fdt_nop_property(initial_boot_params, eth, "phy-handle");
  196. alt_prop = fdt_get_property_w(initial_boot_params, eth, "cavium,alt-phy-handle", NULL);
  197. alt_prop->nameoff = phy_handle_name;
  198. phy = alt_phy;
  199. }
  200. phy_addr &= 0xff;
  201. if (octeon_has_88e1145()) {
  202. fdt_nop_property(initial_boot_params, phy, "marvell,reg-init");
  203. memset(new_name, 0, sizeof(new_name));
  204. strcpy(new_name, "marvell,88e1145");
  205. p = fdt_getprop(initial_boot_params, phy, "compatible",
  206. &current_len);
  207. if (p && current_len >= strlen(new_name))
  208. fdt_setprop_inplace(initial_boot_params, phy,
  209. "compatible", new_name, current_len);
  210. }
  211. reg = fdt_getprop(initial_boot_params, phy, "reg", NULL);
  212. if (phy_addr == be32_to_cpup(reg))
  213. return;
  214. fdt_setprop_inplace_cell(initial_boot_params, phy, "reg", phy_addr);
  215. snprintf(new_name, sizeof(new_name), "ethernet-phy@%x", phy_addr);
  216. p = fdt_get_name(initial_boot_params, phy, &current_len);
  217. if (p && current_len == strlen(new_name))
  218. fdt_set_name(initial_boot_params, phy, new_name);
  219. else
  220. pr_err("Error: could not rename ethernet phy: <%s>", p);
  221. }
  222. static void __init octeon_fdt_set_mac_addr(int n, u64 *pmac)
  223. {
  224. u8 new_mac[6];
  225. u64 mac = *pmac;
  226. int r;
  227. new_mac[0] = (mac >> 40) & 0xff;
  228. new_mac[1] = (mac >> 32) & 0xff;
  229. new_mac[2] = (mac >> 24) & 0xff;
  230. new_mac[3] = (mac >> 16) & 0xff;
  231. new_mac[4] = (mac >> 8) & 0xff;
  232. new_mac[5] = mac & 0xff;
  233. r = fdt_setprop_inplace(initial_boot_params, n, "local-mac-address",
  234. new_mac, sizeof(new_mac));
  235. if (r) {
  236. pr_err("Setting \"local-mac-address\" failed %d", r);
  237. return;
  238. }
  239. *pmac = mac + 1;
  240. }
  241. static void __init octeon_fdt_rm_ethernet(int node)
  242. {
  243. const __be32 *phy_handle;
  244. phy_handle = fdt_getprop(initial_boot_params, node, "phy-handle", NULL);
  245. if (phy_handle) {
  246. u32 ph = be32_to_cpup(phy_handle);
  247. int p = fdt_node_offset_by_phandle(initial_boot_params, ph);
  248. if (p >= 0)
  249. fdt_nop_node(initial_boot_params, p);
  250. }
  251. fdt_nop_node(initial_boot_params, node);
  252. }
  253. static void __init octeon_fdt_pip_port(int iface, int i, int p, int max, u64 *pmac)
  254. {
  255. char name_buffer[20];
  256. int eth;
  257. int phy_addr;
  258. int ipd_port;
  259. snprintf(name_buffer, sizeof(name_buffer), "ethernet@%x", p);
  260. eth = fdt_subnode_offset(initial_boot_params, iface, name_buffer);
  261. if (eth < 0)
  262. return;
  263. if (p > max) {
  264. pr_debug("Deleting port %x:%x\n", i, p);
  265. octeon_fdt_rm_ethernet(eth);
  266. return;
  267. }
  268. if (OCTEON_IS_MODEL(OCTEON_CN68XX))
  269. ipd_port = (0x100 * i) + (0x10 * p) + 0x800;
  270. else
  271. ipd_port = 16 * i + p;
  272. phy_addr = cvmx_helper_board_get_mii_address(ipd_port);
  273. octeon_fdt_set_phy(eth, phy_addr);
  274. octeon_fdt_set_mac_addr(eth, pmac);
  275. }
  276. static void __init octeon_fdt_pip_iface(int pip, int idx, u64 *pmac)
  277. {
  278. char name_buffer[20];
  279. int iface;
  280. int p;
  281. int count = 0;
  282. if (cvmx_helper_interface_enumerate(idx) == 0)
  283. count = cvmx_helper_ports_on_interface(idx);
  284. snprintf(name_buffer, sizeof(name_buffer), "interface@%d", idx);
  285. iface = fdt_subnode_offset(initial_boot_params, pip, name_buffer);
  286. if (iface < 0)
  287. return;
  288. for (p = 0; p < 16; p++)
  289. octeon_fdt_pip_port(iface, idx, p, count - 1, pmac);
  290. }
  291. int __init octeon_prune_device_tree(void)
  292. {
  293. int i, max_port, uart_mask;
  294. const char *pip_path;
  295. const char *alias_prop;
  296. char name_buffer[20];
  297. int aliases;
  298. u64 mac_addr_base;
  299. if (fdt_check_header(initial_boot_params))
  300. panic("Corrupt Device Tree.");
  301. aliases = fdt_path_offset(initial_boot_params, "/aliases");
  302. if (aliases < 0) {
  303. pr_err("Error: No /aliases node in device tree.");
  304. return -EINVAL;
  305. }
  306. mac_addr_base =
  307. ((octeon_bootinfo->mac_addr_base[0] & 0xffull)) << 40 |
  308. ((octeon_bootinfo->mac_addr_base[1] & 0xffull)) << 32 |
  309. ((octeon_bootinfo->mac_addr_base[2] & 0xffull)) << 24 |
  310. ((octeon_bootinfo->mac_addr_base[3] & 0xffull)) << 16 |
  311. ((octeon_bootinfo->mac_addr_base[4] & 0xffull)) << 8 |
  312. (octeon_bootinfo->mac_addr_base[5] & 0xffull);
  313. if (OCTEON_IS_MODEL(OCTEON_CN52XX) || OCTEON_IS_MODEL(OCTEON_CN63XX))
  314. max_port = 2;
  315. else if (OCTEON_IS_MODEL(OCTEON_CN56XX) || OCTEON_IS_MODEL(OCTEON_CN68XX))
  316. max_port = 1;
  317. else
  318. max_port = 0;
  319. if (octeon_bootinfo->board_type == CVMX_BOARD_TYPE_NIC10E)
  320. max_port = 0;
  321. for (i = 0; i < 2; i++) {
  322. int mgmt;
  323. snprintf(name_buffer, sizeof(name_buffer),
  324. "mix%d", i);
  325. alias_prop = fdt_getprop(initial_boot_params, aliases,
  326. name_buffer, NULL);
  327. if (alias_prop) {
  328. mgmt = fdt_path_offset(initial_boot_params, alias_prop);
  329. if (mgmt < 0)
  330. continue;
  331. if (i >= max_port) {
  332. pr_debug("Deleting mix%d\n", i);
  333. octeon_fdt_rm_ethernet(mgmt);
  334. fdt_nop_property(initial_boot_params, aliases,
  335. name_buffer);
  336. } else {
  337. int phy_addr = cvmx_helper_board_get_mii_address(CVMX_HELPER_BOARD_MGMT_IPD_PORT + i);
  338. octeon_fdt_set_phy(mgmt, phy_addr);
  339. octeon_fdt_set_mac_addr(mgmt, &mac_addr_base);
  340. }
  341. }
  342. }
  343. pip_path = fdt_getprop(initial_boot_params, aliases, "pip", NULL);
  344. if (pip_path) {
  345. int pip = fdt_path_offset(initial_boot_params, pip_path);
  346. if (pip >= 0)
  347. for (i = 0; i <= 4; i++)
  348. octeon_fdt_pip_iface(pip, i, &mac_addr_base);
  349. }
  350. /* I2C */
  351. if (OCTEON_IS_MODEL(OCTEON_CN52XX) ||
  352. OCTEON_IS_MODEL(OCTEON_CN63XX) ||
  353. OCTEON_IS_MODEL(OCTEON_CN68XX) ||
  354. OCTEON_IS_MODEL(OCTEON_CN56XX))
  355. max_port = 2;
  356. else
  357. max_port = 1;
  358. for (i = 0; i < 2; i++) {
  359. int i2c;
  360. snprintf(name_buffer, sizeof(name_buffer),
  361. "twsi%d", i);
  362. alias_prop = fdt_getprop(initial_boot_params, aliases,
  363. name_buffer, NULL);
  364. if (alias_prop) {
  365. i2c = fdt_path_offset(initial_boot_params, alias_prop);
  366. if (i2c < 0)
  367. continue;
  368. if (i >= max_port) {
  369. pr_debug("Deleting twsi%d\n", i);
  370. fdt_nop_node(initial_boot_params, i2c);
  371. fdt_nop_property(initial_boot_params, aliases,
  372. name_buffer);
  373. }
  374. }
  375. }
  376. /* SMI/MDIO */
  377. if (OCTEON_IS_MODEL(OCTEON_CN68XX))
  378. max_port = 4;
  379. else if (OCTEON_IS_MODEL(OCTEON_CN52XX) ||
  380. OCTEON_IS_MODEL(OCTEON_CN63XX) ||
  381. OCTEON_IS_MODEL(OCTEON_CN56XX))
  382. max_port = 2;
  383. else
  384. max_port = 1;
  385. for (i = 0; i < 2; i++) {
  386. int i2c;
  387. snprintf(name_buffer, sizeof(name_buffer),
  388. "smi%d", i);
  389. alias_prop = fdt_getprop(initial_boot_params, aliases,
  390. name_buffer, NULL);
  391. if (alias_prop) {
  392. i2c = fdt_path_offset(initial_boot_params, alias_prop);
  393. if (i2c < 0)
  394. continue;
  395. if (i >= max_port) {
  396. pr_debug("Deleting smi%d\n", i);
  397. fdt_nop_node(initial_boot_params, i2c);
  398. fdt_nop_property(initial_boot_params, aliases,
  399. name_buffer);
  400. }
  401. }
  402. }
  403. /* Serial */
  404. uart_mask = 3;
  405. /* Right now CN52XX is the only chip with a third uart */
  406. if (OCTEON_IS_MODEL(OCTEON_CN52XX))
  407. uart_mask |= 4; /* uart2 */
  408. for (i = 0; i < 3; i++) {
  409. int uart;
  410. snprintf(name_buffer, sizeof(name_buffer),
  411. "uart%d", i);
  412. alias_prop = fdt_getprop(initial_boot_params, aliases,
  413. name_buffer, NULL);
  414. if (alias_prop) {
  415. uart = fdt_path_offset(initial_boot_params, alias_prop);
  416. if (uart_mask & (1 << i)) {
  417. __be32 f;
  418. f = cpu_to_be32(octeon_get_io_clock_rate());
  419. fdt_setprop_inplace(initial_boot_params,
  420. uart, "clock-frequency",
  421. &f, sizeof(f));
  422. continue;
  423. }
  424. pr_debug("Deleting uart%d\n", i);
  425. fdt_nop_node(initial_boot_params, uart);
  426. fdt_nop_property(initial_boot_params, aliases,
  427. name_buffer);
  428. }
  429. }
  430. /* Compact Flash */
  431. alias_prop = fdt_getprop(initial_boot_params, aliases,
  432. "cf0", NULL);
  433. if (alias_prop) {
  434. union cvmx_mio_boot_reg_cfgx mio_boot_reg_cfg;
  435. unsigned long base_ptr, region_base, region_size;
  436. unsigned long region1_base = 0;
  437. unsigned long region1_size = 0;
  438. int cs, bootbus;
  439. bool is_16bit = false;
  440. bool is_true_ide = false;
  441. __be32 new_reg[6];
  442. __be32 *ranges;
  443. int len;
  444. int cf = fdt_path_offset(initial_boot_params, alias_prop);
  445. base_ptr = 0;
  446. if (octeon_bootinfo->major_version == 1
  447. && octeon_bootinfo->minor_version >= 1) {
  448. if (octeon_bootinfo->compact_flash_common_base_addr)
  449. base_ptr = octeon_bootinfo->compact_flash_common_base_addr;
  450. } else {
  451. base_ptr = 0x1d000800;
  452. }
  453. if (!base_ptr)
  454. goto no_cf;
  455. /* Find CS0 region. */
  456. for (cs = 0; cs < 8; cs++) {
  457. mio_boot_reg_cfg.u64 = cvmx_read_csr(CVMX_MIO_BOOT_REG_CFGX(cs));
  458. region_base = mio_boot_reg_cfg.s.base << 16;
  459. region_size = (mio_boot_reg_cfg.s.size + 1) << 16;
  460. if (mio_boot_reg_cfg.s.en && base_ptr >= region_base
  461. && base_ptr < region_base + region_size) {
  462. is_16bit = mio_boot_reg_cfg.s.width;
  463. break;
  464. }
  465. }
  466. if (cs >= 7) {
  467. /* cs and cs + 1 are CS0 and CS1, both must be less than 8. */
  468. goto no_cf;
  469. }
  470. if (!(base_ptr & 0xfffful)) {
  471. /*
  472. * Boot loader signals availability of DMA (true_ide
  473. * mode) by setting low order bits of base_ptr to
  474. * zero.
  475. */
  476. /* Asume that CS1 immediately follows. */
  477. mio_boot_reg_cfg.u64 =
  478. cvmx_read_csr(CVMX_MIO_BOOT_REG_CFGX(cs + 1));
  479. region1_base = mio_boot_reg_cfg.s.base << 16;
  480. region1_size = (mio_boot_reg_cfg.s.size + 1) << 16;
  481. if (!mio_boot_reg_cfg.s.en)
  482. goto no_cf;
  483. is_true_ide = true;
  484. } else {
  485. fdt_nop_property(initial_boot_params, cf, "cavium,true-ide");
  486. fdt_nop_property(initial_boot_params, cf, "cavium,dma-engine-handle");
  487. if (!is_16bit) {
  488. __be32 width = cpu_to_be32(8);
  489. fdt_setprop_inplace(initial_boot_params, cf,
  490. "cavium,bus-width", &width, sizeof(width));
  491. }
  492. }
  493. new_reg[0] = cpu_to_be32(cs);
  494. new_reg[1] = cpu_to_be32(0);
  495. new_reg[2] = cpu_to_be32(0x10000);
  496. new_reg[3] = cpu_to_be32(cs + 1);
  497. new_reg[4] = cpu_to_be32(0);
  498. new_reg[5] = cpu_to_be32(0x10000);
  499. fdt_setprop_inplace(initial_boot_params, cf,
  500. "reg", new_reg, sizeof(new_reg));
  501. bootbus = fdt_parent_offset(initial_boot_params, cf);
  502. if (bootbus < 0)
  503. goto no_cf;
  504. ranges = fdt_getprop_w(initial_boot_params, bootbus, "ranges", &len);
  505. if (!ranges || len < (5 * 8 * sizeof(__be32)))
  506. goto no_cf;
  507. ranges[(cs * 5) + 2] = cpu_to_be32(region_base >> 32);
  508. ranges[(cs * 5) + 3] = cpu_to_be32(region_base & 0xffffffff);
  509. ranges[(cs * 5) + 4] = cpu_to_be32(region_size);
  510. if (is_true_ide) {
  511. cs++;
  512. ranges[(cs * 5) + 2] = cpu_to_be32(region1_base >> 32);
  513. ranges[(cs * 5) + 3] = cpu_to_be32(region1_base & 0xffffffff);
  514. ranges[(cs * 5) + 4] = cpu_to_be32(region1_size);
  515. }
  516. goto end_cf;
  517. no_cf:
  518. fdt_nop_node(initial_boot_params, cf);
  519. end_cf:
  520. ;
  521. }
  522. /* 8 char LED */
  523. alias_prop = fdt_getprop(initial_boot_params, aliases,
  524. "led0", NULL);
  525. if (alias_prop) {
  526. union cvmx_mio_boot_reg_cfgx mio_boot_reg_cfg;
  527. unsigned long base_ptr, region_base, region_size;
  528. int cs, bootbus;
  529. __be32 new_reg[6];
  530. __be32 *ranges;
  531. int len;
  532. int led = fdt_path_offset(initial_boot_params, alias_prop);
  533. base_ptr = octeon_bootinfo->led_display_base_addr;
  534. if (base_ptr == 0)
  535. goto no_led;
  536. /* Find CS0 region. */
  537. for (cs = 0; cs < 8; cs++) {
  538. mio_boot_reg_cfg.u64 = cvmx_read_csr(CVMX_MIO_BOOT_REG_CFGX(cs));
  539. region_base = mio_boot_reg_cfg.s.base << 16;
  540. region_size = (mio_boot_reg_cfg.s.size + 1) << 16;
  541. if (mio_boot_reg_cfg.s.en && base_ptr >= region_base
  542. && base_ptr < region_base + region_size)
  543. break;
  544. }
  545. if (cs > 7)
  546. goto no_led;
  547. new_reg[0] = cpu_to_be32(cs);
  548. new_reg[1] = cpu_to_be32(0x20);
  549. new_reg[2] = cpu_to_be32(0x20);
  550. new_reg[3] = cpu_to_be32(cs);
  551. new_reg[4] = cpu_to_be32(0);
  552. new_reg[5] = cpu_to_be32(0x20);
  553. fdt_setprop_inplace(initial_boot_params, led,
  554. "reg", new_reg, sizeof(new_reg));
  555. bootbus = fdt_parent_offset(initial_boot_params, led);
  556. if (bootbus < 0)
  557. goto no_led;
  558. ranges = fdt_getprop_w(initial_boot_params, bootbus, "ranges", &len);
  559. if (!ranges || len < (5 * 8 * sizeof(__be32)))
  560. goto no_led;
  561. ranges[(cs * 5) + 2] = cpu_to_be32(region_base >> 32);
  562. ranges[(cs * 5) + 3] = cpu_to_be32(region_base & 0xffffffff);
  563. ranges[(cs * 5) + 4] = cpu_to_be32(region_size);
  564. goto end_led;
  565. no_led:
  566. fdt_nop_node(initial_boot_params, led);
  567. end_led:
  568. ;
  569. }
  570. /* OHCI/UHCI USB */
  571. alias_prop = fdt_getprop(initial_boot_params, aliases,
  572. "uctl", NULL);
  573. if (alias_prop) {
  574. int uctl = fdt_path_offset(initial_boot_params, alias_prop);
  575. if (uctl >= 0 && (!OCTEON_IS_MODEL(OCTEON_CN6XXX) ||
  576. octeon_bootinfo->board_type == CVMX_BOARD_TYPE_NIC2E)) {
  577. pr_debug("Deleting uctl\n");
  578. fdt_nop_node(initial_boot_params, uctl);
  579. fdt_nop_property(initial_boot_params, aliases, "uctl");
  580. } else if (octeon_bootinfo->board_type == CVMX_BOARD_TYPE_NIC10E ||
  581. octeon_bootinfo->board_type == CVMX_BOARD_TYPE_NIC4E) {
  582. /* Missing "refclk-type" defaults to crystal. */
  583. fdt_nop_property(initial_boot_params, uctl, "refclk-type");
  584. }
  585. }
  586. return 0;
  587. }
  588. static int __init octeon_publish_devices(void)
  589. {
  590. return of_platform_bus_probe(NULL, octeon_ids, NULL);
  591. }
  592. device_initcall(octeon_publish_devices);
  593. MODULE_AUTHOR("David Daney <ddaney@caviumnetworks.com>");
  594. MODULE_LICENSE("GPL");
  595. MODULE_DESCRIPTION("Platform driver for Octeon SOC");