drivers/iio/accel/mma9553.c

Source file repositories/reference/linux-study-clean/drivers/iio/accel/mma9553.c

File Facts

System
Linux kernel
Corpus path
drivers/iio/accel/mma9553.c
Extension
.c
Size
32158 bytes
Lines
1245
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.

Dependency Surface

Detected Declarations

Annotated Snippet

struct mma9553_event {
	const struct mma9553_event_info *info;
	bool enabled;
};

struct mma9553_conf_regs {
	u16 sleepmin;
	u16 sleepmax;
	u16 sleepthd;
	u16 config;
	u16 height_weight;
	u16 filter;
	u16 speed_step;
	u16 actthd;
} __packed;

struct mma9553_data {
	struct i2c_client *client;
	/*
	 * 1. Serialize access to HW (requested by mma9551_core API).
	 * 2. Serialize sequences that power on/off the device and access HW.
	 */
	struct mutex mutex;
	struct mma9553_conf_regs conf;
	struct mma9553_event events[MMA9553_EVENTS_INFO_SIZE];
	int num_events;
	u8 gpio_bitnum;
	/*
	 * This is used for all features that depend on step count:
	 * step count, distance, speed, calories.
	 */
	bool stepcnt_enabled;
	u16 stepcnt;
	u8 activity;
	s64 timestamp;
};

static u8 mma9553_get_bits(u16 val, u16 mask)
{
	return (val & mask) >> (ffs(mask) - 1);
}

static u16 mma9553_set_bits(u16 current_val, u16 val, u16 mask)
{
	return (current_val & ~mask) | (val << (ffs(mask) - 1));
}

static enum iio_modifier mma9553_activity_to_mod(enum activity_level activity)
{
	switch (activity) {
	case ACTIVITY_RUNNING:
		return IIO_MOD_RUNNING;
	case ACTIVITY_JOGGING:
		return IIO_MOD_JOGGING;
	case ACTIVITY_WALKING:
		return IIO_MOD_WALKING;
	case ACTIVITY_REST:
		return IIO_MOD_STILL;
	case ACTIVITY_UNKNOWN:
	default:
		return IIO_NO_MOD;
	}
}

static void mma9553_init_events(struct mma9553_data *data)
{
	int i;

	data->num_events = MMA9553_EVENTS_INFO_SIZE;
	for (i = 0; i < data->num_events; i++) {
		data->events[i].info = &mma9553_events_info[i];
		data->events[i].enabled = false;
	}
}

static struct mma9553_event *mma9553_get_event(struct mma9553_data *data,
					       enum iio_chan_type type,
					       enum iio_modifier mod,
					       enum iio_event_direction dir)
{
	int i;

	for (i = 0; i < data->num_events; i++)
		if (data->events[i].info->type == type &&
		    data->events[i].info->mod == mod &&
		    data->events[i].info->dir == dir)
			return &data->events[i];

	return NULL;
}

Annotation

Implementation Notes