Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Freescale eSPI controller driver. |
| 3 | * |
| 4 | * Copyright 2010 Freescale Semiconductor, Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms of the GNU General Public License as published by the |
| 8 | * Free Software Foundation; either version 2 of the License, or (at your |
| 9 | * option) any later version. |
| 10 | */ |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 11 | #include <linux/delay.h> |
Xiubo Li | a310836 | 2014-09-29 10:57:06 +0800 | [diff] [blame] | 12 | #include <linux/err.h> |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 13 | #include <linux/fsl_devices.h> |
Xiubo Li | a310836 | 2014-09-29 10:57:06 +0800 | [diff] [blame] | 14 | #include <linux/interrupt.h> |
Xiubo Li | a310836 | 2014-09-29 10:57:06 +0800 | [diff] [blame] | 15 | #include <linux/module.h> |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 16 | #include <linux/mm.h> |
| 17 | #include <linux/of.h> |
Rob Herring | 5af5073 | 2013-09-17 14:28:33 -0500 | [diff] [blame] | 18 | #include <linux/of_address.h> |
| 19 | #include <linux/of_irq.h> |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 20 | #include <linux/of_platform.h> |
Xiubo Li | a310836 | 2014-09-29 10:57:06 +0800 | [diff] [blame] | 21 | #include <linux/platform_device.h> |
| 22 | #include <linux/spi/spi.h> |
Heiner Kallweit | e9abb4d | 2015-08-26 21:21:55 +0200 | [diff] [blame] | 23 | #include <linux/pm_runtime.h> |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 24 | #include <sysdev/fsl_soc.h> |
| 25 | |
Grant Likely | ca632f5 | 2011-06-06 01:16:30 -0600 | [diff] [blame] | 26 | #include "spi-fsl-lib.h" |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 27 | |
| 28 | /* eSPI Controller registers */ |
Heiner Kallweit | 46afd38 | 2016-09-13 23:16:02 +0200 | [diff] [blame] | 29 | #define ESPI_SPMODE 0x00 /* eSPI mode register */ |
| 30 | #define ESPI_SPIE 0x04 /* eSPI event register */ |
| 31 | #define ESPI_SPIM 0x08 /* eSPI mask register */ |
| 32 | #define ESPI_SPCOM 0x0c /* eSPI command register */ |
| 33 | #define ESPI_SPITF 0x10 /* eSPI transmit FIFO access register*/ |
| 34 | #define ESPI_SPIRF 0x14 /* eSPI receive FIFO access register*/ |
| 35 | #define ESPI_SPMODE0 0x20 /* eSPI cs0 mode register */ |
| 36 | |
| 37 | #define ESPI_SPMODEx(x) (ESPI_SPMODE0 + (x) * 4) |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 38 | |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 39 | /* eSPI Controller mode register definitions */ |
Heiner Kallweit | 81abc2e | 2016-09-13 23:16:06 +0200 | [diff] [blame] | 40 | #define SPMODE_ENABLE BIT(31) |
| 41 | #define SPMODE_LOOP BIT(30) |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 42 | #define SPMODE_TXTHR(x) ((x) << 8) |
| 43 | #define SPMODE_RXTHR(x) ((x) << 0) |
| 44 | |
| 45 | /* eSPI Controller CS mode register definitions */ |
Heiner Kallweit | 81abc2e | 2016-09-13 23:16:06 +0200 | [diff] [blame] | 46 | #define CSMODE_CI_INACTIVEHIGH BIT(31) |
| 47 | #define CSMODE_CP_BEGIN_EDGECLK BIT(30) |
| 48 | #define CSMODE_REV BIT(29) |
| 49 | #define CSMODE_DIV16 BIT(28) |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 50 | #define CSMODE_PM(x) ((x) << 24) |
Heiner Kallweit | 81abc2e | 2016-09-13 23:16:06 +0200 | [diff] [blame] | 51 | #define CSMODE_POL_1 BIT(20) |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 52 | #define CSMODE_LEN(x) ((x) << 16) |
| 53 | #define CSMODE_BEF(x) ((x) << 12) |
| 54 | #define CSMODE_AFT(x) ((x) << 8) |
| 55 | #define CSMODE_CG(x) ((x) << 3) |
| 56 | |
Heiner Kallweit | 5473126 | 2016-10-27 21:25:58 +0200 | [diff] [blame] | 57 | #define FSL_ESPI_FIFO_SIZE 32 |
Heiner Kallweit | e508cea | 2016-10-27 21:27:56 +0200 | [diff] [blame] | 58 | #define FSL_ESPI_RXTHR 15 |
Heiner Kallweit | 5473126 | 2016-10-27 21:25:58 +0200 | [diff] [blame] | 59 | |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 60 | /* Default mode/csmode for eSPI controller */ |
Heiner Kallweit | e508cea | 2016-10-27 21:27:56 +0200 | [diff] [blame] | 61 | #define SPMODE_INIT_VAL (SPMODE_TXTHR(4) | SPMODE_RXTHR(FSL_ESPI_RXTHR)) |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 62 | #define CSMODE_INIT_VAL (CSMODE_POL_1 | CSMODE_BEF(0) \ |
| 63 | | CSMODE_AFT(0) | CSMODE_CG(1)) |
| 64 | |
| 65 | /* SPIE register values */ |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 66 | #define SPIE_RXCNT(reg) ((reg >> 24) & 0x3F) |
| 67 | #define SPIE_TXCNT(reg) ((reg >> 16) & 0x3F) |
Heiner Kallweit | 81abc2e | 2016-09-13 23:16:06 +0200 | [diff] [blame] | 68 | #define SPIE_TXE BIT(15) /* TX FIFO empty */ |
| 69 | #define SPIE_DON BIT(14) /* TX done */ |
| 70 | #define SPIE_RXT BIT(13) /* RX FIFO threshold */ |
| 71 | #define SPIE_RXF BIT(12) /* RX FIFO full */ |
| 72 | #define SPIE_TXT BIT(11) /* TX FIFO threshold*/ |
| 73 | #define SPIE_RNE BIT(9) /* RX FIFO not empty */ |
| 74 | #define SPIE_TNF BIT(8) /* TX FIFO not full */ |
| 75 | |
| 76 | /* SPIM register values */ |
| 77 | #define SPIM_TXE BIT(15) /* TX FIFO empty */ |
| 78 | #define SPIM_DON BIT(14) /* TX done */ |
| 79 | #define SPIM_RXT BIT(13) /* RX FIFO threshold */ |
| 80 | #define SPIM_RXF BIT(12) /* RX FIFO full */ |
| 81 | #define SPIM_TXT BIT(11) /* TX FIFO threshold*/ |
| 82 | #define SPIM_RNE BIT(9) /* RX FIFO not empty */ |
| 83 | #define SPIM_TNF BIT(8) /* TX FIFO not full */ |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 84 | |
| 85 | /* SPCOM register values */ |
| 86 | #define SPCOM_CS(x) ((x) << 30) |
Heiner Kallweit | 81abc2e | 2016-09-13 23:16:06 +0200 | [diff] [blame] | 87 | #define SPCOM_DO BIT(28) /* Dual output */ |
| 88 | #define SPCOM_TO BIT(27) /* TX only */ |
| 89 | #define SPCOM_RXSKIP(x) ((x) << 16) |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 90 | #define SPCOM_TRANLEN(x) ((x) << 0) |
Heiner Kallweit | 81abc2e | 2016-09-13 23:16:06 +0200 | [diff] [blame] | 91 | |
Hou Zhiqiang | 5cfa1e4 | 2016-01-22 18:58:26 +0800 | [diff] [blame] | 92 | #define SPCOM_TRANLEN_MAX 0x10000 /* Max transaction length */ |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 93 | |
Heiner Kallweit | e9abb4d | 2015-08-26 21:21:55 +0200 | [diff] [blame] | 94 | #define AUTOSUSPEND_TIMEOUT 2000 |
| 95 | |
Heiner Kallweit | 46afd38 | 2016-09-13 23:16:02 +0200 | [diff] [blame] | 96 | static inline u32 fsl_espi_read_reg(struct mpc8xxx_spi *mspi, int offset) |
| 97 | { |
| 98 | return ioread32be(mspi->reg_base + offset); |
| 99 | } |
| 100 | |
| 101 | static inline u8 fsl_espi_read_reg8(struct mpc8xxx_spi *mspi, int offset) |
| 102 | { |
| 103 | return ioread8(mspi->reg_base + offset); |
| 104 | } |
| 105 | |
| 106 | static inline void fsl_espi_write_reg(struct mpc8xxx_spi *mspi, int offset, |
| 107 | u32 val) |
| 108 | { |
| 109 | iowrite32be(val, mspi->reg_base + offset); |
| 110 | } |
| 111 | |
| 112 | static inline void fsl_espi_write_reg8(struct mpc8xxx_spi *mspi, int offset, |
| 113 | u8 val) |
| 114 | { |
| 115 | iowrite8(val, mspi->reg_base + offset); |
| 116 | } |
| 117 | |
Heiner Kallweit | 923ab15 | 2016-10-02 14:22:57 +0200 | [diff] [blame] | 118 | static void fsl_espi_memcpy_swab(void *to, const void *from, |
| 119 | struct spi_message *m, |
| 120 | struct spi_transfer *t) |
| 121 | { |
| 122 | unsigned int len = t->len; |
| 123 | |
| 124 | if (!(m->spi->mode & SPI_LSB_FIRST) || t->bits_per_word <= 8) { |
| 125 | memcpy(to, from, len); |
| 126 | return; |
| 127 | } |
| 128 | |
| 129 | /* In case of LSB-first and bits_per_word > 8 byte-swap all words */ |
| 130 | while (len) |
| 131 | if (len >= 4) { |
| 132 | *(u32 *)to = swahb32p(from); |
| 133 | to += 4; |
| 134 | from += 4; |
| 135 | len -= 4; |
| 136 | } else { |
| 137 | *(u16 *)to = swab16p(from); |
| 138 | to += 2; |
| 139 | from += 2; |
| 140 | len -= 2; |
| 141 | } |
| 142 | } |
| 143 | |
Heiner Kallweit | cce7e3a | 2016-09-07 22:54:18 +0200 | [diff] [blame] | 144 | static void fsl_espi_copy_to_buf(struct spi_message *m, |
| 145 | struct mpc8xxx_spi *mspi) |
Heiner Kallweit | 7c159aa | 2016-09-07 22:50:53 +0200 | [diff] [blame] | 146 | { |
Heiner Kallweit | 7c159aa | 2016-09-07 22:50:53 +0200 | [diff] [blame] | 147 | struct spi_transfer *t; |
| 148 | u8 *buf = mspi->local_buf; |
| 149 | |
| 150 | list_for_each_entry(t, &m->transfers, transfer_list) { |
Heiner Kallweit | cce7e3a | 2016-09-07 22:54:18 +0200 | [diff] [blame] | 151 | if (t->tx_buf) |
Heiner Kallweit | 923ab15 | 2016-10-02 14:22:57 +0200 | [diff] [blame] | 152 | fsl_espi_memcpy_swab(buf, t->tx_buf, m, t); |
Heiner Kallweit | aca7515 | 2016-11-09 22:58:01 +0100 | [diff] [blame] | 153 | /* In RXSKIP mode controller shifts out zeros internally */ |
| 154 | else if (!mspi->rxskip) |
Heiner Kallweit | 7c159aa | 2016-09-07 22:50:53 +0200 | [diff] [blame] | 155 | memset(buf, 0, t->len); |
Heiner Kallweit | 7c159aa | 2016-09-07 22:50:53 +0200 | [diff] [blame] | 156 | buf += t->len; |
| 157 | } |
Heiner Kallweit | cce7e3a | 2016-09-07 22:54:18 +0200 | [diff] [blame] | 158 | } |
Heiner Kallweit | 7c159aa | 2016-09-07 22:50:53 +0200 | [diff] [blame] | 159 | |
Heiner Kallweit | cce7e3a | 2016-09-07 22:54:18 +0200 | [diff] [blame] | 160 | static void fsl_espi_copy_from_buf(struct spi_message *m, |
| 161 | struct mpc8xxx_spi *mspi) |
| 162 | { |
| 163 | struct spi_transfer *t; |
| 164 | u8 *buf = mspi->local_buf; |
| 165 | |
| 166 | list_for_each_entry(t, &m->transfers, transfer_list) { |
| 167 | if (t->rx_buf) |
Heiner Kallweit | 923ab15 | 2016-10-02 14:22:57 +0200 | [diff] [blame] | 168 | fsl_espi_memcpy_swab(t->rx_buf, buf, m, t); |
Heiner Kallweit | cce7e3a | 2016-09-07 22:54:18 +0200 | [diff] [blame] | 169 | buf += t->len; |
| 170 | } |
Heiner Kallweit | 7c159aa | 2016-09-07 22:50:53 +0200 | [diff] [blame] | 171 | } |
| 172 | |
Heiner Kallweit | d3152cf1 | 2016-09-07 22:53:38 +0200 | [diff] [blame] | 173 | static int fsl_espi_check_message(struct spi_message *m) |
| 174 | { |
| 175 | struct mpc8xxx_spi *mspi = spi_master_get_devdata(m->spi->master); |
| 176 | struct spi_transfer *t, *first; |
| 177 | |
| 178 | if (m->frame_length > SPCOM_TRANLEN_MAX) { |
| 179 | dev_err(mspi->dev, "message too long, size is %u bytes\n", |
| 180 | m->frame_length); |
| 181 | return -EMSGSIZE; |
| 182 | } |
| 183 | |
| 184 | first = list_first_entry(&m->transfers, struct spi_transfer, |
| 185 | transfer_list); |
Heiner Kallweit | e4be705 | 2016-10-02 14:22:35 +0200 | [diff] [blame] | 186 | |
Heiner Kallweit | d3152cf1 | 2016-09-07 22:53:38 +0200 | [diff] [blame] | 187 | list_for_each_entry(t, &m->transfers, transfer_list) { |
| 188 | if (first->bits_per_word != t->bits_per_word || |
| 189 | first->speed_hz != t->speed_hz) { |
| 190 | dev_err(mspi->dev, "bits_per_word/speed_hz should be the same for all transfers\n"); |
| 191 | return -EINVAL; |
| 192 | } |
| 193 | } |
| 194 | |
Heiner Kallweit | e4be705 | 2016-10-02 14:22:35 +0200 | [diff] [blame] | 195 | /* ESPI supports MSB-first transfers for word size 8 / 16 only */ |
| 196 | if (!(m->spi->mode & SPI_LSB_FIRST) && first->bits_per_word != 8 && |
| 197 | first->bits_per_word != 16) { |
| 198 | dev_err(mspi->dev, |
| 199 | "MSB-first transfer not supported for wordsize %u\n", |
| 200 | first->bits_per_word); |
| 201 | return -EINVAL; |
| 202 | } |
| 203 | |
Heiner Kallweit | d3152cf1 | 2016-09-07 22:53:38 +0200 | [diff] [blame] | 204 | return 0; |
| 205 | } |
| 206 | |
Heiner Kallweit | aca7515 | 2016-11-09 22:58:01 +0100 | [diff] [blame] | 207 | static unsigned int fsl_espi_check_rxskip_mode(struct spi_message *m) |
| 208 | { |
| 209 | struct spi_transfer *t; |
| 210 | unsigned int i = 0, rxskip = 0; |
| 211 | |
| 212 | /* |
| 213 | * prerequisites for ESPI rxskip mode: |
| 214 | * - message has two transfers |
| 215 | * - first transfer is a write and second is a read |
| 216 | * |
| 217 | * In addition the current low-level transfer mechanism requires |
| 218 | * that the rxskip bytes fit into the TX FIFO. Else the transfer |
| 219 | * would hang because after the first FSL_ESPI_FIFO_SIZE bytes |
| 220 | * the TX FIFO isn't re-filled. |
| 221 | */ |
| 222 | list_for_each_entry(t, &m->transfers, transfer_list) { |
| 223 | if (i == 0) { |
| 224 | if (!t->tx_buf || t->rx_buf || |
| 225 | t->len > FSL_ESPI_FIFO_SIZE) |
| 226 | return 0; |
| 227 | rxskip = t->len; |
| 228 | } else if (i == 1) { |
| 229 | if (t->tx_buf || !t->rx_buf) |
| 230 | return 0; |
| 231 | } |
| 232 | i++; |
| 233 | } |
| 234 | |
| 235 | return i == 2 ? rxskip : 0; |
| 236 | } |
| 237 | |
Heiner Kallweit | 5473126 | 2016-10-27 21:25:58 +0200 | [diff] [blame] | 238 | static void fsl_espi_fill_tx_fifo(struct mpc8xxx_spi *mspi, u32 events) |
| 239 | { |
| 240 | u32 tx_fifo_avail; |
| 241 | |
| 242 | /* if events is zero transfer has not started and tx fifo is empty */ |
| 243 | tx_fifo_avail = events ? SPIE_TXCNT(events) : FSL_ESPI_FIFO_SIZE; |
| 244 | |
| 245 | while (tx_fifo_avail >= min(4U, mspi->tx_len) && mspi->tx_len) |
| 246 | if (mspi->tx_len >= 4) { |
| 247 | fsl_espi_write_reg(mspi, ESPI_SPITF, *(u32 *)mspi->tx); |
| 248 | mspi->tx += 4; |
| 249 | mspi->tx_len -= 4; |
| 250 | tx_fifo_avail -= 4; |
| 251 | } else { |
| 252 | fsl_espi_write_reg8(mspi, ESPI_SPITF, *(u8 *)mspi->tx); |
| 253 | mspi->tx += 1; |
| 254 | mspi->tx_len -= 1; |
| 255 | tx_fifo_avail -= 1; |
| 256 | } |
| 257 | } |
| 258 | |
Heiner Kallweit | f05689a | 2016-10-27 21:27:35 +0200 | [diff] [blame] | 259 | static void fsl_espi_read_rx_fifo(struct mpc8xxx_spi *mspi, u32 events) |
| 260 | { |
| 261 | u32 rx_fifo_avail = SPIE_RXCNT(events); |
| 262 | |
| 263 | while (rx_fifo_avail >= min(4U, mspi->rx_len) && mspi->rx_len) |
| 264 | if (mspi->rx_len >= 4) { |
| 265 | *(u32 *)mspi->rx = fsl_espi_read_reg(mspi, ESPI_SPIRF); |
| 266 | mspi->rx += 4; |
| 267 | mspi->rx_len -= 4; |
| 268 | rx_fifo_avail -= 4; |
| 269 | } else { |
| 270 | *(u8 *)mspi->rx = fsl_espi_read_reg8(mspi, ESPI_SPIRF); |
| 271 | mspi->rx += 1; |
| 272 | mspi->rx_len -= 1; |
| 273 | rx_fifo_avail -= 1; |
| 274 | } |
| 275 | } |
| 276 | |
Heiner Kallweit | ea616ee | 2016-08-25 06:44:42 +0200 | [diff] [blame] | 277 | static void fsl_espi_setup_transfer(struct spi_device *spi, |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 278 | struct spi_transfer *t) |
| 279 | { |
| 280 | struct mpc8xxx_spi *mpc8xxx_spi = spi_master_get_devdata(spi->master); |
Heiner Kallweit | d198ebf | 2016-09-13 23:15:45 +0200 | [diff] [blame] | 281 | int bits_per_word = t ? t->bits_per_word : spi->bits_per_word; |
Paulo Zaneti | 73aaf15 | 2016-10-29 11:02:19 +0200 | [diff] [blame] | 282 | u32 pm, hz = t ? t->speed_hz : spi->max_speed_hz; |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 283 | struct spi_mpc8xxx_cs *cs = spi->controller_state; |
Heiner Kallweit | 8f3086d | 2016-11-04 21:01:12 +0100 | [diff] [blame] | 284 | u32 hw_mode_old = cs->hw_mode; |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 285 | |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 286 | /* mask out bits we are going to set */ |
| 287 | cs->hw_mode &= ~(CSMODE_LEN(0xF) | CSMODE_DIV16 | CSMODE_PM(0xF)); |
| 288 | |
Heiner Kallweit | a755af5 | 2016-09-04 09:56:57 +0200 | [diff] [blame] | 289 | cs->hw_mode |= CSMODE_LEN(bits_per_word - 1); |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 290 | |
Paulo Zaneti | 73aaf15 | 2016-10-29 11:02:19 +0200 | [diff] [blame] | 291 | pm = DIV_ROUND_UP(mpc8xxx_spi->spibrg, hz * 4) - 1; |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 292 | |
Paulo Zaneti | 73aaf15 | 2016-10-29 11:02:19 +0200 | [diff] [blame] | 293 | if (pm > 15) { |
| 294 | cs->hw_mode |= CSMODE_DIV16; |
| 295 | pm = DIV_ROUND_UP(mpc8xxx_spi->spibrg, hz * 16 * 4) - 1; |
| 296 | |
| 297 | WARN_ONCE(pm > 15, |
| 298 | "%s: Requested speed is too low: %u Hz. Will use %u Hz instead.\n", |
| 299 | dev_name(&spi->dev), hz, |
| 300 | mpc8xxx_spi->spibrg / (4 * 16 * (15 + 1))); |
| 301 | if (pm > 15) |
| 302 | pm = 15; |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 303 | } |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 304 | |
| 305 | cs->hw_mode |= CSMODE_PM(pm); |
| 306 | |
Heiner Kallweit | 8f3086d | 2016-11-04 21:01:12 +0100 | [diff] [blame] | 307 | /* don't write the mode register if the mode doesn't change */ |
| 308 | if (cs->hw_mode != hw_mode_old) |
| 309 | fsl_espi_write_reg(mpc8xxx_spi, ESPI_SPMODEx(spi->chip_select), |
| 310 | cs->hw_mode); |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 311 | } |
| 312 | |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 313 | static int fsl_espi_bufs(struct spi_device *spi, struct spi_transfer *t) |
| 314 | { |
| 315 | struct mpc8xxx_spi *mpc8xxx_spi = spi_master_get_devdata(spi->master); |
Heiner Kallweit | aca7515 | 2016-11-09 22:58:01 +0100 | [diff] [blame] | 316 | u32 mask, spcom; |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 317 | int ret; |
| 318 | |
Heiner Kallweit | f895e27 | 2016-10-27 21:26:08 +0200 | [diff] [blame] | 319 | mpc8xxx_spi->rx_len = t->len; |
Heiner Kallweit | 5473126 | 2016-10-27 21:25:58 +0200 | [diff] [blame] | 320 | mpc8xxx_spi->tx_len = t->len; |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 321 | |
| 322 | mpc8xxx_spi->tx = t->tx_buf; |
| 323 | mpc8xxx_spi->rx = t->rx_buf; |
| 324 | |
Wolfram Sang | 16735d0 | 2013-11-14 14:32:02 -0800 | [diff] [blame] | 325 | reinit_completion(&mpc8xxx_spi->done); |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 326 | |
| 327 | /* Set SPCOM[CS] and SPCOM[TRANLEN] field */ |
Heiner Kallweit | aca7515 | 2016-11-09 22:58:01 +0100 | [diff] [blame] | 328 | spcom = SPCOM_CS(spi->chip_select); |
| 329 | spcom |= SPCOM_TRANLEN(t->len - 1); |
| 330 | |
| 331 | /* configure RXSKIP mode */ |
| 332 | if (mpc8xxx_spi->rxskip) { |
| 333 | spcom |= SPCOM_RXSKIP(mpc8xxx_spi->rxskip); |
| 334 | mpc8xxx_spi->tx_len = mpc8xxx_spi->rxskip; |
| 335 | mpc8xxx_spi->rx_len = t->len - mpc8xxx_spi->rxskip; |
| 336 | mpc8xxx_spi->rx = t->rx_buf + mpc8xxx_spi->rxskip; |
Heiner Kallweit | 8263cb3 | 2016-11-09 22:58:34 +0100 | [diff] [blame] | 337 | if (t->rx_nbits == SPI_NBITS_DUAL) |
| 338 | spcom |= SPCOM_DO; |
Heiner Kallweit | aca7515 | 2016-11-09 22:58:01 +0100 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | fsl_espi_write_reg(mpc8xxx_spi, ESPI_SPCOM, spcom); |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 342 | |
Heiner Kallweit | e508cea | 2016-10-27 21:27:56 +0200 | [diff] [blame] | 343 | /* enable interrupts */ |
| 344 | mask = SPIM_DON; |
| 345 | if (mpc8xxx_spi->rx_len > FSL_ESPI_FIFO_SIZE) |
| 346 | mask |= SPIM_RXT; |
| 347 | fsl_espi_write_reg(mpc8xxx_spi, ESPI_SPIM, mask); |
Heiner Kallweit | 5bcc6a2 | 2016-09-07 22:53:01 +0200 | [diff] [blame] | 348 | |
Heiner Kallweit | 5473126 | 2016-10-27 21:25:58 +0200 | [diff] [blame] | 349 | /* Prevent filling the fifo from getting interrupted */ |
| 350 | spin_lock_irq(&mpc8xxx_spi->lock); |
| 351 | fsl_espi_fill_tx_fifo(mpc8xxx_spi, 0); |
| 352 | spin_unlock_irq(&mpc8xxx_spi->lock); |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 353 | |
Nobuteru Hayashi | aa70e56 | 2016-03-18 11:35:21 +0000 | [diff] [blame] | 354 | /* Won't hang up forever, SPI bus sometimes got lost interrupts... */ |
| 355 | ret = wait_for_completion_timeout(&mpc8xxx_spi->done, 2 * HZ); |
| 356 | if (ret == 0) |
| 357 | dev_err(mpc8xxx_spi->dev, |
Heiner Kallweit | db1b049 | 2016-10-27 21:28:02 +0200 | [diff] [blame] | 358 | "Transaction hanging up (left %u tx bytes, %u rx bytes)\n", |
| 359 | mpc8xxx_spi->tx_len, mpc8xxx_spi->rx_len); |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 360 | |
| 361 | /* disable rx ints */ |
Heiner Kallweit | 46afd38 | 2016-09-13 23:16:02 +0200 | [diff] [blame] | 362 | fsl_espi_write_reg(mpc8xxx_spi, ESPI_SPIM, 0); |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 363 | |
Heiner Kallweit | db1b049 | 2016-10-27 21:28:02 +0200 | [diff] [blame] | 364 | return ret == 0 ? -ETIMEDOUT : 0; |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 365 | } |
| 366 | |
Heiner Kallweit | 38d003f | 2016-09-07 22:54:51 +0200 | [diff] [blame] | 367 | static int fsl_espi_trans(struct spi_message *m, struct spi_transfer *trans) |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 368 | { |
Heiner Kallweit | 38d003f | 2016-09-07 22:54:51 +0200 | [diff] [blame] | 369 | struct mpc8xxx_spi *mspi = spi_master_get_devdata(m->spi->master); |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 370 | struct spi_device *spi = m->spi; |
Heiner Kallweit | 38d003f | 2016-09-07 22:54:51 +0200 | [diff] [blame] | 371 | int ret; |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 372 | |
Heiner Kallweit | aca7515 | 2016-11-09 22:58:01 +0100 | [diff] [blame] | 373 | mspi->rxskip = fsl_espi_check_rxskip_mode(m); |
Heiner Kallweit | 8263cb3 | 2016-11-09 22:58:34 +0100 | [diff] [blame] | 374 | if (trans->rx_nbits == SPI_NBITS_DUAL && !mspi->rxskip) { |
| 375 | dev_err(mspi->dev, "Dual output mode requires RXSKIP mode!\n"); |
| 376 | return -EINVAL; |
| 377 | } |
| 378 | |
Heiner Kallweit | 38d003f | 2016-09-07 22:54:51 +0200 | [diff] [blame] | 379 | fsl_espi_copy_to_buf(m, mspi); |
Heiner Kallweit | faceef3 | 2016-09-07 22:52:06 +0200 | [diff] [blame] | 380 | fsl_espi_setup_transfer(spi, trans); |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 381 | |
Heiner Kallweit | 06af115 | 2016-09-07 22:54:35 +0200 | [diff] [blame] | 382 | ret = fsl_espi_bufs(spi, trans); |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 383 | |
Heiner Kallweit | faceef3 | 2016-09-07 22:52:06 +0200 | [diff] [blame] | 384 | if (trans->delay_usecs) |
| 385 | udelay(trans->delay_usecs); |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 386 | |
Heiner Kallweit | cce7e3a | 2016-09-07 22:54:18 +0200 | [diff] [blame] | 387 | if (!ret) |
| 388 | fsl_espi_copy_from_buf(m, mspi); |
Heiner Kallweit | e33a3ad | 2016-09-07 22:51:10 +0200 | [diff] [blame] | 389 | |
| 390 | return ret; |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 391 | } |
| 392 | |
Heiner Kallweit | c592bec | 2014-12-03 07:56:17 +0100 | [diff] [blame] | 393 | static int fsl_espi_do_one_msg(struct spi_master *master, |
| 394 | struct spi_message *m) |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 395 | { |
Heiner Kallweit | 96361faf | 2016-09-07 22:54:00 +0200 | [diff] [blame] | 396 | struct mpc8xxx_spi *mspi = spi_master_get_devdata(m->spi->master); |
Heiner Kallweit | 8263cb3 | 2016-11-09 22:58:34 +0100 | [diff] [blame] | 397 | unsigned int delay_usecs = 0, rx_nbits = 0; |
Heiner Kallweit | faceef3 | 2016-09-07 22:52:06 +0200 | [diff] [blame] | 398 | struct spi_transfer *t, trans = {}; |
Heiner Kallweit | e33a3ad | 2016-09-07 22:51:10 +0200 | [diff] [blame] | 399 | int ret; |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 400 | |
Heiner Kallweit | d3152cf1 | 2016-09-07 22:53:38 +0200 | [diff] [blame] | 401 | ret = fsl_espi_check_message(m); |
| 402 | if (ret) |
| 403 | goto out; |
| 404 | |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 405 | list_for_each_entry(t, &m->transfers, transfer_list) { |
Heiner Kallweit | 96361faf | 2016-09-07 22:54:00 +0200 | [diff] [blame] | 406 | if (t->delay_usecs > delay_usecs) |
| 407 | delay_usecs = t->delay_usecs; |
Heiner Kallweit | 8263cb3 | 2016-11-09 22:58:34 +0100 | [diff] [blame] | 408 | if (t->rx_nbits > rx_nbits) |
| 409 | rx_nbits = t->rx_nbits; |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 410 | } |
| 411 | |
Heiner Kallweit | 96361faf | 2016-09-07 22:54:00 +0200 | [diff] [blame] | 412 | t = list_first_entry(&m->transfers, struct spi_transfer, |
| 413 | transfer_list); |
| 414 | |
Heiner Kallweit | 06af115 | 2016-09-07 22:54:35 +0200 | [diff] [blame] | 415 | trans.len = m->frame_length; |
Heiner Kallweit | 96361faf | 2016-09-07 22:54:00 +0200 | [diff] [blame] | 416 | trans.speed_hz = t->speed_hz; |
| 417 | trans.bits_per_word = t->bits_per_word; |
| 418 | trans.delay_usecs = delay_usecs; |
| 419 | trans.tx_buf = mspi->local_buf; |
| 420 | trans.rx_buf = mspi->local_buf; |
Heiner Kallweit | 8263cb3 | 2016-11-09 22:58:34 +0100 | [diff] [blame] | 421 | trans.rx_nbits = rx_nbits; |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 422 | |
Heiner Kallweit | 06af115 | 2016-09-07 22:54:35 +0200 | [diff] [blame] | 423 | if (trans.len) |
| 424 | ret = fsl_espi_trans(m, &trans); |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 425 | |
Heiner Kallweit | faceef3 | 2016-09-07 22:52:06 +0200 | [diff] [blame] | 426 | m->actual_length = ret ? 0 : trans.len; |
Heiner Kallweit | d3152cf1 | 2016-09-07 22:53:38 +0200 | [diff] [blame] | 427 | out: |
Heiner Kallweit | 0319d49 | 2016-09-07 22:51:29 +0200 | [diff] [blame] | 428 | if (m->status == -EINPROGRESS) |
| 429 | m->status = ret; |
| 430 | |
Heiner Kallweit | c592bec | 2014-12-03 07:56:17 +0100 | [diff] [blame] | 431 | spi_finalize_current_message(master); |
Heiner Kallweit | 0319d49 | 2016-09-07 22:51:29 +0200 | [diff] [blame] | 432 | |
| 433 | return ret; |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | static int fsl_espi_setup(struct spi_device *spi) |
| 437 | { |
| 438 | struct mpc8xxx_spi *mpc8xxx_spi; |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 439 | u32 loop_mode; |
Axel Lin | d9f2674 | 2014-08-31 12:44:09 +0800 | [diff] [blame] | 440 | struct spi_mpc8xxx_cs *cs = spi_get_ctldata(spi); |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 441 | |
| 442 | if (!spi->max_speed_hz) |
| 443 | return -EINVAL; |
| 444 | |
| 445 | if (!cs) { |
Axel Lin | d9f2674 | 2014-08-31 12:44:09 +0800 | [diff] [blame] | 446 | cs = kzalloc(sizeof(*cs), GFP_KERNEL); |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 447 | if (!cs) |
| 448 | return -ENOMEM; |
Axel Lin | d9f2674 | 2014-08-31 12:44:09 +0800 | [diff] [blame] | 449 | spi_set_ctldata(spi, cs); |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | mpc8xxx_spi = spi_master_get_devdata(spi->master); |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 453 | |
Heiner Kallweit | e9abb4d | 2015-08-26 21:21:55 +0200 | [diff] [blame] | 454 | pm_runtime_get_sync(mpc8xxx_spi->dev); |
| 455 | |
Heiner Kallweit | 46afd38 | 2016-09-13 23:16:02 +0200 | [diff] [blame] | 456 | cs->hw_mode = fsl_espi_read_reg(mpc8xxx_spi, |
| 457 | ESPI_SPMODEx(spi->chip_select)); |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 458 | /* mask out bits we are going to set */ |
| 459 | cs->hw_mode &= ~(CSMODE_CP_BEGIN_EDGECLK | CSMODE_CI_INACTIVEHIGH |
| 460 | | CSMODE_REV); |
| 461 | |
| 462 | if (spi->mode & SPI_CPHA) |
| 463 | cs->hw_mode |= CSMODE_CP_BEGIN_EDGECLK; |
| 464 | if (spi->mode & SPI_CPOL) |
| 465 | cs->hw_mode |= CSMODE_CI_INACTIVEHIGH; |
| 466 | if (!(spi->mode & SPI_LSB_FIRST)) |
| 467 | cs->hw_mode |= CSMODE_REV; |
| 468 | |
| 469 | /* Handle the loop mode */ |
Heiner Kallweit | 46afd38 | 2016-09-13 23:16:02 +0200 | [diff] [blame] | 470 | loop_mode = fsl_espi_read_reg(mpc8xxx_spi, ESPI_SPMODE); |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 471 | loop_mode &= ~SPMODE_LOOP; |
| 472 | if (spi->mode & SPI_LOOP) |
| 473 | loop_mode |= SPMODE_LOOP; |
Heiner Kallweit | 46afd38 | 2016-09-13 23:16:02 +0200 | [diff] [blame] | 474 | fsl_espi_write_reg(mpc8xxx_spi, ESPI_SPMODE, loop_mode); |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 475 | |
Heiner Kallweit | ea616ee | 2016-08-25 06:44:42 +0200 | [diff] [blame] | 476 | fsl_espi_setup_transfer(spi, NULL); |
Heiner Kallweit | e9abb4d | 2015-08-26 21:21:55 +0200 | [diff] [blame] | 477 | |
| 478 | pm_runtime_mark_last_busy(mpc8xxx_spi->dev); |
| 479 | pm_runtime_put_autosuspend(mpc8xxx_spi->dev); |
| 480 | |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 481 | return 0; |
| 482 | } |
| 483 | |
Axel Lin | d9f2674 | 2014-08-31 12:44:09 +0800 | [diff] [blame] | 484 | static void fsl_espi_cleanup(struct spi_device *spi) |
| 485 | { |
| 486 | struct spi_mpc8xxx_cs *cs = spi_get_ctldata(spi); |
| 487 | |
| 488 | kfree(cs); |
| 489 | spi_set_ctldata(spi, NULL); |
| 490 | } |
| 491 | |
Heiner Kallweit | 10ed1e6 | 2016-08-25 06:45:16 +0200 | [diff] [blame] | 492 | static void fsl_espi_cpu_irq(struct mpc8xxx_spi *mspi, u32 events) |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 493 | { |
Heiner Kallweit | f05689a | 2016-10-27 21:27:35 +0200 | [diff] [blame] | 494 | if (mspi->rx_len) |
| 495 | fsl_espi_read_rx_fifo(mspi, events); |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 496 | |
Heiner Kallweit | 5473126 | 2016-10-27 21:25:58 +0200 | [diff] [blame] | 497 | if (mspi->tx_len) |
| 498 | fsl_espi_fill_tx_fifo(mspi, events); |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 499 | |
Heiner Kallweit | db1b049 | 2016-10-27 21:28:02 +0200 | [diff] [blame] | 500 | if (mspi->tx_len || mspi->rx_len) |
| 501 | return; |
| 502 | |
| 503 | /* we're done, but check for errors before returning */ |
| 504 | events = fsl_espi_read_reg(mspi, ESPI_SPIE); |
| 505 | |
| 506 | if (!(events & SPIE_DON)) |
| 507 | dev_err(mspi->dev, |
| 508 | "Transfer done but SPIE_DON isn't set!\n"); |
| 509 | |
| 510 | if (SPIE_RXCNT(events) || SPIE_TXCNT(events) != FSL_ESPI_FIFO_SIZE) |
| 511 | dev_err(mspi->dev, "Transfer done but rx/tx fifo's aren't empty!\n"); |
| 512 | |
| 513 | complete(&mspi->done); |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | static irqreturn_t fsl_espi_irq(s32 irq, void *context_data) |
| 517 | { |
| 518 | struct mpc8xxx_spi *mspi = context_data; |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 519 | u32 events; |
| 520 | |
Heiner Kallweit | 5473126 | 2016-10-27 21:25:58 +0200 | [diff] [blame] | 521 | spin_lock(&mspi->lock); |
| 522 | |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 523 | /* Get interrupt events(tx/rx) */ |
Heiner Kallweit | 46afd38 | 2016-09-13 23:16:02 +0200 | [diff] [blame] | 524 | events = fsl_espi_read_reg(mspi, ESPI_SPIE); |
Heiner Kallweit | 5473126 | 2016-10-27 21:25:58 +0200 | [diff] [blame] | 525 | if (!events) { |
Heiner Kallweit | 66b8053 | 2016-10-29 10:53:19 +0200 | [diff] [blame] | 526 | spin_unlock(&mspi->lock); |
Heiner Kallweit | 35f5d71 | 2016-09-13 23:15:57 +0200 | [diff] [blame] | 527 | return IRQ_NONE; |
Heiner Kallweit | 5473126 | 2016-10-27 21:25:58 +0200 | [diff] [blame] | 528 | } |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 529 | |
| 530 | dev_vdbg(mspi->dev, "%s: events %x\n", __func__, events); |
| 531 | |
| 532 | fsl_espi_cpu_irq(mspi, events); |
| 533 | |
Heiner Kallweit | 35f5d71 | 2016-09-13 23:15:57 +0200 | [diff] [blame] | 534 | /* Clear the events */ |
Heiner Kallweit | 46afd38 | 2016-09-13 23:16:02 +0200 | [diff] [blame] | 535 | fsl_espi_write_reg(mspi, ESPI_SPIE, events); |
Heiner Kallweit | 35f5d71 | 2016-09-13 23:15:57 +0200 | [diff] [blame] | 536 | |
Heiner Kallweit | 5473126 | 2016-10-27 21:25:58 +0200 | [diff] [blame] | 537 | spin_unlock(&mspi->lock); |
| 538 | |
Heiner Kallweit | 35f5d71 | 2016-09-13 23:15:57 +0200 | [diff] [blame] | 539 | return IRQ_HANDLED; |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 540 | } |
| 541 | |
Heiner Kallweit | e9abb4d | 2015-08-26 21:21:55 +0200 | [diff] [blame] | 542 | #ifdef CONFIG_PM |
| 543 | static int fsl_espi_runtime_suspend(struct device *dev) |
Heiner Kallweit | 75506d0 | 2014-12-03 07:56:19 +0100 | [diff] [blame] | 544 | { |
Heiner Kallweit | e9abb4d | 2015-08-26 21:21:55 +0200 | [diff] [blame] | 545 | struct spi_master *master = dev_get_drvdata(dev); |
| 546 | struct mpc8xxx_spi *mpc8xxx_spi = spi_master_get_devdata(master); |
Heiner Kallweit | 75506d0 | 2014-12-03 07:56:19 +0100 | [diff] [blame] | 547 | u32 regval; |
| 548 | |
Heiner Kallweit | 46afd38 | 2016-09-13 23:16:02 +0200 | [diff] [blame] | 549 | regval = fsl_espi_read_reg(mpc8xxx_spi, ESPI_SPMODE); |
Heiner Kallweit | 75506d0 | 2014-12-03 07:56:19 +0100 | [diff] [blame] | 550 | regval &= ~SPMODE_ENABLE; |
Heiner Kallweit | 46afd38 | 2016-09-13 23:16:02 +0200 | [diff] [blame] | 551 | fsl_espi_write_reg(mpc8xxx_spi, ESPI_SPMODE, regval); |
Heiner Kallweit | 75506d0 | 2014-12-03 07:56:19 +0100 | [diff] [blame] | 552 | |
| 553 | return 0; |
| 554 | } |
| 555 | |
Heiner Kallweit | e9abb4d | 2015-08-26 21:21:55 +0200 | [diff] [blame] | 556 | static int fsl_espi_runtime_resume(struct device *dev) |
Heiner Kallweit | 75506d0 | 2014-12-03 07:56:19 +0100 | [diff] [blame] | 557 | { |
Heiner Kallweit | e9abb4d | 2015-08-26 21:21:55 +0200 | [diff] [blame] | 558 | struct spi_master *master = dev_get_drvdata(dev); |
| 559 | struct mpc8xxx_spi *mpc8xxx_spi = spi_master_get_devdata(master); |
Heiner Kallweit | 75506d0 | 2014-12-03 07:56:19 +0100 | [diff] [blame] | 560 | u32 regval; |
| 561 | |
Heiner Kallweit | 46afd38 | 2016-09-13 23:16:02 +0200 | [diff] [blame] | 562 | regval = fsl_espi_read_reg(mpc8xxx_spi, ESPI_SPMODE); |
Heiner Kallweit | 75506d0 | 2014-12-03 07:56:19 +0100 | [diff] [blame] | 563 | regval |= SPMODE_ENABLE; |
Heiner Kallweit | 46afd38 | 2016-09-13 23:16:02 +0200 | [diff] [blame] | 564 | fsl_espi_write_reg(mpc8xxx_spi, ESPI_SPMODE, regval); |
Heiner Kallweit | 75506d0 | 2014-12-03 07:56:19 +0100 | [diff] [blame] | 565 | |
| 566 | return 0; |
| 567 | } |
Heiner Kallweit | e9abb4d | 2015-08-26 21:21:55 +0200 | [diff] [blame] | 568 | #endif |
Heiner Kallweit | 75506d0 | 2014-12-03 07:56:19 +0100 | [diff] [blame] | 569 | |
Heiner Kallweit | 02a595d | 2016-08-17 21:11:01 +0200 | [diff] [blame] | 570 | static size_t fsl_espi_max_message_size(struct spi_device *spi) |
Michal Suchanek | b541eef | 2015-12-02 10:38:21 +0000 | [diff] [blame] | 571 | { |
| 572 | return SPCOM_TRANLEN_MAX; |
| 573 | } |
| 574 | |
Heiner Kallweit | 604042a | 2016-09-17 15:43:31 +0200 | [diff] [blame] | 575 | static int fsl_espi_probe(struct device *dev, struct resource *mem, |
Heiner Kallweit | 7454346 | 2016-11-13 14:36:39 +0100 | [diff] [blame] | 576 | unsigned int irq, unsigned int num_cs) |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 577 | { |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 578 | struct spi_master *master; |
| 579 | struct mpc8xxx_spi *mpc8xxx_spi; |
Jane Wan | d0fb47a5 | 2014-04-16 13:09:39 -0700 | [diff] [blame] | 580 | struct device_node *nc; |
Heiner Kallweit | b497eb0 | 2016-10-01 21:07:52 +0200 | [diff] [blame] | 581 | u32 regval, csmode, cs, prop; |
| 582 | int ret; |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 583 | |
| 584 | master = spi_alloc_master(dev, sizeof(struct mpc8xxx_spi)); |
Heiner Kallweit | 604042a | 2016-09-17 15:43:31 +0200 | [diff] [blame] | 585 | if (!master) |
| 586 | return -ENOMEM; |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 587 | |
| 588 | dev_set_drvdata(dev, master); |
| 589 | |
Heiner Kallweit | c592bec | 2014-12-03 07:56:17 +0100 | [diff] [blame] | 590 | mpc8xxx_spi_probe(dev, mem, irq); |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 591 | |
Heiner Kallweit | 8263cb3 | 2016-11-09 22:58:34 +0100 | [diff] [blame] | 592 | master->mode_bits |= SPI_RX_DUAL; |
Stephen Warren | 24778be | 2013-05-21 20:36:35 -0600 | [diff] [blame] | 593 | master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 16); |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 594 | master->setup = fsl_espi_setup; |
Axel Lin | d9f2674 | 2014-08-31 12:44:09 +0800 | [diff] [blame] | 595 | master->cleanup = fsl_espi_cleanup; |
Heiner Kallweit | c592bec | 2014-12-03 07:56:17 +0100 | [diff] [blame] | 596 | master->transfer_one_message = fsl_espi_do_one_msg; |
Heiner Kallweit | e9abb4d | 2015-08-26 21:21:55 +0200 | [diff] [blame] | 597 | master->auto_runtime_pm = true; |
Heiner Kallweit | 02a595d | 2016-08-17 21:11:01 +0200 | [diff] [blame] | 598 | master->max_message_size = fsl_espi_max_message_size; |
Heiner Kallweit | 7454346 | 2016-11-13 14:36:39 +0100 | [diff] [blame] | 599 | master->num_chipselect = num_cs; |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 600 | |
| 601 | mpc8xxx_spi = spi_master_get_devdata(master); |
Heiner Kallweit | 5473126 | 2016-10-27 21:25:58 +0200 | [diff] [blame] | 602 | spin_lock_init(&mpc8xxx_spi->lock); |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 603 | |
Heiner Kallweit | 1423877 | 2016-09-07 22:50:22 +0200 | [diff] [blame] | 604 | mpc8xxx_spi->local_buf = |
| 605 | devm_kmalloc(dev, SPCOM_TRANLEN_MAX, GFP_KERNEL); |
| 606 | if (!mpc8xxx_spi->local_buf) { |
| 607 | ret = -ENOMEM; |
| 608 | goto err_probe; |
| 609 | } |
| 610 | |
Heiner Kallweit | 4178b6b | 2015-08-26 21:21:50 +0200 | [diff] [blame] | 611 | mpc8xxx_spi->reg_base = devm_ioremap_resource(dev, mem); |
Axel Lin | 37c5db7 | 2015-08-30 18:35:51 +0800 | [diff] [blame] | 612 | if (IS_ERR(mpc8xxx_spi->reg_base)) { |
| 613 | ret = PTR_ERR(mpc8xxx_spi->reg_base); |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 614 | goto err_probe; |
| 615 | } |
| 616 | |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 617 | /* Register for SPI Interrupt */ |
Heiner Kallweit | 4178b6b | 2015-08-26 21:21:50 +0200 | [diff] [blame] | 618 | ret = devm_request_irq(dev, mpc8xxx_spi->irq, fsl_espi_irq, |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 619 | 0, "fsl_espi", mpc8xxx_spi); |
| 620 | if (ret) |
Heiner Kallweit | 4178b6b | 2015-08-26 21:21:50 +0200 | [diff] [blame] | 621 | goto err_probe; |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 622 | |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 623 | /* SPI controller initializations */ |
Heiner Kallweit | 46afd38 | 2016-09-13 23:16:02 +0200 | [diff] [blame] | 624 | fsl_espi_write_reg(mpc8xxx_spi, ESPI_SPMODE, 0); |
| 625 | fsl_espi_write_reg(mpc8xxx_spi, ESPI_SPIM, 0); |
| 626 | fsl_espi_write_reg(mpc8xxx_spi, ESPI_SPCOM, 0); |
| 627 | fsl_espi_write_reg(mpc8xxx_spi, ESPI_SPIE, 0xffffffff); |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 628 | |
| 629 | /* Init eSPI CS mode register */ |
Jane Wan | d0fb47a5 | 2014-04-16 13:09:39 -0700 | [diff] [blame] | 630 | for_each_available_child_of_node(master->dev.of_node, nc) { |
| 631 | /* get chip select */ |
Heiner Kallweit | b497eb0 | 2016-10-01 21:07:52 +0200 | [diff] [blame] | 632 | ret = of_property_read_u32(nc, "reg", &cs); |
Heiner Kallweit | 7454346 | 2016-11-13 14:36:39 +0100 | [diff] [blame] | 633 | if (ret || cs >= num_cs) |
Jane Wan | d0fb47a5 | 2014-04-16 13:09:39 -0700 | [diff] [blame] | 634 | continue; |
| 635 | |
| 636 | csmode = CSMODE_INIT_VAL; |
Jane Wan | d0fb47a5 | 2014-04-16 13:09:39 -0700 | [diff] [blame] | 637 | |
Heiner Kallweit | b497eb0 | 2016-10-01 21:07:52 +0200 | [diff] [blame] | 638 | /* check if CSBEF is set in device tree */ |
| 639 | ret = of_property_read_u32(nc, "fsl,csbef", &prop); |
| 640 | if (!ret) { |
| 641 | csmode &= ~(CSMODE_BEF(0xf)); |
| 642 | csmode |= CSMODE_BEF(prop); |
| 643 | } |
| 644 | |
| 645 | /* check if CSAFT is set in device tree */ |
| 646 | ret = of_property_read_u32(nc, "fsl,csaft", &prop); |
| 647 | if (!ret) { |
| 648 | csmode &= ~(CSMODE_AFT(0xf)); |
| 649 | csmode |= CSMODE_AFT(prop); |
| 650 | } |
| 651 | |
| 652 | fsl_espi_write_reg(mpc8xxx_spi, ESPI_SPMODEx(cs), csmode); |
| 653 | |
| 654 | dev_info(dev, "cs=%u, init_csmode=0x%x\n", cs, csmode); |
Jane Wan | d0fb47a5 | 2014-04-16 13:09:39 -0700 | [diff] [blame] | 655 | } |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 656 | |
| 657 | /* Enable SPI interface */ |
Heiner Kallweit | 689d41f | 2016-11-13 14:36:01 +0100 | [diff] [blame] | 658 | regval = SPMODE_INIT_VAL | SPMODE_ENABLE; |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 659 | |
Heiner Kallweit | 46afd38 | 2016-09-13 23:16:02 +0200 | [diff] [blame] | 660 | fsl_espi_write_reg(mpc8xxx_spi, ESPI_SPMODE, regval); |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 661 | |
Heiner Kallweit | e9abb4d | 2015-08-26 21:21:55 +0200 | [diff] [blame] | 662 | pm_runtime_set_autosuspend_delay(dev, AUTOSUSPEND_TIMEOUT); |
| 663 | pm_runtime_use_autosuspend(dev); |
| 664 | pm_runtime_set_active(dev); |
| 665 | pm_runtime_enable(dev); |
| 666 | pm_runtime_get_sync(dev); |
| 667 | |
Heiner Kallweit | 4178b6b | 2015-08-26 21:21:50 +0200 | [diff] [blame] | 668 | ret = devm_spi_register_master(dev, master); |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 669 | if (ret < 0) |
Heiner Kallweit | e9abb4d | 2015-08-26 21:21:55 +0200 | [diff] [blame] | 670 | goto err_pm; |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 671 | |
Heiner Kallweit | 46afd38 | 2016-09-13 23:16:02 +0200 | [diff] [blame] | 672 | dev_info(dev, "at 0x%p (irq = %d)\n", mpc8xxx_spi->reg_base, |
| 673 | mpc8xxx_spi->irq); |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 674 | |
Heiner Kallweit | e9abb4d | 2015-08-26 21:21:55 +0200 | [diff] [blame] | 675 | pm_runtime_mark_last_busy(dev); |
| 676 | pm_runtime_put_autosuspend(dev); |
| 677 | |
Heiner Kallweit | 604042a | 2016-09-17 15:43:31 +0200 | [diff] [blame] | 678 | return 0; |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 679 | |
Heiner Kallweit | e9abb4d | 2015-08-26 21:21:55 +0200 | [diff] [blame] | 680 | err_pm: |
| 681 | pm_runtime_put_noidle(dev); |
| 682 | pm_runtime_disable(dev); |
| 683 | pm_runtime_set_suspended(dev); |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 684 | err_probe: |
| 685 | spi_master_put(master); |
Heiner Kallweit | 604042a | 2016-09-17 15:43:31 +0200 | [diff] [blame] | 686 | return ret; |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | static int of_fsl_espi_get_chipselects(struct device *dev) |
| 690 | { |
| 691 | struct device_node *np = dev->of_node; |
Heiner Kallweit | b497eb0 | 2016-10-01 21:07:52 +0200 | [diff] [blame] | 692 | u32 num_cs; |
| 693 | int ret; |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 694 | |
Heiner Kallweit | b497eb0 | 2016-10-01 21:07:52 +0200 | [diff] [blame] | 695 | ret = of_property_read_u32(np, "fsl,espi-num-chipselects", &num_cs); |
| 696 | if (ret) { |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 697 | dev_err(dev, "No 'fsl,espi-num-chipselects' property\n"); |
Heiner Kallweit | 7454346 | 2016-11-13 14:36:39 +0100 | [diff] [blame] | 698 | return 0; |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 699 | } |
| 700 | |
Heiner Kallweit | 7454346 | 2016-11-13 14:36:39 +0100 | [diff] [blame] | 701 | return num_cs; |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 702 | } |
| 703 | |
Grant Likely | fd4a319 | 2012-12-07 16:57:14 +0000 | [diff] [blame] | 704 | static int of_fsl_espi_probe(struct platform_device *ofdev) |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 705 | { |
| 706 | struct device *dev = &ofdev->dev; |
| 707 | struct device_node *np = ofdev->dev.of_node; |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 708 | struct resource mem; |
Heiner Kallweit | 7454346 | 2016-11-13 14:36:39 +0100 | [diff] [blame] | 709 | unsigned int irq, num_cs; |
Heiner Kallweit | acf6921 | 2016-09-17 15:43:00 +0200 | [diff] [blame] | 710 | int ret; |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 711 | |
Heiner Kallweit | e3ce4f4 | 2016-11-13 14:37:18 +0100 | [diff] [blame^] | 712 | if (of_property_read_bool(np, "mode")) { |
| 713 | dev_err(dev, "mode property is not supported on ESPI!\n"); |
| 714 | return -EINVAL; |
| 715 | } |
| 716 | |
Grant Likely | 18d306d | 2011-02-22 21:02:43 -0700 | [diff] [blame] | 717 | ret = of_mpc8xxx_spi_probe(ofdev); |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 718 | if (ret) |
| 719 | return ret; |
| 720 | |
Heiner Kallweit | 7454346 | 2016-11-13 14:36:39 +0100 | [diff] [blame] | 721 | num_cs = of_fsl_espi_get_chipselects(dev); |
| 722 | if (!num_cs) |
| 723 | return -EINVAL; |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 724 | |
| 725 | ret = of_address_to_resource(np, 0, &mem); |
| 726 | if (ret) |
Heiner Kallweit | acf6921 | 2016-09-17 15:43:00 +0200 | [diff] [blame] | 727 | return ret; |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 728 | |
Thierry Reding | f757849 | 2013-09-18 15:24:44 +0200 | [diff] [blame] | 729 | irq = irq_of_parse_and_map(np, 0); |
Heiner Kallweit | acf6921 | 2016-09-17 15:43:00 +0200 | [diff] [blame] | 730 | if (!irq) |
| 731 | return -EINVAL; |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 732 | |
Heiner Kallweit | 7454346 | 2016-11-13 14:36:39 +0100 | [diff] [blame] | 733 | return fsl_espi_probe(dev, &mem, irq, num_cs); |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 734 | } |
| 735 | |
Heiner Kallweit | e9abb4d | 2015-08-26 21:21:55 +0200 | [diff] [blame] | 736 | static int of_fsl_espi_remove(struct platform_device *dev) |
| 737 | { |
| 738 | pm_runtime_disable(&dev->dev); |
| 739 | |
| 740 | return 0; |
| 741 | } |
| 742 | |
Hou Zhiqiang | 714bb65 | 2013-12-12 12:53:52 +0800 | [diff] [blame] | 743 | #ifdef CONFIG_PM_SLEEP |
| 744 | static int of_fsl_espi_suspend(struct device *dev) |
| 745 | { |
| 746 | struct spi_master *master = dev_get_drvdata(dev); |
Hou Zhiqiang | 714bb65 | 2013-12-12 12:53:52 +0800 | [diff] [blame] | 747 | int ret; |
| 748 | |
Hou Zhiqiang | 714bb65 | 2013-12-12 12:53:52 +0800 | [diff] [blame] | 749 | ret = spi_master_suspend(master); |
| 750 | if (ret) { |
| 751 | dev_warn(dev, "cannot suspend master\n"); |
| 752 | return ret; |
| 753 | } |
| 754 | |
Heiner Kallweit | e9abb4d | 2015-08-26 21:21:55 +0200 | [diff] [blame] | 755 | ret = pm_runtime_force_suspend(dev); |
| 756 | if (ret < 0) |
| 757 | return ret; |
| 758 | |
| 759 | return 0; |
Hou Zhiqiang | 714bb65 | 2013-12-12 12:53:52 +0800 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | static int of_fsl_espi_resume(struct device *dev) |
| 763 | { |
Hou Zhiqiang | 714bb65 | 2013-12-12 12:53:52 +0800 | [diff] [blame] | 764 | struct spi_master *master = dev_get_drvdata(dev); |
| 765 | struct mpc8xxx_spi *mpc8xxx_spi; |
Hou Zhiqiang | 714bb65 | 2013-12-12 12:53:52 +0800 | [diff] [blame] | 766 | u32 regval; |
Heiner Kallweit | e9abb4d | 2015-08-26 21:21:55 +0200 | [diff] [blame] | 767 | int i, ret; |
Hou Zhiqiang | 714bb65 | 2013-12-12 12:53:52 +0800 | [diff] [blame] | 768 | |
| 769 | mpc8xxx_spi = spi_master_get_devdata(master); |
Hou Zhiqiang | 714bb65 | 2013-12-12 12:53:52 +0800 | [diff] [blame] | 770 | |
| 771 | /* SPI controller initializations */ |
Heiner Kallweit | 46afd38 | 2016-09-13 23:16:02 +0200 | [diff] [blame] | 772 | fsl_espi_write_reg(mpc8xxx_spi, ESPI_SPMODE, 0); |
| 773 | fsl_espi_write_reg(mpc8xxx_spi, ESPI_SPIM, 0); |
| 774 | fsl_espi_write_reg(mpc8xxx_spi, ESPI_SPCOM, 0); |
| 775 | fsl_espi_write_reg(mpc8xxx_spi, ESPI_SPIE, 0xffffffff); |
Hou Zhiqiang | 714bb65 | 2013-12-12 12:53:52 +0800 | [diff] [blame] | 776 | |
| 777 | /* Init eSPI CS mode register */ |
Heiner Kallweit | 7454346 | 2016-11-13 14:36:39 +0100 | [diff] [blame] | 778 | for (i = 0; i < master->num_chipselect; i++) |
Heiner Kallweit | 46afd38 | 2016-09-13 23:16:02 +0200 | [diff] [blame] | 779 | fsl_espi_write_reg(mpc8xxx_spi, ESPI_SPMODEx(i), |
| 780 | CSMODE_INIT_VAL); |
Hou Zhiqiang | 714bb65 | 2013-12-12 12:53:52 +0800 | [diff] [blame] | 781 | |
| 782 | /* Enable SPI interface */ |
Heiner Kallweit | 689d41f | 2016-11-13 14:36:01 +0100 | [diff] [blame] | 783 | regval = SPMODE_INIT_VAL | SPMODE_ENABLE; |
Hou Zhiqiang | 714bb65 | 2013-12-12 12:53:52 +0800 | [diff] [blame] | 784 | |
Heiner Kallweit | 46afd38 | 2016-09-13 23:16:02 +0200 | [diff] [blame] | 785 | fsl_espi_write_reg(mpc8xxx_spi, ESPI_SPMODE, regval); |
Hou Zhiqiang | 714bb65 | 2013-12-12 12:53:52 +0800 | [diff] [blame] | 786 | |
Heiner Kallweit | e9abb4d | 2015-08-26 21:21:55 +0200 | [diff] [blame] | 787 | ret = pm_runtime_force_resume(dev); |
| 788 | if (ret < 0) |
| 789 | return ret; |
| 790 | |
Hou Zhiqiang | 714bb65 | 2013-12-12 12:53:52 +0800 | [diff] [blame] | 791 | return spi_master_resume(master); |
| 792 | } |
| 793 | #endif /* CONFIG_PM_SLEEP */ |
| 794 | |
| 795 | static const struct dev_pm_ops espi_pm = { |
Heiner Kallweit | e9abb4d | 2015-08-26 21:21:55 +0200 | [diff] [blame] | 796 | SET_RUNTIME_PM_OPS(fsl_espi_runtime_suspend, |
| 797 | fsl_espi_runtime_resume, NULL) |
Hou Zhiqiang | 714bb65 | 2013-12-12 12:53:52 +0800 | [diff] [blame] | 798 | SET_SYSTEM_SLEEP_PM_OPS(of_fsl_espi_suspend, of_fsl_espi_resume) |
| 799 | }; |
| 800 | |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 801 | static const struct of_device_id of_fsl_espi_match[] = { |
| 802 | { .compatible = "fsl,mpc8536-espi" }, |
| 803 | {} |
| 804 | }; |
| 805 | MODULE_DEVICE_TABLE(of, of_fsl_espi_match); |
| 806 | |
Grant Likely | 18d306d | 2011-02-22 21:02:43 -0700 | [diff] [blame] | 807 | static struct platform_driver fsl_espi_driver = { |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 808 | .driver = { |
| 809 | .name = "fsl_espi", |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 810 | .of_match_table = of_fsl_espi_match, |
Hou Zhiqiang | 714bb65 | 2013-12-12 12:53:52 +0800 | [diff] [blame] | 811 | .pm = &espi_pm, |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 812 | }, |
| 813 | .probe = of_fsl_espi_probe, |
Heiner Kallweit | e9abb4d | 2015-08-26 21:21:55 +0200 | [diff] [blame] | 814 | .remove = of_fsl_espi_remove, |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 815 | }; |
Grant Likely | 940ab88 | 2011-10-05 11:29:49 -0600 | [diff] [blame] | 816 | module_platform_driver(fsl_espi_driver); |
Mingkai Hu | 8b60d6c | 2010-10-12 18:18:32 +0800 | [diff] [blame] | 817 | |
| 818 | MODULE_AUTHOR("Mingkai Hu"); |
| 819 | MODULE_DESCRIPTION("Enhanced Freescale SPI Driver"); |
| 820 | MODULE_LICENSE("GPL"); |