blob: d3333a59db01caa940224a99df6b43a3375cacf8 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Jorge Ramirez-Ortiz9f2d1b22018-01-10 11:33:50 +01002/*
3 * Board init file for Dragonboard 820C
4 *
Jorge Ramirez-Ortizc8833d32018-01-10 11:33:52 +01005 * (C) Copyright 2017 Jorge Ramirez-Ortiz <jorge.ramirez-ortiz@linaro.org>
Jorge Ramirez-Ortiz9f2d1b22018-01-10 11:33:50 +01006 */
7
Caleb Connolly89a90d02023-12-05 13:46:48 +00008#include <button.h>
Simon Glassafb02152019-12-28 10:45:01 -07009#include <cpu_func.h>
Simon Glass97589732020-05-10 11:40:02 -060010#include <init.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060011#include <env.h>
Simon Glass274e0b02020-05-10 11:39:56 -060012#include <asm/cache.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060013#include <asm/global_data.h>
Jorge Ramirez-Ortiz9f2d1b22018-01-10 11:33:50 +010014#include <linux/arm-smccc.h>
15#include <linux/psci.h>
Jorge Ramirez-Ortiz9f2d1b22018-01-10 11:33:50 +010016#include <dm.h>
17#include <asm/io.h>
18#include <linux/bitops.h>
19#include <asm/psci.h>
Jorge Ramirez-Ortizc8833d32018-01-10 11:33:52 +010020#include <asm/gpio.h>
Jorge Ramirez-Ortiz9f2d1b22018-01-10 11:33:50 +010021
Caleb Connolly10a0abb2023-11-07 12:41:03 +000022#define TLMM_BASE_ADDR (0x1010000)
23
24/* Strength (sdc1) */
25#define SDC1_HDRV_PULL_CTL_REG (TLMM_BASE_ADDR + 0x0012D000)
26
Jorge Ramirez-Ortiz9f2d1b22018-01-10 11:33:50 +010027DECLARE_GLOBAL_DATA_PTR;
28
Jorge Ramirez-Ortiz9f2d1b22018-01-10 11:33:50 +010029static 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 Denk9d328a62021-09-27 17:42:38 +020062
Jorge Ramirez-Ortiz9f2d1b22018-01-10 11:33:50 +010063 { 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 Denk9d328a62021-09-27 17:42:38 +020070
Jorge Ramirez-Ortiz9f2d1b22018-01-10 11:33:50 +010071 { 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 Denk9d328a62021-09-27 17:42:38 +020077
Jorge Ramirez-Ortiz9f2d1b22018-01-10 11:33:50 +010078 { 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 Connollyfe1694c2024-02-26 17:26:24 +000097void qcom_board_init(void)
Jorge Ramirez-Ortiz9f2d1b22018-01-10 11:33:50 +010098{
99 sdhci_power_init();
Jorge Ramirez-Ortizc8833d32018-01-10 11:33:52 +0100100}
101
102/* Check for vol- button - if pressed - stop autoboot */
103int misc_init_r(void)
104{
Caleb Connolly89a90d02023-12-05 13:46:48 +0000105 struct udevice *btn;
106 int ret;
107 enum button_state_t state;
Jorge Ramirez-Ortizc8833d32018-01-10 11:33:52 +0100108
Caleb Connolly89a90d02023-12-05 13:46:48 +0000109 ret = button_get_by_label("pwrkey", &btn);
Jorge Ramirez-Ortizc8833d32018-01-10 11:33:52 +0100110 if (ret < 0) {
Caleb Connolly89a90d02023-12-05 13:46:48 +0000111 printf("Couldn't find power button!\n");
112 return ret;
Jorge Ramirez-Ortizc8833d32018-01-10 11:33:52 +0100113 }
114
Caleb Connolly89a90d02023-12-05 13:46:48 +0000115 state = button_get_state(btn);
116 if (state == BUTTON_ON) {
Jorge Ramirez-Ortizc8833d32018-01-10 11:33:52 +0100117 env_set("bootdelay", "-1");
118 printf("Power button pressed - dropping to console.\n");
119 }
120
121 return 0;
122}