octeon-platform.c 24 KB

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