drivers/iio/accel/stk8ba50.c
Source file repositories/reference/linux-study-clean/drivers/iio/accel/stk8ba50.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/accel/stk8ba50.c- Extension
.c- Size
- 13994 bytes
- Lines
- 550
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/i2c.hlinux/interrupt.hlinux/kernel.hlinux/module.hlinux/mod_devicetable.hlinux/types.hlinux/iio/buffer.hlinux/iio/iio.hlinux/iio/sysfs.hlinux/iio/trigger.hlinux/iio/triggered_buffer.hlinux/iio/trigger_consumer.h
Detected Declarations
struct stk8ba50_datafunction stk8ba50_read_accelfunction stk8ba50_data_rdy_trigger_set_statefunction stk8ba50_set_powerfunction stk8ba50_read_rawfunction stk8ba50_write_rawfunction stk8ba50_trigger_handlerfunction iio_for_each_active_channelfunction stk8ba50_data_rdy_trig_pollfunction stk8ba50_buffer_preenablefunction stk8ba50_buffer_postdisablefunction stk8ba50_probefunction stk8ba50_removefunction stk8ba50_suspendfunction stk8ba50_resume
Annotated Snippet
struct stk8ba50_data {
struct i2c_client *client;
struct mutex lock;
int range;
u8 sample_rate_idx;
struct iio_trigger *dready_trig;
bool dready_trigger_on;
/* Ensure timestamp is naturally aligned */
struct {
s16 chans[3];
aligned_s64 timetamp;
} scan;
};
#define STK8BA50_ACCEL_CHANNEL(index, reg, axis) { \
.type = IIO_ACCEL, \
.address = reg, \
.modified = 1, \
.channel2 = IIO_MOD_##axis, \
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
BIT(IIO_CHAN_INFO_SAMP_FREQ), \
.scan_index = index, \
.scan_type = { \
.sign = 's', \
.realbits = 10, \
.storagebits = 16, \
.shift = STK8BA50_DATA_SHIFT, \
.endianness = IIO_CPU, \
}, \
}
static const struct iio_chan_spec stk8ba50_channels[] = {
STK8BA50_ACCEL_CHANNEL(0, STK8BA50_REG_XOUT, X),
STK8BA50_ACCEL_CHANNEL(1, STK8BA50_REG_YOUT, Y),
STK8BA50_ACCEL_CHANNEL(2, STK8BA50_REG_ZOUT, Z),
IIO_CHAN_SOFT_TIMESTAMP(3),
};
static IIO_CONST_ATTR(in_accel_scale_available, STK8BA50_SCALE_AVAIL);
static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("14 25 56 112 224 448 896 1792");
static struct attribute *stk8ba50_attributes[] = {
&iio_const_attr_in_accel_scale_available.dev_attr.attr,
&iio_const_attr_sampling_frequency_available.dev_attr.attr,
NULL,
};
static const struct attribute_group stk8ba50_attribute_group = {
.attrs = stk8ba50_attributes
};
static int stk8ba50_read_accel(struct stk8ba50_data *data, u8 reg)
{
int ret;
struct i2c_client *client = data->client;
ret = i2c_smbus_read_word_data(client, reg);
if (ret < 0) {
dev_err(&client->dev, "register read failed\n");
return ret;
}
return ret;
}
static int stk8ba50_data_rdy_trigger_set_state(struct iio_trigger *trig,
bool state)
{
struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig);
struct stk8ba50_data *data = iio_priv(indio_dev);
int ret;
if (state)
ret = i2c_smbus_write_byte_data(data->client,
STK8BA50_REG_INTEN2, STK8BA50_DREADY_INT_MASK);
else
ret = i2c_smbus_write_byte_data(data->client,
STK8BA50_REG_INTEN2, 0x00);
if (ret < 0)
dev_err(&data->client->dev, "failed to set trigger state\n");
else
data->dready_trigger_on = state;
return ret;
}
static const struct iio_trigger_ops stk8ba50_trigger_ops = {
Annotation
- Immediate include surface: `linux/i2c.h`, `linux/interrupt.h`, `linux/kernel.h`, `linux/module.h`, `linux/mod_devicetable.h`, `linux/types.h`, `linux/iio/buffer.h`, `linux/iio/iio.h`.
- Detected declarations: `struct stk8ba50_data`, `function stk8ba50_read_accel`, `function stk8ba50_data_rdy_trigger_set_state`, `function stk8ba50_set_power`, `function stk8ba50_read_raw`, `function stk8ba50_write_raw`, `function stk8ba50_trigger_handler`, `function iio_for_each_active_channel`, `function stk8ba50_data_rdy_trig_poll`, `function stk8ba50_buffer_preenable`.
- 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.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.