drivers/iio/accel/kxsd9.c
Source file repositories/reference/linux-study-clean/drivers/iio/accel/kxsd9.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/accel/kxsd9.c- Extension
.c- Size
- 12008 bytes
- Lines
- 511
- Domain
- Driver Families
- Bucket
- drivers/iio
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/device.hlinux/kernel.hlinux/sysfs.hlinux/slab.hlinux/types.hlinux/module.hlinux/regmap.hlinux/bitops.hlinux/delay.hlinux/regulator/consumer.hlinux/pm_runtime.hlinux/iio/iio.hlinux/iio/sysfs.hlinux/iio/buffer.hlinux/iio/triggered_buffer.hlinux/iio/trigger_consumer.hkxsd9.h
Detected Declarations
struct kxsd9_statefunction kxsd9_write_scalefunction kxsd9_write_rawfunction kxsd9_read_rawfunction kxsd9_trigger_handlerfunction kxsd9_buffer_preenablefunction kxsd9_buffer_postdisablefunction kxsd9_get_mount_matrixfunction kxsd9_power_upfunction kxsd9_power_downfunction kxsd9_common_probefunction kxsd9_common_removefunction kxsd9_runtime_suspendfunction kxsd9_runtime_resume
Annotated Snippet
struct kxsd9_state {
struct device *dev;
struct regmap *map;
struct iio_mount_matrix orientation;
struct regulator_bulk_data regs[2];
u8 scale;
};
#define KXSD9_SCALE_2G "0.011978"
#define KXSD9_SCALE_4G "0.023927"
#define KXSD9_SCALE_6G "0.035934"
#define KXSD9_SCALE_8G "0.047853"
/* reverse order */
static const int kxsd9_micro_scales[4] = { 47853, 35934, 23927, 11978 };
#define KXSD9_ZERO_G_OFFSET -2048
/*
* Regulator names
*/
static const char kxsd9_reg_vdd[] = "vdd";
static const char kxsd9_reg_iovdd[] = "iovdd";
static int kxsd9_write_scale(struct iio_dev *indio_dev, int micro)
{
int ret, i;
struct kxsd9_state *st = iio_priv(indio_dev);
bool foundit = false;
for (i = 0; i < 4; i++)
if (micro == kxsd9_micro_scales[i]) {
foundit = true;
break;
}
if (!foundit)
return -EINVAL;
ret = regmap_update_bits(st->map,
KXSD9_REG_CTRL_C,
KXSD9_CTRL_C_FS_MASK,
i);
if (ret < 0)
goto error_ret;
/* Cached scale when the sensor is powered down */
st->scale = i;
error_ret:
return ret;
}
static IIO_CONST_ATTR(accel_scale_available,
KXSD9_SCALE_2G " "
KXSD9_SCALE_4G " "
KXSD9_SCALE_6G " "
KXSD9_SCALE_8G);
static struct attribute *kxsd9_attributes[] = {
&iio_const_attr_accel_scale_available.dev_attr.attr,
NULL,
};
static int kxsd9_write_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int val,
int val2,
long mask)
{
int ret = -EINVAL;
struct kxsd9_state *st = iio_priv(indio_dev);
pm_runtime_get_sync(st->dev);
if (mask == IIO_CHAN_INFO_SCALE) {
/* Check no integer component */
if (val)
return -EINVAL;
ret = kxsd9_write_scale(indio_dev, val2);
}
pm_runtime_put_autosuspend(st->dev);
return ret;
}
static int kxsd9_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val, int *val2, long mask)
{
Annotation
- Immediate include surface: `linux/device.h`, `linux/kernel.h`, `linux/sysfs.h`, `linux/slab.h`, `linux/types.h`, `linux/module.h`, `linux/regmap.h`, `linux/bitops.h`.
- Detected declarations: `struct kxsd9_state`, `function kxsd9_write_scale`, `function kxsd9_write_raw`, `function kxsd9_read_raw`, `function kxsd9_trigger_handler`, `function kxsd9_buffer_preenable`, `function kxsd9_buffer_postdisable`, `function kxsd9_get_mount_matrix`, `function kxsd9_power_up`, `function kxsd9_power_down`.
- Atlas domain: Driver Families / drivers/iio.
- Implementation status: integration implementation candidate.
- 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.