drivers/spi/spi-sh-hspi.c
Source file repositories/reference/linux-study-clean/drivers/spi/spi-sh-hspi.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/spi/spi-sh-hspi.c- Extension
.c- Size
- 6058 bytes
- Lines
- 306
- 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/module.hlinux/kernel.hlinux/timer.hlinux/delay.hlinux/list.hlinux/interrupt.hlinux/platform_device.hlinux/pm_runtime.hlinux/io.hlinux/spi/spi.hlinux/spi/sh_hspi.h
Detected Declarations
struct hspi_privfunction hspi_writefunction hspi_readfunction hspi_bit_setfunction hspi_status_check_timeoutfunction hspi_hw_cs_ctrlfunction hspi_hw_setupfunction hspi_transfer_one_messagefunction hspi_probefunction hspi_remove
Annotated Snippet
struct hspi_priv {
void __iomem *addr;
struct spi_controller *ctlr;
struct device *dev;
struct clk *clk;
};
/*
* basic function
*/
static void hspi_write(struct hspi_priv *hspi, int reg, u32 val)
{
iowrite32(val, hspi->addr + reg);
}
static u32 hspi_read(struct hspi_priv *hspi, int reg)
{
return ioread32(hspi->addr + reg);
}
static void hspi_bit_set(struct hspi_priv *hspi, int reg, u32 mask, u32 set)
{
u32 val = hspi_read(hspi, reg);
val &= ~mask;
val |= set & mask;
hspi_write(hspi, reg, val);
}
/*
* transfer function
*/
static int hspi_status_check_timeout(struct hspi_priv *hspi, u32 mask, u32 val)
{
int t = 256;
while (t--) {
if ((mask & hspi_read(hspi, SPSR)) == val)
return 0;
udelay(10);
}
dev_err(hspi->dev, "timeout\n");
return -ETIMEDOUT;
}
/*
* spi host function
*/
#define hspi_hw_cs_enable(hspi) hspi_hw_cs_ctrl(hspi, 0)
#define hspi_hw_cs_disable(hspi) hspi_hw_cs_ctrl(hspi, 1)
static void hspi_hw_cs_ctrl(struct hspi_priv *hspi, int hi)
{
hspi_bit_set(hspi, SPSCR, (1 << 6), (hi) << 6);
}
static void hspi_hw_setup(struct hspi_priv *hspi,
struct spi_message *msg,
struct spi_transfer *t)
{
struct spi_device *spi = msg->spi;
struct device *dev = hspi->dev;
u32 spcr, idiv_clk;
u32 rate, best_rate, min, tmp;
/*
* find best IDIV/CLKCx settings
*/
min = ~0;
best_rate = 0;
spcr = 0;
for (idiv_clk = 0x00; idiv_clk <= 0x3F; idiv_clk++) {
rate = clk_get_rate(hspi->clk);
/* IDIV calculation */
if (idiv_clk & (1 << 5))
rate /= 128;
else
rate /= 16;
/* CLKCx calculation */
rate /= (((idiv_clk & 0x1F) + 1) * 2);
/* save best settings */
tmp = abs(t->speed_hz - rate);
if (tmp < min) {
min = tmp;
Annotation
- Immediate include surface: `linux/clk.h`, `linux/module.h`, `linux/kernel.h`, `linux/timer.h`, `linux/delay.h`, `linux/list.h`, `linux/interrupt.h`, `linux/platform_device.h`.
- Detected declarations: `struct hspi_priv`, `function hspi_write`, `function hspi_read`, `function hspi_bit_set`, `function hspi_status_check_timeout`, `function hspi_hw_cs_ctrl`, `function hspi_hw_setup`, `function hspi_transfer_one_message`, `function hspi_probe`, `function hspi_remove`.
- 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.