Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Jorge Ramirez-Ortiz | 9f2d1b2 | 2018-01-10 11:33:50 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Board init file for Dragonboard 820C |
| 4 | * |
Jorge Ramirez-Ortiz | c8833d3 | 2018-01-10 11:33:52 +0100 | [diff] [blame] | 5 | * (C) Copyright 2017 Jorge Ramirez-Ortiz <jorge.ramirez-ortiz@linaro.org> |
Jorge Ramirez-Ortiz | 9f2d1b2 | 2018-01-10 11:33:50 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
Caleb Connolly | 89a90d0 | 2023-12-05 13:46:48 +0000 | [diff] [blame] | 8 | #include <button.h> |
Simon Glass | afb0215 | 2019-12-28 10:45:01 -0700 | [diff] [blame] | 9 | #include <cpu_func.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 10 | #include <init.h> |
Simon Glass | 5e6201b | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 11 | #include <env.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 12 | #include <asm/cache.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 13 | #include <asm/global_data.h> |
Jorge Ramirez-Ortiz | 9f2d1b2 | 2018-01-10 11:33:50 +0100 | [diff] [blame] | 14 | #include <linux/arm-smccc.h> |
| 15 | #include <linux/psci.h> |
Jorge Ramirez-Ortiz | 9f2d1b2 | 2018-01-10 11:33:50 +0100 | [diff] [blame] | 16 | #include <dm.h> |
| 17 | #include <asm/io.h> |
| 18 | #include <linux/bitops.h> |
| 19 | #include <asm/psci.h> |
Jorge Ramirez-Ortiz | c8833d3 | 2018-01-10 11:33:52 +0100 | [diff] [blame] | 20 | #include <asm/gpio.h> |
Jorge Ramirez-Ortiz | 9f2d1b2 | 2018-01-10 11:33:50 +0100 | [diff] [blame] | 21 | |
Caleb Connolly | 10a0abb | 2023-11-07 12:41:03 +0000 | [diff] [blame] | 22 | #define TLMM_BASE_ADDR (0x1010000) |
| 23 | |
| 24 | /* Strength (sdc1) */ |
| 25 | #define SDC1_HDRV_PULL_CTL_REG (TLMM_BASE_ADDR + 0x0012D000) |
| 26 | |
Jorge Ramirez-Ortiz | 9f2d1b2 | 2018-01-10 11:33:50 +0100 | [diff] [blame] | 27 | DECLARE_GLOBAL_DATA_PTR; |
| 28 | |
Jorge Ramirez-Ortiz | 9f2d1b2 | 2018-01-10 11:33:50 +0100 | [diff] [blame] | 29 | static void sdhci_power_init(void) |
| 30 | { |
| 31 | const u32 TLMM_PULL_MASK = 0x3; |
| 32 | const u32 TLMM_HDRV_MASK = 0x7; |
| 33 | |
| 34 | struct tlmm_cfg { |
| 35 | u32 bit; /* bit in the register */ |
| 36 | u8 mask; /* mask clk/dat/cmd control */ |
| 37 | u8 val; |
| 38 | }; |
| 39 | |
| 40 | /* bit offsets in the sdc tlmm register */ |
| 41 | enum { SDC1_DATA_HDRV = 0, |
| 42 | SDC1_CMD_HDRV = 3, |
| 43 | SDC1_CLK_HDRV = 6, |
| 44 | SDC1_DATA_PULL = 9, |
| 45 | SDC1_CMD_PULL = 11, |
| 46 | SDC1_CLK_PULL = 13, |
| 47 | SDC1_RCLK_PULL = 15, |
| 48 | }; |
| 49 | |
| 50 | enum { TLMM_PULL_DOWN = 0x1, |
| 51 | TLMM_PULL_UP = 0x3, |
| 52 | TLMM_NO_PULL = 0x0, |
| 53 | }; |
| 54 | |
| 55 | enum { TLMM_CUR_VAL_10MA = 0x04, |
| 56 | TLMM_CUR_VAL_16MA = 0x07, |
| 57 | }; |
| 58 | int i; |
| 59 | |
| 60 | /* drive strength configs for sdhc pins */ |
| 61 | const struct tlmm_cfg hdrv[] = { |
Wolfgang Denk | 9d328a6 | 2021-09-27 17:42:38 +0200 | [diff] [blame] | 62 | |
Jorge Ramirez-Ortiz | 9f2d1b2 | 2018-01-10 11:33:50 +0100 | [diff] [blame] | 63 | { SDC1_CLK_HDRV, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, }, |
| 64 | { SDC1_CMD_HDRV, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, }, |
| 65 | { SDC1_DATA_HDRV, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, }, |
| 66 | }; |
| 67 | |
| 68 | /* pull configs for sdhc pins */ |
| 69 | const struct tlmm_cfg pull[] = { |
Wolfgang Denk | 9d328a6 | 2021-09-27 17:42:38 +0200 | [diff] [blame] | 70 | |
Jorge Ramirez-Ortiz | 9f2d1b2 | 2018-01-10 11:33:50 +0100 | [diff] [blame] | 71 | { SDC1_CLK_PULL, TLMM_NO_PULL, TLMM_PULL_MASK, }, |
| 72 | { SDC1_CMD_PULL, TLMM_PULL_UP, TLMM_PULL_MASK, }, |
| 73 | { SDC1_DATA_PULL, TLMM_PULL_UP, TLMM_PULL_MASK, }, |
| 74 | }; |
| 75 | |
| 76 | const struct tlmm_cfg rclk[] = { |
Wolfgang Denk | 9d328a6 | 2021-09-27 17:42:38 +0200 | [diff] [blame] | 77 | |
Jorge Ramirez-Ortiz | 9f2d1b2 | 2018-01-10 11:33:50 +0100 | [diff] [blame] | 78 | { SDC1_RCLK_PULL, TLMM_PULL_DOWN, TLMM_PULL_MASK,}, |
| 79 | }; |
| 80 | |
| 81 | for (i = 0; i < ARRAY_SIZE(hdrv); i++) |
| 82 | clrsetbits_le32(SDC1_HDRV_PULL_CTL_REG, |
| 83 | hdrv[i].mask << hdrv[i].bit, |
| 84 | hdrv[i].val << hdrv[i].bit); |
| 85 | |
| 86 | for (i = 0; i < ARRAY_SIZE(pull); i++) |
| 87 | clrsetbits_le32(SDC1_HDRV_PULL_CTL_REG, |
| 88 | pull[i].mask << pull[i].bit, |
| 89 | pull[i].val << pull[i].bit); |
| 90 | |
| 91 | for (i = 0; i < ARRAY_SIZE(rclk); i++) |
| 92 | clrsetbits_le32(SDC1_HDRV_PULL_CTL_REG, |
| 93 | rclk[i].mask << rclk[i].bit, |
| 94 | rclk[i].val << rclk[i].bit); |
| 95 | } |
| 96 | |
Caleb Connolly | fe1694c | 2024-02-26 17:26:24 +0000 | [diff] [blame] | 97 | void qcom_board_init(void) |
Jorge Ramirez-Ortiz | 9f2d1b2 | 2018-01-10 11:33:50 +0100 | [diff] [blame] | 98 | { |
| 99 | sdhci_power_init(); |
Jorge Ramirez-Ortiz | c8833d3 | 2018-01-10 11:33:52 +0100 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | /* Check for vol- button - if pressed - stop autoboot */ |
| 103 | int misc_init_r(void) |
| 104 | { |
Caleb Connolly | 89a90d0 | 2023-12-05 13:46:48 +0000 | [diff] [blame] | 105 | struct udevice *btn; |
| 106 | int ret; |
| 107 | enum button_state_t state; |
Jorge Ramirez-Ortiz | c8833d3 | 2018-01-10 11:33:52 +0100 | [diff] [blame] | 108 | |
Caleb Connolly | 89a90d0 | 2023-12-05 13:46:48 +0000 | [diff] [blame] | 109 | ret = button_get_by_label("pwrkey", &btn); |
Jorge Ramirez-Ortiz | c8833d3 | 2018-01-10 11:33:52 +0100 | [diff] [blame] | 110 | if (ret < 0) { |
Caleb Connolly | 89a90d0 | 2023-12-05 13:46:48 +0000 | [diff] [blame] | 111 | printf("Couldn't find power button!\n"); |
| 112 | return ret; |
Jorge Ramirez-Ortiz | c8833d3 | 2018-01-10 11:33:52 +0100 | [diff] [blame] | 113 | } |
| 114 | |
Caleb Connolly | 89a90d0 | 2023-12-05 13:46:48 +0000 | [diff] [blame] | 115 | state = button_get_state(btn); |
| 116 | if (state == BUTTON_ON) { |
Jorge Ramirez-Ortiz | c8833d3 | 2018-01-10 11:33:52 +0100 | [diff] [blame] | 117 | env_set("bootdelay", "-1"); |
| 118 | printf("Power button pressed - dropping to console.\n"); |
| 119 | } |
| 120 | |
| 121 | return 0; |
| 122 | } |