Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'memory-controller-drv-5.16-2' of git://git.kernel.org/pub/scm/linux/kernel/git/krzk/linux-mem-ctrl into arm/drivers

Memory controller drivers for v5.16, part two

1. Convert LPDDR2 bindings to dtschema and extend them with new
properties.
2. Tegra 20 EMC: support matching timings by LPDDR2 configuration from
devicetree.

* tag 'memory-controller-drv-5.16-2' of git://git.kernel.org/pub/scm/linux/kernel/git/krzk/linux-mem-ctrl:
memory: tegra20-emc: Add runtime dependency on devfreq governor module
memory: tegra20-emc: Support matching timings by LPDDR2 configuration
memory: Add LPDDR2-info helpers
dt-bindings: memory: tegra20: emc: Document new LPDDR2 sub-node
dt-bindings: Add vendor prefix for Elpida Memory
dt-bindings: memory: lpddr2: Document Elpida B8132B2PB-6D-F
dt-bindings: memory: lpddr2: Add revision-id properties
dt-bindings: memory: lpddr2: Convert to schema
dt-bindings: Relocate DDR bindings

Link: https://lore.kernel.org/r/20211021093002.118192-1-krzysztof.kozlowski@canonical.com
Signed-off-by: Arnd Bergmann <arnd@arndb.de>

+622 -121
Documentation/devicetree/bindings/ddr/lpddr2-timings.txt Documentation/devicetree/bindings/memory-controllers/ddr/lpddr2-timings.txt
-102
Documentation/devicetree/bindings/ddr/lpddr2.txt
··· 1 - * LPDDR2 SDRAM memories compliant to JEDEC JESD209-2 2 - 3 - Required properties: 4 - - compatible : Should be one of - "jedec,lpddr2-nvm", "jedec,lpddr2-s2", 5 - "jedec,lpddr2-s4" 6 - 7 - "ti,jedec-lpddr2-s2" should be listed if the memory part is LPDDR2-S2 type 8 - 9 - "ti,jedec-lpddr2-s4" should be listed if the memory part is LPDDR2-S4 type 10 - 11 - "ti,jedec-lpddr2-nvm" should be listed if the memory part is LPDDR2-NVM type 12 - 13 - - density : <u32> representing density in Mb (Mega bits) 14 - 15 - - io-width : <u32> representing bus width. Possible values are 8, 16, and 32 16 - 17 - Optional properties: 18 - 19 - The following optional properties represent the minimum value of some AC 20 - timing parameters of the DDR device in terms of number of clock cycles. 21 - These values shall be obtained from the device data-sheet. 22 - - tRRD-min-tck 23 - - tWTR-min-tck 24 - - tXP-min-tck 25 - - tRTP-min-tck 26 - - tCKE-min-tck 27 - - tRPab-min-tck 28 - - tRCD-min-tck 29 - - tWR-min-tck 30 - - tRASmin-min-tck 31 - - tCKESR-min-tck 32 - - tFAW-min-tck 33 - 34 - Child nodes: 35 - - The lpddr2 node may have one or more child nodes of type "lpddr2-timings". 36 - "lpddr2-timings" provides AC timing parameters of the device for 37 - a given speed-bin. The user may provide the timings for as many 38 - speed-bins as is required. Please see Documentation/devicetree/ 39 - bindings/ddr/lpddr2-timings.txt for more information on "lpddr2-timings" 40 - 41 - Example: 42 - 43 - elpida_ECB240ABACN : lpddr2 { 44 - compatible = "Elpida,ECB240ABACN","jedec,lpddr2-s4"; 45 - density = <2048>; 46 - io-width = <32>; 47 - 48 - tRPab-min-tck = <3>; 49 - tRCD-min-tck = <3>; 50 - tWR-min-tck = <3>; 51 - tRASmin-min-tck = <3>; 52 - tRRD-min-tck = <2>; 53 - tWTR-min-tck = <2>; 54 - tXP-min-tck = <2>; 55 - tRTP-min-tck = <2>; 56 - tCKE-min-tck = <3>; 57 - tCKESR-min-tck = <3>; 58 - tFAW-min-tck = <8>; 59 - 60 - timings_elpida_ECB240ABACN_400mhz: lpddr2-timings@0 { 61 - compatible = "jedec,lpddr2-timings"; 62 - min-freq = <10000000>; 63 - max-freq = <400000000>; 64 - tRPab = <21000>; 65 - tRCD = <18000>; 66 - tWR = <15000>; 67 - tRAS-min = <42000>; 68 - tRRD = <10000>; 69 - tWTR = <7500>; 70 - tXP = <7500>; 71 - tRTP = <7500>; 72 - tCKESR = <15000>; 73 - tDQSCK-max = <5500>; 74 - tFAW = <50000>; 75 - tZQCS = <90000>; 76 - tZQCL = <360000>; 77 - tZQinit = <1000000>; 78 - tRAS-max-ns = <70000>; 79 - }; 80 - 81 - timings_elpida_ECB240ABACN_200mhz: lpddr2-timings@1 { 82 - compatible = "jedec,lpddr2-timings"; 83 - min-freq = <10000000>; 84 - max-freq = <200000000>; 85 - tRPab = <21000>; 86 - tRCD = <18000>; 87 - tWR = <15000>; 88 - tRAS-min = <42000>; 89 - tRRD = <10000>; 90 - tWTR = <10000>; 91 - tXP = <7500>; 92 - tRTP = <7500>; 93 - tCKESR = <15000>; 94 - tDQSCK-max = <5500>; 95 - tFAW = <50000>; 96 - tZQCS = <90000>; 97 - tZQCL = <360000>; 98 - tZQinit = <1000000>; 99 - tRAS-max-ns = <70000>; 100 - }; 101 - 102 - }
Documentation/devicetree/bindings/ddr/lpddr3-timings.txt Documentation/devicetree/bindings/memory-controllers/ddr/lpddr3-timings.txt
+3 -2
Documentation/devicetree/bindings/ddr/lpddr3.txt Documentation/devicetree/bindings/memory-controllers/ddr/lpddr3.txt
··· 43 43 Child nodes: 44 44 - The lpddr3 node may have one or more child nodes of type "lpddr3-timings". 45 45 "lpddr3-timings" provides AC timing parameters of the device for 46 - a given speed-bin. Please see Documentation/devicetree/ 47 - bindings/ddr/lpddr3-timings.txt for more information on "lpddr3-timings" 46 + a given speed-bin. Please see 47 + Documentation/devicetree/bindings/memory-controllers/ddr/lpddr3-timings.txt 48 + for more information on "lpddr3-timings" 48 49 49 50 Example: 50 51
+223
Documentation/devicetree/bindings/memory-controllers/ddr/jedec,lpddr2.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/memory-controllers/ddr/jedec,lpddr2.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: LPDDR2 SDRAM compliant to JEDEC JESD209-2 8 + 9 + maintainers: 10 + - Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com> 11 + 12 + properties: 13 + compatible: 14 + oneOf: 15 + - items: 16 + - enum: 17 + - elpida,ECB240ABACN 18 + - elpida,B8132B2PB-6D-F 19 + - enum: 20 + - jedec,lpddr2-s4 21 + - items: 22 + - enum: 23 + - jedec,lpddr2-s2 24 + - items: 25 + - enum: 26 + - jedec,lpddr2-nvm 27 + 28 + revision-id1: 29 + $ref: /schemas/types.yaml#/definitions/uint32 30 + maximum: 255 31 + description: | 32 + Revision 1 value of SDRAM chip. Obtained from device datasheet. 33 + 34 + revision-id2: 35 + $ref: /schemas/types.yaml#/definitions/uint32 36 + maximum: 255 37 + description: | 38 + Revision 2 value of SDRAM chip. Obtained from device datasheet. 39 + 40 + density: 41 + $ref: /schemas/types.yaml#/definitions/uint32 42 + description: | 43 + Density in megabits of SDRAM chip. Obtained from device datasheet. 44 + enum: 45 + - 64 46 + - 128 47 + - 256 48 + - 512 49 + - 1024 50 + - 2048 51 + - 4096 52 + - 8192 53 + - 16384 54 + - 32768 55 + 56 + io-width: 57 + $ref: /schemas/types.yaml#/definitions/uint32 58 + description: | 59 + IO bus width in bits of SDRAM chip. Obtained from device datasheet. 60 + enum: 61 + - 32 62 + - 16 63 + - 8 64 + 65 + tRRD-min-tck: 66 + $ref: /schemas/types.yaml#/definitions/uint32 67 + maximum: 16 68 + description: | 69 + Active bank a to active bank b in terms of number of clock cycles. 70 + Obtained from device datasheet. 71 + 72 + tWTR-min-tck: 73 + $ref: /schemas/types.yaml#/definitions/uint32 74 + maximum: 16 75 + description: | 76 + Internal WRITE-to-READ command delay in terms of number of clock cycles. 77 + Obtained from device datasheet. 78 + 79 + tXP-min-tck: 80 + $ref: /schemas/types.yaml#/definitions/uint32 81 + maximum: 16 82 + description: | 83 + Exit power-down to next valid command delay in terms of number of clock 84 + cycles. Obtained from device datasheet. 85 + 86 + tRTP-min-tck: 87 + $ref: /schemas/types.yaml#/definitions/uint32 88 + maximum: 16 89 + description: | 90 + Internal READ to PRECHARGE command delay in terms of number of clock 91 + cycles. Obtained from device datasheet. 92 + 93 + tCKE-min-tck: 94 + $ref: /schemas/types.yaml#/definitions/uint32 95 + maximum: 16 96 + description: | 97 + CKE minimum pulse width (HIGH and LOW pulse width) in terms of number 98 + of clock cycles. Obtained from device datasheet. 99 + 100 + tRPab-min-tck: 101 + $ref: /schemas/types.yaml#/definitions/uint32 102 + maximum: 16 103 + description: | 104 + Row precharge time (all banks) in terms of number of clock cycles. 105 + Obtained from device datasheet. 106 + 107 + tRCD-min-tck: 108 + $ref: /schemas/types.yaml#/definitions/uint32 109 + maximum: 16 110 + description: | 111 + RAS-to-CAS delay in terms of number of clock cycles. Obtained from 112 + device datasheet. 113 + 114 + tWR-min-tck: 115 + $ref: /schemas/types.yaml#/definitions/uint32 116 + maximum: 16 117 + description: | 118 + WRITE recovery time in terms of number of clock cycles. Obtained from 119 + device datasheet. 120 + 121 + tRASmin-min-tck: 122 + $ref: /schemas/types.yaml#/definitions/uint32 123 + maximum: 16 124 + description: | 125 + Row active time in terms of number of clock cycles. Obtained from device 126 + datasheet. 127 + 128 + tCKESR-min-tck: 129 + $ref: /schemas/types.yaml#/definitions/uint32 130 + maximum: 16 131 + description: | 132 + CKE minimum pulse width during SELF REFRESH (low pulse width during 133 + SELF REFRESH) in terms of number of clock cycles. Obtained from device 134 + datasheet. 135 + 136 + tFAW-min-tck: 137 + $ref: /schemas/types.yaml#/definitions/uint32 138 + maximum: 16 139 + description: | 140 + Four-bank activate window in terms of number of clock cycles. Obtained 141 + from device datasheet. 142 + 143 + patternProperties: 144 + "^lpddr2-timings": 145 + type: object 146 + description: | 147 + The lpddr2 node may have one or more child nodes of type "lpddr2-timings". 148 + "lpddr2-timings" provides AC timing parameters of the device for 149 + a given speed-bin. The user may provide the timings for as many 150 + speed-bins as is required. Please see Documentation/devicetree/ 151 + bindings/memory-controllers/ddr/lpddr2-timings.txt for more information 152 + on "lpddr2-timings". 153 + 154 + required: 155 + - compatible 156 + - density 157 + - io-width 158 + 159 + additionalProperties: false 160 + 161 + examples: 162 + - | 163 + elpida_ECB240ABACN: lpddr2 { 164 + compatible = "elpida,ECB240ABACN", "jedec,lpddr2-s4"; 165 + density = <2048>; 166 + io-width = <32>; 167 + revision-id1 = <1>; 168 + revision-id2 = <0>; 169 + 170 + tRPab-min-tck = <3>; 171 + tRCD-min-tck = <3>; 172 + tWR-min-tck = <3>; 173 + tRASmin-min-tck = <3>; 174 + tRRD-min-tck = <2>; 175 + tWTR-min-tck = <2>; 176 + tXP-min-tck = <2>; 177 + tRTP-min-tck = <2>; 178 + tCKE-min-tck = <3>; 179 + tCKESR-min-tck = <3>; 180 + tFAW-min-tck = <8>; 181 + 182 + timings_elpida_ECB240ABACN_400mhz: lpddr2-timings0 { 183 + compatible = "jedec,lpddr2-timings"; 184 + min-freq = <10000000>; 185 + max-freq = <400000000>; 186 + tRPab = <21000>; 187 + tRCD = <18000>; 188 + tWR = <15000>; 189 + tRAS-min = <42000>; 190 + tRRD = <10000>; 191 + tWTR = <7500>; 192 + tXP = <7500>; 193 + tRTP = <7500>; 194 + tCKESR = <15000>; 195 + tDQSCK-max = <5500>; 196 + tFAW = <50000>; 197 + tZQCS = <90000>; 198 + tZQCL = <360000>; 199 + tZQinit = <1000000>; 200 + tRAS-max-ns = <70000>; 201 + }; 202 + 203 + timings_elpida_ECB240ABACN_200mhz: lpddr2-timings1 { 204 + compatible = "jedec,lpddr2-timings"; 205 + min-freq = <10000000>; 206 + max-freq = <200000000>; 207 + tRPab = <21000>; 208 + tRCD = <18000>; 209 + tWR = <15000>; 210 + tRAS-min = <42000>; 211 + tRRD = <10000>; 212 + tWTR = <10000>; 213 + tXP = <7500>; 214 + tRTP = <7500>; 215 + tCKESR = <15000>; 216 + tDQSCK-max = <5500>; 217 + tFAW = <50000>; 218 + tZQCS = <90000>; 219 + tZQCL = <360000>; 220 + tZQinit = <1000000>; 221 + tRAS-max-ns = <70000>; 222 + }; 223 + };
+21 -2
Documentation/devicetree/bindings/memory-controllers/nvidia,tegra20-emc.yaml
··· 164 164 "#size-cells": 165 165 const: 0 166 166 167 + lpddr2: 168 + $ref: "ddr/jedec,lpddr2.yaml#" 169 + type: object 170 + 167 171 patternProperties: 168 172 "^emc-table@[0-9]+$": 169 173 $ref: "#/$defs/emc-table" 170 174 171 - required: 172 - - nvidia,ram-code 175 + oneOf: 176 + - required: 177 + - nvidia,ram-code 178 + 179 + - required: 180 + - lpddr2 173 181 174 182 additionalProperties: false 175 183 ··· 233 225 0x00000000 0x00000000 0x00000083 0xf0440303 234 226 0x007fe010 0x00001414 0x00000000 0x00000000 235 227 0x00000000 0x00000000 0x00000000 0x00000000>; 228 + }; 229 + }; 230 + 231 + emc-tables@1 { 232 + reg = <1>; 233 + 234 + lpddr2 { 235 + compatible = "elpida,B8132B2PB-6D-F", "jedec,lpddr2-s4"; 236 + revision-id1 = <1>; 237 + density = <2048>; 238 + io-width = <16>; 236 239 }; 237 240 }; 238 241 };
+2 -1
Documentation/devicetree/bindings/memory-controllers/samsung,exynos5422-dmc.yaml
··· 51 51 $ref: '/schemas/types.yaml#/definitions/phandle' 52 52 description: | 53 53 phandle of the connected DRAM memory device. For more information please 54 - refer to documentation file: Documentation/devicetree/bindings/ddr/lpddr3.txt 54 + refer to documentation file: 55 + Documentation/devicetree/bindings/memory-controllers/ddr/lpddr3.txt 55 56 56 57 operating-points-v2: true 57 58
+2
Documentation/devicetree/bindings/vendor-prefixes.yaml
··· 353 353 description: Shenzhen Elida Technology Co., Ltd. 354 354 "^elimo,.*": 355 355 description: Elimo Engineering Ltd. 356 + "^elpida,.*": 357 + description: Elpida Memory, Inc. 356 358 "^embest,.*": 357 359 description: Shenzhen Embest Technology Co., Ltd. 358 360 "^emlid,.*":
+47
drivers/memory/jedec_ddr.h
··· 112 112 #define NUM_DDR_ADDR_TABLE_ENTRIES 11 113 113 #define NUM_DDR_TIMING_TABLE_ENTRIES 4 114 114 115 + #define LPDDR2_MANID_SAMSUNG 1 116 + #define LPDDR2_MANID_QIMONDA 2 117 + #define LPDDR2_MANID_ELPIDA 3 118 + #define LPDDR2_MANID_ETRON 4 119 + #define LPDDR2_MANID_NANYA 5 120 + #define LPDDR2_MANID_HYNIX 6 121 + #define LPDDR2_MANID_MOSEL 7 122 + #define LPDDR2_MANID_WINBOND 8 123 + #define LPDDR2_MANID_ESMT 9 124 + #define LPDDR2_MANID_SPANSION 11 125 + #define LPDDR2_MANID_SST 12 126 + #define LPDDR2_MANID_ZMOS 13 127 + #define LPDDR2_MANID_INTEL 14 128 + #define LPDDR2_MANID_NUMONYX 254 129 + #define LPDDR2_MANID_MICRON 255 130 + 131 + #define LPDDR2_TYPE_S4 0 132 + #define LPDDR2_TYPE_S2 1 133 + #define LPDDR2_TYPE_NVM 2 134 + 115 135 /* Structure for DDR addressing info from the JEDEC spec */ 116 136 struct lpddr2_addressing { 117 137 u32 num_banks; ··· 189 169 extern const struct lpddr2_timings 190 170 lpddr2_jedec_timings[NUM_DDR_TIMING_TABLE_ENTRIES]; 191 171 extern const struct lpddr2_min_tck lpddr2_jedec_min_tck; 172 + 173 + /* Structure of MR8 */ 174 + union lpddr2_basic_config4 { 175 + u32 value; 176 + 177 + struct { 178 + unsigned int arch_type : 2; 179 + unsigned int density : 4; 180 + unsigned int io_width : 2; 181 + } __packed; 182 + }; 183 + 184 + /* 185 + * Structure for information about LPDDR2 chip. All parameters are 186 + * matching raw values of standard mode register bitfields or set to 187 + * -ENOENT if info unavailable. 188 + */ 189 + struct lpddr2_info { 190 + int arch_type; 191 + int density; 192 + int io_width; 193 + int manufacturer_id; 194 + int revision_id1; 195 + int revision_id2; 196 + }; 197 + 198 + const char *lpddr2_jedec_manufacturer(unsigned int manufacturer_id); 192 199 193 200 /* 194 201 * Structure for timings for LPDDR3 based on LPDDR2 plus additional fields.
+41
drivers/memory/jedec_ddr_data.c
··· 131 131 .tFAW = 8 132 132 }; 133 133 EXPORT_SYMBOL_GPL(lpddr2_jedec_min_tck); 134 + 135 + const char *lpddr2_jedec_manufacturer(unsigned int manufacturer_id) 136 + { 137 + switch (manufacturer_id) { 138 + case LPDDR2_MANID_SAMSUNG: 139 + return "Samsung"; 140 + case LPDDR2_MANID_QIMONDA: 141 + return "Qimonda"; 142 + case LPDDR2_MANID_ELPIDA: 143 + return "Elpida"; 144 + case LPDDR2_MANID_ETRON: 145 + return "Etron"; 146 + case LPDDR2_MANID_NANYA: 147 + return "Nanya"; 148 + case LPDDR2_MANID_HYNIX: 149 + return "Hynix"; 150 + case LPDDR2_MANID_MOSEL: 151 + return "Mosel"; 152 + case LPDDR2_MANID_WINBOND: 153 + return "Winbond"; 154 + case LPDDR2_MANID_ESMT: 155 + return "ESMT"; 156 + case LPDDR2_MANID_SPANSION: 157 + return "Spansion"; 158 + case LPDDR2_MANID_SST: 159 + return "SST"; 160 + case LPDDR2_MANID_ZMOS: 161 + return "ZMOS"; 162 + case LPDDR2_MANID_INTEL: 163 + return "Intel"; 164 + case LPDDR2_MANID_NUMONYX: 165 + return "Numonyx"; 166 + case LPDDR2_MANID_MICRON: 167 + return "Micron"; 168 + default: 169 + break; 170 + } 171 + 172 + return "invalid"; 173 + } 174 + EXPORT_SYMBOL_GPL(lpddr2_jedec_manufacturer);
+87
drivers/memory/of_memory.c
··· 298 298 return NULL; 299 299 } 300 300 EXPORT_SYMBOL(of_lpddr3_get_ddr_timings); 301 + 302 + /** 303 + * of_lpddr2_get_info() - extracts information about the lpddr2 chip. 304 + * @np: Pointer to device tree node containing lpddr2 info 305 + * @dev: Device requesting info 306 + * 307 + * Populates lpddr2_info structure by extracting data from device 308 + * tree node. Returns pointer to populated structure. If error 309 + * happened while populating, returns NULL. If property is missing 310 + * in a device-tree, then the corresponding value is set to -ENOENT. 311 + */ 312 + const struct lpddr2_info 313 + *of_lpddr2_get_info(struct device_node *np, struct device *dev) 314 + { 315 + struct lpddr2_info *ret_info, info = {}; 316 + struct property *prop; 317 + const char *cp; 318 + int err; 319 + 320 + err = of_property_read_u32(np, "revision-id1", &info.revision_id1); 321 + if (err) 322 + info.revision_id1 = -ENOENT; 323 + 324 + err = of_property_read_u32(np, "revision-id2", &info.revision_id2); 325 + if (err) 326 + info.revision_id2 = -ENOENT; 327 + 328 + err = of_property_read_u32(np, "io-width", &info.io_width); 329 + if (err) 330 + return NULL; 331 + 332 + info.io_width = 32 / info.io_width - 1; 333 + 334 + err = of_property_read_u32(np, "density", &info.density); 335 + if (err) 336 + return NULL; 337 + 338 + info.density = ffs(info.density) - 7; 339 + 340 + if (of_device_is_compatible(np, "jedec,lpddr2-s4")) 341 + info.arch_type = LPDDR2_TYPE_S4; 342 + else if (of_device_is_compatible(np, "jedec,lpddr2-s2")) 343 + info.arch_type = LPDDR2_TYPE_S2; 344 + else if (of_device_is_compatible(np, "jedec,lpddr2-nvm")) 345 + info.arch_type = LPDDR2_TYPE_NVM; 346 + else 347 + return NULL; 348 + 349 + prop = of_find_property(np, "compatible", NULL); 350 + for (cp = of_prop_next_string(prop, NULL); cp; 351 + cp = of_prop_next_string(prop, cp)) { 352 + 353 + #define OF_LPDDR2_VENDOR_CMP(compat, ID) \ 354 + if (!of_compat_cmp(cp, compat ",", strlen(compat ","))) { \ 355 + info.manufacturer_id = LPDDR2_MANID_##ID; \ 356 + break; \ 357 + } 358 + 359 + OF_LPDDR2_VENDOR_CMP("samsung", SAMSUNG) 360 + OF_LPDDR2_VENDOR_CMP("qimonda", QIMONDA) 361 + OF_LPDDR2_VENDOR_CMP("elpida", ELPIDA) 362 + OF_LPDDR2_VENDOR_CMP("etron", ETRON) 363 + OF_LPDDR2_VENDOR_CMP("nanya", NANYA) 364 + OF_LPDDR2_VENDOR_CMP("hynix", HYNIX) 365 + OF_LPDDR2_VENDOR_CMP("mosel", MOSEL) 366 + OF_LPDDR2_VENDOR_CMP("winbond", WINBOND) 367 + OF_LPDDR2_VENDOR_CMP("esmt", ESMT) 368 + OF_LPDDR2_VENDOR_CMP("spansion", SPANSION) 369 + OF_LPDDR2_VENDOR_CMP("sst", SST) 370 + OF_LPDDR2_VENDOR_CMP("zmos", ZMOS) 371 + OF_LPDDR2_VENDOR_CMP("intel", INTEL) 372 + OF_LPDDR2_VENDOR_CMP("numonyx", NUMONYX) 373 + OF_LPDDR2_VENDOR_CMP("micron", MICRON) 374 + 375 + #undef OF_LPDDR2_VENDOR_CMP 376 + } 377 + 378 + if (!info.manufacturer_id) 379 + info.manufacturer_id = -ENOENT; 380 + 381 + ret_info = devm_kzalloc(dev, sizeof(*ret_info), GFP_KERNEL); 382 + if (ret_info) 383 + *ret_info = info; 384 + 385 + return ret_info; 386 + } 387 + EXPORT_SYMBOL(of_lpddr2_get_info);
+9
drivers/memory/of_memory.h
··· 20 20 const struct lpddr3_timings * 21 21 of_lpddr3_get_ddr_timings(struct device_node *np_ddr, 22 22 struct device *dev, u32 device_type, u32 *nr_frequencies); 23 + 24 + const struct lpddr2_info *of_lpddr2_get_info(struct device_node *np, 25 + struct device *dev); 23 26 #else 24 27 static inline const struct lpddr2_min_tck 25 28 *of_get_min_tck(struct device_node *np, struct device *dev) ··· 46 43 static inline const struct lpddr3_timings 47 44 *of_lpddr3_get_ddr_timings(struct device_node *np_ddr, 48 45 struct device *dev, u32 device_type, u32 *nr_frequencies) 46 + { 47 + return NULL; 48 + } 49 + 50 + static inline const struct lpddr2_info 51 + *of_lpddr2_get_info(struct device_node *np, struct device *dev) 49 52 { 50 53 return NULL; 51 54 }
+1
drivers/memory/tegra/Kconfig
··· 16 16 depends on ARCH_TEGRA_2x_SOC || COMPILE_TEST 17 17 select DEVFREQ_GOV_SIMPLE_ONDEMAND 18 18 select PM_DEVFREQ 19 + select DDR 19 20 help 20 21 This driver is for the External Memory Controller (EMC) found on 21 22 Tegra20 chips. The EMC controls the external DRAM on the board.
+186 -14
drivers/memory/tegra/tegra20-emc.c
··· 5 5 * Author: Dmitry Osipenko <digetx@gmail.com> 6 6 */ 7 7 8 + #include <linux/bitfield.h> 8 9 #include <linux/clk.h> 9 10 #include <linux/clk/tegra.h> 10 11 #include <linux/debugfs.h> ··· 28 27 #include <soc/tegra/common.h> 29 28 #include <soc/tegra/fuse.h> 30 29 30 + #include "../jedec_ddr.h" 31 + #include "../of_memory.h" 32 + 31 33 #include "mc.h" 32 34 33 35 #define EMC_INTSTATUS 0x000 34 36 #define EMC_INTMASK 0x004 35 37 #define EMC_DBG 0x008 38 + #define EMC_ADR_CFG_0 0x010 36 39 #define EMC_TIMING_CONTROL 0x028 37 40 #define EMC_RC 0x02c 38 41 #define EMC_RFC 0x030 ··· 73 68 #define EMC_QUSE_EXTRA 0x0ac 74 69 #define EMC_ODT_WRITE 0x0b0 75 70 #define EMC_ODT_READ 0x0b4 71 + #define EMC_MRR 0x0ec 76 72 #define EMC_FBIO_CFG5 0x104 77 73 #define EMC_FBIO_CFG6 0x114 78 74 #define EMC_STAT_CONTROL 0x160 ··· 100 94 101 95 #define EMC_REFRESH_OVERFLOW_INT BIT(3) 102 96 #define EMC_CLKCHANGE_COMPLETE_INT BIT(4) 97 + #define EMC_MRR_DIVLD_INT BIT(5) 103 98 104 99 #define EMC_DBG_READ_MUX_ASSEMBLY BIT(0) 105 100 #define EMC_DBG_WRITE_MUX_ACTIVE BIT(1) ··· 109 102 #define EMC_DBG_CFG_PRIORITY BIT(24) 110 103 111 104 #define EMC_FBIO_CFG5_DRAM_WIDTH_X16 BIT(4) 105 + #define EMC_FBIO_CFG5_DRAM_TYPE GENMASK(1, 0) 106 + 107 + #define EMC_MRR_DEV_SELECTN GENMASK(31, 30) 108 + #define EMC_MRR_MRR_MA GENMASK(23, 16) 109 + #define EMC_MRR_MRR_DATA GENMASK(15, 0) 110 + 111 + #define EMC_ADR_CFG_0_EMEM_NUMDEV GENMASK(25, 24) 112 112 113 113 #define EMC_PWR_GATHER_CLEAR (1 << 8) 114 114 #define EMC_PWR_GATHER_DISABLE (2 << 8) 115 115 #define EMC_PWR_GATHER_ENABLE (3 << 8) 116 + 117 + enum emc_dram_type { 118 + DRAM_TYPE_RESERVED, 119 + DRAM_TYPE_DDR1, 120 + DRAM_TYPE_LPDDR2, 121 + DRAM_TYPE_DDR2, 122 + }; 116 123 117 124 static const u16 emc_timing_registers[] = { 118 125 EMC_RC, ··· 222 201 struct mutex rate_lock; 223 202 224 203 struct devfreq_simple_ondemand_data ondemand_data; 204 + 205 + /* memory chip identity information */ 206 + union lpddr2_basic_config4 basic_conf4; 207 + unsigned int manufacturer_id; 208 + unsigned int revision_id1; 209 + unsigned int revision_id2; 210 + 211 + bool mrr_error; 225 212 }; 226 213 227 214 static irqreturn_t tegra_emc_isr(int irq, void *data) ··· 426 397 if (!emc->timings) 427 398 return -ENOMEM; 428 399 429 - emc->num_timings = child_count; 430 400 timing = emc->timings; 431 401 432 402 for_each_child_of_node(node, child) { 403 + if (of_node_name_eq(child, "lpddr2")) 404 + continue; 405 + 433 406 err = load_one_timing_from_dt(emc, timing++, child); 434 407 if (err) { 435 408 of_node_put(child); 436 409 return err; 437 410 } 411 + 412 + emc->num_timings++; 438 413 } 439 414 440 415 sort(emc->timings, emc->num_timings, sizeof(*timing), cmp_timings, ··· 455 422 } 456 423 457 424 static struct device_node * 458 - tegra_emc_find_node_by_ram_code(struct device *dev) 425 + tegra_emc_find_node_by_ram_code(struct tegra_emc *emc) 459 426 { 427 + struct device *dev = emc->dev; 460 428 struct device_node *np; 461 429 u32 value, ram_code; 462 430 int err; 431 + 432 + if (emc->mrr_error) { 433 + dev_warn(dev, "memory timings skipped due to MRR error\n"); 434 + return NULL; 435 + } 463 436 464 437 if (of_get_child_count(dev->of_node) == 0) { 465 438 dev_info_once(dev, "device-tree doesn't have memory timings\n"); ··· 481 442 np = of_find_node_by_name(np, "emc-tables")) { 482 443 err = of_property_read_u32(np, "nvidia,ram-code", &value); 483 444 if (err || value != ram_code) { 484 - of_node_put(np); 485 - continue; 445 + struct device_node *lpddr2_np; 446 + bool cfg_mismatches = false; 447 + 448 + lpddr2_np = of_find_node_by_name(np, "lpddr2"); 449 + if (lpddr2_np) { 450 + const struct lpddr2_info *info; 451 + 452 + info = of_lpddr2_get_info(lpddr2_np, dev); 453 + if (info) { 454 + if (info->manufacturer_id >= 0 && 455 + info->manufacturer_id != emc->manufacturer_id) 456 + cfg_mismatches = true; 457 + 458 + if (info->revision_id1 >= 0 && 459 + info->revision_id1 != emc->revision_id1) 460 + cfg_mismatches = true; 461 + 462 + if (info->revision_id2 >= 0 && 463 + info->revision_id2 != emc->revision_id2) 464 + cfg_mismatches = true; 465 + 466 + if (info->density != emc->basic_conf4.density) 467 + cfg_mismatches = true; 468 + 469 + if (info->io_width != emc->basic_conf4.io_width) 470 + cfg_mismatches = true; 471 + 472 + if (info->arch_type != emc->basic_conf4.arch_type) 473 + cfg_mismatches = true; 474 + } else { 475 + dev_err(dev, "failed to parse %pOF\n", lpddr2_np); 476 + cfg_mismatches = true; 477 + } 478 + 479 + of_node_put(lpddr2_np); 480 + } else { 481 + cfg_mismatches = true; 482 + } 483 + 484 + if (cfg_mismatches) { 485 + of_node_put(np); 486 + continue; 487 + } 486 488 } 487 489 488 490 return np; ··· 535 455 return NULL; 536 456 } 537 457 458 + static int emc_read_lpddr_mode_register(struct tegra_emc *emc, 459 + unsigned int emem_dev, 460 + unsigned int register_addr, 461 + unsigned int *register_data) 462 + { 463 + u32 memory_dev = emem_dev + 1; 464 + u32 val, mr_mask = 0xff; 465 + int err; 466 + 467 + /* clear data-valid interrupt status */ 468 + writel_relaxed(EMC_MRR_DIVLD_INT, emc->regs + EMC_INTSTATUS); 469 + 470 + /* issue mode register read request */ 471 + val = FIELD_PREP(EMC_MRR_DEV_SELECTN, memory_dev); 472 + val |= FIELD_PREP(EMC_MRR_MRR_MA, register_addr); 473 + 474 + writel_relaxed(val, emc->regs + EMC_MRR); 475 + 476 + /* wait for the LPDDR2 data-valid interrupt */ 477 + err = readl_relaxed_poll_timeout_atomic(emc->regs + EMC_INTSTATUS, val, 478 + val & EMC_MRR_DIVLD_INT, 479 + 1, 100); 480 + if (err) { 481 + dev_err(emc->dev, "mode register %u read failed: %d\n", 482 + register_addr, err); 483 + emc->mrr_error = true; 484 + return err; 485 + } 486 + 487 + /* read out mode register data */ 488 + val = readl_relaxed(emc->regs + EMC_MRR); 489 + *register_data = FIELD_GET(EMC_MRR_MRR_DATA, val) & mr_mask; 490 + 491 + return 0; 492 + } 493 + 494 + static void emc_read_lpddr_sdram_info(struct tegra_emc *emc, 495 + unsigned int emem_dev, 496 + bool print_out) 497 + { 498 + /* these registers are standard for all LPDDR JEDEC memory chips */ 499 + emc_read_lpddr_mode_register(emc, emem_dev, 5, &emc->manufacturer_id); 500 + emc_read_lpddr_mode_register(emc, emem_dev, 6, &emc->revision_id1); 501 + emc_read_lpddr_mode_register(emc, emem_dev, 7, &emc->revision_id2); 502 + emc_read_lpddr_mode_register(emc, emem_dev, 8, &emc->basic_conf4.value); 503 + 504 + if (!print_out) 505 + return; 506 + 507 + dev_info(emc->dev, "SDRAM[dev%u]: manufacturer: 0x%x (%s) rev1: 0x%x rev2: 0x%x prefetch: S%u density: %uMbit iowidth: %ubit\n", 508 + emem_dev, emc->manufacturer_id, 509 + lpddr2_jedec_manufacturer(emc->manufacturer_id), 510 + emc->revision_id1, emc->revision_id2, 511 + 4 >> emc->basic_conf4.arch_type, 512 + 64 << emc->basic_conf4.density, 513 + 32 >> emc->basic_conf4.io_width); 514 + } 515 + 538 516 static int emc_setup_hw(struct tegra_emc *emc) 539 517 { 518 + u32 emc_cfg, emc_dbg, emc_fbio, emc_adr_cfg; 540 519 u32 intmask = EMC_REFRESH_OVERFLOW_INT; 541 - u32 emc_cfg, emc_dbg, emc_fbio; 520 + static bool print_sdram_info_once; 521 + enum emc_dram_type dram_type; 522 + const char *dram_type_str; 523 + unsigned int emem_numdev; 542 524 543 525 emc_cfg = readl_relaxed(emc->regs + EMC_CFG_2); 544 526 ··· 638 496 else 639 497 emc->dram_bus_width = 32; 640 498 641 - dev_info_once(emc->dev, "%ubit DRAM bus\n", emc->dram_bus_width); 499 + dram_type = FIELD_GET(EMC_FBIO_CFG5_DRAM_TYPE, emc_fbio); 500 + 501 + switch (dram_type) { 502 + case DRAM_TYPE_RESERVED: 503 + dram_type_str = "INVALID"; 504 + break; 505 + case DRAM_TYPE_DDR1: 506 + dram_type_str = "DDR1"; 507 + break; 508 + case DRAM_TYPE_LPDDR2: 509 + dram_type_str = "LPDDR2"; 510 + break; 511 + case DRAM_TYPE_DDR2: 512 + dram_type_str = "DDR2"; 513 + break; 514 + } 515 + 516 + emc_adr_cfg = readl_relaxed(emc->regs + EMC_ADR_CFG_0); 517 + emem_numdev = FIELD_GET(EMC_ADR_CFG_0_EMEM_NUMDEV, emc_adr_cfg) + 1; 518 + 519 + dev_info_once(emc->dev, "%ubit DRAM bus, %u %s %s attached\n", 520 + emc->dram_bus_width, emem_numdev, dram_type_str, 521 + emem_numdev == 2 ? "devices" : "device"); 522 + 523 + if (dram_type == DRAM_TYPE_LPDDR2) { 524 + while (emem_numdev--) 525 + emc_read_lpddr_sdram_info(emc, emem_numdev, 526 + !print_sdram_info_once); 527 + print_sdram_info_once = true; 528 + } 642 529 643 530 return 0; 644 531 } ··· 1220 1049 emc->clk_nb.notifier_call = tegra_emc_clk_change_notify; 1221 1050 emc->dev = &pdev->dev; 1222 1051 1223 - np = tegra_emc_find_node_by_ram_code(&pdev->dev); 1224 - if (np) { 1225 - err = tegra_emc_load_timings_from_dt(emc, np); 1226 - of_node_put(np); 1227 - if (err) 1228 - return err; 1229 - } 1230 - 1231 1052 emc->regs = devm_platform_ioremap_resource(pdev, 0); 1232 1053 if (IS_ERR(emc->regs)) 1233 1054 return PTR_ERR(emc->regs); ··· 1227 1064 err = emc_setup_hw(emc); 1228 1065 if (err) 1229 1066 return err; 1067 + 1068 + np = tegra_emc_find_node_by_ram_code(emc); 1069 + if (np) { 1070 + err = tegra_emc_load_timings_from_dt(emc, np); 1071 + of_node_put(np); 1072 + if (err) 1073 + return err; 1074 + } 1230 1075 1231 1076 err = devm_request_irq(&pdev->dev, irq, tegra_emc_isr, 0, 1232 1077 dev_name(&pdev->dev), emc); ··· 1288 1117 1289 1118 MODULE_AUTHOR("Dmitry Osipenko <digetx@gmail.com>"); 1290 1119 MODULE_DESCRIPTION("NVIDIA Tegra20 EMC driver"); 1120 + MODULE_SOFTDEP("pre: governor_simpleondemand"); 1291 1121 MODULE_LICENSE("GPL v2");