13
13
#include <linux/err.h>
14
14
#include <linux/io.h>
15
15
#include <linux/kernel.h>
16
+ #include <linux/memory/ti-aemif.h>
16
17
#include <linux/module.h>
18
+ #include <linux/mutex.h>
17
19
#include <linux/of.h>
18
20
#include <linux/of_platform.h>
19
21
#include <linux/platform_device.h>
79
81
80
82
#define CONFIG_MASK (EW(EW_MAX) | SSTROBE(SSTROBE_MAX) | ASIZE_MAX)
81
83
82
- /**
83
- * struct aemif_cs_timings: structure to hold CS timings
84
- * @wstrobe: write strobe width, number of cycles - 1
85
- * @rstrobe: read strobe width, number of cycles - 1
86
- * @wsetup: write setup width, number of cycles - 1
87
- * @whold: write hold width, number of cycles - 1
88
- * @rsetup: read setup width, number of cycles - 1
89
- * @rhold: read hold width, number of cycles - 1
90
- * @ta: minimum turn around time, number of cycles - 1
91
- */
92
- struct aemif_cs_timings {
93
- u32 wstrobe ;
94
- u32 rstrobe ;
95
- u32 wsetup ;
96
- u32 whold ;
97
- u32 rsetup ;
98
- u32 rhold ;
99
- u32 ta ;
100
- };
101
-
102
84
/**
103
85
* struct aemif_cs_data: structure to hold CS parameters
104
86
* @timings: timings configuration
@@ -123,6 +105,7 @@ struct aemif_cs_data {
123
105
* @num_cs: number of assigned chip-selects
124
106
* @cs_offset: start number of cs nodes
125
107
* @cs_data: array of chip-select settings
108
+ * @config_cs_lock: lock used to access CS configuration
126
109
*/
127
110
struct aemif_device {
128
111
void __iomem * base ;
@@ -131,6 +114,7 @@ struct aemif_device {
131
114
u8 num_cs ;
132
115
int cs_offset ;
133
116
struct aemif_cs_data cs_data [NUM_CS ];
117
+ struct mutex config_cs_lock ;
134
118
};
135
119
136
120
/**
@@ -139,7 +123,7 @@ struct aemif_device {
139
123
*
140
124
* @return: 0 if the timing configuration is valid, negative error number otherwise.
141
125
*/
142
- static int aemif_check_cs_timings (struct aemif_cs_timings * timings )
126
+ int aemif_check_cs_timings (struct aemif_cs_timings * timings )
143
127
{
144
128
if (timings -> ta > TA_MAX )
145
129
return - EINVAL ;
@@ -164,6 +148,7 @@ static int aemif_check_cs_timings(struct aemif_cs_timings *timings)
164
148
165
149
return 0 ;
166
150
}
151
+ EXPORT_SYMBOL_GPL (aemif_check_cs_timings );
167
152
168
153
/**
169
154
* aemif_set_cs_timings() - Set the timing configuration of a given chip select.
@@ -173,7 +158,8 @@ static int aemif_check_cs_timings(struct aemif_cs_timings *timings)
173
158
*
174
159
* @return: 0 on success, else negative errno.
175
160
*/
176
- static int aemif_set_cs_timings (struct aemif_device * aemif , u8 cs , struct aemif_cs_timings * timings )
161
+ int aemif_set_cs_timings (struct aemif_device * aemif , u8 cs ,
162
+ struct aemif_cs_timings * timings )
177
163
{
178
164
unsigned int offset ;
179
165
u32 val , set ;
@@ -195,13 +181,16 @@ static int aemif_set_cs_timings(struct aemif_device *aemif, u8 cs, struct aemif_
195
181
196
182
offset = A1CR_OFFSET + cs * 4 ;
197
183
184
+ mutex_lock (& aemif -> config_cs_lock );
198
185
val = readl (aemif -> base + offset );
199
186
val &= ~TIMINGS_MASK ;
200
187
val |= set ;
201
188
writel (val , aemif -> base + offset );
189
+ mutex_unlock (& aemif -> config_cs_lock );
202
190
203
191
return 0 ;
204
192
}
193
+ EXPORT_SYMBOL_GPL (aemif_set_cs_timings );
205
194
206
195
/**
207
196
* aemif_calc_rate - calculate timing data.
@@ -257,10 +246,12 @@ static int aemif_config_abus(struct platform_device *pdev, int csnum)
257
246
if (data -> enable_ss )
258
247
set |= ACR_SSTROBE_MASK ;
259
248
249
+ mutex_lock (& aemif -> config_cs_lock );
260
250
val = readl (aemif -> base + offset );
261
251
val &= ~CONFIG_MASK ;
262
252
val |= set ;
263
253
writel (val , aemif -> base + offset );
254
+ mutex_unlock (& aemif -> config_cs_lock );
264
255
265
256
return aemif_set_cs_timings (aemif , data -> cs - aemif -> cs_offset , & data -> timings );
266
257
}
@@ -399,6 +390,7 @@ static int aemif_probe(struct platform_device *pdev)
399
390
if (IS_ERR (aemif -> base ))
400
391
return PTR_ERR (aemif -> base );
401
392
393
+ mutex_init (& aemif -> config_cs_lock );
402
394
if (np ) {
403
395
/*
404
396
* For every controller device node, there is a cs device node
0 commit comments