drivers/power/supply/mt6370-charger.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/mt6370-charger.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/mt6370-charger.c- Extension
.c- Size
- 24656 bytes
- Lines
- 933
- Domain
- Driver Families
- Bucket
- drivers/power
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/bitfield.hlinux/bits.hlinux/devm-helpers.hlinux/gpio/consumer.hlinux/iio/consumer.hlinux/init.hlinux/interrupt.hlinux/kernel.hlinux/linear_range.hlinux/module.hlinux/of.hlinux/platform_device.hlinux/power_supply.hlinux/regmap.hlinux/regulator/driver.hlinux/workqueue.h
Detected Declarations
struct mt6370_privstruct mt6370_chg_fieldenum mt6370_chg_reg_fieldenum mt6370_irqenum mt6370_usb_statusfunction mt6370_chg_field_getfunction mt6370_chg_field_setfunction mt6370_chg_otg_of_parse_cbfunction mt6370_chg_bc12_work_funcfunction mt6370_chg_toggle_cfofunction mt6370_chg_read_adc_chanfunction mt6370_chg_mivr_dwork_funcfunction mt6370_chg_pwr_rdy_checkfunction mt6370_chg_get_onlinefunction mt6370_chg_get_statusfunction mt6370_chg_get_charge_typefunction mt6370_chg_set_onlinefunction mt6370_chg_get_propertyfunction mt6370_chg_set_propertyfunction mt6370_chg_property_is_writeablefunction mt6370_chg_init_rmap_fieldsfunction mt6370_chg_init_settingfunction mt6370_chg_init_otg_regulatorfunction mt6370_chg_init_psyfunction mt6370_attach_i_handlerfunction mt6370_uvp_d_evt_handlerfunction mt6370_mivr_handlerfunction mt6370_chg_init_irqfunction mt6370_chg_probe
Annotated Snippet
struct mt6370_priv {
struct device *dev;
struct iio_channel *iio_adcs;
struct mutex attach_lock;
struct power_supply *psy;
struct regmap *regmap;
struct regmap_field *rmap_fields[F_MAX];
struct regulator_dev *rdev;
struct workqueue_struct *wq;
struct work_struct bc12_work;
struct delayed_work mivr_dwork;
unsigned int irq_nums[MT6370_IRQ_MAX];
int attach;
int psy_usb_type;
bool pwr_rdy;
};
enum mt6370_usb_status {
MT6370_USB_STAT_NO_VBUS = 0,
MT6370_USB_STAT_VBUS_FLOW_IS_UNDER_GOING,
MT6370_USB_STAT_SDP,
MT6370_USB_STAT_SDP_NSTD,
MT6370_USB_STAT_DCP,
MT6370_USB_STAT_CDP,
MT6370_USB_STAT_MAX
};
struct mt6370_chg_field {
const char *name;
const struct linear_range *range;
struct reg_field field;
};
enum {
MT6370_RANGE_F_IAICR = 0,
MT6370_RANGE_F_VOREG,
MT6370_RANGE_F_VMIVR,
MT6370_RANGE_F_ICHG,
MT6370_RANGE_F_IPREC,
MT6370_RANGE_F_IEOC,
MT6370_RANGE_F_MAX
};
static const struct linear_range mt6370_chg_ranges[MT6370_RANGE_F_MAX] = {
LINEAR_RANGE_IDX(MT6370_RANGE_F_IAICR, 100000, 0x0, 0x3F, 50000),
LINEAR_RANGE_IDX(MT6370_RANGE_F_VOREG, 3900000, 0x0, 0x51, 10000),
LINEAR_RANGE_IDX(MT6370_RANGE_F_VMIVR, 3900000, 0x0, 0x5F, 100000),
LINEAR_RANGE_IDX(MT6370_RANGE_F_ICHG, 900000, 0x08, 0x31, 100000),
LINEAR_RANGE_IDX(MT6370_RANGE_F_IPREC, 100000, 0x0, 0x0F, 50000),
LINEAR_RANGE_IDX(MT6370_RANGE_F_IEOC, 100000, 0x0, 0x0F, 50000),
};
#define MT6370_CHG_FIELD(_fd, _reg, _lsb, _msb) \
[_fd] = { \
.name = #_fd, \
.range = NULL, \
.field = REG_FIELD(_reg, _lsb, _msb), \
}
#define MT6370_CHG_FIELD_RANGE(_fd, _reg, _lsb, _msb) \
[_fd] = { \
.name = #_fd, \
.range = &mt6370_chg_ranges[MT6370_RANGE_##_fd], \
.field = REG_FIELD(_reg, _lsb, _msb), \
}
static const struct mt6370_chg_field mt6370_chg_fields[F_MAX] = {
MT6370_CHG_FIELD(F_IINLMTSEL, MT6370_REG_CHG_CTRL2, 2, 3),
MT6370_CHG_FIELD(F_CFO_EN, MT6370_REG_CHG_CTRL2, 1, 1),
MT6370_CHG_FIELD(F_CHG_EN, MT6370_REG_CHG_CTRL2, 0, 0),
MT6370_CHG_FIELD_RANGE(F_IAICR, MT6370_REG_CHG_CTRL3, 2, 7),
MT6370_CHG_FIELD(F_AICR_EN, MT6370_REG_CHG_CTRL3, 1, 1),
MT6370_CHG_FIELD(F_ILIM_EN, MT6370_REG_CHG_CTRL3, 0, 0),
MT6370_CHG_FIELD_RANGE(F_VOREG, MT6370_REG_CHG_CTRL4, 1, 7),
MT6370_CHG_FIELD_RANGE(F_VMIVR, MT6370_REG_CHG_CTRL6, 1, 7),
MT6370_CHG_FIELD_RANGE(F_ICHG, MT6370_REG_CHG_CTRL7, 2, 7),
MT6370_CHG_FIELD_RANGE(F_IPREC, MT6370_REG_CHG_CTRL8, 0, 3),
MT6370_CHG_FIELD_RANGE(F_IEOC, MT6370_REG_CHG_CTRL9, 4, 7),
MT6370_CHG_FIELD(F_USBCHGEN, MT6370_REG_DEVICE_TYPE, 7, 7),
MT6370_CHG_FIELD(F_USB_STAT, MT6370_REG_USB_STATUS1, 4, 6),
MT6370_CHG_FIELD(F_CHGDET, MT6370_REG_USB_STATUS1, 3, 3),
MT6370_CHG_FIELD(F_CHG_STAT, MT6370_REG_CHG_STAT, 6, 7),
MT6370_CHG_FIELD(F_BOOST_STAT, MT6370_REG_CHG_STAT, 3, 3),
MT6370_CHG_FIELD(F_VBAT_LVL, MT6370_REG_CHG_STAT, 5, 5),
MT6370_CHG_FIELD(F_FL_STROBE, MT6370_REG_FLED_EN, 2, 2),
MT6370_CHG_FIELD(F_CHG_MIVR_STAT, MT6370_REG_CHG_STAT1, 6, 6),
MT6370_CHG_FIELD(F_UVP_D_STAT, MT6370_REG_OVPCTRL_STAT, 4, 4),
};
static inline int mt6370_chg_field_get(struct mt6370_priv *priv,
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/bits.h`, `linux/devm-helpers.h`, `linux/gpio/consumer.h`, `linux/iio/consumer.h`, `linux/init.h`, `linux/interrupt.h`, `linux/kernel.h`.
- Detected declarations: `struct mt6370_priv`, `struct mt6370_chg_field`, `enum mt6370_chg_reg_field`, `enum mt6370_irq`, `enum mt6370_usb_status`, `function mt6370_chg_field_get`, `function mt6370_chg_field_set`, `function mt6370_chg_otg_of_parse_cb`, `function mt6370_chg_bc12_work_func`, `function mt6370_chg_toggle_cfo`.
- Atlas domain: Driver Families / drivers/power.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.