Patrick Georgi (pgeorgi(a)google.com) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/16712
-gerrit
commit 91cdcba9bed9d54ff6652c76741a40197b3fbcb0
Author: Simon Glass <sjg(a)chromium.org>
Date: Mon Sep 5 11:10:26 2016 -0600
rockchip: spi: Add support for 16-bit APB reads
With a SPI clock above about 24MHz the APB cannot keep up when doing
individual byte transfers. Adjust the driver to use 16-bit reads when
it can, to remove this bottleneck.
Any transaction which involves writing bytes still uses 8-bit transfers,
to simplify the code. These are the transfers that are not time-critical
since they tend to be small. The case that really matters is reading from
SPI flash.
In general we can use 16-bit reads anytime we are transferring an even
number of bytes. If the code detects an odd number of bytes, it tries to
perform the operation in two steps: once in 16-bit mode with an even
number of bytes, and once in 8-bit mode for the final byte. This allow
us to use 16-bit reads even if asked to transfer (for example) 0xf423
bytes.
The limit on in_now and out_now is adjusted to 0xfffe to avoid an extra
transfer when transferring ~>=64KB.
CQ-DEPEND=CL:383232
BUG=chrome-os-partner:56556
BRANCH=none
TEST=boot on gru and see that things still work correctly. I tested (with
extra debugging) that the 16-bit case is being picked when it should be.
Change-Id: If5effae9a84e4de06537fd594bedf7f01d6a9c88
Signed-off-by: Patrick Georgi <pgeorgi(a)chromium.org>
Original-Commit-Id: ec250b4931c7d99cc014e32ab597fca948299d08
Original-Change-Id: Idc5b7e5d82cdbdc1e8fe8b2d6da819edf2d5570c
Original-Signed-off-by: Simon Glass <sjg(a)chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/381312
Original-Commit-Ready: Julius Werner <jwerner(a)chromium.org>
Original-Tested-by: Julius Werner <jwerner(a)chromium.org>
Original-Reviewed-by: Julius Werner <jwerner(a)chromium.org>
---
src/soc/rockchip/common/spi.c | 53 ++++++++++++++++++++++++++++++++-----------
1 file changed, 40 insertions(+), 13 deletions(-)
diff --git a/src/soc/rockchip/common/spi.c b/src/soc/rockchip/common/spi.c
index 7dcaaad..57e9ca1 100644
--- a/src/soc/rockchip/common/spi.c
+++ b/src/soc/rockchip/common/spi.c
@@ -149,9 +149,6 @@ void rockchip_spi_init(unsigned int bus, unsigned int speed_hz)
/* First Bit Mode */
ctrlr0 |= (SPI_FBM_MSB << SPI_FBM_OFFSET);
- /* Byte and Halfword Transform */
- ctrlr0 |= (SPI_APB_8BIT << SPI_HALF_WORLD_TX_OFFSET);
-
/* Frame Format */
ctrlr0 |= (SPI_FRF_SPI << SPI_FRF_OFFSET);
@@ -220,7 +217,7 @@ static void set_transfer_mode(struct rockchip_spi *regs,
}
/* returns 0 to indicate success, <0 otherwise */
-static int do_xfer(struct rockchip_spi *regs, const void *dout,
+static int do_xfer(struct rockchip_spi *regs, bool use_16bit, const void *dout,
unsigned int *bytes_out, void *din, unsigned int *bytes_in)
{
uint8_t *in_buf = din;
@@ -251,12 +248,23 @@ static int do_xfer(struct rockchip_spi *regs, const void *dout,
* sychronizing with the SPI clock which is pretty slow.
*/
if (*bytes_in && !(sr & SR_RF_EMPT)) {
- int todo = read32(®s->rxflr) & RXFLR_LEVEL_MASK;
-
- *bytes_in -= todo;
- xferred = todo;
- while (todo-- > 0)
- *in_buf++ = read32(®s->rxdr) & 0xff;
+ int fifo = read32(®s->rxflr) & RXFLR_LEVEL_MASK;
+ int val;
+
+ if (use_16bit)
+ xferred = fifo * 2;
+ else
+ xferred = fifo;
+ *bytes_in -= xferred;
+ while (fifo-- > 0) {
+ val = read32(®s->rxdr);
+ if (use_16bit) {
+ *in_buf++ = val & 0xff;
+ *in_buf++ = (val >> 8) & 0xff;
+ } else {
+ *in_buf++ = val & 0xff;
+ }
+ }
}
min_xfer -= xferred;
@@ -290,12 +298,31 @@ int spi_xfer(struct spi_slave *slave, const void *dout,
* seems to work fine.
*/
while (bytes_out || bytes_in) {
- unsigned int in_now = MIN(bytes_in, 0xffff);
- unsigned int out_now = MIN(bytes_out, 0xffff);
+ unsigned int in_now = MIN(bytes_in, 0xfffe);
+ unsigned int out_now = MIN(bytes_out, 0xfffe);
unsigned int in_rem, out_rem;
+ unsigned int mask;
+ bool use_16bit;
rockchip_spi_enable_chip(regs, 0);
+ /*
+ * Use 16-bit transfers for higher-speed reads. If we are
+ * transferring an odd number of bytes, try to make it even.
+ */
+ use_16bit = false;
+ if (bytes_out == 0) {
+ if ((in_now & 1) && in_now > 1)
+ in_now--;
+ if (!(in_now & 1))
+ use_16bit = true;
+ }
+ mask = SPI_APB_8BIT << SPI_HALF_WORLD_TX_OFFSET;
+ if (use_16bit)
+ clrbits_le32(®s->ctrlr0, mask);
+ else
+ setbits_le32(®s->ctrlr0, mask);
+
/* Enable/disable transmitter and receiver as needed to
* avoid sending or reading spurious bits. */
set_transfer_mode(regs, bytes_out, bytes_in);
@@ -307,7 +334,7 @@ int spi_xfer(struct spi_slave *slave, const void *dout,
in_rem = in_now;
out_rem = out_now;
- ret = do_xfer(regs, dout, &out_rem, din, &in_rem);
+ ret = do_xfer(regs, use_16bit, dout, &out_rem, din, &in_rem);
if (ret < 0)
break;
Patrick Georgi (pgeorgi(a)google.com) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/16708
-gerrit
commit 0f027f52bd50d0fe63b56bf514dd0feaf47ab6e7
Author: Simon Glass <sjg(a)chromium.org>
Date: Sun Sep 4 18:56:46 2016 -0600
gru: Increase SPI speed to 33MHz
Increase the SPI bus speed to speed up boot time. The maximum supported
speed at 1.8V is 37.5MHz, and 33MHz is the next lowest convenient speed,
given the clock parents.
BUG=chrome-os-partner:56556
BRANCH=none
TEST=boot on gru and see that things still work correctly. Total time
spent on reading from SPI reduces from 185ms to 141ms.
Change-Id: I71436c9e343b18360fa63d528dea5cfcfbc831e6
Signed-off-by: Patrick Georgi <pgeorgi(a)chromium.org>
Original-Commit-Id: d7576f6e53e407af61160be142c3d589e864a8cf
Original-Change-Id: I55a19f523817862e081d23469e94fd795456dd67
Original-Signed-off-by: Simon Glass <sjg(a)chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/381313
Original-Commit-Ready: Julius Werner <jwerner(a)chromium.org>
Original-Tested-by: Simon Glass <sjg(a)google.com>
Original-Reviewed-by: Julius Werner <jwerner(a)chromium.org>
---
src/mainboard/google/gru/bootblock.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/mainboard/google/gru/bootblock.c b/src/mainboard/google/gru/bootblock.c
index 6598dfe..c630b2d 100644
--- a/src/mainboard/google/gru/bootblock.c
+++ b/src/mainboard/google/gru/bootblock.c
@@ -82,7 +82,8 @@ void bootblock_mainboard_init(void)
/* Set pinmux and configure spi flashrom. */
write32(&rk3399_pmugrf->spi1_rxd, IOMUX_SPI1_RX);
write32(&rk3399_pmugrf->spi1_csclktx, IOMUX_SPI1_CSCLKTX);
- rockchip_spi_init(CONFIG_BOOT_DEVICE_SPI_FLASH_BUS, 24750*KHz);
+ rockchip_spi_init(CONFIG_BOOT_DEVICE_SPI_FLASH_BUS, 33000*KHz);
+ rockchip_spi_set_sample_delay(CONFIG_BOOT_DEVICE_SPI_FLASH_BUS, 5);
/* Set pinmux and configure EC SPI. */
write32(&rk3399_grf->iomux_spi5, IOMUX_SPI5);
Patrick Georgi (pgeorgi(a)google.com) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/16707
-gerrit
commit 84f89cdb8cdec9c43010ec72e60d900e88732960
Author: Simon Glass <sjg(a)chromium.org>
Date: Mon Sep 5 11:04:50 2016 -0600
rockchip: spi: Set rxd sample delay when using high speed
At higher SPI bus speeds the SPI RX value is not available in time for
sampling at the normal time. Add a delay to ensure that we read the
correct data.
The value of 40ns is chosen arbitrarily. In my testing I can use a sample
delay of 1 even at 24MHz. But since it is not necessary, I have left that
case alone. It kicks in at 25MHz and up.
BUG=chrome-os-partner:56556
BRANCH=none
TEST=boot on gru and see no change at current speed
Change-Id: I3ef335d9a532eaef1e76034bd02e185acf11176a
Signed-off-by: Patrick Georgi <pgeorgi(a)chromium.org>
Original-Commit-Id: e9b620c47fc3e39211487507fadb8657afdebee7
Original-Change-Id: I65d66d752cbbbee4d02f475de23a52069a0e9782
Original-Signed-off-by: Simon Glass <sjg(a)chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/381311
Original-Commit-Ready: Julius Werner <jwerner(a)chromium.org>
Original-Tested-by: Simon Glass <sjg(a)google.com>
Original-Reviewed-by: Julius Werner <jwerner(a)chromium.org>
---
src/soc/rockchip/common/include/soc/spi.h | 3 +++
src/soc/rockchip/common/spi.c | 18 ++++++++++++++----
2 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/src/soc/rockchip/common/include/soc/spi.h b/src/soc/rockchip/common/include/soc/spi.h
index dcaa471..0e1847c 100644
--- a/src/soc/rockchip/common/include/soc/spi.h
+++ b/src/soc/rockchip/common/include/soc/spi.h
@@ -199,4 +199,7 @@ check_member(rockchip_spi, rxdr, 0x800);
void rockchip_spi_init(unsigned int bus, unsigned int speed_hz);
+/* Set the receive sample delay in nanoseconds */
+void rockchip_spi_set_sample_delay(unsigned int bus, unsigned int delay_ns);
+
#endif /* ! __COREBOOT_SRC_SOC_ROCKCHIP_COMMON_INCLUDE_SOC_SPI_H */
diff --git a/src/soc/rockchip/common/spi.c b/src/soc/rockchip/common/spi.c
index f35f915..7dcaaad 100644
--- a/src/soc/rockchip/common/spi.c
+++ b/src/soc/rockchip/common/spi.c
@@ -32,7 +32,7 @@ struct rockchip_spi_slave {
};
#define SPI_TIMEOUT_US 1000
-#define SPI_SRCCLK_HZ (99*MHz)
+#define SPI_SRCCLK_HZ (198*MHz)
#define SPI_FIFO_DEPTH 32
static struct rockchip_spi_slave rockchip_spi_slaves[] = {
@@ -152,9 +152,6 @@ void rockchip_spi_init(unsigned int bus, unsigned int speed_hz)
/* Byte and Halfword Transform */
ctrlr0 |= (SPI_APB_8BIT << SPI_HALF_WORLD_TX_OFFSET);
- /* Rxd Sample Delay */
- ctrlr0 |= (0 << SPI_RXDSD_OFFSET);
-
/* Frame Format */
ctrlr0 |= (SPI_FRF_SPI << SPI_FRF_OFFSET);
@@ -165,6 +162,19 @@ void rockchip_spi_init(unsigned int bus, unsigned int speed_hz)
write32(®s->rxftlr, SPI_FIFO_DEPTH / 2 - 1);
}
+void rockchip_spi_set_sample_delay(unsigned int bus, unsigned int delay_ns)
+{
+ assert(bus >= 0 && bus < ARRAY_SIZE(rockchip_spi_slaves));
+ struct rockchip_spi *regs = rockchip_spi_slaves[bus].regs;
+ unsigned int rsd;
+
+ /* Rxd Sample Delay */
+ rsd = DIV_ROUND_CLOSEST(delay_ns * (SPI_SRCCLK_HZ >> 8), 1*GHz >> 8);
+ assert(rsd >= 0 && rsd <= 3);
+ clrsetbits_le32(®s->ctrlr0, SPI_RXDSD_MASK << SPI_RXDSD_OFFSET,
+ rsd << SPI_RXDSD_OFFSET);
+}
+
int spi_claim_bus(struct spi_slave *slave)
{
spi_cs_activate(slave);
Patrick Georgi (pgeorgi(a)google.com) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/16706
-gerrit
commit 5461404295d6283e607dd9f4073d3fe511115d73
Author: Simon Glass <sjg(a)chromium.org>
Date: Sat Aug 27 12:18:38 2016 -0600
arm64: Use 'payload' format for ATF instead of 'stage'
Switch the BL31 (ARM Trusted Firmware) format to payload so that it can
have multiple independent segments. This also requires disabling the region
check since SRAM is currently faulted by that check.
This has been tested with Rockchip's pending change:
https://chromium-review.googlesource.com/#/c/368592/3
with the patch mentioned on the bug at #13.
BUG=chrome-os-partner:56314
BRANCH=none
TEST=boot on gru and see that BL31 loads and runs. Im not sure if it is
correct though:
CBFS: Locating 'fallback/payload'
CBFS: Found @ offset 1b440 size 15a75
Loading segment from ROM address 0x0000000000100000
code (compression=1)
New segment dstaddr 0x18104800 memsize 0x117fbe0 srcaddr 0x100038 filesize 0x15a3d
Loading segment from ROM address 0x000000000010001c
Entry Point 0x0000000018104800
Loading Segment: addr: 0x0000000018104800 memsz: 0x000000000117fbe0 filesz: 0x0000000000015a3d
lb: [0x0000000000300000, 0x0000000000320558)
Post relocation: addr: 0x0000000018104800 memsz: 0x000000000117fbe0 filesz: 0x0000000000015a3d
using LZMA
[ 0x18104800, 18137d90, 0x192843e0) <- 00100038
Clearing Segment: addr: 0x0000000018137d90 memsz: 0x000000000114c650
dest 0000000018104800, end 00000000192843e0, bouncebuffer ffffffffffffffff
Loaded segments
BS: BS_PAYLOAD_LOAD times (us): entry 0 run 125150 exit 1
Jumping to boot code at 0000000018104800(00000000f7eda000)
CPU0: stack: 00000000ff8ec000 - 00000000ff8f0000, lowest used address 00000000ff8ef3d0, stack used: 3120 bytes
CBFS: 'VBOOT' located CBFS at [402000:44cc00)
CBFS: Locating 'fallback/bl31'
CBFS: Found @ offset 10ec0 size 8d0c
Loading segment from ROM address 0x0000000000100000
code (compression=1)
New segment dstaddr 0x10000 memsize 0x40000 srcaddr 0x100054 filesize 0x8192
Loading segment from ROM address 0x000000000010001c
code (compression=1)
New segment dstaddr 0xff8d4000 memsize 0x1f50 srcaddr 0x1081e6 filesize 0xb26
Loading segment from ROM address 0x0000000000100038
Entry Point 0x0000000000010000
Loading Segment: addr: 0x0000000000010000 memsz: 0x0000000000040000 filesz: 0x0000000000008192
lb: [0x0000000000300000, 0x0000000000320558)
Post relocation: addr: 0x0000000000010000 memsz: 0x0000000000040000 filesz: 0x0000000000008192
using LZMA
[ 0x00010000, 00035708, 0x00050000) <- 00100054
Clearing Segment: addr: 0x0000000000035708 memsz: 0x000000000001a8f8
dest 0000000000010000, end 0000000000050000, bouncebuffer ffffffffffffffff
Loading Segment: addr: 0x00000000ff8d4000 memsz: 0x0000000000001f50 filesz: 0x0000000000000b26
lb: [0x0000000000300000, 0x0000000000320558)
Post relocation: addr: 0x00000000ff8d4000 memsz: 0x0000000000001f50 filesz: 0x0000000000000b26
using LZMA
[ 0xff8d4000, ff8d5f50, 0xff8d5f50) <- 001081e6
dest 00000000ff8d4000, end 00000000ff8d5f50, bouncebuffer ffffffffffffffff
Loaded segments
INFO: plat_rockchip_pmusram_prepare pmu: code d2bfe625,d2bfe625,80
INFO: plat_rockchip_pmusram_prepare pmu: code 0xff8d4000,0x50000,3364
INFO: plat_rockchip_pmusram_prepare: data 0xff8d4d28,0xff8d4d24,4648
NOTICE: BL31: v1.2(debug):
NOTICE: BL31: Built : Sun Sep 4 22:36:16 UTC 2016
INFO: GICv3 with legacy support detected. ARM GICV3 driver initialized in EL3
INFO: plat_rockchip_pmu_init(1189): pd status 3e
INFO: BL31: Initializing runtime services
INFO: BL31: Preparing for EL3 exit to normal world
INFO: Entry point address = 0x18104800
INFO: SPSR = 0x8
Change-Id: Ie2484d122a603f1c7b7082a1de3f240aa6e6d540
Signed-off-by: Patrick Georgi <pgeorgi(a)chromium.org>
Original-Commit-Id: 8c1d75bff6e810a39776048ad9049ec0a9c5d94e
Original-Change-Id: I2d60e5762f8377e43835558f76a3928156acb26c
Original-Signed-off-by: Simon Glass <sjg(a)chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/376849
Original-Commit-Ready: Simon Glass <sjg(a)google.com>
Original-Tested-by: Simon Glass <sjg(a)google.com>
Original-Reviewed-by: Julius Werner <jwerner(a)chromium.org>
---
src/arch/arm64/Makefile.inc | 2 +-
src/arch/arm64/arm_tf.c | 5 ++---
src/include/program_loading.h | 10 ++++++++--
src/lib/prog_loaders.c | 2 +-
src/lib/selfboot.c | 24 ++++++++++++++----------
5 files changed, 26 insertions(+), 17 deletions(-)
diff --git a/src/arch/arm64/Makefile.inc b/src/arch/arm64/Makefile.inc
index ece35a6..6e3f080 100644
--- a/src/arch/arm64/Makefile.inc
+++ b/src/arch/arm64/Makefile.inc
@@ -178,7 +178,7 @@ $(BL31): $(obj)/build.h
BL31_CBFS := $(CONFIG_CBFS_PREFIX)/bl31
$(BL31_CBFS)-file := $(BL31)
-$(BL31_CBFS)-type := stage
+$(BL31_CBFS)-type := payload
$(BL31_CBFS)-compression := $(CBFS_COMPRESS_FLAG)
cbfs-files-y += $(BL31_CBFS)
diff --git a/src/arch/arm64/arm_tf.c b/src/arch/arm64/arm_tf.c
index 1ec87c4..e976e34 100644
--- a/src/arch/arm64/arm_tf.c
+++ b/src/arch/arm64/arm_tf.c
@@ -50,11 +50,10 @@ void arm_tf_run_bl31(u64 payload_entry, u64 payload_arg0, u64 payload_spsr)
if (prog_locate(&bl31))
die("BL31 not found");
- if (cbfs_prog_stage_load(&bl31))
+ bl31_entry = selfload(&bl31, false);
+ if (!bl31_entry)
die("BL31 load failed");
- bl31_entry = prog_entry(&bl31);
-
SET_PARAM_HEAD(&bl31_params, PARAM_BL31, VERSION_1, 0);
if (IS_ENABLED(CONFIG_ARM64_USE_SECURE_OS)) {
diff --git a/src/include/program_loading.h b/src/include/program_loading.h
index e265b18..3958fda 100644
--- a/src/include/program_loading.h
+++ b/src/include/program_loading.h
@@ -189,7 +189,13 @@ void payload_run(void);
/* Mirror the payload to be loaded. */
void mirror_payload(struct prog *payload);
-/* Defined in src/lib/selfboot.c */
-void *selfload(struct prog *payload);
+/*
+ * Set check_regions to true to check that the payload targets usable memory.
+ * With this flag set, if it does not, the load will fail and this function
+ * will return NULL.
+ *
+ * Defined in src/lib/selfboot.c
+ */
+void *selfload(struct prog *payload, bool check_regions);
#endif /* PROGRAM_LOADING_H */
diff --git a/src/lib/prog_loaders.c b/src/lib/prog_loaders.c
index ecbc679..c0dcd60 100644
--- a/src/lib/prog_loaders.c
+++ b/src/lib/prog_loaders.c
@@ -161,7 +161,7 @@ void payload_load(void)
mirror_payload(payload);
/* Pass cbtables to payload if architecture desires it. */
- prog_set_entry(payload, selfload(payload),
+ prog_set_entry(payload, selfload(payload, true),
cbmem_find(CBMEM_ID_CBTABLE));
out:
diff --git a/src/lib/selfboot.c b/src/lib/selfboot.c
index 1ce7f94..162a034 100644
--- a/src/lib/selfboot.c
+++ b/src/lib/selfboot.c
@@ -88,7 +88,8 @@ static void get_bounce_buffer(unsigned long req_size)
/* When the ramstage is relocatable there is no need for a bounce
* buffer. All payloads should not overlap the ramstage.
*/
- if (IS_ENABLED(CONFIG_RELOCATABLE_RAMSTAGE)) {
+ if (IS_ENABLED(CONFIG_RELOCATABLE_RAMSTAGE) ||
+ !arch_supports_bounce_buffer()) {
bounce_buffer = ~0UL;
bounce_size = 0;
return;
@@ -357,15 +358,16 @@ static int payload_targets_usable_ram(struct segment *head)
return 1;
}
-static int load_self_segments(
- struct segment *head,
- struct prog *payload)
+static int load_self_segments(struct segment *head, struct prog *payload,
+ bool check_regions)
{
struct segment *ptr;
unsigned long bounce_high = lb_end;
- if (!payload_targets_usable_ram(head))
- return 0;
+ if (check_regions) {
+ if (!payload_targets_usable_ram(head))
+ return 0;
+ }
for(ptr = head->next; ptr != head; ptr = ptr->next) {
/*
@@ -373,8 +375,10 @@ static int load_self_segments(
* allocated so that there aren't conflicts with the actual
* payload.
*/
- bootmem_add_range(ptr->s_dstaddr, ptr->s_memsz,
- LB_MEM_UNUSABLE);
+ if (check_regions) {
+ bootmem_add_range(ptr->s_dstaddr, ptr->s_memsz,
+ LB_MEM_UNUSABLE);
+ }
if (!overlaps_coreboot(ptr))
continue;
@@ -486,7 +490,7 @@ static int load_self_segments(
return 1;
}
-void *selfload(struct prog *payload)
+void *selfload(struct prog *payload, bool check_regions)
{
uintptr_t entry = 0;
struct segment head;
@@ -502,7 +506,7 @@ void *selfload(struct prog *payload)
goto out;
/* Load the segments */
- if (!load_self_segments(&head, payload))
+ if (!load_self_segments(&head, payload, check_regions))
goto out;
printk(BIOS_SPEW, "Loaded segments\n");
Patrick Georgi (pgeorgi(a)google.com) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/16705
-gerrit
commit 6c0ac553762dca0c1412d6a75785bd96a0b09661
Author: Simon Glass <sjg(a)chromium.org>
Date: Wed Sep 7 16:01:55 2016 -0600
Add DIV_ROUND_CLOSEST
Bring in this useful function from Linux 4.7.
BUG=chrome-os-partner:56556
BRANCH=none
TEST=build on gru
Change-Id: I1577309e3e9ddea794e7e77354d50e582b70a43c
Signed-off-by: Patrick Georgi <pgeorgi(a)chromium.org>
Original-Commit-Id: 99f22182c2be0a6d02204b40f8f792f36d31c745
Original-Change-Id: I37617e35b4784d6cdc51e6910aa91f566caf971d
Original-Signed-off-by: Simon Glass <sjg(a)chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/382320
Original-Reviewed-by: Julius Werner <jwerner(a)chromium.org>
---
src/include/stdlib.h | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/src/include/stdlib.h b/src/include/stdlib.h
index d6e7faf..6200f1c 100644
--- a/src/include/stdlib.h
+++ b/src/include/stdlib.h
@@ -16,6 +16,22 @@ static inline unsigned long div_round_up(unsigned int n, unsigned int d)
{
return (n + d - 1) / d;
}
+
+/*
+ * Divide positive or negative dividend by positive divisor and round
+ * to closest integer. Result is undefined for negative divisors and
+ * for negative dividends if the divisor variable type is unsigned.
+ */
+#define DIV_ROUND_CLOSEST(x, divisor)( \
+{ \
+ typeof(x) __x = x; \
+ typeof(divisor) __d = divisor; \
+ (((typeof(x))-1) > 0 || \
+ ((typeof(divisor))-1) > 0 || (__x) > 0) ? \
+ (((__x) + ((__d) / 2)) / (__d)) : \
+ (((__x) - ((__d) / 2)) / (__d)); \
+} \
+)
#endif
Patrick Georgi (pgeorgi(a)google.com) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/16703
-gerrit
commit 6a6885a069c63bff1cde5939809de8cf1efcf410
Author: Julius Werner <jwerner(a)chromium.org>
Date: Fri Sep 2 23:48:10 2016 -0700
rockchip/rk3399: Fix rkclk_init() to actually use PERILP1_PCLK_HZ
This patch fixes a typo in the clock initialization code that caused the
PERILP1_PCLK_HZ constant to be ignored and the clock to always run at
the same speed as its parent (PERILP1_HCLK_HZ). Since we've done all our
previous tests and validation with this bug, we should probably increase
the value of the constant (that had not actually been used) to the value
that we had been incorrectly using instead (which also makes effective
SPI read times faster).
BRANCH=None
BUG=chrome-os-partner:56556
TEST=Booted Kevin.
Change-Id: Ibeb08f5fe5e984a74e3f57e60c62d4bfb644b6ca
Signed-off-by: Patrick Georgi <pgeorgi(a)chromium.org>
Original-Commit-Id: 06e605a5fcb9bdf13a3d301112380633b892fd4e
Original-Change-Id: Icb5e079f53eb22b0dbf0ea4d1c2ff08688e3fa8e
Original-Signed-off-by: Julius Werner <jwerner(a)chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/381031
Original-Reviewed-by: Simon Glass <sjg(a)chromium.org>
---
src/soc/rockchip/rk3399/clock.c | 6 +++---
src/soc/rockchip/rk3399/include/soc/clock.h | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/soc/rockchip/rk3399/clock.c b/src/soc/rockchip/rk3399/clock.c
index 291a70c..c695ac0 100644
--- a/src/soc/rockchip/rk3399/clock.c
+++ b/src/soc/rockchip/rk3399/clock.c
@@ -477,9 +477,9 @@ void rkclk_init(void)
assert((hclk_div + 1) * PERILP1_HCLK_HZ ==
GPLL_HZ && (hclk_div < 0x1f));
- pclk_div = PERILP1_HCLK_HZ / PERILP1_HCLK_HZ - 1;
- assert((pclk_div + 1) * PERILP1_HCLK_HZ ==
- PERILP1_HCLK_HZ && (hclk_div < 0x7));
+ pclk_div = PERILP1_HCLK_HZ / PERILP1_PCLK_HZ - 1;
+ assert((pclk_div + 1) * PERILP1_PCLK_HZ ==
+ PERILP1_HCLK_HZ && (pclk_div < 0x7));
write32(&cru_ptr->clksel_con[25],
RK_CLRSETBITS(PCLK_PERILP1_DIV_CON_MASK <<
diff --git a/src/soc/rockchip/rk3399/include/soc/clock.h b/src/soc/rockchip/rk3399/include/soc/clock.h
index 9d57e46..5926051 100644
--- a/src/soc/rockchip/rk3399/include/soc/clock.h
+++ b/src/soc/rockchip/rk3399/include/soc/clock.h
@@ -92,7 +92,7 @@ static struct rk3399_cru_reg * const cru_ptr = (void *)CRU_BASE;
#define PERILP0_PCLK_HZ (49500*KHz)
#define PERILP1_HCLK_HZ (99000*KHz)
-#define PERILP1_PCLK_HZ (49500*KHz)
+#define PERILP1_PCLK_HZ (99000*KHz)
#define PWM_CLOCK_HZ PMU_PCLK_HZ