summaryrefslogtreecommitdiff
path: root/arch/x86/cpu/broadwell/lpc.c
blob: 9dc9b63db614e27bd30f5d20b3c05501dbaf431e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright (c) 2016 Google, Inc
 *
 * From coreboot broadwell support
 */

#include <common.h>
#include <dm.h>
#include <pch.h>
#include <asm/intel_regs.h>
#include <asm/io.h>
#include <asm/lpc_common.h>
#include <asm/arch/pch.h>
#include <asm/arch/spi.h>

static void set_spi_speed(void)
{
	u32 fdod;
	u8 ssfc;

	/* Observe SPI Descriptor Component Section 0 */
	writel(0x1000, SPI_REG(SPIBAR_FDOC));

	/* Extract the Write/Erase SPI Frequency from descriptor */
	fdod = readl(SPI_REG(SPIBAR_FDOD));
	fdod >>= 24;
	fdod &= 7;

	/* Set Software Sequence frequency to match */
	ssfc = readb(SPI_REG(SPIBAR_SSFC + 2));
	ssfc &= ~7;
	ssfc |= fdod;
	writeb(ssfc, SPI_REG(SPIBAR_SSFC + 2));
}

static int broadwell_lpc_early_init(struct udevice *dev)
{
	set_spi_speed();

	return 0;
}

static int lpc_init_extra(struct udevice *dev)
{
	return 0;
}

static int broadwell_lpc_probe(struct udevice *dev)
{
	int ret;

	if (!(gd->flags & GD_FLG_RELOC)) {
		ret = lpc_common_early_init(dev);
		if (ret) {
			debug("%s: lpc_early_init() failed\n", __func__);
			return ret;
		}

		return broadwell_lpc_early_init(dev);
	}

	return lpc_init_extra(dev);
}

static const struct udevice_id broadwell_lpc_ids[] = {
	{ .compatible = "intel,broadwell-lpc" },
	{ }
};

U_BOOT_DRIVER(broadwell_lpc_drv) = {
	.name		= "lpc",
	.id		= UCLASS_LPC,
	.of_match	= broadwell_lpc_ids,
	.probe		= broadwell_lpc_probe,
};