1
0
Files
kernel-49/drivers/extcon/extcon-max8997.c
Greg Kroah-Hartman e3c1be14a2 Merge 4.9.276 into android-4.9-q
Changes in 4.9.276
	ALSA: usb-audio: fix rate on Ozone Z90 USB headset
	media: dvb-usb: fix wrong definition
	Input: usbtouchscreen - fix control-request directions
	net: can: ems_usb: fix use-after-free in ems_usb_disconnect()
	usb: gadget: eem: fix echo command packet response issue
	USB: cdc-acm: blacklist Heimann USB Appset device
	ntfs: fix validity check for file name attribute
	iov_iter_fault_in_readable() should do nothing in xarray case
	Input: joydev - prevent use of not validated data in JSIOCSBTNMAP ioctl
	ARM: dts: at91: sama5d4: fix pinctrl muxing
	btrfs: clear defrag status of a root if starting transaction fails
	ext4: fix kernel infoleak via ext4_extent_header
	ext4: correct the cache_nr in tracepoint ext4_es_shrink_exit
	ext4: remove check for zero nr_to_scan in ext4_es_scan()
	ext4: fix avefreec in find_group_orlov
	SUNRPC: Fix the batch tasks count wraparound.
	SUNRPC: Should wake up the privileged task firstly.
	s390/cio: dont call css_wait_for_slow_path() inside a lock
	iio: ltr501: mark register holding upper 8 bits of ALS_DATA{0,1} and PS_DATA as volatile, too
	iio: ltr501: ltr559: fix initialization of LTR501_ALS_CONTR
	iio: ltr501: ltr501_read_ps(): add missing endianness conversion
	serial: sh-sci: Stop dmaengine transfer in sci_stop_tx()
	serial_cs: Add Option International GSM-Ready 56K/ISDN modem
	serial_cs: remove wrong GLOBETROTTER.cis entry
	ath9k: Fix kernel NULL pointer dereference during ath_reset_internal()
	ssb: sdio: Don't overwrite const buffer if block_write fails
	seq_buf: Make trace_seq_putmem_hex() support data longer than 8
	fuse: check connected before queueing on fpq->io
	spi: spi-loopback-test: Fix 'tx_buf' might be 'rx_buf'
	spi: spi-topcliff-pch: Fix potential double free in pch_spi_process_messages()
	spi: omap-100k: Fix the length judgment problem
	crypto: nx - add missing MODULE_DEVICE_TABLE
	media: cpia2: fix memory leak in cpia2_usb_probe
	media: cobalt: fix race condition in setting HPD
	media: pvrusb2: fix warning in pvr2_i2c_core_done
	crypto: qat - check return code of qat_hal_rd_rel_reg()
	crypto: qat - remove unused macro in FW loader
	media: v4l2-core: Avoid the dangling pointer in v4l2_fh_release
	media: bt8xx: Fix a missing check bug in bt878_probe
	media: st-hva: Fix potential NULL pointer dereferences
	mmc: via-sdmmc: add a check against NULL pointer dereference
	crypto: shash - avoid comparing pointers to exported functions under CFI
	media: dvb_net: avoid speculation from net slot
	media: siano: fix device register error path
	btrfs: abort transaction if we fail to update the delayed inode
	btrfs: disable build on platforms having page size 256K
	regulator: da9052: Ensure enough delay time for .set_voltage_time_sel
	ACPI: processor idle: Fix up C-state latency if not ordered
	block_dump: remove block_dump feature in mark_inode_dirty()
	fs: dlm: cancel work sync othercon
	random32: Fix implicit truncation warning in prandom_seed_state()
	fs: dlm: fix memory leak when fenced
	ACPI: bus: Call kobject_put() in acpi_init() error path
	platform/x86: toshiba_acpi: Fix missing error code in toshiba_acpi_setup_keyboard()
	ACPI: tables: Add custom DSDT file as makefile prerequisite
	ia64: mca_drv: fix incorrect array size calculation
	media: s5p_cec: decrement usage count if disabled
	crypto: ixp4xx - dma_unmap the correct address
	crypto: ux500 - Fix error return code in hash_hw_final()
	sata_highbank: fix deferred probing
	pata_rb532_cf: fix deferred probing
	media: I2C: change 'RST' to "RSET" to fix multiple build errors
	pata_octeon_cf: avoid WARN_ON() in ata_host_activate()
	pata_ep93xx: fix deferred probing
	media: tc358743: Fix error return code in tc358743_probe_of()
	media: siano: Fix out-of-bounds warnings in smscore_load_firmware_family2()
	mmc: usdhi6rol0: fix error return code in usdhi6_probe()
	media: s5p-g2d: Fix a memory leak on ctx->fh.m2m_ctx
	hwmon: (max31722) Remove non-standard ACPI device IDs
	hwmon: (max31790) Fix fan speed reporting for fan7..12
	spi: spi-sun6i: Fix chipselect/clock bug
	crypto: nx - Fix RCU warning in nx842_OF_upd_status
	ACPI: sysfs: Fix a buffer overrun problem with description_show()
	ocfs2: fix snprintf() checking
	net: pch_gbe: Propagate error from devm_gpio_request_one()
	ehea: fix error return code in ehea_restart_qps()
	RDMA/rxe: Fix failure during driver load
	drm: qxl: ensure surf.data is ininitialized
	wireless: carl9170: fix LEDS build errors & warnings
	brcmsmac: mac80211_if: Fix a resource leak in an error handling path
	ath10k: Fix an error code in ath10k_add_interface()
	netlabel: Fix memory leak in netlbl_mgmt_add_common
	netfilter: nft_exthdr: check for IPv6 packet before further processing
	net: ethernet: aeroflex: fix UAF in greth_of_remove
	net: ethernet: ezchip: fix UAF in nps_enet_remove
	net: ethernet: ezchip: fix error handling
	vxlan: add missing rcu_read_lock() in neigh_reduce()
	i40e: Fix error handling in i40e_vsi_open
	Bluetooth: mgmt: Fix slab-out-of-bounds in tlv_data_is_valid
	writeback: fix obtain a reference to a freeing memcg css
	net: sched: fix warning in tcindex_alloc_perfect_hash
	tty: nozomi: Fix a resource leak in an error handling function
	iio: adis_buffer: do not return ints in irq handlers
	iio: accel: bma180: Fix buffer alignment in iio_push_to_buffers_with_timestamp()
	iio: accel: bma220: Fix buffer alignment in iio_push_to_buffers_with_timestamp()
	iio: accel: kxcjk-1013: Fix buffer alignment in iio_push_to_buffers_with_timestamp()
	iio: accel: stk8312: Fix buffer alignment in iio_push_to_buffers_with_timestamp()
	iio: accel: stk8ba50: Fix buffer alignment in iio_push_to_buffers_with_timestamp()
	iio: adc: ti-ads1015: Fix buffer alignment in iio_push_to_buffers_with_timestamp()
	iio: adc: vf610: Fix buffer alignment in iio_push_to_buffers_with_timestamp()
	iio: gyro: bmg160: Fix buffer alignment in iio_push_to_buffers_with_timestamp()
	iio: humidity: am2315: Fix buffer alignment in iio_push_to_buffers_with_timestamp()
	iio: prox: pulsed-light: Fix buffer alignment in iio_push_to_buffers_with_timestamp()
	iio: light: isl29125: Fix buffer alignment in iio_push_to_buffers_with_timestamp()
	iio: light: tcs3414: Fix buffer alignment in iio_push_to_buffers_with_timestamp()
	Input: hil_kbd - fix error return code in hil_dev_connect()
	char: pcmcia: error out if 'num_bytes_read' is greater than 4 in set_protocol()
	tty: nozomi: Fix the error handling path of 'nozomi_card_init()'
	scsi: FlashPoint: Rename si_flags field
	s390: appldata depends on PROC_SYSCTL
	staging: gdm724x: check for buffer overflow in gdm_lte_multi_sdu_pkt()
	staging: gdm724x: check for overflow in gdm_lte_netif_rx()
	of: Fix truncation of memory sizes on 32-bit platforms
	scsi: mpt3sas: Fix error return value in _scsih_expander_add()
	phy: ti: dm816x: Fix the error handling path in 'dm816x_usb_phy_probe()
	extcon: sm5502: Drop invalid register write in sm5502_reg_data
	extcon: max8997: Add missing modalias string
	configfs: fix memleak in configfs_release_bin_file
	leds: ktd2692: Fix an error handling path
	mm/huge_memory.c: don't discard hugepage if other processes are mapping it
	selftests/vm/pkeys: fix alloc_random_pkey() to make it really, really random
	mmc: vub3000: fix control-request direction
	scsi: core: Retry I/O for Notify (Enable Spinup) Required error
	net: pch_gbe: Use proper accessors to BE data in pch_ptp_match()
	hugetlb: clear huge pte during flush function on mips platform
	atm: iphase: fix possible use-after-free in ia_module_exit()
	mISDN: fix possible use-after-free in HFC_cleanup()
	atm: nicstar: Fix possible use-after-free in nicstar_cleanup()
	net: Treat __napi_schedule_irqoff() as __napi_schedule() on PREEMPT_RT
	reiserfs: add check for invalid 1st journal block
	drm/virtio: Fix double free on probe failure
	udf: Fix NULL pointer dereference in udf_symlink function
	e100: handle eeprom as little endian
	clk: tegra: Ensure that PLLU configuration is applied properly
	ipv6: use prandom_u32() for ID generation
	RDMA/cxgb4: Fix missing error code in create_qp()
	dm space maps: don't reset space map allocation cursor when committing
	net: micrel: check return value after calling platform_get_resource()
	fjes: check return value after calling platform_get_resource()
	selinux: use __GFP_NOWARN with GFP_NOWAIT in the AVC
	xfrm: Fix error reporting in xfrm_state_construct.
	wlcore/wl12xx: Fix wl12xx get_mac error if device is in ELP
	wl1251: Fix possible buffer overflow in wl1251_cmd_scan
	cw1200: add missing MODULE_DEVICE_TABLE
	MIPS: add PMD table accounting into MIPS'pmd_alloc_one
	atm: nicstar: use 'dma_free_coherent' instead of 'kfree'
	atm: nicstar: register the interrupt handler in the right place
	RDMA/rxe: Don't overwrite errno from ib_umem_get()
	sfc: avoid double pci_remove of VFs
	sfc: error code if SRIOV cannot be disabled
	wireless: wext-spy: Fix out-of-bounds warning
	RDMA/cma: Fix rdma_resolve_route() memory leak
	Bluetooth: Fix the HCI to MGMT status conversion table
	Bluetooth: Shutdown controller after workqueues are flushed or cancelled
	Bluetooth: btusb: fix bt fiwmare downloading failure issue for qca btsoc.
	sctp: add size validation when walking chunks
	fuse: reject internal errno
	can: gw: synchronize rcu operations before removing gw job entry
	can: bcm: delay release of struct bcm_op after synchronize_rcu()
	mac80211: fix memory corruption in EAPOL handling
	powerpc/barrier: Avoid collision with clang's __lwsync macro
	pinctrl/amd: Add device HID for new AMD GPIO controller
	mmc: sdhci: Fix warning message when accessing RPMB in HS400 mode
	mmc: core: clear flags before allowing to retune
	ata: ahci_sunxi: Disable DIPM
	ASoC: tegra: Set driver_name=tegra for all machine drivers
	qemu_fw_cfg: Make fw_cfg_rev_attr a proper kobj_attribute
	ipmi/watchdog: Stop watchdog timer when the current action is 'none'
	power: supply: ab8500: Fix an old bug
	seq_buf: Fix overflow in seq_buf_putmem_hex()
	ipack/carriers/tpci200: Fix a double free in tpci200_pci_probe
	dm btree remove: assign new_root only when removal succeeds
	media: dtv5100: fix control-request directions
	media: zr364xx: fix memory leak in zr364xx_start_readpipe
	media: gspca/sq905: fix control-request direction
	media: gspca/sunplus: fix zero-length control requests
	media: uvcvideo: Fix pixel format change for Elgato Cam Link 4K
	jfs: fix GPF in diFree
	smackfs: restrict bytes count in smk_set_cipso()
	KVM: x86: Use guest MAXPHYADDR from CPUID.0x8000_0008 iff TDP is enabled
	KVM: X86: Disable hardware breakpoints unconditionally before kvm_x86->run()
	scsi: core: Fix bad pointer dereference when ehandler kthread is invalid
	tracing: Do not reference char * as a string in histograms
	fscrypt: don't ignore minor_hash when hash is 0
	tty: serial: fsl_lpuart: fix the potential risk of division or modulo by zero
	misc/libmasm/module: Fix two use after free in ibmasm_init_one
	Revert "ALSA: bebob/oxfw: fix Kconfig entry for Mackie d.2 Pro"
	scsi: lpfc: Fix "Unexpected timeout" error in direct attach topology
	tty: serial: 8250: serial_cs: Fix a memory leak in error handling path
	fs/jfs: Fix missing error code in lmLogInit()
	scsi: iscsi: Add iscsi_cls_conn refcount helpers
	mfd: da9052/stmpe: Add and modify MODULE_DEVICE_TABLE
	s390/sclp_vt220: fix console name to match device
	ALSA: sb: Fix potential double-free of CSP mixer elements
	powerpc/ps3: Add dma_mask to ps3_dma_region
	gpio: zynq: Check return value of pm_runtime_get_sync
	ALSA: ppc: fix error return code in snd_pmac_probe()
	selftests/powerpc: Fix "no_handler" EBB selftest
	ASoC: soc-core: Fix the error return code in snd_soc_of_parse_audio_routing()
	ALSA: bebob: add support for ToneWeal FW66
	usb: gadget: f_hid: fix endianness issue with descriptors
	usb: gadget: hid: fix error return code in hid_bind()
	powerpc/boot: Fixup device-tree on little endian
	backlight: lm3630a: Fix return code of .update_status() callback
	ALSA: hda: Add IRQ check for platform_get_irq()
	i2c: core: Disable client irq on reboot/shutdown
	lib/decompress_unlz4.c: correctly handle zero-padding around initrds.
	pwm: spear: Don't modify HW state in .remove callback
	power: supply: ab8500: Avoid NULL pointers
	power: reset: gpio-poweroff: add missing MODULE_DEVICE_TABLE
	ARM: 9087/1: kprobes: test-thumb: fix for LLVM_IAS=1
	watchdog: Fix possible use-after-free in wdt_startup()
	watchdog: sc520_wdt: Fix possible use-after-free in wdt_turnoff()
	watchdog: Fix possible use-after-free by calling del_timer_sync()
	x86/fpu: Return proper error codes from user access functions
	orangefs: fix orangefs df output.
	ceph: remove bogus checks and WARN_ONs from ceph_set_page_dirty
	power: supply: charger-manager: add missing MODULE_DEVICE_TABLE
	power: supply: ab8500: add missing MODULE_DEVICE_TABLE
	pwm: tegra: Don't modify HW state in .remove callback
	ACPI: AMBA: Fix resource name in /proc/iomem
	virtio-blk: Fix memory leak among suspend/resume procedure
	virtio_console: Assure used length from device is limited
	PCI/sysfs: Fix dsm_label_utf16s_to_utf8s() buffer overrun
	power: supply: rt5033_battery: Fix device tree enumeration
	um: fix error return code in slip_open()
	um: fix error return code in winch_tramp()
	watchdog: aspeed: fix hardware timeout calculation
	nfs: fix acl memory leak of posix_acl_create()
	ubifs: Set/Clear I_LINKABLE under i_lock for whiteout inode
	x86/fpu: Limit xstate copy size in xstateregs_set()
	ALSA: isa: Fix error return code in snd_cmi8330_probe()
	hexagon: use common DISCARDS macro
	ARM: dts: exynos: fix PWM LED max brightness on Odroid XU/XU3
	ARM: dts: exynos: fix PWM LED max brightness on Odroid XU4
	rtc: fix snprintf() checking in is_rtc_hctosys()
	ARM: dts: r8a7779, marzen: Fix DU clock names
	reset: bail if try_module_get() fails
	memory: fsl_ifc: fix leak of IO mapping on probe failure
	memory: fsl_ifc: fix leak of private memory on probe failure
	ARM: dts: am335x: align ti,pindir-d0-out-d1-in property with dt-shema
	scsi: be2iscsi: Fix an error handling path in beiscsi_dev_probe()
	mips: always link byteswap helpers into decompressor
	mips: disable branch profiling in boot/decompress.o
	MIPS: vdso: Invalid GIC access through VDSO
	seq_file: disallow extremely large seq buffer allocations
	Linux 4.9.276

Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Change-Id: I595c090068eb1b1934b15a0d54394abc38b4b0cc
2021-07-25 20:02:04 +03:00

787 lines
20 KiB
C

/*
* extcon-max8997.c - MAX8997 extcon driver to support MAX8997 MUIC
*
* Copyright (C) 2012 Samsung Electronics
* Donggeun Kim <dg77.kim@samsung.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/i2c.h>
#include <linux/slab.h>
#include <linux/interrupt.h>
#include <linux/err.h>
#include <linux/platform_device.h>
#include <linux/kobject.h>
#include <linux/mfd/max8997.h>
#include <linux/mfd/max8997-private.h>
#include <linux/extcon.h>
#include <linux/irqdomain.h>
#define DEV_NAME "max8997-muic"
#define DELAY_MS_DEFAULT 20000 /* unit: millisecond */
enum max8997_muic_adc_debounce_time {
ADC_DEBOUNCE_TIME_0_5MS = 0, /* 0.5ms */
ADC_DEBOUNCE_TIME_10MS, /* 10ms */
ADC_DEBOUNCE_TIME_25MS, /* 25ms */
ADC_DEBOUNCE_TIME_38_62MS, /* 38.62ms */
};
struct max8997_muic_irq {
unsigned int irq;
const char *name;
unsigned int virq;
};
static struct max8997_muic_irq muic_irqs[] = {
{ MAX8997_MUICIRQ_ADCError, "muic-ADCERROR" },
{ MAX8997_MUICIRQ_ADCLow, "muic-ADCLOW" },
{ MAX8997_MUICIRQ_ADC, "muic-ADC" },
{ MAX8997_MUICIRQ_VBVolt, "muic-VBVOLT" },
{ MAX8997_MUICIRQ_DBChg, "muic-DBCHG" },
{ MAX8997_MUICIRQ_DCDTmr, "muic-DCDTMR" },
{ MAX8997_MUICIRQ_ChgDetRun, "muic-CHGDETRUN" },
{ MAX8997_MUICIRQ_ChgTyp, "muic-CHGTYP" },
{ MAX8997_MUICIRQ_OVP, "muic-OVP" },
};
/* Define supported cable type */
enum max8997_muic_acc_type {
MAX8997_MUIC_ADC_GROUND = 0x0,
MAX8997_MUIC_ADC_MHL, /* MHL*/
MAX8997_MUIC_ADC_REMOTE_S1_BUTTON,
MAX8997_MUIC_ADC_REMOTE_S2_BUTTON,
MAX8997_MUIC_ADC_REMOTE_S3_BUTTON,
MAX8997_MUIC_ADC_REMOTE_S4_BUTTON,
MAX8997_MUIC_ADC_REMOTE_S5_BUTTON,
MAX8997_MUIC_ADC_REMOTE_S6_BUTTON,
MAX8997_MUIC_ADC_REMOTE_S7_BUTTON,
MAX8997_MUIC_ADC_REMOTE_S8_BUTTON,
MAX8997_MUIC_ADC_REMOTE_S9_BUTTON,
MAX8997_MUIC_ADC_REMOTE_S10_BUTTON,
MAX8997_MUIC_ADC_REMOTE_S11_BUTTON,
MAX8997_MUIC_ADC_REMOTE_S12_BUTTON,
MAX8997_MUIC_ADC_RESERVED_ACC_1,
MAX8997_MUIC_ADC_RESERVED_ACC_2,
MAX8997_MUIC_ADC_RESERVED_ACC_3,
MAX8997_MUIC_ADC_RESERVED_ACC_4,
MAX8997_MUIC_ADC_RESERVED_ACC_5,
MAX8997_MUIC_ADC_CEA936_AUDIO,
MAX8997_MUIC_ADC_PHONE_POWERED_DEV,
MAX8997_MUIC_ADC_TTY_CONVERTER,
MAX8997_MUIC_ADC_UART_CABLE,
MAX8997_MUIC_ADC_CEA936A_TYPE1_CHG,
MAX8997_MUIC_ADC_FACTORY_MODE_USB_OFF, /* JIG-USB-OFF */
MAX8997_MUIC_ADC_FACTORY_MODE_USB_ON, /* JIG-USB-ON */
MAX8997_MUIC_ADC_AV_CABLE_NOLOAD, /* DESKDOCK */
MAX8997_MUIC_ADC_CEA936A_TYPE2_CHG,
MAX8997_MUIC_ADC_FACTORY_MODE_UART_OFF, /* JIG-UART */
MAX8997_MUIC_ADC_FACTORY_MODE_UART_ON, /* CARDOCK */
MAX8997_MUIC_ADC_AUDIO_MODE_REMOTE,
MAX8997_MUIC_ADC_OPEN, /* OPEN */
};
enum max8997_muic_cable_group {
MAX8997_CABLE_GROUP_ADC = 0,
MAX8997_CABLE_GROUP_ADC_GND,
MAX8997_CABLE_GROUP_CHG,
MAX8997_CABLE_GROUP_VBVOLT,
};
enum max8997_muic_usb_type {
MAX8997_USB_HOST,
MAX8997_USB_DEVICE,
};
enum max8997_muic_charger_type {
MAX8997_CHARGER_TYPE_NONE = 0,
MAX8997_CHARGER_TYPE_USB,
MAX8997_CHARGER_TYPE_DOWNSTREAM_PORT,
MAX8997_CHARGER_TYPE_DEDICATED_CHG,
MAX8997_CHARGER_TYPE_500MA,
MAX8997_CHARGER_TYPE_1A,
MAX8997_CHARGER_TYPE_DEAD_BATTERY = 7,
};
struct max8997_muic_info {
struct device *dev;
struct i2c_client *muic;
struct extcon_dev *edev;
int prev_cable_type;
int prev_chg_type;
u8 status[2];
int irq;
struct work_struct irq_work;
struct mutex mutex;
struct max8997_muic_platform_data *muic_pdata;
enum max8997_muic_charger_type pre_charger_type;
/*
* Use delayed workqueue to detect cable state and then
* notify cable state to notifiee/platform through uevent.
* After completing the booting of platform, the extcon provider
* driver should notify cable state to upper layer.
*/
struct delayed_work wq_detcable;
/*
* Default usb/uart path whether UART/USB or AUX_UART/AUX_USB
* h/w path of COMP2/COMN1 on CONTROL1 register.
*/
int path_usb;
int path_uart;
};
static const unsigned int max8997_extcon_cable[] = {
EXTCON_USB,
EXTCON_USB_HOST,
EXTCON_CHG_USB_SDP,
EXTCON_CHG_USB_DCP,
EXTCON_CHG_USB_FAST,
EXTCON_CHG_USB_SLOW,
EXTCON_CHG_USB_CDP,
EXTCON_DISP_MHL,
EXTCON_DOCK,
EXTCON_JIG,
EXTCON_NONE,
};
/*
* max8997_muic_set_debounce_time - Set the debounce time of ADC
* @info: the instance including private data of max8997 MUIC
* @time: the debounce time of ADC
*/
static int max8997_muic_set_debounce_time(struct max8997_muic_info *info,
enum max8997_muic_adc_debounce_time time)
{
int ret;
switch (time) {
case ADC_DEBOUNCE_TIME_0_5MS:
case ADC_DEBOUNCE_TIME_10MS:
case ADC_DEBOUNCE_TIME_25MS:
case ADC_DEBOUNCE_TIME_38_62MS:
ret = max8997_update_reg(info->muic,
MAX8997_MUIC_REG_CONTROL3,
time << CONTROL3_ADCDBSET_SHIFT,
CONTROL3_ADCDBSET_MASK);
if (ret) {
dev_err(info->dev, "failed to set ADC debounce time\n");
return ret;
}
break;
default:
dev_err(info->dev, "invalid ADC debounce time\n");
return -EINVAL;
}
return 0;
};
/*
* max8997_muic_set_path - Set hardware line according to attached cable
* @info: the instance including private data of max8997 MUIC
* @value: the path according to attached cable
* @attached: the state of cable (true:attached, false:detached)
*
* The max8997 MUIC device share outside H/W line among a varity of cables,
* so this function set internal path of H/W line according to the type of
* attached cable.
*/
static int max8997_muic_set_path(struct max8997_muic_info *info,
u8 val, bool attached)
{
int ret = 0;
u8 ctrl1, ctrl2 = 0;
if (attached)
ctrl1 = val;
else
ctrl1 = CONTROL1_SW_OPEN;
ret = max8997_update_reg(info->muic,
MAX8997_MUIC_REG_CONTROL1, ctrl1, COMP_SW_MASK);
if (ret < 0) {
dev_err(info->dev, "failed to update MUIC register\n");
return ret;
}
if (attached)
ctrl2 |= CONTROL2_CPEN_MASK; /* LowPwr=0, CPEn=1 */
else
ctrl2 |= CONTROL2_LOWPWR_MASK; /* LowPwr=1, CPEn=0 */
ret = max8997_update_reg(info->muic,
MAX8997_MUIC_REG_CONTROL2, ctrl2,
CONTROL2_LOWPWR_MASK | CONTROL2_CPEN_MASK);
if (ret < 0) {
dev_err(info->dev, "failed to update MUIC register\n");
return ret;
}
dev_info(info->dev,
"CONTROL1 : 0x%02x, CONTROL2 : 0x%02x, state : %s\n",
ctrl1, ctrl2, attached ? "attached" : "detached");
return 0;
}
/*
* max8997_muic_get_cable_type - Return cable type and check cable state
* @info: the instance including private data of max8997 MUIC
* @group: the path according to attached cable
* @attached: store cable state and return
*
* This function check the cable state either attached or detached,
* and then divide precise type of cable according to cable group.
* - MAX8997_CABLE_GROUP_ADC
* - MAX8997_CABLE_GROUP_CHG
*/
static int max8997_muic_get_cable_type(struct max8997_muic_info *info,
enum max8997_muic_cable_group group, bool *attached)
{
int cable_type = 0;
int adc;
int chg_type;
switch (group) {
case MAX8997_CABLE_GROUP_ADC:
/*
* Read ADC value to check cable type and decide cable state
* according to cable type
*/
adc = info->status[0] & STATUS1_ADC_MASK;
adc >>= STATUS1_ADC_SHIFT;
/*
* Check current cable state/cable type and store cable type
* (info->prev_cable_type) for handling cable when cable is
* detached.
*/
if (adc == MAX8997_MUIC_ADC_OPEN) {
*attached = false;
cable_type = info->prev_cable_type;
info->prev_cable_type = MAX8997_MUIC_ADC_OPEN;
} else {
*attached = true;
cable_type = info->prev_cable_type = adc;
}
break;
case MAX8997_CABLE_GROUP_CHG:
/*
* Read charger type to check cable type and decide cable state
* according to type of charger cable.
*/
chg_type = info->status[1] & STATUS2_CHGTYP_MASK;
chg_type >>= STATUS2_CHGTYP_SHIFT;
if (chg_type == MAX8997_CHARGER_TYPE_NONE) {
*attached = false;
cable_type = info->prev_chg_type;
info->prev_chg_type = MAX8997_CHARGER_TYPE_NONE;
} else {
*attached = true;
/*
* Check current cable state/cable type and store cable
* type(info->prev_chg_type) for handling cable when
* charger cable is detached.
*/
cable_type = info->prev_chg_type = chg_type;
}
break;
default:
dev_err(info->dev, "Unknown cable group (%d)\n", group);
cable_type = -EINVAL;
break;
}
return cable_type;
}
static int max8997_muic_handle_usb(struct max8997_muic_info *info,
enum max8997_muic_usb_type usb_type, bool attached)
{
int ret = 0;
ret = max8997_muic_set_path(info, info->path_usb, attached);
if (ret < 0) {
dev_err(info->dev, "failed to update muic register\n");
return ret;
}
switch (usb_type) {
case MAX8997_USB_HOST:
extcon_set_state_sync(info->edev, EXTCON_USB_HOST, attached);
break;
case MAX8997_USB_DEVICE:
extcon_set_state_sync(info->edev, EXTCON_USB, attached);
extcon_set_state_sync(info->edev, EXTCON_CHG_USB_SDP,
attached);
break;
default:
dev_err(info->dev, "failed to detect %s usb cable\n",
attached ? "attached" : "detached");
return -EINVAL;
}
return 0;
}
static int max8997_muic_handle_dock(struct max8997_muic_info *info,
int cable_type, bool attached)
{
int ret = 0;
ret = max8997_muic_set_path(info, CONTROL1_SW_AUDIO, attached);
if (ret) {
dev_err(info->dev, "failed to update muic register\n");
return ret;
}
switch (cable_type) {
case MAX8997_MUIC_ADC_AV_CABLE_NOLOAD:
case MAX8997_MUIC_ADC_FACTORY_MODE_UART_ON:
extcon_set_state_sync(info->edev, EXTCON_DOCK, attached);
break;
default:
dev_err(info->dev, "failed to detect %s dock device\n",
attached ? "attached" : "detached");
return -EINVAL;
}
return 0;
}
static int max8997_muic_handle_jig_uart(struct max8997_muic_info *info,
bool attached)
{
int ret = 0;
/* switch to UART */
ret = max8997_muic_set_path(info, info->path_uart, attached);
if (ret) {
dev_err(info->dev, "failed to update muic register\n");
return ret;
}
extcon_set_state_sync(info->edev, EXTCON_JIG, attached);
return 0;
}
static int max8997_muic_adc_handler(struct max8997_muic_info *info)
{
int cable_type;
bool attached;
int ret = 0;
/* Check cable state which is either detached or attached */
cable_type = max8997_muic_get_cable_type(info,
MAX8997_CABLE_GROUP_ADC, &attached);
switch (cable_type) {
case MAX8997_MUIC_ADC_GROUND:
ret = max8997_muic_handle_usb(info, MAX8997_USB_HOST, attached);
if (ret < 0)
return ret;
break;
case MAX8997_MUIC_ADC_MHL:
extcon_set_state_sync(info->edev, EXTCON_DISP_MHL, attached);
break;
case MAX8997_MUIC_ADC_FACTORY_MODE_USB_OFF:
case MAX8997_MUIC_ADC_FACTORY_MODE_USB_ON:
ret = max8997_muic_handle_usb(info,
MAX8997_USB_DEVICE, attached);
if (ret < 0)
return ret;
break;
case MAX8997_MUIC_ADC_AV_CABLE_NOLOAD:
case MAX8997_MUIC_ADC_FACTORY_MODE_UART_ON:
ret = max8997_muic_handle_dock(info, cable_type, attached);
if (ret < 0)
return ret;
break;
case MAX8997_MUIC_ADC_FACTORY_MODE_UART_OFF:
ret = max8997_muic_handle_jig_uart(info, attached);
break;
case MAX8997_MUIC_ADC_REMOTE_S1_BUTTON:
case MAX8997_MUIC_ADC_REMOTE_S2_BUTTON:
case MAX8997_MUIC_ADC_REMOTE_S3_BUTTON:
case MAX8997_MUIC_ADC_REMOTE_S4_BUTTON:
case MAX8997_MUIC_ADC_REMOTE_S5_BUTTON:
case MAX8997_MUIC_ADC_REMOTE_S6_BUTTON:
case MAX8997_MUIC_ADC_REMOTE_S7_BUTTON:
case MAX8997_MUIC_ADC_REMOTE_S8_BUTTON:
case MAX8997_MUIC_ADC_REMOTE_S9_BUTTON:
case MAX8997_MUIC_ADC_REMOTE_S10_BUTTON:
case MAX8997_MUIC_ADC_REMOTE_S11_BUTTON:
case MAX8997_MUIC_ADC_REMOTE_S12_BUTTON:
case MAX8997_MUIC_ADC_RESERVED_ACC_1:
case MAX8997_MUIC_ADC_RESERVED_ACC_2:
case MAX8997_MUIC_ADC_RESERVED_ACC_3:
case MAX8997_MUIC_ADC_RESERVED_ACC_4:
case MAX8997_MUIC_ADC_RESERVED_ACC_5:
case MAX8997_MUIC_ADC_CEA936_AUDIO:
case MAX8997_MUIC_ADC_PHONE_POWERED_DEV:
case MAX8997_MUIC_ADC_TTY_CONVERTER:
case MAX8997_MUIC_ADC_UART_CABLE:
case MAX8997_MUIC_ADC_CEA936A_TYPE1_CHG:
case MAX8997_MUIC_ADC_CEA936A_TYPE2_CHG:
case MAX8997_MUIC_ADC_AUDIO_MODE_REMOTE:
/*
* This cable isn't used in general case if it is specially
* needed to detect additional cable, should implement
* proper operation when this cable is attached/detached.
*/
dev_info(info->dev,
"cable is %s but it isn't used (type:0x%x)\n",
attached ? "attached" : "detached", cable_type);
return -EAGAIN;
default:
dev_err(info->dev,
"failed to detect %s unknown cable (type:0x%x)\n",
attached ? "attached" : "detached", cable_type);
return -EINVAL;
}
return 0;
}
static int max8997_muic_chg_handler(struct max8997_muic_info *info)
{
int chg_type;
bool attached;
int adc;
chg_type = max8997_muic_get_cable_type(info,
MAX8997_CABLE_GROUP_CHG, &attached);
switch (chg_type) {
case MAX8997_CHARGER_TYPE_NONE:
break;
case MAX8997_CHARGER_TYPE_USB:
adc = info->status[0] & STATUS1_ADC_MASK;
adc >>= STATUS1_ADC_SHIFT;
if ((adc & STATUS1_ADC_MASK) == MAX8997_MUIC_ADC_OPEN) {
max8997_muic_handle_usb(info,
MAX8997_USB_DEVICE, attached);
}
break;
case MAX8997_CHARGER_TYPE_DOWNSTREAM_PORT:
extcon_set_state_sync(info->edev, EXTCON_CHG_USB_CDP,
attached);
break;
case MAX8997_CHARGER_TYPE_DEDICATED_CHG:
extcon_set_state_sync(info->edev, EXTCON_CHG_USB_DCP,
attached);
break;
case MAX8997_CHARGER_TYPE_500MA:
extcon_set_state_sync(info->edev, EXTCON_CHG_USB_SLOW,
attached);
break;
case MAX8997_CHARGER_TYPE_1A:
extcon_set_state_sync(info->edev, EXTCON_CHG_USB_FAST,
attached);
break;
default:
dev_err(info->dev,
"failed to detect %s unknown chg cable (type:0x%x)\n",
attached ? "attached" : "detached", chg_type);
return -EINVAL;
}
return 0;
}
static void max8997_muic_irq_work(struct work_struct *work)
{
struct max8997_muic_info *info = container_of(work,
struct max8997_muic_info, irq_work);
int irq_type = 0;
int i, ret;
if (!info->edev)
return;
mutex_lock(&info->mutex);
for (i = 0; i < ARRAY_SIZE(muic_irqs); i++)
if (info->irq == muic_irqs[i].virq)
irq_type = muic_irqs[i].irq;
ret = max8997_bulk_read(info->muic, MAX8997_MUIC_REG_STATUS1,
2, info->status);
if (ret) {
dev_err(info->dev, "failed to read muic register\n");
mutex_unlock(&info->mutex);
return;
}
switch (irq_type) {
case MAX8997_MUICIRQ_ADCError:
case MAX8997_MUICIRQ_ADCLow:
case MAX8997_MUICIRQ_ADC:
/* Handle all of cable except for charger cable */
ret = max8997_muic_adc_handler(info);
break;
case MAX8997_MUICIRQ_VBVolt:
case MAX8997_MUICIRQ_DBChg:
case MAX8997_MUICIRQ_DCDTmr:
case MAX8997_MUICIRQ_ChgDetRun:
case MAX8997_MUICIRQ_ChgTyp:
/* Handle charger cable */
ret = max8997_muic_chg_handler(info);
break;
case MAX8997_MUICIRQ_OVP:
break;
default:
dev_info(info->dev, "misc interrupt: irq %d occurred\n",
irq_type);
mutex_unlock(&info->mutex);
return;
}
if (ret < 0)
dev_err(info->dev, "failed to handle MUIC interrupt\n");
mutex_unlock(&info->mutex);
}
static irqreturn_t max8997_muic_irq_handler(int irq, void *data)
{
struct max8997_muic_info *info = data;
dev_dbg(info->dev, "irq:%d\n", irq);
info->irq = irq;
schedule_work(&info->irq_work);
return IRQ_HANDLED;
}
static int max8997_muic_detect_dev(struct max8997_muic_info *info)
{
int ret = 0;
int adc;
int chg_type;
bool attached;
mutex_lock(&info->mutex);
/* Read STATUSx register to detect accessory */
ret = max8997_bulk_read(info->muic,
MAX8997_MUIC_REG_STATUS1, 2, info->status);
if (ret) {
dev_err(info->dev, "failed to read MUIC register\n");
mutex_unlock(&info->mutex);
return ret;
}
adc = max8997_muic_get_cable_type(info, MAX8997_CABLE_GROUP_ADC,
&attached);
if (attached && adc != MAX8997_MUIC_ADC_OPEN) {
ret = max8997_muic_adc_handler(info);
if (ret < 0) {
dev_err(info->dev, "Cannot detect ADC cable\n");
mutex_unlock(&info->mutex);
return ret;
}
}
chg_type = max8997_muic_get_cable_type(info, MAX8997_CABLE_GROUP_CHG,
&attached);
if (attached && chg_type != MAX8997_CHARGER_TYPE_NONE) {
ret = max8997_muic_chg_handler(info);
if (ret < 0) {
dev_err(info->dev, "Cannot detect charger cable\n");
mutex_unlock(&info->mutex);
return ret;
}
}
mutex_unlock(&info->mutex);
return 0;
}
static void max8997_muic_detect_cable_wq(struct work_struct *work)
{
struct max8997_muic_info *info = container_of(to_delayed_work(work),
struct max8997_muic_info, wq_detcable);
int ret;
ret = max8997_muic_detect_dev(info);
if (ret < 0)
dev_err(info->dev, "failed to detect cable type\n");
}
static int max8997_muic_probe(struct platform_device *pdev)
{
struct max8997_dev *max8997 = dev_get_drvdata(pdev->dev.parent);
struct max8997_platform_data *pdata = dev_get_platdata(max8997->dev);
struct max8997_muic_info *info;
int delay_jiffies;
int ret, i;
info = devm_kzalloc(&pdev->dev, sizeof(struct max8997_muic_info),
GFP_KERNEL);
if (!info)
return -ENOMEM;
info->dev = &pdev->dev;
info->muic = max8997->muic;
platform_set_drvdata(pdev, info);
mutex_init(&info->mutex);
INIT_WORK(&info->irq_work, max8997_muic_irq_work);
for (i = 0; i < ARRAY_SIZE(muic_irqs); i++) {
struct max8997_muic_irq *muic_irq = &muic_irqs[i];
unsigned int virq = 0;
virq = irq_create_mapping(max8997->irq_domain, muic_irq->irq);
if (!virq) {
ret = -EINVAL;
goto err_irq;
}
muic_irq->virq = virq;
ret = request_threaded_irq(virq, NULL,
max8997_muic_irq_handler,
IRQF_NO_SUSPEND,
muic_irq->name, info);
if (ret) {
dev_err(&pdev->dev,
"failed: irq request (IRQ: %d, error :%d)\n",
muic_irq->irq, ret);
goto err_irq;
}
}
/* External connector */
info->edev = devm_extcon_dev_allocate(&pdev->dev, max8997_extcon_cable);
if (IS_ERR(info->edev)) {
dev_err(&pdev->dev, "failed to allocate memory for extcon\n");
ret = -ENOMEM;
goto err_irq;
}
ret = devm_extcon_dev_register(&pdev->dev, info->edev);
if (ret) {
dev_err(&pdev->dev, "failed to register extcon device\n");
goto err_irq;
}
if (pdata && pdata->muic_pdata) {
struct max8997_muic_platform_data *muic_pdata
= pdata->muic_pdata;
/* Initialize registers according to platform data */
for (i = 0; i < muic_pdata->num_init_data; i++) {
max8997_write_reg(info->muic,
muic_pdata->init_data[i].addr,
muic_pdata->init_data[i].data);
}
/*
* Default usb/uart path whether UART/USB or AUX_UART/AUX_USB
* h/w path of COMP2/COMN1 on CONTROL1 register.
*/
if (muic_pdata->path_uart)
info->path_uart = muic_pdata->path_uart;
else
info->path_uart = CONTROL1_SW_UART;
if (muic_pdata->path_usb)
info->path_usb = muic_pdata->path_usb;
else
info->path_usb = CONTROL1_SW_USB;
/*
* Default delay time for detecting cable state
* after certain time.
*/
if (muic_pdata->detcable_delay_ms)
delay_jiffies =
msecs_to_jiffies(muic_pdata->detcable_delay_ms);
else
delay_jiffies = msecs_to_jiffies(DELAY_MS_DEFAULT);
} else {
info->path_uart = CONTROL1_SW_UART;
info->path_usb = CONTROL1_SW_USB;
delay_jiffies = msecs_to_jiffies(DELAY_MS_DEFAULT);
}
/* Set initial path for UART */
max8997_muic_set_path(info, info->path_uart, true);
/* Set ADC debounce time */
max8997_muic_set_debounce_time(info, ADC_DEBOUNCE_TIME_25MS);
/*
* Detect accessory after completing the initialization of platform
*
* - Use delayed workqueue to detect cable state and then
* notify cable state to notifiee/platform through uevent.
* After completing the booting of platform, the extcon provider
* driver should notify cable state to upper layer.
*/
INIT_DELAYED_WORK(&info->wq_detcable, max8997_muic_detect_cable_wq);
queue_delayed_work(system_power_efficient_wq, &info->wq_detcable,
delay_jiffies);
return 0;
err_irq:
while (--i >= 0)
free_irq(muic_irqs[i].virq, info);
return ret;
}
static int max8997_muic_remove(struct platform_device *pdev)
{
struct max8997_muic_info *info = platform_get_drvdata(pdev);
int i;
for (i = 0; i < ARRAY_SIZE(muic_irqs); i++)
free_irq(muic_irqs[i].virq, info);
cancel_work_sync(&info->irq_work);
return 0;
}
static struct platform_driver max8997_muic_driver = {
.driver = {
.name = DEV_NAME,
},
.probe = max8997_muic_probe,
.remove = max8997_muic_remove,
};
module_platform_driver(max8997_muic_driver);
MODULE_DESCRIPTION("Maxim MAX8997 Extcon driver");
MODULE_AUTHOR("Donggeun Kim <dg77.kim@samsung.com>");
MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:max8997-muic");