blob: 3cdc1bb8254c6764c453fb978f748aae6d8f526a [file] [log] [blame]
Mike Rapoportf2a44392010-09-27 11:26:34 +02001/*
2 * arch/arm/mach-tegra/board-harmony-pcie.c
3 *
4 * Copyright (C) 2010 CompuLab, Ltd.
5 * Mike Rapoport <mike@compulab.co.il>
6 *
7 * This software is licensed under the terms of the GNU General Public
8 * License version 2, as published by the Free Software Foundation, and
9 * may be copied, distributed, and modified under those terms.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 */
17
18#include <linux/kernel.h>
19#include <linux/gpio.h>
20#include <linux/err.h>
Laxman Dewangan3cc404d2012-08-16 20:59:59 +000021#include <linux/of_gpio.h>
Mike Rapoportf2a44392010-09-27 11:26:34 +020022#include <linux/regulator/consumer.h>
23
24#include <asm/mach-types.h>
25
Mike Rapoportf2a44392010-09-27 11:26:34 +020026#include "board.h"
27
28#ifdef CONFIG_TEGRA_PCI
29
Stephen Warrena12c0ef2012-05-02 15:47:12 -060030int __init harmony_pcie_init(void)
Mike Rapoportf2a44392010-09-27 11:26:34 +020031{
Laxman Dewangan3cc404d2012-08-16 20:59:59 +000032 struct device_node *np;
33 int en_vdd_1v05;
Mike Rapoportce005cf2011-03-09 16:31:17 +020034 struct regulator *regulator = NULL;
Mike Rapoportf2a44392010-09-27 11:26:34 +020035 int err;
36
Laxman Dewangan3cc404d2012-08-16 20:59:59 +000037 np = of_find_node_by_path("/regulators/regulator@3");
38 if (!np) {
39 pr_err("%s: of_find_node_by_path failed\n", __func__);
40 return -ENODEV;
41 }
42
43 en_vdd_1v05 = of_get_named_gpio(np, "gpio", 0);
44 if (en_vdd_1v05 < 0) {
45 pr_err("%s: of_get_named_gpio failed: %d\n", __func__,
46 en_vdd_1v05);
47 return en_vdd_1v05;
48 }
49
50 err = gpio_request(en_vdd_1v05, "EN_VDD_1V05");
51 if (err) {
52 pr_err("%s: gpio_request failed: %d\n", __func__, err);
Mike Rapoportce005cf2011-03-09 16:31:17 +020053 return err;
Laxman Dewangan3cc404d2012-08-16 20:59:59 +000054 }
Mike Rapoportce005cf2011-03-09 16:31:17 +020055
Laxman Dewangan3cc404d2012-08-16 20:59:59 +000056 gpio_direction_output(en_vdd_1v05, 1);
Mike Rapoportce005cf2011-03-09 16:31:17 +020057
Laxman Dewangan3cc404d2012-08-16 20:59:59 +000058 regulator = regulator_get(NULL, "vdd_ldo0,vddio_pex_clk");
59 if (IS_ERR_OR_NULL(regulator)) {
60 pr_err("%s: regulator_get failed: %d\n", __func__,
61 (int)PTR_ERR(regulator));
Mike Rapoportce005cf2011-03-09 16:31:17 +020062 goto err_reg;
Laxman Dewangan3cc404d2012-08-16 20:59:59 +000063 }
Mike Rapoportce005cf2011-03-09 16:31:17 +020064
65 regulator_enable(regulator);
66
Mike Rapoportf2a44392010-09-27 11:26:34 +020067 err = tegra_pcie_init(true, true);
Laxman Dewangan3cc404d2012-08-16 20:59:59 +000068 if (err) {
69 pr_err("%s: tegra_pcie_init failed: %d\n", __func__, err);
Mike Rapoportf2a44392010-09-27 11:26:34 +020070 goto err_pcie;
Laxman Dewangan3cc404d2012-08-16 20:59:59 +000071 }
Mike Rapoportf2a44392010-09-27 11:26:34 +020072
73 return 0;
74
75err_pcie:
Mike Rapoportce005cf2011-03-09 16:31:17 +020076 regulator_disable(regulator);
77 regulator_put(regulator);
78err_reg:
Laxman Dewangan3cc404d2012-08-16 20:59:59 +000079 gpio_free(en_vdd_1v05);
Mike Rapoportce005cf2011-03-09 16:31:17 +020080
Mike Rapoportf2a44392010-09-27 11:26:34 +020081 return err;
82}
83
Mike Rapoportf2a44392010-09-27 11:26:34 +020084#endif