2019-05-27 06:55:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2006-03-08 07:53:24 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2005 Stephen Street / StreetFire Sound Labs
|
2013-01-22 10:26:32 +00:00
|
|
|
* Copyright (C) 2013, Intel Corporation
|
2006-03-08 07:53:24 +00:00
|
|
|
*/
|
|
|
|
|
2019-10-18 10:54:26 +00:00
|
|
|
#include <linux/acpi.h>
|
2015-10-28 13:13:41 +00:00
|
|
|
#include <linux/bitops.h>
|
2019-10-18 10:54:26 +00:00
|
|
|
#include <linux/clk.h>
|
|
|
|
#include <linux/delay.h>
|
2006-03-08 07:53:24 +00:00
|
|
|
#include <linux/device.h>
|
2013-04-08 10:19:33 +00:00
|
|
|
#include <linux/err.h>
|
2019-10-18 10:54:26 +00:00
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/gpio/consumer.h>
|
|
|
|
#include <linux/gpio.h>
|
|
|
|
#include <linux/init.h>
|
2006-03-08 07:53:24 +00:00
|
|
|
#include <linux/interrupt.h>
|
2019-10-18 10:54:26 +00:00
|
|
|
#include <linux/ioport.h>
|
2015-03-25 13:06:16 +00:00
|
|
|
#include <linux/kernel.h>
|
2019-10-18 10:54:26 +00:00
|
|
|
#include <linux/module.h>
|
2019-10-18 10:54:29 +00:00
|
|
|
#include <linux/mod_devicetable.h>
|
|
|
|
#include <linux/of.h>
|
2015-07-30 13:30:07 +00:00
|
|
|
#include <linux/pci.h>
|
2006-03-08 07:53:24 +00:00
|
|
|
#include <linux/platform_device.h>
|
2019-10-18 10:54:26 +00:00
|
|
|
#include <linux/pm_runtime.h>
|
2019-10-18 10:54:28 +00:00
|
|
|
#include <linux/property.h>
|
2019-10-18 10:54:26 +00:00
|
|
|
#include <linux/slab.h>
|
2010-11-23 01:12:15 +00:00
|
|
|
#include <linux/spi/pxa2xx_spi.h>
|
2006-03-08 07:53:24 +00:00
|
|
|
#include <linux/spi/spi.h>
|
|
|
|
|
2013-01-22 10:26:28 +00:00
|
|
|
#include "spi-pxa2xx.h"
|
2006-03-08 07:53:24 +00:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Stephen Street");
|
2007-12-10 23:49:25 +00:00
|
|
|
MODULE_DESCRIPTION("PXA2xx SSP SPI Controller");
|
2006-03-08 07:53:24 +00:00
|
|
|
MODULE_LICENSE("GPL");
|
2008-04-11 04:29:20 +00:00
|
|
|
MODULE_ALIAS("platform:pxa2xx-spi");
|
2006-03-08 07:53:24 +00:00
|
|
|
|
2008-10-16 05:02:43 +00:00
|
|
|
#define TIMOUT_DFLT 1000
|
|
|
|
|
2008-02-23 23:23:40 +00:00
|
|
|
/*
|
|
|
|
* for testing SSCR1 changes that require SSP restart, basically
|
|
|
|
* everything except the service and interrupt enables, the pxa270 developer
|
|
|
|
* manual says only SSCR1_SCFR, SSCR1_SPH, SSCR1_SPO need to be in this
|
|
|
|
* list, but the PXA255 dev man says all bits without really meaning the
|
|
|
|
* service and interrupt enables
|
|
|
|
*/
|
|
|
|
#define SSCR1_CHANGE_MASK (SSCR1_TTELP | SSCR1_TTE | SSCR1_SCFR \
|
2006-12-10 10:18:54 +00:00
|
|
|
| SSCR1_ECRA | SSCR1_ECRB | SSCR1_SCLKDIR \
|
2008-02-23 23:23:40 +00:00
|
|
|
| SSCR1_SFRMDIR | SSCR1_RWOT | SSCR1_TRAIL \
|
|
|
|
| SSCR1_IFS | SSCR1_STRF | SSCR1_EFWR \
|
|
|
|
| SSCR1_RFT | SSCR1_TFT | SSCR1_MWDS \
|
|
|
|
| SSCR1_SPH | SSCR1_SPO | SSCR1_LBM)
|
2006-12-10 10:18:54 +00:00
|
|
|
|
2014-11-26 10:35:10 +00:00
|
|
|
#define QUARK_X1000_SSCR1_CHANGE_MASK (QUARK_X1000_SSCR1_STRF \
|
|
|
|
| QUARK_X1000_SSCR1_EFWR \
|
|
|
|
| QUARK_X1000_SSCR1_RFT \
|
|
|
|
| QUARK_X1000_SSCR1_TFT \
|
|
|
|
| SSCR1_SPH | SSCR1_SPO | SSCR1_LBM)
|
|
|
|
|
2016-09-07 12:43:22 +00:00
|
|
|
#define CE4100_SSCR1_CHANGE_MASK (SSCR1_TTELP | SSCR1_TTE | SSCR1_SCFR \
|
|
|
|
| SSCR1_ECRA | SSCR1_ECRB | SSCR1_SCLKDIR \
|
|
|
|
| SSCR1_SFRMDIR | SSCR1_RWOT | SSCR1_TRAIL \
|
|
|
|
| SSCR1_IFS | SSCR1_STRF | SSCR1_EFWR \
|
|
|
|
| CE4100_SSCR1_RFT | CE4100_SSCR1_TFT | SSCR1_MWDS \
|
|
|
|
| SSCR1_SPH | SSCR1_SPO | SSCR1_LBM)
|
|
|
|
|
2015-10-28 13:13:39 +00:00
|
|
|
#define LPSS_GENERAL_REG_RXTO_HOLDOFF_DISABLE BIT(24)
|
|
|
|
#define LPSS_CS_CONTROL_SW_MODE BIT(0)
|
|
|
|
#define LPSS_CS_CONTROL_CS_HIGH BIT(1)
|
2015-10-28 13:13:41 +00:00
|
|
|
#define LPSS_CAPS_CS_EN_SHIFT 9
|
|
|
|
#define LPSS_CAPS_CS_EN_MASK (0xf << LPSS_CAPS_CS_EN_SHIFT)
|
2013-01-22 10:26:32 +00:00
|
|
|
|
2020-02-11 22:37:00 +00:00
|
|
|
#define LPSS_PRIV_CLOCK_GATE 0x38
|
|
|
|
#define LPSS_PRIV_CLOCK_GATE_CLK_CTL_MASK 0x3
|
|
|
|
#define LPSS_PRIV_CLOCK_GATE_CLK_CTL_FORCE_ON 0x3
|
|
|
|
|
2015-06-04 13:55:11 +00:00
|
|
|
struct lpss_config {
|
|
|
|
/* LPSS offset from drv_data->ioaddr */
|
|
|
|
unsigned offset;
|
|
|
|
/* Register offsets from drv_data->lpss_base or -1 */
|
|
|
|
int reg_general;
|
|
|
|
int reg_ssp;
|
|
|
|
int reg_cs_ctrl;
|
2015-10-28 13:13:41 +00:00
|
|
|
int reg_capabilities;
|
2015-06-04 13:55:11 +00:00
|
|
|
/* FIFO thresholds */
|
|
|
|
u32 rx_threshold;
|
|
|
|
u32 tx_threshold_lo;
|
|
|
|
u32 tx_threshold_hi;
|
2016-02-08 15:14:30 +00:00
|
|
|
/* Chip select control */
|
|
|
|
unsigned cs_sel_shift;
|
|
|
|
unsigned cs_sel_mask;
|
2016-02-08 15:14:31 +00:00
|
|
|
unsigned cs_num;
|
2020-02-11 22:37:00 +00:00
|
|
|
/* Quirks */
|
|
|
|
unsigned cs_clk_stays_gated : 1;
|
2015-06-04 13:55:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Keep these sorted with enum pxa_ssp_type */
|
|
|
|
static const struct lpss_config lpss_platforms[] = {
|
|
|
|
{ /* LPSS_LPT_SSP */
|
|
|
|
.offset = 0x800,
|
|
|
|
.reg_general = 0x08,
|
|
|
|
.reg_ssp = 0x0c,
|
|
|
|
.reg_cs_ctrl = 0x18,
|
2015-10-28 13:13:41 +00:00
|
|
|
.reg_capabilities = -1,
|
2015-06-04 13:55:11 +00:00
|
|
|
.rx_threshold = 64,
|
|
|
|
.tx_threshold_lo = 160,
|
|
|
|
.tx_threshold_hi = 224,
|
|
|
|
},
|
|
|
|
{ /* LPSS_BYT_SSP */
|
|
|
|
.offset = 0x400,
|
|
|
|
.reg_general = 0x08,
|
|
|
|
.reg_ssp = 0x0c,
|
|
|
|
.reg_cs_ctrl = 0x18,
|
2015-10-28 13:13:41 +00:00
|
|
|
.reg_capabilities = -1,
|
2015-06-04 13:55:11 +00:00
|
|
|
.rx_threshold = 64,
|
|
|
|
.tx_threshold_lo = 160,
|
|
|
|
.tx_threshold_hi = 224,
|
|
|
|
},
|
2016-02-08 15:14:31 +00:00
|
|
|
{ /* LPSS_BSW_SSP */
|
|
|
|
.offset = 0x400,
|
|
|
|
.reg_general = 0x08,
|
|
|
|
.reg_ssp = 0x0c,
|
|
|
|
.reg_cs_ctrl = 0x18,
|
|
|
|
.reg_capabilities = -1,
|
|
|
|
.rx_threshold = 64,
|
|
|
|
.tx_threshold_lo = 160,
|
|
|
|
.tx_threshold_hi = 224,
|
|
|
|
.cs_sel_shift = 2,
|
|
|
|
.cs_sel_mask = 1 << 2,
|
|
|
|
.cs_num = 2,
|
|
|
|
},
|
2015-07-30 13:30:07 +00:00
|
|
|
{ /* LPSS_SPT_SSP */
|
|
|
|
.offset = 0x200,
|
|
|
|
.reg_general = -1,
|
|
|
|
.reg_ssp = 0x20,
|
|
|
|
.reg_cs_ctrl = 0x24,
|
2016-04-26 07:08:26 +00:00
|
|
|
.reg_capabilities = -1,
|
2015-07-30 13:30:07 +00:00
|
|
|
.rx_threshold = 1,
|
|
|
|
.tx_threshold_lo = 32,
|
|
|
|
.tx_threshold_hi = 56,
|
|
|
|
},
|
2015-10-28 13:13:42 +00:00
|
|
|
{ /* LPSS_BXT_SSP */
|
|
|
|
.offset = 0x200,
|
|
|
|
.reg_general = -1,
|
|
|
|
.reg_ssp = 0x20,
|
|
|
|
.reg_cs_ctrl = 0x24,
|
|
|
|
.reg_capabilities = 0xfc,
|
|
|
|
.rx_threshold = 1,
|
|
|
|
.tx_threshold_lo = 16,
|
|
|
|
.tx_threshold_hi = 48,
|
2016-02-08 15:14:30 +00:00
|
|
|
.cs_sel_shift = 8,
|
|
|
|
.cs_sel_mask = 3 << 8,
|
2020-04-27 23:32:48 +00:00
|
|
|
.cs_clk_stays_gated = true,
|
2015-10-28 13:13:42 +00:00
|
|
|
},
|
2017-05-30 14:31:21 +00:00
|
|
|
{ /* LPSS_CNL_SSP */
|
|
|
|
.offset = 0x200,
|
|
|
|
.reg_general = -1,
|
|
|
|
.reg_ssp = 0x20,
|
|
|
|
.reg_cs_ctrl = 0x24,
|
|
|
|
.reg_capabilities = 0xfc,
|
|
|
|
.rx_threshold = 1,
|
|
|
|
.tx_threshold_lo = 32,
|
|
|
|
.tx_threshold_hi = 56,
|
|
|
|
.cs_sel_shift = 8,
|
|
|
|
.cs_sel_mask = 3 << 8,
|
2020-02-11 22:37:00 +00:00
|
|
|
.cs_clk_stays_gated = true,
|
2017-05-30 14:31:21 +00:00
|
|
|
},
|
2015-06-04 13:55:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static inline const struct lpss_config
|
|
|
|
*lpss_get_config(const struct driver_data *drv_data)
|
|
|
|
{
|
|
|
|
return &lpss_platforms[drv_data->ssp_type - LPSS_LPT_SSP];
|
|
|
|
}
|
|
|
|
|
2013-01-22 10:26:32 +00:00
|
|
|
static bool is_lpss_ssp(const struct driver_data *drv_data)
|
|
|
|
{
|
2015-06-04 13:55:10 +00:00
|
|
|
switch (drv_data->ssp_type) {
|
|
|
|
case LPSS_LPT_SSP:
|
|
|
|
case LPSS_BYT_SSP:
|
2016-02-08 15:14:31 +00:00
|
|
|
case LPSS_BSW_SSP:
|
2015-07-30 13:30:07 +00:00
|
|
|
case LPSS_SPT_SSP:
|
2015-10-28 13:13:42 +00:00
|
|
|
case LPSS_BXT_SSP:
|
2017-05-30 14:31:21 +00:00
|
|
|
case LPSS_CNL_SSP:
|
2015-06-04 13:55:10 +00:00
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2013-01-22 10:26:32 +00:00
|
|
|
}
|
|
|
|
|
2014-11-26 10:35:10 +00:00
|
|
|
static bool is_quark_x1000_ssp(const struct driver_data *drv_data)
|
|
|
|
{
|
|
|
|
return drv_data->ssp_type == QUARK_X1000_SSP;
|
|
|
|
}
|
|
|
|
|
2020-02-27 16:25:56 +00:00
|
|
|
static bool is_mmp2_ssp(const struct driver_data *drv_data)
|
|
|
|
{
|
|
|
|
return drv_data->ssp_type == MMP2_SSP;
|
|
|
|
}
|
|
|
|
|
2014-10-08 15:50:22 +00:00
|
|
|
static u32 pxa2xx_spi_get_ssrc1_change_mask(const struct driver_data *drv_data)
|
|
|
|
{
|
|
|
|
switch (drv_data->ssp_type) {
|
2014-11-26 10:35:10 +00:00
|
|
|
case QUARK_X1000_SSP:
|
|
|
|
return QUARK_X1000_SSCR1_CHANGE_MASK;
|
2016-09-07 12:43:22 +00:00
|
|
|
case CE4100_SSP:
|
|
|
|
return CE4100_SSCR1_CHANGE_MASK;
|
2014-10-08 15:50:22 +00:00
|
|
|
default:
|
|
|
|
return SSCR1_CHANGE_MASK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static u32
|
|
|
|
pxa2xx_spi_get_rx_default_thre(const struct driver_data *drv_data)
|
|
|
|
{
|
|
|
|
switch (drv_data->ssp_type) {
|
2014-11-26 10:35:10 +00:00
|
|
|
case QUARK_X1000_SSP:
|
|
|
|
return RX_THRESH_QUARK_X1000_DFLT;
|
2016-09-07 12:43:22 +00:00
|
|
|
case CE4100_SSP:
|
|
|
|
return RX_THRESH_CE4100_DFLT;
|
2014-10-08 15:50:22 +00:00
|
|
|
default:
|
|
|
|
return RX_THRESH_DFLT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool pxa2xx_spi_txfifo_full(const struct driver_data *drv_data)
|
|
|
|
{
|
|
|
|
u32 mask;
|
|
|
|
|
|
|
|
switch (drv_data->ssp_type) {
|
2014-11-26 10:35:10 +00:00
|
|
|
case QUARK_X1000_SSP:
|
|
|
|
mask = QUARK_X1000_SSSR_TFL_MASK;
|
|
|
|
break;
|
2016-09-07 12:43:22 +00:00
|
|
|
case CE4100_SSP:
|
|
|
|
mask = CE4100_SSSR_TFL_MASK;
|
|
|
|
break;
|
2014-10-08 15:50:22 +00:00
|
|
|
default:
|
|
|
|
mask = SSSR_TFL_MASK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-12-18 13:04:23 +00:00
|
|
|
return (pxa2xx_spi_read(drv_data, SSSR) & mask) == mask;
|
2014-10-08 15:50:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void pxa2xx_spi_clear_rx_thre(const struct driver_data *drv_data,
|
|
|
|
u32 *sccr1_reg)
|
|
|
|
{
|
|
|
|
u32 mask;
|
|
|
|
|
|
|
|
switch (drv_data->ssp_type) {
|
2014-11-26 10:35:10 +00:00
|
|
|
case QUARK_X1000_SSP:
|
|
|
|
mask = QUARK_X1000_SSCR1_RFT;
|
|
|
|
break;
|
2016-09-07 12:43:22 +00:00
|
|
|
case CE4100_SSP:
|
|
|
|
mask = CE4100_SSCR1_RFT;
|
|
|
|
break;
|
2014-10-08 15:50:22 +00:00
|
|
|
default:
|
|
|
|
mask = SSCR1_RFT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
*sccr1_reg &= ~mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pxa2xx_spi_set_rx_thre(const struct driver_data *drv_data,
|
|
|
|
u32 *sccr1_reg, u32 threshold)
|
|
|
|
{
|
|
|
|
switch (drv_data->ssp_type) {
|
2014-11-26 10:35:10 +00:00
|
|
|
case QUARK_X1000_SSP:
|
|
|
|
*sccr1_reg |= QUARK_X1000_SSCR1_RxTresh(threshold);
|
|
|
|
break;
|
2016-09-07 12:43:22 +00:00
|
|
|
case CE4100_SSP:
|
|
|
|
*sccr1_reg |= CE4100_SSCR1_RxTresh(threshold);
|
|
|
|
break;
|
2014-10-08 15:50:22 +00:00
|
|
|
default:
|
|
|
|
*sccr1_reg |= SSCR1_RxTresh(threshold);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static u32 pxa2xx_configure_sscr0(const struct driver_data *drv_data,
|
|
|
|
u32 clk_div, u8 bits)
|
|
|
|
{
|
|
|
|
switch (drv_data->ssp_type) {
|
2014-11-26 10:35:10 +00:00
|
|
|
case QUARK_X1000_SSP:
|
|
|
|
return clk_div
|
|
|
|
| QUARK_X1000_SSCR0_Motorola
|
|
|
|
| QUARK_X1000_SSCR0_DataSize(bits > 32 ? 8 : bits)
|
|
|
|
| SSCR0_SSE;
|
2014-10-08 15:50:22 +00:00
|
|
|
default:
|
|
|
|
return clk_div
|
|
|
|
| SSCR0_Motorola
|
|
|
|
| SSCR0_DataSize(bits > 16 ? bits - 16 : bits)
|
|
|
|
| SSCR0_SSE
|
|
|
|
| (bits > 16 ? SSCR0_EDSS : 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-22 10:26:32 +00:00
|
|
|
/*
|
|
|
|
* Read and write LPSS SSP private registers. Caller must first check that
|
|
|
|
* is_lpss_ssp() returns true before these can be called.
|
|
|
|
*/
|
|
|
|
static u32 __lpss_ssp_read_priv(struct driver_data *drv_data, unsigned offset)
|
|
|
|
{
|
|
|
|
WARN_ON(!drv_data->lpss_base);
|
|
|
|
return readl(drv_data->lpss_base + offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __lpss_ssp_write_priv(struct driver_data *drv_data,
|
|
|
|
unsigned offset, u32 value)
|
|
|
|
{
|
|
|
|
WARN_ON(!drv_data->lpss_base);
|
|
|
|
writel(value, drv_data->lpss_base + offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* lpss_ssp_setup - perform LPSS SSP specific setup
|
|
|
|
* @drv_data: pointer to the driver private data
|
|
|
|
*
|
|
|
|
* Perform LPSS SSP specific setup. This function must be called first if
|
|
|
|
* one is going to use LPSS SSP private registers.
|
|
|
|
*/
|
|
|
|
static void lpss_ssp_setup(struct driver_data *drv_data)
|
|
|
|
{
|
2015-06-04 13:55:11 +00:00
|
|
|
const struct lpss_config *config;
|
|
|
|
u32 value;
|
2013-01-22 10:26:32 +00:00
|
|
|
|
2015-06-04 13:55:11 +00:00
|
|
|
config = lpss_get_config(drv_data);
|
|
|
|
drv_data->lpss_base = drv_data->ioaddr + config->offset;
|
2013-01-22 10:26:32 +00:00
|
|
|
|
|
|
|
/* Enable software chip select control */
|
2015-10-22 13:44:42 +00:00
|
|
|
value = __lpss_ssp_read_priv(drv_data, config->reg_cs_ctrl);
|
2015-10-28 13:13:39 +00:00
|
|
|
value &= ~(LPSS_CS_CONTROL_SW_MODE | LPSS_CS_CONTROL_CS_HIGH);
|
|
|
|
value |= LPSS_CS_CONTROL_SW_MODE | LPSS_CS_CONTROL_CS_HIGH;
|
2015-06-04 13:55:11 +00:00
|
|
|
__lpss_ssp_write_priv(drv_data, config->reg_cs_ctrl, value);
|
2013-03-05 10:05:17 +00:00
|
|
|
|
|
|
|
/* Enable multiblock DMA transfers */
|
2019-01-16 15:13:31 +00:00
|
|
|
if (drv_data->controller_info->enable_dma) {
|
2015-06-04 13:55:11 +00:00
|
|
|
__lpss_ssp_write_priv(drv_data, config->reg_ssp, 1);
|
2013-07-03 10:25:06 +00:00
|
|
|
|
2015-06-04 13:55:12 +00:00
|
|
|
if (config->reg_general >= 0) {
|
|
|
|
value = __lpss_ssp_read_priv(drv_data,
|
|
|
|
config->reg_general);
|
2015-10-28 13:13:39 +00:00
|
|
|
value |= LPSS_GENERAL_REG_RXTO_HOLDOFF_DISABLE;
|
2015-06-04 13:55:12 +00:00
|
|
|
__lpss_ssp_write_priv(drv_data,
|
|
|
|
config->reg_general, value);
|
|
|
|
}
|
2013-07-03 10:25:06 +00:00
|
|
|
}
|
2013-01-22 10:26:32 +00:00
|
|
|
}
|
|
|
|
|
2018-04-17 14:20:02 +00:00
|
|
|
static void lpss_ssp_select_cs(struct spi_device *spi,
|
2016-02-08 15:14:30 +00:00
|
|
|
const struct lpss_config *config)
|
|
|
|
{
|
2018-04-17 14:20:02 +00:00
|
|
|
struct driver_data *drv_data =
|
|
|
|
spi_controller_get_devdata(spi->controller);
|
2016-02-08 15:14:30 +00:00
|
|
|
u32 value, cs;
|
|
|
|
|
|
|
|
if (!config->cs_sel_mask)
|
|
|
|
return;
|
|
|
|
|
|
|
|
value = __lpss_ssp_read_priv(drv_data, config->reg_cs_ctrl);
|
|
|
|
|
2018-04-17 14:20:02 +00:00
|
|
|
cs = spi->chip_select;
|
2016-02-08 15:14:30 +00:00
|
|
|
cs <<= config->cs_sel_shift;
|
|
|
|
if (cs != (value & config->cs_sel_mask)) {
|
|
|
|
/*
|
|
|
|
* When switching another chip select output active the
|
|
|
|
* output must be selected first and wait 2 ssp_clk cycles
|
|
|
|
* before changing state to active. Otherwise a short
|
|
|
|
* glitch will occur on the previous chip select since
|
|
|
|
* output select is latched but state control is not.
|
|
|
|
*/
|
|
|
|
value &= ~config->cs_sel_mask;
|
|
|
|
value |= cs;
|
|
|
|
__lpss_ssp_write_priv(drv_data,
|
|
|
|
config->reg_cs_ctrl, value);
|
|
|
|
ndelay(1000000000 /
|
2019-01-16 15:13:31 +00:00
|
|
|
(drv_data->controller->max_speed_hz / 2));
|
2016-02-08 15:14:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-17 14:20:02 +00:00
|
|
|
static void lpss_ssp_cs_control(struct spi_device *spi, bool enable)
|
2013-01-22 10:26:32 +00:00
|
|
|
{
|
2018-04-17 14:20:02 +00:00
|
|
|
struct driver_data *drv_data =
|
|
|
|
spi_controller_get_devdata(spi->controller);
|
2015-06-04 13:55:11 +00:00
|
|
|
const struct lpss_config *config;
|
2016-02-08 15:14:30 +00:00
|
|
|
u32 value;
|
2013-01-22 10:26:32 +00:00
|
|
|
|
2015-06-04 13:55:11 +00:00
|
|
|
config = lpss_get_config(drv_data);
|
|
|
|
|
2016-02-08 15:14:30 +00:00
|
|
|
if (enable)
|
2018-04-17 14:20:02 +00:00
|
|
|
lpss_ssp_select_cs(spi, config);
|
2016-02-08 15:14:30 +00:00
|
|
|
|
2015-06-04 13:55:11 +00:00
|
|
|
value = __lpss_ssp_read_priv(drv_data, config->reg_cs_ctrl);
|
2016-02-08 15:14:30 +00:00
|
|
|
if (enable)
|
2015-10-28 13:13:39 +00:00
|
|
|
value &= ~LPSS_CS_CONTROL_CS_HIGH;
|
2016-02-08 15:14:30 +00:00
|
|
|
else
|
2015-10-28 13:13:39 +00:00
|
|
|
value |= LPSS_CS_CONTROL_CS_HIGH;
|
2015-06-04 13:55:11 +00:00
|
|
|
__lpss_ssp_write_priv(drv_data, config->reg_cs_ctrl, value);
|
2020-02-11 22:37:00 +00:00
|
|
|
if (config->cs_clk_stays_gated) {
|
|
|
|
u32 clkgate;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Changing CS alone when dynamic clock gating is on won't
|
|
|
|
* actually flip CS at that time. This ruins SPI transfers
|
|
|
|
* that specify delays, or have no data. Toggle the clock mode
|
|
|
|
* to force on briefly to poke the CS pin to move.
|
|
|
|
*/
|
|
|
|
clkgate = __lpss_ssp_read_priv(drv_data, LPSS_PRIV_CLOCK_GATE);
|
|
|
|
value = (clkgate & ~LPSS_PRIV_CLOCK_GATE_CLK_CTL_MASK) |
|
|
|
|
LPSS_PRIV_CLOCK_GATE_CLK_CTL_FORCE_ON;
|
|
|
|
|
|
|
|
__lpss_ssp_write_priv(drv_data, LPSS_PRIV_CLOCK_GATE, value);
|
|
|
|
__lpss_ssp_write_priv(drv_data, LPSS_PRIV_CLOCK_GATE, clkgate);
|
|
|
|
}
|
2013-01-22 10:26:32 +00:00
|
|
|
}
|
|
|
|
|
2018-04-17 14:20:02 +00:00
|
|
|
static void cs_assert(struct spi_device *spi)
|
2009-04-07 02:00:54 +00:00
|
|
|
{
|
2018-04-17 14:20:02 +00:00
|
|
|
struct chip_data *chip = spi_get_ctldata(spi);
|
|
|
|
struct driver_data *drv_data =
|
|
|
|
spi_controller_get_devdata(spi->controller);
|
2009-04-07 02:00:54 +00:00
|
|
|
|
2010-11-23 01:12:17 +00:00
|
|
|
if (drv_data->ssp_type == CE4100_SSP) {
|
2016-09-07 14:04:07 +00:00
|
|
|
pxa2xx_spi_write(drv_data, SSSR, chip->frm);
|
2010-11-23 01:12:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-04-07 02:00:54 +00:00
|
|
|
if (chip->cs_control) {
|
|
|
|
chip->cs_control(PXA2XX_CS_ASSERT);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-03 11:40:32 +00:00
|
|
|
if (chip->gpiod_cs) {
|
|
|
|
gpiod_set_value(chip->gpiod_cs, chip->gpio_cs_inverted);
|
2013-01-22 10:26:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-12-18 13:04:20 +00:00
|
|
|
if (is_lpss_ssp(drv_data))
|
2018-04-17 14:20:02 +00:00
|
|
|
lpss_ssp_cs_control(spi, true);
|
2009-04-07 02:00:54 +00:00
|
|
|
}
|
|
|
|
|
2018-04-17 14:20:02 +00:00
|
|
|
static void cs_deassert(struct spi_device *spi)
|
2009-04-07 02:00:54 +00:00
|
|
|
{
|
2018-04-17 14:20:02 +00:00
|
|
|
struct chip_data *chip = spi_get_ctldata(spi);
|
|
|
|
struct driver_data *drv_data =
|
|
|
|
spi_controller_get_devdata(spi->controller);
|
2018-02-09 14:31:07 +00:00
|
|
|
unsigned long timeout;
|
2009-04-07 02:00:54 +00:00
|
|
|
|
2010-11-23 01:12:17 +00:00
|
|
|
if (drv_data->ssp_type == CE4100_SSP)
|
|
|
|
return;
|
|
|
|
|
2018-02-09 14:31:07 +00:00
|
|
|
/* Wait until SSP becomes idle before deasserting the CS */
|
|
|
|
timeout = jiffies + msecs_to_jiffies(10);
|
|
|
|
while (pxa2xx_spi_read(drv_data, SSSR) & SSSR_BSY &&
|
|
|
|
!time_after(jiffies, timeout))
|
|
|
|
cpu_relax();
|
|
|
|
|
2009-04-07 02:00:54 +00:00
|
|
|
if (chip->cs_control) {
|
2009-04-09 01:48:03 +00:00
|
|
|
chip->cs_control(PXA2XX_CS_DEASSERT);
|
2009-04-07 02:00:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-03 11:40:32 +00:00
|
|
|
if (chip->gpiod_cs) {
|
|
|
|
gpiod_set_value(chip->gpiod_cs, !chip->gpio_cs_inverted);
|
2013-01-22 10:26:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-12-18 13:04:20 +00:00
|
|
|
if (is_lpss_ssp(drv_data))
|
2018-04-17 14:20:02 +00:00
|
|
|
lpss_ssp_cs_control(spi, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pxa2xx_spi_set_cs(struct spi_device *spi, bool level)
|
|
|
|
{
|
|
|
|
if (level)
|
|
|
|
cs_deassert(spi);
|
|
|
|
else
|
|
|
|
cs_assert(spi);
|
2009-04-07 02:00:54 +00:00
|
|
|
}
|
|
|
|
|
2013-01-22 10:26:28 +00:00
|
|
|
int pxa2xx_spi_flush(struct driver_data *drv_data)
|
2006-03-08 07:53:24 +00:00
|
|
|
{
|
|
|
|
unsigned long limit = loops_per_jiffy << 1;
|
|
|
|
|
|
|
|
do {
|
2014-12-18 13:04:23 +00:00
|
|
|
while (pxa2xx_spi_read(drv_data, SSSR) & SSSR_RNE)
|
|
|
|
pxa2xx_spi_read(drv_data, SSDR);
|
|
|
|
} while ((pxa2xx_spi_read(drv_data, SSSR) & SSSR_BSY) && --limit);
|
2010-11-23 01:12:17 +00:00
|
|
|
write_SSSR_CS(drv_data, SSSR_ROR);
|
2006-03-08 07:53:24 +00:00
|
|
|
|
|
|
|
return limit;
|
|
|
|
}
|
|
|
|
|
2020-01-18 09:40:31 +00:00
|
|
|
static void pxa2xx_spi_off(struct driver_data *drv_data)
|
|
|
|
{
|
2020-02-27 16:25:56 +00:00
|
|
|
/* On MMP, disabling SSE seems to corrupt the Rx FIFO */
|
|
|
|
if (is_mmp2_ssp(drv_data))
|
2020-01-18 09:40:31 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
pxa2xx_spi_write(drv_data, SSCR0,
|
|
|
|
pxa2xx_spi_read(drv_data, SSCR0) & ~SSCR0_SSE);
|
|
|
|
}
|
|
|
|
|
2006-12-10 10:18:54 +00:00
|
|
|
static int null_writer(struct driver_data *drv_data)
|
2006-03-08 07:53:24 +00:00
|
|
|
{
|
2006-03-28 22:05:23 +00:00
|
|
|
u8 n_bytes = drv_data->n_bytes;
|
2006-03-08 07:53:24 +00:00
|
|
|
|
2014-10-08 15:50:22 +00:00
|
|
|
if (pxa2xx_spi_txfifo_full(drv_data)
|
2006-12-10 10:18:54 +00:00
|
|
|
|| (drv_data->tx == drv_data->tx_end))
|
|
|
|
return 0;
|
|
|
|
|
2014-12-18 13:04:23 +00:00
|
|
|
pxa2xx_spi_write(drv_data, SSDR, 0);
|
2006-12-10 10:18:54 +00:00
|
|
|
drv_data->tx += n_bytes;
|
|
|
|
|
|
|
|
return 1;
|
2006-03-08 07:53:24 +00:00
|
|
|
}
|
|
|
|
|
2006-12-10 10:18:54 +00:00
|
|
|
static int null_reader(struct driver_data *drv_data)
|
2006-03-08 07:53:24 +00:00
|
|
|
{
|
2006-03-28 22:05:23 +00:00
|
|
|
u8 n_bytes = drv_data->n_bytes;
|
2006-03-08 07:53:24 +00:00
|
|
|
|
2014-12-18 13:04:23 +00:00
|
|
|
while ((pxa2xx_spi_read(drv_data, SSSR) & SSSR_RNE)
|
|
|
|
&& (drv_data->rx < drv_data->rx_end)) {
|
|
|
|
pxa2xx_spi_read(drv_data, SSDR);
|
2006-03-08 07:53:24 +00:00
|
|
|
drv_data->rx += n_bytes;
|
|
|
|
}
|
2006-12-10 10:18:54 +00:00
|
|
|
|
|
|
|
return drv_data->rx == drv_data->rx_end;
|
2006-03-08 07:53:24 +00:00
|
|
|
}
|
|
|
|
|
2006-12-10 10:18:54 +00:00
|
|
|
static int u8_writer(struct driver_data *drv_data)
|
2006-03-08 07:53:24 +00:00
|
|
|
{
|
2014-10-08 15:50:22 +00:00
|
|
|
if (pxa2xx_spi_txfifo_full(drv_data)
|
2006-12-10 10:18:54 +00:00
|
|
|
|| (drv_data->tx == drv_data->tx_end))
|
|
|
|
return 0;
|
|
|
|
|
2014-12-18 13:04:23 +00:00
|
|
|
pxa2xx_spi_write(drv_data, SSDR, *(u8 *)(drv_data->tx));
|
2006-12-10 10:18:54 +00:00
|
|
|
++drv_data->tx;
|
|
|
|
|
|
|
|
return 1;
|
2006-03-08 07:53:24 +00:00
|
|
|
}
|
|
|
|
|
2006-12-10 10:18:54 +00:00
|
|
|
static int u8_reader(struct driver_data *drv_data)
|
2006-03-08 07:53:24 +00:00
|
|
|
{
|
2014-12-18 13:04:23 +00:00
|
|
|
while ((pxa2xx_spi_read(drv_data, SSSR) & SSSR_RNE)
|
|
|
|
&& (drv_data->rx < drv_data->rx_end)) {
|
|
|
|
*(u8 *)(drv_data->rx) = pxa2xx_spi_read(drv_data, SSDR);
|
2006-03-08 07:53:24 +00:00
|
|
|
++drv_data->rx;
|
|
|
|
}
|
2006-12-10 10:18:54 +00:00
|
|
|
|
|
|
|
return drv_data->rx == drv_data->rx_end;
|
2006-03-08 07:53:24 +00:00
|
|
|
}
|
|
|
|
|
2006-12-10 10:18:54 +00:00
|
|
|
static int u16_writer(struct driver_data *drv_data)
|
2006-03-08 07:53:24 +00:00
|
|
|
{
|
2014-10-08 15:50:22 +00:00
|
|
|
if (pxa2xx_spi_txfifo_full(drv_data)
|
2006-12-10 10:18:54 +00:00
|
|
|
|| (drv_data->tx == drv_data->tx_end))
|
|
|
|
return 0;
|
|
|
|
|
2014-12-18 13:04:23 +00:00
|
|
|
pxa2xx_spi_write(drv_data, SSDR, *(u16 *)(drv_data->tx));
|
2006-12-10 10:18:54 +00:00
|
|
|
drv_data->tx += 2;
|
|
|
|
|
|
|
|
return 1;
|
2006-03-08 07:53:24 +00:00
|
|
|
}
|
|
|
|
|
2006-12-10 10:18:54 +00:00
|
|
|
static int u16_reader(struct driver_data *drv_data)
|
2006-03-08 07:53:24 +00:00
|
|
|
{
|
2014-12-18 13:04:23 +00:00
|
|
|
while ((pxa2xx_spi_read(drv_data, SSSR) & SSSR_RNE)
|
|
|
|
&& (drv_data->rx < drv_data->rx_end)) {
|
|
|
|
*(u16 *)(drv_data->rx) = pxa2xx_spi_read(drv_data, SSDR);
|
2006-03-08 07:53:24 +00:00
|
|
|
drv_data->rx += 2;
|
|
|
|
}
|
2006-12-10 10:18:54 +00:00
|
|
|
|
|
|
|
return drv_data->rx == drv_data->rx_end;
|
2006-03-08 07:53:24 +00:00
|
|
|
}
|
2006-12-10 10:18:54 +00:00
|
|
|
|
|
|
|
static int u32_writer(struct driver_data *drv_data)
|
2006-03-08 07:53:24 +00:00
|
|
|
{
|
2014-10-08 15:50:22 +00:00
|
|
|
if (pxa2xx_spi_txfifo_full(drv_data)
|
2006-12-10 10:18:54 +00:00
|
|
|
|| (drv_data->tx == drv_data->tx_end))
|
|
|
|
return 0;
|
|
|
|
|
2014-12-18 13:04:23 +00:00
|
|
|
pxa2xx_spi_write(drv_data, SSDR, *(u32 *)(drv_data->tx));
|
2006-12-10 10:18:54 +00:00
|
|
|
drv_data->tx += 4;
|
|
|
|
|
|
|
|
return 1;
|
2006-03-08 07:53:24 +00:00
|
|
|
}
|
|
|
|
|
2006-12-10 10:18:54 +00:00
|
|
|
static int u32_reader(struct driver_data *drv_data)
|
2006-03-08 07:53:24 +00:00
|
|
|
{
|
2014-12-18 13:04:23 +00:00
|
|
|
while ((pxa2xx_spi_read(drv_data, SSSR) & SSSR_RNE)
|
|
|
|
&& (drv_data->rx < drv_data->rx_end)) {
|
|
|
|
*(u32 *)(drv_data->rx) = pxa2xx_spi_read(drv_data, SSDR);
|
2006-03-08 07:53:24 +00:00
|
|
|
drv_data->rx += 4;
|
|
|
|
}
|
2006-12-10 10:18:54 +00:00
|
|
|
|
|
|
|
return drv_data->rx == drv_data->rx_end;
|
2006-03-08 07:53:24 +00:00
|
|
|
}
|
|
|
|
|
2010-11-23 01:12:17 +00:00
|
|
|
static void reset_sccr1(struct driver_data *drv_data)
|
|
|
|
{
|
2016-09-07 14:04:07 +00:00
|
|
|
struct chip_data *chip =
|
2019-01-16 15:13:31 +00:00
|
|
|
spi_get_ctldata(drv_data->controller->cur_msg->spi);
|
2010-11-23 01:12:17 +00:00
|
|
|
u32 sccr1_reg;
|
|
|
|
|
2014-12-18 13:04:23 +00:00
|
|
|
sccr1_reg = pxa2xx_spi_read(drv_data, SSCR1) & ~drv_data->int_cr1;
|
2016-07-06 09:08:11 +00:00
|
|
|
switch (drv_data->ssp_type) {
|
|
|
|
case QUARK_X1000_SSP:
|
|
|
|
sccr1_reg &= ~QUARK_X1000_SSCR1_RFT;
|
|
|
|
break;
|
2016-09-07 12:43:22 +00:00
|
|
|
case CE4100_SSP:
|
|
|
|
sccr1_reg &= ~CE4100_SSCR1_RFT;
|
|
|
|
break;
|
2016-07-06 09:08:11 +00:00
|
|
|
default:
|
|
|
|
sccr1_reg &= ~SSCR1_RFT;
|
|
|
|
break;
|
|
|
|
}
|
2010-11-23 01:12:17 +00:00
|
|
|
sccr1_reg |= chip->threshold;
|
2014-12-18 13:04:23 +00:00
|
|
|
pxa2xx_spi_write(drv_data, SSCR1, sccr1_reg);
|
2010-11-23 01:12:17 +00:00
|
|
|
}
|
|
|
|
|
2006-12-10 10:18:54 +00:00
|
|
|
static void int_error_stop(struct driver_data *drv_data, const char* msg)
|
2006-03-08 07:53:24 +00:00
|
|
|
{
|
2006-12-10 10:18:54 +00:00
|
|
|
/* Stop and reset SSP */
|
2010-11-23 01:12:17 +00:00
|
|
|
write_SSSR_CS(drv_data, drv_data->clear_sr);
|
2010-11-23 01:12:17 +00:00
|
|
|
reset_sccr1(drv_data);
|
2010-11-23 01:12:17 +00:00
|
|
|
if (!pxa25x_ssp_comp(drv_data))
|
2014-12-18 13:04:23 +00:00
|
|
|
pxa2xx_spi_write(drv_data, SSTO, 0);
|
2013-01-22 10:26:28 +00:00
|
|
|
pxa2xx_spi_flush(drv_data);
|
2020-01-18 09:40:31 +00:00
|
|
|
pxa2xx_spi_off(drv_data);
|
2006-03-08 07:53:24 +00:00
|
|
|
|
2006-12-10 10:18:54 +00:00
|
|
|
dev_err(&drv_data->pdev->dev, "%s\n", msg);
|
2006-03-08 07:53:24 +00:00
|
|
|
|
2019-01-16 15:13:31 +00:00
|
|
|
drv_data->controller->cur_msg->status = -EIO;
|
|
|
|
spi_finalize_current_transfer(drv_data->controller);
|
2006-12-10 10:18:54 +00:00
|
|
|
}
|
2006-05-20 22:00:19 +00:00
|
|
|
|
2006-12-10 10:18:54 +00:00
|
|
|
static void int_transfer_complete(struct driver_data *drv_data)
|
|
|
|
{
|
2016-02-04 10:30:56 +00:00
|
|
|
/* Clear and disable interrupts */
|
2010-11-23 01:12:17 +00:00
|
|
|
write_SSSR_CS(drv_data, drv_data->clear_sr);
|
2010-11-23 01:12:17 +00:00
|
|
|
reset_sccr1(drv_data);
|
2010-11-23 01:12:17 +00:00
|
|
|
if (!pxa25x_ssp_comp(drv_data))
|
2014-12-18 13:04:23 +00:00
|
|
|
pxa2xx_spi_write(drv_data, SSTO, 0);
|
2006-03-08 07:53:24 +00:00
|
|
|
|
2019-01-16 15:13:31 +00:00
|
|
|
spi_finalize_current_transfer(drv_data->controller);
|
2006-12-10 10:18:54 +00:00
|
|
|
}
|
2006-03-08 07:53:24 +00:00
|
|
|
|
2006-12-10 10:18:54 +00:00
|
|
|
static irqreturn_t interrupt_transfer(struct driver_data *drv_data)
|
|
|
|
{
|
2014-12-18 13:04:23 +00:00
|
|
|
u32 irq_mask = (pxa2xx_spi_read(drv_data, SSCR1) & SSCR1_TIE) ?
|
|
|
|
drv_data->mask_sr : drv_data->mask_sr & ~SSSR_TFS;
|
2006-03-08 07:53:24 +00:00
|
|
|
|
2014-12-18 13:04:23 +00:00
|
|
|
u32 irq_status = pxa2xx_spi_read(drv_data, SSSR) & irq_mask;
|
2006-03-08 07:53:24 +00:00
|
|
|
|
2006-12-10 10:18:54 +00:00
|
|
|
if (irq_status & SSSR_ROR) {
|
|
|
|
int_error_stop(drv_data, "interrupt_transfer: fifo overrun");
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
2006-03-08 07:53:24 +00:00
|
|
|
|
2018-11-13 10:22:25 +00:00
|
|
|
if (irq_status & SSSR_TUR) {
|
|
|
|
int_error_stop(drv_data, "interrupt_transfer: fifo underrun");
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2006-12-10 10:18:54 +00:00
|
|
|
if (irq_status & SSSR_TINT) {
|
2014-12-18 13:04:23 +00:00
|
|
|
pxa2xx_spi_write(drv_data, SSSR, SSSR_TINT);
|
2006-12-10 10:18:54 +00:00
|
|
|
if (drv_data->read(drv_data)) {
|
|
|
|
int_transfer_complete(drv_data);
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
}
|
2006-03-08 07:53:24 +00:00
|
|
|
|
2006-12-10 10:18:54 +00:00
|
|
|
/* Drain rx fifo, Fill tx fifo and prevent overruns */
|
|
|
|
do {
|
|
|
|
if (drv_data->read(drv_data)) {
|
|
|
|
int_transfer_complete(drv_data);
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
} while (drv_data->write(drv_data));
|
2006-03-08 07:53:24 +00:00
|
|
|
|
2006-12-10 10:18:54 +00:00
|
|
|
if (drv_data->read(drv_data)) {
|
|
|
|
int_transfer_complete(drv_data);
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
2006-03-08 07:53:24 +00:00
|
|
|
|
2006-12-10 10:18:54 +00:00
|
|
|
if (drv_data->tx == drv_data->tx_end) {
|
2010-11-23 01:12:17 +00:00
|
|
|
u32 bytes_left;
|
|
|
|
u32 sccr1_reg;
|
|
|
|
|
2014-12-18 13:04:23 +00:00
|
|
|
sccr1_reg = pxa2xx_spi_read(drv_data, SSCR1);
|
2010-11-23 01:12:17 +00:00
|
|
|
sccr1_reg &= ~SSCR1_TIE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PXA25x_SSP has no timeout, set up rx threshould for the
|
2011-03-31 01:57:33 +00:00
|
|
|
* remaining RX bytes.
|
2010-11-23 01:12:17 +00:00
|
|
|
*/
|
2010-11-23 01:12:17 +00:00
|
|
|
if (pxa25x_ssp_comp(drv_data)) {
|
2014-10-08 15:50:22 +00:00
|
|
|
u32 rx_thre;
|
2010-11-23 01:12:17 +00:00
|
|
|
|
2014-10-08 15:50:22 +00:00
|
|
|
pxa2xx_spi_clear_rx_thre(drv_data, &sccr1_reg);
|
2010-11-23 01:12:17 +00:00
|
|
|
|
|
|
|
bytes_left = drv_data->rx_end - drv_data->rx;
|
|
|
|
switch (drv_data->n_bytes) {
|
|
|
|
case 4:
|
2018-10-03 15:55:22 +00:00
|
|
|
bytes_left >>= 2;
|
|
|
|
break;
|
2010-11-23 01:12:17 +00:00
|
|
|
case 2:
|
|
|
|
bytes_left >>= 1;
|
2018-10-03 15:55:22 +00:00
|
|
|
break;
|
2006-12-10 10:18:54 +00:00
|
|
|
}
|
2010-11-23 01:12:17 +00:00
|
|
|
|
2014-10-08 15:50:22 +00:00
|
|
|
rx_thre = pxa2xx_spi_get_rx_default_thre(drv_data);
|
|
|
|
if (rx_thre > bytes_left)
|
|
|
|
rx_thre = bytes_left;
|
2010-11-23 01:12:17 +00:00
|
|
|
|
2014-10-08 15:50:22 +00:00
|
|
|
pxa2xx_spi_set_rx_thre(drv_data, &sccr1_reg, rx_thre);
|
2006-03-08 07:53:24 +00:00
|
|
|
}
|
2014-12-18 13:04:23 +00:00
|
|
|
pxa2xx_spi_write(drv_data, SSCR1, sccr1_reg);
|
2006-03-08 07:53:24 +00:00
|
|
|
}
|
|
|
|
|
2006-05-20 22:00:19 +00:00
|
|
|
/* We did something */
|
|
|
|
return IRQ_HANDLED;
|
2006-03-08 07:53:24 +00:00
|
|
|
}
|
|
|
|
|
2017-01-16 18:44:54 +00:00
|
|
|
static void handle_bad_msg(struct driver_data *drv_data)
|
|
|
|
{
|
2020-01-18 09:40:31 +00:00
|
|
|
pxa2xx_spi_off(drv_data);
|
2017-01-16 18:44:54 +00:00
|
|
|
pxa2xx_spi_write(drv_data, SSCR1,
|
|
|
|
pxa2xx_spi_read(drv_data, SSCR1) & ~drv_data->int_cr1);
|
|
|
|
if (!pxa25x_ssp_comp(drv_data))
|
|
|
|
pxa2xx_spi_write(drv_data, SSTO, 0);
|
|
|
|
write_SSSR_CS(drv_data, drv_data->clear_sr);
|
|
|
|
|
|
|
|
dev_err(&drv_data->pdev->dev,
|
|
|
|
"bad message state in interrupt handler\n");
|
|
|
|
}
|
|
|
|
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 13:55:46 +00:00
|
|
|
static irqreturn_t ssp_int(int irq, void *dev_id)
|
2006-03-08 07:53:24 +00:00
|
|
|
{
|
2006-10-06 19:00:58 +00:00
|
|
|
struct driver_data *drv_data = dev_id;
|
2013-01-22 10:26:30 +00:00
|
|
|
u32 sccr1_reg;
|
2010-11-23 01:12:14 +00:00
|
|
|
u32 mask = drv_data->mask_sr;
|
|
|
|
u32 status;
|
|
|
|
|
2013-01-22 10:26:30 +00:00
|
|
|
/*
|
|
|
|
* The IRQ might be shared with other peripherals so we must first
|
|
|
|
* check that are we RPM suspended or not. If we are we assume that
|
|
|
|
* the IRQ was not for us (we shouldn't be RPM suspended when the
|
|
|
|
* interrupt is enabled).
|
|
|
|
*/
|
|
|
|
if (pm_runtime_suspended(&drv_data->pdev->dev))
|
|
|
|
return IRQ_NONE;
|
|
|
|
|
2013-09-04 10:37:43 +00:00
|
|
|
/*
|
|
|
|
* If the device is not yet in RPM suspended state and we get an
|
|
|
|
* interrupt that is meant for another device, check if status bits
|
|
|
|
* are all set to one. That means that the device is already
|
|
|
|
* powered off.
|
|
|
|
*/
|
2014-12-18 13:04:23 +00:00
|
|
|
status = pxa2xx_spi_read(drv_data, SSSR);
|
2013-09-04 10:37:43 +00:00
|
|
|
if (status == ~0)
|
|
|
|
return IRQ_NONE;
|
|
|
|
|
2014-12-18 13:04:23 +00:00
|
|
|
sccr1_reg = pxa2xx_spi_read(drv_data, SSCR1);
|
2010-11-23 01:12:14 +00:00
|
|
|
|
|
|
|
/* Ignore possible writes if we don't need to write */
|
|
|
|
if (!(sccr1_reg & SSCR1_TIE))
|
|
|
|
mask &= ~SSSR_TFS;
|
|
|
|
|
2015-09-01 02:22:51 +00:00
|
|
|
/* Ignore RX timeout interrupt if it is disabled */
|
|
|
|
if (!(sccr1_reg & SSCR1_TINTE))
|
|
|
|
mask &= ~SSSR_TINT;
|
|
|
|
|
2010-11-23 01:12:14 +00:00
|
|
|
if (!(status & mask))
|
|
|
|
return IRQ_NONE;
|
2006-03-08 07:53:24 +00:00
|
|
|
|
2017-01-21 09:06:38 +00:00
|
|
|
pxa2xx_spi_write(drv_data, SSCR1, sccr1_reg & ~drv_data->int_cr1);
|
|
|
|
pxa2xx_spi_write(drv_data, SSCR1, sccr1_reg);
|
2006-05-20 22:00:19 +00:00
|
|
|
|
2019-01-16 15:13:31 +00:00
|
|
|
if (!drv_data->controller->cur_msg) {
|
2017-01-16 18:44:54 +00:00
|
|
|
handle_bad_msg(drv_data);
|
2006-03-08 07:53:24 +00:00
|
|
|
/* Never fail */
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return drv_data->transfer_handler(drv_data);
|
|
|
|
}
|
|
|
|
|
2014-11-26 10:35:10 +00:00
|
|
|
/*
|
2015-03-25 13:06:16 +00:00
|
|
|
* The Quark SPI has an additional 24 bit register (DDS_CLK_RATE) to multiply
|
|
|
|
* input frequency by fractions of 2^24. It also has a divider by 5.
|
|
|
|
*
|
|
|
|
* There are formulas to get baud rate value for given input frequency and
|
|
|
|
* divider parameters, such as DDS_CLK_RATE and SCR:
|
|
|
|
*
|
|
|
|
* Fsys = 200MHz
|
|
|
|
*
|
|
|
|
* Fssp = Fsys * DDS_CLK_RATE / 2^24 (1)
|
|
|
|
* Baud rate = Fsclk = Fssp / (2 * (SCR + 1)) (2)
|
|
|
|
*
|
|
|
|
* DDS_CLK_RATE either 2^n or 2^n / 5.
|
|
|
|
* SCR is in range 0 .. 255
|
|
|
|
*
|
|
|
|
* Divisor = 5^i * 2^j * 2 * k
|
|
|
|
* i = [0, 1] i = 1 iff j = 0 or j > 3
|
|
|
|
* j = [0, 23] j = 0 iff i = 1
|
|
|
|
* k = [1, 256]
|
|
|
|
* Special case: j = 0, i = 1: Divisor = 2 / 5
|
|
|
|
*
|
|
|
|
* Accordingly to the specification the recommended values for DDS_CLK_RATE
|
|
|
|
* are:
|
|
|
|
* Case 1: 2^n, n = [0, 23]
|
|
|
|
* Case 2: 2^24 * 2 / 5 (0x666666)
|
|
|
|
* Case 3: less than or equal to 2^24 / 5 / 16 (0x33333)
|
|
|
|
*
|
|
|
|
* In all cases the lowest possible value is better.
|
|
|
|
*
|
|
|
|
* The function calculates parameters for all cases and chooses the one closest
|
|
|
|
* to the asked baud rate.
|
2014-11-26 10:35:10 +00:00
|
|
|
*/
|
2015-03-25 13:06:16 +00:00
|
|
|
static unsigned int quark_x1000_get_clk_div(int rate, u32 *dds)
|
|
|
|
{
|
|
|
|
unsigned long xtal = 200000000;
|
|
|
|
unsigned long fref = xtal / 2; /* mandatory division by 2,
|
|
|
|
see (2) */
|
|
|
|
/* case 3 */
|
|
|
|
unsigned long fref1 = fref / 2; /* case 1 */
|
|
|
|
unsigned long fref2 = fref * 2 / 5; /* case 2 */
|
|
|
|
unsigned long scale;
|
|
|
|
unsigned long q, q1, q2;
|
|
|
|
long r, r1, r2;
|
|
|
|
u32 mul;
|
|
|
|
|
|
|
|
/* Case 1 */
|
|
|
|
|
|
|
|
/* Set initial value for DDS_CLK_RATE */
|
|
|
|
mul = (1 << 24) >> 1;
|
|
|
|
|
|
|
|
/* Calculate initial quot */
|
2015-10-13 14:09:14 +00:00
|
|
|
q1 = DIV_ROUND_UP(fref1, rate);
|
2015-03-25 13:06:16 +00:00
|
|
|
|
|
|
|
/* Scale q1 if it's too big */
|
|
|
|
if (q1 > 256) {
|
|
|
|
/* Scale q1 to range [1, 512] */
|
|
|
|
scale = fls_long(q1 - 1);
|
|
|
|
if (scale > 9) {
|
|
|
|
q1 >>= scale - 9;
|
|
|
|
mul >>= scale - 9;
|
2014-11-26 10:35:10 +00:00
|
|
|
}
|
2015-03-25 13:06:16 +00:00
|
|
|
|
|
|
|
/* Round the result if we have a remainder */
|
|
|
|
q1 += q1 & 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Decrease DDS_CLK_RATE as much as we can without loss in precision */
|
|
|
|
scale = __ffs(q1);
|
|
|
|
q1 >>= scale;
|
|
|
|
mul >>= scale;
|
|
|
|
|
|
|
|
/* Get the remainder */
|
|
|
|
r1 = abs(fref1 / (1 << (24 - fls_long(mul))) / q1 - rate);
|
|
|
|
|
|
|
|
/* Case 2 */
|
|
|
|
|
2015-10-13 14:09:14 +00:00
|
|
|
q2 = DIV_ROUND_UP(fref2, rate);
|
2015-03-25 13:06:16 +00:00
|
|
|
r2 = abs(fref2 / q2 - rate);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Choose the best between two: less remainder we have the better. We
|
|
|
|
* can't go case 2 if q2 is greater than 256 since SCR register can
|
|
|
|
* hold only values 0 .. 255.
|
|
|
|
*/
|
|
|
|
if (r2 >= r1 || q2 > 256) {
|
|
|
|
/* case 1 is better */
|
|
|
|
r = r1;
|
|
|
|
q = q1;
|
|
|
|
} else {
|
|
|
|
/* case 2 is better */
|
|
|
|
r = r2;
|
|
|
|
q = q2;
|
|
|
|
mul = (1 << 24) * 2 / 5;
|
2014-11-26 10:35:10 +00:00
|
|
|
}
|
|
|
|
|
2015-10-13 14:09:14 +00:00
|
|
|
/* Check case 3 only if the divisor is big enough */
|
2015-03-25 13:06:16 +00:00
|
|
|
if (fref / rate >= 80) {
|
|
|
|
u64 fssp;
|
|
|
|
u32 m;
|
|
|
|
|
|
|
|
/* Calculate initial quot */
|
2015-10-13 14:09:14 +00:00
|
|
|
q1 = DIV_ROUND_UP(fref, rate);
|
2015-03-25 13:06:16 +00:00
|
|
|
m = (1 << 24) / q1;
|
|
|
|
|
|
|
|
/* Get the remainder */
|
|
|
|
fssp = (u64)fref * m;
|
|
|
|
do_div(fssp, 1 << 24);
|
|
|
|
r1 = abs(fssp - rate);
|
|
|
|
|
|
|
|
/* Choose this one if it suits better */
|
|
|
|
if (r1 < r) {
|
|
|
|
/* case 3 is better */
|
|
|
|
q = 1;
|
|
|
|
mul = m;
|
|
|
|
}
|
|
|
|
}
|
2014-11-26 10:35:10 +00:00
|
|
|
|
2015-03-25 13:06:16 +00:00
|
|
|
*dds = mul;
|
|
|
|
return q - 1;
|
2014-11-26 10:35:10 +00:00
|
|
|
}
|
|
|
|
|
2013-01-22 10:26:27 +00:00
|
|
|
static unsigned int ssp_get_clk_div(struct driver_data *drv_data, int rate)
|
2007-11-21 10:50:53 +00:00
|
|
|
{
|
2019-01-16 15:13:31 +00:00
|
|
|
unsigned long ssp_clk = drv_data->controller->max_speed_hz;
|
2013-01-22 10:26:27 +00:00
|
|
|
const struct ssp_device *ssp = drv_data->ssp;
|
|
|
|
|
|
|
|
rate = min_t(int, ssp_clk, rate);
|
2007-11-21 10:50:53 +00:00
|
|
|
|
2019-04-12 07:32:19 +00:00
|
|
|
/*
|
|
|
|
* Calculate the divisor for the SCR (Serial Clock Rate), avoiding
|
|
|
|
* that the SSP transmission rate can be greater than the device rate
|
|
|
|
*/
|
2010-11-23 01:12:17 +00:00
|
|
|
if (ssp->type == PXA25x_SSP || ssp->type == CE4100_SSP)
|
2019-04-12 07:32:19 +00:00
|
|
|
return (DIV_ROUND_UP(ssp_clk, 2 * rate) - 1) & 0xff;
|
2007-11-21 10:50:53 +00:00
|
|
|
else
|
2019-04-12 07:32:19 +00:00
|
|
|
return (DIV_ROUND_UP(ssp_clk, rate) - 1) & 0xfff;
|
2007-11-21 10:50:53 +00:00
|
|
|
}
|
|
|
|
|
2014-11-26 10:35:10 +00:00
|
|
|
static unsigned int pxa2xx_ssp_get_clk_div(struct driver_data *drv_data,
|
2015-10-22 13:44:40 +00:00
|
|
|
int rate)
|
2014-11-26 10:35:10 +00:00
|
|
|
{
|
2016-09-07 14:04:07 +00:00
|
|
|
struct chip_data *chip =
|
2019-01-16 15:13:31 +00:00
|
|
|
spi_get_ctldata(drv_data->controller->cur_msg->spi);
|
2015-03-24 15:43:21 +00:00
|
|
|
unsigned int clk_div;
|
2014-11-26 10:35:10 +00:00
|
|
|
|
|
|
|
switch (drv_data->ssp_type) {
|
|
|
|
case QUARK_X1000_SSP:
|
2015-03-25 13:06:16 +00:00
|
|
|
clk_div = quark_x1000_get_clk_div(rate, &chip->dds_rate);
|
2015-03-31 13:49:38 +00:00
|
|
|
break;
|
2014-11-26 10:35:10 +00:00
|
|
|
default:
|
2015-03-24 15:43:21 +00:00
|
|
|
clk_div = ssp_get_clk_div(drv_data, rate);
|
2015-03-31 13:49:38 +00:00
|
|
|
break;
|
2014-11-26 10:35:10 +00:00
|
|
|
}
|
2015-03-24 15:43:21 +00:00
|
|
|
return clk_div << 8;
|
2014-11-26 10:35:10 +00:00
|
|
|
}
|
|
|
|
|
2019-01-16 15:13:31 +00:00
|
|
|
static bool pxa2xx_spi_can_dma(struct spi_controller *controller,
|
2016-06-21 10:21:34 +00:00
|
|
|
struct spi_device *spi,
|
|
|
|
struct spi_transfer *xfer)
|
|
|
|
{
|
|
|
|
struct chip_data *chip = spi_get_ctldata(spi);
|
|
|
|
|
|
|
|
return chip->enable_dma &&
|
|
|
|
xfer->len <= MAX_DMA_LEN &&
|
|
|
|
xfer->len >= chip->dma_burst_size;
|
|
|
|
}
|
|
|
|
|
2019-01-16 15:13:31 +00:00
|
|
|
static int pxa2xx_spi_transfer_one(struct spi_controller *controller,
|
2018-04-17 19:53:23 +00:00
|
|
|
struct spi_device *spi,
|
|
|
|
struct spi_transfer *transfer)
|
2006-03-08 07:53:24 +00:00
|
|
|
{
|
2019-01-16 15:13:31 +00:00
|
|
|
struct driver_data *drv_data = spi_controller_get_devdata(controller);
|
|
|
|
struct spi_message *message = controller->cur_msg;
|
2019-03-29 13:00:45 +00:00
|
|
|
struct chip_data *chip = spi_get_ctldata(spi);
|
2016-09-07 14:04:07 +00:00
|
|
|
u32 dma_thresh = chip->dma_threshold;
|
|
|
|
u32 dma_burst = chip->dma_burst_size;
|
|
|
|
u32 change_mask = pxa2xx_spi_get_ssrc1_change_mask(drv_data);
|
2016-09-07 14:04:05 +00:00
|
|
|
u32 clk_div;
|
|
|
|
u8 bits;
|
|
|
|
u32 speed;
|
2006-03-28 22:05:23 +00:00
|
|
|
u32 cr0;
|
2006-12-10 10:18:54 +00:00
|
|
|
u32 cr1;
|
2016-03-24 13:35:42 +00:00
|
|
|
int err;
|
2016-06-21 10:21:34 +00:00
|
|
|
int dma_mapped;
|
2006-03-08 07:53:24 +00:00
|
|
|
|
2013-01-22 10:26:28 +00:00
|
|
|
/* Check if we can DMA this transfer */
|
2016-06-21 10:21:34 +00:00
|
|
|
if (transfer->len > MAX_DMA_LEN && chip->enable_dma) {
|
2008-09-13 09:33:18 +00:00
|
|
|
|
|
|
|
/* reject already-mapped transfers; PIO won't always work */
|
|
|
|
if (message->is_dma_mapped
|
|
|
|
|| transfer->rx_dma || transfer->tx_dma) {
|
2019-03-29 13:00:46 +00:00
|
|
|
dev_err(&spi->dev,
|
2018-04-17 14:20:01 +00:00
|
|
|
"Mapped transfer length of %u is greater than %d\n",
|
2008-09-13 09:33:18 +00:00
|
|
|
transfer->len, MAX_DMA_LEN);
|
2018-04-17 14:20:02 +00:00
|
|
|
return -EINVAL;
|
2008-09-13 09:33:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* warn ... we force this to PIO mode */
|
2019-03-29 13:00:45 +00:00
|
|
|
dev_warn_ratelimited(&spi->dev,
|
2018-04-17 14:20:01 +00:00
|
|
|
"DMA disabled for transfer length %ld greater than %d\n",
|
2018-04-17 14:20:02 +00:00
|
|
|
(long)transfer->len, MAX_DMA_LEN);
|
2006-12-10 10:18:54 +00:00
|
|
|
}
|
|
|
|
|
2006-03-08 07:53:24 +00:00
|
|
|
/* Setup the transfer state based on the type of transfer */
|
2013-01-22 10:26:28 +00:00
|
|
|
if (pxa2xx_spi_flush(drv_data) == 0) {
|
2019-03-29 13:00:46 +00:00
|
|
|
dev_err(&spi->dev, "Flush failed\n");
|
2018-04-17 14:20:02 +00:00
|
|
|
return -EIO;
|
2006-03-08 07:53:24 +00:00
|
|
|
}
|
2006-03-28 22:05:23 +00:00
|
|
|
drv_data->n_bytes = chip->n_bytes;
|
2006-03-08 07:53:24 +00:00
|
|
|
drv_data->tx = (void *)transfer->tx_buf;
|
|
|
|
drv_data->tx_end = drv_data->tx + transfer->len;
|
|
|
|
drv_data->rx = transfer->rx_buf;
|
|
|
|
drv_data->rx_end = drv_data->rx + transfer->len;
|
|
|
|
drv_data->write = drv_data->tx ? chip->write : null_writer;
|
|
|
|
drv_data->read = drv_data->rx ? chip->read : null_reader;
|
2006-03-28 22:05:23 +00:00
|
|
|
|
|
|
|
/* Change speed and bit per word on a per transfer */
|
2015-09-15 13:26:27 +00:00
|
|
|
bits = transfer->bits_per_word;
|
|
|
|
speed = transfer->speed_hz;
|
|
|
|
|
2015-10-22 13:44:40 +00:00
|
|
|
clk_div = pxa2xx_ssp_get_clk_div(drv_data, speed);
|
2015-09-15 13:26:27 +00:00
|
|
|
|
|
|
|
if (bits <= 8) {
|
|
|
|
drv_data->n_bytes = 1;
|
|
|
|
drv_data->read = drv_data->read != null_reader ?
|
|
|
|
u8_reader : null_reader;
|
|
|
|
drv_data->write = drv_data->write != null_writer ?
|
|
|
|
u8_writer : null_writer;
|
|
|
|
} else if (bits <= 16) {
|
|
|
|
drv_data->n_bytes = 2;
|
|
|
|
drv_data->read = drv_data->read != null_reader ?
|
|
|
|
u16_reader : null_reader;
|
|
|
|
drv_data->write = drv_data->write != null_writer ?
|
|
|
|
u16_writer : null_writer;
|
|
|
|
} else if (bits <= 32) {
|
|
|
|
drv_data->n_bytes = 4;
|
|
|
|
drv_data->read = drv_data->read != null_reader ?
|
|
|
|
u32_reader : null_reader;
|
|
|
|
drv_data->write = drv_data->write != null_writer ?
|
|
|
|
u32_writer : null_writer;
|
2006-03-28 22:05:23 +00:00
|
|
|
}
|
2015-09-15 13:26:27 +00:00
|
|
|
/*
|
|
|
|
* if bits/word is changed in dma mode, then must check the
|
|
|
|
* thresholds and burst also
|
|
|
|
*/
|
|
|
|
if (chip->enable_dma) {
|
|
|
|
if (pxa2xx_spi_set_dma_burst_and_threshold(chip,
|
2019-03-29 13:00:45 +00:00
|
|
|
spi,
|
2015-09-15 13:26:27 +00:00
|
|
|
bits, &dma_burst,
|
|
|
|
&dma_thresh))
|
2019-03-29 13:00:45 +00:00
|
|
|
dev_warn_ratelimited(&spi->dev,
|
2018-04-17 14:20:01 +00:00
|
|
|
"DMA burst size reduced to match bits_per_word\n");
|
2006-03-28 22:05:23 +00:00
|
|
|
}
|
|
|
|
|
2019-01-16 15:13:31 +00:00
|
|
|
dma_mapped = controller->can_dma &&
|
2019-03-29 13:00:45 +00:00
|
|
|
controller->can_dma(controller, spi, transfer) &&
|
2019-01-16 15:13:31 +00:00
|
|
|
controller->cur_msg_mapped;
|
2016-06-21 10:21:34 +00:00
|
|
|
if (dma_mapped) {
|
2006-03-08 07:53:24 +00:00
|
|
|
|
|
|
|
/* Ensure we have the correct interrupt handler */
|
2013-01-22 10:26:28 +00:00
|
|
|
drv_data->transfer_handler = pxa2xx_spi_dma_transfer;
|
|
|
|
|
2018-04-17 14:20:02 +00:00
|
|
|
err = pxa2xx_spi_dma_prepare(drv_data, transfer);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2006-03-08 07:53:24 +00:00
|
|
|
|
2006-12-10 10:18:54 +00:00
|
|
|
/* Clear status and start DMA engine */
|
|
|
|
cr1 = chip->cr1 | dma_thresh | drv_data->dma_cr1;
|
2014-12-18 13:04:23 +00:00
|
|
|
pxa2xx_spi_write(drv_data, SSSR, drv_data->clear_sr);
|
2013-01-22 10:26:28 +00:00
|
|
|
|
|
|
|
pxa2xx_spi_dma_start(drv_data);
|
2006-03-08 07:53:24 +00:00
|
|
|
} else {
|
|
|
|
/* Ensure we have the correct interrupt handler */
|
|
|
|
drv_data->transfer_handler = interrupt_transfer;
|
|
|
|
|
2006-12-10 10:18:54 +00:00
|
|
|
/* Clear status */
|
|
|
|
cr1 = chip->cr1 | chip->threshold | drv_data->int_cr1;
|
2010-11-23 01:12:17 +00:00
|
|
|
write_SSSR_CS(drv_data, drv_data->clear_sr);
|
2006-12-10 10:18:54 +00:00
|
|
|
}
|
|
|
|
|
2016-01-26 13:33:21 +00:00
|
|
|
/* NOTE: PXA25x_SSP _could_ use external clocking ... */
|
|
|
|
cr0 = pxa2xx_configure_sscr0(drv_data, clk_div, bits);
|
|
|
|
if (!pxa25x_ssp_comp(drv_data))
|
2019-03-29 13:00:45 +00:00
|
|
|
dev_dbg(&spi->dev, "%u Hz actual, %s\n",
|
2019-01-16 15:13:31 +00:00
|
|
|
controller->max_speed_hz
|
2016-01-26 13:33:21 +00:00
|
|
|
/ (1 + ((cr0 & SSCR0_SCR(0xfff)) >> 8)),
|
2016-06-21 10:21:34 +00:00
|
|
|
dma_mapped ? "DMA" : "PIO");
|
2016-01-26 13:33:21 +00:00
|
|
|
else
|
2019-03-29 13:00:45 +00:00
|
|
|
dev_dbg(&spi->dev, "%u Hz actual, %s\n",
|
2019-01-16 15:13:31 +00:00
|
|
|
controller->max_speed_hz / 2
|
2016-01-26 13:33:21 +00:00
|
|
|
/ (1 + ((cr0 & SSCR0_SCR(0x0ff)) >> 8)),
|
2016-06-21 10:21:34 +00:00
|
|
|
dma_mapped ? "DMA" : "PIO");
|
2016-01-26 13:33:21 +00:00
|
|
|
|
2013-01-22 10:26:32 +00:00
|
|
|
if (is_lpss_ssp(drv_data)) {
|
2014-12-18 13:04:23 +00:00
|
|
|
if ((pxa2xx_spi_read(drv_data, SSIRF) & 0xff)
|
|
|
|
!= chip->lpss_rx_threshold)
|
|
|
|
pxa2xx_spi_write(drv_data, SSIRF,
|
|
|
|
chip->lpss_rx_threshold);
|
|
|
|
if ((pxa2xx_spi_read(drv_data, SSITF) & 0xffff)
|
|
|
|
!= chip->lpss_tx_threshold)
|
|
|
|
pxa2xx_spi_write(drv_data, SSITF,
|
|
|
|
chip->lpss_tx_threshold);
|
2013-01-22 10:26:32 +00:00
|
|
|
}
|
|
|
|
|
2014-11-26 10:35:10 +00:00
|
|
|
if (is_quark_x1000_ssp(drv_data) &&
|
2014-12-18 13:04:23 +00:00
|
|
|
(pxa2xx_spi_read(drv_data, DDS_RATE) != chip->dds_rate))
|
|
|
|
pxa2xx_spi_write(drv_data, DDS_RATE, chip->dds_rate);
|
2014-11-26 10:35:10 +00:00
|
|
|
|
2006-12-10 10:18:54 +00:00
|
|
|
/* see if we need to reload the config registers */
|
2014-12-18 13:04:23 +00:00
|
|
|
if ((pxa2xx_spi_read(drv_data, SSCR0) != cr0)
|
|
|
|
|| (pxa2xx_spi_read(drv_data, SSCR1) & change_mask)
|
|
|
|
!= (cr1 & change_mask)) {
|
2008-02-23 23:23:40 +00:00
|
|
|
/* stop the SSP, and update the other bits */
|
2020-02-27 16:25:56 +00:00
|
|
|
if (!is_mmp2_ssp(drv_data))
|
2020-01-18 09:40:31 +00:00
|
|
|
pxa2xx_spi_write(drv_data, SSCR0, cr0 & ~SSCR0_SSE);
|
2010-11-23 01:12:17 +00:00
|
|
|
if (!pxa25x_ssp_comp(drv_data))
|
2014-12-18 13:04:23 +00:00
|
|
|
pxa2xx_spi_write(drv_data, SSTO, chip->timeout);
|
2008-02-23 23:23:40 +00:00
|
|
|
/* first set CR1 without interrupt and service enables */
|
2014-12-18 13:04:23 +00:00
|
|
|
pxa2xx_spi_write(drv_data, SSCR1, cr1 & change_mask);
|
2008-02-23 23:23:40 +00:00
|
|
|
/* restart the SSP */
|
2014-12-18 13:04:23 +00:00
|
|
|
pxa2xx_spi_write(drv_data, SSCR0, cr0);
|
2008-02-23 23:23:40 +00:00
|
|
|
|
2006-12-10 10:18:54 +00:00
|
|
|
} else {
|
2010-11-23 01:12:17 +00:00
|
|
|
if (!pxa25x_ssp_comp(drv_data))
|
2014-12-18 13:04:23 +00:00
|
|
|
pxa2xx_spi_write(drv_data, SSTO, chip->timeout);
|
2006-03-08 07:53:24 +00:00
|
|
|
}
|
2008-02-23 23:23:40 +00:00
|
|
|
|
2020-02-27 16:25:56 +00:00
|
|
|
if (is_mmp2_ssp(drv_data)) {
|
2018-11-13 10:22:28 +00:00
|
|
|
u8 tx_level = (pxa2xx_spi_read(drv_data, SSSR)
|
|
|
|
& SSSR_TFL_MASK) >> 8;
|
|
|
|
|
|
|
|
if (tx_level) {
|
|
|
|
/* On MMP2, flipping SSE doesn't to empty TXFIFO. */
|
|
|
|
dev_warn(&spi->dev, "%d bytes of garbage in TXFIFO!\n",
|
|
|
|
tx_level);
|
|
|
|
if (tx_level > transfer->len)
|
|
|
|
tx_level = transfer->len;
|
|
|
|
drv_data->tx += tx_level;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-16 15:13:31 +00:00
|
|
|
if (spi_controller_is_slave(controller)) {
|
2018-11-13 10:22:25 +00:00
|
|
|
while (drv_data->write(drv_data))
|
|
|
|
;
|
2018-11-13 10:22:27 +00:00
|
|
|
if (drv_data->gpiod_ready) {
|
|
|
|
gpiod_set_value(drv_data->gpiod_ready, 1);
|
|
|
|
udelay(1);
|
|
|
|
gpiod_set_value(drv_data->gpiod_ready, 0);
|
|
|
|
}
|
2018-11-13 10:22:25 +00:00
|
|
|
}
|
|
|
|
|
2018-04-17 14:20:02 +00:00
|
|
|
/*
|
|
|
|
* Release the data by enabling service requests and interrupts,
|
|
|
|
* without changing any mode bits
|
|
|
|
*/
|
2014-12-18 13:04:23 +00:00
|
|
|
pxa2xx_spi_write(drv_data, SSCR1, cr1);
|
2018-04-17 14:20:02 +00:00
|
|
|
|
|
|
|
return 1;
|
2006-03-08 07:53:24 +00:00
|
|
|
}
|
|
|
|
|
2019-01-16 15:13:31 +00:00
|
|
|
static int pxa2xx_spi_slave_abort(struct spi_controller *controller)
|
2018-11-13 10:22:25 +00:00
|
|
|
{
|
2019-01-16 15:13:31 +00:00
|
|
|
struct driver_data *drv_data = spi_controller_get_devdata(controller);
|
2018-11-13 10:22:25 +00:00
|
|
|
|
|
|
|
/* Stop and reset SSP */
|
|
|
|
write_SSSR_CS(drv_data, drv_data->clear_sr);
|
|
|
|
reset_sccr1(drv_data);
|
|
|
|
if (!pxa25x_ssp_comp(drv_data))
|
|
|
|
pxa2xx_spi_write(drv_data, SSTO, 0);
|
|
|
|
pxa2xx_spi_flush(drv_data);
|
2020-01-18 09:40:31 +00:00
|
|
|
pxa2xx_spi_off(drv_data);
|
2018-11-13 10:22:25 +00:00
|
|
|
|
|
|
|
dev_dbg(&drv_data->pdev->dev, "transfer aborted\n");
|
|
|
|
|
2019-01-16 15:13:31 +00:00
|
|
|
drv_data->controller->cur_msg->status = -EINTR;
|
|
|
|
spi_finalize_current_transfer(drv_data->controller);
|
2018-11-13 10:22:25 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-01-16 15:13:31 +00:00
|
|
|
static void pxa2xx_spi_handle_err(struct spi_controller *controller,
|
2018-04-17 14:20:02 +00:00
|
|
|
struct spi_message *msg)
|
2006-03-08 07:53:24 +00:00
|
|
|
{
|
2019-01-16 15:13:31 +00:00
|
|
|
struct driver_data *drv_data = spi_controller_get_devdata(controller);
|
2006-03-08 07:53:24 +00:00
|
|
|
|
2018-04-17 14:20:02 +00:00
|
|
|
/* Disable the SSP */
|
2020-01-18 09:40:31 +00:00
|
|
|
pxa2xx_spi_off(drv_data);
|
2018-04-17 14:20:02 +00:00
|
|
|
/* Clear and disable interrupts and service requests */
|
|
|
|
write_SSSR_CS(drv_data, drv_data->clear_sr);
|
|
|
|
pxa2xx_spi_write(drv_data, SSCR1,
|
|
|
|
pxa2xx_spi_read(drv_data, SSCR1)
|
|
|
|
& ~(drv_data->int_cr1 | drv_data->dma_cr1));
|
|
|
|
if (!pxa25x_ssp_comp(drv_data))
|
|
|
|
pxa2xx_spi_write(drv_data, SSTO, 0);
|
2006-03-08 07:53:24 +00:00
|
|
|
|
2018-04-17 14:20:02 +00:00
|
|
|
/*
|
|
|
|
* Stop the DMA if running. Note DMA callback handler may have unset
|
|
|
|
* the dma_running already, which is fine as stopping is not needed
|
|
|
|
* then but we shouldn't rely this flag for anything else than
|
|
|
|
* stopping. For instance to differentiate between PIO and DMA
|
|
|
|
* transfers.
|
|
|
|
*/
|
|
|
|
if (atomic_read(&drv_data->dma_running))
|
|
|
|
pxa2xx_spi_dma_stop(drv_data);
|
2006-03-08 07:53:24 +00:00
|
|
|
}
|
|
|
|
|
2019-01-16 15:13:31 +00:00
|
|
|
static int pxa2xx_spi_unprepare_transfer(struct spi_controller *controller)
|
2013-01-22 10:26:30 +00:00
|
|
|
{
|
2019-01-16 15:13:31 +00:00
|
|
|
struct driver_data *drv_data = spi_controller_get_devdata(controller);
|
2013-01-22 10:26:30 +00:00
|
|
|
|
|
|
|
/* Disable the SSP now */
|
2020-01-18 09:40:31 +00:00
|
|
|
pxa2xx_spi_off(drv_data);
|
2013-01-22 10:26:30 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-04-07 02:00:54 +00:00
|
|
|
static int setup_cs(struct spi_device *spi, struct chip_data *chip,
|
|
|
|
struct pxa2xx_spi_chip *chip_info)
|
|
|
|
{
|
2018-02-01 15:17:30 +00:00
|
|
|
struct driver_data *drv_data =
|
|
|
|
spi_controller_get_devdata(spi->controller);
|
2017-08-03 11:40:32 +00:00
|
|
|
struct gpio_desc *gpiod;
|
2009-04-07 02:00:54 +00:00
|
|
|
int err = 0;
|
|
|
|
|
2016-09-26 12:19:50 +00:00
|
|
|
if (chip == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2017-07-27 11:37:08 +00:00
|
|
|
if (drv_data->cs_gpiods) {
|
|
|
|
gpiod = drv_data->cs_gpiods[spi->chip_select];
|
|
|
|
if (gpiod) {
|
2017-08-03 11:40:32 +00:00
|
|
|
chip->gpiod_cs = gpiod;
|
2017-07-27 11:37:08 +00:00
|
|
|
chip->gpio_cs_inverted = spi->mode & SPI_CS_HIGH;
|
|
|
|
gpiod_set_value(gpiod, chip->gpio_cs_inverted);
|
2016-09-26 12:19:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (chip_info == NULL)
|
2009-04-07 02:00:54 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* NOTE: setup() can be called multiple times, possibly with
|
|
|
|
* different chip_info, release previously requested GPIO
|
|
|
|
*/
|
2017-08-03 11:40:32 +00:00
|
|
|
if (chip->gpiod_cs) {
|
2017-12-22 16:15:36 +00:00
|
|
|
gpiod_put(chip->gpiod_cs);
|
2017-08-03 11:40:32 +00:00
|
|
|
chip->gpiod_cs = NULL;
|
|
|
|
}
|
2009-04-07 02:00:54 +00:00
|
|
|
|
|
|
|
/* If (*cs_control) is provided, ignore GPIO chip select */
|
|
|
|
if (chip_info->cs_control) {
|
|
|
|
chip->cs_control = chip_info->cs_control;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gpio_is_valid(chip_info->gpio_cs)) {
|
|
|
|
err = gpio_request(chip_info->gpio_cs, "SPI_CS");
|
|
|
|
if (err) {
|
2013-10-11 10:54:00 +00:00
|
|
|
dev_err(&spi->dev, "failed to request chip select GPIO%d\n",
|
|
|
|
chip_info->gpio_cs);
|
2009-04-07 02:00:54 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2017-08-03 11:40:32 +00:00
|
|
|
gpiod = gpio_to_desc(chip_info->gpio_cs);
|
|
|
|
chip->gpiod_cs = gpiod;
|
2009-04-07 02:00:54 +00:00
|
|
|
chip->gpio_cs_inverted = spi->mode & SPI_CS_HIGH;
|
|
|
|
|
2017-08-03 11:40:32 +00:00
|
|
|
err = gpiod_direction_output(gpiod, !chip->gpio_cs_inverted);
|
2009-04-07 02:00:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2006-03-08 07:53:24 +00:00
|
|
|
static int setup(struct spi_device *spi)
|
|
|
|
{
|
2016-09-07 14:04:05 +00:00
|
|
|
struct pxa2xx_spi_chip *chip_info;
|
2006-03-08 07:53:24 +00:00
|
|
|
struct chip_data *chip;
|
2015-06-04 13:55:11 +00:00
|
|
|
const struct lpss_config *config;
|
2018-02-01 15:17:30 +00:00
|
|
|
struct driver_data *drv_data =
|
|
|
|
spi_controller_get_devdata(spi->controller);
|
2013-01-22 10:26:32 +00:00
|
|
|
uint tx_thres, tx_hi_thres, rx_thres;
|
|
|
|
|
2014-11-26 10:35:10 +00:00
|
|
|
switch (drv_data->ssp_type) {
|
|
|
|
case QUARK_X1000_SSP:
|
|
|
|
tx_thres = TX_THRESH_QUARK_X1000_DFLT;
|
|
|
|
tx_hi_thres = 0;
|
|
|
|
rx_thres = RX_THRESH_QUARK_X1000_DFLT;
|
|
|
|
break;
|
2016-09-07 12:43:22 +00:00
|
|
|
case CE4100_SSP:
|
|
|
|
tx_thres = TX_THRESH_CE4100_DFLT;
|
|
|
|
tx_hi_thres = 0;
|
|
|
|
rx_thres = RX_THRESH_CE4100_DFLT;
|
|
|
|
break;
|
2015-06-04 13:55:10 +00:00
|
|
|
case LPSS_LPT_SSP:
|
|
|
|
case LPSS_BYT_SSP:
|
2016-02-08 15:14:31 +00:00
|
|
|
case LPSS_BSW_SSP:
|
2015-07-30 13:30:07 +00:00
|
|
|
case LPSS_SPT_SSP:
|
2015-10-28 13:13:42 +00:00
|
|
|
case LPSS_BXT_SSP:
|
2017-05-30 14:31:21 +00:00
|
|
|
case LPSS_CNL_SSP:
|
2015-06-04 13:55:11 +00:00
|
|
|
config = lpss_get_config(drv_data);
|
|
|
|
tx_thres = config->tx_threshold_lo;
|
|
|
|
tx_hi_thres = config->tx_threshold_hi;
|
|
|
|
rx_thres = config->rx_threshold;
|
2014-11-26 10:35:10 +00:00
|
|
|
break;
|
|
|
|
default:
|
2013-01-22 10:26:32 +00:00
|
|
|
tx_hi_thres = 0;
|
2019-01-16 15:13:31 +00:00
|
|
|
if (spi_controller_is_slave(drv_data->controller)) {
|
2018-11-13 10:22:25 +00:00
|
|
|
tx_thres = 1;
|
|
|
|
rx_thres = 2;
|
|
|
|
} else {
|
|
|
|
tx_thres = TX_THRESH_DFLT;
|
|
|
|
rx_thres = RX_THRESH_DFLT;
|
|
|
|
}
|
2014-11-26 10:35:10 +00:00
|
|
|
break;
|
2013-01-22 10:26:32 +00:00
|
|
|
}
|
2006-03-08 07:53:24 +00:00
|
|
|
|
2006-12-10 10:18:54 +00:00
|
|
|
/* Only alloc on first setup */
|
2006-03-08 07:53:24 +00:00
|
|
|
chip = spi_get_ctldata(spi);
|
2006-12-10 10:18:54 +00:00
|
|
|
if (!chip) {
|
2006-03-08 07:53:24 +00:00
|
|
|
chip = kzalloc(sizeof(struct chip_data), GFP_KERNEL);
|
2014-04-29 08:19:38 +00:00
|
|
|
if (!chip)
|
2006-03-08 07:53:24 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2010-11-23 01:12:17 +00:00
|
|
|
if (drv_data->ssp_type == CE4100_SSP) {
|
|
|
|
if (spi->chip_select > 4) {
|
2013-10-11 10:54:00 +00:00
|
|
|
dev_err(&spi->dev,
|
|
|
|
"failed setup: cs number must not be > 4.\n");
|
2010-11-23 01:12:17 +00:00
|
|
|
kfree(chip);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
chip->frm = spi->chip_select;
|
2017-08-03 11:40:32 +00:00
|
|
|
}
|
2019-01-16 15:13:31 +00:00
|
|
|
chip->enable_dma = drv_data->controller_info->enable_dma;
|
2008-10-16 05:02:43 +00:00
|
|
|
chip->timeout = TIMOUT_DFLT;
|
2006-03-08 07:53:24 +00:00
|
|
|
}
|
|
|
|
|
2006-12-10 10:18:54 +00:00
|
|
|
/* protocol drivers may change the chip settings, so...
|
|
|
|
* if chip_info exists, use it */
|
|
|
|
chip_info = spi->controller_data;
|
|
|
|
|
2006-03-08 07:53:24 +00:00
|
|
|
/* chip_info isn't always needed */
|
2006-12-10 10:18:54 +00:00
|
|
|
chip->cr1 = 0;
|
2006-03-08 07:53:24 +00:00
|
|
|
if (chip_info) {
|
2008-10-16 05:02:43 +00:00
|
|
|
if (chip_info->timeout)
|
|
|
|
chip->timeout = chip_info->timeout;
|
|
|
|
if (chip_info->tx_threshold)
|
|
|
|
tx_thres = chip_info->tx_threshold;
|
2013-01-22 10:26:32 +00:00
|
|
|
if (chip_info->tx_hi_threshold)
|
|
|
|
tx_hi_thres = chip_info->tx_hi_threshold;
|
2008-10-16 05:02:43 +00:00
|
|
|
if (chip_info->rx_threshold)
|
|
|
|
rx_thres = chip_info->rx_threshold;
|
2006-03-08 07:53:24 +00:00
|
|
|
chip->dma_threshold = 0;
|
|
|
|
if (chip_info->enable_loopback)
|
|
|
|
chip->cr1 = SSCR1_LBM;
|
|
|
|
}
|
2019-01-16 15:13:31 +00:00
|
|
|
if (spi_controller_is_slave(drv_data->controller)) {
|
2018-11-13 10:22:25 +00:00
|
|
|
chip->cr1 |= SSCR1_SCFR;
|
|
|
|
chip->cr1 |= SSCR1_SCLKDIR;
|
|
|
|
chip->cr1 |= SSCR1_SFRMDIR;
|
|
|
|
chip->cr1 |= SSCR1_SPH;
|
|
|
|
}
|
2006-03-08 07:53:24 +00:00
|
|
|
|
2013-01-22 10:26:32 +00:00
|
|
|
chip->lpss_rx_threshold = SSIRF_RxThresh(rx_thres);
|
|
|
|
chip->lpss_tx_threshold = SSITF_TxLoThresh(tx_thres)
|
|
|
|
| SSITF_TxHiThresh(tx_hi_thres);
|
|
|
|
|
2006-12-10 10:18:54 +00:00
|
|
|
/* set dma burst and threshold outside of chip_info path so that if
|
|
|
|
* chip_info goes away after setting chip->enable_dma, the
|
|
|
|
* burst and threshold can still respond to changes in bits_per_word */
|
|
|
|
if (chip->enable_dma) {
|
|
|
|
/* set up legal burst and threshold for dma */
|
2013-01-22 10:26:28 +00:00
|
|
|
if (pxa2xx_spi_set_dma_burst_and_threshold(chip, spi,
|
|
|
|
spi->bits_per_word,
|
2006-12-10 10:18:54 +00:00
|
|
|
&chip->dma_burst_size,
|
|
|
|
&chip->dma_threshold)) {
|
2013-10-11 10:54:00 +00:00
|
|
|
dev_warn(&spi->dev,
|
|
|
|
"in setup: DMA burst size reduced to match bits_per_word\n");
|
2006-12-10 10:18:54 +00:00
|
|
|
}
|
2019-03-19 15:48:43 +00:00
|
|
|
dev_dbg(&spi->dev,
|
|
|
|
"in setup: DMA burst size set to %u\n",
|
|
|
|
chip->dma_burst_size);
|
2006-12-10 10:18:54 +00:00
|
|
|
}
|
|
|
|
|
2014-11-26 10:35:10 +00:00
|
|
|
switch (drv_data->ssp_type) {
|
|
|
|
case QUARK_X1000_SSP:
|
|
|
|
chip->threshold = (QUARK_X1000_SSCR1_RxTresh(rx_thres)
|
|
|
|
& QUARK_X1000_SSCR1_RFT)
|
|
|
|
| (QUARK_X1000_SSCR1_TxTresh(tx_thres)
|
|
|
|
& QUARK_X1000_SSCR1_TFT);
|
|
|
|
break;
|
2016-09-07 12:43:22 +00:00
|
|
|
case CE4100_SSP:
|
|
|
|
chip->threshold = (CE4100_SSCR1_RxTresh(rx_thres) & CE4100_SSCR1_RFT) |
|
|
|
|
(CE4100_SSCR1_TxTresh(tx_thres) & CE4100_SSCR1_TFT);
|
|
|
|
break;
|
2014-11-26 10:35:10 +00:00
|
|
|
default:
|
|
|
|
chip->threshold = (SSCR1_RxTresh(rx_thres) & SSCR1_RFT) |
|
|
|
|
(SSCR1_TxTresh(tx_thres) & SSCR1_TFT);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-01-26 08:56:44 +00:00
|
|
|
chip->cr1 &= ~(SSCR1_SPO | SSCR1_SPH);
|
|
|
|
chip->cr1 |= (((spi->mode & SPI_CPHA) != 0) ? SSCR1_SPH : 0)
|
|
|
|
| (((spi->mode & SPI_CPOL) != 0) ? SSCR1_SPO : 0);
|
2006-03-08 07:53:24 +00:00
|
|
|
|
2013-01-22 10:26:31 +00:00
|
|
|
if (spi->mode & SPI_LOOP)
|
|
|
|
chip->cr1 |= SSCR1_LBM;
|
|
|
|
|
2006-03-08 07:53:24 +00:00
|
|
|
if (spi->bits_per_word <= 8) {
|
|
|
|
chip->n_bytes = 1;
|
|
|
|
chip->read = u8_reader;
|
|
|
|
chip->write = u8_writer;
|
|
|
|
} else if (spi->bits_per_word <= 16) {
|
|
|
|
chip->n_bytes = 2;
|
|
|
|
chip->read = u16_reader;
|
|
|
|
chip->write = u16_writer;
|
|
|
|
} else if (spi->bits_per_word <= 32) {
|
|
|
|
chip->n_bytes = 4;
|
|
|
|
chip->read = u32_reader;
|
|
|
|
chip->write = u32_writer;
|
|
|
|
}
|
|
|
|
|
|
|
|
spi_set_ctldata(spi, chip);
|
|
|
|
|
2010-11-23 01:12:17 +00:00
|
|
|
if (drv_data->ssp_type == CE4100_SSP)
|
|
|
|
return 0;
|
|
|
|
|
2009-04-07 02:00:54 +00:00
|
|
|
return setup_cs(spi, chip, chip_info);
|
2006-03-08 07:53:24 +00:00
|
|
|
}
|
|
|
|
|
2007-02-12 08:52:45 +00:00
|
|
|
static void cleanup(struct spi_device *spi)
|
2006-03-08 07:53:24 +00:00
|
|
|
{
|
2007-02-12 08:52:45 +00:00
|
|
|
struct chip_data *chip = spi_get_ctldata(spi);
|
2018-02-01 15:17:30 +00:00
|
|
|
struct driver_data *drv_data =
|
|
|
|
spi_controller_get_devdata(spi->controller);
|
2006-03-08 07:53:24 +00:00
|
|
|
|
2009-05-12 20:19:36 +00:00
|
|
|
if (!chip)
|
|
|
|
return;
|
|
|
|
|
2017-07-27 11:37:08 +00:00
|
|
|
if (drv_data->ssp_type != CE4100_SSP && !drv_data->cs_gpiods &&
|
2017-08-03 11:40:32 +00:00
|
|
|
chip->gpiod_cs)
|
2017-12-22 16:15:36 +00:00
|
|
|
gpiod_put(chip->gpiod_cs);
|
2009-04-07 02:00:54 +00:00
|
|
|
|
2006-03-08 07:53:24 +00:00
|
|
|
kfree(chip);
|
|
|
|
}
|
|
|
|
|
2020-07-17 13:54:23 +00:00
|
|
|
#ifdef CONFIG_ACPI
|
2015-06-13 12:22:14 +00:00
|
|
|
static const struct acpi_device_id pxa2xx_spi_acpi_match[] = {
|
2015-06-04 13:55:10 +00:00
|
|
|
{ "INT33C0", LPSS_LPT_SSP },
|
|
|
|
{ "INT33C1", LPSS_LPT_SSP },
|
|
|
|
{ "INT3430", LPSS_LPT_SSP },
|
|
|
|
{ "INT3431", LPSS_LPT_SSP },
|
|
|
|
{ "80860F0E", LPSS_BYT_SSP },
|
2016-02-08 15:14:31 +00:00
|
|
|
{ "8086228E", LPSS_BSW_SSP },
|
2015-06-04 13:55:10 +00:00
|
|
|
{ },
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(acpi, pxa2xx_spi_acpi_match);
|
2020-07-17 13:54:23 +00:00
|
|
|
#endif
|
2015-06-04 13:55:10 +00:00
|
|
|
|
2015-07-30 13:30:07 +00:00
|
|
|
/*
|
|
|
|
* PCI IDs of compound devices that integrate both host controller and private
|
|
|
|
* integrated DMA engine. Please note these are not used in module
|
|
|
|
* autoloading and probing in this module but matching the LPSS SSP type.
|
|
|
|
*/
|
|
|
|
static const struct pci_device_id pxa2xx_spi_pci_compound_match[] = {
|
|
|
|
/* SPT-LP */
|
|
|
|
{ PCI_VDEVICE(INTEL, 0x9d29), LPSS_SPT_SSP },
|
|
|
|
{ PCI_VDEVICE(INTEL, 0x9d2a), LPSS_SPT_SSP },
|
|
|
|
/* SPT-H */
|
|
|
|
{ PCI_VDEVICE(INTEL, 0xa129), LPSS_SPT_SSP },
|
|
|
|
{ PCI_VDEVICE(INTEL, 0xa12a), LPSS_SPT_SSP },
|
2016-07-04 10:21:07 +00:00
|
|
|
/* KBL-H */
|
|
|
|
{ PCI_VDEVICE(INTEL, 0xa2a9), LPSS_SPT_SSP },
|
|
|
|
{ PCI_VDEVICE(INTEL, 0xa2aa), LPSS_SPT_SSP },
|
2020-01-16 09:10:35 +00:00
|
|
|
/* CML-V */
|
|
|
|
{ PCI_VDEVICE(INTEL, 0xa3a9), LPSS_SPT_SSP },
|
|
|
|
{ PCI_VDEVICE(INTEL, 0xa3aa), LPSS_SPT_SSP },
|
2016-03-02 07:54:14 +00:00
|
|
|
/* BXT A-Step */
|
2015-10-28 13:13:42 +00:00
|
|
|
{ PCI_VDEVICE(INTEL, 0x0ac2), LPSS_BXT_SSP },
|
|
|
|
{ PCI_VDEVICE(INTEL, 0x0ac4), LPSS_BXT_SSP },
|
|
|
|
{ PCI_VDEVICE(INTEL, 0x0ac6), LPSS_BXT_SSP },
|
2016-03-02 07:54:14 +00:00
|
|
|
/* BXT B-Step */
|
|
|
|
{ PCI_VDEVICE(INTEL, 0x1ac2), LPSS_BXT_SSP },
|
|
|
|
{ PCI_VDEVICE(INTEL, 0x1ac4), LPSS_BXT_SSP },
|
|
|
|
{ PCI_VDEVICE(INTEL, 0x1ac6), LPSS_BXT_SSP },
|
2017-01-19 14:25:21 +00:00
|
|
|
/* GLK */
|
|
|
|
{ PCI_VDEVICE(INTEL, 0x31c2), LPSS_BXT_SSP },
|
|
|
|
{ PCI_VDEVICE(INTEL, 0x31c4), LPSS_BXT_SSP },
|
|
|
|
{ PCI_VDEVICE(INTEL, 0x31c6), LPSS_BXT_SSP },
|
2018-06-28 10:52:23 +00:00
|
|
|
/* ICL-LP */
|
|
|
|
{ PCI_VDEVICE(INTEL, 0x34aa), LPSS_CNL_SSP },
|
|
|
|
{ PCI_VDEVICE(INTEL, 0x34ab), LPSS_CNL_SSP },
|
|
|
|
{ PCI_VDEVICE(INTEL, 0x34fb), LPSS_CNL_SSP },
|
2019-07-03 11:46:03 +00:00
|
|
|
/* EHL */
|
|
|
|
{ PCI_VDEVICE(INTEL, 0x4b2a), LPSS_BXT_SSP },
|
|
|
|
{ PCI_VDEVICE(INTEL, 0x4b2b), LPSS_BXT_SSP },
|
|
|
|
{ PCI_VDEVICE(INTEL, 0x4b37), LPSS_BXT_SSP },
|
2019-11-25 12:51:59 +00:00
|
|
|
/* JSL */
|
|
|
|
{ PCI_VDEVICE(INTEL, 0x4daa), LPSS_CNL_SSP },
|
|
|
|
{ PCI_VDEVICE(INTEL, 0x4dab), LPSS_CNL_SSP },
|
|
|
|
{ PCI_VDEVICE(INTEL, 0x4dfb), LPSS_CNL_SSP },
|
2020-06-25 14:00:41 +00:00
|
|
|
/* TGL-H */
|
|
|
|
{ PCI_VDEVICE(INTEL, 0x43aa), LPSS_CNL_SSP },
|
|
|
|
{ PCI_VDEVICE(INTEL, 0x43ab), LPSS_CNL_SSP },
|
|
|
|
{ PCI_VDEVICE(INTEL, 0x43fb), LPSS_CNL_SSP },
|
|
|
|
{ PCI_VDEVICE(INTEL, 0x43fd), LPSS_CNL_SSP },
|
2015-10-28 13:13:42 +00:00
|
|
|
/* APL */
|
|
|
|
{ PCI_VDEVICE(INTEL, 0x5ac2), LPSS_BXT_SSP },
|
|
|
|
{ PCI_VDEVICE(INTEL, 0x5ac4), LPSS_BXT_SSP },
|
|
|
|
{ PCI_VDEVICE(INTEL, 0x5ac6), LPSS_BXT_SSP },
|
2017-05-30 14:31:21 +00:00
|
|
|
/* CNL-LP */
|
|
|
|
{ PCI_VDEVICE(INTEL, 0x9daa), LPSS_CNL_SSP },
|
|
|
|
{ PCI_VDEVICE(INTEL, 0x9dab), LPSS_CNL_SSP },
|
|
|
|
{ PCI_VDEVICE(INTEL, 0x9dfb), LPSS_CNL_SSP },
|
|
|
|
/* CNL-H */
|
|
|
|
{ PCI_VDEVICE(INTEL, 0xa32a), LPSS_CNL_SSP },
|
|
|
|
{ PCI_VDEVICE(INTEL, 0xa32b), LPSS_CNL_SSP },
|
|
|
|
{ PCI_VDEVICE(INTEL, 0xa37b), LPSS_CNL_SSP },
|
2019-04-16 03:27:43 +00:00
|
|
|
/* CML-LP */
|
|
|
|
{ PCI_VDEVICE(INTEL, 0x02aa), LPSS_CNL_SSP },
|
|
|
|
{ PCI_VDEVICE(INTEL, 0x02ab), LPSS_CNL_SSP },
|
|
|
|
{ PCI_VDEVICE(INTEL, 0x02fb), LPSS_CNL_SSP },
|
2019-10-29 11:58:02 +00:00
|
|
|
/* CML-H */
|
|
|
|
{ PCI_VDEVICE(INTEL, 0x06aa), LPSS_CNL_SSP },
|
|
|
|
{ PCI_VDEVICE(INTEL, 0x06ab), LPSS_CNL_SSP },
|
|
|
|
{ PCI_VDEVICE(INTEL, 0x06fb), LPSS_CNL_SSP },
|
2019-08-01 13:49:01 +00:00
|
|
|
/* TGL-LP */
|
|
|
|
{ PCI_VDEVICE(INTEL, 0xa0aa), LPSS_CNL_SSP },
|
|
|
|
{ PCI_VDEVICE(INTEL, 0xa0ab), LPSS_CNL_SSP },
|
|
|
|
{ PCI_VDEVICE(INTEL, 0xa0de), LPSS_CNL_SSP },
|
|
|
|
{ PCI_VDEVICE(INTEL, 0xa0df), LPSS_CNL_SSP },
|
|
|
|
{ PCI_VDEVICE(INTEL, 0xa0fb), LPSS_CNL_SSP },
|
|
|
|
{ PCI_VDEVICE(INTEL, 0xa0fd), LPSS_CNL_SSP },
|
|
|
|
{ PCI_VDEVICE(INTEL, 0xa0fe), LPSS_CNL_SSP },
|
2015-08-04 05:52:22 +00:00
|
|
|
{ },
|
2015-07-30 13:30:07 +00:00
|
|
|
};
|
|
|
|
|
2018-10-10 17:09:29 +00:00
|
|
|
static const struct of_device_id pxa2xx_spi_of_match[] = {
|
|
|
|
{ .compatible = "marvell,mmp2-ssp", .data = (void *)MMP2_SSP },
|
|
|
|
{},
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, pxa2xx_spi_of_match);
|
|
|
|
|
|
|
|
#ifdef CONFIG_ACPI
|
|
|
|
|
2019-10-18 10:54:27 +00:00
|
|
|
static int pxa2xx_spi_get_port_id(struct device *dev)
|
2018-10-10 17:09:29 +00:00
|
|
|
{
|
2019-10-18 10:54:27 +00:00
|
|
|
struct acpi_device *adev;
|
2018-10-10 17:09:29 +00:00
|
|
|
unsigned int devid;
|
|
|
|
int port_id = -1;
|
|
|
|
|
2019-10-18 10:54:27 +00:00
|
|
|
adev = ACPI_COMPANION(dev);
|
2018-10-10 17:09:29 +00:00
|
|
|
if (adev && adev->pnp.unique_id &&
|
|
|
|
!kstrtouint(adev->pnp.unique_id, 0, &devid))
|
|
|
|
port_id = devid;
|
|
|
|
return port_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else /* !CONFIG_ACPI */
|
|
|
|
|
2019-10-18 10:54:27 +00:00
|
|
|
static int pxa2xx_spi_get_port_id(struct device *dev)
|
2018-10-10 17:09:29 +00:00
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_ACPI */
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef CONFIG_PCI
|
|
|
|
|
2015-07-30 13:30:07 +00:00
|
|
|
static bool pxa2xx_spi_idma_filter(struct dma_chan *chan, void *param)
|
|
|
|
{
|
dmaengine: idma64: Use actual device for DMA transfers
Intel IOMMU, when enabled, tries to find the domain of the device,
assuming it's a PCI one, during DMA operations, such as mapping or
unmapping. Since we are splitting the actual PCI device to couple of
children via MFD framework (see drivers/mfd/intel-lpss.c for details),
the DMA device appears to be a platform one, and thus not an actual one
that performs DMA. In a such situation IOMMU can't find or allocate
a proper domain for its operations. As a result, all DMA operations are
failed.
In order to fix this, supply parent of the platform device
to the DMA engine framework and fix filter functions accordingly.
We may rely on the fact that parent is a real PCI device, because no
other configuration is present in the wild.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Mark Brown <broonie@kernel.org>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> [for tty parts]
Signed-off-by: Vinod Koul <vkoul@kernel.org>
2019-03-18 15:39:30 +00:00
|
|
|
return param == chan->device->dev;
|
2015-07-30 13:30:07 +00:00
|
|
|
}
|
|
|
|
|
2018-10-10 17:09:29 +00:00
|
|
|
#endif /* CONFIG_PCI */
|
|
|
|
|
2019-01-16 15:13:31 +00:00
|
|
|
static struct pxa2xx_spi_controller *
|
2015-10-28 13:13:43 +00:00
|
|
|
pxa2xx_spi_init_pdata(struct platform_device *pdev)
|
2013-01-22 10:26:33 +00:00
|
|
|
{
|
2019-01-16 15:13:31 +00:00
|
|
|
struct pxa2xx_spi_controller *pdata;
|
2013-01-22 10:26:33 +00:00
|
|
|
struct ssp_device *ssp;
|
|
|
|
struct resource *res;
|
2019-10-21 10:36:24 +00:00
|
|
|
struct device *parent = pdev->dev.parent;
|
|
|
|
struct pci_dev *pcidev = dev_is_pci(parent) ? to_pci_dev(parent) : NULL;
|
2015-07-30 13:30:07 +00:00
|
|
|
const struct pci_device_id *pcidev_id = NULL;
|
2018-10-10 17:09:28 +00:00
|
|
|
enum pxa_ssp_type type;
|
2019-10-18 10:54:28 +00:00
|
|
|
const void *match;
|
2013-01-22 10:26:33 +00:00
|
|
|
|
2019-10-21 10:36:24 +00:00
|
|
|
if (pcidev)
|
|
|
|
pcidev_id = pci_match_id(pxa2xx_spi_pci_compound_match, pcidev);
|
2015-07-30 13:30:07 +00:00
|
|
|
|
2019-10-18 10:54:28 +00:00
|
|
|
match = device_get_match_data(&pdev->dev);
|
|
|
|
if (match)
|
|
|
|
type = (enum pxa_ssp_type)match;
|
2015-07-30 13:30:07 +00:00
|
|
|
else if (pcidev_id)
|
2018-10-10 17:09:28 +00:00
|
|
|
type = (enum pxa_ssp_type)pcidev_id->driver_data;
|
2015-06-04 13:55:10 +00:00
|
|
|
else
|
2020-02-24 15:45:55 +00:00
|
|
|
return ERR_PTR(-EINVAL);
|
2015-06-04 13:55:10 +00:00
|
|
|
|
2013-06-20 14:44:22 +00:00
|
|
|
pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
|
2014-04-29 08:19:38 +00:00
|
|
|
if (!pdata)
|
2020-02-24 15:45:55 +00:00
|
|
|
return ERR_PTR(-ENOMEM);
|
2013-01-22 10:26:33 +00:00
|
|
|
|
|
|
|
ssp = &pdata->ssp;
|
|
|
|
|
2019-10-21 10:36:25 +00:00
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
2013-04-08 10:19:33 +00:00
|
|
|
ssp->mmio_base = devm_ioremap_resource(&pdev->dev, res);
|
|
|
|
if (IS_ERR(ssp->mmio_base))
|
2020-02-24 15:45:55 +00:00
|
|
|
return ERR_CAST(ssp->mmio_base);
|
2013-01-22 10:26:33 +00:00
|
|
|
|
2019-10-21 10:36:25 +00:00
|
|
|
ssp->phys_base = res->start;
|
|
|
|
|
2018-10-10 17:09:29 +00:00
|
|
|
#ifdef CONFIG_PCI
|
2015-07-30 13:30:07 +00:00
|
|
|
if (pcidev_id) {
|
2019-10-21 10:36:24 +00:00
|
|
|
pdata->tx_param = parent;
|
|
|
|
pdata->rx_param = parent;
|
2015-07-30 13:30:07 +00:00
|
|
|
pdata->dma_filter = pxa2xx_spi_idma_filter;
|
|
|
|
}
|
2018-10-10 17:09:29 +00:00
|
|
|
#endif
|
2015-07-30 13:30:07 +00:00
|
|
|
|
2013-01-22 10:26:33 +00:00
|
|
|
ssp->clk = devm_clk_get(&pdev->dev, NULL);
|
2019-11-09 08:09:43 +00:00
|
|
|
if (IS_ERR(ssp->clk))
|
2020-02-24 15:45:55 +00:00
|
|
|
return ERR_CAST(ssp->clk);
|
2019-11-09 08:09:43 +00:00
|
|
|
|
2013-01-22 10:26:33 +00:00
|
|
|
ssp->irq = platform_get_irq(pdev, 0);
|
2019-11-09 08:09:43 +00:00
|
|
|
if (ssp->irq < 0)
|
2020-02-24 15:45:55 +00:00
|
|
|
return ERR_PTR(ssp->irq);
|
2019-11-09 08:09:43 +00:00
|
|
|
|
2015-06-04 13:55:10 +00:00
|
|
|
ssp->type = type;
|
2019-10-18 10:54:25 +00:00
|
|
|
ssp->dev = &pdev->dev;
|
2019-10-18 10:54:27 +00:00
|
|
|
ssp->port_id = pxa2xx_spi_get_port_id(&pdev->dev);
|
2013-01-22 10:26:33 +00:00
|
|
|
|
2019-10-18 10:54:28 +00:00
|
|
|
pdata->is_slave = device_property_read_bool(&pdev->dev, "spi-slave");
|
2013-01-22 10:26:33 +00:00
|
|
|
pdata->num_chipselect = 1;
|
2013-05-13 10:45:10 +00:00
|
|
|
pdata->enable_dma = true;
|
2019-03-19 15:48:42 +00:00
|
|
|
pdata->dma_burst_size = 1;
|
2013-01-22 10:26:33 +00:00
|
|
|
|
|
|
|
return pdata;
|
|
|
|
}
|
|
|
|
|
2019-01-16 15:13:31 +00:00
|
|
|
static int pxa2xx_spi_fw_translate_cs(struct spi_controller *controller,
|
2018-02-01 15:17:30 +00:00
|
|
|
unsigned int cs)
|
spi: pxa2xx: Translate ACPI DeviceSelection to Linux chip select on Baytrail
The Windows Baytrail SPI host controller driver uses 1 as the first (and
only) value for ACPI DeviceSelection like can be seen in DSDT taken from
Lenovo Thinkpad 10:
Device (FPNT)
{
...
Method (_CRS, 0, NotSerialized) // _CRS: Current Resource Settings
{
Name (UBUF, ResourceTemplate ()
{
SpiSerialBus (0x0001, // DeviceSelection
PolarityLow, FourWireMode, 0x08,
ControllerInitiated, 0x007A1200, ClockPolarityLow,
ClockPhaseFirst, "\\_SB.SPI1",
0x00, ResourceConsumer,,)
This will fail to enumerate in Linux with following error:
[ 0.241296] pxa2xx-spi 80860F0E:00: cs1 >= max 1
[ 0.241312] spi_master spi32766: failed to add SPI device VFSI6101:00 from ACPI
To make the Linux SPI core successfully enumerate the device we provide a
custom version of ->fw_translate_cs() that translates DeviceSelection
correctly.
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Reviewed-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2016-02-08 15:14:29 +00:00
|
|
|
{
|
2019-01-16 15:13:31 +00:00
|
|
|
struct driver_data *drv_data = spi_controller_get_devdata(controller);
|
spi: pxa2xx: Translate ACPI DeviceSelection to Linux chip select on Baytrail
The Windows Baytrail SPI host controller driver uses 1 as the first (and
only) value for ACPI DeviceSelection like can be seen in DSDT taken from
Lenovo Thinkpad 10:
Device (FPNT)
{
...
Method (_CRS, 0, NotSerialized) // _CRS: Current Resource Settings
{
Name (UBUF, ResourceTemplate ()
{
SpiSerialBus (0x0001, // DeviceSelection
PolarityLow, FourWireMode, 0x08,
ControllerInitiated, 0x007A1200, ClockPolarityLow,
ClockPhaseFirst, "\\_SB.SPI1",
0x00, ResourceConsumer,,)
This will fail to enumerate in Linux with following error:
[ 0.241296] pxa2xx-spi 80860F0E:00: cs1 >= max 1
[ 0.241312] spi_master spi32766: failed to add SPI device VFSI6101:00 from ACPI
To make the Linux SPI core successfully enumerate the device we provide a
custom version of ->fw_translate_cs() that translates DeviceSelection
correctly.
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Reviewed-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2016-02-08 15:14:29 +00:00
|
|
|
|
|
|
|
if (has_acpi_companion(&drv_data->pdev->dev)) {
|
|
|
|
switch (drv_data->ssp_type) {
|
|
|
|
/*
|
|
|
|
* For Atoms the ACPI DeviceSelection used by the Windows
|
|
|
|
* driver starts from 1 instead of 0 so translate it here
|
|
|
|
* to match what Linux expects.
|
|
|
|
*/
|
|
|
|
case LPSS_BYT_SSP:
|
2016-02-08 15:14:31 +00:00
|
|
|
case LPSS_BSW_SSP:
|
spi: pxa2xx: Translate ACPI DeviceSelection to Linux chip select on Baytrail
The Windows Baytrail SPI host controller driver uses 1 as the first (and
only) value for ACPI DeviceSelection like can be seen in DSDT taken from
Lenovo Thinkpad 10:
Device (FPNT)
{
...
Method (_CRS, 0, NotSerialized) // _CRS: Current Resource Settings
{
Name (UBUF, ResourceTemplate ()
{
SpiSerialBus (0x0001, // DeviceSelection
PolarityLow, FourWireMode, 0x08,
ControllerInitiated, 0x007A1200, ClockPolarityLow,
ClockPhaseFirst, "\\_SB.SPI1",
0x00, ResourceConsumer,,)
This will fail to enumerate in Linux with following error:
[ 0.241296] pxa2xx-spi 80860F0E:00: cs1 >= max 1
[ 0.241312] spi_master spi32766: failed to add SPI device VFSI6101:00 from ACPI
To make the Linux SPI core successfully enumerate the device we provide a
custom version of ->fw_translate_cs() that translates DeviceSelection
correctly.
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Reviewed-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2016-02-08 15:14:29 +00:00
|
|
|
return cs - 1;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return cs;
|
|
|
|
}
|
|
|
|
|
2019-10-17 06:44:26 +00:00
|
|
|
static size_t pxa2xx_spi_max_dma_transfer_size(struct spi_device *spi)
|
|
|
|
{
|
|
|
|
return MAX_DMA_LEN;
|
|
|
|
}
|
|
|
|
|
2012-12-07 16:57:14 +00:00
|
|
|
static int pxa2xx_spi_probe(struct platform_device *pdev)
|
2006-03-08 07:53:24 +00:00
|
|
|
{
|
|
|
|
struct device *dev = &pdev->dev;
|
2019-01-16 15:13:31 +00:00
|
|
|
struct pxa2xx_spi_controller *platform_info;
|
|
|
|
struct spi_controller *controller;
|
2008-10-16 05:02:42 +00:00
|
|
|
struct driver_data *drv_data;
|
2007-11-21 10:50:53 +00:00
|
|
|
struct ssp_device *ssp;
|
2015-10-28 13:13:41 +00:00
|
|
|
const struct lpss_config *config;
|
2016-09-26 12:19:50 +00:00
|
|
|
int status, count;
|
2014-12-18 13:04:23 +00:00
|
|
|
u32 tmp;
|
2006-03-08 07:53:24 +00:00
|
|
|
|
2013-01-07 10:44:33 +00:00
|
|
|
platform_info = dev_get_platdata(dev);
|
|
|
|
if (!platform_info) {
|
2015-10-28 13:13:43 +00:00
|
|
|
platform_info = pxa2xx_spi_init_pdata(pdev);
|
2020-02-24 15:45:55 +00:00
|
|
|
if (IS_ERR(platform_info)) {
|
2013-01-22 10:26:33 +00:00
|
|
|
dev_err(&pdev->dev, "missing platform data\n");
|
2020-02-24 15:45:55 +00:00
|
|
|
return PTR_ERR(platform_info);
|
2013-01-22 10:26:33 +00:00
|
|
|
}
|
2013-01-07 10:44:33 +00:00
|
|
|
}
|
2006-03-08 07:53:24 +00:00
|
|
|
|
2010-05-05 14:11:15 +00:00
|
|
|
ssp = pxa_ssp_request(pdev->id, pdev->name);
|
2013-01-07 10:44:33 +00:00
|
|
|
if (!ssp)
|
|
|
|
ssp = &platform_info->ssp;
|
|
|
|
|
|
|
|
if (!ssp->mmio_base) {
|
|
|
|
dev_err(&pdev->dev, "failed to get ssp\n");
|
2006-03-08 07:53:24 +00:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2018-11-13 10:22:25 +00:00
|
|
|
if (platform_info->is_slave)
|
2019-01-16 15:13:31 +00:00
|
|
|
controller = spi_alloc_slave(dev, sizeof(struct driver_data));
|
2018-11-13 10:22:25 +00:00
|
|
|
else
|
2019-01-16 15:13:31 +00:00
|
|
|
controller = spi_alloc_master(dev, sizeof(struct driver_data));
|
2018-11-13 10:22:25 +00:00
|
|
|
|
2019-01-16 15:13:31 +00:00
|
|
|
if (!controller) {
|
|
|
|
dev_err(&pdev->dev, "cannot alloc spi_controller\n");
|
2010-05-05 14:11:15 +00:00
|
|
|
pxa_ssp_free(ssp);
|
2006-03-08 07:53:24 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2019-01-16 15:13:31 +00:00
|
|
|
drv_data = spi_controller_get_devdata(controller);
|
|
|
|
drv_data->controller = controller;
|
|
|
|
drv_data->controller_info = platform_info;
|
2006-03-08 07:53:24 +00:00
|
|
|
drv_data->pdev = pdev;
|
2007-11-21 10:50:53 +00:00
|
|
|
drv_data->ssp = ssp;
|
2006-03-08 07:53:24 +00:00
|
|
|
|
2019-01-16 15:13:31 +00:00
|
|
|
controller->dev.of_node = pdev->dev.of_node;
|
2009-06-17 23:26:04 +00:00
|
|
|
/* the spi->mode bits understood by this driver: */
|
2019-01-16 15:13:31 +00:00
|
|
|
controller->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LOOP;
|
|
|
|
|
|
|
|
controller->bus_num = ssp->port_id;
|
|
|
|
controller->dma_alignment = DMA_ALIGNMENT;
|
|
|
|
controller->cleanup = cleanup;
|
|
|
|
controller->setup = setup;
|
|
|
|
controller->set_cs = pxa2xx_spi_set_cs;
|
|
|
|
controller->transfer_one = pxa2xx_spi_transfer_one;
|
|
|
|
controller->slave_abort = pxa2xx_spi_slave_abort;
|
|
|
|
controller->handle_err = pxa2xx_spi_handle_err;
|
|
|
|
controller->unprepare_transfer_hardware = pxa2xx_spi_unprepare_transfer;
|
|
|
|
controller->fw_translate_cs = pxa2xx_spi_fw_translate_cs;
|
|
|
|
controller->auto_runtime_pm = true;
|
|
|
|
controller->flags = SPI_CONTROLLER_MUST_RX | SPI_CONTROLLER_MUST_TX;
|
2006-03-08 07:53:24 +00:00
|
|
|
|
2007-11-21 10:50:53 +00:00
|
|
|
drv_data->ssp_type = ssp->type;
|
2006-03-08 07:53:24 +00:00
|
|
|
|
2007-11-21 10:50:53 +00:00
|
|
|
drv_data->ioaddr = ssp->mmio_base;
|
|
|
|
drv_data->ssdr_physical = ssp->phys_base + SSDR;
|
2010-11-23 01:12:17 +00:00
|
|
|
if (pxa25x_ssp_comp(drv_data)) {
|
2014-11-26 10:35:10 +00:00
|
|
|
switch (drv_data->ssp_type) {
|
|
|
|
case QUARK_X1000_SSP:
|
2019-01-16 15:13:31 +00:00
|
|
|
controller->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32);
|
2014-11-26 10:35:10 +00:00
|
|
|
break;
|
|
|
|
default:
|
2019-01-16 15:13:31 +00:00
|
|
|
controller->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 16);
|
2014-11-26 10:35:10 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-03-08 07:53:24 +00:00
|
|
|
drv_data->int_cr1 = SSCR1_TIE | SSCR1_RIE;
|
|
|
|
drv_data->dma_cr1 = 0;
|
|
|
|
drv_data->clear_sr = SSSR_ROR;
|
|
|
|
drv_data->mask_sr = SSSR_RFS | SSSR_TFS | SSSR_ROR;
|
|
|
|
} else {
|
2019-01-16 15:13:31 +00:00
|
|
|
controller->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32);
|
2006-03-08 07:53:24 +00:00
|
|
|
drv_data->int_cr1 = SSCR1_TIE | SSCR1_RIE | SSCR1_TINTE;
|
2013-01-22 10:26:29 +00:00
|
|
|
drv_data->dma_cr1 = DEFAULT_DMA_CR1;
|
2006-03-08 07:53:24 +00:00
|
|
|
drv_data->clear_sr = SSSR_ROR | SSSR_TINT;
|
2018-11-13 10:22:25 +00:00
|
|
|
drv_data->mask_sr = SSSR_TINT | SSSR_RFS | SSSR_TFS
|
|
|
|
| SSSR_ROR | SSSR_TUR;
|
2006-03-08 07:53:24 +00:00
|
|
|
}
|
|
|
|
|
2010-11-23 01:12:14 +00:00
|
|
|
status = request_irq(ssp->irq, ssp_int, IRQF_SHARED, dev_name(dev),
|
|
|
|
drv_data);
|
2006-03-08 07:53:24 +00:00
|
|
|
if (status < 0) {
|
2008-10-16 05:02:42 +00:00
|
|
|
dev_err(&pdev->dev, "cannot get IRQ %d\n", ssp->irq);
|
2019-01-16 15:13:31 +00:00
|
|
|
goto out_error_controller_alloc;
|
2006-03-08 07:53:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Setup DMA if requested */
|
|
|
|
if (platform_info->enable_dma) {
|
2013-01-22 10:26:28 +00:00
|
|
|
status = pxa2xx_spi_dma_setup(drv_data);
|
|
|
|
if (status) {
|
2019-04-05 12:40:22 +00:00
|
|
|
dev_warn(dev, "no DMA channels available, using PIO\n");
|
2013-01-22 10:26:28 +00:00
|
|
|
platform_info->enable_dma = false;
|
2016-06-21 10:21:34 +00:00
|
|
|
} else {
|
2019-01-16 15:13:31 +00:00
|
|
|
controller->can_dma = pxa2xx_spi_can_dma;
|
2019-02-20 17:58:18 +00:00
|
|
|
controller->max_dma_len = MAX_DMA_LEN;
|
2019-10-17 06:44:26 +00:00
|
|
|
controller->max_transfer_size =
|
|
|
|
pxa2xx_spi_max_dma_transfer_size;
|
2006-03-08 07:53:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enable SOC clock */
|
2018-04-30 14:30:06 +00:00
|
|
|
status = clk_prepare_enable(ssp->clk);
|
|
|
|
if (status)
|
|
|
|
goto out_error_dma_irq_alloc;
|
2013-01-22 10:26:27 +00:00
|
|
|
|
2019-01-16 15:13:31 +00:00
|
|
|
controller->max_speed_hz = clk_get_rate(ssp->clk);
|
2019-06-28 14:07:17 +00:00
|
|
|
/*
|
|
|
|
* Set minimum speed for all other platforms than Intel Quark which is
|
|
|
|
* able do under 1 Hz transfers.
|
|
|
|
*/
|
|
|
|
if (!pxa25x_ssp_comp(drv_data))
|
|
|
|
controller->min_speed_hz =
|
|
|
|
DIV_ROUND_UP(controller->max_speed_hz, 4096);
|
|
|
|
else if (!is_quark_x1000_ssp(drv_data))
|
|
|
|
controller->min_speed_hz =
|
|
|
|
DIV_ROUND_UP(controller->max_speed_hz, 512);
|
2006-03-08 07:53:24 +00:00
|
|
|
|
|
|
|
/* Load default SSP configuration */
|
2014-12-18 13:04:23 +00:00
|
|
|
pxa2xx_spi_write(drv_data, SSCR0, 0);
|
2014-11-26 10:35:10 +00:00
|
|
|
switch (drv_data->ssp_type) {
|
|
|
|
case QUARK_X1000_SSP:
|
2016-09-07 12:43:22 +00:00
|
|
|
tmp = QUARK_X1000_SSCR1_RxTresh(RX_THRESH_QUARK_X1000_DFLT) |
|
|
|
|
QUARK_X1000_SSCR1_TxTresh(TX_THRESH_QUARK_X1000_DFLT);
|
2014-12-18 13:04:23 +00:00
|
|
|
pxa2xx_spi_write(drv_data, SSCR1, tmp);
|
2014-11-26 10:35:10 +00:00
|
|
|
|
|
|
|
/* using the Motorola SPI protocol and use 8 bit frame */
|
2016-09-07 12:43:22 +00:00
|
|
|
tmp = QUARK_X1000_SSCR0_Motorola | QUARK_X1000_SSCR0_DataSize(8);
|
|
|
|
pxa2xx_spi_write(drv_data, SSCR0, tmp);
|
2014-11-26 10:35:10 +00:00
|
|
|
break;
|
2016-09-07 12:43:22 +00:00
|
|
|
case CE4100_SSP:
|
|
|
|
tmp = CE4100_SSCR1_RxTresh(RX_THRESH_CE4100_DFLT) |
|
|
|
|
CE4100_SSCR1_TxTresh(TX_THRESH_CE4100_DFLT);
|
|
|
|
pxa2xx_spi_write(drv_data, SSCR1, tmp);
|
|
|
|
tmp = SSCR0_SCR(2) | SSCR0_Motorola | SSCR0_DataSize(8);
|
|
|
|
pxa2xx_spi_write(drv_data, SSCR0, tmp);
|
2017-01-02 11:44:28 +00:00
|
|
|
break;
|
2014-11-26 10:35:10 +00:00
|
|
|
default:
|
2018-11-13 10:22:25 +00:00
|
|
|
|
2019-01-16 15:13:31 +00:00
|
|
|
if (spi_controller_is_slave(controller)) {
|
2018-11-13 10:22:25 +00:00
|
|
|
tmp = SSCR1_SCFR |
|
|
|
|
SSCR1_SCLKDIR |
|
|
|
|
SSCR1_SFRMDIR |
|
|
|
|
SSCR1_RxTresh(2) |
|
|
|
|
SSCR1_TxTresh(1) |
|
|
|
|
SSCR1_SPH;
|
|
|
|
} else {
|
|
|
|
tmp = SSCR1_RxTresh(RX_THRESH_DFLT) |
|
|
|
|
SSCR1_TxTresh(TX_THRESH_DFLT);
|
|
|
|
}
|
2014-12-18 13:04:23 +00:00
|
|
|
pxa2xx_spi_write(drv_data, SSCR1, tmp);
|
2018-11-13 10:22:25 +00:00
|
|
|
tmp = SSCR0_Motorola | SSCR0_DataSize(8);
|
2019-01-16 15:13:31 +00:00
|
|
|
if (!spi_controller_is_slave(controller))
|
2018-11-13 10:22:25 +00:00
|
|
|
tmp |= SSCR0_SCR(2);
|
2014-12-18 13:04:23 +00:00
|
|
|
pxa2xx_spi_write(drv_data, SSCR0, tmp);
|
2014-11-26 10:35:10 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-11-23 01:12:17 +00:00
|
|
|
if (!pxa25x_ssp_comp(drv_data))
|
2014-12-18 13:04:23 +00:00
|
|
|
pxa2xx_spi_write(drv_data, SSTO, 0);
|
2014-11-26 10:35:10 +00:00
|
|
|
|
|
|
|
if (!is_quark_x1000_ssp(drv_data))
|
2014-12-18 13:04:23 +00:00
|
|
|
pxa2xx_spi_write(drv_data, SSPSP, 0);
|
2006-03-08 07:53:24 +00:00
|
|
|
|
2015-10-28 13:13:41 +00:00
|
|
|
if (is_lpss_ssp(drv_data)) {
|
|
|
|
lpss_ssp_setup(drv_data);
|
|
|
|
config = lpss_get_config(drv_data);
|
|
|
|
if (config->reg_capabilities >= 0) {
|
|
|
|
tmp = __lpss_ssp_read_priv(drv_data,
|
|
|
|
config->reg_capabilities);
|
|
|
|
tmp &= LPSS_CAPS_CS_EN_MASK;
|
|
|
|
tmp >>= LPSS_CAPS_CS_EN_SHIFT;
|
|
|
|
platform_info->num_chipselect = ffz(tmp);
|
2016-02-08 15:14:31 +00:00
|
|
|
} else if (config->cs_num) {
|
|
|
|
platform_info->num_chipselect = config->cs_num;
|
2015-10-28 13:13:41 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-16 15:13:31 +00:00
|
|
|
controller->num_chipselect = platform_info->num_chipselect;
|
2015-10-28 13:13:41 +00:00
|
|
|
|
2016-09-26 12:19:50 +00:00
|
|
|
count = gpiod_count(&pdev->dev, "cs");
|
2017-07-27 11:37:08 +00:00
|
|
|
if (count > 0) {
|
|
|
|
int i;
|
|
|
|
|
2019-01-16 15:13:31 +00:00
|
|
|
controller->num_chipselect = max_t(int, count,
|
|
|
|
controller->num_chipselect);
|
2016-09-26 12:19:50 +00:00
|
|
|
|
2017-07-27 11:37:08 +00:00
|
|
|
drv_data->cs_gpiods = devm_kcalloc(&pdev->dev,
|
2019-01-16 15:13:31 +00:00
|
|
|
controller->num_chipselect, sizeof(struct gpio_desc *),
|
2017-07-27 11:37:08 +00:00
|
|
|
GFP_KERNEL);
|
|
|
|
if (!drv_data->cs_gpiods) {
|
|
|
|
status = -ENOMEM;
|
|
|
|
goto out_error_clock_enabled;
|
|
|
|
}
|
|
|
|
|
2019-01-16 15:13:31 +00:00
|
|
|
for (i = 0; i < controller->num_chipselect; i++) {
|
2017-07-27 11:37:08 +00:00
|
|
|
struct gpio_desc *gpiod;
|
|
|
|
|
2017-07-27 15:49:33 +00:00
|
|
|
gpiod = devm_gpiod_get_index(dev, "cs", i, GPIOD_ASIS);
|
2017-07-27 11:37:08 +00:00
|
|
|
if (IS_ERR(gpiod)) {
|
|
|
|
/* Means use native chip select */
|
|
|
|
if (PTR_ERR(gpiod) == -ENOENT)
|
|
|
|
continue;
|
|
|
|
|
2018-11-13 10:22:27 +00:00
|
|
|
status = PTR_ERR(gpiod);
|
2017-07-27 11:37:08 +00:00
|
|
|
goto out_error_clock_enabled;
|
|
|
|
} else {
|
|
|
|
drv_data->cs_gpiods[i] = gpiod;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-13 10:22:27 +00:00
|
|
|
if (platform_info->is_slave) {
|
|
|
|
drv_data->gpiod_ready = devm_gpiod_get_optional(dev,
|
|
|
|
"ready", GPIOD_OUT_LOW);
|
|
|
|
if (IS_ERR(drv_data->gpiod_ready)) {
|
|
|
|
status = PTR_ERR(drv_data->gpiod_ready);
|
|
|
|
goto out_error_clock_enabled;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-30 16:18:09 +00:00
|
|
|
pm_runtime_set_autosuspend_delay(&pdev->dev, 50);
|
|
|
|
pm_runtime_use_autosuspend(&pdev->dev);
|
|
|
|
pm_runtime_set_active(&pdev->dev);
|
|
|
|
pm_runtime_enable(&pdev->dev);
|
|
|
|
|
2006-03-08 07:53:24 +00:00
|
|
|
/* Register with the SPI framework */
|
|
|
|
platform_set_drvdata(pdev, drv_data);
|
spi: pxa2xx: Fix controller unregister order
The PXA2xx SPI driver uses devm_spi_register_controller() on bind.
As a consequence, on unbind, __device_release_driver() first invokes
pxa2xx_spi_remove() before unregistering the SPI controller via
devres_release_all().
This order is incorrect: pxa2xx_spi_remove() disables the chip,
rendering the SPI bus inaccessible even though the SPI controller is
still registered. When the SPI controller is subsequently unregistered,
it unbinds all its slave devices. Because their drivers cannot access
the SPI bus, e.g. to quiesce interrupts, the slave devices may be left
in an improper state.
As a rule, devm_spi_register_controller() must not be used if the
->remove() hook performs teardown steps which shall be performed after
unregistering the controller and specifically after unbinding of slaves.
Fix by reverting to the non-devm variant of spi_register_controller().
An alternative approach would be to use device-managed functions for all
steps in pxa2xx_spi_remove(), e.g. by calling devm_add_action_or_reset()
on probe. However that approach would add more LoC to the driver and
it wouldn't lend itself as well to backporting to stable.
The improper use of devm_spi_register_controller() was introduced in 2013
by commit a807fcd090d6 ("spi: pxa2xx: use devm_spi_register_master()"),
but all earlier versions of the driver going back to 2006 were likewise
broken because they invoked spi_unregister_master() at the end of
pxa2xx_spi_remove(), rather than at the beginning.
Fixes: e0c9905e87ac ("[PATCH] SPI: add PXA2xx SSP SPI Driver")
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: stable@vger.kernel.org # v2.6.17+
Cc: Tsuchiya Yuto <kitakar@gmail.com>
Link: https://bugzilla.kernel.org/show_bug.cgi?id=206403#c1
Link: https://lore.kernel.org/r/834c446b1cf3284d2660f1bee1ebe3e737cd02a9.1590408496.git.lukas@wunner.de
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-05-25 12:25:02 +00:00
|
|
|
status = spi_register_controller(controller);
|
2006-03-08 07:53:24 +00:00
|
|
|
if (status != 0) {
|
2019-01-16 15:13:31 +00:00
|
|
|
dev_err(&pdev->dev, "problem registering spi controller\n");
|
2019-07-19 12:27:13 +00:00
|
|
|
goto out_error_pm_runtime_enabled;
|
2006-03-08 07:53:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
|
2019-07-19 12:27:13 +00:00
|
|
|
out_error_pm_runtime_enabled:
|
2018-03-07 15:05:04 +00:00
|
|
|
pm_runtime_disable(&pdev->dev);
|
2019-07-19 12:27:13 +00:00
|
|
|
|
|
|
|
out_error_clock_enabled:
|
2013-01-22 10:26:27 +00:00
|
|
|
clk_disable_unprepare(ssp->clk);
|
2018-04-30 14:30:06 +00:00
|
|
|
|
|
|
|
out_error_dma_irq_alloc:
|
2013-01-22 10:26:28 +00:00
|
|
|
pxa2xx_spi_dma_release(drv_data);
|
2007-11-21 10:50:53 +00:00
|
|
|
free_irq(ssp->irq, drv_data);
|
2006-03-08 07:53:24 +00:00
|
|
|
|
2019-01-16 15:13:31 +00:00
|
|
|
out_error_controller_alloc:
|
|
|
|
spi_controller_put(controller);
|
2010-05-05 14:11:15 +00:00
|
|
|
pxa_ssp_free(ssp);
|
2006-03-08 07:53:24 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pxa2xx_spi_remove(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct driver_data *drv_data = platform_get_drvdata(pdev);
|
2020-02-24 15:45:56 +00:00
|
|
|
struct ssp_device *ssp = drv_data->ssp;
|
2006-03-08 07:53:24 +00:00
|
|
|
|
2013-01-22 10:26:30 +00:00
|
|
|
pm_runtime_get_sync(&pdev->dev);
|
|
|
|
|
spi: pxa2xx: Fix controller unregister order
The PXA2xx SPI driver uses devm_spi_register_controller() on bind.
As a consequence, on unbind, __device_release_driver() first invokes
pxa2xx_spi_remove() before unregistering the SPI controller via
devres_release_all().
This order is incorrect: pxa2xx_spi_remove() disables the chip,
rendering the SPI bus inaccessible even though the SPI controller is
still registered. When the SPI controller is subsequently unregistered,
it unbinds all its slave devices. Because their drivers cannot access
the SPI bus, e.g. to quiesce interrupts, the slave devices may be left
in an improper state.
As a rule, devm_spi_register_controller() must not be used if the
->remove() hook performs teardown steps which shall be performed after
unregistering the controller and specifically after unbinding of slaves.
Fix by reverting to the non-devm variant of spi_register_controller().
An alternative approach would be to use device-managed functions for all
steps in pxa2xx_spi_remove(), e.g. by calling devm_add_action_or_reset()
on probe. However that approach would add more LoC to the driver and
it wouldn't lend itself as well to backporting to stable.
The improper use of devm_spi_register_controller() was introduced in 2013
by commit a807fcd090d6 ("spi: pxa2xx: use devm_spi_register_master()"),
but all earlier versions of the driver going back to 2006 were likewise
broken because they invoked spi_unregister_master() at the end of
pxa2xx_spi_remove(), rather than at the beginning.
Fixes: e0c9905e87ac ("[PATCH] SPI: add PXA2xx SSP SPI Driver")
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: stable@vger.kernel.org # v2.6.17+
Cc: Tsuchiya Yuto <kitakar@gmail.com>
Link: https://bugzilla.kernel.org/show_bug.cgi?id=206403#c1
Link: https://lore.kernel.org/r/834c446b1cf3284d2660f1bee1ebe3e737cd02a9.1590408496.git.lukas@wunner.de
Signed-off-by: Mark Brown <broonie@kernel.org>
2020-05-25 12:25:02 +00:00
|
|
|
spi_unregister_controller(drv_data->controller);
|
|
|
|
|
2006-03-08 07:53:24 +00:00
|
|
|
/* Disable the SSP at the peripheral and SOC level */
|
2014-12-18 13:04:23 +00:00
|
|
|
pxa2xx_spi_write(drv_data, SSCR0, 0);
|
2013-01-22 10:26:27 +00:00
|
|
|
clk_disable_unprepare(ssp->clk);
|
2006-03-08 07:53:24 +00:00
|
|
|
|
|
|
|
/* Release DMA */
|
2019-01-16 15:13:31 +00:00
|
|
|
if (drv_data->controller_info->enable_dma)
|
2013-01-22 10:26:28 +00:00
|
|
|
pxa2xx_spi_dma_release(drv_data);
|
2006-03-08 07:53:24 +00:00
|
|
|
|
2013-01-22 10:26:30 +00:00
|
|
|
pm_runtime_put_noidle(&pdev->dev);
|
|
|
|
pm_runtime_disable(&pdev->dev);
|
|
|
|
|
2006-03-08 07:53:24 +00:00
|
|
|
/* Release IRQ */
|
2007-11-21 10:50:53 +00:00
|
|
|
free_irq(ssp->irq, drv_data);
|
|
|
|
|
|
|
|
/* Release SSP */
|
2010-05-05 14:11:15 +00:00
|
|
|
pxa_ssp_free(ssp);
|
2006-03-08 07:53:24 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-01-16 12:50:55 +00:00
|
|
|
#ifdef CONFIG_PM_SLEEP
|
2009-07-21 14:50:16 +00:00
|
|
|
static int pxa2xx_spi_suspend(struct device *dev)
|
2006-03-08 07:53:24 +00:00
|
|
|
{
|
2009-07-21 14:50:16 +00:00
|
|
|
struct driver_data *drv_data = dev_get_drvdata(dev);
|
2007-11-21 10:50:53 +00:00
|
|
|
struct ssp_device *ssp = drv_data->ssp;
|
2016-09-07 14:04:05 +00:00
|
|
|
int status;
|
2006-03-08 07:53:24 +00:00
|
|
|
|
2019-01-16 15:13:31 +00:00
|
|
|
status = spi_controller_suspend(drv_data->controller);
|
2006-03-08 07:53:24 +00:00
|
|
|
if (status != 0)
|
|
|
|
return status;
|
2014-12-18 13:04:23 +00:00
|
|
|
pxa2xx_spi_write(drv_data, SSCR0, 0);
|
2014-11-06 11:08:29 +00:00
|
|
|
|
|
|
|
if (!pm_runtime_suspended(dev))
|
|
|
|
clk_disable_unprepare(ssp->clk);
|
2006-03-08 07:53:24 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-07-21 14:50:16 +00:00
|
|
|
static int pxa2xx_spi_resume(struct device *dev)
|
2006-03-08 07:53:24 +00:00
|
|
|
{
|
2009-07-21 14:50:16 +00:00
|
|
|
struct driver_data *drv_data = dev_get_drvdata(dev);
|
2007-11-21 10:50:53 +00:00
|
|
|
struct ssp_device *ssp = drv_data->ssp;
|
2016-09-07 14:04:05 +00:00
|
|
|
int status;
|
2006-03-08 07:53:24 +00:00
|
|
|
|
|
|
|
/* Enable the SSP clock */
|
2018-04-30 14:30:06 +00:00
|
|
|
if (!pm_runtime_suspended(dev)) {
|
|
|
|
status = clk_prepare_enable(ssp->clk);
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
}
|
2006-03-08 07:53:24 +00:00
|
|
|
|
|
|
|
/* Start the queue running */
|
2019-01-16 15:13:31 +00:00
|
|
|
return spi_controller_resume(drv_data->controller);
|
2006-03-08 07:53:24 +00:00
|
|
|
}
|
2013-01-22 10:26:30 +00:00
|
|
|
#endif
|
|
|
|
|
2014-12-12 23:41:15 +00:00
|
|
|
#ifdef CONFIG_PM
|
2013-01-22 10:26:30 +00:00
|
|
|
static int pxa2xx_spi_runtime_suspend(struct device *dev)
|
|
|
|
{
|
|
|
|
struct driver_data *drv_data = dev_get_drvdata(dev);
|
|
|
|
|
|
|
|
clk_disable_unprepare(drv_data->ssp->clk);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pxa2xx_spi_runtime_resume(struct device *dev)
|
|
|
|
{
|
|
|
|
struct driver_data *drv_data = dev_get_drvdata(dev);
|
2018-04-30 14:30:06 +00:00
|
|
|
int status;
|
2013-01-22 10:26:30 +00:00
|
|
|
|
2018-04-30 14:30:06 +00:00
|
|
|
status = clk_prepare_enable(drv_data->ssp->clk);
|
|
|
|
return status;
|
2013-01-22 10:26:30 +00:00
|
|
|
}
|
|
|
|
#endif
|
2009-07-21 14:50:16 +00:00
|
|
|
|
2009-12-15 02:00:08 +00:00
|
|
|
static const struct dev_pm_ops pxa2xx_spi_pm_ops = {
|
2013-01-22 10:26:30 +00:00
|
|
|
SET_SYSTEM_SLEEP_PM_OPS(pxa2xx_spi_suspend, pxa2xx_spi_resume)
|
|
|
|
SET_RUNTIME_PM_OPS(pxa2xx_spi_runtime_suspend,
|
|
|
|
pxa2xx_spi_runtime_resume, NULL)
|
2009-07-21 14:50:16 +00:00
|
|
|
};
|
2006-03-08 07:53:24 +00:00
|
|
|
|
|
|
|
static struct platform_driver driver = {
|
|
|
|
.driver = {
|
2009-07-21 14:50:16 +00:00
|
|
|
.name = "pxa2xx-spi",
|
|
|
|
.pm = &pxa2xx_spi_pm_ops,
|
2013-01-22 10:26:33 +00:00
|
|
|
.acpi_match_table = ACPI_PTR(pxa2xx_spi_acpi_match),
|
2018-10-10 17:09:29 +00:00
|
|
|
.of_match_table = of_match_ptr(pxa2xx_spi_of_match),
|
2006-03-08 07:53:24 +00:00
|
|
|
},
|
2010-11-19 17:00:11 +00:00
|
|
|
.probe = pxa2xx_spi_probe,
|
2007-10-16 08:27:46 +00:00
|
|
|
.remove = pxa2xx_spi_remove,
|
2006-03-08 07:53:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int __init pxa2xx_spi_init(void)
|
|
|
|
{
|
2010-11-19 17:00:11 +00:00
|
|
|
return platform_driver_register(&driver);
|
2006-03-08 07:53:24 +00:00
|
|
|
}
|
2009-09-22 23:46:10 +00:00
|
|
|
subsys_initcall(pxa2xx_spi_init);
|
2006-03-08 07:53:24 +00:00
|
|
|
|
|
|
|
static void __exit pxa2xx_spi_exit(void)
|
|
|
|
{
|
|
|
|
platform_driver_unregister(&driver);
|
|
|
|
}
|
|
|
|
module_exit(pxa2xx_spi_exit);
|
2019-04-10 12:51:36 +00:00
|
|
|
|
|
|
|
MODULE_SOFTDEP("pre: dw_dmac");
|