Skip to content

Commit 976897d

Browse files
Lukasz Lubakrzk
authored andcommitted
memory: Extend of_memory with LPDDR3 support
Add AC timings information needed to support LPDDR3 and memory controllers along with helpers to obtain it. These will be necessary for upcoming Exynos5422 Dynamic Memory Controller driver. Signed-off-by: Lukasz Luba <l.luba@partner.samsung.com> Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
1 parent 54ecb8f commit 976897d

3 files changed

Lines changed: 228 additions & 0 deletions

File tree

‎drivers/memory/jedec_ddr.h‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#define DDR_TYPE_LPDDR2_S4 3
3030
#define DDR_TYPE_LPDDR2_S2 4
3131
#define DDR_TYPE_LPDDR2_NVM 5
32+
#define DDR_TYPE_LPDDR3 6
3233

3334
/* DDR IO width */
3435
#define DDR_IO_WIDTH_4 1
@@ -169,4 +170,64 @@ extern const struct lpddr2_timings
169170
lpddr2_jedec_timings[NUM_DDR_TIMING_TABLE_ENTRIES];
170171
extern const struct lpddr2_min_tck lpddr2_jedec_min_tck;
171172

173+
/*
174+
* Structure for timings for LPDDR3 based on LPDDR2 plus additional fields.
175+
* All parameters are in pico seconds(ps) excluding max_freq, min_freq which
176+
* are in Hz.
177+
*/
178+
struct lpddr3_timings {
179+
u32 max_freq;
180+
u32 min_freq;
181+
u32 tRFC;
182+
u32 tRRD;
183+
u32 tRPab;
184+
u32 tRPpb;
185+
u32 tRCD;
186+
u32 tRC;
187+
u32 tRAS;
188+
u32 tWTR;
189+
u32 tWR;
190+
u32 tRTP;
191+
u32 tW2W_C2C;
192+
u32 tR2R_C2C;
193+
u32 tWL;
194+
u32 tDQSCK;
195+
u32 tRL;
196+
u32 tFAW;
197+
u32 tXSR;
198+
u32 tXP;
199+
u32 tCKE;
200+
u32 tCKESR;
201+
u32 tMRD;
202+
};
203+
204+
/*
205+
* Min value for some parameters in terms of number of tCK cycles(nCK)
206+
* Please set to zero parameters that are not valid for a given memory
207+
* type
208+
*/
209+
struct lpddr3_min_tck {
210+
u32 tRFC;
211+
u32 tRRD;
212+
u32 tRPab;
213+
u32 tRPpb;
214+
u32 tRCD;
215+
u32 tRC;
216+
u32 tRAS;
217+
u32 tWTR;
218+
u32 tWR;
219+
u32 tRTP;
220+
u32 tW2W_C2C;
221+
u32 tR2R_C2C;
222+
u32 tWL;
223+
u32 tDQSCK;
224+
u32 tRL;
225+
u32 tFAW;
226+
u32 tXSR;
227+
u32 tXP;
228+
u32 tCKE;
229+
u32 tCKESR;
230+
u32 tMRD;
231+
};
232+
172233
#endif /* __JEDEC_DDR_H */

‎drivers/memory/of_memory.c‎

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* OpenFirmware helpers for memory drivers
44
*
55
* Copyright (C) 2012 Texas Instruments, Inc.
6+
* Copyright (C) 2019 Samsung Electronics Co., Ltd.
67
*/
78

89
#include <linux/device.h>
@@ -149,3 +150,151 @@ const struct lpddr2_timings *of_get_ddr_timings(struct device_node *np_ddr,
149150
return lpddr2_jedec_timings;
150151
}
151152
EXPORT_SYMBOL(of_get_ddr_timings);
153+
154+
/**
155+
* of_lpddr3_get_min_tck() - extract min timing values for lpddr3
156+
* @np: pointer to ddr device tree node
157+
* @device: device requesting for min timing values
158+
*
159+
* Populates the lpddr3_min_tck structure by extracting data
160+
* from device tree node. Returns a pointer to the populated
161+
* structure. If any error in populating the structure, returns NULL.
162+
*/
163+
const struct lpddr3_min_tck *of_lpddr3_get_min_tck(struct device_node *np,
164+
struct device *dev)
165+
{
166+
int ret = 0;
167+
struct lpddr3_min_tck *min;
168+
169+
min = devm_kzalloc(dev, sizeof(*min), GFP_KERNEL);
170+
if (!min)
171+
goto default_min_tck;
172+
173+
ret |= of_property_read_u32(np, "tRFC-min-tck", &min->tRFC);
174+
ret |= of_property_read_u32(np, "tRRD-min-tck", &min->tRRD);
175+
ret |= of_property_read_u32(np, "tRPab-min-tck", &min->tRPab);
176+
ret |= of_property_read_u32(np, "tRPpb-min-tck", &min->tRPpb);
177+
ret |= of_property_read_u32(np, "tRCD-min-tck", &min->tRCD);
178+
ret |= of_property_read_u32(np, "tRC-min-tck", &min->tRC);
179+
ret |= of_property_read_u32(np, "tRAS-min-tck", &min->tRAS);
180+
ret |= of_property_read_u32(np, "tWTR-min-tck", &min->tWTR);
181+
ret |= of_property_read_u32(np, "tWR-min-tck", &min->tWR);
182+
ret |= of_property_read_u32(np, "tRTP-min-tck", &min->tRTP);
183+
ret |= of_property_read_u32(np, "tW2W-C2C-min-tck", &min->tW2W_C2C);
184+
ret |= of_property_read_u32(np, "tR2R-C2C-min-tck", &min->tR2R_C2C);
185+
ret |= of_property_read_u32(np, "tWL-min-tck", &min->tWL);
186+
ret |= of_property_read_u32(np, "tDQSCK-min-tck", &min->tDQSCK);
187+
ret |= of_property_read_u32(np, "tRL-min-tck", &min->tRL);
188+
ret |= of_property_read_u32(np, "tFAW-min-tck", &min->tFAW);
189+
ret |= of_property_read_u32(np, "tXSR-min-tck", &min->tXSR);
190+
ret |= of_property_read_u32(np, "tXP-min-tck", &min->tXP);
191+
ret |= of_property_read_u32(np, "tCKE-min-tck", &min->tCKE);
192+
ret |= of_property_read_u32(np, "tCKESR-min-tck", &min->tCKESR);
193+
ret |= of_property_read_u32(np, "tMRD-min-tck", &min->tMRD);
194+
195+
if (ret) {
196+
dev_warn(dev, "%s: errors while parsing min-tck values\n",
197+
__func__);
198+
devm_kfree(dev, min);
199+
goto default_min_tck;
200+
}
201+
202+
return min;
203+
204+
default_min_tck:
205+
dev_warn(dev, "%s: using default min-tck values\n", __func__);
206+
return NULL;
207+
}
208+
EXPORT_SYMBOL(of_lpddr3_get_min_tck);
209+
210+
static int of_lpddr3_do_get_timings(struct device_node *np,
211+
struct lpddr3_timings *tim)
212+
{
213+
int ret;
214+
215+
/* The 'reg' param required since DT has changed, used as 'max-freq' */
216+
ret = of_property_read_u32(np, "reg", &tim->max_freq);
217+
ret |= of_property_read_u32(np, "min-freq", &tim->min_freq);
218+
ret |= of_property_read_u32(np, "tRFC", &tim->tRFC);
219+
ret |= of_property_read_u32(np, "tRRD", &tim->tRRD);
220+
ret |= of_property_read_u32(np, "tRPab", &tim->tRPab);
221+
ret |= of_property_read_u32(np, "tRPpb", &tim->tRPpb);
222+
ret |= of_property_read_u32(np, "tRCD", &tim->tRCD);
223+
ret |= of_property_read_u32(np, "tRC", &tim->tRC);
224+
ret |= of_property_read_u32(np, "tRAS", &tim->tRAS);
225+
ret |= of_property_read_u32(np, "tWTR", &tim->tWTR);
226+
ret |= of_property_read_u32(np, "tWR", &tim->tWR);
227+
ret |= of_property_read_u32(np, "tRTP", &tim->tRTP);
228+
ret |= of_property_read_u32(np, "tW2W-C2C", &tim->tW2W_C2C);
229+
ret |= of_property_read_u32(np, "tR2R-C2C", &tim->tR2R_C2C);
230+
ret |= of_property_read_u32(np, "tFAW", &tim->tFAW);
231+
ret |= of_property_read_u32(np, "tXSR", &tim->tXSR);
232+
ret |= of_property_read_u32(np, "tXP", &tim->tXP);
233+
ret |= of_property_read_u32(np, "tCKE", &tim->tCKE);
234+
ret |= of_property_read_u32(np, "tCKESR", &tim->tCKESR);
235+
ret |= of_property_read_u32(np, "tMRD", &tim->tMRD);
236+
237+
return ret;
238+
}
239+
240+
/**
241+
* of_lpddr3_get_ddr_timings() - extracts the lpddr3 timings and updates no of
242+
* frequencies available.
243+
* @np_ddr: Pointer to ddr device tree node
244+
* @dev: Device requesting for ddr timings
245+
* @device_type: Type of ddr
246+
* @nr_frequencies: No of frequencies available for ddr
247+
* (updated by this function)
248+
*
249+
* Populates lpddr3_timings structure by extracting data from device
250+
* tree node. Returns pointer to populated structure. If any error
251+
* while populating, returns NULL.
252+
*/
253+
const struct lpddr3_timings
254+
*of_lpddr3_get_ddr_timings(struct device_node *np_ddr, struct device *dev,
255+
u32 device_type, u32 *nr_frequencies)
256+
{
257+
struct lpddr3_timings *timings = NULL;
258+
u32 arr_sz = 0, i = 0;
259+
struct device_node *np_tim;
260+
char *tim_compat = NULL;
261+
262+
switch (device_type) {
263+
case DDR_TYPE_LPDDR3:
264+
tim_compat = "jedec,lpddr3-timings";
265+
break;
266+
default:
267+
dev_warn(dev, "%s: un-supported memory type\n", __func__);
268+
}
269+
270+
for_each_child_of_node(np_ddr, np_tim)
271+
if (of_device_is_compatible(np_tim, tim_compat))
272+
arr_sz++;
273+
274+
if (arr_sz)
275+
timings = devm_kcalloc(dev, arr_sz, sizeof(*timings),
276+
GFP_KERNEL);
277+
278+
if (!timings)
279+
goto default_timings;
280+
281+
for_each_child_of_node(np_ddr, np_tim) {
282+
if (of_device_is_compatible(np_tim, tim_compat)) {
283+
if (of_lpddr3_do_get_timings(np_tim, &timings[i])) {
284+
devm_kfree(dev, timings);
285+
goto default_timings;
286+
}
287+
i++;
288+
}
289+
}
290+
291+
*nr_frequencies = arr_sz;
292+
293+
return timings;
294+
295+
default_timings:
296+
dev_warn(dev, "%s: failed to get timings\n", __func__);
297+
*nr_frequencies = 0;
298+
return NULL;
299+
}
300+
EXPORT_SYMBOL(of_lpddr3_get_ddr_timings);

‎drivers/memory/of_memory.h‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ extern const struct lpddr2_min_tck *of_get_min_tck(struct device_node *np,
1414
extern const struct lpddr2_timings
1515
*of_get_ddr_timings(struct device_node *np_ddr, struct device *dev,
1616
u32 device_type, u32 *nr_frequencies);
17+
extern const struct lpddr3_min_tck
18+
*of_lpddr3_get_min_tck(struct device_node *np, struct device *dev);
19+
extern const struct lpddr3_timings
20+
*of_lpddr3_get_ddr_timings(struct device_node *np_ddr,
21+
struct device *dev, u32 device_type, u32 *nr_frequencies);
1722
#else
1823
static inline const struct lpddr2_min_tck
1924
*of_get_min_tck(struct device_node *np, struct device *dev)
@@ -27,6 +32,19 @@ static inline const struct lpddr2_timings
2732
{
2833
return NULL;
2934
}
35+
36+
static inline const struct lpddr3_min_tck
37+
*of_lpddr3_get_min_tck(struct device_node *np, struct device *dev)
38+
{
39+
return NULL;
40+
}
41+
42+
static inline const struct lpddr3_timings
43+
*of_lpddr3_get_ddr_timings(struct device_node *np_ddr,
44+
struct device *dev, u32 device_type, u32 *nr_frequencies)
45+
{
46+
return NULL;
47+
}
3048
#endif /* CONFIG_OF && CONFIG_DDR */
3149

3250
#endif /* __LINUX_MEMORY_OF_REG_ */

0 commit comments

Comments
 (0)