* [PATCH 0/4] spi: pxa2xx: Chip select fixes for Intel Baytrail and Braswell @ 2016-01-26 11:18 Mika Westerberg 2016-01-26 11:18 ` [PATCH 2/4] spi: pxa2xx: Translate ACPI DeviceSelection to Linux chip select on Baytrail Mika Westerberg ` (2 more replies) 0 siblings, 3 replies; 9+ messages in thread From: Mika Westerberg @ 2016-01-26 11:18 UTC (permalink / raw) To: Mark Brown Cc: Daniel Mack, Haojian Zhuang, Robert Jarzmik, Jarkko Nikula, Mika Westerberg, Bastien Nocera, linux-spi, linux-acpi, linux-kernel It turns out that in Windows SPI drivers are responsible for handling ACPI DeviceSelection field themselves. Furthermore there has been separate drivers for big core and atom SPI host controllers. For atom (including Baytrail and Braswell) the driver starts DeviceSelection from 1 instead of 0 as expected by the Linux SPI core. As an example Microsoft Surface 3 has touch screen connected to SPI bus described in ACPI DSDT like this: Scope (_SB.PCI0.SPI1) { Device (NTRG) { Name (_HID, "MSHW0037") // _HID: Hardware ID ... Name (CRS1, ResourceTemplate () { SpiSerialBus (0x0001, // SPI DeviceSelection PolarityLow, FourWireMode, 0x10, ControllerInitiated, 0x007A1200, ClockPolarityLow, ClockPhaseFirst, "\\_SB.PCI0.SPI1", 0x00, ResourceConsumer, , ) This fails to enumerate because ACPI DeviceSelection of 1 is greater than number of chip selects the driver supports [1]. This series adds a new hook to struct spi_master ->fw_translate_cs() that allows a driver to translate the chip select number from firmware to the numbering scheme expected by the Linux SPI core and implement that for both Baytrail and Braswell. In addition to that we add support for the second chip select found on Braswell. [1] https://bugzilla.kernel.org/show_bug.cgi?id=104291 Mika Westerberg (4): spi: Let drivers translate ACPI DeviceSelection to suitable Linux chip select spi: pxa2xx: Translate ACPI DeviceSelection to Linux chip select on Baytrail spi: pxa2xx: Move chip select control bits into lpss_config structure spi: pxa2xx: Add support for both chip selects on Intel Braswell drivers/spi/spi-pxa2xx.c | 106 ++++++++++++++++++++++++++++++++++----------- drivers/spi/spi.c | 19 +++++++- include/linux/pxa2xx_ssp.h | 1 + include/linux/spi/spi.h | 5 +++ 4 files changed, 105 insertions(+), 26 deletions(-) -- 2.7.0.rc3 ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 2/4] spi: pxa2xx: Translate ACPI DeviceSelection to Linux chip select on Baytrail 2016-01-26 11:18 [PATCH 0/4] spi: pxa2xx: Chip select fixes for Intel Baytrail and Braswell Mika Westerberg @ 2016-01-26 11:18 ` Mika Westerberg [not found] ` <1453807111-103111-3-git-send-email-mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org> 2016-01-26 13:27 ` Mika Westerberg [not found] ` <1453807111-103111-1-git-send-email-mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org> 2016-01-26 12:52 ` [PATCH 0/4] spi: pxa2xx: Chip select fixes for Intel Baytrail and Braswell Jarkko Nikula 2 siblings, 2 replies; 9+ messages in thread From: Mika Westerberg @ 2016-01-26 11:18 UTC (permalink / raw) To: Mark Brown Cc: Daniel Mack, Haojian Zhuang, Robert Jarzmik, Jarkko Nikula, Mika Westerberg, Bastien Nocera, linux-spi, linux-acpi, linux-kernel 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> --- drivers/spi/spi-pxa2xx.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/spi/spi-pxa2xx.c b/drivers/spi/spi-pxa2xx.c index ab9914ad8365..baa98365a490 100644 --- a/drivers/spi/spi-pxa2xx.c +++ b/drivers/spi/spi-pxa2xx.c @@ -1328,11 +1328,30 @@ static int pxa2xx_spi_get_port_id(struct acpi_device *adev) port_id = devid; return port_id; } + +static int pxa2xx_spi_fw_translate_cs(struct spi_master *master, unsigned cs) +{ + struct driver_data *drv_data = spi_master_get_devdata(master); + + switch (drv_data->ssp_type) { + /* + * For Atoms the Windows driver starts enumerating chip selects + * from 1 instead of 0 so translate it here to match what Linux + * expects. + */ + case LPSS_BYT_SSP: + return cs - 1; + + default: + return cs; + } +} #else /* !CONFIG_ACPI */ static int pxa2xx_spi_get_port_id(struct acpi_device *adev) { return -1; } +#define pxa2xx_spi_fw_translate_cs NULL #endif /* @@ -1490,6 +1509,7 @@ static int pxa2xx_spi_probe(struct platform_device *pdev) master->setup = setup; master->transfer_one_message = pxa2xx_spi_transfer_one_message; master->unprepare_transfer_hardware = pxa2xx_spi_unprepare_transfer; + master->fw_translate_cs = pxa2xx_spi_fw_translate_cs; master->auto_runtime_pm = true; drv_data->ssp_type = ssp->type; -- 2.7.0.rc3 ^ permalink raw reply related [flat|nested] 9+ messages in thread
[parent not found: <1453807111-103111-3-git-send-email-mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>]
* Re: [PATCH 2/4] spi: pxa2xx: Translate ACPI DeviceSelection to Linux chip select on Baytrail [not found] ` <1453807111-103111-3-git-send-email-mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org> @ 2016-01-26 13:14 ` kbuild test robot 0 siblings, 0 replies; 9+ messages in thread From: kbuild test robot @ 2016-01-26 13:14 UTC (permalink / raw) To: Mika Westerberg Cc: kbuild-all-JC7UmRfGjtg, Mark Brown, Daniel Mack, Haojian Zhuang, Robert Jarzmik, Jarkko Nikula, Mika Westerberg, Bastien Nocera, linux-spi-u79uwXL29TY76Z2rM5mHXA, linux-acpi-u79uwXL29TY76Z2rM5mHXA, linux-kernel-u79uwXL29TY76Z2rM5mHXA [-- Attachment #1: Type: text/plain, Size: 1827 bytes --] Hi Mika, [auto build test ERROR on spi/for-next] [also build test ERROR on v4.5-rc1 next-20160125] [if your patch is applied to the wrong git tree, please drop us a note to help improving the system] url: https://github.com/0day-ci/linux/commits/Mika-Westerberg/spi-pxa2xx-Chip-select-fixes-for-Intel-Baytrail-and-Braswell/20160126-192113 base: https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi for-next config: arm-zeus_defconfig (attached as .config) reproduce: wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree make.cross ARCH=arm All errors (new ones prefixed by >>): drivers/spi/spi-pxa2xx.c: In function 'pxa2xx_spi_probe': >> drivers/spi/spi-pxa2xx.c:1512:28: error: 'pxa2xx_spi_fw_translate_cs' undeclared (first use in this function) master->fw_translate_cs = pxa2xx_spi_fw_translate_cs; ^ drivers/spi/spi-pxa2xx.c:1512:28: note: each undeclared identifier is reported only once for each function it appears in vim +/pxa2xx_spi_fw_translate_cs +1512 drivers/spi/spi-pxa2xx.c 1506 master->bus_num = ssp->port_id; 1507 master->dma_alignment = DMA_ALIGNMENT; 1508 master->cleanup = cleanup; 1509 master->setup = setup; 1510 master->transfer_one_message = pxa2xx_spi_transfer_one_message; 1511 master->unprepare_transfer_hardware = pxa2xx_spi_unprepare_transfer; > 1512 master->fw_translate_cs = pxa2xx_spi_fw_translate_cs; 1513 master->auto_runtime_pm = true; 1514 1515 drv_data->ssp_type = ssp->type; --- 0-DAY kernel test infrastructure Open Source Technology Center https://lists.01.org/pipermail/kbuild-all Intel Corporation [-- Attachment #2: .config.gz --] [-- Type: application/octet-stream, Size: 19687 bytes --] ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/4] spi: pxa2xx: Translate ACPI DeviceSelection to Linux chip select on Baytrail 2016-01-26 11:18 ` [PATCH 2/4] spi: pxa2xx: Translate ACPI DeviceSelection to Linux chip select on Baytrail Mika Westerberg [not found] ` <1453807111-103111-3-git-send-email-mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org> @ 2016-01-26 13:27 ` Mika Westerberg 1 sibling, 0 replies; 9+ messages in thread From: Mika Westerberg @ 2016-01-26 13:27 UTC (permalink / raw) To: Mark Brown Cc: Daniel Mack, Haojian Zhuang, Robert Jarzmik, Jarkko Nikula, Bastien Nocera, linux-spi, linux-acpi, linux-kernel On Tue, Jan 26, 2016 at 01:18:29PM +0200, Mika Westerberg wrote: > #else /* !CONFIG_ACPI */ > static int pxa2xx_spi_get_port_id(struct acpi_device *adev) > { > return -1; > } > +#define pxa2xx_spi_fw_translate_cs NULL I need to move this elsewhere because it is still guarded by CONFIG_PCI as pointed out by kbuild robot. Will do that in next revision. ^ permalink raw reply [flat|nested] 9+ messages in thread
[parent not found: <1453807111-103111-1-git-send-email-mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>]
* [PATCH 1/4] spi: Let drivers translate ACPI DeviceSelection to suitable Linux chip select [not found] ` <1453807111-103111-1-git-send-email-mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org> @ 2016-01-26 11:18 ` Mika Westerberg [not found] ` <1453807111-103111-2-git-send-email-mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org> 2016-01-26 11:18 ` [PATCH 3/4] spi: pxa2xx: Move chip select control bits into lpss_config structure Mika Westerberg 2016-01-26 11:18 ` [PATCH 4/4] spi: pxa2xx: Add support for both chip selects on Intel Braswell Mika Westerberg 2 siblings, 1 reply; 9+ messages in thread From: Mika Westerberg @ 2016-01-26 11:18 UTC (permalink / raw) To: Mark Brown Cc: Daniel Mack, Haojian Zhuang, Robert Jarzmik, Jarkko Nikula, Mika Westerberg, Bastien Nocera, linux-spi-u79uwXL29TY76Z2rM5mHXA, linux-acpi-u79uwXL29TY76Z2rM5mHXA, linux-kernel-u79uwXL29TY76Z2rM5mHXA In Windows it is up to the SPI host controller driver to handle the ACPI DeviceSelection as it likes. The SPI core does not take any part in it. This is different in Linux because we always expect to have chip select in range of 0 .. master->num_chipselect - 1. In order to support this in Linux we need a way to allow the driver to translate between ACPI DeviceSelection field and Linux chip select number so provide a new optional hook ->fw_translate_cs() that can be used by a driver to handle translation and call this hook if set during SPI slave ACPI enumeration. Signed-off-by: Mika Westerberg <mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org> --- drivers/spi/spi.c | 19 ++++++++++++++++++- include/linux/spi/spi.h | 5 +++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 47eff8012a77..2c0c26a57f03 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -1581,13 +1581,30 @@ static void of_register_spi_devices(struct spi_master *master) { } static int acpi_spi_add_resource(struct acpi_resource *ares, void *data) { struct spi_device *spi = data; + struct spi_master *master = spi->master; if (ares->type == ACPI_RESOURCE_TYPE_SERIAL_BUS) { struct acpi_resource_spi_serialbus *sb; sb = &ares->data.spi_serial_bus; if (sb->type == ACPI_RESOURCE_SERIAL_TYPE_SPI) { - spi->chip_select = sb->device_selection; + /* + * ACPI DeviceSelection numbering is handled by the + * host controller driver in Windows and can vary + * from driver to driver. In Linux we always expect + * 0 .. max - 1 so we need to ask the driver to + * translate between the two schemes. + */ + if (master->fw_translate_cs) { + int cs = master->fw_translate_cs(master, + sb->device_selection); + if (cs < 0) + return cs; + spi->chip_select = cs; + } else { + spi->chip_select = sb->device_selection; + } + spi->max_speed_hz = sb->connection_speed; if (sb->clock_phase == ACPI_SPI_SECOND_PHASE) diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index 53be3a4c60cb..8a25e6c2fb56 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -369,6 +369,9 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv) * @dma_rx: DMA receive channel * @dummy_rx: dummy receive buffer for full-duplex devices * @dummy_tx: dummy transmit buffer for full-duplex devices + * @fw_translate_cs: If the boot firmware uses different numbering scheme + * what Linux expects, this optional hook can be used to translate + * between the two. * * Each SPI master controller can communicate with one or more @spi_device * children. These make a small bus, sharing MOSI, MISO and SCK signals @@ -537,6 +540,8 @@ struct spi_master { /* dummy data for full duplex devices */ void *dummy_rx; void *dummy_tx; + + int (*fw_translate_cs)(struct spi_master *master, unsigned cs); }; static inline void *spi_master_get_devdata(struct spi_master *master) -- 2.7.0.rc3 -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply related [flat|nested] 9+ messages in thread
[parent not found: <1453807111-103111-2-git-send-email-mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>]
* Applied "spi: Let drivers translate ACPI DeviceSelection to suitable Linux chip select" to the spi tree [not found] ` <1453807111-103111-2-git-send-email-mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org> @ 2016-02-09 18:20 ` Mark Brown 0 siblings, 0 replies; 9+ messages in thread From: Mark Brown @ 2016-02-09 18:20 UTC (permalink / raw) To: Mika Westerberg, Mark Brown; +Cc: linux-spi-u79uwXL29TY76Z2rM5mHXA The patch spi: Let drivers translate ACPI DeviceSelection to suitable Linux chip select has been applied to the spi tree at git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted. You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed. If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced. Please add any relevant lists and maintainers to the CCs when replying to this mail. Thanks, Mark >From a0a90718f18264dc904d34a580f332006f5561e9 Mon Sep 17 00:00:00 2001 From: Mika Westerberg <mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org> Date: Mon, 8 Feb 2016 17:14:28 +0200 Subject: [PATCH] spi: Let drivers translate ACPI DeviceSelection to suitable Linux chip select In Windows it is up to the SPI host controller driver to handle the ACPI DeviceSelection as it likes. The SPI core does not take any part in it. This is different in Linux because we always expect to have chip select in range of 0 .. master->num_chipselect - 1. In order to support this in Linux we need a way to allow the driver to translate between ACPI DeviceSelection field and Linux chip select number so provide a new optional hook ->fw_translate_cs() that can be used by a driver to handle translation and call this hook if set during SPI slave ACPI enumeration. Signed-off-by: Mika Westerberg <mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org> Reviewed-by: Jarkko Nikula <jarkko.nikula-VuQAYsv1563Yd54FQh9/CA@public.gmane.org> Signed-off-by: Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> --- drivers/spi/spi.c | 19 ++++++++++++++++++- include/linux/spi/spi.h | 5 +++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 47eff8012a77..2c0c26a57f03 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -1581,13 +1581,30 @@ static void of_register_spi_devices(struct spi_master *master) { } static int acpi_spi_add_resource(struct acpi_resource *ares, void *data) { struct spi_device *spi = data; + struct spi_master *master = spi->master; if (ares->type == ACPI_RESOURCE_TYPE_SERIAL_BUS) { struct acpi_resource_spi_serialbus *sb; sb = &ares->data.spi_serial_bus; if (sb->type == ACPI_RESOURCE_SERIAL_TYPE_SPI) { - spi->chip_select = sb->device_selection; + /* + * ACPI DeviceSelection numbering is handled by the + * host controller driver in Windows and can vary + * from driver to driver. In Linux we always expect + * 0 .. max - 1 so we need to ask the driver to + * translate between the two schemes. + */ + if (master->fw_translate_cs) { + int cs = master->fw_translate_cs(master, + sb->device_selection); + if (cs < 0) + return cs; + spi->chip_select = cs; + } else { + spi->chip_select = sb->device_selection; + } + spi->max_speed_hz = sb->connection_speed; if (sb->clock_phase == ACPI_SPI_SECOND_PHASE) diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index 53be3a4c60cb..8a25e6c2fb56 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -369,6 +369,9 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv) * @dma_rx: DMA receive channel * @dummy_rx: dummy receive buffer for full-duplex devices * @dummy_tx: dummy transmit buffer for full-duplex devices + * @fw_translate_cs: If the boot firmware uses different numbering scheme + * what Linux expects, this optional hook can be used to translate + * between the two. * * Each SPI master controller can communicate with one or more @spi_device * children. These make a small bus, sharing MOSI, MISO and SCK signals @@ -537,6 +540,8 @@ struct spi_master { /* dummy data for full duplex devices */ void *dummy_rx; void *dummy_tx; + + int (*fw_translate_cs)(struct spi_master *master, unsigned cs); }; static inline void *spi_master_get_devdata(struct spi_master *master) -- 2.7.0.rc3 -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 3/4] spi: pxa2xx: Move chip select control bits into lpss_config structure [not found] ` <1453807111-103111-1-git-send-email-mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org> 2016-01-26 11:18 ` [PATCH 1/4] spi: Let drivers translate ACPI DeviceSelection to suitable Linux chip select Mika Westerberg @ 2016-01-26 11:18 ` Mika Westerberg 2016-01-26 11:18 ` [PATCH 4/4] spi: pxa2xx: Add support for both chip selects on Intel Braswell Mika Westerberg 2 siblings, 0 replies; 9+ messages in thread From: Mika Westerberg @ 2016-01-26 11:18 UTC (permalink / raw) To: Mark Brown Cc: Daniel Mack, Haojian Zhuang, Robert Jarzmik, Jarkko Nikula, Mika Westerberg, Bastien Nocera, linux-spi-u79uwXL29TY76Z2rM5mHXA, linux-acpi-u79uwXL29TY76Z2rM5mHXA, linux-kernel-u79uwXL29TY76Z2rM5mHXA Some Intel LPSS SPI controllers, like the one in Braswell has these bits in a different location so move these bits to be part of the LPSS configuration. Since not all LPSS SPI controllers support multiple native chip selects we refactor selecting chip select to its own function and check control->cs_sel_mask before switching to another chip select. Signed-off-by: Mika Westerberg <mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org> --- drivers/spi/spi-pxa2xx.c | 65 ++++++++++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 24 deletions(-) diff --git a/drivers/spi/spi-pxa2xx.c b/drivers/spi/spi-pxa2xx.c index baa98365a490..d6a7855cf148 100644 --- a/drivers/spi/spi-pxa2xx.c +++ b/drivers/spi/spi-pxa2xx.c @@ -65,8 +65,6 @@ MODULE_ALIAS("platform:pxa2xx-spi"); #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) -#define LPSS_CS_CONTROL_CS_SEL_SHIFT 8 -#define LPSS_CS_CONTROL_CS_SEL_MASK (3 << LPSS_CS_CONTROL_CS_SEL_SHIFT) #define LPSS_CAPS_CS_EN_SHIFT 9 #define LPSS_CAPS_CS_EN_MASK (0xf << LPSS_CAPS_CS_EN_SHIFT) @@ -82,6 +80,9 @@ struct lpss_config { u32 rx_threshold; u32 tx_threshold_lo; u32 tx_threshold_hi; + /* Chip select control */ + unsigned cs_sel_shift; + unsigned cs_sel_mask; }; /* Keep these sorted with enum pxa_ssp_type */ @@ -125,6 +126,8 @@ static const struct lpss_config lpss_platforms[] = { .rx_threshold = 1, .tx_threshold_lo = 16, .tx_threshold_hi = 48, + .cs_sel_shift = 8, + .cs_sel_mask = 3 << 8, }, }; @@ -288,37 +291,51 @@ static void lpss_ssp_setup(struct driver_data *drv_data) } } +static void lpss_ssp_select_cs(struct driver_data *drv_data, + const struct lpss_config *config) +{ + u32 value, cs; + + if (!config->cs_sel_mask) + return; + + value = __lpss_ssp_read_priv(drv_data, config->reg_cs_ctrl); + + cs = drv_data->cur_msg->spi->chip_select; + 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 / + (drv_data->master->max_speed_hz / 2)); + } +} + static void lpss_ssp_cs_control(struct driver_data *drv_data, bool enable) { const struct lpss_config *config; - u32 value, cs; + u32 value; config = lpss_get_config(drv_data); + if (enable) + lpss_ssp_select_cs(drv_data, config); + value = __lpss_ssp_read_priv(drv_data, config->reg_cs_ctrl); - if (enable) { - cs = drv_data->cur_msg->spi->chip_select; - cs <<= LPSS_CS_CONTROL_CS_SEL_SHIFT; - if (cs != (value & LPSS_CS_CONTROL_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 &= ~LPSS_CS_CONTROL_CS_SEL_MASK; - value |= cs; - __lpss_ssp_write_priv(drv_data, - config->reg_cs_ctrl, value); - ndelay(1000000000 / - (drv_data->master->max_speed_hz / 2)); - } + if (enable) value &= ~LPSS_CS_CONTROL_CS_HIGH; - } else { + else value |= LPSS_CS_CONTROL_CS_HIGH; - } __lpss_ssp_write_priv(drv_data, config->reg_cs_ctrl, value); } -- 2.7.0.rc3 -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 4/4] spi: pxa2xx: Add support for both chip selects on Intel Braswell [not found] ` <1453807111-103111-1-git-send-email-mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org> 2016-01-26 11:18 ` [PATCH 1/4] spi: Let drivers translate ACPI DeviceSelection to suitable Linux chip select Mika Westerberg 2016-01-26 11:18 ` [PATCH 3/4] spi: pxa2xx: Move chip select control bits into lpss_config structure Mika Westerberg @ 2016-01-26 11:18 ` Mika Westerberg 2 siblings, 0 replies; 9+ messages in thread From: Mika Westerberg @ 2016-01-26 11:18 UTC (permalink / raw) To: Mark Brown Cc: Daniel Mack, Haojian Zhuang, Robert Jarzmik, Jarkko Nikula, Mika Westerberg, Bastien Nocera, linux-spi-u79uwXL29TY76Z2rM5mHXA, linux-acpi-u79uwXL29TY76Z2rM5mHXA, linux-kernel-u79uwXL29TY76Z2rM5mHXA Intel Braswell LPSS SPI controller actually has two chip selects and there is no capabilities register where this could be found out. These two chip selects are controlled by bits which are in slightly differrent location than Broxton has. Braswell Windows driver also starts chip select (ACPI DeviceSelection) numbering from 1 so translate it to be suitable for Linux as well. Signed-off-by: Mika Westerberg <mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org> --- drivers/spi/spi-pxa2xx.c | 21 ++++++++++++++++++++- include/linux/pxa2xx_ssp.h | 1 + 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi-pxa2xx.c b/drivers/spi/spi-pxa2xx.c index d6a7855cf148..e05d0dc2eb11 100644 --- a/drivers/spi/spi-pxa2xx.c +++ b/drivers/spi/spi-pxa2xx.c @@ -83,6 +83,7 @@ struct lpss_config { /* Chip select control */ unsigned cs_sel_shift; unsigned cs_sel_mask; + unsigned cs_num; }; /* Keep these sorted with enum pxa_ssp_type */ @@ -107,6 +108,19 @@ static const struct lpss_config lpss_platforms[] = { .tx_threshold_lo = 160, .tx_threshold_hi = 224, }, + { /* 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, + }, { /* LPSS_SPT_SSP */ .offset = 0x200, .reg_general = -1, @@ -142,6 +156,7 @@ static bool is_lpss_ssp(const struct driver_data *drv_data) switch (drv_data->ssp_type) { case LPSS_LPT_SSP: case LPSS_BYT_SSP: + case LPSS_BSW_SSP: case LPSS_SPT_SSP: case LPSS_BXT_SSP: return true; @@ -1183,6 +1198,7 @@ static int setup(struct spi_device *spi) break; case LPSS_LPT_SSP: case LPSS_BYT_SSP: + case LPSS_BSW_SSP: case LPSS_SPT_SSP: case LPSS_BXT_SSP: config = lpss_get_config(drv_data); @@ -1330,7 +1346,7 @@ static const struct acpi_device_id pxa2xx_spi_acpi_match[] = { { "INT3430", LPSS_LPT_SSP }, { "INT3431", LPSS_LPT_SSP }, { "80860F0E", LPSS_BYT_SSP }, - { "8086228E", LPSS_BYT_SSP }, + { "8086228E", LPSS_BSW_SSP }, { }, }; MODULE_DEVICE_TABLE(acpi, pxa2xx_spi_acpi_match); @@ -1357,6 +1373,7 @@ static int pxa2xx_spi_fw_translate_cs(struct spi_master *master, unsigned cs) * expects. */ case LPSS_BYT_SSP: + case LPSS_BSW_SSP: return cs - 1; default: @@ -1613,6 +1630,8 @@ static int pxa2xx_spi_probe(struct platform_device *pdev) tmp &= LPSS_CAPS_CS_EN_MASK; tmp >>= LPSS_CAPS_CS_EN_SHIFT; platform_info->num_chipselect = ffz(tmp); + } else if (config->cs_num) { + platform_info->num_chipselect = config->cs_num; } } master->num_chipselect = platform_info->num_chipselect; diff --git a/include/linux/pxa2xx_ssp.h b/include/linux/pxa2xx_ssp.h index c2f2574ff61c..2a097d176ba9 100644 --- a/include/linux/pxa2xx_ssp.h +++ b/include/linux/pxa2xx_ssp.h @@ -197,6 +197,7 @@ enum pxa_ssp_type { QUARK_X1000_SSP, LPSS_LPT_SSP, /* Keep LPSS types sorted with lpss_platforms[] */ LPSS_BYT_SSP, + LPSS_BSW_SSP, LPSS_SPT_SSP, LPSS_BXT_SSP, }; -- 2.7.0.rc3 -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 0/4] spi: pxa2xx: Chip select fixes for Intel Baytrail and Braswell 2016-01-26 11:18 [PATCH 0/4] spi: pxa2xx: Chip select fixes for Intel Baytrail and Braswell Mika Westerberg 2016-01-26 11:18 ` [PATCH 2/4] spi: pxa2xx: Translate ACPI DeviceSelection to Linux chip select on Baytrail Mika Westerberg [not found] ` <1453807111-103111-1-git-send-email-mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org> @ 2016-01-26 12:52 ` Jarkko Nikula 2 siblings, 0 replies; 9+ messages in thread From: Jarkko Nikula @ 2016-01-26 12:52 UTC (permalink / raw) To: Mika Westerberg, Mark Brown Cc: Daniel Mack, Haojian Zhuang, Robert Jarzmik, Bastien Nocera, linux-spi, linux-acpi, linux-kernel On 01/26/2016 01:18 PM, Mika Westerberg wrote: > It turns out that in Windows SPI drivers are responsible for handling ACPI > DeviceSelection field themselves. Furthermore there has been separate > drivers for big core and atom SPI host controllers. For atom (including > Baytrail and Braswell) the driver starts DeviceSelection from 1 instead of 0 > as expected by the Linux SPI core. > > As an example Microsoft Surface 3 has touch screen connected to SPI bus > described in ACPI DSDT like this: > > Scope (_SB.PCI0.SPI1) > { > Device (NTRG) > { > Name (_HID, "MSHW0037") // _HID: Hardware ID > ... > Name (CRS1, ResourceTemplate () > { > SpiSerialBus (0x0001, // SPI DeviceSelection > PolarityLow, FourWireMode, 0x10, > ControllerInitiated, 0x007A1200, ClockPolarityLow, > ClockPhaseFirst, "\\_SB.PCI0.SPI1", > 0x00, ResourceConsumer, , > ) > > This fails to enumerate because ACPI DeviceSelection of 1 is greater than > number of chip selects the driver supports [1]. > > This series adds a new hook to struct spi_master ->fw_translate_cs() that > allows a driver to translate the chip select number from firmware to the > numbering scheme expected by the Linux SPI core and implement that for both > Baytrail and Braswell. > > In addition to that we add support for the second chip select found on > Braswell. > > [1] https://bugzilla.kernel.org/show_bug.cgi?id=104291 > > Mika Westerberg (4): > spi: Let drivers translate ACPI DeviceSelection to suitable Linux chip select > spi: pxa2xx: Translate ACPI DeviceSelection to Linux chip select on Baytrail > spi: pxa2xx: Move chip select control bits into lpss_config structure > spi: pxa2xx: Add support for both chip selects on Intel Braswell > > drivers/spi/spi-pxa2xx.c | 106 ++++++++++++++++++++++++++++++++++----------- > drivers/spi/spi.c | 19 +++++++- > include/linux/pxa2xx_ssp.h | 1 + > include/linux/spi/spi.h | 5 +++ > 4 files changed, 105 insertions(+), 26 deletions(-) > Reviewed-by: Jarkko Nikula <jarkko.nikula@linux.intel.com> ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2016-02-09 18:20 UTC | newest] Thread overview: 9+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2016-01-26 11:18 [PATCH 0/4] spi: pxa2xx: Chip select fixes for Intel Baytrail and Braswell Mika Westerberg 2016-01-26 11:18 ` [PATCH 2/4] spi: pxa2xx: Translate ACPI DeviceSelection to Linux chip select on Baytrail Mika Westerberg [not found] ` <1453807111-103111-3-git-send-email-mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org> 2016-01-26 13:14 ` kbuild test robot 2016-01-26 13:27 ` Mika Westerberg [not found] ` <1453807111-103111-1-git-send-email-mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org> 2016-01-26 11:18 ` [PATCH 1/4] spi: Let drivers translate ACPI DeviceSelection to suitable Linux chip select Mika Westerberg [not found] ` <1453807111-103111-2-git-send-email-mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org> 2016-02-09 18:20 ` Applied "spi: Let drivers translate ACPI DeviceSelection to suitable Linux chip select" to the spi tree Mark Brown 2016-01-26 11:18 ` [PATCH 3/4] spi: pxa2xx: Move chip select control bits into lpss_config structure Mika Westerberg 2016-01-26 11:18 ` [PATCH 4/4] spi: pxa2xx: Add support for both chip selects on Intel Braswell Mika Westerberg 2016-01-26 12:52 ` [PATCH 0/4] spi: pxa2xx: Chip select fixes for Intel Baytrail and Braswell Jarkko Nikula
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).