drivers/spi/spi-npcm-pspi.c
Source file repositories/reference/linux-study-clean/drivers/spi/spi-npcm-pspi.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/spi/spi-npcm-pspi.c- Extension
.c- Size
- 10482 bytes
- Lines
- 459
- Domain
- Driver Families
- Bucket
- drivers/spi
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/bitfield.hlinux/bitops.hlinux/clk.hlinux/interrupt.hlinux/io.hlinux/module.hlinux/platform_device.hlinux/spi/spi.hlinux/reset.hlinux/unaligned.hlinux/regmap.hlinux/mfd/syscon.h
Detected Declarations
struct npcm_pspifunction bytes_per_wordfunction npcm_pspi_irq_enablefunction npcm_pspi_irq_disablefunction npcm_pspi_enablefunction npcm_pspi_disablefunction npcm_pspi_set_modefunction npcm_pspi_set_transfer_sizefunction npcm_pspi_set_baudratefunction npcm_pspi_setup_transferfunction npcm_pspi_sendfunction npcm_pspi_recvfunction npcm_pspi_transfer_onefunction npcm_pspi_prepare_transfer_hardwarefunction npcm_pspi_unprepare_transfer_hardwarefunction npcm_pspi_reset_hwfunction npcm_pspi_handlerfunction npcm_pspi_probefunction npcm_pspi_remove
Annotated Snippet
struct npcm_pspi {
struct completion xfer_done;
struct reset_control *reset;
struct spi_controller *host;
unsigned int tx_bytes;
unsigned int rx_bytes;
void __iomem *base;
bool is_save_param;
u8 bits_per_word;
const u8 *tx_buf;
struct clk *clk;
u32 speed_hz;
u8 *rx_buf;
u16 mode;
u32 id;
};
#define DRIVER_NAME "npcm-pspi"
#define NPCM_PSPI_DATA 0x00
#define NPCM_PSPI_CTL1 0x02
#define NPCM_PSPI_STAT 0x04
/* definitions for control and status register */
#define NPCM_PSPI_CTL1_SPIEN BIT(0)
#define NPCM_PSPI_CTL1_MOD BIT(2)
#define NPCM_PSPI_CTL1_EIR BIT(5)
#define NPCM_PSPI_CTL1_EIW BIT(6)
#define NPCM_PSPI_CTL1_SCM BIT(7)
#define NPCM_PSPI_CTL1_SCIDL BIT(8)
#define NPCM_PSPI_CTL1_SCDV6_0 GENMASK(15, 9)
#define NPCM_PSPI_STAT_BSY BIT(0)
#define NPCM_PSPI_STAT_RBF BIT(1)
/* general definitions */
#define NPCM_PSPI_TIMEOUT_MS 2000
#define NPCM_PSPI_MAX_CLK_DIVIDER 256
#define NPCM_PSPI_MIN_CLK_DIVIDER 4
#define NPCM_PSPI_DEFAULT_CLK 25000000
static inline unsigned int bytes_per_word(unsigned int bits)
{
return bits <= 8 ? 1 : 2;
}
static inline void npcm_pspi_irq_enable(struct npcm_pspi *priv, u16 mask)
{
u16 val;
val = ioread16(priv->base + NPCM_PSPI_CTL1);
val |= mask;
iowrite16(val, priv->base + NPCM_PSPI_CTL1);
}
static inline void npcm_pspi_irq_disable(struct npcm_pspi *priv, u16 mask)
{
u16 val;
val = ioread16(priv->base + NPCM_PSPI_CTL1);
val &= ~mask;
iowrite16(val, priv->base + NPCM_PSPI_CTL1);
}
static inline void npcm_pspi_enable(struct npcm_pspi *priv)
{
u16 val;
val = ioread16(priv->base + NPCM_PSPI_CTL1);
val |= NPCM_PSPI_CTL1_SPIEN;
iowrite16(val, priv->base + NPCM_PSPI_CTL1);
}
static inline void npcm_pspi_disable(struct npcm_pspi *priv)
{
u16 val;
val = ioread16(priv->base + NPCM_PSPI_CTL1);
val &= ~NPCM_PSPI_CTL1_SPIEN;
iowrite16(val, priv->base + NPCM_PSPI_CTL1);
}
static void npcm_pspi_set_mode(struct spi_device *spi)
{
struct npcm_pspi *priv = spi_controller_get_devdata(spi->controller);
u16 regtemp;
u16 mode_val;
switch (spi->mode & SPI_MODE_X_MASK) {
case SPI_MODE_0:
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/bitfield.h`, `linux/bitops.h`, `linux/clk.h`, `linux/interrupt.h`, `linux/io.h`, `linux/module.h`, `linux/platform_device.h`.
- Detected declarations: `struct npcm_pspi`, `function bytes_per_word`, `function npcm_pspi_irq_enable`, `function npcm_pspi_irq_disable`, `function npcm_pspi_enable`, `function npcm_pspi_disable`, `function npcm_pspi_set_mode`, `function npcm_pspi_set_transfer_size`, `function npcm_pspi_set_baudrate`, `function npcm_pspi_setup_transfer`.
- Atlas domain: Driver Families / drivers/spi.
- Implementation status: source implementation candidate.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.