drivers/staging/iio/addac/adt7316-spi.c
Source file repositories/reference/linux-study-clean/drivers/staging/iio/addac/adt7316-spi.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/staging/iio/addac/adt7316-spi.c- Extension
.c- Size
- 3519 bytes
- Lines
- 155
- Domain
- Driver Families
- Bucket
- drivers/staging
- 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/device.hlinux/kernel.hlinux/module.hlinux/interrupt.hlinux/spi/spi.hadt7316.h
Detected Declarations
function adt7316_spi_multi_readfunction adt7316_spi_multi_writefunction adt7316_spi_readfunction adt7316_spi_writefunction adt7316_spi_probe
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0+
/*
* API bus driver for ADT7316/7/8 ADT7516/7/9 digital temperature
* sensor, ADC and DAC
*
* Copyright 2010 Analog Devices Inc.
*/
#include <linux/device.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/interrupt.h>
#include <linux/spi/spi.h>
#include "adt7316.h"
#define ADT7316_SPI_MAX_FREQ_HZ 5000000
#define ADT7316_SPI_CMD_READ 0x91
#define ADT7316_SPI_CMD_WRITE 0x90
/*
* adt7316 register access by SPI
*/
static int adt7316_spi_multi_read(void *client, u8 reg, u8 count, u8 *data)
{
struct spi_device *spi_dev = client;
u8 cmd[2];
int ret;
if (count > ADT7316_REG_MAX_ADDR)
count = ADT7316_REG_MAX_ADDR;
cmd[0] = ADT7316_SPI_CMD_WRITE;
cmd[1] = reg;
ret = spi_write(spi_dev, cmd, 2);
if (ret < 0) {
dev_err(&spi_dev->dev, "SPI fail to select reg\n");
return ret;
}
cmd[0] = ADT7316_SPI_CMD_READ;
ret = spi_write_then_read(spi_dev, cmd, 1, data, count);
if (ret < 0) {
dev_err(&spi_dev->dev, "SPI read data error\n");
return ret;
}
return 0;
}
static int adt7316_spi_multi_write(void *client, u8 reg, u8 count, u8 *data)
{
struct spi_device *spi_dev = client;
u8 buf[ADT7316_REG_MAX_ADDR + 2];
int i, ret;
if (count > ADT7316_REG_MAX_ADDR)
count = ADT7316_REG_MAX_ADDR;
buf[0] = ADT7316_SPI_CMD_WRITE;
buf[1] = reg;
for (i = 0; i < count; i++)
buf[i + 2] = data[i];
ret = spi_write(spi_dev, buf, count + 2);
if (ret < 0) {
dev_err(&spi_dev->dev, "SPI write error\n");
return ret;
}
return ret;
}
static int adt7316_spi_read(void *client, u8 reg, u8 *data)
{
return adt7316_spi_multi_read(client, reg, 1, data);
}
static int adt7316_spi_write(void *client, u8 reg, u8 val)
{
return adt7316_spi_multi_write(client, reg, 1, &val);
}
/*
* device probe and remove
*/
Annotation
- Immediate include surface: `linux/device.h`, `linux/kernel.h`, `linux/module.h`, `linux/interrupt.h`, `linux/spi/spi.h`, `adt7316.h`.
- Detected declarations: `function adt7316_spi_multi_read`, `function adt7316_spi_multi_write`, `function adt7316_spi_read`, `function adt7316_spi_write`, `function adt7316_spi_probe`.
- Atlas domain: Driver Families / drivers/staging.
- 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.