linux/drivers/power/supply/twl4030_charger.c

// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * TWL4030/TPS65950 BCI (Battery Charger Interface) driver
 *
 * Copyright (C) 2010 Gražvydas Ignotas <[email protected]>
 *
 * based on twl4030_bci_battery.c by TI
 * Copyright (C) 2008 Texas Instruments, Inc.
 */

#include <linux/init.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/err.h>
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/interrupt.h>
#include <linux/mfd/twl.h>
#include <linux/power_supply.h>
#include <linux/notifier.h>
#include <linux/usb/otg.h>
#include <linux/iio/consumer.h>

#define TWL4030_BCIMDEN
#define TWL4030_BCIMDKEY
#define TWL4030_BCIMSTATEC
#define TWL4030_BCIICHG
#define TWL4030_BCIVAC
#define TWL4030_BCIVBUS
#define TWL4030_BCIMFSTS3
#define TWL4030_BCIMFSTS4
#define TWL4030_BCICTL1
#define TWL4030_BB_CFG
#define TWL4030_BCIIREF1
#define TWL4030_BCIIREF2
#define TWL4030_BCIMFKEY
#define TWL4030_BCIMFEN3
#define TWL4030_BCIMFTH8
#define TWL4030_BCIMFTH9
#define TWL4030_BCIWDKEY

#define TWL4030_BCIMFSTS1

#define TWL4030_BCIAUTOWEN
#define TWL4030_CONFIG_DONE
#define TWL4030_CVENAC
#define TWL4030_BCIAUTOUSB
#define TWL4030_BCIAUTOAC
#define TWL4030_CGAIN
#define TWL4030_USBFASTMCHG
#define TWL4030_STS_VBUS
#define TWL4030_STS_USB_ID
#define TWL4030_BBCHEN
#define TWL4030_BBSEL_MASK
#define TWL4030_BBSEL_2V5
#define TWL4030_BBSEL_3V0
#define TWL4030_BBSEL_3V1
#define TWL4030_BBSEL_3V2
#define TWL4030_BBISEL_MASK
#define TWL4030_BBISEL_25uA
#define TWL4030_BBISEL_150uA
#define TWL4030_BBISEL_500uA
#define TWL4030_BBISEL_1000uA

#define TWL4030_BATSTSPCHG
#define TWL4030_BATSTSMCHG

/* BCI interrupts */
#define TWL4030_WOVF
#define TWL4030_TMOVF
#define TWL4030_ICHGHIGH
#define TWL4030_ICHGLOW
#define TWL4030_ICHGEOC
#define TWL4030_TBATOR2
#define TWL4030_TBATOR1
#define TWL4030_BATSTS

#define TWL4030_VBATLVL
#define TWL4030_VBATOV
#define TWL4030_VBUSOV
#define TWL4030_ACCHGOV

#define TWL4030_MSTATEC_USB
#define TWL4030_MSTATEC_AC
#define TWL4030_MSTATEC_MASK
#define TWL4030_MSTATEC_QUICK1
#define TWL4030_MSTATEC_QUICK7
#define TWL4030_MSTATEC_COMPLETE1
#define TWL4030_MSTATEC_COMPLETE4

/*
 * If AC (Accessory Charger) voltage exceeds 4.5V (MADC 11)
 * then AC is available.
 */
static inline int ac_available(struct iio_channel *channel_vac)
{}

static bool allow_usb;
module_param(allow_usb, bool, 0644);
MODULE_PARM_DESC();

struct twl4030_bci {};

/* strings for 'usb_mode' values */
static const char *modes[] =;

/*
 * clear and set bits on an given register on a given module
 */
static int twl4030_clear_set(u8 mod_no, u8 clear, u8 set, u8 reg)
{}

static int twl4030_bci_read(u8 reg, u8 *val)
{}

static int twl4030_clear_set_boot_bci(u8 clear, u8 set)
{}

static int twl4030bci_read_adc_val(u8 reg)
{}

/*
 * TI provided formulas:
 * CGAIN == 0: ICHG = (BCIICHG * 1.7) / (2^10 - 1) - 0.85
 * CGAIN == 1: ICHG = (BCIICHG * 3.4) / (2^10 - 1) - 1.7
 * Here we use integer approximation of:
 * CGAIN == 0: val * 1.6618 - 0.85 * 1000
 * CGAIN == 1: (val * 1.6618 - 0.85 * 1000) * 2
 */
/*
 * convert twl register value for currents into uA
 */
static int regval2ua(int regval, bool cgain)
{}

/*
 * convert uA currents into twl register value
 */
static int ua2regval(int ua, bool cgain)
{}

static int twl4030_charger_update_current(struct twl4030_bci *bci)
{}

static int twl4030_charger_get_current(void);

static void twl4030_current_worker(struct work_struct *data)
{}

/*
 * Enable/Disable USB Charge functionality.
 */
static int twl4030_charger_enable_usb(struct twl4030_bci *bci, bool enable)
{}

/*
 * Enable/Disable AC Charge funtionality.
 */
static int twl4030_charger_enable_ac(struct twl4030_bci *bci, bool enable)
{}

/*
 * Enable/Disable charging of Backup Battery.
 */
static int twl4030_charger_enable_backup(int uvolt, int uamp)
{}

/*
 * TWL4030 CHG_PRES (AC charger presence) events
 */
static irqreturn_t twl4030_charger_interrupt(int irq, void *arg)
{}

/*
 * TWL4030 BCI monitoring events
 */
static irqreturn_t twl4030_bci_interrupt(int irq, void *arg)
{}

static void twl4030_bci_usb_work(struct work_struct *data)
{}

static int twl4030_bci_usb_ncb(struct notifier_block *nb, unsigned long val,
			       void *priv)
{}

/*
 * sysfs charger enabled store
 */
static ssize_t
twl4030_bci_mode_store(struct device *dev, struct device_attribute *attr,
			  const char *buf, size_t n)
{}

/*
 * sysfs charger enabled show
 */
static ssize_t
twl4030_bci_mode_show(struct device *dev,
			     struct device_attribute *attr, char *buf)
{}
static DEVICE_ATTR(mode, 0644, twl4030_bci_mode_show,
		   twl4030_bci_mode_store);

static int twl4030_charger_get_current(void)
{}

/*
 * Returns the main charge FSM state
 * Or < 0 on failure.
 */
static int twl4030bci_state(struct twl4030_bci *bci)
{}

static int twl4030_bci_state_to_status(int state)
{}

static int twl4030_bci_get_property(struct power_supply *psy,
				    enum power_supply_property psp,
				    union power_supply_propval *val)
{}

static int twl4030_bci_set_property(struct power_supply *psy,
				    enum power_supply_property psp,
				    const union power_supply_propval *val)
{}

static int twl4030_bci_property_is_writeable(struct power_supply *psy,
				      enum power_supply_property psp)
{}

static enum power_supply_property twl4030_charger_props[] =;

#ifdef CONFIG_OF
static const struct twl4030_bci_platform_data *
twl4030_bci_parse_dt(struct device *dev)
{}
#else
static inline const struct twl4030_bci_platform_data *
twl4030_bci_parse_dt(struct device *dev)
{
	return NULL;
}
#endif

static const struct power_supply_desc twl4030_bci_ac_desc =;

static const struct power_supply_desc twl4030_bci_usb_desc =;

static int twl4030_bci_probe(struct platform_device *pdev)
{}

static void twl4030_bci_remove(struct platform_device *pdev)
{}

static const struct of_device_id twl_bci_of_match[] __maybe_unused =;
MODULE_DEVICE_TABLE(of, twl_bci_of_match);

static struct platform_driver twl4030_bci_driver =;
module_platform_driver();

MODULE_AUTHOR();
MODULE_DESCRIPTION();
MODULE_LICENSE();
MODULE_ALIAS();