spi_mpc83xx: much improved driver

The current driver may cause glitches on SPI CLK line since one must disable
the SPI controller before changing any HW settings. Fix this by implementing
a local spi_transfer function that won't change speed and/or word size while
CS is active.

While doing that heavy lifting a few other issues were addressed too:
- Make word size 16 and 32 work too.
- Honor bits_per_word and speed_hz in spi transaction.
- Optimize the common path.

This also stops using the "bitbang" framework (except for a few constants).

[Roel Kluin <12o3l@tiscali.nl>: "irq" needs to be signed]
Signed-off-by: Joakim Tjernlund <Joakim.Tjernlund@transmode.se>
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by Joakim Tjernlund and committed by Linus Torvalds c9bfcb31 f4ed0dea

+288 -136
-1
drivers/spi/Kconfig
··· 126 126 config SPI_MPC83xx 127 127 tristate "Freescale MPC83xx/QUICC Engine SPI controller" 128 128 depends on SPI_MASTER && (PPC_83xx || QUICC_ENGINE) && EXPERIMENTAL 129 - select SPI_BITBANG 130 129 help 131 130 This enables using the Freescale MPC83xx and QUICC Engine SPI 132 131 controllers in master mode.
+288 -135
drivers/spi/spi_mpc83xx.c
··· 49 49 #define SPMODE_LEN(x) ((x) << 20) 50 50 #define SPMODE_PM(x) ((x) << 16) 51 51 #define SPMODE_OP (1 << 14) 52 + #define SPMODE_CG(x) ((x) << 7) 52 53 53 54 /* 54 55 * Default for SPI Mode: ··· 68 67 69 68 /* SPI Controller driver's private data. */ 70 69 struct mpc83xx_spi { 71 - /* bitbang has to be first */ 72 - struct spi_bitbang bitbang; 73 - struct completion done; 74 - 75 70 struct mpc83xx_spi_reg __iomem *base; 76 71 77 72 /* rx & tx bufs from the spi_transfer */ ··· 79 82 u32(*get_tx) (struct mpc83xx_spi *); 80 83 81 84 unsigned int count; 82 - u32 irq; 85 + int irq; 83 86 84 87 unsigned nsecs; /* (clock cycle time)/2 */ 85 88 ··· 91 94 92 95 void (*activate_cs) (u8 cs, u8 polarity); 93 96 void (*deactivate_cs) (u8 cs, u8 polarity); 97 + 98 + u8 busy; 99 + 100 + struct workqueue_struct *workqueue; 101 + struct work_struct work; 102 + 103 + struct list_head queue; 104 + spinlock_t lock; 105 + 106 + struct completion done; 107 + }; 108 + 109 + struct spi_mpc83xx_cs { 110 + /* functions to deal with different sized buffers */ 111 + void (*get_rx) (u32 rx_data, struct mpc83xx_spi *); 112 + u32 (*get_tx) (struct mpc83xx_spi *); 113 + u32 rx_shift; /* RX data reg shift when in qe mode */ 114 + u32 tx_shift; /* TX data reg shift when in qe mode */ 115 + u32 hw_mode; /* Holds HW mode register settings */ 94 116 }; 95 117 96 118 static inline void mpc83xx_spi_write_reg(__be32 __iomem * reg, u32 val) ··· 153 137 { 154 138 struct mpc83xx_spi *mpc83xx_spi; 155 139 u8 pol = spi->mode & SPI_CS_HIGH ? 1 : 0; 140 + struct spi_mpc83xx_cs *cs = spi->controller_state; 156 141 157 142 mpc83xx_spi = spi_master_get_devdata(spi->master); 158 143 ··· 164 147 165 148 if (value == BITBANG_CS_ACTIVE) { 166 149 u32 regval = mpc83xx_spi_read_reg(&mpc83xx_spi->base->mode); 167 - u32 len = spi->bits_per_word; 168 - u8 pm; 169 150 170 - if (len == 32) 171 - len = 0; 172 - else 173 - len = len - 1; 151 + mpc83xx_spi->rx_shift = cs->rx_shift; 152 + mpc83xx_spi->tx_shift = cs->tx_shift; 153 + mpc83xx_spi->get_rx = cs->get_rx; 154 + mpc83xx_spi->get_tx = cs->get_tx; 174 155 175 - /* mask out bits we are going to set */ 176 - regval &= ~(SPMODE_CP_BEGIN_EDGECLK | SPMODE_CI_INACTIVEHIGH 177 - | SPMODE_LEN(0xF) | SPMODE_DIV16 178 - | SPMODE_PM(0xF) | SPMODE_REV | SPMODE_LOOP); 156 + if (cs->hw_mode != regval) { 157 + unsigned long flags; 158 + void *tmp_ptr = &mpc83xx_spi->base->mode; 179 159 180 - if (spi->mode & SPI_CPHA) 181 - regval |= SPMODE_CP_BEGIN_EDGECLK; 182 - if (spi->mode & SPI_CPOL) 183 - regval |= SPMODE_CI_INACTIVEHIGH; 184 - if (!(spi->mode & SPI_LSB_FIRST)) 185 - regval |= SPMODE_REV; 186 - if (spi->mode & SPI_LOOP) 187 - regval |= SPMODE_LOOP; 188 - 189 - regval |= SPMODE_LEN(len); 190 - 191 - if ((mpc83xx_spi->spibrg / spi->max_speed_hz) >= 64) { 192 - pm = mpc83xx_spi->spibrg / (spi->max_speed_hz * 64) - 1; 193 - if (pm > 0x0f) { 194 - dev_err(&spi->dev, "Requested speed is too " 195 - "low: %d Hz. Will use %d Hz instead.\n", 196 - spi->max_speed_hz, 197 - mpc83xx_spi->spibrg / 1024); 198 - pm = 0x0f; 199 - } 200 - regval |= SPMODE_PM(pm) | SPMODE_DIV16; 201 - } else { 202 - pm = mpc83xx_spi->spibrg / (spi->max_speed_hz * 4); 203 - if (pm) 204 - pm--; 205 - regval |= SPMODE_PM(pm); 160 + regval = cs->hw_mode; 161 + /* Turn off IRQs locally to minimize time that 162 + * SPI is disabled 163 + */ 164 + local_irq_save(flags); 165 + /* Turn off SPI unit prior changing mode */ 166 + mpc83xx_spi_write_reg(tmp_ptr, regval & ~SPMODE_ENABLE); 167 + mpc83xx_spi_write_reg(tmp_ptr, regval); 168 + local_irq_restore(flags); 206 169 } 207 - 208 - /* Turn off SPI unit prior changing mode */ 209 - mpc83xx_spi_write_reg(&mpc83xx_spi->base->mode, 0); 210 - mpc83xx_spi_write_reg(&mpc83xx_spi->base->mode, regval); 211 170 if (mpc83xx_spi->activate_cs) 212 171 mpc83xx_spi->activate_cs(spi->chip_select, pol); 213 172 } ··· 194 201 { 195 202 struct mpc83xx_spi *mpc83xx_spi; 196 203 u32 regval; 197 - u8 bits_per_word; 204 + u8 bits_per_word, pm; 198 205 u32 hz; 206 + struct spi_mpc83xx_cs *cs = spi->controller_state; 199 207 200 208 mpc83xx_spi = spi_master_get_devdata(spi->master); 201 209 ··· 217 223 || ((bits_per_word > 16) && (bits_per_word != 32))) 218 224 return -EINVAL; 219 225 220 - mpc83xx_spi->rx_shift = 0; 221 - mpc83xx_spi->tx_shift = 0; 226 + if (!hz) 227 + hz = spi->max_speed_hz; 228 + 229 + cs->rx_shift = 0; 230 + cs->tx_shift = 0; 222 231 if (bits_per_word <= 8) { 223 - mpc83xx_spi->get_rx = mpc83xx_spi_rx_buf_u8; 224 - mpc83xx_spi->get_tx = mpc83xx_spi_tx_buf_u8; 232 + cs->get_rx = mpc83xx_spi_rx_buf_u8; 233 + cs->get_tx = mpc83xx_spi_tx_buf_u8; 225 234 if (mpc83xx_spi->qe_mode) { 226 - mpc83xx_spi->rx_shift = 16; 227 - mpc83xx_spi->tx_shift = 24; 235 + cs->rx_shift = 16; 236 + cs->tx_shift = 24; 228 237 } 229 238 } else if (bits_per_word <= 16) { 230 - mpc83xx_spi->get_rx = mpc83xx_spi_rx_buf_u16; 231 - mpc83xx_spi->get_tx = mpc83xx_spi_tx_buf_u16; 239 + cs->get_rx = mpc83xx_spi_rx_buf_u16; 240 + cs->get_tx = mpc83xx_spi_tx_buf_u16; 232 241 if (mpc83xx_spi->qe_mode) { 233 - mpc83xx_spi->rx_shift = 16; 234 - mpc83xx_spi->tx_shift = 16; 242 + cs->rx_shift = 16; 243 + cs->tx_shift = 16; 235 244 } 236 245 } else if (bits_per_word <= 32) { 237 - mpc83xx_spi->get_rx = mpc83xx_spi_rx_buf_u32; 238 - mpc83xx_spi->get_tx = mpc83xx_spi_tx_buf_u32; 246 + cs->get_rx = mpc83xx_spi_rx_buf_u32; 247 + cs->get_tx = mpc83xx_spi_tx_buf_u32; 239 248 } else 240 249 return -EINVAL; 241 250 242 251 if (mpc83xx_spi->qe_mode && spi->mode & SPI_LSB_FIRST) { 243 - mpc83xx_spi->tx_shift = 0; 252 + cs->tx_shift = 0; 244 253 if (bits_per_word <= 8) 245 - mpc83xx_spi->rx_shift = 8; 254 + cs->rx_shift = 8; 246 255 else 247 - mpc83xx_spi->rx_shift = 0; 256 + cs->rx_shift = 0; 248 257 } 249 258 250 - /* nsecs = (clock period)/2 */ 251 - if (!hz) 252 - hz = spi->max_speed_hz; 253 - mpc83xx_spi->nsecs = (1000000000 / 2) / hz; 254 - if (mpc83xx_spi->nsecs > MAX_UDELAY_MS * 1000) 255 - return -EINVAL; 259 + mpc83xx_spi->rx_shift = cs->rx_shift; 260 + mpc83xx_spi->tx_shift = cs->tx_shift; 261 + mpc83xx_spi->get_rx = cs->get_rx; 262 + mpc83xx_spi->get_tx = cs->get_tx; 256 263 257 264 if (bits_per_word == 32) 258 265 bits_per_word = 0; 259 266 else 260 267 bits_per_word = bits_per_word - 1; 261 268 262 - regval = mpc83xx_spi_read_reg(&mpc83xx_spi->base->mode); 263 - 264 269 /* mask out bits we are going to set */ 265 - regval &= ~(SPMODE_LEN(0xF) | SPMODE_REV); 266 - regval |= SPMODE_LEN(bits_per_word); 267 - if (!(spi->mode & SPI_LSB_FIRST)) 268 - regval |= SPMODE_REV; 270 + cs->hw_mode &= ~(SPMODE_LEN(0xF) | SPMODE_DIV16 271 + | SPMODE_PM(0xF)); 269 272 270 - /* Turn off SPI unit prior changing mode */ 271 - mpc83xx_spi_write_reg(&mpc83xx_spi->base->mode, 0); 272 - mpc83xx_spi_write_reg(&mpc83xx_spi->base->mode, regval); 273 + cs->hw_mode |= SPMODE_LEN(bits_per_word); 273 274 274 - return 0; 275 - } 276 - 277 - /* the spi->mode bits understood by this driver: */ 278 - #define MODEBITS (SPI_CPOL | SPI_CPHA | SPI_CS_HIGH \ 279 - | SPI_LSB_FIRST | SPI_LOOP) 280 - 281 - static int mpc83xx_spi_setup(struct spi_device *spi) 282 - { 283 - struct spi_bitbang *bitbang; 284 - struct mpc83xx_spi *mpc83xx_spi; 285 - int retval; 286 - 287 - if (spi->mode & ~MODEBITS) { 288 - dev_dbg(&spi->dev, "setup: unsupported mode bits %x\n", 289 - spi->mode & ~MODEBITS); 290 - return -EINVAL; 275 + if ((mpc83xx_spi->spibrg / hz) >= 64) { 276 + pm = mpc83xx_spi->spibrg / (hz * 64) - 1; 277 + if (pm > 0x0f) { 278 + dev_err(&spi->dev, "Requested speed is too " 279 + "low: %d Hz. Will use %d Hz instead.\n", 280 + hz, mpc83xx_spi->spibrg / 1024); 281 + pm = 0x0f; 282 + } 283 + cs->hw_mode |= SPMODE_PM(pm) | SPMODE_DIV16; 284 + } else { 285 + pm = mpc83xx_spi->spibrg / (hz * 4); 286 + if (pm) 287 + pm--; 288 + cs->hw_mode |= SPMODE_PM(pm); 291 289 } 290 + regval = mpc83xx_spi_read_reg(&mpc83xx_spi->base->mode); 291 + if (cs->hw_mode != regval) { 292 + unsigned long flags; 293 + void *tmp_ptr = &mpc83xx_spi->base->mode; 292 294 293 - if (!spi->max_speed_hz) 294 - return -EINVAL; 295 - 296 - bitbang = spi_master_get_devdata(spi->master); 297 - mpc83xx_spi = spi_master_get_devdata(spi->master); 298 - 299 - if (!spi->bits_per_word) 300 - spi->bits_per_word = 8; 301 - 302 - retval = mpc83xx_spi_setup_transfer(spi, NULL); 303 - if (retval < 0) 304 - return retval; 305 - 306 - dev_dbg(&spi->dev, "%s, mode %d, %u bits/w, %u nsec\n", 307 - __func__, spi->mode & (SPI_CPOL | SPI_CPHA), 308 - spi->bits_per_word, 2 * mpc83xx_spi->nsecs); 309 - 310 - /* NOTE we _need_ to call chipselect() early, ideally with adapter 311 - * setup, unless the hardware defaults cooperate to avoid confusion 312 - * between normal (active low) and inverted chipselects. 313 - */ 314 - 315 - /* deselect chip (low or high) */ 316 - spin_lock(&bitbang->lock); 317 - if (!bitbang->busy) { 318 - bitbang->chipselect(spi, BITBANG_CS_INACTIVE); 319 - ndelay(mpc83xx_spi->nsecs); 295 + regval = cs->hw_mode; 296 + /* Turn off IRQs locally to minimize time 297 + * that SPI is disabled 298 + */ 299 + local_irq_save(flags); 300 + /* Turn off SPI unit prior changing mode */ 301 + mpc83xx_spi_write_reg(tmp_ptr, regval & ~SPMODE_ENABLE); 302 + mpc83xx_spi_write_reg(tmp_ptr, regval); 303 + local_irq_restore(flags); 320 304 } 321 - spin_unlock(&bitbang->lock); 322 - 323 305 return 0; 324 306 } 325 307 326 308 static int mpc83xx_spi_bufs(struct spi_device *spi, struct spi_transfer *t) 327 309 { 328 310 struct mpc83xx_spi *mpc83xx_spi; 329 - u32 word; 311 + u32 word, len, bits_per_word; 330 312 331 313 mpc83xx_spi = spi_master_get_devdata(spi->master); 332 314 333 315 mpc83xx_spi->tx = t->tx_buf; 334 316 mpc83xx_spi->rx = t->rx_buf; 335 - mpc83xx_spi->count = t->len; 317 + bits_per_word = spi->bits_per_word; 318 + if (t->bits_per_word) 319 + bits_per_word = t->bits_per_word; 320 + len = t->len; 321 + if (bits_per_word > 8) 322 + len /= 2; 323 + if (bits_per_word > 16) 324 + len /= 2; 325 + mpc83xx_spi->count = len; 336 326 INIT_COMPLETION(mpc83xx_spi->done); 337 327 338 328 /* enable rx ints */ ··· 331 353 /* disable rx ints */ 332 354 mpc83xx_spi_write_reg(&mpc83xx_spi->base->mask, 0); 333 355 334 - return t->len - mpc83xx_spi->count; 356 + return mpc83xx_spi->count; 357 + } 358 + 359 + static void mpc83xx_spi_work(struct work_struct *work) 360 + { 361 + struct mpc83xx_spi *mpc83xx_spi = 362 + container_of(work, struct mpc83xx_spi, work); 363 + 364 + spin_lock_irq(&mpc83xx_spi->lock); 365 + mpc83xx_spi->busy = 1; 366 + while (!list_empty(&mpc83xx_spi->queue)) { 367 + struct spi_message *m; 368 + struct spi_device *spi; 369 + struct spi_transfer *t = NULL; 370 + unsigned cs_change; 371 + int status, nsecs = 50; 372 + 373 + m = container_of(mpc83xx_spi->queue.next, 374 + struct spi_message, queue); 375 + list_del_init(&m->queue); 376 + spin_unlock_irq(&mpc83xx_spi->lock); 377 + 378 + spi = m->spi; 379 + cs_change = 1; 380 + status = 0; 381 + list_for_each_entry(t, &m->transfers, transfer_list) { 382 + if (t->bits_per_word || t->speed_hz) { 383 + /* Don't allow changes if CS is active */ 384 + status = -EINVAL; 385 + 386 + if (cs_change) 387 + status = mpc83xx_spi_setup_transfer(spi, t); 388 + if (status < 0) 389 + break; 390 + } 391 + 392 + if (cs_change) 393 + mpc83xx_spi_chipselect(spi, BITBANG_CS_ACTIVE); 394 + cs_change = t->cs_change; 395 + if (t->len) 396 + status = mpc83xx_spi_bufs(spi, t); 397 + if (status) { 398 + status = -EMSGSIZE; 399 + break; 400 + } 401 + m->actual_length += t->len; 402 + 403 + if (t->delay_usecs) 404 + udelay(t->delay_usecs); 405 + 406 + if (cs_change) { 407 + ndelay(nsecs); 408 + mpc83xx_spi_chipselect(spi, BITBANG_CS_INACTIVE); 409 + ndelay(nsecs); 410 + } 411 + } 412 + 413 + m->status = status; 414 + m->complete(m->context); 415 + 416 + if (status || !cs_change) { 417 + ndelay(nsecs); 418 + mpc83xx_spi_chipselect(spi, BITBANG_CS_INACTIVE); 419 + } 420 + 421 + mpc83xx_spi_setup_transfer(spi, NULL); 422 + 423 + spin_lock_irq(&mpc83xx_spi->lock); 424 + } 425 + mpc83xx_spi->busy = 0; 426 + spin_unlock_irq(&mpc83xx_spi->lock); 427 + } 428 + 429 + /* the spi->mode bits understood by this driver: */ 430 + #define MODEBITS (SPI_CPOL | SPI_CPHA | SPI_CS_HIGH \ 431 + | SPI_LSB_FIRST | SPI_LOOP) 432 + 433 + static int mpc83xx_spi_setup(struct spi_device *spi) 434 + { 435 + struct mpc83xx_spi *mpc83xx_spi; 436 + int retval; 437 + u32 hw_mode; 438 + struct spi_mpc83xx_cs *cs = spi->controller_state; 439 + 440 + if (spi->mode & ~MODEBITS) { 441 + dev_dbg(&spi->dev, "setup: unsupported mode bits %x\n", 442 + spi->mode & ~MODEBITS); 443 + return -EINVAL; 444 + } 445 + 446 + if (!spi->max_speed_hz) 447 + return -EINVAL; 448 + 449 + if (!cs) { 450 + cs = kzalloc(sizeof *cs, GFP_KERNEL); 451 + if (!cs) 452 + return -ENOMEM; 453 + spi->controller_state = cs; 454 + } 455 + mpc83xx_spi = spi_master_get_devdata(spi->master); 456 + 457 + if (!spi->bits_per_word) 458 + spi->bits_per_word = 8; 459 + 460 + hw_mode = cs->hw_mode; /* Save orginal settings */ 461 + cs->hw_mode = mpc83xx_spi_read_reg(&mpc83xx_spi->base->mode); 462 + /* mask out bits we are going to set */ 463 + cs->hw_mode &= ~(SPMODE_CP_BEGIN_EDGECLK | SPMODE_CI_INACTIVEHIGH 464 + | SPMODE_REV | SPMODE_LOOP); 465 + 466 + if (spi->mode & SPI_CPHA) 467 + cs->hw_mode |= SPMODE_CP_BEGIN_EDGECLK; 468 + if (spi->mode & SPI_CPOL) 469 + cs->hw_mode |= SPMODE_CI_INACTIVEHIGH; 470 + if (!(spi->mode & SPI_LSB_FIRST)) 471 + cs->hw_mode |= SPMODE_REV; 472 + if (spi->mode & SPI_LOOP) 473 + cs->hw_mode |= SPMODE_LOOP; 474 + 475 + retval = mpc83xx_spi_setup_transfer(spi, NULL); 476 + if (retval < 0) { 477 + cs->hw_mode = hw_mode; /* Restore settings */ 478 + return retval; 479 + } 480 + 481 + dev_dbg(&spi->dev, "%s, mode %d, %u bits/w, %u Hz\n", 482 + __func__, spi->mode & (SPI_CPOL | SPI_CPHA), 483 + spi->bits_per_word, spi->max_speed_hz); 484 + #if 0 /* Don't think this is needed */ 485 + /* NOTE we _need_ to call chipselect() early, ideally with adapter 486 + * setup, unless the hardware defaults cooperate to avoid confusion 487 + * between normal (active low) and inverted chipselects. 488 + */ 489 + 490 + /* deselect chip (low or high) */ 491 + spin_lock(&mpc83xx_spi->lock); 492 + if (!mpc83xx_spi->busy) 493 + mpc83xx_spi_chipselect(spi, BITBANG_CS_INACTIVE); 494 + spin_unlock(&mpc83xx_spi->lock); 495 + #endif 496 + return 0; 335 497 } 336 498 337 499 irqreturn_t mpc83xx_spi_irq(s32 irq, void *context_data) ··· 513 395 514 396 return ret; 515 397 } 398 + static int mpc83xx_spi_transfer(struct spi_device *spi, 399 + struct spi_message *m) 400 + { 401 + struct mpc83xx_spi *mpc83xx_spi = spi_master_get_devdata(spi->master); 402 + unsigned long flags; 403 + 404 + m->actual_length = 0; 405 + m->status = -EINPROGRESS; 406 + 407 + spin_lock_irqsave(&mpc83xx_spi->lock, flags); 408 + list_add_tail(&m->queue, &mpc83xx_spi->queue); 409 + queue_work(mpc83xx_spi->workqueue, &mpc83xx_spi->work); 410 + spin_unlock_irqrestore(&mpc83xx_spi->lock, flags); 411 + 412 + return 0; 413 + } 414 + 415 + 416 + static void mpc83xx_spi_cleanup(struct spi_device *spi) 417 + { 418 + kfree(spi->controller_state); 419 + } 516 420 517 421 static int __init mpc83xx_spi_probe(struct platform_device *dev) 518 422 { ··· 566 426 ret = -ENODEV; 567 427 goto free_master; 568 428 } 429 + master->setup = mpc83xx_spi_setup; 430 + master->transfer = mpc83xx_spi_transfer; 431 + master->cleanup = mpc83xx_spi_cleanup; 432 + 569 433 mpc83xx_spi = spi_master_get_devdata(master); 570 - mpc83xx_spi->bitbang.master = spi_master_get(master); 571 - mpc83xx_spi->bitbang.chipselect = mpc83xx_spi_chipselect; 572 - mpc83xx_spi->bitbang.setup_transfer = mpc83xx_spi_setup_transfer; 573 - mpc83xx_spi->bitbang.txrx_bufs = mpc83xx_spi_bufs; 574 434 mpc83xx_spi->activate_cs = pdata->activate_cs; 575 435 mpc83xx_spi->deactivate_cs = pdata->deactivate_cs; 576 436 mpc83xx_spi->qe_mode = pdata->qe_mode; ··· 585 445 mpc83xx_spi->tx_shift = 24; 586 446 } 587 447 588 - mpc83xx_spi->bitbang.master->setup = mpc83xx_spi_setup; 589 448 init_completion(&mpc83xx_spi->done); 590 449 591 450 mpc83xx_spi->base = ioremap(r->start, r->end - r->start + 1); ··· 622 483 regval |= SPMODE_OP; 623 484 624 485 mpc83xx_spi_write_reg(&mpc83xx_spi->base->mode, regval); 486 + spin_lock_init(&mpc83xx_spi->lock); 487 + init_completion(&mpc83xx_spi->done); 488 + INIT_WORK(&mpc83xx_spi->work, mpc83xx_spi_work); 489 + INIT_LIST_HEAD(&mpc83xx_spi->queue); 625 490 626 - ret = spi_bitbang_start(&mpc83xx_spi->bitbang); 627 - 628 - if (ret != 0) 491 + mpc83xx_spi->workqueue = create_singlethread_workqueue( 492 + master->dev.parent->bus_id); 493 + if (mpc83xx_spi->workqueue == NULL) { 494 + ret = -EBUSY; 629 495 goto free_irq; 496 + } 497 + 498 + ret = spi_register_master(master); 499 + if (ret < 0) 500 + goto unreg_master; 630 501 631 502 printk(KERN_INFO 632 503 "%s: MPC83xx SPI Controller driver at 0x%p (irq = %d)\n", ··· 644 495 645 496 return ret; 646 497 498 + unreg_master: 499 + destroy_workqueue(mpc83xx_spi->workqueue); 647 500 free_irq: 648 501 free_irq(mpc83xx_spi->irq, mpc83xx_spi); 649 502 unmap_io: ··· 666 515 master = platform_get_drvdata(dev); 667 516 mpc83xx_spi = spi_master_get_devdata(master); 668 517 669 - spi_bitbang_stop(&mpc83xx_spi->bitbang); 518 + flush_workqueue(mpc83xx_spi->workqueue); 519 + destroy_workqueue(mpc83xx_spi->workqueue); 520 + spi_unregister_master(master); 521 + 670 522 free_irq(mpc83xx_spi->irq, mpc83xx_spi); 671 523 iounmap(mpc83xx_spi->base); 672 - spi_master_put(mpc83xx_spi->bitbang.master); 673 524 674 525 return 0; 675 526 }