@@ -117,24 +117,18 @@ struct sprd_adi {
117
117
struct notifier_block restart_handler ;
118
118
};
119
119
120
- static int sprd_adi_check_paddr (struct sprd_adi * sadi , u32 paddr )
120
+ static int sprd_adi_check_addr (struct sprd_adi * sadi , u32 reg )
121
121
{
122
- if (paddr < sadi -> slave_pbase || paddr >
123
- (sadi -> slave_pbase + ADI_SLAVE_ADDR_SIZE )) {
122
+ if (reg > ADI_SLAVE_ADDR_SIZE ) {
124
123
dev_err (sadi -> dev ,
125
- "slave physical address is incorrect, addr = 0x%x\n" ,
126
- paddr );
124
+ "slave address offset is incorrect, reg = 0x%x\n" ,
125
+ reg );
127
126
return - EINVAL ;
128
127
}
129
128
130
129
return 0 ;
131
130
}
132
131
133
- static unsigned long sprd_adi_to_vaddr (struct sprd_adi * sadi , u32 paddr )
134
- {
135
- return (paddr - sadi -> slave_pbase + sadi -> slave_vbase );
136
- }
137
-
138
132
static int sprd_adi_drain_fifo (struct sprd_adi * sadi )
139
133
{
140
134
u32 timeout = ADI_FIFO_DRAIN_TIMEOUT ;
@@ -161,11 +155,11 @@ static int sprd_adi_fifo_is_full(struct sprd_adi *sadi)
161
155
return readl_relaxed (sadi -> base + REG_ADI_ARM_FIFO_STS ) & BIT_FIFO_FULL ;
162
156
}
163
157
164
- static int sprd_adi_read (struct sprd_adi * sadi , u32 reg_paddr , u32 * read_val )
158
+ static int sprd_adi_read (struct sprd_adi * sadi , u32 reg , u32 * read_val )
165
159
{
166
160
int read_timeout = ADI_READ_TIMEOUT ;
167
161
unsigned long flags ;
168
- u32 val , rd_addr ;
162
+ u32 val , rd_addr , paddr ;
169
163
int ret = 0 ;
170
164
171
165
if (sadi -> hwlock ) {
@@ -178,11 +172,16 @@ static int sprd_adi_read(struct sprd_adi *sadi, u32 reg_paddr, u32 *read_val)
178
172
}
179
173
}
180
174
175
+ ret = sprd_adi_check_addr (sadi , reg );
176
+ if (ret )
177
+ goto out ;
178
+
181
179
/*
182
180
* Set the physical register address need to read into RD_CMD register,
183
181
* then ADI controller will start to transfer automatically.
184
182
*/
185
- writel_relaxed (reg_paddr , sadi -> base + REG_ADI_RD_CMD );
183
+ paddr = sadi -> slave_pbase + reg ;
184
+ writel_relaxed (paddr , sadi -> base + REG_ADI_RD_CMD );
186
185
187
186
/*
188
187
* Wait read operation complete, the BIT_RD_CMD_BUSY will be set
@@ -212,9 +211,9 @@ static int sprd_adi_read(struct sprd_adi *sadi, u32 reg_paddr, u32 *read_val)
212
211
*/
213
212
rd_addr = (val & RD_ADDR_MASK ) >> RD_ADDR_SHIFT ;
214
213
215
- if (rd_addr != (reg_paddr & REG_ADDR_LOW_MASK )) {
214
+ if (rd_addr != (paddr & REG_ADDR_LOW_MASK )) {
216
215
dev_err (sadi -> dev , "read error, reg addr = 0x%x, val = 0x%x\n" ,
217
- reg_paddr , val );
216
+ paddr , val );
218
217
ret = - EIO ;
219
218
goto out ;
220
219
}
@@ -227,9 +226,8 @@ static int sprd_adi_read(struct sprd_adi *sadi, u32 reg_paddr, u32 *read_val)
227
226
return ret ;
228
227
}
229
228
230
- static int sprd_adi_write (struct sprd_adi * sadi , u32 reg_paddr , u32 val )
229
+ static int sprd_adi_write (struct sprd_adi * sadi , u32 reg , u32 val )
231
230
{
232
- unsigned long reg = sprd_adi_to_vaddr (sadi , reg_paddr );
233
231
u32 timeout = ADI_FIFO_DRAIN_TIMEOUT ;
234
232
unsigned long flags ;
235
233
int ret ;
@@ -244,6 +242,10 @@ static int sprd_adi_write(struct sprd_adi *sadi, u32 reg_paddr, u32 val)
244
242
}
245
243
}
246
244
245
+ ret = sprd_adi_check_addr (sadi , reg );
246
+ if (ret )
247
+ goto out ;
248
+
247
249
ret = sprd_adi_drain_fifo (sadi );
248
250
if (ret < 0 )
249
251
goto out ;
@@ -254,7 +256,8 @@ static int sprd_adi_write(struct sprd_adi *sadi, u32 reg_paddr, u32 val)
254
256
*/
255
257
do {
256
258
if (!sprd_adi_fifo_is_full (sadi )) {
257
- writel_relaxed (val , (void __iomem * )reg );
259
+ /* we need virtual register address to write. */
260
+ writel_relaxed (val , (void __iomem * )(sadi -> slave_vbase + reg ));
258
261
break ;
259
262
}
260
263
@@ -277,44 +280,24 @@ static int sprd_adi_transfer_one(struct spi_controller *ctlr,
277
280
struct spi_transfer * t )
278
281
{
279
282
struct sprd_adi * sadi = spi_controller_get_devdata (ctlr );
280
- u32 phy_reg , val ;
283
+ u32 reg , val ;
281
284
int ret ;
282
285
283
286
if (t -> rx_buf ) {
284
- phy_reg = * (u32 * )t -> rx_buf + sadi -> slave_pbase ;
285
-
286
- ret = sprd_adi_check_paddr (sadi , phy_reg );
287
- if (ret )
288
- return ret ;
289
-
290
- ret = sprd_adi_read (sadi , phy_reg , & val );
291
- if (ret )
292
- return ret ;
293
-
287
+ reg = * (u32 * )t -> rx_buf ;
288
+ ret = sprd_adi_read (sadi , reg , & val );
294
289
* (u32 * )t -> rx_buf = val ;
295
290
} else if (t -> tx_buf ) {
296
291
u32 * p = (u32 * )t -> tx_buf ;
297
-
298
- /*
299
- * Get the physical register address need to write and convert
300
- * the physical address to virtual address. Since we need
301
- * virtual register address to write.
302
- */
303
- phy_reg = * p ++ + sadi -> slave_pbase ;
304
- ret = sprd_adi_check_paddr (sadi , phy_reg );
305
- if (ret )
306
- return ret ;
307
-
292
+ reg = * p ++ ;
308
293
val = * p ;
309
- ret = sprd_adi_write (sadi , phy_reg , val );
310
- if (ret )
311
- return ret ;
294
+ ret = sprd_adi_write (sadi , reg , val );
312
295
} else {
313
296
dev_err (sadi -> dev , "no buffer for transfer\n" );
314
- return - EINVAL ;
297
+ ret = - EINVAL ;
315
298
}
316
299
317
- return 0 ;
300
+ return ret ;
318
301
}
319
302
320
303
static void sprd_adi_set_wdt_rst_mode (struct sprd_adi * sadi )
@@ -323,9 +306,9 @@ static void sprd_adi_set_wdt_rst_mode(struct sprd_adi *sadi)
323
306
u32 val ;
324
307
325
308
/* Set default watchdog reboot mode */
326
- sprd_adi_read (sadi , sadi -> slave_pbase + PMIC_RST_STATUS , & val );
309
+ sprd_adi_read (sadi , PMIC_RST_STATUS , & val );
327
310
val |= HWRST_STATUS_WATCHDOG ;
328
- sprd_adi_write (sadi , sadi -> slave_pbase + PMIC_RST_STATUS , val );
311
+ sprd_adi_write (sadi , PMIC_RST_STATUS , val );
329
312
#endif
330
313
}
331
314
@@ -366,40 +349,40 @@ static int sprd_adi_restart_handler(struct notifier_block *this,
366
349
reboot_mode = HWRST_STATUS_NORMAL ;
367
350
368
351
/* Record the reboot mode */
369
- sprd_adi_read (sadi , sadi -> slave_pbase + PMIC_RST_STATUS , & val );
352
+ sprd_adi_read (sadi , PMIC_RST_STATUS , & val );
370
353
val &= ~HWRST_STATUS_WATCHDOG ;
371
354
val |= reboot_mode ;
372
- sprd_adi_write (sadi , sadi -> slave_pbase + PMIC_RST_STATUS , val );
355
+ sprd_adi_write (sadi , PMIC_RST_STATUS , val );
373
356
374
357
/* Enable the interface clock of the watchdog */
375
- sprd_adi_read (sadi , sadi -> slave_pbase + PMIC_MODULE_EN , & val );
358
+ sprd_adi_read (sadi , PMIC_MODULE_EN , & val );
376
359
val |= BIT_WDG_EN ;
377
- sprd_adi_write (sadi , sadi -> slave_pbase + PMIC_MODULE_EN , val );
360
+ sprd_adi_write (sadi , PMIC_MODULE_EN , val );
378
361
379
362
/* Enable the work clock of the watchdog */
380
- sprd_adi_read (sadi , sadi -> slave_pbase + PMIC_CLK_EN , & val );
363
+ sprd_adi_read (sadi , PMIC_CLK_EN , & val );
381
364
val |= BIT_WDG_EN ;
382
- sprd_adi_write (sadi , sadi -> slave_pbase + PMIC_CLK_EN , val );
365
+ sprd_adi_write (sadi , PMIC_CLK_EN , val );
383
366
384
367
/* Unlock the watchdog */
385
- sprd_adi_write (sadi , sadi -> slave_pbase + REG_WDG_LOCK , WDG_UNLOCK_KEY );
368
+ sprd_adi_write (sadi , REG_WDG_LOCK , WDG_UNLOCK_KEY );
386
369
387
- sprd_adi_read (sadi , sadi -> slave_pbase + REG_WDG_CTRL , & val );
370
+ sprd_adi_read (sadi , REG_WDG_CTRL , & val );
388
371
val |= BIT_WDG_NEW ;
389
- sprd_adi_write (sadi , sadi -> slave_pbase + REG_WDG_CTRL , val );
372
+ sprd_adi_write (sadi , REG_WDG_CTRL , val );
390
373
391
374
/* Load the watchdog timeout value, 50ms is always enough. */
392
- sprd_adi_write (sadi , sadi -> slave_pbase + REG_WDG_LOAD_HIGH , 0 );
393
- sprd_adi_write (sadi , sadi -> slave_pbase + REG_WDG_LOAD_LOW ,
375
+ sprd_adi_write (sadi , REG_WDG_LOAD_HIGH , 0 );
376
+ sprd_adi_write (sadi , REG_WDG_LOAD_LOW ,
394
377
WDG_LOAD_VAL & WDG_LOAD_MASK );
395
378
396
379
/* Start the watchdog to reset system */
397
- sprd_adi_read (sadi , sadi -> slave_pbase + REG_WDG_CTRL , & val );
380
+ sprd_adi_read (sadi , REG_WDG_CTRL , & val );
398
381
val |= BIT_WDG_RUN | BIT_WDG_RST ;
399
- sprd_adi_write (sadi , sadi -> slave_pbase + REG_WDG_CTRL , val );
382
+ sprd_adi_write (sadi , REG_WDG_CTRL , val );
400
383
401
384
/* Lock the watchdog */
402
- sprd_adi_write (sadi , sadi -> slave_pbase + REG_WDG_LOCK , ~WDG_UNLOCK_KEY );
385
+ sprd_adi_write (sadi , REG_WDG_LOCK , ~WDG_UNLOCK_KEY );
403
386
404
387
mdelay (1000 );
405
388
0 commit comments