#include <asm/unaligned.h>
#include <linux/jiffies.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/power_supply.h>
#include <linux/sysfs.h>
#include <linux/types.h>
#include <linux/workqueue.h>
#include <linux/surface_aggregator/device.h>
enum sam_event_cid_bat { … };
enum sam_battery_sta { … };
enum sam_battery_state { … };
enum sam_battery_power_unit { … };
struct spwr_bix { … } __packed;
static_assert(…);
struct spwr_bst { … } __packed;
static_assert(…);
#define SPWR_BIX_REVISION …
#define SPWR_BATTERY_VALUE_UNKNOWN …
SSAM_DEFINE_SYNC_REQUEST_CL_R(ssam_bat_get_sta, __le32, {
.target_category = SSAM_SSH_TC_BAT,
.command_id = 0x01,
});
SSAM_DEFINE_SYNC_REQUEST_CL_R(ssam_bat_get_bix, struct spwr_bix, {
.target_category = SSAM_SSH_TC_BAT,
.command_id = 0x02,
});
SSAM_DEFINE_SYNC_REQUEST_CL_R(ssam_bat_get_bst, struct spwr_bst, {
.target_category = SSAM_SSH_TC_BAT,
.command_id = 0x03,
});
SSAM_DEFINE_SYNC_REQUEST_CL_W(ssam_bat_set_btp, __le32, {
.target_category = SSAM_SSH_TC_BAT,
.command_id = 0x04,
});
struct spwr_psy_properties { … };
struct spwr_battery_device { … };
static unsigned int cache_time = …;
module_param(cache_time, uint, 0644);
MODULE_PARM_DESC(…) …;
#define SPWR_AC_BAT_UPDATE_DELAY …
static bool spwr_battery_present(struct spwr_battery_device *bat)
{ … }
static int spwr_battery_load_sta(struct spwr_battery_device *bat)
{ … }
static int spwr_battery_load_bix(struct spwr_battery_device *bat)
{ … }
static int spwr_battery_load_bst(struct spwr_battery_device *bat)
{ … }
static int spwr_battery_set_alarm_unlocked(struct spwr_battery_device *bat, u32 value)
{ … }
static int spwr_battery_update_bst_unlocked(struct spwr_battery_device *bat, bool cached)
{ … }
static int spwr_battery_update_bst(struct spwr_battery_device *bat, bool cached)
{ … }
static int spwr_battery_update_bix_unlocked(struct spwr_battery_device *bat)
{ … }
static u32 sprw_battery_get_full_cap_safe(struct spwr_battery_device *bat)
{ … }
static bool spwr_battery_is_full(struct spwr_battery_device *bat)
{ … }
static int spwr_battery_recheck_full(struct spwr_battery_device *bat)
{ … }
static int spwr_battery_recheck_status(struct spwr_battery_device *bat)
{ … }
static u32 spwr_notify_bat(struct ssam_event_notifier *nf, const struct ssam_event *event)
{ … }
static void spwr_battery_update_bst_workfn(struct work_struct *work)
{ … }
static void spwr_external_power_changed(struct power_supply *psy)
{ … }
static const enum power_supply_property spwr_battery_props_chg[] = …;
static const enum power_supply_property spwr_battery_props_eng[] = …;
static int spwr_battery_prop_status(struct spwr_battery_device *bat)
{ … }
static int spwr_battery_prop_technology(struct spwr_battery_device *bat)
{ … }
static int spwr_battery_prop_capacity(struct spwr_battery_device *bat)
{ … }
static int spwr_battery_prop_capacity_level(struct spwr_battery_device *bat)
{ … }
static int spwr_battery_get_property(struct power_supply *psy, enum power_supply_property psp,
union power_supply_propval *val)
{ … }
static ssize_t alarm_show(struct device *dev, struct device_attribute *attr, char *buf)
{ … }
static ssize_t alarm_store(struct device *dev, struct device_attribute *attr, const char *buf,
size_t count)
{ … }
static DEVICE_ATTR_RW(alarm);
static struct attribute *spwr_battery_attrs[] = …;
ATTRIBUTE_GROUPS(…);
static void spwr_battery_init(struct spwr_battery_device *bat, struct ssam_device *sdev,
struct ssam_event_registry registry, const char *name)
{ … }
static int spwr_battery_register(struct spwr_battery_device *bat)
{ … }
static int __maybe_unused surface_battery_resume(struct device *dev)
{ … }
static SIMPLE_DEV_PM_OPS(surface_battery_pm_ops, NULL, surface_battery_resume);
static int surface_battery_probe(struct ssam_device *sdev)
{ … }
static void surface_battery_remove(struct ssam_device *sdev)
{ … }
static const struct spwr_psy_properties spwr_psy_props_bat1 = …;
static const struct spwr_psy_properties spwr_psy_props_bat2_sb3 = …;
static const struct ssam_device_id surface_battery_match[] = …;
MODULE_DEVICE_TABLE(ssam, surface_battery_match);
static struct ssam_device_driver surface_battery_driver = …;
module_ssam_device_driver(…) …;
MODULE_AUTHOR(…) …;
MODULE_DESCRIPTION(…) …;
MODULE_LICENSE(…) …;