2016-01-14 14:48:12 +01:00
|
|
|
/* spi_dw.h - Designware SPI driver private definitions */
|
2015-11-22 03:28:21 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2015 Intel Corporation.
|
|
|
|
*
|
2017-01-19 02:01:01 +01:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2015-11-22 03:28:21 +01:00
|
|
|
*/
|
|
|
|
|
2016-01-14 14:48:12 +01:00
|
|
|
#ifndef __SPI_DW_H__
|
|
|
|
#define __SPI_DW_H__
|
2015-11-22 03:28:21 +01:00
|
|
|
|
|
|
|
#include <spi.h>
|
|
|
|
|
2016-01-22 18:38:49 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2016-01-08 09:46:14 +01:00
|
|
|
typedef void (*spi_dw_config_t)(void);
|
2015-11-22 03:28:21 +01:00
|
|
|
|
|
|
|
/* Private structures */
|
|
|
|
struct spi_dw_config {
|
2017-04-21 17:03:20 +02:00
|
|
|
u32_t regs;
|
2015-11-22 03:28:21 +01:00
|
|
|
#ifdef CONFIG_SPI_DW_CLOCK_GATE
|
|
|
|
void *clock_data;
|
|
|
|
#endif /* CONFIG_SPI_DW_CLOCK_GATE */
|
2016-01-18 17:16:24 +01:00
|
|
|
#ifdef CONFIG_SPI_DW_CS_GPIO
|
|
|
|
char *cs_gpio_name;
|
2017-04-21 17:03:20 +02:00
|
|
|
u32_t cs_gpio_pin;
|
2016-01-18 17:16:24 +01:00
|
|
|
#endif /* CONFIG_SPI_DW_CS_GPIO */
|
2015-11-22 03:28:21 +01:00
|
|
|
spi_dw_config_t config_func;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct spi_dw_data {
|
2016-12-06 01:20:13 +01:00
|
|
|
struct k_sem device_sync_sem;
|
2017-04-21 17:03:20 +02:00
|
|
|
u32_t error:1;
|
|
|
|
u32_t dfs:3; /* dfs in bytes: 1,2 or 4 */
|
|
|
|
u32_t slave:17; /* up 16 slaves */
|
|
|
|
u32_t fifo_diff:9; /* cannot be bigger than FIFO depth */
|
|
|
|
u32_t last_tx:1;
|
|
|
|
u32_t _unused:1;
|
2015-11-22 03:28:21 +01:00
|
|
|
#ifdef CONFIG_SPI_DW_CLOCK_GATE
|
|
|
|
struct device *clock;
|
|
|
|
#endif /* CONFIG_SPI_DW_CLOCK_GATE */
|
2016-01-18 17:16:24 +01:00
|
|
|
#ifdef CONFIG_SPI_DW_CS_GPIO
|
|
|
|
struct device *cs_gpio_port;
|
|
|
|
#endif /* CONFIG_SPI_DW_CS_GPIO */
|
2017-04-21 17:03:20 +02:00
|
|
|
const u8_t *tx_buf;
|
|
|
|
u32_t tx_buf_len;
|
|
|
|
u8_t *rx_buf;
|
|
|
|
u32_t rx_buf_len;
|
2015-11-22 03:28:21 +01:00
|
|
|
};
|
|
|
|
|
spi: dw: Quark SE Sensor Sub-System support
Though it's an ARC core, Quark SE SS does not follow the same registers
mapping as the official DesignWare document. Some parts are common, some
not.
Instead of bloating spi_dw.c with a lot of #ifdef or rewriting a whole
new driver though the logic is 99% the same, it's then better to:
- centralize common macros and definitions into spi_dw.h
- have a specific spi_dw_quark_se_ss_reg.h for register map, clock
gating and register helpers dedicated to Quark SE SS.
- have a spi_dw_regs.h for the common case, i.e. not Quark SE SS.
GPIO CS emulation and interrupt masking ends up then in spi_dw.h.
Clock gating is specific thus found in respective *_regs.h header.
Adding proper interrupt masks to quark_se_ss soc.h file as well.
One of the main difference is also the interrupt management: through one
line or multiple lines (one for each interrupt: rx, tx and error). On
Quark SE Sensor Sub-System it has been set to use multiple lines, thus
introducing relevant Kconfig options and managing those when configuring
the IRQs.
Quark SE SS SPI controller is also working on a lower level, i.e. it
requires a tiny bit more logic from the driver. Main example is the data
register which needs to be told what is happening from the driver.
Taking the opportunity to fix minor logic issues:
- ICR register should be cleared by reading, only on error in the ISR
handler, but it does not harm doing it anyway and because Quark SE SS
requires to clear up interrupt as soon as they have been handled,
introducing a clear_interrupts() function called at the and of the ISR
handler.
- TXFTLR should be set after each spi_transceive() since last pull_data
might set it to 0.
- Enable the clock (i.e. open the clock gate) at initialization.
- No need to mask interrupts at spi_configure() since these are already
masked at initialization and at the end of a transaction.
- Let's use BIT() macro when relevant.
Change-Id: I24344aaf8bff3390383a84436f516951c1a2d2a4
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-01-19 14:43:52 +01:00
|
|
|
/* Helper macros */
|
|
|
|
|
|
|
|
#ifdef CONFIG_SPI_DW_ARC_AUX_REGS
|
|
|
|
#define _REG_READ(__sz) sys_in##__sz
|
|
|
|
#define _REG_WRITE(__sz) sys_out##__sz
|
|
|
|
#define _REG_SET_BIT sys_io_set_bit
|
|
|
|
#define _REG_CLEAR_BIT sys_io_clear_bit
|
|
|
|
#define _REG_TEST_BIT sys_io_test_bit
|
|
|
|
#else
|
|
|
|
#define _REG_READ(__sz) sys_read##__sz
|
|
|
|
#define _REG_WRITE(__sz) sys_write##__sz
|
|
|
|
#define _REG_SET_BIT sys_set_bit
|
|
|
|
#define _REG_CLEAR_BIT sys_clear_bit
|
|
|
|
#define _REG_TEST_BIT sys_test_bit
|
|
|
|
#endif /* CONFIG_SPI_DW_ARC_AUX_REGS */
|
|
|
|
|
|
|
|
#define DEFINE_MM_REG_READ(__reg, __off, __sz) \
|
2017-04-21 17:03:20 +02:00
|
|
|
static inline u32_t read_##__reg(u32_t addr) \
|
spi: dw: Quark SE Sensor Sub-System support
Though it's an ARC core, Quark SE SS does not follow the same registers
mapping as the official DesignWare document. Some parts are common, some
not.
Instead of bloating spi_dw.c with a lot of #ifdef or rewriting a whole
new driver though the logic is 99% the same, it's then better to:
- centralize common macros and definitions into spi_dw.h
- have a specific spi_dw_quark_se_ss_reg.h for register map, clock
gating and register helpers dedicated to Quark SE SS.
- have a spi_dw_regs.h for the common case, i.e. not Quark SE SS.
GPIO CS emulation and interrupt masking ends up then in spi_dw.h.
Clock gating is specific thus found in respective *_regs.h header.
Adding proper interrupt masks to quark_se_ss soc.h file as well.
One of the main difference is also the interrupt management: through one
line or multiple lines (one for each interrupt: rx, tx and error). On
Quark SE Sensor Sub-System it has been set to use multiple lines, thus
introducing relevant Kconfig options and managing those when configuring
the IRQs.
Quark SE SS SPI controller is also working on a lower level, i.e. it
requires a tiny bit more logic from the driver. Main example is the data
register which needs to be told what is happening from the driver.
Taking the opportunity to fix minor logic issues:
- ICR register should be cleared by reading, only on error in the ISR
handler, but it does not harm doing it anyway and because Quark SE SS
requires to clear up interrupt as soon as they have been handled,
introducing a clear_interrupts() function called at the and of the ISR
handler.
- TXFTLR should be set after each spi_transceive() since last pull_data
might set it to 0.
- Enable the clock (i.e. open the clock gate) at initialization.
- No need to mask interrupts at spi_configure() since these are already
masked at initialization and at the end of a transaction.
- Let's use BIT() macro when relevant.
Change-Id: I24344aaf8bff3390383a84436f516951c1a2d2a4
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-01-19 14:43:52 +01:00
|
|
|
{ \
|
|
|
|
return _REG_READ(__sz)(addr + __off); \
|
|
|
|
}
|
|
|
|
#define DEFINE_MM_REG_WRITE(__reg, __off, __sz) \
|
2017-04-21 17:03:20 +02:00
|
|
|
static inline void write_##__reg(u32_t data, u32_t addr) \
|
spi: dw: Quark SE Sensor Sub-System support
Though it's an ARC core, Quark SE SS does not follow the same registers
mapping as the official DesignWare document. Some parts are common, some
not.
Instead of bloating spi_dw.c with a lot of #ifdef or rewriting a whole
new driver though the logic is 99% the same, it's then better to:
- centralize common macros and definitions into spi_dw.h
- have a specific spi_dw_quark_se_ss_reg.h for register map, clock
gating and register helpers dedicated to Quark SE SS.
- have a spi_dw_regs.h for the common case, i.e. not Quark SE SS.
GPIO CS emulation and interrupt masking ends up then in spi_dw.h.
Clock gating is specific thus found in respective *_regs.h header.
Adding proper interrupt masks to quark_se_ss soc.h file as well.
One of the main difference is also the interrupt management: through one
line or multiple lines (one for each interrupt: rx, tx and error). On
Quark SE Sensor Sub-System it has been set to use multiple lines, thus
introducing relevant Kconfig options and managing those when configuring
the IRQs.
Quark SE SS SPI controller is also working on a lower level, i.e. it
requires a tiny bit more logic from the driver. Main example is the data
register which needs to be told what is happening from the driver.
Taking the opportunity to fix minor logic issues:
- ICR register should be cleared by reading, only on error in the ISR
handler, but it does not harm doing it anyway and because Quark SE SS
requires to clear up interrupt as soon as they have been handled,
introducing a clear_interrupts() function called at the and of the ISR
handler.
- TXFTLR should be set after each spi_transceive() since last pull_data
might set it to 0.
- Enable the clock (i.e. open the clock gate) at initialization.
- No need to mask interrupts at spi_configure() since these are already
masked at initialization and at the end of a transaction.
- Let's use BIT() macro when relevant.
Change-Id: I24344aaf8bff3390383a84436f516951c1a2d2a4
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-01-19 14:43:52 +01:00
|
|
|
{ \
|
|
|
|
_REG_WRITE(__sz)(data, addr + __off); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DEFINE_SET_BIT_OP(__reg_bit, __reg_off, __bit) \
|
2017-04-21 17:03:20 +02:00
|
|
|
static inline void set_bit_##__reg_bit(u32_t addr) \
|
spi: dw: Quark SE Sensor Sub-System support
Though it's an ARC core, Quark SE SS does not follow the same registers
mapping as the official DesignWare document. Some parts are common, some
not.
Instead of bloating spi_dw.c with a lot of #ifdef or rewriting a whole
new driver though the logic is 99% the same, it's then better to:
- centralize common macros and definitions into spi_dw.h
- have a specific spi_dw_quark_se_ss_reg.h for register map, clock
gating and register helpers dedicated to Quark SE SS.
- have a spi_dw_regs.h for the common case, i.e. not Quark SE SS.
GPIO CS emulation and interrupt masking ends up then in spi_dw.h.
Clock gating is specific thus found in respective *_regs.h header.
Adding proper interrupt masks to quark_se_ss soc.h file as well.
One of the main difference is also the interrupt management: through one
line or multiple lines (one for each interrupt: rx, tx and error). On
Quark SE Sensor Sub-System it has been set to use multiple lines, thus
introducing relevant Kconfig options and managing those when configuring
the IRQs.
Quark SE SS SPI controller is also working on a lower level, i.e. it
requires a tiny bit more logic from the driver. Main example is the data
register which needs to be told what is happening from the driver.
Taking the opportunity to fix minor logic issues:
- ICR register should be cleared by reading, only on error in the ISR
handler, but it does not harm doing it anyway and because Quark SE SS
requires to clear up interrupt as soon as they have been handled,
introducing a clear_interrupts() function called at the and of the ISR
handler.
- TXFTLR should be set after each spi_transceive() since last pull_data
might set it to 0.
- Enable the clock (i.e. open the clock gate) at initialization.
- No need to mask interrupts at spi_configure() since these are already
masked at initialization and at the end of a transaction.
- Let's use BIT() macro when relevant.
Change-Id: I24344aaf8bff3390383a84436f516951c1a2d2a4
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-01-19 14:43:52 +01:00
|
|
|
{ \
|
|
|
|
_REG_SET_BIT(addr + __reg_off, __bit); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DEFINE_CLEAR_BIT_OP(__reg_bit, __reg_off, __bit) \
|
2017-04-21 17:03:20 +02:00
|
|
|
static inline void clear_bit_##__reg_bit(u32_t addr) \
|
spi: dw: Quark SE Sensor Sub-System support
Though it's an ARC core, Quark SE SS does not follow the same registers
mapping as the official DesignWare document. Some parts are common, some
not.
Instead of bloating spi_dw.c with a lot of #ifdef or rewriting a whole
new driver though the logic is 99% the same, it's then better to:
- centralize common macros and definitions into spi_dw.h
- have a specific spi_dw_quark_se_ss_reg.h for register map, clock
gating and register helpers dedicated to Quark SE SS.
- have a spi_dw_regs.h for the common case, i.e. not Quark SE SS.
GPIO CS emulation and interrupt masking ends up then in spi_dw.h.
Clock gating is specific thus found in respective *_regs.h header.
Adding proper interrupt masks to quark_se_ss soc.h file as well.
One of the main difference is also the interrupt management: through one
line or multiple lines (one for each interrupt: rx, tx and error). On
Quark SE Sensor Sub-System it has been set to use multiple lines, thus
introducing relevant Kconfig options and managing those when configuring
the IRQs.
Quark SE SS SPI controller is also working on a lower level, i.e. it
requires a tiny bit more logic from the driver. Main example is the data
register which needs to be told what is happening from the driver.
Taking the opportunity to fix minor logic issues:
- ICR register should be cleared by reading, only on error in the ISR
handler, but it does not harm doing it anyway and because Quark SE SS
requires to clear up interrupt as soon as they have been handled,
introducing a clear_interrupts() function called at the and of the ISR
handler.
- TXFTLR should be set after each spi_transceive() since last pull_data
might set it to 0.
- Enable the clock (i.e. open the clock gate) at initialization.
- No need to mask interrupts at spi_configure() since these are already
masked at initialization and at the end of a transaction.
- Let's use BIT() macro when relevant.
Change-Id: I24344aaf8bff3390383a84436f516951c1a2d2a4
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-01-19 14:43:52 +01:00
|
|
|
{ \
|
|
|
|
_REG_CLEAR_BIT(addr + __reg_off, __bit); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DEFINE_TEST_BIT_OP(__reg_bit, __reg_off, __bit) \
|
2017-04-21 17:03:20 +02:00
|
|
|
static inline int test_bit_##__reg_bit(u32_t addr) \
|
spi: dw: Quark SE Sensor Sub-System support
Though it's an ARC core, Quark SE SS does not follow the same registers
mapping as the official DesignWare document. Some parts are common, some
not.
Instead of bloating spi_dw.c with a lot of #ifdef or rewriting a whole
new driver though the logic is 99% the same, it's then better to:
- centralize common macros and definitions into spi_dw.h
- have a specific spi_dw_quark_se_ss_reg.h for register map, clock
gating and register helpers dedicated to Quark SE SS.
- have a spi_dw_regs.h for the common case, i.e. not Quark SE SS.
GPIO CS emulation and interrupt masking ends up then in spi_dw.h.
Clock gating is specific thus found in respective *_regs.h header.
Adding proper interrupt masks to quark_se_ss soc.h file as well.
One of the main difference is also the interrupt management: through one
line or multiple lines (one for each interrupt: rx, tx and error). On
Quark SE Sensor Sub-System it has been set to use multiple lines, thus
introducing relevant Kconfig options and managing those when configuring
the IRQs.
Quark SE SS SPI controller is also working on a lower level, i.e. it
requires a tiny bit more logic from the driver. Main example is the data
register which needs to be told what is happening from the driver.
Taking the opportunity to fix minor logic issues:
- ICR register should be cleared by reading, only on error in the ISR
handler, but it does not harm doing it anyway and because Quark SE SS
requires to clear up interrupt as soon as they have been handled,
introducing a clear_interrupts() function called at the and of the ISR
handler.
- TXFTLR should be set after each spi_transceive() since last pull_data
might set it to 0.
- Enable the clock (i.e. open the clock gate) at initialization.
- No need to mask interrupts at spi_configure() since these are already
masked at initialization and at the end of a transaction.
- Let's use BIT() macro when relevant.
Change-Id: I24344aaf8bff3390383a84436f516951c1a2d2a4
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-01-19 14:43:52 +01:00
|
|
|
{ \
|
|
|
|
return _REG_TEST_BIT(addr + __reg_off, __bit); \
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Common registers settings, bits etc... */
|
2015-11-22 03:28:21 +01:00
|
|
|
|
|
|
|
/* CTRLR0 settings */
|
spi: dw: Quark SE Sensor Sub-System support
Though it's an ARC core, Quark SE SS does not follow the same registers
mapping as the official DesignWare document. Some parts are common, some
not.
Instead of bloating spi_dw.c with a lot of #ifdef or rewriting a whole
new driver though the logic is 99% the same, it's then better to:
- centralize common macros and definitions into spi_dw.h
- have a specific spi_dw_quark_se_ss_reg.h for register map, clock
gating and register helpers dedicated to Quark SE SS.
- have a spi_dw_regs.h for the common case, i.e. not Quark SE SS.
GPIO CS emulation and interrupt masking ends up then in spi_dw.h.
Clock gating is specific thus found in respective *_regs.h header.
Adding proper interrupt masks to quark_se_ss soc.h file as well.
One of the main difference is also the interrupt management: through one
line or multiple lines (one for each interrupt: rx, tx and error). On
Quark SE Sensor Sub-System it has been set to use multiple lines, thus
introducing relevant Kconfig options and managing those when configuring
the IRQs.
Quark SE SS SPI controller is also working on a lower level, i.e. it
requires a tiny bit more logic from the driver. Main example is the data
register which needs to be told what is happening from the driver.
Taking the opportunity to fix minor logic issues:
- ICR register should be cleared by reading, only on error in the ISR
handler, but it does not harm doing it anyway and because Quark SE SS
requires to clear up interrupt as soon as they have been handled,
introducing a clear_interrupts() function called at the and of the ISR
handler.
- TXFTLR should be set after each spi_transceive() since last pull_data
might set it to 0.
- Enable the clock (i.e. open the clock gate) at initialization.
- No need to mask interrupts at spi_configure() since these are already
masked at initialization and at the end of a transaction.
- Let's use BIT() macro when relevant.
Change-Id: I24344aaf8bff3390383a84436f516951c1a2d2a4
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-01-19 14:43:52 +01:00
|
|
|
#define DW_SPI_CTRLR0_SCPH_BIT (6)
|
|
|
|
#define DW_SPI_CTRLR0_SCPOL_BIT (7)
|
|
|
|
#define DW_SPI_CTRLR0_SRL_BIT (11)
|
|
|
|
|
|
|
|
#define DW_SPI_CTRLR0_SCPH BIT(DW_SPI_CTRLR0_SCPH_BIT)
|
|
|
|
#define DW_SPI_CTRLR0_SCPOL BIT(DW_SPI_CTRLR0_SCPOL_BIT)
|
|
|
|
#define DW_SPI_CTRLR0_SRL BIT(DW_SPI_CTRLR0_SRL_BIT)
|
|
|
|
|
2016-01-14 16:04:28 +01:00
|
|
|
#define DW_SPI_CTRLR0_DFS_16(__bpw) ((__bpw) - 1)
|
|
|
|
#define DW_SPI_CTRLR0_DFS_32(__bpw) (((__bpw) - 1) << 16)
|
spi: dw: Quark SE Sensor Sub-System support
Though it's an ARC core, Quark SE SS does not follow the same registers
mapping as the official DesignWare document. Some parts are common, some
not.
Instead of bloating spi_dw.c with a lot of #ifdef or rewriting a whole
new driver though the logic is 99% the same, it's then better to:
- centralize common macros and definitions into spi_dw.h
- have a specific spi_dw_quark_se_ss_reg.h for register map, clock
gating and register helpers dedicated to Quark SE SS.
- have a spi_dw_regs.h for the common case, i.e. not Quark SE SS.
GPIO CS emulation and interrupt masking ends up then in spi_dw.h.
Clock gating is specific thus found in respective *_regs.h header.
Adding proper interrupt masks to quark_se_ss soc.h file as well.
One of the main difference is also the interrupt management: through one
line or multiple lines (one for each interrupt: rx, tx and error). On
Quark SE Sensor Sub-System it has been set to use multiple lines, thus
introducing relevant Kconfig options and managing those when configuring
the IRQs.
Quark SE SS SPI controller is also working on a lower level, i.e. it
requires a tiny bit more logic from the driver. Main example is the data
register which needs to be told what is happening from the driver.
Taking the opportunity to fix minor logic issues:
- ICR register should be cleared by reading, only on error in the ISR
handler, but it does not harm doing it anyway and because Quark SE SS
requires to clear up interrupt as soon as they have been handled,
introducing a clear_interrupts() function called at the and of the ISR
handler.
- TXFTLR should be set after each spi_transceive() since last pull_data
might set it to 0.
- Enable the clock (i.e. open the clock gate) at initialization.
- No need to mask interrupts at spi_configure() since these are already
masked at initialization and at the end of a transaction.
- Let's use BIT() macro when relevant.
Change-Id: I24344aaf8bff3390383a84436f516951c1a2d2a4
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-01-19 14:43:52 +01:00
|
|
|
|
2016-01-14 16:04:28 +01:00
|
|
|
#ifdef CONFIG_ARC
|
|
|
|
#define DW_SPI_CTRLR0_DFS DW_SPI_CTRLR0_DFS_16
|
|
|
|
#else
|
|
|
|
#define DW_SPI_CTRLR0_DFS DW_SPI_CTRLR0_DFS_32
|
|
|
|
#endif
|
2015-11-22 03:28:21 +01:00
|
|
|
|
2016-01-15 10:11:24 +01:00
|
|
|
/* 0x38 represents the bits 8,16 and 32. Knowing that 24 is bits 8 and 16
|
|
|
|
* These are the bits were when you divide by 8, you keep the result as it is.
|
|
|
|
* For all the other ones, 4 to 7, 9 to 15, etc... you need a +1,
|
|
|
|
* since on such division it takes only the result above 0
|
|
|
|
*/
|
|
|
|
#define SPI_DFS_TO_BYTES(__bpw) (((__bpw) & ~0x38) ? \
|
|
|
|
(((__bpw) / 8) + 1) : \
|
|
|
|
((__bpw) / 8))
|
2015-12-19 00:26:42 +01:00
|
|
|
|
2015-11-22 03:28:21 +01:00
|
|
|
/* SSIENR bits */
|
|
|
|
#define DW_SPI_SSIENR_SSIEN_BIT (0)
|
|
|
|
|
|
|
|
/* SR bits and values */
|
|
|
|
#define DW_SPI_SR_BUSY_BIT (0)
|
|
|
|
#define DW_SPI_SR_TFNF_BIT (1)
|
|
|
|
#define DW_SPI_SR_RFNE_BIT (3)
|
|
|
|
|
2016-01-14 17:45:05 +01:00
|
|
|
/* IMR bits (ISR valid as well) */
|
2015-11-22 03:28:21 +01:00
|
|
|
#define DW_SPI_IMR_TXEIM_BIT (0)
|
|
|
|
#define DW_SPI_IMR_TXOIM_BIT (1)
|
|
|
|
#define DW_SPI_IMR_RXUIM_BIT (2)
|
|
|
|
#define DW_SPI_IMR_RXOIM_BIT (3)
|
|
|
|
#define DW_SPI_IMR_RXFIM_BIT (4)
|
|
|
|
#define DW_SPI_IMR_MSTIM_BIT (5)
|
|
|
|
|
2016-01-14 17:45:05 +01:00
|
|
|
/* IMR values */
|
spi: dw: Quark SE Sensor Sub-System support
Though it's an ARC core, Quark SE SS does not follow the same registers
mapping as the official DesignWare document. Some parts are common, some
not.
Instead of bloating spi_dw.c with a lot of #ifdef or rewriting a whole
new driver though the logic is 99% the same, it's then better to:
- centralize common macros and definitions into spi_dw.h
- have a specific spi_dw_quark_se_ss_reg.h for register map, clock
gating and register helpers dedicated to Quark SE SS.
- have a spi_dw_regs.h for the common case, i.e. not Quark SE SS.
GPIO CS emulation and interrupt masking ends up then in spi_dw.h.
Clock gating is specific thus found in respective *_regs.h header.
Adding proper interrupt masks to quark_se_ss soc.h file as well.
One of the main difference is also the interrupt management: through one
line or multiple lines (one for each interrupt: rx, tx and error). On
Quark SE Sensor Sub-System it has been set to use multiple lines, thus
introducing relevant Kconfig options and managing those when configuring
the IRQs.
Quark SE SS SPI controller is also working on a lower level, i.e. it
requires a tiny bit more logic from the driver. Main example is the data
register which needs to be told what is happening from the driver.
Taking the opportunity to fix minor logic issues:
- ICR register should be cleared by reading, only on error in the ISR
handler, but it does not harm doing it anyway and because Quark SE SS
requires to clear up interrupt as soon as they have been handled,
introducing a clear_interrupts() function called at the and of the ISR
handler.
- TXFTLR should be set after each spi_transceive() since last pull_data
might set it to 0.
- Enable the clock (i.e. open the clock gate) at initialization.
- No need to mask interrupts at spi_configure() since these are already
masked at initialization and at the end of a transaction.
- Let's use BIT() macro when relevant.
Change-Id: I24344aaf8bff3390383a84436f516951c1a2d2a4
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-01-19 14:43:52 +01:00
|
|
|
#define DW_SPI_IMR_TXEIM BIT(DW_SPI_IMR_TXEIM_BIT)
|
|
|
|
#define DW_SPI_IMR_TXOIM BIT(DW_SPI_IMR_TXOIM_BIT)
|
|
|
|
#define DW_SPI_IMR_RXUIM BIT(DW_SPI_IMR_RXUIM_BIT)
|
|
|
|
#define DW_SPI_IMR_RXOIM BIT(DW_SPI_IMR_RXOIM_BIT)
|
|
|
|
#define DW_SPI_IMR_RXFIM BIT(DW_SPI_IMR_RXFIM_BIT)
|
|
|
|
#define DW_SPI_IMR_MSTIM BIT(DW_SPI_IMR_MSTIM_BIT)
|
2016-01-14 17:45:05 +01:00
|
|
|
|
|
|
|
/* ISR values (same as IMR) */
|
|
|
|
#define DW_SPI_ISR_TXEIS DW_SPI_IMR_TXEIM
|
|
|
|
#define DW_SPI_ISR_TXOIS DW_SPI_IMR_TXOIM
|
|
|
|
#define DW_SPI_ISR_RXUIS DW_SPI_IMR_RXUIM
|
|
|
|
#define DW_SPI_ISR_RXOIS DW_SPI_IMR_RXOIM
|
|
|
|
#define DW_SPI_ISR_RXFIS DW_SPI_IMR_RXFIM
|
|
|
|
#define DW_SPI_ISR_MSTIS DW_SPI_IMR_MSTIM
|
2015-11-22 03:28:21 +01:00
|
|
|
|
|
|
|
/* Error interrupt */
|
2016-01-14 17:45:05 +01:00
|
|
|
#define DW_SPI_ISR_ERRORS_MASK (DW_SPI_ISR_TXOIS | \
|
2015-11-22 03:28:21 +01:00
|
|
|
DW_SPI_ISR_RXUIS | \
|
|
|
|
DW_SPI_ISR_RXOIS | \
|
|
|
|
DW_SPI_ISR_MSTIS)
|
|
|
|
/* ICR Bit */
|
|
|
|
#define DW_SPI_SR_ICR_BIT (0)
|
|
|
|
|
|
|
|
/* Threshold defaults */
|
2016-05-18 22:11:35 +02:00
|
|
|
#define DW_SPI_FIFO_DEPTH CONFIG_SPI_DW_FIFO_DEPTH
|
2016-05-26 01:43:31 +02:00
|
|
|
#define DW_SPI_TXFTLR_DFLT ((DW_SPI_FIFO_DEPTH*1)/2) /* 50% */
|
2016-05-18 22:11:35 +02:00
|
|
|
#define DW_SPI_RXFTLR_DFLT ((DW_SPI_FIFO_DEPTH*5)/8)
|
2015-11-22 03:28:21 +01:00
|
|
|
|
|
|
|
/* Interrupt mask (IMR) */
|
|
|
|
#define DW_SPI_IMR_MASK (0x0)
|
2016-01-14 17:45:05 +01:00
|
|
|
#define DW_SPI_IMR_UNMASK (DW_SPI_IMR_TXEIM | \
|
|
|
|
DW_SPI_IMR_TXOIM | \
|
|
|
|
DW_SPI_IMR_RXUIM | \
|
|
|
|
DW_SPI_IMR_RXOIM | \
|
|
|
|
DW_SPI_IMR_RXFIM)
|
|
|
|
#define DW_SPI_IMR_MASK_TX (~(DW_SPI_IMR_TXEIM | \
|
|
|
|
DW_SPI_IMR_TXOIM))
|
|
|
|
#define DW_SPI_IMR_MASK_RX (~(DW_SPI_IMR_RXUIM | \
|
|
|
|
DW_SPI_IMR_RXOIM | \
|
|
|
|
DW_SPI_IMR_RXFIM))
|
2015-11-22 03:28:21 +01:00
|
|
|
|
spi: dw: Quark SE Sensor Sub-System support
Though it's an ARC core, Quark SE SS does not follow the same registers
mapping as the official DesignWare document. Some parts are common, some
not.
Instead of bloating spi_dw.c with a lot of #ifdef or rewriting a whole
new driver though the logic is 99% the same, it's then better to:
- centralize common macros and definitions into spi_dw.h
- have a specific spi_dw_quark_se_ss_reg.h for register map, clock
gating and register helpers dedicated to Quark SE SS.
- have a spi_dw_regs.h for the common case, i.e. not Quark SE SS.
GPIO CS emulation and interrupt masking ends up then in spi_dw.h.
Clock gating is specific thus found in respective *_regs.h header.
Adding proper interrupt masks to quark_se_ss soc.h file as well.
One of the main difference is also the interrupt management: through one
line or multiple lines (one for each interrupt: rx, tx and error). On
Quark SE Sensor Sub-System it has been set to use multiple lines, thus
introducing relevant Kconfig options and managing those when configuring
the IRQs.
Quark SE SS SPI controller is also working on a lower level, i.e. it
requires a tiny bit more logic from the driver. Main example is the data
register which needs to be told what is happening from the driver.
Taking the opportunity to fix minor logic issues:
- ICR register should be cleared by reading, only on error in the ISR
handler, but it does not harm doing it anyway and because Quark SE SS
requires to clear up interrupt as soon as they have been handled,
introducing a clear_interrupts() function called at the and of the ISR
handler.
- TXFTLR should be set after each spi_transceive() since last pull_data
might set it to 0.
- Enable the clock (i.e. open the clock gate) at initialization.
- No need to mask interrupts at spi_configure() since these are already
masked at initialization and at the end of a transaction.
- Let's use BIT() macro when relevant.
Change-Id: I24344aaf8bff3390383a84436f516951c1a2d2a4
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-01-19 14:43:52 +01:00
|
|
|
/*
|
|
|
|
* Including the right register definition file
|
|
|
|
* SoC SPECIFIC!
|
|
|
|
*/
|
2016-08-30 14:27:26 +02:00
|
|
|
#ifdef CONFIG_SOC_QUARK_SE_C1000_SS
|
spi: dw: Quark SE Sensor Sub-System support
Though it's an ARC core, Quark SE SS does not follow the same registers
mapping as the official DesignWare document. Some parts are common, some
not.
Instead of bloating spi_dw.c with a lot of #ifdef or rewriting a whole
new driver though the logic is 99% the same, it's then better to:
- centralize common macros and definitions into spi_dw.h
- have a specific spi_dw_quark_se_ss_reg.h for register map, clock
gating and register helpers dedicated to Quark SE SS.
- have a spi_dw_regs.h for the common case, i.e. not Quark SE SS.
GPIO CS emulation and interrupt masking ends up then in spi_dw.h.
Clock gating is specific thus found in respective *_regs.h header.
Adding proper interrupt masks to quark_se_ss soc.h file as well.
One of the main difference is also the interrupt management: through one
line or multiple lines (one for each interrupt: rx, tx and error). On
Quark SE Sensor Sub-System it has been set to use multiple lines, thus
introducing relevant Kconfig options and managing those when configuring
the IRQs.
Quark SE SS SPI controller is also working on a lower level, i.e. it
requires a tiny bit more logic from the driver. Main example is the data
register which needs to be told what is happening from the driver.
Taking the opportunity to fix minor logic issues:
- ICR register should be cleared by reading, only on error in the ISR
handler, but it does not harm doing it anyway and because Quark SE SS
requires to clear up interrupt as soon as they have been handled,
introducing a clear_interrupts() function called at the and of the ISR
handler.
- TXFTLR should be set after each spi_transceive() since last pull_data
might set it to 0.
- Enable the clock (i.e. open the clock gate) at initialization.
- No need to mask interrupts at spi_configure() since these are already
masked at initialization and at the end of a transaction.
- Let's use BIT() macro when relevant.
Change-Id: I24344aaf8bff3390383a84436f516951c1a2d2a4
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-01-19 14:43:52 +01:00
|
|
|
#include "spi_dw_quark_se_ss_regs.h"
|
|
|
|
#else
|
|
|
|
#include "spi_dw_regs.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* GPIO used to emulate CS */
|
|
|
|
#ifdef CONFIG_SPI_DW_CS_GPIO
|
|
|
|
|
|
|
|
#include <gpio.h>
|
|
|
|
|
|
|
|
static inline void _spi_config_cs(struct device *dev)
|
|
|
|
{
|
2016-10-06 20:28:52 +02:00
|
|
|
const struct spi_dw_config *info = dev->config->config_info;
|
spi: dw: Quark SE Sensor Sub-System support
Though it's an ARC core, Quark SE SS does not follow the same registers
mapping as the official DesignWare document. Some parts are common, some
not.
Instead of bloating spi_dw.c with a lot of #ifdef or rewriting a whole
new driver though the logic is 99% the same, it's then better to:
- centralize common macros and definitions into spi_dw.h
- have a specific spi_dw_quark_se_ss_reg.h for register map, clock
gating and register helpers dedicated to Quark SE SS.
- have a spi_dw_regs.h for the common case, i.e. not Quark SE SS.
GPIO CS emulation and interrupt masking ends up then in spi_dw.h.
Clock gating is specific thus found in respective *_regs.h header.
Adding proper interrupt masks to quark_se_ss soc.h file as well.
One of the main difference is also the interrupt management: through one
line or multiple lines (one for each interrupt: rx, tx and error). On
Quark SE Sensor Sub-System it has been set to use multiple lines, thus
introducing relevant Kconfig options and managing those when configuring
the IRQs.
Quark SE SS SPI controller is also working on a lower level, i.e. it
requires a tiny bit more logic from the driver. Main example is the data
register which needs to be told what is happening from the driver.
Taking the opportunity to fix minor logic issues:
- ICR register should be cleared by reading, only on error in the ISR
handler, but it does not harm doing it anyway and because Quark SE SS
requires to clear up interrupt as soon as they have been handled,
introducing a clear_interrupts() function called at the and of the ISR
handler.
- TXFTLR should be set after each spi_transceive() since last pull_data
might set it to 0.
- Enable the clock (i.e. open the clock gate) at initialization.
- No need to mask interrupts at spi_configure() since these are already
masked at initialization and at the end of a transaction.
- Let's use BIT() macro when relevant.
Change-Id: I24344aaf8bff3390383a84436f516951c1a2d2a4
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-01-19 14:43:52 +01:00
|
|
|
struct spi_dw_data *spi = dev->driver_data;
|
|
|
|
struct device *gpio;
|
|
|
|
|
|
|
|
gpio = device_get_binding(info->cs_gpio_name);
|
|
|
|
if (!gpio) {
|
|
|
|
spi->cs_gpio_port = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gpio_pin_configure(gpio, info->cs_gpio_pin, GPIO_DIR_OUT);
|
|
|
|
/* Default CS line to high (idling) */
|
|
|
|
gpio_pin_write(gpio, info->cs_gpio_pin, 1);
|
|
|
|
|
|
|
|
spi->cs_gpio_port = gpio;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void _spi_control_cs(struct device *dev, int on)
|
|
|
|
{
|
2016-10-06 20:28:52 +02:00
|
|
|
const struct spi_dw_config *info = dev->config->config_info;
|
spi: dw: Quark SE Sensor Sub-System support
Though it's an ARC core, Quark SE SS does not follow the same registers
mapping as the official DesignWare document. Some parts are common, some
not.
Instead of bloating spi_dw.c with a lot of #ifdef or rewriting a whole
new driver though the logic is 99% the same, it's then better to:
- centralize common macros and definitions into spi_dw.h
- have a specific spi_dw_quark_se_ss_reg.h for register map, clock
gating and register helpers dedicated to Quark SE SS.
- have a spi_dw_regs.h for the common case, i.e. not Quark SE SS.
GPIO CS emulation and interrupt masking ends up then in spi_dw.h.
Clock gating is specific thus found in respective *_regs.h header.
Adding proper interrupt masks to quark_se_ss soc.h file as well.
One of the main difference is also the interrupt management: through one
line or multiple lines (one for each interrupt: rx, tx and error). On
Quark SE Sensor Sub-System it has been set to use multiple lines, thus
introducing relevant Kconfig options and managing those when configuring
the IRQs.
Quark SE SS SPI controller is also working on a lower level, i.e. it
requires a tiny bit more logic from the driver. Main example is the data
register which needs to be told what is happening from the driver.
Taking the opportunity to fix minor logic issues:
- ICR register should be cleared by reading, only on error in the ISR
handler, but it does not harm doing it anyway and because Quark SE SS
requires to clear up interrupt as soon as they have been handled,
introducing a clear_interrupts() function called at the and of the ISR
handler.
- TXFTLR should be set after each spi_transceive() since last pull_data
might set it to 0.
- Enable the clock (i.e. open the clock gate) at initialization.
- No need to mask interrupts at spi_configure() since these are already
masked at initialization and at the end of a transaction.
- Let's use BIT() macro when relevant.
Change-Id: I24344aaf8bff3390383a84436f516951c1a2d2a4
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-01-19 14:43:52 +01:00
|
|
|
struct spi_dw_data *spi = dev->driver_data;
|
|
|
|
|
|
|
|
if (spi->cs_gpio_port) {
|
|
|
|
gpio_pin_write(spi->cs_gpio_port, info->cs_gpio_pin, !on);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define _spi_control_cs(...)
|
|
|
|
#define _spi_config_cs(...)
|
|
|
|
#endif /* CONFIG_SPI_DW_CS_GPIO */
|
|
|
|
|
|
|
|
/* Interrupt mask
|
|
|
|
* SoC SPECIFIC!
|
|
|
|
*/
|
2016-08-30 14:41:04 +02:00
|
|
|
#if defined(CONFIG_SOC_QUARK_SE_C1000) || defined(CONFIG_SOC_QUARK_SE_C1000_SS)
|
spi: dw: Quark SE Sensor Sub-System support
Though it's an ARC core, Quark SE SS does not follow the same registers
mapping as the official DesignWare document. Some parts are common, some
not.
Instead of bloating spi_dw.c with a lot of #ifdef or rewriting a whole
new driver though the logic is 99% the same, it's then better to:
- centralize common macros and definitions into spi_dw.h
- have a specific spi_dw_quark_se_ss_reg.h for register map, clock
gating and register helpers dedicated to Quark SE SS.
- have a spi_dw_regs.h for the common case, i.e. not Quark SE SS.
GPIO CS emulation and interrupt masking ends up then in spi_dw.h.
Clock gating is specific thus found in respective *_regs.h header.
Adding proper interrupt masks to quark_se_ss soc.h file as well.
One of the main difference is also the interrupt management: through one
line or multiple lines (one for each interrupt: rx, tx and error). On
Quark SE Sensor Sub-System it has been set to use multiple lines, thus
introducing relevant Kconfig options and managing those when configuring
the IRQs.
Quark SE SS SPI controller is also working on a lower level, i.e. it
requires a tiny bit more logic from the driver. Main example is the data
register which needs to be told what is happening from the driver.
Taking the opportunity to fix minor logic issues:
- ICR register should be cleared by reading, only on error in the ISR
handler, but it does not harm doing it anyway and because Quark SE SS
requires to clear up interrupt as soon as they have been handled,
introducing a clear_interrupts() function called at the and of the ISR
handler.
- TXFTLR should be set after each spi_transceive() since last pull_data
might set it to 0.
- Enable the clock (i.e. open the clock gate) at initialization.
- No need to mask interrupts at spi_configure() since these are already
masked at initialization and at the end of a transaction.
- Let's use BIT() macro when relevant.
Change-Id: I24344aaf8bff3390383a84436f516951c1a2d2a4
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-01-19 14:43:52 +01:00
|
|
|
#ifdef CONFIG_ARC
|
|
|
|
#define _INT_UNMASK INT_ENABLE_ARC
|
|
|
|
#else
|
|
|
|
#define _INT_UNMASK INT_UNMASK_IA
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define _spi_int_unmask(__mask) \
|
|
|
|
sys_write32(sys_read32(__mask) & _INT_UNMASK, __mask)
|
|
|
|
#else
|
|
|
|
#define _spi_int_unmask(...)
|
2016-08-30 14:41:04 +02:00
|
|
|
#endif /* CONFIG_SOC_QUARK_SE_C1000 || CONFIG_SOC_QUARK_SE_C1000_SS */
|
spi: dw: Quark SE Sensor Sub-System support
Though it's an ARC core, Quark SE SS does not follow the same registers
mapping as the official DesignWare document. Some parts are common, some
not.
Instead of bloating spi_dw.c with a lot of #ifdef or rewriting a whole
new driver though the logic is 99% the same, it's then better to:
- centralize common macros and definitions into spi_dw.h
- have a specific spi_dw_quark_se_ss_reg.h for register map, clock
gating and register helpers dedicated to Quark SE SS.
- have a spi_dw_regs.h for the common case, i.e. not Quark SE SS.
GPIO CS emulation and interrupt masking ends up then in spi_dw.h.
Clock gating is specific thus found in respective *_regs.h header.
Adding proper interrupt masks to quark_se_ss soc.h file as well.
One of the main difference is also the interrupt management: through one
line or multiple lines (one for each interrupt: rx, tx and error). On
Quark SE Sensor Sub-System it has been set to use multiple lines, thus
introducing relevant Kconfig options and managing those when configuring
the IRQs.
Quark SE SS SPI controller is also working on a lower level, i.e. it
requires a tiny bit more logic from the driver. Main example is the data
register which needs to be told what is happening from the driver.
Taking the opportunity to fix minor logic issues:
- ICR register should be cleared by reading, only on error in the ISR
handler, but it does not harm doing it anyway and because Quark SE SS
requires to clear up interrupt as soon as they have been handled,
introducing a clear_interrupts() function called at the and of the ISR
handler.
- TXFTLR should be set after each spi_transceive() since last pull_data
might set it to 0.
- Enable the clock (i.e. open the clock gate) at initialization.
- No need to mask interrupts at spi_configure() since these are already
masked at initialization and at the end of a transaction.
- Let's use BIT() macro when relevant.
Change-Id: I24344aaf8bff3390383a84436f516951c1a2d2a4
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2016-01-19 14:43:52 +01:00
|
|
|
|
|
|
|
/* Based on those macros above, here are common helpers for some registers */
|
|
|
|
DEFINE_MM_REG_WRITE(baudr, DW_SPI_REG_BAUDR, 16)
|
|
|
|
DEFINE_MM_REG_READ(txflr, DW_SPI_REG_TXFLR, 32)
|
|
|
|
DEFINE_MM_REG_READ(rxflr, DW_SPI_REG_RXFLR, 32)
|
|
|
|
DEFINE_MM_REG_WRITE(imr, DW_SPI_REG_IMR, 8)
|
|
|
|
DEFINE_MM_REG_READ(isr, DW_SPI_REG_ISR, 8)
|
|
|
|
|
|
|
|
DEFINE_SET_BIT_OP(ssienr, DW_SPI_REG_SSIENR, DW_SPI_SSIENR_SSIEN_BIT)
|
|
|
|
DEFINE_CLEAR_BIT_OP(ssienr, DW_SPI_REG_SSIENR, DW_SPI_SSIENR_SSIEN_BIT)
|
|
|
|
DEFINE_TEST_BIT_OP(ssienr, DW_SPI_REG_SSIENR, DW_SPI_SSIENR_SSIEN_BIT)
|
|
|
|
DEFINE_TEST_BIT_OP(sr_busy, DW_SPI_REG_SR, DW_SPI_SR_BUSY_BIT)
|
|
|
|
|
2016-01-22 18:38:49 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
2016-01-14 14:48:12 +01:00
|
|
|
#endif /* __SPI_DW_H__ */
|
2016-01-22 18:38:49 +01:00
|
|
|
|