Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2005 Stephen Street / StreetFire Sound Labs |
Mika Westerberg | a0d2642 | 2013-01-22 12:26:32 +0200 | [diff] [blame] | 3 | * Copyright (C) 2013, Intel Corporation |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 18 | */ |
| 19 | |
| 20 | #include <linux/init.h> |
| 21 | #include <linux/module.h> |
| 22 | #include <linux/device.h> |
| 23 | #include <linux/ioport.h> |
| 24 | #include <linux/errno.h> |
Sachin Kamat | cbfd6a2 | 2013-04-08 15:49:33 +0530 | [diff] [blame] | 25 | #include <linux/err.h> |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 26 | #include <linux/interrupt.h> |
| 27 | #include <linux/platform_device.h> |
Sebastian Andrzej Siewior | 8348c25 | 2010-11-22 17:12:15 -0800 | [diff] [blame] | 28 | #include <linux/spi/pxa2xx_spi.h> |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 29 | #include <linux/spi/spi.h> |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 30 | #include <linux/delay.h> |
Eric Miao | a7bb390 | 2009-04-06 19:00:54 -0700 | [diff] [blame] | 31 | #include <linux/gpio.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 32 | #include <linux/slab.h> |
Mika Westerberg | 3343b7a | 2013-01-22 12:26:27 +0200 | [diff] [blame] | 33 | #include <linux/clk.h> |
Mika Westerberg | 7d94a50 | 2013-01-22 12:26:30 +0200 | [diff] [blame] | 34 | #include <linux/pm_runtime.h> |
Mika Westerberg | a349685 | 2013-01-22 12:26:33 +0200 | [diff] [blame] | 35 | #include <linux/acpi.h> |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 36 | |
| 37 | #include <asm/io.h> |
| 38 | #include <asm/irq.h> |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 39 | #include <asm/delay.h> |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 40 | |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 41 | #include "spi-pxa2xx.h" |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 42 | |
| 43 | MODULE_AUTHOR("Stephen Street"); |
Will Newton | 037cdaf | 2007-12-10 15:49:25 -0800 | [diff] [blame] | 44 | MODULE_DESCRIPTION("PXA2xx SSP SPI Controller"); |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 45 | MODULE_LICENSE("GPL"); |
Kay Sievers | 7e38c3c | 2008-04-10 21:29:20 -0700 | [diff] [blame] | 46 | MODULE_ALIAS("platform:pxa2xx-spi"); |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 47 | |
| 48 | #define MAX_BUSES 3 |
| 49 | |
Vernon Sauder | f1f640a | 2008-10-15 22:02:43 -0700 | [diff] [blame] | 50 | #define TIMOUT_DFLT 1000 |
| 51 | |
Ned Forrester | b97c74b | 2008-02-23 15:23:40 -0800 | [diff] [blame] | 52 | /* |
| 53 | * for testing SSCR1 changes that require SSP restart, basically |
| 54 | * everything except the service and interrupt enables, the pxa270 developer |
| 55 | * manual says only SSCR1_SCFR, SSCR1_SPH, SSCR1_SPO need to be in this |
| 56 | * list, but the PXA255 dev man says all bits without really meaning the |
| 57 | * service and interrupt enables |
| 58 | */ |
| 59 | #define SSCR1_CHANGE_MASK (SSCR1_TTELP | SSCR1_TTE | SSCR1_SCFR \ |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 60 | | SSCR1_ECRA | SSCR1_ECRB | SSCR1_SCLKDIR \ |
Ned Forrester | b97c74b | 2008-02-23 15:23:40 -0800 | [diff] [blame] | 61 | | SSCR1_SFRMDIR | SSCR1_RWOT | SSCR1_TRAIL \ |
| 62 | | SSCR1_IFS | SSCR1_STRF | SSCR1_EFWR \ |
| 63 | | SSCR1_RFT | SSCR1_TFT | SSCR1_MWDS \ |
| 64 | | SSCR1_SPH | SSCR1_SPO | SSCR1_LBM) |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 65 | |
Mika Westerberg | a0d2642 | 2013-01-22 12:26:32 +0200 | [diff] [blame] | 66 | #define LPSS_RX_THRESH_DFLT 64 |
| 67 | #define LPSS_TX_LOTHRESH_DFLT 160 |
| 68 | #define LPSS_TX_HITHRESH_DFLT 224 |
| 69 | |
| 70 | /* Offset from drv_data->lpss_base */ |
Mika Westerberg | 1de7061 | 2013-07-03 13:25:06 +0300 | [diff] [blame] | 71 | #define GENERAL_REG 0x08 |
| 72 | #define GENERAL_REG_RXTO_HOLDOFF_DISABLE BIT(24) |
Mika Westerberg | 0054e28 | 2013-03-05 12:05:17 +0200 | [diff] [blame] | 73 | #define SSP_REG 0x0c |
Mika Westerberg | a0d2642 | 2013-01-22 12:26:32 +0200 | [diff] [blame] | 74 | #define SPI_CS_CONTROL 0x18 |
| 75 | #define SPI_CS_CONTROL_SW_MODE BIT(0) |
| 76 | #define SPI_CS_CONTROL_CS_HIGH BIT(1) |
| 77 | |
| 78 | static bool is_lpss_ssp(const struct driver_data *drv_data) |
| 79 | { |
| 80 | return drv_data->ssp_type == LPSS_SSP; |
| 81 | } |
| 82 | |
Weike Chen | 4fdb242 | 2014-10-08 08:50:22 -0700 | [diff] [blame^] | 83 | static u32 pxa2xx_spi_get_ssrc1_change_mask(const struct driver_data *drv_data) |
| 84 | { |
| 85 | switch (drv_data->ssp_type) { |
| 86 | default: |
| 87 | return SSCR1_CHANGE_MASK; |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | static u32 |
| 92 | pxa2xx_spi_get_rx_default_thre(const struct driver_data *drv_data) |
| 93 | { |
| 94 | switch (drv_data->ssp_type) { |
| 95 | default: |
| 96 | return RX_THRESH_DFLT; |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | static bool pxa2xx_spi_txfifo_full(const struct driver_data *drv_data) |
| 101 | { |
| 102 | void __iomem *reg = drv_data->ioaddr; |
| 103 | u32 mask; |
| 104 | |
| 105 | switch (drv_data->ssp_type) { |
| 106 | default: |
| 107 | mask = SSSR_TFL_MASK; |
| 108 | break; |
| 109 | } |
| 110 | |
| 111 | return (read_SSSR(reg) & mask) == mask; |
| 112 | } |
| 113 | |
| 114 | static void pxa2xx_spi_clear_rx_thre(const struct driver_data *drv_data, |
| 115 | u32 *sccr1_reg) |
| 116 | { |
| 117 | u32 mask; |
| 118 | |
| 119 | switch (drv_data->ssp_type) { |
| 120 | default: |
| 121 | mask = SSCR1_RFT; |
| 122 | break; |
| 123 | } |
| 124 | *sccr1_reg &= ~mask; |
| 125 | } |
| 126 | |
| 127 | static void pxa2xx_spi_set_rx_thre(const struct driver_data *drv_data, |
| 128 | u32 *sccr1_reg, u32 threshold) |
| 129 | { |
| 130 | switch (drv_data->ssp_type) { |
| 131 | default: |
| 132 | *sccr1_reg |= SSCR1_RxTresh(threshold); |
| 133 | break; |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | static u32 pxa2xx_configure_sscr0(const struct driver_data *drv_data, |
| 138 | u32 clk_div, u8 bits) |
| 139 | { |
| 140 | switch (drv_data->ssp_type) { |
| 141 | default: |
| 142 | return clk_div |
| 143 | | SSCR0_Motorola |
| 144 | | SSCR0_DataSize(bits > 16 ? bits - 16 : bits) |
| 145 | | SSCR0_SSE |
| 146 | | (bits > 16 ? SSCR0_EDSS : 0); |
| 147 | } |
| 148 | } |
| 149 | |
Mika Westerberg | a0d2642 | 2013-01-22 12:26:32 +0200 | [diff] [blame] | 150 | /* |
| 151 | * Read and write LPSS SSP private registers. Caller must first check that |
| 152 | * is_lpss_ssp() returns true before these can be called. |
| 153 | */ |
| 154 | static u32 __lpss_ssp_read_priv(struct driver_data *drv_data, unsigned offset) |
| 155 | { |
| 156 | WARN_ON(!drv_data->lpss_base); |
| 157 | return readl(drv_data->lpss_base + offset); |
| 158 | } |
| 159 | |
| 160 | static void __lpss_ssp_write_priv(struct driver_data *drv_data, |
| 161 | unsigned offset, u32 value) |
| 162 | { |
| 163 | WARN_ON(!drv_data->lpss_base); |
| 164 | writel(value, drv_data->lpss_base + offset); |
| 165 | } |
| 166 | |
| 167 | /* |
| 168 | * lpss_ssp_setup - perform LPSS SSP specific setup |
| 169 | * @drv_data: pointer to the driver private data |
| 170 | * |
| 171 | * Perform LPSS SSP specific setup. This function must be called first if |
| 172 | * one is going to use LPSS SSP private registers. |
| 173 | */ |
| 174 | static void lpss_ssp_setup(struct driver_data *drv_data) |
| 175 | { |
| 176 | unsigned offset = 0x400; |
| 177 | u32 value, orig; |
| 178 | |
| 179 | if (!is_lpss_ssp(drv_data)) |
| 180 | return; |
| 181 | |
| 182 | /* |
| 183 | * Perform auto-detection of the LPSS SSP private registers. They |
| 184 | * can be either at 1k or 2k offset from the base address. |
| 185 | */ |
| 186 | orig = readl(drv_data->ioaddr + offset + SPI_CS_CONTROL); |
| 187 | |
Chew, Chiau Ee | e61f487 | 2014-06-13 23:57:25 +0800 | [diff] [blame] | 188 | /* Test SPI_CS_CONTROL_SW_MODE bit enabling */ |
Mika Westerberg | a0d2642 | 2013-01-22 12:26:32 +0200 | [diff] [blame] | 189 | value = orig | SPI_CS_CONTROL_SW_MODE; |
| 190 | writel(value, drv_data->ioaddr + offset + SPI_CS_CONTROL); |
| 191 | value = readl(drv_data->ioaddr + offset + SPI_CS_CONTROL); |
| 192 | if (value != (orig | SPI_CS_CONTROL_SW_MODE)) { |
| 193 | offset = 0x800; |
| 194 | goto detection_done; |
| 195 | } |
| 196 | |
Chew, Chiau Ee | e61f487 | 2014-06-13 23:57:25 +0800 | [diff] [blame] | 197 | orig = readl(drv_data->ioaddr + offset + SPI_CS_CONTROL); |
| 198 | |
| 199 | /* Test SPI_CS_CONTROL_SW_MODE bit disabling */ |
| 200 | value = orig & ~SPI_CS_CONTROL_SW_MODE; |
Mika Westerberg | a0d2642 | 2013-01-22 12:26:32 +0200 | [diff] [blame] | 201 | writel(value, drv_data->ioaddr + offset + SPI_CS_CONTROL); |
| 202 | value = readl(drv_data->ioaddr + offset + SPI_CS_CONTROL); |
Chew, Chiau Ee | e61f487 | 2014-06-13 23:57:25 +0800 | [diff] [blame] | 203 | if (value != (orig & ~SPI_CS_CONTROL_SW_MODE)) { |
Mika Westerberg | a0d2642 | 2013-01-22 12:26:32 +0200 | [diff] [blame] | 204 | offset = 0x800; |
| 205 | goto detection_done; |
| 206 | } |
| 207 | |
| 208 | detection_done: |
| 209 | /* Now set the LPSS base */ |
| 210 | drv_data->lpss_base = drv_data->ioaddr + offset; |
| 211 | |
| 212 | /* Enable software chip select control */ |
| 213 | value = SPI_CS_CONTROL_SW_MODE | SPI_CS_CONTROL_CS_HIGH; |
| 214 | __lpss_ssp_write_priv(drv_data, SPI_CS_CONTROL, value); |
Mika Westerberg | 0054e28 | 2013-03-05 12:05:17 +0200 | [diff] [blame] | 215 | |
| 216 | /* Enable multiblock DMA transfers */ |
Mika Westerberg | 1de7061 | 2013-07-03 13:25:06 +0300 | [diff] [blame] | 217 | if (drv_data->master_info->enable_dma) { |
Mika Westerberg | 0054e28 | 2013-03-05 12:05:17 +0200 | [diff] [blame] | 218 | __lpss_ssp_write_priv(drv_data, SSP_REG, 1); |
Mika Westerberg | 1de7061 | 2013-07-03 13:25:06 +0300 | [diff] [blame] | 219 | |
| 220 | value = __lpss_ssp_read_priv(drv_data, GENERAL_REG); |
| 221 | value |= GENERAL_REG_RXTO_HOLDOFF_DISABLE; |
| 222 | __lpss_ssp_write_priv(drv_data, GENERAL_REG, value); |
| 223 | } |
Mika Westerberg | a0d2642 | 2013-01-22 12:26:32 +0200 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | static void lpss_ssp_cs_control(struct driver_data *drv_data, bool enable) |
| 227 | { |
| 228 | u32 value; |
| 229 | |
| 230 | if (!is_lpss_ssp(drv_data)) |
| 231 | return; |
| 232 | |
| 233 | value = __lpss_ssp_read_priv(drv_data, SPI_CS_CONTROL); |
| 234 | if (enable) |
| 235 | value &= ~SPI_CS_CONTROL_CS_HIGH; |
| 236 | else |
| 237 | value |= SPI_CS_CONTROL_CS_HIGH; |
| 238 | __lpss_ssp_write_priv(drv_data, SPI_CS_CONTROL, value); |
| 239 | } |
| 240 | |
Eric Miao | a7bb390 | 2009-04-06 19:00:54 -0700 | [diff] [blame] | 241 | static void cs_assert(struct driver_data *drv_data) |
| 242 | { |
| 243 | struct chip_data *chip = drv_data->cur_chip; |
| 244 | |
Sebastian Andrzej Siewior | 2a8626a | 2010-11-22 17:12:17 -0800 | [diff] [blame] | 245 | if (drv_data->ssp_type == CE4100_SSP) { |
| 246 | write_SSSR(drv_data->cur_chip->frm, drv_data->ioaddr); |
| 247 | return; |
| 248 | } |
| 249 | |
Eric Miao | a7bb390 | 2009-04-06 19:00:54 -0700 | [diff] [blame] | 250 | if (chip->cs_control) { |
| 251 | chip->cs_control(PXA2XX_CS_ASSERT); |
| 252 | return; |
| 253 | } |
| 254 | |
Mika Westerberg | a0d2642 | 2013-01-22 12:26:32 +0200 | [diff] [blame] | 255 | if (gpio_is_valid(chip->gpio_cs)) { |
Eric Miao | a7bb390 | 2009-04-06 19:00:54 -0700 | [diff] [blame] | 256 | gpio_set_value(chip->gpio_cs, chip->gpio_cs_inverted); |
Mika Westerberg | a0d2642 | 2013-01-22 12:26:32 +0200 | [diff] [blame] | 257 | return; |
| 258 | } |
| 259 | |
| 260 | lpss_ssp_cs_control(drv_data, true); |
Eric Miao | a7bb390 | 2009-04-06 19:00:54 -0700 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | static void cs_deassert(struct driver_data *drv_data) |
| 264 | { |
| 265 | struct chip_data *chip = drv_data->cur_chip; |
| 266 | |
Sebastian Andrzej Siewior | 2a8626a | 2010-11-22 17:12:17 -0800 | [diff] [blame] | 267 | if (drv_data->ssp_type == CE4100_SSP) |
| 268 | return; |
| 269 | |
Eric Miao | a7bb390 | 2009-04-06 19:00:54 -0700 | [diff] [blame] | 270 | if (chip->cs_control) { |
Daniel Ribeiro | 2b2562d | 2009-04-08 22:48:03 -0300 | [diff] [blame] | 271 | chip->cs_control(PXA2XX_CS_DEASSERT); |
Eric Miao | a7bb390 | 2009-04-06 19:00:54 -0700 | [diff] [blame] | 272 | return; |
| 273 | } |
| 274 | |
Mika Westerberg | a0d2642 | 2013-01-22 12:26:32 +0200 | [diff] [blame] | 275 | if (gpio_is_valid(chip->gpio_cs)) { |
Eric Miao | a7bb390 | 2009-04-06 19:00:54 -0700 | [diff] [blame] | 276 | gpio_set_value(chip->gpio_cs, !chip->gpio_cs_inverted); |
Mika Westerberg | a0d2642 | 2013-01-22 12:26:32 +0200 | [diff] [blame] | 277 | return; |
| 278 | } |
| 279 | |
| 280 | lpss_ssp_cs_control(drv_data, false); |
Eric Miao | a7bb390 | 2009-04-06 19:00:54 -0700 | [diff] [blame] | 281 | } |
| 282 | |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 283 | int pxa2xx_spi_flush(struct driver_data *drv_data) |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 284 | { |
| 285 | unsigned long limit = loops_per_jiffy << 1; |
| 286 | |
David Brownell | cf43369 | 2008-04-28 02:14:17 -0700 | [diff] [blame] | 287 | void __iomem *reg = drv_data->ioaddr; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 288 | |
| 289 | do { |
| 290 | while (read_SSSR(reg) & SSSR_RNE) { |
| 291 | read_SSDR(reg); |
| 292 | } |
Roel Kluin | 306c68a | 2009-04-21 12:24:46 -0700 | [diff] [blame] | 293 | } while ((read_SSSR(reg) & SSSR_BSY) && --limit); |
Sebastian Andrzej Siewior | 2a8626a | 2010-11-22 17:12:17 -0800 | [diff] [blame] | 294 | write_SSSR_CS(drv_data, SSSR_ROR); |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 295 | |
| 296 | return limit; |
| 297 | } |
| 298 | |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 299 | static int null_writer(struct driver_data *drv_data) |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 300 | { |
David Brownell | cf43369 | 2008-04-28 02:14:17 -0700 | [diff] [blame] | 301 | void __iomem *reg = drv_data->ioaddr; |
Stephen Street | 9708c12 | 2006-03-28 14:05:23 -0800 | [diff] [blame] | 302 | u8 n_bytes = drv_data->n_bytes; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 303 | |
Weike Chen | 4fdb242 | 2014-10-08 08:50:22 -0700 | [diff] [blame^] | 304 | if (pxa2xx_spi_txfifo_full(drv_data) |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 305 | || (drv_data->tx == drv_data->tx_end)) |
| 306 | return 0; |
| 307 | |
| 308 | write_SSDR(0, reg); |
| 309 | drv_data->tx += n_bytes; |
| 310 | |
| 311 | return 1; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 312 | } |
| 313 | |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 314 | static int null_reader(struct driver_data *drv_data) |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 315 | { |
David Brownell | cf43369 | 2008-04-28 02:14:17 -0700 | [diff] [blame] | 316 | void __iomem *reg = drv_data->ioaddr; |
Stephen Street | 9708c12 | 2006-03-28 14:05:23 -0800 | [diff] [blame] | 317 | u8 n_bytes = drv_data->n_bytes; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 318 | |
| 319 | while ((read_SSSR(reg) & SSSR_RNE) |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 320 | && (drv_data->rx < drv_data->rx_end)) { |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 321 | read_SSDR(reg); |
| 322 | drv_data->rx += n_bytes; |
| 323 | } |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 324 | |
| 325 | return drv_data->rx == drv_data->rx_end; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 326 | } |
| 327 | |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 328 | static int u8_writer(struct driver_data *drv_data) |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 329 | { |
David Brownell | cf43369 | 2008-04-28 02:14:17 -0700 | [diff] [blame] | 330 | void __iomem *reg = drv_data->ioaddr; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 331 | |
Weike Chen | 4fdb242 | 2014-10-08 08:50:22 -0700 | [diff] [blame^] | 332 | if (pxa2xx_spi_txfifo_full(drv_data) |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 333 | || (drv_data->tx == drv_data->tx_end)) |
| 334 | return 0; |
| 335 | |
| 336 | write_SSDR(*(u8 *)(drv_data->tx), reg); |
| 337 | ++drv_data->tx; |
| 338 | |
| 339 | return 1; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 340 | } |
| 341 | |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 342 | static int u8_reader(struct driver_data *drv_data) |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 343 | { |
David Brownell | cf43369 | 2008-04-28 02:14:17 -0700 | [diff] [blame] | 344 | void __iomem *reg = drv_data->ioaddr; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 345 | |
| 346 | while ((read_SSSR(reg) & SSSR_RNE) |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 347 | && (drv_data->rx < drv_data->rx_end)) { |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 348 | *(u8 *)(drv_data->rx) = read_SSDR(reg); |
| 349 | ++drv_data->rx; |
| 350 | } |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 351 | |
| 352 | return drv_data->rx == drv_data->rx_end; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 353 | } |
| 354 | |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 355 | static int u16_writer(struct driver_data *drv_data) |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 356 | { |
David Brownell | cf43369 | 2008-04-28 02:14:17 -0700 | [diff] [blame] | 357 | void __iomem *reg = drv_data->ioaddr; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 358 | |
Weike Chen | 4fdb242 | 2014-10-08 08:50:22 -0700 | [diff] [blame^] | 359 | if (pxa2xx_spi_txfifo_full(drv_data) |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 360 | || (drv_data->tx == drv_data->tx_end)) |
| 361 | return 0; |
| 362 | |
| 363 | write_SSDR(*(u16 *)(drv_data->tx), reg); |
| 364 | drv_data->tx += 2; |
| 365 | |
| 366 | return 1; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 367 | } |
| 368 | |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 369 | static int u16_reader(struct driver_data *drv_data) |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 370 | { |
David Brownell | cf43369 | 2008-04-28 02:14:17 -0700 | [diff] [blame] | 371 | void __iomem *reg = drv_data->ioaddr; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 372 | |
| 373 | while ((read_SSSR(reg) & SSSR_RNE) |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 374 | && (drv_data->rx < drv_data->rx_end)) { |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 375 | *(u16 *)(drv_data->rx) = read_SSDR(reg); |
| 376 | drv_data->rx += 2; |
| 377 | } |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 378 | |
| 379 | return drv_data->rx == drv_data->rx_end; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 380 | } |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 381 | |
| 382 | static int u32_writer(struct driver_data *drv_data) |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 383 | { |
David Brownell | cf43369 | 2008-04-28 02:14:17 -0700 | [diff] [blame] | 384 | void __iomem *reg = drv_data->ioaddr; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 385 | |
Weike Chen | 4fdb242 | 2014-10-08 08:50:22 -0700 | [diff] [blame^] | 386 | if (pxa2xx_spi_txfifo_full(drv_data) |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 387 | || (drv_data->tx == drv_data->tx_end)) |
| 388 | return 0; |
| 389 | |
| 390 | write_SSDR(*(u32 *)(drv_data->tx), reg); |
| 391 | drv_data->tx += 4; |
| 392 | |
| 393 | return 1; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 394 | } |
| 395 | |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 396 | static int u32_reader(struct driver_data *drv_data) |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 397 | { |
David Brownell | cf43369 | 2008-04-28 02:14:17 -0700 | [diff] [blame] | 398 | void __iomem *reg = drv_data->ioaddr; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 399 | |
| 400 | while ((read_SSSR(reg) & SSSR_RNE) |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 401 | && (drv_data->rx < drv_data->rx_end)) { |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 402 | *(u32 *)(drv_data->rx) = read_SSDR(reg); |
| 403 | drv_data->rx += 4; |
| 404 | } |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 405 | |
| 406 | return drv_data->rx == drv_data->rx_end; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 407 | } |
| 408 | |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 409 | void *pxa2xx_spi_next_transfer(struct driver_data *drv_data) |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 410 | { |
| 411 | struct spi_message *msg = drv_data->cur_msg; |
| 412 | struct spi_transfer *trans = drv_data->cur_transfer; |
| 413 | |
| 414 | /* Move to next transfer */ |
| 415 | if (trans->transfer_list.next != &msg->transfers) { |
| 416 | drv_data->cur_transfer = |
| 417 | list_entry(trans->transfer_list.next, |
| 418 | struct spi_transfer, |
| 419 | transfer_list); |
| 420 | return RUNNING_STATE; |
| 421 | } else |
| 422 | return DONE_STATE; |
| 423 | } |
| 424 | |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 425 | /* caller already set message->status; dma and pio irqs are blocked */ |
Stephen Street | 5daa3ba | 2006-05-20 15:00:19 -0700 | [diff] [blame] | 426 | static void giveback(struct driver_data *drv_data) |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 427 | { |
| 428 | struct spi_transfer* last_transfer; |
Stephen Street | 5daa3ba | 2006-05-20 15:00:19 -0700 | [diff] [blame] | 429 | struct spi_message *msg; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 430 | |
Stephen Street | 5daa3ba | 2006-05-20 15:00:19 -0700 | [diff] [blame] | 431 | msg = drv_data->cur_msg; |
| 432 | drv_data->cur_msg = NULL; |
| 433 | drv_data->cur_transfer = NULL; |
Stephen Street | 5daa3ba | 2006-05-20 15:00:19 -0700 | [diff] [blame] | 434 | |
Axel Lin | 23e2c2a | 2014-02-12 22:13:27 +0800 | [diff] [blame] | 435 | last_transfer = list_last_entry(&msg->transfers, struct spi_transfer, |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 436 | transfer_list); |
| 437 | |
Ned Forrester | 8423597 | 2008-09-13 02:33:17 -0700 | [diff] [blame] | 438 | /* Delay if requested before any change in chip select */ |
| 439 | if (last_transfer->delay_usecs) |
| 440 | udelay(last_transfer->delay_usecs); |
| 441 | |
| 442 | /* Drop chip select UNLESS cs_change is true or we are returning |
| 443 | * a message with an error, or next message is for another chip |
| 444 | */ |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 445 | if (!last_transfer->cs_change) |
Eric Miao | a7bb390 | 2009-04-06 19:00:54 -0700 | [diff] [blame] | 446 | cs_deassert(drv_data); |
Ned Forrester | 8423597 | 2008-09-13 02:33:17 -0700 | [diff] [blame] | 447 | else { |
| 448 | struct spi_message *next_msg; |
| 449 | |
| 450 | /* Holding of cs was hinted, but we need to make sure |
| 451 | * the next message is for the same chip. Don't waste |
| 452 | * time with the following tests unless this was hinted. |
| 453 | * |
| 454 | * We cannot postpone this until pump_messages, because |
| 455 | * after calling msg->complete (below) the driver that |
| 456 | * sent the current message could be unloaded, which |
| 457 | * could invalidate the cs_control() callback... |
| 458 | */ |
| 459 | |
| 460 | /* get a pointer to the next message, if any */ |
Mika Westerberg | 7f86bde | 2013-01-22 12:26:26 +0200 | [diff] [blame] | 461 | next_msg = spi_get_next_queued_message(drv_data->master); |
Ned Forrester | 8423597 | 2008-09-13 02:33:17 -0700 | [diff] [blame] | 462 | |
| 463 | /* see if the next and current messages point |
| 464 | * to the same chip |
| 465 | */ |
| 466 | if (next_msg && next_msg->spi != msg->spi) |
| 467 | next_msg = NULL; |
| 468 | if (!next_msg || msg->state == ERROR_STATE) |
Eric Miao | a7bb390 | 2009-04-06 19:00:54 -0700 | [diff] [blame] | 469 | cs_deassert(drv_data); |
Ned Forrester | 8423597 | 2008-09-13 02:33:17 -0700 | [diff] [blame] | 470 | } |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 471 | |
Mika Westerberg | 7f86bde | 2013-01-22 12:26:26 +0200 | [diff] [blame] | 472 | spi_finalize_current_message(drv_data->master); |
Eric Miao | a7bb390 | 2009-04-06 19:00:54 -0700 | [diff] [blame] | 473 | drv_data->cur_chip = NULL; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 474 | } |
| 475 | |
Sebastian Andrzej Siewior | 579d3bb | 2010-11-22 17:12:17 -0800 | [diff] [blame] | 476 | static void reset_sccr1(struct driver_data *drv_data) |
| 477 | { |
| 478 | void __iomem *reg = drv_data->ioaddr; |
| 479 | struct chip_data *chip = drv_data->cur_chip; |
| 480 | u32 sccr1_reg; |
| 481 | |
| 482 | sccr1_reg = read_SSCR1(reg) & ~drv_data->int_cr1; |
| 483 | sccr1_reg &= ~SSCR1_RFT; |
| 484 | sccr1_reg |= chip->threshold; |
| 485 | write_SSCR1(sccr1_reg, reg); |
| 486 | } |
| 487 | |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 488 | static void int_error_stop(struct driver_data *drv_data, const char* msg) |
| 489 | { |
David Brownell | cf43369 | 2008-04-28 02:14:17 -0700 | [diff] [blame] | 490 | void __iomem *reg = drv_data->ioaddr; |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 491 | |
| 492 | /* Stop and reset SSP */ |
Sebastian Andrzej Siewior | 2a8626a | 2010-11-22 17:12:17 -0800 | [diff] [blame] | 493 | write_SSSR_CS(drv_data, drv_data->clear_sr); |
Sebastian Andrzej Siewior | 579d3bb | 2010-11-22 17:12:17 -0800 | [diff] [blame] | 494 | reset_sccr1(drv_data); |
Sebastian Andrzej Siewior | 2a8626a | 2010-11-22 17:12:17 -0800 | [diff] [blame] | 495 | if (!pxa25x_ssp_comp(drv_data)) |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 496 | write_SSTO(0, reg); |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 497 | pxa2xx_spi_flush(drv_data); |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 498 | write_SSCR0(read_SSCR0(reg) & ~SSCR0_SSE, reg); |
| 499 | |
| 500 | dev_err(&drv_data->pdev->dev, "%s\n", msg); |
| 501 | |
| 502 | drv_data->cur_msg->state = ERROR_STATE; |
| 503 | tasklet_schedule(&drv_data->pump_transfers); |
| 504 | } |
| 505 | |
| 506 | static void int_transfer_complete(struct driver_data *drv_data) |
| 507 | { |
David Brownell | cf43369 | 2008-04-28 02:14:17 -0700 | [diff] [blame] | 508 | void __iomem *reg = drv_data->ioaddr; |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 509 | |
| 510 | /* Stop SSP */ |
Sebastian Andrzej Siewior | 2a8626a | 2010-11-22 17:12:17 -0800 | [diff] [blame] | 511 | write_SSSR_CS(drv_data, drv_data->clear_sr); |
Sebastian Andrzej Siewior | 579d3bb | 2010-11-22 17:12:17 -0800 | [diff] [blame] | 512 | reset_sccr1(drv_data); |
Sebastian Andrzej Siewior | 2a8626a | 2010-11-22 17:12:17 -0800 | [diff] [blame] | 513 | if (!pxa25x_ssp_comp(drv_data)) |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 514 | write_SSTO(0, reg); |
| 515 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 516 | /* Update total byte transferred return count actual bytes read */ |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 517 | drv_data->cur_msg->actual_length += drv_data->len - |
| 518 | (drv_data->rx_end - drv_data->rx); |
| 519 | |
Ned Forrester | 8423597 | 2008-09-13 02:33:17 -0700 | [diff] [blame] | 520 | /* Transfer delays and chip select release are |
| 521 | * handled in pump_transfers or giveback |
| 522 | */ |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 523 | |
| 524 | /* Move to next transfer */ |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 525 | drv_data->cur_msg->state = pxa2xx_spi_next_transfer(drv_data); |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 526 | |
| 527 | /* Schedule transfer tasklet */ |
| 528 | tasklet_schedule(&drv_data->pump_transfers); |
| 529 | } |
| 530 | |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 531 | static irqreturn_t interrupt_transfer(struct driver_data *drv_data) |
| 532 | { |
David Brownell | cf43369 | 2008-04-28 02:14:17 -0700 | [diff] [blame] | 533 | void __iomem *reg = drv_data->ioaddr; |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 534 | |
Stephen Street | 5daa3ba | 2006-05-20 15:00:19 -0700 | [diff] [blame] | 535 | u32 irq_mask = (read_SSCR1(reg) & SSCR1_TIE) ? |
| 536 | drv_data->mask_sr : drv_data->mask_sr & ~SSSR_TFS; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 537 | |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 538 | u32 irq_status = read_SSSR(reg) & irq_mask; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 539 | |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 540 | if (irq_status & SSSR_ROR) { |
| 541 | int_error_stop(drv_data, "interrupt_transfer: fifo overrun"); |
| 542 | return IRQ_HANDLED; |
| 543 | } |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 544 | |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 545 | if (irq_status & SSSR_TINT) { |
| 546 | write_SSSR(SSSR_TINT, reg); |
| 547 | if (drv_data->read(drv_data)) { |
| 548 | int_transfer_complete(drv_data); |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 549 | return IRQ_HANDLED; |
| 550 | } |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 551 | } |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 552 | |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 553 | /* Drain rx fifo, Fill tx fifo and prevent overruns */ |
| 554 | do { |
| 555 | if (drv_data->read(drv_data)) { |
| 556 | int_transfer_complete(drv_data); |
| 557 | return IRQ_HANDLED; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 558 | } |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 559 | } while (drv_data->write(drv_data)); |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 560 | |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 561 | if (drv_data->read(drv_data)) { |
| 562 | int_transfer_complete(drv_data); |
| 563 | return IRQ_HANDLED; |
| 564 | } |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 565 | |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 566 | if (drv_data->tx == drv_data->tx_end) { |
Sebastian Andrzej Siewior | 579d3bb | 2010-11-22 17:12:17 -0800 | [diff] [blame] | 567 | u32 bytes_left; |
| 568 | u32 sccr1_reg; |
| 569 | |
| 570 | sccr1_reg = read_SSCR1(reg); |
| 571 | sccr1_reg &= ~SSCR1_TIE; |
| 572 | |
| 573 | /* |
| 574 | * PXA25x_SSP has no timeout, set up rx threshould for the |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 575 | * remaining RX bytes. |
Sebastian Andrzej Siewior | 579d3bb | 2010-11-22 17:12:17 -0800 | [diff] [blame] | 576 | */ |
Sebastian Andrzej Siewior | 2a8626a | 2010-11-22 17:12:17 -0800 | [diff] [blame] | 577 | if (pxa25x_ssp_comp(drv_data)) { |
Weike Chen | 4fdb242 | 2014-10-08 08:50:22 -0700 | [diff] [blame^] | 578 | u32 rx_thre; |
Sebastian Andrzej Siewior | 579d3bb | 2010-11-22 17:12:17 -0800 | [diff] [blame] | 579 | |
Weike Chen | 4fdb242 | 2014-10-08 08:50:22 -0700 | [diff] [blame^] | 580 | pxa2xx_spi_clear_rx_thre(drv_data, &sccr1_reg); |
Sebastian Andrzej Siewior | 579d3bb | 2010-11-22 17:12:17 -0800 | [diff] [blame] | 581 | |
| 582 | bytes_left = drv_data->rx_end - drv_data->rx; |
| 583 | switch (drv_data->n_bytes) { |
| 584 | case 4: |
| 585 | bytes_left >>= 1; |
| 586 | case 2: |
| 587 | bytes_left >>= 1; |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 588 | } |
Sebastian Andrzej Siewior | 579d3bb | 2010-11-22 17:12:17 -0800 | [diff] [blame] | 589 | |
Weike Chen | 4fdb242 | 2014-10-08 08:50:22 -0700 | [diff] [blame^] | 590 | rx_thre = pxa2xx_spi_get_rx_default_thre(drv_data); |
| 591 | if (rx_thre > bytes_left) |
| 592 | rx_thre = bytes_left; |
Sebastian Andrzej Siewior | 579d3bb | 2010-11-22 17:12:17 -0800 | [diff] [blame] | 593 | |
Weike Chen | 4fdb242 | 2014-10-08 08:50:22 -0700 | [diff] [blame^] | 594 | pxa2xx_spi_set_rx_thre(drv_data, &sccr1_reg, rx_thre); |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 595 | } |
Sebastian Andrzej Siewior | 579d3bb | 2010-11-22 17:12:17 -0800 | [diff] [blame] | 596 | write_SSCR1(sccr1_reg, reg); |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 597 | } |
| 598 | |
Stephen Street | 5daa3ba | 2006-05-20 15:00:19 -0700 | [diff] [blame] | 599 | /* We did something */ |
| 600 | return IRQ_HANDLED; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 601 | } |
| 602 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 603 | static irqreturn_t ssp_int(int irq, void *dev_id) |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 604 | { |
Jeff Garzik | c7bec5a | 2006-10-06 15:00:58 -0400 | [diff] [blame] | 605 | struct driver_data *drv_data = dev_id; |
David Brownell | cf43369 | 2008-04-28 02:14:17 -0700 | [diff] [blame] | 606 | void __iomem *reg = drv_data->ioaddr; |
Mika Westerberg | 7d94a50 | 2013-01-22 12:26:30 +0200 | [diff] [blame] | 607 | u32 sccr1_reg; |
Sebastian Andrzej Siewior | 49cbb1e | 2010-11-22 17:12:14 -0800 | [diff] [blame] | 608 | u32 mask = drv_data->mask_sr; |
| 609 | u32 status; |
| 610 | |
Mika Westerberg | 7d94a50 | 2013-01-22 12:26:30 +0200 | [diff] [blame] | 611 | /* |
| 612 | * The IRQ might be shared with other peripherals so we must first |
| 613 | * check that are we RPM suspended or not. If we are we assume that |
| 614 | * the IRQ was not for us (we shouldn't be RPM suspended when the |
| 615 | * interrupt is enabled). |
| 616 | */ |
| 617 | if (pm_runtime_suspended(&drv_data->pdev->dev)) |
| 618 | return IRQ_NONE; |
| 619 | |
Mika Westerberg | 269e4a4 | 2013-09-04 13:37:43 +0300 | [diff] [blame] | 620 | /* |
| 621 | * If the device is not yet in RPM suspended state and we get an |
| 622 | * interrupt that is meant for another device, check if status bits |
| 623 | * are all set to one. That means that the device is already |
| 624 | * powered off. |
| 625 | */ |
Sebastian Andrzej Siewior | 49cbb1e | 2010-11-22 17:12:14 -0800 | [diff] [blame] | 626 | status = read_SSSR(reg); |
Mika Westerberg | 269e4a4 | 2013-09-04 13:37:43 +0300 | [diff] [blame] | 627 | if (status == ~0) |
| 628 | return IRQ_NONE; |
| 629 | |
| 630 | sccr1_reg = read_SSCR1(reg); |
Sebastian Andrzej Siewior | 49cbb1e | 2010-11-22 17:12:14 -0800 | [diff] [blame] | 631 | |
| 632 | /* Ignore possible writes if we don't need to write */ |
| 633 | if (!(sccr1_reg & SSCR1_TIE)) |
| 634 | mask &= ~SSSR_TFS; |
| 635 | |
| 636 | if (!(status & mask)) |
| 637 | return IRQ_NONE; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 638 | |
| 639 | if (!drv_data->cur_msg) { |
Stephen Street | 5daa3ba | 2006-05-20 15:00:19 -0700 | [diff] [blame] | 640 | |
| 641 | write_SSCR0(read_SSCR0(reg) & ~SSCR0_SSE, reg); |
| 642 | write_SSCR1(read_SSCR1(reg) & ~drv_data->int_cr1, reg); |
Sebastian Andrzej Siewior | 2a8626a | 2010-11-22 17:12:17 -0800 | [diff] [blame] | 643 | if (!pxa25x_ssp_comp(drv_data)) |
Stephen Street | 5daa3ba | 2006-05-20 15:00:19 -0700 | [diff] [blame] | 644 | write_SSTO(0, reg); |
Sebastian Andrzej Siewior | 2a8626a | 2010-11-22 17:12:17 -0800 | [diff] [blame] | 645 | write_SSSR_CS(drv_data, drv_data->clear_sr); |
Stephen Street | 5daa3ba | 2006-05-20 15:00:19 -0700 | [diff] [blame] | 646 | |
Jarkko Nikula | f6bd03a | 2013-10-11 13:54:00 +0300 | [diff] [blame] | 647 | dev_err(&drv_data->pdev->dev, |
| 648 | "bad message state in interrupt handler\n"); |
Stephen Street | 5daa3ba | 2006-05-20 15:00:19 -0700 | [diff] [blame] | 649 | |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 650 | /* Never fail */ |
| 651 | return IRQ_HANDLED; |
| 652 | } |
| 653 | |
| 654 | return drv_data->transfer_handler(drv_data); |
| 655 | } |
| 656 | |
Mika Westerberg | 3343b7a | 2013-01-22 12:26:27 +0200 | [diff] [blame] | 657 | static unsigned int ssp_get_clk_div(struct driver_data *drv_data, int rate) |
eric miao | 2f1a74e | 2007-11-21 18:50:53 +0800 | [diff] [blame] | 658 | { |
Mika Westerberg | 3343b7a | 2013-01-22 12:26:27 +0200 | [diff] [blame] | 659 | unsigned long ssp_clk = drv_data->max_clk_rate; |
| 660 | const struct ssp_device *ssp = drv_data->ssp; |
| 661 | |
| 662 | rate = min_t(int, ssp_clk, rate); |
eric miao | 2f1a74e | 2007-11-21 18:50:53 +0800 | [diff] [blame] | 663 | |
Sebastian Andrzej Siewior | 2a8626a | 2010-11-22 17:12:17 -0800 | [diff] [blame] | 664 | if (ssp->type == PXA25x_SSP || ssp->type == CE4100_SSP) |
eric miao | 2f1a74e | 2007-11-21 18:50:53 +0800 | [diff] [blame] | 665 | return ((ssp_clk / (2 * rate) - 1) & 0xff) << 8; |
| 666 | else |
| 667 | return ((ssp_clk / rate - 1) & 0xfff) << 8; |
| 668 | } |
| 669 | |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 670 | static void pump_transfers(unsigned long data) |
| 671 | { |
| 672 | struct driver_data *drv_data = (struct driver_data *)data; |
| 673 | struct spi_message *message = NULL; |
| 674 | struct spi_transfer *transfer = NULL; |
| 675 | struct spi_transfer *previous = NULL; |
| 676 | struct chip_data *chip = NULL; |
David Brownell | cf43369 | 2008-04-28 02:14:17 -0700 | [diff] [blame] | 677 | void __iomem *reg = drv_data->ioaddr; |
Stephen Street | 9708c12 | 2006-03-28 14:05:23 -0800 | [diff] [blame] | 678 | u32 clk_div = 0; |
| 679 | u8 bits = 0; |
| 680 | u32 speed = 0; |
| 681 | u32 cr0; |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 682 | u32 cr1; |
| 683 | u32 dma_thresh = drv_data->cur_chip->dma_threshold; |
| 684 | u32 dma_burst = drv_data->cur_chip->dma_burst_size; |
Weike Chen | 4fdb242 | 2014-10-08 08:50:22 -0700 | [diff] [blame^] | 685 | u32 change_mask = pxa2xx_spi_get_ssrc1_change_mask(drv_data); |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 686 | |
| 687 | /* Get current state information */ |
| 688 | message = drv_data->cur_msg; |
| 689 | transfer = drv_data->cur_transfer; |
| 690 | chip = drv_data->cur_chip; |
| 691 | |
| 692 | /* Handle for abort */ |
| 693 | if (message->state == ERROR_STATE) { |
| 694 | message->status = -EIO; |
Stephen Street | 5daa3ba | 2006-05-20 15:00:19 -0700 | [diff] [blame] | 695 | giveback(drv_data); |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 696 | return; |
| 697 | } |
| 698 | |
| 699 | /* Handle end of message */ |
| 700 | if (message->state == DONE_STATE) { |
| 701 | message->status = 0; |
Stephen Street | 5daa3ba | 2006-05-20 15:00:19 -0700 | [diff] [blame] | 702 | giveback(drv_data); |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 703 | return; |
| 704 | } |
| 705 | |
Ned Forrester | 8423597 | 2008-09-13 02:33:17 -0700 | [diff] [blame] | 706 | /* Delay if requested at end of transfer before CS change */ |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 707 | if (message->state == RUNNING_STATE) { |
| 708 | previous = list_entry(transfer->transfer_list.prev, |
| 709 | struct spi_transfer, |
| 710 | transfer_list); |
| 711 | if (previous->delay_usecs) |
| 712 | udelay(previous->delay_usecs); |
Ned Forrester | 8423597 | 2008-09-13 02:33:17 -0700 | [diff] [blame] | 713 | |
| 714 | /* Drop chip select only if cs_change is requested */ |
| 715 | if (previous->cs_change) |
Eric Miao | a7bb390 | 2009-04-06 19:00:54 -0700 | [diff] [blame] | 716 | cs_deassert(drv_data); |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 717 | } |
| 718 | |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 719 | /* Check if we can DMA this transfer */ |
| 720 | if (!pxa2xx_spi_dma_is_possible(transfer->len) && chip->enable_dma) { |
Ned Forrester | 7e96445 | 2008-09-13 02:33:18 -0700 | [diff] [blame] | 721 | |
| 722 | /* reject already-mapped transfers; PIO won't always work */ |
| 723 | if (message->is_dma_mapped |
| 724 | || transfer->rx_dma || transfer->tx_dma) { |
| 725 | dev_err(&drv_data->pdev->dev, |
Jarkko Nikula | f6bd03a | 2013-10-11 13:54:00 +0300 | [diff] [blame] | 726 | "pump_transfers: mapped transfer length of " |
| 727 | "%u is greater than %d\n", |
Ned Forrester | 7e96445 | 2008-09-13 02:33:18 -0700 | [diff] [blame] | 728 | transfer->len, MAX_DMA_LEN); |
| 729 | message->status = -EINVAL; |
| 730 | giveback(drv_data); |
| 731 | return; |
| 732 | } |
| 733 | |
| 734 | /* warn ... we force this to PIO mode */ |
Jarkko Nikula | f6bd03a | 2013-10-11 13:54:00 +0300 | [diff] [blame] | 735 | dev_warn_ratelimited(&message->spi->dev, |
| 736 | "pump_transfers: DMA disabled for transfer length %ld " |
| 737 | "greater than %d\n", |
| 738 | (long)drv_data->len, MAX_DMA_LEN); |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 739 | } |
| 740 | |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 741 | /* Setup the transfer state based on the type of transfer */ |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 742 | if (pxa2xx_spi_flush(drv_data) == 0) { |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 743 | dev_err(&drv_data->pdev->dev, "pump_transfers: flush failed\n"); |
| 744 | message->status = -EIO; |
Stephen Street | 5daa3ba | 2006-05-20 15:00:19 -0700 | [diff] [blame] | 745 | giveback(drv_data); |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 746 | return; |
| 747 | } |
Stephen Street | 9708c12 | 2006-03-28 14:05:23 -0800 | [diff] [blame] | 748 | drv_data->n_bytes = chip->n_bytes; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 749 | drv_data->tx = (void *)transfer->tx_buf; |
| 750 | drv_data->tx_end = drv_data->tx + transfer->len; |
| 751 | drv_data->rx = transfer->rx_buf; |
| 752 | drv_data->rx_end = drv_data->rx + transfer->len; |
| 753 | drv_data->rx_dma = transfer->rx_dma; |
| 754 | drv_data->tx_dma = transfer->tx_dma; |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 755 | drv_data->len = transfer->len; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 756 | drv_data->write = drv_data->tx ? chip->write : null_writer; |
| 757 | drv_data->read = drv_data->rx ? chip->read : null_reader; |
Stephen Street | 9708c12 | 2006-03-28 14:05:23 -0800 | [diff] [blame] | 758 | |
| 759 | /* Change speed and bit per word on a per transfer */ |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 760 | cr0 = chip->cr0; |
Stephen Street | 9708c12 | 2006-03-28 14:05:23 -0800 | [diff] [blame] | 761 | if (transfer->speed_hz || transfer->bits_per_word) { |
| 762 | |
Stephen Street | 9708c12 | 2006-03-28 14:05:23 -0800 | [diff] [blame] | 763 | bits = chip->bits_per_word; |
| 764 | speed = chip->speed_hz; |
| 765 | |
| 766 | if (transfer->speed_hz) |
| 767 | speed = transfer->speed_hz; |
| 768 | |
| 769 | if (transfer->bits_per_word) |
| 770 | bits = transfer->bits_per_word; |
| 771 | |
Mika Westerberg | 3343b7a | 2013-01-22 12:26:27 +0200 | [diff] [blame] | 772 | clk_div = ssp_get_clk_div(drv_data, speed); |
Stephen Street | 9708c12 | 2006-03-28 14:05:23 -0800 | [diff] [blame] | 773 | |
| 774 | if (bits <= 8) { |
| 775 | drv_data->n_bytes = 1; |
Stephen Street | 9708c12 | 2006-03-28 14:05:23 -0800 | [diff] [blame] | 776 | drv_data->read = drv_data->read != null_reader ? |
| 777 | u8_reader : null_reader; |
| 778 | drv_data->write = drv_data->write != null_writer ? |
| 779 | u8_writer : null_writer; |
| 780 | } else if (bits <= 16) { |
| 781 | drv_data->n_bytes = 2; |
Stephen Street | 9708c12 | 2006-03-28 14:05:23 -0800 | [diff] [blame] | 782 | drv_data->read = drv_data->read != null_reader ? |
| 783 | u16_reader : null_reader; |
| 784 | drv_data->write = drv_data->write != null_writer ? |
| 785 | u16_writer : null_writer; |
| 786 | } else if (bits <= 32) { |
| 787 | drv_data->n_bytes = 4; |
Stephen Street | 9708c12 | 2006-03-28 14:05:23 -0800 | [diff] [blame] | 788 | drv_data->read = drv_data->read != null_reader ? |
| 789 | u32_reader : null_reader; |
| 790 | drv_data->write = drv_data->write != null_writer ? |
| 791 | u32_writer : null_writer; |
| 792 | } |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 793 | /* if bits/word is changed in dma mode, then must check the |
| 794 | * thresholds and burst also */ |
| 795 | if (chip->enable_dma) { |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 796 | if (pxa2xx_spi_set_dma_burst_and_threshold(chip, |
| 797 | message->spi, |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 798 | bits, &dma_burst, |
| 799 | &dma_thresh)) |
Jarkko Nikula | f6bd03a | 2013-10-11 13:54:00 +0300 | [diff] [blame] | 800 | dev_warn_ratelimited(&message->spi->dev, |
| 801 | "pump_transfers: DMA burst size reduced to match bits_per_word\n"); |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 802 | } |
Stephen Street | 9708c12 | 2006-03-28 14:05:23 -0800 | [diff] [blame] | 803 | |
Weike Chen | 4fdb242 | 2014-10-08 08:50:22 -0700 | [diff] [blame^] | 804 | cr0 = pxa2xx_configure_sscr0(drv_data, clk_div, bits); |
Stephen Street | 9708c12 | 2006-03-28 14:05:23 -0800 | [diff] [blame] | 805 | } |
| 806 | |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 807 | message->state = RUNNING_STATE; |
| 808 | |
Ned Forrester | 7e96445 | 2008-09-13 02:33:18 -0700 | [diff] [blame] | 809 | drv_data->dma_mapped = 0; |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 810 | if (pxa2xx_spi_dma_is_possible(drv_data->len)) |
| 811 | drv_data->dma_mapped = pxa2xx_spi_map_dma_buffers(drv_data); |
Ned Forrester | 7e96445 | 2008-09-13 02:33:18 -0700 | [diff] [blame] | 812 | if (drv_data->dma_mapped) { |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 813 | |
| 814 | /* Ensure we have the correct interrupt handler */ |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 815 | drv_data->transfer_handler = pxa2xx_spi_dma_transfer; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 816 | |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 817 | pxa2xx_spi_dma_prepare(drv_data, dma_burst); |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 818 | |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 819 | /* Clear status and start DMA engine */ |
| 820 | cr1 = chip->cr1 | dma_thresh | drv_data->dma_cr1; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 821 | write_SSSR(drv_data->clear_sr, reg); |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 822 | |
| 823 | pxa2xx_spi_dma_start(drv_data); |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 824 | } else { |
| 825 | /* Ensure we have the correct interrupt handler */ |
| 826 | drv_data->transfer_handler = interrupt_transfer; |
| 827 | |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 828 | /* Clear status */ |
| 829 | cr1 = chip->cr1 | chip->threshold | drv_data->int_cr1; |
Sebastian Andrzej Siewior | 2a8626a | 2010-11-22 17:12:17 -0800 | [diff] [blame] | 830 | write_SSSR_CS(drv_data, drv_data->clear_sr); |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 831 | } |
| 832 | |
Mika Westerberg | a0d2642 | 2013-01-22 12:26:32 +0200 | [diff] [blame] | 833 | if (is_lpss_ssp(drv_data)) { |
| 834 | if ((read_SSIRF(reg) & 0xff) != chip->lpss_rx_threshold) |
| 835 | write_SSIRF(chip->lpss_rx_threshold, reg); |
| 836 | if ((read_SSITF(reg) & 0xffff) != chip->lpss_tx_threshold) |
| 837 | write_SSITF(chip->lpss_tx_threshold, reg); |
| 838 | } |
| 839 | |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 840 | /* see if we need to reload the config registers */ |
Weike Chen | 4fdb242 | 2014-10-08 08:50:22 -0700 | [diff] [blame^] | 841 | if ((read_SSCR0(reg) != cr0) || |
| 842 | (read_SSCR1(reg) & change_mask) != (cr1 & change_mask)) { |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 843 | |
Ned Forrester | b97c74b | 2008-02-23 15:23:40 -0800 | [diff] [blame] | 844 | /* stop the SSP, and update the other bits */ |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 845 | write_SSCR0(cr0 & ~SSCR0_SSE, reg); |
Sebastian Andrzej Siewior | 2a8626a | 2010-11-22 17:12:17 -0800 | [diff] [blame] | 846 | if (!pxa25x_ssp_comp(drv_data)) |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 847 | write_SSTO(chip->timeout, reg); |
Ned Forrester | b97c74b | 2008-02-23 15:23:40 -0800 | [diff] [blame] | 848 | /* first set CR1 without interrupt and service enables */ |
Weike Chen | 4fdb242 | 2014-10-08 08:50:22 -0700 | [diff] [blame^] | 849 | write_SSCR1(cr1 & change_mask, reg); |
Ned Forrester | b97c74b | 2008-02-23 15:23:40 -0800 | [diff] [blame] | 850 | /* restart the SSP */ |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 851 | write_SSCR0(cr0, reg); |
Ned Forrester | b97c74b | 2008-02-23 15:23:40 -0800 | [diff] [blame] | 852 | |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 853 | } else { |
Sebastian Andrzej Siewior | 2a8626a | 2010-11-22 17:12:17 -0800 | [diff] [blame] | 854 | if (!pxa25x_ssp_comp(drv_data)) |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 855 | write_SSTO(chip->timeout, reg); |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 856 | } |
Ned Forrester | b97c74b | 2008-02-23 15:23:40 -0800 | [diff] [blame] | 857 | |
Eric Miao | a7bb390 | 2009-04-06 19:00:54 -0700 | [diff] [blame] | 858 | cs_assert(drv_data); |
Ned Forrester | b97c74b | 2008-02-23 15:23:40 -0800 | [diff] [blame] | 859 | |
| 860 | /* after chip select, release the data by enabling service |
| 861 | * requests and interrupts, without changing any mode bits */ |
| 862 | write_SSCR1(cr1, reg); |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 863 | } |
| 864 | |
Mika Westerberg | 7f86bde | 2013-01-22 12:26:26 +0200 | [diff] [blame] | 865 | static int pxa2xx_spi_transfer_one_message(struct spi_master *master, |
| 866 | struct spi_message *msg) |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 867 | { |
Mika Westerberg | 7f86bde | 2013-01-22 12:26:26 +0200 | [diff] [blame] | 868 | struct driver_data *drv_data = spi_master_get_devdata(master); |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 869 | |
Mika Westerberg | 7f86bde | 2013-01-22 12:26:26 +0200 | [diff] [blame] | 870 | drv_data->cur_msg = msg; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 871 | /* Initial message state*/ |
| 872 | drv_data->cur_msg->state = START_STATE; |
| 873 | drv_data->cur_transfer = list_entry(drv_data->cur_msg->transfers.next, |
| 874 | struct spi_transfer, |
| 875 | transfer_list); |
| 876 | |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 877 | /* prepare to setup the SSP, in pump_transfers, using the per |
| 878 | * chip configuration */ |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 879 | drv_data->cur_chip = spi_get_ctldata(drv_data->cur_msg->spi); |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 880 | |
| 881 | /* Mark as busy and launch transfers */ |
| 882 | tasklet_schedule(&drv_data->pump_transfers); |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 883 | return 0; |
| 884 | } |
| 885 | |
Mika Westerberg | 7d94a50 | 2013-01-22 12:26:30 +0200 | [diff] [blame] | 886 | static int pxa2xx_spi_unprepare_transfer(struct spi_master *master) |
| 887 | { |
| 888 | struct driver_data *drv_data = spi_master_get_devdata(master); |
| 889 | |
| 890 | /* Disable the SSP now */ |
| 891 | write_SSCR0(read_SSCR0(drv_data->ioaddr) & ~SSCR0_SSE, |
| 892 | drv_data->ioaddr); |
| 893 | |
Mika Westerberg | 7d94a50 | 2013-01-22 12:26:30 +0200 | [diff] [blame] | 894 | return 0; |
| 895 | } |
| 896 | |
Eric Miao | a7bb390 | 2009-04-06 19:00:54 -0700 | [diff] [blame] | 897 | static int setup_cs(struct spi_device *spi, struct chip_data *chip, |
| 898 | struct pxa2xx_spi_chip *chip_info) |
| 899 | { |
| 900 | int err = 0; |
| 901 | |
| 902 | if (chip == NULL || chip_info == NULL) |
| 903 | return 0; |
| 904 | |
| 905 | /* NOTE: setup() can be called multiple times, possibly with |
| 906 | * different chip_info, release previously requested GPIO |
| 907 | */ |
| 908 | if (gpio_is_valid(chip->gpio_cs)) |
| 909 | gpio_free(chip->gpio_cs); |
| 910 | |
| 911 | /* If (*cs_control) is provided, ignore GPIO chip select */ |
| 912 | if (chip_info->cs_control) { |
| 913 | chip->cs_control = chip_info->cs_control; |
| 914 | return 0; |
| 915 | } |
| 916 | |
| 917 | if (gpio_is_valid(chip_info->gpio_cs)) { |
| 918 | err = gpio_request(chip_info->gpio_cs, "SPI_CS"); |
| 919 | if (err) { |
Jarkko Nikula | f6bd03a | 2013-10-11 13:54:00 +0300 | [diff] [blame] | 920 | dev_err(&spi->dev, "failed to request chip select GPIO%d\n", |
| 921 | chip_info->gpio_cs); |
Eric Miao | a7bb390 | 2009-04-06 19:00:54 -0700 | [diff] [blame] | 922 | return err; |
| 923 | } |
| 924 | |
| 925 | chip->gpio_cs = chip_info->gpio_cs; |
| 926 | chip->gpio_cs_inverted = spi->mode & SPI_CS_HIGH; |
| 927 | |
| 928 | err = gpio_direction_output(chip->gpio_cs, |
| 929 | !chip->gpio_cs_inverted); |
| 930 | } |
| 931 | |
| 932 | return err; |
| 933 | } |
| 934 | |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 935 | static int setup(struct spi_device *spi) |
| 936 | { |
| 937 | struct pxa2xx_spi_chip *chip_info = NULL; |
| 938 | struct chip_data *chip; |
| 939 | struct driver_data *drv_data = spi_master_get_devdata(spi->master); |
| 940 | unsigned int clk_div; |
Mika Westerberg | a0d2642 | 2013-01-22 12:26:32 +0200 | [diff] [blame] | 941 | uint tx_thres, tx_hi_thres, rx_thres; |
| 942 | |
| 943 | if (is_lpss_ssp(drv_data)) { |
| 944 | tx_thres = LPSS_TX_LOTHRESH_DFLT; |
| 945 | tx_hi_thres = LPSS_TX_HITHRESH_DFLT; |
| 946 | rx_thres = LPSS_RX_THRESH_DFLT; |
| 947 | } else { |
| 948 | tx_thres = TX_THRESH_DFLT; |
| 949 | tx_hi_thres = 0; |
| 950 | rx_thres = RX_THRESH_DFLT; |
| 951 | } |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 952 | |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 953 | /* Only alloc on first setup */ |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 954 | chip = spi_get_ctldata(spi); |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 955 | if (!chip) { |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 956 | chip = kzalloc(sizeof(struct chip_data), GFP_KERNEL); |
Jingoo Han | 9deae45 | 2014-04-29 17:19:38 +0900 | [diff] [blame] | 957 | if (!chip) |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 958 | return -ENOMEM; |
| 959 | |
Sebastian Andrzej Siewior | 2a8626a | 2010-11-22 17:12:17 -0800 | [diff] [blame] | 960 | if (drv_data->ssp_type == CE4100_SSP) { |
| 961 | if (spi->chip_select > 4) { |
Jarkko Nikula | f6bd03a | 2013-10-11 13:54:00 +0300 | [diff] [blame] | 962 | dev_err(&spi->dev, |
| 963 | "failed setup: cs number must not be > 4.\n"); |
Sebastian Andrzej Siewior | 2a8626a | 2010-11-22 17:12:17 -0800 | [diff] [blame] | 964 | kfree(chip); |
| 965 | return -EINVAL; |
| 966 | } |
| 967 | |
| 968 | chip->frm = spi->chip_select; |
| 969 | } else |
| 970 | chip->gpio_cs = -1; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 971 | chip->enable_dma = 0; |
Vernon Sauder | f1f640a | 2008-10-15 22:02:43 -0700 | [diff] [blame] | 972 | chip->timeout = TIMOUT_DFLT; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 973 | } |
| 974 | |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 975 | /* protocol drivers may change the chip settings, so... |
| 976 | * if chip_info exists, use it */ |
| 977 | chip_info = spi->controller_data; |
| 978 | |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 979 | /* chip_info isn't always needed */ |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 980 | chip->cr1 = 0; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 981 | if (chip_info) { |
Vernon Sauder | f1f640a | 2008-10-15 22:02:43 -0700 | [diff] [blame] | 982 | if (chip_info->timeout) |
| 983 | chip->timeout = chip_info->timeout; |
| 984 | if (chip_info->tx_threshold) |
| 985 | tx_thres = chip_info->tx_threshold; |
Mika Westerberg | a0d2642 | 2013-01-22 12:26:32 +0200 | [diff] [blame] | 986 | if (chip_info->tx_hi_threshold) |
| 987 | tx_hi_thres = chip_info->tx_hi_threshold; |
Vernon Sauder | f1f640a | 2008-10-15 22:02:43 -0700 | [diff] [blame] | 988 | if (chip_info->rx_threshold) |
| 989 | rx_thres = chip_info->rx_threshold; |
| 990 | chip->enable_dma = drv_data->master_info->enable_dma; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 991 | chip->dma_threshold = 0; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 992 | if (chip_info->enable_loopback) |
| 993 | chip->cr1 = SSCR1_LBM; |
Mika Westerberg | a349685 | 2013-01-22 12:26:33 +0200 | [diff] [blame] | 994 | } else if (ACPI_HANDLE(&spi->dev)) { |
| 995 | /* |
| 996 | * Slave devices enumerated from ACPI namespace don't |
| 997 | * usually have chip_info but we still might want to use |
| 998 | * DMA with them. |
| 999 | */ |
| 1000 | chip->enable_dma = drv_data->master_info->enable_dma; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1001 | } |
| 1002 | |
Vernon Sauder | f1f640a | 2008-10-15 22:02:43 -0700 | [diff] [blame] | 1003 | chip->threshold = (SSCR1_RxTresh(rx_thres) & SSCR1_RFT) | |
| 1004 | (SSCR1_TxTresh(tx_thres) & SSCR1_TFT); |
| 1005 | |
Mika Westerberg | a0d2642 | 2013-01-22 12:26:32 +0200 | [diff] [blame] | 1006 | chip->lpss_rx_threshold = SSIRF_RxThresh(rx_thres); |
| 1007 | chip->lpss_tx_threshold = SSITF_TxLoThresh(tx_thres) |
| 1008 | | SSITF_TxHiThresh(tx_hi_thres); |
| 1009 | |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 1010 | /* set dma burst and threshold outside of chip_info path so that if |
| 1011 | * chip_info goes away after setting chip->enable_dma, the |
| 1012 | * burst and threshold can still respond to changes in bits_per_word */ |
| 1013 | if (chip->enable_dma) { |
| 1014 | /* set up legal burst and threshold for dma */ |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 1015 | if (pxa2xx_spi_set_dma_burst_and_threshold(chip, spi, |
| 1016 | spi->bits_per_word, |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 1017 | &chip->dma_burst_size, |
| 1018 | &chip->dma_threshold)) { |
Jarkko Nikula | f6bd03a | 2013-10-11 13:54:00 +0300 | [diff] [blame] | 1019 | dev_warn(&spi->dev, |
| 1020 | "in setup: DMA burst size reduced to match bits_per_word\n"); |
Stephen Street | 8d94cc5 | 2006-12-10 02:18:54 -0800 | [diff] [blame] | 1021 | } |
| 1022 | } |
| 1023 | |
Mika Westerberg | 3343b7a | 2013-01-22 12:26:27 +0200 | [diff] [blame] | 1024 | clk_div = ssp_get_clk_div(drv_data, spi->max_speed_hz); |
Stephen Street | 9708c12 | 2006-03-28 14:05:23 -0800 | [diff] [blame] | 1025 | chip->speed_hz = spi->max_speed_hz; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1026 | |
Weike Chen | 4fdb242 | 2014-10-08 08:50:22 -0700 | [diff] [blame^] | 1027 | chip->cr0 = pxa2xx_configure_sscr0(drv_data, clk_div, |
| 1028 | spi->bits_per_word); |
Justin Clacherty | 7f6ee1a | 2007-01-26 00:56:44 -0800 | [diff] [blame] | 1029 | chip->cr1 &= ~(SSCR1_SPO | SSCR1_SPH); |
| 1030 | chip->cr1 |= (((spi->mode & SPI_CPHA) != 0) ? SSCR1_SPH : 0) |
| 1031 | | (((spi->mode & SPI_CPOL) != 0) ? SSCR1_SPO : 0); |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1032 | |
Mika Westerberg | b833172 | 2013-01-22 12:26:31 +0200 | [diff] [blame] | 1033 | if (spi->mode & SPI_LOOP) |
| 1034 | chip->cr1 |= SSCR1_LBM; |
| 1035 | |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1036 | /* NOTE: PXA25x_SSP _could_ use external clocking ... */ |
Sebastian Andrzej Siewior | 2a8626a | 2010-11-22 17:12:17 -0800 | [diff] [blame] | 1037 | if (!pxa25x_ssp_comp(drv_data)) |
David Brownell | 7d07719 | 2009-06-17 16:26:03 -0700 | [diff] [blame] | 1038 | dev_dbg(&spi->dev, "%ld Hz actual, %s\n", |
Mika Westerberg | 3343b7a | 2013-01-22 12:26:27 +0200 | [diff] [blame] | 1039 | drv_data->max_clk_rate |
Eric Miao | c9840da | 2010-03-16 16:48:01 +0800 | [diff] [blame] | 1040 | / (1 + ((chip->cr0 & SSCR0_SCR(0xfff)) >> 8)), |
| 1041 | chip->enable_dma ? "DMA" : "PIO"); |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1042 | else |
David Brownell | 7d07719 | 2009-06-17 16:26:03 -0700 | [diff] [blame] | 1043 | dev_dbg(&spi->dev, "%ld Hz actual, %s\n", |
Mika Westerberg | 3343b7a | 2013-01-22 12:26:27 +0200 | [diff] [blame] | 1044 | drv_data->max_clk_rate / 2 |
Eric Miao | c9840da | 2010-03-16 16:48:01 +0800 | [diff] [blame] | 1045 | / (1 + ((chip->cr0 & SSCR0_SCR(0x0ff)) >> 8)), |
| 1046 | chip->enable_dma ? "DMA" : "PIO"); |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1047 | |
| 1048 | if (spi->bits_per_word <= 8) { |
| 1049 | chip->n_bytes = 1; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1050 | chip->read = u8_reader; |
| 1051 | chip->write = u8_writer; |
| 1052 | } else if (spi->bits_per_word <= 16) { |
| 1053 | chip->n_bytes = 2; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1054 | chip->read = u16_reader; |
| 1055 | chip->write = u16_writer; |
| 1056 | } else if (spi->bits_per_word <= 32) { |
| 1057 | chip->cr0 |= SSCR0_EDSS; |
| 1058 | chip->n_bytes = 4; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1059 | chip->read = u32_reader; |
| 1060 | chip->write = u32_writer; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1061 | } |
Stephen Street | 9708c12 | 2006-03-28 14:05:23 -0800 | [diff] [blame] | 1062 | chip->bits_per_word = spi->bits_per_word; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1063 | |
| 1064 | spi_set_ctldata(spi, chip); |
| 1065 | |
Sebastian Andrzej Siewior | 2a8626a | 2010-11-22 17:12:17 -0800 | [diff] [blame] | 1066 | if (drv_data->ssp_type == CE4100_SSP) |
| 1067 | return 0; |
| 1068 | |
Eric Miao | a7bb390 | 2009-04-06 19:00:54 -0700 | [diff] [blame] | 1069 | return setup_cs(spi, chip, chip_info); |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1070 | } |
| 1071 | |
Hans-Peter Nilsson | 0ffa028 | 2007-02-12 00:52:45 -0800 | [diff] [blame] | 1072 | static void cleanup(struct spi_device *spi) |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1073 | { |
Hans-Peter Nilsson | 0ffa028 | 2007-02-12 00:52:45 -0800 | [diff] [blame] | 1074 | struct chip_data *chip = spi_get_ctldata(spi); |
Sebastian Andrzej Siewior | 2a8626a | 2010-11-22 17:12:17 -0800 | [diff] [blame] | 1075 | struct driver_data *drv_data = spi_master_get_devdata(spi->master); |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1076 | |
Daniel Ribeiro | 7348d82 | 2009-05-12 13:19:36 -0700 | [diff] [blame] | 1077 | if (!chip) |
| 1078 | return; |
| 1079 | |
Sebastian Andrzej Siewior | 2a8626a | 2010-11-22 17:12:17 -0800 | [diff] [blame] | 1080 | if (drv_data->ssp_type != CE4100_SSP && gpio_is_valid(chip->gpio_cs)) |
Eric Miao | a7bb390 | 2009-04-06 19:00:54 -0700 | [diff] [blame] | 1081 | gpio_free(chip->gpio_cs); |
| 1082 | |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1083 | kfree(chip); |
| 1084 | } |
| 1085 | |
Mika Westerberg | a349685 | 2013-01-22 12:26:33 +0200 | [diff] [blame] | 1086 | #ifdef CONFIG_ACPI |
Mika Westerberg | a349685 | 2013-01-22 12:26:33 +0200 | [diff] [blame] | 1087 | static struct pxa2xx_spi_master * |
| 1088 | pxa2xx_spi_acpi_get_pdata(struct platform_device *pdev) |
| 1089 | { |
| 1090 | struct pxa2xx_spi_master *pdata; |
Mika Westerberg | a349685 | 2013-01-22 12:26:33 +0200 | [diff] [blame] | 1091 | struct acpi_device *adev; |
| 1092 | struct ssp_device *ssp; |
| 1093 | struct resource *res; |
| 1094 | int devid; |
| 1095 | |
| 1096 | if (!ACPI_HANDLE(&pdev->dev) || |
| 1097 | acpi_bus_get_device(ACPI_HANDLE(&pdev->dev), &adev)) |
| 1098 | return NULL; |
| 1099 | |
Mika Westerberg | cc0ee98 | 2013-06-20 17:44:22 +0300 | [diff] [blame] | 1100 | pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); |
Jingoo Han | 9deae45 | 2014-04-29 17:19:38 +0900 | [diff] [blame] | 1101 | if (!pdata) |
Mika Westerberg | a349685 | 2013-01-22 12:26:33 +0200 | [diff] [blame] | 1102 | return NULL; |
Mika Westerberg | a349685 | 2013-01-22 12:26:33 +0200 | [diff] [blame] | 1103 | |
| 1104 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1105 | if (!res) |
| 1106 | return NULL; |
| 1107 | |
| 1108 | ssp = &pdata->ssp; |
| 1109 | |
| 1110 | ssp->phys_base = res->start; |
Sachin Kamat | cbfd6a2 | 2013-04-08 15:49:33 +0530 | [diff] [blame] | 1111 | ssp->mmio_base = devm_ioremap_resource(&pdev->dev, res); |
| 1112 | if (IS_ERR(ssp->mmio_base)) |
Mika Westerberg | 6dc81f6 | 2013-05-13 13:45:09 +0300 | [diff] [blame] | 1113 | return NULL; |
Mika Westerberg | a349685 | 2013-01-22 12:26:33 +0200 | [diff] [blame] | 1114 | |
| 1115 | ssp->clk = devm_clk_get(&pdev->dev, NULL); |
| 1116 | ssp->irq = platform_get_irq(pdev, 0); |
| 1117 | ssp->type = LPSS_SSP; |
| 1118 | ssp->pdev = pdev; |
| 1119 | |
| 1120 | ssp->port_id = -1; |
| 1121 | if (adev->pnp.unique_id && !kstrtoint(adev->pnp.unique_id, 0, &devid)) |
| 1122 | ssp->port_id = devid; |
| 1123 | |
| 1124 | pdata->num_chipselect = 1; |
Mika Westerberg | cddb339 | 2013-05-13 13:45:10 +0300 | [diff] [blame] | 1125 | pdata->enable_dma = true; |
Mika Westerberg | a349685 | 2013-01-22 12:26:33 +0200 | [diff] [blame] | 1126 | |
| 1127 | return pdata; |
| 1128 | } |
| 1129 | |
| 1130 | static struct acpi_device_id pxa2xx_spi_acpi_match[] = { |
| 1131 | { "INT33C0", 0 }, |
| 1132 | { "INT33C1", 0 }, |
Mika Westerberg | 54acbd9 | 2013-11-12 12:06:21 +0200 | [diff] [blame] | 1133 | { "INT3430", 0 }, |
| 1134 | { "INT3431", 0 }, |
Mika Westerberg | 4b30f2a | 2013-05-13 13:45:11 +0300 | [diff] [blame] | 1135 | { "80860F0E", 0 }, |
Alan Cox | aca2636 | 2014-08-20 13:57:26 +0300 | [diff] [blame] | 1136 | { "8086228E", 0 }, |
Mika Westerberg | a349685 | 2013-01-22 12:26:33 +0200 | [diff] [blame] | 1137 | { }, |
| 1138 | }; |
| 1139 | MODULE_DEVICE_TABLE(acpi, pxa2xx_spi_acpi_match); |
| 1140 | #else |
| 1141 | static inline struct pxa2xx_spi_master * |
| 1142 | pxa2xx_spi_acpi_get_pdata(struct platform_device *pdev) |
| 1143 | { |
| 1144 | return NULL; |
| 1145 | } |
| 1146 | #endif |
| 1147 | |
Grant Likely | fd4a319 | 2012-12-07 16:57:14 +0000 | [diff] [blame] | 1148 | static int pxa2xx_spi_probe(struct platform_device *pdev) |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1149 | { |
| 1150 | struct device *dev = &pdev->dev; |
| 1151 | struct pxa2xx_spi_master *platform_info; |
| 1152 | struct spi_master *master; |
Guennadi Liakhovetski | 65a00a2 | 2008-10-15 22:02:42 -0700 | [diff] [blame] | 1153 | struct driver_data *drv_data; |
eric miao | 2f1a74e | 2007-11-21 18:50:53 +0800 | [diff] [blame] | 1154 | struct ssp_device *ssp; |
Guennadi Liakhovetski | 65a00a2 | 2008-10-15 22:02:42 -0700 | [diff] [blame] | 1155 | int status; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1156 | |
Mika Westerberg | 851bacf | 2013-01-07 12:44:33 +0200 | [diff] [blame] | 1157 | platform_info = dev_get_platdata(dev); |
| 1158 | if (!platform_info) { |
Mika Westerberg | a349685 | 2013-01-22 12:26:33 +0200 | [diff] [blame] | 1159 | platform_info = pxa2xx_spi_acpi_get_pdata(pdev); |
| 1160 | if (!platform_info) { |
| 1161 | dev_err(&pdev->dev, "missing platform data\n"); |
| 1162 | return -ENODEV; |
| 1163 | } |
Mika Westerberg | 851bacf | 2013-01-07 12:44:33 +0200 | [diff] [blame] | 1164 | } |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1165 | |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 1166 | ssp = pxa_ssp_request(pdev->id, pdev->name); |
Mika Westerberg | 851bacf | 2013-01-07 12:44:33 +0200 | [diff] [blame] | 1167 | if (!ssp) |
| 1168 | ssp = &platform_info->ssp; |
| 1169 | |
| 1170 | if (!ssp->mmio_base) { |
| 1171 | dev_err(&pdev->dev, "failed to get ssp\n"); |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1172 | return -ENODEV; |
| 1173 | } |
| 1174 | |
| 1175 | /* Allocate master with space for drv_data and null dma buffer */ |
| 1176 | master = spi_alloc_master(dev, sizeof(struct driver_data) + 16); |
| 1177 | if (!master) { |
Guennadi Liakhovetski | 65a00a2 | 2008-10-15 22:02:42 -0700 | [diff] [blame] | 1178 | dev_err(&pdev->dev, "cannot alloc spi_master\n"); |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 1179 | pxa_ssp_free(ssp); |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1180 | return -ENOMEM; |
| 1181 | } |
| 1182 | drv_data = spi_master_get_devdata(master); |
| 1183 | drv_data->master = master; |
| 1184 | drv_data->master_info = platform_info; |
| 1185 | drv_data->pdev = pdev; |
eric miao | 2f1a74e | 2007-11-21 18:50:53 +0800 | [diff] [blame] | 1186 | drv_data->ssp = ssp; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1187 | |
Sebastian Andrzej Siewior | 21486af | 2010-10-08 18:11:19 +0200 | [diff] [blame] | 1188 | master->dev.parent = &pdev->dev; |
Sebastian Andrzej Siewior | 21486af | 2010-10-08 18:11:19 +0200 | [diff] [blame] | 1189 | master->dev.of_node = pdev->dev.of_node; |
David Brownell | e7db06b | 2009-06-17 16:26:04 -0700 | [diff] [blame] | 1190 | /* the spi->mode bits understood by this driver: */ |
Mika Westerberg | b833172 | 2013-01-22 12:26:31 +0200 | [diff] [blame] | 1191 | master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LOOP; |
David Brownell | e7db06b | 2009-06-17 16:26:04 -0700 | [diff] [blame] | 1192 | |
Mika Westerberg | 851bacf | 2013-01-07 12:44:33 +0200 | [diff] [blame] | 1193 | master->bus_num = ssp->port_id; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1194 | master->num_chipselect = platform_info->num_chipselect; |
Mike Rapoport | 7ad0ba9 | 2009-04-06 19:00:57 -0700 | [diff] [blame] | 1195 | master->dma_alignment = DMA_ALIGNMENT; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1196 | master->cleanup = cleanup; |
| 1197 | master->setup = setup; |
Mika Westerberg | 7f86bde | 2013-01-22 12:26:26 +0200 | [diff] [blame] | 1198 | master->transfer_one_message = pxa2xx_spi_transfer_one_message; |
Mika Westerberg | 7d94a50 | 2013-01-22 12:26:30 +0200 | [diff] [blame] | 1199 | master->unprepare_transfer_hardware = pxa2xx_spi_unprepare_transfer; |
Mark Brown | 7dd6278 | 2013-07-28 15:35:21 +0100 | [diff] [blame] | 1200 | master->auto_runtime_pm = true; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1201 | |
eric miao | 2f1a74e | 2007-11-21 18:50:53 +0800 | [diff] [blame] | 1202 | drv_data->ssp_type = ssp->type; |
Mika Westerberg | 2b9b84f | 2013-01-22 12:26:25 +0200 | [diff] [blame] | 1203 | drv_data->null_dma_buf = (u32 *)PTR_ALIGN(&drv_data[1], DMA_ALIGNMENT); |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1204 | |
eric miao | 2f1a74e | 2007-11-21 18:50:53 +0800 | [diff] [blame] | 1205 | drv_data->ioaddr = ssp->mmio_base; |
| 1206 | drv_data->ssdr_physical = ssp->phys_base + SSDR; |
Sebastian Andrzej Siewior | 2a8626a | 2010-11-22 17:12:17 -0800 | [diff] [blame] | 1207 | if (pxa25x_ssp_comp(drv_data)) { |
Stephen Warren | 24778be | 2013-05-21 20:36:35 -0600 | [diff] [blame] | 1208 | master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 16); |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1209 | drv_data->int_cr1 = SSCR1_TIE | SSCR1_RIE; |
| 1210 | drv_data->dma_cr1 = 0; |
| 1211 | drv_data->clear_sr = SSSR_ROR; |
| 1212 | drv_data->mask_sr = SSSR_RFS | SSSR_TFS | SSSR_ROR; |
| 1213 | } else { |
Stephen Warren | 24778be | 2013-05-21 20:36:35 -0600 | [diff] [blame] | 1214 | master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32); |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1215 | drv_data->int_cr1 = SSCR1_TIE | SSCR1_RIE | SSCR1_TINTE; |
Mika Westerberg | 5928808 | 2013-01-22 12:26:29 +0200 | [diff] [blame] | 1216 | drv_data->dma_cr1 = DEFAULT_DMA_CR1; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1217 | drv_data->clear_sr = SSSR_ROR | SSSR_TINT; |
| 1218 | drv_data->mask_sr = SSSR_TINT | SSSR_RFS | SSSR_TFS | SSSR_ROR; |
| 1219 | } |
| 1220 | |
Sebastian Andrzej Siewior | 49cbb1e | 2010-11-22 17:12:14 -0800 | [diff] [blame] | 1221 | status = request_irq(ssp->irq, ssp_int, IRQF_SHARED, dev_name(dev), |
| 1222 | drv_data); |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1223 | if (status < 0) { |
Guennadi Liakhovetski | 65a00a2 | 2008-10-15 22:02:42 -0700 | [diff] [blame] | 1224 | dev_err(&pdev->dev, "cannot get IRQ %d\n", ssp->irq); |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1225 | goto out_error_master_alloc; |
| 1226 | } |
| 1227 | |
| 1228 | /* Setup DMA if requested */ |
| 1229 | drv_data->tx_channel = -1; |
| 1230 | drv_data->rx_channel = -1; |
| 1231 | if (platform_info->enable_dma) { |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 1232 | status = pxa2xx_spi_dma_setup(drv_data); |
| 1233 | if (status) { |
Mika Westerberg | cddb339 | 2013-05-13 13:45:10 +0300 | [diff] [blame] | 1234 | dev_dbg(dev, "no DMA channels available, using PIO\n"); |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 1235 | platform_info->enable_dma = false; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1236 | } |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1237 | } |
| 1238 | |
| 1239 | /* Enable SOC clock */ |
Mika Westerberg | 3343b7a | 2013-01-22 12:26:27 +0200 | [diff] [blame] | 1240 | clk_prepare_enable(ssp->clk); |
| 1241 | |
| 1242 | drv_data->max_clk_rate = clk_get_rate(ssp->clk); |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1243 | |
| 1244 | /* Load default SSP configuration */ |
| 1245 | write_SSCR0(0, drv_data->ioaddr); |
Vernon Sauder | f1f640a | 2008-10-15 22:02:43 -0700 | [diff] [blame] | 1246 | write_SSCR1(SSCR1_RxTresh(RX_THRESH_DFLT) | |
| 1247 | SSCR1_TxTresh(TX_THRESH_DFLT), |
| 1248 | drv_data->ioaddr); |
Eric Miao | c9840da | 2010-03-16 16:48:01 +0800 | [diff] [blame] | 1249 | write_SSCR0(SSCR0_SCR(2) |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1250 | | SSCR0_Motorola |
| 1251 | | SSCR0_DataSize(8), |
| 1252 | drv_data->ioaddr); |
Sebastian Andrzej Siewior | 2a8626a | 2010-11-22 17:12:17 -0800 | [diff] [blame] | 1253 | if (!pxa25x_ssp_comp(drv_data)) |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1254 | write_SSTO(0, drv_data->ioaddr); |
| 1255 | write_SSPSP(0, drv_data->ioaddr); |
| 1256 | |
Mika Westerberg | a0d2642 | 2013-01-22 12:26:32 +0200 | [diff] [blame] | 1257 | lpss_ssp_setup(drv_data); |
| 1258 | |
Mika Westerberg | 7f86bde | 2013-01-22 12:26:26 +0200 | [diff] [blame] | 1259 | tasklet_init(&drv_data->pump_transfers, pump_transfers, |
| 1260 | (unsigned long)drv_data); |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1261 | |
Antonio Ospite | 836d1a2 | 2014-05-30 18:18:09 +0200 | [diff] [blame] | 1262 | pm_runtime_set_autosuspend_delay(&pdev->dev, 50); |
| 1263 | pm_runtime_use_autosuspend(&pdev->dev); |
| 1264 | pm_runtime_set_active(&pdev->dev); |
| 1265 | pm_runtime_enable(&pdev->dev); |
| 1266 | |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1267 | /* Register with the SPI framework */ |
| 1268 | platform_set_drvdata(pdev, drv_data); |
Jingoo Han | a807fcd | 2013-09-24 13:46:55 +0900 | [diff] [blame] | 1269 | status = devm_spi_register_master(&pdev->dev, master); |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1270 | if (status != 0) { |
| 1271 | dev_err(&pdev->dev, "problem registering spi master\n"); |
Mika Westerberg | 7f86bde | 2013-01-22 12:26:26 +0200 | [diff] [blame] | 1272 | goto out_error_clock_enabled; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1273 | } |
| 1274 | |
| 1275 | return status; |
| 1276 | |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1277 | out_error_clock_enabled: |
Mika Westerberg | 3343b7a | 2013-01-22 12:26:27 +0200 | [diff] [blame] | 1278 | clk_disable_unprepare(ssp->clk); |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 1279 | pxa2xx_spi_dma_release(drv_data); |
eric miao | 2f1a74e | 2007-11-21 18:50:53 +0800 | [diff] [blame] | 1280 | free_irq(ssp->irq, drv_data); |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1281 | |
| 1282 | out_error_master_alloc: |
| 1283 | spi_master_put(master); |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 1284 | pxa_ssp_free(ssp); |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1285 | return status; |
| 1286 | } |
| 1287 | |
| 1288 | static int pxa2xx_spi_remove(struct platform_device *pdev) |
| 1289 | { |
| 1290 | struct driver_data *drv_data = platform_get_drvdata(pdev); |
Julia Lawall | 51e911e | 2009-01-06 14:41:45 -0800 | [diff] [blame] | 1291 | struct ssp_device *ssp; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1292 | |
| 1293 | if (!drv_data) |
| 1294 | return 0; |
Julia Lawall | 51e911e | 2009-01-06 14:41:45 -0800 | [diff] [blame] | 1295 | ssp = drv_data->ssp; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1296 | |
Mika Westerberg | 7d94a50 | 2013-01-22 12:26:30 +0200 | [diff] [blame] | 1297 | pm_runtime_get_sync(&pdev->dev); |
| 1298 | |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1299 | /* Disable the SSP at the peripheral and SOC level */ |
| 1300 | write_SSCR0(0, drv_data->ioaddr); |
Mika Westerberg | 3343b7a | 2013-01-22 12:26:27 +0200 | [diff] [blame] | 1301 | clk_disable_unprepare(ssp->clk); |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1302 | |
| 1303 | /* Release DMA */ |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 1304 | if (drv_data->master_info->enable_dma) |
| 1305 | pxa2xx_spi_dma_release(drv_data); |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1306 | |
Mika Westerberg | 7d94a50 | 2013-01-22 12:26:30 +0200 | [diff] [blame] | 1307 | pm_runtime_put_noidle(&pdev->dev); |
| 1308 | pm_runtime_disable(&pdev->dev); |
| 1309 | |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1310 | /* Release IRQ */ |
eric miao | 2f1a74e | 2007-11-21 18:50:53 +0800 | [diff] [blame] | 1311 | free_irq(ssp->irq, drv_data); |
| 1312 | |
| 1313 | /* Release SSP */ |
Haojian Zhuang | baffe16 | 2010-05-05 10:11:15 -0400 | [diff] [blame] | 1314 | pxa_ssp_free(ssp); |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1315 | |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1316 | return 0; |
| 1317 | } |
| 1318 | |
| 1319 | static void pxa2xx_spi_shutdown(struct platform_device *pdev) |
| 1320 | { |
| 1321 | int status = 0; |
| 1322 | |
| 1323 | if ((status = pxa2xx_spi_remove(pdev)) != 0) |
| 1324 | dev_err(&pdev->dev, "shutdown failed with %d\n", status); |
| 1325 | } |
| 1326 | |
Mika Westerberg | 382cebb | 2014-01-16 14:50:55 +0200 | [diff] [blame] | 1327 | #ifdef CONFIG_PM_SLEEP |
Mike Rapoport | 86d2593 | 2009-07-21 17:50:16 +0300 | [diff] [blame] | 1328 | static int pxa2xx_spi_suspend(struct device *dev) |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1329 | { |
Mike Rapoport | 86d2593 | 2009-07-21 17:50:16 +0300 | [diff] [blame] | 1330 | struct driver_data *drv_data = dev_get_drvdata(dev); |
eric miao | 2f1a74e | 2007-11-21 18:50:53 +0800 | [diff] [blame] | 1331 | struct ssp_device *ssp = drv_data->ssp; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1332 | int status = 0; |
| 1333 | |
Mika Westerberg | 7f86bde | 2013-01-22 12:26:26 +0200 | [diff] [blame] | 1334 | status = spi_master_suspend(drv_data->master); |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1335 | if (status != 0) |
| 1336 | return status; |
| 1337 | write_SSCR0(0, drv_data->ioaddr); |
Dmitry Eremin-Solenikov | 2b9375b | 2014-11-06 14:08:29 +0300 | [diff] [blame] | 1338 | |
| 1339 | if (!pm_runtime_suspended(dev)) |
| 1340 | clk_disable_unprepare(ssp->clk); |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1341 | |
| 1342 | return 0; |
| 1343 | } |
| 1344 | |
Mike Rapoport | 86d2593 | 2009-07-21 17:50:16 +0300 | [diff] [blame] | 1345 | static int pxa2xx_spi_resume(struct device *dev) |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1346 | { |
Mike Rapoport | 86d2593 | 2009-07-21 17:50:16 +0300 | [diff] [blame] | 1347 | struct driver_data *drv_data = dev_get_drvdata(dev); |
eric miao | 2f1a74e | 2007-11-21 18:50:53 +0800 | [diff] [blame] | 1348 | struct ssp_device *ssp = drv_data->ssp; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1349 | int status = 0; |
| 1350 | |
Mika Westerberg | cd7bed0 | 2013-01-22 12:26:28 +0200 | [diff] [blame] | 1351 | pxa2xx_spi_dma_resume(drv_data); |
Daniel Ribeiro | 148da33 | 2009-04-21 12:24:43 -0700 | [diff] [blame] | 1352 | |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1353 | /* Enable the SSP clock */ |
Dmitry Eremin-Solenikov | 2b9375b | 2014-11-06 14:08:29 +0300 | [diff] [blame] | 1354 | if (!pm_runtime_suspended(dev)) |
| 1355 | clk_prepare_enable(ssp->clk); |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1356 | |
Chew, Chiau Ee | c50325f | 2013-11-29 02:13:11 +0800 | [diff] [blame] | 1357 | /* Restore LPSS private register bits */ |
| 1358 | lpss_ssp_setup(drv_data); |
| 1359 | |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1360 | /* Start the queue running */ |
Mika Westerberg | 7f86bde | 2013-01-22 12:26:26 +0200 | [diff] [blame] | 1361 | status = spi_master_resume(drv_data->master); |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1362 | if (status != 0) { |
Mike Rapoport | 86d2593 | 2009-07-21 17:50:16 +0300 | [diff] [blame] | 1363 | dev_err(dev, "problem starting queue (%d)\n", status); |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1364 | return status; |
| 1365 | } |
| 1366 | |
| 1367 | return 0; |
| 1368 | } |
Mika Westerberg | 7d94a50 | 2013-01-22 12:26:30 +0200 | [diff] [blame] | 1369 | #endif |
| 1370 | |
| 1371 | #ifdef CONFIG_PM_RUNTIME |
| 1372 | static int pxa2xx_spi_runtime_suspend(struct device *dev) |
| 1373 | { |
| 1374 | struct driver_data *drv_data = dev_get_drvdata(dev); |
| 1375 | |
| 1376 | clk_disable_unprepare(drv_data->ssp->clk); |
| 1377 | return 0; |
| 1378 | } |
| 1379 | |
| 1380 | static int pxa2xx_spi_runtime_resume(struct device *dev) |
| 1381 | { |
| 1382 | struct driver_data *drv_data = dev_get_drvdata(dev); |
| 1383 | |
| 1384 | clk_prepare_enable(drv_data->ssp->clk); |
| 1385 | return 0; |
| 1386 | } |
| 1387 | #endif |
Mike Rapoport | 86d2593 | 2009-07-21 17:50:16 +0300 | [diff] [blame] | 1388 | |
Alexey Dobriyan | 4714521 | 2009-12-14 18:00:08 -0800 | [diff] [blame] | 1389 | static const struct dev_pm_ops pxa2xx_spi_pm_ops = { |
Mika Westerberg | 7d94a50 | 2013-01-22 12:26:30 +0200 | [diff] [blame] | 1390 | SET_SYSTEM_SLEEP_PM_OPS(pxa2xx_spi_suspend, pxa2xx_spi_resume) |
| 1391 | SET_RUNTIME_PM_OPS(pxa2xx_spi_runtime_suspend, |
| 1392 | pxa2xx_spi_runtime_resume, NULL) |
Mike Rapoport | 86d2593 | 2009-07-21 17:50:16 +0300 | [diff] [blame] | 1393 | }; |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1394 | |
| 1395 | static struct platform_driver driver = { |
| 1396 | .driver = { |
Mike Rapoport | 86d2593 | 2009-07-21 17:50:16 +0300 | [diff] [blame] | 1397 | .name = "pxa2xx-spi", |
| 1398 | .owner = THIS_MODULE, |
Mike Rapoport | 86d2593 | 2009-07-21 17:50:16 +0300 | [diff] [blame] | 1399 | .pm = &pxa2xx_spi_pm_ops, |
Mika Westerberg | a349685 | 2013-01-22 12:26:33 +0200 | [diff] [blame] | 1400 | .acpi_match_table = ACPI_PTR(pxa2xx_spi_acpi_match), |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1401 | }, |
Sebastian Andrzej Siewior | fbd29a1 | 2010-11-19 09:00:11 -0800 | [diff] [blame] | 1402 | .probe = pxa2xx_spi_probe, |
David Brownell | d1e44d9 | 2007-10-16 01:27:46 -0700 | [diff] [blame] | 1403 | .remove = pxa2xx_spi_remove, |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1404 | .shutdown = pxa2xx_spi_shutdown, |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1405 | }; |
| 1406 | |
| 1407 | static int __init pxa2xx_spi_init(void) |
| 1408 | { |
Sebastian Andrzej Siewior | fbd29a1 | 2010-11-19 09:00:11 -0800 | [diff] [blame] | 1409 | return platform_driver_register(&driver); |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1410 | } |
Antonio Ospite | 5b61a74 | 2009-09-22 16:46:10 -0700 | [diff] [blame] | 1411 | subsys_initcall(pxa2xx_spi_init); |
Stephen Street | e0c9905 | 2006-03-07 23:53:24 -0800 | [diff] [blame] | 1412 | |
| 1413 | static void __exit pxa2xx_spi_exit(void) |
| 1414 | { |
| 1415 | platform_driver_unregister(&driver); |
| 1416 | } |
| 1417 | module_exit(pxa2xx_spi_exit); |