drivers/net/dsa/microchip/ksz_spi.c
Source file repositories/reference/linux-study-clean/drivers/net/dsa/microchip/ksz_spi.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/dsa/microchip/ksz_spi.c- Extension
.c- Size
- 8294 bytes
- Lines
- 367
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/unaligned.hlinux/delay.hlinux/kernel.hlinux/module.hlinux/regmap.hlinux/spi/spi.hksz_common.h
Detected Declarations
function ksz8463_regfunction ksz8463_spi_readfunction ksz8463_spi_writefunction ksz_spi_probefunction ksz_spi_removefunction ksz_spi_shutdown
Annotated Snippet
if (val_size == 2) {
u16 v = get_unaligned_le16(val);
memcpy(val, &v, sizeof(v));
} else if (val_size == 4) {
u32 v = get_unaligned_le32(val);
memcpy(val, &v, sizeof(v));
}
}
#endif
return rc;
}
static int ksz8463_spi_write(void *context, const void *data, size_t count)
{
struct device *dev = context;
struct spi_device *spi = to_spi_device(dev);
size_t val_size = count - 2;
u8 bytes[6];
u16 cmd;
if (count <= 2 || count > 6)
return -EINVAL;
memcpy(bytes, data, count);
memcpy(&cmd, data, sizeof(u16));
cmd = ksz8463_reg(cmd, val_size);
cmd |= (1 << (KSZ8463_SPI_ADDR_SHIFT + KSZ8463_SPI_TURNAROUND_SHIFT));
/* SPI command uses big-endian format. */
put_unaligned_be16(cmd, bytes);
#if defined(__BIG_ENDIAN)
/* Register value uses little-endian format so need to convert when
* running in big-endian system.
*/
if (val_size == 2) {
u8 *val = &bytes[2];
u16 v;
memcpy(&v, val, sizeof(v));
put_unaligned_le16(v, val);
} else if (val_size == 4) {
u8 *val = &bytes[2];
u32 v;
memcpy(&v, val, sizeof(v));
put_unaligned_le32(v, val);
}
#endif
return spi_write(spi, bytes, count);
}
KSZ8463_REGMAP_TABLE(ksz8463, KSZ8463_SPI_ADDR_SHIFT, 0,
KSZ8463_SPI_ADDR_ALIGN);
static int ksz_spi_probe(struct spi_device *spi)
{
const struct regmap_config *regmap_config;
const struct ksz_chip_data *chip;
struct device *ddev = &spi->dev;
struct regmap_config rc;
struct ksz_device *dev;
int i, ret = 0;
chip = device_get_match_data(ddev);
if (!chip)
return -EINVAL;
dev = ksz_switch_alloc(&spi->dev, chip, spi);
if (!dev)
return -ENOMEM;
/* Save chip id to do special initialization when probing. */
dev->chip_id = chip->chip_id;
if (chip->chip_id == KSZ88X3_CHIP_ID)
regmap_config = ksz8863_regmap_config;
else if (chip->chip_id == KSZ8463_CHIP_ID)
regmap_config = ksz8463_regmap_config;
else if (chip->chip_id == KSZ8795_CHIP_ID ||
chip->chip_id == KSZ8794_CHIP_ID ||
chip->chip_id == KSZ8765_CHIP_ID)
regmap_config = ksz8795_regmap_config;
else if (chip->chip_id == KSZ8895_CHIP_ID ||
chip->chip_id == KSZ8864_CHIP_ID)
regmap_config = ksz8863_regmap_config;
else
regmap_config = ksz9477_regmap_config;
for (i = 0; i < __KSZ_NUM_REGMAPS; i++) {
rc = regmap_config[i];
rc.lock_arg = &dev->regmap_mutex;
Annotation
- Immediate include surface: `linux/unaligned.h`, `linux/delay.h`, `linux/kernel.h`, `linux/module.h`, `linux/regmap.h`, `linux/spi/spi.h`, `ksz_common.h`.
- Detected declarations: `function ksz8463_reg`, `function ksz8463_spi_read`, `function ksz8463_spi_write`, `function ksz_spi_probe`, `function ksz_spi_remove`, `function ksz_spi_shutdown`.
- Atlas domain: Driver Families / drivers/net.
- 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.