drivers/power/supply/isp1704_charger.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/isp1704_charger.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/isp1704_charger.c- Extension
.c- Size
- 12938 bytes
- Lines
- 513
- 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.
- 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/kernel.hlinux/module.hlinux/err.hlinux/init.hlinux/types.hlinux/device.hlinux/sysfs.hlinux/platform_device.hlinux/power_supply.hlinux/delay.hlinux/of.hlinux/gpio/consumer.hlinux/usb/otg.hlinux/usb/ulpi.hlinux/usb/ch9.hlinux/usb/gadget.h
Detected Declarations
struct isp1704_chargerfunction isp1704_readfunction isp1704_writefunction isp1704_charger_set_powerfunction DCPfunction isp1704_charger_verifyfunction isp1704_charger_detectfunction isp1704_charger_detect_dcpfunction isp1704_charger_workfunction isp1704_notifier_callfunction isp1704_charger_get_propertyfunction isp1704_test_ulpifunction isp1704_charger_probefunction isp1704_charger_remove
Annotated Snippet
struct isp1704_charger {
struct device *dev;
struct power_supply *psy;
struct power_supply_desc psy_desc;
struct gpio_desc *enable_gpio;
struct usb_phy *phy;
struct notifier_block nb;
struct work_struct work;
/* properties */
char model[8];
unsigned present:1;
unsigned online:1;
unsigned current_max;
};
static inline int isp1704_read(struct isp1704_charger *isp, u32 reg)
{
return usb_phy_io_read(isp->phy, reg);
}
static inline int isp1704_write(struct isp1704_charger *isp, u32 reg, u32 val)
{
return usb_phy_io_write(isp->phy, val, reg);
}
static void isp1704_charger_set_power(struct isp1704_charger *isp, bool on)
{
gpiod_set_value(isp->enable_gpio, on);
}
/*
* Determine is the charging port DCP (dedicated charger) or CDP (Host/HUB
* chargers).
*
* REVISIT: The method is defined in Battery Charging Specification and is
* applicable to any ULPI transceiver. Nothing isp170x specific here.
*/
static inline int isp1704_charger_type(struct isp1704_charger *isp)
{
u8 reg;
u8 func_ctrl;
u8 otg_ctrl;
int type = POWER_SUPPLY_TYPE_USB_DCP;
func_ctrl = isp1704_read(isp, ULPI_FUNC_CTRL);
otg_ctrl = isp1704_read(isp, ULPI_OTG_CTRL);
/* disable pulldowns */
reg = ULPI_OTG_CTRL_DM_PULLDOWN | ULPI_OTG_CTRL_DP_PULLDOWN;
isp1704_write(isp, ULPI_CLR(ULPI_OTG_CTRL), reg);
/* full speed */
isp1704_write(isp, ULPI_CLR(ULPI_FUNC_CTRL),
ULPI_FUNC_CTRL_XCVRSEL_MASK);
isp1704_write(isp, ULPI_SET(ULPI_FUNC_CTRL),
ULPI_FUNC_CTRL_FULL_SPEED);
/* Enable strong pull-up on DP (1.5K) and reset */
reg = ULPI_FUNC_CTRL_TERMSELECT | ULPI_FUNC_CTRL_RESET;
isp1704_write(isp, ULPI_SET(ULPI_FUNC_CTRL), reg);
usleep_range(1000, 2000);
reg = isp1704_read(isp, ULPI_DEBUG);
if ((reg & 3) != 3)
type = POWER_SUPPLY_TYPE_USB_CDP;
/* recover original state */
isp1704_write(isp, ULPI_FUNC_CTRL, func_ctrl);
isp1704_write(isp, ULPI_OTG_CTRL, otg_ctrl);
return type;
}
/*
* ISP1704 detects PS/2 adapters as charger. To make sure the detected charger
* is actually a dedicated charger, the following steps need to be taken.
*/
static inline int isp1704_charger_verify(struct isp1704_charger *isp)
{
int ret = 0;
u8 r;
/* Reset the transceiver */
r = isp1704_read(isp, ULPI_FUNC_CTRL);
r |= ULPI_FUNC_CTRL_RESET;
isp1704_write(isp, ULPI_FUNC_CTRL, r);
usleep_range(1000, 2000);
/* Set normal mode */
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/err.h`, `linux/init.h`, `linux/types.h`, `linux/device.h`, `linux/sysfs.h`, `linux/platform_device.h`.
- Detected declarations: `struct isp1704_charger`, `function isp1704_read`, `function isp1704_write`, `function isp1704_charger_set_power`, `function DCP`, `function isp1704_charger_verify`, `function isp1704_charger_detect`, `function isp1704_charger_detect_dcp`, `function isp1704_charger_work`, `function isp1704_notifier_call`.
- 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.
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.