1 /*
2  * (C) Copyright 2014
3  * NVIDIA Corporation <www.nvidia.com>
4  *
5  * SPDX-License-Identifier:     GPL-2.0+
6  */
7 
8 #include <common.h>
9 #include <dm.h>
10 #include <power/as3722.h>
11 #include <power/pmic.h>
12 
13 #include <asm/arch/gpio.h>
14 #include <asm/arch/pinmux.h>
15 
16 #include "pinmux-config-jetson-tk1.h"
17 
18 DECLARE_GLOBAL_DATA_PTR;
19 
20 /*
21  * Routine: pinmux_init
22  * Description: Do individual peripheral pinmux configs
23  */
24 void pinmux_init(void)
25 {
26 	pinmux_clear_tristate_input_clamping();
27 
28 	gpio_config_table(jetson_tk1_gpio_inits,
29 			  ARRAY_SIZE(jetson_tk1_gpio_inits));
30 
31 	pinmux_config_pingrp_table(jetson_tk1_pingrps,
32 				   ARRAY_SIZE(jetson_tk1_pingrps));
33 
34 	pinmux_config_drvgrp_table(jetson_tk1_drvgrps,
35 				   ARRAY_SIZE(jetson_tk1_drvgrps));
36 
37 	pinmux_config_mipipadctrlgrp_table(jetson_tk1_mipipadctrlgrps,
38 					ARRAY_SIZE(jetson_tk1_mipipadctrlgrps));
39 }
40 
41 #ifdef CONFIG_PCI_TEGRA
42 /* TODO: Convert to driver model */
43 static int as3722_sd_enable(struct udevice *pmic, unsigned int sd)
44 {
45 	int err;
46 
47 	if (sd > 6)
48 		return -EINVAL;
49 
50 	err = pmic_clrsetbits(pmic, AS3722_SD_CONTROL, 0, 1 << sd);
51 	if (err) {
52 		pr_err("failed to update SD control register: %d", err);
53 		return err;
54 	}
55 
56 	return 0;
57 }
58 
59 int tegra_pcie_board_init(void)
60 {
61 	struct udevice *dev;
62 	int ret;
63 
64 	ret = uclass_get_device_by_driver(UCLASS_PMIC,
65 					  DM_GET_DRIVER(pmic_as3722), &dev);
66 	if (ret) {
67 		debug("%s: Failed to find PMIC\n", __func__);
68 		return ret;
69 	}
70 
71 	ret = as3722_sd_enable(dev, 4);
72 	if (ret < 0) {
73 		pr_err("failed to enable SD4: %d\n", ret);
74 		return ret;
75 	}
76 
77 	ret = as3722_sd_set_voltage(dev, 4, 0x24);
78 	if (ret < 0) {
79 		pr_err("failed to set SD4 voltage: %d\n", ret);
80 		return ret;
81 	}
82 
83 	return 0;
84 }
85 #endif /* PCI */
86