octeon-platform.c 20 KB

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