drivers/extcon/extcon-lc824206xa.c

Source file repositories/reference/linux-study-clean/drivers/extcon/extcon-lc824206xa.c

File Facts

System
Linux kernel
Corpus path
drivers/extcon/extcon-lc824206xa.c
Extension
.c
Size
14004 bytes
Lines
496
Domain
Driver Families
Bucket
drivers/extcon
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 lc824206xa_data {
	struct work_struct work;
	struct i2c_client *client;
	struct extcon_dev *edev;
	struct power_supply *psy;
	struct regulator *vbus_boost;
	unsigned int usb_type;
	unsigned int cable;
	unsigned int previous_cable;
	u8 switch_control;
	u8 previous_switch_control;
	bool vbus_ok;
	bool vbus_boost_enabled;
	bool fastcharge_over_miclr;
};

static const unsigned int lc824206xa_cables[] = {
	EXTCON_USB_HOST,
	EXTCON_CHG_USB_SDP,
	EXTCON_CHG_USB_CDP,
	EXTCON_CHG_USB_DCP,
	EXTCON_CHG_USB_ACA,
	EXTCON_CHG_USB_FAST,
	EXTCON_NONE,
};

/* read/write reg helpers to add error logging to smbus byte functions */
static int lc824206xa_read_reg(struct lc824206xa_data *data, u8 reg)
{
	int ret;

	ret = i2c_smbus_read_byte_data(data->client, reg);
	if (ret < 0)
		dev_err(&data->client->dev, "Error %d reading reg 0x%02x\n", ret, reg);

	return ret;
}

static int lc824206xa_write_reg(struct lc824206xa_data *data, u8 reg, u8 val)
{
	int ret;

	ret = i2c_smbus_write_byte_data(data->client, reg, val);
	if (ret < 0)
		dev_err(&data->client->dev, "Error %d writing reg 0x%02x\n", ret, reg);

	return ret;
}

static int lc824206xa_get_id(struct lc824206xa_data *data)
{
	int ret;

	ret = lc824206xa_write_reg(data, REG_ID_PIN_ADC_CTRL, ID_PIN_ADC_CONTINUOUS);
	if (ret)
		return ret;

	ret = lc824206xa_read_reg(data, REG_ID_PIN_ADC_VALUE);

	lc824206xa_write_reg(data, REG_ID_PIN_ADC_CTRL, ID_PIN_ADC_AUTO);

	return ret;
}

static void lc824206xa_set_vbus_boost(struct lc824206xa_data *data, bool enable)
{
	int ret;

	if (data->vbus_boost_enabled == enable)
		return;

	if (enable)
		ret = regulator_enable(data->vbus_boost);
	else
		ret = regulator_disable(data->vbus_boost);

	if (ret == 0)
		data->vbus_boost_enabled = enable;
	else
		dev_err(&data->client->dev, "Error updating Vbus boost regulator: %d\n", ret);
}

static void lc824206xa_charger_detect(struct lc824206xa_data *data)
{
	int charger_type, ret;

	charger_type = lc824206xa_read_reg(data, REG_CHARGER_TYPE);
	if (charger_type < 0)
		return;

Annotation

Implementation Notes