aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSeungwon Jeon <tgih.jun@samsung.com>2013-06-26 13:09:26 -0400
committerJames Bottomley <JBottomley@Parallels.com>2013-06-28 15:57:52 -0400
commitb873a27538dff59e77c15eaf23bdf7e6be7d36e9 (patch)
tree82d201759567ac986a9012b5019df684c6d81bc1
parent8b612fa23f13a51f5ee8eb318fe05eef63dc3de9 (diff)
[SCSI] ufs: wrap the i/o access operations
Simplify operations with hiding mmio_base. Signed-off-by: Seungwon Jeon <tgih.jun@samsung.com> Tested-by: Maya Erez <merez@codeaurora.org> Signed-off-by: Santosh Y <santoshsy@gmail.com> Signed-off-by: James Bottomley <JBottomley@Parallels.com>
-rw-r--r--drivers/scsi/ufs/ufshcd.c105
-rw-r--r--drivers/scsi/ufs/ufshcd.h7
2 files changed, 50 insertions, 62 deletions
diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index c32a478df81b..871c2f0568ae 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -71,7 +71,7 @@ enum {
71 */ 71 */
72static inline u32 ufshcd_get_ufs_version(struct ufs_hba *hba) 72static inline u32 ufshcd_get_ufs_version(struct ufs_hba *hba)
73{ 73{
74 return readl(hba->mmio_base + REG_UFS_VERSION); 74 return ufshcd_readl(hba, REG_UFS_VERSION);
75} 75}
76 76
77/** 77/**
@@ -130,8 +130,7 @@ static inline int ufshcd_get_tm_free_slot(struct ufs_hba *hba)
130 */ 130 */
131static inline void ufshcd_utrl_clear(struct ufs_hba *hba, u32 pos) 131static inline void ufshcd_utrl_clear(struct ufs_hba *hba, u32 pos)
132{ 132{
133 writel(~(1 << pos), 133 ufshcd_writel(hba, ~(1 << pos), REG_UTP_TRANSFER_REQ_LIST_CLEAR);
134 (hba->mmio_base + REG_UTP_TRANSFER_REQ_LIST_CLEAR));
135} 134}
136 135
137/** 136/**
@@ -165,7 +164,7 @@ static inline int ufshcd_get_lists_status(u32 reg)
165 */ 164 */
166static inline int ufshcd_get_uic_cmd_result(struct ufs_hba *hba) 165static inline int ufshcd_get_uic_cmd_result(struct ufs_hba *hba)
167{ 166{
168 return readl(hba->mmio_base + REG_UIC_COMMAND_ARG_2) & 167 return ufshcd_readl(hba, REG_UIC_COMMAND_ARG_2) &
169 MASK_UIC_COMMAND_RESULT; 168 MASK_UIC_COMMAND_RESULT;
170} 169}
171 170
@@ -243,18 +242,15 @@ ufshcd_config_int_aggr(struct ufs_hba *hba, int option)
243{ 242{
244 switch (option) { 243 switch (option) {
245 case INT_AGGR_RESET: 244 case INT_AGGR_RESET:
246 writel((INT_AGGR_ENABLE | 245 ufshcd_writel(hba, INT_AGGR_ENABLE |
247 INT_AGGR_COUNTER_AND_TIMER_RESET), 246 INT_AGGR_COUNTER_AND_TIMER_RESET,
248 (hba->mmio_base + 247 REG_UTP_TRANSFER_REQ_INT_AGG_CONTROL);
249 REG_UTP_TRANSFER_REQ_INT_AGG_CONTROL));
250 break; 248 break;
251 case INT_AGGR_CONFIG: 249 case INT_AGGR_CONFIG:
252 writel((INT_AGGR_ENABLE | 250 ufshcd_writel(hba, INT_AGGR_ENABLE | INT_AGGR_PARAM_WRITE |
253 INT_AGGR_PARAM_WRITE | 251 INT_AGGR_COUNTER_THRESHOLD_VALUE |
254 INT_AGGR_COUNTER_THRESHOLD_VALUE | 252 INT_AGGR_TIMEOUT_VALUE,
255 INT_AGGR_TIMEOUT_VALUE), 253 REG_UTP_TRANSFER_REQ_INT_AGG_CONTROL);
256 (hba->mmio_base +
257 REG_UTP_TRANSFER_REQ_INT_AGG_CONTROL));
258 break; 254 break;
259 } 255 }
260} 256}
@@ -267,12 +263,10 @@ ufshcd_config_int_aggr(struct ufs_hba *hba, int option)
267 */ 263 */
268static void ufshcd_enable_run_stop_reg(struct ufs_hba *hba) 264static void ufshcd_enable_run_stop_reg(struct ufs_hba *hba)
269{ 265{
270 writel(UTP_TASK_REQ_LIST_RUN_STOP_BIT, 266 ufshcd_writel(hba, UTP_TASK_REQ_LIST_RUN_STOP_BIT,
271 (hba->mmio_base + 267 REG_UTP_TASK_REQ_LIST_RUN_STOP);
272 REG_UTP_TASK_REQ_LIST_RUN_STOP)); 268 ufshcd_writel(hba, UTP_TRANSFER_REQ_LIST_RUN_STOP_BIT,
273 writel(UTP_TRANSFER_REQ_LIST_RUN_STOP_BIT, 269 REG_UTP_TRANSFER_REQ_LIST_RUN_STOP);
274 (hba->mmio_base +
275 REG_UTP_TRANSFER_REQ_LIST_RUN_STOP));
276} 270}
277 271
278/** 272/**
@@ -281,7 +275,7 @@ static void ufshcd_enable_run_stop_reg(struct ufs_hba *hba)
281 */ 275 */
282static inline void ufshcd_hba_start(struct ufs_hba *hba) 276static inline void ufshcd_hba_start(struct ufs_hba *hba)
283{ 277{
284 writel(CONTROLLER_ENABLE , (hba->mmio_base + REG_CONTROLLER_ENABLE)); 278 ufshcd_writel(hba, CONTROLLER_ENABLE, REG_CONTROLLER_ENABLE);
285} 279}
286 280
287/** 281/**
@@ -292,7 +286,7 @@ static inline void ufshcd_hba_start(struct ufs_hba *hba)
292 */ 286 */
293static inline int ufshcd_is_hba_active(struct ufs_hba *hba) 287static inline int ufshcd_is_hba_active(struct ufs_hba *hba)
294{ 288{
295 return (readl(hba->mmio_base + REG_CONTROLLER_ENABLE) & 0x1) ? 0 : 1; 289 return (ufshcd_readl(hba, REG_CONTROLLER_ENABLE) & 0x1) ? 0 : 1;
296} 290}
297 291
298/** 292/**
@@ -304,8 +298,7 @@ static inline
304void ufshcd_send_command(struct ufs_hba *hba, unsigned int task_tag) 298void ufshcd_send_command(struct ufs_hba *hba, unsigned int task_tag)
305{ 299{
306 __set_bit(task_tag, &hba->outstanding_reqs); 300 __set_bit(task_tag, &hba->outstanding_reqs);
307 writel((1 << task_tag), 301 ufshcd_writel(hba, 1 << task_tag, REG_UTP_TRANSFER_REQ_DOOR_BELL);
308 (hba->mmio_base + REG_UTP_TRANSFER_REQ_DOOR_BELL));
309} 302}
310 303
311/** 304/**
@@ -329,8 +322,7 @@ static inline void ufshcd_copy_sense_data(struct ufshcd_lrb *lrbp)
329 */ 322 */
330static inline void ufshcd_hba_capabilities(struct ufs_hba *hba) 323static inline void ufshcd_hba_capabilities(struct ufs_hba *hba)
331{ 324{
332 hba->capabilities = 325 hba->capabilities = ufshcd_readl(hba, REG_CONTROLLER_CAPABILITIES);
333 readl(hba->mmio_base + REG_CONTROLLER_CAPABILITIES);
334 326
335 /* nutrs and nutmrs are 0 based values */ 327 /* nutrs and nutmrs are 0 based values */
336 hba->nutrs = (hba->capabilities & MASK_TRANSFER_REQUESTS_SLOTS) + 1; 328 hba->nutrs = (hba->capabilities & MASK_TRANSFER_REQUESTS_SLOTS) + 1;
@@ -347,16 +339,13 @@ static inline void
347ufshcd_send_uic_command(struct ufs_hba *hba, struct uic_command *uic_cmnd) 339ufshcd_send_uic_command(struct ufs_hba *hba, struct uic_command *uic_cmnd)
348{ 340{
349 /* Write Args */ 341 /* Write Args */
350 writel(uic_cmnd->argument1, 342 ufshcd_writel(hba, uic_cmnd->argument1, REG_UIC_COMMAND_ARG_1);
351 (hba->mmio_base + REG_UIC_COMMAND_ARG_1)); 343 ufshcd_writel(hba, uic_cmnd->argument2, REG_UIC_COMMAND_ARG_2);
352 writel(uic_cmnd->argument2, 344 ufshcd_writel(hba, uic_cmnd->argument3, REG_UIC_COMMAND_ARG_3);
353 (hba->mmio_base + REG_UIC_COMMAND_ARG_2));
354 writel(uic_cmnd->argument3,
355 (hba->mmio_base + REG_UIC_COMMAND_ARG_3));
356 345
357 /* Write UIC Cmd */ 346 /* Write UIC Cmd */
358 writel((uic_cmnd->command & COMMAND_OPCODE_MASK), 347 ufshcd_writel(hba, uic_cmnd->command & COMMAND_OPCODE_MASK,
359 (hba->mmio_base + REG_UIC_COMMAND)); 348 REG_UIC_COMMAND);
360} 349}
361 350
362/** 351/**
@@ -408,16 +397,15 @@ static void ufshcd_int_config(struct ufs_hba *hba, u32 option)
408{ 397{
409 switch (option) { 398 switch (option) {
410 case UFSHCD_INT_ENABLE: 399 case UFSHCD_INT_ENABLE:
411 writel(hba->int_enable_mask, 400 ufshcd_writel(hba, hba->int_enable_mask, REG_INTERRUPT_ENABLE);
412 (hba->mmio_base + REG_INTERRUPT_ENABLE));
413 break; 401 break;
414 case UFSHCD_INT_DISABLE: 402 case UFSHCD_INT_DISABLE:
415 if (hba->ufs_version == UFSHCI_VERSION_10) 403 if (hba->ufs_version == UFSHCI_VERSION_10)
416 writel(INTERRUPT_DISABLE_MASK_10, 404 ufshcd_writel(hba, INTERRUPT_DISABLE_MASK_10,
417 (hba->mmio_base + REG_INTERRUPT_ENABLE)); 405 REG_INTERRUPT_ENABLE);
418 else 406 else
419 writel(INTERRUPT_DISABLE_MASK_11, 407 ufshcd_writel(hba, INTERRUPT_DISABLE_MASK_11,
420 (hba->mmio_base + REG_INTERRUPT_ENABLE)); 408 REG_INTERRUPT_ENABLE);
421 break; 409 break;
422 } 410 }
423} 411}
@@ -703,7 +691,7 @@ static int ufshcd_dme_link_startup(struct ufs_hba *hba)
703 unsigned long flags; 691 unsigned long flags;
704 692
705 /* check if controller is ready to accept UIC commands */ 693 /* check if controller is ready to accept UIC commands */
706 if (((readl(hba->mmio_base + REG_CONTROLLER_STATUS)) & 694 if ((ufshcd_readl(hba, REG_CONTROLLER_STATUS) &
707 UIC_COMMAND_READY) == 0x0) { 695 UIC_COMMAND_READY) == 0x0) {
708 dev_err(hba->dev, 696 dev_err(hba->dev,
709 "Controller not ready" 697 "Controller not ready"
@@ -748,7 +736,7 @@ static int ufshcd_make_hba_operational(struct ufs_hba *hba)
748 u32 reg; 736 u32 reg;
749 737
750 /* check if device present */ 738 /* check if device present */
751 reg = readl((hba->mmio_base + REG_CONTROLLER_STATUS)); 739 reg = ufshcd_readl(hba, REG_CONTROLLER_STATUS);
752 if (!ufshcd_is_device_present(reg)) { 740 if (!ufshcd_is_device_present(reg)) {
753 dev_err(hba->dev, "cc: Device not present\n"); 741 dev_err(hba->dev, "cc: Device not present\n");
754 err = -ENXIO; 742 err = -ENXIO;
@@ -870,14 +858,14 @@ static int ufshcd_initialize_hba(struct ufs_hba *hba)
870 return -EIO; 858 return -EIO;
871 859
872 /* Configure UTRL and UTMRL base address registers */ 860 /* Configure UTRL and UTMRL base address registers */
873 writel(lower_32_bits(hba->utrdl_dma_addr), 861 ufshcd_writel(hba, lower_32_bits(hba->utrdl_dma_addr),
874 (hba->mmio_base + REG_UTP_TRANSFER_REQ_LIST_BASE_L)); 862 REG_UTP_TRANSFER_REQ_LIST_BASE_L);
875 writel(upper_32_bits(hba->utrdl_dma_addr), 863 ufshcd_writel(hba, upper_32_bits(hba->utrdl_dma_addr),
876 (hba->mmio_base + REG_UTP_TRANSFER_REQ_LIST_BASE_H)); 864 REG_UTP_TRANSFER_REQ_LIST_BASE_H);
877 writel(lower_32_bits(hba->utmrdl_dma_addr), 865 ufshcd_writel(hba, lower_32_bits(hba->utmrdl_dma_addr),
878 (hba->mmio_base + REG_UTP_TASK_REQ_LIST_BASE_L)); 866 REG_UTP_TASK_REQ_LIST_BASE_L);
879 writel(upper_32_bits(hba->utmrdl_dma_addr), 867 ufshcd_writel(hba, upper_32_bits(hba->utmrdl_dma_addr),
880 (hba->mmio_base + REG_UTP_TASK_REQ_LIST_BASE_H)); 868 REG_UTP_TASK_REQ_LIST_BASE_H);
881 869
882 /* Initialize unipro link startup procedure */ 870 /* Initialize unipro link startup procedure */
883 return ufshcd_dme_link_startup(hba); 871 return ufshcd_dme_link_startup(hba);
@@ -1169,8 +1157,7 @@ static void ufshcd_transfer_req_compl(struct ufs_hba *hba)
1169 int index; 1157 int index;
1170 1158
1171 lrb = hba->lrb; 1159 lrb = hba->lrb;
1172 tr_doorbell = 1160 tr_doorbell = ufshcd_readl(hba, REG_UTP_TRANSFER_REQ_DOOR_BELL);
1173 readl(hba->mmio_base + REG_UTP_TRANSFER_REQ_DOOR_BELL);
1174 completed_reqs = tr_doorbell ^ hba->outstanding_reqs; 1161 completed_reqs = tr_doorbell ^ hba->outstanding_reqs;
1175 1162
1176 for (index = 0; index < hba->nutrs; index++) { 1163 for (index = 0; index < hba->nutrs; index++) {
@@ -1244,9 +1231,7 @@ static void ufshcd_err_handler(struct ufs_hba *hba)
1244 goto fatal_eh; 1231 goto fatal_eh;
1245 1232
1246 if (hba->errors & UIC_ERROR) { 1233 if (hba->errors & UIC_ERROR) {
1247 1234 reg = ufshcd_readl(hba, REG_UIC_ERROR_CODE_PHY_ADAPTER_LAYER);
1248 reg = readl(hba->mmio_base +
1249 REG_UIC_ERROR_CODE_PHY_ADAPTER_LAYER);
1250 if (reg & UIC_DATA_LINK_LAYER_ERROR_PA_INIT) 1235 if (reg & UIC_DATA_LINK_LAYER_ERROR_PA_INIT)
1251 goto fatal_eh; 1236 goto fatal_eh;
1252 } 1237 }
@@ -1264,7 +1249,7 @@ static void ufshcd_tmc_handler(struct ufs_hba *hba)
1264{ 1249{
1265 u32 tm_doorbell; 1250 u32 tm_doorbell;
1266 1251
1267 tm_doorbell = readl(hba->mmio_base + REG_UTP_TASK_REQ_DOOR_BELL); 1252 tm_doorbell = ufshcd_readl(hba, REG_UTP_TASK_REQ_DOOR_BELL);
1268 hba->tm_condition = tm_doorbell ^ hba->outstanding_tasks; 1253 hba->tm_condition = tm_doorbell ^ hba->outstanding_tasks;
1269 wake_up_interruptible(&hba->ufshcd_tm_wait_queue); 1254 wake_up_interruptible(&hba->ufshcd_tm_wait_queue);
1270} 1255}
@@ -1305,15 +1290,14 @@ static irqreturn_t ufshcd_intr(int irq, void *__hba)
1305 struct ufs_hba *hba = __hba; 1290 struct ufs_hba *hba = __hba;
1306 1291
1307 spin_lock(hba->host->host_lock); 1292 spin_lock(hba->host->host_lock);
1308 intr_status = readl(hba->mmio_base + REG_INTERRUPT_STATUS); 1293 intr_status = ufshcd_readl(hba, REG_INTERRUPT_STATUS);
1309 1294
1310 if (intr_status) { 1295 if (intr_status) {
1311 ufshcd_sl_intr(hba, intr_status); 1296 ufshcd_sl_intr(hba, intr_status);
1312 1297
1313 /* If UFSHCI 1.0 then clear interrupt status register */ 1298 /* If UFSHCI 1.0 then clear interrupt status register */
1314 if (hba->ufs_version == UFSHCI_VERSION_10) 1299 if (hba->ufs_version == UFSHCI_VERSION_10)
1315 writel(intr_status, 1300 ufshcd_writel(hba, intr_status, REG_INTERRUPT_STATUS);
1316 (hba->mmio_base + REG_INTERRUPT_STATUS));
1317 retval = IRQ_HANDLED; 1301 retval = IRQ_HANDLED;
1318 } 1302 }
1319 spin_unlock(hba->host->host_lock); 1303 spin_unlock(hba->host->host_lock);
@@ -1378,8 +1362,7 @@ ufshcd_issue_tm_cmd(struct ufs_hba *hba,
1378 1362
1379 /* send command to the controller */ 1363 /* send command to the controller */
1380 __set_bit(free_slot, &hba->outstanding_tasks); 1364 __set_bit(free_slot, &hba->outstanding_tasks);
1381 writel((1 << free_slot), 1365 ufshcd_writel(hba, 1 << free_slot, REG_UTP_TASK_REQ_DOOR_BELL);
1382 (hba->mmio_base + REG_UTP_TASK_REQ_DOOR_BELL));
1383 1366
1384 spin_unlock_irqrestore(host->host_lock, flags); 1367 spin_unlock_irqrestore(host->host_lock, flags);
1385 1368
diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h
index 6b99a42f5819..807dd2d740d4 100644
--- a/drivers/scsi/ufs/ufshcd.h
+++ b/drivers/scsi/ufs/ufshcd.h
@@ -186,6 +186,11 @@ struct ufs_hba {
186 u32 errors; 186 u32 errors;
187}; 187};
188 188
189#define ufshcd_writel(hba, val, reg) \
190 writel((val), (hba)->mmio_base + (reg))
191#define ufshcd_readl(hba, reg) \
192 readl((hba)->mmio_base + (reg))
193
189int ufshcd_init(struct device *, struct ufs_hba ** , void __iomem * , 194int ufshcd_init(struct device *, struct ufs_hba ** , void __iomem * ,
190 unsigned int); 195 unsigned int);
191void ufshcd_remove(struct ufs_hba *); 196void ufshcd_remove(struct ufs_hba *);
@@ -196,7 +201,7 @@ void ufshcd_remove(struct ufs_hba *);
196 */ 201 */
197static inline void ufshcd_hba_stop(struct ufs_hba *hba) 202static inline void ufshcd_hba_stop(struct ufs_hba *hba)
198{ 203{
199 writel(CONTROLLER_DISABLE, (hba->mmio_base + REG_CONTROLLER_ENABLE)); 204 ufshcd_writel(hba, CONTROLLER_DISABLE, REG_CONTROLLER_ENABLE);
200} 205}
201 206
202#endif /* End of Header */ 207#endif /* End of Header */