Commit b873a275 authored by Seungwon Jeon's avatar Seungwon Jeon Committed by James Bottomley

[SCSI] ufs: wrap the i/o access operations

Simplify operations with hiding mmio_base.
Signed-off-by: default avatarSeungwon Jeon <tgih.jun@samsung.com>
Tested-by: default avatarMaya Erez <merez@codeaurora.org>
Signed-off-by: default avatarSantosh Y <santoshsy@gmail.com>
Signed-off-by: default avatarJames Bottomley <JBottomley@Parallels.com>
parent 8b612fa2
...@@ -71,7 +71,7 @@ enum { ...@@ -71,7 +71,7 @@ enum {
*/ */
static inline u32 ufshcd_get_ufs_version(struct ufs_hba *hba) static inline u32 ufshcd_get_ufs_version(struct ufs_hba *hba)
{ {
return readl(hba->mmio_base + REG_UFS_VERSION); return ufshcd_readl(hba, REG_UFS_VERSION);
} }
/** /**
...@@ -130,8 +130,7 @@ static inline int ufshcd_get_tm_free_slot(struct ufs_hba *hba) ...@@ -130,8 +130,7 @@ static inline int ufshcd_get_tm_free_slot(struct ufs_hba *hba)
*/ */
static inline void ufshcd_utrl_clear(struct ufs_hba *hba, u32 pos) static inline void ufshcd_utrl_clear(struct ufs_hba *hba, u32 pos)
{ {
writel(~(1 << pos), ufshcd_writel(hba, ~(1 << pos), REG_UTP_TRANSFER_REQ_LIST_CLEAR);
(hba->mmio_base + REG_UTP_TRANSFER_REQ_LIST_CLEAR));
} }
/** /**
...@@ -165,7 +164,7 @@ static inline int ufshcd_get_lists_status(u32 reg) ...@@ -165,7 +164,7 @@ static inline int ufshcd_get_lists_status(u32 reg)
*/ */
static inline int ufshcd_get_uic_cmd_result(struct ufs_hba *hba) static inline int ufshcd_get_uic_cmd_result(struct ufs_hba *hba)
{ {
return readl(hba->mmio_base + REG_UIC_COMMAND_ARG_2) & return ufshcd_readl(hba, REG_UIC_COMMAND_ARG_2) &
MASK_UIC_COMMAND_RESULT; MASK_UIC_COMMAND_RESULT;
} }
...@@ -243,18 +242,15 @@ ufshcd_config_int_aggr(struct ufs_hba *hba, int option) ...@@ -243,18 +242,15 @@ ufshcd_config_int_aggr(struct ufs_hba *hba, int option)
{ {
switch (option) { switch (option) {
case INT_AGGR_RESET: case INT_AGGR_RESET:
writel((INT_AGGR_ENABLE | ufshcd_writel(hba, INT_AGGR_ENABLE |
INT_AGGR_COUNTER_AND_TIMER_RESET), INT_AGGR_COUNTER_AND_TIMER_RESET,
(hba->mmio_base + REG_UTP_TRANSFER_REQ_INT_AGG_CONTROL);
REG_UTP_TRANSFER_REQ_INT_AGG_CONTROL));
break; break;
case INT_AGGR_CONFIG: case INT_AGGR_CONFIG:
writel((INT_AGGR_ENABLE | ufshcd_writel(hba, INT_AGGR_ENABLE | INT_AGGR_PARAM_WRITE |
INT_AGGR_PARAM_WRITE | INT_AGGR_COUNTER_THRESHOLD_VALUE |
INT_AGGR_COUNTER_THRESHOLD_VALUE | INT_AGGR_TIMEOUT_VALUE,
INT_AGGR_TIMEOUT_VALUE), REG_UTP_TRANSFER_REQ_INT_AGG_CONTROL);
(hba->mmio_base +
REG_UTP_TRANSFER_REQ_INT_AGG_CONTROL));
break; break;
} }
} }
...@@ -267,12 +263,10 @@ ufshcd_config_int_aggr(struct ufs_hba *hba, int option) ...@@ -267,12 +263,10 @@ ufshcd_config_int_aggr(struct ufs_hba *hba, int option)
*/ */
static void ufshcd_enable_run_stop_reg(struct ufs_hba *hba) static void ufshcd_enable_run_stop_reg(struct ufs_hba *hba)
{ {
writel(UTP_TASK_REQ_LIST_RUN_STOP_BIT, ufshcd_writel(hba, UTP_TASK_REQ_LIST_RUN_STOP_BIT,
(hba->mmio_base + REG_UTP_TASK_REQ_LIST_RUN_STOP);
REG_UTP_TASK_REQ_LIST_RUN_STOP)); ufshcd_writel(hba, UTP_TRANSFER_REQ_LIST_RUN_STOP_BIT,
writel(UTP_TRANSFER_REQ_LIST_RUN_STOP_BIT, REG_UTP_TRANSFER_REQ_LIST_RUN_STOP);
(hba->mmio_base +
REG_UTP_TRANSFER_REQ_LIST_RUN_STOP));
} }
/** /**
...@@ -281,7 +275,7 @@ static void ufshcd_enable_run_stop_reg(struct ufs_hba *hba) ...@@ -281,7 +275,7 @@ static void ufshcd_enable_run_stop_reg(struct ufs_hba *hba)
*/ */
static inline void ufshcd_hba_start(struct ufs_hba *hba) static inline void ufshcd_hba_start(struct ufs_hba *hba)
{ {
writel(CONTROLLER_ENABLE , (hba->mmio_base + REG_CONTROLLER_ENABLE)); ufshcd_writel(hba, CONTROLLER_ENABLE, REG_CONTROLLER_ENABLE);
} }
/** /**
...@@ -292,7 +286,7 @@ static inline void ufshcd_hba_start(struct ufs_hba *hba) ...@@ -292,7 +286,7 @@ static inline void ufshcd_hba_start(struct ufs_hba *hba)
*/ */
static inline int ufshcd_is_hba_active(struct ufs_hba *hba) static inline int ufshcd_is_hba_active(struct ufs_hba *hba)
{ {
return (readl(hba->mmio_base + REG_CONTROLLER_ENABLE) & 0x1) ? 0 : 1; return (ufshcd_readl(hba, REG_CONTROLLER_ENABLE) & 0x1) ? 0 : 1;
} }
/** /**
...@@ -304,8 +298,7 @@ static inline ...@@ -304,8 +298,7 @@ static inline
void ufshcd_send_command(struct ufs_hba *hba, unsigned int task_tag) void ufshcd_send_command(struct ufs_hba *hba, unsigned int task_tag)
{ {
__set_bit(task_tag, &hba->outstanding_reqs); __set_bit(task_tag, &hba->outstanding_reqs);
writel((1 << task_tag), ufshcd_writel(hba, 1 << task_tag, REG_UTP_TRANSFER_REQ_DOOR_BELL);
(hba->mmio_base + REG_UTP_TRANSFER_REQ_DOOR_BELL));
} }
/** /**
...@@ -329,8 +322,7 @@ static inline void ufshcd_copy_sense_data(struct ufshcd_lrb *lrbp) ...@@ -329,8 +322,7 @@ static inline void ufshcd_copy_sense_data(struct ufshcd_lrb *lrbp)
*/ */
static inline void ufshcd_hba_capabilities(struct ufs_hba *hba) static inline void ufshcd_hba_capabilities(struct ufs_hba *hba)
{ {
hba->capabilities = hba->capabilities = ufshcd_readl(hba, REG_CONTROLLER_CAPABILITIES);
readl(hba->mmio_base + REG_CONTROLLER_CAPABILITIES);
/* nutrs and nutmrs are 0 based values */ /* nutrs and nutmrs are 0 based values */
hba->nutrs = (hba->capabilities & MASK_TRANSFER_REQUESTS_SLOTS) + 1; hba->nutrs = (hba->capabilities & MASK_TRANSFER_REQUESTS_SLOTS) + 1;
...@@ -347,16 +339,13 @@ static inline void ...@@ -347,16 +339,13 @@ static inline void
ufshcd_send_uic_command(struct ufs_hba *hba, struct uic_command *uic_cmnd) ufshcd_send_uic_command(struct ufs_hba *hba, struct uic_command *uic_cmnd)
{ {
/* Write Args */ /* Write Args */
writel(uic_cmnd->argument1, ufshcd_writel(hba, uic_cmnd->argument1, REG_UIC_COMMAND_ARG_1);
(hba->mmio_base + REG_UIC_COMMAND_ARG_1)); ufshcd_writel(hba, uic_cmnd->argument2, REG_UIC_COMMAND_ARG_2);
writel(uic_cmnd->argument2, ufshcd_writel(hba, uic_cmnd->argument3, REG_UIC_COMMAND_ARG_3);
(hba->mmio_base + REG_UIC_COMMAND_ARG_2));
writel(uic_cmnd->argument3,
(hba->mmio_base + REG_UIC_COMMAND_ARG_3));
/* Write UIC Cmd */ /* Write UIC Cmd */
writel((uic_cmnd->command & COMMAND_OPCODE_MASK), ufshcd_writel(hba, uic_cmnd->command & COMMAND_OPCODE_MASK,
(hba->mmio_base + REG_UIC_COMMAND)); REG_UIC_COMMAND);
} }
/** /**
...@@ -408,16 +397,15 @@ static void ufshcd_int_config(struct ufs_hba *hba, u32 option) ...@@ -408,16 +397,15 @@ static void ufshcd_int_config(struct ufs_hba *hba, u32 option)
{ {
switch (option) { switch (option) {
case UFSHCD_INT_ENABLE: case UFSHCD_INT_ENABLE:
writel(hba->int_enable_mask, ufshcd_writel(hba, hba->int_enable_mask, REG_INTERRUPT_ENABLE);
(hba->mmio_base + REG_INTERRUPT_ENABLE));
break; break;
case UFSHCD_INT_DISABLE: case UFSHCD_INT_DISABLE:
if (hba->ufs_version == UFSHCI_VERSION_10) if (hba->ufs_version == UFSHCI_VERSION_10)
writel(INTERRUPT_DISABLE_MASK_10, ufshcd_writel(hba, INTERRUPT_DISABLE_MASK_10,
(hba->mmio_base + REG_INTERRUPT_ENABLE)); REG_INTERRUPT_ENABLE);
else else
writel(INTERRUPT_DISABLE_MASK_11, ufshcd_writel(hba, INTERRUPT_DISABLE_MASK_11,
(hba->mmio_base + REG_INTERRUPT_ENABLE)); REG_INTERRUPT_ENABLE);
break; break;
} }
} }
...@@ -703,7 +691,7 @@ static int ufshcd_dme_link_startup(struct ufs_hba *hba) ...@@ -703,7 +691,7 @@ static int ufshcd_dme_link_startup(struct ufs_hba *hba)
unsigned long flags; unsigned long flags;
/* check if controller is ready to accept UIC commands */ /* check if controller is ready to accept UIC commands */
if (((readl(hba->mmio_base + REG_CONTROLLER_STATUS)) & if ((ufshcd_readl(hba, REG_CONTROLLER_STATUS) &
UIC_COMMAND_READY) == 0x0) { UIC_COMMAND_READY) == 0x0) {
dev_err(hba->dev, dev_err(hba->dev,
"Controller not ready" "Controller not ready"
...@@ -748,7 +736,7 @@ static int ufshcd_make_hba_operational(struct ufs_hba *hba) ...@@ -748,7 +736,7 @@ static int ufshcd_make_hba_operational(struct ufs_hba *hba)
u32 reg; u32 reg;
/* check if device present */ /* check if device present */
reg = readl((hba->mmio_base + REG_CONTROLLER_STATUS)); reg = ufshcd_readl(hba, REG_CONTROLLER_STATUS);
if (!ufshcd_is_device_present(reg)) { if (!ufshcd_is_device_present(reg)) {
dev_err(hba->dev, "cc: Device not present\n"); dev_err(hba->dev, "cc: Device not present\n");
err = -ENXIO; err = -ENXIO;
...@@ -870,14 +858,14 @@ static int ufshcd_initialize_hba(struct ufs_hba *hba) ...@@ -870,14 +858,14 @@ static int ufshcd_initialize_hba(struct ufs_hba *hba)
return -EIO; return -EIO;
/* Configure UTRL and UTMRL base address registers */ /* Configure UTRL and UTMRL base address registers */
writel(lower_32_bits(hba->utrdl_dma_addr), ufshcd_writel(hba, lower_32_bits(hba->utrdl_dma_addr),
(hba->mmio_base + REG_UTP_TRANSFER_REQ_LIST_BASE_L)); REG_UTP_TRANSFER_REQ_LIST_BASE_L);
writel(upper_32_bits(hba->utrdl_dma_addr), ufshcd_writel(hba, upper_32_bits(hba->utrdl_dma_addr),
(hba->mmio_base + REG_UTP_TRANSFER_REQ_LIST_BASE_H)); REG_UTP_TRANSFER_REQ_LIST_BASE_H);
writel(lower_32_bits(hba->utmrdl_dma_addr), ufshcd_writel(hba, lower_32_bits(hba->utmrdl_dma_addr),
(hba->mmio_base + REG_UTP_TASK_REQ_LIST_BASE_L)); REG_UTP_TASK_REQ_LIST_BASE_L);
writel(upper_32_bits(hba->utmrdl_dma_addr), ufshcd_writel(hba, upper_32_bits(hba->utmrdl_dma_addr),
(hba->mmio_base + REG_UTP_TASK_REQ_LIST_BASE_H)); REG_UTP_TASK_REQ_LIST_BASE_H);
/* Initialize unipro link startup procedure */ /* Initialize unipro link startup procedure */
return ufshcd_dme_link_startup(hba); return ufshcd_dme_link_startup(hba);
...@@ -1169,8 +1157,7 @@ static void ufshcd_transfer_req_compl(struct ufs_hba *hba) ...@@ -1169,8 +1157,7 @@ static void ufshcd_transfer_req_compl(struct ufs_hba *hba)
int index; int index;
lrb = hba->lrb; lrb = hba->lrb;
tr_doorbell = tr_doorbell = ufshcd_readl(hba, REG_UTP_TRANSFER_REQ_DOOR_BELL);
readl(hba->mmio_base + REG_UTP_TRANSFER_REQ_DOOR_BELL);
completed_reqs = tr_doorbell ^ hba->outstanding_reqs; completed_reqs = tr_doorbell ^ hba->outstanding_reqs;
for (index = 0; index < hba->nutrs; index++) { for (index = 0; index < hba->nutrs; index++) {
...@@ -1244,9 +1231,7 @@ static void ufshcd_err_handler(struct ufs_hba *hba) ...@@ -1244,9 +1231,7 @@ static void ufshcd_err_handler(struct ufs_hba *hba)
goto fatal_eh; goto fatal_eh;
if (hba->errors & UIC_ERROR) { if (hba->errors & UIC_ERROR) {
reg = ufshcd_readl(hba, REG_UIC_ERROR_CODE_PHY_ADAPTER_LAYER);
reg = readl(hba->mmio_base +
REG_UIC_ERROR_CODE_PHY_ADAPTER_LAYER);
if (reg & UIC_DATA_LINK_LAYER_ERROR_PA_INIT) if (reg & UIC_DATA_LINK_LAYER_ERROR_PA_INIT)
goto fatal_eh; goto fatal_eh;
} }
...@@ -1264,7 +1249,7 @@ static void ufshcd_tmc_handler(struct ufs_hba *hba) ...@@ -1264,7 +1249,7 @@ static void ufshcd_tmc_handler(struct ufs_hba *hba)
{ {
u32 tm_doorbell; u32 tm_doorbell;
tm_doorbell = readl(hba->mmio_base + REG_UTP_TASK_REQ_DOOR_BELL); tm_doorbell = ufshcd_readl(hba, REG_UTP_TASK_REQ_DOOR_BELL);
hba->tm_condition = tm_doorbell ^ hba->outstanding_tasks; hba->tm_condition = tm_doorbell ^ hba->outstanding_tasks;
wake_up_interruptible(&hba->ufshcd_tm_wait_queue); wake_up_interruptible(&hba->ufshcd_tm_wait_queue);
} }
...@@ -1305,15 +1290,14 @@ static irqreturn_t ufshcd_intr(int irq, void *__hba) ...@@ -1305,15 +1290,14 @@ static irqreturn_t ufshcd_intr(int irq, void *__hba)
struct ufs_hba *hba = __hba; struct ufs_hba *hba = __hba;
spin_lock(hba->host->host_lock); spin_lock(hba->host->host_lock);
intr_status = readl(hba->mmio_base + REG_INTERRUPT_STATUS); intr_status = ufshcd_readl(hba, REG_INTERRUPT_STATUS);
if (intr_status) { if (intr_status) {
ufshcd_sl_intr(hba, intr_status); ufshcd_sl_intr(hba, intr_status);
/* If UFSHCI 1.0 then clear interrupt status register */ /* If UFSHCI 1.0 then clear interrupt status register */
if (hba->ufs_version == UFSHCI_VERSION_10) if (hba->ufs_version == UFSHCI_VERSION_10)
writel(intr_status, ufshcd_writel(hba, intr_status, REG_INTERRUPT_STATUS);
(hba->mmio_base + REG_INTERRUPT_STATUS));
retval = IRQ_HANDLED; retval = IRQ_HANDLED;
} }
spin_unlock(hba->host->host_lock); spin_unlock(hba->host->host_lock);
...@@ -1378,8 +1362,7 @@ ufshcd_issue_tm_cmd(struct ufs_hba *hba, ...@@ -1378,8 +1362,7 @@ ufshcd_issue_tm_cmd(struct ufs_hba *hba,
/* send command to the controller */ /* send command to the controller */
__set_bit(free_slot, &hba->outstanding_tasks); __set_bit(free_slot, &hba->outstanding_tasks);
writel((1 << free_slot), ufshcd_writel(hba, 1 << free_slot, REG_UTP_TASK_REQ_DOOR_BELL);
(hba->mmio_base + REG_UTP_TASK_REQ_DOOR_BELL));
spin_unlock_irqrestore(host->host_lock, flags); spin_unlock_irqrestore(host->host_lock, flags);
......
...@@ -186,6 +186,11 @@ struct ufs_hba { ...@@ -186,6 +186,11 @@ struct ufs_hba {
u32 errors; u32 errors;
}; };
#define ufshcd_writel(hba, val, reg) \
writel((val), (hba)->mmio_base + (reg))
#define ufshcd_readl(hba, reg) \
readl((hba)->mmio_base + (reg))
int ufshcd_init(struct device *, struct ufs_hba ** , void __iomem * , int ufshcd_init(struct device *, struct ufs_hba ** , void __iomem * ,
unsigned int); unsigned int);
void ufshcd_remove(struct ufs_hba *); void ufshcd_remove(struct ufs_hba *);
...@@ -196,7 +201,7 @@ void ufshcd_remove(struct ufs_hba *); ...@@ -196,7 +201,7 @@ void ufshcd_remove(struct ufs_hba *);
*/ */
static inline void ufshcd_hba_stop(struct ufs_hba *hba) static inline void ufshcd_hba_stop(struct ufs_hba *hba)
{ {
writel(CONTROLLER_DISABLE, (hba->mmio_base + REG_CONTROLLER_ENABLE)); ufshcd_writel(hba, CONTROLLER_DISABLE, REG_CONTROLLER_ENABLE);
} }
#endif /* End of Header */ #endif /* End of Header */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment