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
428 lines
11 KiB
C
428 lines
11 KiB
C
/*
|
|
* LED driver : leds-ktd2692.c
|
|
*
|
|
* Copyright (C) 2015 Samsung Electronics
|
|
* Ingi Kim <ingi2.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 version 2 as
|
|
* published by the Free Software Foundation.
|
|
*/
|
|
|
|
#include <linux/delay.h>
|
|
#include <linux/err.h>
|
|
#include <linux/gpio/consumer.h>
|
|
#include <linux/led-class-flash.h>
|
|
#include <linux/module.h>
|
|
#include <linux/mutex.h>
|
|
#include <linux/of.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/regulator/consumer.h>
|
|
|
|
/* Value related the movie mode */
|
|
#define KTD2692_MOVIE_MODE_CURRENT_LEVELS 16
|
|
#define KTD2692_MM_TO_FL_RATIO(x) ((x) / 3)
|
|
#define KTD2962_MM_MIN_CURR_THRESHOLD_SCALE 8
|
|
|
|
/* Value related the flash mode */
|
|
#define KTD2692_FLASH_MODE_TIMEOUT_LEVELS 8
|
|
#define KTD2692_FLASH_MODE_TIMEOUT_DISABLE 0
|
|
#define KTD2692_FLASH_MODE_CURR_PERCENT(x) (((x) * 16) / 100)
|
|
|
|
/* Macro for getting offset of flash timeout */
|
|
#define GET_TIMEOUT_OFFSET(timeout, step) ((timeout) / (step))
|
|
|
|
/* Base register address */
|
|
#define KTD2692_REG_LVP_BASE 0x00
|
|
#define KTD2692_REG_FLASH_TIMEOUT_BASE 0x20
|
|
#define KTD2692_REG_MM_MIN_CURR_THRESHOLD_BASE 0x40
|
|
#define KTD2692_REG_MOVIE_CURRENT_BASE 0x60
|
|
#define KTD2692_REG_FLASH_CURRENT_BASE 0x80
|
|
#define KTD2692_REG_MODE_BASE 0xA0
|
|
|
|
/* Set bit coding time for expresswire interface */
|
|
#define KTD2692_TIME_RESET_US 700
|
|
#define KTD2692_TIME_DATA_START_TIME_US 10
|
|
#define KTD2692_TIME_HIGH_END_OF_DATA_US 350
|
|
#define KTD2692_TIME_LOW_END_OF_DATA_US 10
|
|
#define KTD2692_TIME_SHORT_BITSET_US 4
|
|
#define KTD2692_TIME_LONG_BITSET_US 12
|
|
|
|
/* KTD2692 default length of name */
|
|
#define KTD2692_NAME_LENGTH 20
|
|
|
|
enum ktd2692_bitset {
|
|
KTD2692_LOW = 0,
|
|
KTD2692_HIGH,
|
|
};
|
|
|
|
/* Movie / Flash Mode Control */
|
|
enum ktd2692_led_mode {
|
|
KTD2692_MODE_DISABLE = 0, /* default */
|
|
KTD2692_MODE_MOVIE,
|
|
KTD2692_MODE_FLASH,
|
|
};
|
|
|
|
struct ktd2692_led_config_data {
|
|
/* maximum LED current in movie mode */
|
|
u32 movie_max_microamp;
|
|
/* maximum LED current in flash mode */
|
|
u32 flash_max_microamp;
|
|
/* maximum flash timeout */
|
|
u32 flash_max_timeout;
|
|
/* max LED brightness level */
|
|
enum led_brightness max_brightness;
|
|
};
|
|
|
|
struct ktd2692_context {
|
|
/* Related LED Flash class device */
|
|
struct led_classdev_flash fled_cdev;
|
|
|
|
/* secures access to the device */
|
|
struct mutex lock;
|
|
struct regulator *regulator;
|
|
|
|
struct gpio_desc *aux_gpio;
|
|
struct gpio_desc *ctrl_gpio;
|
|
|
|
enum ktd2692_led_mode mode;
|
|
enum led_brightness torch_brightness;
|
|
};
|
|
|
|
static struct ktd2692_context *fled_cdev_to_led(
|
|
struct led_classdev_flash *fled_cdev)
|
|
{
|
|
return container_of(fled_cdev, struct ktd2692_context, fled_cdev);
|
|
}
|
|
|
|
static void ktd2692_expresswire_start(struct ktd2692_context *led)
|
|
{
|
|
gpiod_direction_output(led->ctrl_gpio, KTD2692_HIGH);
|
|
udelay(KTD2692_TIME_DATA_START_TIME_US);
|
|
}
|
|
|
|
static void ktd2692_expresswire_reset(struct ktd2692_context *led)
|
|
{
|
|
gpiod_direction_output(led->ctrl_gpio, KTD2692_LOW);
|
|
udelay(KTD2692_TIME_RESET_US);
|
|
}
|
|
|
|
static void ktd2692_expresswire_end(struct ktd2692_context *led)
|
|
{
|
|
gpiod_direction_output(led->ctrl_gpio, KTD2692_LOW);
|
|
udelay(KTD2692_TIME_LOW_END_OF_DATA_US);
|
|
gpiod_direction_output(led->ctrl_gpio, KTD2692_HIGH);
|
|
udelay(KTD2692_TIME_HIGH_END_OF_DATA_US);
|
|
}
|
|
|
|
static void ktd2692_expresswire_set_bit(struct ktd2692_context *led, bool bit)
|
|
{
|
|
/*
|
|
* The Low Bit(0) and High Bit(1) is based on a time detection
|
|
* algorithm between time low and time high
|
|
* Time_(L_LB) : Low time of the Low Bit(0)
|
|
* Time_(H_LB) : High time of the LOW Bit(0)
|
|
* Time_(L_HB) : Low time of the High Bit(1)
|
|
* Time_(H_HB) : High time of the High Bit(1)
|
|
*
|
|
* It can be simplified to:
|
|
* Low Bit(0) : 2 * Time_(H_LB) < Time_(L_LB)
|
|
* High Bit(1) : 2 * Time_(L_HB) < Time_(H_HB)
|
|
* HIGH ___ ____ _.. _________ ___
|
|
* |_________| |_.. |____| |__|
|
|
* LOW <L_LB> <H_LB> <L_HB> <H_HB>
|
|
* [ Low Bit (0) ] [ High Bit(1) ]
|
|
*/
|
|
if (bit) {
|
|
gpiod_direction_output(led->ctrl_gpio, KTD2692_LOW);
|
|
udelay(KTD2692_TIME_SHORT_BITSET_US);
|
|
gpiod_direction_output(led->ctrl_gpio, KTD2692_HIGH);
|
|
udelay(KTD2692_TIME_LONG_BITSET_US);
|
|
} else {
|
|
gpiod_direction_output(led->ctrl_gpio, KTD2692_LOW);
|
|
udelay(KTD2692_TIME_LONG_BITSET_US);
|
|
gpiod_direction_output(led->ctrl_gpio, KTD2692_HIGH);
|
|
udelay(KTD2692_TIME_SHORT_BITSET_US);
|
|
}
|
|
}
|
|
|
|
static void ktd2692_expresswire_write(struct ktd2692_context *led, u8 value)
|
|
{
|
|
int i;
|
|
|
|
ktd2692_expresswire_start(led);
|
|
for (i = 7; i >= 0; i--)
|
|
ktd2692_expresswire_set_bit(led, value & BIT(i));
|
|
ktd2692_expresswire_end(led);
|
|
}
|
|
|
|
static int ktd2692_led_brightness_set(struct led_classdev *led_cdev,
|
|
enum led_brightness brightness)
|
|
{
|
|
struct led_classdev_flash *fled_cdev = lcdev_to_flcdev(led_cdev);
|
|
struct ktd2692_context *led = fled_cdev_to_led(fled_cdev);
|
|
|
|
mutex_lock(&led->lock);
|
|
|
|
if (brightness == LED_OFF) {
|
|
led->mode = KTD2692_MODE_DISABLE;
|
|
gpiod_direction_output(led->aux_gpio, KTD2692_LOW);
|
|
} else {
|
|
ktd2692_expresswire_write(led, brightness |
|
|
KTD2692_REG_MOVIE_CURRENT_BASE);
|
|
led->mode = KTD2692_MODE_MOVIE;
|
|
}
|
|
|
|
ktd2692_expresswire_write(led, led->mode | KTD2692_REG_MODE_BASE);
|
|
mutex_unlock(&led->lock);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int ktd2692_led_flash_strobe_set(struct led_classdev_flash *fled_cdev,
|
|
bool state)
|
|
{
|
|
struct ktd2692_context *led = fled_cdev_to_led(fled_cdev);
|
|
struct led_flash_setting *timeout = &fled_cdev->timeout;
|
|
u32 flash_tm_reg;
|
|
|
|
mutex_lock(&led->lock);
|
|
|
|
if (state) {
|
|
flash_tm_reg = GET_TIMEOUT_OFFSET(timeout->val, timeout->step);
|
|
ktd2692_expresswire_write(led, flash_tm_reg
|
|
| KTD2692_REG_FLASH_TIMEOUT_BASE);
|
|
|
|
led->mode = KTD2692_MODE_FLASH;
|
|
gpiod_direction_output(led->aux_gpio, KTD2692_HIGH);
|
|
} else {
|
|
led->mode = KTD2692_MODE_DISABLE;
|
|
gpiod_direction_output(led->aux_gpio, KTD2692_LOW);
|
|
}
|
|
|
|
ktd2692_expresswire_write(led, led->mode | KTD2692_REG_MODE_BASE);
|
|
|
|
fled_cdev->led_cdev.brightness = LED_OFF;
|
|
led->mode = KTD2692_MODE_DISABLE;
|
|
|
|
mutex_unlock(&led->lock);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int ktd2692_led_flash_timeout_set(struct led_classdev_flash *fled_cdev,
|
|
u32 timeout)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static void ktd2692_init_movie_current_max(struct ktd2692_led_config_data *cfg)
|
|
{
|
|
u32 offset, step;
|
|
u32 movie_current_microamp;
|
|
|
|
offset = KTD2692_MOVIE_MODE_CURRENT_LEVELS;
|
|
step = KTD2692_MM_TO_FL_RATIO(cfg->flash_max_microamp)
|
|
/ KTD2692_MOVIE_MODE_CURRENT_LEVELS;
|
|
|
|
do {
|
|
movie_current_microamp = step * offset;
|
|
offset--;
|
|
} while ((movie_current_microamp > cfg->movie_max_microamp) &&
|
|
(offset > 0));
|
|
|
|
cfg->max_brightness = offset;
|
|
}
|
|
|
|
static void ktd2692_init_flash_timeout(struct led_classdev_flash *fled_cdev,
|
|
struct ktd2692_led_config_data *cfg)
|
|
{
|
|
struct led_flash_setting *setting;
|
|
|
|
setting = &fled_cdev->timeout;
|
|
setting->min = KTD2692_FLASH_MODE_TIMEOUT_DISABLE;
|
|
setting->max = cfg->flash_max_timeout;
|
|
setting->step = cfg->flash_max_timeout
|
|
/ (KTD2692_FLASH_MODE_TIMEOUT_LEVELS - 1);
|
|
setting->val = cfg->flash_max_timeout;
|
|
}
|
|
|
|
static void ktd2692_setup(struct ktd2692_context *led)
|
|
{
|
|
led->mode = KTD2692_MODE_DISABLE;
|
|
ktd2692_expresswire_reset(led);
|
|
gpiod_direction_output(led->aux_gpio, KTD2692_LOW);
|
|
|
|
ktd2692_expresswire_write(led, (KTD2962_MM_MIN_CURR_THRESHOLD_SCALE - 1)
|
|
| KTD2692_REG_MM_MIN_CURR_THRESHOLD_BASE);
|
|
ktd2692_expresswire_write(led, KTD2692_FLASH_MODE_CURR_PERCENT(45)
|
|
| KTD2692_REG_FLASH_CURRENT_BASE);
|
|
}
|
|
|
|
static void regulator_disable_action(void *_data)
|
|
{
|
|
struct device *dev = _data;
|
|
struct ktd2692_context *led = dev_get_drvdata(dev);
|
|
int ret;
|
|
|
|
ret = regulator_disable(led->regulator);
|
|
if (ret)
|
|
dev_err(dev, "Failed to disable supply: %d\n", ret);
|
|
}
|
|
|
|
static int ktd2692_parse_dt(struct ktd2692_context *led, struct device *dev,
|
|
struct ktd2692_led_config_data *cfg)
|
|
{
|
|
struct device_node *np = dev->of_node;
|
|
struct device_node *child_node;
|
|
int ret;
|
|
|
|
if (!dev->of_node)
|
|
return -ENXIO;
|
|
|
|
led->ctrl_gpio = devm_gpiod_get(dev, "ctrl", GPIOD_ASIS);
|
|
ret = PTR_ERR_OR_ZERO(led->ctrl_gpio);
|
|
if (ret) {
|
|
dev_err(dev, "cannot get ctrl-gpios %d\n", ret);
|
|
return ret;
|
|
}
|
|
|
|
led->aux_gpio = devm_gpiod_get(dev, "aux", GPIOD_ASIS);
|
|
ret = PTR_ERR_OR_ZERO(led->aux_gpio);
|
|
if (ret) {
|
|
dev_err(dev, "cannot get aux-gpios %d\n", ret);
|
|
return ret;
|
|
}
|
|
|
|
led->regulator = devm_regulator_get(dev, "vin");
|
|
if (IS_ERR(led->regulator))
|
|
led->regulator = NULL;
|
|
|
|
if (led->regulator) {
|
|
ret = regulator_enable(led->regulator);
|
|
if (ret) {
|
|
dev_err(dev, "Failed to enable supply: %d\n", ret);
|
|
} else {
|
|
ret = devm_add_action_or_reset(dev,
|
|
regulator_disable_action, dev);
|
|
if (ret)
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
child_node = of_get_next_available_child(np, NULL);
|
|
if (!child_node) {
|
|
dev_err(dev, "No DT child node found for connected LED.\n");
|
|
return -EINVAL;
|
|
}
|
|
|
|
led->fled_cdev.led_cdev.name =
|
|
of_get_property(child_node, "label", NULL) ? : child_node->name;
|
|
|
|
ret = of_property_read_u32(child_node, "led-max-microamp",
|
|
&cfg->movie_max_microamp);
|
|
if (ret) {
|
|
dev_err(dev, "failed to parse led-max-microamp\n");
|
|
goto err_parse_dt;
|
|
}
|
|
|
|
ret = of_property_read_u32(child_node, "flash-max-microamp",
|
|
&cfg->flash_max_microamp);
|
|
if (ret) {
|
|
dev_err(dev, "failed to parse flash-max-microamp\n");
|
|
goto err_parse_dt;
|
|
}
|
|
|
|
ret = of_property_read_u32(child_node, "flash-max-timeout-us",
|
|
&cfg->flash_max_timeout);
|
|
if (ret) {
|
|
dev_err(dev, "failed to parse flash-max-timeout-us\n");
|
|
goto err_parse_dt;
|
|
}
|
|
|
|
err_parse_dt:
|
|
of_node_put(child_node);
|
|
return ret;
|
|
}
|
|
|
|
static const struct led_flash_ops flash_ops = {
|
|
.strobe_set = ktd2692_led_flash_strobe_set,
|
|
.timeout_set = ktd2692_led_flash_timeout_set,
|
|
};
|
|
|
|
static int ktd2692_probe(struct platform_device *pdev)
|
|
{
|
|
struct ktd2692_context *led;
|
|
struct led_classdev *led_cdev;
|
|
struct led_classdev_flash *fled_cdev;
|
|
struct ktd2692_led_config_data led_cfg;
|
|
int ret;
|
|
|
|
led = devm_kzalloc(&pdev->dev, sizeof(*led), GFP_KERNEL);
|
|
if (!led)
|
|
return -ENOMEM;
|
|
|
|
fled_cdev = &led->fled_cdev;
|
|
led_cdev = &fled_cdev->led_cdev;
|
|
|
|
ret = ktd2692_parse_dt(led, &pdev->dev, &led_cfg);
|
|
if (ret)
|
|
return ret;
|
|
|
|
ktd2692_init_flash_timeout(fled_cdev, &led_cfg);
|
|
ktd2692_init_movie_current_max(&led_cfg);
|
|
|
|
fled_cdev->ops = &flash_ops;
|
|
|
|
led_cdev->max_brightness = led_cfg.max_brightness;
|
|
led_cdev->brightness_set_blocking = ktd2692_led_brightness_set;
|
|
led_cdev->flags |= LED_CORE_SUSPENDRESUME | LED_DEV_CAP_FLASH;
|
|
|
|
mutex_init(&led->lock);
|
|
|
|
platform_set_drvdata(pdev, led);
|
|
|
|
ret = led_classdev_flash_register(&pdev->dev, fled_cdev);
|
|
if (ret) {
|
|
dev_err(&pdev->dev, "can't register LED %s\n", led_cdev->name);
|
|
mutex_destroy(&led->lock);
|
|
return ret;
|
|
}
|
|
|
|
ktd2692_setup(led);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int ktd2692_remove(struct platform_device *pdev)
|
|
{
|
|
struct ktd2692_context *led = platform_get_drvdata(pdev);
|
|
|
|
led_classdev_flash_unregister(&led->fled_cdev);
|
|
|
|
mutex_destroy(&led->lock);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static const struct of_device_id ktd2692_match[] = {
|
|
{ .compatible = "kinetic,ktd2692", },
|
|
{ /* sentinel */ },
|
|
};
|
|
MODULE_DEVICE_TABLE(of, ktd2692_match);
|
|
|
|
static struct platform_driver ktd2692_driver = {
|
|
.driver = {
|
|
.name = "ktd2692",
|
|
.of_match_table = ktd2692_match,
|
|
},
|
|
.probe = ktd2692_probe,
|
|
.remove = ktd2692_remove,
|
|
};
|
|
|
|
module_platform_driver(ktd2692_driver);
|
|
|
|
MODULE_AUTHOR("Ingi Kim <ingi2.kim@samsung.com>");
|
|
MODULE_DESCRIPTION("Kinetic KTD2692 LED driver");
|
|
MODULE_LICENSE("GPL v2");
|