849cf81f35c9dbc85f6d8d2b9f85df66626008dd
[depthcharge.git] / src / board / kevin / board.c
1 /*
2  * Copyright 2016 Rockchip Inc.
3  *
4  * See file CREDITS for list of people who contributed to this
5  * project.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2 of
10  * the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but without any warranty; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  */
17
18 #include <assert.h>
19 #include <libpayload.h>
20
21 #include "base/init_funcs.h"
22 #include "boot/fit.h"
23 #include "config.h"
24 #include "drivers/bus/spi/rockchip.h"
25 #include "drivers/ec/cros/spi.h"
26 #include "drivers/flash/spi.h"
27 #include "drivers/flash/spi.h"
28 #include "drivers/gpio/rockchip.h"
29 #include "drivers/gpio/sysinfo.h"
30 #include "drivers/storage/dw_mmc.h"
31 #include "drivers/storage/rk_dwmmc.h"
32 #include "drivers/storage/sdhci.h"
33 #include "vboot/util/flag.h"
34
35 static const int emmc_sd_clock_min = 400 * 1000;
36 static const int emmc_clock_max = 200 * 1000 * 1000;
37
38 static int board_setup(void)
39 {
40         // Claim that we have an open lid to satisfy vboot.
41         flag_replace(FLAG_LIDSW, new_gpio_high());
42
43         // Claim that we have an power key to satisfy vboot.
44         flag_replace(FLAG_PWRSW, new_gpio_low());
45
46         RkSpi *spi1 = new_rockchip_spi(0xff1d0000);
47
48         flash_set_ops(&new_spi_flash(&spi1->ops)->ops);
49
50         // EC on Kevin is connected to SPI bus #5
51         RkSpi *spi5 = new_rockchip_spi(0xff200000);
52         CrosEcSpiBus *cros_ec_spi_bus = new_cros_ec_spi_bus(&spi5->ops);
53         GpioOps *ec_int = sysinfo_lookup_gpio("EC interrupt", 1,
54                                               new_rk_gpio_input_from_coreboot);
55         CrosEc *cros_ec = new_cros_ec(&cros_ec_spi_bus->ops, 0, ec_int);
56         register_vboot_ec(&cros_ec->vboot, 0);
57
58
59         SdhciHost *emmc = new_mem_sdhci_host((void *)0xfe330000,
60                                              SDHCI_PLATFORM_NO_EMMC_HS200 |
61                                              SDHCI_PLATFORM_NO_CLK_BASE,
62                                              emmc_sd_clock_min,
63                                              emmc_clock_max, 198);
64
65         list_insert_after(&emmc->mmc_ctrlr.ctrlr.list_node,
66                           &fixed_block_dev_controllers);
67
68         RkGpio *card_detect;
69
70          /* SDMMC_DET_L is different on different board revisions. */
71         switch (lib_sysinfo.board_id) {
72         case 0:  /* This is for Kevin rev1. */
73                 card_detect = new_rk_gpio_input(GPIO(4, D, 2));
74                 break;
75         default:
76                 card_detect = new_rk_gpio_input(GPIO(4, D, 0));
77                 break;
78         }
79
80         GpioOps *card_detect_ops = &card_detect->ops;
81
82         card_detect_ops = new_gpio_not(card_detect_ops);
83
84         DwmciHost *sd_card = new_rkdwmci_host(0xfe320000, 594000000, 4, 1,
85                                               card_detect_ops);
86
87         list_insert_after(&sd_card->mmc.ctrlr.list_node,
88                           &removable_block_dev_controllers);
89
90         return 0;
91 }
92
93 INIT_FUNC(board_setup);