Merge 4.9.185 into android-4.9
Linux 4.9.185
* arm64: kaslr: keep modules inside module region when KASAN is enabled
arch/arm64/kernel/module.c
dmaengine: imx-sdma: remove BD_INTR for channel0
MIPS: Add missing EHB in mtc0 -> mfc0 sequence.
IB/hfi1: Close PSM sdma_progress sleep window
KVM: LAPIC: Fix pending interrupt in IRR blocked by software disable LAPIC
* arm64, vdso: Define vdso_{start,end} as array
arch/arm64/kernel/vdso.c
tty: rocket: fix incorrect forward declaration of 'rp_init()'
btrfs: Ensure replaced device doesn't have pending chunk allocation
drm/imx: only send event on crtc disable if kept disabled
drm/imx: notify drm core before sending event during crtc disable
* lib/mpi: Fix karactx leak in mpi_powm
lib/mpi/mpi-pow.c
* ALSA: usb-audio: fix sign unintended sign extension on left shifts
sound/usb/mixer_quirks.c
ALSA: line6: Fix write on zero-sized buffer
ALSA: firewire-lib/fireworks: fix miss detection of received MIDI messages
ALSA: seq: fix incorrect order of dest_client/dest_ports arguments
crypto: user - prevent operating on larval algorithms
* ptrace: Fix ->ptracer_cred handling for PTRACE_TRACEME
kernel/ptrace.c
MIPS: Workaround GCC __builtin_unreachable reordering bug
drm/i915/dmc: protect against reading random memory
KVM: x86: degrade WARN to pr_warn_ratelimited
clk: sunxi: fix uninitialized access
ARC: handle gcc generated __builtin_trap for older compiler
* bug.h: work around GCC PR82365 in BUG()
include/asm-generic/bug.h
include/linux/compiler-gcc.h
include/linux/compiler.h
ARC: fix allnoconfig build warning
mfd: omap-usb-tll: Fix register offsets
MIPS: netlogic: xlr: Remove erroneous check in nlm_fmn_send()
MIPS: math-emu: do not use bools for arithmetic
* mm/mlock.c: change count_mm_mlocked_page_nr return type
mm/mlock.c
scripts/decode_stacktrace.sh: prefix addr2line with $CROSS_COMPILE
scsi: hpsa: correct ioaccel2 chaining
usb: gadget: udc: lpc32xx: allocate descriptor with GFP_ATOMIC
usb: gadget: fusb300_udc: Fix memory leak of fusb300->ep[i]
ASoC: max98090: remove 24-bit format support if RJ is 0
drm/mediatek: fix unbind functions
spi: bitbang: Fix NULL pointer dereference in spi_unregister_master
* ASoC: soc-pcm: BE dai needs prepare when pause release after resume
sound/soc/soc-pcm.c
ASoC : cs4265 : readable register too low
* Bluetooth: Fix faulty expression for minimum encryption key size check
net/bluetooth/l2cap_core.c
tipc: pass tunnel dev as NULL to udp_tunnel(6)_xmit_skb
* bpf: udp: ipv6: Avoid running reuseport's bpf_prog from __udp6_lib_err
net/ipv6/udp.c
* bpf: udp: Avoid calling reuseport's bpf_prog from udp_gro
net/ipv4/udp.c
net/ipv6/udp.c
* net: check before dereferencing netdev_ops during busy poll
net/core/dev.c
* ipv4: Use return value of inet_iif() for __raw_v4_lookup in the while loop
net/ipv4/raw.c
* bonding: Always enable vlan tx offload
drivers/net/bonding/bond_main.c
team: Always enable vlan tx offload
* tun: wake up waitqueues after IFF_UP is set
drivers/net/tun.c
tipc: check msg->req data len in tipc_nl_compat_bearer_disable
tipc: change to use register_pernet_device
sctp: change to hold sk after auth shkey is created successfully
net: stmmac: fixed new system time seconds value calculation
* af_packet: Block execution of tasks waiting for transmit to complete in AF_PACKET
net/packet/af_packet.c
net/packet/internal.h
* cpu/speculation: Warn on unsupported mitigations= parameter
kernel/cpu.c
NFS/flexfiles: Use the correct TCP timeout for flexfiles I/O
x86/speculation: Allow guests to use SSBD even if host does not
scsi: vmw_pscsi: Fix use-after-free in pvscsi_queue_lck()
* mm/page_idle.c: fix oops because end_pfn is larger than max_pfn
mm/page_idle.c
fs/binfmt_flat.c: make load_flat_shared_library() work
* fs/proc/array.c: allow reporting eip/esp for all coredumping threads
fs/proc/array.c
net/9p: include trans_common.h to fix missing prototype warning.
9p: p9dirent_read: check network-provided name length
9p/rdma: remove useless check in cm_event_handler
9p: acl: fix uninitialized iattr access
9p/rdma: do not disconnect on down_interruptible EAGAIN
perf header: Fix unchecked usage of strncpy()
perf help: Remove needless use of strncpy()
perf ui helpline: Use strlcpy() as a shorter form of strncpy() + explicit set nul
IB/hfi1: Avoid hardlockup with flushlist_lock
mac80211: Do not use stack memory with scatterlist for GMAC
mac80211: drop robust management frames from unknown TA
* cfg80211: fix memory leak of wiphy device name
net/wireless/core.c
* Bluetooth: Fix regression with minimum encryption key size alignment
net/bluetooth/hci_conn.c
net/bluetooth/l2cap_core.c
* Bluetooth: Align minimum encryption key size for LE and BR/EDR connections
include/net/bluetooth/hci_core.h
net/bluetooth/hci_conn.c
ARM: imx: cpuidle-imx6sx: Restrict the SW2ISO increase to i.MX6SX
powerpc/bpf: use unsigned division instruction for 64-bit operations
can: purge socket error queue on sock destruct
can: flexcan: fix timeout when set small bitrate
btrfs: start readahead also in seed devices
nvme: Fix u32 overflow in the number of namespace list calculation
hwmon: (pmbus/core) Treat parameters as paged if on multiple pages
s390/qeth: fix VLAN attribute in bridge_hostnotify udev event
* scsi: ufs: Check that space was properly alloced in copy_query_response
drivers/scsi/ufs/ufshcd.c
scripts/checkstack.pl: Fix arm64 wrong or unknown architecture
drm/arm/hdlcd: Allow a bit of clock tolerance
net: ethernet: mediatek: Use NET_IP_ALIGN to judge if HW RX_2BYTE_OFFSET is enabled
net: ethernet: mediatek: Use hw_feature to judge if HWLRO is supported
sparc: perf: fix updated event period in response to PERF_EVENT_IOC_PERIOD
net: hns: Fix loopback test failed at copper ports
net: dsa: mv88e6xxx: avoid error message on remove from VLAN 0
MIPS: uprobes: remove set but not used variable 'epc'
IB/{qib, hfi1, rdmavt}: Correct ibv_devinfo max_mr value
IB/hfi1: Insure freeze_work work_struct is canceled on shutdown
IB/rdmavt: Fix alloc_qpn() WARN_ON()
parisc: Fix compiler warnings in float emulation code
parport: Fix mem leak in parport_register_dev_model
ARC: fix build warnings with !CONFIG_KPROBES
apparmor: enforce nullbyte at end of tag string
* Input: uinput - add compat ioctl number translation for UI_*_FF_UPLOAD
drivers/input/misc/uinput.c
IB/hfi1: Silence txreq allocation warnings
usb: chipidea: udc: workaround for endpoint conflict issue
* scsi: ufs: Avoid runtime suspend possibly being blocked forever
drivers/scsi/ufs/ufshcd-pltfrm.c
* gcc-9: silence 'address-of-packed-member' warning
Makefile
* tracing: Silence GCC 9 array bounds warning
kernel/trace/trace.c
kernel/trace/trace.h
BACKPORT: kheaders: Do not regenerate archive if config is not changed
* BACKPORT: kheaders: Move from proc to sysfs
init/Kconfig
kernel/Makefile
* BACKPORT: Provide in-kernel headers to make extending kernel easier
init/Kconfig
kernel/Makefile
Merge 4.9.184 into android-4.9
Linux 4.9.184
* tcp: refine memory limit test in tcp_fragment()
net/ipv4/tcp_output.c
Merge 4.9.183 into android-4.9
Linux 4.9.183
* Abort file_remove_privs() for non-reg. files
fs/inode.c
mlxsw: spectrum: Prevent force of 56G
scsi: libsas: delete sas port if expander discover failed
scsi: smartpqi: properly set both the DMA mask and the coherent DMA mask
scsi: libcxgbi: add a check for NULL pointer in cxgbi_check_route()
net: sh_eth: fix mdio access in sh_eth_close() for R-Car Gen2 and RZ/A1 SoCs
KVM: PPC: Book3S HV: Don't take kvm->lock around kvm_for_each_vcpu
KVM: PPC: Book3S: Use new mutex to synchronize access to rtas token list
ia64: fix build errors by exporting paddr_to_nid()
perf record: Fix s390 missing module symbol and warning for non-root users
perf data: Fix 'strncat may truncate' build failure with recent gcc
* configfs: Fix use-after-free when accessing sd->s_dentry
fs/configfs/dir.c
* i2c: dev: fix potential memory leak in i2cdev_ioctl_rdwr
drivers/i2c/i2c-dev.c
net: tulip: de4x5: Drop redundant MODULE_DEVICE_TABLE()
* gpio: fix gpio-adp5588 build errors
drivers/gpio/Kconfig
* perf/ring_buffer: Add ordering to rb->nest increment
kernel/events/ring_buffer.c
* perf/ring_buffer: Fix exposing a temporarily decreased data_head
kernel/events/ring_buffer.c
x86/CPU/AMD: Don't force the CPB cap when running under a hypervisor
mISDN: make sure device name is NUL terminated
selftests: netfilter: missing error check when setting up veth interface
perf/x86/intel/ds: Fix EVENT vs. UEVENT PEBS constraints
Revert "staging: vc04_services: prevent integer overflow in create_pagelist()"
sunhv: Fix device naming inconsistency between sunhv_console and sunhv_reg
* neigh: fix use-after-free read in pneigh_get_next
net/core/neighbour.c
lapb: fixed leak of control-blocks.
* ipv6: flowlabel: fl6_sock_lookup() must use atomic_inc_not_zero
net/ipv6/ip6_flowlabel.c
be2net: Fix number of Rx queues used for flow hashing
ax25: fix inconsistent lock state in ax25_destroy_timer
rtc: pcf8523: don't return invalid date when battery is low
USB: serial: option: add Telit 0x1260 and 0x1261 compositions
USB: serial: option: add support for Simcom SIM7500/SIM7600 RNDIS mode
USB: serial: pl2303: add Allied Telesis VT-Kit3
* USB: usb-storage: Add new ID to ums-realtek
drivers/usb/storage/unusual_realtek.h
* USB: Fix chipmunk-like voice when using Logitech C270 for recording audio.
drivers/usb/core/quirks.c
usb: dwc2: Fix DMA cache alignment issues
drm/vmwgfx: NULL pointer dereference from vmw_cmd_dx_view_define()
drm/vmwgfx: integer underflow in vmw_cmd_dx_set_shader() leading to an invalid read
KVM: s390: fix memory slot handling for KVM_SET_USER_MEMORY_REGION
KVM: x86/pmu: do not mask the value that is written to fixed PMUs
usbnet: ipheth: fix racing condition
selftests/timers: Add missing fflush(stdout) calls
scsi: bnx2fc: fix incorrect cast to u64 on shift operation
* arm64/mm: Inhibit huge-vmap with ptdump
arch/arm64/mm/mmu.c
scsi: lpfc: add check for loss of ndlp when sending RRQ
Drivers: misc: fix out-of-bounds access in function param_set_kgdbts_var
Revert "ALSA: seq: Protect in-kernel ioctl calls with mutex"
ALSA: seq: Fix race of get-subscription call vs port-delete ioctls
ALSA: seq: Protect in-kernel ioctl calls with mutex
* x86/uaccess, kcov: Disable stack protector
kernel/Makefile
ASoC: fsl_asrc: Fix the issue about unsupported rate
ASoC: cs42xx8: Add regcache mask dirty
* cgroup: Use css_tryget() instead of css_tryget_online() in task_get_css()
include/linux/cgroup.h
bcache: fix stack corruption by PRECEDING_KEY()
i2c: acorn: fix i2c warning
* media: v4l2-ioctl: clear fields in s_parm
drivers/media/v4l2-core/v4l2-ioctl.c
* ptrace: restore smp_rmb() in __ptrace_may_access()
kernel/cred.c
kernel/ptrace.c
* signal/ptrace: Don't leak unitialized kernel memory with PTRACE_PEEK_SIGINFO
kernel/ptrace.c
fs/ocfs2: fix race in ocfs2_dentry_attach_lock()
* mm/list_lru.c: fix memory leak in __memcg_init_list_lru_node
mm/list_lru.c
libata: Extend quirks for the ST1000LM024 drives with NOLPM quirk
ALSA: oxfw: allow PCM capture for Stanton SCS.1m
ALSA: seq: Cover unsubscribe_port() in list_mutex
* Revert "Bluetooth: Align minimum encryption key size for LE and BR/EDR connections"
include/net/bluetooth/hci_core.h
net/bluetooth/hci_conn.c
ARM: exynos: Fix undefined instruction during Exynos5422 resume
* pwm: Fix deadlock warning when removing PWM device
drivers/pwm/core.c
drivers/pwm/sysfs.c
include/linux/pwm.h
ARM: dts: exynos: Always enable necessary APIO_1V8 and ABB_1V8 regulators on Arndale Octa
pwm: tiehrpwm: Update shadow register for disabling PWMs
dmaengine: idma64: Use actual device for DMA transfers
gpio: gpio-omap: add check for off wake capable gpios
PCI: xilinx: Check for __get_free_pages() failure
video: imsttfb: fix potential NULL pointer dereferences
video: hgafb: fix potential NULL pointer dereference
PCI: rcar: Fix 64bit MSI message address handling
PCI: rcar: Fix a potential NULL pointer dereference
platform/x86: intel_pmc_ipc: adding error handling
PCI: rpadlpar: Fix leaked device_node references in add/remove paths
ARM: dts: imx6qdl: Specify IMX6QDL_CLK_IPG as "ipg" clock to SDMA
ARM: dts: imx6sx: Specify IMX6SX_CLK_IPG as "ipg" clock to SDMA
ARM: dts: imx6ul: Specify IMX6UL_CLK_IPG as "ipg" clock to SDMA
ARM: dts: imx7d: Specify IMX7D_CLK_IPG as "ipg" clock to SDMA
ARM: dts: imx6sx: Specify IMX6SX_CLK_IPG as "ahb" clock to SDMA
clk: rockchip: Turn on "aclk_dmac1" for suspend on rk3288
soc: mediatek: pwrap: Zero initialize rdata in pwrap_init_cipher
platform/chrome: cros_ec_proto: check for NULL transfer function
x86/PCI: Fix PCI IRQ routing table memory leak
nfsd: allow fh_want_write to be called twice
* fuse: retrieve: cap requested size to negotiated max_write
fs/fuse/dev.c
* nvmem: core: fix read buffer in place
drivers/nvmem/core.c
ALSA: hda - Register irq handler after the chip initialization
iommu/vt-d: Set intel_iommu_gfx_mapped correctly
* watchdog: fix compile time error of pretimeout governors
drivers/watchdog/Kconfig
watchdog: imx2_wdt: Fix set_timeout for big timeout values
uml: fix a boot splat wrt use of cpu_all_mask
* configfs: fix possible use-after-free in configfs_register_group
fs/configfs/dir.c
* f2fs: fix to do sanity check on valid block count of segment
fs/f2fs/segment.h
* f2fs: fix to clear dirty inode in error path of f2fs_iget()
fs/f2fs/inode.c
* f2fs: fix to avoid panic in do_recover_data()
fs/f2fs/recovery.c
* ntp: Allow TAI-UTC offset to be set to zero
kernel/time/ntp.c
pwm: meson: Use the spin-lock only to protect register modifications
objtool: Don't use ignore flag for fake jumps
drm/bridge: adv7511: Fix low refresh rate selection
perf/x86/intel: Allow PEBS multi-entry in watermark mode
mfd: twl6040: Fix device init errors for ACCCTL register
mfd: intel-lpss: Set the device in reset state when init
mfd: tps65912-spi: Add missing of table registration
drivers: thermal: tsens: Don't print error message on -EPROBE_DEFER
* kernel/sys.c: prctl: fix false positive in validate_prctl_map()
kernel/sys.c
mm/slab.c: fix an infinite loop in leaks_show()
mm/cma_debug.c: fix the break condition in cma_maxchunk_get()
* mm/cma.c: fix crash on CMA allocation if bitmap allocation fails
mm/cma.c
* mem-hotplug: fix node spanned pages when we have a node with only ZONE_MOVABLE
mm/page_alloc.c
hugetlbfs: on restore reserve error path retain subpool reservation
ARM: prevent tracing IPI_CPU_BACKTRACE
ipc: prevent lockup on alloc_msg and free_msg
* sysctl: return -EINVAL if val violates minmax
kernel/sysctl.c
* fs/fat/file.c: issue flush after the writeback of FAT
fs/fat/file.c
rapidio: fix a NULL pointer dereference when create_workqueue() fails
* ANDROID: kernel: cgroup: cpuset: Clear cpus_requested for empty buf
kernel/cpuset.c
* ANDROID: kernel: cgroup: cpuset: Add missing allocation of cpus_requested in alloc_trial_cpuset
kernel/cpuset.c
* mm: memcontrol: fix NULL pointer crash in test_clear_page_writeback()
include/linux/memcontrol.h
mm/memcontrol.c
mm/page-writeback.c
Merge 4.9.182 into android-4.9
Linux 4.9.182
* tcp: enforce tcp_min_snd_mss in tcp_mtu_probing()
net/ipv4/tcp_timer.c
* tcp: add tcp_min_snd_mss sysctl
include/net/netns/ipv4.h
net/ipv4/sysctl_net_ipv4.c
net/ipv4/tcp_ipv4.c
net/ipv4/tcp_output.c
* tcp: tcp_fragment() should apply sane memory limits
include/uapi/linux/snmp.h
net/ipv4/proc.c
net/ipv4/tcp_output.c
* tcp: limit payload size of sacked skbs
include/linux/tcp.h
include/net/tcp.h
net/ipv4/tcp.c
net/ipv4/tcp_input.c
net/ipv4/tcp_output.c
* tcp: reduce tcp_fastretrans_alert() verbosity
net/ipv4/tcp_input.c
efi/libstub: remove duplicate nokaslr
* BACKPORT: Add support for BPF_FUNC_probe_read_str
kernel/trace/bpf_trace.c
* UPSTREAM: binder: check for overflow when alloc for security context
drivers/android/binder.c
* BACKPORT: binder: fix race between munmap() and direct reclaim
drivers/android/binder_alloc.c
Merge 4.9.181 into android-4.9
Linux 4.9.181
* ethtool: check the return value of get_regs_len
net/core/ethtool.c
* ipv4: Define __ipv4_neigh_lookup_noref when CONFIG_INET is disabled
include/net/arp.h
* fuse: Add FOPEN_STREAM to use stream_open()
fs/fuse/file.c
include/uapi/linux/fuse.h
* fs: stream_open - opener for stream-like files so that read and write can run simultaneously without deadlock
fs/open.c
fs/read_write.c
include/linux/fs.h
* TTY: serial_core, add ->install
drivers/tty/serial/serial_core.c
drm/i915: Fix I915_EXEC_RING_MASK
drm/radeon: prefer lower reference dividers
drm/gma500/cdv: Check vbt config bits when detecting lvds panels
genwqe: Prevent an integer overflow in the ioctl
Revert "MIPS: perf: ath79: Fix perfcount IRQ assignment"
MIPS: pistachio: Build uImage.gz by default
* x86/power: Fix 'nosmt' vs hibernation triple fault during resume
include/linux/cpu.h
kernel/cpu.c
* fuse: fallocate: fix return with locked inode
fs/fuse/file.c
parisc: Use implicit space register selection for loading the coherence index of I/O pdirs
* rcu: locking and unlocking need to always be at least barriers
include/linux/rcupdate.h
* Revert "fib_rules: return 0 directly if an exactly same rule exists when NLM_F_EXCL not supplied"
net/core/fib_rules.c
* Revert "fib_rules: fix error in backport of e9919a24d302 ("fib_rules: return 0...")"
net/core/fib_rules.c
* ipv6: use READ_ONCE() for inet->hdrincl as in ipv4
net/ipv6/raw.c
* ipv6: fix EFAULT on sendto with icmpv6 and hdrincl
net/ipv6/raw.c
pktgen: do not sleep with the thread lock held.
net: rds: fix memory leak in rds_ib_flush_mr_pool
net/mlx4_en: ethtool, Remove unsupported SFP EEPROM high pages query
* neighbor: Call __ipv4_neigh_lookup_noref in neigh_xmit
net/core/neighbour.c
* ethtool: fix potential userspace buffer overflow
net/core/ethtool.c
media: uvcvideo: Fix uvc_alloc_entity() allocation alignment
* efi/libstub: Unify command line param parsing
include/linux/efi.h
Revert "x86/build: Move _etext to actual end of .text"
* mm: make page ref count overflow check tighter and more explicit
include/linux/mm.h
* mm: prevent get_user_pages() from overflowing page refcount
mm/gup.c
* mm, gup: ensure real head page is ref-counted when using hugepages
mm/gup.c
* mm, gup: remove broken VM_BUG_ON_PAGE compound check for hugepages
mm/gup.c
* fs: prevent page refcount overflow in pipe_buf_get
fs/fuse/dev.c
fs/pipe.c
fs/splice.c
include/linux/pipe_fs_i.h
kernel/trace/trace.c
* binder: replace "%p" with "%pK"
drivers/android/binder.c
* binder: Replace "%p" with "%pK" for stable
drivers/android/binder.c
brcmfmac: add subtype check for event handling in data path
brcmfmac: assure SSID length from firmware is limited
brcmfmac: add length checks in scheduled scan result handler
drm/vmwgfx: Don't send drm sysfs hotplug events on initial master set
gcc-plugins: Fix build failures under Darwin host
CIFS: cifs_read_allocate_pages: don't iterate through whole page array on ENOMEM
staging: vc04_services: prevent integer overflow in create_pagelist()
docs: Fix conf.py for Sphinx 2.0
* kernel/signal.c: trace_signal_deliver when signal_group_exit
kernel/signal.c
* memcg: make it work on sparse non-0-node systems
include/linux/list_lru.h
mm/list_lru.c
tty: max310x: Fix external crystal register setup
tty: serial: msm_serial: Fix XON/XOFF
drm/nouveau/i2c: Disable i2c bus access after ->fini()
ALSA: hda/realtek - Set default power save node to 0
powerpc/perf: Fix MMCRA corruption by bhrb_filter
Btrfs: fix race updating log root item during fsync
scsi: zfcp: fix to prevent port_remove with pure auto scan LUNs (only sdevs)
scsi: zfcp: fix missing zfcp_port reference put on -EBUSY from port_remove
media: smsusb: better handle optional alignment
media: usb: siano: Fix false-positive "uninitialized variable" warning
media: usb: siano: Fix general protection fault in smsusb
USB: rio500: fix memory leak in close after disconnect
USB: rio500: refuse more than one device at a time
* USB: Add LPM quirk for Surface Dock GigE adapter
drivers/usb/core/quirks.c
USB: sisusbvga: fix oops in error path of sisusb_probe
* USB: Fix slab-out-of-bounds write in usb_get_bos_descriptor
drivers/usb/core/config.c
usbip: usbip_host: fix stub_dev lock context imbalance regression
usbip: usbip_host: fix BUG: sleeping function called from invalid context
* usb: xhci: avoid null pointer deref when bos field is NULL
drivers/usb/host/xhci.c
* xhci: Convert xhci_handshake() to use readl_poll_timeout_atomic()
drivers/usb/host/xhci.c
* xhci: Use %zu for printing size_t type
drivers/usb/host/xhci-ring.c
* xhci: update bounce buffer with correct sg num
drivers/usb/host/xhci-ring.c
* include/linux/bitops.h: sanitize rotate primitives
include/linux/bitops.h
sparc64: Fix regression in non-hypervisor TLB flush xcall
tipc: fix modprobe tipc failed after switch order of device registration
Revert "tipc: fix modprobe tipc failed after switch order of device registration"
xen/pciback: Don't disable PCI_COMMAND on PCI device reset.
crypto: vmx - ghash: do nosimd fallback manually
net: mvpp2: fix bad MVPP2_TXQ_SCHED_TOKEN_CNTR_REG queue value
net: mvneta: Fix err code path of probe
net: dsa: mv88e6xxx: fix handling of upper half of STATS_TYPE_PORT
* ipv4/igmp: fix build error if !CONFIG_IP_MULTICAST
net/ipv4/igmp.c
* ipv4/igmp: fix another memory leak in igmpv3_del_delrec()
net/ipv4/igmp.c
bnxt_en: Fix aggregation buffer leak under OOM condition.
tipc: Avoid copying bytes beyond the supplied data
* usbnet: fix kernel crash after disconnect
drivers/net/usb/usbnet.c
net: stmmac: fix reset gpio free missing
* net-gro: fix use-after-free read in napi_gro_frags()
net/core/dev.c
net: fec: fix the clk mismatch in failed_reset path
* llc: fix skb leak in llc_build_and_send_ui_pkt()
net/llc/llc_output.c
* ipv6: Consider sk_bound_dev_if when binding a raw socket to an address
net/ipv6/raw.c
* Revert "fib_rules: return 0 directly if an exactly same rule exists when NLM_F_EXCL not supplied"
net/core/fib_rules.c
* Revert "fib_rules: fix error in backport of e9919a24d302 ("fib_rules: return 0...")"
net/core/fib_rules.c
Revert "x86/build: Move _etext to actual end of .text"
Merge 4.9.180 into android-4.9
Linux 4.9.180
* drm: Wake up next in drm_read() chain if we are forced to putback the event
drivers/gpu/drm/drm_fops.c
ASoC: davinci-mcasp: Fix clang warning without CONFIG_PM
* spi: Fix zero length xfer bug
drivers/spi/spi.c
spi: rspi: Fix sequencer reset during initialization
spi : spi-topcliff-pch: Fix to handle empty DMA buffers
scsi: lpfc: Fix SLI3 commands being issued on SLI4 devices
media: saa7146: avoid high stack usage with clang
scsi: lpfc: Fix FDMI manufacturer attribute value
media: go7007: avoid clang frame overflow warning with KASAN
media: m88ds3103: serialize reset messages in m88ds3103_set_frontend
dmaengine: tegra210-adma: use devm_clk_*() helpers
scsi: qla4xxx: avoid freeing unallocated dma memory
* usb: core: Add PM runtime calls to usb_hcd_platform_shutdown
drivers/usb/core/hcd.c
rcuperf: Fix cleanup path for invalid perf_type strings
rcutorture: Fix cleanup path for invalid torture_type strings
x86/mce: Fix machine_check_poll() tests for error types
tty: ipwireless: fix missing checks for ioremap
virtio_console: initialize vtermno value for ports
media: wl128x: prevent two potential buffer overflows
spi: tegra114: reset controller on probe
cxgb3/l2t: Fix undefined behaviour
ASoC: fsl_utils: fix a leaked reference by adding missing of_node_put
ASoC: eukrea-tlv320: fix a leaked reference by adding missing of_node_put
* HID: core: move Usage Page concatenation to Main item
drivers/hid/hid-core.c
include/linux/hid.h
* chardev: add additional check for minor range overlap
fs/char_dev.c
x86/ia32: Fix ia32_restore_sigcontext() AC leak
x86/uaccess, signal: Fix AC=1 bloat
* arm64: cpu_ops: fix a leaked reference by adding missing of_node_put
arch/arm64/kernel/cpu_ops.c
* scsi: ufs: Avoid configuring regulator with undefined voltage range
drivers/scsi/ufs/ufshcd.c
* scsi: ufs: Fix regulator load and icc-level configuration
drivers/scsi/ufs/ufshcd.c
brcmfmac: fix Oops when bringing up interface during USB disconnect
brcmfmac: fix race during disconnect when USB completion is in progress
brcmfmac: convert dev_init_lock mutex to completion
b43: shut up clang -Wuninitialized variable warning
brcmfmac: fix missing checks for kmemdup
mwifiex: Fix mem leak in mwifiex_tm_cmd
rtlwifi: fix a potential NULL pointer dereference
iio: common: ssp_sensors: Initialize calculated_time in ssp_common_process_data
iio: hmc5843: fix potential NULL pointer dereferences
iio: ad_sigma_delta: Properly handle SPI bus locking vs CS assertion
x86/build: Keep local relocations with ld.lld
cpufreq: pmac32: fix possible object reference leak
cpufreq/pasemi: fix possible object reference leak
cpufreq: ppc_cbe: fix possible object reference leak
s390: cio: fix cio_irb declaration
extcon: arizona: Disable mic detect if running when driver is removed
* PM / core: Propagate dev->power.wakeup_path when no callbacks
drivers/base/power/main.c
mmc: sdhci-of-esdhc: add erratum eSDHC-A001 and A-008358 support
mmc: sdhci-of-esdhc: add erratum eSDHC5 support
mmc_spi: add a status check for spi_sync_locked
* mmc: core: make pwrseq_emmc (partially) support sleepy GPIO controllers
drivers/mmc/core/pwrseq_emmc.c
scsi: libsas: Do discovery on empty PHY to update PHY info
hwmon: (f71805f) Use request_muxed_region for Super-IO accesses
hwmon: (pc87427) Use request_muxed_region for Super-IO accesses
hwmon: (smsc47b397) Use request_muxed_region for Super-IO accesses
hwmon: (smsc47m1) Use request_muxed_region for Super-IO accesses
hwmon: (vt1211) Use request_muxed_region for Super-IO accesses
RDMA/cxgb4: Fix null pointer dereference on alloc_skb failure
* arm64: vdso: Fix clock_getres() for CLOCK_REALTIME
arch/arm64/include/asm/vdso_datapage.h
arch/arm64/kernel/asm-offsets.c
arch/arm64/kernel/vdso.c
i40e: don't allow changes to HW VLAN stripping on active port VLANs
x86/irq/64: Limit IST stack overflow check to #DB stack
* USB: core: Don't unbind interfaces following device reset failure
drivers/usb/core/hub.c
* sched/core: Handle overflow in cpu_shares_write_u64
kernel/sched/core.c
* sched/core: Check quota and period overflow at usec to nsec conversion
kernel/sched/core.c
powerpc/numa: improve control of topology updates
media: pvrusb2: Prevent a buffer overflow
media: au0828: Fix NULL pointer dereference in au0828_analog_stream_enable()
* audit: fix a memory leak bug
kernel/auditfilter.c
media: ov2659: make S_FMT succeed even if requested format doesn't match
media: au0828: stop video streaming only when last user stops
media: ov6650: Move v4l2_clk_get() to ov6650_video_probe() helper
media: coda: clear error return value before picture run
dmaengine: at_xdmac: remove BUG_ON macro in tasklet
pinctrl: pistachio: fix leaked of_node references
HID: logitech-hidpp: use RAP instead of FAP to get the protocol version
* mm/uaccess: Use 'unsigned long' to placate UBSAN warnings on older GCC versions
lib/strncpy_from_user.c
lib/strnlen_user.c
x86/mm: Remove in_nmi() warning from 64-bit implementation of vmalloc_fault()
* smpboot: Place the __percpu annotation correctly
include/linux/smpboot.h
x86/build: Move _etext to actual end of .text
bcache: avoid clang -Wunintialized warning
bcache: add failure check to run_cache_set() for journal replay
bcache: fix failure in journal relplay
bcache: return error immediately in bch_journal_replay()
crypto: sun4i-ss - Fix invalid calculation of hash end
net: cw1200: fix a NULL pointer dereference
mwifiex: prevent an array overflow
ASoC: fsl_sai: Update is_slave_mode with correct value
* mac80211/cfg80211: update bss channel on channel switch
net/wireless/nl80211.c
dmaengine: pl330: _stop: clear interrupt status
w1: fix the resume command API
rtc: 88pm860x: prevent use-after-free on device remove
iwlwifi: pcie: don't crash on invalid RX interrupt
scsi: qla2xxx: Fix a qla24xx_enable_msix() error path
* sched/cpufreq: Fix kobject memleak
drivers/cpufreq/cpufreq.c
* arm64: Fix compiler warning from pte_unmap() with -Wunused-but-set-variable
arch/arm64/include/asm/pgtable.h
ARM: vdso: Remove dependency with the arch_timer driver internals
brcm80211: potential NULL dereference in brcmf_cfg80211_vndr_cmds_dcmd_handler()
spi: pxa2xx: fix SCR (divisor) calculation
* ASoC: imx: fix fiq dependencies
sound/soc/fsl/Kconfig
powerpc/boot: Fix missing check of lseek() return value
* ASoC: hdmi-codec: unlock the device on startup errors
sound/soc/codecs/hdmi-codec.c
net: ena: gcc 8: fix compilation warning
dmaengine: tegra210-dma: free dma controller in remove()
* mmc: core: Verify SD bus width
drivers/mmc/core/sd.c
cxgb4: Fix error path in cxgb4_init_module
gfs2: Fix lru_count going negative
Revert "btrfs: Honour FITRIM range constraints during free space trim"
tools include: Adopt linux/bits.h
perf tools: No need to include bitops.h in util.h
at76c50x-usb: Don't register led_trigger if usb_register_driver failed
ssb: Fix possible NULL pointer dereference in ssb_host_pcmcia_exit
media: vivid: use vfree() instead of kfree() for dev->bitmap_cap
media: cpia2: Fix use-after-free in cpia2_exit
* fbdev: fix WARNING in __alloc_pages_nodemask bug
drivers/video/fbdev/core/fbcmap.c
* hugetlb: use same fault hash key for shared and private mappings
include/linux/hugetlb.h
* fbdev: fix divide error in fb_var_to_videomode
drivers/video/fbdev/core/modedb.c
btrfs: sysfs: don't leak memory when failing add fsid
Btrfs: fix race between ranged fsync and writeback of adjacent ranges
Btrfs: do not abort transaction at btrfs_update_root() after failure to COW path
gfs2: Fix sign extension bug in gfs2_update_stats
* arm64: Save and restore OSDLR_EL1 across suspend/resume
arch/arm64/mm/proc.S
libnvdimm/namespace: Fix label tracking error
kvm: svm/avic: fix off-by-one in checking host APIC ID
crypto: vmx - CTR: always increment IV as quadword
* Revert "scsi: sd: Keep disk read-only when re-reading partition"
drivers/scsi/sd.c
* bio: fix improper use of smp_mb__before_atomic()
include/linux/bio.h
KVM: x86: fix return value for reserved EFER
* ext4: do not delete unlinked inode from orphan list on failed truncate
fs/ext4/inode.c
Merge remote-tracking branch 'origin/upstream-f2fs-stable-linux-4.9.y' into android-4.9
Merge 4.9.179 into android-4.9
Linux 4.9.179
fbdev: sm712fb: fix memory frequency by avoiding a switch/case fallthrough
btrfs: Honour FITRIM range constraints during free space trim
md/raid: raid5 preserve the writeback action after the parity check
Revert "Don't jump to compute_result state from check_result state"
perf bench numa: Add define for RUSAGE_THREAD if not present
ufs: fix braino in ufs_get_inode_gid() for solaris UFS flavour
* power: supply: sysfs: prevent endless uevent loop with CONFIG_POWER_SUPPLY_DEBUG
drivers/power/supply/power_supply_sysfs.c
KVM: arm/arm64: Ensure vcpu target is unset on reset failure
mac80211: Fix kernel panic due to use of txq after free
* xfrm4: Fix uninitialized memory read in _decode_session4
net/ipv4/xfrm4_policy.c
* vti4: ipip tunnel deregistration fixes.
net/ipv4/ip_vti.c
* xfrm6_tunnel: Fix potential panic when unloading xfrm6_tunnel module
net/ipv6/xfrm6_tunnel.c
* xfrm: policy: Fix out-of-bound array accesses in __xfrm_policy_unlink
net/xfrm/xfrm_user.c
dm delay: fix a crash when invalid device is specified
* PCI: Work around Pericom PCIe-to-PCI bridge Retrain Link erratum
drivers/pci/quirks.c
include/linux/pci.h
PCI: Factor out pcie_retrain_link() function
* PCI: Mark Atheros AR9462 to avoid bus reset
drivers/pci/quirks.c
fbdev: sm712fb: fix crashes and garbled display during DPMS modesetting
fbdev: sm712fb: use 1024x768 by default on non-MIPS, fix garbled display
fbdev: sm712fb: fix support for 1024x768-16 mode
fbdev: sm712fb: fix crashes during framebuffer writes by correctly mapping VRAM
fbdev: sm712fb: fix boot screen glitch when sm712fb replaces VGA
fbdev: sm712fb: fix white screen of death on reboot, don't set CR3B-CR3F
fbdev: sm712fb: fix VRAM detection, don't set SR70/71/74/75
fbdev: sm712fb: fix brightness control on reboot, don't set SR30
objtool: Allow AR to be overridden with HOSTAR
perf intel-pt: Fix sample timestamp wrt non-taken branches
perf intel-pt: Fix improved sample timestamp
perf intel-pt: Fix instructions sampling rate
memory: tegra: Fix integer overflow on tick value calculation
* tracing: Fix partial reading of trace event's id file
kernel/trace/trace_events.c
ceph: flush dirty inodes before proceeding with remount
iommu/tegra-smmu: Fix invalid ASID bits on Tegra30/114
* fuse: honor RLIMIT_FSIZE in fuse_file_fallocate
fs/fuse/file.c
* fuse: fix writepages on 32bit
fs/fuse/file.c
clk: tegra: Fix PLLM programming on Tegra124+ when PMC overrides divider
NFS4: Fix v4.0 client state corruption when mount
media: ov6650: Fix sensor possibly not detected on probe
cifs: fix strcat buffer overflow and reduce raciness in smb21_set_oplock_level()
* of: fix clang -Wunsequenced for be32_to_cpu()
include/linux/of.h
p54: drop device reference count if fails to enable device
intel_th: msu: Fix single mode with IOMMU
md: add mddev->pers to avoid potential NULL pointer dereference
stm class: Fix channel free in stm output free path
parisc: Rename LEVEL to PA_ASM_LEVEL to avoid name clash with DRBD code
parisc: Skip registering LED when running in QEMU
parisc: Export running_on_qemu symbol for modules
vsock/virtio: Initialize core virtio vsock before registering the driver
tipc: fix modprobe tipc failed after switch order of device registration
vsock/virtio: free packets during the socket release
tipc: switch order of device registration to fix a crash
* ppp: deflate: Fix possible crash in deflate_init
drivers/net/ppp/ppp_deflate.c
net/mlx4_core: Change the error print to info print
* net: avoid weird emergency message
net/core/dev.c
* f2fs: link f2fs quota ops for sysfile
fs/f2fs/checkpoint.c
fs/f2fs/super.c
* BACKPORT: gcov: clang support
kernel/gcov/Kconfig
UPSTREAM: gcov: docs: add a note on GCC vs Clang differences
UPSTREAM: gcov: clang: move common GCC code into gcc_base.c
* UPSTREAM: module: add stubs for within_module functions
include/linux/module.h
* UPSTREAM: gcov: remove CONFIG_GCOV_FORMAT_AUTODETECT
kernel/gcov/Kconfig
* BACKPORT: kbuild: gcov: enable -fno-tree-loop-im if supported
Makefile
Merge remote-tracking branch 'origin/upstream-f2fs-stable-linux-4.9.y' into android-4.9
* ext4: fix build warning
fs/ext4/file.c
Change-Id: I8e7abd3cefdf0f9d9c1fa5b63a0abf243fe7c7d1
Signed-off-by: Robin Peng <robinpeng@google.com>
725 lines
19 KiB
C
725 lines
19 KiB
C
#ifndef __LINUX_PWM_H
|
|
#define __LINUX_PWM_H
|
|
|
|
#include <linux/err.h>
|
|
#include <linux/mutex.h>
|
|
#include <linux/of.h>
|
|
|
|
struct pwm_capture;
|
|
struct seq_file;
|
|
|
|
struct pwm_chip;
|
|
|
|
/**
|
|
* enum pwm_polarity - polarity of a PWM signal
|
|
* @PWM_POLARITY_NORMAL: a high signal for the duration of the duty-
|
|
* cycle, followed by a low signal for the remainder of the pulse
|
|
* period
|
|
* @PWM_POLARITY_INVERSED: a low signal for the duration of the duty-
|
|
* cycle, followed by a high signal for the remainder of the pulse
|
|
* period
|
|
*/
|
|
enum pwm_polarity {
|
|
PWM_POLARITY_NORMAL,
|
|
PWM_POLARITY_INVERSED,
|
|
};
|
|
|
|
/**
|
|
* struct pwm_args - board-dependent PWM arguments
|
|
* @period: reference period
|
|
* @polarity: reference polarity
|
|
*
|
|
* This structure describes board-dependent arguments attached to a PWM
|
|
* device. These arguments are usually retrieved from the PWM lookup table or
|
|
* device tree.
|
|
*
|
|
* Do not confuse this with the PWM state: PWM arguments represent the initial
|
|
* configuration that users want to use on this PWM device rather than the
|
|
* current PWM hardware state.
|
|
*/
|
|
struct pwm_args {
|
|
unsigned int period;
|
|
enum pwm_polarity polarity;
|
|
};
|
|
|
|
enum {
|
|
PWMF_REQUESTED = 1 << 0,
|
|
PWMF_EXPORTED = 1 << 1,
|
|
};
|
|
|
|
/**
|
|
* enum pwm_output_type - output type of the PWM signal
|
|
* @PWM_OUTPUT_FIXED: PWM output is fixed until a change request
|
|
* @PWM_OUTPUT_MODULATED: PWM output is modulated in hardware
|
|
* autonomously with a predefined pattern
|
|
*/
|
|
enum pwm_output_type {
|
|
PWM_OUTPUT_FIXED = 1 << 0,
|
|
PWM_OUTPUT_MODULATED = 1 << 1,
|
|
};
|
|
|
|
/**
|
|
* struct pwm_output_pattern - PWM duty pattern for MODULATED duty type
|
|
* @duty_pattern: PWM duty cycles in the pattern for duty modulation
|
|
* @num_entries: number of entries in the pattern
|
|
* @cycles_per_duty: number of PWM period cycles an entry stays at
|
|
*/
|
|
struct pwm_output_pattern {
|
|
unsigned int *duty_pattern;
|
|
unsigned int num_entries;
|
|
unsigned int cycles_per_duty;
|
|
};
|
|
|
|
/*
|
|
* struct pwm_state - state of a PWM channel
|
|
* @period: PWM period (in nanoseconds)
|
|
* @duty_cycle: PWM duty cycle (in nanoseconds)
|
|
* @polarity: PWM polarity
|
|
* @enabled: PWM enabled status
|
|
*/
|
|
struct pwm_state {
|
|
unsigned int period;
|
|
unsigned int duty_cycle;
|
|
enum pwm_polarity polarity;
|
|
enum pwm_output_type output_type;
|
|
struct pwm_output_pattern *output_pattern;
|
|
bool enabled;
|
|
};
|
|
|
|
/**
|
|
* struct pwm_device - PWM channel object
|
|
* @label: name of the PWM device
|
|
* @flags: flags associated with the PWM device
|
|
* @hwpwm: per-chip relative index of the PWM device
|
|
* @pwm: global index of the PWM device
|
|
* @chip: PWM chip providing this PWM device
|
|
* @chip_data: chip-private data associated with the PWM device
|
|
* @args: PWM arguments
|
|
* @state: curent PWM channel state
|
|
*/
|
|
struct pwm_device {
|
|
const char *label;
|
|
unsigned long flags;
|
|
unsigned int hwpwm;
|
|
unsigned int pwm;
|
|
struct pwm_chip *chip;
|
|
void *chip_data;
|
|
|
|
struct pwm_args args;
|
|
struct pwm_state state;
|
|
};
|
|
|
|
/**
|
|
* pwm_get_state() - retrieve the current PWM state
|
|
* @pwm: PWM device
|
|
* @state: state to fill with the current PWM state
|
|
*/
|
|
static inline void pwm_get_state(const struct pwm_device *pwm,
|
|
struct pwm_state *state)
|
|
{
|
|
*state = pwm->state;
|
|
}
|
|
|
|
static inline bool pwm_is_enabled(const struct pwm_device *pwm)
|
|
{
|
|
struct pwm_state state;
|
|
|
|
pwm_get_state(pwm, &state);
|
|
|
|
return state.enabled;
|
|
}
|
|
|
|
static inline void pwm_set_period(struct pwm_device *pwm, unsigned int period)
|
|
{
|
|
if (pwm)
|
|
pwm->state.period = period;
|
|
}
|
|
|
|
static inline unsigned int pwm_get_period(const struct pwm_device *pwm)
|
|
{
|
|
struct pwm_state state;
|
|
|
|
pwm_get_state(pwm, &state);
|
|
|
|
return state.period;
|
|
}
|
|
|
|
static inline void pwm_set_duty_cycle(struct pwm_device *pwm, unsigned int duty)
|
|
{
|
|
if (pwm)
|
|
pwm->state.duty_cycle = duty;
|
|
}
|
|
|
|
static inline unsigned int pwm_get_duty_cycle(const struct pwm_device *pwm)
|
|
{
|
|
struct pwm_state state;
|
|
|
|
pwm_get_state(pwm, &state);
|
|
|
|
return state.duty_cycle;
|
|
}
|
|
|
|
static inline enum pwm_polarity pwm_get_polarity(const struct pwm_device *pwm)
|
|
{
|
|
struct pwm_state state;
|
|
|
|
pwm_get_state(pwm, &state);
|
|
|
|
return state.polarity;
|
|
}
|
|
|
|
static inline enum pwm_output_type pwm_get_output_type(
|
|
const struct pwm_device *pwm)
|
|
{
|
|
struct pwm_state state;
|
|
|
|
pwm_get_state(pwm, &state);
|
|
|
|
return state.output_type;
|
|
}
|
|
|
|
static inline struct pwm_output_pattern *pwm_get_output_pattern(
|
|
struct pwm_device *pwm)
|
|
{
|
|
struct pwm_state state;
|
|
|
|
pwm_get_state(pwm, &state);
|
|
|
|
return pwm->state.output_pattern ?: NULL;
|
|
}
|
|
|
|
static inline void pwm_get_args(const struct pwm_device *pwm,
|
|
struct pwm_args *args)
|
|
{
|
|
*args = pwm->args;
|
|
}
|
|
|
|
/**
|
|
* pwm_init_state() - prepare a new state to be applied with pwm_apply_state()
|
|
* @pwm: PWM device
|
|
* @state: state to fill with the prepared PWM state
|
|
*
|
|
* This functions prepares a state that can later be tweaked and applied
|
|
* to the PWM device with pwm_apply_state(). This is a convenient function
|
|
* that first retrieves the current PWM state and the replaces the period
|
|
* and polarity fields with the reference values defined in pwm->args.
|
|
* Once the function returns, you can adjust the ->enabled and ->duty_cycle
|
|
* fields according to your needs before calling pwm_apply_state().
|
|
*
|
|
* ->duty_cycle is initially set to zero to avoid cases where the current
|
|
* ->duty_cycle value exceed the pwm_args->period one, which would trigger
|
|
* an error if the user calls pwm_apply_state() without adjusting ->duty_cycle
|
|
* first.
|
|
*/
|
|
static inline void pwm_init_state(const struct pwm_device *pwm,
|
|
struct pwm_state *state)
|
|
{
|
|
struct pwm_args args;
|
|
|
|
/* First get the current state. */
|
|
pwm_get_state(pwm, state);
|
|
|
|
/* Then fill it with the reference config */
|
|
pwm_get_args(pwm, &args);
|
|
|
|
state->period = args.period;
|
|
state->polarity = args.polarity;
|
|
state->duty_cycle = 0;
|
|
}
|
|
|
|
/**
|
|
* pwm_get_relative_duty_cycle() - Get a relative duty cycle value
|
|
* @state: PWM state to extract the duty cycle from
|
|
* @scale: target scale of the relative duty cycle
|
|
*
|
|
* This functions converts the absolute duty cycle stored in @state (expressed
|
|
* in nanosecond) into a value relative to the period.
|
|
*
|
|
* For example if you want to get the duty_cycle expressed in percent, call:
|
|
*
|
|
* pwm_get_state(pwm, &state);
|
|
* duty = pwm_get_relative_duty_cycle(&state, 100);
|
|
*/
|
|
static inline unsigned int
|
|
pwm_get_relative_duty_cycle(const struct pwm_state *state, unsigned int scale)
|
|
{
|
|
if (!state->period)
|
|
return 0;
|
|
|
|
return DIV_ROUND_CLOSEST_ULL((u64)state->duty_cycle * scale,
|
|
state->period);
|
|
}
|
|
|
|
/**
|
|
* pwm_set_relative_duty_cycle() - Set a relative duty cycle value
|
|
* @state: PWM state to fill
|
|
* @duty_cycle: relative duty cycle value
|
|
* @scale: scale in which @duty_cycle is expressed
|
|
*
|
|
* This functions converts a relative into an absolute duty cycle (expressed
|
|
* in nanoseconds), and puts the result in state->duty_cycle.
|
|
*
|
|
* For example if you want to configure a 50% duty cycle, call:
|
|
*
|
|
* pwm_init_state(pwm, &state);
|
|
* pwm_set_relative_duty_cycle(&state, 50, 100);
|
|
* pwm_apply_state(pwm, &state);
|
|
*
|
|
* This functions returns -EINVAL if @duty_cycle and/or @scale are
|
|
* inconsistent (@scale == 0 or @duty_cycle > @scale).
|
|
*/
|
|
static inline int
|
|
pwm_set_relative_duty_cycle(struct pwm_state *state, unsigned int duty_cycle,
|
|
unsigned int scale)
|
|
{
|
|
if (!scale || duty_cycle > scale)
|
|
return -EINVAL;
|
|
|
|
state->duty_cycle = DIV_ROUND_CLOSEST_ULL((u64)duty_cycle *
|
|
state->period,
|
|
scale);
|
|
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* struct pwm_ops - PWM controller operations
|
|
* @request: optional hook for requesting a PWM
|
|
* @free: optional hook for freeing a PWM
|
|
* @config: configure duty cycles and period length for this PWM
|
|
* @set_polarity: configure the polarity of this PWM
|
|
* @capture: capture and report PWM signal
|
|
* @enable: enable PWM output toggling
|
|
* @disable: disable PWM output toggling
|
|
* @get_output_type_supported: get the supported output type
|
|
* @set_output_type: set PWM output type
|
|
* @set_output_pattern: set the pattern for the modulated output
|
|
* @apply: atomically apply a new PWM config. The state argument
|
|
* should be adjusted with the real hardware config (if the
|
|
* approximate the period or duty_cycle value, state should
|
|
* reflect it)
|
|
* @get_state: get the current PWM state. This function is only
|
|
* called once per PWM device when the PWM chip is
|
|
* registered.
|
|
* @dbg_show: optional routine to show contents in debugfs
|
|
* @owner: helps prevent removal of modules exporting active PWMs
|
|
*/
|
|
struct pwm_ops {
|
|
int (*request)(struct pwm_chip *chip, struct pwm_device *pwm);
|
|
void (*free)(struct pwm_chip *chip, struct pwm_device *pwm);
|
|
int (*config)(struct pwm_chip *chip, struct pwm_device *pwm,
|
|
int duty_ns, int period_ns);
|
|
int (*set_polarity)(struct pwm_chip *chip, struct pwm_device *pwm,
|
|
enum pwm_polarity polarity);
|
|
int (*capture)(struct pwm_chip *chip, struct pwm_device *pwm,
|
|
struct pwm_capture *result, unsigned long timeout);
|
|
int (*enable)(struct pwm_chip *chip, struct pwm_device *pwm);
|
|
void (*disable)(struct pwm_chip *chip, struct pwm_device *pwm);
|
|
int (*get_output_type_supported)(struct pwm_chip *chip,
|
|
struct pwm_device *pwm);
|
|
int (*set_output_type)(struct pwm_chip *chip, struct pwm_device *pwm,
|
|
enum pwm_output_type output_type);
|
|
int (*set_output_pattern)(struct pwm_chip *chip,
|
|
struct pwm_device *pwm,
|
|
struct pwm_output_pattern *output_pattern);
|
|
int (*apply)(struct pwm_chip *chip, struct pwm_device *pwm,
|
|
struct pwm_state *state);
|
|
void (*get_state)(struct pwm_chip *chip, struct pwm_device *pwm,
|
|
struct pwm_state *state);
|
|
#ifdef CONFIG_DEBUG_FS
|
|
void (*dbg_show)(struct pwm_chip *chip, struct seq_file *s);
|
|
#endif
|
|
struct module *owner;
|
|
};
|
|
|
|
/**
|
|
* struct pwm_chip - abstract a PWM controller
|
|
* @dev: device providing the PWMs
|
|
* @list: list node for internal use
|
|
* @ops: callbacks for this PWM controller
|
|
* @base: number of first PWM controlled by this chip
|
|
* @npwm: number of PWMs controlled by this chip
|
|
* @pwms: array of PWM devices allocated by the framework
|
|
* @of_xlate: request a PWM device given a device tree PWM specifier
|
|
* @of_pwm_n_cells: number of cells expected in the device tree PWM specifier
|
|
* @can_sleep: must be true if the .config(), .enable() or .disable()
|
|
* operations may sleep
|
|
*/
|
|
struct pwm_chip {
|
|
struct device *dev;
|
|
struct list_head list;
|
|
const struct pwm_ops *ops;
|
|
int base;
|
|
unsigned int npwm;
|
|
|
|
struct pwm_device *pwms;
|
|
|
|
struct pwm_device * (*of_xlate)(struct pwm_chip *pc,
|
|
const struct of_phandle_args *args);
|
|
unsigned int of_pwm_n_cells;
|
|
bool can_sleep;
|
|
};
|
|
|
|
/**
|
|
* struct pwm_capture - PWM capture data
|
|
* @period: period of the PWM signal (in nanoseconds)
|
|
* @duty_cycle: duty cycle of the PWM signal (in nanoseconds)
|
|
*/
|
|
struct pwm_capture {
|
|
unsigned int period;
|
|
unsigned int duty_cycle;
|
|
};
|
|
|
|
#if IS_ENABLED(CONFIG_PWM)
|
|
/* PWM user APIs */
|
|
struct pwm_device *pwm_request(int pwm_id, const char *label);
|
|
void pwm_free(struct pwm_device *pwm);
|
|
int pwm_apply_state(struct pwm_device *pwm, struct pwm_state *state);
|
|
int pwm_adjust_config(struct pwm_device *pwm);
|
|
|
|
/**
|
|
* pwm_output_type_support()
|
|
* @pwm: PWM device
|
|
*
|
|
* Returns: output types supported by the PWM device
|
|
*/
|
|
static inline int pwm_get_output_type_supported(struct pwm_device *pwm)
|
|
{
|
|
if (pwm->chip->ops->get_output_type_supported != NULL)
|
|
return pwm->chip->ops->
|
|
get_output_type_supported(pwm->chip, pwm);
|
|
else
|
|
return PWM_OUTPUT_FIXED;
|
|
}
|
|
|
|
/**
|
|
* pwm_config() - change a PWM device configuration
|
|
* @pwm: PWM device
|
|
* @duty_ns: "on" time (in nanoseconds)
|
|
* @period_ns: duration (in nanoseconds) of one cycle
|
|
*
|
|
* Returns: 0 on success or a negative error code on failure.
|
|
*/
|
|
static inline int pwm_config(struct pwm_device *pwm, int duty_ns,
|
|
int period_ns)
|
|
{
|
|
struct pwm_state state;
|
|
|
|
if (!pwm)
|
|
return -EINVAL;
|
|
|
|
if (duty_ns < 0 || period_ns < 0)
|
|
return -EINVAL;
|
|
|
|
pwm_get_state(pwm, &state);
|
|
if (state.duty_cycle == duty_ns && state.period == period_ns)
|
|
return 0;
|
|
|
|
state.duty_cycle = duty_ns;
|
|
state.period = period_ns;
|
|
return pwm_apply_state(pwm, &state);
|
|
}
|
|
|
|
/**
|
|
* pwm_set_polarity() - configure the polarity of a PWM signal
|
|
* @pwm: PWM device
|
|
* @polarity: new polarity of the PWM signal
|
|
*
|
|
* Note that the polarity cannot be configured while the PWM device is
|
|
* enabled.
|
|
*
|
|
* Returns: 0 on success or a negative error code on failure.
|
|
*/
|
|
static inline int pwm_set_polarity(struct pwm_device *pwm,
|
|
enum pwm_polarity polarity)
|
|
{
|
|
struct pwm_state state;
|
|
|
|
if (!pwm)
|
|
return -EINVAL;
|
|
|
|
pwm_get_state(pwm, &state);
|
|
if (state.polarity == polarity)
|
|
return 0;
|
|
|
|
/*
|
|
* Changing the polarity of a running PWM without adjusting the
|
|
* dutycycle/period value is a bit risky (can introduce glitches).
|
|
* Return -EBUSY in this case.
|
|
* Note that this is allowed when using pwm_apply_state() because
|
|
* the user specifies all the parameters.
|
|
*/
|
|
if (state.enabled)
|
|
return -EBUSY;
|
|
|
|
state.polarity = polarity;
|
|
return pwm_apply_state(pwm, &state);
|
|
}
|
|
|
|
/**
|
|
* pwm_enable() - start a PWM output toggling
|
|
* @pwm: PWM device
|
|
*
|
|
* Returns: 0 on success or a negative error code on failure.
|
|
*/
|
|
static inline int pwm_enable(struct pwm_device *pwm)
|
|
{
|
|
struct pwm_state state;
|
|
|
|
if (!pwm)
|
|
return -EINVAL;
|
|
|
|
pwm_get_state(pwm, &state);
|
|
if (state.enabled)
|
|
return 0;
|
|
|
|
state.enabled = true;
|
|
return pwm_apply_state(pwm, &state);
|
|
}
|
|
|
|
/**
|
|
* pwm_disable() - stop a PWM output toggling
|
|
* @pwm: PWM device
|
|
*/
|
|
static inline void pwm_disable(struct pwm_device *pwm)
|
|
{
|
|
struct pwm_state state;
|
|
|
|
if (!pwm)
|
|
return;
|
|
|
|
pwm_get_state(pwm, &state);
|
|
if (!state.enabled)
|
|
return;
|
|
|
|
state.enabled = false;
|
|
pwm_apply_state(pwm, &state);
|
|
}
|
|
|
|
/* PWM provider APIs */
|
|
int pwm_capture(struct pwm_device *pwm, struct pwm_capture *result,
|
|
unsigned long timeout);
|
|
int pwm_set_chip_data(struct pwm_device *pwm, void *data);
|
|
void *pwm_get_chip_data(struct pwm_device *pwm);
|
|
|
|
int pwmchip_add_with_polarity(struct pwm_chip *chip,
|
|
enum pwm_polarity polarity);
|
|
int pwmchip_add(struct pwm_chip *chip);
|
|
int pwmchip_remove(struct pwm_chip *chip);
|
|
struct pwm_device *pwm_request_from_chip(struct pwm_chip *chip,
|
|
unsigned int index,
|
|
const char *label);
|
|
|
|
struct pwm_device *of_pwm_xlate_with_flags(struct pwm_chip *pc,
|
|
const struct of_phandle_args *args);
|
|
|
|
struct pwm_device *pwm_get(struct device *dev, const char *con_id);
|
|
struct pwm_device *of_pwm_get(struct device_node *np, const char *con_id);
|
|
void pwm_put(struct pwm_device *pwm);
|
|
|
|
struct pwm_device *devm_pwm_get(struct device *dev, const char *con_id);
|
|
struct pwm_device *devm_of_pwm_get(struct device *dev, struct device_node *np,
|
|
const char *con_id);
|
|
void devm_pwm_put(struct device *dev, struct pwm_device *pwm);
|
|
|
|
bool pwm_can_sleep(struct pwm_device *pwm);
|
|
#else
|
|
static inline struct pwm_device *pwm_request(int pwm_id, const char *label)
|
|
{
|
|
return ERR_PTR(-ENODEV);
|
|
}
|
|
|
|
static inline void pwm_free(struct pwm_device *pwm)
|
|
{
|
|
}
|
|
|
|
static inline int pwm_apply_state(struct pwm_device *pwm,
|
|
const struct pwm_state *state)
|
|
{
|
|
return -ENOTSUPP;
|
|
}
|
|
|
|
static inline int pwm_adjust_config(struct pwm_device *pwm)
|
|
{
|
|
return -ENOTSUPP;
|
|
}
|
|
|
|
static inline int pwm_config(struct pwm_device *pwm, int duty_ns,
|
|
int period_ns)
|
|
{
|
|
return -EINVAL;
|
|
}
|
|
|
|
static inline int pwm_capture(struct pwm_device *pwm,
|
|
struct pwm_capture *result,
|
|
unsigned long timeout)
|
|
{
|
|
return -EINVAL;
|
|
}
|
|
|
|
static inline int pwm_set_polarity(struct pwm_device *pwm,
|
|
enum pwm_polarity polarity)
|
|
{
|
|
return -ENOTSUPP;
|
|
}
|
|
|
|
static inline int pwm_enable(struct pwm_device *pwm)
|
|
{
|
|
return -EINVAL;
|
|
}
|
|
|
|
static inline void pwm_disable(struct pwm_device *pwm)
|
|
{
|
|
}
|
|
|
|
static inline int pwm_set_chip_data(struct pwm_device *pwm, void *data)
|
|
{
|
|
return -EINVAL;
|
|
}
|
|
|
|
static inline void *pwm_get_chip_data(struct pwm_device *pwm)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
static inline int pwmchip_add(struct pwm_chip *chip)
|
|
{
|
|
return -EINVAL;
|
|
}
|
|
|
|
static inline int pwmchip_add_inversed(struct pwm_chip *chip)
|
|
{
|
|
return -EINVAL;
|
|
}
|
|
|
|
static inline int pwmchip_remove(struct pwm_chip *chip)
|
|
{
|
|
return -EINVAL;
|
|
}
|
|
|
|
static inline struct pwm_device *pwm_request_from_chip(struct pwm_chip *chip,
|
|
unsigned int index,
|
|
const char *label)
|
|
{
|
|
return ERR_PTR(-ENODEV);
|
|
}
|
|
|
|
static inline struct pwm_device *pwm_get(struct device *dev,
|
|
const char *consumer)
|
|
{
|
|
return ERR_PTR(-ENODEV);
|
|
}
|
|
|
|
static inline struct pwm_device *of_pwm_get(struct device_node *np,
|
|
const char *con_id)
|
|
{
|
|
return ERR_PTR(-ENODEV);
|
|
}
|
|
|
|
static inline void pwm_put(struct pwm_device *pwm)
|
|
{
|
|
}
|
|
|
|
static inline struct pwm_device *devm_pwm_get(struct device *dev,
|
|
const char *consumer)
|
|
{
|
|
return ERR_PTR(-ENODEV);
|
|
}
|
|
|
|
static inline struct pwm_device *devm_of_pwm_get(struct device *dev,
|
|
struct device_node *np,
|
|
const char *con_id)
|
|
{
|
|
return ERR_PTR(-ENODEV);
|
|
}
|
|
|
|
static inline void devm_pwm_put(struct device *dev, struct pwm_device *pwm)
|
|
{
|
|
}
|
|
|
|
static inline bool pwm_can_sleep(struct pwm_device *pwm)
|
|
{
|
|
return false;
|
|
}
|
|
#endif
|
|
|
|
static inline void pwm_apply_args(struct pwm_device *pwm)
|
|
{
|
|
struct pwm_state state = { };
|
|
|
|
/*
|
|
* PWM users calling pwm_apply_args() expect to have a fresh config
|
|
* where the polarity and period are set according to pwm_args info.
|
|
* The problem is, polarity can only be changed when the PWM is
|
|
* disabled.
|
|
*
|
|
* PWM drivers supporting hardware readout may declare the PWM device
|
|
* as enabled, and prevent polarity setting, which changes from the
|
|
* existing behavior, where all PWM devices are declared as disabled
|
|
* at startup (even if they are actually enabled), thus authorizing
|
|
* polarity setting.
|
|
*
|
|
* To fulfill this requirement, we apply a new state which disables
|
|
* the PWM device and set the reference period and polarity config.
|
|
*
|
|
* Note that PWM users requiring a smooth handover between the
|
|
* bootloader and the kernel (like critical regulators controlled by
|
|
* PWM devices) will have to switch to the atomic API and avoid calling
|
|
* pwm_apply_args().
|
|
*/
|
|
|
|
state.enabled = false;
|
|
state.polarity = pwm->args.polarity;
|
|
state.period = pwm->args.period;
|
|
|
|
pwm_apply_state(pwm, &state);
|
|
}
|
|
|
|
struct pwm_lookup {
|
|
struct list_head list;
|
|
const char *provider;
|
|
unsigned int index;
|
|
const char *dev_id;
|
|
const char *con_id;
|
|
unsigned int period;
|
|
enum pwm_polarity polarity;
|
|
};
|
|
|
|
#define PWM_LOOKUP(_provider, _index, _dev_id, _con_id, _period, _polarity) \
|
|
{ \
|
|
.provider = _provider, \
|
|
.index = _index, \
|
|
.dev_id = _dev_id, \
|
|
.con_id = _con_id, \
|
|
.period = _period, \
|
|
.polarity = _polarity \
|
|
}
|
|
|
|
#if IS_ENABLED(CONFIG_PWM)
|
|
void pwm_add_table(struct pwm_lookup *table, size_t num);
|
|
void pwm_remove_table(struct pwm_lookup *table, size_t num);
|
|
#else
|
|
static inline void pwm_add_table(struct pwm_lookup *table, size_t num)
|
|
{
|
|
}
|
|
|
|
static inline void pwm_remove_table(struct pwm_lookup *table, size_t num)
|
|
{
|
|
}
|
|
#endif
|
|
|
|
#ifdef CONFIG_PWM_SYSFS
|
|
void pwmchip_sysfs_export(struct pwm_chip *chip);
|
|
void pwmchip_sysfs_unexport(struct pwm_chip *chip);
|
|
#else
|
|
static inline void pwmchip_sysfs_export(struct pwm_chip *chip)
|
|
{
|
|
}
|
|
|
|
static inline void pwmchip_sysfs_unexport(struct pwm_chip *chip)
|
|
{
|
|
}
|
|
#endif /* CONFIG_PWM_SYSFS */
|
|
|
|
#endif /* __LINUX_PWM_H */
|