octeon-platform.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  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-5750-usbn", },
  143. { .compatible = "cavium,octeon-3860-bootbus", },
  144. { .compatible = "cavium,mdio-mux", },
  145. { .compatible = "gpio-leds", },
  146. {},
  147. };
  148. static bool __init octeon_has_88e1145(void)
  149. {
  150. return !OCTEON_IS_MODEL(OCTEON_CN52XX) &&
  151. !OCTEON_IS_MODEL(OCTEON_CN6XXX) &&
  152. !OCTEON_IS_MODEL(OCTEON_CN56XX);
  153. }
  154. static void __init octeon_fdt_set_phy(int eth, int phy_addr)
  155. {
  156. const __be32 *phy_handle;
  157. const __be32 *alt_phy_handle;
  158. const __be32 *reg;
  159. u32 phandle;
  160. int phy;
  161. int alt_phy;
  162. const char *p;
  163. int current_len;
  164. char new_name[20];
  165. phy_handle = fdt_getprop(initial_boot_params, eth, "phy-handle", NULL);
  166. if (!phy_handle)
  167. return;
  168. phandle = be32_to_cpup(phy_handle);
  169. phy = fdt_node_offset_by_phandle(initial_boot_params, phandle);
  170. alt_phy_handle = fdt_getprop(initial_boot_params, eth, "cavium,alt-phy-handle", NULL);
  171. if (alt_phy_handle) {
  172. u32 alt_phandle = be32_to_cpup(alt_phy_handle);
  173. alt_phy = fdt_node_offset_by_phandle(initial_boot_params, alt_phandle);
  174. } else {
  175. alt_phy = -1;
  176. }
  177. if (phy_addr < 0 || phy < 0) {
  178. /* Delete the PHY things */
  179. fdt_nop_property(initial_boot_params, eth, "phy-handle");
  180. /* This one may fail */
  181. fdt_nop_property(initial_boot_params, eth, "cavium,alt-phy-handle");
  182. if (phy >= 0)
  183. fdt_nop_node(initial_boot_params, phy);
  184. if (alt_phy >= 0)
  185. fdt_nop_node(initial_boot_params, alt_phy);
  186. return;
  187. }
  188. if (phy_addr >= 256 && alt_phy > 0) {
  189. const struct fdt_property *phy_prop;
  190. struct fdt_property *alt_prop;
  191. u32 phy_handle_name;
  192. /* Use the alt phy node instead.*/
  193. phy_prop = fdt_get_property(initial_boot_params, eth, "phy-handle", NULL);
  194. phy_handle_name = phy_prop->nameoff;
  195. fdt_nop_node(initial_boot_params, phy);
  196. fdt_nop_property(initial_boot_params, eth, "phy-handle");
  197. alt_prop = fdt_get_property_w(initial_boot_params, eth, "cavium,alt-phy-handle", NULL);
  198. alt_prop->nameoff = phy_handle_name;
  199. phy = alt_phy;
  200. }
  201. phy_addr &= 0xff;
  202. if (octeon_has_88e1145()) {
  203. fdt_nop_property(initial_boot_params, phy, "marvell,reg-init");
  204. memset(new_name, 0, sizeof(new_name));
  205. strcpy(new_name, "marvell,88e1145");
  206. p = fdt_getprop(initial_boot_params, phy, "compatible",
  207. &current_len);
  208. if (p && current_len >= strlen(new_name))
  209. fdt_setprop_inplace(initial_boot_params, phy,
  210. "compatible", new_name, current_len);
  211. }
  212. reg = fdt_getprop(initial_boot_params, phy, "reg", NULL);
  213. if (phy_addr == be32_to_cpup(reg))
  214. return;
  215. fdt_setprop_inplace_cell(initial_boot_params, phy, "reg", phy_addr);
  216. snprintf(new_name, sizeof(new_name), "ethernet-phy@%x", phy_addr);
  217. p = fdt_get_name(initial_boot_params, phy, &current_len);
  218. if (p && current_len == strlen(new_name))
  219. fdt_set_name(initial_boot_params, phy, new_name);
  220. else
  221. pr_err("Error: could not rename ethernet phy: <%s>", p);
  222. }
  223. static void __init octeon_fdt_set_mac_addr(int n, u64 *pmac)
  224. {
  225. u8 new_mac[6];
  226. u64 mac = *pmac;
  227. int r;
  228. new_mac[0] = (mac >> 40) & 0xff;
  229. new_mac[1] = (mac >> 32) & 0xff;
  230. new_mac[2] = (mac >> 24) & 0xff;
  231. new_mac[3] = (mac >> 16) & 0xff;
  232. new_mac[4] = (mac >> 8) & 0xff;
  233. new_mac[5] = mac & 0xff;
  234. r = fdt_setprop_inplace(initial_boot_params, n, "local-mac-address",
  235. new_mac, sizeof(new_mac));
  236. if (r) {
  237. pr_err("Setting \"local-mac-address\" failed %d", r);
  238. return;
  239. }
  240. *pmac = mac + 1;
  241. }
  242. static void __init octeon_fdt_rm_ethernet(int node)
  243. {
  244. const __be32 *phy_handle;
  245. phy_handle = fdt_getprop(initial_boot_params, node, "phy-handle", NULL);
  246. if (phy_handle) {
  247. u32 ph = be32_to_cpup(phy_handle);
  248. int p = fdt_node_offset_by_phandle(initial_boot_params, ph);
  249. if (p >= 0)
  250. fdt_nop_node(initial_boot_params, p);
  251. }
  252. fdt_nop_node(initial_boot_params, node);
  253. }
  254. static void __init octeon_fdt_pip_port(int iface, int i, int p, int max, u64 *pmac)
  255. {
  256. char name_buffer[20];
  257. int eth;
  258. int phy_addr;
  259. int ipd_port;
  260. snprintf(name_buffer, sizeof(name_buffer), "ethernet@%x", p);
  261. eth = fdt_subnode_offset(initial_boot_params, iface, name_buffer);
  262. if (eth < 0)
  263. return;
  264. if (p > max) {
  265. pr_debug("Deleting port %x:%x\n", i, p);
  266. octeon_fdt_rm_ethernet(eth);
  267. return;
  268. }
  269. if (OCTEON_IS_MODEL(OCTEON_CN68XX))
  270. ipd_port = (0x100 * i) + (0x10 * p) + 0x800;
  271. else
  272. ipd_port = 16 * i + p;
  273. phy_addr = cvmx_helper_board_get_mii_address(ipd_port);
  274. octeon_fdt_set_phy(eth, phy_addr);
  275. octeon_fdt_set_mac_addr(eth, pmac);
  276. }
  277. static void __init octeon_fdt_pip_iface(int pip, int idx, u64 *pmac)
  278. {
  279. char name_buffer[20];
  280. int iface;
  281. int p;
  282. int count = 0;
  283. snprintf(name_buffer, sizeof(name_buffer), "interface@%d", idx);
  284. iface = fdt_subnode_offset(initial_boot_params, pip, name_buffer);
  285. if (iface < 0)
  286. return;
  287. if (cvmx_helper_interface_enumerate(idx) == 0)
  288. count = cvmx_helper_ports_on_interface(idx);
  289. for (p = 0; p < 16; p++)
  290. octeon_fdt_pip_port(iface, idx, p, count - 1, pmac);
  291. }
  292. int __init octeon_prune_device_tree(void)
  293. {
  294. int i, max_port, uart_mask;
  295. const char *pip_path;
  296. const char *alias_prop;
  297. char name_buffer[20];
  298. int aliases;
  299. u64 mac_addr_base;
  300. if (fdt_check_header(initial_boot_params))
  301. panic("Corrupt Device Tree.");
  302. aliases = fdt_path_offset(initial_boot_params, "/aliases");
  303. if (aliases < 0) {
  304. pr_err("Error: No /aliases node in device tree.");
  305. return -EINVAL;
  306. }
  307. mac_addr_base =
  308. ((octeon_bootinfo->mac_addr_base[0] & 0xffull)) << 40 |
  309. ((octeon_bootinfo->mac_addr_base[1] & 0xffull)) << 32 |
  310. ((octeon_bootinfo->mac_addr_base[2] & 0xffull)) << 24 |
  311. ((octeon_bootinfo->mac_addr_base[3] & 0xffull)) << 16 |
  312. ((octeon_bootinfo->mac_addr_base[4] & 0xffull)) << 8 |
  313. (octeon_bootinfo->mac_addr_base[5] & 0xffull);
  314. if (OCTEON_IS_MODEL(OCTEON_CN52XX) || OCTEON_IS_MODEL(OCTEON_CN63XX))
  315. max_port = 2;
  316. else if (OCTEON_IS_MODEL(OCTEON_CN56XX) || OCTEON_IS_MODEL(OCTEON_CN68XX))
  317. max_port = 1;
  318. else
  319. max_port = 0;
  320. if (octeon_bootinfo->board_type == CVMX_BOARD_TYPE_NIC10E)
  321. max_port = 0;
  322. for (i = 0; i < 2; i++) {
  323. int mgmt;
  324. snprintf(name_buffer, sizeof(name_buffer),
  325. "mix%d", i);
  326. alias_prop = fdt_getprop(initial_boot_params, aliases,
  327. name_buffer, NULL);
  328. if (alias_prop) {
  329. mgmt = fdt_path_offset(initial_boot_params, alias_prop);
  330. if (mgmt < 0)
  331. continue;
  332. if (i >= max_port) {
  333. pr_debug("Deleting mix%d\n", i);
  334. octeon_fdt_rm_ethernet(mgmt);
  335. fdt_nop_property(initial_boot_params, aliases,
  336. name_buffer);
  337. } else {
  338. int phy_addr = cvmx_helper_board_get_mii_address(CVMX_HELPER_BOARD_MGMT_IPD_PORT + i);
  339. octeon_fdt_set_phy(mgmt, phy_addr);
  340. octeon_fdt_set_mac_addr(mgmt, &mac_addr_base);
  341. }
  342. }
  343. }
  344. pip_path = fdt_getprop(initial_boot_params, aliases, "pip", NULL);
  345. if (pip_path) {
  346. int pip = fdt_path_offset(initial_boot_params, pip_path);
  347. if (pip >= 0)
  348. for (i = 0; i <= 4; i++)
  349. octeon_fdt_pip_iface(pip, i, &mac_addr_base);
  350. }
  351. /* I2C */
  352. if (OCTEON_IS_MODEL(OCTEON_CN52XX) ||
  353. OCTEON_IS_MODEL(OCTEON_CN63XX) ||
  354. OCTEON_IS_MODEL(OCTEON_CN68XX) ||
  355. OCTEON_IS_MODEL(OCTEON_CN56XX))
  356. max_port = 2;
  357. else
  358. max_port = 1;
  359. for (i = 0; i < 2; i++) {
  360. int i2c;
  361. snprintf(name_buffer, sizeof(name_buffer),
  362. "twsi%d", i);
  363. alias_prop = fdt_getprop(initial_boot_params, aliases,
  364. name_buffer, NULL);
  365. if (alias_prop) {
  366. i2c = fdt_path_offset(initial_boot_params, alias_prop);
  367. if (i2c < 0)
  368. continue;
  369. if (i >= max_port) {
  370. pr_debug("Deleting twsi%d\n", i);
  371. fdt_nop_node(initial_boot_params, i2c);
  372. fdt_nop_property(initial_boot_params, aliases,
  373. name_buffer);
  374. }
  375. }
  376. }
  377. /* SMI/MDIO */
  378. if (OCTEON_IS_MODEL(OCTEON_CN68XX))
  379. max_port = 4;
  380. else if (OCTEON_IS_MODEL(OCTEON_CN52XX) ||
  381. OCTEON_IS_MODEL(OCTEON_CN63XX) ||
  382. OCTEON_IS_MODEL(OCTEON_CN56XX))
  383. max_port = 2;
  384. else
  385. max_port = 1;
  386. for (i = 0; i < 2; i++) {
  387. int i2c;
  388. snprintf(name_buffer, sizeof(name_buffer),
  389. "smi%d", i);
  390. alias_prop = fdt_getprop(initial_boot_params, aliases,
  391. name_buffer, NULL);
  392. if (alias_prop) {
  393. i2c = fdt_path_offset(initial_boot_params, alias_prop);
  394. if (i2c < 0)
  395. continue;
  396. if (i >= max_port) {
  397. pr_debug("Deleting smi%d\n", i);
  398. fdt_nop_node(initial_boot_params, i2c);
  399. fdt_nop_property(initial_boot_params, aliases,
  400. name_buffer);
  401. }
  402. }
  403. }
  404. /* Serial */
  405. uart_mask = 3;
  406. /* Right now CN52XX is the only chip with a third uart */
  407. if (OCTEON_IS_MODEL(OCTEON_CN52XX))
  408. uart_mask |= 4; /* uart2 */
  409. for (i = 0; i < 3; i++) {
  410. int uart;
  411. snprintf(name_buffer, sizeof(name_buffer),
  412. "uart%d", i);
  413. alias_prop = fdt_getprop(initial_boot_params, aliases,
  414. name_buffer, NULL);
  415. if (alias_prop) {
  416. uart = fdt_path_offset(initial_boot_params, alias_prop);
  417. if (uart_mask & (1 << i)) {
  418. __be32 f;
  419. f = cpu_to_be32(octeon_get_io_clock_rate());
  420. fdt_setprop_inplace(initial_boot_params,
  421. uart, "clock-frequency",
  422. &f, sizeof(f));
  423. continue;
  424. }
  425. pr_debug("Deleting uart%d\n", i);
  426. fdt_nop_node(initial_boot_params, uart);
  427. fdt_nop_property(initial_boot_params, aliases,
  428. name_buffer);
  429. }
  430. }
  431. /* Compact Flash */
  432. alias_prop = fdt_getprop(initial_boot_params, aliases,
  433. "cf0", NULL);
  434. if (alias_prop) {
  435. union cvmx_mio_boot_reg_cfgx mio_boot_reg_cfg;
  436. unsigned long base_ptr, region_base, region_size;
  437. unsigned long region1_base = 0;
  438. unsigned long region1_size = 0;
  439. int cs, bootbus;
  440. bool is_16bit = false;
  441. bool is_true_ide = false;
  442. __be32 new_reg[6];
  443. __be32 *ranges;
  444. int len;
  445. int cf = fdt_path_offset(initial_boot_params, alias_prop);
  446. base_ptr = 0;
  447. if (octeon_bootinfo->major_version == 1
  448. && octeon_bootinfo->minor_version >= 1) {
  449. if (octeon_bootinfo->compact_flash_common_base_addr)
  450. base_ptr = octeon_bootinfo->compact_flash_common_base_addr;
  451. } else {
  452. base_ptr = 0x1d000800;
  453. }
  454. if (!base_ptr)
  455. goto no_cf;
  456. /* Find CS0 region. */
  457. for (cs = 0; cs < 8; cs++) {
  458. mio_boot_reg_cfg.u64 = cvmx_read_csr(CVMX_MIO_BOOT_REG_CFGX(cs));
  459. region_base = mio_boot_reg_cfg.s.base << 16;
  460. region_size = (mio_boot_reg_cfg.s.size + 1) << 16;
  461. if (mio_boot_reg_cfg.s.en && base_ptr >= region_base
  462. && base_ptr < region_base + region_size) {
  463. is_16bit = mio_boot_reg_cfg.s.width;
  464. break;
  465. }
  466. }
  467. if (cs >= 7) {
  468. /* cs and cs + 1 are CS0 and CS1, both must be less than 8. */
  469. goto no_cf;
  470. }
  471. if (!(base_ptr & 0xfffful)) {
  472. /*
  473. * Boot loader signals availability of DMA (true_ide
  474. * mode) by setting low order bits of base_ptr to
  475. * zero.
  476. */
  477. /* Asume that CS1 immediately follows. */
  478. mio_boot_reg_cfg.u64 =
  479. cvmx_read_csr(CVMX_MIO_BOOT_REG_CFGX(cs + 1));
  480. region1_base = mio_boot_reg_cfg.s.base << 16;
  481. region1_size = (mio_boot_reg_cfg.s.size + 1) << 16;
  482. if (!mio_boot_reg_cfg.s.en)
  483. goto no_cf;
  484. is_true_ide = true;
  485. } else {
  486. fdt_nop_property(initial_boot_params, cf, "cavium,true-ide");
  487. fdt_nop_property(initial_boot_params, cf, "cavium,dma-engine-handle");
  488. if (!is_16bit) {
  489. __be32 width = cpu_to_be32(8);
  490. fdt_setprop_inplace(initial_boot_params, cf,
  491. "cavium,bus-width", &width, sizeof(width));
  492. }
  493. }
  494. new_reg[0] = cpu_to_be32(cs);
  495. new_reg[1] = cpu_to_be32(0);
  496. new_reg[2] = cpu_to_be32(0x10000);
  497. new_reg[3] = cpu_to_be32(cs + 1);
  498. new_reg[4] = cpu_to_be32(0);
  499. new_reg[5] = cpu_to_be32(0x10000);
  500. fdt_setprop_inplace(initial_boot_params, cf,
  501. "reg", new_reg, sizeof(new_reg));
  502. bootbus = fdt_parent_offset(initial_boot_params, cf);
  503. if (bootbus < 0)
  504. goto no_cf;
  505. ranges = fdt_getprop_w(initial_boot_params, bootbus, "ranges", &len);
  506. if (!ranges || len < (5 * 8 * sizeof(__be32)))
  507. goto no_cf;
  508. ranges[(cs * 5) + 2] = cpu_to_be32(region_base >> 32);
  509. ranges[(cs * 5) + 3] = cpu_to_be32(region_base & 0xffffffff);
  510. ranges[(cs * 5) + 4] = cpu_to_be32(region_size);
  511. if (is_true_ide) {
  512. cs++;
  513. ranges[(cs * 5) + 2] = cpu_to_be32(region1_base >> 32);
  514. ranges[(cs * 5) + 3] = cpu_to_be32(region1_base & 0xffffffff);
  515. ranges[(cs * 5) + 4] = cpu_to_be32(region1_size);
  516. }
  517. goto end_cf;
  518. no_cf:
  519. fdt_nop_node(initial_boot_params, cf);
  520. end_cf:
  521. ;
  522. }
  523. /* 8 char LED */
  524. alias_prop = fdt_getprop(initial_boot_params, aliases,
  525. "led0", NULL);
  526. if (alias_prop) {
  527. union cvmx_mio_boot_reg_cfgx mio_boot_reg_cfg;
  528. unsigned long base_ptr, region_base, region_size;
  529. int cs, bootbus;
  530. __be32 new_reg[6];
  531. __be32 *ranges;
  532. int len;
  533. int led = fdt_path_offset(initial_boot_params, alias_prop);
  534. base_ptr = octeon_bootinfo->led_display_base_addr;
  535. if (base_ptr == 0)
  536. goto no_led;
  537. /* Find CS0 region. */
  538. for (cs = 0; cs < 8; cs++) {
  539. mio_boot_reg_cfg.u64 = cvmx_read_csr(CVMX_MIO_BOOT_REG_CFGX(cs));
  540. region_base = mio_boot_reg_cfg.s.base << 16;
  541. region_size = (mio_boot_reg_cfg.s.size + 1) << 16;
  542. if (mio_boot_reg_cfg.s.en && base_ptr >= region_base
  543. && base_ptr < region_base + region_size)
  544. break;
  545. }
  546. if (cs > 7)
  547. goto no_led;
  548. new_reg[0] = cpu_to_be32(cs);
  549. new_reg[1] = cpu_to_be32(0x20);
  550. new_reg[2] = cpu_to_be32(0x20);
  551. new_reg[3] = cpu_to_be32(cs);
  552. new_reg[4] = cpu_to_be32(0);
  553. new_reg[5] = cpu_to_be32(0x20);
  554. fdt_setprop_inplace(initial_boot_params, led,
  555. "reg", new_reg, sizeof(new_reg));
  556. bootbus = fdt_parent_offset(initial_boot_params, led);
  557. if (bootbus < 0)
  558. goto no_led;
  559. ranges = fdt_getprop_w(initial_boot_params, bootbus, "ranges", &len);
  560. if (!ranges || len < (5 * 8 * sizeof(__be32)))
  561. goto no_led;
  562. ranges[(cs * 5) + 2] = cpu_to_be32(region_base >> 32);
  563. ranges[(cs * 5) + 3] = cpu_to_be32(region_base & 0xffffffff);
  564. ranges[(cs * 5) + 4] = cpu_to_be32(region_size);
  565. goto end_led;
  566. no_led:
  567. fdt_nop_node(initial_boot_params, led);
  568. end_led:
  569. ;
  570. }
  571. /* OHCI/UHCI USB */
  572. alias_prop = fdt_getprop(initial_boot_params, aliases,
  573. "uctl", NULL);
  574. if (alias_prop) {
  575. int uctl = fdt_path_offset(initial_boot_params, alias_prop);
  576. if (uctl >= 0 && (!OCTEON_IS_MODEL(OCTEON_CN6XXX) ||
  577. octeon_bootinfo->board_type == CVMX_BOARD_TYPE_NIC2E)) {
  578. pr_debug("Deleting uctl\n");
  579. fdt_nop_node(initial_boot_params, uctl);
  580. fdt_nop_property(initial_boot_params, aliases, "uctl");
  581. } else if (octeon_bootinfo->board_type == CVMX_BOARD_TYPE_NIC10E ||
  582. octeon_bootinfo->board_type == CVMX_BOARD_TYPE_NIC4E) {
  583. /* Missing "refclk-type" defaults to crystal. */
  584. fdt_nop_property(initial_boot_params, uctl, "refclk-type");
  585. }
  586. }
  587. /* DWC2 USB */
  588. alias_prop = fdt_getprop(initial_boot_params, aliases,
  589. "usbn", NULL);
  590. if (alias_prop) {
  591. int usbn = fdt_path_offset(initial_boot_params, alias_prop);
  592. if (usbn >= 0 && (current_cpu_type() == CPU_CAVIUM_OCTEON2 ||
  593. !octeon_has_feature(OCTEON_FEATURE_USB))) {
  594. pr_debug("Deleting usbn\n");
  595. fdt_nop_node(initial_boot_params, usbn);
  596. fdt_nop_property(initial_boot_params, aliases, "usbn");
  597. } else {
  598. __be32 new_f[1];
  599. enum cvmx_helper_board_usb_clock_types c;
  600. c = __cvmx_helper_board_usb_get_clock_type();
  601. switch (c) {
  602. case USB_CLOCK_TYPE_REF_48:
  603. new_f[0] = cpu_to_be32(48000000);
  604. fdt_setprop_inplace(initial_boot_params, usbn,
  605. "refclk-frequency", new_f, sizeof(new_f));
  606. /* Fall through ...*/
  607. case USB_CLOCK_TYPE_REF_12:
  608. /* Missing "refclk-type" defaults to external. */
  609. fdt_nop_property(initial_boot_params, usbn, "refclk-type");
  610. break;
  611. default:
  612. break;
  613. }
  614. }
  615. }
  616. return 0;
  617. }
  618. static int __init octeon_publish_devices(void)
  619. {
  620. return of_platform_bus_probe(NULL, octeon_ids, NULL);
  621. }
  622. device_initcall(octeon_publish_devices);
  623. MODULE_AUTHOR("David Daney <ddaney@caviumnetworks.com>");
  624. MODULE_LICENSE("GPL");
  625. MODULE_DESCRIPTION("Platform driver for Octeon SOC");