drivers/auxdisplay/max6959.c

Source file repositories/reference/linux-study-clean/drivers/auxdisplay/max6959.c

File Facts

System
Linux kernel
Corpus path
drivers/auxdisplay/max6959.c
Extension
.c
Size
4843 bytes
Lines
192
Domain
Driver Families
Bucket
drivers/auxdisplay
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 max6959_priv {
	struct linedisp linedisp;
	struct delayed_work work;
	struct regmap *regmap;
};

static void max6959_disp_update(struct work_struct *work)
{
	struct max6959_priv *priv = container_of(work, struct max6959_priv, work.work);
	struct linedisp *linedisp = &priv->linedisp;
	struct linedisp_map *map = linedisp->map;
	char *s = linedisp->buf;
	u8 buf[4];

	/* Map segments according to datasheet */
	buf[0] = bitrev8(map_to_seg7(&map->map.seg7, *s++)) >> 1;
	buf[1] = bitrev8(map_to_seg7(&map->map.seg7, *s++)) >> 1;
	buf[2] = bitrev8(map_to_seg7(&map->map.seg7, *s++)) >> 1;
	buf[3] = bitrev8(map_to_seg7(&map->map.seg7, *s++)) >> 1;

	regmap_bulk_write(priv->regmap, REG_DIGIT(0), buf, ARRAY_SIZE(buf));
}

static int max6959_linedisp_get_map_type(struct linedisp *linedisp)
{
	struct max6959_priv *priv = container_of(linedisp, struct max6959_priv, linedisp);

	INIT_DELAYED_WORK(&priv->work, max6959_disp_update);
	return LINEDISP_MAP_SEG7;
}

static void max6959_linedisp_update(struct linedisp *linedisp)
{
	struct max6959_priv *priv = container_of(linedisp, struct max6959_priv, linedisp);

	schedule_delayed_work(&priv->work, 0);
}

static const struct linedisp_ops max6959_linedisp_ops = {
	.get_map_type = max6959_linedisp_get_map_type,
	.update = max6959_linedisp_update,
};

static int max6959_enable(struct max6959_priv *priv, bool enable)
{
	return regmap_assign_bits(priv->regmap, REG_CONFIGURATION, REG_CONFIGURATION_S_BIT, enable);
}

static void max6959_power_off(void *priv)
{
	max6959_enable(priv, false);
}

static int max6959_power_on(struct max6959_priv *priv)
{
	struct device *dev = regmap_get_device(priv->regmap);
	int ret;

	ret = max6959_enable(priv, true);
	if (ret)
		return ret;

	return devm_add_action_or_reset(dev, max6959_power_off, priv);
}

static const struct regmap_config max6959_regmap_config = {
	.reg_bits = 8,
	.val_bits = 8,

	.max_register = REG_MAX,
	.cache_type = REGCACHE_MAPLE,
};

static int max6959_i2c_probe(struct i2c_client *client)
{
	struct device *dev = &client->dev;
	struct max6959_priv *priv;
	int ret;

	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
	if (!priv)
		return -ENOMEM;

	priv->regmap = devm_regmap_init_i2c(client, &max6959_regmap_config);
	if (IS_ERR(priv->regmap))
		return PTR_ERR(priv->regmap);

	ret = max6959_power_on(priv);
	if (ret)
		return ret;

Annotation

Implementation Notes