82
82
/**
83
83
* struct aemif_cs_data: structure to hold cs parameters
84
84
* @cs: chip-select number
85
- * @wstrobe: write strobe width, ns
86
- * @rstrobe: read strobe width, ns
87
- * @wsetup: write setup width, ns
88
- * @whold: write hold width, ns
89
- * @rsetup: read setup width, ns
90
- * @rhold: read hold width, ns
91
- * @ta: minimum turn around time, ns
85
+ * @wstrobe: write strobe width, number of cycles - 1
86
+ * @rstrobe: read strobe width, number of cycles - 1
87
+ * @wsetup: write setup width, number of cycles - 1
88
+ * @whold: write hold width, number of cycles - 1
89
+ * @rsetup: read setup width, number of cycles - 1
90
+ * @rhold: read hold width, number of cycles - 1
91
+ * @ta: minimum turn around time, number of cycles - 1
92
92
* @enable_ss: enable/disable select strobe mode
93
93
* @enable_ew: enable/disable extended wait mode
94
94
* @asize: width of the asynchronous device's data bus
95
95
*/
96
96
struct aemif_cs_data {
97
97
u8 cs ;
98
- u16 wstrobe ;
99
- u16 rstrobe ;
100
- u8 wsetup ;
101
- u8 whold ;
102
- u8 rsetup ;
103
- u8 rhold ;
104
- u8 ta ;
98
+ u32 wstrobe ;
99
+ u32 rstrobe ;
100
+ u32 wsetup ;
101
+ u32 whold ;
102
+ u32 rsetup ;
103
+ u32 rhold ;
104
+ u32 ta ;
105
105
u8 enable_ss ;
106
106
u8 enable_ew ;
107
107
u8 asize ;
@@ -175,26 +175,18 @@ static int aemif_config_abus(struct platform_device *pdev, int csnum)
175
175
struct aemif_device * aemif = platform_get_drvdata (pdev );
176
176
struct aemif_cs_data * data = & aemif -> cs_data [csnum ];
177
177
int ta , rhold , rstrobe , rsetup , whold , wstrobe , wsetup ;
178
- unsigned long clk_rate = aemif -> clk_rate ;
179
178
unsigned offset ;
180
179
u32 set , val ;
181
180
182
181
offset = A1CR_OFFSET + (data -> cs - aemif -> cs_offset ) * 4 ;
183
182
184
- ta = aemif_calc_rate (pdev , data -> ta , clk_rate , TA_MAX );
185
- rhold = aemif_calc_rate (pdev , data -> rhold , clk_rate , RHOLD_MAX );
186
- rstrobe = aemif_calc_rate (pdev , data -> rstrobe , clk_rate , RSTROBE_MAX );
187
- rsetup = aemif_calc_rate (pdev , data -> rsetup , clk_rate , RSETUP_MAX );
188
- whold = aemif_calc_rate (pdev , data -> whold , clk_rate , WHOLD_MAX );
189
- wstrobe = aemif_calc_rate (pdev , data -> wstrobe , clk_rate , WSTROBE_MAX );
190
- wsetup = aemif_calc_rate (pdev , data -> wsetup , clk_rate , WSETUP_MAX );
191
-
192
- if (ta < 0 || rhold < 0 || rstrobe < 0 || rsetup < 0 ||
193
- whold < 0 || wstrobe < 0 || wsetup < 0 ) {
194
- dev_err (& pdev -> dev , "%s: cannot get suitable timings\n" ,
195
- __func__ );
196
- return - EINVAL ;
197
- }
183
+ ta = data -> ta ;
184
+ rhold = data -> rhold ;
185
+ rstrobe = data -> rstrobe ;
186
+ rsetup = data -> rsetup ;
187
+ whold = data -> whold ;
188
+ wstrobe = data -> wstrobe ;
189
+ wsetup = data -> wsetup ;
198
190
199
191
set = TA (ta ) | RHOLD (rhold ) | RSTROBE (rstrobe ) | RSETUP (rsetup ) |
200
192
WHOLD (whold ) | WSTROBE (wstrobe ) | WSETUP (wsetup );
@@ -213,11 +205,6 @@ static int aemif_config_abus(struct platform_device *pdev, int csnum)
213
205
return 0 ;
214
206
}
215
207
216
- static inline int aemif_cycles_to_nsec (int val , unsigned long clk_rate )
217
- {
218
- return ((val + 1 ) * NSEC_PER_MSEC ) / clk_rate ;
219
- }
220
-
221
208
/**
222
209
* aemif_get_hw_params - function to read hw register values
223
210
* @pdev: platform device to read for
@@ -231,19 +218,18 @@ static void aemif_get_hw_params(struct platform_device *pdev, int csnum)
231
218
{
232
219
struct aemif_device * aemif = platform_get_drvdata (pdev );
233
220
struct aemif_cs_data * data = & aemif -> cs_data [csnum ];
234
- unsigned long clk_rate = aemif -> clk_rate ;
235
221
u32 val , offset ;
236
222
237
223
offset = A1CR_OFFSET + (data -> cs - aemif -> cs_offset ) * 4 ;
238
224
val = readl (aemif -> base + offset );
239
225
240
- data -> ta = aemif_cycles_to_nsec ( TA_VAL (val ), clk_rate );
241
- data -> rhold = aemif_cycles_to_nsec ( RHOLD_VAL (val ), clk_rate );
242
- data -> rstrobe = aemif_cycles_to_nsec ( RSTROBE_VAL (val ), clk_rate );
243
- data -> rsetup = aemif_cycles_to_nsec ( RSETUP_VAL (val ), clk_rate );
244
- data -> whold = aemif_cycles_to_nsec ( WHOLD_VAL (val ), clk_rate );
245
- data -> wstrobe = aemif_cycles_to_nsec ( WSTROBE_VAL (val ), clk_rate );
246
- data -> wsetup = aemif_cycles_to_nsec ( WSETUP_VAL (val ), clk_rate );
226
+ data -> ta = TA_VAL (val );
227
+ data -> rhold = RHOLD_VAL (val );
228
+ data -> rstrobe = RSTROBE_VAL (val );
229
+ data -> rsetup = RSETUP_VAL (val );
230
+ data -> whold = WHOLD_VAL (val );
231
+ data -> wstrobe = WSTROBE_VAL (val );
232
+ data -> wsetup = WSETUP_VAL (val );
247
233
data -> enable_ew = EW_VAL (val );
248
234
data -> enable_ss = SSTROBE_VAL (val );
249
235
data -> asize = val & ASIZE_MAX ;
@@ -261,7 +247,9 @@ static int of_aemif_parse_abus_config(struct platform_device *pdev,
261
247
struct device_node * np )
262
248
{
263
249
struct aemif_device * aemif = platform_get_drvdata (pdev );
250
+ unsigned long clk_rate = aemif -> clk_rate ;
264
251
struct aemif_cs_data * data ;
252
+ int ret ;
265
253
u32 cs ;
266
254
u32 val ;
267
255
@@ -287,26 +275,61 @@ static int of_aemif_parse_abus_config(struct platform_device *pdev,
287
275
aemif_get_hw_params (pdev , aemif -> num_cs ++ );
288
276
289
277
/* override the values from device node */
290
- if (!of_property_read_u32 (np , "ti,cs-min-turnaround-ns" , & val ))
291
- data -> ta = val ;
278
+ if (!of_property_read_u32 (np , "ti,cs-min-turnaround-ns" , & val )) {
279
+ ret = aemif_calc_rate (pdev , val , clk_rate , TA_MAX );
280
+ if (ret < 0 )
281
+ return ret ;
292
282
293
- if (! of_property_read_u32 ( np , "ti,cs-read-hold-ns" , & val ))
294
- data -> rhold = val ;
283
+ data -> ta = ret ;
284
+ }
295
285
296
- if (!of_property_read_u32 (np , "ti,cs-read-strobe-ns" , & val ))
297
- data -> rstrobe = val ;
286
+ if (!of_property_read_u32 (np , "ti,cs-read-hold-ns" , & val )) {
287
+ ret = aemif_calc_rate (pdev , val , clk_rate , RHOLD_MAX );
288
+ if (ret < 0 )
289
+ return ret ;
298
290
299
- if (! of_property_read_u32 ( np , "ti,cs-read-setup-ns" , & val ))
300
- data -> rsetup = val ;
291
+ data -> rhold = ret ;
292
+ }
301
293
302
- if (!of_property_read_u32 (np , "ti,cs-write-hold-ns" , & val ))
303
- data -> whold = val ;
294
+ if (!of_property_read_u32 (np , "ti,cs-read-strobe-ns" , & val )) {
295
+ ret = aemif_calc_rate (pdev , val , clk_rate , RSTROBE_MAX );
296
+ if (ret < 0 )
297
+ return ret ;
304
298
305
- if (! of_property_read_u32 ( np , "ti,cs-write-strobe-ns" , & val ))
306
- data -> wstrobe = val ;
299
+ data -> rstrobe = ret ;
300
+ }
307
301
308
- if (!of_property_read_u32 (np , "ti,cs-write-setup-ns" , & val ))
309
- data -> wsetup = val ;
302
+ if (!of_property_read_u32 (np , "ti,cs-read-setup-ns" , & val )) {
303
+ ret = aemif_calc_rate (pdev , val , clk_rate , RSETUP_MAX );
304
+ if (ret < 0 )
305
+ return ret ;
306
+
307
+ data -> rsetup = ret ;
308
+ }
309
+
310
+ if (!of_property_read_u32 (np , "ti,cs-write-hold-ns" , & val )) {
311
+ ret = aemif_calc_rate (pdev , val , clk_rate , WHOLD_MAX );
312
+ if (ret < 0 )
313
+ return ret ;
314
+
315
+ data -> whold = ret ;
316
+ }
317
+
318
+ if (!of_property_read_u32 (np , "ti,cs-write-strobe-ns" , & val )) {
319
+ ret = aemif_calc_rate (pdev , val , clk_rate , WSTROBE_MAX );
320
+ if (ret < 0 )
321
+ return ret ;
322
+
323
+ data -> wstrobe = ret ;
324
+ }
325
+
326
+ if (!of_property_read_u32 (np , "ti,cs-write-setup-ns" , & val )) {
327
+ ret = aemif_calc_rate (pdev , val , clk_rate , WSETUP_MAX );
328
+ if (ret < 0 )
329
+ return ret ;
330
+
331
+ data -> wsetup = ret ;
332
+ }
310
333
311
334
if (!of_property_read_u32 (np , "ti,cs-bus-width" , & val ))
312
335
if (val == 16 )
0 commit comments