sniper.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * LG Optimus Black codename sniper board
  4. *
  5. * Copyright (C) 2015 Paul Kocialkowski <contact@paulk.fr>
  6. */
  7. #include <config.h>
  8. #include <common.h>
  9. #include <dm.h>
  10. #include <env.h>
  11. #include <fastboot.h>
  12. #include <init.h>
  13. #include <linux/ctype.h>
  14. #include <linux/usb/musb.h>
  15. #include <asm/omap_musb.h>
  16. #include <asm/arch/mmc_host_def.h>
  17. #include <asm/arch/sys_proto.h>
  18. #include <asm/arch/mem.h>
  19. #include <asm/io.h>
  20. #include <ns16550.h>
  21. #include <twl4030.h>
  22. #include "sniper.h"
  23. DECLARE_GLOBAL_DATA_PTR;
  24. const omap3_sysinfo sysinfo = {
  25. .mtype = DDR_STACKED,
  26. .board_string = "sniper",
  27. .nand_string = "MMC"
  28. };
  29. static const struct ns16550_plat serial_omap_plat = {
  30. .base = OMAP34XX_UART3,
  31. .reg_shift = 2,
  32. .clock = V_NS16550_CLK,
  33. .fcr = UART_FCR_DEFVAL,
  34. };
  35. U_BOOT_DEVICE(sniper_serial) = {
  36. .name = "ns16550_serial",
  37. .plat = &serial_omap_plat
  38. };
  39. static struct musb_hdrc_config musb_config = {
  40. .multipoint = 1,
  41. .dyn_fifo = 1,
  42. .num_eps = 16,
  43. .ram_bits = 12
  44. };
  45. static struct omap_musb_board_data musb_board_data = {
  46. .interface_type = MUSB_INTERFACE_ULPI,
  47. };
  48. static struct musb_hdrc_platform_data musb_platform_data = {
  49. .mode = MUSB_PERIPHERAL,
  50. .config = &musb_config,
  51. .power = 100,
  52. .platform_ops = &omap2430_ops,
  53. .board_data = &musb_board_data,
  54. };
  55. void set_muxconf_regs(void)
  56. {
  57. MUX_SNIPER();
  58. }
  59. #ifdef CONFIG_SPL_BUILD
  60. void get_board_mem_timings(struct board_sdrc_timings *timings)
  61. {
  62. timings->mcfg = HYNIX_V_MCFG_200(256 << 20);
  63. timings->ctrla = HYNIX_V_ACTIMA_200;
  64. timings->ctrlb = HYNIX_V_ACTIMB_200;
  65. timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_200MHz;
  66. timings->mr = MICRON_V_MR_165;
  67. }
  68. #endif
  69. int board_init(void)
  70. {
  71. /* GPMC init */
  72. gpmc_init();
  73. /* MACH number */
  74. gd->bd->bi_arch_number = 3000;
  75. /* ATAGs location */
  76. gd->bd->bi_boot_params = OMAP34XX_SDRC_CS0 + 0x100;
  77. return 0;
  78. }
  79. int misc_init_r(void)
  80. {
  81. unsigned char keypad_matrix[64] = { 0 };
  82. char reboot_mode[2] = { 0 };
  83. unsigned char keys[3];
  84. unsigned char data = 0;
  85. int rc;
  86. /* Power button reset init */
  87. twl4030_power_reset_init();
  88. /* Keypad */
  89. twl4030_keypad_scan((unsigned char *)&keypad_matrix);
  90. keys[0] = twl4030_keypad_key((unsigned char *)&keypad_matrix, 0, 0);
  91. keys[1] = twl4030_keypad_key((unsigned char *)&keypad_matrix, 0, 1);
  92. keys[2] = twl4030_keypad_key((unsigned char *)&keypad_matrix, 0, 2);
  93. /* Reboot mode */
  94. rc = omap_reboot_mode(reboot_mode, sizeof(reboot_mode));
  95. if (keys[0])
  96. reboot_mode[0] = 'r';
  97. else if (keys[1])
  98. reboot_mode[0] = 'b';
  99. if (rc < 0 || reboot_mode[0] == 'o') {
  100. /*
  101. * When not rebooting, valid power on reasons are either the
  102. * power button, charger plug or USB plug.
  103. */
  104. data |= twl4030_input_power_button();
  105. data |= twl4030_input_charger();
  106. data |= twl4030_input_usb();
  107. if (!data)
  108. twl4030_power_off();
  109. }
  110. if (reboot_mode[0] > 0 && isascii(reboot_mode[0])) {
  111. if (!env_get("reboot-mode"))
  112. env_set("reboot-mode", (char *)reboot_mode);
  113. }
  114. omap_reboot_mode_clear();
  115. /* Serial number */
  116. omap_die_id_serial();
  117. /* MUSB */
  118. musb_register(&musb_platform_data, &musb_board_data, (void *)MUSB_BASE);
  119. return 0;
  120. }
  121. u32 get_board_rev(void)
  122. {
  123. /* Sold devices are expected to be at least revision F. */
  124. return 6;
  125. }
  126. void get_board_serial(struct tag_serialnr *serialnr)
  127. {
  128. omap_die_id_get_board_serial(serialnr);
  129. }
  130. void reset_misc(void)
  131. {
  132. char reboot_mode[2] = { 0 };
  133. /*
  134. * Valid resets must contain the reboot mode magic, but we must not
  135. * override it when set previously (e.g. reboot to bootloader).
  136. */
  137. omap_reboot_mode(reboot_mode, sizeof(reboot_mode));
  138. omap_reboot_mode_store(reboot_mode);
  139. }
  140. int fastboot_set_reboot_flag(enum fastboot_reboot_reason reason)
  141. {
  142. if (reason != FASTBOOT_REBOOT_REASON_BOOTLOADER)
  143. return -ENOTSUPP;
  144. return omap_reboot_mode_store("b");
  145. }
  146. int board_mmc_init(struct bd_info *bis)
  147. {
  148. return omap_mmc_init(1, 0, 0, -1, -1);
  149. }
  150. void board_mmc_power_init(void)
  151. {
  152. twl4030_power_mmc_init(1);
  153. }