drivers/staging/greybus/light.c

Source file repositories/reference/linux-study-clean/drivers/staging/greybus/light.c

File Facts

System
Linux kernel
Corpus path
drivers/staging/greybus/light.c
Extension
.c
Size
33384 bytes
Lines
1345
Domain
Driver Families
Bucket
drivers/staging
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 gb_channel {
	u8				id;
	u32				flags;
	u32				color;
	char				*color_name;
	u8				fade_in;
	u8				fade_out;
	u32				mode;
	char				*mode_name;
	struct attribute		**attrs;
	struct attribute_group		*attr_group;
	const struct attribute_group	**attr_groups;
	struct led_classdev		*led;
	struct led_classdev_flash	fled;
	struct led_flash_setting	intensity_uA;
	struct led_flash_setting	timeout_us;
	struct gb_light			*light;
	bool				is_registered;
	bool				releasing;
	bool				strobe_state;
	bool				active;
	struct mutex			lock;
};

struct gb_light {
	u8			id;
	char			*name;
	struct gb_lights	*glights;
	u32			flags;
	u8			channels_count;
	struct gb_channel	*channels;
	bool			has_flash;
	bool			ready;
#if IS_REACHABLE(CONFIG_V4L2_FLASH_LED_CLASS)
	struct v4l2_flash	*v4l2_flash;
	struct v4l2_flash	*v4l2_flash_ind;
#endif
};

struct gb_lights {
	struct gb_connection	*connection;
	u8			lights_count;
	struct gb_light		*lights;
	struct mutex		lights_lock;
};

static void gb_lights_channel_free(struct gb_channel *channel);

static struct gb_connection *get_conn_from_channel(struct gb_channel *channel)
{
	return channel->light->glights->connection;
}

static struct gb_connection *get_conn_from_light(struct gb_light *light)
{
	return light->glights->connection;
}

static bool is_channel_flash(struct gb_channel *channel)
{
	return !!(channel->mode & (GB_CHANNEL_MODE_FLASH | GB_CHANNEL_MODE_TORCH
				   | GB_CHANNEL_MODE_INDICATOR));
}

static struct gb_channel *get_channel_from_cdev(struct led_classdev *cdev)
{
	struct led_classdev_flash *fled_cdev = lcdev_to_flcdev(cdev);

	return container_of(fled_cdev, struct gb_channel, fled);
}

static struct led_classdev *get_channel_cdev(struct gb_channel *channel)
{
	return &channel->fled.led_cdev;
}

static struct gb_channel *get_channel_from_mode(struct gb_light *light,
						u32 mode)
{
	struct gb_channel *channel;
	int i;

	for (i = 0; i < light->channels_count; i++) {
		channel = &light->channels[i];
		if (channel->mode == mode)
			return channel;
	}
	return NULL;
}

Annotation

Implementation Notes