board-ocelot.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // SPDX-License-Identifier: (GPL-2.0 OR MIT)
  2. /*
  3. * Microsemi MIPS SoC support
  4. *
  5. * Copyright (c) 2017 Microsemi Corporation
  6. */
  7. #include <linux/string.h>
  8. #include <asm/machine.h>
  9. #include <asm/prom.h>
  10. #define DEVCPU_GCB_CHIP_REGS_CHIP_ID 0x71070000
  11. #define CHIP_ID_PART_ID GENMASK(27, 12)
  12. #define OCELOT_PART_ID (0x7514 << 12)
  13. #define UART_UART 0x70100000
  14. static __init bool ocelot_detect(void)
  15. {
  16. u32 rev;
  17. int idx;
  18. /* Look for the TLB entry set up by redboot before trying to use it */
  19. write_c0_entryhi(DEVCPU_GCB_CHIP_REGS_CHIP_ID);
  20. mtc0_tlbw_hazard();
  21. tlb_probe();
  22. tlb_probe_hazard();
  23. idx = read_c0_index();
  24. if (idx < 0)
  25. return false;
  26. /* A TLB entry exists, lets assume its usable and check the CHIP ID */
  27. rev = __raw_readl((void __iomem *)DEVCPU_GCB_CHIP_REGS_CHIP_ID);
  28. if ((rev & CHIP_ID_PART_ID) != OCELOT_PART_ID)
  29. return false;
  30. /* Copy command line from bootloader early for Initrd detection */
  31. if (fw_arg0 < 10 && (fw_arg1 & 0xFFF00000) == 0x80000000) {
  32. unsigned int prom_argc = fw_arg0;
  33. const char **prom_argv = (const char **)fw_arg1;
  34. if (prom_argc > 1 && strlen(prom_argv[1]) > 0)
  35. /* ignore all built-in args if any f/w args given */
  36. strscpy(arcs_cmdline, prom_argv[1]);
  37. }
  38. return true;
  39. }
  40. static void __init ocelot_earlyprintk_init(void)
  41. {
  42. void __iomem *uart_base;
  43. uart_base = ioremap(UART_UART, 0x20);
  44. setup_8250_early_printk_port((unsigned long)uart_base, 2, 50000);
  45. }
  46. static void __init ocelot_late_init(void)
  47. {
  48. ocelot_earlyprintk_init();
  49. }
  50. static __init const void *ocelot_fixup_fdt(const void *fdt,
  51. const void *match_data)
  52. {
  53. /* This has to be done so late because ioremap needs to work */
  54. late_time_init = ocelot_late_init;
  55. return fdt;
  56. }
  57. extern char __dtb_ocelot_pcb123_begin[];
  58. MIPS_MACHINE(ocelot) = {
  59. .fdt = __dtb_ocelot_pcb123_begin,
  60. .fixup_fdt = ocelot_fixup_fdt,
  61. .detect = ocelot_detect,
  62. };