.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * OpenFirmware helpers for memory drivers |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (C) 2012 Texas Instruments, Inc. |
---|
5 | | - * |
---|
6 | | - * This program is free software; you can redistribute it and/or modify |
---|
7 | | - * it under the terms of the GNU General Public License as published by |
---|
8 | | - * the Free Software Foundation; either version 2 of the License, or |
---|
9 | | - * (at your option) any later version. |
---|
| 6 | + * Copyright (C) 2019 Samsung Electronics Co., Ltd. |
---|
| 7 | + * Copyright (C) 2020 Krzysztof Kozlowski <krzk@kernel.org> |
---|
10 | 8 | */ |
---|
11 | 9 | |
---|
12 | 10 | #include <linux/device.h> |
---|
13 | | -#include <linux/platform_device.h> |
---|
14 | | -#include <linux/list.h> |
---|
15 | 11 | #include <linux/of.h> |
---|
16 | 12 | #include <linux/gfp.h> |
---|
17 | | -#include <memory/jedec_ddr.h> |
---|
18 | 13 | #include <linux/export.h> |
---|
| 14 | + |
---|
| 15 | +#include "jedec_ddr.h" |
---|
19 | 16 | #include "of_memory.h" |
---|
20 | 17 | |
---|
21 | 18 | /** |
---|
22 | 19 | * of_get_min_tck() - extract min timing values for ddr |
---|
23 | 20 | * @np: pointer to ddr device tree node |
---|
24 | | - * @device: device requesting for min timing values |
---|
| 21 | + * @dev: device requesting for min timing values |
---|
25 | 22 | * |
---|
26 | 23 | * Populates the lpddr2_min_tck structure by extracting data |
---|
27 | 24 | * from device tree node. Returns a pointer to the populated |
---|
.. | .. |
---|
29 | 26 | * default min timings provided by JEDEC. |
---|
30 | 27 | */ |
---|
31 | 28 | const struct lpddr2_min_tck *of_get_min_tck(struct device_node *np, |
---|
32 | | - struct device *dev) |
---|
| 29 | + struct device *dev) |
---|
33 | 30 | { |
---|
34 | 31 | int ret = 0; |
---|
35 | 32 | struct lpddr2_min_tck *min; |
---|
.. | .. |
---|
58 | 55 | return min; |
---|
59 | 56 | |
---|
60 | 57 | default_min_tck: |
---|
61 | | - dev_warn(dev, "%s: using default min-tck values\n", __func__); |
---|
| 58 | + dev_warn(dev, "Using default min-tck values\n"); |
---|
62 | 59 | return &lpddr2_jedec_min_tck; |
---|
63 | 60 | } |
---|
64 | 61 | EXPORT_SYMBOL(of_get_min_tck); |
---|
65 | 62 | |
---|
66 | 63 | static int of_do_get_timings(struct device_node *np, |
---|
67 | | - struct lpddr2_timings *tim) |
---|
| 64 | + struct lpddr2_timings *tim) |
---|
68 | 65 | { |
---|
69 | 66 | int ret; |
---|
70 | 67 | |
---|
.. | .. |
---|
86 | 83 | ret |= of_property_read_u32(np, "tZQinit", &tim->tZQinit); |
---|
87 | 84 | ret |= of_property_read_u32(np, "tRAS-max-ns", &tim->tRAS_max_ns); |
---|
88 | 85 | ret |= of_property_read_u32(np, "tDQSCK-max-derated", |
---|
89 | | - &tim->tDQSCK_max_derated); |
---|
| 86 | + &tim->tDQSCK_max_derated); |
---|
90 | 87 | |
---|
91 | 88 | return ret; |
---|
92 | 89 | } |
---|
.. | .. |
---|
105 | 102 | * while populating, returns default timings provided by JEDEC. |
---|
106 | 103 | */ |
---|
107 | 104 | const struct lpddr2_timings *of_get_ddr_timings(struct device_node *np_ddr, |
---|
108 | | - struct device *dev, u32 device_type, u32 *nr_frequencies) |
---|
| 105 | + struct device *dev, |
---|
| 106 | + u32 device_type, |
---|
| 107 | + u32 *nr_frequencies) |
---|
109 | 108 | { |
---|
110 | 109 | struct lpddr2_timings *timings = NULL; |
---|
111 | 110 | u32 arr_sz = 0, i = 0; |
---|
.. | .. |
---|
118 | 117 | tim_compat = "jedec,lpddr2-timings"; |
---|
119 | 118 | break; |
---|
120 | 119 | default: |
---|
121 | | - dev_warn(dev, "%s: un-supported memory type\n", __func__); |
---|
| 120 | + dev_warn(dev, "Unsupported memory type\n"); |
---|
122 | 121 | } |
---|
123 | 122 | |
---|
124 | 123 | for_each_child_of_node(np_ddr, np_tim) |
---|
.. | .. |
---|
135 | 134 | for_each_child_of_node(np_ddr, np_tim) { |
---|
136 | 135 | if (of_device_is_compatible(np_tim, tim_compat)) { |
---|
137 | 136 | if (of_do_get_timings(np_tim, &timings[i])) { |
---|
| 137 | + of_node_put(np_tim); |
---|
138 | 138 | devm_kfree(dev, timings); |
---|
139 | 139 | goto default_timings; |
---|
140 | 140 | } |
---|
.. | .. |
---|
147 | 147 | return timings; |
---|
148 | 148 | |
---|
149 | 149 | default_timings: |
---|
150 | | - dev_warn(dev, "%s: using default timings\n", __func__); |
---|
| 150 | + dev_warn(dev, "Using default memory timings\n"); |
---|
151 | 151 | *nr_frequencies = ARRAY_SIZE(lpddr2_jedec_timings); |
---|
152 | 152 | return lpddr2_jedec_timings; |
---|
153 | 153 | } |
---|
154 | 154 | EXPORT_SYMBOL(of_get_ddr_timings); |
---|
| 155 | + |
---|
| 156 | +/** |
---|
| 157 | + * of_lpddr3_get_min_tck() - extract min timing values for lpddr3 |
---|
| 158 | + * @np: pointer to ddr device tree node |
---|
| 159 | + * @dev: device requesting for min timing values |
---|
| 160 | + * |
---|
| 161 | + * Populates the lpddr3_min_tck structure by extracting data |
---|
| 162 | + * from device tree node. Returns a pointer to the populated |
---|
| 163 | + * structure. If any error in populating the structure, returns NULL. |
---|
| 164 | + */ |
---|
| 165 | +const struct lpddr3_min_tck *of_lpddr3_get_min_tck(struct device_node *np, |
---|
| 166 | + struct device *dev) |
---|
| 167 | +{ |
---|
| 168 | + int ret = 0; |
---|
| 169 | + struct lpddr3_min_tck *min; |
---|
| 170 | + |
---|
| 171 | + min = devm_kzalloc(dev, sizeof(*min), GFP_KERNEL); |
---|
| 172 | + if (!min) |
---|
| 173 | + goto default_min_tck; |
---|
| 174 | + |
---|
| 175 | + ret |= of_property_read_u32(np, "tRFC-min-tck", &min->tRFC); |
---|
| 176 | + ret |= of_property_read_u32(np, "tRRD-min-tck", &min->tRRD); |
---|
| 177 | + ret |= of_property_read_u32(np, "tRPab-min-tck", &min->tRPab); |
---|
| 178 | + ret |= of_property_read_u32(np, "tRPpb-min-tck", &min->tRPpb); |
---|
| 179 | + ret |= of_property_read_u32(np, "tRCD-min-tck", &min->tRCD); |
---|
| 180 | + ret |= of_property_read_u32(np, "tRC-min-tck", &min->tRC); |
---|
| 181 | + ret |= of_property_read_u32(np, "tRAS-min-tck", &min->tRAS); |
---|
| 182 | + ret |= of_property_read_u32(np, "tWTR-min-tck", &min->tWTR); |
---|
| 183 | + ret |= of_property_read_u32(np, "tWR-min-tck", &min->tWR); |
---|
| 184 | + ret |= of_property_read_u32(np, "tRTP-min-tck", &min->tRTP); |
---|
| 185 | + ret |= of_property_read_u32(np, "tW2W-C2C-min-tck", &min->tW2W_C2C); |
---|
| 186 | + ret |= of_property_read_u32(np, "tR2R-C2C-min-tck", &min->tR2R_C2C); |
---|
| 187 | + ret |= of_property_read_u32(np, "tWL-min-tck", &min->tWL); |
---|
| 188 | + ret |= of_property_read_u32(np, "tDQSCK-min-tck", &min->tDQSCK); |
---|
| 189 | + ret |= of_property_read_u32(np, "tRL-min-tck", &min->tRL); |
---|
| 190 | + ret |= of_property_read_u32(np, "tFAW-min-tck", &min->tFAW); |
---|
| 191 | + ret |= of_property_read_u32(np, "tXSR-min-tck", &min->tXSR); |
---|
| 192 | + ret |= of_property_read_u32(np, "tXP-min-tck", &min->tXP); |
---|
| 193 | + ret |= of_property_read_u32(np, "tCKE-min-tck", &min->tCKE); |
---|
| 194 | + ret |= of_property_read_u32(np, "tCKESR-min-tck", &min->tCKESR); |
---|
| 195 | + ret |= of_property_read_u32(np, "tMRD-min-tck", &min->tMRD); |
---|
| 196 | + |
---|
| 197 | + if (ret) { |
---|
| 198 | + dev_warn(dev, "Errors while parsing min-tck values\n"); |
---|
| 199 | + devm_kfree(dev, min); |
---|
| 200 | + goto default_min_tck; |
---|
| 201 | + } |
---|
| 202 | + |
---|
| 203 | + return min; |
---|
| 204 | + |
---|
| 205 | +default_min_tck: |
---|
| 206 | + dev_warn(dev, "Using default min-tck values\n"); |
---|
| 207 | + return NULL; |
---|
| 208 | +} |
---|
| 209 | +EXPORT_SYMBOL(of_lpddr3_get_min_tck); |
---|
| 210 | + |
---|
| 211 | +static int of_lpddr3_do_get_timings(struct device_node *np, |
---|
| 212 | + struct lpddr3_timings *tim) |
---|
| 213 | +{ |
---|
| 214 | + int ret; |
---|
| 215 | + |
---|
| 216 | + /* The 'reg' param required since DT has changed, used as 'max-freq' */ |
---|
| 217 | + ret = of_property_read_u32(np, "reg", &tim->max_freq); |
---|
| 218 | + ret |= of_property_read_u32(np, "min-freq", &tim->min_freq); |
---|
| 219 | + ret |= of_property_read_u32(np, "tRFC", &tim->tRFC); |
---|
| 220 | + ret |= of_property_read_u32(np, "tRRD", &tim->tRRD); |
---|
| 221 | + ret |= of_property_read_u32(np, "tRPab", &tim->tRPab); |
---|
| 222 | + ret |= of_property_read_u32(np, "tRPpb", &tim->tRPpb); |
---|
| 223 | + ret |= of_property_read_u32(np, "tRCD", &tim->tRCD); |
---|
| 224 | + ret |= of_property_read_u32(np, "tRC", &tim->tRC); |
---|
| 225 | + ret |= of_property_read_u32(np, "tRAS", &tim->tRAS); |
---|
| 226 | + ret |= of_property_read_u32(np, "tWTR", &tim->tWTR); |
---|
| 227 | + ret |= of_property_read_u32(np, "tWR", &tim->tWR); |
---|
| 228 | + ret |= of_property_read_u32(np, "tRTP", &tim->tRTP); |
---|
| 229 | + ret |= of_property_read_u32(np, "tW2W-C2C", &tim->tW2W_C2C); |
---|
| 230 | + ret |= of_property_read_u32(np, "tR2R-C2C", &tim->tR2R_C2C); |
---|
| 231 | + ret |= of_property_read_u32(np, "tFAW", &tim->tFAW); |
---|
| 232 | + ret |= of_property_read_u32(np, "tXSR", &tim->tXSR); |
---|
| 233 | + ret |= of_property_read_u32(np, "tXP", &tim->tXP); |
---|
| 234 | + ret |= of_property_read_u32(np, "tCKE", &tim->tCKE); |
---|
| 235 | + ret |= of_property_read_u32(np, "tCKESR", &tim->tCKESR); |
---|
| 236 | + ret |= of_property_read_u32(np, "tMRD", &tim->tMRD); |
---|
| 237 | + |
---|
| 238 | + return ret; |
---|
| 239 | +} |
---|
| 240 | + |
---|
| 241 | +/** |
---|
| 242 | + * of_lpddr3_get_ddr_timings() - extracts the lpddr3 timings and updates no of |
---|
| 243 | + * frequencies available. |
---|
| 244 | + * @np_ddr: Pointer to ddr device tree node |
---|
| 245 | + * @dev: Device requesting for ddr timings |
---|
| 246 | + * @device_type: Type of ddr |
---|
| 247 | + * @nr_frequencies: No of frequencies available for ddr |
---|
| 248 | + * (updated by this function) |
---|
| 249 | + * |
---|
| 250 | + * Populates lpddr3_timings structure by extracting data from device |
---|
| 251 | + * tree node. Returns pointer to populated structure. If any error |
---|
| 252 | + * while populating, returns NULL. |
---|
| 253 | + */ |
---|
| 254 | +const struct lpddr3_timings |
---|
| 255 | +*of_lpddr3_get_ddr_timings(struct device_node *np_ddr, struct device *dev, |
---|
| 256 | + u32 device_type, u32 *nr_frequencies) |
---|
| 257 | +{ |
---|
| 258 | + struct lpddr3_timings *timings = NULL; |
---|
| 259 | + u32 arr_sz = 0, i = 0; |
---|
| 260 | + struct device_node *np_tim; |
---|
| 261 | + char *tim_compat = NULL; |
---|
| 262 | + |
---|
| 263 | + switch (device_type) { |
---|
| 264 | + case DDR_TYPE_LPDDR3: |
---|
| 265 | + tim_compat = "jedec,lpddr3-timings"; |
---|
| 266 | + break; |
---|
| 267 | + default: |
---|
| 268 | + dev_warn(dev, "Unsupported memory type\n"); |
---|
| 269 | + } |
---|
| 270 | + |
---|
| 271 | + for_each_child_of_node(np_ddr, np_tim) |
---|
| 272 | + if (of_device_is_compatible(np_tim, tim_compat)) |
---|
| 273 | + arr_sz++; |
---|
| 274 | + |
---|
| 275 | + if (arr_sz) |
---|
| 276 | + timings = devm_kcalloc(dev, arr_sz, sizeof(*timings), |
---|
| 277 | + GFP_KERNEL); |
---|
| 278 | + |
---|
| 279 | + if (!timings) |
---|
| 280 | + goto default_timings; |
---|
| 281 | + |
---|
| 282 | + for_each_child_of_node(np_ddr, np_tim) { |
---|
| 283 | + if (of_device_is_compatible(np_tim, tim_compat)) { |
---|
| 284 | + if (of_lpddr3_do_get_timings(np_tim, &timings[i])) { |
---|
| 285 | + devm_kfree(dev, timings); |
---|
| 286 | + of_node_put(np_tim); |
---|
| 287 | + goto default_timings; |
---|
| 288 | + } |
---|
| 289 | + i++; |
---|
| 290 | + } |
---|
| 291 | + } |
---|
| 292 | + |
---|
| 293 | + *nr_frequencies = arr_sz; |
---|
| 294 | + |
---|
| 295 | + return timings; |
---|
| 296 | + |
---|
| 297 | +default_timings: |
---|
| 298 | + dev_warn(dev, "Failed to get timings\n"); |
---|
| 299 | + *nr_frequencies = 0; |
---|
| 300 | + return NULL; |
---|
| 301 | +} |
---|
| 302 | +EXPORT_SYMBOL(of_lpddr3_get_ddr_timings); |
---|