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
713 lines
19 KiB
C
713 lines
19 KiB
C
/*
|
|
* extcon-sm5502.c - Silicon Mitus SM5502 extcon drvier to support USB switches
|
|
*
|
|
* Copyright (c) 2014 Samsung Electronics Co., Ltd
|
|
* Author: Chanwoo Choi <cw00.choi@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.
|
|
*/
|
|
|
|
#include <linux/err.h>
|
|
#include <linux/i2c.h>
|
|
#include <linux/interrupt.h>
|
|
#include <linux/irqdomain.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/module.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/regmap.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/extcon.h>
|
|
|
|
#include "extcon-sm5502.h"
|
|
|
|
#define DELAY_MS_DEFAULT 17000 /* unit: millisecond */
|
|
|
|
struct muic_irq {
|
|
unsigned int irq;
|
|
const char *name;
|
|
unsigned int virq;
|
|
};
|
|
|
|
struct reg_data {
|
|
u8 reg;
|
|
unsigned int val;
|
|
bool invert;
|
|
};
|
|
|
|
struct sm5502_muic_info {
|
|
struct device *dev;
|
|
struct extcon_dev *edev;
|
|
|
|
struct i2c_client *i2c;
|
|
struct regmap *regmap;
|
|
|
|
struct regmap_irq_chip_data *irq_data;
|
|
struct muic_irq *muic_irqs;
|
|
unsigned int num_muic_irqs;
|
|
int irq;
|
|
bool irq_attach;
|
|
bool irq_detach;
|
|
struct work_struct irq_work;
|
|
|
|
struct reg_data *reg_data;
|
|
unsigned int num_reg_data;
|
|
|
|
struct mutex mutex;
|
|
|
|
/*
|
|
* 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 value of SM5502 register to bring up MUIC device. */
|
|
static struct reg_data sm5502_reg_data[] = {
|
|
{
|
|
.reg = SM5502_REG_RESET,
|
|
.val = SM5502_REG_RESET_MASK,
|
|
.invert = true,
|
|
}, {
|
|
.reg = SM5502_REG_CONTROL,
|
|
.val = SM5502_REG_CONTROL_MASK_INT_MASK,
|
|
.invert = false,
|
|
}, {
|
|
.reg = SM5502_REG_INTMASK1,
|
|
.val = SM5502_REG_INTM1_KP_MASK
|
|
| SM5502_REG_INTM1_LKP_MASK
|
|
| SM5502_REG_INTM1_LKR_MASK,
|
|
.invert = true,
|
|
}, {
|
|
.reg = SM5502_REG_INTMASK2,
|
|
.val = SM5502_REG_INTM2_VBUS_DET_MASK
|
|
| SM5502_REG_INTM2_REV_ACCE_MASK
|
|
| SM5502_REG_INTM2_ADC_CHG_MASK
|
|
| SM5502_REG_INTM2_STUCK_KEY_MASK
|
|
| SM5502_REG_INTM2_STUCK_KEY_RCV_MASK
|
|
| SM5502_REG_INTM2_MHL_MASK,
|
|
.invert = true,
|
|
},
|
|
};
|
|
|
|
/* List of detectable cables */
|
|
static const unsigned int sm5502_extcon_cable[] = {
|
|
EXTCON_USB,
|
|
EXTCON_USB_HOST,
|
|
EXTCON_CHG_USB_SDP,
|
|
EXTCON_CHG_USB_DCP,
|
|
EXTCON_NONE,
|
|
};
|
|
|
|
/* Define supported accessory type */
|
|
enum sm5502_muic_acc_type {
|
|
SM5502_MUIC_ADC_GROUND = 0x0,
|
|
SM5502_MUIC_ADC_SEND_END_BUTTON,
|
|
SM5502_MUIC_ADC_REMOTE_S1_BUTTON,
|
|
SM5502_MUIC_ADC_REMOTE_S2_BUTTON,
|
|
SM5502_MUIC_ADC_REMOTE_S3_BUTTON,
|
|
SM5502_MUIC_ADC_REMOTE_S4_BUTTON,
|
|
SM5502_MUIC_ADC_REMOTE_S5_BUTTON,
|
|
SM5502_MUIC_ADC_REMOTE_S6_BUTTON,
|
|
SM5502_MUIC_ADC_REMOTE_S7_BUTTON,
|
|
SM5502_MUIC_ADC_REMOTE_S8_BUTTON,
|
|
SM5502_MUIC_ADC_REMOTE_S9_BUTTON,
|
|
SM5502_MUIC_ADC_REMOTE_S10_BUTTON,
|
|
SM5502_MUIC_ADC_REMOTE_S11_BUTTON,
|
|
SM5502_MUIC_ADC_REMOTE_S12_BUTTON,
|
|
SM5502_MUIC_ADC_RESERVED_ACC_1,
|
|
SM5502_MUIC_ADC_RESERVED_ACC_2,
|
|
SM5502_MUIC_ADC_RESERVED_ACC_3,
|
|
SM5502_MUIC_ADC_RESERVED_ACC_4,
|
|
SM5502_MUIC_ADC_RESERVED_ACC_5,
|
|
SM5502_MUIC_ADC_AUDIO_TYPE2,
|
|
SM5502_MUIC_ADC_PHONE_POWERED_DEV,
|
|
SM5502_MUIC_ADC_TTY_CONVERTER,
|
|
SM5502_MUIC_ADC_UART_CABLE,
|
|
SM5502_MUIC_ADC_TYPE1_CHARGER,
|
|
SM5502_MUIC_ADC_FACTORY_MODE_BOOT_OFF_USB,
|
|
SM5502_MUIC_ADC_FACTORY_MODE_BOOT_ON_USB,
|
|
SM5502_MUIC_ADC_AUDIO_VIDEO_CABLE,
|
|
SM5502_MUIC_ADC_TYPE2_CHARGER,
|
|
SM5502_MUIC_ADC_FACTORY_MODE_BOOT_OFF_UART,
|
|
SM5502_MUIC_ADC_FACTORY_MODE_BOOT_ON_UART,
|
|
SM5502_MUIC_ADC_AUDIO_TYPE1,
|
|
SM5502_MUIC_ADC_OPEN = 0x1f,
|
|
|
|
/* The below accessories have same ADC value (0x1f or 0x1e).
|
|
So, Device type1 is used to separate specific accessory. */
|
|
/* |---------|--ADC| */
|
|
/* | [7:5]|[4:0]| */
|
|
SM5502_MUIC_ADC_AUDIO_TYPE1_FULL_REMOTE = 0x3e, /* | 001|11110| */
|
|
SM5502_MUIC_ADC_AUDIO_TYPE1_SEND_END = 0x5e, /* | 010|11110| */
|
|
/* |Dev Type1|--ADC| */
|
|
SM5502_MUIC_ADC_OPEN_USB = 0x5f, /* | 010|11111| */
|
|
SM5502_MUIC_ADC_OPEN_TA = 0xdf, /* | 110|11111| */
|
|
SM5502_MUIC_ADC_OPEN_USB_OTG = 0xff, /* | 111|11111| */
|
|
};
|
|
|
|
/* List of supported interrupt for SM5502 */
|
|
static struct muic_irq sm5502_muic_irqs[] = {
|
|
{ SM5502_IRQ_INT1_ATTACH, "muic-attach" },
|
|
{ SM5502_IRQ_INT1_DETACH, "muic-detach" },
|
|
{ SM5502_IRQ_INT1_KP, "muic-kp" },
|
|
{ SM5502_IRQ_INT1_LKP, "muic-lkp" },
|
|
{ SM5502_IRQ_INT1_LKR, "muic-lkr" },
|
|
{ SM5502_IRQ_INT1_OVP_EVENT, "muic-ovp-event" },
|
|
{ SM5502_IRQ_INT1_OCP_EVENT, "muic-ocp-event" },
|
|
{ SM5502_IRQ_INT1_OVP_OCP_DIS, "muic-ovp-ocp-dis" },
|
|
{ SM5502_IRQ_INT2_VBUS_DET, "muic-vbus-det" },
|
|
{ SM5502_IRQ_INT2_REV_ACCE, "muic-rev-acce" },
|
|
{ SM5502_IRQ_INT2_ADC_CHG, "muic-adc-chg" },
|
|
{ SM5502_IRQ_INT2_STUCK_KEY, "muic-stuck-key" },
|
|
{ SM5502_IRQ_INT2_STUCK_KEY_RCV, "muic-stuck-key-rcv" },
|
|
{ SM5502_IRQ_INT2_MHL, "muic-mhl" },
|
|
};
|
|
|
|
/* Define interrupt list of SM5502 to register regmap_irq */
|
|
static const struct regmap_irq sm5502_irqs[] = {
|
|
/* INT1 interrupts */
|
|
{ .reg_offset = 0, .mask = SM5502_IRQ_INT1_ATTACH_MASK, },
|
|
{ .reg_offset = 0, .mask = SM5502_IRQ_INT1_DETACH_MASK, },
|
|
{ .reg_offset = 0, .mask = SM5502_IRQ_INT1_KP_MASK, },
|
|
{ .reg_offset = 0, .mask = SM5502_IRQ_INT1_LKP_MASK, },
|
|
{ .reg_offset = 0, .mask = SM5502_IRQ_INT1_LKR_MASK, },
|
|
{ .reg_offset = 0, .mask = SM5502_IRQ_INT1_OVP_EVENT_MASK, },
|
|
{ .reg_offset = 0, .mask = SM5502_IRQ_INT1_OCP_EVENT_MASK, },
|
|
{ .reg_offset = 0, .mask = SM5502_IRQ_INT1_OVP_OCP_DIS_MASK, },
|
|
|
|
/* INT2 interrupts */
|
|
{ .reg_offset = 1, .mask = SM5502_IRQ_INT2_VBUS_DET_MASK,},
|
|
{ .reg_offset = 1, .mask = SM5502_IRQ_INT2_REV_ACCE_MASK, },
|
|
{ .reg_offset = 1, .mask = SM5502_IRQ_INT2_ADC_CHG_MASK, },
|
|
{ .reg_offset = 1, .mask = SM5502_IRQ_INT2_STUCK_KEY_MASK, },
|
|
{ .reg_offset = 1, .mask = SM5502_IRQ_INT2_STUCK_KEY_RCV_MASK, },
|
|
{ .reg_offset = 1, .mask = SM5502_IRQ_INT2_MHL_MASK, },
|
|
};
|
|
|
|
static const struct regmap_irq_chip sm5502_muic_irq_chip = {
|
|
.name = "sm5502",
|
|
.status_base = SM5502_REG_INT1,
|
|
.mask_base = SM5502_REG_INTMASK1,
|
|
.mask_invert = false,
|
|
.num_regs = 2,
|
|
.irqs = sm5502_irqs,
|
|
.num_irqs = ARRAY_SIZE(sm5502_irqs),
|
|
};
|
|
|
|
/* Define regmap configuration of SM5502 for I2C communication */
|
|
static bool sm5502_muic_volatile_reg(struct device *dev, unsigned int reg)
|
|
{
|
|
switch (reg) {
|
|
case SM5502_REG_INTMASK1:
|
|
case SM5502_REG_INTMASK2:
|
|
return true;
|
|
default:
|
|
break;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
static const struct regmap_config sm5502_muic_regmap_config = {
|
|
.reg_bits = 8,
|
|
.val_bits = 8,
|
|
.volatile_reg = sm5502_muic_volatile_reg,
|
|
.max_register = SM5502_REG_END,
|
|
};
|
|
|
|
/* Change DM_CON/DP_CON/VBUSIN switch according to cable type */
|
|
static int sm5502_muic_set_path(struct sm5502_muic_info *info,
|
|
unsigned int con_sw, unsigned int vbus_sw,
|
|
bool attached)
|
|
{
|
|
int ret;
|
|
|
|
if (!attached) {
|
|
con_sw = DM_DP_SWITCH_OPEN;
|
|
vbus_sw = VBUSIN_SWITCH_OPEN;
|
|
}
|
|
|
|
switch (con_sw) {
|
|
case DM_DP_SWITCH_OPEN:
|
|
case DM_DP_SWITCH_USB:
|
|
case DM_DP_SWITCH_AUDIO:
|
|
case DM_DP_SWITCH_UART:
|
|
ret = regmap_update_bits(info->regmap, SM5502_REG_MANUAL_SW1,
|
|
SM5502_REG_MANUAL_SW1_DP_MASK |
|
|
SM5502_REG_MANUAL_SW1_DM_MASK,
|
|
con_sw);
|
|
if (ret < 0) {
|
|
dev_err(info->dev,
|
|
"cannot update DM_CON/DP_CON switch\n");
|
|
return ret;
|
|
}
|
|
break;
|
|
default:
|
|
dev_err(info->dev, "Unknown DM_CON/DP_CON switch type (%d)\n",
|
|
con_sw);
|
|
return -EINVAL;
|
|
};
|
|
|
|
switch (vbus_sw) {
|
|
case VBUSIN_SWITCH_OPEN:
|
|
case VBUSIN_SWITCH_VBUSOUT:
|
|
case VBUSIN_SWITCH_MIC:
|
|
case VBUSIN_SWITCH_VBUSOUT_WITH_USB:
|
|
ret = regmap_update_bits(info->regmap, SM5502_REG_MANUAL_SW1,
|
|
SM5502_REG_MANUAL_SW1_VBUSIN_MASK,
|
|
vbus_sw);
|
|
if (ret < 0) {
|
|
dev_err(info->dev,
|
|
"cannot update VBUSIN switch\n");
|
|
return ret;
|
|
}
|
|
break;
|
|
default:
|
|
dev_err(info->dev, "Unknown VBUS switch type (%d)\n", vbus_sw);
|
|
return -EINVAL;
|
|
};
|
|
|
|
return 0;
|
|
}
|
|
|
|
/* Return cable type of attached or detached accessories */
|
|
static unsigned int sm5502_muic_get_cable_type(struct sm5502_muic_info *info)
|
|
{
|
|
unsigned int cable_type = -1, adc, dev_type1;
|
|
int ret;
|
|
|
|
/* Read ADC value according to external cable or button */
|
|
ret = regmap_read(info->regmap, SM5502_REG_ADC, &adc);
|
|
if (ret) {
|
|
dev_err(info->dev, "failed to read ADC register\n");
|
|
return ret;
|
|
}
|
|
|
|
/*
|
|
* If ADC is SM5502_MUIC_ADC_GROUND(0x0), external cable hasn't
|
|
* connected with to MUIC device.
|
|
*/
|
|
cable_type = adc & SM5502_REG_ADC_MASK;
|
|
if (cable_type == SM5502_MUIC_ADC_GROUND)
|
|
return SM5502_MUIC_ADC_GROUND;
|
|
|
|
switch (cable_type) {
|
|
case SM5502_MUIC_ADC_GROUND:
|
|
case SM5502_MUIC_ADC_SEND_END_BUTTON:
|
|
case SM5502_MUIC_ADC_REMOTE_S1_BUTTON:
|
|
case SM5502_MUIC_ADC_REMOTE_S2_BUTTON:
|
|
case SM5502_MUIC_ADC_REMOTE_S3_BUTTON:
|
|
case SM5502_MUIC_ADC_REMOTE_S4_BUTTON:
|
|
case SM5502_MUIC_ADC_REMOTE_S5_BUTTON:
|
|
case SM5502_MUIC_ADC_REMOTE_S6_BUTTON:
|
|
case SM5502_MUIC_ADC_REMOTE_S7_BUTTON:
|
|
case SM5502_MUIC_ADC_REMOTE_S8_BUTTON:
|
|
case SM5502_MUIC_ADC_REMOTE_S9_BUTTON:
|
|
case SM5502_MUIC_ADC_REMOTE_S10_BUTTON:
|
|
case SM5502_MUIC_ADC_REMOTE_S11_BUTTON:
|
|
case SM5502_MUIC_ADC_REMOTE_S12_BUTTON:
|
|
case SM5502_MUIC_ADC_RESERVED_ACC_1:
|
|
case SM5502_MUIC_ADC_RESERVED_ACC_2:
|
|
case SM5502_MUIC_ADC_RESERVED_ACC_3:
|
|
case SM5502_MUIC_ADC_RESERVED_ACC_4:
|
|
case SM5502_MUIC_ADC_RESERVED_ACC_5:
|
|
case SM5502_MUIC_ADC_AUDIO_TYPE2:
|
|
case SM5502_MUIC_ADC_PHONE_POWERED_DEV:
|
|
case SM5502_MUIC_ADC_TTY_CONVERTER:
|
|
case SM5502_MUIC_ADC_UART_CABLE:
|
|
case SM5502_MUIC_ADC_TYPE1_CHARGER:
|
|
case SM5502_MUIC_ADC_FACTORY_MODE_BOOT_OFF_USB:
|
|
case SM5502_MUIC_ADC_FACTORY_MODE_BOOT_ON_USB:
|
|
case SM5502_MUIC_ADC_AUDIO_VIDEO_CABLE:
|
|
case SM5502_MUIC_ADC_TYPE2_CHARGER:
|
|
case SM5502_MUIC_ADC_FACTORY_MODE_BOOT_OFF_UART:
|
|
case SM5502_MUIC_ADC_FACTORY_MODE_BOOT_ON_UART:
|
|
break;
|
|
case SM5502_MUIC_ADC_AUDIO_TYPE1:
|
|
/*
|
|
* Check whether cable type is
|
|
* SM5502_MUIC_ADC_AUDIO_TYPE1_FULL_REMOTE
|
|
* or SM5502_MUIC_ADC_AUDIO_TYPE1_SEND_END
|
|
* by using Button event.
|
|
*/
|
|
break;
|
|
case SM5502_MUIC_ADC_OPEN:
|
|
ret = regmap_read(info->regmap, SM5502_REG_DEV_TYPE1,
|
|
&dev_type1);
|
|
if (ret) {
|
|
dev_err(info->dev, "failed to read DEV_TYPE1 reg\n");
|
|
return ret;
|
|
}
|
|
|
|
switch (dev_type1) {
|
|
case SM5502_REG_DEV_TYPE1_USB_SDP_MASK:
|
|
cable_type = SM5502_MUIC_ADC_OPEN_USB;
|
|
break;
|
|
case SM5502_REG_DEV_TYPE1_DEDICATED_CHG_MASK:
|
|
cable_type = SM5502_MUIC_ADC_OPEN_TA;
|
|
break;
|
|
case SM5502_REG_DEV_TYPE1_USB_OTG_MASK:
|
|
cable_type = SM5502_MUIC_ADC_OPEN_USB_OTG;
|
|
break;
|
|
default:
|
|
dev_dbg(info->dev,
|
|
"cannot identify the cable type: adc(0x%x)\n",
|
|
adc);
|
|
return -EINVAL;
|
|
};
|
|
break;
|
|
default:
|
|
dev_err(info->dev,
|
|
"failed to identify the cable type: adc(0x%x)\n", adc);
|
|
return -EINVAL;
|
|
};
|
|
|
|
return cable_type;
|
|
}
|
|
|
|
static int sm5502_muic_cable_handler(struct sm5502_muic_info *info,
|
|
bool attached)
|
|
{
|
|
static unsigned int prev_cable_type = SM5502_MUIC_ADC_GROUND;
|
|
unsigned int cable_type = SM5502_MUIC_ADC_GROUND;
|
|
unsigned int con_sw = DM_DP_SWITCH_OPEN;
|
|
unsigned int vbus_sw = VBUSIN_SWITCH_OPEN;
|
|
unsigned int id;
|
|
int ret;
|
|
|
|
/* Get the type of attached or detached cable */
|
|
if (attached)
|
|
cable_type = sm5502_muic_get_cable_type(info);
|
|
else
|
|
cable_type = prev_cable_type;
|
|
prev_cable_type = cable_type;
|
|
|
|
switch (cable_type) {
|
|
case SM5502_MUIC_ADC_OPEN_USB:
|
|
id = EXTCON_USB;
|
|
con_sw = DM_DP_SWITCH_USB;
|
|
vbus_sw = VBUSIN_SWITCH_VBUSOUT_WITH_USB;
|
|
break;
|
|
case SM5502_MUIC_ADC_OPEN_TA:
|
|
id = EXTCON_CHG_USB_DCP;
|
|
con_sw = DM_DP_SWITCH_OPEN;
|
|
vbus_sw = VBUSIN_SWITCH_VBUSOUT;
|
|
break;
|
|
case SM5502_MUIC_ADC_OPEN_USB_OTG:
|
|
id = EXTCON_USB_HOST;
|
|
con_sw = DM_DP_SWITCH_USB;
|
|
vbus_sw = VBUSIN_SWITCH_OPEN;
|
|
break;
|
|
default:
|
|
dev_dbg(info->dev,
|
|
"cannot handle this cable_type (0x%x)\n", cable_type);
|
|
return 0;
|
|
};
|
|
|
|
/* Change internal hardware path(DM_CON/DP_CON, VBUSIN) */
|
|
ret = sm5502_muic_set_path(info, con_sw, vbus_sw, attached);
|
|
if (ret < 0)
|
|
return ret;
|
|
|
|
/* Change the state of external accessory */
|
|
extcon_set_state_sync(info->edev, id, attached);
|
|
if (id == EXTCON_USB)
|
|
extcon_set_state_sync(info->edev, EXTCON_CHG_USB_SDP,
|
|
attached);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void sm5502_muic_irq_work(struct work_struct *work)
|
|
{
|
|
struct sm5502_muic_info *info = container_of(work,
|
|
struct sm5502_muic_info, irq_work);
|
|
int ret = 0;
|
|
|
|
if (!info->edev)
|
|
return;
|
|
|
|
mutex_lock(&info->mutex);
|
|
|
|
/* Detect attached or detached cables */
|
|
if (info->irq_attach) {
|
|
ret = sm5502_muic_cable_handler(info, true);
|
|
info->irq_attach = false;
|
|
}
|
|
if (info->irq_detach) {
|
|
ret = sm5502_muic_cable_handler(info, false);
|
|
info->irq_detach = false;
|
|
}
|
|
|
|
if (ret < 0)
|
|
dev_err(info->dev, "failed to handle MUIC interrupt\n");
|
|
|
|
mutex_unlock(&info->mutex);
|
|
}
|
|
|
|
/*
|
|
* Sets irq_attach or irq_detach in sm5502_muic_info and returns 0.
|
|
* Returns -ESRCH if irq_type does not match registered IRQ for this dev type.
|
|
*/
|
|
static int sm5502_parse_irq(struct sm5502_muic_info *info, int irq_type)
|
|
{
|
|
switch (irq_type) {
|
|
case SM5502_IRQ_INT1_ATTACH:
|
|
info->irq_attach = true;
|
|
break;
|
|
case SM5502_IRQ_INT1_DETACH:
|
|
info->irq_detach = true;
|
|
break;
|
|
case SM5502_IRQ_INT1_KP:
|
|
case SM5502_IRQ_INT1_LKP:
|
|
case SM5502_IRQ_INT1_LKR:
|
|
case SM5502_IRQ_INT1_OVP_EVENT:
|
|
case SM5502_IRQ_INT1_OCP_EVENT:
|
|
case SM5502_IRQ_INT1_OVP_OCP_DIS:
|
|
case SM5502_IRQ_INT2_VBUS_DET:
|
|
case SM5502_IRQ_INT2_REV_ACCE:
|
|
case SM5502_IRQ_INT2_ADC_CHG:
|
|
case SM5502_IRQ_INT2_STUCK_KEY:
|
|
case SM5502_IRQ_INT2_STUCK_KEY_RCV:
|
|
case SM5502_IRQ_INT2_MHL:
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static irqreturn_t sm5502_muic_irq_handler(int irq, void *data)
|
|
{
|
|
struct sm5502_muic_info *info = data;
|
|
int i, irq_type = -1, ret;
|
|
|
|
for (i = 0; i < info->num_muic_irqs; i++)
|
|
if (irq == info->muic_irqs[i].virq)
|
|
irq_type = info->muic_irqs[i].irq;
|
|
|
|
ret = sm5502_parse_irq(info, irq_type);
|
|
if (ret < 0) {
|
|
dev_warn(info->dev, "cannot handle is interrupt:%d\n",
|
|
irq_type);
|
|
return IRQ_HANDLED;
|
|
}
|
|
schedule_work(&info->irq_work);
|
|
|
|
return IRQ_HANDLED;
|
|
}
|
|
|
|
static void sm5502_muic_detect_cable_wq(struct work_struct *work)
|
|
{
|
|
struct sm5502_muic_info *info = container_of(to_delayed_work(work),
|
|
struct sm5502_muic_info, wq_detcable);
|
|
int ret;
|
|
|
|
/* Notify the state of connector cable or not */
|
|
ret = sm5502_muic_cable_handler(info, true);
|
|
if (ret < 0)
|
|
dev_warn(info->dev, "failed to detect cable state\n");
|
|
}
|
|
|
|
static void sm5502_init_dev_type(struct sm5502_muic_info *info)
|
|
{
|
|
unsigned int reg_data, vendor_id, version_id;
|
|
int i, ret;
|
|
|
|
/* To test I2C, Print version_id and vendor_id of SM5502 */
|
|
ret = regmap_read(info->regmap, SM5502_REG_DEVICE_ID, ®_data);
|
|
if (ret) {
|
|
dev_err(info->dev,
|
|
"failed to read DEVICE_ID register: %d\n", ret);
|
|
return;
|
|
}
|
|
|
|
vendor_id = ((reg_data & SM5502_REG_DEVICE_ID_VENDOR_MASK) >>
|
|
SM5502_REG_DEVICE_ID_VENDOR_SHIFT);
|
|
version_id = ((reg_data & SM5502_REG_DEVICE_ID_VERSION_MASK) >>
|
|
SM5502_REG_DEVICE_ID_VERSION_SHIFT);
|
|
|
|
dev_info(info->dev, "Device type: version: 0x%x, vendor: 0x%x\n",
|
|
version_id, vendor_id);
|
|
|
|
/* Initiazle the register of SM5502 device to bring-up */
|
|
for (i = 0; i < info->num_reg_data; i++) {
|
|
unsigned int val = 0;
|
|
|
|
if (!info->reg_data[i].invert)
|
|
val |= ~info->reg_data[i].val;
|
|
else
|
|
val = info->reg_data[i].val;
|
|
regmap_write(info->regmap, info->reg_data[i].reg, val);
|
|
}
|
|
}
|
|
|
|
static int sm5022_muic_i2c_probe(struct i2c_client *i2c,
|
|
const struct i2c_device_id *id)
|
|
{
|
|
struct device_node *np = i2c->dev.of_node;
|
|
struct sm5502_muic_info *info;
|
|
int i, ret, irq_flags;
|
|
|
|
if (!np)
|
|
return -EINVAL;
|
|
|
|
info = devm_kzalloc(&i2c->dev, sizeof(*info), GFP_KERNEL);
|
|
if (!info)
|
|
return -ENOMEM;
|
|
i2c_set_clientdata(i2c, info);
|
|
|
|
info->dev = &i2c->dev;
|
|
info->i2c = i2c;
|
|
info->irq = i2c->irq;
|
|
info->muic_irqs = sm5502_muic_irqs;
|
|
info->num_muic_irqs = ARRAY_SIZE(sm5502_muic_irqs);
|
|
info->reg_data = sm5502_reg_data;
|
|
info->num_reg_data = ARRAY_SIZE(sm5502_reg_data);
|
|
|
|
mutex_init(&info->mutex);
|
|
|
|
INIT_WORK(&info->irq_work, sm5502_muic_irq_work);
|
|
|
|
info->regmap = devm_regmap_init_i2c(i2c, &sm5502_muic_regmap_config);
|
|
if (IS_ERR(info->regmap)) {
|
|
ret = PTR_ERR(info->regmap);
|
|
dev_err(info->dev, "failed to allocate register map: %d\n",
|
|
ret);
|
|
return ret;
|
|
}
|
|
|
|
/* Support irq domain for SM5502 MUIC device */
|
|
irq_flags = IRQF_TRIGGER_FALLING | IRQF_ONESHOT | IRQF_SHARED;
|
|
ret = regmap_add_irq_chip(info->regmap, info->irq, irq_flags, 0,
|
|
&sm5502_muic_irq_chip, &info->irq_data);
|
|
if (ret != 0) {
|
|
dev_err(info->dev, "failed to request IRQ %d: %d\n",
|
|
info->irq, ret);
|
|
return ret;
|
|
}
|
|
|
|
for (i = 0; i < info->num_muic_irqs; i++) {
|
|
struct muic_irq *muic_irq = &info->muic_irqs[i];
|
|
int virq = 0;
|
|
|
|
virq = regmap_irq_get_virq(info->irq_data, muic_irq->irq);
|
|
if (virq <= 0)
|
|
return -EINVAL;
|
|
muic_irq->virq = virq;
|
|
|
|
ret = devm_request_threaded_irq(info->dev, virq, NULL,
|
|
sm5502_muic_irq_handler,
|
|
IRQF_NO_SUSPEND,
|
|
muic_irq->name, info);
|
|
if (ret) {
|
|
dev_err(info->dev,
|
|
"failed: irq request (IRQ: %d, error :%d)\n",
|
|
muic_irq->irq, ret);
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
/* Allocate extcon device */
|
|
info->edev = devm_extcon_dev_allocate(info->dev, sm5502_extcon_cable);
|
|
if (IS_ERR(info->edev)) {
|
|
dev_err(info->dev, "failed to allocate memory for extcon\n");
|
|
return -ENOMEM;
|
|
}
|
|
|
|
/* Register extcon device */
|
|
ret = devm_extcon_dev_register(info->dev, info->edev);
|
|
if (ret) {
|
|
dev_err(info->dev, "failed to register extcon device\n");
|
|
return ret;
|
|
}
|
|
|
|
/*
|
|
* 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, sm5502_muic_detect_cable_wq);
|
|
queue_delayed_work(system_power_efficient_wq, &info->wq_detcable,
|
|
msecs_to_jiffies(DELAY_MS_DEFAULT));
|
|
|
|
/* Initialize SM5502 device and print vendor id and version id */
|
|
sm5502_init_dev_type(info);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int sm5502_muic_i2c_remove(struct i2c_client *i2c)
|
|
{
|
|
struct sm5502_muic_info *info = i2c_get_clientdata(i2c);
|
|
|
|
regmap_del_irq_chip(info->irq, info->irq_data);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static const struct of_device_id sm5502_dt_match[] = {
|
|
{ .compatible = "siliconmitus,sm5502-muic" },
|
|
{ },
|
|
};
|
|
MODULE_DEVICE_TABLE(of, sm5502_dt_match);
|
|
|
|
#ifdef CONFIG_PM_SLEEP
|
|
static int sm5502_muic_suspend(struct device *dev)
|
|
{
|
|
struct i2c_client *i2c = to_i2c_client(dev);
|
|
struct sm5502_muic_info *info = i2c_get_clientdata(i2c);
|
|
|
|
enable_irq_wake(info->irq);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int sm5502_muic_resume(struct device *dev)
|
|
{
|
|
struct i2c_client *i2c = to_i2c_client(dev);
|
|
struct sm5502_muic_info *info = i2c_get_clientdata(i2c);
|
|
|
|
disable_irq_wake(info->irq);
|
|
|
|
return 0;
|
|
}
|
|
#endif
|
|
|
|
static SIMPLE_DEV_PM_OPS(sm5502_muic_pm_ops,
|
|
sm5502_muic_suspend, sm5502_muic_resume);
|
|
|
|
static const struct i2c_device_id sm5502_i2c_id[] = {
|
|
{ "sm5502", TYPE_SM5502 },
|
|
{ }
|
|
};
|
|
MODULE_DEVICE_TABLE(i2c, sm5502_i2c_id);
|
|
|
|
static struct i2c_driver sm5502_muic_i2c_driver = {
|
|
.driver = {
|
|
.name = "sm5502",
|
|
.pm = &sm5502_muic_pm_ops,
|
|
.of_match_table = sm5502_dt_match,
|
|
},
|
|
.probe = sm5022_muic_i2c_probe,
|
|
.remove = sm5502_muic_i2c_remove,
|
|
.id_table = sm5502_i2c_id,
|
|
};
|
|
|
|
static int __init sm5502_muic_i2c_init(void)
|
|
{
|
|
return i2c_add_driver(&sm5502_muic_i2c_driver);
|
|
}
|
|
subsys_initcall(sm5502_muic_i2c_init);
|
|
|
|
MODULE_DESCRIPTION("Silicon Mitus SM5502 Extcon driver");
|
|
MODULE_AUTHOR("Chanwoo Choi <cw00.choi@samsung.com>");
|
|
MODULE_LICENSE("GPL");
|