x86: apl: Use devicetree for FSP-M configuration
[oweals/u-boot.git] / arch / x86 / include / asm / arch-apollolake / fsp_bindings.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright 2019 Google LLC
4  * Copyright 2020 B&R Industrial Automation GmbH - http://www.br-automation.com
5  */
6
7 #ifndef __ASM_ARCH_FSP_BINDINGS_H
8 #define __ASM_ARCH_FSP_BINDINGS_H
9
10 #include <asm/arch/fsp/fsp_m_upd.h>
11
12 #define ARRAY_SIZE_OF_MEMBER(s, m) (ARRAY_SIZE((((s *)0)->m)))
13 #define SIZE_OF_MEMBER(s, m) (sizeof((((s *)0)->m)))
14
15 enum conf_type {
16         FSP_UINT8,
17         FSP_UINT16,
18         FSP_UINT32,
19         FSP_STRING,
20         FSP_LPDDR4_SWIZZLE,
21 };
22
23 /**
24  * struct fsp_binding - Binding describing devicetree/FSP relationships
25  * @offset:   Offset within the FSP config structure
26  * @propname: Name of property to read
27  * @type:     Type of the property to read
28  * @count:    If the property is expected to be an array, this is the
29  *            number of expected elements
30  *            Set to 0 if the property is expected to be a scalar
31  *
32  * The struct fsp_binding is used to describe the relationship between
33  * values stored in devicetree and where they are placed in the FSP
34  * configuration structure.
35  */
36 struct fsp_binding {
37         size_t offset;
38         char *propname;
39         enum conf_type type;
40         size_t count;
41 };
42
43 /*
44  * LPDDR4 helper routines for configuring the memory UPD for LPDDR4 operation.
45  * There are four physical LPDDR4 channels, each 32-bits wide. There are two
46  * logical channels using two physical channels together to form a 64-bit
47  * interface to memory for each logical channel.
48  */
49
50 enum {
51         LP4_PHYS_CH0A,
52         LP4_PHYS_CH0B,
53         LP4_PHYS_CH1A,
54         LP4_PHYS_CH1B,
55
56         LP4_NUM_PHYS_CHANNELS,
57 };
58
59 /*
60  * The DQs within a physical channel can be bit-swizzled within each byte.
61  * Within a channel the bytes can be swapped, but the DQs need to be routed
62  * with the corresponding DQS (strobe).
63  */
64 enum {
65         LP4_DQS0,
66         LP4_DQS1,
67         LP4_DQS2,
68         LP4_DQS3,
69
70         LP4_NUM_BYTE_LANES,
71         DQ_BITS_PER_DQS         = 8,
72 };
73
74 /* Provide bit swizzling per DQS and byte swapping within a channel */
75 struct lpddr4_chan_swizzle_cfg {
76         u8 dqs[LP4_NUM_BYTE_LANES][DQ_BITS_PER_DQS];
77 };
78
79 struct lpddr4_swizzle_cfg {
80         struct lpddr4_chan_swizzle_cfg phys[LP4_NUM_PHYS_CHANNELS];
81 };
82
83 /**
84  * fsp_m_update_config_from_dtb() - Read FSP-M config from devicetree node
85  * @node: Valid node reference to read property from
86  * @cfg:  Pointer to FSP-M config structure
87  * @return 0 on success, -ve on error
88  *
89  * This function reads the configuration for FSP-M from the provided
90  * devicetree node and saves it in the FSP-M configuration structure.
91  * Configuration options that are not present in the devicetree are
92  * left at their current value.
93  */
94 int fsp_m_update_config_from_dtb(ofnode node, struct fsp_m_config *cfg);
95
96 #endif