1 #ifndef DW_SPI_HEADER_H
2 #define DW_SPI_HEADER_H
5 /* Bit fields in CTRLR0 */
6 #define SPI_DFS_OFFSET 0
8 #define SPI_FRF_OFFSET 4
9 #define SPI_FRF_SPI 0x0
10 #define SPI_FRF_SSP 0x1
11 #define SPI_FRF_MICROWIRE 0x2
12 #define SPI_FRF_RESV 0x3
14 #define SPI_MODE_OFFSET 6
15 #define SPI_SCPH_OFFSET 6
16 #define SPI_SCOL_OFFSET 7
17 #define SPI_TMOD_OFFSET 8
18 #define SPI_TMOD_TR 0x0 /* xmit & recv */
19 #define SPI_TMOD_TO 0x1 /* xmit only */
20 #define SPI_TMOD_RO 0x2 /* recv only */
21 #define SPI_TMOD_EPROMREAD 0x3 /* eeprom read mode */
23 #define SPI_SLVOE_OFFSET 10
24 #define SPI_SRL_OFFSET 11
25 #define SPI_CFS_OFFSET 12
27 /* Bit fields in SR, 7 bits */
28 #define SR_MASK 0x7f /* cover 7 bits */
29 #define SR_BUSY (1 << 0)
30 #define SR_TF_NOT_FULL (1 << 1)
31 #define SR_TF_EMPT (1 << 2)
32 #define SR_RF_NOT_EMPT (1 << 3)
33 #define SR_RF_FULL (1 << 4)
34 #define SR_TX_ERR (1 << 5)
35 #define SR_DCOL (1 << 6)
37 /* Bit fields in ISR, IMR, RISR, 7 bits */
38 #define SPI_INT_TXEI (1 << 0)
39 #define SPI_INT_TXOI (1 << 1)
40 #define SPI_INT_RXUI (1 << 2)
41 #define SPI_INT_RXOI (1 << 3)
42 #define SPI_INT_RXFI (1 << 4)
43 #define SPI_INT_MSTI (1 << 5)
45 /* TX RX interrupt level threshhold, max can be 256 */
46 #define SPI_INT_THRESHOLD 32
79 u32 dr
; /* Currently oper as 32 bits,
80 though only low 16 bits matters */
84 struct spi_master
*master
;
85 struct spi_device
*cur_dev
;
86 struct device
*parent_dev
;
87 enum dw_ssi_type type
;
93 u32 fifo_len
; /* depth of the FIFO buffer */
94 u32 max_freq
; /* max bus freq supported */
97 u16 num_cs
; /* supported slave numbers */
99 /* Driver message queue */
100 struct workqueue_struct
*workqueue
;
101 struct work_struct pump_messages
;
103 struct list_head queue
;
107 /* Message Transfer pump */
108 struct tasklet_struct pump_transfers
;
110 /* Current message transfer state info */
111 struct spi_message
*cur_msg
;
112 struct spi_transfer
*cur_transfer
;
113 struct chip_data
*cur_chip
;
114 struct chip_data
*prev_chip
;
125 u8 n_bytes
; /* current is a 1/2 bytes op */
126 u8 max_bits_per_word
; /* maxim is 16b */
129 int (*write
)(struct dw_spi
*dws
);
130 int (*read
)(struct dw_spi
*dws
);
131 irqreturn_t (*transfer_handler
)(struct dw_spi
*dws
);
132 void (*cs_control
)(u32 command
);
136 struct dma_chan
*txchan
;
137 struct dma_chan
*rxchan
;
142 struct device
*dma_dev
;
145 /* Bus interface info */
147 #ifdef CONFIG_DEBUG_FS
148 struct dentry
*debugfs
;
152 #define dw_readl(dw, name) \
153 __raw_readl(&(((struct dw_spi_reg *)dw->regs)->name))
154 #define dw_writel(dw, name, val) \
155 __raw_writel((val), &(((struct dw_spi_reg *)dw->regs)->name))
156 #define dw_readw(dw, name) \
157 __raw_readw(&(((struct dw_spi_reg *)dw->regs)->name))
158 #define dw_writew(dw, name, val) \
159 __raw_writew((val), &(((struct dw_spi_reg *)dw->regs)->name))
161 static inline void spi_enable_chip(struct dw_spi
*dws
, int enable
)
163 dw_writel(dws
, ssienr
, (enable
? 1 : 0));
166 static inline void spi_set_clk(struct dw_spi
*dws
, u16 div
)
168 dw_writel(dws
, baudr
, div
);
171 static inline void spi_chip_sel(struct dw_spi
*dws
, u16 cs
)
173 if (cs
> dws
->num_cs
)
179 dw_writel(dws
, ser
, 1 << cs
);
182 /* Disable IRQ bits */
183 static inline void spi_mask_intr(struct dw_spi
*dws
, u32 mask
)
187 new_mask
= dw_readl(dws
, imr
) & ~mask
;
188 dw_writel(dws
, imr
, new_mask
);
191 /* Enable IRQ bits */
192 static inline void spi_umask_intr(struct dw_spi
*dws
, u32 mask
)
196 new_mask
= dw_readl(dws
, imr
) | mask
;
197 dw_writel(dws
, imr
, new_mask
);
201 * Each SPI slave device to work with dw_api controller should
202 * has such a structure claiming its working mode (PIO/DMA etc),
203 * which can be save in the "controller_data" member of the
207 u8 poll_mode
; /* 0 for contoller polling mode */
208 u8 type
; /* SPI/SSP/Micrwire */
210 void (*cs_control
)(u32 command
);
213 extern int dw_spi_add_host(struct dw_spi
*dws
);
214 extern void dw_spi_remove_host(struct dw_spi
*dws
);
215 extern int dw_spi_suspend_host(struct dw_spi
*dws
);
216 extern int dw_spi_resume_host(struct dw_spi
*dws
);
217 #endif /* DW_SPI_HEADER_H */