Merge series "spi: pxa2xx: Set of cleanups" from Andy Shevchenko <andriy.shevchenko@linux.intel.com>:

Set of cleanups here and there related to the SPI PXA2xx driver.
On top of them, adding the special type for Intel Merrifield.

In v2:
- cover letter (Mark)
- drop moving the header in patch 5 (Mark)

Andy Shevchenko (14):
  spi: pxa2xx: Use one point of return when ->probe() fails
  spi: pxa2xx: Utilize MMIO and physical base from struct ssp_device
  spi: pxa2xx: Utilize struct device from struct ssp_device
  spi: pxa2xx: Replace header inclusions by forward declarations
  spi: pxa2xx: Unify ifdeffery used in the headers
  spi: pxa2xx: Group Intel Quark specific definitions
  spi: pxa2xx: Introduce int_stop_and_reset() helper
  spi: pxa2xx: Reuse int_error_stop() in pxa2xx_spi_slave_abort()
  spi: pxa2xx: Use pxa_ssp_enable()/pxa_ssp_disable() in the driver
  spi: pxa2xx: Extract pxa2xx_spi_update() helper
  spi: pxa2xx: Extract clear_SSCR1_bits() helper
  spi: pxa2xx: Extract read_SSSR_bits() helper
  spi: pxa2xx: Constify struct driver_data parameter
  spi: pxa2xx: Introduce special type for Merrifield SPIs

 drivers/spi/spi-pxa2xx-dma.c   |  37 +++----
 drivers/spi/spi-pxa2xx-pci.c   |   4 +-
 drivers/spi/spi-pxa2xx.c       | 190 +++++++++++++++++----------------
 drivers/spi/spi-pxa2xx.h       |  52 ++++-----
 include/linux/pxa2xx_ssp.h     |  42 +++++++-
 include/linux/spi/pxa2xx_spi.h |   9 +-
 sound/soc/pxa/pxa-ssp.c        |  16 ---
 7 files changed, 185 insertions(+), 165 deletions(-)

--
2.30.2
This commit is contained in:
Mark Brown 2021-05-11 09:06:06 +01:00
commit bf2509a455
No known key found for this signature in database
GPG Key ID: 24D68B725D5487D0
6 changed files with 47 additions and 52 deletions

View File

@ -9,11 +9,11 @@
#include <linux/device.h> #include <linux/device.h>
#include <linux/dma-mapping.h> #include <linux/dma-mapping.h>
#include <linux/dmaengine.h> #include <linux/dmaengine.h>
#include <linux/pxa2xx_ssp.h>
#include <linux/scatterlist.h> #include <linux/scatterlist.h>
#include <linux/sizes.h> #include <linux/sizes.h>
#include <linux/spi/spi.h>
#include <linux/spi/pxa2xx_spi.h> #include <linux/spi/pxa2xx_spi.h>
#include <linux/spi/spi.h>
#include "spi-pxa2xx.h" #include "spi-pxa2xx.h"
@ -94,14 +94,14 @@ pxa2xx_spi_dma_prepare_one(struct driver_data *drv_data,
cfg.direction = dir; cfg.direction = dir;
if (dir == DMA_MEM_TO_DEV) { if (dir == DMA_MEM_TO_DEV) {
cfg.dst_addr = drv_data->ssdr_physical; cfg.dst_addr = drv_data->ssp->phys_base + SSDR;
cfg.dst_addr_width = width; cfg.dst_addr_width = width;
cfg.dst_maxburst = chip->dma_burst_size; cfg.dst_maxburst = chip->dma_burst_size;
sgt = &xfer->tx_sg; sgt = &xfer->tx_sg;
chan = drv_data->controller->dma_tx; chan = drv_data->controller->dma_tx;
} else { } else {
cfg.src_addr = drv_data->ssdr_physical; cfg.src_addr = drv_data->ssp->phys_base + SSDR;
cfg.src_addr_width = width; cfg.src_addr_width = width;
cfg.src_maxburst = chip->dma_burst_size; cfg.src_maxburst = chip->dma_burst_size;
@ -111,7 +111,7 @@ pxa2xx_spi_dma_prepare_one(struct driver_data *drv_data,
ret = dmaengine_slave_config(chan, &cfg); ret = dmaengine_slave_config(chan, &cfg);
if (ret) { if (ret) {
dev_warn(&drv_data->pdev->dev, "DMA slave config failed\n"); dev_warn(drv_data->ssp->dev, "DMA slave config failed\n");
return NULL; return NULL;
} }
@ -125,7 +125,7 @@ irqreturn_t pxa2xx_spi_dma_transfer(struct driver_data *drv_data)
status = pxa2xx_spi_read(drv_data, SSSR) & drv_data->mask_sr; status = pxa2xx_spi_read(drv_data, SSSR) & drv_data->mask_sr;
if (status & SSSR_ROR) { if (status & SSSR_ROR) {
dev_err(&drv_data->pdev->dev, "FIFO overrun\n"); dev_err(drv_data->ssp->dev, "FIFO overrun\n");
dmaengine_terminate_async(drv_data->controller->dma_rx); dmaengine_terminate_async(drv_data->controller->dma_rx);
dmaengine_terminate_async(drv_data->controller->dma_tx); dmaengine_terminate_async(drv_data->controller->dma_tx);
@ -145,16 +145,14 @@ int pxa2xx_spi_dma_prepare(struct driver_data *drv_data,
tx_desc = pxa2xx_spi_dma_prepare_one(drv_data, DMA_MEM_TO_DEV, xfer); tx_desc = pxa2xx_spi_dma_prepare_one(drv_data, DMA_MEM_TO_DEV, xfer);
if (!tx_desc) { if (!tx_desc) {
dev_err(&drv_data->pdev->dev, dev_err(drv_data->ssp->dev, "failed to get DMA TX descriptor\n");
"failed to get DMA TX descriptor\n");
err = -EBUSY; err = -EBUSY;
goto err_tx; goto err_tx;
} }
rx_desc = pxa2xx_spi_dma_prepare_one(drv_data, DMA_DEV_TO_MEM, xfer); rx_desc = pxa2xx_spi_dma_prepare_one(drv_data, DMA_DEV_TO_MEM, xfer);
if (!rx_desc) { if (!rx_desc) {
dev_err(&drv_data->pdev->dev, dev_err(drv_data->ssp->dev, "failed to get DMA RX descriptor\n");
"failed to get DMA RX descriptor\n");
err = -EBUSY; err = -EBUSY;
goto err_rx; goto err_rx;
} }
@ -191,8 +189,8 @@ void pxa2xx_spi_dma_stop(struct driver_data *drv_data)
int pxa2xx_spi_dma_setup(struct driver_data *drv_data) int pxa2xx_spi_dma_setup(struct driver_data *drv_data)
{ {
struct pxa2xx_spi_controller *pdata = drv_data->controller_info; struct pxa2xx_spi_controller *pdata = drv_data->controller_info;
struct device *dev = &drv_data->pdev->dev;
struct spi_controller *controller = drv_data->controller; struct spi_controller *controller = drv_data->controller;
struct device *dev = drv_data->ssp->dev;
dma_cap_mask_t mask; dma_cap_mask_t mask;
dma_cap_zero(mask); dma_cap_zero(mask);

View File

@ -8,6 +8,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/pci.h> #include <linux/pci.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/spi/pxa2xx_spi.h> #include <linux/spi/pxa2xx_spi.h>
#include <linux/dmaengine.h> #include <linux/dmaengine.h>
@ -239,6 +240,7 @@ static int pxa2xx_spi_pci_probe(struct pci_dev *dev,
spi_pdata.dma_burst_size = c->dma_burst_size ? c->dma_burst_size : 1; spi_pdata.dma_burst_size = c->dma_burst_size ? c->dma_burst_size : 1;
ssp = &spi_pdata.ssp; ssp = &spi_pdata.ssp;
ssp->dev = &dev->dev;
ssp->phys_base = pci_resource_start(dev, 0); ssp->phys_base = pci_resource_start(dev, 0);
ssp->mmio_base = pcim_iomap_table(dev)[0]; ssp->mmio_base = pcim_iomap_table(dev)[0];
ssp->port_id = (c->port_id >= 0) ? c->port_id : dev->devfn; ssp->port_id = (c->port_id >= 0) ? c->port_id : dev->devfn;

View File

@ -9,6 +9,7 @@
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/device.h> #include <linux/device.h>
#include <linux/dmaengine.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/gpio/consumer.h> #include <linux/gpio/consumer.h>
@ -25,6 +26,7 @@
#include <linux/pm_runtime.h> #include <linux/pm_runtime.h>
#include <linux/property.h> #include <linux/property.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/spi/pxa2xx_spi.h> #include <linux/spi/pxa2xx_spi.h>
#include <linux/spi/spi.h> #include <linux/spi/spi.h>
@ -325,7 +327,7 @@ static void lpss_ssp_setup(struct driver_data *drv_data)
u32 value; u32 value;
config = lpss_get_config(drv_data); config = lpss_get_config(drv_data);
drv_data->lpss_base = drv_data->ioaddr + config->offset; drv_data->lpss_base = drv_data->ssp->mmio_base + config->offset;
/* Enable software chip select control */ /* Enable software chip select control */
value = __lpss_ssp_read_priv(drv_data, config->reg_cs_ctrl); value = __lpss_ssp_read_priv(drv_data, config->reg_cs_ctrl);
@ -628,7 +630,7 @@ static void int_error_stop(struct driver_data *drv_data, const char *msg)
pxa2xx_spi_flush(drv_data); pxa2xx_spi_flush(drv_data);
pxa2xx_spi_off(drv_data); pxa2xx_spi_off(drv_data);
dev_err(&drv_data->pdev->dev, "%s\n", msg); dev_err(drv_data->ssp->dev, "%s\n", msg);
drv_data->controller->cur_msg->status = -EIO; drv_data->controller->cur_msg->status = -EIO;
spi_finalize_current_transfer(drv_data->controller); spi_finalize_current_transfer(drv_data->controller);
@ -731,8 +733,7 @@ static void handle_bad_msg(struct driver_data *drv_data)
pxa2xx_spi_write(drv_data, SSTO, 0); pxa2xx_spi_write(drv_data, SSTO, 0);
write_SSSR_CS(drv_data, drv_data->clear_sr); write_SSSR_CS(drv_data, drv_data->clear_sr);
dev_err(&drv_data->pdev->dev, dev_err(drv_data->ssp->dev, "bad message state in interrupt handler\n");
"bad message state in interrupt handler\n");
} }
static irqreturn_t ssp_int(int irq, void *dev_id) static irqreturn_t ssp_int(int irq, void *dev_id)
@ -748,7 +749,7 @@ static irqreturn_t ssp_int(int irq, void *dev_id)
* the IRQ was not for us (we shouldn't be RPM suspended when the * the IRQ was not for us (we shouldn't be RPM suspended when the
* interrupt is enabled). * interrupt is enabled).
*/ */
if (pm_runtime_suspended(&drv_data->pdev->dev)) if (pm_runtime_suspended(drv_data->ssp->dev))
return IRQ_NONE; return IRQ_NONE;
/* /*
@ -1158,7 +1159,7 @@ static int pxa2xx_spi_slave_abort(struct spi_controller *controller)
pxa2xx_spi_flush(drv_data); pxa2xx_spi_flush(drv_data);
pxa2xx_spi_off(drv_data); pxa2xx_spi_off(drv_data);
dev_dbg(&drv_data->pdev->dev, "transfer aborted\n"); dev_dbg(drv_data->ssp->dev, "transfer aborted\n");
drv_data->controller->cur_msg->status = -EINTR; drv_data->controller->cur_msg->status = -EINTR;
spi_finalize_current_transfer(drv_data->controller); spi_finalize_current_transfer(drv_data->controller);
@ -1645,7 +1646,7 @@ static int pxa2xx_spi_fw_translate_cs(struct spi_controller *controller,
{ {
struct driver_data *drv_data = spi_controller_get_devdata(controller); struct driver_data *drv_data = spi_controller_get_devdata(controller);
if (has_acpi_companion(&drv_data->pdev->dev)) { if (has_acpi_companion(drv_data->ssp->dev)) {
switch (drv_data->ssp_type) { switch (drv_data->ssp_type) {
/* /*
* For Atoms the ACPI DeviceSelection used by the Windows * For Atoms the ACPI DeviceSelection used by the Windows
@ -1705,13 +1706,12 @@ static int pxa2xx_spi_probe(struct platform_device *pdev)
if (!controller) { if (!controller) {
dev_err(&pdev->dev, "cannot alloc spi_controller\n"); dev_err(&pdev->dev, "cannot alloc spi_controller\n");
pxa_ssp_free(ssp); status = -ENOMEM;
return -ENOMEM; goto out_error_controller_alloc;
} }
drv_data = spi_controller_get_devdata(controller); drv_data = spi_controller_get_devdata(controller);
drv_data->controller = controller; drv_data->controller = controller;
drv_data->controller_info = platform_info; drv_data->controller_info = platform_info;
drv_data->pdev = pdev;
drv_data->ssp = ssp; drv_data->ssp = ssp;
controller->dev.of_node = pdev->dev.of_node; controller->dev.of_node = pdev->dev.of_node;
@ -1733,8 +1733,6 @@ static int pxa2xx_spi_probe(struct platform_device *pdev)
drv_data->ssp_type = ssp->type; drv_data->ssp_type = ssp->type;
drv_data->ioaddr = ssp->mmio_base;
drv_data->ssdr_physical = ssp->phys_base + SSDR;
if (pxa25x_ssp_comp(drv_data)) { if (pxa25x_ssp_comp(drv_data)) {
switch (drv_data->ssp_type) { switch (drv_data->ssp_type) {
case QUARK_X1000_SSP: case QUARK_X1000_SSP:

View File

@ -7,22 +7,20 @@
#ifndef SPI_PXA2XX_H #ifndef SPI_PXA2XX_H
#define SPI_PXA2XX_H #define SPI_PXA2XX_H
#include <linux/atomic.h>
#include <linux/dmaengine.h>
#include <linux/errno.h>
#include <linux/io.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/platform_device.h> #include <linux/io.h>
#include <linux/pxa2xx_ssp.h> #include <linux/types.h>
#include <linux/scatterlist.h>
#include <linux/sizes.h> #include <linux/sizes.h>
#include <linux/spi/spi.h>
#include <linux/spi/pxa2xx_spi.h> #include <linux/pxa2xx_ssp.h>
struct gpio_desc;
struct pxa2xx_spi_controller;
struct spi_controller;
struct spi_device;
struct spi_transfer;
struct driver_data { struct driver_data {
/* Driver model hookup */
struct platform_device *pdev;
/* SSP Info */ /* SSP Info */
struct ssp_device *ssp; struct ssp_device *ssp;
@ -33,10 +31,6 @@ struct driver_data {
/* PXA hookup */ /* PXA hookup */
struct pxa2xx_spi_controller *controller_info; struct pxa2xx_spi_controller *controller_info;
/* SSP register addresses */
void __iomem *ioaddr;
phys_addr_t ssdr_physical;
/* SSP masks*/ /* SSP masks*/
u32 dma_cr1; u32 dma_cr1;
u32 int_cr1; u32 int_cr1;
@ -87,16 +81,14 @@ struct chip_data {
void (*cs_control)(u32 command); void (*cs_control)(u32 command);
}; };
static inline u32 pxa2xx_spi_read(const struct driver_data *drv_data, static inline u32 pxa2xx_spi_read(const struct driver_data *drv_data, u32 reg)
unsigned reg)
{ {
return __raw_readl(drv_data->ioaddr + reg); return pxa_ssp_read_reg(drv_data->ssp, reg);
} }
static inline void pxa2xx_spi_write(const struct driver_data *drv_data, static inline void pxa2xx_spi_write(const struct driver_data *drv_data, u32 reg, u32 val)
unsigned reg, u32 val)
{ {
__raw_writel(val, drv_data->ioaddr + reg); pxa_ssp_write_reg(drv_data->ssp, reg, val);
} }
#define DMA_ALIGNMENT 8 #define DMA_ALIGNMENT 8

View File

@ -11,8 +11,8 @@
* PXA3xx SSP1, SSP2, SSP3, SSP4 * PXA3xx SSP1, SSP2, SSP3, SSP4
*/ */
#ifndef __LINUX_SSP_H #ifndef __LINUX_PXA2XX_SSP_H
#define __LINUX_SSP_H #define __LINUX_PXA2XX_SSP_H
#include <linux/bits.h> #include <linux/bits.h>
#include <linux/compiler_types.h> #include <linux/compiler_types.h>
@ -38,7 +38,6 @@ struct device_node;
#define SSDR (0x10) /* SSP Data Write/Data Read Register */ #define SSDR (0x10) /* SSP Data Write/Data Read Register */
#define SSTO (0x28) /* SSP Time Out Register */ #define SSTO (0x28) /* SSP Time Out Register */
#define DDS_RATE (0x28) /* SSP DDS Clock Rate Register (Intel Quark) */
#define SSPSP (0x2C) /* SSP Programmable Serial Protocol */ #define SSPSP (0x2C) /* SSP Programmable Serial Protocol */
#define SSTSA (0x30) /* SSP Tx Timeslot Active */ #define SSTSA (0x30) /* SSP Tx Timeslot Active */
#define SSRSA (0x34) /* SSP Rx Timeslot Active */ #define SSRSA (0x34) /* SSP Rx Timeslot Active */
@ -105,6 +104,9 @@ struct device_node;
#define CE4100_SSCR1_RFT GENMASK(11, 10) /* Receive FIFO Threshold (mask) */ #define CE4100_SSCR1_RFT GENMASK(11, 10) /* Receive FIFO Threshold (mask) */
#define CE4100_SSCR1_RxTresh(x) (((x) - 1) << 10) /* level [1..4] */ #define CE4100_SSCR1_RxTresh(x) (((x) - 1) << 10) /* level [1..4] */
/* Intel Quark X1000 */
#define DDS_RATE 0x28 /* SSP DDS Clock Rate Register */
/* QUARK_X1000 SSCR0 bit definition */ /* QUARK_X1000 SSCR0 bit definition */
#define QUARK_X1000_SSCR0_DSS GENMASK(4, 0) /* Data Size Select (mask) */ #define QUARK_X1000_SSCR0_DSS GENMASK(4, 0) /* Data Size Select (mask) */
#define QUARK_X1000_SSCR0_DataSize(x) ((x) - 1) /* Data Size Select [4..32] */ #define QUARK_X1000_SSCR0_DataSize(x) ((x) - 1) /* Data Size Select [4..32] */
@ -270,4 +272,4 @@ static inline struct ssp_device *pxa_ssp_request_of(const struct device_node *n,
static inline void pxa_ssp_free(struct ssp_device *ssp) {} static inline void pxa_ssp_free(struct ssp_device *ssp) {}
#endif #endif
#endif #endif /* __LINUX_PXA2XX_SSP_H */

View File

@ -2,8 +2,10 @@
/* /*
* Copyright (C) 2005 Stephen Street / StreetFire Sound Labs * Copyright (C) 2005 Stephen Street / StreetFire Sound Labs
*/ */
#ifndef __linux_pxa2xx_spi_h #ifndef __LINUX_SPI_PXA2XX_SPI_H
#define __linux_pxa2xx_spi_h #define __LINUX_SPI_PXA2XX_SPI_H
#include <linux/types.h>
#include <linux/pxa2xx_ssp.h> #include <linux/pxa2xx_ssp.h>
@ -49,4 +51,5 @@ struct pxa2xx_spi_chip {
extern void pxa2xx_set_spi_info(unsigned id, struct pxa2xx_spi_controller *info); extern void pxa2xx_set_spi_info(unsigned id, struct pxa2xx_spi_controller *info);
#endif #endif
#endif
#endif /* __LINUX_SPI_PXA2XX_SPI_H */