Deepa Dinamani | 1e09494 | 2012-10-30 15:49:02 -0700 | [diff] [blame^] | 1 | /* Copyright (c) 2012, The Linux Foundation. All rights reserved. |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 2 | * |
| 3 | * Redistribution and use in source and binary forms, with or without |
Deepa Dinamani | 1e09494 | 2012-10-30 15:49:02 -0700 | [diff] [blame^] | 4 | * modification, are permitted provided that the following conditions are |
| 5 | * met: |
| 6 | * * Redistributions of source code must retain the above copyright |
| 7 | * notice, this list of conditions and the following disclaimer. |
| 8 | * * Redistributions in binary form must reproduce the above |
| 9 | * copyright notice, this list of conditions and the following |
| 10 | * disclaimer in the documentation and/or other materials provided |
| 11 | * with the distribution. |
| 12 | * * Neither the name of The Linux Foundation nor the names of its |
| 13 | * contributors may be used to endorse or promote products derived |
| 14 | * from this software without specific prior written permission. |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 15 | * |
Deepa Dinamani | 1e09494 | 2012-10-30 15:49:02 -0700 | [diff] [blame^] | 16 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 23 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 25 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 26 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 27 | */ |
| 28 | |
| 29 | #include <debug.h> |
| 30 | #include <platform/iomap.h> |
| 31 | #include <reg.h> |
| 32 | #include <target.h> |
| 33 | #include <platform.h> |
Deepa Dinamani | 26e9326 | 2012-05-21 17:35:14 -0700 | [diff] [blame] | 34 | #include <uart_dm.h> |
Amol Jadi | 29f9503 | 2012-06-22 12:52:54 -0700 | [diff] [blame] | 35 | #include <mmc.h> |
Deepa Dinamani | c2a9b36 | 2012-02-23 15:15:54 -0800 | [diff] [blame] | 36 | #include <spmi.h> |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 37 | #include <board.h> |
| 38 | #include <smem.h> |
| 39 | #include <baseband.h> |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 40 | #include <dev/keys.h> |
| 41 | #include <pm8x41.h> |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 42 | |
| 43 | static unsigned int target_id; |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 44 | |
Deepa Dinamani | c2a9b36 | 2012-02-23 15:15:54 -0800 | [diff] [blame] | 45 | #define PMIC_ARB_CHANNEL_NUM 0 |
| 46 | #define PMIC_ARB_OWNER_ID 0 |
| 47 | |
Deepa Dinamani | 1e09494 | 2012-10-30 15:49:02 -0700 | [diff] [blame^] | 48 | #define WDOG_DEBUG_DISABLE_BIT 17 |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 49 | |
Deepa Dinamani | ca5ad85 | 2012-05-07 18:19:47 -0700 | [diff] [blame] | 50 | static uint32_t mmc_sdc_base[] = |
| 51 | { MSM_SDC1_BASE, MSM_SDC2_BASE, MSM_SDC3_BASE, MSM_SDC4_BASE }; |
| 52 | |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 53 | void target_early_init(void) |
| 54 | { |
Deepa Dinamani | b073ba2 | 2012-08-10 11:06:41 -0700 | [diff] [blame] | 55 | #if WITH_DEBUG_UART |
Neeti Desai | ac01127 | 2012-08-29 18:24:54 -0700 | [diff] [blame] | 56 | uart_dm_init(1, 0, BLSP1_UART1_BASE); |
Deepa Dinamani | b073ba2 | 2012-08-10 11:06:41 -0700 | [diff] [blame] | 57 | #endif |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 58 | } |
| 59 | |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 60 | /* Return 1 if vol_up pressed */ |
| 61 | static int target_volume_up() |
| 62 | { |
| 63 | uint8_t status = 0; |
| 64 | struct pm8x41_gpio gpio; |
| 65 | |
| 66 | /* CDP vol_up seems to be always grounded. So gpio status is read as 0, |
| 67 | * whether key is pressed or not. |
| 68 | * Ignore volume_up key on CDP for now. |
| 69 | */ |
| 70 | if (board_hardware_id() == HW_PLATFORM_SURF) |
| 71 | return 0; |
| 72 | |
| 73 | /* Configure the GPIO */ |
| 74 | gpio.direction = PM_GPIO_DIR_IN; |
| 75 | gpio.function = 0; |
| 76 | gpio.pull = PM_GPIO_PULL_UP_30; |
| 77 | gpio.vin_sel = 0; |
| 78 | |
| 79 | pm8x41_gpio_config(5, &gpio); |
| 80 | |
| 81 | /* Get status of P_GPIO_5 */ |
| 82 | pm8x41_gpio_get(5, &status); |
| 83 | |
| 84 | return !status; /* active low */ |
| 85 | } |
| 86 | |
| 87 | /* Return 1 if vol_down pressed */ |
| 88 | int target_volume_down() |
| 89 | { |
| 90 | return pm8x41_vol_down_key_status(); |
| 91 | } |
| 92 | |
| 93 | static void target_keystatus() |
| 94 | { |
| 95 | keys_init(); |
| 96 | |
| 97 | if(target_volume_down()) |
| 98 | keys_post_event(KEY_VOLUMEDOWN, 1); |
| 99 | |
| 100 | if(target_volume_up()) |
| 101 | keys_post_event(KEY_VOLUMEUP, 1); |
| 102 | } |
| 103 | |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 104 | void target_init(void) |
| 105 | { |
Deepa Dinamani | ca5ad85 | 2012-05-07 18:19:47 -0700 | [diff] [blame] | 106 | uint32_t base_addr; |
| 107 | uint8_t slot; |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 108 | |
Deepa Dinamani | 26e9326 | 2012-05-21 17:35:14 -0700 | [diff] [blame] | 109 | |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 110 | dprintf(INFO, "target_init()\n"); |
| 111 | |
Deepa Dinamani | c2a9b36 | 2012-02-23 15:15:54 -0800 | [diff] [blame] | 112 | spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID); |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 113 | |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 114 | target_keystatus(); |
| 115 | |
Deepa Dinamani | ca5ad85 | 2012-05-07 18:19:47 -0700 | [diff] [blame] | 116 | /* Trying Slot 1*/ |
| 117 | slot = 1; |
| 118 | base_addr = mmc_sdc_base[slot - 1]; |
| 119 | if (mmc_boot_main(slot, base_addr)) |
| 120 | { |
Deepa Dinamani | d18b47a | 2012-06-27 13:06:03 -0700 | [diff] [blame] | 121 | |
| 122 | /* Trying Slot 2 next */ |
| 123 | slot = 2; |
| 124 | base_addr = mmc_sdc_base[slot - 1]; |
| 125 | if (mmc_boot_main(slot, base_addr)) { |
| 126 | dprintf(CRITICAL, "mmc init failed!"); |
| 127 | ASSERT(0); |
| 128 | } |
Deepa Dinamani | ca5ad85 | 2012-05-07 18:19:47 -0700 | [diff] [blame] | 129 | } |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | unsigned board_machtype(void) |
| 133 | { |
| 134 | return target_id; |
| 135 | } |
| 136 | |
| 137 | /* Do any target specific intialization needed before entering fastboot mode */ |
| 138 | void target_fastboot_init(void) |
| 139 | { |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 140 | /* Set the BOOT_DONE flag in PM8921 */ |
| 141 | pm8x41_set_boot_done(); |
Deepa Dinamani | 7d6c897 | 2011-12-14 15:16:56 -0800 | [diff] [blame] | 142 | } |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 143 | |
| 144 | /* Detect the target type */ |
| 145 | void target_detect(struct board_data *board) |
| 146 | { |
| 147 | board->target = LINUX_MACHTYPE_UNKNOWN; |
| 148 | } |
| 149 | |
| 150 | /* Detect the modem type */ |
| 151 | void target_baseband_detect(struct board_data *board) |
| 152 | { |
| 153 | /* Check for baseband variants. Default to MSM */ |
| 154 | if (board->platform_subtype == HW_PLATFORM_SUBTYPE_MDM) |
| 155 | board->baseband = BASEBAND_MDM; |
| 156 | else |
| 157 | board->baseband = BASEBAND_MSM; |
| 158 | } |
Deepa Dinamani | 9a61293 | 2012-08-14 16:15:03 -0700 | [diff] [blame] | 159 | |
| 160 | void target_serialno(unsigned char *buf) |
| 161 | { |
| 162 | unsigned int serialno; |
| 163 | if (target_is_emmc_boot()) { |
| 164 | serialno = mmc_get_psn(); |
| 165 | snprintf((char *)buf, 13, "%x", serialno); |
| 166 | } |
| 167 | } |
Amol Jadi | 6639d45 | 2012-08-16 14:51:19 -0700 | [diff] [blame] | 168 | |
| 169 | unsigned check_reboot_mode(void) |
| 170 | { |
| 171 | uint32_t restart_reason = 0; |
| 172 | |
| 173 | /* Read reboot reason and scrub it */ |
| 174 | restart_reason = readl(RESTART_REASON_ADDR); |
| 175 | writel(0x00, RESTART_REASON_ADDR); |
| 176 | |
| 177 | return restart_reason; |
| 178 | } |
Neeti Desai | 120b55d | 2012-08-20 17:15:56 -0700 | [diff] [blame] | 179 | |
| 180 | void reboot_device(unsigned reboot_reason) |
| 181 | { |
| 182 | /* Write the reboot reason */ |
| 183 | writel(reboot_reason, RESTART_REASON_ADDR); |
| 184 | |
| 185 | /* Configure PMIC for warm reset */ |
| 186 | pm8x41_reset_configure(PON_PSHOLD_WARM_RESET); |
| 187 | |
Deepa Dinamani | 1e09494 | 2012-10-30 15:49:02 -0700 | [diff] [blame^] | 188 | /* Disable Watchdog Debug. |
| 189 | * Required becuase of a H/W bug which causes the system to |
| 190 | * reset partially even for non watchdog resets. |
| 191 | */ |
| 192 | writel(readl(GCC_WDOG_DEBUG) & ~(1 << WDOG_DEBUG_DISABLE_BIT), GCC_WDOG_DEBUG); |
| 193 | |
Neeti Desai | 120b55d | 2012-08-20 17:15:56 -0700 | [diff] [blame] | 194 | /* Drop PS_HOLD for MSM */ |
| 195 | writel(0x00, MPM2_MPM_PS_HOLD); |
| 196 | |
| 197 | mdelay(5000); |
| 198 | |
| 199 | dprintf(CRITICAL, "Rebooting failed\n"); |
| 200 | } |