octeon-platform.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882
  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. /* Octeon SMI/MDIO interface. */
  148. static int __init octeon_mdiobus_device_init(void)
  149. {
  150. struct platform_device *pd;
  151. int ret = 0;
  152. if (octeon_is_simulation())
  153. return 0; /* No mdio in the simulator. */
  154. /* The bus number is the platform_device id. */
  155. pd = platform_device_alloc("mdio-octeon", 0);
  156. if (!pd) {
  157. ret = -ENOMEM;
  158. goto out;
  159. }
  160. ret = platform_device_add(pd);
  161. if (ret)
  162. goto fail;
  163. return ret;
  164. fail:
  165. platform_device_put(pd);
  166. out:
  167. return ret;
  168. }
  169. device_initcall(octeon_mdiobus_device_init);
  170. /* Octeon mgmt port Ethernet interface. */
  171. static int __init octeon_mgmt_device_init(void)
  172. {
  173. struct platform_device *pd;
  174. int ret = 0;
  175. int port, num_ports;
  176. struct resource mgmt_port_resource = {
  177. .flags = IORESOURCE_IRQ,
  178. .start = -1,
  179. .end = -1
  180. };
  181. if (!OCTEON_IS_MODEL(OCTEON_CN56XX) && !OCTEON_IS_MODEL(OCTEON_CN52XX))
  182. return 0;
  183. if (OCTEON_IS_MODEL(OCTEON_CN56XX))
  184. num_ports = 1;
  185. else
  186. num_ports = 2;
  187. for (port = 0; port < num_ports; port++) {
  188. pd = platform_device_alloc("octeon_mgmt", port);
  189. if (!pd) {
  190. ret = -ENOMEM;
  191. goto out;
  192. }
  193. /* No DMA restrictions */
  194. pd->dev.coherent_dma_mask = DMA_BIT_MASK(64);
  195. pd->dev.dma_mask = &pd->dev.coherent_dma_mask;
  196. switch (port) {
  197. case 0:
  198. mgmt_port_resource.start = OCTEON_IRQ_MII0;
  199. break;
  200. case 1:
  201. mgmt_port_resource.start = OCTEON_IRQ_MII1;
  202. break;
  203. default:
  204. BUG();
  205. }
  206. mgmt_port_resource.end = mgmt_port_resource.start;
  207. ret = platform_device_add_resources(pd, &mgmt_port_resource, 1);
  208. if (ret)
  209. goto fail;
  210. ret = platform_device_add(pd);
  211. if (ret)
  212. goto fail;
  213. }
  214. return ret;
  215. fail:
  216. platform_device_put(pd);
  217. out:
  218. return ret;
  219. }
  220. device_initcall(octeon_mgmt_device_init);
  221. #ifdef CONFIG_USB
  222. static int __init octeon_ehci_device_init(void)
  223. {
  224. struct platform_device *pd;
  225. int ret = 0;
  226. struct resource usb_resources[] = {
  227. {
  228. .flags = IORESOURCE_MEM,
  229. }, {
  230. .flags = IORESOURCE_IRQ,
  231. }
  232. };
  233. /* Only Octeon2 has ehci/ohci */
  234. if (!OCTEON_IS_MODEL(OCTEON_CN63XX))
  235. return 0;
  236. if (octeon_is_simulation() || usb_disabled())
  237. return 0; /* No USB in the simulator. */
  238. pd = platform_device_alloc("octeon-ehci", 0);
  239. if (!pd) {
  240. ret = -ENOMEM;
  241. goto out;
  242. }
  243. usb_resources[0].start = 0x00016F0000000000ULL;
  244. usb_resources[0].end = usb_resources[0].start + 0x100;
  245. usb_resources[1].start = OCTEON_IRQ_USB0;
  246. usb_resources[1].end = OCTEON_IRQ_USB0;
  247. ret = platform_device_add_resources(pd, usb_resources,
  248. ARRAY_SIZE(usb_resources));
  249. if (ret)
  250. goto fail;
  251. ret = platform_device_add(pd);
  252. if (ret)
  253. goto fail;
  254. return ret;
  255. fail:
  256. platform_device_put(pd);
  257. out:
  258. return ret;
  259. }
  260. device_initcall(octeon_ehci_device_init);
  261. static int __init octeon_ohci_device_init(void)
  262. {
  263. struct platform_device *pd;
  264. int ret = 0;
  265. struct resource usb_resources[] = {
  266. {
  267. .flags = IORESOURCE_MEM,
  268. }, {
  269. .flags = IORESOURCE_IRQ,
  270. }
  271. };
  272. /* Only Octeon2 has ehci/ohci */
  273. if (!OCTEON_IS_MODEL(OCTEON_CN63XX))
  274. return 0;
  275. if (octeon_is_simulation() || usb_disabled())
  276. return 0; /* No USB in the simulator. */
  277. pd = platform_device_alloc("octeon-ohci", 0);
  278. if (!pd) {
  279. ret = -ENOMEM;
  280. goto out;
  281. }
  282. usb_resources[0].start = 0x00016F0000000400ULL;
  283. usb_resources[0].end = usb_resources[0].start + 0x100;
  284. usb_resources[1].start = OCTEON_IRQ_USB0;
  285. usb_resources[1].end = OCTEON_IRQ_USB0;
  286. ret = platform_device_add_resources(pd, usb_resources,
  287. ARRAY_SIZE(usb_resources));
  288. if (ret)
  289. goto fail;
  290. ret = platform_device_add(pd);
  291. if (ret)
  292. goto fail;
  293. return ret;
  294. fail:
  295. platform_device_put(pd);
  296. out:
  297. return ret;
  298. }
  299. device_initcall(octeon_ohci_device_init);
  300. #endif /* CONFIG_USB */
  301. static struct of_device_id __initdata octeon_ids[] = {
  302. { .compatible = "simple-bus", },
  303. { .compatible = "cavium,octeon-6335-uctl", },
  304. { .compatible = "cavium,octeon-3860-bootbus", },
  305. { .compatible = "cavium,mdio-mux", },
  306. { .compatible = "gpio-leds", },
  307. {},
  308. };
  309. static bool __init octeon_has_88e1145(void)
  310. {
  311. return !OCTEON_IS_MODEL(OCTEON_CN52XX) &&
  312. !OCTEON_IS_MODEL(OCTEON_CN6XXX) &&
  313. !OCTEON_IS_MODEL(OCTEON_CN56XX);
  314. }
  315. static void __init octeon_fdt_set_phy(int eth, int phy_addr)
  316. {
  317. const __be32 *phy_handle;
  318. const __be32 *alt_phy_handle;
  319. const __be32 *reg;
  320. u32 phandle;
  321. int phy;
  322. int alt_phy;
  323. const char *p;
  324. int current_len;
  325. char new_name[20];
  326. phy_handle = fdt_getprop(initial_boot_params, eth, "phy-handle", NULL);
  327. if (!phy_handle)
  328. return;
  329. phandle = be32_to_cpup(phy_handle);
  330. phy = fdt_node_offset_by_phandle(initial_boot_params, phandle);
  331. alt_phy_handle = fdt_getprop(initial_boot_params, eth, "cavium,alt-phy-handle", NULL);
  332. if (alt_phy_handle) {
  333. u32 alt_phandle = be32_to_cpup(alt_phy_handle);
  334. alt_phy = fdt_node_offset_by_phandle(initial_boot_params, alt_phandle);
  335. } else {
  336. alt_phy = -1;
  337. }
  338. if (phy_addr < 0 || phy < 0) {
  339. /* Delete the PHY things */
  340. fdt_nop_property(initial_boot_params, eth, "phy-handle");
  341. /* This one may fail */
  342. fdt_nop_property(initial_boot_params, eth, "cavium,alt-phy-handle");
  343. if (phy >= 0)
  344. fdt_nop_node(initial_boot_params, phy);
  345. if (alt_phy >= 0)
  346. fdt_nop_node(initial_boot_params, alt_phy);
  347. return;
  348. }
  349. if (phy_addr >= 256 && alt_phy > 0) {
  350. const struct fdt_property *phy_prop;
  351. struct fdt_property *alt_prop;
  352. u32 phy_handle_name;
  353. /* Use the alt phy node instead.*/
  354. phy_prop = fdt_get_property(initial_boot_params, eth, "phy-handle", NULL);
  355. phy_handle_name = phy_prop->nameoff;
  356. fdt_nop_node(initial_boot_params, phy);
  357. fdt_nop_property(initial_boot_params, eth, "phy-handle");
  358. alt_prop = fdt_get_property_w(initial_boot_params, eth, "cavium,alt-phy-handle", NULL);
  359. alt_prop->nameoff = phy_handle_name;
  360. phy = alt_phy;
  361. }
  362. phy_addr &= 0xff;
  363. if (octeon_has_88e1145()) {
  364. fdt_nop_property(initial_boot_params, phy, "marvell,reg-init");
  365. memset(new_name, 0, sizeof(new_name));
  366. strcpy(new_name, "marvell,88e1145");
  367. p = fdt_getprop(initial_boot_params, phy, "compatible",
  368. &current_len);
  369. if (p && current_len >= strlen(new_name))
  370. fdt_setprop_inplace(initial_boot_params, phy,
  371. "compatible", new_name, current_len);
  372. }
  373. reg = fdt_getprop(initial_boot_params, phy, "reg", NULL);
  374. if (phy_addr == be32_to_cpup(reg))
  375. return;
  376. fdt_setprop_inplace_cell(initial_boot_params, phy, "reg", phy_addr);
  377. snprintf(new_name, sizeof(new_name), "ethernet-phy@%x", phy_addr);
  378. p = fdt_get_name(initial_boot_params, phy, &current_len);
  379. if (p && current_len == strlen(new_name))
  380. fdt_set_name(initial_boot_params, phy, new_name);
  381. else
  382. pr_err("Error: could not rename ethernet phy: <%s>", p);
  383. }
  384. static void __init octeon_fdt_set_mac_addr(int n, u64 *pmac)
  385. {
  386. u8 new_mac[6];
  387. u64 mac = *pmac;
  388. int r;
  389. new_mac[0] = (mac >> 40) & 0xff;
  390. new_mac[1] = (mac >> 32) & 0xff;
  391. new_mac[2] = (mac >> 24) & 0xff;
  392. new_mac[3] = (mac >> 16) & 0xff;
  393. new_mac[4] = (mac >> 8) & 0xff;
  394. new_mac[5] = mac & 0xff;
  395. r = fdt_setprop_inplace(initial_boot_params, n, "local-mac-address",
  396. new_mac, sizeof(new_mac));
  397. if (r) {
  398. pr_err("Setting \"local-mac-address\" failed %d", r);
  399. return;
  400. }
  401. *pmac = mac + 1;
  402. }
  403. static void __init octeon_fdt_rm_ethernet(int node)
  404. {
  405. const __be32 *phy_handle;
  406. phy_handle = fdt_getprop(initial_boot_params, node, "phy-handle", NULL);
  407. if (phy_handle) {
  408. u32 ph = be32_to_cpup(phy_handle);
  409. int p = fdt_node_offset_by_phandle(initial_boot_params, ph);
  410. if (p >= 0)
  411. fdt_nop_node(initial_boot_params, p);
  412. }
  413. fdt_nop_node(initial_boot_params, node);
  414. }
  415. static void __init octeon_fdt_pip_port(int iface, int i, int p, int max, u64 *pmac)
  416. {
  417. char name_buffer[20];
  418. int eth;
  419. int phy_addr;
  420. int ipd_port;
  421. snprintf(name_buffer, sizeof(name_buffer), "ethernet@%x", p);
  422. eth = fdt_subnode_offset(initial_boot_params, iface, name_buffer);
  423. if (eth < 0)
  424. return;
  425. if (p > max) {
  426. pr_debug("Deleting port %x:%x\n", i, p);
  427. octeon_fdt_rm_ethernet(eth);
  428. return;
  429. }
  430. if (OCTEON_IS_MODEL(OCTEON_CN68XX))
  431. ipd_port = (0x100 * i) + (0x10 * p) + 0x800;
  432. else
  433. ipd_port = 16 * i + p;
  434. phy_addr = cvmx_helper_board_get_mii_address(ipd_port);
  435. octeon_fdt_set_phy(eth, phy_addr);
  436. octeon_fdt_set_mac_addr(eth, pmac);
  437. }
  438. static void __init octeon_fdt_pip_iface(int pip, int idx, u64 *pmac)
  439. {
  440. char name_buffer[20];
  441. int iface;
  442. int p;
  443. int count;
  444. count = cvmx_helper_interface_enumerate(idx);
  445. snprintf(name_buffer, sizeof(name_buffer), "interface@%d", idx);
  446. iface = fdt_subnode_offset(initial_boot_params, pip, name_buffer);
  447. if (iface < 0)
  448. return;
  449. for (p = 0; p < 16; p++)
  450. octeon_fdt_pip_port(iface, idx, p, count - 1, pmac);
  451. }
  452. int __init octeon_prune_device_tree(void)
  453. {
  454. int i, max_port, uart_mask;
  455. const char *pip_path;
  456. const char *alias_prop;
  457. char name_buffer[20];
  458. int aliases;
  459. u64 mac_addr_base;
  460. if (fdt_check_header(initial_boot_params))
  461. panic("Corrupt Device Tree.");
  462. aliases = fdt_path_offset(initial_boot_params, "/aliases");
  463. if (aliases < 0) {
  464. pr_err("Error: No /aliases node in device tree.");
  465. return -EINVAL;
  466. }
  467. mac_addr_base =
  468. ((octeon_bootinfo->mac_addr_base[0] & 0xffull)) << 40 |
  469. ((octeon_bootinfo->mac_addr_base[1] & 0xffull)) << 32 |
  470. ((octeon_bootinfo->mac_addr_base[2] & 0xffull)) << 24 |
  471. ((octeon_bootinfo->mac_addr_base[3] & 0xffull)) << 16 |
  472. ((octeon_bootinfo->mac_addr_base[4] & 0xffull)) << 8 |
  473. (octeon_bootinfo->mac_addr_base[5] & 0xffull);
  474. if (OCTEON_IS_MODEL(OCTEON_CN52XX) || OCTEON_IS_MODEL(OCTEON_CN63XX))
  475. max_port = 2;
  476. else if (OCTEON_IS_MODEL(OCTEON_CN56XX) || OCTEON_IS_MODEL(OCTEON_CN68XX))
  477. max_port = 1;
  478. else
  479. max_port = 0;
  480. if (octeon_bootinfo->board_type == CVMX_BOARD_TYPE_NIC10E)
  481. max_port = 0;
  482. for (i = 0; i < 2; i++) {
  483. int mgmt;
  484. snprintf(name_buffer, sizeof(name_buffer),
  485. "mix%d", i);
  486. alias_prop = fdt_getprop(initial_boot_params, aliases,
  487. name_buffer, NULL);
  488. if (alias_prop) {
  489. mgmt = fdt_path_offset(initial_boot_params, alias_prop);
  490. if (mgmt < 0)
  491. continue;
  492. if (i >= max_port) {
  493. pr_debug("Deleting mix%d\n", i);
  494. octeon_fdt_rm_ethernet(mgmt);
  495. fdt_nop_property(initial_boot_params, aliases,
  496. name_buffer);
  497. } else {
  498. int phy_addr = cvmx_helper_board_get_mii_address(CVMX_HELPER_BOARD_MGMT_IPD_PORT + i);
  499. octeon_fdt_set_phy(mgmt, phy_addr);
  500. octeon_fdt_set_mac_addr(mgmt, &mac_addr_base);
  501. }
  502. }
  503. }
  504. pip_path = fdt_getprop(initial_boot_params, aliases, "pip", NULL);
  505. if (pip_path) {
  506. int pip = fdt_path_offset(initial_boot_params, pip_path);
  507. if (pip >= 0)
  508. for (i = 0; i <= 4; i++)
  509. octeon_fdt_pip_iface(pip, i, &mac_addr_base);
  510. }
  511. /* I2C */
  512. if (OCTEON_IS_MODEL(OCTEON_CN52XX) ||
  513. OCTEON_IS_MODEL(OCTEON_CN63XX) ||
  514. OCTEON_IS_MODEL(OCTEON_CN68XX) ||
  515. OCTEON_IS_MODEL(OCTEON_CN56XX))
  516. max_port = 2;
  517. else
  518. max_port = 1;
  519. for (i = 0; i < 2; i++) {
  520. int i2c;
  521. snprintf(name_buffer, sizeof(name_buffer),
  522. "twsi%d", i);
  523. alias_prop = fdt_getprop(initial_boot_params, aliases,
  524. name_buffer, NULL);
  525. if (alias_prop) {
  526. i2c = fdt_path_offset(initial_boot_params, alias_prop);
  527. if (i2c < 0)
  528. continue;
  529. if (i >= max_port) {
  530. pr_debug("Deleting twsi%d\n", i);
  531. fdt_nop_node(initial_boot_params, i2c);
  532. fdt_nop_property(initial_boot_params, aliases,
  533. name_buffer);
  534. }
  535. }
  536. }
  537. /* SMI/MDIO */
  538. if (OCTEON_IS_MODEL(OCTEON_CN68XX))
  539. max_port = 4;
  540. else if (OCTEON_IS_MODEL(OCTEON_CN52XX) ||
  541. OCTEON_IS_MODEL(OCTEON_CN63XX) ||
  542. OCTEON_IS_MODEL(OCTEON_CN56XX))
  543. max_port = 2;
  544. else
  545. max_port = 1;
  546. for (i = 0; i < 2; i++) {
  547. int i2c;
  548. snprintf(name_buffer, sizeof(name_buffer),
  549. "smi%d", i);
  550. alias_prop = fdt_getprop(initial_boot_params, aliases,
  551. name_buffer, NULL);
  552. if (alias_prop) {
  553. i2c = fdt_path_offset(initial_boot_params, alias_prop);
  554. if (i2c < 0)
  555. continue;
  556. if (i >= max_port) {
  557. pr_debug("Deleting smi%d\n", i);
  558. fdt_nop_node(initial_boot_params, i2c);
  559. fdt_nop_property(initial_boot_params, aliases,
  560. name_buffer);
  561. }
  562. }
  563. }
  564. /* Serial */
  565. uart_mask = 3;
  566. /* Right now CN52XX is the only chip with a third uart */
  567. if (OCTEON_IS_MODEL(OCTEON_CN52XX))
  568. uart_mask |= 4; /* uart2 */
  569. for (i = 0; i < 3; i++) {
  570. int uart;
  571. snprintf(name_buffer, sizeof(name_buffer),
  572. "uart%d", i);
  573. alias_prop = fdt_getprop(initial_boot_params, aliases,
  574. name_buffer, NULL);
  575. if (alias_prop) {
  576. uart = fdt_path_offset(initial_boot_params, alias_prop);
  577. if (uart_mask & (1 << i))
  578. continue;
  579. pr_debug("Deleting uart%d\n", i);
  580. fdt_nop_node(initial_boot_params, uart);
  581. fdt_nop_property(initial_boot_params, aliases,
  582. name_buffer);
  583. }
  584. }
  585. /* Compact Flash */
  586. alias_prop = fdt_getprop(initial_boot_params, aliases,
  587. "cf0", NULL);
  588. if (alias_prop) {
  589. union cvmx_mio_boot_reg_cfgx mio_boot_reg_cfg;
  590. unsigned long base_ptr, region_base, region_size;
  591. unsigned long region1_base = 0;
  592. unsigned long region1_size = 0;
  593. int cs, bootbus;
  594. bool is_16bit = false;
  595. bool is_true_ide = false;
  596. __be32 new_reg[6];
  597. __be32 *ranges;
  598. int len;
  599. int cf = fdt_path_offset(initial_boot_params, alias_prop);
  600. base_ptr = 0;
  601. if (octeon_bootinfo->major_version == 1
  602. && octeon_bootinfo->minor_version >= 1) {
  603. if (octeon_bootinfo->compact_flash_common_base_addr)
  604. base_ptr = octeon_bootinfo->compact_flash_common_base_addr;
  605. } else {
  606. base_ptr = 0x1d000800;
  607. }
  608. if (!base_ptr)
  609. goto no_cf;
  610. /* Find CS0 region. */
  611. for (cs = 0; cs < 8; cs++) {
  612. mio_boot_reg_cfg.u64 = cvmx_read_csr(CVMX_MIO_BOOT_REG_CFGX(cs));
  613. region_base = mio_boot_reg_cfg.s.base << 16;
  614. region_size = (mio_boot_reg_cfg.s.size + 1) << 16;
  615. if (mio_boot_reg_cfg.s.en && base_ptr >= region_base
  616. && base_ptr < region_base + region_size) {
  617. is_16bit = mio_boot_reg_cfg.s.width;
  618. break;
  619. }
  620. }
  621. if (cs >= 7) {
  622. /* cs and cs + 1 are CS0 and CS1, both must be less than 8. */
  623. goto no_cf;
  624. }
  625. if (!(base_ptr & 0xfffful)) {
  626. /*
  627. * Boot loader signals availability of DMA (true_ide
  628. * mode) by setting low order bits of base_ptr to
  629. * zero.
  630. */
  631. /* Asume that CS1 immediately follows. */
  632. mio_boot_reg_cfg.u64 =
  633. cvmx_read_csr(CVMX_MIO_BOOT_REG_CFGX(cs + 1));
  634. region1_base = mio_boot_reg_cfg.s.base << 16;
  635. region1_size = (mio_boot_reg_cfg.s.size + 1) << 16;
  636. if (!mio_boot_reg_cfg.s.en)
  637. goto no_cf;
  638. is_true_ide = true;
  639. } else {
  640. fdt_nop_property(initial_boot_params, cf, "cavium,true-ide");
  641. fdt_nop_property(initial_boot_params, cf, "cavium,dma-engine-handle");
  642. if (!is_16bit) {
  643. __be32 width = cpu_to_be32(8);
  644. fdt_setprop_inplace(initial_boot_params, cf,
  645. "cavium,bus-width", &width, sizeof(width));
  646. }
  647. }
  648. new_reg[0] = cpu_to_be32(cs);
  649. new_reg[1] = cpu_to_be32(0);
  650. new_reg[2] = cpu_to_be32(0x10000);
  651. new_reg[3] = cpu_to_be32(cs + 1);
  652. new_reg[4] = cpu_to_be32(0);
  653. new_reg[5] = cpu_to_be32(0x10000);
  654. fdt_setprop_inplace(initial_boot_params, cf,
  655. "reg", new_reg, sizeof(new_reg));
  656. bootbus = fdt_parent_offset(initial_boot_params, cf);
  657. if (bootbus < 0)
  658. goto no_cf;
  659. ranges = fdt_getprop_w(initial_boot_params, bootbus, "ranges", &len);
  660. if (!ranges || len < (5 * 8 * sizeof(__be32)))
  661. goto no_cf;
  662. ranges[(cs * 5) + 2] = cpu_to_be32(region_base >> 32);
  663. ranges[(cs * 5) + 3] = cpu_to_be32(region_base & 0xffffffff);
  664. ranges[(cs * 5) + 4] = cpu_to_be32(region_size);
  665. if (is_true_ide) {
  666. cs++;
  667. ranges[(cs * 5) + 2] = cpu_to_be32(region1_base >> 32);
  668. ranges[(cs * 5) + 3] = cpu_to_be32(region1_base & 0xffffffff);
  669. ranges[(cs * 5) + 4] = cpu_to_be32(region1_size);
  670. }
  671. goto end_cf;
  672. no_cf:
  673. fdt_nop_node(initial_boot_params, cf);
  674. end_cf:
  675. ;
  676. }
  677. /* 8 char LED */
  678. alias_prop = fdt_getprop(initial_boot_params, aliases,
  679. "led0", NULL);
  680. if (alias_prop) {
  681. union cvmx_mio_boot_reg_cfgx mio_boot_reg_cfg;
  682. unsigned long base_ptr, region_base, region_size;
  683. int cs, bootbus;
  684. __be32 new_reg[6];
  685. __be32 *ranges;
  686. int len;
  687. int led = fdt_path_offset(initial_boot_params, alias_prop);
  688. base_ptr = octeon_bootinfo->led_display_base_addr;
  689. if (base_ptr == 0)
  690. goto no_led;
  691. /* Find CS0 region. */
  692. for (cs = 0; cs < 8; cs++) {
  693. mio_boot_reg_cfg.u64 = cvmx_read_csr(CVMX_MIO_BOOT_REG_CFGX(cs));
  694. region_base = mio_boot_reg_cfg.s.base << 16;
  695. region_size = (mio_boot_reg_cfg.s.size + 1) << 16;
  696. if (mio_boot_reg_cfg.s.en && base_ptr >= region_base
  697. && base_ptr < region_base + region_size)
  698. break;
  699. }
  700. if (cs > 7)
  701. goto no_led;
  702. new_reg[0] = cpu_to_be32(cs);
  703. new_reg[1] = cpu_to_be32(0x20);
  704. new_reg[2] = cpu_to_be32(0x20);
  705. new_reg[3] = cpu_to_be32(cs);
  706. new_reg[4] = cpu_to_be32(0);
  707. new_reg[5] = cpu_to_be32(0x20);
  708. fdt_setprop_inplace(initial_boot_params, led,
  709. "reg", new_reg, sizeof(new_reg));
  710. bootbus = fdt_parent_offset(initial_boot_params, led);
  711. if (bootbus < 0)
  712. goto no_led;
  713. ranges = fdt_getprop_w(initial_boot_params, bootbus, "ranges", &len);
  714. if (!ranges || len < (5 * 8 * sizeof(__be32)))
  715. goto no_led;
  716. ranges[(cs * 5) + 2] = cpu_to_be32(region_base >> 32);
  717. ranges[(cs * 5) + 3] = cpu_to_be32(region_base & 0xffffffff);
  718. ranges[(cs * 5) + 4] = cpu_to_be32(region_size);
  719. goto end_led;
  720. no_led:
  721. fdt_nop_node(initial_boot_params, led);
  722. end_led:
  723. ;
  724. }
  725. /* OHCI/UHCI USB */
  726. alias_prop = fdt_getprop(initial_boot_params, aliases,
  727. "uctl", NULL);
  728. if (alias_prop) {
  729. int uctl = fdt_path_offset(initial_boot_params, alias_prop);
  730. if (uctl >= 0 && (!OCTEON_IS_MODEL(OCTEON_CN6XXX) ||
  731. octeon_bootinfo->board_type == CVMX_BOARD_TYPE_NIC2E)) {
  732. pr_debug("Deleting uctl\n");
  733. fdt_nop_node(initial_boot_params, uctl);
  734. fdt_nop_property(initial_boot_params, aliases, "uctl");
  735. } else if (octeon_bootinfo->board_type == CVMX_BOARD_TYPE_NIC10E ||
  736. octeon_bootinfo->board_type == CVMX_BOARD_TYPE_NIC4E) {
  737. /* Missing "refclk-type" defaults to crystal. */
  738. fdt_nop_property(initial_boot_params, uctl, "refclk-type");
  739. }
  740. }
  741. return 0;
  742. }
  743. static int __init octeon_publish_devices(void)
  744. {
  745. return of_platform_bus_probe(NULL, octeon_ids, NULL);
  746. }
  747. device_initcall(octeon_publish_devices);
  748. MODULE_AUTHOR("David Daney <ddaney@caviumnetworks.com>");
  749. MODULE_LICENSE("GPL");
  750. MODULE_DESCRIPTION("Platform driver for Octeon SOC");