@@ -133,18 +133,48 @@ struct aemif_device {
133
133
struct aemif_cs_data cs_data [NUM_CS ];
134
134
};
135
135
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
+
136
168
/**
137
169
* aemif_calc_rate - calculate timing data.
138
170
* @pdev: platform device to calculate for
139
171
* @wanted: The cycle time needed in nanoseconds.
140
172
* @clk: The input clock rate in kHz.
141
- * @max: The maximum divider value that can be programmed.
142
173
*
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.
145
176
*/
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 )
148
178
{
149
179
int result ;
150
180
@@ -157,10 +187,6 @@ static int aemif_calc_rate(struct platform_device *pdev, int wanted,
157
187
if (result < 0 )
158
188
result = 0 ;
159
189
160
- /* ... But configuring tighter timings is not an option. */
161
- else if (result > max )
162
- result = - EINVAL ;
163
-
164
190
return result ;
165
191
}
166
192
@@ -250,7 +276,6 @@ static int of_aemif_parse_abus_config(struct platform_device *pdev,
250
276
struct aemif_device * aemif = platform_get_drvdata (pdev );
251
277
unsigned long clk_rate = aemif -> clk_rate ;
252
278
struct aemif_cs_data * data ;
253
- int ret ;
254
279
u32 cs ;
255
280
u32 val ;
256
281
@@ -276,68 +301,34 @@ static int of_aemif_parse_abus_config(struct platform_device *pdev,
276
301
aemif_get_hw_params (pdev , aemif -> num_cs ++ );
277
302
278
303
/* 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 );
286
306
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 );
294
309
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 );
299
312
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 );
302
315
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 );
307
318
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 );
310
321
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 );
334
324
335
325
if (!of_property_read_u32 (np , "ti,cs-bus-width" , & val ))
336
326
if (val == 16 )
337
327
data -> asize = 1 ;
338
328
data -> enable_ew = of_property_read_bool (np , "ti,cs-extended-wait-mode" );
339
329
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 );
341
332
}
342
333
343
334
static const struct of_device_id aemif_of_match [] = {
0 commit comments