Kevin: Add support audio path with max98357a
[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/i2s/rockchip.h"
25 #include "drivers/bus/spi/rockchip.h"
26 #include "drivers/ec/cros/spi.h"
27 #include "drivers/flash/spi.h"
28 #include "drivers/flash/spi.h"
29 #include "drivers/gpio/rockchip.h"
30 #include "drivers/gpio/sysinfo.h"
31 #include "drivers/sound/i2s.h"
32 #include "drivers/sound/max98357a.h"
33 #include "drivers/sound/route.h"
34 #include "drivers/storage/dw_mmc.h"
35 #include "drivers/storage/rk_dwmmc.h"
36 #include "drivers/storage/sdhci.h"
37 #include "vboot/util/flag.h"
38
39 static const int emmc_sd_clock_min = 400 * 1000;
40 static const int emmc_clock_max = 200 * 1000 * 1000;
41
42 static int board_setup(void)
43 {
44         // Claim that we have an open lid to satisfy vboot.
45         flag_replace(FLAG_LIDSW, new_gpio_high());
46
47         // Claim that we have an power key to satisfy vboot.
48         flag_replace(FLAG_PWRSW, new_gpio_low());
49
50         RkSpi *spi1 = new_rockchip_spi(0xff1d0000);
51
52         flash_set_ops(&new_spi_flash(&spi1->ops)->ops);
53
54         // EC on Kevin is connected to SPI bus #5
55         RkSpi *spi5 = new_rockchip_spi(0xff200000);
56         CrosEcSpiBus *cros_ec_spi_bus = new_cros_ec_spi_bus(&spi5->ops);
57         GpioOps *ec_int = sysinfo_lookup_gpio("EC interrupt", 1,
58                                               new_rk_gpio_input_from_coreboot);
59         CrosEc *cros_ec = new_cros_ec(&cros_ec_spi_bus->ops, 0, ec_int);
60         register_vboot_ec(&cros_ec->vboot, 0);
61
62
63         SdhciHost *emmc = new_mem_sdhci_host((void *)0xfe330000,
64                                              SDHCI_PLATFORM_NO_EMMC_HS200 |
65                                              SDHCI_PLATFORM_NO_CLK_BASE,
66                                              emmc_sd_clock_min,
67                                              emmc_clock_max, 198);
68
69         list_insert_after(&emmc->mmc_ctrlr.ctrlr.list_node,
70                           &fixed_block_dev_controllers);
71
72         RockchipI2s *i2s0 = new_rockchip_i2s(0xff880000, 16, 2, 256);
73         I2sSource *i2s_source = new_i2s_source(&i2s0->ops, 48000, 2, 16000);
74         SoundRoute *sound_route = new_sound_route(&i2s_source->ops);
75
76         /* Speaker Amp codec MAX98357A */
77         GpioOps *sdmode_gpio = &new_rk_gpio_output(GPIO(1, A, 2))->ops;
78
79         max98357aCodec *speaker_amp =
80                 new_max98357a_codec(sdmode_gpio);
81
82         list_insert_after(&speaker_amp->component.list_node,
83                           &sound_route->components);
84
85         sound_set_ops(&sound_route->ops);
86
87         RkGpio *card_detect;
88
89          /* SDMMC_DET_L is different on different board revisions. */
90         switch (lib_sysinfo.board_id) {
91         case 0:  /* This is for Kevin rev1. */
92                 card_detect = new_rk_gpio_input(GPIO(4, D, 2));
93                 break;
94         default:
95                 card_detect = new_rk_gpio_input(GPIO(4, D, 0));
96                 break;
97         }
98
99         GpioOps *card_detect_ops = &card_detect->ops;
100
101         card_detect_ops = new_gpio_not(card_detect_ops);
102
103         DwmciHost *sd_card = new_rkdwmci_host(0xfe320000, 594000000, 4, 1,
104                                               card_detect_ops);
105
106         list_insert_after(&sd_card->mmc.ctrlr.list_node,
107                           &removable_block_dev_controllers);
108
109         return 0;
110 }
111
112 INIT_FUNC(board_setup);