drivers/power/supply/wm8350_power.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/wm8350_power.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/wm8350_power.c- Extension
.c- Size
- 16301 bytes
- Lines
- 591
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/err.hlinux/platform_device.hlinux/power_supply.hlinux/mfd/wm8350/supply.hlinux/mfd/wm8350/core.hlinux/mfd/wm8350/comparator.h
Detected Declarations
function wm8350_read_battery_uvoltsfunction wm8350_read_line_uvoltsfunction wm8350_read_usb_uvoltsfunction wm8350_charge_time_minfunction wm8350_get_suppliesfunction wm8350_charger_configfunction wm8350_batt_statusfunction charger_state_showfunction wm8350_charger_handlerfunction wm8350_ac_get_propfunction wm8350_usb_get_propfunction wm8350_bat_check_healthfunction wm8350_bat_get_charge_typefunction wm8350_bat_get_propertyfunction wm8350_init_chargerfunction free_charger_irqfunction wm8350_power_probefunction wm8350_power_remove
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/*
* Battery driver for wm8350 PMIC
*
* Copyright 2007, 2008 Wolfson Microelectronics PLC.
*
* Based on OLPC Battery Driver
*
* Copyright 2006 David Woodhouse <dwmw2@infradead.org>
*/
#include <linux/module.h>
#include <linux/err.h>
#include <linux/platform_device.h>
#include <linux/power_supply.h>
#include <linux/mfd/wm8350/supply.h>
#include <linux/mfd/wm8350/core.h>
#include <linux/mfd/wm8350/comparator.h>
static int wm8350_read_battery_uvolts(struct wm8350 *wm8350)
{
return wm8350_read_auxadc(wm8350, WM8350_AUXADC_BATT, 0, 0)
* WM8350_AUX_COEFF;
}
static int wm8350_read_line_uvolts(struct wm8350 *wm8350)
{
return wm8350_read_auxadc(wm8350, WM8350_AUXADC_LINE, 0, 0)
* WM8350_AUX_COEFF;
}
static int wm8350_read_usb_uvolts(struct wm8350 *wm8350)
{
return wm8350_read_auxadc(wm8350, WM8350_AUXADC_USB, 0, 0)
* WM8350_AUX_COEFF;
}
#define WM8350_BATT_SUPPLY 1
#define WM8350_USB_SUPPLY 2
#define WM8350_LINE_SUPPLY 4
static inline int wm8350_charge_time_min(struct wm8350 *wm8350, int min)
{
if (!wm8350->power.rev_g_coeff)
return (((min - 30) / 15) & 0xf) << 8;
else
return (((min - 30) / 30) & 0xf) << 8;
}
static int wm8350_get_supplies(struct wm8350 *wm8350)
{
u16 sm, ov, co, chrg;
int supplies = 0;
sm = wm8350_reg_read(wm8350, WM8350_STATE_MACHINE_STATUS);
ov = wm8350_reg_read(wm8350, WM8350_MISC_OVERRIDES);
co = wm8350_reg_read(wm8350, WM8350_COMPARATOR_OVERRIDES);
chrg = wm8350_reg_read(wm8350, WM8350_BATTERY_CHARGER_CONTROL_2);
/* USB_SM */
sm = (sm & WM8350_USB_SM_MASK) >> WM8350_USB_SM_SHIFT;
/* CHG_ISEL */
chrg &= WM8350_CHG_ISEL_MASK;
/* If the USB state machine is active then we're using that with or
* without battery, otherwise check for wall supply */
if (((sm == WM8350_USB_SM_100_SLV) ||
(sm == WM8350_USB_SM_500_SLV) ||
(sm == WM8350_USB_SM_STDBY_SLV))
&& !(ov & WM8350_USB_LIMIT_OVRDE))
supplies = WM8350_USB_SUPPLY;
else if (((sm == WM8350_USB_SM_100_SLV) ||
(sm == WM8350_USB_SM_500_SLV) ||
(sm == WM8350_USB_SM_STDBY_SLV))
&& (ov & WM8350_USB_LIMIT_OVRDE) && (chrg == 0))
supplies = WM8350_USB_SUPPLY | WM8350_BATT_SUPPLY;
else if (co & WM8350_WALL_FB_OVRDE)
supplies = WM8350_LINE_SUPPLY;
else
supplies = WM8350_BATT_SUPPLY;
return supplies;
}
static int wm8350_charger_config(struct wm8350 *wm8350,
struct wm8350_charger_policy *policy)
{
u16 reg, eoc_mA, fast_limit_mA;
Annotation
- Immediate include surface: `linux/module.h`, `linux/err.h`, `linux/platform_device.h`, `linux/power_supply.h`, `linux/mfd/wm8350/supply.h`, `linux/mfd/wm8350/core.h`, `linux/mfd/wm8350/comparator.h`.
- Detected declarations: `function wm8350_read_battery_uvolts`, `function wm8350_read_line_uvolts`, `function wm8350_read_usb_uvolts`, `function wm8350_charge_time_min`, `function wm8350_get_supplies`, `function wm8350_charger_config`, `function wm8350_batt_status`, `function charger_state_show`, `function wm8350_charger_handler`, `function wm8350_ac_get_prop`.
- Atlas domain: Driver Families / drivers/power.
- Implementation status: source implementation candidate.
- 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.