blob: 787ad569c99b7f7d02ac97d193e816bb1623dbc5 [file] [log] [blame]
Will Newtonf95f3852011-01-02 01:11:59 -05001/*
2 * Synopsys DesignWare Multimedia Card Interface driver
3 * (Based on NXP driver for lpc 31xx)
4 *
5 * Copyright (C) 2009 NXP Semiconductors
6 * Copyright (C) 2009, 2010 Imagination Technologies Ltd.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 */
13
Robert P. J. Day100e9182011-05-27 16:04:03 -040014#ifndef LINUX_MMC_DW_MMC_H
15#define LINUX_MMC_DW_MMC_H
Will Newtonf95f3852011-01-02 01:11:59 -050016
Seungwon Jeonf9c2a0d2012-02-09 14:32:43 +090017#include <linux/scatterlist.h>
18
Will Newtonf95f3852011-01-02 01:11:59 -050019#define MAX_MCI_SLOTS 2
20
21enum dw_mci_state {
22 STATE_IDLE = 0,
23 STATE_SENDING_CMD,
24 STATE_SENDING_DATA,
25 STATE_DATA_BUSY,
26 STATE_SENDING_STOP,
27 STATE_DATA_ERROR,
28};
29
30enum {
31 EVENT_CMD_COMPLETE = 0,
32 EVENT_XFER_COMPLETE,
33 EVENT_DATA_COMPLETE,
34 EVENT_DATA_ERROR,
35 EVENT_XFER_ERROR
36};
37
38struct mmc_data;
39
40/**
41 * struct dw_mci - MMC controller state shared between all slots
42 * @lock: Spinlock protecting the queue and associated data.
43 * @regs: Pointer to MMIO registers.
44 * @sg: Scatterlist entry currently being processed by PIO code, if any.
Seungwon Jeonf9c2a0d2012-02-09 14:32:43 +090045 * @sg_miter: PIO mapping scatterlist iterator.
Will Newtonf95f3852011-01-02 01:11:59 -050046 * @cur_slot: The slot which is currently using the controller.
47 * @mrq: The request currently being processed on @cur_slot,
48 * or NULL if the controller is idle.
49 * @cmd: The command currently being sent to the card, or NULL.
50 * @data: The data currently being transferred, or NULL if no data
51 * transfer is in progress.
52 * @use_dma: Whether DMA channel is initialized or not.
James Hogan03e8cb52011-06-29 09:28:43 +010053 * @using_dma: Whether DMA is in use for the current transfer.
Will Newtonf95f3852011-01-02 01:11:59 -050054 * @sg_dma: Bus address of DMA buffer.
55 * @sg_cpu: Virtual address of DMA buffer.
56 * @dma_ops: Pointer to platform-specific DMA callbacks.
57 * @cmd_status: Snapshot of SR taken upon completion of the current
58 * command. Only valid when EVENT_CMD_COMPLETE is pending.
59 * @data_status: Snapshot of SR taken upon completion of the current
60 * data transfer. Only valid when EVENT_DATA_COMPLETE or
61 * EVENT_DATA_ERROR is pending.
62 * @stop_cmdr: Value to be loaded into CMDR when the stop command is
63 * to be sent.
64 * @dir_status: Direction of current transfer.
65 * @tasklet: Tasklet running the request state machine.
66 * @card_tasklet: Tasklet handling card detect.
67 * @pending_events: Bitmask of events flagged by the interrupt handler
68 * to be processed by the tasklet.
69 * @completed_events: Bitmask of events which the state machine has
70 * processed.
71 * @state: Tasklet state.
72 * @queue: List of slots waiting for access to the controller.
73 * @bus_hz: The rate of @mck in Hz. This forms the basis for MMC bus
74 * rate and timeout calculations.
75 * @current_speed: Configured rate of the controller.
76 * @num_slots: Number of slots available.
Jaehoon Chung4e0a5ad2011-10-17 19:36:23 +090077 * @verid: Denote Version ID.
78 * @data_offset: Set the offset of DATA register according to VERID.
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +053079 * @dev: Device associated with the MMC controller.
Will Newtonf95f3852011-01-02 01:11:59 -050080 * @pdata: Platform data associated with the MMC controller.
Thomas Abrahamf90a0612012-09-17 18:16:38 +000081 * @biu_clk: Pointer to bus interface unit clock instance.
82 * @ciu_clk: Pointer to card interface unit clock instance.
Will Newtonf95f3852011-01-02 01:11:59 -050083 * @slot: Slots sharing this MMC controller.
James Hoganb86d8252011-06-24 13:57:18 +010084 * @fifo_depth: depth of FIFO.
Will Newtonf95f3852011-01-02 01:11:59 -050085 * @data_shift: log2 of FIFO item size.
James Hogan34b664a2011-06-24 13:57:56 +010086 * @part_buf_start: Start index in part_buf.
87 * @part_buf_count: Bytes of partial data in part_buf.
88 * @part_buf: Simple buffer for partial fifo reads/writes.
Will Newtonf95f3852011-01-02 01:11:59 -050089 * @push_data: Pointer to FIFO push function.
90 * @pull_data: Pointer to FIFO pull function.
91 * @quirks: Set of quirks that apply to specific versions of the IP.
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +053092 * @irq_flags: The flags to be passed to request_irq.
93 * @irq: The irq value to be passed to request_irq.
Will Newtonf95f3852011-01-02 01:11:59 -050094 *
95 * Locking
96 * =======
97 *
98 * @lock is a softirq-safe spinlock protecting @queue as well as
99 * @cur_slot, @mrq and @state. These must always be updated
100 * at the same time while holding @lock.
101 *
102 * The @mrq field of struct dw_mci_slot is also protected by @lock,
103 * and must always be written at the same time as the slot is added to
104 * @queue.
105 *
106 * @pending_events and @completed_events are accessed using atomic bit
107 * operations, so they don't need any locking.
108 *
109 * None of the fields touched by the interrupt handler need any
110 * locking. However, ordering is important: Before EVENT_DATA_ERROR or
111 * EVENT_DATA_COMPLETE is set in @pending_events, all data-related
112 * interrupts must be disabled and @data_status updated with a
113 * snapshot of SR. Similarly, before EVENT_CMD_COMPLETE is set, the
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300114 * CMDRDY interrupt must be disabled and @cmd_status updated with a
Will Newtonf95f3852011-01-02 01:11:59 -0500115 * snapshot of SR, and before EVENT_XFER_COMPLETE can be set, the
116 * bytes_xfered field of @data must be written. This is ensured by
117 * using barriers.
118 */
119struct dw_mci {
120 spinlock_t lock;
121 void __iomem *regs;
122
123 struct scatterlist *sg;
Seungwon Jeonf9c2a0d2012-02-09 14:32:43 +0900124 struct sg_mapping_iter sg_miter;
Will Newtonf95f3852011-01-02 01:11:59 -0500125
126 struct dw_mci_slot *cur_slot;
127 struct mmc_request *mrq;
128 struct mmc_command *cmd;
129 struct mmc_data *data;
Thomas Abraham95dcc2c2012-05-01 14:57:36 -0700130 struct workqueue_struct *card_workqueue;
Will Newtonf95f3852011-01-02 01:11:59 -0500131
132 /* DMA interface members*/
133 int use_dma;
James Hogan03e8cb52011-06-29 09:28:43 +0100134 int using_dma;
Will Newtonf95f3852011-01-02 01:11:59 -0500135
136 dma_addr_t sg_dma;
137 void *sg_cpu;
138 struct dw_mci_dma_ops *dma_ops;
139#ifdef CONFIG_MMC_DW_IDMAC
140 unsigned int ring_size;
141#else
142 struct dw_mci_dma_data *dma_data;
143#endif
144 u32 cmd_status;
145 u32 data_status;
146 u32 stop_cmdr;
147 u32 dir_status;
148 struct tasklet_struct tasklet;
James Hogan1791b13e2011-06-24 13:55:55 +0100149 struct work_struct card_work;
Will Newtonf95f3852011-01-02 01:11:59 -0500150 unsigned long pending_events;
151 unsigned long completed_events;
152 enum dw_mci_state state;
153 struct list_head queue;
154
155 u32 bus_hz;
156 u32 current_speed;
157 u32 num_slots;
Jaehoon Chunge61cf112011-03-17 20:32:33 +0900158 u32 fifoth_val;
Jaehoon Chung4e0a5ad2011-10-17 19:36:23 +0900159 u16 verid;
160 u16 data_offset;
Thomas Abraham4a909202012-09-17 18:16:35 +0000161 struct device *dev;
Will Newtonf95f3852011-01-02 01:11:59 -0500162 struct dw_mci_board *pdata;
Thomas Abrahamf90a0612012-09-17 18:16:38 +0000163 struct clk *biu_clk;
164 struct clk *ciu_clk;
Will Newtonf95f3852011-01-02 01:11:59 -0500165 struct dw_mci_slot *slot[MAX_MCI_SLOTS];
166
167 /* FIFO push and pull */
James Hoganb86d8252011-06-24 13:57:18 +0100168 int fifo_depth;
Will Newtonf95f3852011-01-02 01:11:59 -0500169 int data_shift;
James Hogan34b664a2011-06-24 13:57:56 +0100170 u8 part_buf_start;
171 u8 part_buf_count;
172 union {
173 u16 part_buf16;
174 u32 part_buf32;
175 u64 part_buf;
176 };
Will Newtonf95f3852011-01-02 01:11:59 -0500177 void (*push_data)(struct dw_mci *host, void *buf, int cnt);
178 void (*pull_data)(struct dw_mci *host, void *buf, int cnt);
179
180 /* Workaround flags */
181 u32 quirks;
Jaehoon Chungc07946a2011-02-25 11:08:14 +0900182
183 struct regulator *vmmc; /* Power regulator */
Shashidhar Hiremath62ca8032012-01-13 16:04:57 +0530184 unsigned long irq_flags; /* IRQ flags */
185 unsigned int irq;
Will Newtonf95f3852011-01-02 01:11:59 -0500186};
187
188/* DMA ops for Internal/External DMAC interface */
189struct dw_mci_dma_ops {
190 /* DMA Ops */
191 int (*init)(struct dw_mci *host);
192 void (*start)(struct dw_mci *host, unsigned int sg_len);
193 void (*complete)(struct dw_mci *host);
194 void (*stop)(struct dw_mci *host);
195 void (*cleanup)(struct dw_mci *host);
196 void (*exit)(struct dw_mci *host);
197};
198
199/* IP Quirks/flags. */
Will Newtonf95f3852011-01-02 01:11:59 -0500200/* DTO fix for command transmission with IDMAC configured */
Jaehoon Chungfc3d7722011-02-25 11:08:15 +0900201#define DW_MCI_QUIRK_IDMAC_DTO BIT(0)
Will Newtonf95f3852011-01-02 01:11:59 -0500202/* delay needed between retries on some 2.11a implementations */
Jaehoon Chungfc3d7722011-02-25 11:08:15 +0900203#define DW_MCI_QUIRK_RETRY_DELAY BIT(1)
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300204/* High Speed Capable - Supports HS cards (up to 50MHz) */
Jaehoon Chungfc3d7722011-02-25 11:08:15 +0900205#define DW_MCI_QUIRK_HIGHSPEED BIT(2)
206/* Unreliable card detection */
207#define DW_MCI_QUIRK_BROKEN_CARD_DETECTION BIT(3)
Will Newtonf95f3852011-01-02 01:11:59 -0500208
209
210struct dma_pdata;
211
212struct block_settings {
213 unsigned short max_segs; /* see blk_queue_max_segments */
214 unsigned int max_blk_size; /* maximum size of one mmc block */
215 unsigned int max_blk_count; /* maximum number of blocks in one req*/
216 unsigned int max_req_size; /* maximum number of bytes in one req*/
217 unsigned int max_seg_size; /* see blk_queue_max_segment_size */
218};
219
220/* Board platform data */
221struct dw_mci_board {
222 u32 num_slots;
223
224 u32 quirks; /* Workaround / Quirk flags */
225 unsigned int bus_hz; /* Bus speed */
226
Jaehoon Chungfc3d7722011-02-25 11:08:15 +0900227 unsigned int caps; /* Capabilities */
Seungwon Jeon4f408cc2011-12-09 14:55:52 +0900228 unsigned int caps2; /* More capabilities */
James Hoganb86d8252011-06-24 13:57:18 +0100229 /*
230 * Override fifo depth. If 0, autodetect it from the FIFOTH register,
231 * but note that this may not be reliable after a bootloader has used
232 * it.
233 */
234 unsigned int fifo_depth;
Jaehoon Chungfc3d7722011-02-25 11:08:15 +0900235
Will Newtonf95f3852011-01-02 01:11:59 -0500236 /* delay in mS before detecting cards after interrupt */
237 u32 detect_delay_ms;
238
239 int (*init)(u32 slot_id, irq_handler_t , void *);
240 int (*get_ro)(u32 slot_id);
241 int (*get_cd)(u32 slot_id);
242 int (*get_ocr)(u32 slot_id);
243 int (*get_bus_wd)(u32 slot_id);
244 /*
245 * Enable power to selected slot and set voltage to desired level.
246 * Voltage levels are specified using MMC_VDD_xxx defines defined
247 * in linux/mmc/host.h file.
248 */
249 void (*setpower)(u32 slot_id, u32 volt);
250 void (*exit)(u32 slot_id);
251 void (*select_slot)(u32 slot_id);
252
253 struct dw_mci_dma_ops *dma_ops;
254 struct dma_pdata *data;
255 struct block_settings *blk_settings;
256};
257
Robert P. J. Day100e9182011-05-27 16:04:03 -0400258#endif /* LINUX_MMC_DW_MMC_H */