Deepa Dinamani | 7dc3d4b | 2013-02-08 16:40:38 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2013, The Linux Foundation. All rights reserved. |
| 2 | * |
| 3 | * Redistribution and use in source and binary forms, with or without |
| 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. |
| 15 | * |
| 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. |
| 27 | */ |
| 28 | |
| 29 | #include <debug.h> |
| 30 | #include <platform/iomap.h> |
| 31 | #include <reg.h> |
| 32 | #include <target.h> |
| 33 | #include <platform.h> |
| 34 | #include <uart_dm.h> |
| 35 | #include <mmc.h> |
Deepa Dinamani | 8ff46f0 | 2013-03-20 17:52:14 -0700 | [diff] [blame] | 36 | #include <platform/gpio.h> |
Deepa Dinamani | 7dc3d4b | 2013-02-08 16:40:38 -0800 | [diff] [blame] | 37 | #include <spmi.h> |
| 38 | #include <board.h> |
Deepa Dinamani | 41803e0 | 2013-03-25 11:44:15 -0700 | [diff] [blame] | 39 | #include <smem.h> |
| 40 | #include <baseband.h> |
Deepa Dinamani | 8ff46f0 | 2013-03-20 17:52:14 -0700 | [diff] [blame] | 41 | #include <dev/keys.h> |
| 42 | #include <pm8x41.h> |
Deepa Dinamani | 7dc3d4b | 2013-02-08 16:40:38 -0800 | [diff] [blame] | 43 | |
| 44 | #define PMIC_ARB_CHANNEL_NUM 0 |
| 45 | #define PMIC_ARB_OWNER_ID 0 |
| 46 | |
Deepa Dinamani | 8ff46f0 | 2013-03-20 17:52:14 -0700 | [diff] [blame] | 47 | #define TLMM_VOL_UP_BTN_GPIO 72 |
| 48 | |
Deepa Dinamani | 7dc3d4b | 2013-02-08 16:40:38 -0800 | [diff] [blame] | 49 | static uint32_t mmc_sdc_base[] = |
| 50 | { MSM_SDC1_BASE, MSM_SDC2_BASE }; |
| 51 | |
| 52 | void target_early_init(void) |
| 53 | { |
| 54 | #if WITH_DEBUG_UART |
Deepa Dinamani | d1823b4 | 2013-03-21 11:49:35 -0700 | [diff] [blame] | 55 | uart_dm_init(2, 0, BLSP1_UART1_BASE); |
Deepa Dinamani | 7dc3d4b | 2013-02-08 16:40:38 -0800 | [diff] [blame] | 56 | #endif |
| 57 | } |
| 58 | |
Deepa Dinamani | 8ff46f0 | 2013-03-20 17:52:14 -0700 | [diff] [blame] | 59 | /* Return 1 if vol_up pressed */ |
| 60 | static int target_volume_up() |
| 61 | { |
| 62 | uint8_t status = 0; |
| 63 | |
| 64 | gpio_tlmm_config(TLMM_VOL_UP_BTN_GPIO, 0, GPIO_INPUT, GPIO_PULL_UP, GPIO_2MA, GPIO_ENABLE); |
| 65 | |
| 66 | /* Get status of GPIO */ |
| 67 | status = gpio_status(TLMM_VOL_UP_BTN_GPIO); |
| 68 | |
| 69 | /* Active low signal. */ |
| 70 | return !status; |
| 71 | } |
| 72 | |
| 73 | /* Return 1 if vol_down pressed */ |
| 74 | uint32_t target_volume_down() |
| 75 | { |
| 76 | /* Volume down button tied in with PMIC RESIN. */ |
| 77 | return pm8x41_resin_status(); |
| 78 | } |
| 79 | |
Deepa Dinamani | 7dc3d4b | 2013-02-08 16:40:38 -0800 | [diff] [blame] | 80 | static void target_keystatus() |
| 81 | { |
Deepa Dinamani | 8ff46f0 | 2013-03-20 17:52:14 -0700 | [diff] [blame] | 82 | keys_init(); |
| 83 | |
| 84 | if(target_volume_down()) |
| 85 | keys_post_event(KEY_VOLUMEDOWN, 1); |
| 86 | |
| 87 | if(target_volume_up()) |
| 88 | keys_post_event(KEY_VOLUMEUP, 1); |
Deepa Dinamani | 7dc3d4b | 2013-02-08 16:40:38 -0800 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | void target_init(void) |
| 92 | { |
| 93 | uint32_t base_addr; |
| 94 | uint8_t slot; |
| 95 | |
| 96 | dprintf(INFO, "target_init()\n"); |
| 97 | |
| 98 | spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID); |
| 99 | |
Deepa Dinamani | 8ff46f0 | 2013-03-20 17:52:14 -0700 | [diff] [blame] | 100 | target_keystatus(); |
| 101 | |
Deepa Dinamani | 7dc3d4b | 2013-02-08 16:40:38 -0800 | [diff] [blame] | 102 | /* Trying Slot 1*/ |
| 103 | slot = 1; |
| 104 | base_addr = mmc_sdc_base[slot - 1]; |
| 105 | |
| 106 | if (mmc_boot_main(slot, base_addr)) |
| 107 | { |
| 108 | /* Trying Slot 2 next */ |
| 109 | slot = 2; |
| 110 | base_addr = mmc_sdc_base[slot - 1]; |
| 111 | |
| 112 | if (mmc_boot_main(slot, base_addr)) |
| 113 | { |
| 114 | dprintf(CRITICAL, "mmc init failed!"); |
| 115 | ASSERT(0); |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | |
Deepa Dinamani | 2b795bb | 2013-03-25 11:31:58 -0700 | [diff] [blame] | 120 | /* Do any target specific intialization needed before entering fastboot mode */ |
| 121 | void target_fastboot_init(void) |
| 122 | { |
| 123 | /* Set the BOOT_DONE flag in PM8110 */ |
| 124 | pm8x41_set_boot_done(); |
| 125 | } |
| 126 | |
Deepa Dinamani | 41803e0 | 2013-03-25 11:44:15 -0700 | [diff] [blame] | 127 | /* Detect the target type */ |
| 128 | void target_detect(struct board_data *board) |
| 129 | { |
| 130 | board->target = LINUX_MACHTYPE_UNKNOWN; |
| 131 | } |
| 132 | |
| 133 | /* Detect the modem type */ |
| 134 | void target_baseband_detect(struct board_data *board) |
| 135 | { |
| 136 | uint32_t platform; |
| 137 | uint32_t platform_subtype; |
| 138 | |
| 139 | platform = board->platform; |
| 140 | platform_subtype = board->platform_subtype; |
| 141 | |
| 142 | /* |
| 143 | * Look for platform subtype if present, else |
| 144 | * check for platform type to decide on the |
| 145 | * baseband type |
| 146 | */ |
| 147 | switch(platform_subtype) |
| 148 | { |
| 149 | case HW_PLATFORM_SUBTYPE_UNKNOWN: |
| 150 | break; |
| 151 | default: |
| 152 | dprintf(CRITICAL, "Platform Subtype : %u is not supported\n", platform_subtype); |
| 153 | ASSERT(0); |
| 154 | }; |
| 155 | |
| 156 | switch(platform) |
| 157 | { |
| 158 | case MSM8610: |
| 159 | case MSM8110: |
| 160 | case MSM8210: |
| 161 | case MSM8810: |
| 162 | board->baseband = BASEBAND_MSM; |
| 163 | break; |
| 164 | default: |
| 165 | dprintf(CRITICAL, "Platform type: %u is not supported\n", platform); |
| 166 | ASSERT(0); |
| 167 | }; |
| 168 | } |
| 169 | |
| 170 | unsigned target_baseband() |
| 171 | { |
| 172 | return board_baseband(); |
| 173 | } |
| 174 | |
Deepa Dinamani | a6d1b75 | 2013-03-25 11:47:20 -0700 | [diff] [blame] | 175 | void target_serialno(unsigned char *buf) |
| 176 | { |
| 177 | uint32_t serialno; |
| 178 | if (target_is_emmc_boot()) { |
| 179 | serialno = mmc_get_psn(); |
| 180 | snprintf((char *)buf, 13, "%x", serialno); |
| 181 | } |
| 182 | } |
| 183 | |
Deepa Dinamani | 5390e10 | 2013-03-25 11:55:31 -0700 | [diff] [blame^] | 184 | unsigned check_reboot_mode(void) |
| 185 | { |
| 186 | uint32_t restart_reason = 0; |
| 187 | |
| 188 | /* Read reboot reason and scrub it */ |
| 189 | restart_reason = readl(RESTART_REASON_ADDR); |
| 190 | writel(0x00, RESTART_REASON_ADDR); |
| 191 | |
| 192 | return restart_reason; |
| 193 | } |
| 194 | |
Deepa Dinamani | 7dc3d4b | 2013-02-08 16:40:38 -0800 | [diff] [blame] | 195 | unsigned board_machtype(void) |
| 196 | { |
Deepa Dinamani | 2b795bb | 2013-03-25 11:31:58 -0700 | [diff] [blame] | 197 | return 0; |
Deepa Dinamani | 7dc3d4b | 2013-02-08 16:40:38 -0800 | [diff] [blame] | 198 | } |