Lines Matching refs:pdev
128 static inline void stmSpiDataPullMode(struct StmSpiDev *pdev, enum StmGpioSpeed dataSpeed, enum GpioPullMode dataPull)
130 gpioConfigAlt(pdev->miso, dataSpeed, dataPull, GPIO_OUT_PUSH_PULL, pdev->board->gpioFunc);
131 gpioConfigAlt(pdev->mosi, dataSpeed, dataPull, GPIO_OUT_PUSH_PULL, pdev->board->gpioFunc);
134 static inline void stmSpiSckPullMode(struct StmSpiDev *pdev, enum StmGpioSpeed sckSpeed, enum GpioPullMode sckPull)
136 gpioConfigAlt(pdev->sck, sckSpeed, sckPull, GPIO_OUT_PUSH_PULL, pdev->board->gpioFunc);
139 static inline void stmSpiStartDma(struct StmSpiDev *pdev,
143 struct StmSpi *regs = pdev->cfg->regs;
162 dmaStart(pdev->cfg->dmaBus, dmaCfg->stream, buf, size, &mode, callback,
163 pdev);
166 static inline int stmSpiEnable(struct StmSpiDev *pdev,
169 struct StmSpi *regs = pdev->cfg->regs;
170 struct StmSpiState *state = &pdev->state;
181 uint32_t pclk = pwrGetBusSpeed(pdev->cfg->clockBus);
194 pwrUnitClock(pdev->cfg->clockBus, pdev->cfg->clockUnit, true);
232 struct StmSpiDev *pdev = dev->pdata;
234 int err = stmSpiEnable(pdev, mode, true);
238 stmSpiDataPullMode(pdev, pdev->board->gpioSpeed, pdev->board->gpioPull);
239 stmSpiSckPullMode(pdev, pdev->board->gpioSpeed, mode->cpol ? GPIO_PULL_UP : GPIO_PULL_DOWN);
241 if (!pdev->nss)
242 pdev->nss = gpioRequest(cs);
243 if (!pdev->nss)
245 gpioConfigOutput(pdev->nss, pdev->board->gpioSpeed, pdev->board->gpioPull, GPIO_OUT_PUSH_PULL, 1);
253 struct StmSpiDev *pdev = dev->pdata;
255 stmSpiDataPullMode(pdev, pdev->board->gpioSpeed, GPIO_PULL_NONE);
256 stmSpiSckPullMode(pdev, pdev->board->gpioSpeed, GPIO_PULL_NONE);
258 if (!pdev->nss)
259 pdev->nss = stmSpiGpioInit(pdev->board->gpioNss, pdev->board->gpioSpeed, pdev->board->gpioFunc);
260 if (!pdev->nss)
263 return stmSpiEnable(pdev, mode, false);
266 static inline bool stmSpiIsMaster(struct StmSpiDev *pdev)
268 struct StmSpi *regs = pdev->cfg->regs;
272 static void stmSpiDone(struct StmSpiDev *pdev, int err)
274 struct StmSpi *regs = pdev->cfg->regs;
275 struct StmSpiState *state = &pdev->state;
277 if (pdev->board->sleepDev >= 0)
278 platReleaseDevInSleepMode(pdev->board->sleepDev);
283 if (stmSpiIsMaster(pdev)) {
284 if (state->nssChange && pdev->nss)
285 gpioSet(pdev->nss, 1);
286 spiMasterRxTxDone(pdev->base, err);
289 spiSlaveRxTxDone(pdev->base, err);
295 struct StmSpiDev *pdev = cookie;
296 struct StmSpi *regs = pdev->cfg->regs;
297 struct StmSpiState *state = &pdev->state;
304 stmSpiDone(pdev, err);
310 struct StmSpiDev *pdev = cookie;
311 struct StmSpi *regs = pdev->cfg->regs;
312 struct StmSpiState *state = &pdev->state;
319 stmSpiDone(pdev, err);
326 struct StmSpiDev *pdev = dev->pdata;
327 struct StmSpi *regs = pdev->cfg->regs;
328 struct StmSpiState *state = &pdev->state;
335 if (stmSpiIsMaster(pdev) && pdev->nss)
336 gpioSet(pdev->nss, 0);
353 if (!rxBuf && stmSpiIsMaster(pdev)) {
359 stmSpiStartDma(pdev, &pdev->board->dmaRx, rxBuf, mode->bitsPerWord,
370 stmSpiStartDma(pdev, &pdev->board->dmaTx, txBuf, mode->bitsPerWord, txMinc,
378 if (!stmSpiIsMaster(pdev)) {
380 NVIC_ClearPendingIRQ(pdev->cfg->irq);
389 if (pdev->board->sleepDev >= 0)
390 platRequestDevInSleepMode(pdev->board->sleepDev, 12);
401 struct StmSpiDev *pdev = dev->pdata;
402 struct StmSpi *regs = pdev->cfg->regs;
403 struct StmSpiState *state = &pdev->state;
417 struct StmSpiDev *pdev = dev->pdata;
418 struct StmSpi *regs = pdev->cfg->regs;
424 stmSpiSckPullMode(pdev, pdev->board->gpioSpeed, pdev->board->gpioPull);
429 pwrUnitClock(pdev->cfg->clockBus, pdev->cfg->clockUnit, false);
434 struct StmSpiDev *pdev = dev->pdata;
436 if (pdev->nss) {
437 gpioSet(pdev->nss, 1);
438 gpioRelease(pdev->nss);
442 pdev->nss = NULL;
448 struct StmSpiDev *pdev = dev->pdata;
450 if (pdev->nss)
451 gpioRelease(pdev->nss);
454 pdev->nss = NULL;
461 struct StmSpiDev *pdev = container_of(state, struct StmSpiDev, state);
463 if (pdev->nss && !extiIsPendingGpio(pdev->nss))
466 spiSlaveCsInactive(pdev->base);
467 if (pdev->nss)
468 extiClearPendingGpio(pdev->nss);
474 struct StmSpiDev *pdev = dev->pdata;
475 struct ChainedIsr *isr = &pdev->state.isrNss;
480 if (pdev->nss) {
481 syscfgSetExtiPort(pdev->nss);
482 extiEnableIntGpio(pdev->nss, EXTI_TRIGGER_RISING);
484 extiChainIsr(pdev->board->irqNss, isr);
486 extiUnchainIsr(pdev->board->irqNss, isr);
487 if (pdev->nss)
488 extiDisableIntGpio(pdev->nss);
494 struct StmSpiDev *pdev = dev->pdata;
495 return pdev->nss && !gpioGet(pdev->nss);
498 static inline void stmSpiTxe(struct StmSpiDev *pdev)
500 struct StmSpi *regs = pdev->cfg->regs;
507 regs->DR = pdev->state.txWord;
511 static void stmSpiIsr(struct StmSpiDev *pdev)
513 struct StmSpi *regs = pdev->cfg->regs;
516 stmSpiTxe(pdev);
524 struct StmSpiDev *pdev = dev->pdata;
526 NVIC_DisableIRQ(pdev->cfg->irq);
528 pdev->base = NULL;
593 static void stmSpiInit(struct StmSpiDev *pdev, const struct StmSpiCfg *cfg,
596 pdev->miso = stmSpiGpioInit(board->gpioMiso, board->gpioSpeed, board->gpioFunc);
597 pdev->mosi = stmSpiGpioInit(board->gpioMosi, board->gpioSpeed, board->gpioFunc);
598 pdev->sck = stmSpiGpioInit(board->gpioSclk, board->gpioSpeed, board->gpioFunc);
602 pdev->base = dev;
603 pdev->cfg = cfg;
604 pdev
616 struct StmSpiDev *pdev = &mStmSpiDevs[busId];
618 if (!pdev->base)
619 stmSpiInit(pdev, cfg, board, dev);
621 memset(&pdev->state, 0, sizeof(pdev->state));
623 dev->pdata = pdev;
632 struct StmSpiDev *pdev = &mStmSpiDevs[busId];
634 return dmaIrq(pdev->cfg->dmaBus, pdev->board->dmaRx.stream);
642 struct StmSpiDev *pdev = &mStmSpiDevs[busId];
644 return dmaIrq(pdev->cfg->dmaBus, pdev->board->dmaTx.stream);