drivers/net/ethernet/micrel/ks8851_spi.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/micrel/ks8851_spi.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/micrel/ks8851_spi.c- Extension
.c- Size
- 12472 bytes
- Lines
- 479
- Domain
- Driver Families
- Bucket
- drivers/net
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/interrupt.hlinux/module.hlinux/kernel.hlinux/netdevice.hlinux/etherdevice.hlinux/ethtool.hlinux/cache.hlinux/crc32.hlinux/mii.hlinux/regulator/consumer.hlinux/spi/spi.hlinux/of_net.hks8851.h
Detected Declarations
struct ks8851_net_spifunction ks8851_lock_spifunction ks8851_unlock_spifunction datafunction messagefunction ks8851_rdreg16_spifunction ks8851_rdfifo_spifunction ks8851_wrfifo_spifunction calc_txlenfunction ks8851_tx_workfunction ks8851_flush_tx_work_spifunction ks8851_start_xmit_spifunction ks8851_probe_spifunction ks8851_remove_spi
Annotated Snippet
struct ks8851_net_spi {
struct ks8851_net ks8851;
struct mutex lock;
struct work_struct tx_work;
struct spi_device *spidev;
struct spi_message spi_msg1;
struct spi_message spi_msg2;
struct spi_transfer spi_xfer1;
struct spi_transfer spi_xfer2[2];
};
#define to_ks8851_spi(ks) container_of((ks), struct ks8851_net_spi, ks8851)
/* SPI frame opcodes */
#define KS_SPIOP_RD 0x00
#define KS_SPIOP_WR 0x40
#define KS_SPIOP_RXFIFO 0x80
#define KS_SPIOP_TXFIFO 0xC0
/* shift for byte-enable data */
#define BYTE_EN(_x) ((_x) << 2)
/* turn register number and byte-enable mask into data for start of packet */
#define MK_OP(_byteen, _reg) \
(BYTE_EN(_byteen) | (_reg) << (8 + 2) | (_reg) >> 6)
/**
* ks8851_lock_spi - register access lock
* @ks: The chip state
*
* Claim chip register access lock
*/
static void ks8851_lock_spi(struct ks8851_net *ks)
{
struct ks8851_net_spi *kss = to_ks8851_spi(ks);
mutex_lock(&kss->lock);
}
/**
* ks8851_unlock_spi - register access unlock
* @ks: The chip state
*
* Release chip register access lock
*/
static void ks8851_unlock_spi(struct ks8851_net *ks)
{
struct ks8851_net_spi *kss = to_ks8851_spi(ks);
mutex_unlock(&kss->lock);
}
/* SPI register read/write calls.
*
* All these calls issue SPI transactions to access the chip's registers. They
* all require that the necessary lock is held to prevent accesses when the
* chip is busy transferring packet data (RX/TX FIFO accesses).
*/
/**
* ks8851_wrreg16_spi - write 16bit register value to chip via SPI
* @ks: The chip state
* @reg: The register address
* @val: The value to write
*
* Issue a write to put the value @val into the register specified in @reg.
*/
static void ks8851_wrreg16_spi(struct ks8851_net *ks, unsigned int reg,
unsigned int val)
{
struct ks8851_net_spi *kss = to_ks8851_spi(ks);
struct spi_transfer *xfer = &kss->spi_xfer1;
struct spi_message *msg = &kss->spi_msg1;
__le16 txb[2];
int ret;
txb[0] = cpu_to_le16(MK_OP(reg & 2 ? 0xC : 0x03, reg) | KS_SPIOP_WR);
txb[1] = cpu_to_le16(val);
xfer->tx_buf = txb;
xfer->rx_buf = NULL;
xfer->len = 4;
ret = spi_sync(kss->spidev, msg);
if (ret < 0)
netdev_err(ks->netdev, "spi_sync() failed\n");
}
/**
* ks8851_rdreg - issue read register command and return the data
Annotation
- Immediate include surface: `linux/interrupt.h`, `linux/module.h`, `linux/kernel.h`, `linux/netdevice.h`, `linux/etherdevice.h`, `linux/ethtool.h`, `linux/cache.h`, `linux/crc32.h`.
- Detected declarations: `struct ks8851_net_spi`, `function ks8851_lock_spi`, `function ks8851_unlock_spi`, `function data`, `function message`, `function ks8851_rdreg16_spi`, `function ks8851_rdfifo_spi`, `function ks8851_wrfifo_spi`, `function calc_txlen`, `function ks8851_tx_work`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.