Skip to content

Commit 2c7b585

Browse files
bastien-curutchetkrzk
authored andcommitted
memory: ti-aemif: Create aemif_check_cs_timings()
aemif_calc_rate() checks the validity of a new computed timing against a 'max' value given as input. This isn't convenient if we want to check the CS timing configuration somewhere else in the code. Wrap the verification of all the chip select's timing configuration into a single function to ease its exportation in upcoming patches. Remove the validity check from aemif_calc_rate(). Also remove the no longer used 'max' input and change the return type to u32. Remove the check of the aemif_calc_rate()'s return value during device-tree parsing as aemif_calc_rate() can't fail anymore. Signed-off-by: Bastien Curutchet <[email protected]> Reviewed-by: Miquel Raynal <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Krzysztof Kozlowski <[email protected]>
1 parent 30b4da6 commit 2c7b585

File tree

1 file changed

+51
-60
lines changed

1 file changed

+51
-60
lines changed

drivers/memory/ti-aemif.c

Lines changed: 51 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -133,18 +133,48 @@ struct aemif_device {
133133
struct aemif_cs_data cs_data[NUM_CS];
134134
};
135135

136+
/**
137+
* aemif_check_cs_timings() - Check the validity of a CS timing configuration.
138+
* @timings: timings configuration
139+
*
140+
* @return: 0 if the timing configuration is valid, negative error number otherwise.
141+
*/
142+
static int aemif_check_cs_timings(struct aemif_cs_timings *timings)
143+
{
144+
if (timings->ta > TA_MAX)
145+
return -EINVAL;
146+
147+
if (timings->rhold > RHOLD_MAX)
148+
return -EINVAL;
149+
150+
if (timings->rstrobe > RSTROBE_MAX)
151+
return -EINVAL;
152+
153+
if (timings->rsetup > RSETUP_MAX)
154+
return -EINVAL;
155+
156+
if (timings->whold > WHOLD_MAX)
157+
return -EINVAL;
158+
159+
if (timings->wstrobe > WSTROBE_MAX)
160+
return -EINVAL;
161+
162+
if (timings->wsetup > WSETUP_MAX)
163+
return -EINVAL;
164+
165+
return 0;
166+
}
167+
136168
/**
137169
* aemif_calc_rate - calculate timing data.
138170
* @pdev: platform device to calculate for
139171
* @wanted: The cycle time needed in nanoseconds.
140172
* @clk: The input clock rate in kHz.
141-
* @max: The maximum divider value that can be programmed.
142173
*
143-
* On success, returns the calculated timing value minus 1 for easy
144-
* programming into AEMIF timing registers, else negative errno.
174+
* @return: the calculated timing value minus 1 for easy
175+
* programming into AEMIF timing registers.
145176
*/
146-
static int aemif_calc_rate(struct platform_device *pdev, int wanted,
147-
unsigned long clk, int max)
177+
static u32 aemif_calc_rate(struct platform_device *pdev, int wanted, unsigned long clk)
148178
{
149179
int result;
150180

@@ -157,10 +187,6 @@ static int aemif_calc_rate(struct platform_device *pdev, int wanted,
157187
if (result < 0)
158188
result = 0;
159189

160-
/* ... But configuring tighter timings is not an option. */
161-
else if (result > max)
162-
result = -EINVAL;
163-
164190
return result;
165191
}
166192

@@ -250,7 +276,6 @@ static int of_aemif_parse_abus_config(struct platform_device *pdev,
250276
struct aemif_device *aemif = platform_get_drvdata(pdev);
251277
unsigned long clk_rate = aemif->clk_rate;
252278
struct aemif_cs_data *data;
253-
int ret;
254279
u32 cs;
255280
u32 val;
256281

@@ -276,68 +301,34 @@ static int of_aemif_parse_abus_config(struct platform_device *pdev,
276301
aemif_get_hw_params(pdev, aemif->num_cs++);
277302

278303
/* override the values from device node */
279-
if (!of_property_read_u32(np, "ti,cs-min-turnaround-ns", &val)) {
280-
ret = aemif_calc_rate(pdev, val, clk_rate, TA_MAX);
281-
if (ret < 0)
282-
return ret;
283-
284-
data->timings.ta = ret;
285-
}
304+
if (!of_property_read_u32(np, "ti,cs-min-turnaround-ns", &val))
305+
data->timings.ta = aemif_calc_rate(pdev, val, clk_rate);
286306

287-
if (!of_property_read_u32(np, "ti,cs-read-hold-ns", &val)) {
288-
ret = aemif_calc_rate(pdev, val, clk_rate, RHOLD_MAX);
289-
if (ret < 0)
290-
return ret;
291-
292-
data->timings.rhold = ret;
293-
}
307+
if (!of_property_read_u32(np, "ti,cs-read-hold-ns", &val))
308+
data->timings.rhold = aemif_calc_rate(pdev, val, clk_rate);
294309

295-
if (!of_property_read_u32(np, "ti,cs-read-strobe-ns", &val)) {
296-
ret = aemif_calc_rate(pdev, val, clk_rate, RSTROBE_MAX);
297-
if (ret < 0)
298-
return ret;
310+
if (!of_property_read_u32(np, "ti,cs-read-strobe-ns", &val))
311+
data->timings.rstrobe = aemif_calc_rate(pdev, val, clk_rate);
299312

300-
data->timings.rstrobe = ret;
301-
}
313+
if (!of_property_read_u32(np, "ti,cs-read-setup-ns", &val))
314+
data->timings.rsetup = aemif_calc_rate(pdev, val, clk_rate);
302315

303-
if (!of_property_read_u32(np, "ti,cs-read-setup-ns", &val)) {
304-
ret = aemif_calc_rate(pdev, val, clk_rate, RSETUP_MAX);
305-
if (ret < 0)
306-
return ret;
316+
if (!of_property_read_u32(np, "ti,cs-write-hold-ns", &val))
317+
data->timings.whold = aemif_calc_rate(pdev, val, clk_rate);
307318

308-
data->timings.rsetup = ret;
309-
}
319+
if (!of_property_read_u32(np, "ti,cs-write-strobe-ns", &val))
320+
data->timings.wstrobe = aemif_calc_rate(pdev, val, clk_rate);
310321

311-
if (!of_property_read_u32(np, "ti,cs-write-hold-ns", &val)) {
312-
ret = aemif_calc_rate(pdev, val, clk_rate, WHOLD_MAX);
313-
if (ret < 0)
314-
return ret;
315-
316-
data->timings.whold = ret;
317-
}
318-
319-
if (!of_property_read_u32(np, "ti,cs-write-strobe-ns", &val)) {
320-
ret = aemif_calc_rate(pdev, val, clk_rate, WSTROBE_MAX);
321-
if (ret < 0)
322-
return ret;
323-
324-
data->timings.wstrobe = ret;
325-
}
326-
327-
if (!of_property_read_u32(np, "ti,cs-write-setup-ns", &val)) {
328-
ret = aemif_calc_rate(pdev, val, clk_rate, WSETUP_MAX);
329-
if (ret < 0)
330-
return ret;
331-
332-
data->timings.wsetup = ret;
333-
}
322+
if (!of_property_read_u32(np, "ti,cs-write-setup-ns", &val))
323+
data->timings.wsetup = aemif_calc_rate(pdev, val, clk_rate);
334324

335325
if (!of_property_read_u32(np, "ti,cs-bus-width", &val))
336326
if (val == 16)
337327
data->asize = 1;
338328
data->enable_ew = of_property_read_bool(np, "ti,cs-extended-wait-mode");
339329
data->enable_ss = of_property_read_bool(np, "ti,cs-select-strobe-mode");
340-
return 0;
330+
331+
return aemif_check_cs_timings(&data->timings);
341332
}
342333

343334
static const struct of_device_id aemif_of_match[] = {

0 commit comments

Comments
 (0)