mohitmishra786/low-level-dev-skills

bus-drivers-i2c-spi

I2C and SPI bus driver skill for Linux client drivers.

Ver código fuente

Cómo usar

  1. Copia el comando y revisa el paquete antes de instalarlo en tu entorno de agente.
  2. Consulta las herramientas, credenciales y entornos necesarios en el documento original.
  3. Describe las entradas y el resultado deseado; contrasta la salida con las fuentes.
npx skills add https://github.com/mohitmishra786/low-level-dev-skills --skill bus-drivers-i2c-spi

Antes de empezar

  • La instalación no incluye suscripción al modelo, cuota API ni permisos sobre tus archivos.
  • Las estrellas e instalaciones reflejan actividad, no una prueba independiente de calidad o seguridad.
Documento original del Skill

Contenido del repositorio de origen con títulos, ejemplos, código, tablas, enlaces e imágenes preservados.

Bus Drivers (I2C and SPI)

Purpose

Guide agents through Linux I2C and SPI client drivers: bus registration, i2c_transfer / spi_sync, regmap abstraction, DT compatible on bus children, and probe patterns — complementing platform MMIO drivers in skills/kernel/device-drivers.

When to Use

  • Sensor or PMIC on I2C/SPI bus
  • Converting bare-metal SPI register reads to kernel driver
  • Using regmap for multi-byte register access
  • Debugging -EREMOTEIO or missing ACK

Workflow

1. I2C client driver

c
#include <linux/i2c.h>
#include <linux/mod_devicetable.h>

static int my_probe(struct i2c_client *client)
{
    struct regmap *map;

    map = devm_regmap_init_i2c(client, &my_regmap_config);
    if (IS_ERR(map))
        return PTR_ERR(map);

    dev_info(&client->dev, "probed at 0x%02x\n", client->addr);
    return 0;
}

static const struct of_device_id my_of_id[] = {
    { .compatible = "vendor,sensor" },
    { }
};
MODULE_DEVICE_TABLE(of, my_of_id);

static const struct i2c_device_id my_id[] = {
    { "mysensor", 0 },
    { }
};
MODULE_DEVICE_TABLE(i2c, my_id);

static struct i2c_driver my_driver = {
    .probe    = my_probe,
    .remove   = my_remove,
    .driver   = { .name = "mysensor", .of_match_table = my_of_id },
    .id_table = my_id,
};
module_i2c_driver(my_driver);

DT child:

dts
i2c1 {
    sensor@48 {
        compatible = "vendor,sensor";
        reg = <0x48>;
    };
};

2. Raw I2C transfer

c
u8 reg = 0x0F, val;
struct i2c_msg msgs[] = {
    { .addr = client->addr, .flags = 0,       .len = 1, .buf = &reg },
    { .addr = client->addr, .flags = I2C_M_RD, .len = 1, .buf = &val },
};
ret = i2c_transfer(client->adapter, msgs, 2);

3. SPI driver

c
static int spi_probe(struct spi_device *spi)
{
    spi->mode = SPI_MODE_0;
    spi->bits_per_word = 8;
    spi_setup(spi);

    struct spi_transfer t = {
        .tx_buf = tx,
        .rx_buf = rx,
        .len    = len,
    };
    struct spi_message m;
    spi_message_init(&m);
    spi_message_add_tail(&t, &m);
    return spi_sync(spi, &m);
}

static struct spi_driver spi_drv = {
    .probe  = spi_probe,
    .driver = { .name = "my-spi", .of_match_table = my_of_match },
};
module_spi_driver(spi_drv);

4. regmap (preferred for register maps)

c
static const struct regmap_config my_regmap_config = {
    .reg_bits   = 8,
    .val_bits   = 8,
    .max_register = 0x7F,
};

regmap_read(map, REG_STATUS, &val);
regmap_write(map, REG_CTRL, CTRL_ENABLE);
regmap_update_bits(map, REG_CTRL, MASK, ENABLE);

5. Debug

bash
i2cdetect -y 1
i2cdump -y 1 0x48
cat /sys/bus/i2c/devices/i2c-1/1-0048/name

6. Agent usage

/bus-drivers-i2c-spi Write regmap-based driver for I2C PMIC at 0x58

Common Problems

SymptomCauseFix
-EREMOTEIONACK — wrong addressi2cdetect; check reg in DT
SPI mode wrongCPOL/CPHA mismatchMatch datasheet + spi->mode
Probe deferRegulator/clock supplierReturn -EPROBE_DEFER
regmap -EIO16-bit vs 8-bit regSet reg_bits, val_bits
DMA not usedSmall spi_sync OKspi_sync_transfer for bulk

Related Skills

  • skills/kernel/device-drivers — IRQ, DMA, PM runtime
  • skills/kernel-dev/device-tree — bus child nodes
  • skills/baremetal/spi-i2c-baremetal — register-level protocol
  • skills/kernel-dev/platform-device-model — driver model parallels
  • skills/kernel-dev/writing-char-drivers — expose sensor via char dev

Relacionados por tarea

del mismo repositorio

Más Skills

Todos los Skills
mohitmishra786
Comunidad

core-dumps

Core dump analysis skill for production crash triage. Use when loading core files in GDB or LLDB, enabling core dump generation on Linux/macOS, mapping symbols with debuginfo or debuginfod, or extracting backtraces from crashes without re-running the program. Activates on queries about core files, ulimit, coredumpctl, debuginfod, crash triage, or analyzing segfaults from production binaries.

instalaciones
2
GitHub Stars
267
Actualizado
27 jun
mohitmishra786
Comunidad

custom-allocators

Custom allocator skill for memory allocation strategies. Use when implementing pool/slab/arena allocators, tuning jemalloc/mimalloc, writing Rust GlobalAlloc, or benchmarking allocator performance. Activates on queries about jemalloc, mimalloc, tcmalloc, arena allocator, GlobalAlloc, or fragmentation.

instalaciones
2
GitHub Stars
267
Actualizado
27 jun
mohitmishra786
Comunidad

ebpf

eBPF skill for Linux observability and networking. Use when writing eBPF programs with libbpf or bpftrace, attaching kprobes/tracepoints/XDP hooks, debugging verifier errors, working with eBPF maps, or achieving CO-RE portability across kernel versions. Activates on queries about eBPF, bpftool, bpftrace, XDP programs, libbpf, verifier errors, eBPF maps, or kernel tracing with BPF.

instalaciones
2
GitHub Stars
267
Actualizado
27 jun
mohitmishra786
Comunidad

flamegraphs

Flamegraph generation and interpretation skill. Use when converting perf, Valgrind Callgrind, or other profiler output into SVG flamegraphs using Brendan Gregg's FlameGraph tools, or when reading flamegraphs to identify performance bottlenecks. Activates on queries about flamegraphs, stackcollapse, flamegraph.svg, identifying hot frames, wide vs tall frames, or performance visualisation.

instalaciones
2
GitHub Stars
267
Actualizado
27 jun