drivers/spi/spi-mt7621.c
Source file repositories/reference/linux-study-clean/drivers/spi/spi-mt7621.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/spi/spi-mt7621.c- Extension
.c- Size
- 9197 bytes
- Lines
- 388
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/clk.hlinux/delay.hlinux/io.hlinux/module.hlinux/of.hlinux/of_device.hlinux/platform_device.hlinux/reset.hlinux/spi/spi.h
Detected Declarations
struct mt7621_spifunction mt7621_spi_readfunction mt7621_spi_writefunction mt7621_spi_set_native_csfunction mt7621_spi_preparefunction mt7621_spi_wait_till_readyfunction mt7621_spi_prepare_messagefunction mt7621_spi_read_half_duplexfunction mt7621_spi_flushfunction mt7621_spi_write_half_duplexfunction mt7621_spi_transfer_onefunction mt7621_spi_setupfunction mt7621_spi_probe
Annotated Snippet
struct mt7621_spi {
struct spi_controller *host;
void __iomem *base;
unsigned int sys_freq;
unsigned int speed;
int pending_write;
};
static inline struct mt7621_spi *spidev_to_mt7621_spi(struct spi_device *spi)
{
return spi_controller_get_devdata(spi->controller);
}
static inline u32 mt7621_spi_read(struct mt7621_spi *rs, u32 reg)
{
return ioread32(rs->base + reg);
}
static inline void mt7621_spi_write(struct mt7621_spi *rs, u32 reg, u32 val)
{
iowrite32(val, rs->base + reg);
}
static void mt7621_spi_set_native_cs(struct spi_device *spi, bool enable)
{
struct mt7621_spi *rs = spidev_to_mt7621_spi(spi);
int cs = spi_get_chipselect(spi, 0);
bool active = spi->mode & SPI_CS_HIGH ? enable : !enable;
u32 polar = 0;
u32 host;
/*
* Select SPI device 7, enable "more buffer mode" and disable
* full-duplex (only half-duplex really works on this chip
* reliably)
*/
host = mt7621_spi_read(rs, MT7621_SPI_MASTER);
host |= MASTER_RS_SLAVE_SEL | MASTER_MORE_BUFMODE;
host &= ~MASTER_FULL_DUPLEX;
mt7621_spi_write(rs, MT7621_SPI_MASTER, host);
rs->pending_write = 0;
if (active)
polar = BIT(cs);
mt7621_spi_write(rs, MT7621_SPI_POLAR, polar);
}
static int mt7621_spi_prepare(struct spi_device *spi, unsigned int speed)
{
struct mt7621_spi *rs = spidev_to_mt7621_spi(spi);
u32 rate;
u32 reg;
dev_dbg(&spi->dev, "speed:%u\n", speed);
rate = DIV_ROUND_UP(rs->sys_freq, speed);
dev_dbg(&spi->dev, "rate-1:%u\n", rate);
if (rate > 4097)
return -EINVAL;
if (rate < 2)
rate = 2;
reg = mt7621_spi_read(rs, MT7621_SPI_MASTER);
reg &= ~MASTER_RS_CLK_SEL;
reg |= (rate - 2) << MASTER_RS_CLK_SEL_SHIFT;
rs->speed = speed;
reg &= ~MT7621_LSB_FIRST;
if (spi->mode & SPI_LSB_FIRST)
reg |= MT7621_LSB_FIRST;
/*
* This SPI controller seems to be tested on SPI flash only and some
* bits are swizzled under other SPI modes probably due to incorrect
* wiring inside the silicon. Only mode 0 works correctly.
*/
reg &= ~(MT7621_CPHA | MT7621_CPOL);
mt7621_spi_write(rs, MT7621_SPI_MASTER, reg);
return 0;
}
static inline int mt7621_spi_wait_till_ready(struct mt7621_spi *rs)
{
int i;
Annotation
- Immediate include surface: `linux/clk.h`, `linux/delay.h`, `linux/io.h`, `linux/module.h`, `linux/of.h`, `linux/of_device.h`, `linux/platform_device.h`, `linux/reset.h`.
- Detected declarations: `struct mt7621_spi`, `function mt7621_spi_read`, `function mt7621_spi_write`, `function mt7621_spi_set_native_cs`, `function mt7621_spi_prepare`, `function mt7621_spi_wait_till_ready`, `function mt7621_spi_prepare_message`, `function mt7621_spi_read_half_duplex`, `function mt7621_spi_flush`, `function mt7621_spi_write_half_duplex`.
- Atlas domain: Driver Families / drivers/spi.
- Implementation status: source implementation candidate.
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.