blob: 71c71ed6ec231e26e6bd5bf597013ca1f0adb98b [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Allen Martina6c7b462014-12-04 06:36:30 -07002/*
3 * (C) Copyright 2014
4 * NVIDIA Corporation <www.nvidia.com>
Allen Martina6c7b462014-12-04 06:36:30 -07005 */
6
7#include <common.h>
Simon Glasse3f44f52017-07-25 08:30:12 -06008#include <dm.h>
Simon Glass0deba292015-04-14 21:03:29 -06009#include <errno.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060010#include <log.h>
Simon Glass0deba292015-04-14 21:03:29 -060011#include <asm/gpio.h>
Simon Glass7cfde812015-06-05 14:39:43 -060012#include <asm/io.h>
Allen Martina6c7b462014-12-04 06:36:30 -070013#include <asm/arch/pinmux.h>
Simon Glass7cfde812015-06-05 14:39:43 -060014#include <asm/arch/clock.h>
15#include <asm/arch/mc.h>
16#include <asm/arch-tegra/clk_rst.h>
17#include <asm/arch-tegra/pmc.h>
Simon Glassc05ed002020-05-10 11:40:11 -060018#include <linux/delay.h>
Simon Glass0deba292015-04-14 21:03:29 -060019#include <power/as3722.h>
20#include <power/pmic.h>
Allen Martina6c7b462014-12-04 06:36:30 -070021#include "pinmux-config-nyan-big.h"
22
23/*
24 * Routine: pinmux_init
25 * Description: Do individual peripheral pinmux configs
26 */
27void pinmux_init(void)
28{
29 gpio_config_table(nyan_big_gpio_inits,
30 ARRAY_SIZE(nyan_big_gpio_inits));
31
32 pinmux_config_pingrp_table(nyan_big_pingrps,
33 ARRAY_SIZE(nyan_big_pingrps));
34
35 pinmux_config_drvgrp_table(nyan_big_drvgrps,
36 ARRAY_SIZE(nyan_big_drvgrps));
37}
Simon Glass0deba292015-04-14 21:03:29 -060038
39int tegra_board_id(void)
40{
Stephen Warren01a97a12016-05-12 12:07:39 -060041 static const int vector[] = {TEGRA_GPIO(Q, 3), TEGRA_GPIO(T, 1),
42 TEGRA_GPIO(X, 1), TEGRA_GPIO(X, 4),
43 -1};
Simon Glass0deba292015-04-14 21:03:29 -060044
45 gpio_claim_vector(vector, "board_id%d");
46 return gpio_get_values_as_int(vector);
47}
48
49int tegra_lcd_pmic_init(int board_id)
50{
Simon Glasse3f44f52017-07-25 08:30:12 -060051 struct udevice *dev;
Simon Glass0deba292015-04-14 21:03:29 -060052 int ret;
53
Simon Glasse3f44f52017-07-25 08:30:12 -060054 ret = uclass_get_device_by_driver(UCLASS_PMIC,
55 DM_GET_DRIVER(pmic_as3722), &dev);
56 if (ret) {
57 debug("%s: Failed to find PMIC\n", __func__);
58 return ret;
59 }
Simon Glass0deba292015-04-14 21:03:29 -060060
61 if (board_id == 0)
Simon Glasse3f44f52017-07-25 08:30:12 -060062 pmic_reg_write(dev, 0x00, 0x3c);
Simon Glass0deba292015-04-14 21:03:29 -060063 else
Simon Glasse3f44f52017-07-25 08:30:12 -060064 pmic_reg_write(dev, 0x00, 0x50);
65 pmic_reg_write(dev, 0x12, 0x10);
66 pmic_reg_write(dev, 0x0c, 0x07);
67 pmic_reg_write(dev, 0x20, 0x10);
Simon Glass0deba292015-04-14 21:03:29 -060068
69 return 0;
70}
Simon Glass7cfde812015-06-05 14:39:43 -060071
72/* Setup required information for Linux kernel */
73static void setup_kernel_info(void)
74{
75 struct mc_ctlr *mc = (void *)NV_PA_MC_BASE;
76
77 /* The kernel graphics driver needs this region locked down */
78 writel(0, &mc->mc_video_protect_bom);
79 writel(0, &mc->mc_video_protect_size_mb);
80 writel(1, &mc->mc_video_protect_reg_ctrl);
81}
82
83/*
84 * We need to take ALL audio devices conntected to AHUB (AUDIO, APBIF,
85 * I2S, DAM, AMX, ADX, SPDIF, AFC) out of reset and enable the clocks.
86 * Otherwise reading AHUB devices will hang when the kernel boots.
87 */
88static void enable_required_clocks(void)
89{
90 static enum periph_id ids[] = {
91 PERIPH_ID_I2S0,
92 PERIPH_ID_I2S1,
93 PERIPH_ID_I2S2,
94 PERIPH_ID_I2S3,
95 PERIPH_ID_I2S4,
96 PERIPH_ID_AUDIO,
97 PERIPH_ID_APBIF,
98 PERIPH_ID_DAM0,
99 PERIPH_ID_DAM1,
100 PERIPH_ID_DAM2,
101 PERIPH_ID_AMX0,
102 PERIPH_ID_AMX1,
103 PERIPH_ID_ADX0,
104 PERIPH_ID_ADX1,
105 PERIPH_ID_SPDIF,
106 PERIPH_ID_AFC0,
107 PERIPH_ID_AFC1,
108 PERIPH_ID_AFC2,
109 PERIPH_ID_AFC3,
110 PERIPH_ID_AFC4,
111 PERIPH_ID_AFC5,
112 PERIPH_ID_EXTPERIPH1
113 };
114 int i;
115
116 for (i = 0; i < ARRAY_SIZE(ids); i++)
117 clock_enable(ids[i]);
118 udelay(2);
119 for (i = 0; i < ARRAY_SIZE(ids); i++)
120 reset_set_enable(ids[i], 0);
121}
122
123int nvidia_board_init(void)
124{
125 clock_start_periph_pll(PERIPH_ID_EXTPERIPH1, CLOCK_ID_OSC, 12000000);
Simon Glassf6ac3fa2019-04-01 13:38:38 -0700126 clock_start_periph_pll(PERIPH_ID_I2S1, CLOCK_ID_CLK_M, 1500000);
Simon Glass7cfde812015-06-05 14:39:43 -0600127
128 /* For external MAX98090 audio codec */
129 clock_external_output(1);
130 setup_kernel_info();
131 enable_required_clocks();
132
133 return 0;
134}