drivers/iio/dac/m62332.c
Source file repositories/reference/linux-study-clean/drivers/iio/dac/m62332.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/dac/m62332.c- Extension
.c- Size
- 5218 bytes
- Lines
- 250
- Domain
- Driver Families
- Bucket
- drivers/iio
- 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/module.hlinux/slab.hlinux/i2c.hlinux/err.hlinux/iio/iio.hlinux/iio/driver.hlinux/regulator/consumer.h
Detected Declarations
struct m62332_datafunction m62332_set_valuefunction m62332_read_rawfunction m62332_write_rawfunction m62332_suspendfunction m62332_resumefunction m62332_probefunction m62332_remove
Annotated Snippet
struct m62332_data {
struct i2c_client *client;
struct regulator *vcc;
struct mutex mutex;
u8 raw[M62332_CHANNELS];
u8 save[M62332_CHANNELS];
};
static int m62332_set_value(struct iio_dev *indio_dev, u8 val, int channel)
{
struct m62332_data *data = iio_priv(indio_dev);
struct i2c_client *client = data->client;
u8 outbuf[2];
int res;
if (val == data->raw[channel])
return 0;
outbuf[0] = channel;
outbuf[1] = val;
mutex_lock(&data->mutex);
if (val) {
res = regulator_enable(data->vcc);
if (res)
goto out;
}
res = i2c_master_send(client, outbuf, ARRAY_SIZE(outbuf));
if (res >= 0 && res != ARRAY_SIZE(outbuf))
res = -EIO;
if (res < 0)
goto out;
data->raw[channel] = val;
if (!val)
regulator_disable(data->vcc);
mutex_unlock(&data->mutex);
return 0;
out:
mutex_unlock(&data->mutex);
return res;
}
static int m62332_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val,
int *val2,
long mask)
{
struct m62332_data *data = iio_priv(indio_dev);
int ret;
switch (mask) {
case IIO_CHAN_INFO_SCALE:
/* Corresponds to Vref / 2^(bits) */
ret = regulator_get_voltage(data->vcc);
if (ret < 0)
return ret;
*val = ret / 1000; /* mV */
*val2 = 8;
return IIO_VAL_FRACTIONAL_LOG2;
case IIO_CHAN_INFO_RAW:
*val = data->raw[chan->channel];
return IIO_VAL_INT;
case IIO_CHAN_INFO_OFFSET:
*val = 1;
return IIO_VAL_INT;
default:
break;
}
return -EINVAL;
}
static int m62332_write_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan, int val, int val2,
long mask)
{
switch (mask) {
Annotation
- Immediate include surface: `linux/module.h`, `linux/slab.h`, `linux/i2c.h`, `linux/err.h`, `linux/iio/iio.h`, `linux/iio/driver.h`, `linux/regulator/consumer.h`.
- Detected declarations: `struct m62332_data`, `function m62332_set_value`, `function m62332_read_raw`, `function m62332_write_raw`, `function m62332_suspend`, `function m62332_resume`, `function m62332_probe`, `function m62332_remove`.
- Atlas domain: Driver Families / drivers/iio.
- 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.