Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 1 | /* |
| 2 | * OMAP2 McSPI controller driver |
| 3 | * |
| 4 | * Copyright (C) 2005, 2006 Nokia Corporation |
| 5 | * Author: Samuel Ortiz <samuel.ortiz@nokia.com> and |
Charulatha V | 1a5d819 | 2011-02-02 17:52:14 +0530 | [diff] [blame] | 6 | * Juha Yrj�l� <juha.yrjola@nokia.com> |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 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 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | #include <linux/kernel.h> |
| 25 | #include <linux/init.h> |
| 26 | #include <linux/interrupt.h> |
| 27 | #include <linux/module.h> |
| 28 | #include <linux/device.h> |
| 29 | #include <linux/delay.h> |
| 30 | #include <linux/dma-mapping.h> |
| 31 | #include <linux/platform_device.h> |
| 32 | #include <linux/err.h> |
| 33 | #include <linux/clk.h> |
| 34 | #include <linux/io.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 35 | #include <linux/slab.h> |
Govindraj.R | 1f1a438 | 2011-02-02 17:52:15 +0530 | [diff] [blame] | 36 | #include <linux/pm_runtime.h> |
Benoit Cousson | d5a8003 | 2012-02-15 18:37:34 +0100 | [diff] [blame] | 37 | #include <linux/of.h> |
| 38 | #include <linux/of_device.h> |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 39 | |
| 40 | #include <linux/spi/spi.h> |
| 41 | |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 42 | #include <plat/dma.h> |
| 43 | #include <plat/clock.h> |
Roman Tereshonkov | 4743a0f | 2010-04-13 10:41:51 +0000 | [diff] [blame] | 44 | #include <plat/mcspi.h> |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 45 | |
| 46 | #define OMAP2_MCSPI_MAX_FREQ 48000000 |
Shubhrajyoti D | 27b5284 | 2012-03-26 17:04:22 +0530 | [diff] [blame^] | 47 | #define SPI_AUTOSUSPEND_TIMEOUT 2000 |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 48 | |
| 49 | #define OMAP2_MCSPI_REVISION 0x00 |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 50 | #define OMAP2_MCSPI_SYSSTATUS 0x14 |
| 51 | #define OMAP2_MCSPI_IRQSTATUS 0x18 |
| 52 | #define OMAP2_MCSPI_IRQENABLE 0x1c |
| 53 | #define OMAP2_MCSPI_WAKEUPENABLE 0x20 |
| 54 | #define OMAP2_MCSPI_SYST 0x24 |
| 55 | #define OMAP2_MCSPI_MODULCTRL 0x28 |
| 56 | |
| 57 | /* per-channel banks, 0x14 bytes each, first is: */ |
| 58 | #define OMAP2_MCSPI_CHCONF0 0x2c |
| 59 | #define OMAP2_MCSPI_CHSTAT0 0x30 |
| 60 | #define OMAP2_MCSPI_CHCTRL0 0x34 |
| 61 | #define OMAP2_MCSPI_TX0 0x38 |
| 62 | #define OMAP2_MCSPI_RX0 0x3c |
| 63 | |
| 64 | /* per-register bitmasks: */ |
| 65 | |
Jouni Hogander | 7a8fa72 | 2009-09-22 16:45:58 -0700 | [diff] [blame] | 66 | #define OMAP2_MCSPI_MODULCTRL_SINGLE BIT(0) |
| 67 | #define OMAP2_MCSPI_MODULCTRL_MS BIT(2) |
| 68 | #define OMAP2_MCSPI_MODULCTRL_STEST BIT(3) |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 69 | |
Jouni Hogander | 7a8fa72 | 2009-09-22 16:45:58 -0700 | [diff] [blame] | 70 | #define OMAP2_MCSPI_CHCONF_PHA BIT(0) |
| 71 | #define OMAP2_MCSPI_CHCONF_POL BIT(1) |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 72 | #define OMAP2_MCSPI_CHCONF_CLKD_MASK (0x0f << 2) |
Jouni Hogander | 7a8fa72 | 2009-09-22 16:45:58 -0700 | [diff] [blame] | 73 | #define OMAP2_MCSPI_CHCONF_EPOL BIT(6) |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 74 | #define OMAP2_MCSPI_CHCONF_WL_MASK (0x1f << 7) |
Jouni Hogander | 7a8fa72 | 2009-09-22 16:45:58 -0700 | [diff] [blame] | 75 | #define OMAP2_MCSPI_CHCONF_TRM_RX_ONLY BIT(12) |
| 76 | #define OMAP2_MCSPI_CHCONF_TRM_TX_ONLY BIT(13) |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 77 | #define OMAP2_MCSPI_CHCONF_TRM_MASK (0x03 << 12) |
Jouni Hogander | 7a8fa72 | 2009-09-22 16:45:58 -0700 | [diff] [blame] | 78 | #define OMAP2_MCSPI_CHCONF_DMAW BIT(14) |
| 79 | #define OMAP2_MCSPI_CHCONF_DMAR BIT(15) |
| 80 | #define OMAP2_MCSPI_CHCONF_DPE0 BIT(16) |
| 81 | #define OMAP2_MCSPI_CHCONF_DPE1 BIT(17) |
| 82 | #define OMAP2_MCSPI_CHCONF_IS BIT(18) |
| 83 | #define OMAP2_MCSPI_CHCONF_TURBO BIT(19) |
| 84 | #define OMAP2_MCSPI_CHCONF_FORCE BIT(20) |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 85 | |
Jouni Hogander | 7a8fa72 | 2009-09-22 16:45:58 -0700 | [diff] [blame] | 86 | #define OMAP2_MCSPI_CHSTAT_RXS BIT(0) |
| 87 | #define OMAP2_MCSPI_CHSTAT_TXS BIT(1) |
| 88 | #define OMAP2_MCSPI_CHSTAT_EOT BIT(2) |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 89 | |
Jouni Hogander | 7a8fa72 | 2009-09-22 16:45:58 -0700 | [diff] [blame] | 90 | #define OMAP2_MCSPI_CHCTRL_EN BIT(0) |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 91 | |
Jouni Hogander | 7a8fa72 | 2009-09-22 16:45:58 -0700 | [diff] [blame] | 92 | #define OMAP2_MCSPI_WAKEUPENABLE_WKEN BIT(0) |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 93 | |
| 94 | /* We have 2 DMA channels per CS, one for RX and one for TX */ |
| 95 | struct omap2_mcspi_dma { |
| 96 | int dma_tx_channel; |
| 97 | int dma_rx_channel; |
| 98 | |
| 99 | int dma_tx_sync_dev; |
| 100 | int dma_rx_sync_dev; |
| 101 | |
| 102 | struct completion dma_tx_completion; |
| 103 | struct completion dma_rx_completion; |
| 104 | }; |
| 105 | |
| 106 | /* use PIO for small transfers, avoiding DMA setup/teardown overhead and |
| 107 | * cache operations; better heuristics consider wordsize and bitrate. |
| 108 | */ |
Roman Tereshonkov | 8b66c13 | 2010-04-12 09:07:54 +0000 | [diff] [blame] | 109 | #define DMA_MIN_BYTES 160 |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 110 | |
| 111 | |
Benoit Cousson | 1bd897f8 | 2012-03-26 15:32:33 +0530 | [diff] [blame] | 112 | /* |
| 113 | * Used for context save and restore, structure members to be updated whenever |
| 114 | * corresponding registers are modified. |
| 115 | */ |
| 116 | struct omap2_mcspi_regs { |
| 117 | u32 modulctrl; |
| 118 | u32 wakeupenable; |
| 119 | struct list_head cs; |
| 120 | }; |
| 121 | |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 122 | struct omap2_mcspi { |
| 123 | struct work_struct work; |
| 124 | /* lock protects queue and registers */ |
| 125 | spinlock_t lock; |
| 126 | struct list_head msg_queue; |
| 127 | struct spi_master *master; |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 128 | /* Virtual base address of the controller */ |
| 129 | void __iomem *base; |
Russell King | e5480b73 | 2008-09-01 21:51:50 +0100 | [diff] [blame] | 130 | unsigned long phys; |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 131 | /* SPI1 has 4 channels, while SPI2 has 2 */ |
| 132 | struct omap2_mcspi_dma *dma_channels; |
Benoit Cousson | 1bd897f8 | 2012-03-26 15:32:33 +0530 | [diff] [blame] | 133 | struct device *dev; |
Shubhrajyoti D | 2856ac1 | 2011-10-28 17:14:17 +0530 | [diff] [blame] | 134 | struct workqueue_struct *wq; |
Benoit Cousson | 1bd897f8 | 2012-03-26 15:32:33 +0530 | [diff] [blame] | 135 | struct omap2_mcspi_regs ctx; |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 136 | }; |
| 137 | |
| 138 | struct omap2_mcspi_cs { |
| 139 | void __iomem *base; |
Russell King | e5480b73 | 2008-09-01 21:51:50 +0100 | [diff] [blame] | 140 | unsigned long phys; |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 141 | int word_len; |
Tero Kristo | 89c0537 | 2009-09-22 16:46:17 -0700 | [diff] [blame] | 142 | struct list_head node; |
Hemanth V | a41ae1a | 2009-09-22 16:46:16 -0700 | [diff] [blame] | 143 | /* Context save and restore shadow register */ |
| 144 | u32 chconf0; |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 145 | }; |
| 146 | |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 147 | #define MOD_REG_BIT(val, mask, set) do { \ |
| 148 | if (set) \ |
| 149 | val |= mask; \ |
| 150 | else \ |
| 151 | val &= ~mask; \ |
| 152 | } while (0) |
| 153 | |
| 154 | static inline void mcspi_write_reg(struct spi_master *master, |
| 155 | int idx, u32 val) |
| 156 | { |
| 157 | struct omap2_mcspi *mcspi = spi_master_get_devdata(master); |
| 158 | |
| 159 | __raw_writel(val, mcspi->base + idx); |
| 160 | } |
| 161 | |
| 162 | static inline u32 mcspi_read_reg(struct spi_master *master, int idx) |
| 163 | { |
| 164 | struct omap2_mcspi *mcspi = spi_master_get_devdata(master); |
| 165 | |
| 166 | return __raw_readl(mcspi->base + idx); |
| 167 | } |
| 168 | |
| 169 | static inline void mcspi_write_cs_reg(const struct spi_device *spi, |
| 170 | int idx, u32 val) |
| 171 | { |
| 172 | struct omap2_mcspi_cs *cs = spi->controller_state; |
| 173 | |
| 174 | __raw_writel(val, cs->base + idx); |
| 175 | } |
| 176 | |
| 177 | static inline u32 mcspi_read_cs_reg(const struct spi_device *spi, int idx) |
| 178 | { |
| 179 | struct omap2_mcspi_cs *cs = spi->controller_state; |
| 180 | |
| 181 | return __raw_readl(cs->base + idx); |
| 182 | } |
| 183 | |
Hemanth V | a41ae1a | 2009-09-22 16:46:16 -0700 | [diff] [blame] | 184 | static inline u32 mcspi_cached_chconf0(const struct spi_device *spi) |
| 185 | { |
| 186 | struct omap2_mcspi_cs *cs = spi->controller_state; |
| 187 | |
| 188 | return cs->chconf0; |
| 189 | } |
| 190 | |
| 191 | static inline void mcspi_write_chconf0(const struct spi_device *spi, u32 val) |
| 192 | { |
| 193 | struct omap2_mcspi_cs *cs = spi->controller_state; |
| 194 | |
| 195 | cs->chconf0 = val; |
| 196 | mcspi_write_cs_reg(spi, OMAP2_MCSPI_CHCONF0, val); |
Roman Tereshonkov | a330ce2 | 2010-03-15 09:06:28 +0000 | [diff] [blame] | 197 | mcspi_read_cs_reg(spi, OMAP2_MCSPI_CHCONF0); |
Hemanth V | a41ae1a | 2009-09-22 16:46:16 -0700 | [diff] [blame] | 198 | } |
| 199 | |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 200 | static void omap2_mcspi_set_dma_req(const struct spi_device *spi, |
| 201 | int is_read, int enable) |
| 202 | { |
| 203 | u32 l, rw; |
| 204 | |
Hemanth V | a41ae1a | 2009-09-22 16:46:16 -0700 | [diff] [blame] | 205 | l = mcspi_cached_chconf0(spi); |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 206 | |
| 207 | if (is_read) /* 1 is read, 0 write */ |
| 208 | rw = OMAP2_MCSPI_CHCONF_DMAR; |
| 209 | else |
| 210 | rw = OMAP2_MCSPI_CHCONF_DMAW; |
| 211 | |
| 212 | MOD_REG_BIT(l, rw, enable); |
Hemanth V | a41ae1a | 2009-09-22 16:46:16 -0700 | [diff] [blame] | 213 | mcspi_write_chconf0(spi, l); |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | static void omap2_mcspi_set_enable(const struct spi_device *spi, int enable) |
| 217 | { |
| 218 | u32 l; |
| 219 | |
| 220 | l = enable ? OMAP2_MCSPI_CHCTRL_EN : 0; |
| 221 | mcspi_write_cs_reg(spi, OMAP2_MCSPI_CHCTRL0, l); |
Roman Tereshonkov | 4743a0f | 2010-04-13 10:41:51 +0000 | [diff] [blame] | 222 | /* Flash post-writes */ |
| 223 | mcspi_read_cs_reg(spi, OMAP2_MCSPI_CHCTRL0); |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | static void omap2_mcspi_force_cs(struct spi_device *spi, int cs_active) |
| 227 | { |
| 228 | u32 l; |
| 229 | |
Hemanth V | a41ae1a | 2009-09-22 16:46:16 -0700 | [diff] [blame] | 230 | l = mcspi_cached_chconf0(spi); |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 231 | MOD_REG_BIT(l, OMAP2_MCSPI_CHCONF_FORCE, cs_active); |
Hemanth V | a41ae1a | 2009-09-22 16:46:16 -0700 | [diff] [blame] | 232 | mcspi_write_chconf0(spi, l); |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | static void omap2_mcspi_set_master_mode(struct spi_master *master) |
| 236 | { |
Benoit Cousson | 1bd897f8 | 2012-03-26 15:32:33 +0530 | [diff] [blame] | 237 | struct omap2_mcspi *mcspi = spi_master_get_devdata(master); |
| 238 | struct omap2_mcspi_regs *ctx = &mcspi->ctx; |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 239 | u32 l; |
| 240 | |
Benoit Cousson | 1bd897f8 | 2012-03-26 15:32:33 +0530 | [diff] [blame] | 241 | /* |
| 242 | * Setup when switching from (reset default) slave mode |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 243 | * to single-channel master mode |
| 244 | */ |
| 245 | l = mcspi_read_reg(master, OMAP2_MCSPI_MODULCTRL); |
| 246 | MOD_REG_BIT(l, OMAP2_MCSPI_MODULCTRL_STEST, 0); |
| 247 | MOD_REG_BIT(l, OMAP2_MCSPI_MODULCTRL_MS, 0); |
| 248 | MOD_REG_BIT(l, OMAP2_MCSPI_MODULCTRL_SINGLE, 1); |
| 249 | mcspi_write_reg(master, OMAP2_MCSPI_MODULCTRL, l); |
Hemanth V | a41ae1a | 2009-09-22 16:46:16 -0700 | [diff] [blame] | 250 | |
Benoit Cousson | 1bd897f8 | 2012-03-26 15:32:33 +0530 | [diff] [blame] | 251 | ctx->modulctrl = l; |
Hemanth V | a41ae1a | 2009-09-22 16:46:16 -0700 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | static void omap2_mcspi_restore_ctx(struct omap2_mcspi *mcspi) |
| 255 | { |
Benoit Cousson | 1bd897f8 | 2012-03-26 15:32:33 +0530 | [diff] [blame] | 256 | struct spi_master *spi_cntrl = mcspi->master; |
| 257 | struct omap2_mcspi_regs *ctx = &mcspi->ctx; |
| 258 | struct omap2_mcspi_cs *cs; |
Hemanth V | a41ae1a | 2009-09-22 16:46:16 -0700 | [diff] [blame] | 259 | |
| 260 | /* McSPI: context restore */ |
Benoit Cousson | 1bd897f8 | 2012-03-26 15:32:33 +0530 | [diff] [blame] | 261 | mcspi_write_reg(spi_cntrl, OMAP2_MCSPI_MODULCTRL, ctx->modulctrl); |
| 262 | mcspi_write_reg(spi_cntrl, OMAP2_MCSPI_WAKEUPENABLE, ctx->wakeupenable); |
Hemanth V | a41ae1a | 2009-09-22 16:46:16 -0700 | [diff] [blame] | 263 | |
Benoit Cousson | 1bd897f8 | 2012-03-26 15:32:33 +0530 | [diff] [blame] | 264 | list_for_each_entry(cs, &ctx->cs, node) |
Tero Kristo | 89c0537 | 2009-09-22 16:46:17 -0700 | [diff] [blame] | 265 | __raw_writel(cs->chconf0, cs->base + OMAP2_MCSPI_CHCONF0); |
Hemanth V | a41ae1a | 2009-09-22 16:46:16 -0700 | [diff] [blame] | 266 | } |
| 267 | static void omap2_mcspi_disable_clocks(struct omap2_mcspi *mcspi) |
| 268 | { |
Shubhrajyoti D | 27b5284 | 2012-03-26 17:04:22 +0530 | [diff] [blame^] | 269 | pm_runtime_mark_last_busy(mcspi->dev); |
| 270 | pm_runtime_put_autosuspend(mcspi->dev); |
Hemanth V | a41ae1a | 2009-09-22 16:46:16 -0700 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | static int omap2_mcspi_enable_clocks(struct omap2_mcspi *mcspi) |
| 274 | { |
Govindraj.R | 1f1a438 | 2011-02-02 17:52:15 +0530 | [diff] [blame] | 275 | return pm_runtime_get_sync(mcspi->dev); |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 276 | } |
| 277 | |
Ilkka Koskinen | 2764c50 | 2010-10-19 17:07:31 +0300 | [diff] [blame] | 278 | static int mcspi_wait_for_reg_bit(void __iomem *reg, unsigned long bit) |
| 279 | { |
| 280 | unsigned long timeout; |
| 281 | |
| 282 | timeout = jiffies + msecs_to_jiffies(1000); |
| 283 | while (!(__raw_readl(reg) & bit)) { |
| 284 | if (time_after(jiffies, timeout)) |
| 285 | return -1; |
| 286 | cpu_relax(); |
| 287 | } |
| 288 | return 0; |
| 289 | } |
| 290 | |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 291 | static unsigned |
| 292 | omap2_mcspi_txrx_dma(struct spi_device *spi, struct spi_transfer *xfer) |
| 293 | { |
| 294 | struct omap2_mcspi *mcspi; |
| 295 | struct omap2_mcspi_cs *cs = spi->controller_state; |
| 296 | struct omap2_mcspi_dma *mcspi_dma; |
| 297 | unsigned int count, c; |
| 298 | unsigned long base, tx_reg, rx_reg; |
| 299 | int word_len, data_type, element_count; |
Govindraj.R | 8b20c8c | 2011-06-01 11:31:24 +0530 | [diff] [blame] | 300 | int elements = 0; |
Roman Tereshonkov | 4743a0f | 2010-04-13 10:41:51 +0000 | [diff] [blame] | 301 | u32 l; |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 302 | u8 * rx; |
| 303 | const u8 * tx; |
Ilkka Koskinen | 2764c50 | 2010-10-19 17:07:31 +0300 | [diff] [blame] | 304 | void __iomem *chstat_reg; |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 305 | |
| 306 | mcspi = spi_master_get_devdata(spi->master); |
| 307 | mcspi_dma = &mcspi->dma_channels[spi->chip_select]; |
Roman Tereshonkov | 4743a0f | 2010-04-13 10:41:51 +0000 | [diff] [blame] | 308 | l = mcspi_cached_chconf0(spi); |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 309 | |
Ilkka Koskinen | 2764c50 | 2010-10-19 17:07:31 +0300 | [diff] [blame] | 310 | chstat_reg = cs->base + OMAP2_MCSPI_CHSTAT0; |
| 311 | |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 312 | count = xfer->len; |
| 313 | c = count; |
| 314 | word_len = cs->word_len; |
| 315 | |
Russell King | e5480b73 | 2008-09-01 21:51:50 +0100 | [diff] [blame] | 316 | base = cs->phys; |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 317 | tx_reg = base + OMAP2_MCSPI_TX0; |
| 318 | rx_reg = base + OMAP2_MCSPI_RX0; |
| 319 | rx = xfer->rx_buf; |
| 320 | tx = xfer->tx_buf; |
| 321 | |
| 322 | if (word_len <= 8) { |
| 323 | data_type = OMAP_DMA_DATA_TYPE_S8; |
| 324 | element_count = count; |
| 325 | } else if (word_len <= 16) { |
| 326 | data_type = OMAP_DMA_DATA_TYPE_S16; |
| 327 | element_count = count >> 1; |
| 328 | } else /* word_len <= 32 */ { |
| 329 | data_type = OMAP_DMA_DATA_TYPE_S32; |
| 330 | element_count = count >> 2; |
| 331 | } |
| 332 | |
| 333 | if (tx != NULL) { |
| 334 | omap_set_dma_transfer_params(mcspi_dma->dma_tx_channel, |
| 335 | data_type, element_count, 1, |
| 336 | OMAP_DMA_SYNC_ELEMENT, |
| 337 | mcspi_dma->dma_tx_sync_dev, 0); |
| 338 | |
| 339 | omap_set_dma_dest_params(mcspi_dma->dma_tx_channel, 0, |
| 340 | OMAP_DMA_AMODE_CONSTANT, |
| 341 | tx_reg, 0, 0); |
| 342 | |
| 343 | omap_set_dma_src_params(mcspi_dma->dma_tx_channel, 0, |
| 344 | OMAP_DMA_AMODE_POST_INC, |
| 345 | xfer->tx_dma, 0, 0); |
| 346 | } |
| 347 | |
| 348 | if (rx != NULL) { |
Roman Tereshonkov | 4743a0f | 2010-04-13 10:41:51 +0000 | [diff] [blame] | 349 | elements = element_count - 1; |
| 350 | if (l & OMAP2_MCSPI_CHCONF_TURBO) |
| 351 | elements--; |
| 352 | |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 353 | omap_set_dma_transfer_params(mcspi_dma->dma_rx_channel, |
Roman Tereshonkov | 4743a0f | 2010-04-13 10:41:51 +0000 | [diff] [blame] | 354 | data_type, elements, 1, |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 355 | OMAP_DMA_SYNC_ELEMENT, |
| 356 | mcspi_dma->dma_rx_sync_dev, 1); |
| 357 | |
| 358 | omap_set_dma_src_params(mcspi_dma->dma_rx_channel, 0, |
| 359 | OMAP_DMA_AMODE_CONSTANT, |
| 360 | rx_reg, 0, 0); |
| 361 | |
| 362 | omap_set_dma_dest_params(mcspi_dma->dma_rx_channel, 0, |
| 363 | OMAP_DMA_AMODE_POST_INC, |
| 364 | xfer->rx_dma, 0, 0); |
| 365 | } |
| 366 | |
| 367 | if (tx != NULL) { |
| 368 | omap_start_dma(mcspi_dma->dma_tx_channel); |
| 369 | omap2_mcspi_set_dma_req(spi, 0, 1); |
| 370 | } |
| 371 | |
| 372 | if (rx != NULL) { |
| 373 | omap_start_dma(mcspi_dma->dma_rx_channel); |
| 374 | omap2_mcspi_set_dma_req(spi, 1, 1); |
| 375 | } |
| 376 | |
| 377 | if (tx != NULL) { |
| 378 | wait_for_completion(&mcspi_dma->dma_tx_completion); |
Russell King - ARM Linux | 07fe035 | 2011-01-07 15:49:20 +0000 | [diff] [blame] | 379 | dma_unmap_single(&spi->dev, xfer->tx_dma, count, DMA_TO_DEVICE); |
Ilkka Koskinen | 2764c50 | 2010-10-19 17:07:31 +0300 | [diff] [blame] | 380 | |
| 381 | /* for TX_ONLY mode, be sure all words have shifted out */ |
| 382 | if (rx == NULL) { |
| 383 | if (mcspi_wait_for_reg_bit(chstat_reg, |
| 384 | OMAP2_MCSPI_CHSTAT_TXS) < 0) |
| 385 | dev_err(&spi->dev, "TXS timed out\n"); |
| 386 | else if (mcspi_wait_for_reg_bit(chstat_reg, |
| 387 | OMAP2_MCSPI_CHSTAT_EOT) < 0) |
| 388 | dev_err(&spi->dev, "EOT timed out\n"); |
| 389 | } |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | if (rx != NULL) { |
| 393 | wait_for_completion(&mcspi_dma->dma_rx_completion); |
Russell King - ARM Linux | 07fe035 | 2011-01-07 15:49:20 +0000 | [diff] [blame] | 394 | dma_unmap_single(&spi->dev, xfer->rx_dma, count, DMA_FROM_DEVICE); |
Eero Nurkkala | 57c5c28d | 2009-07-29 15:02:12 -0700 | [diff] [blame] | 395 | omap2_mcspi_set_enable(spi, 0); |
Roman Tereshonkov | 4743a0f | 2010-04-13 10:41:51 +0000 | [diff] [blame] | 396 | |
| 397 | if (l & OMAP2_MCSPI_CHCONF_TURBO) { |
| 398 | |
| 399 | if (likely(mcspi_read_cs_reg(spi, OMAP2_MCSPI_CHSTAT0) |
| 400 | & OMAP2_MCSPI_CHSTAT_RXS)) { |
| 401 | u32 w; |
| 402 | |
| 403 | w = mcspi_read_cs_reg(spi, OMAP2_MCSPI_RX0); |
| 404 | if (word_len <= 8) |
| 405 | ((u8 *)xfer->rx_buf)[elements++] = w; |
| 406 | else if (word_len <= 16) |
| 407 | ((u16 *)xfer->rx_buf)[elements++] = w; |
| 408 | else /* word_len <= 32 */ |
| 409 | ((u32 *)xfer->rx_buf)[elements++] = w; |
| 410 | } else { |
| 411 | dev_err(&spi->dev, |
| 412 | "DMA RX penultimate word empty"); |
| 413 | count -= (word_len <= 8) ? 2 : |
| 414 | (word_len <= 16) ? 4 : |
| 415 | /* word_len <= 32 */ 8; |
| 416 | omap2_mcspi_set_enable(spi, 1); |
| 417 | return count; |
| 418 | } |
| 419 | } |
| 420 | |
Eero Nurkkala | 57c5c28d | 2009-07-29 15:02:12 -0700 | [diff] [blame] | 421 | if (likely(mcspi_read_cs_reg(spi, OMAP2_MCSPI_CHSTAT0) |
| 422 | & OMAP2_MCSPI_CHSTAT_RXS)) { |
| 423 | u32 w; |
| 424 | |
| 425 | w = mcspi_read_cs_reg(spi, OMAP2_MCSPI_RX0); |
| 426 | if (word_len <= 8) |
Roman Tereshonkov | 4743a0f | 2010-04-13 10:41:51 +0000 | [diff] [blame] | 427 | ((u8 *)xfer->rx_buf)[elements] = w; |
Eero Nurkkala | 57c5c28d | 2009-07-29 15:02:12 -0700 | [diff] [blame] | 428 | else if (word_len <= 16) |
Roman Tereshonkov | 4743a0f | 2010-04-13 10:41:51 +0000 | [diff] [blame] | 429 | ((u16 *)xfer->rx_buf)[elements] = w; |
Eero Nurkkala | 57c5c28d | 2009-07-29 15:02:12 -0700 | [diff] [blame] | 430 | else /* word_len <= 32 */ |
Roman Tereshonkov | 4743a0f | 2010-04-13 10:41:51 +0000 | [diff] [blame] | 431 | ((u32 *)xfer->rx_buf)[elements] = w; |
Eero Nurkkala | 57c5c28d | 2009-07-29 15:02:12 -0700 | [diff] [blame] | 432 | } else { |
| 433 | dev_err(&spi->dev, "DMA RX last word empty"); |
| 434 | count -= (word_len <= 8) ? 1 : |
| 435 | (word_len <= 16) ? 2 : |
| 436 | /* word_len <= 32 */ 4; |
| 437 | } |
| 438 | omap2_mcspi_set_enable(spi, 1); |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 439 | } |
| 440 | return count; |
| 441 | } |
| 442 | |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 443 | static unsigned |
| 444 | omap2_mcspi_txrx_pio(struct spi_device *spi, struct spi_transfer *xfer) |
| 445 | { |
| 446 | struct omap2_mcspi *mcspi; |
| 447 | struct omap2_mcspi_cs *cs = spi->controller_state; |
| 448 | unsigned int count, c; |
| 449 | u32 l; |
| 450 | void __iomem *base = cs->base; |
| 451 | void __iomem *tx_reg; |
| 452 | void __iomem *rx_reg; |
| 453 | void __iomem *chstat_reg; |
| 454 | int word_len; |
| 455 | |
| 456 | mcspi = spi_master_get_devdata(spi->master); |
| 457 | count = xfer->len; |
| 458 | c = count; |
| 459 | word_len = cs->word_len; |
| 460 | |
Hemanth V | a41ae1a | 2009-09-22 16:46:16 -0700 | [diff] [blame] | 461 | l = mcspi_cached_chconf0(spi); |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 462 | |
| 463 | /* We store the pre-calculated register addresses on stack to speed |
| 464 | * up the transfer loop. */ |
| 465 | tx_reg = base + OMAP2_MCSPI_TX0; |
| 466 | rx_reg = base + OMAP2_MCSPI_RX0; |
| 467 | chstat_reg = base + OMAP2_MCSPI_CHSTAT0; |
| 468 | |
Michael Jones | adef658 | 2011-02-25 16:55:11 +0100 | [diff] [blame] | 469 | if (c < (word_len>>3)) |
| 470 | return 0; |
| 471 | |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 472 | if (word_len <= 8) { |
| 473 | u8 *rx; |
| 474 | const u8 *tx; |
| 475 | |
| 476 | rx = xfer->rx_buf; |
| 477 | tx = xfer->tx_buf; |
| 478 | |
| 479 | do { |
Kalle Valo | feed9ba | 2008-01-24 14:00:40 -0800 | [diff] [blame] | 480 | c -= 1; |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 481 | if (tx != NULL) { |
| 482 | if (mcspi_wait_for_reg_bit(chstat_reg, |
| 483 | OMAP2_MCSPI_CHSTAT_TXS) < 0) { |
| 484 | dev_err(&spi->dev, "TXS timed out\n"); |
| 485 | goto out; |
| 486 | } |
Felipe Balbi | 079a176 | 2010-09-29 17:31:29 +0900 | [diff] [blame] | 487 | dev_vdbg(&spi->dev, "write-%d %02x\n", |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 488 | word_len, *tx); |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 489 | __raw_writel(*tx++, tx_reg); |
| 490 | } |
| 491 | if (rx != NULL) { |
| 492 | if (mcspi_wait_for_reg_bit(chstat_reg, |
| 493 | OMAP2_MCSPI_CHSTAT_RXS) < 0) { |
| 494 | dev_err(&spi->dev, "RXS timed out\n"); |
| 495 | goto out; |
| 496 | } |
Roman Tereshonkov | 4743a0f | 2010-04-13 10:41:51 +0000 | [diff] [blame] | 497 | |
| 498 | if (c == 1 && tx == NULL && |
| 499 | (l & OMAP2_MCSPI_CHCONF_TURBO)) { |
| 500 | omap2_mcspi_set_enable(spi, 0); |
| 501 | *rx++ = __raw_readl(rx_reg); |
Felipe Balbi | 079a176 | 2010-09-29 17:31:29 +0900 | [diff] [blame] | 502 | dev_vdbg(&spi->dev, "read-%d %02x\n", |
Roman Tereshonkov | 4743a0f | 2010-04-13 10:41:51 +0000 | [diff] [blame] | 503 | word_len, *(rx - 1)); |
Roman Tereshonkov | 4743a0f | 2010-04-13 10:41:51 +0000 | [diff] [blame] | 504 | if (mcspi_wait_for_reg_bit(chstat_reg, |
| 505 | OMAP2_MCSPI_CHSTAT_RXS) < 0) { |
| 506 | dev_err(&spi->dev, |
| 507 | "RXS timed out\n"); |
| 508 | goto out; |
| 509 | } |
| 510 | c = 0; |
| 511 | } else if (c == 0 && tx == NULL) { |
| 512 | omap2_mcspi_set_enable(spi, 0); |
| 513 | } |
| 514 | |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 515 | *rx++ = __raw_readl(rx_reg); |
Felipe Balbi | 079a176 | 2010-09-29 17:31:29 +0900 | [diff] [blame] | 516 | dev_vdbg(&spi->dev, "read-%d %02x\n", |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 517 | word_len, *(rx - 1)); |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 518 | } |
Jarkko Nikula | 95c5c3a | 2011-03-21 16:27:30 +0200 | [diff] [blame] | 519 | } while (c); |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 520 | } else if (word_len <= 16) { |
| 521 | u16 *rx; |
| 522 | const u16 *tx; |
| 523 | |
| 524 | rx = xfer->rx_buf; |
| 525 | tx = xfer->tx_buf; |
| 526 | do { |
Kalle Valo | feed9ba | 2008-01-24 14:00:40 -0800 | [diff] [blame] | 527 | c -= 2; |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 528 | if (tx != NULL) { |
| 529 | if (mcspi_wait_for_reg_bit(chstat_reg, |
| 530 | OMAP2_MCSPI_CHSTAT_TXS) < 0) { |
| 531 | dev_err(&spi->dev, "TXS timed out\n"); |
| 532 | goto out; |
| 533 | } |
Felipe Balbi | 079a176 | 2010-09-29 17:31:29 +0900 | [diff] [blame] | 534 | dev_vdbg(&spi->dev, "write-%d %04x\n", |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 535 | word_len, *tx); |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 536 | __raw_writel(*tx++, tx_reg); |
| 537 | } |
| 538 | if (rx != NULL) { |
| 539 | if (mcspi_wait_for_reg_bit(chstat_reg, |
| 540 | OMAP2_MCSPI_CHSTAT_RXS) < 0) { |
| 541 | dev_err(&spi->dev, "RXS timed out\n"); |
| 542 | goto out; |
| 543 | } |
Roman Tereshonkov | 4743a0f | 2010-04-13 10:41:51 +0000 | [diff] [blame] | 544 | |
| 545 | if (c == 2 && tx == NULL && |
| 546 | (l & OMAP2_MCSPI_CHCONF_TURBO)) { |
| 547 | omap2_mcspi_set_enable(spi, 0); |
| 548 | *rx++ = __raw_readl(rx_reg); |
Felipe Balbi | 079a176 | 2010-09-29 17:31:29 +0900 | [diff] [blame] | 549 | dev_vdbg(&spi->dev, "read-%d %04x\n", |
Roman Tereshonkov | 4743a0f | 2010-04-13 10:41:51 +0000 | [diff] [blame] | 550 | word_len, *(rx - 1)); |
Roman Tereshonkov | 4743a0f | 2010-04-13 10:41:51 +0000 | [diff] [blame] | 551 | if (mcspi_wait_for_reg_bit(chstat_reg, |
| 552 | OMAP2_MCSPI_CHSTAT_RXS) < 0) { |
| 553 | dev_err(&spi->dev, |
| 554 | "RXS timed out\n"); |
| 555 | goto out; |
| 556 | } |
| 557 | c = 0; |
| 558 | } else if (c == 0 && tx == NULL) { |
| 559 | omap2_mcspi_set_enable(spi, 0); |
| 560 | } |
| 561 | |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 562 | *rx++ = __raw_readl(rx_reg); |
Felipe Balbi | 079a176 | 2010-09-29 17:31:29 +0900 | [diff] [blame] | 563 | dev_vdbg(&spi->dev, "read-%d %04x\n", |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 564 | word_len, *(rx - 1)); |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 565 | } |
Jarkko Nikula | 95c5c3a | 2011-03-21 16:27:30 +0200 | [diff] [blame] | 566 | } while (c >= 2); |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 567 | } else if (word_len <= 32) { |
| 568 | u32 *rx; |
| 569 | const u32 *tx; |
| 570 | |
| 571 | rx = xfer->rx_buf; |
| 572 | tx = xfer->tx_buf; |
| 573 | do { |
Kalle Valo | feed9ba | 2008-01-24 14:00:40 -0800 | [diff] [blame] | 574 | c -= 4; |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 575 | if (tx != NULL) { |
| 576 | if (mcspi_wait_for_reg_bit(chstat_reg, |
| 577 | OMAP2_MCSPI_CHSTAT_TXS) < 0) { |
| 578 | dev_err(&spi->dev, "TXS timed out\n"); |
| 579 | goto out; |
| 580 | } |
Felipe Balbi | 079a176 | 2010-09-29 17:31:29 +0900 | [diff] [blame] | 581 | dev_vdbg(&spi->dev, "write-%d %08x\n", |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 582 | word_len, *tx); |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 583 | __raw_writel(*tx++, tx_reg); |
| 584 | } |
| 585 | if (rx != NULL) { |
| 586 | if (mcspi_wait_for_reg_bit(chstat_reg, |
| 587 | OMAP2_MCSPI_CHSTAT_RXS) < 0) { |
| 588 | dev_err(&spi->dev, "RXS timed out\n"); |
| 589 | goto out; |
| 590 | } |
Roman Tereshonkov | 4743a0f | 2010-04-13 10:41:51 +0000 | [diff] [blame] | 591 | |
| 592 | if (c == 4 && tx == NULL && |
| 593 | (l & OMAP2_MCSPI_CHCONF_TURBO)) { |
| 594 | omap2_mcspi_set_enable(spi, 0); |
| 595 | *rx++ = __raw_readl(rx_reg); |
Felipe Balbi | 079a176 | 2010-09-29 17:31:29 +0900 | [diff] [blame] | 596 | dev_vdbg(&spi->dev, "read-%d %08x\n", |
Roman Tereshonkov | 4743a0f | 2010-04-13 10:41:51 +0000 | [diff] [blame] | 597 | word_len, *(rx - 1)); |
Roman Tereshonkov | 4743a0f | 2010-04-13 10:41:51 +0000 | [diff] [blame] | 598 | if (mcspi_wait_for_reg_bit(chstat_reg, |
| 599 | OMAP2_MCSPI_CHSTAT_RXS) < 0) { |
| 600 | dev_err(&spi->dev, |
| 601 | "RXS timed out\n"); |
| 602 | goto out; |
| 603 | } |
| 604 | c = 0; |
| 605 | } else if (c == 0 && tx == NULL) { |
| 606 | omap2_mcspi_set_enable(spi, 0); |
| 607 | } |
| 608 | |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 609 | *rx++ = __raw_readl(rx_reg); |
Felipe Balbi | 079a176 | 2010-09-29 17:31:29 +0900 | [diff] [blame] | 610 | dev_vdbg(&spi->dev, "read-%d %08x\n", |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 611 | word_len, *(rx - 1)); |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 612 | } |
Jarkko Nikula | 95c5c3a | 2011-03-21 16:27:30 +0200 | [diff] [blame] | 613 | } while (c >= 4); |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | /* for TX_ONLY mode, be sure all words have shifted out */ |
| 617 | if (xfer->rx_buf == NULL) { |
| 618 | if (mcspi_wait_for_reg_bit(chstat_reg, |
| 619 | OMAP2_MCSPI_CHSTAT_TXS) < 0) { |
| 620 | dev_err(&spi->dev, "TXS timed out\n"); |
| 621 | } else if (mcspi_wait_for_reg_bit(chstat_reg, |
| 622 | OMAP2_MCSPI_CHSTAT_EOT) < 0) |
| 623 | dev_err(&spi->dev, "EOT timed out\n"); |
Jason Wang | e1993ed | 2010-10-19 18:03:27 +0800 | [diff] [blame] | 624 | |
| 625 | /* disable chan to purge rx datas received in TX_ONLY transfer, |
| 626 | * otherwise these rx datas will affect the direct following |
| 627 | * RX_ONLY transfer. |
| 628 | */ |
| 629 | omap2_mcspi_set_enable(spi, 0); |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 630 | } |
| 631 | out: |
Roman Tereshonkov | 4743a0f | 2010-04-13 10:41:51 +0000 | [diff] [blame] | 632 | omap2_mcspi_set_enable(spi, 1); |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 633 | return count - c; |
| 634 | } |
| 635 | |
Hannu Heikkinen | 57d9c10 | 2011-02-24 21:31:33 +0200 | [diff] [blame] | 636 | static u32 omap2_mcspi_calc_divisor(u32 speed_hz) |
| 637 | { |
| 638 | u32 div; |
| 639 | |
| 640 | for (div = 0; div < 15; div++) |
| 641 | if (speed_hz >= (OMAP2_MCSPI_MAX_FREQ >> div)) |
| 642 | return div; |
| 643 | |
| 644 | return 15; |
| 645 | } |
| 646 | |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 647 | /* called only when no transfer is active to this device */ |
| 648 | static int omap2_mcspi_setup_transfer(struct spi_device *spi, |
| 649 | struct spi_transfer *t) |
| 650 | { |
| 651 | struct omap2_mcspi_cs *cs = spi->controller_state; |
| 652 | struct omap2_mcspi *mcspi; |
Hemanth V | a41ae1a | 2009-09-22 16:46:16 -0700 | [diff] [blame] | 653 | struct spi_master *spi_cntrl; |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 654 | u32 l = 0, div = 0; |
| 655 | u8 word_len = spi->bits_per_word; |
Scott Ellis | 9bd4517 | 2010-03-10 14:23:13 -0700 | [diff] [blame] | 656 | u32 speed_hz = spi->max_speed_hz; |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 657 | |
| 658 | mcspi = spi_master_get_devdata(spi->master); |
Hemanth V | a41ae1a | 2009-09-22 16:46:16 -0700 | [diff] [blame] | 659 | spi_cntrl = mcspi->master; |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 660 | |
| 661 | if (t != NULL && t->bits_per_word) |
| 662 | word_len = t->bits_per_word; |
| 663 | |
| 664 | cs->word_len = word_len; |
| 665 | |
Scott Ellis | 9bd4517 | 2010-03-10 14:23:13 -0700 | [diff] [blame] | 666 | if (t && t->speed_hz) |
| 667 | speed_hz = t->speed_hz; |
| 668 | |
Hannu Heikkinen | 57d9c10 | 2011-02-24 21:31:33 +0200 | [diff] [blame] | 669 | speed_hz = min_t(u32, speed_hz, OMAP2_MCSPI_MAX_FREQ); |
| 670 | div = omap2_mcspi_calc_divisor(speed_hz); |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 671 | |
Hemanth V | a41ae1a | 2009-09-22 16:46:16 -0700 | [diff] [blame] | 672 | l = mcspi_cached_chconf0(spi); |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 673 | |
| 674 | /* standard 4-wire master mode: SCK, MOSI/out, MISO/in, nCS |
| 675 | * REVISIT: this controller could support SPI_3WIRE mode. |
| 676 | */ |
| 677 | l &= ~(OMAP2_MCSPI_CHCONF_IS|OMAP2_MCSPI_CHCONF_DPE1); |
| 678 | l |= OMAP2_MCSPI_CHCONF_DPE0; |
| 679 | |
| 680 | /* wordlength */ |
| 681 | l &= ~OMAP2_MCSPI_CHCONF_WL_MASK; |
| 682 | l |= (word_len - 1) << 7; |
| 683 | |
| 684 | /* set chipselect polarity; manage with FORCE */ |
| 685 | if (!(spi->mode & SPI_CS_HIGH)) |
| 686 | l |= OMAP2_MCSPI_CHCONF_EPOL; /* active-low; normal */ |
| 687 | else |
| 688 | l &= ~OMAP2_MCSPI_CHCONF_EPOL; |
| 689 | |
| 690 | /* set clock divisor */ |
| 691 | l &= ~OMAP2_MCSPI_CHCONF_CLKD_MASK; |
| 692 | l |= div << 2; |
| 693 | |
| 694 | /* set SPI mode 0..3 */ |
| 695 | if (spi->mode & SPI_CPOL) |
| 696 | l |= OMAP2_MCSPI_CHCONF_POL; |
| 697 | else |
| 698 | l &= ~OMAP2_MCSPI_CHCONF_POL; |
| 699 | if (spi->mode & SPI_CPHA) |
| 700 | l |= OMAP2_MCSPI_CHCONF_PHA; |
| 701 | else |
| 702 | l &= ~OMAP2_MCSPI_CHCONF_PHA; |
| 703 | |
Hemanth V | a41ae1a | 2009-09-22 16:46:16 -0700 | [diff] [blame] | 704 | mcspi_write_chconf0(spi, l); |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 705 | |
| 706 | dev_dbg(&spi->dev, "setup: speed %d, sample %s edge, clk %s\n", |
Hannu Heikkinen | 57d9c10 | 2011-02-24 21:31:33 +0200 | [diff] [blame] | 707 | OMAP2_MCSPI_MAX_FREQ >> div, |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 708 | (spi->mode & SPI_CPHA) ? "trailing" : "leading", |
| 709 | (spi->mode & SPI_CPOL) ? "inverted" : "normal"); |
| 710 | |
| 711 | return 0; |
| 712 | } |
| 713 | |
| 714 | static void omap2_mcspi_dma_rx_callback(int lch, u16 ch_status, void *data) |
| 715 | { |
| 716 | struct spi_device *spi = data; |
| 717 | struct omap2_mcspi *mcspi; |
| 718 | struct omap2_mcspi_dma *mcspi_dma; |
| 719 | |
| 720 | mcspi = spi_master_get_devdata(spi->master); |
| 721 | mcspi_dma = &(mcspi->dma_channels[spi->chip_select]); |
| 722 | |
| 723 | complete(&mcspi_dma->dma_rx_completion); |
| 724 | |
| 725 | /* We must disable the DMA RX request */ |
| 726 | omap2_mcspi_set_dma_req(spi, 1, 0); |
| 727 | } |
| 728 | |
| 729 | static void omap2_mcspi_dma_tx_callback(int lch, u16 ch_status, void *data) |
| 730 | { |
| 731 | struct spi_device *spi = data; |
| 732 | struct omap2_mcspi *mcspi; |
| 733 | struct omap2_mcspi_dma *mcspi_dma; |
| 734 | |
| 735 | mcspi = spi_master_get_devdata(spi->master); |
| 736 | mcspi_dma = &(mcspi->dma_channels[spi->chip_select]); |
| 737 | |
| 738 | complete(&mcspi_dma->dma_tx_completion); |
| 739 | |
| 740 | /* We must disable the DMA TX request */ |
| 741 | omap2_mcspi_set_dma_req(spi, 0, 0); |
| 742 | } |
| 743 | |
| 744 | static int omap2_mcspi_request_dma(struct spi_device *spi) |
| 745 | { |
| 746 | struct spi_master *master = spi->master; |
| 747 | struct omap2_mcspi *mcspi; |
| 748 | struct omap2_mcspi_dma *mcspi_dma; |
| 749 | |
| 750 | mcspi = spi_master_get_devdata(master); |
| 751 | mcspi_dma = mcspi->dma_channels + spi->chip_select; |
| 752 | |
| 753 | if (omap_request_dma(mcspi_dma->dma_rx_sync_dev, "McSPI RX", |
| 754 | omap2_mcspi_dma_rx_callback, spi, |
| 755 | &mcspi_dma->dma_rx_channel)) { |
| 756 | dev_err(&spi->dev, "no RX DMA channel for McSPI\n"); |
| 757 | return -EAGAIN; |
| 758 | } |
| 759 | |
| 760 | if (omap_request_dma(mcspi_dma->dma_tx_sync_dev, "McSPI TX", |
| 761 | omap2_mcspi_dma_tx_callback, spi, |
| 762 | &mcspi_dma->dma_tx_channel)) { |
| 763 | omap_free_dma(mcspi_dma->dma_rx_channel); |
| 764 | mcspi_dma->dma_rx_channel = -1; |
| 765 | dev_err(&spi->dev, "no TX DMA channel for McSPI\n"); |
| 766 | return -EAGAIN; |
| 767 | } |
| 768 | |
| 769 | init_completion(&mcspi_dma->dma_rx_completion); |
| 770 | init_completion(&mcspi_dma->dma_tx_completion); |
| 771 | |
| 772 | return 0; |
| 773 | } |
| 774 | |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 775 | static int omap2_mcspi_setup(struct spi_device *spi) |
| 776 | { |
| 777 | int ret; |
Benoit Cousson | 1bd897f8 | 2012-03-26 15:32:33 +0530 | [diff] [blame] | 778 | struct omap2_mcspi *mcspi = spi_master_get_devdata(spi->master); |
| 779 | struct omap2_mcspi_regs *ctx = &mcspi->ctx; |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 780 | struct omap2_mcspi_dma *mcspi_dma; |
| 781 | struct omap2_mcspi_cs *cs = spi->controller_state; |
| 782 | |
David Brownell | 7d07719 | 2009-06-17 16:26:03 -0700 | [diff] [blame] | 783 | if (spi->bits_per_word < 4 || spi->bits_per_word > 32) { |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 784 | dev_dbg(&spi->dev, "setup: unsupported %d bit words\n", |
| 785 | spi->bits_per_word); |
| 786 | return -EINVAL; |
| 787 | } |
| 788 | |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 789 | mcspi_dma = &mcspi->dma_channels[spi->chip_select]; |
| 790 | |
| 791 | if (!cs) { |
Shubhrajyoti D | 1a77b12 | 2012-03-17 12:44:01 +0530 | [diff] [blame] | 792 | cs = devm_kzalloc(&spi->dev , sizeof *cs, GFP_KERNEL); |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 793 | if (!cs) |
| 794 | return -ENOMEM; |
| 795 | cs->base = mcspi->base + spi->chip_select * 0x14; |
Russell King | e5480b73 | 2008-09-01 21:51:50 +0100 | [diff] [blame] | 796 | cs->phys = mcspi->phys + spi->chip_select * 0x14; |
Hemanth V | a41ae1a | 2009-09-22 16:46:16 -0700 | [diff] [blame] | 797 | cs->chconf0 = 0; |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 798 | spi->controller_state = cs; |
Tero Kristo | 89c0537 | 2009-09-22 16:46:17 -0700 | [diff] [blame] | 799 | /* Link this to context save list */ |
Benoit Cousson | 1bd897f8 | 2012-03-26 15:32:33 +0530 | [diff] [blame] | 800 | list_add_tail(&cs->node, &ctx->cs); |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 801 | } |
| 802 | |
| 803 | if (mcspi_dma->dma_rx_channel == -1 |
| 804 | || mcspi_dma->dma_tx_channel == -1) { |
| 805 | ret = omap2_mcspi_request_dma(spi); |
| 806 | if (ret < 0) |
| 807 | return ret; |
| 808 | } |
| 809 | |
Govindraj.R | 1f1a438 | 2011-02-02 17:52:15 +0530 | [diff] [blame] | 810 | ret = omap2_mcspi_enable_clocks(mcspi); |
| 811 | if (ret < 0) |
| 812 | return ret; |
Hemanth V | a41ae1a | 2009-09-22 16:46:16 -0700 | [diff] [blame] | 813 | |
Kyungmin Park | 86eeb6f | 2007-10-16 01:27:45 -0700 | [diff] [blame] | 814 | ret = omap2_mcspi_setup_transfer(spi, NULL); |
Hemanth V | a41ae1a | 2009-09-22 16:46:16 -0700 | [diff] [blame] | 815 | omap2_mcspi_disable_clocks(mcspi); |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 816 | |
| 817 | return ret; |
| 818 | } |
| 819 | |
| 820 | static void omap2_mcspi_cleanup(struct spi_device *spi) |
| 821 | { |
| 822 | struct omap2_mcspi *mcspi; |
| 823 | struct omap2_mcspi_dma *mcspi_dma; |
Tero Kristo | 89c0537 | 2009-09-22 16:46:17 -0700 | [diff] [blame] | 824 | struct omap2_mcspi_cs *cs; |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 825 | |
| 826 | mcspi = spi_master_get_devdata(spi->master); |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 827 | |
Scott Ellis | 5e77494 | 2010-03-10 14:22:45 -0700 | [diff] [blame] | 828 | if (spi->controller_state) { |
| 829 | /* Unlink controller state from context save list */ |
| 830 | cs = spi->controller_state; |
| 831 | list_del(&cs->node); |
Tero Kristo | 89c0537 | 2009-09-22 16:46:17 -0700 | [diff] [blame] | 832 | |
Scott Ellis | 5e77494 | 2010-03-10 14:22:45 -0700 | [diff] [blame] | 833 | } |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 834 | |
Scott Ellis | 99f1a43 | 2010-05-24 14:20:27 +0000 | [diff] [blame] | 835 | if (spi->chip_select < spi->master->num_chipselect) { |
| 836 | mcspi_dma = &mcspi->dma_channels[spi->chip_select]; |
| 837 | |
| 838 | if (mcspi_dma->dma_rx_channel != -1) { |
| 839 | omap_free_dma(mcspi_dma->dma_rx_channel); |
| 840 | mcspi_dma->dma_rx_channel = -1; |
| 841 | } |
| 842 | if (mcspi_dma->dma_tx_channel != -1) { |
| 843 | omap_free_dma(mcspi_dma->dma_tx_channel); |
| 844 | mcspi_dma->dma_tx_channel = -1; |
| 845 | } |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 846 | } |
| 847 | } |
| 848 | |
| 849 | static void omap2_mcspi_work(struct work_struct *work) |
| 850 | { |
| 851 | struct omap2_mcspi *mcspi; |
| 852 | |
| 853 | mcspi = container_of(work, struct omap2_mcspi, work); |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 854 | |
Govindraj.R | 1f1a438 | 2011-02-02 17:52:15 +0530 | [diff] [blame] | 855 | if (omap2_mcspi_enable_clocks(mcspi) < 0) |
| 856 | return; |
| 857 | |
| 858 | spin_lock_irq(&mcspi->lock); |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 859 | |
| 860 | /* We only enable one channel at a time -- the one whose message is |
| 861 | * at the head of the queue -- although this controller would gladly |
| 862 | * arbitrate among multiple channels. This corresponds to "single |
| 863 | * channel" master mode. As a side effect, we need to manage the |
| 864 | * chipselect with the FORCE bit ... CS != channel enable. |
| 865 | */ |
| 866 | while (!list_empty(&mcspi->msg_queue)) { |
| 867 | struct spi_message *m; |
| 868 | struct spi_device *spi; |
| 869 | struct spi_transfer *t = NULL; |
| 870 | int cs_active = 0; |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 871 | struct omap2_mcspi_cs *cs; |
Roman Tereshonkov | 4743a0f | 2010-04-13 10:41:51 +0000 | [diff] [blame] | 872 | struct omap2_mcspi_device_config *cd; |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 873 | int par_override = 0; |
| 874 | int status = 0; |
| 875 | u32 chconf; |
| 876 | |
| 877 | m = container_of(mcspi->msg_queue.next, struct spi_message, |
| 878 | queue); |
| 879 | |
| 880 | list_del_init(&m->queue); |
| 881 | spin_unlock_irq(&mcspi->lock); |
| 882 | |
| 883 | spi = m->spi; |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 884 | cs = spi->controller_state; |
Roman Tereshonkov | 4743a0f | 2010-04-13 10:41:51 +0000 | [diff] [blame] | 885 | cd = spi->controller_data; |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 886 | |
| 887 | omap2_mcspi_set_enable(spi, 1); |
| 888 | list_for_each_entry(t, &m->transfers, transfer_list) { |
| 889 | if (t->tx_buf == NULL && t->rx_buf == NULL && t->len) { |
| 890 | status = -EINVAL; |
| 891 | break; |
| 892 | } |
| 893 | if (par_override || t->speed_hz || t->bits_per_word) { |
| 894 | par_override = 1; |
| 895 | status = omap2_mcspi_setup_transfer(spi, t); |
| 896 | if (status < 0) |
| 897 | break; |
| 898 | if (!t->speed_hz && !t->bits_per_word) |
| 899 | par_override = 0; |
| 900 | } |
| 901 | |
| 902 | if (!cs_active) { |
| 903 | omap2_mcspi_force_cs(spi, 1); |
| 904 | cs_active = 1; |
| 905 | } |
| 906 | |
Hemanth V | a41ae1a | 2009-09-22 16:46:16 -0700 | [diff] [blame] | 907 | chconf = mcspi_cached_chconf0(spi); |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 908 | chconf &= ~OMAP2_MCSPI_CHCONF_TRM_MASK; |
Roman Tereshonkov | 4743a0f | 2010-04-13 10:41:51 +0000 | [diff] [blame] | 909 | chconf &= ~OMAP2_MCSPI_CHCONF_TURBO; |
| 910 | |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 911 | if (t->tx_buf == NULL) |
| 912 | chconf |= OMAP2_MCSPI_CHCONF_TRM_RX_ONLY; |
| 913 | else if (t->rx_buf == NULL) |
| 914 | chconf |= OMAP2_MCSPI_CHCONF_TRM_TX_ONLY; |
Roman Tereshonkov | 4743a0f | 2010-04-13 10:41:51 +0000 | [diff] [blame] | 915 | |
| 916 | if (cd && cd->turbo_mode && t->tx_buf == NULL) { |
| 917 | /* Turbo mode is for more than one word */ |
| 918 | if (t->len > ((cs->word_len + 7) >> 3)) |
| 919 | chconf |= OMAP2_MCSPI_CHCONF_TURBO; |
| 920 | } |
| 921 | |
Hemanth V | a41ae1a | 2009-09-22 16:46:16 -0700 | [diff] [blame] | 922 | mcspi_write_chconf0(spi, chconf); |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 923 | |
| 924 | if (t->len) { |
| 925 | unsigned count; |
| 926 | |
| 927 | /* RX_ONLY mode needs dummy data in TX reg */ |
| 928 | if (t->tx_buf == NULL) |
| 929 | __raw_writel(0, cs->base |
| 930 | + OMAP2_MCSPI_TX0); |
| 931 | |
| 932 | if (m->is_dma_mapped || t->len >= DMA_MIN_BYTES) |
| 933 | count = omap2_mcspi_txrx_dma(spi, t); |
| 934 | else |
| 935 | count = omap2_mcspi_txrx_pio(spi, t); |
| 936 | m->actual_length += count; |
| 937 | |
| 938 | if (count != t->len) { |
| 939 | status = -EIO; |
| 940 | break; |
| 941 | } |
| 942 | } |
| 943 | |
| 944 | if (t->delay_usecs) |
| 945 | udelay(t->delay_usecs); |
| 946 | |
| 947 | /* ignore the "leave it on after last xfer" hint */ |
| 948 | if (t->cs_change) { |
| 949 | omap2_mcspi_force_cs(spi, 0); |
| 950 | cs_active = 0; |
| 951 | } |
| 952 | } |
| 953 | |
| 954 | /* Restore defaults if they were overriden */ |
| 955 | if (par_override) { |
| 956 | par_override = 0; |
| 957 | status = omap2_mcspi_setup_transfer(spi, NULL); |
| 958 | } |
| 959 | |
| 960 | if (cs_active) |
| 961 | omap2_mcspi_force_cs(spi, 0); |
| 962 | |
| 963 | omap2_mcspi_set_enable(spi, 0); |
| 964 | |
| 965 | m->status = status; |
| 966 | m->complete(m->context); |
| 967 | |
| 968 | spin_lock_irq(&mcspi->lock); |
| 969 | } |
| 970 | |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 971 | spin_unlock_irq(&mcspi->lock); |
Govindraj.R | 1f1a438 | 2011-02-02 17:52:15 +0530 | [diff] [blame] | 972 | |
| 973 | omap2_mcspi_disable_clocks(mcspi); |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 974 | } |
| 975 | |
| 976 | static int omap2_mcspi_transfer(struct spi_device *spi, struct spi_message *m) |
| 977 | { |
| 978 | struct omap2_mcspi *mcspi; |
| 979 | unsigned long flags; |
| 980 | struct spi_transfer *t; |
| 981 | |
| 982 | m->actual_length = 0; |
| 983 | m->status = 0; |
| 984 | |
| 985 | /* reject invalid messages and transfers */ |
| 986 | if (list_empty(&m->transfers) || !m->complete) |
| 987 | return -EINVAL; |
| 988 | list_for_each_entry(t, &m->transfers, transfer_list) { |
| 989 | const void *tx_buf = t->tx_buf; |
| 990 | void *rx_buf = t->rx_buf; |
| 991 | unsigned len = t->len; |
| 992 | |
| 993 | if (t->speed_hz > OMAP2_MCSPI_MAX_FREQ |
| 994 | || (len && !(rx_buf || tx_buf)) |
| 995 | || (t->bits_per_word && |
| 996 | ( t->bits_per_word < 4 |
| 997 | || t->bits_per_word > 32))) { |
| 998 | dev_dbg(&spi->dev, "transfer: %d Hz, %d %s%s, %d bpw\n", |
| 999 | t->speed_hz, |
| 1000 | len, |
| 1001 | tx_buf ? "tx" : "", |
| 1002 | rx_buf ? "rx" : "", |
| 1003 | t->bits_per_word); |
| 1004 | return -EINVAL; |
| 1005 | } |
Hannu Heikkinen | 57d9c10 | 2011-02-24 21:31:33 +0200 | [diff] [blame] | 1006 | if (t->speed_hz && t->speed_hz < (OMAP2_MCSPI_MAX_FREQ >> 15)) { |
| 1007 | dev_dbg(&spi->dev, "speed_hz %d below minimum %d Hz\n", |
| 1008 | t->speed_hz, |
| 1009 | OMAP2_MCSPI_MAX_FREQ >> 15); |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 1010 | return -EINVAL; |
| 1011 | } |
| 1012 | |
| 1013 | if (m->is_dma_mapped || len < DMA_MIN_BYTES) |
| 1014 | continue; |
| 1015 | |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 1016 | if (tx_buf != NULL) { |
| 1017 | t->tx_dma = dma_map_single(&spi->dev, (void *) tx_buf, |
| 1018 | len, DMA_TO_DEVICE); |
FUJITA Tomonori | 8d8bb39 | 2008-07-25 19:44:49 -0700 | [diff] [blame] | 1019 | if (dma_mapping_error(&spi->dev, t->tx_dma)) { |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 1020 | dev_dbg(&spi->dev, "dma %cX %d bytes error\n", |
| 1021 | 'T', len); |
| 1022 | return -EINVAL; |
| 1023 | } |
| 1024 | } |
| 1025 | if (rx_buf != NULL) { |
| 1026 | t->rx_dma = dma_map_single(&spi->dev, rx_buf, t->len, |
| 1027 | DMA_FROM_DEVICE); |
FUJITA Tomonori | 8d8bb39 | 2008-07-25 19:44:49 -0700 | [diff] [blame] | 1028 | if (dma_mapping_error(&spi->dev, t->rx_dma)) { |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 1029 | dev_dbg(&spi->dev, "dma %cX %d bytes error\n", |
| 1030 | 'R', len); |
| 1031 | if (tx_buf != NULL) |
Russell King - ARM Linux | 07fe035 | 2011-01-07 15:49:20 +0000 | [diff] [blame] | 1032 | dma_unmap_single(&spi->dev, t->tx_dma, |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 1033 | len, DMA_TO_DEVICE); |
| 1034 | return -EINVAL; |
| 1035 | } |
| 1036 | } |
| 1037 | } |
| 1038 | |
| 1039 | mcspi = spi_master_get_devdata(spi->master); |
| 1040 | |
| 1041 | spin_lock_irqsave(&mcspi->lock, flags); |
| 1042 | list_add_tail(&m->queue, &mcspi->msg_queue); |
Shubhrajyoti D | 2856ac1 | 2011-10-28 17:14:17 +0530 | [diff] [blame] | 1043 | queue_work(mcspi->wq, &mcspi->work); |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 1044 | spin_unlock_irqrestore(&mcspi->lock, flags); |
| 1045 | |
| 1046 | return 0; |
| 1047 | } |
| 1048 | |
Govindraj.R | 1f1a438 | 2011-02-02 17:52:15 +0530 | [diff] [blame] | 1049 | static int __init omap2_mcspi_master_setup(struct omap2_mcspi *mcspi) |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 1050 | { |
| 1051 | struct spi_master *master = mcspi->master; |
Benoit Cousson | 1bd897f8 | 2012-03-26 15:32:33 +0530 | [diff] [blame] | 1052 | struct omap2_mcspi_regs *ctx = &mcspi->ctx; |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 1053 | u32 tmp; |
Benoit Cousson | 1bd897f8 | 2012-03-26 15:32:33 +0530 | [diff] [blame] | 1054 | int ret = 0; |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 1055 | |
Govindraj.R | 1f1a438 | 2011-02-02 17:52:15 +0530 | [diff] [blame] | 1056 | ret = omap2_mcspi_enable_clocks(mcspi); |
| 1057 | if (ret < 0) |
| 1058 | return ret; |
Jouni Hogander | ddb2219 | 2009-07-29 15:02:11 -0700 | [diff] [blame] | 1059 | |
Hemanth V | a41ae1a | 2009-09-22 16:46:16 -0700 | [diff] [blame] | 1060 | tmp = OMAP2_MCSPI_WAKEUPENABLE_WKEN; |
| 1061 | mcspi_write_reg(master, OMAP2_MCSPI_WAKEUPENABLE, tmp); |
Benoit Cousson | 1bd897f8 | 2012-03-26 15:32:33 +0530 | [diff] [blame] | 1062 | ctx->wakeupenable = tmp; |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 1063 | |
| 1064 | omap2_mcspi_set_master_mode(master); |
Hemanth V | a41ae1a | 2009-09-22 16:46:16 -0700 | [diff] [blame] | 1065 | omap2_mcspi_disable_clocks(mcspi); |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 1066 | return 0; |
| 1067 | } |
| 1068 | |
Govindraj.R | 1f1a438 | 2011-02-02 17:52:15 +0530 | [diff] [blame] | 1069 | static int omap_mcspi_runtime_resume(struct device *dev) |
| 1070 | { |
| 1071 | struct omap2_mcspi *mcspi; |
| 1072 | struct spi_master *master; |
| 1073 | |
| 1074 | master = dev_get_drvdata(dev); |
| 1075 | mcspi = spi_master_get_devdata(master); |
| 1076 | omap2_mcspi_restore_ctx(mcspi); |
| 1077 | |
| 1078 | return 0; |
| 1079 | } |
| 1080 | |
Benoit Cousson | d5a8003 | 2012-02-15 18:37:34 +0100 | [diff] [blame] | 1081 | static struct omap2_mcspi_platform_config omap2_pdata = { |
| 1082 | .regs_offset = 0, |
| 1083 | }; |
| 1084 | |
| 1085 | static struct omap2_mcspi_platform_config omap4_pdata = { |
| 1086 | .regs_offset = OMAP4_MCSPI_REG_OFFSET, |
| 1087 | }; |
| 1088 | |
| 1089 | static const struct of_device_id omap_mcspi_of_match[] = { |
| 1090 | { |
| 1091 | .compatible = "ti,omap2-mcspi", |
| 1092 | .data = &omap2_pdata, |
| 1093 | }, |
| 1094 | { |
| 1095 | .compatible = "ti,omap4-mcspi", |
| 1096 | .data = &omap4_pdata, |
| 1097 | }, |
| 1098 | { }, |
| 1099 | }; |
| 1100 | MODULE_DEVICE_TABLE(of, omap_mcspi_of_match); |
Girish | ccc7bae | 2008-02-06 01:38:16 -0800 | [diff] [blame] | 1101 | |
Felipe Balbi | 7d6b6d8 | 2012-03-14 11:18:30 +0200 | [diff] [blame] | 1102 | static int __devinit omap2_mcspi_probe(struct platform_device *pdev) |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 1103 | { |
| 1104 | struct spi_master *master; |
Benoit Cousson | d5a8003 | 2012-02-15 18:37:34 +0100 | [diff] [blame] | 1105 | struct omap2_mcspi_platform_config *pdata; |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 1106 | struct omap2_mcspi *mcspi; |
| 1107 | struct resource *r; |
| 1108 | int status = 0, i; |
Benoit Cousson | d5a8003 | 2012-02-15 18:37:34 +0100 | [diff] [blame] | 1109 | u32 regs_offset = 0; |
| 1110 | static int bus_num = 1; |
| 1111 | struct device_node *node = pdev->dev.of_node; |
| 1112 | const struct of_device_id *match; |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 1113 | |
| 1114 | master = spi_alloc_master(&pdev->dev, sizeof *mcspi); |
| 1115 | if (master == NULL) { |
| 1116 | dev_dbg(&pdev->dev, "master allocation failed\n"); |
| 1117 | return -ENOMEM; |
| 1118 | } |
| 1119 | |
David Brownell | e7db06b | 2009-06-17 16:26:04 -0700 | [diff] [blame] | 1120 | /* the spi->mode bits understood by this driver: */ |
| 1121 | master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH; |
| 1122 | |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 1123 | master->setup = omap2_mcspi_setup; |
| 1124 | master->transfer = omap2_mcspi_transfer; |
| 1125 | master->cleanup = omap2_mcspi_cleanup; |
Benoit Cousson | d5a8003 | 2012-02-15 18:37:34 +0100 | [diff] [blame] | 1126 | master->dev.of_node = node; |
| 1127 | |
| 1128 | match = of_match_device(omap_mcspi_of_match, &pdev->dev); |
| 1129 | if (match) { |
| 1130 | u32 num_cs = 1; /* default number of chipselect */ |
| 1131 | pdata = match->data; |
| 1132 | |
| 1133 | of_property_read_u32(node, "ti,spi-num-cs", &num_cs); |
| 1134 | master->num_chipselect = num_cs; |
| 1135 | master->bus_num = bus_num++; |
| 1136 | } else { |
| 1137 | pdata = pdev->dev.platform_data; |
| 1138 | master->num_chipselect = pdata->num_cs; |
| 1139 | if (pdev->id != -1) |
| 1140 | master->bus_num = pdev->id; |
| 1141 | } |
| 1142 | regs_offset = pdata->regs_offset; |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 1143 | |
| 1144 | dev_set_drvdata(&pdev->dev, master); |
| 1145 | |
| 1146 | mcspi = spi_master_get_devdata(master); |
| 1147 | mcspi->master = master; |
| 1148 | |
Benoit Cousson | 1bd897f8 | 2012-03-26 15:32:33 +0530 | [diff] [blame] | 1149 | mcspi->wq = alloc_workqueue(dev_name(&pdev->dev), WQ_MEM_RECLAIM, 1); |
Shubhrajyoti D | 2856ac1 | 2011-10-28 17:14:17 +0530 | [diff] [blame] | 1150 | if (mcspi->wq == NULL) { |
| 1151 | status = -ENOMEM; |
Shubhrajyoti D | 39f1b56 | 2011-10-28 17:14:19 +0530 | [diff] [blame] | 1152 | goto free_master; |
Shubhrajyoti D | 2856ac1 | 2011-10-28 17:14:17 +0530 | [diff] [blame] | 1153 | } |
| 1154 | |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 1155 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1156 | if (r == NULL) { |
| 1157 | status = -ENODEV; |
Shubhrajyoti D | 39f1b56 | 2011-10-28 17:14:19 +0530 | [diff] [blame] | 1158 | goto free_master; |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 1159 | } |
Shubhrajyoti D | 1458d16 | 2011-10-24 15:54:24 +0530 | [diff] [blame] | 1160 | |
Benoit Cousson | d5a8003 | 2012-02-15 18:37:34 +0100 | [diff] [blame] | 1161 | r->start += regs_offset; |
| 1162 | r->end += regs_offset; |
Shubhrajyoti D | 1458d16 | 2011-10-24 15:54:24 +0530 | [diff] [blame] | 1163 | mcspi->phys = r->start; |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 1164 | |
Shubhrajyoti D | 1a77b12 | 2012-03-17 12:44:01 +0530 | [diff] [blame] | 1165 | mcspi->base = devm_request_and_ioremap(&pdev->dev, r); |
Russell King | 55c381e | 2008-09-04 14:07:22 +0100 | [diff] [blame] | 1166 | if (!mcspi->base) { |
| 1167 | dev_dbg(&pdev->dev, "can't ioremap MCSPI\n"); |
| 1168 | status = -ENOMEM; |
Shubhrajyoti D | 1a77b12 | 2012-03-17 12:44:01 +0530 | [diff] [blame] | 1169 | goto free_master; |
Russell King | 55c381e | 2008-09-04 14:07:22 +0100 | [diff] [blame] | 1170 | } |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 1171 | |
Govindraj.R | 1f1a438 | 2011-02-02 17:52:15 +0530 | [diff] [blame] | 1172 | mcspi->dev = &pdev->dev; |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 1173 | INIT_WORK(&mcspi->work, omap2_mcspi_work); |
| 1174 | |
| 1175 | spin_lock_init(&mcspi->lock); |
| 1176 | INIT_LIST_HEAD(&mcspi->msg_queue); |
Benoit Cousson | 1bd897f8 | 2012-03-26 15:32:33 +0530 | [diff] [blame] | 1177 | INIT_LIST_HEAD(&mcspi->ctx.cs); |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 1178 | |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 1179 | mcspi->dma_channels = kcalloc(master->num_chipselect, |
| 1180 | sizeof(struct omap2_mcspi_dma), |
| 1181 | GFP_KERNEL); |
| 1182 | |
| 1183 | if (mcspi->dma_channels == NULL) |
Shubhrajyoti D | 1a77b12 | 2012-03-17 12:44:01 +0530 | [diff] [blame] | 1184 | goto free_master; |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 1185 | |
Charulatha V | 1a5d819 | 2011-02-02 17:52:14 +0530 | [diff] [blame] | 1186 | for (i = 0; i < master->num_chipselect; i++) { |
| 1187 | char dma_ch_name[14]; |
| 1188 | struct resource *dma_res; |
| 1189 | |
| 1190 | sprintf(dma_ch_name, "rx%d", i); |
| 1191 | dma_res = platform_get_resource_byname(pdev, IORESOURCE_DMA, |
| 1192 | dma_ch_name); |
| 1193 | if (!dma_res) { |
| 1194 | dev_dbg(&pdev->dev, "cannot get DMA RX channel\n"); |
| 1195 | status = -ENODEV; |
| 1196 | break; |
| 1197 | } |
| 1198 | |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 1199 | mcspi->dma_channels[i].dma_rx_channel = -1; |
Charulatha V | 1a5d819 | 2011-02-02 17:52:14 +0530 | [diff] [blame] | 1200 | mcspi->dma_channels[i].dma_rx_sync_dev = dma_res->start; |
| 1201 | sprintf(dma_ch_name, "tx%d", i); |
| 1202 | dma_res = platform_get_resource_byname(pdev, IORESOURCE_DMA, |
| 1203 | dma_ch_name); |
| 1204 | if (!dma_res) { |
| 1205 | dev_dbg(&pdev->dev, "cannot get DMA TX channel\n"); |
| 1206 | status = -ENODEV; |
| 1207 | break; |
| 1208 | } |
| 1209 | |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 1210 | mcspi->dma_channels[i].dma_tx_channel = -1; |
Charulatha V | 1a5d819 | 2011-02-02 17:52:14 +0530 | [diff] [blame] | 1211 | mcspi->dma_channels[i].dma_tx_sync_dev = dma_res->start; |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 1212 | } |
| 1213 | |
Shubhrajyoti D | 39f1b56 | 2011-10-28 17:14:19 +0530 | [diff] [blame] | 1214 | if (status < 0) |
| 1215 | goto dma_chnl_free; |
| 1216 | |
Shubhrajyoti D | 27b5284 | 2012-03-26 17:04:22 +0530 | [diff] [blame^] | 1217 | pm_runtime_use_autosuspend(&pdev->dev); |
| 1218 | pm_runtime_set_autosuspend_delay(&pdev->dev, SPI_AUTOSUSPEND_TIMEOUT); |
Govindraj.R | 1f1a438 | 2011-02-02 17:52:15 +0530 | [diff] [blame] | 1219 | pm_runtime_enable(&pdev->dev); |
| 1220 | |
| 1221 | if (status || omap2_mcspi_master_setup(mcspi) < 0) |
Shubhrajyoti D | 39f1b56 | 2011-10-28 17:14:19 +0530 | [diff] [blame] | 1222 | goto disable_pm; |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 1223 | |
| 1224 | status = spi_register_master(master); |
| 1225 | if (status < 0) |
Shubhrajyoti D | 39f1b56 | 2011-10-28 17:14:19 +0530 | [diff] [blame] | 1226 | goto err_spi_register; |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 1227 | |
| 1228 | return status; |
| 1229 | |
Shubhrajyoti D | 39f1b56 | 2011-10-28 17:14:19 +0530 | [diff] [blame] | 1230 | err_spi_register: |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 1231 | spi_master_put(master); |
Shubhrajyoti D | 39f1b56 | 2011-10-28 17:14:19 +0530 | [diff] [blame] | 1232 | disable_pm: |
Shubhrajyoti D | 751c925 | 2011-10-28 17:14:18 +0530 | [diff] [blame] | 1233 | pm_runtime_disable(&pdev->dev); |
Shubhrajyoti D | 39f1b56 | 2011-10-28 17:14:19 +0530 | [diff] [blame] | 1234 | dma_chnl_free: |
Govindraj.R | 1f1a438 | 2011-02-02 17:52:15 +0530 | [diff] [blame] | 1235 | kfree(mcspi->dma_channels); |
Shubhrajyoti D | 39f1b56 | 2011-10-28 17:14:19 +0530 | [diff] [blame] | 1236 | free_master: |
| 1237 | kfree(master); |
| 1238 | platform_set_drvdata(pdev, NULL); |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 1239 | return status; |
| 1240 | } |
| 1241 | |
Felipe Balbi | 7d6b6d8 | 2012-03-14 11:18:30 +0200 | [diff] [blame] | 1242 | static int __devexit omap2_mcspi_remove(struct platform_device *pdev) |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 1243 | { |
| 1244 | struct spi_master *master; |
| 1245 | struct omap2_mcspi *mcspi; |
| 1246 | struct omap2_mcspi_dma *dma_channels; |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 1247 | |
| 1248 | master = dev_get_drvdata(&pdev->dev); |
| 1249 | mcspi = spi_master_get_devdata(master); |
| 1250 | dma_channels = mcspi->dma_channels; |
| 1251 | |
Govindraj.R | 1f1a438 | 2011-02-02 17:52:15 +0530 | [diff] [blame] | 1252 | omap2_mcspi_disable_clocks(mcspi); |
Shubhrajyoti D | 751c925 | 2011-10-28 17:14:18 +0530 | [diff] [blame] | 1253 | pm_runtime_disable(&pdev->dev); |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 1254 | |
| 1255 | spi_unregister_master(master); |
| 1256 | kfree(dma_channels); |
Shubhrajyoti D | 2856ac1 | 2011-10-28 17:14:17 +0530 | [diff] [blame] | 1257 | destroy_workqueue(mcspi->wq); |
Shubhrajyoti D | 39f1b56 | 2011-10-28 17:14:19 +0530 | [diff] [blame] | 1258 | platform_set_drvdata(pdev, NULL); |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 1259 | |
| 1260 | return 0; |
| 1261 | } |
| 1262 | |
Kay Sievers | 7e38c3c | 2008-04-10 21:29:20 -0700 | [diff] [blame] | 1263 | /* work with hotplug and coldplug */ |
| 1264 | MODULE_ALIAS("platform:omap2_mcspi"); |
| 1265 | |
Gregory CLEMENT | 42ce7fd | 2010-12-29 11:52:53 +0100 | [diff] [blame] | 1266 | #ifdef CONFIG_SUSPEND |
| 1267 | /* |
| 1268 | * When SPI wake up from off-mode, CS is in activate state. If it was in |
| 1269 | * unactive state when driver was suspend, then force it to unactive state at |
| 1270 | * wake up. |
| 1271 | */ |
| 1272 | static int omap2_mcspi_resume(struct device *dev) |
| 1273 | { |
| 1274 | struct spi_master *master = dev_get_drvdata(dev); |
| 1275 | struct omap2_mcspi *mcspi = spi_master_get_devdata(master); |
Benoit Cousson | 1bd897f8 | 2012-03-26 15:32:33 +0530 | [diff] [blame] | 1276 | struct omap2_mcspi_regs *ctx = &mcspi->ctx; |
| 1277 | struct omap2_mcspi_cs *cs; |
Gregory CLEMENT | 42ce7fd | 2010-12-29 11:52:53 +0100 | [diff] [blame] | 1278 | |
| 1279 | omap2_mcspi_enable_clocks(mcspi); |
Benoit Cousson | 1bd897f8 | 2012-03-26 15:32:33 +0530 | [diff] [blame] | 1280 | list_for_each_entry(cs, &ctx->cs, node) { |
Gregory CLEMENT | 42ce7fd | 2010-12-29 11:52:53 +0100 | [diff] [blame] | 1281 | if ((cs->chconf0 & OMAP2_MCSPI_CHCONF_FORCE) == 0) { |
Gregory CLEMENT | 42ce7fd | 2010-12-29 11:52:53 +0100 | [diff] [blame] | 1282 | /* |
| 1283 | * We need to toggle CS state for OMAP take this |
| 1284 | * change in account. |
| 1285 | */ |
| 1286 | MOD_REG_BIT(cs->chconf0, OMAP2_MCSPI_CHCONF_FORCE, 1); |
| 1287 | __raw_writel(cs->chconf0, cs->base + OMAP2_MCSPI_CHCONF0); |
| 1288 | MOD_REG_BIT(cs->chconf0, OMAP2_MCSPI_CHCONF_FORCE, 0); |
| 1289 | __raw_writel(cs->chconf0, cs->base + OMAP2_MCSPI_CHCONF0); |
| 1290 | } |
| 1291 | } |
| 1292 | omap2_mcspi_disable_clocks(mcspi); |
| 1293 | return 0; |
| 1294 | } |
| 1295 | #else |
| 1296 | #define omap2_mcspi_resume NULL |
| 1297 | #endif |
| 1298 | |
| 1299 | static const struct dev_pm_ops omap2_mcspi_pm_ops = { |
| 1300 | .resume = omap2_mcspi_resume, |
Govindraj.R | 1f1a438 | 2011-02-02 17:52:15 +0530 | [diff] [blame] | 1301 | .runtime_resume = omap_mcspi_runtime_resume, |
Gregory CLEMENT | 42ce7fd | 2010-12-29 11:52:53 +0100 | [diff] [blame] | 1302 | }; |
| 1303 | |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 1304 | static struct platform_driver omap2_mcspi_driver = { |
| 1305 | .driver = { |
| 1306 | .name = "omap2_mcspi", |
| 1307 | .owner = THIS_MODULE, |
Benoit Cousson | d5a8003 | 2012-02-15 18:37:34 +0100 | [diff] [blame] | 1308 | .pm = &omap2_mcspi_pm_ops, |
| 1309 | .of_match_table = omap_mcspi_of_match, |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 1310 | }, |
Felipe Balbi | 7d6b6d8 | 2012-03-14 11:18:30 +0200 | [diff] [blame] | 1311 | .probe = omap2_mcspi_probe, |
| 1312 | .remove = __devexit_p(omap2_mcspi_remove), |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 1313 | }; |
| 1314 | |
Felipe Balbi | 9fdca9d | 2012-03-14 11:18:31 +0200 | [diff] [blame] | 1315 | module_platform_driver(omap2_mcspi_driver); |
Samuel Ortiz | ccdc7bf | 2007-07-17 04:04:13 -0700 | [diff] [blame] | 1316 | MODULE_LICENSE("GPL"); |