drivers/iio/imu/bno055/bno055_ser_core.c
Source file repositories/reference/linux-study-clean/drivers/iio/imu/bno055/bno055_ser_core.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/imu/bno055/bno055_ser_core.c- Extension
.c- Size
- 15917 bytes
- Lines
- 561
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/completion.hlinux/device.hlinux/errno.hlinux/jiffies.hlinux/kernel.hlinux/mod_devicetable.hlinux/module.hlinux/mutex.hlinux/regmap.hlinux/serdev.hbno055_ser_trace.hbno055.h
Detected Declarations
struct bno055_ser_privfunction bno055_ser_send_chunkfunction bno055_ser_do_send_cmdfunction bno055_ser_send_cmdfunction bno055_ser_write_regfunction bno055_ser_read_regfunction validfunction failuresfunction bno055_ser_probe
Annotated Snippet
struct bno055_ser_priv {
enum {
CMD_NONE,
CMD_READ,
CMD_WRITE,
} expect_response;
int expected_data_len;
u8 *response_buf;
/**
* enum cmd_status - represent the status of a command sent to the HW.
* @STATUS_CRIT: The command failed: the serial communication failed.
* @STATUS_OK: The command executed successfully.
* @STATUS_FAIL: The command failed: HW responded with an error.
*/
enum {
STATUS_CRIT = -1,
STATUS_OK = 0,
STATUS_FAIL = 1,
} cmd_status;
/*
* Protects all the above fields, which are accessed in behalf of both
* the serdev RX callback and the regmap side
*/
struct mutex lock;
/* Only accessed in serdev RX callback context*/
struct {
enum {
RX_IDLE,
RX_START,
RX_DATA,
} state;
int databuf_count;
int expected_len;
int type;
} rx;
/* Never accessed in behalf of serdev RX callback context */
bool cmd_stale;
struct completion cmd_complete;
struct serdev_device *serdev;
};
static int bno055_ser_send_chunk(struct bno055_ser_priv *priv, const u8 *data, int len)
{
int ret;
trace_send_chunk(len, data);
ret = serdev_device_write(priv->serdev, data, len, msecs_to_jiffies(25));
if (ret < 0)
return ret;
if (ret < len)
return -EIO;
return 0;
}
/*
* Send a read or write command.
* 'data' can be NULL (used in read case). 'len' parameter is always valid; in
* case 'data' is non-NULL then it must match 'data' size.
*/
static int bno055_ser_do_send_cmd(struct bno055_ser_priv *priv,
bool read, int addr, int len, const u8 *data)
{
u8 hdr[] = {0xAA, read, addr, len};
int chunk_len;
int ret;
ret = bno055_ser_send_chunk(priv, hdr, 2);
if (ret)
goto fail;
usleep_range(2000, 3000);
ret = bno055_ser_send_chunk(priv, hdr + 2, 2);
if (ret)
goto fail;
if (read)
return 0;
while (len) {
chunk_len = min(len, 2);
usleep_range(2000, 3000);
ret = bno055_ser_send_chunk(priv, data, chunk_len);
if (ret)
goto fail;
Annotation
- Immediate include surface: `linux/completion.h`, `linux/device.h`, `linux/errno.h`, `linux/jiffies.h`, `linux/kernel.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/mutex.h`.
- Detected declarations: `struct bno055_ser_priv`, `function bno055_ser_send_chunk`, `function bno055_ser_do_send_cmd`, `function bno055_ser_send_cmd`, `function bno055_ser_write_reg`, `function bno055_ser_read_reg`, `function valid`, `function failures`, `function bno055_ser_probe`.
- 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.